@clocknext/sdk 0.13.0 → 0.15.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 +200 -140
- package/dist/index.cjs +213 -438
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +394 -812
- package/dist/index.d.ts +394 -812
- package/dist/index.js +213 -438
- package/dist/index.js.map +1 -1
- package/examples/node-basic.ts +24 -32
- package/package.json +1 -1
- package/src/client.ts +3 -27
- package/src/customer-ref.ts +14 -0
- package/src/errors.ts +8 -1
- package/src/filters.ts +1 -1
- package/src/index.ts +13 -59
- package/src/resources/customers.ts +201 -82
- package/src/resources/invoices.ts +1 -1
- package/src/resources/plans.ts +4 -56
- package/src/resources/signals.ts +33 -38
- package/src/types.ts +301 -610
- package/src/resources/composites.ts +0 -47
- package/src/resources/credits.ts +0 -76
- package/src/resources/outcomes.ts +0 -82
- package/src/resources/units.ts +0 -76
- package/src/resources/webhooks.ts +0 -37
- package/src/resources/workspace.ts +0 -33
package/dist/index.d.cts
CHANGED
|
@@ -56,37 +56,31 @@ interface CompositeTag {
|
|
|
56
56
|
/** Your correlation value for this occurrence, stored verbatim. */
|
|
57
57
|
value: string | number;
|
|
58
58
|
}
|
|
59
|
-
/**
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
lastFour: string;
|
|
72
|
-
expiresAt: string | null;
|
|
73
|
-
} | null;
|
|
74
|
-
}
|
|
75
|
-
/** One model the org has enabled — `cnk.workspace.models()`. The `modelId` is
|
|
76
|
-
* what you put in a signal's `model`. Prices are USD per 1,000,000 tokens. */
|
|
77
|
-
interface Model {
|
|
78
|
-
modelId: string;
|
|
79
|
-
modelName: string;
|
|
80
|
-
provider: string;
|
|
81
|
-
providerName: string;
|
|
82
|
-
isActive: boolean;
|
|
83
|
-
inputPrice: number;
|
|
84
|
-
outputPrice: number;
|
|
85
|
-
cachePrice: number;
|
|
86
|
-
}
|
|
87
|
-
interface SignalBase {
|
|
88
|
-
/** The customer this usage belongs to (required). */
|
|
59
|
+
/**
|
|
60
|
+
* How a request names its customer: by OUR id (`customerId`) or by YOUR id for
|
|
61
|
+
* them (`externalId` — the value set on the customer via
|
|
62
|
+
* `customers.create()` / `customers.update()`). At least one is required.
|
|
63
|
+
*
|
|
64
|
+
* When both are sent, `customerId` wins and `externalId` is ignored — the
|
|
65
|
+
* server does not check that they agree. An `externalId` matching no active
|
|
66
|
+
* customer is a `NotFoundError` (or, on an async signal, leaves it Pending
|
|
67
|
+
* with that reason — retry once the customer exists).
|
|
68
|
+
*/
|
|
69
|
+
type CustomerRef = {
|
|
70
|
+
/** Our customer id. Wins over `externalId` when both are sent. */
|
|
89
71
|
customerId: string;
|
|
72
|
+
externalId?: string;
|
|
73
|
+
} | {
|
|
74
|
+
customerId?: undefined;
|
|
75
|
+
/** Your id for the customer: 1–32 letters, numbers or "-", matched
|
|
76
|
+
* exactly (case-sensitive). */
|
|
77
|
+
externalId: string;
|
|
78
|
+
};
|
|
79
|
+
/** `Omit` that keeps a union a union (plain `Omit` flattens it to the
|
|
80
|
+
* members' shared keys, losing the {@link CustomerRef} either/or). */
|
|
81
|
+
type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
|
|
82
|
+
/** Every signal names its customer — see {@link CustomerRef}. */
|
|
83
|
+
interface SignalFields {
|
|
90
84
|
/**
|
|
91
85
|
* The model's catalog id — must be enabled in your ClockNext org
|
|
92
86
|
* (Settings → Models). Matched case-insensitively against `OrgModel.modelId`.
|
|
@@ -108,18 +102,19 @@ interface SignalBase {
|
|
|
108
102
|
*/
|
|
109
103
|
idempotencyKey?: string;
|
|
110
104
|
}
|
|
105
|
+
type SignalBase = CustomerRef & SignalFields;
|
|
111
106
|
/** Meters a credit, identified by the credit's stable `agentKey`. */
|
|
112
|
-
|
|
107
|
+
type CreditSignal = SignalBase & {
|
|
113
108
|
type: "credit";
|
|
114
109
|
/** The Credit's stable agent key (assigned when the credit was created). */
|
|
115
110
|
agentKey: string;
|
|
116
111
|
/** Optional composite this signal belongs to. See {@link CompositeTag}. */
|
|
117
112
|
composite?: CompositeTag;
|
|
118
|
-
}
|
|
113
|
+
};
|
|
119
114
|
/** Debits the customer's wallet in USD at the model's cost. */
|
|
120
|
-
|
|
115
|
+
type WalletSignal = SignalBase & {
|
|
121
116
|
type: "wallet";
|
|
122
|
-
}
|
|
117
|
+
};
|
|
123
118
|
/**
|
|
124
119
|
* Records one step of a multi-call outcome run. The `agentKey` identifies the
|
|
125
120
|
* step (and the outcome); `runId` groups every signal of a single run, so a step
|
|
@@ -132,7 +127,7 @@ interface WalletSignal extends SignalBase {
|
|
|
132
127
|
* carries `complete` — see {@link OutcomeCompletionInput} /
|
|
133
128
|
* `signals.completeOutcome()`, its own dedicated route.
|
|
134
129
|
*/
|
|
135
|
-
|
|
130
|
+
type OutcomeSignal = SignalBase & {
|
|
136
131
|
type: "outcome";
|
|
137
132
|
/** The OutcomeStep's stable agent key — identifies the outcome AND the step. */
|
|
138
133
|
agentKey: string;
|
|
@@ -144,12 +139,12 @@ interface OutcomeSignal extends SignalBase {
|
|
|
144
139
|
runId: string;
|
|
145
140
|
/** Optional composite this signal belongs to. See {@link CompositeTag}. */
|
|
146
141
|
composite?: CompositeTag;
|
|
147
|
-
}
|
|
142
|
+
};
|
|
148
143
|
type Signal = CreditSignal | WalletSignal | OutcomeSignal;
|
|
149
144
|
/** Helper input shapes for the per-type convenience methods. */
|
|
150
|
-
type CreditInput =
|
|
151
|
-
type WalletInput =
|
|
152
|
-
type OutcomeInput =
|
|
145
|
+
type CreditInput = DistributiveOmit<CreditSignal, "type">;
|
|
146
|
+
type WalletInput = DistributiveOmit<WalletSignal, "type">;
|
|
147
|
+
type OutcomeInput = DistributiveOmit<OutcomeSignal, "type">;
|
|
153
148
|
/**
|
|
154
149
|
* Input for `signals.completeOutcome()` — closes ONE outcome run, the outcome
|
|
155
150
|
* mirror of {@link CompositeCompletionInput}. No `agentKey`, no `usage`: this
|
|
@@ -161,17 +156,17 @@ type OutcomeInput = Omit<OutcomeSignal, "type">;
|
|
|
161
156
|
* `signals.completeComposite()` — the two completions are independent, and
|
|
162
157
|
* neither implies the other.
|
|
163
158
|
*/
|
|
164
|
-
|
|
165
|
-
customerId: string;
|
|
159
|
+
type OutcomeCompletionInput = CustomerRef & {
|
|
166
160
|
/** The same `runId` the run's step signals were sent with. */
|
|
167
161
|
runId: string;
|
|
168
162
|
/** Optional member (email) this completion is attributed to. */
|
|
169
163
|
member?: string;
|
|
170
|
-
/** Idempotency key, auto-generated if omitted. Sending
|
|
171
|
-
* the same run is already a safe no-op server-side, so this only
|
|
172
|
-
* a retry into one attempt rather than protecting against a
|
|
164
|
+
/** Idempotency key, auto-generated if omitted. Sending this completion twice
|
|
165
|
+
* for the same run is already a safe no-op server-side, so this only
|
|
166
|
+
* collapses a retry into one attempt rather than protecting against a
|
|
167
|
+
* double bill. */
|
|
173
168
|
idempotencyKey?: string;
|
|
174
|
-
}
|
|
169
|
+
};
|
|
175
170
|
/**
|
|
176
171
|
* The result of `signals.completeOutcome()`.
|
|
177
172
|
*
|
|
@@ -274,7 +269,7 @@ interface SerializedUsageLog {
|
|
|
274
269
|
* exhausted allowance is detected by the worker LATER and never surfaces here —
|
|
275
270
|
* the signal is simply dropped. A `202` therefore means "accepted", never
|
|
276
271
|
* "recorded". To confirm a signal actually landed, read it back with
|
|
277
|
-
* `signals.
|
|
272
|
+
* `signals.usageLog({ customerId })`.
|
|
278
273
|
*
|
|
279
274
|
* When the server has no queue configured it prices inline instead and returns
|
|
280
275
|
* `queued: false` with a populated `usageLog`, validating synchronously.
|
|
@@ -296,7 +291,7 @@ interface TrackResult {
|
|
|
296
291
|
* and will price it shortly. It can no longer be lost, but
|
|
297
292
|
* it is not billed yet and `usageLog` is null. A rejection
|
|
298
293
|
* discovered during pricing will NOT come back to you here,
|
|
299
|
-
* nor on `onError`. `signals.
|
|
294
|
+
* nor on `onError`. `signals.usageLog()` shows what got priced;
|
|
300
295
|
* the dashboard's signal log — owner-only, by design — is
|
|
301
296
|
* where an individual rejection says why.
|
|
302
297
|
* `"recorded"` — the server priced it inline and `usageLog` is populated.
|
|
@@ -341,23 +336,98 @@ interface TrackResult {
|
|
|
341
336
|
*/
|
|
342
337
|
rawId?: string;
|
|
343
338
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
339
|
+
/** A preset time window, or `"custom"` for an explicit `from`/`to` range. */
|
|
340
|
+
type UsageLogPeriod = "all" | "today" | "7d" | "30d" | "90d" | "custom";
|
|
341
|
+
interface UsageLogListParams {
|
|
342
|
+
customerId: string;
|
|
343
|
+
/** Default 50, max 200. */
|
|
344
|
+
limit?: number;
|
|
345
|
+
/** Pass back a previous page's `nextCursor` to fetch the next page. Omit for
|
|
346
|
+
* the first page. */
|
|
347
|
+
cursor?: string;
|
|
348
|
+
/** Default `"all"`. Pair `"custom"` with `from`/`to`. */
|
|
349
|
+
period?: UsageLogPeriod;
|
|
350
|
+
/** `YYYY-MM-DD`, only used when `period` is `"custom"`. */
|
|
351
|
+
from?: string;
|
|
352
|
+
/** `YYYY-MM-DD`, only used when `period` is `"custom"`. */
|
|
353
|
+
to?: string;
|
|
354
|
+
}
|
|
355
|
+
interface UsageLogAppliedRule {
|
|
356
|
+
ruleId: string | null;
|
|
357
|
+
ruleName: string;
|
|
358
|
+
mode: "MARGIN" | "CREDIT" | null;
|
|
359
|
+
marginPercentApplied: number | null;
|
|
360
|
+
/** Formatted, same as {@link UsageLogEntry.credit}'s `amount`. */
|
|
361
|
+
creditsApplied: string;
|
|
362
|
+
}
|
|
363
|
+
interface UsageLogOutcomeAttribution {
|
|
364
|
+
/** "2 / 4" — the step this call performed, and the outcome's total step
|
|
365
|
+
* count. Not a progress target: a step may repeat within a run. */
|
|
366
|
+
step: string | null;
|
|
367
|
+
stepName: string | null;
|
|
368
|
+
runId: string | null;
|
|
369
|
+
/** How many signals the run holds. */
|
|
370
|
+
runSignals: number;
|
|
371
|
+
/** True once the run closed (`complete: true` was sent for it). */
|
|
372
|
+
closedRun: boolean;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* One row of a customer's usage history, merged from every meter kind
|
|
376
|
+
* (`UsageLog`, `UnitUsageLog`, completed composite occurrences) into one
|
|
377
|
+
* feed and sorted by time — the same rows the customer portal's own "Usage
|
|
378
|
+
* logs" table shows. `model`, `credit`, `outcome`, `unit` and `composite` are
|
|
379
|
+
* each `null` unless `kind` matches that group.
|
|
380
|
+
*/
|
|
381
|
+
interface UsageLogEntry {
|
|
382
|
+
id: string;
|
|
383
|
+
createdAt: string;
|
|
384
|
+
kind: "credit" | "outcome" | "unit" | "wallet" | "composite";
|
|
385
|
+
status: SignalStatus;
|
|
386
|
+
typeName: string | null;
|
|
387
|
+
member: string | null;
|
|
388
|
+
model: {
|
|
389
|
+
name: string | null;
|
|
390
|
+
provider: string | null;
|
|
391
|
+
} | null;
|
|
392
|
+
usage: {
|
|
393
|
+
inputTokens: number;
|
|
394
|
+
outputTokens: number;
|
|
395
|
+
cacheTokens: number;
|
|
349
396
|
};
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
profit: number;
|
|
355
|
-
creditsUsed: number;
|
|
397
|
+
/** Formatted USD strings (e.g. `"$0.0064"`). */
|
|
398
|
+
cost: {
|
|
399
|
+
providedCost: string;
|
|
400
|
+
customerCost: string;
|
|
356
401
|
};
|
|
357
|
-
|
|
402
|
+
/** Populated only when `kind === "credit"`. `amount` is a formatted credit
|
|
403
|
+
* value, honouring the org's credit-decimals display setting. */
|
|
404
|
+
credit: {
|
|
405
|
+
amount: string;
|
|
406
|
+
appliedRules: UsageLogAppliedRule[];
|
|
407
|
+
} | null;
|
|
408
|
+
/** Populated only when `kind === "outcome"`. */
|
|
409
|
+
outcome: UsageLogOutcomeAttribution | null;
|
|
410
|
+
/** Populated only when `kind === "unit"`. `quantity` is formatted. */
|
|
411
|
+
unit: {
|
|
412
|
+
quantity: string;
|
|
413
|
+
} | null;
|
|
414
|
+
/** Populated only when `kind === "composite"`. `amount` is a formatted USD
|
|
415
|
+
* price — the composite's flat price, read live, not stored per row. */
|
|
416
|
+
composite: {
|
|
417
|
+
amount: string;
|
|
418
|
+
} | null;
|
|
419
|
+
}
|
|
420
|
+
interface UsageLogPage {
|
|
421
|
+
usageLogs: UsageLogEntry[];
|
|
422
|
+
/** Pass this back as `cursor` to fetch the next page; `null` on the last
|
|
423
|
+
* page. */
|
|
424
|
+
nextCursor: string | null;
|
|
358
425
|
}
|
|
359
426
|
interface ApiCustomer {
|
|
360
427
|
id: string;
|
|
428
|
+
/** Your own id for this customer, or `null` when unset. See
|
|
429
|
+
* {@link CustomerProfileInput.externalId}. */
|
|
430
|
+
externalId: string | null;
|
|
361
431
|
slug: string;
|
|
362
432
|
name: string;
|
|
363
433
|
description: string | null;
|
|
@@ -373,11 +443,23 @@ interface ApiCustomer {
|
|
|
373
443
|
taxId: string | null;
|
|
374
444
|
currencyCode: string;
|
|
375
445
|
creditAllowance: number;
|
|
446
|
+
recurringTransactionEmail: boolean;
|
|
447
|
+
autoRecurring: boolean;
|
|
376
448
|
createdAt: string;
|
|
377
449
|
updatedAt: string;
|
|
378
450
|
}
|
|
379
451
|
/** Writable customer profile fields. `null` clears a column; omit to leave it. */
|
|
380
452
|
interface CustomerProfileInput {
|
|
453
|
+
/**
|
|
454
|
+
* The id YOUR product uses for this customer: 1–32 letters, numbers or "-",
|
|
455
|
+
* case-sensitive. Unique among the org's active customers (a clash is a
|
|
456
|
+
* `ConflictError`; an archived customer's id can be reused). Once set,
|
|
457
|
+
* signals and `purchases.create()` can take `externalId` instead of
|
|
458
|
+
* `customerId`, and `customers.getByExternalId()` / `updateByExternalId()` /
|
|
459
|
+
* `updateRecurringGrantByExternalId()` address the customer by it. `null`
|
|
460
|
+
* clears it on update.
|
|
461
|
+
*/
|
|
462
|
+
externalId?: string | null;
|
|
381
463
|
name?: string;
|
|
382
464
|
description?: string | null;
|
|
383
465
|
email?: string | null;
|
|
@@ -392,6 +474,10 @@ interface CustomerProfileInput {
|
|
|
392
474
|
taxId?: string | null;
|
|
393
475
|
/** ISO 4217 (3 letters); must be enabled for the org. */
|
|
394
476
|
currencyCode?: string;
|
|
477
|
+
/** Send the invoice, payment receipt and card-payment-failed emails for recurring invoices. Defaults to `true` on create. */
|
|
478
|
+
recurringTransactionEmail?: boolean;
|
|
479
|
+
/** Issue every recurring invoice as `AUTO_CLOSED` (applied as if paid, never payable). Defaults to `false` on create. */
|
|
480
|
+
autoRecurring?: boolean;
|
|
395
481
|
}
|
|
396
482
|
/** `name` and `email` are required on create; every other field is optional. */
|
|
397
483
|
type CreateCustomerInput = CustomerProfileInput & {
|
|
@@ -423,7 +509,7 @@ interface OutcomeBalance {
|
|
|
423
509
|
remaining: number;
|
|
424
510
|
/** Each step's `agentKey` is what `signals.outcome()` and the outcome adjust
|
|
425
511
|
* API use to address this outcome at runtime. The outcome also has its own
|
|
426
|
-
* separate key (
|
|
512
|
+
* separate key (the outcome's own `agentKey`), but neither of those APIs accepts
|
|
427
513
|
* it — it identifies the outcome in the catalogue, not in a signal. */
|
|
428
514
|
steps: {
|
|
429
515
|
id: string;
|
|
@@ -450,9 +536,15 @@ interface CustomerBalances {
|
|
|
450
536
|
rateUsd: number;
|
|
451
537
|
};
|
|
452
538
|
hasPlan: boolean;
|
|
539
|
+
/** `null` when the plan has no Wallet component. */
|
|
453
540
|
wallet: {
|
|
454
541
|
balanceUsd: number;
|
|
455
542
|
} | null;
|
|
543
|
+
/** The Reserved Wallet; `null` when the org hasn't enabled it. Independent
|
|
544
|
+
* of `wallet` — present whether or not the plan has a Wallet. */
|
|
545
|
+
reservedWallet: {
|
|
546
|
+
balanceUsd: number;
|
|
547
|
+
} | null;
|
|
456
548
|
credits: CreditBalance[];
|
|
457
549
|
outcomes: OutcomeBalance[];
|
|
458
550
|
units: UnitBalance[];
|
|
@@ -503,7 +595,6 @@ interface PortalToken {
|
|
|
503
595
|
type BillingCycle = "MONTHLY" | "QUARTERLY" | "SEMI_ANNUAL" | "YEARLY" | "EVERY_5_MIN" | "FREE";
|
|
504
596
|
type PlanType = "WALLET" | "BUNDLE";
|
|
505
597
|
type PlanKind = "FLAT_PRICE" | "PAY_AS_YOU_GO" | "PAY_PER_SEAT";
|
|
506
|
-
/** A plan component's meter type. */
|
|
507
598
|
/**
|
|
508
599
|
* A plan component's kind.
|
|
509
600
|
*
|
|
@@ -515,116 +606,6 @@ type PlanKind = "FLAT_PRICE" | "PAY_AS_YOU_GO" | "PAY_PER_SEAT";
|
|
|
515
606
|
type ComponentType = "WALLET" | "CREDIT" | "OUTCOME" | "UNIT" | "FLAT" | "PRICING_METRIC";
|
|
516
607
|
/** ADVANCE bills up-front for the cycle; ARREAR bills for what was consumed. */
|
|
517
608
|
type BillingMode = "ADVANCE" | "ARREAR";
|
|
518
|
-
/** Prepaid USD wallet. `amount` is the funded balance (required). Max one
|
|
519
|
-
* wallet component per plan. */
|
|
520
|
-
interface WalletComponentInput {
|
|
521
|
-
type: "WALLET";
|
|
522
|
-
billingMode: BillingMode;
|
|
523
|
-
amount: number;
|
|
524
|
-
}
|
|
525
|
-
/** A one-off flat fee — `amount` is required. Max one flat component per plan;
|
|
526
|
-
* not allowed on FREE plans. */
|
|
527
|
-
interface FlatComponentInput {
|
|
528
|
-
type: "FLAT";
|
|
529
|
-
billingMode: BillingMode;
|
|
530
|
-
amount: number;
|
|
531
|
-
}
|
|
532
|
-
/** A credit entitlement, referenced by `creditId`. Billed ADVANCE it needs a
|
|
533
|
-
* granted `quantity`; billed ARREAR it meters usage with no upfront grant. */
|
|
534
|
-
type CreditComponentInput = {
|
|
535
|
-
type: "CREDIT";
|
|
536
|
-
billingMode: "ADVANCE";
|
|
537
|
-
creditId: string;
|
|
538
|
-
quantity: number;
|
|
539
|
-
} | {
|
|
540
|
-
type: "CREDIT";
|
|
541
|
-
billingMode: "ARREAR";
|
|
542
|
-
creditId: string;
|
|
543
|
-
quantity?: number | null;
|
|
544
|
-
};
|
|
545
|
-
/** An outcome entitlement, referenced by `outcomeId`. ADVANCE needs a granted
|
|
546
|
-
* `quantity`; ARREAR meters usage. */
|
|
547
|
-
type OutcomeComponentInput = {
|
|
548
|
-
type: "OUTCOME";
|
|
549
|
-
billingMode: "ADVANCE";
|
|
550
|
-
outcomeId: string;
|
|
551
|
-
quantity: number;
|
|
552
|
-
} | {
|
|
553
|
-
type: "OUTCOME";
|
|
554
|
-
billingMode: "ARREAR";
|
|
555
|
-
outcomeId: string;
|
|
556
|
-
quantity?: number | null;
|
|
557
|
-
};
|
|
558
|
-
/** A unit entitlement, referenced by `unitId`. ADVANCE needs a granted
|
|
559
|
-
* `quantity`; ARREAR meters usage. */
|
|
560
|
-
type UnitComponentInput = {
|
|
561
|
-
type: "UNIT";
|
|
562
|
-
billingMode: "ADVANCE";
|
|
563
|
-
unitId: string;
|
|
564
|
-
quantity: number;
|
|
565
|
-
} | {
|
|
566
|
-
type: "UNIT";
|
|
567
|
-
billingMode: "ARREAR";
|
|
568
|
-
unitId: string;
|
|
569
|
-
quantity?: number | null;
|
|
570
|
-
};
|
|
571
|
-
/**
|
|
572
|
-
* A COMPOSITE sold on the plan, referenced by `pricingMetricId` (the id from
|
|
573
|
-
* `composites.list()`). This is the line that makes a composite bill: the
|
|
574
|
-
* catalogue entry on its own charges nobody, and this component is what turns
|
|
575
|
-
* it into money — `quantity × the composite's price`, frozen into the purchase
|
|
576
|
-
* snapshot at buy time.
|
|
577
|
-
*
|
|
578
|
-
* The two billing modes differ in what `quantity` means:
|
|
579
|
-
* - **ADVANCE** — a PREPAID POOL of `quantity` flat-rate slots, shared
|
|
580
|
-
* across whichever credits / outcomes / units the composite wraps. Each
|
|
581
|
-
* distinct tag value claims one slot on completion; repeat signals under a
|
|
582
|
-
* value reuse the slot they already claimed, at no extra cost. Once every
|
|
583
|
-
* slot is claimed, further occurrences are refused rather than billed.
|
|
584
|
-
* - **ARREAR** — nothing prepaid; completed occurrences are counted on the
|
|
585
|
-
* cycle-end line.
|
|
586
|
-
*
|
|
587
|
-
* `type` is the wire value `"PRICING_METRIC"`, not `"COMPOSITE"`: the product
|
|
588
|
-
* word changed but the stored enum did not, and the API still speaks the old
|
|
589
|
-
* one. That mismatch is the server's, and it is surfaced rather than hidden so
|
|
590
|
-
* a response and a request read the same.
|
|
591
|
-
*/
|
|
592
|
-
type CompositeComponentInput = {
|
|
593
|
-
type: "PRICING_METRIC";
|
|
594
|
-
billingMode: "ADVANCE";
|
|
595
|
-
pricingMetricId: string;
|
|
596
|
-
quantity: number;
|
|
597
|
-
} | {
|
|
598
|
-
type: "PRICING_METRIC";
|
|
599
|
-
billingMode: "ARREAR";
|
|
600
|
-
pricingMetricId: string;
|
|
601
|
-
quantity?: number | null;
|
|
602
|
-
};
|
|
603
|
-
/**
|
|
604
|
-
* One entitlement line in a plan — a discriminated union on `type` (and, where
|
|
605
|
-
* it matters, `billingMode`) so the per-type fields the server requires are
|
|
606
|
-
* enforced at compile time instead of surfacing as runtime 422s:
|
|
607
|
-
* - CREDIT / OUTCOME / UNIT require their matching id;
|
|
608
|
-
* - PRICING_METRIC (a composite) requires `pricingMetricId`;
|
|
609
|
-
* - CREDIT / OUTCOME / UNIT / PRICING_METRIC require `quantity` when billed
|
|
610
|
-
* ADVANCE;
|
|
611
|
-
* - WALLET / FLAT require `amount`.
|
|
612
|
-
*/
|
|
613
|
-
type PlanComponentInput = WalletComponentInput | FlatComponentInput | CreditComponentInput | OutcomeComponentInput | UnitComponentInput | CompositeComponentInput;
|
|
614
|
-
interface CreatePlanInput {
|
|
615
|
-
name: string;
|
|
616
|
-
description?: string | null;
|
|
617
|
-
billingCycle: BillingCycle;
|
|
618
|
-
/** Carry an unused balance into the next cycle. Default true. */
|
|
619
|
-
carryForward?: boolean;
|
|
620
|
-
/** ISO 4217 (3 letters). Default "USD". */
|
|
621
|
-
currencyCode?: string;
|
|
622
|
-
isActive?: boolean;
|
|
623
|
-
/** At least one component. FREE plans must be ADVANCE-only with no FLAT component. */
|
|
624
|
-
components: PlanComponentInput[];
|
|
625
|
-
}
|
|
626
|
-
/** A full-rewrite update carries the complete plan (same shape as create). */
|
|
627
|
-
type UpdatePlanInput = CreatePlanInput;
|
|
628
609
|
interface PlanComponent {
|
|
629
610
|
id: string;
|
|
630
611
|
type: ComponentType;
|
|
@@ -632,11 +613,9 @@ interface PlanComponent {
|
|
|
632
613
|
creditId: string | null;
|
|
633
614
|
outcomeId: string | null;
|
|
634
615
|
unitId: string | null;
|
|
635
|
-
/** The composite this component sells, on a `PRICING_METRIC`
|
|
636
|
-
*
|
|
637
|
-
|
|
638
|
-
* silently dropped every composite component. */
|
|
639
|
-
pricingMetricId: string | null;
|
|
616
|
+
/** The id of the composite this component sells, on a `PRICING_METRIC`
|
|
617
|
+
* component. */
|
|
618
|
+
compositeId: string | null;
|
|
640
619
|
targetName: string | null;
|
|
641
620
|
quantity: number | null;
|
|
642
621
|
amount: number | null;
|
|
@@ -658,22 +637,8 @@ interface Plan {
|
|
|
658
637
|
isActive: boolean;
|
|
659
638
|
components: PlanComponent[];
|
|
660
639
|
}
|
|
661
|
-
/** The richer plan returned by `plans.get()` (adds aggregate stats). */
|
|
662
|
-
interface PlanDetail extends Plan {
|
|
663
|
-
createdAt: string;
|
|
664
|
-
createdByName: string | null;
|
|
665
|
-
customerCount: number;
|
|
666
|
-
invoiceCount: number;
|
|
667
|
-
openInvoiceCount: number;
|
|
668
|
-
stats: {
|
|
669
|
-
totalInvoiced: number;
|
|
670
|
-
totalCollected: number;
|
|
671
|
-
openBalance: number;
|
|
672
|
-
};
|
|
673
|
-
}
|
|
674
640
|
type PurchaseStatus = "SCHEDULED" | "ACTIVE" | "CANCELLED";
|
|
675
|
-
|
|
676
|
-
customerId: string;
|
|
641
|
+
type CreatePurchaseInput = CustomerRef & {
|
|
677
642
|
planId: string;
|
|
678
643
|
/** `YYYY-MM-DD`. Defaults to today; must be a valid non-past date. */
|
|
679
644
|
billingDate?: string;
|
|
@@ -681,7 +646,7 @@ interface CreatePurchaseInput {
|
|
|
681
646
|
autoPayment?: boolean;
|
|
682
647
|
/** Auto-void the purchase if unpaid after N minutes. */
|
|
683
648
|
voidAfterMinutes?: number;
|
|
684
|
-
}
|
|
649
|
+
};
|
|
685
650
|
interface Purchase {
|
|
686
651
|
id: string;
|
|
687
652
|
purchaseNumber: string;
|
|
@@ -739,7 +704,9 @@ interface PurchaseDetail {
|
|
|
739
704
|
paidCount: number;
|
|
740
705
|
};
|
|
741
706
|
}
|
|
742
|
-
|
|
707
|
+
/** `AUTO_CLOSED` — a recurring invoice for a customer with `autoRecurring` on:
|
|
708
|
+
* applied as if paid, but never payable. */
|
|
709
|
+
type InvoiceStatus = "OPEN" | "PAID" | "VOID" | "AUTO_CLOSED";
|
|
743
710
|
/** Trimmed row from `invoices.list()`. */
|
|
744
711
|
interface InvoiceListRow {
|
|
745
712
|
id: string;
|
|
@@ -903,64 +870,76 @@ interface UpdateMemberInput {
|
|
|
903
870
|
/** Must be unique (case-insensitively) among the customer's active members. */
|
|
904
871
|
email?: string;
|
|
905
872
|
}
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
*
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
type
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
currencyRateUsd: number;
|
|
921
|
-
notes: string | null;
|
|
922
|
-
batchId: string | null;
|
|
923
|
-
createdAt: string;
|
|
924
|
-
createdByName: string | null;
|
|
925
|
-
/** Set only on a wallet-funded metering debit: which kind of entitlement was
|
|
926
|
-
* consumed. Null on top-ups and manual adjustments. */
|
|
927
|
-
entitlementType: WalletEntitlementKind | null;
|
|
928
|
-
/** Id of the credit / outcome / unit consumed. Null unless
|
|
929
|
-
* `entitlementType` is set. */
|
|
930
|
-
targetId: string | null;
|
|
931
|
-
/** Its name at the time of the debit. */
|
|
932
|
-
targetName: string | null;
|
|
933
|
-
/** The signal this debit paid for (credit / outcome). In wallet-funded mode
|
|
934
|
-
* no invoice exists, so this is the only trail from a charge to its cause. */
|
|
935
|
-
usageLogId: string | null;
|
|
936
|
-
/** The unit event this debit paid for. */
|
|
937
|
-
unitUsageLogId: string | null;
|
|
938
|
-
}
|
|
939
|
-
interface WalletList {
|
|
940
|
-
balanceUsd: number;
|
|
941
|
-
transactions: WalletTransaction[];
|
|
942
|
-
}
|
|
943
|
-
interface WalletEntryInput {
|
|
944
|
-
/** DEBIT spends, CREDIT tops up. */
|
|
945
|
-
type: WalletTransactionType;
|
|
946
|
-
/** Always positive; the sign comes from `type`. */
|
|
947
|
-
amount: number;
|
|
873
|
+
/**
|
|
874
|
+
* Which of a customer's two wallet balances an entry moves: `MAIN` (the
|
|
875
|
+
* ordinary wallet) or `RESERVED` (the Reserved Wallet — an org-gated second
|
|
876
|
+
* balance behind it; see {@link WalletAdjustInput.pool}).
|
|
877
|
+
*/
|
|
878
|
+
type WalletPool = "MAIN" | "RESERVED";
|
|
879
|
+
/** Top up (positive) or draw down (negative) a customer's wallet. `delta` is
|
|
880
|
+
* a non-zero amount in USD (cents allowed); absolute value ≤ 10,000,000. No
|
|
881
|
+
* `agentKey` — a customer has exactly one wallet. The wallet can always be
|
|
882
|
+
* adjusted, whatever the customer's plan (even with no plan). A draw-down is
|
|
883
|
+
* never rejected or floored for going below 0 — the wallet may read negative. */
|
|
884
|
+
interface WalletAdjustInput {
|
|
885
|
+
/** Signed change in USD: positive tops up, negative draws down. */
|
|
886
|
+
delta: number;
|
|
948
887
|
notes?: string;
|
|
888
|
+
/**
|
|
889
|
+
* Which balance to move. Default `"MAIN"`, the ordinary wallet.
|
|
890
|
+
*
|
|
891
|
+
* `"RESERVED"` moves the Reserved Wallet instead — a second balance behind
|
|
892
|
+
* the wallet that a wallet-funded Arrear charge draws on once the wallet
|
|
893
|
+
* runs out (Wallet → Reserved down to 0 → Wallet goes negative). It must be
|
|
894
|
+
* switched on for the org (Settings → Organisation → "Enable Reserved
|
|
895
|
+
* balance in wallet"), else this is a `PlanError`. It never goes negative:
|
|
896
|
+
* a reduce below zero is refused (an `AllowanceError`), not capped — drawing
|
|
897
|
+
* down to exactly 0 is fine. `remaining` is then the Reserved balance. A
|
|
898
|
+
* `"MAIN"` adjustment never touches it.
|
|
899
|
+
*/
|
|
900
|
+
pool?: WalletPool;
|
|
901
|
+
/**
|
|
902
|
+
* Optional idempotency key (1–255 characters) that makes this adjustment
|
|
903
|
+
* safe to retry. The first call with a key adjusts; any repeat with the
|
|
904
|
+
* same key and the same request adjusts nothing and comes back with
|
|
905
|
+
* `replayed: true` (and when the original happened, `adjustedAt`). The same
|
|
906
|
+
* key with a different request is a `ConflictError`. Keys are unique per
|
|
907
|
+
* workspace and per adjust endpoint. **Auto-generated (UUID v4) if
|
|
908
|
+
* omitted** and reused across every retry of this call, so a network blip
|
|
909
|
+
* never adjusts twice — same as signals. Supply your own (e.g. your order
|
|
910
|
+
* id) to also dedupe your OWN retries, across restarts or redelivery.
|
|
911
|
+
*/
|
|
912
|
+
idempotencyKey?: string;
|
|
949
913
|
}
|
|
950
914
|
/** Grant (positive) or claw back (negative) a credit balance. `delta` must be a
|
|
951
|
-
* non-zero whole number. The credit is addressed by its stable `agentKey
|
|
952
|
-
*
|
|
953
|
-
*
|
|
915
|
+
* non-zero whole number. The credit is addressed by its stable `agentKey`,
|
|
916
|
+
* and must be a prepaid (ADVANCE) part of the customer's current plan — else
|
|
917
|
+
* a `PlanError` ("… is not part of this customer's plan"). A reduce is never
|
|
918
|
+
* rejected or floored for going below 0 — the resulting balance may read
|
|
919
|
+
* negative, same as a real-usage overdraft already can. */
|
|
954
920
|
interface CreditAdjustInput {
|
|
955
921
|
/** The credit's stable agent key (the same key used to record usage). */
|
|
956
922
|
agentKey: string;
|
|
957
923
|
delta: number;
|
|
958
924
|
notes?: string;
|
|
925
|
+
/**
|
|
926
|
+
* Optional idempotency key (1–255 characters) that makes this adjustment
|
|
927
|
+
* safe to retry. The first call with a key adjusts; any repeat with the
|
|
928
|
+
* same key and the same request adjusts nothing and comes back with
|
|
929
|
+
* `replayed: true` (and when the original happened, `adjustedAt`). The same
|
|
930
|
+
* key with a different request is a `ConflictError`. Keys are unique per
|
|
931
|
+
* workspace and per adjust endpoint. **Auto-generated (UUID v4) if
|
|
932
|
+
* omitted** and reused across every retry of this call, so a network blip
|
|
933
|
+
* never adjusts twice — same as signals. Supply your own (e.g. your order
|
|
934
|
+
* id) to also dedupe your OWN retries, across restarts or redelivery.
|
|
935
|
+
*/
|
|
936
|
+
idempotencyKey?: string;
|
|
959
937
|
}
|
|
960
938
|
/** Grant/claw an outcome balance. `delta` is a non-zero whole number. The
|
|
961
939
|
* outcome is addressed here by a STEP's `agentKey`, which resolves to its
|
|
962
|
-
* parent outcome — NOT by the outcome's own `agentKey
|
|
963
|
-
* which this endpoint does not accept.
|
|
940
|
+
* parent outcome — NOT by the outcome's own `agentKey`,
|
|
941
|
+
* which this endpoint does not accept. The outcome must be a prepaid
|
|
942
|
+
* (ADVANCE) part of the customer's current plan — else a `PlanError`. A reduce is never rejected or floored
|
|
964
943
|
* for going below 0 — the resulting balance may read negative, same as a
|
|
965
944
|
* real-usage overdraft already can. */
|
|
966
945
|
interface OutcomeAdjustInput {
|
|
@@ -969,16 +948,41 @@ interface OutcomeAdjustInput {
|
|
|
969
948
|
agentKey: string;
|
|
970
949
|
delta: number;
|
|
971
950
|
notes?: string;
|
|
951
|
+
/**
|
|
952
|
+
* Optional idempotency key (1–255 characters) that makes this adjustment
|
|
953
|
+
* safe to retry. The first call with a key adjusts; any repeat with the
|
|
954
|
+
* same key and the same request adjusts nothing and comes back with
|
|
955
|
+
* `replayed: true` (and when the original happened, `adjustedAt`). The same
|
|
956
|
+
* key with a different request is a `ConflictError`. Keys are unique per
|
|
957
|
+
* workspace and per adjust endpoint. **Auto-generated (UUID v4) if
|
|
958
|
+
* omitted** and reused across every retry of this call, so a network blip
|
|
959
|
+
* never adjusts twice — same as signals. Supply your own (e.g. your order
|
|
960
|
+
* id) to also dedupe your OWN retries, across restarts or redelivery.
|
|
961
|
+
*/
|
|
962
|
+
idempotencyKey?: string;
|
|
972
963
|
}
|
|
973
964
|
/** Grant/claw a unit balance. `delta` is non-zero (fractional allowed). The
|
|
974
|
-
* unit is addressed by its stable `agentKey
|
|
975
|
-
*
|
|
976
|
-
*
|
|
965
|
+
* unit is addressed by its stable `agentKey`, and must be a prepaid
|
|
966
|
+
* (ADVANCE) part of the customer's current plan — else a `PlanError`. A
|
|
967
|
+
* reduce is never rejected or floored for going below 0 — the resulting
|
|
968
|
+
* balance may read negative, same as a real-usage overdraft already can. */
|
|
977
969
|
interface UnitAdjustInput {
|
|
978
970
|
/** The unit's stable agent key (the same key used to record usage). */
|
|
979
971
|
agentKey: string;
|
|
980
972
|
delta: number;
|
|
981
973
|
notes?: string;
|
|
974
|
+
/**
|
|
975
|
+
* Optional idempotency key (1–255 characters) that makes this adjustment
|
|
976
|
+
* safe to retry. The first call with a key adjusts; any repeat with the
|
|
977
|
+
* same key and the same request adjusts nothing and comes back with
|
|
978
|
+
* `replayed: true` (and when the original happened, `adjustedAt`). The same
|
|
979
|
+
* key with a different request is a `ConflictError`. Keys are unique per
|
|
980
|
+
* workspace and per adjust endpoint. **Auto-generated (UUID v4) if
|
|
981
|
+
* omitted** and reused across every retry of this call, so a network blip
|
|
982
|
+
* never adjusts twice — same as signals. Supply your own (e.g. your order
|
|
983
|
+
* id) to also dedupe your OWN retries, across restarts or redelivery.
|
|
984
|
+
*/
|
|
985
|
+
idempotencyKey?: string;
|
|
982
986
|
}
|
|
983
987
|
/**
|
|
984
988
|
* Grant (positive) or claw back (negative) slots on a customer's ADVANCE
|
|
@@ -990,7 +994,7 @@ interface UnitAdjustInput {
|
|
|
990
994
|
*/
|
|
991
995
|
interface CompositeAdjustInput {
|
|
992
996
|
/**
|
|
993
|
-
* The composite's stable identifier — its `refId
|
|
997
|
+
* The composite's stable identifier — its `refId`,
|
|
994
998
|
* the same value signals tag it with, NOT `agentKey` (a composite has no
|
|
995
999
|
* `agentKey` column of its own). Named `agentKey` on the wire only so the
|
|
996
1000
|
* four adjust endpoints share one request shape.
|
|
@@ -998,248 +1002,66 @@ interface CompositeAdjustInput {
|
|
|
998
1002
|
agentKey: string;
|
|
999
1003
|
delta: number;
|
|
1000
1004
|
notes?: string;
|
|
1001
|
-
}
|
|
1002
|
-
/** A per-model token bundle attached to a credit or outcome step. */
|
|
1003
|
-
interface ModelBundleEntry {
|
|
1004
|
-
orgModelId: string;
|
|
1005
|
-
/** Display label; the server defaults it from the model when omitted. */
|
|
1006
|
-
modelName?: string;
|
|
1007
|
-
tokens: number;
|
|
1008
|
-
input: number;
|
|
1009
|
-
output: number;
|
|
1010
|
-
cache: number;
|
|
1011
|
-
}
|
|
1012
|
-
/** One point on a cost-over-time analytics series. */
|
|
1013
|
-
interface CostPoint {
|
|
1014
|
-
/** UTC day, `YYYY-MM-DD`. */
|
|
1015
|
-
dateIso: string;
|
|
1016
|
-
/** Short display label, e.g. "Jun 24". */
|
|
1017
|
-
label: string;
|
|
1018
|
-
/** Average cost that day, or `null` on days with no usage. */
|
|
1019
|
-
cost: number | null;
|
|
1020
|
-
reqs: number;
|
|
1021
|
-
}
|
|
1022
|
-
/** Summary stats across a cost-over-time series. */
|
|
1023
|
-
interface CostStats {
|
|
1024
|
-
activeDays: number;
|
|
1025
|
-
avgCost: number | null;
|
|
1026
|
-
peakCost: number | null;
|
|
1027
|
-
troughCost: number | null;
|
|
1028
|
-
deviationPct: number | null;
|
|
1029
|
-
}
|
|
1030
|
-
/** Cost-over-time analytics for a credit (`credits.get().analytics`). */
|
|
1031
|
-
interface CreditAnalytics {
|
|
1032
|
-
basePrice: number;
|
|
1033
|
-
pricePerCredit: number;
|
|
1034
|
-
marginPercent: number;
|
|
1035
|
-
points: CostPoint[];
|
|
1036
|
-
stats: CostStats;
|
|
1037
|
-
}
|
|
1038
|
-
/** Cost-over-time analytics for an outcome (`outcomes.get().analytics`).
|
|
1039
|
-
* Each point adds `completions` (workflows finished that day). */
|
|
1040
|
-
interface OutcomeAnalytics {
|
|
1041
|
-
basePrice: number;
|
|
1042
|
-
pricePerOutcome: number;
|
|
1043
|
-
marginPercent: number;
|
|
1044
|
-
points: (CostPoint & {
|
|
1045
|
-
completions: number;
|
|
1046
|
-
})[];
|
|
1047
|
-
stats: CostStats;
|
|
1048
|
-
}
|
|
1049
|
-
interface Credit {
|
|
1050
|
-
id: string;
|
|
1051
|
-
name: string;
|
|
1052
|
-
agentKey: string;
|
|
1053
|
-
description: string | null;
|
|
1054
|
-
tokensPerCredit: number;
|
|
1055
|
-
basePrice: number;
|
|
1056
|
-
marginPercent: number;
|
|
1057
|
-
pricePerCredit: number;
|
|
1058
|
-
isActive: boolean;
|
|
1059
|
-
createdAt: string;
|
|
1060
|
-
}
|
|
1061
|
-
/** `credits.get()` — adds the model bundle plus usage stats/analytics. */
|
|
1062
|
-
interface CreditDetail extends Credit {
|
|
1063
|
-
modelBundle: ModelBundleEntry[];
|
|
1064
|
-
createdByName: string;
|
|
1065
|
-
stats: {
|
|
1066
|
-
customerCount: number;
|
|
1067
|
-
planCount: number;
|
|
1068
|
-
totalGranted: number;
|
|
1069
|
-
totalUsed: number;
|
|
1070
|
-
revenue: number;
|
|
1071
|
-
usageLogCount: number;
|
|
1072
|
-
};
|
|
1073
|
-
analytics: CreditAnalytics;
|
|
1074
|
-
}
|
|
1075
|
-
interface CreateCreditInput {
|
|
1076
|
-
name: string;
|
|
1077
|
-
/** Lowercased stable key used by `signals.credit({ agentKey })`. */
|
|
1078
|
-
agentKey: string;
|
|
1079
|
-
basePrice: number;
|
|
1080
|
-
marginPercent: number;
|
|
1081
|
-
pricePerCredit: number;
|
|
1082
|
-
description?: string;
|
|
1083
|
-
tokensPerCredit?: number;
|
|
1084
|
-
modelBundle?: ModelBundleEntry[];
|
|
1085
|
-
}
|
|
1086
|
-
type UpdateCreditInput = CreateCreditInput;
|
|
1087
|
-
interface OutcomeStepInput {
|
|
1088
|
-
id?: string;
|
|
1089
|
-
name: string;
|
|
1090
|
-
/** Lowercased stable key used by `signals.outcome({ agentKey })`. */
|
|
1091
|
-
agentKey: string;
|
|
1092
|
-
basePrice: number;
|
|
1093
|
-
modelBundle?: ModelBundleEntry[];
|
|
1094
|
-
}
|
|
1095
|
-
interface Outcome {
|
|
1096
|
-
id: string;
|
|
1097
|
-
name: string;
|
|
1098
|
-
/**
|
|
1099
|
-
* The OUTCOME's own stable agent key — its durable identity, mirroring
|
|
1100
|
-
* {@link Credit.agentKey}. Lowercased `[a-z0-9._-]`, max 80 chars, unique per
|
|
1101
|
-
* organisation. A rename never changes it.
|
|
1102
|
-
*
|
|
1103
|
-
* Distinct from each step's `agentKey` in `steps`, and in a SEPARATE
|
|
1104
|
-
* namespace: usage is always reported against a STEP's key
|
|
1105
|
-
* (`signals.outcome({ agentKey })`), never this one. This key identifies the
|
|
1106
|
-
* outcome itself when creating or updating it.
|
|
1107
|
-
*/
|
|
1108
|
-
agentKey: string;
|
|
1109
|
-
description: string | null;
|
|
1110
|
-
isActive: boolean;
|
|
1111
|
-
marginPercent: number;
|
|
1112
|
-
pricePerOutcome: number;
|
|
1113
|
-
}
|
|
1114
|
-
/** `outcomes.get()` — adds steps plus in-flight/completed stats. */
|
|
1115
|
-
interface OutcomeDetail extends Outcome {
|
|
1116
|
-
/** Only the DETAIL row carries these — `outcomes.list()` returns neither.
|
|
1117
|
-
* They were previously declared on {@link Outcome} itself, where
|
|
1118
|
-
* `createdAt` was typed as a required `string` that is always `undefined`
|
|
1119
|
-
* in practice. */
|
|
1120
|
-
createdAt: string;
|
|
1121
|
-
createdByName: string | null;
|
|
1122
|
-
steps: {
|
|
1123
|
-
name: string;
|
|
1124
|
-
agentKey: string;
|
|
1125
|
-
}[];
|
|
1126
|
-
stats: {
|
|
1127
|
-
stepCount: number;
|
|
1128
|
-
customerCount: number;
|
|
1129
|
-
inFlight: number;
|
|
1130
|
-
completed: number;
|
|
1131
|
-
totalRemaining: number;
|
|
1132
|
-
};
|
|
1133
|
-
analytics: OutcomeAnalytics;
|
|
1134
|
-
}
|
|
1135
|
-
interface CreateOutcomeInput {
|
|
1136
|
-
name: string;
|
|
1137
1005
|
/**
|
|
1138
|
-
*
|
|
1139
|
-
*
|
|
1140
|
-
*
|
|
1141
|
-
*
|
|
1142
|
-
* key
|
|
1143
|
-
*
|
|
1006
|
+
* Optional idempotency key (1–255 characters) that makes this adjustment
|
|
1007
|
+
* safe to retry. The first call with a key adjusts; any repeat with the
|
|
1008
|
+
* same key and the same request adjusts nothing and comes back with
|
|
1009
|
+
* `replayed: true` (and when the original happened, `adjustedAt`). The same
|
|
1010
|
+
* key with a different request is a `ConflictError`. Keys are unique per
|
|
1011
|
+
* workspace and per adjust endpoint. **Auto-generated (UUID v4) if
|
|
1012
|
+
* omitted** and reused across every retry of this call, so a network blip
|
|
1013
|
+
* never adjusts twice — same as signals. Supply your own (e.g. your order
|
|
1014
|
+
* id) to also dedupe your OWN retries, across restarts or redelivery.
|
|
1144
1015
|
*/
|
|
1145
|
-
|
|
1146
|
-
basePrice: number;
|
|
1147
|
-
marginPercent: number;
|
|
1148
|
-
pricePerOutcome: number;
|
|
1149
|
-
description?: string | null;
|
|
1150
|
-
isActive?: boolean;
|
|
1151
|
-
/** 1–50 steps; step names and agent keys must be unique. */
|
|
1152
|
-
steps: OutcomeStepInput[];
|
|
1153
|
-
}
|
|
1154
|
-
type UpdateOutcomeInput = CreateOutcomeInput;
|
|
1155
|
-
type UnitPricingType = "FLAT" | "SLAB" | "VOLUME";
|
|
1156
|
-
/** A tier for SLAB/VOLUME pricing; only the last tier may have `upTo: null`. */
|
|
1157
|
-
interface UnitTierInput {
|
|
1158
|
-
id?: string;
|
|
1159
|
-
upTo: number | null;
|
|
1160
|
-
price: number;
|
|
1161
|
-
}
|
|
1162
|
-
interface UnitTier {
|
|
1163
|
-
id: string;
|
|
1164
|
-
upTo: number | null;
|
|
1165
|
-
price: number;
|
|
1166
|
-
order: number;
|
|
1167
|
-
}
|
|
1168
|
-
interface Unit {
|
|
1169
|
-
id: string;
|
|
1170
|
-
/** Stable per-org report key — what `signals.unit({ agentKey })` sends.
|
|
1171
|
-
* The ONLY identifier accepted when reporting unit consumption. */
|
|
1172
|
-
agentKey: string;
|
|
1173
|
-
name: string;
|
|
1174
|
-
description: string | null;
|
|
1175
|
-
pricingType: UnitPricingType;
|
|
1176
|
-
flatPrice: number;
|
|
1177
|
-
tiers: UnitTier[];
|
|
1178
|
-
isActive: boolean;
|
|
1179
|
-
createdAt: string;
|
|
1180
|
-
createdByName: string | null;
|
|
1016
|
+
idempotencyKey?: string;
|
|
1181
1017
|
}
|
|
1182
|
-
/**
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1018
|
+
/**
|
|
1019
|
+
* What every adjust call returns.
|
|
1020
|
+
*
|
|
1021
|
+
* `replayed: true` means this call adjusted NOTHING: an earlier call with the
|
|
1022
|
+
* same `idempotencyKey` already did, at `adjustedAt`. `remaining` is always
|
|
1023
|
+
* the balance as it is now. `customerArchived` is true when the customer is
|
|
1024
|
+
* archived — archived customers follow the same rules (archiving cancels
|
|
1025
|
+
* their plan, so usually only the wallet can still move).
|
|
1026
|
+
*/
|
|
1027
|
+
interface AdjustResult {
|
|
1191
1028
|
remaining: number;
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
interface UnitDetail extends Unit {
|
|
1197
|
-
stats: {
|
|
1198
|
-
planCount: number;
|
|
1199
|
-
customerCount: number;
|
|
1200
|
-
totalRemaining: number;
|
|
1201
|
-
totalUsed: number;
|
|
1202
|
-
};
|
|
1203
|
-
/** First page (≤10) of customers currently metered on this unit. */
|
|
1204
|
-
customers: UnitCustomerRow[];
|
|
1205
|
-
}
|
|
1206
|
-
/** Flat per-event pricing — a single `flatPrice` (defaults to 0), no tiers. */
|
|
1207
|
-
interface FlatUnitInput {
|
|
1208
|
-
name: string;
|
|
1209
|
-
/** Stable per-org report key (`signals.unit({ agentKey })`); `[a-z0-9._-]`. */
|
|
1210
|
-
agentKey: string;
|
|
1211
|
-
pricingType: "FLAT";
|
|
1212
|
-
/** Price per event; defaults to 0. */
|
|
1213
|
-
flatPrice?: number;
|
|
1214
|
-
description?: string | null;
|
|
1215
|
-
isActive?: boolean;
|
|
1216
|
-
}
|
|
1217
|
-
/** Tiered pricing (SLAB or VOLUME) — at least one tier is required. */
|
|
1218
|
-
interface TieredUnitInput {
|
|
1219
|
-
name: string;
|
|
1220
|
-
/** Stable per-org report key (`signals.unit({ agentKey })`); `[a-z0-9._-]`. */
|
|
1221
|
-
agentKey: string;
|
|
1222
|
-
pricingType: "SLAB" | "VOLUME";
|
|
1223
|
-
/** At least one tier (≤50). Only the last tier may have `upTo: null`. */
|
|
1224
|
-
tiers: UnitTierInput[];
|
|
1225
|
-
description?: string | null;
|
|
1226
|
-
isActive?: boolean;
|
|
1029
|
+
replayed: boolean;
|
|
1030
|
+
/** Set only on a replay: when the original adjustment happened (ISO 8601). */
|
|
1031
|
+
adjustedAt?: string;
|
|
1032
|
+
customerArchived: boolean;
|
|
1227
1033
|
}
|
|
1228
1034
|
/**
|
|
1229
|
-
*
|
|
1230
|
-
*
|
|
1231
|
-
*
|
|
1035
|
+
* Change how much a customer is granted every billing cycle. The difference is
|
|
1036
|
+
* applied to the current balance immediately (a shrink is never floored — the
|
|
1037
|
+
* balance may read negative). `quantity` is USD for the wallet and a whole
|
|
1038
|
+
* number for everything else. `agentKey` resolves the same way as the adjust
|
|
1039
|
+
* endpoints: a credit's or unit's `agentKey`, an outcome STEP's `agentKey`, or
|
|
1040
|
+
* a composite's `refId`. The wallet needs none — a customer has at most one.
|
|
1232
1041
|
*/
|
|
1233
|
-
type
|
|
1234
|
-
|
|
1042
|
+
type RecurringGrantInput = {
|
|
1043
|
+
kind: "wallet";
|
|
1044
|
+
quantity: number;
|
|
1045
|
+
} | {
|
|
1046
|
+
kind: "credit" | "outcome" | "unit" | "composite";
|
|
1047
|
+
agentKey: string;
|
|
1048
|
+
quantity: number;
|
|
1049
|
+
};
|
|
1050
|
+
/** Result of `customers.updateRecurringGrant()`. */
|
|
1051
|
+
interface RecurringGrantResult {
|
|
1052
|
+
kind: RecurringGrantInput["kind"];
|
|
1053
|
+
/** The new per-cycle amount. */
|
|
1054
|
+
quantity: number;
|
|
1055
|
+
/** The wallet balance after the change — only present for `kind: "wallet"`. */
|
|
1056
|
+
balanceUsd?: number;
|
|
1057
|
+
}
|
|
1235
1058
|
/**
|
|
1236
1059
|
* Record one unit-metered event. The unit is addressed by its `agentKey` (the
|
|
1237
1060
|
* stable key set when the unit was created) — the ONLY accepted identifier;
|
|
1238
1061
|
* the display name is deliberately not accepted, so a rename can never redirect
|
|
1239
1062
|
* a live integration. Keys are matched exactly (they are stored lowercased).
|
|
1240
1063
|
*/
|
|
1241
|
-
|
|
1242
|
-
customerId: string;
|
|
1064
|
+
type UnitInput = CustomerRef & {
|
|
1243
1065
|
agentKey: string;
|
|
1244
1066
|
member?: string;
|
|
1245
1067
|
/**
|
|
@@ -1270,7 +1092,7 @@ interface UnitInput {
|
|
|
1270
1092
|
* auto key cannot survive.
|
|
1271
1093
|
*/
|
|
1272
1094
|
idempotencyKey?: string;
|
|
1273
|
-
}
|
|
1095
|
+
};
|
|
1274
1096
|
/**
|
|
1275
1097
|
* The result of `signals.unit()`.
|
|
1276
1098
|
*
|
|
@@ -1298,8 +1120,7 @@ interface UnitTrackResult {
|
|
|
1298
1120
|
* Input for `signals.completeComposite()` — closes ONE occurrence of a
|
|
1299
1121
|
* composite, which is the moment it is billed.
|
|
1300
1122
|
*/
|
|
1301
|
-
|
|
1302
|
-
customerId: string;
|
|
1123
|
+
type CompositeCompletionInput = CustomerRef & {
|
|
1303
1124
|
/** Which occurrence to close: the composite's `refId` and the correlation
|
|
1304
1125
|
* value the signals were tagged with. */
|
|
1305
1126
|
composite: CompositeTag;
|
|
@@ -1307,71 +1128,7 @@ interface CompositeCompletionInput {
|
|
|
1307
1128
|
* safe no-op, so this only collapses retries into one recorded attempt
|
|
1308
1129
|
* rather than protecting against a double charge. */
|
|
1309
1130
|
idempotencyKey?: string;
|
|
1310
|
-
}
|
|
1311
|
-
/** One catalogue item a composite is restricted to. `agentKey` is what a
|
|
1312
|
-
* signal names, so it is the field you actually integrate against. */
|
|
1313
|
-
interface CompositeCatalogueRef {
|
|
1314
|
-
id: string;
|
|
1315
|
-
name: string;
|
|
1316
|
-
agentKey: string;
|
|
1317
|
-
}
|
|
1318
|
-
/** One composite in the org's catalogue — `cnk.composites.list()`. */
|
|
1319
|
-
interface Composite {
|
|
1320
|
-
id: string;
|
|
1321
|
-
name: string;
|
|
1322
|
-
/** The stable identifier you put in a signal's `composite` block as `ref`. */
|
|
1323
|
-
refId: string;
|
|
1324
|
-
description: string | null;
|
|
1325
|
-
/** USD charged per occurrence WHEN A PLAN SELLS THIS as a composite
|
|
1326
|
-
* component (`quantity × price`, frozen into the purchase at buy time). The
|
|
1327
|
-
* catalogue row alone bills nothing. */
|
|
1328
|
-
price: number;
|
|
1329
|
-
/** False once archived. An archived composite stops NEW signals resolving to
|
|
1330
|
-
* it but keeps every row it already owns. */
|
|
1331
|
-
isActive: boolean;
|
|
1332
|
-
createdAt: string;
|
|
1333
|
-
/**
|
|
1334
|
-
* The credits / outcomes / units this composite is restricted to — only
|
|
1335
|
-
* signals naming one of these may carry its tag.
|
|
1336
|
-
*
|
|
1337
|
-
* All three lists empty means UNRESTRICTED (it accepts any of the org's
|
|
1338
|
-
* traffic under this tag). Nothing created through the API can be
|
|
1339
|
-
* unrestricted, but rows predating that rule exist — so don't assume
|
|
1340
|
-
* non-empty.
|
|
1341
|
-
*/
|
|
1342
|
-
entitlements: {
|
|
1343
|
-
credits: CompositeCatalogueRef[];
|
|
1344
|
-
outcomes: CompositeCatalogueRef[];
|
|
1345
|
-
units: CompositeCatalogueRef[];
|
|
1346
|
-
};
|
|
1347
|
-
}
|
|
1348
|
-
/** Input for `cnk.composites.create()`. */
|
|
1349
|
-
interface CreateCompositeInput {
|
|
1350
|
-
name: string;
|
|
1351
|
-
/**
|
|
1352
|
-
* The tag identifier. Lowercased, and restricted to the same characters as
|
|
1353
|
-
* an `agentKey` — but validated harder than one, because it may not collide
|
|
1354
|
-
* with a field the ingest schemas already own (`customerId`, `usage`,
|
|
1355
|
-
* `agentKey`, `runId`, `member`, `custom`, `composite`, …). A colliding
|
|
1356
|
-
* `refId` is refused at create time rather than silently ignored at ingest.
|
|
1357
|
-
*/
|
|
1358
|
-
refId: string;
|
|
1359
|
-
/** USD per occurrence once a plan sells it. Required — an unpriced composite
|
|
1360
|
-
* put on a plan would bill 0, which is a money bug that is hard to see. */
|
|
1361
|
-
price: number;
|
|
1362
|
-
description?: string | null;
|
|
1363
|
-
/**
|
|
1364
|
-
* What the composite wraps. At least one id across the three lists is
|
|
1365
|
-
* REQUIRED: a composite restricted to nothing would accept every signal in
|
|
1366
|
-
* the org. Get the ids from `credits.list()`, `outcomes.list()` and
|
|
1367
|
-
* `units.list()`.
|
|
1368
|
-
*/
|
|
1369
|
-
entitlements: {
|
|
1370
|
-
creditIds?: string[];
|
|
1371
|
-
outcomeIds?: string[];
|
|
1372
|
-
unitIds?: string[];
|
|
1373
|
-
};
|
|
1374
|
-
}
|
|
1131
|
+
};
|
|
1375
1132
|
/**
|
|
1376
1133
|
* The result of `signals.completeComposite()`.
|
|
1377
1134
|
*
|
|
@@ -1407,8 +1164,7 @@ interface CompositeCompletionResult {
|
|
|
1407
1164
|
/** The durable inbox id — see {@link TrackResult.rawId}. */
|
|
1408
1165
|
rawId?: string;
|
|
1409
1166
|
}
|
|
1410
|
-
/** One serialized unit-consumption event — the result of `signals.unit()
|
|
1411
|
-
* each element of `UnitUsageList.events`. */
|
|
1167
|
+
/** One serialized unit-consumption event — the result of `signals.unit()`. */
|
|
1412
1168
|
interface SerializedUnitUsage {
|
|
1413
1169
|
id: string;
|
|
1414
1170
|
customerId: string;
|
|
@@ -1423,42 +1179,6 @@ interface SerializedUnitUsage {
|
|
|
1423
1179
|
member: string | null;
|
|
1424
1180
|
createdAt: string;
|
|
1425
1181
|
}
|
|
1426
|
-
interface UnitUsageRow {
|
|
1427
|
-
unit: string;
|
|
1428
|
-
/** The unit's stable agent key — what to send to report against it. */
|
|
1429
|
-
agentKey: string | null;
|
|
1430
|
-
billingMode: BillingMode;
|
|
1431
|
-
granted?: number;
|
|
1432
|
-
used: number;
|
|
1433
|
-
remaining?: number;
|
|
1434
|
-
}
|
|
1435
|
-
interface UnitUsageList {
|
|
1436
|
-
customer: {
|
|
1437
|
-
id: string;
|
|
1438
|
-
name: string;
|
|
1439
|
-
};
|
|
1440
|
-
units: UnitUsageRow[];
|
|
1441
|
-
events: SerializedUnitUsage[];
|
|
1442
|
-
}
|
|
1443
|
-
type ThresholdKind = "CREDIT" | "OUTCOME" | "WALLET";
|
|
1444
|
-
interface Webhook {
|
|
1445
|
-
id: string;
|
|
1446
|
-
kind: ThresholdKind;
|
|
1447
|
-
threshold: number;
|
|
1448
|
-
url: string;
|
|
1449
|
-
isActive: boolean;
|
|
1450
|
-
createdAt: string;
|
|
1451
|
-
updatedAt: string;
|
|
1452
|
-
createdByName: string | null;
|
|
1453
|
-
}
|
|
1454
|
-
interface UpsertWebhookInput {
|
|
1455
|
-
kind: ThresholdKind;
|
|
1456
|
-
/** Fire when the balance crosses this value. */
|
|
1457
|
-
threshold: number;
|
|
1458
|
-
/** http(s) URL to POST the alert to. */
|
|
1459
|
-
url: string;
|
|
1460
|
-
isActive?: boolean;
|
|
1461
|
-
}
|
|
1462
1182
|
type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;
|
|
1463
1183
|
interface Logger {
|
|
1464
1184
|
debug?: (...args: unknown[]) => void;
|
|
@@ -1590,66 +1310,9 @@ declare class Transport {
|
|
|
1590
1310
|
private buildUrl;
|
|
1591
1311
|
}
|
|
1592
1312
|
|
|
1593
|
-
/**
|
|
1594
|
-
* The `composites` resource — manage the org's composite *catalogue*: the
|
|
1595
|
-
* bundles of credits / outcomes / units that are grouped under one tag and
|
|
1596
|
-
* sold on a plan as a single thing. `/api/v1/composites`.
|
|
1597
|
-
*
|
|
1598
|
-
* Two things live elsewhere, deliberately:
|
|
1599
|
-
* • Tagging a signal into a composite occurrence is `composite: { ref, value }`
|
|
1600
|
-
* on the signal itself (see `signals.credit()` / `.outcome()` / `.unit()`).
|
|
1601
|
-
* • Closing an occurrence — the moment it is billed — is
|
|
1602
|
-
* `signals.completeComposite()`.
|
|
1603
|
-
*
|
|
1604
|
-
* This resource only defines what composites EXIST. Creating one prices it but
|
|
1605
|
-
* charges nobody: an invoice is built from plan components, never from a
|
|
1606
|
-
* catalogue entry, so a composite starts costing money only once a plan sells
|
|
1607
|
-
* it (`quantity × price`, frozen into the purchase at buy time).
|
|
1608
|
-
*/
|
|
1609
|
-
declare class Composites {
|
|
1610
|
-
private readonly transport;
|
|
1611
|
-
constructor(transport: Transport);
|
|
1612
|
-
/** List composites. Pass `{ active: true }` for only the ones a signal can
|
|
1613
|
-
* still be tagged with — the default list INCLUDES archived ones, which
|
|
1614
|
-
* keep every row they already own.
|
|
1615
|
-
* `{ active: false }` returns only archived ones; omitting it returns
|
|
1616
|
-
* both. See `activeQuery` — the API itself only supports `true`. */
|
|
1617
|
-
list(params?: {
|
|
1618
|
-
active?: boolean;
|
|
1619
|
-
}): Promise<Composite[]>;
|
|
1620
|
-
/** Create a composite. `POST /api/v1/composites`. */
|
|
1621
|
-
create(input: CreateCompositeInput): Promise<Composite>;
|
|
1622
|
-
}
|
|
1623
|
-
|
|
1624
|
-
/**
|
|
1625
|
-
* The `credits` resource — manage the org's credit *types* (the catalog). A
|
|
1626
|
-
* credit's stable `agentKey` is what you pass to `signals.credit()` when
|
|
1627
|
-
* recording usage against it. `/api/v1/credits`.
|
|
1628
|
-
*/
|
|
1629
|
-
declare class Credits {
|
|
1630
|
-
private readonly transport;
|
|
1631
|
-
constructor(transport: Transport);
|
|
1632
|
-
/** List credit types. Pass `{ active: true }` to only return active ones.
|
|
1633
|
-
* `{ active: false }` returns only archived ones; omitting it returns
|
|
1634
|
-
* both. See `activeQuery` — the API itself only supports `true`. */
|
|
1635
|
-
list(params?: {
|
|
1636
|
-
active?: boolean;
|
|
1637
|
-
}): Promise<Credit[]>;
|
|
1638
|
-
/** Create a credit type; returns the created credit. `POST /api/v1/credits`. */
|
|
1639
|
-
create(input: CreateCreditInput): Promise<Credit>;
|
|
1640
|
-
/** Fetch one credit type with usage stats. `GET /api/v1/credits/:id`. */
|
|
1641
|
-
get(id: string): Promise<CreditDetail>;
|
|
1642
|
-
/** Update a credit type's definition; returns the updated credit. `PATCH /api/v1/credits/:id`. */
|
|
1643
|
-
update(id: string, input: UpdateCreditInput): Promise<Credit>;
|
|
1644
|
-
/** Activate or deactivate a credit type. */
|
|
1645
|
-
setActive(id: string, isActive: boolean): Promise<Credit>;
|
|
1646
|
-
/** Delete a credit type. Refused while a customer is linked to it. */
|
|
1647
|
-
delete(id: string): Promise<void>;
|
|
1648
|
-
}
|
|
1649
|
-
|
|
1650
1313
|
/**
|
|
1651
1314
|
* The `customers` resource — full CRUD over the org's customers plus the
|
|
1652
|
-
* read-only insight endpoints (
|
|
1315
|
+
* read-only insight endpoints (balances / plan). Every call is scoped
|
|
1653
1316
|
* to the API key's organisation server-side; a customer in another org
|
|
1654
1317
|
* resolves as a NotFoundError.
|
|
1655
1318
|
*/
|
|
@@ -1676,14 +1339,25 @@ declare class Customers {
|
|
|
1676
1339
|
get(id: string): Promise<ApiCustomer>;
|
|
1677
1340
|
/** Update a customer (partial). `PATCH /api/v1/customers/:id`. */
|
|
1678
1341
|
update(id: string, input: CustomerProfileInput): Promise<ApiCustomer>;
|
|
1342
|
+
/**
|
|
1343
|
+
* Fetch one customer by YOUR id for them (its `externalId`), instead of
|
|
1344
|
+
* ours. Same result as {@link get}. `GET /api/v1/customers/ext/:externalId`.
|
|
1345
|
+
* An unknown external id is a `NotFoundError`; only active customers match.
|
|
1346
|
+
*/
|
|
1347
|
+
getByExternalId(externalId: string): Promise<ApiCustomer>;
|
|
1348
|
+
/** Update a customer (partial), addressed by its `externalId`. Same body as
|
|
1349
|
+
* {@link update}. `PATCH /api/v1/customers/ext/:externalId`. */
|
|
1350
|
+
updateByExternalId(externalId: string, input: CustomerProfileInput): Promise<ApiCustomer>;
|
|
1351
|
+
/** {@link delete}, addressing the customer by its `externalId`.
|
|
1352
|
+
* `DELETE /api/v1/customers/ext/:externalId`. */
|
|
1353
|
+
deleteByExternalId(externalId: string): Promise<void>;
|
|
1679
1354
|
/** Delete a customer (members, invitations, usage logs cascade). */
|
|
1680
1355
|
delete(id: string): Promise<void>;
|
|
1681
|
-
/** A customer's usage history. `GET /api/v1/usage?customerId=`. */
|
|
1682
|
-
usage(id: string, params?: {
|
|
1683
|
-
limit?: number;
|
|
1684
|
-
}): Promise<UsageList>;
|
|
1685
1356
|
/** Wallet / credit / outcome / unit balances. `GET …/:id/balances`. */
|
|
1686
1357
|
balances(id: string): Promise<CustomerBalances>;
|
|
1358
|
+
/** {@link balances}, addressing the customer by its `externalId`.
|
|
1359
|
+
* `GET /api/v1/customers/ext/:externalId/balances`. */
|
|
1360
|
+
balancesByExternalId(externalId: string): Promise<CustomerBalances>;
|
|
1687
1361
|
/**
|
|
1688
1362
|
* One credit balance for a customer, matched by `creditId` or `creditName`;
|
|
1689
1363
|
* `null` when the customer has no plan or no matching credit. Convenience
|
|
@@ -1711,6 +1385,9 @@ declare class Customers {
|
|
|
1711
1385
|
}): Promise<UnitBalance | null>;
|
|
1712
1386
|
/** The customer's current plan. `GET …/:id/plan`. */
|
|
1713
1387
|
plan(id: string): Promise<CustomerPlan>;
|
|
1388
|
+
/** {@link plan}, addressing the customer by its `externalId`.
|
|
1389
|
+
* `GET /api/v1/customers/ext/:externalId/plan`. */
|
|
1390
|
+
planByExternalId(externalId: string): Promise<CustomerPlan>;
|
|
1714
1391
|
/** List a customer's members. `GET …/:id/members`. */
|
|
1715
1392
|
listMembers(id: string): Promise<Member[]>;
|
|
1716
1393
|
/** Add a member to a customer. Duplicate `email` → ConflictError. */
|
|
@@ -1719,39 +1396,63 @@ declare class Customers {
|
|
|
1719
1396
|
updateMember(id: string, memberId: string, input: UpdateMemberInput): Promise<MemberProfile>;
|
|
1720
1397
|
/** Remove a member from a customer, returning who was removed. `DELETE …/:id/members/:memberId`. */
|
|
1721
1398
|
removeMember(id: string, memberId: string): Promise<RemovedMember>;
|
|
1722
|
-
/**
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1399
|
+
/** Grant or claw back a credit balance. The credit must be a prepaid part of
|
|
1400
|
+
* the customer's current plan. Pass `idempotencyKey` to make it safe to
|
|
1401
|
+
* retry. `POST …/:id/credits/adjust`. */
|
|
1402
|
+
adjustCredit(id: string, input: CreditAdjustInput): Promise<AdjustResult>;
|
|
1403
|
+
/** Grant or claw back an outcome balance. The outcome must be a prepaid part
|
|
1404
|
+
* of the customer's current plan. `POST …/:id/outcomes/adjust`. */
|
|
1405
|
+
adjustOutcome(id: string, input: OutcomeAdjustInput): Promise<AdjustResult>;
|
|
1406
|
+
/** Grant or claw back a unit balance. The unit must be a prepaid part of the
|
|
1407
|
+
* customer's current plan. `POST …/:id/units/adjust`. */
|
|
1408
|
+
adjustUnit(id: string, input: UnitAdjustInput): Promise<AdjustResult>;
|
|
1409
|
+
/** Grant or claw back slots on a customer's ADVANCE composite pool for the
|
|
1410
|
+
* current billing cycle. `remaining` is the resulting slot count.
|
|
1411
|
+
* `POST …/:id/composites/adjust`. */
|
|
1412
|
+
adjustComposite(id: string, input: CompositeAdjustInput): Promise<AdjustResult>;
|
|
1726
1413
|
/**
|
|
1727
|
-
*
|
|
1728
|
-
*
|
|
1414
|
+
* Top up (positive `delta`) or draw down (negative `delta`) a customer's
|
|
1415
|
+
* wallet, in USD — allowed whatever the customer's plan. `remaining` is the
|
|
1416
|
+
* resulting USD balance. No `agentKey` — a customer has exactly one wallet.
|
|
1417
|
+
* Pass `pool: "RESERVED"` to move the Reserved Wallet instead (then
|
|
1418
|
+
* `remaining` is its balance). `POST …/:id/wallet/adjust`.
|
|
1729
1419
|
*/
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
/**
|
|
1735
|
-
* `POST
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
/**
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
}>;
|
|
1420
|
+
adjustWallet(id: string, input: WalletAdjustInput): Promise<AdjustResult>;
|
|
1421
|
+
/** {@link adjustCredit}, addressing the customer by its `externalId` (`id`
|
|
1422
|
+
* here). `POST /api/v1/customers/ext/:externalId/credits/adjust`. */
|
|
1423
|
+
adjustCreditByExternalId(id: string, input: CreditAdjustInput): Promise<AdjustResult>;
|
|
1424
|
+
/** {@link adjustOutcome}, addressing the customer by its `externalId` (`id`
|
|
1425
|
+
* here). `POST /api/v1/customers/ext/:externalId/outcomes/adjust`. */
|
|
1426
|
+
adjustOutcomeByExternalId(id: string, input: OutcomeAdjustInput): Promise<AdjustResult>;
|
|
1427
|
+
/** {@link adjustUnit}, addressing the customer by its `externalId` (`id`
|
|
1428
|
+
* here). `POST /api/v1/customers/ext/:externalId/units/adjust`. */
|
|
1429
|
+
adjustUnitByExternalId(id: string, input: UnitAdjustInput): Promise<AdjustResult>;
|
|
1430
|
+
/** {@link adjustComposite}, addressing the customer by its `externalId`
|
|
1431
|
+
* (`id` here). `POST /api/v1/customers/ext/:externalId/composites/adjust`. */
|
|
1432
|
+
adjustCompositeByExternalId(id: string, input: CompositeAdjustInput): Promise<AdjustResult>;
|
|
1433
|
+
/** {@link adjustWallet}, addressing the customer by its `externalId` (`id`
|
|
1434
|
+
* here). `POST /api/v1/customers/ext/:externalId/wallet/adjust`. */
|
|
1435
|
+
adjustWalletByExternalId(id: string, input: WalletAdjustInput): Promise<AdjustResult>;
|
|
1747
1436
|
/**
|
|
1748
|
-
*
|
|
1749
|
-
*
|
|
1750
|
-
*
|
|
1437
|
+
* The one body behind all ten adjust calls.
|
|
1438
|
+
*
|
|
1439
|
+
* Every adjustment carries an idempotency key — the caller's, or one
|
|
1440
|
+
* generated here ONCE per call, exactly like signals. The server
|
|
1441
|
+
* deduplicates on it, so a transient failure is safe to retry: the same key
|
|
1442
|
+
* rides every attempt, and a retry of one that already landed comes back as
|
|
1443
|
+
* `replayed: true` instead of adjusting again. The key is also copied onto
|
|
1444
|
+
* any thrown error (`error.idempotencyKey`) so the caller can replay safely.
|
|
1751
1445
|
*/
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1446
|
+
private adjust;
|
|
1447
|
+
/**
|
|
1448
|
+
* Change how much a customer is granted every billing cycle (wallet top-up,
|
|
1449
|
+
* credits, outcomes, units or a composite pool). Any increase or decrease
|
|
1450
|
+
* applies to their current balance immediately. `PUT …/:id/recurring-grant`.
|
|
1451
|
+
*/
|
|
1452
|
+
updateRecurringGrant(id: string, input: RecurringGrantInput): Promise<RecurringGrantResult>;
|
|
1453
|
+
/** {@link updateRecurringGrant}, addressing the customer by its
|
|
1454
|
+
* `externalId`. `PUT /api/v1/customers/ext/:externalId/recurring-grant`. */
|
|
1455
|
+
updateRecurringGrantByExternalId(externalId: string, input: RecurringGrantInput): Promise<RecurringGrantResult>;
|
|
1755
1456
|
}
|
|
1756
1457
|
|
|
1757
1458
|
/**
|
|
@@ -1771,44 +1472,12 @@ declare class Invoices {
|
|
|
1771
1472
|
/** Fetch one full invoice + its plan snapshot. `GET /api/v1/invoices/:id`. */
|
|
1772
1473
|
get(id: string): Promise<InvoiceDetail>;
|
|
1773
1474
|
/**
|
|
1774
|
-
* Mint a hosted pay link for an OPEN invoice. PAID/VOID invoices are rejected
|
|
1475
|
+
* Mint a hosted pay link for an OPEN invoice. PAID/VOID/AUTO_CLOSED invoices are rejected
|
|
1775
1476
|
* with a `ConflictError`. `GET /api/v1/invoices/:id/pay-link`.
|
|
1776
1477
|
*/
|
|
1777
1478
|
payLink(id: string): Promise<PayLink>;
|
|
1778
1479
|
}
|
|
1779
1480
|
|
|
1780
|
-
/**
|
|
1781
|
-
* The `outcomes` resource — manage the org's outcome *types* (the catalog). An
|
|
1782
|
-
* outcome is a multi-step workflow. `/api/v1/outcomes`.
|
|
1783
|
-
*
|
|
1784
|
-
* Two distinct kinds of agent key, in separate namespaces, each unique per
|
|
1785
|
-
* organisation — do not conflate them:
|
|
1786
|
-
* - the OUTCOME's own `agentKey`, REQUIRED on `create()` and `update()`, which
|
|
1787
|
-
* names the outcome itself in the catalogue;
|
|
1788
|
-
* - each STEP's `agentKey`, which is what you pass to `signals.outcome()` to
|
|
1789
|
-
* report usage and to the outcome-adjust API.
|
|
1790
|
-
*/
|
|
1791
|
-
declare class Outcomes {
|
|
1792
|
-
private readonly transport;
|
|
1793
|
-
constructor(transport: Transport);
|
|
1794
|
-
/** List outcome types. Pass `{ active: true }` to only return active ones.
|
|
1795
|
-
* `{ active: false }` returns only archived ones; omitting it returns
|
|
1796
|
-
* both. See `activeQuery` — the API itself only supports `true`. */
|
|
1797
|
-
list(params?: {
|
|
1798
|
-
active?: boolean;
|
|
1799
|
-
}): Promise<Outcome[]>;
|
|
1800
|
-
/** Create an outcome type with its steps. `POST /api/v1/outcomes`. */
|
|
1801
|
-
create(input: CreateOutcomeInput): Promise<Outcome>;
|
|
1802
|
-
/** Fetch one outcome type with steps + stats. `GET /api/v1/outcomes/:id`. */
|
|
1803
|
-
get(id: string): Promise<OutcomeDetail>;
|
|
1804
|
-
/** Update an outcome type's definition. `PATCH /api/v1/outcomes/:id`. */
|
|
1805
|
-
update(id: string, input: UpdateOutcomeInput): Promise<Outcome>;
|
|
1806
|
-
/** Activate or deactivate an outcome type; returns the updated outcome. */
|
|
1807
|
-
setActive(id: string, isActive: boolean): Promise<Outcome>;
|
|
1808
|
-
/** Delete an outcome type. */
|
|
1809
|
-
delete(id: string): Promise<void>;
|
|
1810
|
-
}
|
|
1811
|
-
|
|
1812
1481
|
/**
|
|
1813
1482
|
* The `payments` resource — read-only. A payment is a PAID invoice; the `id`
|
|
1814
1483
|
* used here is that underlying invoice id. `/api/v1/payments`.
|
|
@@ -1826,9 +1495,9 @@ declare class Payments {
|
|
|
1826
1495
|
}
|
|
1827
1496
|
|
|
1828
1497
|
/**
|
|
1829
|
-
* The `plans` resource —
|
|
1830
|
-
*
|
|
1831
|
-
*
|
|
1498
|
+
* The `plans` resource — read the billing plans customers can subscribe to.
|
|
1499
|
+
* Each plan is a set of entitlement components (wallet / credit / outcome /
|
|
1500
|
+
* unit / flat) billed on a cycle. `/api/v1/plans`.
|
|
1832
1501
|
*/
|
|
1833
1502
|
declare class Plans {
|
|
1834
1503
|
private readonly transport;
|
|
@@ -1839,16 +1508,6 @@ declare class Plans {
|
|
|
1839
1508
|
list(params?: {
|
|
1840
1509
|
active?: boolean;
|
|
1841
1510
|
}): Promise<Plan[]>;
|
|
1842
|
-
/** Create a plan. `POST /api/v1/plans`. */
|
|
1843
|
-
create(input: CreatePlanInput): Promise<Plan>;
|
|
1844
|
-
/** Fetch one plan with aggregate subscriber/invoice stats. `GET /api/v1/plans/:id`. */
|
|
1845
|
-
get(id: string): Promise<PlanDetail>;
|
|
1846
|
-
/** Replace a plan's definition (components + settings). `PATCH /api/v1/plans/:id`. */
|
|
1847
|
-
update(id: string, input: UpdatePlanInput): Promise<Plan>;
|
|
1848
|
-
/** Activate or deactivate a plan without rewriting it. */
|
|
1849
|
-
setActive(id: string, isActive: boolean): Promise<Plan>;
|
|
1850
|
-
/** Delete a plan. Refused once any customer has purchased it. */
|
|
1851
|
-
delete(id: string): Promise<void>;
|
|
1852
1511
|
}
|
|
1853
1512
|
|
|
1854
1513
|
/**
|
|
@@ -2057,19 +1716,6 @@ declare class Signals {
|
|
|
2057
1716
|
* not a safe no-op — see {@link OutcomeCompletionResult}.
|
|
2058
1717
|
*/
|
|
2059
1718
|
completeOutcome(input: OutcomeCompletionInput): Promise<OutcomeCompletionResult>;
|
|
2060
|
-
/**
|
|
2061
|
-
* Recent usage logs + totals for a customer. `GET /api/v1/usage`.
|
|
2062
|
-
*
|
|
2063
|
-
* Still the legacy path, deliberately. The `/api/v1/signal/*` family is
|
|
2064
|
-
* POST-only — it replaced how usage is INGESTED, not how it is read — so
|
|
2065
|
-
* `GET /api/v1/usage` has no successor and is not deprecated. It is also the
|
|
2066
|
-
* only way to prove a signal landed, which matters more now that ingestion
|
|
2067
|
-
* answers `202` for everything.
|
|
2068
|
-
*/
|
|
2069
|
-
list(params: {
|
|
2070
|
-
customerId: string;
|
|
2071
|
-
limit?: number;
|
|
2072
|
-
}): Promise<UsageList>;
|
|
2073
1719
|
/**
|
|
2074
1720
|
* Record one unit-metered event (a fixed-price meter with no tokens),
|
|
2075
1721
|
* addressed to a catalog unit by its `agentKey`. Sent immediately — unit
|
|
@@ -2110,75 +1756,23 @@ declare class Signals {
|
|
|
2110
1756
|
*/
|
|
2111
1757
|
completeComposite(input: CompositeCompletionInput): Promise<CompositeCompletionResult>;
|
|
2112
1758
|
/**
|
|
2113
|
-
*
|
|
1759
|
+
* One customer's usage history, merged from every meter kind — credit,
|
|
1760
|
+
* outcome, unit, wallet, and completed composite occurrences — into one
|
|
1761
|
+
* feed sorted by time. `GET /api/v1/signal/usage-log`. Exactly the same
|
|
1762
|
+
* rows the customer portal's own "Usage logs" table shows, so a caller can
|
|
1763
|
+
* build against this instead of the portal UI.
|
|
1764
|
+
*
|
|
1765
|
+
* Cursor-paginated, NOT page-numbered: `limit` + `cursor` in, `nextCursor`
|
|
1766
|
+
* out. Omit `cursor` for the first page; pass the previous page's
|
|
1767
|
+
* `nextCursor` back to fetch the next one, and stop once it comes back
|
|
1768
|
+
* `null`. Unlike offset pagination, the cost of a page never grows with how
|
|
1769
|
+
* deep you've paged — each page only asks for rows strictly before the
|
|
1770
|
+
* cursor's position.
|
|
2114
1771
|
*
|
|
2115
|
-
*
|
|
2116
|
-
*
|
|
1772
|
+
* Read-only; unlike {@link track}/{@link unit}/etc., there is nothing to
|
|
1773
|
+
* buffer or retry here.
|
|
2117
1774
|
*/
|
|
2118
|
-
|
|
2119
|
-
customerId: string;
|
|
2120
|
-
limit?: number;
|
|
2121
|
-
}): Promise<UnitUsageList>;
|
|
2122
|
-
}
|
|
2123
|
-
|
|
2124
|
-
/**
|
|
2125
|
-
* The `units` resource — manage the org's unit *types* (the catalog): named,
|
|
2126
|
-
* quantity-priced meters (FLAT / SLAB / VOLUME). Record consumption against a
|
|
2127
|
-
* unit with `signals.unit()`. `/api/v1/units-catalog`.
|
|
2128
|
-
*/
|
|
2129
|
-
declare class Units {
|
|
2130
|
-
private readonly transport;
|
|
2131
|
-
constructor(transport: Transport);
|
|
2132
|
-
/** List unit types. Pass `{ active: true }` to only return active ones.
|
|
2133
|
-
* `{ active: false }` returns only archived ones; omitting it returns
|
|
2134
|
-
* both. See `activeQuery` — the API itself only supports `true`. */
|
|
2135
|
-
list(params?: {
|
|
2136
|
-
active?: boolean;
|
|
2137
|
-
}): Promise<Unit[]>;
|
|
2138
|
-
/** Create a unit type. `POST /api/v1/units-catalog`. */
|
|
2139
|
-
create(input: CreateUnitInput): Promise<Unit>;
|
|
2140
|
-
/** Fetch one unit type with stats. `GET /api/v1/units-catalog/:id`. */
|
|
2141
|
-
get(id: string): Promise<UnitDetail>;
|
|
2142
|
-
/** Update a unit type's definition. `PATCH /api/v1/units-catalog/:id`. */
|
|
2143
|
-
update(id: string, input: UpdateUnitInput): Promise<Unit>;
|
|
2144
|
-
/** Activate or deactivate a unit type. */
|
|
2145
|
-
setActive(id: string, isActive: boolean): Promise<Unit>;
|
|
2146
|
-
/** Delete a unit type. */
|
|
2147
|
-
delete(id: string): Promise<void>;
|
|
2148
|
-
}
|
|
2149
|
-
|
|
2150
|
-
/**
|
|
2151
|
-
* The `webhooks` resource — threshold alerts. At most one webhook per kind
|
|
2152
|
-
* (CREDIT / OUTCOME / WALLET); posting a kind again upserts it. `/api/v1/webhooks`.
|
|
2153
|
-
*/
|
|
2154
|
-
declare class Webhooks {
|
|
2155
|
-
private readonly transport;
|
|
2156
|
-
constructor(transport: Transport);
|
|
2157
|
-
/** List configured webhooks. `GET /api/v1/webhooks`. */
|
|
2158
|
-
list(): Promise<Webhook[]>;
|
|
2159
|
-
/** Create or replace the webhook for a kind. `POST /api/v1/webhooks`. */
|
|
2160
|
-
upsert(input: UpsertWebhookInput): Promise<Webhook>;
|
|
2161
|
-
/** Delete the webhook for a kind (idempotent). `DELETE /api/v1/webhooks/:kind`. */
|
|
2162
|
-
delete(kind: ThresholdKind): Promise<void>;
|
|
2163
|
-
}
|
|
2164
|
-
|
|
2165
|
-
/**
|
|
2166
|
-
* The `workspace` resource — read-only introspection of the org behind the API
|
|
2167
|
-
* key. Grounds an integration (which workspace, and is it `sandbox` or `live`?)
|
|
2168
|
-
* and lists the models it may meter against. `/api/v1/me`, `/api/v1/models`.
|
|
2169
|
-
*/
|
|
2170
|
-
declare class Workspace {
|
|
2171
|
-
private readonly transport;
|
|
2172
|
-
constructor(transport: Transport);
|
|
2173
|
-
/** Identify the org + key behind the request, incl. `sandbox` | `live`. */
|
|
2174
|
-
me(): Promise<WorkspaceIdentity>;
|
|
2175
|
-
/** The org's enabled models with live prices. `{ active: true }` returns only
|
|
2176
|
-
* the models that can be metered right now.
|
|
2177
|
-
* `{ active: false }` returns only archived ones; omitting it returns
|
|
2178
|
-
* both. See `activeQuery` — the API itself only supports `true`. */
|
|
2179
|
-
models(params?: {
|
|
2180
|
-
active?: boolean;
|
|
2181
|
-
}): Promise<Model[]>;
|
|
1775
|
+
usageLog(params: UsageLogListParams): Promise<UsageLogPage>;
|
|
2182
1776
|
}
|
|
2183
1777
|
|
|
2184
1778
|
/**
|
|
@@ -2199,11 +1793,11 @@ declare class Workspace {
|
|
|
2199
1793
|
* ```
|
|
2200
1794
|
*/
|
|
2201
1795
|
declare class ClockNext {
|
|
2202
|
-
/** Record
|
|
1796
|
+
/** Record usage signals (credit / wallet / outcome / unit) and read the usage log. */
|
|
2203
1797
|
readonly signals: Signals;
|
|
2204
|
-
/** Manage customers, their members,
|
|
1798
|
+
/** Manage customers, their members, and balances. */
|
|
2205
1799
|
readonly customers: Customers;
|
|
2206
|
-
/**
|
|
1800
|
+
/** List billing plans. */
|
|
2207
1801
|
readonly plans: Plans;
|
|
2208
1802
|
/** Subscribe customers to plans (purchases). */
|
|
2209
1803
|
readonly purchases: Purchases;
|
|
@@ -2211,20 +1805,8 @@ declare class ClockNext {
|
|
|
2211
1805
|
readonly invoices: Invoices;
|
|
2212
1806
|
/** Read payments (paid invoices). */
|
|
2213
1807
|
readonly payments: Payments;
|
|
2214
|
-
/** Manage the credit-type catalog. */
|
|
2215
|
-
readonly credits: Credits;
|
|
2216
|
-
/** Manage the composite catalog — bundles billed as one thing. */
|
|
2217
|
-
readonly composites: Composites;
|
|
2218
|
-
/** Manage the outcome-type catalog. */
|
|
2219
|
-
readonly outcomes: Outcomes;
|
|
2220
|
-
/** Manage the unit-type catalog. */
|
|
2221
|
-
readonly units: Units;
|
|
2222
|
-
/** Configure threshold webhooks. */
|
|
2223
|
-
readonly webhooks: Webhooks;
|
|
2224
1808
|
/** Mint customer-portal embed tokens. */
|
|
2225
1809
|
readonly portal: Portal;
|
|
2226
|
-
/** Identify the workspace (sandbox/live) + list its models. `/me`, `/models`. */
|
|
2227
|
-
readonly workspace: Workspace;
|
|
2228
1810
|
private readonly cfg;
|
|
2229
1811
|
private readonly flusher;
|
|
2230
1812
|
constructor(config: ClockNextConfig);
|
|
@@ -2312,4 +1894,4 @@ declare class NetworkError extends ClockNextError {
|
|
|
2312
1894
|
});
|
|
2313
1895
|
}
|
|
2314
1896
|
|
|
2315
|
-
export { type AddMemberInput, AllowanceError, type ApiCustomer, AuthError, type BillingCycle, type BillingMode, ClockNext, type ClockNextConfig, ClockNextError, type ClockNextErrorCode, type ComponentType, type
|
|
1897
|
+
export { type AddMemberInput, type AdjustResult, AllowanceError, type ApiCustomer, AuthError, type BillingCycle, type BillingMode, ClockNext, type ClockNextConfig, ClockNextError, type ClockNextErrorCode, type ComponentType, type CompositeAdjustInput, type CompositeCompletionInput, type CompositeCompletionResult, type CompositeTag, ConflictError, type CreateCustomerInput, type CreatePurchaseInput, type CreditAdjustInput, type CreditBalance, type CreditInput, type CreditSignal, type CustomerBalances, type CustomerList, type CustomerPlan, type CustomerPlanDetails, type CustomerProfileInput, type CustomerRef, type DropReason, type FetchLike, ForbiddenError, type Invoice, type InvoiceDetail, type InvoiceLineItem, type InvoiceListRow, type InvoiceParty, type InvoicePlanSnapshot, type InvoiceStatus, type Logger, type Member, type MemberProfile, NetworkError, NotFoundError, type OutcomeAdjustInput, type OutcomeBalance, type OutcomeCompletionInput, type OutcomeCompletionResult, type OutcomeInput, type OutcomeSignal, type PayLink, type PaymentDetail, type PaymentRow, type Plan, type PlanComponent, PlanError, type PlanKind, type PlanRef, type PlanType, type PortalToken, type PortalTokenInput, type Purchase, type PurchaseDetail, type PurchaseStatus, RateLimitError, type RecurringGrantInput, type RecurringGrantResult, type RemovedMember, type SerializedOutcomeAttribution, type SerializedRuleApplication, type SerializedUnitUsage, type SerializedUsageLog, ServerError, type Signal, type SignalDelivery, type SignalStatus, type SignalType, type Tokens, type TrackResult, type UnitAdjustInput, type UnitBalance, type UnitInput, type UnitTrackResult, type UpdateMemberInput, type UsageBalance, type UsageLogAppliedRule, type UsageLogEntry, type UsageLogListParams, type UsageLogOutcomeAttribution, type UsageLogPage, type UsageLogPeriod, ValidationError, type WalletAdjustInput, type WalletInput, type WalletPool, type WalletSignal, signalToWire };
|