diff --git a/.changeset/spicy-bananas-fly.md b/.changeset/spicy-bananas-fly.md new file mode 100644 index 0000000000000..19409da6d2c0c --- /dev/null +++ b/.changeset/spicy-bananas-fly.md @@ -0,0 +1,16 @@ +--- +'@mysten/ledgerjs-hw-app-sui': minor +'@mysten/wallet-standard': minor +'@mysten/suins-toolkit': minor +'@mysten/create-dapp': minor +'@mysten/sui.js': minor +'@mysten/dapp-kit': minor +'@mysten/deepbook': minor +'@mysten/zklogin': minor +'@mysten/zksend': minor +'@mysten/enoki': minor +'@mysten/kiosk': minor +'@mysten/bcs': minor +--- + +Replace tsup based build to fix issues with esm/cjs dual publishing diff --git a/package.json b/package.json index 223744dfcfac7..a4ae00168b781 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,7 @@ "eslint-plugin-unused-imports": "^3.0.0", "prettier": "^3.0.0", "prettier-plugin-tailwindcss": "^0.4.1", + "tsx": "^3.12.7", "turbo": "^1.10.8", "typescript": "^5.1.6" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b2ac0efc03071..409945e9e224a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -73,6 +73,9 @@ importers: prettier-plugin-tailwindcss: specifier: ^0.4.1 version: 0.4.1(@ianvs/prettier-plugin-sort-imports@4.1.0)(prettier@3.0.0) + tsx: + specifier: ^3.12.7 + version: 3.12.7 turbo: specifier: ^1.10.8 version: 1.10.8 @@ -1122,15 +1125,15 @@ importers: specifier: ^5.0.0 version: 5.0.0 devDependencies: + '@mysten/build-scripts': + specifier: workspace:* + version: link:../build-scripts '@size-limit/preset-small-lib': specifier: ^8.2.6 version: 8.2.6(size-limit@8.2.6) size-limit: specifier: ^8.2.6 version: 8.2.6 - tsup: - specifier: ^7.1.0 - version: 7.1.0(ts-node@10.9.1)(typescript@5.1.6) typescript: specifier: ^5.1.6 version: 5.1.6 @@ -1184,9 +1187,6 @@ importers: '@mysten/build-scripts': specifier: workspace:* version: link:../build-scripts - tsx: - specifier: ^3.12.7 - version: 3.12.7 typescript: specifier: ^5.1.6 version: 5.1.6 @@ -1391,9 +1391,6 @@ importers: size-limit: specifier: ^8.2.6 version: 8.2.6 - tsx: - specifier: ^3.12.7 - version: 3.12.7 typescript: specifier: ^5.1.6 version: 5.1.6 @@ -1410,6 +1407,9 @@ importers: specifier: workspace:* version: link:../typescript devDependencies: + '@mysten/build-scripts': + specifier: workspace:* + version: link:../build-scripts '@types/node': specifier: ^20.4.2 version: 20.4.2 @@ -1422,9 +1422,6 @@ importers: ts-retry-promise: specifier: ^0.7.0 version: 0.7.0 - tsup: - specifier: ^7.1.0 - version: 7.1.0(ts-node@10.9.1)(typescript@5.1.6) typescript: specifier: ^5.1.6 version: 5.1.6 @@ -1511,9 +1508,6 @@ importers: react-dom: specifier: ^18.2.0 version: 18.2.0(react@18.2.0) - tsx: - specifier: ^3.12.7 - version: 3.12.7 typescript: specifier: ^5.1.6 version: 5.1.6 @@ -1527,6 +1521,9 @@ importers: specifier: workspace:* version: link:../typescript devDependencies: + '@mysten/build-scripts': + specifier: workspace:* + version: link:../build-scripts cross-env: specifier: ^7.0.3 version: 7.0.3 @@ -1536,9 +1533,6 @@ importers: ts-retry-promise: specifier: ^0.7.0 version: 0.7.0 - tsup: - specifier: ^7.1.0 - version: 7.1.0(ts-node@10.9.1)(typescript@5.1.6) typescript: specifier: ^5.1.6 version: 5.1.6 @@ -1564,6 +1558,9 @@ importers: '@ledgerhq/hw-transport-mocker': specifier: ^6.27.13 version: 6.27.13 + '@mysten/build-scripts': + specifier: workspace:* + version: link:../build-scripts '@size-limit/preset-small-lib': specifier: ^8.2.6 version: 8.2.6(size-limit@8.2.6) @@ -1573,9 +1570,6 @@ importers: size-limit: specifier: ^8.2.6 version: 8.2.6 - tsup: - specifier: ^7.1.0 - version: 7.1.0(ts-node@10.9.1)(typescript@5.1.6) typescript: specifier: ^5.1.6 version: 5.1.6 @@ -1585,9 +1579,9 @@ importers: sdk/move-binary-format-wasm: devDependencies: - tsup: - specifier: ^7.1.0 - version: 7.1.0(ts-node@10.9.1)(typescript@5.1.6) + '@mysten/build-scripts': + specifier: workspace:* + version: link:../build-scripts typescript: specifier: ^5.1.6 version: 5.1.6 @@ -1598,6 +1592,8 @@ importers: specifier: ^0.12.1 version: 0.12.1 + sdk/move-binary-format/pkg: {} + sdk/suins-toolkit: dependencies: '@mysten/sui.js': @@ -1607,12 +1603,12 @@ importers: '@faker-js/faker': specifier: ^8.0.2 version: 8.0.2 + '@mysten/build-scripts': + specifier: workspace:* + version: link:../build-scripts ts-node: specifier: ^10.9.1 version: 10.9.1(@types/node@20.4.2)(typescript@5.1.6) - tsup: - specifier: ^7.1.0 - version: 7.1.0(ts-node@10.9.1)(typescript@5.1.6) typescript: specifier: ^5.1.6 version: 5.1.6 @@ -1674,9 +1670,6 @@ importers: ts-retry-promise: specifier: ^0.7.0 version: 0.7.0 - tsx: - specifier: ^3.12.7 - version: 3.12.7 typedoc: specifier: ^0.24.8 version: 0.24.8(typescript@5.1.6) @@ -1705,9 +1698,9 @@ importers: specifier: 1.0.3 version: 1.0.3 devDependencies: - tsup: - specifier: ^7.1.0 - version: 7.1.0(ts-node@10.9.1)(typescript@5.1.6) + '@mysten/build-scripts': + specifier: workspace:* + version: link:../build-scripts typescript: specifier: ^5.1.6 version: 5.1.6 @@ -1736,9 +1729,6 @@ importers: '@types/node': specifier: ^20.4.2 version: 20.4.2 - tsx: - specifier: ^3.12.7 - version: 3.12.7 typescript: specifier: ^5.1.6 version: 5.1.6 @@ -1758,9 +1748,6 @@ importers: '@types/node': specifier: ^20.4.2 version: 20.4.2 - tsx: - specifier: ^3.12.7 - version: 3.12.7 typescript: specifier: ^5.1.6 version: 5.1.6 @@ -12178,16 +12165,6 @@ packages: run-applescript: 5.0.0 dev: true - /bundle-require@4.0.1(esbuild@0.18.14): - resolution: {integrity: sha512-9NQkRHlNdNpDBGmLpngF3EFDcwodhMUuLz9PaWYciVcQF9SE4LFjM2DB/xV1Li5JiuDMv7ZUWuC3rGbqR0MAXQ==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - peerDependencies: - esbuild: '>=0.17' - dependencies: - esbuild: 0.18.14 - load-tsconfig: 0.2.5 - dev: true - /bunyan@1.8.15: resolution: {integrity: sha512-0tECWShh6wUysgucJcBAoYegf3JJoZWibxdqhTm7OHPeT42qdjkZ29QCMcKwbgU1kiH+auSIasNRXMLWXafXig==} engines: {'0': node >=0.10.0} @@ -17547,11 +17524,6 @@ packages: resolution: {integrity: sha512-j8GhLiKmUAh+dsFXlX1aJCbt5KMibuKb+d7j1JaOJG6s2UjX1PQlW+OKB/sD4a/5ZYF4RcmYmLSndOoU3Lt/3g==} dev: false - /joycon@3.1.1: - resolution: {integrity: sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw==} - engines: {node: '>=10'} - dev: true - /js-levenshtein@1.1.6: resolution: {integrity: sha512-X2BB11YZtrRqY4EnQcLX5Rh373zbK4alC1FW7D7MBhL2gtcC17cTnr6DmfHZeS0s2rTHjUTMMHfG7gO8SSdw+g==} engines: {node: '>=0.10.0'} @@ -17910,11 +17882,6 @@ packages: engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} dev: true - /load-tsconfig@0.2.5: - resolution: {integrity: sha512-IXO6OCs9yg8tMKzfPZ1YmheJbZCiEsnBdcB03l0OcfK9prKnJb96siuHCr5Fl37/yo9DnKU+TLpxzTUspw9shg==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - dev: true - /load-yaml-file@0.2.0: resolution: {integrity: sha512-OfCBkGEw4nN6JLtgRidPX6QxjBQGQf72q3si2uvqyFEMbycSFFHwAZeXx6cJgFM9wmLrf9zBwCP3Ivqa+LLZPw==} engines: {node: '>=6'} @@ -17989,10 +17956,6 @@ packages: resolution: {integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==} dev: true - /lodash.sortby@4.7.0: - resolution: {integrity: sha512-HDWXG8isMntAyRF5vZ7xKuEvOhT4AhlRt/3czTSjvGUxjYCBVRQY48ViDHyfYz9VIoBkW4TMGQNapx+l3RUwdA==} - dev: true - /lodash.startcase@4.4.0: resolution: {integrity: sha512-+WKqsK294HMSc2jEbNgpHpd0JfIBhp7rEV4aqXWqFr6AlXov+SlcgB1Fv01y2kGe3Gc8nMW7VA0SrGuSkRfIEg==} dev: true @@ -22511,13 +22474,6 @@ packages: resolution: {integrity: sha512-l3BikUxvPOcn5E74dZiq5BGsTb5yEwhaTSzccU6t4sDOH8NWJCstKO5QT2CvtFoK6F0saL7p9xHAqHOlCPJygA==} engines: {node: '>= 8'} - /source-map@0.8.0-beta.0: - resolution: {integrity: sha512-2ymg6oRBpebeZi9UUNsgQ89bhx01TcTkmNTGnNO88imTmbSgy4nfujrgVEFKWpMTEGA11EDkTt7mqObTPdigIA==} - engines: {node: '>= 8'} - dependencies: - whatwg-url: 7.1.0 - dev: true - /space-separated-tokens@1.1.5: resolution: {integrity: sha512-q/JSVd1Lptzhf5bkYm4ob4iWPjx0KiRe3sRFBNrVqbJkFaBm5vbbowy1mymoPNLRa52+oadOhJ+K49wsSeSjTA==} dev: true @@ -23453,12 +23409,6 @@ packages: resolution: {integrity: sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==} dev: true - /tr46@1.0.1: - resolution: {integrity: sha512-dTpowEjclQ7Kgx5SdBkqRzVhERQXov8/l9Ft9dVM9fmg0W0KQSVaXX9T4i6twCPNtYiZM53lpSSUAwJbFPOHxA==} - dependencies: - punycode: 2.3.0 - dev: true - /tr46@5.0.0: resolution: {integrity: sha512-tk2G5R2KRwBd+ZN0zaEXpmzdKyOYksXwywulIX95MBODjSzMIuQnQ3m8JxgbhnL1LeVo7lqQKsYa1O3Htl7K5g==} engines: {node: '>=18'} @@ -23600,42 +23550,6 @@ packages: /tslib@2.6.2: resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==} - /tsup@7.1.0(ts-node@10.9.1)(typescript@5.1.6): - resolution: {integrity: sha512-mazl/GRAk70j8S43/AbSYXGgvRP54oQeX8Un4iZxzATHt0roW0t6HYDVZIXMw0ZQIpvr1nFMniIVnN5186lW7w==} - engines: {node: '>=16.14'} - hasBin: true - peerDependencies: - '@swc/core': ^1 - postcss: '>=8.4.31' - typescript: '>=4.1.0' - peerDependenciesMeta: - '@swc/core': - optional: true - postcss: - optional: true - typescript: - optional: true - dependencies: - bundle-require: 4.0.1(esbuild@0.18.14) - cac: 6.7.14 - chokidar: 3.5.3 - debug: 4.3.4(supports-color@8.1.1) - esbuild: 0.18.14 - execa: 5.1.1 - globby: 11.1.0 - joycon: 3.1.1 - postcss-load-config: 4.0.1(postcss@8.4.31)(ts-node@10.9.1) - resolve-from: 5.0.0 - rollup: 3.26.3 - source-map: 0.8.0-beta.0 - sucrase: 3.33.0 - tree-kill: 1.2.2 - typescript: 5.1.6 - transitivePeerDependencies: - - supports-color - - ts-node - dev: true - /tsutils@3.21.0(typescript@5.1.6): resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==} engines: {node: '>= 6'} @@ -24861,10 +24775,6 @@ packages: resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==} dev: true - /webidl-conversions@4.0.2: - resolution: {integrity: sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==} - dev: true - /webidl-conversions@7.0.0: resolution: {integrity: sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==} engines: {node: '>=12'} @@ -25066,14 +24976,6 @@ packages: webidl-conversions: 3.0.1 dev: true - /whatwg-url@7.1.0: - resolution: {integrity: sha512-WUu7Rg1DroM7oQvGWfOiAK21n74Gg+T4elXEQYkOhtyLeWiJFoOGLXPKI/9gzIie9CtwVLm8wtw6YJdKyxSjeg==} - dependencies: - lodash.sortby: 4.7.0 - tr46: 1.0.1 - webidl-conversions: 4.0.2 - dev: true - /when@3.7.7: resolution: {integrity: sha512-9lFZp/KHoqH6bPKjbWqa+3Dg/K/r2v0X/3/G2x4DBGchVS2QX2VXL3cZV994WQVnTM1/PD71Az25nAzryEUugw==} dev: true diff --git a/sdk/bcs/package.json b/sdk/bcs/package.json index 45274b0f0a87f..e6e380f8884d6 100644 --- a/sdk/bcs/package.json +++ b/sdk/bcs/package.json @@ -4,28 +4,26 @@ "description": "BCS - Canonical Binary Serialization implementation for JavaScript", "license": "Apache-2.0", "author": "Mysten Labs ", - "main": "./dist/index.js", - "module": "./dist/index.mjs", - "types": "./dist/index.d.ts", "sideEffects": false, + "type": "commonjs", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/cjs/index.d.ts", "exports": { ".": { - "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "require": "./dist/index.js" + "import": "./dist/esm/index.js", + "require": "./dist/cjs/index.js" } }, "files": [ + "CHANGELOG.md", "dist", - "src", - "CHANGELOG.md" + "src" ], "scripts": { "clean": "rm -rf tsconfig.tsbuildinfo ./dist", "dev": "pnpm build --watch", - "build": "pnpm build:types && pnpm build:tsup", - "build:tsup": "tsup ./src/index.ts --format esm,cjs --sourcemap", - "build:types": "tsc --build", + "build": "build-package", "prepublishOnly": "pnpm build", "test": "vitest run", "test:watch": "vitest", @@ -63,9 +61,9 @@ ], "homepage": "https://github.com/mystenlabs/sui#readme", "devDependencies": { + "@mysten/build-scripts": "workspace:*", "@size-limit/preset-small-lib": "^8.2.6", "size-limit": "^8.2.6", - "tsup": "^7.1.0", "typescript": "^5.1.6", "vitest": "^0.33.0" }, diff --git a/sdk/bcs/src/bcs.ts b/sdk/bcs/src/bcs.ts index 0dd87c0eee4bf..38627e0c79517 100644 --- a/sdk/bcs/src/bcs.ts +++ b/sdk/bcs/src/bcs.ts @@ -563,7 +563,7 @@ export const bcs = { * ``` */ generic>( - names: Names, + _names: Names, cb: (...types: { [K in keyof Names]: BcsType> }) => Type, ): }>( ...types: T diff --git a/sdk/bcs/src/legacy-registry.ts b/sdk/bcs/src/legacy-registry.ts index 1b9344769367d..c928ba1f25f03 100644 --- a/sdk/bcs/src/legacy-registry.ts +++ b/sdk/bcs/src/legacy-registry.ts @@ -438,7 +438,7 @@ export class BCS { (param) => new BcsType({ name: String(param), - write: (data, writer) => { + write: (_data, _writer) => { throw new Error('Not implemented'); }, read: (reader) => { diff --git a/sdk/bcs/tsconfig.esm.json b/sdk/bcs/tsconfig.esm.json new file mode 100644 index 0000000000000..5048bdf8ffc62 --- /dev/null +++ b/sdk/bcs/tsconfig.esm.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "ESNext", + "outDir": "dist/esm" + } +} diff --git a/sdk/bcs/tsconfig.json b/sdk/bcs/tsconfig.json index 753ab120715c7..3404b456f4bbd 100644 --- a/sdk/bcs/tsconfig.json +++ b/sdk/bcs/tsconfig.json @@ -1,17 +1,11 @@ { + "extends": "../build-scripts/tsconfig.shared.json", + "include": ["src"], "compilerOptions": { - "target": "ES2020", - "module": "ES2015", - "moduleResolution": "node", - "lib": ["ESNext", "dom"], - "declaration": true, + "module": "CommonJS", + "outDir": "dist/cjs", + "isolatedModules": true, "rootDir": "src", - "outDir": "dist", - "strict": true, - "esModuleInterop": true, - "skipLibCheck": true, - "composite": true, - "isolatedModules": true - }, - "include": ["src"] + "lib": ["ESNext", "dom"] + } } diff --git a/sdk/create-dapp/package.json b/sdk/create-dapp/package.json index 850d8d5d58e10..81b0f92d34846 100644 --- a/sdk/create-dapp/package.json +++ b/sdk/create-dapp/package.json @@ -36,7 +36,6 @@ }, "devDependencies": { "@mysten/build-scripts": "workspace:*", - "tsx": "^3.12.7", "typescript": "^5.1.6" }, "dependencies": { diff --git a/sdk/dapp-kit/package.json b/sdk/dapp-kit/package.json index 23863e87c9f4f..43008d2c9c5ee 100644 --- a/sdk/dapp-kit/package.json +++ b/sdk/dapp-kit/package.json @@ -73,7 +73,6 @@ "react": "^18.2.0", "react-dom": "^18.2.0", "size-limit": "^8.2.6", - "tsx": "^3.12.7", "typescript": "^5.1.6", "vite": "^4.4.4", "vitest": "^0.33.0" diff --git a/sdk/deepbook/package.json b/sdk/deepbook/package.json index acc4bc399c48d..eebe2e9137356 100644 --- a/sdk/deepbook/package.json +++ b/sdk/deepbook/package.json @@ -4,29 +4,27 @@ "description": "Sui Deepbook SDK", "version": "0.5.12", "license": "Apache-2.0", + "type": "commonjs", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/cjs/index.d.ts", + "exports": { + ".": { + "import": "./dist/esm/index.js", + "require": "./dist/cjs/index.js" + } + }, "files": [ + "CHANGELOG.md", "dist", - "src", - "CHANGELOG.md" + "src" ], "engines": { "node": ">=16" }, - "main": "./dist/index.js", - "module": "./dist/index.mjs", - "types": "./dist/index.d.ts", - "exports": { - ".": { - "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "require": "./dist/index.js" - } - }, "scripts": { "clean": "rm -rf tsconfig.tsbuildinfo ./dist", - "build": "pnpm build:types && pnpm build:tsup", - "build:tsup": "tsup ./src/index.ts --format esm,cjs --sourcemap", - "build:types": "tsc --build", + "build": "build-package", "prepublishOnly": "pnpm build", "dev": "ts-node src/deepbook_sdk.ts", "bfs": "ts-node src/bfs.ts", @@ -43,11 +41,11 @@ "@mysten/sui.js": "workspace:*" }, "devDependencies": { + "@mysten/build-scripts": "workspace:*", "@types/node": "^20.4.2", "tmp": "^0.2.1", "ts-node": "^10.9.1", "ts-retry-promise": "^0.7.0", - "tsup": "^7.1.0", "typescript": "^5.1.6", "vite": "^4.4.4", "vitest": "^0.33.0", diff --git a/sdk/deepbook/tsconfig.esm.json b/sdk/deepbook/tsconfig.esm.json new file mode 100644 index 0000000000000..5048bdf8ffc62 --- /dev/null +++ b/sdk/deepbook/tsconfig.esm.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "ESNext", + "outDir": "dist/esm" + } +} diff --git a/sdk/deepbook/tsconfig.json b/sdk/deepbook/tsconfig.json index 4d1b0eacb7112..b4ed52cfe8a5e 100644 --- a/sdk/deepbook/tsconfig.json +++ b/sdk/deepbook/tsconfig.json @@ -1,38 +1,11 @@ { - // see https://www.typescriptlang.org/tsconfig to better understand tsconfigs - "include": ["src", "types"], + "extends": "../build-scripts/tsconfig.shared.json", + "include": ["src"], "compilerOptions": { - "target": "ES2020", - "module": "esnext", - "lib": ["dom", "esnext"], - // output .d.ts declaration files for consumers - "declaration": true, - "emitDeclarationOnly": true, - // output .js.map sourcemap files for consumers - "sourceMap": true, - // match output dir to input dir. e.g. dist/index instead of dist/src/index - "rootDir": "src", - "outDir": "dist", - // stricter type-checking for stronger correctness. Recommended by TS - "strict": true, - // linter checks for common issues - "noImplicitReturns": true, - "noFallthroughCasesInSwitch": true, - // noUnused* overlap with @typescript-eslint/no-unused-vars, can disable if duplicative - "noUnusedLocals": true, - "noUnusedParameters": true, - // use Node's module resolution algorithm, instead of the legacy TS one - "moduleResolution": "node", - // transpile JSX to React.createElement - "jsx": "react", - // interop between ESM and CJS modules. Recommended by TS - "esModuleInterop": true, - // significant perf increase by skipping checking .d.ts files, particularly those in node_modules. Recommended by TS - "skipLibCheck": true, - // error out if import and file system have a casing mismatch. Recommended by TS - "forceConsistentCasingInFileNames": true, - "resolveJsonModule": true, - "composite": true + "module": "CommonJS", + "outDir": "dist/cjs", + "isolatedModules": true, + "rootDir": "src" }, "references": [{ "path": "../typescript" }] } diff --git a/sdk/enoki/package.json b/sdk/enoki/package.json index 2addd37fbbf22..c2afe9e0a1773 100644 --- a/sdk/enoki/package.json +++ b/sdk/enoki/package.json @@ -51,7 +51,6 @@ "@vitejs/plugin-react-swc": "^3.3.2", "react": "^18.2.0", "react-dom": "^18.2.0", - "tsx": "^3.12.7", "typescript": "^5.1.6", "vite": "^4.4.4" }, diff --git a/sdk/kiosk/package.json b/sdk/kiosk/package.json index 27d4187f9c541..ddae81796b185 100644 --- a/sdk/kiosk/package.json +++ b/sdk/kiosk/package.json @@ -4,29 +4,27 @@ "description": "Sui Kiosk library", "version": "0.7.13", "license": "Apache-2.0", - "main": "./dist/index.js", - "module": "./dist/index.mjs", - "types": "./dist/index.d.ts", + "type": "commonjs", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/cjs/index.d.ts", + "exports": { + ".": { + "import": "./dist/esm/index.js", + "require": "./dist/cjs/index.js" + } + }, "sideEffects": false, "files": [ + "CHANGELOG.md", "dist", - "src", - "CHANGELOG.md" + "src" ], "engines": { "node": ">=16" }, - "exports": { - ".": { - "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "require": "./dist/index.js" - } - }, "scripts": { - "build": "pnpm build:types && pnpm build:tsup", - "build:tsup": "tsup ./src/index.ts --format esm,cjs --sourcemap", - "build:types": "tsc --build", + "build": "build-package", "test": "echo 'No unit tests for kiosk SDK'", "pre-commit": "pnpm prettier:fix && pnpm lint && pnpm build", "prepublishOnly": "pnpm build", @@ -43,10 +41,10 @@ "@mysten/sui.js": "workspace:*" }, "devDependencies": { + "@mysten/build-scripts": "workspace:*", "cross-env": "^7.0.3", "tmp": "^0.2.1", "ts-retry-promise": "^0.7.0", - "tsup": "^7.1.0", "typescript": "^5.1.6", "vite": "^4.4.4", "vitest": "^0.33.0", diff --git a/sdk/kiosk/tsconfig.esm.json b/sdk/kiosk/tsconfig.esm.json new file mode 100644 index 0000000000000..5048bdf8ffc62 --- /dev/null +++ b/sdk/kiosk/tsconfig.esm.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "ESNext", + "outDir": "dist/esm" + } +} diff --git a/sdk/kiosk/tsconfig.json b/sdk/kiosk/tsconfig.json index 2e45f40277009..b4ed52cfe8a5e 100644 --- a/sdk/kiosk/tsconfig.json +++ b/sdk/kiosk/tsconfig.json @@ -1,26 +1,11 @@ { - "include": ["src", "types"], + "extends": "../build-scripts/tsconfig.shared.json", + "include": ["src"], "compilerOptions": { - "target": "ES2020", - "module": "esnext", - "lib": ["dom", "esnext"], - "declaration": true, - "emitDeclarationOnly": true, - "sourceMap": true, - "rootDir": "src", - "outDir": "dist", - "strict": true, - "noImplicitReturns": true, - "noFallthroughCasesInSwitch": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "moduleResolution": "node", - "jsx": "react", - "esModuleInterop": true, - "skipLibCheck": true, - "forceConsistentCasingInFileNames": true, - "resolveJsonModule": true, - "composite": true + "module": "CommonJS", + "outDir": "dist/cjs", + "isolatedModules": true, + "rootDir": "src" }, "references": [{ "path": "../typescript" }] } diff --git a/sdk/ledgerjs-hw-app-sui/package.json b/sdk/ledgerjs-hw-app-sui/package.json index ffc80a786d0dc..6610d863dd95f 100644 --- a/sdk/ledgerjs-hw-app-sui/package.json +++ b/sdk/ledgerjs-hw-app-sui/package.json @@ -24,13 +24,20 @@ }, "homepage": "https://github.com/MystenLabs/sui/sdk/ledgerjs-hw-app-sui/#readme", "files": [ + "CHANGELOG.md", "dist", - "src", - "CHANGELOG.md" + "src" ], - "main": "dist/Sui.js", - "module": "dist/Sui.mjs", - "types": "dist/Sui.d.ts", + "type": "commonjs", + "main": "./dist/cjs/Sui.js", + "module": "./dist/esm/Sui.js", + "types": "./dist/cjs/Sui.d.ts", + "exports": { + ".": { + "import": "./dist/esm/Sui.js", + "require": "./dist/cjs/Sui.js" + } + }, "size-limit": [ { "path": "dist/Sui.js", @@ -40,8 +47,7 @@ "scripts": { "analyze": "size-limit", "clean": "rm -rf tsconfig.tsbuildinfo ./dist", - "build": "pnpm build:types && tsup ./src/Sui.ts --format esm,cjs --sourcemap", - "build:types": "tsc --build", + "build": "build-package", "eslint:check": "eslint --max-warnings=0 .", "eslint:fix": "pnpm run eslint:check --fix", "lint": "pnpm run eslint:check && pnpm run prettier:check", @@ -62,10 +68,10 @@ }, "devDependencies": { "@ledgerhq/hw-transport-mocker": "^6.27.13", + "@mysten/build-scripts": "workspace:*", "@size-limit/preset-small-lib": "^8.2.6", "@types/node": "^20.4.2", "size-limit": "^8.2.6", - "tsup": "^7.1.0", "typescript": "^5.1.6", "vitest": "^0.33.0" } diff --git a/sdk/ledgerjs-hw-app-sui/tsconfig.esm.json b/sdk/ledgerjs-hw-app-sui/tsconfig.esm.json new file mode 100644 index 0000000000000..5048bdf8ffc62 --- /dev/null +++ b/sdk/ledgerjs-hw-app-sui/tsconfig.esm.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "ESNext", + "outDir": "dist/esm" + } +} diff --git a/sdk/ledgerjs-hw-app-sui/tsconfig.json b/sdk/ledgerjs-hw-app-sui/tsconfig.json index f9c9592ac883d..b4ed52cfe8a5e 100644 --- a/sdk/ledgerjs-hw-app-sui/tsconfig.json +++ b/sdk/ledgerjs-hw-app-sui/tsconfig.json @@ -1,19 +1,11 @@ { + "extends": "../build-scripts/tsconfig.shared.json", + "include": ["src"], "compilerOptions": { - "target": "ES2020", - "module": "ES2015", - "moduleResolution": "node", - "lib": ["ESNext", "dom"], - "rootDir": "src", - "outDir": "dist", - "declaration": true, - "emitDeclarationOnly": true, - "strict": true, - "esModuleInterop": true, - "skipLibCheck": true, - "forceConsistentCasingInFileNames": true, - "composite": true, - "sourceMap": true + "module": "CommonJS", + "outDir": "dist/cjs", + "isolatedModules": true, + "rootDir": "src" }, - "include": ["src"] + "references": [{ "path": "../typescript" }] } diff --git a/sdk/move-binary-format-wasm/package.json b/sdk/move-binary-format-wasm/package.json index 26cc5289c0439..6cffd67b1fd5b 100644 --- a/sdk/move-binary-format-wasm/package.json +++ b/sdk/move-binary-format-wasm/package.json @@ -1,21 +1,21 @@ { - "name": "move-binary-format-tests", - "version": "0.1.0", - "description": "Move Binary Format implementation in WASM", - "type": "module", - "private": true, - "scripts": { - "build": "wasm-pack build --target nodejs --scope mysten", - "build:dev": "wasm-pack build --target nodejs --debug --scope mysten", - "build:release": "wasm-pack build --target web --release --scope mysten", - "test": "vitest run" - }, - "author": "Mysten Labs ", - "license": "Apache-2.0", - "devDependencies": { - "tsup": "^7.1.0", - "typescript": "^5.1.6", - "vitest": "^0.33.0", - "wasm-pack": "^0.12.1" - } + "name": "move-binary-format-tests", + "version": "0.1.0", + "description": "Move Binary Format implementation in WASM", + "type": "module", + "private": true, + "scripts": { + "build": "wasm-pack build --target nodejs --scope mysten", + "build:dev": "wasm-pack build --target nodejs --debug --scope mysten", + "build:release": "wasm-pack build --target web --release --scope mysten", + "test": "vitest run" + }, + "author": "Mysten Labs ", + "license": "Apache-2.0", + "devDependencies": { + "@mysten/build-scripts": "workspace:*", + "typescript": "^5.1.6", + "vitest": "^0.33.0", + "wasm-pack": "^0.12.1" + } } diff --git a/sdk/move-binary-format-wasm/tsconfig.esm.json b/sdk/move-binary-format-wasm/tsconfig.esm.json new file mode 100644 index 0000000000000..5048bdf8ffc62 --- /dev/null +++ b/sdk/move-binary-format-wasm/tsconfig.esm.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "ESNext", + "outDir": "dist/esm" + } +} diff --git a/sdk/suins-toolkit/.prettierrc.json b/sdk/suins-toolkit/.prettierrc.json deleted file mode 100644 index e41c1fc3041e6..0000000000000 --- a/sdk/suins-toolkit/.prettierrc.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "printWidth": 100, - "semi": true, - "singleQuote": true, - "tabWidth": 4, - "trailingComma": "all" -} diff --git a/sdk/suins-toolkit/README.md b/sdk/suins-toolkit/README.md index 04bf8f3c92c71..998c5e7dcd51e 100644 --- a/sdk/suins-toolkit/README.md +++ b/sdk/suins-toolkit/README.md @@ -1,10 +1,13 @@ # SuiNS TypeScript SDK -This is a lightweight SDK (1kB minified bundle size), providing utility classes and functions for applications to interact with on-chain `.sui` names registered from [Sui Name Service (suins.io)](https://suins.io). +This is a lightweight SDK (1kB minified bundle size), providing utility classes and functions for +applications to interact with on-chain `.sui` names registered from +[Sui Name Service (suins.io)](https://suins.io). ## Getting started -The SDK is published to [npm registry](https://www.npmjs.com/package/@mysten/suins-toolkit). To use it in your project: +The SDK is published to [npm registry](https://www.npmjs.com/package/@mysten/suins-toolkit). To use +it in your project: ```bash $ npm install @mysten/suins-toolkit @@ -28,11 +31,13 @@ Choose network type: ```typescript export const suinsClient = new SuinsClient(client, { - networkType: 'testnet', + networkType: 'testnet', }); ``` -> **Note:** To ensure best performance, please make sure to create only one instance of the SuinsClient class in your application. Then, import the created `suinsClient` instance to use its functions. +> **Note:** To ensure best performance, please make sure to create only one instance of the +> SuinsClient class in your application. Then, import the created `suinsClient` instance to use its +> functions. Fetch an address linked to a name: @@ -44,7 +49,7 @@ Fetch the default name of an address: ```typescript const defaultName = await suinsClient.getName( - '0xc2f08b6490b87610629673e76bab7e821fe8589c7ea6e752ea5dac2a4d371b41', + '0xc2f08b6490b87610629673e76bab7e821fe8589c7ea6e752ea5dac2a4d371b41', ); ``` @@ -58,7 +63,7 @@ Fetch a name object including the owner: ```typescript const nameObject = await suinsClient.getNameObject('suins.sui', { - showOwner: true, + showOwner: true, }); ``` @@ -66,8 +71,8 @@ Fetch a name object including the Avatar the owner has set (it automatically inc ```typescript const nameObject = await suinsClient.getNameObject('suins.sui', { - showOwner: true, // this can be skipped as showAvatar includes it by default - showAvatar: true, + showOwner: true, // this can be skipped as showAvatar includes it by default + showAvatar: true, }); ``` diff --git a/sdk/suins-toolkit/package.json b/sdk/suins-toolkit/package.json index 5daba5f0ff369..0b6cd23a358b3 100644 --- a/sdk/suins-toolkit/package.json +++ b/sdk/suins-toolkit/package.json @@ -1,50 +1,47 @@ { - "name": "@mysten/suins-toolkit", - "author": "Mysten Labs ", - "description": "SuiNS TypeScript SDK", - "version": "0.3.18", - "license": "Apache-2.0", - "files": [ - "dist", - "src", - "CHANGELOG.md" - ], - "engines": { - "node": ">=16" - }, - "main": "./dist/index.js", - "module": "./dist/index.mjs", - "types": "./dist/index.d.ts", - "exports": { - ".": { - "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "require": "./dist/index.js" - } - }, - "scripts": { - "clean": "rm -rf tsconfig.tsbuildinfo ./dist", - "dev": "pnpm build:tsup --watch", - "build": "pnpm build:types && pnpm build:tsup", - "build:tsup": "tsup ./src/index.ts --format esm,cjs --sourcemap", - "build:types": "tsc --build", - "prepublishOnly": "pnpm build", - "test": "vitest", - "prettier:check": "prettier -c --ignore-unknown .", - "prettier:fix": "prettier -w --ignore-unknown .", - "eslint:check": "eslint --max-warnings=0 .", - "eslint:fix": "pnpm run eslint:check --fix", - "lint": "pnpm run eslint:check && pnpm run prettier:check", - "lint:fix": "pnpm run eslint:fix && pnpm run prettier:fix" - }, - "devDependencies": { - "@faker-js/faker": "^8.0.2", - "ts-node": "^10.9.1", - "tsup": "^7.1.0", - "typescript": "^5.1.6", - "vitest": "^0.33.0" - }, - "dependencies": { - "@mysten/sui.js": "workspace:*" - } + "name": "@mysten/suins-toolkit", + "author": "Mysten Labs ", + "description": "SuiNS TypeScript SDK", + "version": "0.3.18", + "license": "Apache-2.0", + "type": "commonjs", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/cjs/index.d.ts", + "exports": { + ".": { + "import": "./dist/esm/index.js", + "require": "./dist/cjs/index.js" + } + }, + "files": [ + "CHANGELOG.md", + "dist", + "src" + ], + "engines": { + "node": ">=16" + }, + "scripts": { + "clean": "rm -rf tsconfig.tsbuildinfo ./dist", + "build": "build-package", + "prepublishOnly": "pnpm build", + "test": "vitest", + "prettier:check": "prettier -c --ignore-unknown .", + "prettier:fix": "prettier -w --ignore-unknown .", + "eslint:check": "eslint --max-warnings=0 .", + "eslint:fix": "pnpm run eslint:check --fix", + "lint": "pnpm run eslint:check && pnpm run prettier:check", + "lint:fix": "pnpm run eslint:fix && pnpm run prettier:fix" + }, + "devDependencies": { + "@faker-js/faker": "^8.0.2", + "@mysten/build-scripts": "workspace:*", + "ts-node": "^10.9.1", + "typescript": "^5.1.6", + "vitest": "^0.33.0" + }, + "dependencies": { + "@mysten/sui.js": "workspace:*" + } } diff --git a/sdk/suins-toolkit/src/client.ts b/sdk/suins-toolkit/src/client.ts index a658a4154ed4d..19c634ac54ca3 100644 --- a/sdk/suins-toolkit/src/client.ts +++ b/sdk/suins-toolkit/src/client.ts @@ -3,7 +3,7 @@ import { SuiClient } from '@mysten/sui.js/client'; -import { DataFields, NetworkType, NameObject, SuiNSContract } from './types/objects'; +import { DataFields, NameObject, NetworkType, SuiNSContract } from './types/objects'; import { DEVNET_JSON_FILE, GCS_URL, TESTNET_JSON_FILE } from './utils/constants'; import { camelCase, parseObjectDataResponse, parseRegistryResponse } from './utils/parser'; import { getAvatar, getOwner } from './utils/queries'; @@ -11,188 +11,186 @@ import { getAvatar, getOwner } from './utils/queries'; export const AVATAR_NOT_OWNED = 'AVATAR_NOT_OWNED'; class SuinsClient { - private suiClient: SuiClient; - contractObjects: SuiNSContract | undefined; - networkType: NetworkType | undefined; - - constructor( - suiClient: SuiClient, - options?: { - contractObjects?: SuiNSContract; - networkType?: NetworkType; - }, - ) { - if (!suiClient) { - throw new Error('SuiClient must be specified.'); - } - this.suiClient = suiClient; - this.contractObjects = options?.contractObjects; - this.networkType = options?.networkType; - } - - async getSuinsContractObjects() { - if ((this.contractObjects as SuiNSContract)?.packageId) return; - - const contractJsonFileUrl = - GCS_URL + (this.networkType === 'testnet' ? TESTNET_JSON_FILE : DEVNET_JSON_FILE); - - let response; - try { - response = await fetch(contractJsonFileUrl); - } catch (error) { - throw new Error(`Error getting SuiNS contract objects, ${(error as Error).message}`); - } - - if (!response?.ok) { - throw new Error(`Network Error: ${response?.status}`); - } - - this.contractObjects = await response.json(); - } - - protected async getDynamicFieldObject( - parentObjectId: string, - key: unknown, - type = '0x1::string::String', - ) { - const dynamicFieldObject = await this.suiClient.getDynamicFieldObject({ - parentId: parentObjectId, - name: { - type: type, - value: key, - }, - }); - - if (dynamicFieldObject.error?.code === 'dynamicFieldNotFound') return; - - return dynamicFieldObject; - } - - protected async getNameData(dataObjectId: string, fields: DataFields[] = []) { - if (!dataObjectId) return {}; - - const { data: dynamicFields } = await this.suiClient.getDynamicFields({ - parentId: dataObjectId, - }); - - const filteredFields = new Set(fields); - const filteredDynamicFields = dynamicFields.filter(({ name: { value } }) => - filteredFields.has(value as DataFields), - ); - - const data = await Promise.allSettled( - filteredDynamicFields?.map(({ objectId }) => - this.suiClient - .getObject({ - id: objectId, - options: { showContent: true }, - }) - .then(parseObjectDataResponse) - .then((object) => [camelCase(object.name), object.value]), - ) ?? [], - ); - - const fulfilledData = data.filter( - (e) => e.status === 'fulfilled', - ) as PromiseFulfilledResult<[string, unknown]>[]; - - return Object.fromEntries(fulfilledData.map((e) => e.value)); - } - - /** - * Returns the name object data including: - * - * - id: the name object address - * - owner: the owner address // only if you add the `showOwner` parameter. It includes an extra RPC call. - * - targetAddress: the linked address - * - avatar?: the custom avatar id // Only if you add showAvatar parameter. It includes an extra RPC call. - * - contentHash?: the ipfs cid - * - * If the input domain has not been registered, it will return an empty object. - * If `showAvatar` is included, the owner will be fetched as well. - * - * @param key a domain name - */ - async getNameObject( - name: string, - options: { showOwner?: boolean; showAvatar?: boolean } | undefined = { - showOwner: false, - showAvatar: false, - }, - ): Promise { - const [, domain, topLevelDomain] = name.match(/^(.+)\.([^.]+)$/) || []; - await this.getSuinsContractObjects(); - - const registryResponse = await this.getDynamicFieldObject( - (this.contractObjects as SuiNSContract).registry, - [topLevelDomain, domain], - `${this.contractObjects?.packageId}::domain::Domain`, - ); - - const nameObject = parseRegistryResponse(registryResponse); - - // check if we should also query for avatar. - // we can only query if the object has an avatar set - // and the query includes avatar. - const includeAvatar = nameObject.avatar && options?.showAvatar; - - // IF we have showOwner or includeAvatar flag, we fetch the owner &/or avatar, - // We use Promise.all to do these calls at the same time. - if (nameObject.nftId && (includeAvatar || options?.showOwner)) { - const [owner, avatarNft] = await Promise.all([ - getOwner(this.suiClient, nameObject.nftId), - includeAvatar - ? getAvatar(this.suiClient, nameObject.avatar) - : Promise.resolve(null), - ]); - - nameObject.owner = owner; - - // Parse avatar NFT, check ownership and fixup the request response. - if (includeAvatar && avatarNft) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore-next-line - if (avatarNft.data?.owner?.AddressOwner === nameObject.owner) { - const display = avatarNft.data?.display; - nameObject.avatar = display?.data?.image_url || null; - } else { - nameObject.avatar = AVATAR_NOT_OWNED; - } - } else { - delete nameObject.avatar; - } - } - - return nameObject; - } - - /** - * Returns the linked address of the input domain if the link was set. Otherwise, it will return undefined. - * - * @param domain a domain name ends with `.sui` - */ - async getAddress(domain: string): Promise { - const { targetAddress } = await this.getNameObject(domain); - - return targetAddress; - } - - /** - * Returns the default name of the input address if it was set. Otherwise, it will return undefined. - * - * @param address a Sui address. - */ - async getName(address: string): Promise { - const res = await this.getDynamicFieldObject( - this.contractObjects?.reverseRegistry ?? '', - address, - 'address', - ); - const data = parseObjectDataResponse(res); - const labels = data?.value?.fields?.labels; - - return Array.isArray(labels) ? labels.reverse()?.join('.') : undefined; - } + private suiClient: SuiClient; + contractObjects: SuiNSContract | undefined; + networkType: NetworkType | undefined; + + constructor( + suiClient: SuiClient, + options?: { + contractObjects?: SuiNSContract; + networkType?: NetworkType; + }, + ) { + if (!suiClient) { + throw new Error('SuiClient must be specified.'); + } + this.suiClient = suiClient; + this.contractObjects = options?.contractObjects; + this.networkType = options?.networkType; + } + + async getSuinsContractObjects() { + if ((this.contractObjects as SuiNSContract)?.packageId) return; + + const contractJsonFileUrl = + GCS_URL + (this.networkType === 'testnet' ? TESTNET_JSON_FILE : DEVNET_JSON_FILE); + + let response; + try { + response = await fetch(contractJsonFileUrl); + } catch (error) { + throw new Error(`Error getting SuiNS contract objects, ${(error as Error).message}`); + } + + if (!response?.ok) { + throw new Error(`Network Error: ${response?.status}`); + } + + this.contractObjects = await response.json(); + } + + protected async getDynamicFieldObject( + parentObjectId: string, + key: unknown, + type = '0x1::string::String', + ) { + const dynamicFieldObject = await this.suiClient.getDynamicFieldObject({ + parentId: parentObjectId, + name: { + type: type, + value: key, + }, + }); + + if (dynamicFieldObject.error?.code === 'dynamicFieldNotFound') return; + + return dynamicFieldObject; + } + + protected async getNameData(dataObjectId: string, fields: DataFields[] = []) { + if (!dataObjectId) return {}; + + const { data: dynamicFields } = await this.suiClient.getDynamicFields({ + parentId: dataObjectId, + }); + + const filteredFields = new Set(fields); + const filteredDynamicFields = dynamicFields.filter(({ name: { value } }) => + filteredFields.has(value as DataFields), + ); + + const data = await Promise.allSettled( + filteredDynamicFields?.map(({ objectId }) => + this.suiClient + .getObject({ + id: objectId, + options: { showContent: true }, + }) + .then(parseObjectDataResponse) + .then((object) => [camelCase(object.name), object.value]), + ) ?? [], + ); + + const fulfilledData = data.filter((e) => e.status === 'fulfilled') as PromiseFulfilledResult< + [string, unknown] + >[]; + + return Object.fromEntries(fulfilledData.map((e) => e.value)); + } + + /** + * Returns the name object data including: + * + * - id: the name object address + * - owner: the owner address // only if you add the `showOwner` parameter. It includes an extra RPC call. + * - targetAddress: the linked address + * - avatar?: the custom avatar id // Only if you add showAvatar parameter. It includes an extra RPC call. + * - contentHash?: the ipfs cid + * + * If the input domain has not been registered, it will return an empty object. + * If `showAvatar` is included, the owner will be fetched as well. + * + * @param key a domain name + */ + async getNameObject( + name: string, + options: { showOwner?: boolean; showAvatar?: boolean } | undefined = { + showOwner: false, + showAvatar: false, + }, + ): Promise { + const [, domain, topLevelDomain] = name.match(/^(.+)\.([^.]+)$/) || []; + await this.getSuinsContractObjects(); + + const registryResponse = await this.getDynamicFieldObject( + (this.contractObjects as SuiNSContract).registry, + [topLevelDomain, domain], + `${this.contractObjects?.packageId}::domain::Domain`, + ); + + const nameObject = parseRegistryResponse(registryResponse); + + // check if we should also query for avatar. + // we can only query if the object has an avatar set + // and the query includes avatar. + const includeAvatar = nameObject.avatar && options?.showAvatar; + + // IF we have showOwner or includeAvatar flag, we fetch the owner &/or avatar, + // We use Promise.all to do these calls at the same time. + if (nameObject.nftId && (includeAvatar || options?.showOwner)) { + const [owner, avatarNft] = await Promise.all([ + getOwner(this.suiClient, nameObject.nftId), + includeAvatar ? getAvatar(this.suiClient, nameObject.avatar) : Promise.resolve(null), + ]); + + nameObject.owner = owner; + + // Parse avatar NFT, check ownership and fixup the request response. + if (includeAvatar && avatarNft) { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore-next-line + if (avatarNft.data?.owner?.AddressOwner === nameObject.owner) { + const display = avatarNft.data?.display; + nameObject.avatar = display?.data?.image_url || null; + } else { + nameObject.avatar = AVATAR_NOT_OWNED; + } + } else { + delete nameObject.avatar; + } + } + + return nameObject; + } + + /** + * Returns the linked address of the input domain if the link was set. Otherwise, it will return undefined. + * + * @param domain a domain name ends with `.sui` + */ + async getAddress(domain: string): Promise { + const { targetAddress } = await this.getNameObject(domain); + + return targetAddress; + } + + /** + * Returns the default name of the input address if it was set. Otherwise, it will return undefined. + * + * @param address a Sui address. + */ + async getName(address: string): Promise { + const res = await this.getDynamicFieldObject( + this.contractObjects?.reverseRegistry ?? '', + address, + 'address', + ); + const data = parseObjectDataResponse(res); + const labels = data?.value?.fields?.labels; + + return Array.isArray(labels) ? labels.reverse()?.join('.') : undefined; + } } export { SuinsClient }; diff --git a/sdk/suins-toolkit/src/types/objects.ts b/sdk/suins-toolkit/src/types/objects.ts index 3bc4f2a6be81e..9684dc702c0cb 100644 --- a/sdk/suins-toolkit/src/types/objects.ts +++ b/sdk/suins-toolkit/src/types/objects.ts @@ -2,18 +2,18 @@ // SPDX-License-Identifier: Apache-2.0 export type SuiNSContract = { - packageId: string; - suins: string; - registry: string; - reverseRegistry: string; + packageId: string; + suins: string; + registry: string; + reverseRegistry: string; }; export type NameObject = { - id: string; - owner: string; - targetAddress: string; - avatar?: string; - contentHash?: string; + id: string; + owner: string; + targetAddress: string; + avatar?: string; + contentHash?: string; }; export type DataFields = 'avatar' | 'contentHash'; diff --git a/sdk/suins-toolkit/src/utils/parser.ts b/sdk/suins-toolkit/src/utils/parser.ts index b50677e72b946..86ac753335c2e 100644 --- a/sdk/suins-toolkit/src/utils/parser.ts +++ b/sdk/suins-toolkit/src/utils/parser.ts @@ -1,42 +1,40 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -import { SuiObjectResponse, SuiMoveObject, SuiObjectData } from '@mysten/sui.js/client'; +import { SuiMoveObject, SuiObjectData, SuiObjectResponse } from '@mysten/sui.js/client'; import { normalizeSuiAddress } from '@mysten/sui.js/utils'; export const camelCase = (string: string) => string.replace(/(_\w)/g, (g) => g[1].toUpperCase()); export const parseObjectDataResponse = (response: SuiObjectResponse | undefined) => - ((response?.data as SuiObjectData)?.content as SuiMoveObject)?.fields as Record; + ((response?.data as SuiObjectData)?.content as SuiMoveObject)?.fields as Record; export const parseRegistryResponse = (response: SuiObjectResponse | undefined): any => { - const fields = parseObjectDataResponse(response)?.value?.fields || {}; - - const object = Object.fromEntries( - Object.entries({ ...fields }).map(([key, val]) => [camelCase(key), val]), - ); - - if (response?.data?.objectId) { - object.id = response.data.objectId; - } - - delete object.data; - - const data = (fields.data?.fields.contents || []).reduce( - (acc: Record, c: Record) => { - const key = c.fields.key; - const value = c.fields.value; - - return { - ...acc, - [camelCase(key)]: - c.type.includes('Address') || key === 'addr' - ? normalizeSuiAddress(value) - : value, - }; - }, - {}, - ); - - return { ...object, ...data }; + const fields = parseObjectDataResponse(response)?.value?.fields || {}; + + const object = Object.fromEntries( + Object.entries({ ...fields }).map(([key, val]) => [camelCase(key), val]), + ); + + if (response?.data?.objectId) { + object.id = response.data.objectId; + } + + delete object.data; + + const data = (fields.data?.fields.contents || []).reduce( + (acc: Record, c: Record) => { + const key = c.fields.key; + const value = c.fields.value; + + return { + ...acc, + [camelCase(key)]: + c.type.includes('Address') || key === 'addr' ? normalizeSuiAddress(value) : value, + }; + }, + {}, + ); + + return { ...object, ...data }; }; diff --git a/sdk/suins-toolkit/src/utils/queries.ts b/sdk/suins-toolkit/src/utils/queries.ts index bc31e6a8003d2..72568c8876079 100644 --- a/sdk/suins-toolkit/src/utils/queries.ts +++ b/sdk/suins-toolkit/src/utils/queries.ts @@ -1,30 +1,29 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -import { SuiObjectResponse } from '@mysten/sui.js/client'; -import { SuiClient } from '@mysten/sui.js/client'; +import { SuiClient, SuiObjectResponse } from '@mysten/sui.js/client'; // get NFT's owner from RPC. export const getOwner = async (client: SuiClient, nftId: string): Promise => { - const ownerResponse = await client.getObject({ - id: nftId, - options: { showOwner: true }, - }); - const owner = ownerResponse.data?.owner; - return ( - (owner as { AddressOwner: string })?.AddressOwner || - (owner as { ObjectOwner: string })?.ObjectOwner || - null - ); + const ownerResponse = await client.getObject({ + id: nftId, + options: { showOwner: true }, + }); + const owner = ownerResponse.data?.owner; + return ( + (owner as { AddressOwner: string })?.AddressOwner || + (owner as { ObjectOwner: string })?.ObjectOwner || + null + ); }; // get avatar NFT Object from RPC. export const getAvatar = async (client: SuiClient, avatar: string): Promise => { - return await client.getObject({ - id: avatar, - options: { - showDisplay: true, - showOwner: true, - }, - }); + return await client.getObject({ + id: avatar, + options: { + showDisplay: true, + showOwner: true, + }, + }); }; diff --git a/sdk/suins-toolkit/tests/app.test.ts b/sdk/suins-toolkit/tests/app.test.ts index 05b87176281ac..c5a7908514d5f 100644 --- a/sdk/suins-toolkit/tests/app.test.ts +++ b/sdk/suins-toolkit/tests/app.test.ts @@ -2,88 +2,88 @@ // SPDX-License-Identifier: Apache-2.0 // import { faker } from '@faker-js/faker'; -import { describe, beforeEach, expect, it } from 'vitest'; +import { getFullnodeUrl, SuiClient } from '@mysten/sui.js/client'; +import { beforeEach, describe, expect, it } from 'vitest'; import { SuinsClient } from '../src'; -import { getFullnodeUrl, SuiClient } from '@mysten/sui.js/client'; const domainName = 'test.sui'; const walletAddress = '0xfce343a643991c592c4f1a9ee415a7889293f694ab8828f78e3c81d11c9530c6'; describe('SuiNS Client', () => { - const client = new SuinsClient(new SuiClient({ url: getFullnodeUrl('testnet') }), { - networkType: 'testnet', - contractObjects: { - packageId: '0xfdba31b34a43e058f17c5cf4b12d9b9e0a08c0623d8569092c022e0c77df46d3', - registry: '0xac06695279c2a92436068cebe5ea778135ac503337642e27493431603ae6a71d', - reverseRegistry: '0x34a36dd204f8351a157d19b87bada9d448ec40229d56f22bff04fa23713a5c31', - suins: '0x4acaf19db12fafce1943bbd44c7f794e1d81d00aeb63617096e5caa39499ba88', - }, - }); + const client = new SuinsClient(new SuiClient({ url: getFullnodeUrl('testnet') }), { + networkType: 'testnet', + contractObjects: { + packageId: '0xfdba31b34a43e058f17c5cf4b12d9b9e0a08c0623d8569092c022e0c77df46d3', + registry: '0xac06695279c2a92436068cebe5ea778135ac503337642e27493431603ae6a71d', + reverseRegistry: '0x34a36dd204f8351a157d19b87bada9d448ec40229d56f22bff04fa23713a5c31', + suins: '0x4acaf19db12fafce1943bbd44c7f794e1d81d00aeb63617096e5caa39499ba88', + }, + }); - const nonExistingDomain = walletAddress + '.sui'; - const nonExistingWalletAddress = walletAddress.substring(0, walletAddress.length - 4) + '0000'; + const nonExistingDomain = walletAddress + '.sui'; + const nonExistingWalletAddress = walletAddress.substring(0, walletAddress.length - 4) + '0000'; - beforeEach(async () => { - await client.getSuinsContractObjects(); - }); + beforeEach(async () => { + await client.getSuinsContractObjects(); + }); - describe('getAddress', () => { - describe('input domain has a linked address set', () => { - it('returns the linked address', async () => { - expect(await client.getAddress(domainName)).toEqual(walletAddress); - }); - }); + describe('getAddress', () => { + describe('input domain has a linked address set', () => { + it('returns the linked address', async () => { + expect(await client.getAddress(domainName)).toEqual(walletAddress); + }); + }); - describe('input domain does not have a linked address set', () => { - it('returns undefined', async () => { - expect(await client.getAddress(nonExistingDomain)).toBeUndefined(); - }); - }); - }); + describe('input domain does not have a linked address set', () => { + it('returns undefined', async () => { + expect(await client.getAddress(nonExistingDomain)).toBeUndefined(); + }); + }); + }); - describe('getName', () => { - describe('input domain has a default name set', () => { - it('returns the default name', async () => { - expect(await client.getName(walletAddress)).toBe(domainName); - }); - }); + describe('getName', () => { + describe('input domain has a default name set', () => { + it('returns the default name', async () => { + expect(await client.getName(walletAddress)).toBe(domainName); + }); + }); - describe('input domain does not have a default name set', () => { - it('returns undefined', async () => { - expect(await client.getName(nonExistingWalletAddress)).toBeUndefined(); - }); - }); - }); + describe('input domain does not have a default name set', () => { + it('returns undefined', async () => { + expect(await client.getName(nonExistingWalletAddress)).toBeUndefined(); + }); + }); + }); - describe('getNameObject', () => { - it('returns related data of the name', async () => { - expect( - await client.getNameObject(domainName, { - showOwner: true, - showAvatar: true, - }), - ).toMatchObject({ - id: '0x7ee9ac31830e91f76f149952f7544b6d007b9a5520815e3d30264fa3d2791ad1', - nftId: '0x2879ff9464f06c0779ca34eec6138459a3e9855852dd5d1a025164c344b2b555', - expirationTimestampMs: '1715765005617', - owner: walletAddress, - targetAddress: walletAddress, - // avatar: 'https://api-testnet.suifrens.sui.io/suifrens/0x4e3ba002444df6c6774f41833f881d351533728d585343c58cca1fec1fef74ef/svg', - contentHash: 'QmZsHKQk9FbQZYCy7rMYn1z6m9Raa183dNhpGCRm3fX71s', - }); - }); + describe('getNameObject', () => { + it('returns related data of the name', async () => { + expect( + await client.getNameObject(domainName, { + showOwner: true, + showAvatar: true, + }), + ).toMatchObject({ + id: '0x7ee9ac31830e91f76f149952f7544b6d007b9a5520815e3d30264fa3d2791ad1', + nftId: '0x2879ff9464f06c0779ca34eec6138459a3e9855852dd5d1a025164c344b2b555', + expirationTimestampMs: '1715765005617', + owner: walletAddress, + targetAddress: walletAddress, + // avatar: 'https://api-testnet.suifrens.sui.io/suifrens/0x4e3ba002444df6c6774f41833f881d351533728d585343c58cca1fec1fef74ef/svg', + contentHash: 'QmZsHKQk9FbQZYCy7rMYn1z6m9Raa183dNhpGCRm3fX71s', + }); + }); - it('Does not include avatar if the flag is off', async () => { - expect( - await client.getNameObject(domainName, { - showOwner: true, - }), - ).not.toHaveProperty('avatar'); - }); + it('Does not include avatar if the flag is off', async () => { + expect( + await client.getNameObject(domainName, { + showOwner: true, + }), + ).not.toHaveProperty('avatar'); + }); - it('Does not include owner if the flag is off', async () => { - expect(await client.getNameObject(domainName)).not.toHaveProperty('owner'); - }); - }); + it('Does not include owner if the flag is off', async () => { + expect(await client.getNameObject(domainName)).not.toHaveProperty('owner'); + }); + }); }); diff --git a/sdk/suins-toolkit/tsconfig.esm.json b/sdk/suins-toolkit/tsconfig.esm.json new file mode 100644 index 0000000000000..5048bdf8ffc62 --- /dev/null +++ b/sdk/suins-toolkit/tsconfig.esm.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "ESNext", + "outDir": "dist/esm" + } +} diff --git a/sdk/suins-toolkit/tsconfig.json b/sdk/suins-toolkit/tsconfig.json index 386efc427f817..b4ed52cfe8a5e 100644 --- a/sdk/suins-toolkit/tsconfig.json +++ b/sdk/suins-toolkit/tsconfig.json @@ -1,38 +1,11 @@ { - // see https://www.typescriptlang.org/tsconfig to better understand tsconfigs - "include": ["src"], - "compilerOptions": { - "target": "ES2020", - "module": "esnext", - "lib": ["dom", "esnext"], - // output .d.ts declaration files for consumers - "declaration": true, - "emitDeclarationOnly": true, - // output .js.map sourcemap files for consumers - "sourceMap": true, - // match output dir to input dir. e.g. dist/index instead of dist/src/index - "rootDir": "src", - "outDir": "dist", - // stricter type-checking for stronger correctness. Recommended by TS - "strict": true, - // linter checks for common issues - "noImplicitReturns": true, - "noFallthroughCasesInSwitch": true, - // noUnused* overlap with @typescript-eslint/no-unused-vars, can disable if duplicative - "noUnusedLocals": true, - "noUnusedParameters": true, - // use Node's module resolution algorithm, instead of the legacy TS one - "moduleResolution": "node", - // transpile JSX to React.createElement - "jsx": "react", - // interop between ESM and CJS modules. Recommended by TS - "esModuleInterop": true, - // significant perf increase by skipping checking .d.ts files, particularly those in node_modules. Recommended by TS - "skipLibCheck": true, - // error out if import and file system have a casing mismatch. Recommended by TS - "forceConsistentCasingInFileNames": true, - "resolveJsonModule": true, - "composite": true - }, - "references": [{ "path": "../typescript" }] + "extends": "../build-scripts/tsconfig.shared.json", + "include": ["src"], + "compilerOptions": { + "module": "CommonJS", + "outDir": "dist/cjs", + "isolatedModules": true, + "rootDir": "src" + }, + "references": [{ "path": "../typescript" }] } diff --git a/sdk/suins-toolkit/vitest.config.ts b/sdk/suins-toolkit/vitest.config.ts index 47b9eac9b9759..ddc633cfd5df5 100644 --- a/sdk/suins-toolkit/vitest.config.ts +++ b/sdk/suins-toolkit/vitest.config.ts @@ -4,16 +4,16 @@ import { defineConfig } from 'vitest/config'; export default defineConfig({ - test: { - minThreads: 1, - maxThreads: 8, - hookTimeout: 1000000, - testTimeout: 1000000, - }, - resolve: { - alias: { - '@mysten/bcs': new URL('../bcs/src', import.meta.url).toString(), - '@mysten/sui.js': new URL('../typescript/src', import.meta.url).toString(), - }, - }, + test: { + minThreads: 1, + maxThreads: 8, + hookTimeout: 1000000, + testTimeout: 1000000, + }, + resolve: { + alias: { + '@mysten/bcs': new URL('../bcs/src', import.meta.url).toString(), + '@mysten/sui.js': new URL('../typescript/src', import.meta.url).toString(), + }, + }, }); diff --git a/sdk/typescript/package.json b/sdk/typescript/package.json index 79b3794e0e9f3..84c056f9a57dd 100644 --- a/sdk/typescript/package.json +++ b/sdk/typescript/package.json @@ -117,7 +117,6 @@ "msw": "^1.2.2", "tmp": "^0.2.1", "ts-retry-promise": "^0.7.0", - "tsx": "^3.12.7", "typedoc": "^0.24.8", "typescript": "^5.1.6", "vite": "^4.4.4", diff --git a/sdk/wallet-standard/package.json b/sdk/wallet-standard/package.json index bba66c23a986b..6099655d73209 100644 --- a/sdk/wallet-standard/package.json +++ b/sdk/wallet-standard/package.json @@ -4,28 +4,25 @@ "description": "A suite of standard utilities for implementing wallets based on the Wallet Standard.", "license": "Apache-2.0", "author": "Mysten Labs ", - "main": "./dist/index.js", - "module": "./dist/index.mjs", - "types": "./dist/index.d.ts", + "type": "commonjs", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/cjs/index.d.ts", "exports": { ".": { - "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "require": "./dist/index.js" + "import": "./dist/esm/index.js", + "require": "./dist/cjs/index.js" } }, "sideEffects": false, "files": [ + "CHANGELOG.md", "dist", - "src", - "CHANGELOG.md" + "src" ], "scripts": { "clean": "rm -rf tsconfig.tsbuildinfo ./dist", - "dev": "pnpm build --watch", - "build": "pnpm build:types && pnpm build:tsup", - "build:tsup": "tsup ./src/index.ts --format esm,cjs --sourcemap", - "build:types": "tsc --build", + "build": "build-package", "prepublishOnly": "pnpm build", "prettier:check": "prettier -c --ignore-unknown .", "prettier:fix": "prettier -w --ignore-unknown .", @@ -39,7 +36,7 @@ "@wallet-standard/core": "1.0.3" }, "devDependencies": { - "tsup": "^7.1.0", + "@mysten/build-scripts": "workspace:*", "typescript": "^5.1.6" } } diff --git a/sdk/wallet-standard/tsconfig.esm.json b/sdk/wallet-standard/tsconfig.esm.json new file mode 100644 index 0000000000000..5048bdf8ffc62 --- /dev/null +++ b/sdk/wallet-standard/tsconfig.esm.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "ESNext", + "outDir": "dist/esm" + } +} diff --git a/sdk/wallet-standard/tsconfig.json b/sdk/wallet-standard/tsconfig.json index 844c5e9927e2d..f502851efda48 100644 --- a/sdk/wallet-standard/tsconfig.json +++ b/sdk/wallet-standard/tsconfig.json @@ -1,26 +1,12 @@ { + "extends": "../build-scripts/tsconfig.shared.json", "include": ["src"], "compilerOptions": { - "target": "ES2020", + "module": "CommonJS", + "outDir": "dist/cjs", "lib": ["dom", "dom.iterable", "esnext"], - "allowJs": true, - "skipLibCheck": true, - "esModuleInterop": true, - "allowSyntheticDefaultImports": true, - "strict": true, - "forceConsistentCasingInFileNames": true, - "noFallthroughCasesInSwitch": true, - "module": "esnext", - "moduleResolution": "node", - "resolveJsonModule": false, "isolatedModules": true, - "jsx": "react-jsx", - "composite": true, - "declaration": true, - "emitDeclarationOnly": true, - "outDir": "dist", - "rootDir": "src", - "baseUrl": "." + "rootDir": "src" }, "references": [{ "path": "../typescript" }] } diff --git a/sdk/zklogin/package.json b/sdk/zklogin/package.json index b3bb1903fef0a..f4021404dd88d 100644 --- a/sdk/zklogin/package.json +++ b/sdk/zklogin/package.json @@ -43,7 +43,6 @@ "devDependencies": { "@mysten/build-scripts": "workspace:*", "@types/node": "^20.4.2", - "tsx": "^3.12.7", "typescript": "^5.1.6", "vitest": "^0.33.0" }, diff --git a/sdk/zksend/package.json b/sdk/zksend/package.json index de1414cb9b2db..b740c2203ebbe 100644 --- a/sdk/zksend/package.json +++ b/sdk/zksend/package.json @@ -42,7 +42,6 @@ "devDependencies": { "@mysten/build-scripts": "workspace:*", "@types/node": "^20.4.2", - "tsx": "^3.12.7", "typescript": "^5.1.6", "vitest": "^0.33.0" },