@clocknext/sdk 0.18.0 → 0.19.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.
package/dist/index.js CHANGED
@@ -331,7 +331,7 @@ function sleep(ms) {
331
331
  }
332
332
 
333
333
  // src/http.ts
334
- var SDK_VERSION = "0.18.0" ;
334
+ var SDK_VERSION = "0.19.1" ;
335
335
  var Transport = class {
336
336
  constructor(cfg) {
337
337
  this.cfg = cfg;
@@ -680,6 +680,47 @@ var Customers = class {
680
680
  path: `/api/v1/customers/${encodeURIComponent(id)}/balances`
681
681
  });
682
682
  }
683
+ /**
684
+ * One page of the customer's wallet ledger — every movement of wallet
685
+ * money, newest first — plus both wallet balances. Cursor-paginated: pass
686
+ * back `nextCursor` as `cursor`. `GET /api/v1/customers/:id/wallet`.
687
+ */
688
+ wallet(id, params = {}) {
689
+ return this.walletPage(`/api/v1/customers/${encodeURIComponent(id)}/wallet`, params);
690
+ }
691
+ /** {@link wallet}, addressing the customer by its `externalId`.
692
+ * `GET /api/v1/customers/ext/:externalId/wallet`. */
693
+ walletByExternalId(externalId, params = {}) {
694
+ return this.walletPage(
695
+ `/api/v1/customers/ext/${encodeURIComponent(externalId)}/wallet`,
696
+ params
697
+ );
698
+ }
699
+ /**
700
+ * Async iterator over the customer's WHOLE wallet ledger, newest first,
701
+ * following the cursor. `params.cursor` is ignored.
702
+ * `for await (const t of cnk.customers.iterateWallet(id)) { … }`
703
+ */
704
+ async *iterateWallet(id, params = {}) {
705
+ let cursor;
706
+ do {
707
+ const page = await this.wallet(id, { ...params, cursor });
708
+ for (const t of page.transactions) yield t;
709
+ cursor = page.nextCursor ?? void 0;
710
+ } while (cursor);
711
+ }
712
+ walletPage(path, params) {
713
+ return this.transport.request({
714
+ method: "GET",
715
+ path,
716
+ query: {
717
+ limit: params.limit,
718
+ cursor: params.cursor,
719
+ from: params.from,
720
+ to: params.to
721
+ }
722
+ });
723
+ }
683
724
  /** {@link balances}, addressing the customer by its `externalId`.
684
725
  * `GET /api/v1/customers/ext/:externalId/balances`. */
685
726
  balancesByExternalId(externalId) {
@@ -1185,6 +1226,7 @@ var UNIT_PATH = "/api/v1/signal/unit";
1185
1226
  var COMPOSITE_COMPLETE_PATH = "/api/v1/signal/composite/complete";
1186
1227
  var OUTCOME_COMPLETE_PATH = "/api/v1/signal/outcome/complete";
1187
1228
  var USAGE_LOG_PATH = "/api/v1/signal/usage-log";
1229
+ var USAGE_LOG_LOOKUP_PATH = "/api/v1/signal/usage-log/lookup";
1188
1230
  function signalToWire(signal) {
1189
1231
  const t = signal.tokens;
1190
1232
  const body = {
@@ -1304,6 +1346,7 @@ var Signals = class {
1304
1346
  ...customerRefToWire(input),
1305
1347
  runId: input.runId,
1306
1348
  ...input.member ? { member: input.member } : {},
1349
+ ...input.custom ? { custom: input.custom } : {},
1307
1350
  idempotencyKey
1308
1351
  },
1309
1352
  retry: true
@@ -1341,6 +1384,7 @@ var Signals = class {
1341
1384
  ...input.quantity != null ? { quantity: input.quantity } : {},
1342
1385
  ...input.member ? { member: input.member } : {},
1343
1386
  ...input.composite ? { composite: { [input.composite.ref]: input.composite.value } } : {},
1387
+ ...input.custom ? { custom: input.custom } : {},
1344
1388
  // Assigned HERE, before the send, so the SAME key rides every
1345
1389
  // transport-level retry below. Without it a single 500 followed by a
1346
1390
  // success is TWO un-keyed reports, and the server dedups on the key —
@@ -1395,6 +1439,7 @@ var Signals = class {
1395
1439
  body: {
1396
1440
  ...customerRefToWire(input),
1397
1441
  composite: { [input.composite.ref]: input.composite.value },
1442
+ ...input.custom ? { custom: input.custom } : {},
1398
1443
  // Auto-assigned like the others. A retry here could not double-BILL
1399
1444
  // even without it — closing a closed occurrence is a server-side
1400
1445
  // no-op — but that safety comes from occurrence-level dedup, not from
@@ -1444,6 +1489,26 @@ var Signals = class {
1444
1489
  }
1445
1490
  });
1446
1491
  }
1492
+ /**
1493
+ * Fetches up to 100 usage-log rows by id, in one call.
1494
+ * `GET /api/v1/signal/usage-log/lookup`.
1495
+ *
1496
+ * Built for linking a wallet debit to its usage: pass the `usageLogId`s
1497
+ * from `customers.wallet()` instead of paging through
1498
+ * {@link usageLog}. Scoped to your org, not to one customer — every row
1499
+ * carries its own `customerId`.
1500
+ *
1501
+ * Rows come back in the order of `ids`; duplicates are removed. Ids that
1502
+ * match nothing in your org are listed in `notFound`. More than 100
1503
+ * distinct ids is a 400.
1504
+ */
1505
+ lookupUsageLogs(ids) {
1506
+ return this.transport.request({
1507
+ method: "GET",
1508
+ path: USAGE_LOG_LOOKUP_PATH,
1509
+ query: { ids: ids.join(",") }
1510
+ });
1511
+ }
1447
1512
  };
1448
1513
 
1449
1514
  // src/resources/units.ts