@certen.io/sdk 0.2.0

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.
Files changed (56) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/LICENSE +21 -0
  3. package/README.md +117 -0
  4. package/dist/client.d.ts +79 -0
  5. package/dist/client.d.ts.map +1 -0
  6. package/dist/client.js +179 -0
  7. package/dist/client.js.map +1 -0
  8. package/dist/errors.d.ts +35 -0
  9. package/dist/errors.d.ts.map +1 -0
  10. package/dist/errors.js +61 -0
  11. package/dist/errors.js.map +1 -0
  12. package/dist/index.d.ts +5 -0
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +4 -0
  15. package/dist/index.js.map +1 -0
  16. package/dist/internal.d.ts +10 -0
  17. package/dist/internal.d.ts.map +1 -0
  18. package/dist/internal.js +16 -0
  19. package/dist/internal.js.map +1 -0
  20. package/dist/resources/admin.d.ts +34 -0
  21. package/dist/resources/admin.d.ts.map +1 -0
  22. package/dist/resources/admin.js +64 -0
  23. package/dist/resources/admin.js.map +1 -0
  24. package/dist/resources/execute.d.ts +117 -0
  25. package/dist/resources/execute.d.ts.map +1 -0
  26. package/dist/resources/execute.js +158 -0
  27. package/dist/resources/execute.js.map +1 -0
  28. package/dist/resources/governance.d.ts +16 -0
  29. package/dist/resources/governance.d.ts.map +1 -0
  30. package/dist/resources/governance.js +35 -0
  31. package/dist/resources/governance.js.map +1 -0
  32. package/dist/resources/identity.d.ts +32 -0
  33. package/dist/resources/identity.d.ts.map +1 -0
  34. package/dist/resources/identity.js +59 -0
  35. package/dist/resources/identity.js.map +1 -0
  36. package/dist/resources/pending.d.ts +8 -0
  37. package/dist/resources/pending.d.ts.map +1 -0
  38. package/dist/resources/pending.js +19 -0
  39. package/dist/resources/pending.js.map +1 -0
  40. package/dist/resources/portfolio.d.ts +8 -0
  41. package/dist/resources/portfolio.d.ts.map +1 -0
  42. package/dist/resources/portfolio.js +13 -0
  43. package/dist/resources/portfolio.js.map +1 -0
  44. package/dist/resources/sign.d.ts +9 -0
  45. package/dist/resources/sign.d.ts.map +1 -0
  46. package/dist/resources/sign.js +26 -0
  47. package/dist/resources/sign.js.map +1 -0
  48. package/dist/resources/transaction.d.ts +22 -0
  49. package/dist/resources/transaction.d.ts.map +1 -0
  50. package/dist/resources/transaction.js +51 -0
  51. package/dist/resources/transaction.js.map +1 -0
  52. package/dist/types.d.ts +327 -0
  53. package/dist/types.d.ts.map +1 -0
  54. package/dist/types.js +3 -0
  55. package/dist/types.js.map +1 -0
  56. package/package.json +67 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,65 @@
1
+ # Changelog — @certen.io/sdk
2
+
3
+ ## 0.2.0 — first published version
4
+
5
+ **0.1.0 was never published.** Three of its methods could not work against the live API. They were found
6
+ while preparing the package for release, by comparing what the SDK sends against the gateway's own OpenAPI
7
+ spec. Nothing in the existing test suite could have caught them: those tests exercise retry, idempotency,
8
+ and error mapping against a local mock that accepts any body, and a mock answering 200 to anything will
9
+ never tell you the request was wrong.
10
+
11
+ ### Fixed — methods that could not work
12
+
13
+ - **`transaction.create` sent no `intent`.** It sent a flat `{ type, to, amount, token, chain, memo }` body.
14
+ `POST /v1/transaction` requires `identity_id` and `intent`, and accepts none of those six fields — so every
15
+ call returned 400. Now takes `{ identityId, intent, contractAddresses?, proofClass?, signerKeyPage?,
16
+ signerPublicKey?, idempotencyKey? }`, matching the API, including multi-leg and `contractCall` intents.
17
+ - **`governance.create` omitted both required fields.** It sent `{ identity_id, operation_type, payload }`;
18
+ the API requires `identity` (the ADI, not a uuid) and `operations` (an **array**, so several changes are
19
+ authorized under one quorum). Every call returned 400.
20
+ - **`identity.list` called a route that does not exist.** `GET /v1/identities` returns 404 — the gateway has
21
+ no plural collection route. **Removed** rather than shipped as a dead method. Track the ids you create.
22
+
23
+ ### Fixed — silent no-ops
24
+
25
+ - **`identity.create` no longer sends `webhook_url`.** `POST /v1/identity` does not accept it, and Fastify
26
+ strips unknown properties, so the option did nothing while appearing to work. Set it via `identity.update()`,
27
+ which does accept it. `create` now also supports `signingMode`, `signingProvider`, and `idempotencyKey`.
28
+ - **`identity.get` no longer sends an `include` query parameter.** The route takes none; it was ignored.
29
+
30
+ ### Added
31
+
32
+ - **`identity.retire(id)`** — `DELETE /v1/identity/{id}`, which frees the org's identity quota. Soft delete
33
+ inside Certen only: the on-chain ADI, key book, and key page are untouched.
34
+ - **`DEFAULT_BASE_URL` is exported**, and the base URL now resolves `options.baseUrl` → `$CERTEN_API_URL` →
35
+ `https://gateway.kompendium.co`. The previous default was `https://api.certen.io`, which resolves — to the
36
+ Certen marketing site. A client built without an explicit `baseUrl` returned HTML for every call.
37
+ - **`test/contract.test.ts`** — validates the request every method produces against a vendored snapshot of
38
+ the gateway's OpenAPI spec: path exists, method exists, required fields present, no field the endpoint
39
+ would strip. This is the guard that would have caught all of the above. Refresh it with the command at the
40
+ bottom of this file when the API changes.
41
+ - Publish metadata: `files`, `exports`, `engines`, repository, keywords, `prepack` build, README, LICENSE.
42
+
43
+ ### Changed
44
+
45
+ - `license` corrected to **MIT**. `package.json` claimed Apache-2.0 while `LICENSE` is MIT.
46
+
47
+ ## Also fixed, in the gateway
48
+
49
+ Six routes — `/v1/transactions`, `/v1/pending`, `/v1/portfolio`, `/v1/admin/usage`, `/v1/admin/audit-log`,
50
+ and `/v1/admin/webhooks/deliveries` — read query parameters but declared no `querystring` schema, so
51
+ `@fastify/swagger` emitted no `parameters` and the spec reported that they took none.
52
+
53
+ The routes worked. The damage was to everyone reading the spec instead of the source: a client generated
54
+ from it had no paging at all, and `/v1/pending` silently lost the `identity` and `category` filters a signer
55
+ needs to find its own work. All six now declare their parameters, guarded on both sides —
56
+ `test/integration/openapi-snapshot.test.ts` in the gateway, and `test/contract.test.ts` here.
57
+
58
+ Refresh this package's contract fixture after an API change, from the gateway root:
59
+
60
+ ```bash
61
+ REGEN_SDK_CONTRACT=1 npx vitest run test/integration/openapi-snapshot.test.ts
62
+ ```
63
+
64
+ The fixture is generated from `buildServer()` rather than from the deployed gateway on purpose: the SDK
65
+ must be tested against the code it ships beside, not against whatever happens to be live.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Certen IO
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,117 @@
1
+ # @certen.io/sdk
2
+
3
+ TypeScript client for the [CERTEN Gateway](https://gateway.kompendium.co/reference) — proof-gated
4
+ cross-chain execution on Accumulate.
5
+
6
+ ```bash
7
+ npm install @certen.io/sdk
8
+ ```
9
+
10
+ ```ts
11
+ import { CertenClient } from '@certen.io/sdk';
12
+
13
+ const certen = new CertenClient({ apiKey: process.env.CERTEN_API_KEY! });
14
+
15
+ const { intent_id, signing_data, submit_url } = await certen.transaction.create({
16
+ identity_id: identityId,
17
+ intent: {
18
+ fromChain: 'accumulate',
19
+ toChain: 'ethereum-sepolia',
20
+ fromAddress: 'acc://your-org.acme',
21
+ toAddress: '0xBe00…9251',
22
+ amount: '4000',
23
+ tokenSymbol: 'ETH',
24
+ },
25
+ });
26
+
27
+ // You hold the key. Sign the bytes the gateway hands you.
28
+ const signature = sign(signing_data.hash_to_sign);
29
+ await certen.transaction.submitSignature(intent_id, { signature, public_key: publicKey });
30
+ ```
31
+
32
+ **Your key never leaves your process.** The gateway computes what must be signed and you decide whether to
33
+ sign it. That is the supported posture for anything carrying value — see
34
+ [the external-signing guide](../../docs/guides/external-signing.md).
35
+
36
+ ---
37
+
38
+ ## Configuration
39
+
40
+ ```ts
41
+ new CertenClient({
42
+ apiKey: 'ck_live_…', // required
43
+ baseUrl: 'https://…', // optional — see precedence below
44
+ maxRetries: 3, // default 3
45
+ baseBackoffMs: 250,
46
+ maxBackoffMs: 8_000,
47
+ autoIdempotencyKey: true, // default: every POST gets one
48
+ });
49
+ ```
50
+
51
+ **Base URL precedence:** `options.baseUrl` → `$CERTEN_API_URL` → `https://gateway.kompendium.co`. The env var
52
+ is there so a deployment can be retargeted at staging or a self-hosted gateway without a code change.
53
+
54
+ ## What it does for you
55
+
56
+ **Automatic idempotency on POSTs.** Every POST gets a generated `Idempotency-Key` so a retried network error
57
+ is safe to replay. This matters more than it sounds: without one, a timeout is indistinguishable from success,
58
+ and a blind retry can open a second intent or burn identity quota. Opt out per-client with
59
+ `autoIdempotencyKey: false`, or per-route with `noAutoIdempotencyRoutes`.
60
+
61
+ **Retries with backoff, and rate-limit awareness.** Transient failures retry with exponential backoff. On a
62
+ `429` the client remembers the reset window and pre-emptively waits rather than hammering.
63
+
64
+ **Typed errors.** Catch the class you care about instead of matching on status codes:
65
+
66
+ ```ts
67
+ import { CertenAuthError, CertenRateLimitError, CertenBadRequestError, CertenServerError } from '@certen.io/sdk';
68
+
69
+ try {
70
+ await certen.identity.create({ … });
71
+ } catch (e) {
72
+ if (e instanceof CertenBadRequestError) { /* your request — fix and retry */ }
73
+ if (e instanceof CertenRateLimitError) { /* back off; e carries the reset */ }
74
+ if (e instanceof CertenAuthError) { /* key is wrong, revoked, or lacks the scope */ }
75
+ if (e instanceof CertenServerError) { /* gateway or downstream — safe to retry */ }
76
+ }
77
+ ```
78
+
79
+ **Pagination helpers.** `paginate` and `paginateWithTotal` iterate a paged endpoint as an async generator.
80
+
81
+ ## Resources
82
+
83
+ | | |
84
+ |---|---|
85
+ | `certen.identity` | `create` · `get` · `update` · `retire` |
86
+ | `certen.transaction` | `create` · `submitSignature` · `get` · `list` |
87
+ | `certen.sign` | `create` · `submitSignature` |
88
+ | `certen.governance` | `create` · `submitSignature` · `get` |
89
+ | `certen.pending` | `list` |
90
+ | `certen.portfolio` | `get` |
91
+ | `certen.admin` | `createOrg` · `createApiKey` · `listApiKeys` · `revokeApiKey` · `rotateApiKey` · `getAuditLog` · `getUsage` |
92
+
93
+ The gateway serves ~80 endpoints; this covers the integration surface. For anything else, the
94
+ [live spec](https://gateway.kompendium.co/docs/json) is authoritative and the client's `request` path will
95
+ carry it.
96
+
97
+ ## Three things to know
98
+
99
+ **Identity creation is asynchronous.** `identity.create` resolves with a `202`-shaped result and provisioning
100
+ continues. Poll `identity.get` until the status is terminal, and check `can_sign` before building on it.
101
+
102
+ **A proof cycle takes ~60–110 seconds.** Real validator work, not a tunable delay. Do not wrap it in a 30s
103
+ timeout.
104
+
105
+ **`vote` is `approve` | `reject` | `abstain`** — a lowercase string, not a number, and not `accept`.
106
+
107
+ ## Guides
108
+
109
+ - [Onboard an identity](../../docs/guides/onboard-an-identity.md)
110
+ - [Sign while holding your own key](../../docs/guides/external-signing.md)
111
+ - [Proof-gate a contract call](../../docs/guides/proof-gated-contract-call.md)
112
+ - [M-of-N panels](../../docs/guides/multisig-panel.md)
113
+ - [Verify a proof](../../docs/guides/verify-a-proof.md)
114
+
115
+ ## License
116
+
117
+ MIT
@@ -0,0 +1,79 @@
1
+ import { IdentityResource } from './resources/identity.js';
2
+ import { TransactionResource } from './resources/transaction.js';
3
+ import { GovernanceResource } from './resources/governance.js';
4
+ import { PendingResource } from './resources/pending.js';
5
+ import { SignResource } from './resources/sign.js';
6
+ import { PortfolioResource } from './resources/portfolio.js';
7
+ import { AdminResource } from './resources/admin.js';
8
+ import { ExecuteResource } from './resources/execute.js';
9
+ import type { CertenClientOptions } from './types.js';
10
+ /**
11
+ * The gateway this SDK talks to when the caller does not say.
12
+ *
13
+ * It must be a host that actually serves the API. This default was `https://api.certen.io`, which resolves
14
+ * — to the Certen marketing site. So a client constructed without `baseUrl` returned HTML for every call,
15
+ * and the failure read as a broken SDK rather than a wrong address. Point it only at a host whose
16
+ * `/v1/health` answers.
17
+ *
18
+ * Precedence: `options.baseUrl` → `CERTEN_API_URL` → this. The env var exists so a deployment can be
19
+ * retargeted (staging, a self-hosted gateway, a future `api.certen.io` once it fronts the gateway) without
20
+ * a code change or an SDK release.
21
+ */
22
+ export declare const DEFAULT_BASE_URL = "https://gateway.kompendium.co";
23
+ export declare class CertenClient {
24
+ private http;
25
+ private rateLimit;
26
+ private maxRetries;
27
+ private baseBackoffMs;
28
+ private maxBackoffMs;
29
+ identity: IdentityResource;
30
+ transaction: TransactionResource;
31
+ governance: GovernanceResource;
32
+ pending: PendingResource;
33
+ sign: SignResource;
34
+ portfolio: PortfolioResource;
35
+ admin: AdminResource;
36
+ /** The proof-gated execution flow as one call: open, sign, submit, poll, prove. See resources/execute.ts. */
37
+ execute: ExecuteResource;
38
+ constructor(options: CertenClientOptions & {
39
+ maxRetries?: number;
40
+ baseBackoffMs?: number;
41
+ maxBackoffMs?: number;
42
+ /** When true (default), the SDK auto-generates an Idempotency-Key for
43
+ * every POST so a retried network error is safe to replay. Set false
44
+ * to opt out and supply your own key in request options. */
45
+ autoIdempotencyKey?: boolean;
46
+ /**
47
+ * Round-2 #42: opt out of auto-idempotency for specific routes (e.g.
48
+ * `'/v1/oauth/token'`, where the operation is naturally idempotent on
49
+ * the server side and the SDK-generated key would just waste DB rows).
50
+ *
51
+ * Each entry can be:
52
+ * - a literal path string (exact match against `req.url`),
53
+ * - a path prefix ending with `*` (`'/v1/admin/usage*'`),
54
+ * - or a RegExp.
55
+ */
56
+ skipIdempotencyFor?: Array<string | RegExp>;
57
+ });
58
+ }
59
+ /**
60
+ * Async iterator helper for paginated list endpoints. Round-2 #40:
61
+ * `paginateWithTotal` exposes `{ item, index, total }` for progress UIs that
62
+ * need to render "27 of 412". When the server doesn't return `total`, the
63
+ * yielded object's `total` is undefined.
64
+ *
65
+ * Use `paginate(...)` for the simple item-only form.
66
+ */
67
+ export declare function paginate<T>(fetchPage: (limit: number, offset: number) => Promise<{
68
+ items: T[];
69
+ total?: number;
70
+ }>, pageSize?: number): AsyncIterableIterator<T>;
71
+ export declare function paginateWithTotal<T>(fetchPage: (limit: number, offset: number) => Promise<{
72
+ items: T[];
73
+ total?: number;
74
+ }>, pageSize?: number): AsyncIterableIterator<{
75
+ item: T;
76
+ index: number;
77
+ total: number | undefined;
78
+ }>;
79
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gBAAgB,kCAAkC,CAAC;AAyBhE,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QAAQ,SAAM,GACb,qBAAqB,CAAC;IAAE,IAAI,EAAE,CAAC,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC,CAU9E"}
package/dist/client.js ADDED
@@ -0,0 +1,179 @@
1
+ import axios from 'axios';
2
+ import { randomBytes } from 'crypto';
3
+ import { CertenError } from './errors.js';
4
+ import { IdentityResource } from './resources/identity.js';
5
+ import { TransactionResource } from './resources/transaction.js';
6
+ import { GovernanceResource } from './resources/governance.js';
7
+ import { PendingResource } from './resources/pending.js';
8
+ import { SignResource } from './resources/sign.js';
9
+ import { PortfolioResource } from './resources/portfolio.js';
10
+ import { AdminResource } from './resources/admin.js';
11
+ import { ExecuteResource } from './resources/execute.js';
12
+ /**
13
+ * The gateway this SDK talks to when the caller does not say.
14
+ *
15
+ * It must be a host that actually serves the API. This default was `https://api.certen.io`, which resolves
16
+ * — to the Certen marketing site. So a client constructed without `baseUrl` returned HTML for every call,
17
+ * and the failure read as a broken SDK rather than a wrong address. Point it only at a host whose
18
+ * `/v1/health` answers.
19
+ *
20
+ * Precedence: `options.baseUrl` → `CERTEN_API_URL` → this. The env var exists so a deployment can be
21
+ * retargeted (staging, a self-hosted gateway, a future `api.certen.io` once it fronts the gateway) without
22
+ * a code change or an SDK release.
23
+ */
24
+ export const DEFAULT_BASE_URL = 'https://gateway.kompendium.co';
25
+ /** Read an env var without assuming `process` exists — this SDK also runs in browsers, where touching a
26
+ * bare `process` is a ReferenceError rather than `undefined`. */
27
+ function envBaseUrl() {
28
+ try {
29
+ return typeof process !== 'undefined' ? process.env?.CERTEN_API_URL || undefined : undefined;
30
+ }
31
+ catch {
32
+ return undefined;
33
+ }
34
+ }
35
+ const DEFAULT_MAX_RETRIES = 3;
36
+ const DEFAULT_BASE_BACKOFF_MS = 250;
37
+ const DEFAULT_MAX_BACKOFF_MS = 8_000;
38
+ export class CertenClient {
39
+ http;
40
+ rateLimit = { resetAt: null };
41
+ maxRetries;
42
+ baseBackoffMs;
43
+ maxBackoffMs;
44
+ identity;
45
+ transaction;
46
+ governance;
47
+ pending;
48
+ sign;
49
+ portfolio;
50
+ admin;
51
+ /** The proof-gated execution flow as one call: open, sign, submit, poll, prove. See resources/execute.ts. */
52
+ execute;
53
+ constructor(options) {
54
+ this.maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES;
55
+ this.baseBackoffMs = options.baseBackoffMs ?? DEFAULT_BASE_BACKOFF_MS;
56
+ this.maxBackoffMs = options.maxBackoffMs ?? DEFAULT_MAX_BACKOFF_MS;
57
+ this.http = axios.create({
58
+ baseURL: options.baseUrl ?? envBaseUrl() ?? DEFAULT_BASE_URL,
59
+ headers: {
60
+ 'X-API-Key': options.apiKey,
61
+ 'Content-Type': 'application/json',
62
+ 'User-Agent': `certen-sdk-node/${process.env.npm_package_version ?? 'dev'}`,
63
+ },
64
+ timeout: 30_000,
65
+ validateStatus: (status) => status >= 200 && status < 300,
66
+ });
67
+ const autoIdem = options.autoIdempotencyKey !== false;
68
+ const skipPatterns = options.skipIdempotencyFor ?? [];
69
+ const shouldSkip = (path) => {
70
+ for (const p of skipPatterns) {
71
+ if (typeof p === 'string') {
72
+ if (p.endsWith('*') ? path.startsWith(p.slice(0, -1)) : path === p)
73
+ return true;
74
+ }
75
+ else if (p instanceof RegExp && p.test(path)) {
76
+ return true;
77
+ }
78
+ }
79
+ return false;
80
+ };
81
+ // Auto-stamp Idempotency-Key on every POST that didn't already supply one.
82
+ this.http.interceptors.request.use(async (req) => {
83
+ const reqPath = req.url ?? '';
84
+ if (autoIdem && (req.method ?? 'GET').toUpperCase() === 'POST' && !shouldSkip(reqPath)) {
85
+ const headers = req.headers ?? {};
86
+ if (!('Idempotency-Key' in headers) && !('idempotency-key' in headers)) {
87
+ headers['Idempotency-Key'] = generateIdempotencyKey();
88
+ req.headers = headers;
89
+ }
90
+ }
91
+ // Respect any rate-limit reset window the gateway already told us about.
92
+ if (this.rateLimit.resetAt && Date.now() < this.rateLimit.resetAt) {
93
+ const wait = this.rateLimit.resetAt - Date.now();
94
+ await sleep(wait);
95
+ this.rateLimit.resetAt = null;
96
+ }
97
+ return req;
98
+ });
99
+ // Wrap errors into the typed taxonomy + retry transient failures.
100
+ this.http.interceptors.response.use((response) => {
101
+ // Update rate-limit state from headers if present.
102
+ const reset = response.headers['x-ratelimit-reset'];
103
+ if (typeof reset === 'string' && /^\d+$/.test(reset)) {
104
+ this.rateLimit.resetAt = Number(reset) * 1000;
105
+ }
106
+ return response;
107
+ }, async (error) => {
108
+ const cfg = error.config;
109
+ const status = error.response?.status ?? 0;
110
+ const code = error.response?.data?.code ?? (status === 0 ? 'NETWORK_ERROR' : 'UNKNOWN_ERROR');
111
+ const message = error.response?.data?.error ?? error.message;
112
+ const requestId = error.response?.headers?.['x-request-id'] ?? undefined;
113
+ const retryAfter = error.response?.headers?.['retry-after'];
114
+ const details = retryAfter ? { retryAfter: Number(retryAfter) } : undefined;
115
+ if (status === 429 && typeof retryAfter === 'string') {
116
+ this.rateLimit.resetAt = Date.now() + Number(retryAfter) * 1000;
117
+ }
118
+ const wrapped = CertenError.fromAxios(message, status, code, { requestId, details });
119
+ // Retry transient failures with exponential backoff + jitter.
120
+ if (cfg && wrapped.isRetryable) {
121
+ cfg.__retryCount = (cfg.__retryCount ?? 0) + 1;
122
+ if (cfg.__retryCount <= this.maxRetries) {
123
+ const backoff = Math.min(this.maxBackoffMs, this.baseBackoffMs * Math.pow(2, cfg.__retryCount - 1));
124
+ const jitter = Math.floor(Math.random() * backoff);
125
+ await sleep(backoff + jitter);
126
+ return this.http.request(cfg);
127
+ }
128
+ }
129
+ throw wrapped;
130
+ });
131
+ this.identity = new IdentityResource(this.http);
132
+ this.transaction = new TransactionResource(this.http);
133
+ this.governance = new GovernanceResource(this.http);
134
+ this.pending = new PendingResource(this.http);
135
+ this.sign = new SignResource(this.http);
136
+ this.portfolio = new PortfolioResource(this.http);
137
+ this.admin = new AdminResource(this.http);
138
+ this.execute = new ExecuteResource(this.http, generateIdempotencyKey);
139
+ }
140
+ }
141
+ function sleep(ms) {
142
+ return new Promise((r) => setTimeout(r, ms));
143
+ }
144
+ function generateIdempotencyKey() {
145
+ // Stable across retries within a process; unique across calls.
146
+ return `sdk_${Date.now().toString(36)}_${randomBytes(8).toString('hex')}`;
147
+ }
148
+ /**
149
+ * Async iterator helper for paginated list endpoints. Round-2 #40:
150
+ * `paginateWithTotal` exposes `{ item, index, total }` for progress UIs that
151
+ * need to render "27 of 412". When the server doesn't return `total`, the
152
+ * yielded object's `total` is undefined.
153
+ *
154
+ * Use `paginate(...)` for the simple item-only form.
155
+ */
156
+ export async function* paginate(fetchPage, pageSize = 100) {
157
+ let offset = 0;
158
+ for (;;) {
159
+ const { items } = await fetchPage(pageSize, offset);
160
+ for (const it of items)
161
+ yield it;
162
+ if (items.length < pageSize)
163
+ return;
164
+ offset += items.length;
165
+ }
166
+ }
167
+ export async function* paginateWithTotal(fetchPage, pageSize = 100) {
168
+ let offset = 0;
169
+ for (;;) {
170
+ const { items, total } = await fetchPage(pageSize, offset);
171
+ for (let i = 0; i < items.length; i++) {
172
+ yield { item: items[i], index: offset + i, total };
173
+ }
174
+ if (items.length < pageSize)
175
+ return;
176
+ offset += items.length;
177
+ }
178
+ }
179
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAwD,MAAM,OAAO,CAAC;AAC7E,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAA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;QACrD,CAAC;QACD,IAAI,KAAK,CAAC,MAAM,GAAG,QAAQ;YAAE,OAAO;QACpC,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC;IACzB,CAAC;AACH,CAAC"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Error taxonomy. `CertenError.code` mirrors the gateway's response.code
3
+ * field; callers can switch on it for typed retries / user-visible
4
+ * messages.
5
+ */
6
+ export declare class CertenError extends Error {
7
+ readonly status: number;
8
+ readonly code: string;
9
+ readonly requestId?: string;
10
+ readonly details?: unknown;
11
+ constructor(message: string, status: number, code: string, opts?: {
12
+ requestId?: string;
13
+ details?: unknown;
14
+ });
15
+ /** True for transient downstream errors that are safe to retry. */
16
+ get isRetryable(): boolean;
17
+ /** True for client-side input mistakes. Never auto-retry these. */
18
+ get isClientError(): boolean;
19
+ /** Convenience: standard error subclasses surface by status. */
20
+ static fromAxios(message: string, status: number, code: string, opts?: {
21
+ requestId?: string;
22
+ details?: unknown;
23
+ }): CertenError;
24
+ }
25
+ export declare class CertenAuthError extends CertenError {
26
+ }
27
+ export declare class CertenRateLimitError extends CertenError {
28
+ /** Reset window in seconds when the gateway sent Retry-After. */
29
+ get retryAfterSec(): number | undefined;
30
+ }
31
+ export declare class CertenBadRequestError extends CertenError {
32
+ }
33
+ export declare class CertenServerError extends CertenError {
34
+ }
35
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACpC,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnC,SAAgB,OAAO,CAAC,EAAE,OAAO,CAAC;gBAGhC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAO;IAUtD,mEAAmE;IACnE,IAAI,WAAW,IAAI,OAAO,CAMzB;IAED,mEAAmE;IACnE,IAAI,aAAa,IAAI,OAAO,CAE3B;IAED,gEAAgE;IAChE,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,WAAW;CAO/H;AAED,qBAAa,eAAgB,SAAQ,WAAW;CAAG;AACnD,qBAAa,oBAAqB,SAAQ,WAAW;IACnD,iEAAiE;IACjE,IAAI,aAAa,IAAI,MAAM,GAAG,SAAS,CAGtC;CACF;AACD,qBAAa,qBAAsB,SAAQ,WAAW;CAAG;AACzD,qBAAa,iBAAkB,SAAQ,WAAW;CAAG"}
package/dist/errors.js ADDED
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Error taxonomy. `CertenError.code` mirrors the gateway's response.code
3
+ * field; callers can switch on it for typed retries / user-visible
4
+ * messages.
5
+ */
6
+ export class CertenError extends Error {
7
+ status;
8
+ code;
9
+ requestId;
10
+ details;
11
+ constructor(message, status, code, opts = {}) {
12
+ super(message);
13
+ this.name = 'CertenError';
14
+ this.status = status;
15
+ this.code = code;
16
+ this.requestId = opts.requestId;
17
+ this.details = opts.details;
18
+ }
19
+ /** True for transient downstream errors that are safe to retry. */
20
+ get isRetryable() {
21
+ if (this.code === 'NETWORK_ERROR')
22
+ return true;
23
+ if (this.status >= 500 && this.status < 600)
24
+ return true;
25
+ if (this.status === 429)
26
+ return true;
27
+ if (this.status === 408)
28
+ return true;
29
+ return false;
30
+ }
31
+ /** True for client-side input mistakes. Never auto-retry these. */
32
+ get isClientError() {
33
+ return this.status >= 400 && this.status < 500 && this.status !== 408 && this.status !== 429;
34
+ }
35
+ /** Convenience: standard error subclasses surface by status. */
36
+ static fromAxios(message, status, code, opts) {
37
+ if (status === 401 || status === 403)
38
+ return new CertenAuthError(message, status, code, opts);
39
+ if (status === 429)
40
+ return new CertenRateLimitError(message, status, code, opts);
41
+ if (status >= 500)
42
+ return new CertenServerError(message, status, code, opts);
43
+ if (status >= 400)
44
+ return new CertenBadRequestError(message, status, code, opts);
45
+ return new CertenError(message, status, code, opts);
46
+ }
47
+ }
48
+ export class CertenAuthError extends CertenError {
49
+ }
50
+ export class CertenRateLimitError extends CertenError {
51
+ /** Reset window in seconds when the gateway sent Retry-After. */
52
+ get retryAfterSec() {
53
+ const v = this.details?.retryAfter;
54
+ return typeof v === 'number' ? v : undefined;
55
+ }
56
+ }
57
+ export class CertenBadRequestError extends CertenError {
58
+ }
59
+ export class CertenServerError extends CertenError {
60
+ }
61
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpB,MAAM,CAAS;IACf,IAAI,CAAS;IACb,SAAS,CAAU;IACnB,OAAO,CAAW;IAElC,YACE,OAAe,EACf,MAAc,EACd,IAAY,EACZ,OAAkD,EAAE;QAEpD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAChC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;IAC9B,CAAC;IAED,mEAAmE;IACnE,IAAI,WAAW;QACb,IAAI,IAAI,CAAC,IAAI,KAAK,eAAe;YAAE,OAAO,IAAI,CAAC;QAC/C,I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EAAiE;IACjE,IAAI,aAAa;QACf,MAAM,CAAC,GAAI,IAAI,CAAC,OAA+C,EAAE,UAAU,CAAC;QAC5E,OAAO,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/C,CAAC;CACF;AACD,MAAM,OAAO,qBAAsB,SAAQ,WAAW;CAAG;AACzD,MAAM,OAAO,iBAAkB,SAAQ,WAAW;CAAG"}
@@ -0,0 +1,5 @@
1
+ export { CertenClient, paginate, paginateWithTotal, DEFAULT_BASE_URL } from './client.js';
2
+ export * from './types.js';
3
+ export type { SignFn, ProofGatedCallParams, TransferParams, OpenedIntent } from './resources/execute.js';
4
+ export { CertenError, CertenAuthError, CertenRateLimitError, CertenBadRequestError, CertenServerError, } from './errors.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1F,cAAc,YAAY,CAAC;AAC3B,YAAY,EAAE,MAAM,EAAE,oBAAoB,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACzG,OAAO,EACL,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { CertenClient, paginate, paginateWithTotal, DEFAULT_BASE_URL } from './client.js';
2
+ export * from './types.js';
3
+ export { CertenError, CertenAuthError, CertenRateLimitError, CertenBadRequestError, CertenServerError, } from './errors.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1F,cAAc,YAAY,CAAC;AAE3B,OAAO,EACL,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,aAAa,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Strip keys whose value is `undefined` before sending a body.
3
+ *
4
+ * Fastify validates against a declared schema and strips properties it does not know, but an explicit
5
+ * `"field": null`-shaped absence is not the same as omission for an endpoint that treats presence as
6
+ * intent — and a body full of `undefined` keys serialises to nothing useful when debugging a request log.
7
+ * Building bodies through this keeps the wire payload exactly the set of fields the caller actually set.
8
+ */
9
+ export declare function omitUndefined<T extends Record<string, unknown>>(o: T): Partial<T>;
10
+ //# sourceMappingURL=internal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAIjF"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Strip keys whose value is `undefined` before sending a body.
3
+ *
4
+ * Fastify validates against a declared schema and strips properties it does not know, but an explicit
5
+ * `"field": null`-shaped absence is not the same as omission for an endpoint that treats presence as
6
+ * intent — and a body full of `undefined` keys serialises to nothing useful when debugging a request log.
7
+ * Building bodies through this keeps the wire payload exactly the set of fields the caller actually set.
8
+ */
9
+ export function omitUndefined(o) {
10
+ const out = {};
11
+ for (const [k, v] of Object.entries(o))
12
+ if (v !== undefined)
13
+ out[k] = v;
14
+ return out;
15
+ }
16
+ //# sourceMappingURL=internal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAoC,CAAI;IACnE,MAAM,GAAG,GAA4B,EAAE,CAAC;IACxC,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;QAAE,IAAI,CAAC,KAAK,SAAS;YAAE,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACxE,OAAO,GAAiB,CAAC;AAC3B,CAAC"}