@clocknext/sdk 0.19.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/README.md +28 -0
- package/dist/index.cjs +22 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +113 -1
- package/dist/index.d.ts +113 -1
- package/dist/index.js +22 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +3 -0
- package/src/resources/signals.ts +23 -0
- package/src/types.ts +77 -0
package/README.md
CHANGED
|
@@ -655,6 +655,34 @@ for await (const t of cnk.customers.iterateWallet(customerId)) {
|
|
|
655
655
|
}
|
|
656
656
|
```
|
|
657
657
|
|
|
658
|
+
### Look up usage rows by id
|
|
659
|
+
|
|
660
|
+
`signals.lookupUsageLogs(ids)` returns up to 100 usage-log rows in one call —
|
|
661
|
+
for example the row behind each wallet debit's `usageLogId`. It is scoped to
|
|
662
|
+
your org, not one customer: every row has its own `customerId`. Rows come back
|
|
663
|
+
in the order of `ids`; ids with no row in your org are listed in `notFound`.
|
|
664
|
+
|
|
665
|
+
Each row has `entitlement: { type, id, name }` — `type` is `credit`, `outcome`,
|
|
666
|
+
`outcome_completion`, `unit`, `composite_completion` or `wallet` (a wallet row
|
|
667
|
+
is named `"Wallet"`) — and only the matching group (`credit`, `outcome`,
|
|
668
|
+
`outcomeCompletion`, `unit`, `compositeCompletion`, `wallet`) is set.
|
|
669
|
+
`composite: { id, refId, runId }` names the composite that pays for a row.
|
|
670
|
+
`cost.customerCost` is what the row charged, so it matches the wallet debit.
|
|
671
|
+
|
|
672
|
+
```ts
|
|
673
|
+
const ledger = await cnk.customers.wallet(customerId);
|
|
674
|
+
const ids = ledger.transactions
|
|
675
|
+
.filter((t) => t.source === "USAGE_LOG" && t.usageLogId)
|
|
676
|
+
.map((t) => t.usageLogId!);
|
|
677
|
+
|
|
678
|
+
const { usageLogs, notFound } = await cnk.signals.lookupUsageLogs(ids);
|
|
679
|
+
for (const row of usageLogs) {
|
|
680
|
+
row.entitlement.type; // what was charged
|
|
681
|
+
row.cost.customerCost; // what it charged
|
|
682
|
+
row.composite; // { id, refId, runId } | null
|
|
683
|
+
}
|
|
684
|
+
```
|
|
685
|
+
|
|
658
686
|
To change how much a customer is granted **every billing cycle** (not just
|
|
659
687
|
their balance right now), use `updateRecurringGrant`. Any increase or decrease
|
|
660
688
|
applies to their balance immediately. `quantity` is USD for the wallet and a
|
package/dist/index.cjs
CHANGED
|
@@ -333,7 +333,7 @@ function sleep(ms) {
|
|
|
333
333
|
}
|
|
334
334
|
|
|
335
335
|
// src/http.ts
|
|
336
|
-
var SDK_VERSION = "0.19.
|
|
336
|
+
var SDK_VERSION = "0.19.1" ;
|
|
337
337
|
var Transport = class {
|
|
338
338
|
constructor(cfg) {
|
|
339
339
|
this.cfg = cfg;
|
|
@@ -1228,6 +1228,7 @@ var UNIT_PATH = "/api/v1/signal/unit";
|
|
|
1228
1228
|
var COMPOSITE_COMPLETE_PATH = "/api/v1/signal/composite/complete";
|
|
1229
1229
|
var OUTCOME_COMPLETE_PATH = "/api/v1/signal/outcome/complete";
|
|
1230
1230
|
var USAGE_LOG_PATH = "/api/v1/signal/usage-log";
|
|
1231
|
+
var USAGE_LOG_LOOKUP_PATH = "/api/v1/signal/usage-log/lookup";
|
|
1231
1232
|
function signalToWire(signal) {
|
|
1232
1233
|
const t = signal.tokens;
|
|
1233
1234
|
const body = {
|
|
@@ -1490,6 +1491,26 @@ var Signals = class {
|
|
|
1490
1491
|
}
|
|
1491
1492
|
});
|
|
1492
1493
|
}
|
|
1494
|
+
/**
|
|
1495
|
+
* Fetches up to 100 usage-log rows by id, in one call.
|
|
1496
|
+
* `GET /api/v1/signal/usage-log/lookup`.
|
|
1497
|
+
*
|
|
1498
|
+
* Built for linking a wallet debit to its usage: pass the `usageLogId`s
|
|
1499
|
+
* from `customers.wallet()` instead of paging through
|
|
1500
|
+
* {@link usageLog}. Scoped to your org, not to one customer — every row
|
|
1501
|
+
* carries its own `customerId`.
|
|
1502
|
+
*
|
|
1503
|
+
* Rows come back in the order of `ids`; duplicates are removed. Ids that
|
|
1504
|
+
* match nothing in your org are listed in `notFound`. More than 100
|
|
1505
|
+
* distinct ids is a 400.
|
|
1506
|
+
*/
|
|
1507
|
+
lookupUsageLogs(ids) {
|
|
1508
|
+
return this.transport.request({
|
|
1509
|
+
method: "GET",
|
|
1510
|
+
path: USAGE_LOG_LOOKUP_PATH,
|
|
1511
|
+
query: { ids: ids.join(",") }
|
|
1512
|
+
});
|
|
1513
|
+
}
|
|
1493
1514
|
};
|
|
1494
1515
|
|
|
1495
1516
|
// src/resources/units.ts
|