@pacspace-io/sdk 0.1.0 → 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.
- package/README.md +65 -9
- package/dist/client.d.ts +33 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +294 -19
- package/dist/client.js.map +1 -1
- package/dist/errors/index.d.ts +24 -1
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +44 -4
- package/dist/errors/index.js.map +1 -1
- package/dist/index.d.ts +49 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +106 -7
- package/dist/index.js.map +1 -1
- package/dist/resources/balance.d.ts +207 -13
- package/dist/resources/balance.d.ts.map +1 -1
- package/dist/resources/balance.js +356 -16
- package/dist/resources/balance.js.map +1 -1
- package/dist/resources/submission.d.ts +79 -0
- package/dist/resources/submission.d.ts.map +1 -0
- package/dist/resources/submission.js +398 -0
- package/dist/resources/submission.js.map +1 -0
- package/dist/types/balance.d.ts +489 -19
- package/dist/types/balance.d.ts.map +1 -1
- package/dist/types/config.d.ts +51 -1
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/submission.d.ts +125 -0
- package/dist/types/submission.d.ts.map +1 -0
- package/dist/types/submission.js +3 -0
- package/dist/types/submission.js.map +1 -0
- package/dist/webhooks/index.d.ts +1 -1
- package/dist/webhooks/index.d.ts.map +1 -1
- package/dist/webhooks/types.d.ts +27 -31
- package/dist/webhooks/types.d.ts.map +1 -1
- package/dist/webhooks/types.js +0 -3
- package/dist/webhooks/types.js.map +1 -1
- package/dist/webhooks/verify.d.ts +5 -0
- package/dist/webhooks/verify.d.ts.map +1 -1
- package/dist/webhooks/verify.js +19 -4
- package/dist/webhooks/verify.js.map +1 -1
- package/package.json +1 -1
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BalanceResource = void 0;
|
|
4
4
|
const polling_1 = require("../utils/polling");
|
|
5
|
+
const submission_1 = require("./submission");
|
|
5
6
|
/**
|
|
6
7
|
* PacSpace Balance API resource.
|
|
7
8
|
*
|
|
@@ -15,8 +16,12 @@ const polling_1 = require("../utils/polling");
|
|
|
15
16
|
*/
|
|
16
17
|
class BalanceResource {
|
|
17
18
|
/** @internal */
|
|
18
|
-
constructor(client) {
|
|
19
|
+
constructor(client, submissionOptions) {
|
|
19
20
|
this.client = client;
|
|
21
|
+
this.submission = new submission_1.SubmissionCoordinator({
|
|
22
|
+
emitBatch: (deltas) => this.emitBatch(deltas),
|
|
23
|
+
options: submissionOptions,
|
|
24
|
+
});
|
|
20
25
|
}
|
|
21
26
|
// -------------------------------------------------------------------------
|
|
22
27
|
// Emit
|
|
@@ -85,8 +90,131 @@ class BalanceResource {
|
|
|
85
90
|
if (['ANCHORED', 'VERIFIED', 'FAILED'].includes(initial.status)) {
|
|
86
91
|
return initial;
|
|
87
92
|
}
|
|
88
|
-
// Poll for terminal status using the
|
|
89
|
-
return (0, polling_1.pollUntilTerminal)(() => this.client.get(`/api/v1/
|
|
93
|
+
// Poll for terminal status using the balance delta endpoint
|
|
94
|
+
return (0, polling_1.pollUntilTerminal)(() => this.client.get(`/api/v1/balance/delta/${initial.anchorId}`, { signal }), { timeout, pollInterval, signal });
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Check the status of a previously emitted delta.
|
|
98
|
+
*
|
|
99
|
+
* @param anchorId - The anchor ID returned from emit.
|
|
100
|
+
* @param options - Request overrides.
|
|
101
|
+
* @returns Delta status with receipt and transaction details.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const status = await pac.balance.deltaStatus('anc_abc123');
|
|
106
|
+
* console.log(status.status); // 'QUEUED', 'ANCHORED', etc.
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
async deltaStatus(anchorId, options) {
|
|
110
|
+
return this.client.get(`/api/v1/balance/delta/${encodeURIComponent(anchorId)}`, options);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Alias for `deltaStatus()` with lifecycle-oriented naming.
|
|
114
|
+
*/
|
|
115
|
+
async getAnchorStatus(anchorId, options) {
|
|
116
|
+
return this.deltaStatus(anchorId, options);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Poll anchor lifecycle until it reaches a terminal status.
|
|
120
|
+
*
|
|
121
|
+
* Terminal statuses are `ANCHORED`, `VERIFIED`, and `FAILED`.
|
|
122
|
+
*/
|
|
123
|
+
async waitForAnchored(anchorId, options) {
|
|
124
|
+
const { timeout = 60000, pollInterval = 2000, signal, ...requestOptions } = options ?? {};
|
|
125
|
+
return (0, polling_1.pollUntilTerminal)(() => this.getAnchorStatus(anchorId, {
|
|
126
|
+
...requestOptions,
|
|
127
|
+
signal,
|
|
128
|
+
}), { timeout, pollInterval, signal });
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Retrieve tenant usage counters and remaining allotment.
|
|
132
|
+
*/
|
|
133
|
+
async usage(options) {
|
|
134
|
+
return this.client.get('/api/v1/balance/usage', options);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Detect missing per-customer sequence ranges.
|
|
138
|
+
*
|
|
139
|
+
* Use this to identify gaps and re-emit missing deltas safely.
|
|
140
|
+
*/
|
|
141
|
+
async gaps(customerId, options) {
|
|
142
|
+
const { fromSequence, toSequence, limit, ...requestOptions } = options ?? {};
|
|
143
|
+
const params = new URLSearchParams();
|
|
144
|
+
if (fromSequence !== undefined)
|
|
145
|
+
params.set('fromSequence', fromSequence);
|
|
146
|
+
if (toSequence !== undefined)
|
|
147
|
+
params.set('toSequence', toSequence);
|
|
148
|
+
if (limit !== undefined)
|
|
149
|
+
params.set('limit', String(limit));
|
|
150
|
+
const query = params.toString();
|
|
151
|
+
const path = `/api/v1/balance/gaps/${encodeURIComponent(customerId)}${query ? `?${query}` : ''}`;
|
|
152
|
+
return this.client.get(path, requestOptions);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Record multiple deltas in a single batch request.
|
|
156
|
+
*
|
|
157
|
+
* Ideal for end-of-day reconciliation or importing historical data.
|
|
158
|
+
* Up to 100 deltas per batch.
|
|
159
|
+
*
|
|
160
|
+
* @param deltas - Array of deltas to record.
|
|
161
|
+
* @param options - Request overrides.
|
|
162
|
+
* @returns Per-delta results with totals.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* const result = await pac.balance.emitBatch([
|
|
167
|
+
* { customerId: 'cust_123', delta: -100, reason: 'usage' },
|
|
168
|
+
* { customerId: 'cust_456', delta: -200, reason: 'usage' },
|
|
169
|
+
* ]);
|
|
170
|
+
* console.log(result.totalQueued); // 2
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
async emitBatch(deltas, options) {
|
|
174
|
+
const { ...requestOptions } = options ?? {};
|
|
175
|
+
return this.client.post('/api/v1/balance/delta/batch', { deltas }, requestOptions);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Queue one tenant-produced summary for SDK-managed submission.
|
|
179
|
+
*/
|
|
180
|
+
queueSummary(summary) {
|
|
181
|
+
return this.submission.queueSummary(summary);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Queue multiple tenant-produced summaries.
|
|
185
|
+
*/
|
|
186
|
+
queueSummaries(summaries) {
|
|
187
|
+
return this.submission.queueSummaries(summaries);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Flush queued summaries immediately.
|
|
191
|
+
*/
|
|
192
|
+
async flushSummaries(options) {
|
|
193
|
+
return this.submission.flushSummaries(options);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Start periodic summary submission scheduling.
|
|
197
|
+
*/
|
|
198
|
+
startSummaryScheduler() {
|
|
199
|
+
this.submission.start();
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Stop periodic summary submission scheduling.
|
|
203
|
+
*/
|
|
204
|
+
stopSummaryScheduler() {
|
|
205
|
+
this.submission.stop();
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Get queue/scheduler state for summary submission automation.
|
|
209
|
+
*/
|
|
210
|
+
getSummaryQueueState() {
|
|
211
|
+
return this.submission.getQueueState();
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Stop scheduler and flush queued summaries (best for graceful shutdown).
|
|
215
|
+
*/
|
|
216
|
+
async shutdownSummaryScheduler() {
|
|
217
|
+
await this.submission.shutdown();
|
|
90
218
|
}
|
|
91
219
|
// -------------------------------------------------------------------------
|
|
92
220
|
// Derive
|
|
@@ -113,7 +241,7 @@ class BalanceResource {
|
|
|
113
241
|
* ```
|
|
114
242
|
*/
|
|
115
243
|
async derive(customerId, options) {
|
|
116
|
-
const { startingBalance, startingCheckpoint, startingCheckpointType, ...requestOptions } = options ?? {};
|
|
244
|
+
const { startingBalance, startingCheckpoint, startingCheckpointType, limit, offset, ...requestOptions } = options ?? {};
|
|
117
245
|
// Build query string
|
|
118
246
|
const params = new URLSearchParams();
|
|
119
247
|
if (startingBalance !== undefined) {
|
|
@@ -125,6 +253,12 @@ class BalanceResource {
|
|
|
125
253
|
if (startingCheckpointType !== undefined) {
|
|
126
254
|
params.set('startingCheckpointType', startingCheckpointType);
|
|
127
255
|
}
|
|
256
|
+
if (limit !== undefined) {
|
|
257
|
+
params.set('limit', String(limit));
|
|
258
|
+
}
|
|
259
|
+
if (offset !== undefined) {
|
|
260
|
+
params.set('offset', String(offset));
|
|
261
|
+
}
|
|
128
262
|
const query = params.toString();
|
|
129
263
|
const path = `/api/v1/balance/derive/${encodeURIComponent(customerId)}${query ? `?${query}` : ''}`;
|
|
130
264
|
return this.client.get(path, requestOptions);
|
|
@@ -178,22 +312,57 @@ class BalanceResource {
|
|
|
178
312
|
/**
|
|
179
313
|
* Generate a verifiable receipt for a customer.
|
|
180
314
|
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
315
|
+
* When `options.period` is provided, returns a period-specific receipt (proof root,
|
|
316
|
+
* verifyUrl, verificationReference) suitable for sharing on invoices. When
|
|
317
|
+
* omitted, returns the full ledger receipt with all verified deltas.
|
|
183
318
|
*
|
|
184
319
|
* @param customerId - The customer account to generate a receipt for.
|
|
185
|
-
* @param options -
|
|
186
|
-
* @returns Receipt with verification data.
|
|
320
|
+
* @param options - Optional period (YYYY-MM) and request overrides.
|
|
321
|
+
* @returns Receipt with verification data; shape depends on whether period is set.
|
|
187
322
|
*
|
|
188
323
|
* @example
|
|
189
324
|
* ```typescript
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
* console.log(receipt.
|
|
325
|
+
* // Period-specific receipt (shareable proof for invoices)
|
|
326
|
+
* const receipt = await pac.balance.receipt('cust_123', { period: '2026-02' });
|
|
327
|
+
* console.log(receipt.proofRoot); // Include on invoice
|
|
328
|
+
* console.log(receipt.verifyUrl); // Share with counterparty
|
|
329
|
+
*
|
|
330
|
+
* // Full ledger receipt
|
|
331
|
+
* const full = await pac.balance.receipt('cust_123');
|
|
332
|
+
* console.log(full.finalBalance);
|
|
193
333
|
* ```
|
|
194
334
|
*/
|
|
195
335
|
async receipt(customerId, options) {
|
|
196
|
-
|
|
336
|
+
const opts = options ?? {};
|
|
337
|
+
const hasScopedReceipt = opts.period !== undefined ||
|
|
338
|
+
opts.timePreset !== undefined ||
|
|
339
|
+
opts.startDate !== undefined ||
|
|
340
|
+
opts.endDate !== undefined;
|
|
341
|
+
if (hasScopedReceipt) {
|
|
342
|
+
return this.receiptForPeriod(customerId, opts);
|
|
343
|
+
}
|
|
344
|
+
const { period: _period, timePreset: _timePreset, startDate: _startDate, endDate: _endDate, ...requestOptions } = opts;
|
|
345
|
+
const hasOverrides = Object.keys(requestOptions).length > 0;
|
|
346
|
+
return this.client.get(`/api/v1/balance/receipt/${encodeURIComponent(customerId)}`, hasOverrides ? requestOptions : undefined);
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* @internal
|
|
350
|
+
* Generate a period-specific receipt (proof root, verifyUrl). Used by receipt().
|
|
351
|
+
*/
|
|
352
|
+
async receiptForPeriod(customerId, options) {
|
|
353
|
+
const { period, timePreset, startDate, endDate, ...requestOptions } = options ?? {};
|
|
354
|
+
const params = new URLSearchParams();
|
|
355
|
+
if (period !== undefined)
|
|
356
|
+
params.set('period', period);
|
|
357
|
+
if (timePreset !== undefined)
|
|
358
|
+
params.set('timePreset', timePreset);
|
|
359
|
+
if (startDate !== undefined)
|
|
360
|
+
params.set('startDate', startDate);
|
|
361
|
+
if (endDate !== undefined)
|
|
362
|
+
params.set('endDate', endDate);
|
|
363
|
+
const query = params.toString();
|
|
364
|
+
const path = `/api/v1/balance/invoice-proof/${encodeURIComponent(customerId)}${query ? `?${query}` : ''}`;
|
|
365
|
+
return this.client.get(path, requestOptions);
|
|
197
366
|
}
|
|
198
367
|
// -------------------------------------------------------------------------
|
|
199
368
|
// Checkpoint
|
|
@@ -201,9 +370,9 @@ class BalanceResource {
|
|
|
201
370
|
/**
|
|
202
371
|
* Commit a period-end checkpoint.
|
|
203
372
|
*
|
|
204
|
-
* Computes a
|
|
205
|
-
* and
|
|
206
|
-
* for instant counterparty verification.
|
|
373
|
+
* Computes a proof root over all verified deltas in the billing window
|
|
374
|
+
* and records it on the public verification layer. The proof root can be
|
|
375
|
+
* included in invoices for instant counterparty verification.
|
|
207
376
|
*
|
|
208
377
|
* @param customerId - Customer to checkpoint (omit for all customers).
|
|
209
378
|
* @param options - Period (YYYY-MM) and request overrides.
|
|
@@ -218,14 +387,185 @@ class BalanceResource {
|
|
|
218
387
|
* ```
|
|
219
388
|
*/
|
|
220
389
|
async checkpoint(customerId, options) {
|
|
221
|
-
const { period, ...requestOptions } = options ?? {};
|
|
390
|
+
const { period, timePreset, startDate, endDate, mode, fingerprints, ...requestOptions } = options ?? {};
|
|
222
391
|
const body = {};
|
|
223
392
|
if (customerId !== undefined)
|
|
224
393
|
body.customerId = customerId;
|
|
225
394
|
if (period !== undefined)
|
|
226
395
|
body.period = period;
|
|
396
|
+
if (timePreset !== undefined)
|
|
397
|
+
body.timePreset = timePreset;
|
|
398
|
+
if (startDate !== undefined)
|
|
399
|
+
body.startDate = startDate;
|
|
400
|
+
if (endDate !== undefined)
|
|
401
|
+
body.endDate = endDate;
|
|
402
|
+
if (mode !== undefined)
|
|
403
|
+
body.mode = mode;
|
|
404
|
+
if (fingerprints !== undefined)
|
|
405
|
+
body.fingerprints = fingerprints;
|
|
227
406
|
return this.client.post('/api/v1/balance/checkpoint', body, requestOptions);
|
|
228
407
|
}
|
|
408
|
+
// -------------------------------------------------------------------------
|
|
409
|
+
// List Checkpoints
|
|
410
|
+
// -------------------------------------------------------------------------
|
|
411
|
+
/**
|
|
412
|
+
* List committed checkpoints for your tenant.
|
|
413
|
+
*
|
|
414
|
+
* Returns a paginated list of checkpoints, optionally filtered by
|
|
415
|
+
* customer ID and/or billing period.
|
|
416
|
+
*
|
|
417
|
+
* @param options - Filter and pagination options.
|
|
418
|
+
* @returns Paginated list of checkpoints.
|
|
419
|
+
*
|
|
420
|
+
* @example
|
|
421
|
+
* ```typescript
|
|
422
|
+
* const { checkpoints } = await pac.balance.listCheckpoints({
|
|
423
|
+
* period: '2026-02',
|
|
424
|
+
* limit: 10,
|
|
425
|
+
* });
|
|
426
|
+
* ```
|
|
427
|
+
*/
|
|
428
|
+
async listCheckpoints(options) {
|
|
429
|
+
const { customerId, period, timePreset, startDate, endDate, limit, offset, ...requestOptions } = options ?? {};
|
|
430
|
+
const params = new URLSearchParams();
|
|
431
|
+
if (customerId !== undefined)
|
|
432
|
+
params.set('customerId', customerId);
|
|
433
|
+
if (period !== undefined)
|
|
434
|
+
params.set('period', period);
|
|
435
|
+
if (timePreset !== undefined)
|
|
436
|
+
params.set('timePreset', timePreset);
|
|
437
|
+
if (startDate !== undefined)
|
|
438
|
+
params.set('startDate', startDate);
|
|
439
|
+
if (endDate !== undefined)
|
|
440
|
+
params.set('endDate', endDate);
|
|
441
|
+
if (limit !== undefined)
|
|
442
|
+
params.set('limit', String(limit));
|
|
443
|
+
if (offset !== undefined)
|
|
444
|
+
params.set('offset', String(offset));
|
|
445
|
+
const query = params.toString();
|
|
446
|
+
const path = `/api/v1/balance/checkpoints${query ? `?${query}` : ''}`;
|
|
447
|
+
return this.client.get(path, requestOptions);
|
|
448
|
+
}
|
|
449
|
+
// -------------------------------------------------------------------------
|
|
450
|
+
// Webhook Deliveries
|
|
451
|
+
// -------------------------------------------------------------------------
|
|
452
|
+
/**
|
|
453
|
+
* List webhook delivery history.
|
|
454
|
+
*
|
|
455
|
+
* @param options - Filter and pagination options.
|
|
456
|
+
* @returns Paginated list of webhook deliveries.
|
|
457
|
+
*
|
|
458
|
+
* @example
|
|
459
|
+
* ```typescript
|
|
460
|
+
* const { deliveries } = await pac.balance.listWebhookDeliveries({
|
|
461
|
+
* status: 'failed',
|
|
462
|
+
* limit: 10,
|
|
463
|
+
* });
|
|
464
|
+
* ```
|
|
465
|
+
*/
|
|
466
|
+
async listWebhookDeliveries(options) {
|
|
467
|
+
const { status, limit, offset, ...requestOptions } = options ?? {};
|
|
468
|
+
const params = new URLSearchParams();
|
|
469
|
+
if (status !== undefined)
|
|
470
|
+
params.set('status', status);
|
|
471
|
+
if (limit !== undefined)
|
|
472
|
+
params.set('limit', String(limit));
|
|
473
|
+
if (offset !== undefined)
|
|
474
|
+
params.set('offset', String(offset));
|
|
475
|
+
const query = params.toString();
|
|
476
|
+
const path = `/api/v1/balance/webhooks${query ? `?${query}` : ''}`;
|
|
477
|
+
return this.client.get(path, requestOptions);
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Retry a failed webhook delivery.
|
|
481
|
+
*
|
|
482
|
+
* @param eventId - The event ID of the failed delivery.
|
|
483
|
+
* @param options - Request overrides.
|
|
484
|
+
*
|
|
485
|
+
* @example
|
|
486
|
+
* ```typescript
|
|
487
|
+
* await pac.balance.retryWebhook('evt_abc123');
|
|
488
|
+
* ```
|
|
489
|
+
*/
|
|
490
|
+
async retryWebhook(eventId, options) {
|
|
491
|
+
return this.client.post(`/api/v1/balance/webhooks/${encodeURIComponent(eventId)}/retry`, {}, options);
|
|
492
|
+
}
|
|
493
|
+
// -------------------------------------------------------------------------
|
|
494
|
+
// Customer Ledgers
|
|
495
|
+
// -------------------------------------------------------------------------
|
|
496
|
+
/**
|
|
497
|
+
* List all customer ledgers for your account.
|
|
498
|
+
*
|
|
499
|
+
* Each unique customerId passed to emit() automatically creates an
|
|
500
|
+
* isolated ledger. This method returns a paginated list of all ledgers.
|
|
501
|
+
*
|
|
502
|
+
* @param options - Search, pagination, and request overrides.
|
|
503
|
+
* @returns Paginated list of customer ledgers.
|
|
504
|
+
*
|
|
505
|
+
* @example
|
|
506
|
+
* ```typescript
|
|
507
|
+
* const { customers } = await pac.balance.customers();
|
|
508
|
+
* for (const c of customers) {
|
|
509
|
+
* console.log(c.customerId, c.totalDeltas);
|
|
510
|
+
* }
|
|
511
|
+
* ```
|
|
512
|
+
*/
|
|
513
|
+
async customers(options) {
|
|
514
|
+
const { search, limit, page, ...requestOptions } = options ?? {};
|
|
515
|
+
const params = new URLSearchParams();
|
|
516
|
+
if (search !== undefined)
|
|
517
|
+
params.set('search', search);
|
|
518
|
+
if (limit !== undefined)
|
|
519
|
+
params.set('limit', String(limit));
|
|
520
|
+
if (page !== undefined)
|
|
521
|
+
params.set('page', String(page));
|
|
522
|
+
const query = params.toString();
|
|
523
|
+
const path = `/api/v1/balance/customers${query ? `?${query}` : ''}`;
|
|
524
|
+
return this.client.get(path, requestOptions);
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Get the full ledger detail for a specific customer.
|
|
528
|
+
*
|
|
529
|
+
* Returns the derived ledger identifier, computed balance, delta count,
|
|
530
|
+
* and latest checkpoint. The ledger identifier is deterministic --
|
|
531
|
+
* the same customerId always produces the same identifier.
|
|
532
|
+
*
|
|
533
|
+
* @param customerId - The customer to look up.
|
|
534
|
+
* @param options - Activity pagination and request overrides.
|
|
535
|
+
* @returns Customer ledger detail including balance and identifiers.
|
|
536
|
+
*
|
|
537
|
+
* @example
|
|
538
|
+
* ```typescript
|
|
539
|
+
* const ledger = await pac.balance.customer('cust_001');
|
|
540
|
+
* console.log(ledger.ledgerIdentifier); // 0xA1b2...Ef34
|
|
541
|
+
* console.log(ledger.computedBalance); // 4500.00
|
|
542
|
+
* ```
|
|
543
|
+
*/
|
|
544
|
+
async customer(customerId, options) {
|
|
545
|
+
const { deltaPage, deltaLimit, ...requestOptions } = options ?? {};
|
|
546
|
+
const params = new URLSearchParams();
|
|
547
|
+
if (deltaPage !== undefined)
|
|
548
|
+
params.set('deltaPage', String(deltaPage));
|
|
549
|
+
if (deltaLimit !== undefined)
|
|
550
|
+
params.set('deltaLimit', String(deltaLimit));
|
|
551
|
+
const query = params.toString();
|
|
552
|
+
const path = `/api/v1/balance/customers/${encodeURIComponent(customerId)}${query ? `?${query}` : ''}`;
|
|
553
|
+
return this.client.get(path, requestOptions);
|
|
554
|
+
}
|
|
555
|
+
// -------------------------------------------------------------------------
|
|
556
|
+
// Invoice Proof (deprecated — use receipt with period)
|
|
557
|
+
// -------------------------------------------------------------------------
|
|
558
|
+
/**
|
|
559
|
+
* Generate an invoice-ready receipt for a customer's billing period.
|
|
560
|
+
*
|
|
561
|
+
* @deprecated Use `receipt(customerId, { period })` instead.
|
|
562
|
+
* @param customerId - The customer to generate the receipt for.
|
|
563
|
+
* @param options - Period selection and request overrides.
|
|
564
|
+
* @returns Receipt with proof root, verifyUrl, and verification data.
|
|
565
|
+
*/
|
|
566
|
+
async invoiceProof(customerId, options) {
|
|
567
|
+
return this.receiptForPeriod(customerId, options);
|
|
568
|
+
}
|
|
229
569
|
}
|
|
230
570
|
exports.BalanceResource = BalanceResource;
|
|
231
571
|
//# sourceMappingURL=balance.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"balance.js","sourceRoot":"","sources":["../../src/resources/balance.ts"],"names":[],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CAAwB,IAAI,EAAE,cAAc,CAAC,CAAC;IACtE,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,KAAK,CAAC,QAAQ,CACZ,UAAkB,EAClB,OAA4B;QAE5B,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,cAAc,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;QAEnE,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;QACrC,IAAI,SAAS,KAAK,SAAS;YAAE,MAAM,CAAC,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;QACxE,IAAI,UAAU,KAAK,SAAS;YAAE,MAAM,CAAC,GAAG,CAAC,YAAY,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;QAE3E,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;QAChC,MAAM,IAAI,GAAG,6BAA6B,kBAAkB,CAAC,UAAU,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;QAEtG,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAuB,IAAI,EAAE,cAAc,CAAC,CAAC;IACrE,CAAC;IAED,4EAA4E;IAC5E,uDAAuD;IACvD,4EAA4E;IAE5E;;;;;;;OAOG;IACH,KAAK,CAAC,YAAY,CAChB,UAAkB,EAClB,OAA6B;QAE7B,OAAO,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IACpD,CAAC;CACF;AAxtBD,0CAwtBC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { BulkDelta, BulkEmitResponse } from '../types/balance';
|
|
2
|
+
import type { CustomerUsageSummary, FlushSummariesOptions, QueuedUsageSummary, SubmissionAutomationOptions, SubmissionQueueState, SummaryFlushResult } from '../types/submission';
|
|
3
|
+
type EmitBatchFn = (deltas: BulkDelta[]) => Promise<BulkEmitResponse>;
|
|
4
|
+
interface SubmissionCoordinatorConfig {
|
|
5
|
+
emitBatch: EmitBatchFn;
|
|
6
|
+
options?: SubmissionAutomationOptions;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Tenant-owned metering submission automation.
|
|
10
|
+
*
|
|
11
|
+
* This coordinator only submits tenant-produced summaries. It does not infer
|
|
12
|
+
* or meter raw product usage events.
|
|
13
|
+
*/
|
|
14
|
+
export declare class SubmissionCoordinator {
|
|
15
|
+
private static readonly trackedCoordinators;
|
|
16
|
+
private static shutdownHooksRegistered;
|
|
17
|
+
private static readonly shutdownHandlers;
|
|
18
|
+
private readonly emitBatch;
|
|
19
|
+
private readonly profile;
|
|
20
|
+
private readonly cadenceMs;
|
|
21
|
+
private readonly enterprise;
|
|
22
|
+
private readonly autoStart;
|
|
23
|
+
private readonly autoFlushOnShutdown;
|
|
24
|
+
private readonly batchSize;
|
|
25
|
+
private readonly maxRequestsPerMinute;
|
|
26
|
+
private readonly defaultReason;
|
|
27
|
+
private readonly queue;
|
|
28
|
+
private shutdownTracked;
|
|
29
|
+
private timer;
|
|
30
|
+
private running;
|
|
31
|
+
private nextFlushAt;
|
|
32
|
+
private activeFlush;
|
|
33
|
+
private lastRequestAt;
|
|
34
|
+
constructor(config: SubmissionCoordinatorConfig);
|
|
35
|
+
/**
|
|
36
|
+
* Enqueue one tenant-produced customer summary.
|
|
37
|
+
*/
|
|
38
|
+
queueSummary(summary: CustomerUsageSummary): QueuedUsageSummary;
|
|
39
|
+
/**
|
|
40
|
+
* Enqueue multiple tenant-produced summaries.
|
|
41
|
+
*/
|
|
42
|
+
queueSummaries(summaries: CustomerUsageSummary[]): QueuedUsageSummary[];
|
|
43
|
+
/**
|
|
44
|
+
* Returns queue and scheduler state.
|
|
45
|
+
*/
|
|
46
|
+
getQueueState(): SubmissionQueueState;
|
|
47
|
+
/**
|
|
48
|
+
* Start scheduled flushes for non-immediate profiles.
|
|
49
|
+
*/
|
|
50
|
+
start(): void;
|
|
51
|
+
/**
|
|
52
|
+
* Stop scheduled flushes.
|
|
53
|
+
*/
|
|
54
|
+
stop(): void;
|
|
55
|
+
/**
|
|
56
|
+
* Flush queued summaries immediately.
|
|
57
|
+
*/
|
|
58
|
+
flushSummaries(options?: FlushSummariesOptions): Promise<SummaryFlushResult>;
|
|
59
|
+
/**
|
|
60
|
+
* Stop scheduler, flush pending work, and unregister shutdown hooks.
|
|
61
|
+
*/
|
|
62
|
+
shutdown(): Promise<void>;
|
|
63
|
+
private assertProfileCompatibility;
|
|
64
|
+
private normalizeSummary;
|
|
65
|
+
private normalizeIso;
|
|
66
|
+
private buildReferenceId;
|
|
67
|
+
private performFlush;
|
|
68
|
+
private paceRequests;
|
|
69
|
+
private chunk;
|
|
70
|
+
private scheduleNextFlush;
|
|
71
|
+
private onScheduledFlush;
|
|
72
|
+
private ensureShutdownHooks;
|
|
73
|
+
private static flushTrackedCoordinators;
|
|
74
|
+
private trackShutdownHooks;
|
|
75
|
+
private untrackShutdownHooks;
|
|
76
|
+
private sleep;
|
|
77
|
+
}
|
|
78
|
+
export {};
|
|
79
|
+
//# sourceMappingURL=submission.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"submission.d.ts","sourceRoot":"","sources":["../../src/resources/submission.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,KAAK,EACV,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EAClB,2BAA2B,EAE3B,oBAAoB,EAEpB,kBAAkB,EACnB,MAAM,qBAAqB,CAAC;AAE7B,KAAK,WAAW,GAAG,CACjB,MAAM,EAAE,SAAS,EAAE,KAChB,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAE/B,UAAU,2BAA2B;IACnC,SAAS,EAAE,WAAW,CAAC;IACvB,OAAO,CAAC,EAAE,2BAA2B,CAAC;CACvC;AAUD;;;;;GAKG;A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