@pacspace-io/sdk 0.1.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 (50) hide show
  1. package/README.md +192 -0
  2. package/dist/client.d.ts +61 -0
  3. package/dist/client.d.ts.map +1 -0
  4. package/dist/client.js +225 -0
  5. package/dist/client.js.map +1 -0
  6. package/dist/errors/index.d.ts +69 -0
  7. package/dist/errors/index.d.ts.map +1 -0
  8. package/dist/errors/index.js +126 -0
  9. package/dist/errors/index.js.map +1 -0
  10. package/dist/index.d.ts +64 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +68 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/resources/balance.d.ts +148 -0
  15. package/dist/resources/balance.d.ts.map +1 -0
  16. package/dist/resources/balance.js +231 -0
  17. package/dist/resources/balance.js.map +1 -0
  18. package/dist/types/balance.d.ts +218 -0
  19. package/dist/types/balance.d.ts.map +1 -0
  20. package/dist/types/balance.js +3 -0
  21. package/dist/types/balance.js.map +1 -0
  22. package/dist/types/common.d.ts +21 -0
  23. package/dist/types/common.d.ts.map +1 -0
  24. package/dist/types/common.js +3 -0
  25. package/dist/types/common.js.map +1 -0
  26. package/dist/types/config.d.ts +54 -0
  27. package/dist/types/config.d.ts.map +1 -0
  28. package/dist/types/config.js +3 -0
  29. package/dist/types/config.js.map +1 -0
  30. package/dist/utils/polling.d.ts +32 -0
  31. package/dist/utils/polling.d.ts.map +1 -0
  32. package/dist/utils/polling.js +56 -0
  33. package/dist/utils/polling.js.map +1 -0
  34. package/dist/utils/retry.d.ts +14 -0
  35. package/dist/utils/retry.d.ts.map +1 -0
  36. package/dist/utils/retry.js +21 -0
  37. package/dist/utils/retry.js.map +1 -0
  38. package/dist/webhooks/index.d.ts +3 -0
  39. package/dist/webhooks/index.d.ts.map +1 -0
  40. package/dist/webhooks/index.js +6 -0
  41. package/dist/webhooks/index.js.map +1 -0
  42. package/dist/webhooks/types.d.ts +99 -0
  43. package/dist/webhooks/types.d.ts.map +1 -0
  44. package/dist/webhooks/types.js +6 -0
  45. package/dist/webhooks/types.js.map +1 -0
  46. package/dist/webhooks/verify.d.ts +104 -0
  47. package/dist/webhooks/verify.d.ts.map +1 -0
  48. package/dist/webhooks/verify.js +167 -0
  49. package/dist/webhooks/verify.js.map +1 -0
  50. package/package.json +46 -0
@@ -0,0 +1,218 @@
1
+ import type { AnchorStatus, CheckpointType } from './common';
2
+ import type { RequestOptions } from './config';
3
+ /**
4
+ * Options for `balance.emit()`.
5
+ */
6
+ export interface EmitOptions extends RequestOptions {
7
+ /** Your internal reference ID for correlation. */
8
+ referenceId?: string;
9
+ /** Arbitrary key-value metadata to store with the delta. */
10
+ metadata?: Record<string, unknown>;
11
+ }
12
+ /**
13
+ * Options for `balance.emitAndWait()`.
14
+ */
15
+ export interface EmitAndWaitOptions extends EmitOptions {
16
+ /**
17
+ * Maximum time (ms) to wait for verification before throwing.
18
+ * @default 60000
19
+ */
20
+ timeout?: number;
21
+ /**
22
+ * Interval (ms) between status polls.
23
+ * @default 2000
24
+ */
25
+ pollInterval?: number;
26
+ }
27
+ /**
28
+ * Response from `balance.emit()`.
29
+ */
30
+ export interface EmitResponse {
31
+ /** Unique identifier for this anchor/delta record. */
32
+ anchorId: string;
33
+ /** The customer account this delta belongs to. */
34
+ customerId: string;
35
+ /** The recorded adjustment amount. */
36
+ delta: number;
37
+ /** Current processing status. */
38
+ status: AnchorStatus;
39
+ /** Proof root hash — store this for later verification. */
40
+ receiptId: string;
41
+ /** Root hash covering the items in this submission (same as receiptId). */
42
+ itemsRoot: string;
43
+ /** Individual content hashes for each item. */
44
+ itemHashes: string[];
45
+ /** Estimated number of verified deltas this submission will produce. */
46
+ estimatedVerifiedDeltas: number;
47
+ /** Estimated credits that will be consumed upon verification. */
48
+ estimatedCredits: number;
49
+ /** ISO 8601 timestamp of when the submission was received. */
50
+ receivedAt: string;
51
+ /** Human-readable status message. */
52
+ message: string;
53
+ }
54
+ /**
55
+ * Options for `balance.derive()`.
56
+ */
57
+ export interface DeriveOptions extends RequestOptions {
58
+ /**
59
+ * Starting balance to derive from.
60
+ * @default 0
61
+ */
62
+ startingBalance?: number;
63
+ /**
64
+ * Checkpoint value to start derivation from (avoids replaying from genesis).
65
+ * Use the `latestReceiptId` from a previous derivation response.
66
+ */
67
+ startingCheckpoint?: string;
68
+ /**
69
+ * Type of checkpoint provided.
70
+ * @default 'itemsRoot'
71
+ */
72
+ startingCheckpointType?: CheckpointType;
73
+ }
74
+ /**
75
+ * A single verified delta in the derivation response.
76
+ */
77
+ export interface VerifiedDelta {
78
+ anchorId: string;
79
+ itemHash: string;
80
+ itemsRoot: string;
81
+ receiptId: string;
82
+ delta: number;
83
+ reason: string | null;
84
+ referenceId: string | null;
85
+ window: string;
86
+ declaredTimestamp: string | null;
87
+ blockTimestamp: string | null;
88
+ dataPurged: boolean;
89
+ verified: true;
90
+ }
91
+ /**
92
+ * Summary of deltas within a time window.
93
+ */
94
+ export interface WindowSummary {
95
+ window: string;
96
+ deltasCount: number;
97
+ netDelta: number;
98
+ firstBlockTimestamp: string | null;
99
+ lastBlockTimestamp: string | null;
100
+ }
101
+ /**
102
+ * Response from `balance.derive()`.
103
+ */
104
+ export interface DeriveResponse {
105
+ customerId: string;
106
+ startingBalance: number;
107
+ startingCheckpoint: string;
108
+ startingCheckpointType: CheckpointType;
109
+ deltasCount: number;
110
+ computedBalance: number;
111
+ latestCheckpoint: string | null;
112
+ latestReceiptId: string | null;
113
+ deltas: VerifiedDelta[];
114
+ windowSummaries: WindowSummary[];
115
+ verificationProof: {
116
+ itemsRoot: string | null;
117
+ message: string;
118
+ };
119
+ }
120
+ /**
121
+ * Options for `balance.compare()`.
122
+ */
123
+ export interface CompareOptions extends RequestOptions {
124
+ /**
125
+ * Starting balance for derivation.
126
+ * @default 0
127
+ */
128
+ startingBalance?: number;
129
+ /** Checkpoint to start comparison from. */
130
+ startingCheckpoint?: string;
131
+ /** Type of checkpoint provided. */
132
+ startingCheckpointType?: CheckpointType;
133
+ }
134
+ /**
135
+ * Balances to compare — your view vs. their view.
136
+ */
137
+ export interface CompareBalances {
138
+ /** Your calculated balance. */
139
+ yours: number;
140
+ /** Customer's claimed balance. */
141
+ theirs: number;
142
+ }
143
+ /**
144
+ * Discrepancy details when balances don't match.
145
+ */
146
+ export interface DiscrepancyReport {
147
+ amount: number;
148
+ resolution: string;
149
+ divergentParty: 'yours' | 'theirs' | 'both';
150
+ windowsToReview: Array<{
151
+ window: string;
152
+ netDelta: number;
153
+ deltasCount: number;
154
+ timeRange: string;
155
+ }>;
156
+ recommendation: string;
157
+ }
158
+ /**
159
+ * Response from `balance.compare()`.
160
+ */
161
+ export interface CompareResponse {
162
+ customerId: string;
163
+ yourBalance: number;
164
+ theirBalance: number;
165
+ neutralBalance: number;
166
+ matchesYours: boolean;
167
+ matchesTheirs: boolean;
168
+ deltasVerified: number;
169
+ discrepancyReport: DiscrepancyReport | null;
170
+ proof: {
171
+ itemsRoot: string | null;
172
+ latestCheckpoint: string | null;
173
+ windowSummaries: WindowSummary[];
174
+ };
175
+ }
176
+ /**
177
+ * Response from `balance.receipt()`.
178
+ */
179
+ export interface ReceiptResponse {
180
+ customerId: string;
181
+ generatedAt: string;
182
+ deltasCount: number;
183
+ finalBalance: number;
184
+ itemsRoot: string | null;
185
+ receiptId: string | null;
186
+ latestCheckpoint: string | null;
187
+ deltas: VerifiedDelta[];
188
+ windowSummaries: WindowSummary[];
189
+ verification: {
190
+ message: string;
191
+ itemHashes: string[];
192
+ };
193
+ }
194
+ /**
195
+ * Options for `balance.checkpoint()`.
196
+ */
197
+ export interface CheckpointOptions extends RequestOptions {
198
+ /**
199
+ * Billing period in YYYY-MM format.
200
+ * Defaults to the current period.
201
+ */
202
+ period?: string;
203
+ }
204
+ /**
205
+ * Response from `balance.checkpoint()`.
206
+ */
207
+ export interface CheckpointResponse {
208
+ checkpointId: string;
209
+ period: string;
210
+ merkleRoot: string;
211
+ deltaCount: number;
212
+ fromIndex: number;
213
+ toIndex: number;
214
+ customerId: string;
215
+ status: AnchorStatus;
216
+ message: string;
217
+ }
218
+ //# sourceMappingURL=balance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"balance.d.ts","sourceRoot":"","sources":["../../src/types/balance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAM/C;;GAEG;AACH,MAAM,WAAW,WAAY,SAAQ,cAAc;IACjD,kDAAkD;IAClD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,WAAW;IACrD;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,sDAAsD;IACtD,QAAQ,EAAE,MAAM,CAAC;IACjB,kDAAkD;IAClD,UAAU,EAAE,MAAM,CAAC;IACnB,sCAAsC;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,iCAAiC;IACjC,MAAM,EAAE,YAAY,CAAC;IACrB,2DAA2D;IAC3D,SAAS,EAAE,MAAM,CAAC;IAClB,2EAA2E;IAC3E,SAAS,EAAE,MAAM,CAAC;IAClB,+CAA+C;IAC/C,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,wEAAwE;IACxE,uBAAuB,EAAE,MAAM,CAAC;IAChC,iEAAiE;IACjE,gBAAgB,EAAE,MAAM,CAAC;IACzB,8DAA8D;IAC9D,UAAU,EAAE,MAAM,CAAC;IACnB,qCAAqC;IACrC,OAAO,EAAE,MAAM,CAAC;CACjB;AAMD;;GAEG;AACH,MAAM,W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,EAAE,aAAa,EAAE,CAAC;KAClC,CAAC;CACH;AAMD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,MAAM,EAAE,aAAa,EAAE,CAAC;IACxB,eAAe,EAAE,aAAa,EAAE,CAAC;IACjC,YAAY,EAAE;QACZ,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,EAAE,MAAM,EAAE,CAAC;KACtB,CAAC;CACH;AAMD;;GAEG;AACH,MAAM,WAAW,iBAAkB,SAAQ,cAAc;IACvD;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,YAAY,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;CACjB"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=balance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"balance.js","sourceRoot":"","sources":["../../src/types/balance.ts"],"names":[],"mappings":""}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Raw API response envelope returned by all PacSpace endpoints.
3
+ * The SDK unwraps this automatically — users never see it.
4
+ * @internal
5
+ */
6
+ export interface RawApiResponse<T = unknown> {
7
+ success: boolean;
8
+ data?: T;
9
+ message?: string;
10
+ error?: string;
11
+ statusCode?: number;
12
+ }
13
+ /**
14
+ * Anchor status lifecycle.
15
+ */
16
+ export type AnchorStatus = 'QUEUED' | 'PROCESSING' | 'ANCHORING' | 'ANCHORED' | 'VERIFIED' | 'FAILED';
17
+ /**
18
+ * Checkpoint type for balance derivation.
19
+ */
20
+ export type CheckpointType = 'itemsRoot' | 'anchorId';
21
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/types/common.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,OAAO;IACzC,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GACpB,QAAQ,GACR,YAAY,GACZ,WAAW,GACX,UAAU,GACV,UAAU,GACV,QAAQ,CAAC;AAEb;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG,UAAU,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/types/common.ts"],"names":[],"mappings":""}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * PacSpace SDK configuration options.
3
+ */
4
+ export interface PacSpaceConfig {
5
+ /**
6
+ * Your PacSpace API key.
7
+ * Format: `pk_live_PUBLIC.SECRET` (production) or `pk_test_PUBLIC.SECRET` (sandbox).
8
+ */
9
+ apiKey: string;
10
+ /**
11
+ * Base URL for the PacSpace API.
12
+ * Defaults to `https://balance-api.pacspace.io`.
13
+ */
14
+ baseUrl?: string;
15
+ /**
16
+ * Default chain ID to use for all requests.
17
+ * Auto-detected from API key prefix when not set:
18
+ * - `pk_test_*` → 296 (Hedera Testnet)
19
+ * - `pk_live_*` → 295 (Hedera Mainnet)
20
+ */
21
+ chainId?: number;
22
+ /**
23
+ * Default credit pool ID for all requests.
24
+ */
25
+ creditPoolId?: number;
26
+ /**
27
+ * Maximum number of automatic retries on transient errors (5xx, network).
28
+ * @default 2
29
+ */
30
+ maxRetries?: number;
31
+ /**
32
+ * Request timeout in milliseconds.
33
+ * @default 30000
34
+ */
35
+ timeout?: number;
36
+ /**
37
+ * Custom fetch implementation. Uses global `fetch` by default (Node 18+).
38
+ */
39
+ fetch?: typeof fetch;
40
+ }
41
+ /**
42
+ * Per-request options that can override defaults.
43
+ */
44
+ export interface RequestOptions {
45
+ /** Override the default chain ID for this request. */
46
+ chainId?: number;
47
+ /** Override the default credit pool ID for this request. */
48
+ creditPoolId?: number;
49
+ /** Idempotency key to prevent duplicate processing. */
50
+ idempotencyKey?: string;
51
+ /** AbortSignal for request cancellation. */
52
+ signal?: AbortSignal;
53
+ }
54
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,sDAAsD;IACtD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4DAA4D;IAC5D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,uDAAuD;IACvD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,4CAA4C;IAC5C,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":""}
@@ -0,0 +1,32 @@
1
+ import type { AnchorStatus } from '../types/common';
2
+ /**
3
+ * Options for the poll utility.
4
+ */
5
+ export interface PollOptions {
6
+ /**
7
+ * Maximum time (ms) to wait before throwing a TimeoutError.
8
+ * @default 60000
9
+ */
10
+ timeout?: number;
11
+ /**
12
+ * Interval (ms) between polls.
13
+ * @default 2000
14
+ */
15
+ pollInterval?: number;
16
+ /** AbortSignal for cancellation. */
17
+ signal?: AbortSignal;
18
+ }
19
+ /**
20
+ * Poll a status-returning function until a terminal status is reached.
21
+ *
22
+ * @param statusFn — Async function that returns the current status and full data.
23
+ * @param options — Timeout and interval configuration.
24
+ * @returns The full data object once a terminal status is reached.
25
+ * @throws TimeoutError if the timeout is exceeded.
26
+ *
27
+ * @internal
28
+ */
29
+ export declare function pollUntilTerminal<T extends {
30
+ status: AnchorStatus;
31
+ }>(statusFn: () => Promise<T>, options?: PollOptions): Promise<T>;
32
+ //# sourceMappingURL=polling.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polling.d.ts","sourceRoot":"","sources":["../../src/utils/polling.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAYpD;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oCAAoC;IACpC,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;;;;;;;;GASG;AACH,wBAAsB,iBAAiB,CAAC,CAAC,SAAS;IAAE,MAAM,EAAE,YAAY,CAAA;CAAE,EACxE,QAAQ,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAC1B,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,CAAC,CAAC,CA0CZ"}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pollUntilTerminal = pollUntilTerminal;
4
+ const errors_1 = require("../errors");
5
+ /**
6
+ * Terminal statuses — once an anchor reaches these, polling stops.
7
+ */
8
+ const TERMINAL_STATUSES = new Set([
9
+ 'ANCHORED',
10
+ 'VERIFIED',
11
+ 'FAILED',
12
+ ]);
13
+ /**
14
+ * Poll a status-returning function until a terminal status is reached.
15
+ *
16
+ * @param statusFn — Async function that returns the current status and full data.
17
+ * @param options — Timeout and interval configuration.
18
+ * @returns The full data object once a terminal status is reached.
19
+ * @throws TimeoutError if the timeout is exceeded.
20
+ *
21
+ * @internal
22
+ */
23
+ async function pollUntilTerminal(statusFn, options) {
24
+ const timeout = options?.timeout ?? 60000;
25
+ const pollInterval = options?.pollInterval ?? 2000;
26
+ const signal = options?.signal;
27
+ const deadline = Date.now() + timeout;
28
+ while (Date.now() < deadline) {
29
+ // Check cancellation
30
+ if (signal?.aborted) {
31
+ throw new errors_1.TimeoutError('Polling cancelled');
32
+ }
33
+ const result = await statusFn();
34
+ if (TERMINAL_STATUSES.has(result.status)) {
35
+ return result;
36
+ }
37
+ // Wait before next poll, but respect the deadline
38
+ const remaining = deadline - Date.now();
39
+ const delay = Math.min(pollInterval, remaining);
40
+ if (delay <= 0)
41
+ break;
42
+ await new Promise((resolve, reject) => {
43
+ const timer = setTimeout(resolve, delay);
44
+ // If cancelled during sleep, clean up and reject
45
+ if (signal) {
46
+ const onAbort = () => {
47
+ clearTimeout(timer);
48
+ reject(new errors_1.TimeoutError('Polling cancelled'));
49
+ };
50
+ signal.addEventListener('abort', onAbort, { once: true });
51
+ }
52
+ });
53
+ }
54
+ throw new errors_1.TimeoutError(`Operation did not reach a terminal status within ${timeout}ms`);
55
+ }
56
+ //# sourceMappingURL=polling.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polling.js","sourceRoot":"","sources":["../../src/utils/polling.ts"],"names":[],"mappings":";;AAwCA,8CA6CC;AApFD,sCAAyC;AAEzC;;GAEG;AACH,MAAM,iBAAiB,GAAsB,IAAI,GAAG,CAAC;IACnD,UAAU;IACV,UAAU;IACV,QAAQ;CACT,CAAC,CAAC;AAoBH;;;;;;;;;GASG;AACI,KAAK,UAAU,iBAAiB,CACrC,QAA0B,EAC1B,OAAqB;IAErB,MAAM,OAAO,GAAG,OAAO,EAAE,OAAO,IAAI,KAAM,CAAC;IAC3C,MAAM,YAAY,GAAG,OAAO,EAAE,YAAY,IAAI,IAAK,CAAC;IACpD,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,CAAC;IAE/B,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC;IAEtC,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC;QAC7B,qBAAqB;QACrB,IAAI,MAAM,EAAE,OAAO,EAAE,CAAC;YACpB,MAAM,IAAI,qBAAY,CAAC,mBAAmB,CAAC,CAAC;QAC9C,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,QAAQ,EAAE,CAAC;QAEhC,IAAI,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;YACzC,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,kDAAkD;QAClD,MAAM,SAAS,GAAG,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACxC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC;QAEhD,IAAI,KAAK,IAAI,CAAC;YAAE,MAAM;QAEtB,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC1C,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YAEzC,iDAAiD;YACjD,IAAI,MAAM,EAAE,CAAC;gBACX,MAAM,OAAO,GAAG,GAAG,EAAE;oBACnB,YAAY,CAAC,KAAK,CAAC,CAAC;oBACpB,MAAM,CAAC,IAAI,qBAAY,CAAC,mBAAmB,CAAC,CAAC,CAAC;gBAChD,CAAC,CAAC;gBACF,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;YAC5D,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,MAAM,IAAI,qBAAY,CACpB,oDAAoD,OAAO,IAAI,CAChE,CAAC;AACJ,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Utility for exponential backoff delay calculations.
3
+ * @internal — Used by the HttpClient; exported for advanced use cases.
4
+ */
5
+ /**
6
+ * Calculate exponential backoff delay with jitter.
7
+ *
8
+ * @param attempt - The retry attempt number (1-indexed).
9
+ * @param baseDelay - Base delay in milliseconds.
10
+ * @param maxDelay - Maximum delay in milliseconds.
11
+ * @returns Delay in milliseconds.
12
+ */
13
+ export declare function exponentialBackoff(attempt: number, baseDelay?: number, maxDelay?: number): number;
14
+ //# sourceMappingURL=retry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../src/utils/retry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,SAAS,SAAM,EACf,QAAQ,SAAS,GAChB,MAAM,CAIR"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ /**
3
+ * Utility for exponential backoff delay calculations.
4
+ * @internal — Used by the HttpClient; exported for advanced use cases.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.exponentialBackoff = exponentialBackoff;
8
+ /**
9
+ * Calculate exponential backoff delay with jitter.
10
+ *
11
+ * @param attempt - The retry attempt number (1-indexed).
12
+ * @param baseDelay - Base delay in milliseconds.
13
+ * @param maxDelay - Maximum delay in milliseconds.
14
+ * @returns Delay in milliseconds.
15
+ */
16
+ function exponentialBackoff(attempt, baseDelay = 500, maxDelay = 30000) {
17
+ const delay = Math.min(baseDelay * Math.pow(2, attempt - 1), maxDelay);
18
+ const jitter = delay * 0.25 * Math.random();
19
+ return delay + jitter;
20
+ }
21
+ //# sourceMappingURL=retry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.js","sourceRoot":"","sources":["../../src/utils/retry.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAUH,gDAQC;AAhBD;;;;;;;GAOG;AACH,SAAgB,kBAAkB,CAChC,OAAe,EACf,SAAS,GAAG,GAAG,EACf,QAAQ,GAAG,KAAM;IAEjB,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;IACvE,MAAM,MAAM,GAAG,KAAK,GAAG,IAAI,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAC5C,OAAO,KAAK,GAAG,MAAM,CAAC;AACxB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { Webhooks, type VerifyOptions } from './verify';
2
+ export type { WebhookEventType, WebhookEvent, WebhookEventMap, WebhookHeaders, DeltaVerifiedPayload, DeltaStoredPayload, CheckpointVerifiedPayload, FactVerifiedPayload, RecordTransferredPayload, } from './types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/webhooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AACxD,YAAY,EACV,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EAClB,yBAAyB,EACzB,mBAAmB,EACnB,wBAAwB,GACzB,MAAM,SAAS,CAAC"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Webhooks = void 0;
4
+ var verify_1 = require("./verify");
5
+ Object.defineProperty(exports, "Webhooks", { enumerable: true, get: function () { return verify_1.Webhooks; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/webhooks/index.ts"],"names":[],"mappings":";;;AAAA,mCAAwD;AAA/C,kGAAA,QAAQ,OAAA"}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * All supported webhook event types.
3
+ */
4
+ export type WebhookEventType = 'delta.verified' | 'delta.stored' | 'checkpoint.verified' | 'fact.verified' | 'record.transferred';
5
+ export interface DeltaVerifiedPayload {
6
+ receiptId: string;
7
+ deltaIndex: number | null;
8
+ status: 'verified';
9
+ verifiedAt: string;
10
+ verificationId: string;
11
+ delta: {
12
+ customerId: string | null;
13
+ amount: number | null;
14
+ reason: string | null;
15
+ referenceId: string | null;
16
+ metadata: Record<string, unknown>;
17
+ submittedAt: string | null;
18
+ };
19
+ proof: {
20
+ proofHash: string;
21
+ contentHash: string | null;
22
+ itemHashes: string[];
23
+ previousProofHash: string | null;
24
+ };
25
+ verification: {
26
+ verified: boolean;
27
+ latencyMs: number;
28
+ discrepancies: string[];
29
+ };
30
+ period?: {
31
+ id: string;
32
+ deltaCount: number;
33
+ netDelta: number;
34
+ };
35
+ usage?: {
36
+ plan: string;
37
+ includedDeltas: number;
38
+ consumedDeltas: number;
39
+ remainingDeltas: number;
40
+ overageRate: string;
41
+ };
42
+ }
43
+ export interface DeltaStoredPayload {
44
+ startIndex: string;
45
+ count: string;
46
+ verificationId: string;
47
+ verifiedAt: string;
48
+ }
49
+ export interface CheckpointVerifiedPayload {
50
+ fromIndex: string;
51
+ toIndex: string;
52
+ proofHash: string;
53
+ verifiedAt: string;
54
+ verificationId: string;
55
+ message: string;
56
+ }
57
+ export interface FactVerifiedPayload {
58
+ contentHash: string;
59
+ proofHash: string;
60
+ verifiedAt: string;
61
+ verificationId: string;
62
+ }
63
+ export interface RecordTransferredPayload {
64
+ receiptId: string;
65
+ verifiedAt: string;
66
+ verificationId: string;
67
+ }
68
+ /**
69
+ * Map from event type to its payload shape.
70
+ */
71
+ export interface WebhookEventMap {
72
+ 'delta.verified': DeltaVerifiedPayload;
73
+ 'delta.stored': DeltaStoredPayload;
74
+ 'checkpoint.verified': CheckpointVerifiedPayload;
75
+ 'fact.verified': FactVerifiedPayload;
76
+ 'record.transferred': RecordTransferredPayload;
77
+ }
78
+ /**
79
+ * A typed webhook event.
80
+ */
81
+ export interface WebhookEvent<T extends WebhookEventType = WebhookEventType> {
82
+ /** The event type. */
83
+ event: T;
84
+ /** ISO 8601 timestamp of when the webhook was sent. */
85
+ timestamp: string;
86
+ /** Event-specific data. */
87
+ data: T extends keyof WebhookEventMap ? WebhookEventMap[T] : unknown;
88
+ }
89
+ /**
90
+ * Headers sent with every webhook delivery.
91
+ */
92
+ export interface WebhookHeaders {
93
+ 'x-pacspace-signature': string;
94
+ 'x-pacspace-timestamp': string;
95
+ 'x-webhook-event'?: string;
96
+ 'x-event-id'?: string;
97
+ [key: string]: string | undefined;
98
+ }
99
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/webhooks/types.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,MAAM,gBAAgB,GACxB,gBA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Y,CAAC,EAAE,MAAM,CAAC;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CACnC"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ // ---------------------------------------------------------------------------
3
+ // Webhook Event Types
4
+ // ---------------------------------------------------------------------------
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/webhooks/types.ts"],"names":[],"mappings":";AAAA,8EAA8E;AAC9E,sBAAsB;AACtB,8EAA8E"}