Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ coverage/*
/src/types/
/src/sdk/generated
/src/resources

20 changes: 9 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,16 @@ jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
- uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- run: bun i
- run: rm -rf dist
- run: bun run build
node-version: 20
registry-url: "https://registry.npmjs.org"
- uses: pnpm/action-setup@v4
- run: pnpm install --frozen-lockfile
- run: pnpm run build
env:
CODEX_API_KEY: ${{ secrets.CODEX_API_KEY }}
- run: npm publish --access public
- run: pnpm publish --access public --no-git-checks
env:
NPM_TOKEN: ${{secrets.CODEX_SDK_NPM_TOKEN}}
NODE_AUTH_TOKEN: ${{secrets.CODEX_SDK_NPM_TOKEN}}
23 changes: 14 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@ on:
push:
branches-ignore:
- main
pull_request:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
with:
node-version: 18
- uses: oven-sh/setup-bun@v1
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
bun-version: latest
- run: bun i
- run: bun run lint
- run: bun run test
node-version: 20
- uses: pnpm/action-setup@v4
- run: pnpm install --frozen-lockfile
- name: Lint
run: pnpm run lint
- name: Type Check
run: pnpm run build:types
- name: Test
run: pnpm run test
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ coverage
.next
dist
yarn-error.log
src/resources/generated_queries*
src/resources/generated_subscriptions*
src/resources/generated_mutations*

# Generated resources (all regenerated at build time)
src/resources/
3 changes: 2 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
auto-install-peers=true
strict-peer-dependencies=false
19 changes: 19 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Dependencies
node_modules
pnpm-lock.yaml

# Build output
dist
dist-esm

# Generated files
src/resources/
src/sdk/generated/

# IDE
.vscode
.idea

# Misc
coverage
*.log
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"semi": true,
"trailingComma": "all",
"singleQuote": false,
"printWidth": 80,
"tabWidth": 2,
"useTabs": false
}
10 changes: 10 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"recommendations": [
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"bradlc.vscode-tailwindcss",
"GraphQL.vscode-graphql",
"GraphQL.vscode-graphql-syntax",
"ms-vscode.vscode-typescript-next"
]
}
4 changes: 1 addition & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
"request": "launch",
"name": "Launch test",
"cwd": "${workspaceFolder}",
"skipFiles": [
"<node_internals>/**"
],
"skipFiles": ["<node_internals>/**"],
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/tsx"
}
]
Expand Down
26 changes: 26 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.organizeImports": "explicit"
},
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"graphql"
],
"eslint.workingDirectories": [
".",
"./examples/simple",
"./examples/codegen",
"./examples/next"
],
"typescript.preferences.importModuleSpecifier": "relative",
"typescript.suggest.autoImports": true,
"files.associations": {
"*.graphql": "graphql"
}
}
176 changes: 137 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@

This package exists to help you develop on top of the Codex API (https://docs.codex.io).

It provides the public schema SDL for you to use. You can use graphql-codegen to generate types and queries for example.
It provides generated TypeScript types and convenient methods to access the GraphQL API with full type safety.

> [!NOTE]
> We've changed our name from Defined to Codex.
>
> You will see references to our previous company name, Defined, while we make the switch to Codex.

## Features

- πŸš€ **Fully Typed**: Generated TypeScript types for all GraphQL operations
- πŸ“¦ **Tree Shakeable**: ESM support with optimized bundle size
- πŸ”„ **Real-time**: WebSocket subscriptions support
- πŸ›  **Developer Friendly**: Comprehensive examples and documentation

## Installation

| packager | command |
| ----------------------------- | ------------------------- |
| [npm](https://www.npmjs.com/) | `npm add @codex-data/sdk` |
| [yarn](https://yarnpkg.com/) | `yarn add @codex-data/sdk` |
| [bun](https://bun.sh/) | `bun add @codex-data/sdk` |
| Package Manager | Command |
| ----------------------------- | ----------------------------- |
| [npm](https://www.npmjs.com/) | `npm install @codex-data/sdk` |
| [yarn](https://yarnpkg.com/) | `yarn add @codex-data/sdk` |
| [pnpm](https://pnpm.io/) | `pnpm add @codex-data/sdk` |

## Usage

Expand All @@ -41,70 +48,161 @@ sdk.queries
Use your own GraphQL selections

```typescript
import { Network } from "../../src/resources/graphql";
import { Codex } from "@codex-data/sdk/dist/sdk";
import { Codex } from "@codex-data/sdk";

const sdk = new Codex(process.env.CODEX_API_KEY || "");

// Using the raw GraphQL client
sdk
.send<{ getNetworks: Network[] }>(
.send<{ getNetworks: Array<{ id: string; name: string }> }>(
`
query GetNetworks {
getNetworks { id name }
}
`,
{}
{},
)
.then((res) => {
console.log("Networks: ", res.getNetworks);
});
```

## Running the examples
Subscribe to real-time data

```typescript
import { Codex } from "@codex-data/sdk";

const sdk = new Codex(process.env.CODEX_API_KEY || "");

// Subscribe to price updates
sdk.subscriptions.onPriceUpdated(
{
address: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
networkId: 56,
},
(result) => {
if (result.data) {
console.log("Price updated:", result.data.onPriceUpdated);
}
},
);
```

## Development

You'll need to have [`curl`](https://curl.se/) installed in order to build this locally, as it fetches the schema from the Codex API.
### Prerequisites

You need to provide an API key in order for the examples to work. We have [bun](https://bun.sh) in use for development here.
- [Node.js](https://nodejs.org/) >= 17.5.0
- [pnpm](https://pnpm.io/) (recommended) or npm/yarn
- [`curl`](https://curl.se/) for fetching the GraphQL schema

After installing [bun](https://bun.sh), from the project root.
### Building from Source

- `bun i`
- `bun run build`
```bash
# Install dependencies
pnpm install

### Simple
# Build the SDK
pnpm run build
```

This performs a simple inline graphql request, and uses a user-provided query and selection set.
### Running Examples

- `cd examples/simple`
- `bun i`
- `CODEX_API_KEY=xyz bun run index.ts`
All examples require a Codex API key. Get your API key at [docs.codex.io](https://docs.codex.io).

You can define your own GraphQL queries and use those with codegen (see next section). The pre-defined queries we provide in the
examples do not include all of the fields for every query.
#### Simple Example

### Codegen
Basic usage with inline GraphQL queries:

This shows how to use graphql-codegen to generate query types and get a fully typed end-to-end experience.
```bash
cd examples/simple
pnpm install
CODEX_API_KEY=your_api_key pnpm run dev
```

- `cd examples/codegen`
- `bun i`
- `bun run codegen`
- `CODEX_API_KEY=xyz bun run src/index.ts`
#### Codegen Example

### Next
Shows how to use GraphQL Code Generator for fully typed queries:

This shows how you could use it in a NextJS project.
```bash
cd examples/codegen
pnpm install
pnpm run codegen
CODEX_API_KEY=your_api_key pnpm run dev
```

#### Next.js Example

Full-stack example with a Next.js application:

```bash
cd examples/next
pnpm install
NEXT_PUBLIC_CODEX_API_KEY=your_api_key pnpm run dev
```

- `cd examples/next`
- `bun i`
- `NEXT_PUBLIC_CODEX_API_KEY=xyz bun run dev`
## Package Structure

## Releasing a new version
The SDK is built with modern tooling and provides both CommonJS and ESM builds:

- Increase version number to what you want in package.json on a branch.
- Merge that Pr to main
- Release it with the right version number.
```
@codex-data/sdk/
β”œβ”€β”€ dist/
β”‚ β”œβ”€β”€ index.js # CommonJS entry point
β”‚ β”œβ”€β”€ index.mjs # ESM entry point
β”‚ β”œβ”€β”€ index.d.ts # TypeScript definitions
β”‚ └── sdk/ # SDK implementation
β”œβ”€β”€ README.md
└── package.json
```

## Contributing

Prs open!
We welcome contributions! Please feel free to submit a Pull Request.

### Development Scripts

- `pnpm run build` - Build the SDK for production
- `pnpm run test` - Run the test suite
- `pnpm run lint` - Lint the codebase
- `pnpm run clean` - Clean build artifacts

## Releasing

### Publishing Beta Versions

For testing releases before making them public:

1. Update the version in `package.json` to a beta version:

```json
"version": "2.0.0-beta.0"
```

2. Publish to the beta tag:

```bash
pnpm run publish:beta
```

3. Test the beta version:
```bash
npm install @codex-data/sdk@beta
```

Users installing without the `@beta` tag will continue to receive the latest stable version.

### Publishing Production Releases

1. Update the version in `package.json` to a production version:

```json
"version": "2.0.0"
```

2. Publish to the latest tag:
```bash
pnpm run publish:latest
```

> **Note:** The `prepublishOnly` script automatically runs the full build before publishing, ensuring the package is always built before release.
Binary file removed bun.lockb
Binary file not shown.
2 changes: 0 additions & 2 deletions bunfig.toml

This file was deleted.

Loading
Loading