From 55e21e81741755d3022227502ca5c5bd02bb6a86 Mon Sep 17 00:00:00 2001 From: Dev-AdeTutu <2.74891498e+08+Dev-AdeTutu@users.noreply.github.com> Date: Wed, 21 Oct 2026 06:34:10 +0000 Subject: [PATCH] fix: tighten SDK type and package boundaries --- package-lock.json | 4 ++-- package.json | 10 +++++----- scripts/validate-exports.js | 6 +++++- src/shared/index.ts | 8 +++++++- src/shared/public.ts | 35 +++++++++++++++++++++++++++++++++++ tsconfig.json | 7 +++++++ tsup.config.ts | 1 + 7 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 src/shared/public.ts diff --git a/package-lock.json b/package-lock.json index 4cdaed82..da1054cd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "smol-toml": "^1.9.0" }, "devDependencies": { - "@stellar/stellar-sdk": "^13.3.0", + "@stellar/stellar-sdk": "13.3.0", "@types/node": "^20.0.0", "@typescript-eslint/eslint-plugin": "^8.70.1", "@typescript-eslint/parser": "^8.65.0", @@ -31,7 +31,7 @@ }, "peerDependencies": { "@creit.tech/stellar-wallets-kit": ">=1.0.0", - "@stellar/stellar-sdk": ">=13.3.0", + "@stellar/stellar-sdk": "13.3.0", "@walletconnect/sign-client": ">=2.0.0" }, "peerDependenciesMeta": { diff --git a/package.json b/package.json index 5ef0621d..698744dd 100644 --- a/package.json +++ b/package.json @@ -47,9 +47,9 @@ "require": "./dist/network/index.js" }, "./shared": { - "types": "./dist/shared/index.d.ts", - "import": "./dist/shared/index.mjs", - "require": "./dist/shared/index.js" + "types": "./dist/shared/public.d.ts", + "import": "./dist/shared/public.mjs", + "require": "./dist/shared/public.js" }, "./integration": { "types": "./dist/integration/index.d.ts", @@ -107,7 +107,7 @@ "license": "MIT", "peerDependencies": { "@creit.tech/stellar-wallets-kit": ">=1.0.0", - "@stellar/stellar-sdk": ">=13.3.0", + "@stellar/stellar-sdk": "13.3.0", "@walletconnect/sign-client": ">=2.0.0" }, "peerDependenciesMeta": { @@ -119,7 +119,7 @@ } }, "devDependencies": { - "@stellar/stellar-sdk": "^13.3.0", + "@stellar/stellar-sdk": "13.3.0", "@types/node": "^20.0.0", "@typescript-eslint/eslint-plugin": "^8.70.1", "@typescript-eslint/parser": "^8.65.0", diff --git a/scripts/validate-exports.js b/scripts/validate-exports.js index 0f449e2d..fb53845f 100644 --- a/scripts/validate-exports.js +++ b/scripts/validate-exports.js @@ -103,7 +103,7 @@ for (const name of expectedMainExports) { } } -const sharedModule = require(path.resolve(__dirname, '../dist/shared/index.js')); +const sharedModule = require(path.resolve(__dirname, '../dist/shared/public.js')); for (const name of [ 'checkMainnetSafety', 'extractTransactionTotalXlm', 'isMainnetNetwork', 'DEFAULT_MAINNET_SAFETY_THRESHOLD_XLM', 'MAINNET_NETWORK_PASSPHRASE', @@ -113,6 +113,10 @@ for (const name of [ failed = true; } } +if (sharedModule.createSmartCache !== undefined || sharedModule.registerAsset !== undefined) { + console.error('Internal shared utilities leaked from the stable shared entrypoint'); + failed = true; +} if (mainModule.SorokitErrorCode.MAINNET_SAFETY_LIMIT !== 'MAINNET_SAFETY_LIMIT') { console.error('Missing Mainnet safety error code'); failed = true; diff --git a/src/shared/index.ts b/src/shared/index.ts index 525a8c91..5abc1392 100644 --- a/src/shared/index.ts +++ b/src/shared/index.ts @@ -1,3 +1,10 @@ +/** + * Internal implementation barrel. + * + * This file is intentionally not exposed through package.json exports. SDK + * consumers must use the curated `sorokit-core/shared` entrypoint instead; + * the exports below may change without a semver guarantee. + */ export * from "./cache"; export * from "./cacheInvalidation"; export * from "./config"; @@ -64,4 +71,3 @@ export type { // ─── OpenTelemetry (#600) & SmartCache (#604) ──────────────────────────────── export * from "./openTelemetry"; export * from "./smartCache"; - diff --git a/src/shared/public.ts b/src/shared/public.ts new file mode 100644 index 00000000..128bfc33 --- /dev/null +++ b/src/shared/public.ts @@ -0,0 +1,35 @@ +/** + * Stable shared helpers exported by the SDK's `sorokit-core/shared` entrypoint. + * + * Internal shared implementation modules intentionally remain reachable only by + * source-relative imports and are not part of the package export map. + */ +export { + formatAmount, + DEFAULT_ASSET_DECIMALS, +} from "./amountFormatter"; +export type { FormatAmountOptions } from "./amountFormatter"; + +export { + validateStellarAddress, + validatePublicKey, + validateAssetCode, + validateAmount, +} from "./validation"; + +export { + validateStroop, + xlmToStroops, + stroopsToXlm, + STROOPS_PER_XLM, + MAX_STROOPS, + MAX_AMOUNT, +} from "./amountValidation"; + +export { + checkMainnetSafety, + extractTransactionTotalXlm, + isMainnetNetwork, + DEFAULT_MAINNET_SAFETY_THRESHOLD_XLM, + MAINNET_NETWORK_PASSPHRASE, +} from "./mainnetSafety"; diff --git a/tsconfig.json b/tsconfig.json index 000de256..f29630c9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,14 @@ "moduleResolution": "bundler", "lib": ["ES2020", "DOM"], "strict": true, + "noImplicitAny": true, "strictNullChecks": true, + "strictFunctionTypes": true, + "strictBindCallApply": true, + "strictPropertyInitialization": true, + "useUnknownInCatchVariables": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, "exactOptionalPropertyTypes": true, "noUncheckedIndexedAccess": true, "noImplicitOverride": true, diff --git a/tsup.config.ts b/tsup.config.ts index 6bab956e..d36a494c 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -11,6 +11,7 @@ export default defineConfig({ "src/soroban/index.ts", "src/network/index.ts", "src/shared/index.ts", + "src/shared/public.ts", "src/integration/index.ts", "src/lazy/index.ts", "src/shared/keyManagement.ts",