Skip to content

Commit 841747a

Browse files
Kit SDK (#179)
* Use Codama to generate the Umi client * Switch Umi render back to Kinobi, just write Codama tree for now * Tweak regex in kinobi/codama scripts * initial codama SDK * remove anys * tests * use splTokenProgram default * Rename to mpl-token-metadata-kit * fix wrong merge * regenerate sdk * fix CI * add kit to CI * fix pnpm-lock.yaml * Code Rabbit * add typedoc * deploy workflow * code rabbit * fix comment in readme --------- Co-authored-by: Callum <callum.mcintyre@anza.xyz>
1 parent 9b514cd commit 841747a

246 files changed

Lines changed: 118258 additions & 38 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CARGO_TERM_COLOR=always
2-
NODE_VERSION=16.x
2+
NODE_VERSION=20.x
33
PROGRAMS=["token-metadata"]
44
RUST_VERSION=1.79.0
55
SOLANA_VERSION=2.0.9

.github/file-filters.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ client_common: &client_common
3131
- ".github/.env"
3232
- "configs/shank.cjs"
3333
- "configs/kinobi.cjs"
34+
- "configs/codama.cjs"
3435

3536
js_client: &js_client
3637
- *client_common
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
name: Deploy JS Kit Client
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
bump:
7+
description: Version bump
8+
required: true
9+
default: patch
10+
type: choice
11+
options:
12+
- patch
13+
- minor
14+
- major
15+
- prerelease
16+
- prepatch
17+
- preminor
18+
- premajor
19+
tag:
20+
description: NPM Tag (and preid for pre-releases)
21+
required: true
22+
type: string
23+
default: latest
24+
create_release:
25+
description: Create a GitHub release
26+
required: true
27+
type: boolean
28+
default: true
29+
30+
env:
31+
CACHE: true
32+
33+
jobs:
34+
build_programs:
35+
name: Programs
36+
uses: ./.github/workflows/build-programs.yml
37+
secrets: inherit
38+
39+
test_js_client:
40+
name: JS client
41+
needs: build_programs
42+
uses: ./.github/workflows/test-js-client.yml
43+
secrets: inherit
44+
45+
deploy_js_kit_client:
46+
name: JS Kit client / Deploy
47+
runs-on: ubuntu-latest
48+
needs: test_js_client
49+
permissions:
50+
contents: write
51+
steps:
52+
- name: Git checkout
53+
uses: actions/checkout@v4
54+
with:
55+
token: ${{ secrets.SVC_TOKEN }}
56+
57+
- name: Load environment variables
58+
run: cat .github/.env >> $GITHUB_ENV
59+
60+
- name: Install Node.js
61+
uses: metaplex-foundation/actions/install-node-with-pnpm@v1
62+
with:
63+
version: ${{ env.NODE_VERSION }}
64+
cache: ${{ env.CACHE }}
65+
66+
- name: Install dependencies
67+
uses: metaplex-foundation/actions/install-node-dependencies@v1
68+
with:
69+
folder: ./clients/js-kit
70+
cache: ${{ env.CACHE }}
71+
key: clients-js-kit
72+
73+
- name: Build
74+
working-directory: ./clients/js-kit
75+
run: pnpm build
76+
77+
- name: Bump
78+
id: bump
79+
working-directory: ./clients/js-kit
80+
run: |
81+
if [ "${{ startsWith(inputs.bump, 'pre') }}" == "true" ]; then
82+
pnpm version ${{ inputs.bump }} --preid ${{ inputs.tag }} --no-git-tag-version
83+
else
84+
pnpm version ${{ inputs.bump }} --no-git-tag-version
85+
fi
86+
echo "new_version=$(pnpm pkg get version | sed 's/"//g')" >> $GITHUB_OUTPUT
87+
88+
- name: Set publishing config
89+
run: pnpm config set '//registry.npmjs.org/:_authToken' "${NODE_AUTH_TOKEN}"
90+
env:
91+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
92+
93+
- name: Publish
94+
working-directory: ./clients/js-kit
95+
run: pnpm publish --no-git-checks --tag ${{ inputs.tag }}
96+
97+
- name: Commit and tag new version
98+
uses: stefanzweifel/git-auto-commit-action@v4
99+
with:
100+
commit_message: Deploy JS Kit client v${{ steps.bump.outputs.new_version }}
101+
tagging_message: js-kit@v${{ steps.bump.outputs.new_version }}
102+
103+
- name: Create GitHub release
104+
if: github.event.inputs.create_release == 'true'
105+
uses: ncipollo/release-action@v1
106+
with:
107+
tag: js-kit@v${{ steps.bump.outputs.new_version }}
108+
109+
deploy_js_kit_docs:
110+
name: JS Kit client / Deploy docs
111+
runs-on: ubuntu-latest
112+
needs: deploy_js_kit_client
113+
environment:
114+
name: js-kit-client-documentation
115+
url: ${{ steps.deploy.outputs.url }}
116+
steps:
117+
- name: Git checkout
118+
uses: actions/checkout@v3
119+
with:
120+
ref: ${{ github.ref }}
121+
122+
- name: Load environment variables
123+
run: cat .github/.env >> $GITHUB_ENV
124+
125+
- name: Deploy to Vercel
126+
id: deploy
127+
env:
128+
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
129+
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID_JS_KIT }}
130+
working-directory: ./clients/js-kit
131+
run: echo "url=$(vercel deploy --prod --token=${{ secrets.VERCEL_TOKEN }})" | tee $GITHUB_OUTPUT

.github/workflows/test-js-client.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
15-
node: ["16.x", "18.x"]
15+
node: ["18.x", "20.x"]
1616
steps:
1717
- name: Git checkout
1818
uses: actions/checkout@v3
@@ -44,6 +44,21 @@ jobs:
4444
working-directory: ./clients/js
4545
run: pnpm test
4646

47+
- name: Install Kit dependencies
48+
uses: metaplex-foundation/actions/install-node-dependencies@v1
49+
with:
50+
folder: ./clients/js-kit
51+
cache: ${{ env.CACHE }}
52+
key: clients-js-kit
53+
54+
- name: Build Kit
55+
working-directory: ./clients/js-kit
56+
run: pnpm build
57+
58+
- name: Test Kit
59+
working-directory: ./clients/js-kit
60+
run: pnpm test
61+
4762
lint:
4863
name: Lint
4964
runs-on: ubuntu-latest

clients/js-kit/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.vercel
2+
docs

clients/js-kit/.prettierrc.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"semi": true,
3+
"trailingComma": "es5",
4+
"singleQuote": true,
5+
"printWidth": 100,
6+
"tabWidth": 2,
7+
"useTabs": false
8+
}

clients/js-kit/README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# JS Kit Client
2+
3+
This is the TypeScript client for mpl-token-metadata using `@solana/kit` (Solana web3.js 2.0), generated with Codama.
4+
5+
## Generated Code
6+
7+
The client code is auto-generated by Codama in `src/generated/`. Do not edit these files manually - they will be regenerated when running `pnpm generate:clients` from the repository root.
8+
9+
## Testing
10+
11+
Test files have been created in `test/` but require additional infrastructure to run:
12+
13+
14+
### Test Structure
15+
16+
Tests follow the same structure as `clients/js/test/` but use the new API:
17+
18+
```typescript
19+
const mint = await generateKeypair();
20+
const createInstruction = createV1({
21+
mint: mint.address,
22+
name: 'My NFT',
23+
uri: 'https://example.com/my-nft.json',
24+
sellerFeeBasisPoints: 550,
25+
tokenStandard: TokenStandard.Fungible,
26+
});
27+
```
28+
29+
## Running Tests
30+
31+
Tests connect to a local Solana validator and skip gracefully if it's not running:
32+
33+
```bash
34+
# Install dependencies
35+
pnpm install
36+
37+
# Build the project (will show TypeScript errors but still produces output)
38+
pnpm build
39+
40+
# Run tests (will skip if validator not running)
41+
pnpm test
42+
```
43+
44+
### Running Tests with Validator
45+
46+
To actually execute transactions:
47+
48+
```bash
49+
# From repository root, build the program first
50+
pnpm programs:build
51+
52+
# Start the local validator (in a separate terminal)
53+
pnpm validator
54+
55+
# From clients/js-kit, run tests
56+
pnpm test
57+
```
58+
59+
Tests will:
60+
- ✅ Connect to local validator at `http://127.0.0.1:8899`
61+
- ✅ Generate keypairs using @solana/keys
62+
- ✅ Airdrop SOL for test transactions
63+
- ✅ Generate instructions using Codama client
64+
- ✅ Skip transaction sending (not yet implemented)
65+
- ℹ️ Show helpful messages if validator isn't running
66+
67+
## Development
68+
69+
To regenerate this client:
70+
71+
```bash
72+
# From repository root
73+
pnpm generate:clients
74+
```
75+
76+
This will run `configs/codama.cjs` which generates code in `clients/js-kit/src/generated/`.

clients/js-kit/package.json

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"name": "@metaplex-foundation/mpl-token-metadata-kit",
3+
"version": "0.0.1",
4+
"description": "JavaScript client for Token Metadata using @solana/kit",
5+
"main": "dist/src/index.js",
6+
"types": "dist/src/index.d.ts",
7+
"scripts": {
8+
"build": "rimraf dist && tsc -p tsconfig.json",
9+
"build:docs": "typedoc",
10+
"test": "NODE_OPTIONS='--experimental-global-webcrypto' ava",
11+
"lint": "eslint --ext js,ts,tsx src",
12+
"lint:fix": "eslint --fix --ext js,ts,tsx src",
13+
"format": "prettier --check src test",
14+
"format:fix": "prettier --write src test"
15+
},
16+
"files": [
17+
"/dist/src"
18+
],
19+
"publishConfig": {
20+
"access": "public",
21+
"registry": "https://registry.npmjs.org"
22+
},
23+
"homepage": "https://metaplex.com",
24+
"repository": "https://github.com/metaplex-foundation/mpl-token-metadata.git",
25+
"author": "Metaplex Maintainers <contact@metaplex.com>",
26+
"license": "Apache-2.0",
27+
"devDependencies": {
28+
"@ava/typescript": "^3.0.1",
29+
"@solana-program/token": "^0.9.0",
30+
"@types/node": "^20.0.0",
31+
"ava": "^5.1.0",
32+
"eslint": "^8.0.1",
33+
"eslint-config-prettier": "^8.5.0",
34+
"prettier": "^2.5.1",
35+
"rimraf": "^3.0.2",
36+
"typedoc": "^0.28.0",
37+
"typedoc-plugin-missing-exports": "^4.0.0",
38+
"typescript": "^5.9.3",
39+
"vercel": "^28.16.8"
40+
},
41+
"ava": {
42+
"typescript": {
43+
"compile": false,
44+
"rewritePaths": {
45+
"src/": "dist/src/",
46+
"test/": "dist/test/"
47+
}
48+
},
49+
"require": [
50+
"./test/_ava-setup.js"
51+
],
52+
"timeout": "2m",
53+
"serial": true
54+
},
55+
"packageManager": "pnpm@8.9.0",
56+
"dependencies": {
57+
"@solana-program/token": "^0.9.0",
58+
"@solana/accounts": "^5.0.0",
59+
"@solana/addresses": "^5.0.0",
60+
"@solana/codecs": "^5.0.0",
61+
"@solana/codecs-strings": "^5.1.0",
62+
"@solana/functional": "^5.1.0",
63+
"@solana/instructions": "^5.1.0",
64+
"@solana/keys": "^5.0.0",
65+
"@solana/kit": "^5.0.0",
66+
"@solana/rpc": "^5.0.0",
67+
"@solana/rpc-subscriptions": "^5.0.0",
68+
"@solana/rpc-types": "^5.0.0",
69+
"@solana/signers": "^5.0.0",
70+
"@solana/transaction-confirmation": "^2.0.0",
71+
"@solana/transaction-messages": "^5.0.0",
72+
"@solana/transactions": "^5.0.0"
73+
}
74+
}

0 commit comments

Comments
 (0)