@capxul/sdk 1.0.0-alpha.11 → 1.0.0-alpha.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/InMemoryAuthCacheAdapter-EBzKEJmQ.mjs +113 -0
- package/dist/InMemoryAuthCacheAdapter-EBzKEJmQ.mjs.map +1 -0
- package/dist/index.d.mts +335 -459
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +583 -1467
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.d.mts +3 -3
- package/dist/node/index.mjs +2 -1
- package/dist/node/index.mjs.map +1 -1
- package/dist/ports/safe-deployment.d.mts +1 -1
- package/dist/{safe-deployment-D3k9yndM.d.mts → safe-deployment-DMGB1kEL.d.mts} +5 -4
- package/dist/safe-deployment-DMGB1kEL.d.mts.map +1 -0
- package/dist/{signer-D9fUJp8o.d.mts → signer-DEMJbpJ2.d.mts} +8 -7
- package/dist/signer-DEMJbpJ2.d.mts.map +1 -0
- package/package.json +8 -8
- package/dist/InMemoryAuthCacheAdapter-v5W-XB5M.mjs +0 -457
- package/dist/InMemoryAuthCacheAdapter-v5W-XB5M.mjs.map +0 -1
- package/dist/index-CTXgQ_xR.d.mts +0 -158
- package/dist/index-CTXgQ_xR.d.mts.map +0 -1
- package/dist/safe-deployment-D3k9yndM.d.mts.map +0 -1
- package/dist/signer-D9fUJp8o.d.mts.map +0 -1
package/dist/node/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Hex } from "viem";
|
|
1
|
+
import { _ as AuthCachePortTag, g as AuthCachePort, h as AuthCacheError, n as CapxulSigner, v as CachedJwt } from "../signer-DEMJbpJ2.mjs";
|
|
2
|
+
import { AuthSession } from "@capxul/types";
|
|
4
3
|
import { Effect, Layer } from "effect";
|
|
4
|
+
import { Hex } from "viem";
|
|
5
5
|
import * as PlatformFileSystem from "@effect/platform/FileSystem";
|
|
6
6
|
import * as PlatformPath from "@effect/platform/Path";
|
|
7
7
|
|
package/dist/node/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { a as AuthCacheError,
|
|
1
|
+
import { a as AuthCacheError, i as parseCachedJwt, n as BrowserAuthCacheAdapter, o as AuthCachePortTag, r as parseAuthSession, t as InMemoryAuthCacheAdapter } from "../InMemoryAuthCacheAdapter-EBzKEJmQ.mjs";
|
|
2
|
+
import { toAddress } from "@capxul/types";
|
|
2
3
|
import { Effect, Layer } from "effect";
|
|
3
4
|
import { privateKeyToAccount } from "viem/accounts";
|
|
4
5
|
import * as os from "node:os";
|
package/dist/node/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/adapters/auth-cache/FileSystemAuthCacheAdapter.ts","../../src/node/index.ts"],"sourcesContent":["import type * as PlatformError from \"@effect/platform/Error\";\nimport * as PlatformFileSystem from \"@effect/platform/FileSystem\";\nimport * as PlatformPath from \"@effect/platform/Path\";\nimport * as NodeFileSystem from \"@effect/platform-node/NodeFileSystem\";\nimport * as NodePath from \"@effect/platform-node/NodePath\";\nimport { Effect, Layer } from \"effect\";\nimport type { AuthSession } from \"@capxul/types\";\n\nimport {\n AuthCacheError,\n AuthCachePortTag,\n type AuthCachePort,\n type CachedJwt,\n} from \"../../ports/auth-cache\";\nimport { parseAuthSession, parseCachedJwt } from \"./serialization\";\n\ninterface FilePayload {\n readonly session: AuthSession | null;\n readonly jwt: CachedJwt | null;\n}\n\ntype FileSystemRuntime = PlatformFileSystem.FileSystem | PlatformPath.Path;\n\nfunction emptyPayload(): FilePayload {\n return { session: null, jwt: null };\n}\n\nconst nodeFileSystemRuntime = Layer.merge(NodeFileSystem.layer, NodePath.layer);\n\nexport class FileSystemAuthCacheAdapter implements AuthCachePort {\n private readonly path: string;\n private readonly runtime: Layer.Layer<FileSystemRuntime>;\n readonly getSession: Effect.Effect<AuthSession | null, AuthCacheError>;\n readonly setSession: (session: AuthSession) => Effect.Effect<void, AuthCacheError>;\n readonly clearSession: Effect.Effect<void, AuthCacheError>;\n readonly getJwt: Effect.Effect<CachedJwt | null, AuthCacheError>;\n readonly setJwt: (jwt: CachedJwt) => Effect.Effect<void, AuthCacheError>;\n readonly clearJwt: Effect.Effect<void, AuthCacheError>;\n\n constructor(path: string, runtime: Layer.Layer<FileSystemRuntime> = nodeFileSystemRuntime) {\n this.path = path;\n this.runtime = runtime;\n\n this.getSession = this.run(\n \"getSession\",\n this.read().pipe(Effect.map((payload) => payload.session)),\n );\n this.setSession = (session: AuthSession) =>\n this.run(\n \"setSession\",\n Effect.gen(this, function* () {\n const cur = yield* this.read();\n yield* this.write({ session, jwt: cur.jwt });\n }),\n );\n this.clearSession = this.run(\n \"clearSession\",\n Effect.gen(this, function* () {\n const cur = yield* this.read();\n yield* this.write({ session: null, jwt: cur.jwt });\n }),\n );\n this.getJwt = this.run(\"getJwt\", this.read().pipe(Effect.map((payload) => payload.jwt)));\n this.setJwt = (jwt: CachedJwt) =>\n this.run(\n \"setJwt\",\n Effect.gen(this, function* () {\n const cur = yield* this.read();\n yield* this.write({ session: cur.session, jwt });\n }),\n );\n this.clearJwt = this.run(\n \"clearJwt\",\n Effect.gen(this, function* () {\n const cur = yield* this.read();\n yield* this.write({ session: cur.session, jwt: null });\n }),\n );\n }\n\n private read(): Effect.Effect<FilePayload, PlatformError.PlatformError, FileSystemRuntime> {\n return Effect.gen(this, function* () {\n const fs = yield* PlatformFileSystem.FileSystem;\n const exists = yield* fs.exists(this.path);\n if (!exists) return emptyPayload();\n const raw = yield* fs.readFileString(this.path, \"utf-8\");\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch {\n return emptyPayload();\n }\n if (typeof parsed !== \"object\" || parsed === null || Array.isArray(parsed)) {\n return emptyPayload();\n }\n const payload = parsed as { readonly session?: unknown; readonly jwt?: unknown };\n\n return {\n session: parseAuthSession(payload.session),\n jwt: parseCachedJwt(payload.jwt),\n };\n });\n }\n\n private write(\n payload: FilePayload,\n ): Effect.Effect<void, PlatformError.PlatformError, FileSystemRuntime> {\n return Effect.gen(this, function* () {\n const fs = yield* PlatformFileSystem.FileSystem;\n const path = yield* PlatformPath.Path;\n const dir = path.dirname(this.path);\n const dirExists = yield* fs.exists(dir);\n if (!dirExists) {\n yield* fs.makeDirectory(dir, { recursive: true, mode: 0o700 });\n }\n yield* fs.writeFileString(this.path, JSON.stringify(payload), { mode: 0o600 });\n yield* fs.chmod(this.path, 0o600);\n });\n }\n\n private run<T>(\n operation: string,\n effect: Effect.Effect<T, PlatformError.PlatformError, FileSystemRuntime>,\n ): Effect.Effect<T, AuthCacheError> {\n return effect.pipe(\n Effect.mapError((cause) => toAuthCacheError(operation, cause)),\n Effect.provide(this.runtime),\n );\n }\n}\n\nexport function FileSystemAuthCacheLayer(input: {\n readonly path: string;\n readonly runtime?: Layer.Layer<FileSystemRuntime>;\n}): Layer.Layer<AuthCachePortTag, AuthCacheError> {\n return Layer.effect(\n AuthCachePortTag,\n Effect.sync(() => new FileSystemAuthCacheAdapter(input.path, input.runtime)).pipe(\n Effect.mapError((cause) => toAuthCacheError(\"initialize\", cause)),\n ),\n );\n}\n\nfunction toAuthCacheError(operation: string, cause: unknown): AuthCacheError {\n return new AuthCacheError({ operation, cause });\n}\n","// `@capxul/sdk/node` — node-only entry (published-package-boundaries.md).\n//\n// The default `@capxul/sdk` entry is browser-clean: it never statically reaches\n// `@effect/platform-node`. Node consumers import the on-disk auth cache and the\n// node key `CapxulSigner` from here.\n\nimport * as os from \"node:os\";\nimport { join } from \"node:path\";\n\nimport { toAddress } from \"@capxul/types\";\nimport { privateKeyToAccount } from \"viem/accounts\";\nimport type { Hex } from \"viem\";\n\nimport { BrowserAuthCacheAdapter } from \"../adapters/auth-cache/BrowserAuthCacheAdapter\";\nimport { FileSystemAuthCacheAdapter } from \"../adapters/auth-cache/FileSystemAuthCacheAdapter\";\nimport { InMemoryAuthCacheAdapter } from \"../adapters/auth-cache/InMemoryAuthCacheAdapter\";\nimport type { WindowLike } from \"../client/window-like\";\nimport type { AuthCachePort } from \"../ports/auth-cache\";\nimport type { CapxulSigner } from \"../signer\";\n\nexport {\n FileSystemAuthCacheAdapter,\n FileSystemAuthCacheLayer,\n} from \"../adapters/auth-cache/FileSystemAuthCacheAdapter\";\n\nexport interface DetectNodeAuthCacheAdapterOptions {\n readonly authCachePath?: string;\n readonly resolveHomeDirectory?: () => string;\n}\n\n/**\n * Node `CapxulSigner` backed by a raw private key. Signs the EIP-712 `SafeOp`\n * digest the backend returns for a prepared deployment UserOperation. The\n * reference CLI builds this from `DEPLOYER_PRIVATE_KEY` for the live capstone.\n */\nexport function localPrivateKeySigner(input: { readonly privateKey: Hex }): CapxulSigner {\n const account = privateKeyToAccount(input.privateKey);\n return {\n source: \"local-private-key\",\n async getAddress() {\n return toAddress(account.address);\n },\n async signUserOpHash(hash: Hex): Promise<Hex> {\n // `sign({ hash })` signs the already-computed SafeOp digest directly.\n // `signMessage({ message: { raw: hash } })` would add an EIP-191 prefix.\n return account.sign({ hash });\n },\n };\n}\n\n/**\n * Node-aware auth-cache detection. Mirrors the historic default order:\n * 1. Browser localStorage → BrowserAuthCacheAdapter\n * 2. Node.js process → FileSystemAuthCacheAdapter\n * (`~/.config/capxul/auth-cache.json`)\n * 3. Neither detected → InMemoryAuthCacheAdapter\n *\n * Use this from a Node entrypoint and pass the result to\n * `createCapxulClient({ authCache })` for on-disk session persistence.\n */\nexport function detectNodeAuthCacheAdapter(\n options: DetectNodeAuthCacheAdapterOptions = {},\n): AuthCachePort {\n const globalAny = globalThis as unknown as {\n readonly window?: WindowLike;\n readonly process?: { readonly versions?: { readonly node?: string } };\n };\n if (globalAny.window?.localStorage !== undefined) {\n return new BrowserAuthCacheAdapter(globalAny.window.localStorage);\n }\n if (globalAny.process?.versions?.node !== undefined) {\n const authCachePath =\n normalizeConfiguredAuthCachePath(options.authCachePath) ??\n resolveDefaultAuthCachePath(options.resolveHomeDirectory ?? os.homedir);\n if (authCachePath !== null) return new FileSystemAuthCacheAdapter(authCachePath);\n }\n return new InMemoryAuthCacheAdapter();\n}\n\nfunction normalizeConfiguredAuthCachePath(path: string | undefined): string | null {\n if (path === undefined) return null;\n const trimmed = path.trim();\n return trimmed.length > 0 ? trimmed : null;\n}\n\nfunction resolveDefaultAuthCachePath(resolveHomeDirectory: () => string): string | null {\n try {\n return join(resolveHomeDirectory(), \".config\", \"capxul\", \"auth-cache.json\");\n } catch {\n return null;\n }\n}\n"],"mappings":";;;;;;;;;;AAuBA,SAAS,eAA4B;CACnC,OAAO;EAAE,SAAS;EAAM,KAAK;CAAK;AACpC;AAEA,MAAM,wBAAwB,MAAM,MAAM,eAAe,OAAO,SAAS,KAAK;AAE9E,IAAa,6BAAb,MAAiE;CAC/D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA,YAAY,MAAc,UAA0C,uBAAuB;EACzF,KAAK,OAAO;EACZ,KAAK,UAAU;EAEf,KAAK,aAAa,KAAK,IACrB,cACA,KAAK,KAAK,EAAE,KAAK,OAAO,KAAK,YAAY,QAAQ,OAAO,CAAC,CAC3D;EACA,KAAK,cAAc,YACjB,KAAK,IACH,cACA,OAAO,IAAI,MAAM,aAAa;GAC5B,MAAM,MAAM,OAAO,KAAK,KAAK;GAC7B,OAAO,KAAK,MAAM;IAAE;IAAS,KAAK,IAAI;GAAI,CAAC;EAC7C,CAAC,CACH;EACF,KAAK,eAAe,KAAK,IACvB,gBACA,OAAO,IAAI,MAAM,aAAa;GAC5B,MAAM,MAAM,OAAO,KAAK,KAAK;GAC7B,OAAO,KAAK,MAAM;IAAE,SAAS;IAAM,KAAK,IAAI;GAAI,CAAC;EACnD,CAAC,CACH;EACA,KAAK,SAAS,KAAK,IAAI,UAAU,KAAK,KAAK,EAAE,KAAK,OAAO,KAAK,YAAY,QAAQ,GAAG,CAAC,CAAC;EACvF,KAAK,UAAU,QACb,KAAK,IACH,UACA,OAAO,IAAI,MAAM,aA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QAAQ;EACN,OAAO;CACT;AACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/adapters/auth-cache/FileSystemAuthCacheAdapter.ts","../../src/node/index.ts"],"sourcesContent":["import type * as PlatformError from \"@effect/platform/Error\";\nimport * as PlatformFileSystem from \"@effect/platform/FileSystem\";\nimport * as PlatformPath from \"@effect/platform/Path\";\nimport * as NodeFileSystem from \"@effect/platform-node/NodeFileSystem\";\nimport * as NodePath from \"@effect/platform-node/NodePath\";\nimport { Effect, Layer } from \"effect\";\nimport type { AuthSession } from \"@capxul/types\";\n\nimport {\n AuthCacheError,\n AuthCachePortTag,\n type AuthCachePort,\n type CachedJwt,\n} from \"../../ports/auth-cache\";\nimport { parseAuthSession, parseCachedJwt } from \"./serialization\";\n\ninterface FilePayload {\n readonly session: AuthSession | null;\n readonly jwt: CachedJwt | null;\n}\n\ntype FileSystemRuntime = PlatformFileSystem.FileSystem | PlatformPath.Path;\n\nfunction emptyPayload(): FilePayload {\n return { session: null, jwt: null };\n}\n\nconst nodeFileSystemRuntime = Layer.merge(NodeFileSystem.layer, NodePath.layer);\n\nexport class FileSystemAuthCacheAdapter implements AuthCachePort {\n private readonly path: string;\n private readonly runtime: Layer.Layer<FileSystemRuntime>;\n readonly getSession: Effect.Effect<AuthSession | null, AuthCacheError>;\n readonly setSession: (session: AuthSession) => Effect.Effect<void, AuthCacheError>;\n readonly clearSession: Effect.Effect<void, AuthCacheError>;\n readonly getJwt: Effect.Effect<CachedJwt | null, AuthCacheError>;\n readonly setJwt: (jwt: CachedJwt) => Effect.Effect<void, AuthCacheError>;\n readonly clearJwt: Effect.Effect<void, AuthCacheError>;\n\n constructor(path: string, runtime: Layer.Layer<FileSystemRuntime> = nodeFileSystemRuntime) {\n this.path = path;\n this.runtime = runtime;\n\n this.getSession = this.run(\n \"getSession\",\n this.read().pipe(Effect.map((payload) => payload.session)),\n );\n this.setSession = (session: AuthSession) =>\n this.run(\n \"setSession\",\n Effect.gen(this, function* () {\n const cur = yield* this.read();\n yield* this.write({ session, jwt: cur.jwt });\n }),\n );\n this.clearSession = this.run(\n \"clearSession\",\n Effect.gen(this, function* () {\n const cur = yield* this.read();\n yield* this.write({ session: null, jwt: cur.jwt });\n }),\n );\n this.getJwt = this.run(\"getJwt\", this.read().pipe(Effect.map((payload) => payload.jwt)));\n this.setJwt = (jwt: CachedJwt) =>\n this.run(\n \"setJwt\",\n Effect.gen(this, function* () {\n const cur = yield* this.read();\n yield* this.write({ session: cur.session, jwt });\n }),\n );\n this.clearJwt = this.run(\n \"clearJwt\",\n Effect.gen(this, function* () {\n const cur = yield* this.read();\n yield* this.write({ session: cur.session, jwt: null });\n }),\n );\n }\n\n private read(): Effect.Effect<FilePayload, PlatformError.PlatformError, FileSystemRuntime> {\n return Effect.gen(this, function* () {\n const fs = yield* PlatformFileSystem.FileSystem;\n const exists = yield* fs.exists(this.path);\n if (!exists) return emptyPayload();\n const raw = yield* fs.readFileString(this.path, \"utf-8\");\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch {\n return emptyPayload();\n }\n if (typeof parsed !== \"object\" || parsed === null || Array.isArray(parsed)) {\n return emptyPayload();\n }\n const payload = parsed as { readonly session?: unknown; readonly jwt?: unknown };\n\n return {\n session: parseAuthSession(payload.session),\n jwt: parseCachedJwt(payload.jwt),\n };\n });\n }\n\n private write(\n payload: FilePayload,\n ): Effect.Effect<void, PlatformError.PlatformError, FileSystemRuntime> {\n return Effect.gen(this, function* () {\n const fs = yield* PlatformFileSystem.FileSystem;\n const path = yield* PlatformPath.Path;\n const dir = path.dirname(this.path);\n const dirExists = yield* fs.exists(dir);\n if (!dirExists) {\n yield* fs.makeDirectory(dir, { recursive: true, mode: 0o700 });\n }\n yield* fs.writeFileString(this.path, JSON.stringify(payload), { mode: 0o600 });\n yield* fs.chmod(this.path, 0o600);\n });\n }\n\n private run<T>(\n operation: string,\n effect: Effect.Effect<T, PlatformError.PlatformError, FileSystemRuntime>,\n ): Effect.Effect<T, AuthCacheError> {\n return effect.pipe(\n Effect.mapError((cause) => toAuthCacheError(operation, cause)),\n Effect.provide(this.runtime),\n );\n }\n}\n\nexport function FileSystemAuthCacheLayer(input: {\n readonly path: string;\n readonly runtime?: Layer.Layer<FileSystemRuntime>;\n}): Layer.Layer<AuthCachePortTag, AuthCacheError> {\n return Layer.effect(\n AuthCachePortTag,\n Effect.sync(() => new FileSystemAuthCacheAdapter(input.path, input.runtime)).pipe(\n Effect.mapError((cause) => toAuthCacheError(\"initialize\", cause)),\n ),\n );\n}\n\nfunction toAuthCacheError(operation: string, cause: unknown): AuthCacheError {\n return new AuthCacheError({ operation, cause });\n}\n","// `@capxul/sdk/node` — node-only entry (published-package-boundaries.md).\n//\n// The default `@capxul/sdk` entry is browser-clean: it never statically reaches\n// `@effect/platform-node`. Node consumers import the on-disk auth cache and the\n// node key `CapxulSigner` from here.\n\nimport * as os from \"node:os\";\nimport { join } from \"node:path\";\n\nimport { toAddress } from \"@capxul/types\";\nimport { privateKeyToAccount } from \"viem/accounts\";\nimport type { Hex } from \"viem\";\n\nimport { BrowserAuthCacheAdapter } from \"../adapters/auth-cache/BrowserAuthCacheAdapter\";\nimport { FileSystemAuthCacheAdapter } from \"../adapters/auth-cache/FileSystemAuthCacheAdapter\";\nimport { InMemoryAuthCacheAdapter } from \"../adapters/auth-cache/InMemoryAuthCacheAdapter\";\nimport type { WindowLike } from \"../client/window-like\";\nimport type { AuthCachePort } from \"../ports/auth-cache\";\nimport type { CapxulSigner } from \"../signer\";\n\nexport {\n FileSystemAuthCacheAdapter,\n FileSystemAuthCacheLayer,\n} from \"../adapters/auth-cache/FileSystemAuthCacheAdapter\";\n\nexport interface DetectNodeAuthCacheAdapterOptions {\n readonly authCachePath?: string;\n readonly resolveHomeDirectory?: () => string;\n}\n\n/**\n * Node `CapxulSigner` backed by a raw private key. Signs the EIP-712 `SafeOp`\n * digest the backend returns for a prepared deployment UserOperation. The\n * reference CLI builds this from `DEPLOYER_PRIVATE_KEY` for the live capstone.\n */\nexport function localPrivateKeySigner(input: { readonly privateKey: Hex }): CapxulSigner {\n const account = privateKeyToAccount(input.privateKey);\n return {\n source: \"local-private-key\",\n async getAddress() {\n return toAddress(account.address);\n },\n async signUserOpHash(hash: Hex): Promise<Hex> {\n // `sign({ hash })` signs the already-computed SafeOp digest directly.\n // `signMessage({ message: { raw: hash } })` would add an EIP-191 prefix.\n return account.sign({ hash });\n },\n };\n}\n\n/**\n * Node-aware auth-cache detection. Mirrors the historic default order:\n * 1. Browser localStorage → BrowserAuthCacheAdapter\n * 2. Node.js process → FileSystemAuthCacheAdapter\n * (`~/.config/capxul/auth-cache.json`)\n * 3. Neither detected → InMemoryAuthCacheAdapter\n *\n * Use this from a Node entrypoint and pass the result to\n * `createCapxulClient({ authCache })` for on-disk session persistence.\n */\nexport function detectNodeAuthCacheAdapter(\n options: DetectNodeAuthCacheAdapterOptions = {},\n): AuthCachePort {\n const globalAny = globalThis as unknown as {\n readonly window?: WindowLike;\n readonly process?: { readonly versions?: { readonly node?: string } };\n };\n if (globalAny.window?.localStorage !== undefined) {\n return new BrowserAuthCacheAdapter(globalAny.window.localStorage);\n }\n if (globalAny.process?.versions?.node !== undefined) {\n const authCachePath =\n normalizeConfiguredAuthCachePath(options.authCachePath) ??\n resolveDefaultAuthCachePath(options.resolveHomeDirectory ?? os.homedir);\n if (authCachePath !== null) return new FileSystemAuthCacheAdapter(authCachePath);\n }\n return new InMemoryAuthCacheAdapter();\n}\n\nfunction normalizeConfiguredAuthCachePath(path: string | undefined): string | null {\n if (path === undefined) return null;\n const trimmed = path.trim();\n return trimmed.length > 0 ? trimmed : null;\n}\n\nfunction resolveDefaultAuthCachePath(resolveHomeDirectory: () => string): string | null {\n try {\n return join(resolveHomeDirectory(), \".config\", \"capxul\", \"auth-cache.json\");\n } catch {\n return null;\n }\n}\n"],"mappings":";;;;;;;;;;;AAuBA,SAAS,eAA4B;CACnC,OAAO;EAAE,SAAS;EAAM,KAAK;CAAK;AACpC;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D;CACvF,MAAM,UAAU,oBAAoB,MAAM,UAAU;CACpD,OAAO;EACL,QAAQ;EACR,MAAM,aAAa;GACjB,OAAO,UAAU,QAAQ,OAAO;EAClC;EACA,MAAM,eAAe,MAAyB;GAG5C,OAAO,QAAQ,KAAK,EAAE,KAAK,CAAC;EAC9B;CACF;AACF;;;;;;;;;;;AAYA,SAAgB,2BACd,UAA6C,CAAC,GAC/B;CACf,MAAM,YAAY;CAIlB,IAAI,UAAU,QAAQ,iBAAiB,KAAA,GACrC,OAAO,IAAI,wBAAwB,UAAU,OAAO,YAAY;CAElE,IAAI,UAAU,SAAS,UAAU,SAAS,KAAA,GAAW;EACnD,MAAM,gBACJ,iCAAiC,QAAQ,aAAa,KACtD,4BAA4B,QAAQ,wBAAwB,GAAG,OAAO;EACxE,IAAI,kBAAkB,MAAM,OAAO,IAAI,2BAA2B,aAAa;CACjF;CACA,OAAO,IAAI,yBAAyB;AACtC;AAEA,SAAS,iCAAiC,MAAyC;CACjF,IAAI,SAAS,KAAA,GAAW,OAAO;CAC/B,MAAM,UAAU,KAAK,KAAK;CAC1B,OAAO,QAAQ,SAAS,IAAI,UAAU;AACxC;AAEA,SAAS,4BAA4B,sBAAmD;CACtF,IAAI;EACF,OAAO,KAAK,qBAAqB,GAAG,WAAW,UAAU,iBAAiB;CAC5E,QAAQ;EACN,OAAO;CACT;AACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as SafeDeploymentEvidence, c as SafeDeploymentPortTag, i as SafeDeploymentError, l as safeDeploymentErrorFromCapxul, n as SafeDeploymentConfig, o as SafeDeploymentInput, r as SafeDeploymentDeployedQuery, s as SafeDeploymentPort, t as PreparedSafeAccount } from "../safe-deployment-
|
|
1
|
+
import { a as SafeDeploymentEvidence, c as SafeDeploymentPortTag, i as SafeDeploymentError, l as safeDeploymentErrorFromCapxul, n as SafeDeploymentConfig, o as SafeDeploymentInput, r as SafeDeploymentDeployedQuery, s as SafeDeploymentPort, t as PreparedSafeAccount } from "../safe-deployment-DMGB1kEL.mjs";
|
|
2
2
|
export { PreparedSafeAccount, SafeDeploymentConfig, SafeDeploymentDeployedQuery, SafeDeploymentError, SafeDeploymentEvidence, SafeDeploymentInput, SafeDeploymentPort, SafeDeploymentPortTag, safeDeploymentErrorFromCapxul };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { CapxulError, CapxulErrorCode, CapxulErrorDetails } from "@capxul/config";
|
|
2
|
+
import { Address, BlockNumber, ChainId, DurationMs, Email, TxHash } from "@capxul/types";
|
|
3
3
|
import { Context, Effect } from "effect";
|
|
4
|
+
import { Account as Account$1 } from "viem";
|
|
4
5
|
|
|
5
6
|
//#region src/ports/safe-deployment.d.ts
|
|
6
7
|
/**
|
|
@@ -55,7 +56,7 @@ type SafeDeploymentEvidence = {
|
|
|
55
56
|
readonly blockNumber?: BlockNumber;
|
|
56
57
|
};
|
|
57
58
|
type SafeDeploymentInput = {
|
|
58
|
-
readonly signer: Account;
|
|
59
|
+
readonly signer: Account$1;
|
|
59
60
|
readonly email: Email;
|
|
60
61
|
readonly config: SafeDeploymentConfig;
|
|
61
62
|
};
|
|
@@ -133,4 +134,4 @@ declare const SafeDeploymentPortTag_base: Context.TagClass<SafeDeploymentPortTag
|
|
|
133
134
|
declare class SafeDeploymentPortTag extends SafeDeploymentPortTag_base {}
|
|
134
135
|
//#endregion
|
|
135
136
|
export { SafeDeploymentEvidence as a, SafeDeploymentPortTag as c, SafeDeploymentError as i, safeDeploymentErrorFromCapxul as l, SafeDeploymentConfig as n, SafeDeploymentInput as o, SafeDeploymentDeployedQuery as r, SafeDeploymentPort as s, PreparedSafeAccount as t };
|
|
136
|
-
//# sourceMappingURL=safe-deployment-
|
|
137
|
+
//# sourceMappingURL=safe-deployment-DMGB1kEL.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safe-deployment-DMGB1kEL.d.mts","names":[],"sources":["../src/ports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AnEF;;;;;;;EA4EvC,UAAA,CACE,KAAA,EAAO,2BAAA,GACN,MAAA,CAAO,MAAA,UAAgB,mBAAA;AAAA;AAAA,cAC3B,0BAAA;cAEY,qBAAA,SAA8B,0BAGxC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { CapxulError } from "@capxul/errors";
|
|
2
|
+
import { Address, AuthSession, EpochSeconds, JwtToken, Profile, SmartAccount } from "@capxul/types";
|
|
3
3
|
import { Context, Effect } from "effect";
|
|
4
|
+
import { Account as Account$1, Hex } from "viem";
|
|
4
5
|
|
|
5
6
|
//#region src/ports/auth-cache.d.ts
|
|
6
7
|
/**
|
|
@@ -51,8 +52,8 @@ declare class AuthCachePortTag extends AuthCachePortTag_base {}
|
|
|
51
52
|
//#endregion
|
|
52
53
|
//#region src/client/types.d.ts
|
|
53
54
|
type Session = AuthSession;
|
|
54
|
-
type Profile = Profile
|
|
55
|
-
type SmartAccount = SmartAccount
|
|
55
|
+
type Profile$1 = Profile;
|
|
56
|
+
type SmartAccount$1 = SmartAccount;
|
|
56
57
|
/**
|
|
57
58
|
* Result-shape returned by every method on `CapxulClient`. Mirrors the
|
|
58
59
|
* existing per-port `Result` aliases; centralized here so consumers have
|
|
@@ -94,7 +95,7 @@ interface AccountProvider {
|
|
|
94
95
|
* Custom providers MUST honor this contract.
|
|
95
96
|
*/
|
|
96
97
|
getAddress(): Promise<CapxulResult<Address>>;
|
|
97
|
-
getDeployAccount(): Promise<CapxulResult<Account>>;
|
|
98
|
+
getDeployAccount(): Promise<CapxulResult<Account$1>>;
|
|
98
99
|
}
|
|
99
100
|
interface Eip1193Provider {
|
|
100
101
|
request(args: {
|
|
@@ -143,5 +144,5 @@ interface Eip1193RequestProvider {
|
|
|
143
144
|
*/
|
|
144
145
|
declare function injectedWalletSigner(provider: Eip1193RequestProvider): CapxulSigner;
|
|
145
146
|
//#endregion
|
|
146
|
-
export { AuthCachePortTag as _, AccountProvider as a, Eip1193Provider as c, CapxulResult as d, Profile as f, AuthCachePort as g, AuthCacheError as h, injectedWalletSigner as i, eip1193AccountProvider as l, SmartAccount as m, CapxulSigner as n, AccountProviderSource as o, Session as p, Eip1193RequestProvider as r, AccountRequirement as s, CapxulDigestSigner as t, localPrivateKeyAccountProvider as u, CachedJwt as v };
|
|
147
|
-
//# sourceMappingURL=signer-
|
|
147
|
+
export { AuthCachePortTag as _, AccountProvider as a, Eip1193Provider as c, CapxulResult as d, Profile$1 as f, AuthCachePort as g, AuthCacheError as h, injectedWalletSigner as i, eip1193AccountProvider as l, SmartAccount$1 as m, CapxulSigner as n, AccountProviderSource as o, Session as p, Eip1193RequestProvider as r, AccountRequirement as s, CapxulDigestSigner as t, localPrivateKeyAccountProvider as u, CachedJwt as v };
|
|
148
|
+
//# sourceMappingURL=signer-DEMJbpJ2.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer-DEMJbpJ2.d.mts","names":[],"sources":["../src/ports/auth-cache.ts","../src/client/types.ts","../src/client/account-providers.ts","../src/signer.ts"],"mappings":";;;;;;;;;;AAiBA;;;;;;;;;;UAAiB,aAAA;EAAA,SACN,UAAA,EAAY,MAAA,CAAO,MAAA,CAAO,WAAA,SAAoB,cAAA;EAAA,SAC9C,UAAA,GAAa,OAAA,EAAS,WAAA,KAAgB,MAAA,CAAO,MAAA,OAAa,cAAA;EAAA,SAC1D,YAAA,EAAc,MAAA,CAAO,MAAA,OAAa,cAAA;EAQpB;;;;;EAAA,SADd,MAAA,EAAQ,MAAA,CAAO,MAAA,CAAO,SAAA,SAAkB,cAAA;EAAA,SACxC,MAAA,GAAS,GAAA,EAAK,SAAA,KAAc,MAAA,CAAO,MAAA,OAAa,cAAA;EAAA,SAChD,QAAA,EAAU,MAAA,CAAO,MAAA,OAAa,cAAA;AAAA;;;;;;UAQxB,SAAA;EAAA,SACN,KAAA,EAAO,QAAA;EAAA,SACP,eAAA,EAAiB,YAAY;AAAA;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YAAY"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capxul/sdk",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.12",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist",
|
|
6
6
|
"package.json",
|
|
@@ -33,7 +33,12 @@
|
|
|
33
33
|
"@openfort/openfort-js": "^1.3.6",
|
|
34
34
|
"convex": "^1.39.1",
|
|
35
35
|
"effect": "^3.21.2",
|
|
36
|
-
"viem": "^2.53.1"
|
|
36
|
+
"viem": "^2.53.1",
|
|
37
|
+
"@capxul/config": "0.1.0-alpha.1",
|
|
38
|
+
"@capxul/observability": "0.1.0-alpha.0",
|
|
39
|
+
"@capxul/types": "0.1.0-alpha.0",
|
|
40
|
+
"@capxul/wire": "0.1.0-alpha.1",
|
|
41
|
+
"@capxul/errors": "0.0.0"
|
|
37
42
|
},
|
|
38
43
|
"devDependencies": {
|
|
39
44
|
"@effect/vitest": "^0.29.0",
|
|
@@ -41,12 +46,7 @@
|
|
|
41
46
|
"fast-check": "^3.23.2",
|
|
42
47
|
"permissionless": "0.3.4",
|
|
43
48
|
"typescript": "5.9.2",
|
|
44
|
-
"vitest": "npm:@voidzero-dev/vite-plus-test@0.1.23"
|
|
45
|
-
"@capxul/types": "0.1.0-alpha.0",
|
|
46
|
-
"@capxul/config": "0.1.0-alpha.1",
|
|
47
|
-
"@capxul/observability": "0.1.0-alpha.0",
|
|
48
|
-
"@capxul/errors": "0.0.0",
|
|
49
|
-
"@capxul/wire": "0.1.0-alpha.1"
|
|
49
|
+
"vitest": "npm:@voidzero-dev/vite-plus-test@0.1.23"
|
|
50
50
|
},
|
|
51
51
|
"_permissionlessPinReason": "permissionless.toSafeSmartAccount is pinned to 0.3.4 for live Safe deployment E2E. Counterfactual address fixtures captured 2026-05-17 in packages/backend/convex/_shared/__tests__/counterfactual.test.ts and packages/config/tests/safe.test.ts must be re-verified before upgrading.",
|
|
52
52
|
"scripts": {
|
|
@@ -1,457 +0,0 @@
|
|
|
1
|
-
import { Context, Data, Effect, Layer } from "effect";
|
|
2
|
-
//#region ../errors/src/errors.ts
|
|
3
|
-
const CAPXUL_ERROR_CODES = [
|
|
4
|
-
"NOT_AUTHENTICATED",
|
|
5
|
-
"EMAIL_DELIVERY_FAILED",
|
|
6
|
-
"PROFILE_NOT_FOUND",
|
|
7
|
-
"SMART_ACCOUNT_MISSING",
|
|
8
|
-
"PLAYER_NOT_FOUND",
|
|
9
|
-
"ACCOUNT_NOT_FOUND",
|
|
10
|
-
"PROVIDER_ERROR",
|
|
11
|
-
"INVALID_INPUT",
|
|
12
|
-
"ENV_MISSING",
|
|
13
|
-
"NOT_IMPLEMENTED",
|
|
14
|
-
"VERIFICATION_REQUIRED",
|
|
15
|
-
"INSUFFICIENT_BALANCE",
|
|
16
|
-
"INVALID_RECIPIENT",
|
|
17
|
-
"ROLE_PERMISSION_DENIED",
|
|
18
|
-
"TRANSACTION_FAILED",
|
|
19
|
-
"RATE_LIMITED",
|
|
20
|
-
"NETWORK_ERROR",
|
|
21
|
-
"UNKNOWN",
|
|
22
|
-
"OTP_EXPIRED",
|
|
23
|
-
"SIGNER_REJECTED",
|
|
24
|
-
"CANCELLED",
|
|
25
|
-
"WRONG_STATE"
|
|
26
|
-
];
|
|
27
|
-
var CapxulError = class extends Error {
|
|
28
|
-
code;
|
|
29
|
-
details;
|
|
30
|
-
correlationId;
|
|
31
|
-
layer;
|
|
32
|
-
constructor(code, message, options = {}) {
|
|
33
|
-
super(message, "cause" in options ? { cause: options.cause } : void 0);
|
|
34
|
-
this.name = "CapxulError";
|
|
35
|
-
this.code = code;
|
|
36
|
-
if (options.details !== void 0) this.details = options.details;
|
|
37
|
-
if (options.correlationId !== void 0) this.correlationId = options.correlationId;
|
|
38
|
-
if (options.layer !== void 0) this.layer = options.layer;
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
function isCapxulError(value) {
|
|
42
|
-
return value instanceof CapxulError;
|
|
43
|
-
}
|
|
44
|
-
function deserializeCapxulError(serialized) {
|
|
45
|
-
return new CapxulError(serialized.code, serialized.message, compactErrorOptions({
|
|
46
|
-
details: serialized.details,
|
|
47
|
-
correlationId: serialized.correlationId,
|
|
48
|
-
layer: serialized.layer
|
|
49
|
-
}));
|
|
50
|
-
}
|
|
51
|
-
function compactErrorOptions(options) {
|
|
52
|
-
const result = {};
|
|
53
|
-
if ("cause" in options) result.cause = options.cause;
|
|
54
|
-
if (options.details !== void 0) result.details = options.details;
|
|
55
|
-
if (options.correlationId !== void 0) result.correlationId = options.correlationId;
|
|
56
|
-
if (options.layer !== void 0) result.layer = options.layer;
|
|
57
|
-
return result;
|
|
58
|
-
}
|
|
59
|
-
const Errors = {
|
|
60
|
-
notAuthenticated: (message, opts) => new CapxulError("NOT_AUTHENTICATED", message ?? "Not authenticated", opts?.failure_mode ? { details: { failure_mode: opts.failure_mode } } : void 0),
|
|
61
|
-
emailDeliveryFailed: (detail) => new CapxulError("EMAIL_DELIVERY_FAILED", "Failed to send email", { details: { detail } }),
|
|
62
|
-
profileNotFound: (authUserId) => new CapxulError("PROFILE_NOT_FOUND", `Profile not found for user ${authUserId}`, { details: { authUserId } }),
|
|
63
|
-
smartAccountMissing: (authUserId) => new CapxulError("SMART_ACCOUNT_MISSING", "Smart account not provisioned", { details: { authUserId } }),
|
|
64
|
-
playerNotFound: (playerId) => new CapxulError("PLAYER_NOT_FOUND", playerId ? `Openfort player ${playerId} not found` : "Openfort player not found", playerId === void 0 ? void 0 : { details: { playerId } }),
|
|
65
|
-
accountNotFound: (accountId) => new CapxulError("ACCOUNT_NOT_FOUND", accountId ? `Openfort account ${accountId} not found` : "Openfort account not found", accountId === void 0 ? void 0 : { details: { accountId } }),
|
|
66
|
-
providerError: (provider, operation, cause, opts) => {
|
|
67
|
-
const details = {
|
|
68
|
-
provider,
|
|
69
|
-
operation
|
|
70
|
-
};
|
|
71
|
-
if (opts?.failure_mode) details.failure_mode = opts.failure_mode;
|
|
72
|
-
return new CapxulError("PROVIDER_ERROR", `Provider error: ${provider} ${operation}`, {
|
|
73
|
-
cause,
|
|
74
|
-
details
|
|
75
|
-
});
|
|
76
|
-
},
|
|
77
|
-
invalidInput: (field, reason) => new CapxulError("INVALID_INPUT", `Invalid ${field}: ${reason}`, { details: {
|
|
78
|
-
field,
|
|
79
|
-
reason
|
|
80
|
-
} }),
|
|
81
|
-
envMissing: (name) => new CapxulError("ENV_MISSING", `Environment variable ${name} not configured`, { details: { name } }),
|
|
82
|
-
notImplemented: (domain, method) => new CapxulError("NOT_IMPLEMENTED", `${domain}.${method} is not yet implemented. This feature is planned for a future release.`, { details: {
|
|
83
|
-
domain,
|
|
84
|
-
method
|
|
85
|
-
} }),
|
|
86
|
-
/**
|
|
87
|
-
* Sibling factory to {@link Errors.providerError} for the per-state timeout
|
|
88
|
-
* path in flows (initially ProvisioningFlow's mint_openfort / deploy_safe /
|
|
89
|
-
* register_indexer `after:` timers). Same `PROVIDER_ERROR` code as
|
|
90
|
-
* `providerError`, plus a `details.reason: "timeout"` discriminator so
|
|
91
|
-
* downstream observers can distinguish failure modes without parsing the
|
|
92
|
-
* message string. The redacted message names the timeout budget; the
|
|
93
|
-
* native `cause` carries the same information for `reportError` fidelity.
|
|
94
|
-
*/
|
|
95
|
-
providerTimeout: (provider, operation, timeoutMs) => new CapxulError("PROVIDER_ERROR", `Provider error: ${provider} ${operation} (timeout exceeded ${timeoutMs}ms)`, {
|
|
96
|
-
details: {
|
|
97
|
-
provider,
|
|
98
|
-
operation,
|
|
99
|
-
reason: "timeout"
|
|
100
|
-
},
|
|
101
|
-
cause: /* @__PURE__ */ new Error(`timeout: ${operation} exceeded ${timeoutMs}ms`)
|
|
102
|
-
}),
|
|
103
|
-
verificationRequired: (details) => {
|
|
104
|
-
return new CapxulError("VERIFICATION_REQUIRED", "rail" in details ? `Verification is required before ${details.rail} can use ${details.currentKind}.` : `Verification tier ${details.requiredTier} is required.`, { details });
|
|
105
|
-
},
|
|
106
|
-
insufficientBalance: (asset, available, required) => new CapxulError("INSUFFICIENT_BALANCE", `Insufficient ${asset} balance`, { details: {
|
|
107
|
-
asset,
|
|
108
|
-
available,
|
|
109
|
-
required
|
|
110
|
-
} }),
|
|
111
|
-
invalidRecipient: (reason) => new CapxulError("INVALID_RECIPIENT", `Invalid recipient: ${reason}`, { details: { reason } }),
|
|
112
|
-
/**
|
|
113
|
-
* The org Zodiac Roles modifier REFUSED the spend on-chain (G4 · #547): the
|
|
114
|
-
* member's role condition (per-tx cap, per-day allowance, allowed recipient,
|
|
115
|
-
* or membership) was violated, so `execTransactionWithRole` reverted. This is
|
|
116
|
-
* a PERMISSION denial — explicitly NOT an `INSUFFICIENT_BALANCE` (the treasury
|
|
117
|
-
* held the funds; the role's authority is what bound). `reason` discriminates
|
|
118
|
-
* the violated condition (`over_cap` / `daily_cap` / `not_member` /
|
|
119
|
-
* `disallowed_recipient` / `condition_violation`); leak-safe — no on-chain
|
|
120
|
-
* identifiers ever enter the details.
|
|
121
|
-
*/
|
|
122
|
-
rolePermissionDenied: (details) => new CapxulError("ROLE_PERMISSION_DENIED", `Org role denied this spend on-chain (${details.reason}).`, { details: details.operation === void 0 ? { reason: details.reason } : {
|
|
123
|
-
reason: details.reason,
|
|
124
|
-
operation: details.operation
|
|
125
|
-
} }),
|
|
126
|
-
/**
|
|
127
|
-
* A transaction (or sponsored UserOp) failed. `details.reason` discriminates
|
|
128
|
-
* the failure mode for callers that must distinguish a CONFIRMED on-chain
|
|
129
|
-
* revert (`"onchain_revert"` — the op executed and reverted, e.g. a Zodiac
|
|
130
|
-
* Roles condition violation) from an inconclusive infra failure. A confirmed
|
|
131
|
-
* revert is the ONLY mode the org spend port may map to a roles denial.
|
|
132
|
-
*/
|
|
133
|
-
transactionFailed: (operation, cause, extra) => new CapxulError("TRANSACTION_FAILED", `Transaction failed: ${operation}`, {
|
|
134
|
-
cause,
|
|
135
|
-
details: extra?.reason === void 0 ? { operation } : {
|
|
136
|
-
operation,
|
|
137
|
-
reason: extra.reason
|
|
138
|
-
}
|
|
139
|
-
}),
|
|
140
|
-
rateLimited: (details) => new CapxulError("RATE_LIMITED", "Rate limit exceeded", details === void 0 ? void 0 : { details: { ...details } }),
|
|
141
|
-
networkError: (operation, cause) => new CapxulError("NETWORK_ERROR", `Network error during ${operation}`, {
|
|
142
|
-
cause,
|
|
143
|
-
details: { operation }
|
|
144
|
-
}),
|
|
145
|
-
unknown: (cause) => new CapxulError("UNKNOWN", "Unknown error", { cause }),
|
|
146
|
-
otpExpired: (details) => new CapxulError("OTP_EXPIRED", "Verification code has expired. Request a new one.", details === void 0 ? void 0 : { details: { ...details } }),
|
|
147
|
-
signerRejected: (details) => new CapxulError("SIGNER_REJECTED", "Signer rejected the request.", {
|
|
148
|
-
cause: details.cause,
|
|
149
|
-
details: details.reason === void 0 ? { source: details.source } : {
|
|
150
|
-
source: details.source,
|
|
151
|
-
reason: details.reason
|
|
152
|
-
}
|
|
153
|
-
}),
|
|
154
|
-
cancelled: (details) => new CapxulError("CANCELLED", "Operation was cancelled.", details === void 0 ? void 0 : { details: { ...details } }),
|
|
155
|
-
/**
|
|
156
|
-
* Method called from a flow state where its precondition fails (TA16). The
|
|
157
|
-
* SDK's method API short-circuits with this error before driving the
|
|
158
|
-
* internal state machine. `currentState` is the Effect-machine snapshot
|
|
159
|
-
* tag (stringified — substrate is `@effect/experimental/Machine` per
|
|
160
|
-
* `docs/canon/decisions/state-machine-substrate.md`); `validStates`
|
|
161
|
-
* enumerates the states the method accepts.
|
|
162
|
-
*/
|
|
163
|
-
wrongState: (details) => new CapxulError("WRONG_STATE", `${details.method} called from state '${details.currentState}'; valid states: ${details.validStates.join(", ")}`, { details: {
|
|
164
|
-
...details,
|
|
165
|
-
validStates: [...details.validStates]
|
|
166
|
-
} })
|
|
167
|
-
};
|
|
168
|
-
//#endregion
|
|
169
|
-
//#region ../errors/src/convex-error-decoding.ts
|
|
170
|
-
const KNOWN_CODES = new Set(CAPXUL_ERROR_CODES);
|
|
171
|
-
function isCapxulCode(value) {
|
|
172
|
-
return typeof value === "string" && KNOWN_CODES.has(value);
|
|
173
|
-
}
|
|
174
|
-
function reconstruct(serialized) {
|
|
175
|
-
if (!isCapxulCode(serialized.code)) return null;
|
|
176
|
-
return deserializeCapxulError({
|
|
177
|
-
code: serialized.code,
|
|
178
|
-
message: typeof serialized.message === "string" ? serialized.message : String(serialized.code),
|
|
179
|
-
...typeof serialized.details === "object" && serialized.details !== null && !Array.isArray(serialized.details) ? { details: serialized.details } : {},
|
|
180
|
-
...typeof serialized.correlationId === "string" ? { correlationId: serialized.correlationId } : {},
|
|
181
|
-
...typeof serialized.layer === "string" ? { layer: serialized.layer } : {}
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
function decodeConvexError(err) {
|
|
185
|
-
if (err === null || err === void 0) return null;
|
|
186
|
-
if (err instanceof CapxulError) return err;
|
|
187
|
-
if (typeof err !== "object") return null;
|
|
188
|
-
const record = err;
|
|
189
|
-
if (!("data" in record)) return null;
|
|
190
|
-
const data = record.data;
|
|
191
|
-
if (typeof data === "object" && data !== null) return reconstruct(data);
|
|
192
|
-
if (typeof data === "string") try {
|
|
193
|
-
const parsed = JSON.parse(data);
|
|
194
|
-
if (typeof parsed === "object" && parsed !== null) return reconstruct(parsed);
|
|
195
|
-
} catch {}
|
|
196
|
-
return null;
|
|
197
|
-
}
|
|
198
|
-
//#endregion
|
|
199
|
-
//#region ../types/src/index.ts
|
|
200
|
-
const EVM_ADDRESS_RE = /^0x[0-9a-f]{40}$/i;
|
|
201
|
-
const BYTES32_RE = /^0x[0-9a-f]{64}$/i;
|
|
202
|
-
const PUBLISHABLE_KEY_PATTERN = /^cap_pk_(test|live)_[0-9A-HJKMNP-TV-Z]{32}$/;
|
|
203
|
-
const SUPPORTED_CURRENCIES = [
|
|
204
|
-
{
|
|
205
|
-
code: "USD",
|
|
206
|
-
symbol: "$",
|
|
207
|
-
name: "US Dollar"
|
|
208
|
-
},
|
|
209
|
-
{
|
|
210
|
-
code: "NGN",
|
|
211
|
-
symbol: "NGN",
|
|
212
|
-
name: "Nigerian Naira"
|
|
213
|
-
},
|
|
214
|
-
{
|
|
215
|
-
code: "GHS",
|
|
216
|
-
symbol: "GHS",
|
|
217
|
-
name: "Ghanaian Cedi"
|
|
218
|
-
},
|
|
219
|
-
{
|
|
220
|
-
code: "KES",
|
|
221
|
-
symbol: "KSh",
|
|
222
|
-
name: "Kenyan Shilling"
|
|
223
|
-
},
|
|
224
|
-
{
|
|
225
|
-
code: "UGX",
|
|
226
|
-
symbol: "USh",
|
|
227
|
-
name: "Ugandan Shilling"
|
|
228
|
-
}
|
|
229
|
-
];
|
|
230
|
-
const SUPPORTED_CURRENCY_CODES = SUPPORTED_CURRENCIES.map((currency) => currency.code);
|
|
231
|
-
Object.fromEntries(SUPPORTED_CURRENCIES.map((currency) => [currency.code, currency.symbol]));
|
|
232
|
-
const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
233
|
-
const COUNTRY_CODE_RE = /^[A-Z]{2}$/;
|
|
234
|
-
const ANONYMOUS_DISTINCT_ID_RE = /^anon_[a-zA-Z0-9-]+$/;
|
|
235
|
-
const ACCOUNT_ID_RE = /^account_[0-9A-Za-z]+$/;
|
|
236
|
-
const SUBACCOUNT_ID_RE = /^subaccount_[0-9A-Za-z]+$/;
|
|
237
|
-
const APP_ID_RE = /^app_[0-7][0-9A-HJKMNP-TV-Z]{25}$/;
|
|
238
|
-
Math.floor(Number.MAX_SAFE_INTEGER / 1e3);
|
|
239
|
-
function toAddress(raw) {
|
|
240
|
-
if (typeof raw !== "string" || !EVM_ADDRESS_RE.test(raw)) throw Errors.invalidInput("address", invalidValueReason("invalid EVM address format", raw));
|
|
241
|
-
return raw.toLowerCase();
|
|
242
|
-
}
|
|
243
|
-
function toEmail(raw) {
|
|
244
|
-
if (typeof raw !== "string" || !EMAIL_RE.test(raw)) throw Errors.invalidInput("email", invalidValueReason("must look like an email address", raw));
|
|
245
|
-
return raw.toLowerCase();
|
|
246
|
-
}
|
|
247
|
-
function toAuthUserId(raw) {
|
|
248
|
-
return toNonEmptyStringBrand(raw, "authUserId");
|
|
249
|
-
}
|
|
250
|
-
function toAnonymousDistinctId(raw) {
|
|
251
|
-
if (typeof raw !== "string" || !ANONYMOUS_DISTINCT_ID_RE.test(raw)) throw Errors.invalidInput("anonDistinctId", invalidValueReason("must be anon_ plus letters, digits, or hyphens", raw));
|
|
252
|
-
return raw;
|
|
253
|
-
}
|
|
254
|
-
function toAccountId(raw) {
|
|
255
|
-
if (typeof raw !== "string" || !ACCOUNT_ID_RE.test(raw)) throw Errors.invalidInput("accountId", invalidValueReason("must be account_ plus an alphanumeric id", raw));
|
|
256
|
-
return raw;
|
|
257
|
-
}
|
|
258
|
-
function toSubAccountId(raw) {
|
|
259
|
-
if (typeof raw !== "string" || !SUBACCOUNT_ID_RE.test(raw)) throw Errors.invalidInput("subAccountId", invalidValueReason("must be subaccount_ plus an alphanumeric id", raw));
|
|
260
|
-
return raw;
|
|
261
|
-
}
|
|
262
|
-
function toOrgId(raw) {
|
|
263
|
-
return toNonEmptyStringBrand(raw, "orgId");
|
|
264
|
-
}
|
|
265
|
-
function toAppId(raw) {
|
|
266
|
-
if (typeof raw !== "string" || !APP_ID_RE.test(raw)) throw Errors.invalidInput("appId", invalidValueReason("must be app_ plus a ULID", raw));
|
|
267
|
-
return raw;
|
|
268
|
-
}
|
|
269
|
-
function toAllowedOrigin(raw) {
|
|
270
|
-
if (typeof raw !== "string") throw Errors.invalidInput("allowedOrigin", "must be an http or https origin string");
|
|
271
|
-
const normalized = normalizeAllowedOrigin(raw);
|
|
272
|
-
if (normalized === null) throw Errors.invalidInput("allowedOrigin", invalidValueReason("must be an http or https origin", raw));
|
|
273
|
-
return normalized;
|
|
274
|
-
}
|
|
275
|
-
function toPublishableKeyId(raw) {
|
|
276
|
-
return toNonEmptyStringBrand(raw, "keyId");
|
|
277
|
-
}
|
|
278
|
-
function toDurationMs(raw) {
|
|
279
|
-
if (typeof raw !== "number" || !Number.isSafeInteger(raw) || raw < 0) throw Errors.invalidInput("duration", invalidValueReason("must be a non-negative safe integer", raw));
|
|
280
|
-
return raw;
|
|
281
|
-
}
|
|
282
|
-
function toPublishableKey(raw) {
|
|
283
|
-
if (typeof raw !== "string" || !PUBLISHABLE_KEY_PATTERN.test(raw)) throw Errors.invalidInput("publishableKey", invalidValueReason("must match cap_pk_(test|live) plus 32 Crockford base32 chars", raw));
|
|
284
|
-
return raw;
|
|
285
|
-
}
|
|
286
|
-
function toEpochMs(raw) {
|
|
287
|
-
assertSafeNonNegativeInteger(raw, "epochMs");
|
|
288
|
-
return raw;
|
|
289
|
-
}
|
|
290
|
-
function toEpochSeconds(raw) {
|
|
291
|
-
assertSafeNonNegativeInteger(raw, "epochSeconds");
|
|
292
|
-
return raw;
|
|
293
|
-
}
|
|
294
|
-
function toChainId(raw) {
|
|
295
|
-
if (typeof raw !== "number" || !Number.isSafeInteger(raw) || raw <= 0) throw Errors.invalidInput("chainId", invalidValueReason("must be a positive safe integer", raw));
|
|
296
|
-
return raw;
|
|
297
|
-
}
|
|
298
|
-
function toCountryCode(raw) {
|
|
299
|
-
if (typeof raw !== "string") throw Errors.invalidInput("countryCode", "must be a string");
|
|
300
|
-
const upper = raw.toUpperCase();
|
|
301
|
-
if (!COUNTRY_CODE_RE.test(upper)) throw Errors.invalidInput("countryCode", invalidValueReason("must be a 2-letter ISO 3166-1 alpha-2 code", raw));
|
|
302
|
-
return upper;
|
|
303
|
-
}
|
|
304
|
-
function toCurrencyCode(raw) {
|
|
305
|
-
if (typeof raw !== "string" || !SUPPORTED_CURRENCY_CODES.includes(raw)) throw Errors.invalidInput("currencyCode", invalidValueReason("unsupported currency", raw));
|
|
306
|
-
return raw;
|
|
307
|
-
}
|
|
308
|
-
function toKycTier(raw) {
|
|
309
|
-
if (typeof raw !== "number" || !Number.isInteger(raw) || raw < 0 || raw > 3) throw Errors.invalidInput("kycTier", invalidValueReason("must be an integer in [0, 3]", raw));
|
|
310
|
-
return raw;
|
|
311
|
-
}
|
|
312
|
-
function toRoleKey(raw) {
|
|
313
|
-
if (typeof raw !== "string" || !BYTES32_RE.test(raw)) throw Errors.invalidInput("roleKey", invalidValueReason("must be 0x + 64 hex chars", raw));
|
|
314
|
-
return raw.toLowerCase();
|
|
315
|
-
}
|
|
316
|
-
function toSessionToken(raw) {
|
|
317
|
-
if (typeof raw !== "string" || raw.length === 0) throw Errors.invalidInput("token", "must be a non-empty string");
|
|
318
|
-
return raw;
|
|
319
|
-
}
|
|
320
|
-
function toJwtToken(raw) {
|
|
321
|
-
if (typeof raw !== "string" || raw.length === 0) throw Errors.invalidInput("jwtToken", "must be a non-empty string");
|
|
322
|
-
return raw;
|
|
323
|
-
}
|
|
324
|
-
function toNonEmptyStringBrand(raw, field) {
|
|
325
|
-
if (typeof raw !== "string" || raw.length === 0) throw Errors.invalidInput(field, "must be a non-empty string");
|
|
326
|
-
return raw;
|
|
327
|
-
}
|
|
328
|
-
function assertSafeNonNegativeInteger(raw, field) {
|
|
329
|
-
if (typeof raw !== "number" || !Number.isSafeInteger(raw) || raw < 0) throw Errors.invalidInput(field, invalidValueReason("must be a non-negative safe integer", raw));
|
|
330
|
-
}
|
|
331
|
-
function normalizeAllowedOrigin(raw) {
|
|
332
|
-
let parsed;
|
|
333
|
-
try {
|
|
334
|
-
parsed = new URL(raw);
|
|
335
|
-
} catch {
|
|
336
|
-
return null;
|
|
337
|
-
}
|
|
338
|
-
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return null;
|
|
339
|
-
if (parsed.hostname.includes("*")) return null;
|
|
340
|
-
return parsed.origin;
|
|
341
|
-
}
|
|
342
|
-
function invalidValueReason(prefix, raw) {
|
|
343
|
-
if (typeof raw === "string") return `${prefix}: ${raw.slice(0, 40)}`;
|
|
344
|
-
return `${prefix}: ${String(raw)}`;
|
|
345
|
-
}
|
|
346
|
-
//#endregion
|
|
347
|
-
//#region src/ports/auth-cache.ts
|
|
348
|
-
var AuthCacheError = class extends Data.TaggedError("AuthCacheError") {};
|
|
349
|
-
var AuthCachePortTag = class extends Context.Tag("@capxul/sdk/ports/AuthCachePort")() {};
|
|
350
|
-
//#endregion
|
|
351
|
-
//#region src/adapters/auth-cache/serialization.ts
|
|
352
|
-
function parseAuthSession(raw) {
|
|
353
|
-
if (typeof raw !== "object" || raw === null) return null;
|
|
354
|
-
const candidate = raw;
|
|
355
|
-
try {
|
|
356
|
-
return {
|
|
357
|
-
authUserId: toAuthUserId(candidate.authUserId),
|
|
358
|
-
email: toEmail(candidate.email),
|
|
359
|
-
token: toSessionToken(candidate.token),
|
|
360
|
-
expiresAt: toEpochMs(candidate.expiresAt)
|
|
361
|
-
};
|
|
362
|
-
} catch {
|
|
363
|
-
return null;
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
function parseCachedJwt(raw) {
|
|
367
|
-
if (typeof raw !== "object" || raw === null) return null;
|
|
368
|
-
const candidate = raw;
|
|
369
|
-
try {
|
|
370
|
-
return {
|
|
371
|
-
token: toJwtToken(candidate.token),
|
|
372
|
-
expEpochSeconds: toEpochSeconds(candidate.expEpochSeconds)
|
|
373
|
-
};
|
|
374
|
-
} catch {
|
|
375
|
-
return null;
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
//#endregion
|
|
379
|
-
//#region src/adapters/auth-cache/BrowserAuthCacheAdapter.ts
|
|
380
|
-
const SESSION_KEY = "capxul.session";
|
|
381
|
-
const JWT_KEY = "capxul.jwt";
|
|
382
|
-
var BrowserAuthCacheAdapter = class {
|
|
383
|
-
storage;
|
|
384
|
-
constructor(storage) {
|
|
385
|
-
this.storage = storage;
|
|
386
|
-
}
|
|
387
|
-
getSession = authCacheTry("getSession", () => {
|
|
388
|
-
const raw = this.storage.getItem(SESSION_KEY);
|
|
389
|
-
if (raw === null) return null;
|
|
390
|
-
try {
|
|
391
|
-
return parseAuthSession(JSON.parse(raw));
|
|
392
|
-
} catch {
|
|
393
|
-
return null;
|
|
394
|
-
}
|
|
395
|
-
});
|
|
396
|
-
setSession = (session) => authCacheTry("setSession", () => {
|
|
397
|
-
this.storage.setItem(SESSION_KEY, JSON.stringify(session));
|
|
398
|
-
});
|
|
399
|
-
clearSession = authCacheTry("clearSession", () => {
|
|
400
|
-
this.storage.removeItem(SESSION_KEY);
|
|
401
|
-
});
|
|
402
|
-
getJwt = authCacheTry("getJwt", () => {
|
|
403
|
-
const raw = this.storage.getItem(JWT_KEY);
|
|
404
|
-
if (raw === null) return null;
|
|
405
|
-
try {
|
|
406
|
-
return parseCachedJwt(JSON.parse(raw));
|
|
407
|
-
} catch {
|
|
408
|
-
return null;
|
|
409
|
-
}
|
|
410
|
-
});
|
|
411
|
-
setJwt = (jwt) => authCacheTry("setJwt", () => {
|
|
412
|
-
this.storage.setItem(JWT_KEY, JSON.stringify(jwt));
|
|
413
|
-
});
|
|
414
|
-
clearJwt = authCacheTry("clearJwt", () => {
|
|
415
|
-
this.storage.removeItem(JWT_KEY);
|
|
416
|
-
});
|
|
417
|
-
};
|
|
418
|
-
function toAuthCacheError(operation, cause) {
|
|
419
|
-
return new AuthCacheError({
|
|
420
|
-
operation,
|
|
421
|
-
cause
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
function authCacheTry(operation, run) {
|
|
425
|
-
return Effect.try({
|
|
426
|
-
try: run,
|
|
427
|
-
catch: (cause) => toAuthCacheError(operation, cause)
|
|
428
|
-
});
|
|
429
|
-
}
|
|
430
|
-
//#endregion
|
|
431
|
-
//#region src/adapters/auth-cache/InMemoryAuthCacheAdapter.ts
|
|
432
|
-
var InMemoryAuthCacheAdapter = class {
|
|
433
|
-
session = null;
|
|
434
|
-
jwt = null;
|
|
435
|
-
getSession = Effect.sync(() => this.session);
|
|
436
|
-
setSession = (session) => Effect.sync(() => {
|
|
437
|
-
this.session = session;
|
|
438
|
-
});
|
|
439
|
-
clearSession = Effect.sync(() => {
|
|
440
|
-
this.session = null;
|
|
441
|
-
});
|
|
442
|
-
getJwt = Effect.sync(() => this.jwt);
|
|
443
|
-
setJwt = (jwt) => Effect.sync(() => {
|
|
444
|
-
this.jwt = jwt;
|
|
445
|
-
});
|
|
446
|
-
clearJwt = Effect.sync(() => {
|
|
447
|
-
this.jwt = null;
|
|
448
|
-
});
|
|
449
|
-
};
|
|
450
|
-
Layer.effect(AuthCachePortTag, Effect.sync(() => new InMemoryAuthCacheAdapter()).pipe(Effect.mapError((cause) => new AuthCacheError({
|
|
451
|
-
operation: "initialize",
|
|
452
|
-
cause
|
|
453
|
-
}))));
|
|
454
|
-
//#endregion
|
|
455
|
-
export { toSessionToken as A, toEpochSeconds as C, toPublishableKey as D, toOrgId as E, isCapxulError as F, decodeConvexError as M, CapxulError as N, toPublishableKeyId as O, Errors as P, toEpochMs as S, toKycTier as T, toChainId as _, AuthCacheError as a, toDurationMs as b, BYTES32_RE as c, toAccountId as d, toAddress as f, toAuthUserId as g, toAppId as h, parseCachedJwt as i, toSubAccountId as j, toRoleKey as k, EVM_ADDRESS_RE as l, toAnonymousDistinctId as m, BrowserAuthCacheAdapter as n, AuthCachePortTag as o, toAllowedOrigin as p, parseAuthSession as r, APP_ID_RE as s, InMemoryAuthCacheAdapter as t, SUPPORTED_CURRENCY_CODES as u, toCountryCode as v, toJwtToken as w, toEmail as x, toCurrencyCode as y };
|
|
456
|
-
|
|
457
|
-
//# sourceMappingURL=InMemoryAuthCacheAdapter-v5W-XB5M.mjs.map
|