@xkova/sdk 0.1.0-alpha.1

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 (76) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +453 -0
  3. package/dist/abi.d.ts +10288 -0
  4. package/dist/abi.js +6645 -0
  5. package/dist/client.d.ts +80 -0
  6. package/dist/client.js +251 -0
  7. package/dist/cursor.d.ts +21 -0
  8. package/dist/cursor.js +28 -0
  9. package/dist/errors.d.ts +31 -0
  10. package/dist/errors.js +63 -0
  11. package/dist/generated/types.d.ts +13371 -0
  12. package/dist/generated/types.js +3 -0
  13. package/dist/idempotency.d.ts +25 -0
  14. package/dist/idempotency.js +46 -0
  15. package/dist/index.d.ts +11 -0
  16. package/dist/index.js +8 -0
  17. package/dist/member-action-intents.d.ts +72 -0
  18. package/dist/member-action-intents.js +181 -0
  19. package/dist/member-bff.d.ts +535 -0
  20. package/dist/member-bff.js +1594 -0
  21. package/dist/member-resources.d.ts +203 -0
  22. package/dist/member-resources.js +56 -0
  23. package/dist/request-signing.d.ts +23 -0
  24. package/dist/request-signing.js +112 -0
  25. package/dist/resources/account-holders.d.ts +295 -0
  26. package/dist/resources/account-holders.js +166 -0
  27. package/dist/resources/base.d.ts +47 -0
  28. package/dist/resources/base.js +25 -0
  29. package/dist/resources/branding.d.ts +154 -0
  30. package/dist/resources/branding.js +34 -0
  31. package/dist/resources/chains.d.ts +6 -0
  32. package/dist/resources/chains.js +6 -0
  33. package/dist/resources/contacts.d.ts +55 -0
  34. package/dist/resources/contacts.js +22 -0
  35. package/dist/resources/escrows.d.ts +45 -0
  36. package/dist/resources/escrows.js +18 -0
  37. package/dist/resources/fee-schedules.d.ts +40 -0
  38. package/dist/resources/fee-schedules.js +15 -0
  39. package/dist/resources/index.d.ts +21 -0
  40. package/dist/resources/index.js +21 -0
  41. package/dist/resources/integration-gateways.d.ts +114 -0
  42. package/dist/resources/integration-gateways.js +27 -0
  43. package/dist/resources/onboarding.d.ts +18 -0
  44. package/dist/resources/onboarding.js +9 -0
  45. package/dist/resources/payment-requests.d.ts +115 -0
  46. package/dist/resources/payment-requests.js +27 -0
  47. package/dist/resources/payments.d.ts +182 -0
  48. package/dist/resources/payments.js +33 -0
  49. package/dist/resources/ramps.d.ts +163 -0
  50. package/dist/resources/ramps.js +44 -0
  51. package/dist/resources/rwa.d.ts +397 -0
  52. package/dist/resources/rwa.js +150 -0
  53. package/dist/resources/tenant.d.ts +136 -0
  54. package/dist/resources/tenant.js +42 -0
  55. package/dist/resources/tokenization.d.ts +394 -0
  56. package/dist/resources/tokenization.js +126 -0
  57. package/dist/resources/transactions.d.ts +8 -0
  58. package/dist/resources/transactions.js +6 -0
  59. package/dist/resources/wallets.d.ts +56 -0
  60. package/dist/resources/wallets.js +21 -0
  61. package/dist/resources/webhooks.d.ts +115 -0
  62. package/dist/resources/webhooks.js +43 -0
  63. package/dist/resources/workflows.d.ts +44 -0
  64. package/dist/resources/workflows.js +70 -0
  65. package/dist/resources/workspace-tokens.d.ts +6 -0
  66. package/dist/resources/workspace-tokens.js +6 -0
  67. package/dist/resources/workspaces.d.ts +25 -0
  68. package/dist/resources/workspaces.js +12 -0
  69. package/dist/retry.d.ts +21 -0
  70. package/dist/retry.js +44 -0
  71. package/dist/rwa-verify.d.ts +50 -0
  72. package/dist/rwa-verify.js +159 -0
  73. package/dist/webhook.d.ts +24 -0
  74. package/dist/webhook.js +56 -0
  75. package/llms.txt +84 -0
  76. package/package.json +62 -0
@@ -0,0 +1,126 @@
1
+ import { Resource } from './base.js';
2
+ export class TokenizationResource extends Resource {
3
+ deployErc20(body, opts) {
4
+ return this.postJson('/tokenization/erc20', body, opts);
5
+ }
6
+ deployErc721(body, opts) {
7
+ return this.postJson('/tokenization/erc721', body, opts);
8
+ }
9
+ deployErc1155(body, opts) {
10
+ return this.postJson('/tokenization/erc1155', body, opts);
11
+ }
12
+ list(query = {}) {
13
+ return this.getJson('/tokenization/tokens', query);
14
+ }
15
+ retrieve(id) {
16
+ return this.getJson(`/tokenization/tokens/${this.enc(id)}`);
17
+ }
18
+ mint(id, body, opts) {
19
+ return this.postJson(`/tokenization/tokens/${this.enc(id)}/mint`, body, opts);
20
+ }
21
+ burn(id, body, opts) {
22
+ return this.postJson(`/tokenization/tokens/${this.enc(id)}/burn`, body, opts);
23
+ }
24
+ listAuthorities(query = {}) {
25
+ return this.getJson('/tokenization/authorities', query);
26
+ }
27
+ registerAuthority(body, opts) {
28
+ return this.postJson('/tokenization/authorities', body, opts);
29
+ }
30
+ getAuthority(id) {
31
+ return this.getJson(`/tokenization/authorities/${this.enc(id)}`);
32
+ }
33
+ submitAuthorityProof(id, body, opts) {
34
+ return this.postJson(`/tokenization/authorities/${this.enc(id)}/proof`, body, opts);
35
+ }
36
+ issueAuthorityProofChallenge(id, opts) {
37
+ return this.postJson(`/tokenization/authorities/${this.enc(id)}/proof-challenge`, undefined, opts);
38
+ }
39
+ createControlSafe(body, opts) {
40
+ return this.postJson('/tokenization/authorities/control-safes', body, opts);
41
+ }
42
+ accessListAdd(id, body, opts) {
43
+ return this.postJson(`/tokenization/tokens/${this.enc(id)}/access-list/add`, body, opts);
44
+ }
45
+ accessListRemove(id, body, opts) {
46
+ return this.postJson(`/tokenization/tokens/${this.enc(id)}/access-list/remove`, body, opts);
47
+ }
48
+ enableAccessRegistry(id, body, opts) {
49
+ return this.postJson(`/tokenization/tokens/${this.enc(id)}/access-registry`, body, opts);
50
+ }
51
+ disableAccessRegistry(id, opts) {
52
+ return this.postJson(`/tokenization/tokens/${this.enc(id)}/access-registry/disable`, undefined, opts);
53
+ }
54
+ listContracts(id) {
55
+ return this.getJson(`/tokenization/tokens/${this.enc(id)}/contracts`);
56
+ }
57
+ read(id, query) {
58
+ return this.getJson(`/tokenization/tokens/${this.enc(id)}/read`, query);
59
+ }
60
+ resumeDeploy(id, opts) {
61
+ return this.postJson(`/tokenization/tokens/${this.enc(id)}/deploy/resume`, undefined, opts);
62
+ }
63
+ deprecate(id, opts) {
64
+ return this.postJson(`/tokenization/tokens/${this.enc(id)}/deprecate`, undefined, opts);
65
+ }
66
+ relayGaslessTransfer(id, body, opts) {
67
+ return this.postJson(`/tokenization/tokens/${this.enc(id)}/gasless/relay`, body, opts);
68
+ }
69
+ buildGaslessTransferRequest(id, body, opts) {
70
+ return this.postJson(`/tokenization/tokens/${this.enc(id)}/gasless/transfer-request`, body, opts);
71
+ }
72
+ relayNftTransfer(id, body, opts) {
73
+ return this.postJson(`/tokenization/tokens/${this.enc(id)}/nft-transfers`, body, opts);
74
+ }
75
+ buildNftTransferRequest(id, body, opts) {
76
+ return this.postJson(`/tokenization/tokens/${this.enc(id)}/nft-transfers/build`, body, opts);
77
+ }
78
+ listOperations(id, query = {}) {
79
+ return this.getJson(`/tokenization/tokens/${this.enc(id)}/operations`, query);
80
+ }
81
+ getOperation(id, opId) {
82
+ return this.getJson(`/tokenization/tokens/${this.enc(id)}/operations/${this.enc(opId)}`);
83
+ }
84
+ submitModuleSignature(id, opId, body, opts) {
85
+ return this.postJson(`/tokenization/tokens/${this.enc(id)}/operations/${this.enc(opId)}/module-signature`, body, opts);
86
+ }
87
+ submitOperationSignature(id, opId, body, opts) {
88
+ return this.postJson(`/tokenization/tokens/${this.enc(id)}/operations/${this.enc(opId)}/signatures`, body, opts);
89
+ }
90
+ pause(id, opts) {
91
+ return this.postJson(`/tokenization/tokens/${this.enc(id)}/pause`, undefined, opts);
92
+ }
93
+ unpause(id, opts) {
94
+ return this.postJson(`/tokenization/tokens/${this.enc(id)}/unpause`, undefined, opts);
95
+ }
96
+ setMintPolicy(id, body, opts) {
97
+ return this.postJson(`/tokenization/tokens/${this.enc(id)}/policies`, body, opts);
98
+ }
99
+ revokeMintPolicy(id, body, opts) {
100
+ return this.postJson(`/tokenization/tokens/${this.enc(id)}/policies/revoke`, body, opts);
101
+ }
102
+ buildPolicyMint(id, body, opts) {
103
+ return this.postJson(`/tokenization/tokens/${this.enc(id)}/policy-mint`, body, opts);
104
+ }
105
+ rawSafeTx(id, body, opts) {
106
+ return this.postJson(`/tokenization/tokens/${this.enc(id)}/raw-safe-tx`, body, opts);
107
+ }
108
+ recover(id, body, opts) {
109
+ return this.postJson(`/tokenization/tokens/${this.enc(id)}/recover`, body, opts);
110
+ }
111
+ grantRole(id, body, opts) {
112
+ return this.postJson(`/tokenization/tokens/${this.enc(id)}/roles/grant`, body, opts);
113
+ }
114
+ revokeRole(id, body, opts) {
115
+ return this.postJson(`/tokenization/tokens/${this.enc(id)}/roles/revoke`, body, opts);
116
+ }
117
+ disableForTreasury(id, opts) {
118
+ return this.postJson(`/tokenization/tokens/${this.enc(id)}/treasury-disable`, undefined, opts);
119
+ }
120
+ enableForTreasury(id, body, opts) {
121
+ return this.postJson(`/tokenization/tokens/${this.enc(id)}/treasury-enable`, body, opts);
122
+ }
123
+ treasuryStatus(id) {
124
+ return this.getJson(`/tokenization/tokens/${this.enc(id)}/treasury-status`);
125
+ }
126
+ }
@@ -0,0 +1,8 @@
1
+ import { Resource, type Query } from './base.js';
2
+ export declare class TransactionsResource extends Resource {
3
+ list(query?: Query<'listTransactions'>): Promise<{
4
+ data: import("../generated/types.js").components["schemas"]["Transaction"][];
5
+ next_cursor: string | null;
6
+ has_more: boolean;
7
+ }>;
8
+ }
@@ -0,0 +1,6 @@
1
+ import { Resource } from './base.js';
2
+ export class TransactionsResource extends Resource {
3
+ list(query = {}) {
4
+ return this.getJson('/transactions', query);
5
+ }
6
+ }
@@ -0,0 +1,56 @@
1
+ import { Resource, type Query, type ReqBody } from './base.js';
2
+ import type { XKOVAMutationOptions } from '../client.js';
3
+ export declare class WalletsResource extends Resource {
4
+ retrieve(id: string): Promise<{
5
+ id: import("../generated/types.js").components["schemas"]["WalletId"];
6
+ tenant_id: string;
7
+ account_holder_id: import("../generated/types.js").components["schemas"]["AccountHolderId"];
8
+ address: string;
9
+ chain_id: string;
10
+ chain: import("../generated/types.js").components["schemas"]["ChainDescriptor"];
11
+ custody_model: "custodial" | "non_custodial";
12
+ provider: string;
13
+ state: "active" | "decommissioned";
14
+ monitoring_status: "pending_live" | "catching_up" | "ready" | "halted";
15
+ created_at: import("../generated/types.js").components["schemas"]["TimestampUtc"];
16
+ updated_at: import("../generated/types.js").components["schemas"]["TimestampUtc"];
17
+ }>;
18
+ balance(id: string, query: Query<'getWalletBalance'>): Promise<{
19
+ chain_id: number;
20
+ wallet: string;
21
+ token: string;
22
+ balance: string;
23
+ last_updated_block: string;
24
+ last_updated_tx: string;
25
+ }>;
26
+ listHistory(id: string, query?: Query<'listWalletHistory'>): Promise<{
27
+ data: import("../generated/types.js").components["schemas"]["WalletTransactionSummary"][];
28
+ next_cursor?: string | null;
29
+ has_more: boolean;
30
+ }>;
31
+ listLedger(id: string, query?: Query<'listWalletLedger'>): Promise<{
32
+ data: unknown[];
33
+ next_cursor: string | null;
34
+ has_more: boolean;
35
+ } & {
36
+ data?: import("../generated/types.js").components["schemas"]["LedgerEntry"][];
37
+ }>;
38
+ decommission(id: string, opts?: XKOVAMutationOptions): Promise<{
39
+ id: import("../generated/types.js").components["schemas"]["WalletId"];
40
+ tenant_id: string;
41
+ account_holder_id: import("../generated/types.js").components["schemas"]["AccountHolderId"];
42
+ address: string;
43
+ chain_id: string;
44
+ chain: import("../generated/types.js").components["schemas"]["ChainDescriptor"];
45
+ custody_model: "custodial" | "non_custodial";
46
+ provider: string;
47
+ state: "active" | "decommissioned";
48
+ monitoring_status: "pending_live" | "catching_up" | "ready" | "halted";
49
+ created_at: import("../generated/types.js").components["schemas"]["TimestampUtc"];
50
+ updated_at: import("../generated/types.js").components["schemas"]["TimestampUtc"];
51
+ }>;
52
+ generateReceiveQr(id: string, body?: ReqBody<'generateReceiveQr'>, opts?: XKOVAMutationOptions): Promise<{
53
+ uri?: string;
54
+ png_data_url?: string;
55
+ }>;
56
+ }
@@ -0,0 +1,21 @@
1
+ import { Resource } from './base.js';
2
+ export class WalletsResource extends Resource {
3
+ retrieve(id) {
4
+ return this.getJson(`/wallets/${this.enc(id)}`);
5
+ }
6
+ balance(id, query) {
7
+ return this.getJson(`/wallets/${this.enc(id)}/balance`, query);
8
+ }
9
+ listHistory(id, query = {}) {
10
+ return this.getJson(`/wallets/${this.enc(id)}/history`, query);
11
+ }
12
+ listLedger(id, query = {}) {
13
+ return this.getJson(`/wallets/${this.enc(id)}/ledger`, query);
14
+ }
15
+ decommission(id, opts) {
16
+ return this.postJson(`/wallets/${this.enc(id)}/decommission`, undefined, opts);
17
+ }
18
+ generateReceiveQr(id, body = {}, opts) {
19
+ return this.postJson(`/wallets/${this.enc(id)}/qr`, body, opts);
20
+ }
21
+ }
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Verify incoming deliveries with `verifyWebhookSignature` from
3
+ * `@xkova/sdk/webhook` before processing them. It checks HMAC-SHA256 signatures.
4
+ */
5
+ import { Resource, type ReqBody, type Query } from './base.js';
6
+ import type { XKOVAMutationOptions } from '../client.js';
7
+ export declare class WebhooksResource extends Resource {
8
+ list(query?: Query<'listWebhookEndpoints'>): Promise<{
9
+ data: unknown[];
10
+ next_cursor: string | null;
11
+ has_more: boolean;
12
+ } & {
13
+ data?: import("../generated/types.js").components["schemas"]["WebhookEndpoint"][];
14
+ }>;
15
+ create(body: ReqBody<'createWebhookEndpoint'>, opts?: XKOVAMutationOptions): Promise<{
16
+ id?: import("../generated/types.js").components["schemas"]["WebhookEndpointId"];
17
+ url?: string;
18
+ events?: string[];
19
+ hmac_secret_fingerprint?: string;
20
+ previous_hmac_secret_fingerprint?: string | null;
21
+ previous_secret_retired_at?: import("../generated/types.js").components["schemas"]["TimestampUtc"] | null;
22
+ enabled?: boolean;
23
+ created_at?: import("../generated/types.js").components["schemas"]["TimestampUtc"];
24
+ updated_at?: import("../generated/types.js").components["schemas"]["TimestampUtc"];
25
+ } & {
26
+ secret?: string;
27
+ }>;
28
+ retrieve(id: string): Promise<{
29
+ id?: import("../generated/types.js").components["schemas"]["WebhookEndpointId"];
30
+ url?: string;
31
+ events?: string[];
32
+ hmac_secret_fingerprint?: string;
33
+ previous_hmac_secret_fingerprint?: string | null;
34
+ previous_secret_retired_at?: import("../generated/types.js").components["schemas"]["TimestampUtc"] | null;
35
+ enabled?: boolean;
36
+ created_at?: import("../generated/types.js").components["schemas"]["TimestampUtc"];
37
+ updated_at?: import("../generated/types.js").components["schemas"]["TimestampUtc"];
38
+ }>;
39
+ update(id: string, body: ReqBody<'updateWebhookEndpoint'>, opts?: XKOVAMutationOptions): Promise<{
40
+ id?: import("../generated/types.js").components["schemas"]["WebhookEndpointId"];
41
+ url?: string;
42
+ events?: string[];
43
+ hmac_secret_fingerprint?: string;
44
+ previous_hmac_secret_fingerprint?: string | null;
45
+ previous_secret_retired_at?: import("../generated/types.js").components["schemas"]["TimestampUtc"] | null;
46
+ enabled?: boolean;
47
+ created_at?: import("../generated/types.js").components["schemas"]["TimestampUtc"];
48
+ updated_at?: import("../generated/types.js").components["schemas"]["TimestampUtc"];
49
+ }>;
50
+ delete(id: string, opts?: XKOVAMutationOptions): Promise<void>;
51
+ rotateSecret(id: string, opts?: XKOVAMutationOptions): Promise<{
52
+ id?: import("../generated/types.js").components["schemas"]["WebhookEndpointId"];
53
+ url?: string;
54
+ events?: string[];
55
+ hmac_secret_fingerprint?: string;
56
+ previous_hmac_secret_fingerprint?: string | null;
57
+ previous_secret_retired_at?: import("../generated/types.js").components["schemas"]["TimestampUtc"] | null;
58
+ enabled?: boolean;
59
+ created_at?: import("../generated/types.js").components["schemas"]["TimestampUtc"];
60
+ updated_at?: import("../generated/types.js").components["schemas"]["TimestampUtc"];
61
+ } & {
62
+ secret?: string;
63
+ }>;
64
+ test(id: string, opts?: XKOVAMutationOptions): Promise<{
65
+ delivered: boolean;
66
+ status_code: number | null;
67
+ duration_ms: number;
68
+ error: string | null;
69
+ }>;
70
+ listEventTypes(): Promise<{
71
+ data?: import("../generated/types.js").components["schemas"]["WebhookEventType"][];
72
+ }>;
73
+ listDeliveries(query?: Query<'listWebhookDeliveries'>): Promise<{
74
+ data: unknown[];
75
+ next_cursor: string | null;
76
+ has_more: boolean;
77
+ } & {
78
+ data?: import("../generated/types.js").components["schemas"]["WebhookDelivery"][];
79
+ }>;
80
+ retrieveDelivery(id: string): Promise<{
81
+ id?: import("../generated/types.js").components["schemas"]["WebhookDeliveryId"];
82
+ webhook_endpoint_id?: import("../generated/types.js").components["schemas"]["WebhookEndpointId"];
83
+ event?: string;
84
+ payload?: import("../generated/types.js").components["schemas"]["WebhookEventEnvelope"];
85
+ attempt_count?: number;
86
+ status?: "pending" | "delivered" | "failed" | "dlq";
87
+ last_status_code?: number | null;
88
+ last_response_body?: string | null;
89
+ next_retry_at?: import("../generated/types.js").components["schemas"]["TimestampUtc"] | null;
90
+ delivered_at?: import("../generated/types.js").components["schemas"]["TimestampUtc"] | null;
91
+ correlation_id?: import("../generated/types.js").components["schemas"]["CorrelationId"];
92
+ created_at?: import("../generated/types.js").components["schemas"]["TimestampUtc"];
93
+ updated_at?: import("../generated/types.js").components["schemas"]["TimestampUtc"];
94
+ }>;
95
+ replayDelivery(id: string, opts?: XKOVAMutationOptions): Promise<{
96
+ id?: import("../generated/types.js").components["schemas"]["WebhookDeliveryId"];
97
+ webhook_endpoint_id?: import("../generated/types.js").components["schemas"]["WebhookEndpointId"];
98
+ event?: string;
99
+ payload?: import("../generated/types.js").components["schemas"]["WebhookEventEnvelope"];
100
+ attempt_count?: number;
101
+ status?: "pending" | "delivered" | "failed" | "dlq";
102
+ last_status_code?: number | null;
103
+ last_response_body?: string | null;
104
+ next_retry_at?: import("../generated/types.js").components["schemas"]["TimestampUtc"] | null;
105
+ delivered_at?: import("../generated/types.js").components["schemas"]["TimestampUtc"] | null;
106
+ correlation_id?: import("../generated/types.js").components["schemas"]["CorrelationId"];
107
+ created_at?: import("../generated/types.js").components["schemas"]["TimestampUtc"];
108
+ updated_at?: import("../generated/types.js").components["schemas"]["TimestampUtc"];
109
+ }>;
110
+ bulkReplayDeliveries(body: ReqBody<'bulkReplayWebhookDeliveries'>, opts?: XKOVAMutationOptions): Promise<{
111
+ data: import("../generated/types.js").components["schemas"]["WebhookDelivery"][];
112
+ replayed_count: number;
113
+ skipped_count: number;
114
+ }>;
115
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Verify incoming deliveries with `verifyWebhookSignature` from
3
+ * `@xkova/sdk/webhook` before processing them. It checks HMAC-SHA256 signatures.
4
+ */
5
+ import { Resource } from './base.js';
6
+ export class WebhooksResource extends Resource {
7
+ list(query = {}) {
8
+ return this.getJson('/webhook-endpoints', query);
9
+ }
10
+ create(body, opts) {
11
+ return this.postJson('/webhook-endpoints', body, opts);
12
+ }
13
+ retrieve(id) {
14
+ return this.getJson(`/webhook-endpoints/${this.enc(id)}`);
15
+ }
16
+ update(id, body, opts) {
17
+ return this.patchJson(`/webhook-endpoints/${this.enc(id)}`, body, opts);
18
+ }
19
+ delete(id, opts) {
20
+ return this.deleteJson(`/webhook-endpoints/${this.enc(id)}`, opts);
21
+ }
22
+ rotateSecret(id, opts) {
23
+ return this.postJson(`/webhook-endpoints/${this.enc(id)}/rotate`, undefined, opts);
24
+ }
25
+ test(id, opts) {
26
+ return this.postJson(`/webhook-endpoints/${this.enc(id)}/test`, undefined, opts);
27
+ }
28
+ listEventTypes() {
29
+ return this.getJson('/webhook-event-types');
30
+ }
31
+ listDeliveries(query = {}) {
32
+ return this.getJson('/webhook-deliveries', query);
33
+ }
34
+ retrieveDelivery(id) {
35
+ return this.getJson(`/webhook-deliveries/${this.enc(id)}`);
36
+ }
37
+ replayDelivery(id, opts) {
38
+ return this.postJson(`/webhook-deliveries/${this.enc(id)}/replay`, undefined, opts);
39
+ }
40
+ bulkReplayDeliveries(body, opts) {
41
+ return this.postJson('/webhook-deliveries/bulk-replay', body, opts);
42
+ }
43
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Workflow helpers call resource methods and poll their results. Member
3
+ * signing requires a separate authorization through `@xkova/sdk/member-bff`.
4
+ */
5
+ import type { XKOVAClient, XKOVAMutationOptions } from '../client.js';
6
+ import type { Ok, ReqBody } from './base.js';
7
+ export interface PollOptions {
8
+ /** Max poll attempts before giving up (default 30). */
9
+ attempts?: number;
10
+ /** Delay between attempts in ms (default 2000). */
11
+ intervalMs?: number;
12
+ /** Cancels polling and any pending interval. */
13
+ signal?: AbortSignal;
14
+ }
15
+ export declare class WorkflowClient {
16
+ private readonly client;
17
+ constructor(client: XKOVAClient);
18
+ /**
19
+ * Deploy a token and wait for on-chain confirmation.
20
+ * The deploy poller auto-registers the token on the payment router.
21
+ */
22
+ tokenDeploy(standard: 'erc20', body: ReqBody<'deployCustomerErc20'>, opts?: XKOVAMutationOptions & {
23
+ poll?: PollOptions;
24
+ }): Promise<Ok<'getCustomerToken'>>;
25
+ tokenDeploy(standard: 'erc721', body: ReqBody<'deployCustomerErc721'>, opts?: XKOVAMutationOptions & {
26
+ poll?: PollOptions;
27
+ }): Promise<Ok<'getCustomerToken'>>;
28
+ tokenDeploy(standard: 'erc1155', body: ReqBody<'deployCustomerErc1155'>, opts?: XKOVAMutationOptions & {
29
+ poll?: PollOptions;
30
+ }): Promise<Ok<'getCustomerToken'>>;
31
+ /** Mint to a holder and wait for confirmation. */
32
+ tokenMint(tokenId: string, body: ReqBody<'mintCustomerToken'>, opts?: XKOVAMutationOptions & {
33
+ poll?: PollOptions;
34
+ }): Promise<Ok<'getCustomerToken'>>;
35
+ /**
36
+ * Off-ramp: resolve the burn address and create the request. The member then
37
+ * burns stablecoin to the returned address out-of-band; poll
38
+ * `client.ramps.getOffRamp(id)` for settlement.
39
+ */
40
+ offRampInitiate(chainRef: string, body: ReqBody<'createOffRampRequest'>, opts?: XKOVAMutationOptions): Promise<{
41
+ request: Ok<'createOffRampRequest'>;
42
+ burnAddress: Ok<'getOffRampBurnAddress'>;
43
+ }>;
44
+ }
@@ -0,0 +1,70 @@
1
+ const DEFAULT_POLL = { attempts: 30, intervalMs: 2000 };
2
+ const SUCCESS = new Set(['confirmed', 'completed', 'settled', 'succeeded', 'deployed', 'active']);
3
+ const FAILURE = new Set(['failed', 'reverted', 'cancelled', 'canceled', 'expired', 'rejected']);
4
+ export class WorkflowClient {
5
+ client;
6
+ constructor(client) {
7
+ this.client = client;
8
+ }
9
+ async tokenDeploy(standard, body, opts = {}) {
10
+ const t = this.client.tokenization;
11
+ const deployed = standard === 'erc20'
12
+ ? await t.deployErc20(body, opts)
13
+ : standard === 'erc721'
14
+ ? await t.deployErc721(body, opts)
15
+ : await t.deployErc1155(body, opts);
16
+ const tokenId = readString(deployed, 'customer_token_id');
17
+ return pollEntity(() => t.retrieve(tokenId), pollOptions(opts.poll, opts.signal), 'token');
18
+ }
19
+ /** Mint to a holder and wait for confirmation. */
20
+ async tokenMint(tokenId, body, opts = {}) {
21
+ await this.client.tokenization.mint(tokenId, body, opts);
22
+ return pollEntity(() => this.client.tokenization.retrieve(tokenId), pollOptions(opts.poll, opts.signal), 'token');
23
+ }
24
+ /**
25
+ * Off-ramp: resolve the burn address and create the request. The member then
26
+ * burns stablecoin to the returned address out-of-band; poll
27
+ * `client.ramps.getOffRamp(id)` for settlement.
28
+ */
29
+ async offRampInitiate(chainRef, body, opts = {}) {
30
+ const burnAddress = await this.client.ramps.offRampBurnAddress({ chain_ref: chainRef });
31
+ const request = await this.client.ramps.createOffRamp(body, opts);
32
+ return { request, burnAddress };
33
+ }
34
+ }
35
+ function pollOptions(poll, signal) {
36
+ return { ...poll, ...(signal !== undefined && { signal }) };
37
+ }
38
+ function readString(obj, key) {
39
+ const v = obj?.[key];
40
+ if (typeof v !== 'string' || v.length === 0) {
41
+ throw new Error(`expected string field "${key}" on response`);
42
+ }
43
+ return v;
44
+ }
45
+ async function pollEntity(fetchOne, poll, label) {
46
+ const { attempts, intervalMs, signal } = { ...DEFAULT_POLL, ...poll };
47
+ let last;
48
+ for (let i = 0; i < attempts; i++) {
49
+ signal?.throwIfAborted();
50
+ last = await fetchOne();
51
+ const status = String(last?.['status'] ?? '');
52
+ if (SUCCESS.has(status))
53
+ return last;
54
+ if (FAILURE.has(status)) {
55
+ throw new Error(`${label} reached terminal failure status: ${status}`);
56
+ }
57
+ await sleep(intervalMs, signal);
58
+ }
59
+ throw new Error(`${label} did not reach a terminal status after ${attempts} attempts`);
60
+ }
61
+ function sleep(ms, signal) {
62
+ return new Promise((resolve, reject) => {
63
+ signal?.throwIfAborted();
64
+ const timer = setTimeout(resolve, ms);
65
+ signal?.addEventListener('abort', () => {
66
+ clearTimeout(timer);
67
+ reject(signal.reason);
68
+ }, { once: true });
69
+ });
70
+ }
@@ -0,0 +1,6 @@
1
+ import { Resource } from './base.js';
2
+ export declare class WorkspaceTokensResource extends Resource {
3
+ list(): Promise<{
4
+ data: import("../generated/types.js").components["schemas"]["WorkspaceToken"][];
5
+ }>;
6
+ }
@@ -0,0 +1,6 @@
1
+ import { Resource } from './base.js';
2
+ export class WorkspaceTokensResource extends Resource {
3
+ list() {
4
+ return this.getJson('/workspace-tokens');
5
+ }
6
+ }
@@ -0,0 +1,25 @@
1
+ import { Resource, type ReqBody } from './base.js';
2
+ import type { XKOVAMutationOptions } from '../client.js';
3
+ export declare class WorkspacesResource extends Resource {
4
+ list(): Promise<{
5
+ data: import("../generated/types.js").components["schemas"]["Workspace"][];
6
+ }>;
7
+ retrieve(id: string): Promise<{
8
+ id: string;
9
+ tenant_id: string;
10
+ type: "sandbox" | "production";
11
+ name?: string | null;
12
+ status: "pending_setup" | "active" | "archived";
13
+ created_at: import("../generated/types.js").components["schemas"]["TimestampUtc"];
14
+ updated_at: import("../generated/types.js").components["schemas"]["TimestampUtc"];
15
+ }>;
16
+ update(id: string, body: ReqBody<'updateWorkspace'>, opts?: XKOVAMutationOptions): Promise<{
17
+ id: string;
18
+ tenant_id: string;
19
+ type: "sandbox" | "production";
20
+ name?: string | null;
21
+ status: "pending_setup" | "active" | "archived";
22
+ created_at: import("../generated/types.js").components["schemas"]["TimestampUtc"];
23
+ updated_at: import("../generated/types.js").components["schemas"]["TimestampUtc"];
24
+ }>;
25
+ }
@@ -0,0 +1,12 @@
1
+ import { Resource } from './base.js';
2
+ export class WorkspacesResource extends Resource {
3
+ list() {
4
+ return this.getJson('/workspaces');
5
+ }
6
+ retrieve(id) {
7
+ return this.getJson(`/workspaces/${this.enc(id)}`);
8
+ }
9
+ update(id, body, opts) {
10
+ return this.patchJson(`/workspaces/${this.enc(id)}`, body, opts);
11
+ }
12
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Retries are explicit because a failed response can hide a successful write.
3
+ * For mutations, keep the input and idempotency key unchanged across attempts.
4
+ */
5
+ export interface RetryPolicy<E = unknown> {
6
+ /** Hard cap on attempts including the first. */
7
+ maxAttempts: number;
8
+ /** Delays between attempts. The last repeats if needed; an empty list means no delay. */
9
+ delaysMs: readonly number[];
10
+ /** Multiplicative jitter factor; default 0.25. Set to 0 for deterministic tests. */
11
+ jitter?: number;
12
+ /** Decide whether an error is worth retrying. Default: every error retries. */
13
+ isRetryable?: (err: E) => boolean;
14
+ /** Runs after a retryable failure, before the next attempt. */
15
+ onAttempt?: (attempt: number, err: E) => void;
16
+ /** Hook for logging/metrics when retries are exhausted. */
17
+ onExhausted?: (err: E) => void;
18
+ /** Override the timer to avoid real delays in tests. */
19
+ sleep?: (ms: number) => Promise<void>;
20
+ }
21
+ export declare function withRetry<T, E = unknown>(fn: () => Promise<T>, policy: RetryPolicy<E>): Promise<T>;
package/dist/retry.js ADDED
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Retries are explicit because a failed response can hide a successful write.
3
+ * For mutations, keep the input and idempotency key unchanged across attempts.
4
+ */
5
+ export async function withRetry(fn, policy) {
6
+ if (policy.maxAttempts < 1) {
7
+ throw new Error('withRetry: maxAttempts must be >= 1');
8
+ }
9
+ const sleep = policy.sleep ?? defaultSleep;
10
+ const isRetryable = policy.isRetryable ?? (() => true);
11
+ const jitter = policy.jitter ?? 0.25;
12
+ let lastErr;
13
+ for (let attempt = 1; attempt <= policy.maxAttempts; attempt += 1) {
14
+ try {
15
+ return await fn();
16
+ }
17
+ catch (err) {
18
+ lastErr = err;
19
+ if (!isRetryable(lastErr))
20
+ throw err;
21
+ if (attempt === policy.maxAttempts)
22
+ break;
23
+ policy.onAttempt?.(attempt, lastErr);
24
+ const baseDelay = pickDelay(policy.delaysMs, attempt - 1);
25
+ await sleep(applyJitter(baseDelay, jitter));
26
+ }
27
+ }
28
+ policy.onExhausted?.(lastErr);
29
+ throw lastErr;
30
+ }
31
+ function pickDelay(delays, idx) {
32
+ if (delays.length === 0)
33
+ return 0;
34
+ return delays[Math.min(idx, delays.length - 1)] ?? 0;
35
+ }
36
+ function applyJitter(baseMs, factor) {
37
+ if (factor <= 0)
38
+ return baseMs;
39
+ const delta = baseMs * factor;
40
+ return Math.max(0, baseMs + (Math.random() * 2 - 1) * delta);
41
+ }
42
+ function defaultSleep(ms) {
43
+ return new Promise((resolve) => setTimeout(resolve, ms));
44
+ }