@clocknext/sdk 0.12.1 → 0.13.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 +20 -5
- package/dist/index.cjs +68 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +129 -28
- package/dist/index.d.ts +129 -28
- package/dist/index.js +68 -11
- package/dist/index.js.map +1 -1
- package/examples/node-basic.ts +5 -3
- package/package.json +1 -1
- package/src/index.ts +3 -0
- package/src/resources/customers.ts +26 -3
- package/src/resources/signals.ts +66 -11
- package/src/types.ts +92 -18
package/dist/index.d.cts
CHANGED
|
@@ -123,7 +123,14 @@ interface WalletSignal extends SignalBase {
|
|
|
123
123
|
/**
|
|
124
124
|
* Records one step of a multi-call outcome run. The `agentKey` identifies the
|
|
125
125
|
* step (and the outcome); `runId` groups every signal of a single run, so a step
|
|
126
|
-
* may repeat freely. The run bills once, when the caller
|
|
126
|
+
* may repeat freely. The run bills once, when the caller closes it with
|
|
127
|
+
* `signals.completeOutcome()` — a SEPARATE, dedicated call, never a flag on a
|
|
128
|
+
* step signal.
|
|
129
|
+
*
|
|
130
|
+
* There is no `complete` field here. `POST /api/v1/signal/outcome` (what this
|
|
131
|
+
* type posts to) now accepts ONLY the step shape and rejects a body that also
|
|
132
|
+
* carries `complete` — see {@link OutcomeCompletionInput} /
|
|
133
|
+
* `signals.completeOutcome()`, its own dedicated route.
|
|
127
134
|
*/
|
|
128
135
|
interface OutcomeSignal extends SignalBase {
|
|
129
136
|
type: "outcome";
|
|
@@ -135,17 +142,6 @@ interface OutcomeSignal extends SignalBase {
|
|
|
135
142
|
* outcome). Opaque to ClockNext — any string you can correlate; unique per org.
|
|
136
143
|
*/
|
|
137
144
|
runId: string;
|
|
138
|
-
/**
|
|
139
|
-
* Set `true` on the LAST step signal to declare the run finished — completion
|
|
140
|
-
* is never inferred from step coverage. Sending it twice is a safe no-op and
|
|
141
|
-
* can't bill again.
|
|
142
|
-
*
|
|
143
|
-
* This closes the RUN only. If the signal also carries a `composite`, that
|
|
144
|
-
* occurrence stays open and unbilled until you call
|
|
145
|
-
* `signals.completeComposite()` — the two completions are separate, and
|
|
146
|
-
* neither implies the other.
|
|
147
|
-
*/
|
|
148
|
-
complete?: boolean;
|
|
149
145
|
/** Optional composite this signal belongs to. See {@link CompositeTag}. */
|
|
150
146
|
composite?: CompositeTag;
|
|
151
147
|
}
|
|
@@ -154,6 +150,56 @@ type Signal = CreditSignal | WalletSignal | OutcomeSignal;
|
|
|
154
150
|
type CreditInput = Omit<CreditSignal, "type">;
|
|
155
151
|
type WalletInput = Omit<WalletSignal, "type">;
|
|
156
152
|
type OutcomeInput = Omit<OutcomeSignal, "type">;
|
|
153
|
+
/**
|
|
154
|
+
* Input for `signals.completeOutcome()` — closes ONE outcome run, the outcome
|
|
155
|
+
* mirror of {@link CompositeCompletionInput}. No `agentKey`, no `usage`: this
|
|
156
|
+
* closes an EXISTING run that an earlier `signals.outcome()` step already
|
|
157
|
+
* opened, so there is no step behind this call and nothing here to price.
|
|
158
|
+
*
|
|
159
|
+
* This closes the RUN only. If a step of this run also carried a `composite`,
|
|
160
|
+
* that occurrence stays open and unbilled until you separately call
|
|
161
|
+
* `signals.completeComposite()` — the two completions are independent, and
|
|
162
|
+
* neither implies the other.
|
|
163
|
+
*/
|
|
164
|
+
interface OutcomeCompletionInput {
|
|
165
|
+
customerId: string;
|
|
166
|
+
/** The same `runId` the run's step signals were sent with. */
|
|
167
|
+
runId: string;
|
|
168
|
+
/** Optional member (email) this completion is attributed to. */
|
|
169
|
+
member?: string;
|
|
170
|
+
/** Idempotency key, auto-generated if omitted. Sending `complete` twice for
|
|
171
|
+
* the same run is already a safe no-op server-side, so this only collapses
|
|
172
|
+
* a retry into one attempt rather than protecting against a double bill. */
|
|
173
|
+
idempotencyKey?: string;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* The result of `signals.completeOutcome()`.
|
|
177
|
+
*
|
|
178
|
+
* Unlike {@link CompositeCompletionResult}, `ALREADY_COMPLETED` is NOT what a
|
|
179
|
+
* normal second ping for the same run gets back — that is rejected outright
|
|
180
|
+
* (a permanent error: the run has already been billed, and completing it again
|
|
181
|
+
* would bill it twice). `ALREADY_COMPLETED` is reserved for the much rarer case
|
|
182
|
+
* of two concurrent deliveries of the exact same request (e.g. a client-side
|
|
183
|
+
* retry racing the original), which really is a harmless echo.
|
|
184
|
+
*/
|
|
185
|
+
interface OutcomeCompletionResult {
|
|
186
|
+
/** How far the ping got. Never `"buffered"` — completions are always sent
|
|
187
|
+
* immediately. See {@link TrackResult.status}. */
|
|
188
|
+
delivery: Extract<SignalDelivery, "accepted" | "recorded">;
|
|
189
|
+
/** True when the ping was accepted but not yet applied (`202`). Prefer
|
|
190
|
+
* {@link OutcomeCompletionResult.delivery}. */
|
|
191
|
+
queued: boolean;
|
|
192
|
+
/** `COMPLETED` on the first close, `ALREADY_COMPLETED` only on the rare
|
|
193
|
+
* concurrent-replay case described above. Absent when the ping was queued. */
|
|
194
|
+
status?: "COMPLETED" | "ALREADY_COMPLETED";
|
|
195
|
+
/** The priced usage log, when the server closed the run inline. `null` on a
|
|
196
|
+
* `202` hand-off. */
|
|
197
|
+
usageLog?: SerializedUsageLog | null;
|
|
198
|
+
/** The durable inbox id — see {@link TrackResult.rawId}. */
|
|
199
|
+
rawId?: string;
|
|
200
|
+
/** The queue message id, present only on a `202` hand-off. */
|
|
201
|
+
messageId?: string;
|
|
202
|
+
}
|
|
157
203
|
interface SerializedRuleApplication {
|
|
158
204
|
ruleId: string | null;
|
|
159
205
|
ruleName: string;
|
|
@@ -902,17 +948,21 @@ interface WalletEntryInput {
|
|
|
902
948
|
notes?: string;
|
|
903
949
|
}
|
|
904
950
|
/** Grant (positive) or claw back (negative) a credit balance. `delta` must be a
|
|
905
|
-
* non-zero whole number. The credit is addressed by its stable `agentKey`.
|
|
951
|
+
* non-zero whole number. The credit is addressed by its stable `agentKey`. A
|
|
952
|
+
* reduce is never rejected or floored for going below 0 — the resulting
|
|
953
|
+
* balance may read negative, same as a real-usage overdraft already can. */
|
|
906
954
|
interface CreditAdjustInput {
|
|
907
955
|
/** The credit's stable agent key (the same key used to record usage). */
|
|
908
956
|
agentKey: string;
|
|
909
957
|
delta: number;
|
|
910
958
|
notes?: string;
|
|
911
959
|
}
|
|
912
|
-
/** Grant/claw an outcome balance. `delta` is a non-zero whole number
|
|
913
|
-
*
|
|
960
|
+
/** Grant/claw an outcome balance. `delta` is a non-zero whole number. The
|
|
961
|
+
* outcome is addressed here by a STEP's `agentKey`, which resolves to its
|
|
914
962
|
* parent outcome — NOT by the outcome's own `agentKey` ({@link Outcome.agentKey}),
|
|
915
|
-
* which this endpoint does not accept.
|
|
963
|
+
* which this endpoint does not accept. A reduce is never rejected or floored
|
|
964
|
+
* for going below 0 — the resulting balance may read negative, same as a
|
|
965
|
+
* real-usage overdraft already can. */
|
|
916
966
|
interface OutcomeAdjustInput {
|
|
917
967
|
/** An outcome STEP's stable agent key — identifies the parent outcome. Passing
|
|
918
968
|
* the outcome's own `agentKey` here fails with `422`. */
|
|
@@ -920,14 +970,35 @@ interface OutcomeAdjustInput {
|
|
|
920
970
|
delta: number;
|
|
921
971
|
notes?: string;
|
|
922
972
|
}
|
|
923
|
-
/** Grant/claw a unit balance. `delta` is non-zero (fractional allowed)
|
|
924
|
-
*
|
|
973
|
+
/** Grant/claw a unit balance. `delta` is non-zero (fractional allowed). The
|
|
974
|
+
* unit is addressed by its stable `agentKey`. A reduce is never rejected or
|
|
975
|
+
* floored for going below 0 — the resulting balance may read negative, same
|
|
976
|
+
* as a real-usage overdraft already can. */
|
|
925
977
|
interface UnitAdjustInput {
|
|
926
978
|
/** The unit's stable agent key (the same key used to record usage). */
|
|
927
979
|
agentKey: string;
|
|
928
980
|
delta: number;
|
|
929
981
|
notes?: string;
|
|
930
982
|
}
|
|
983
|
+
/**
|
|
984
|
+
* Grant (positive) or claw back (negative) slots on a customer's ADVANCE
|
|
985
|
+
* composite (pricing metric) pool for the CURRENT billing cycle. `delta` is a
|
|
986
|
+
* non-zero whole number. A reduce is never rejected or floored for going below
|
|
987
|
+
* 0 — same as credit/outcome/unit adjustments; the resulting pool may read
|
|
988
|
+
* negative. Fails if the customer has no active ADVANCE purchase component
|
|
989
|
+
* selling this composite.
|
|
990
|
+
*/
|
|
991
|
+
interface CompositeAdjustInput {
|
|
992
|
+
/**
|
|
993
|
+
* The composite's stable identifier — its `refId` (see {@link Composite.refId}),
|
|
994
|
+
* the same value signals tag it with, NOT `agentKey` (a composite has no
|
|
995
|
+
* `agentKey` column of its own). Named `agentKey` on the wire only so the
|
|
996
|
+
* four adjust endpoints share one request shape.
|
|
997
|
+
*/
|
|
998
|
+
agentKey: string;
|
|
999
|
+
delta: number;
|
|
1000
|
+
notes?: string;
|
|
1001
|
+
}
|
|
931
1002
|
/** A per-model token bundle attached to a credit or outcome step. */
|
|
932
1003
|
interface ModelBundleEntry {
|
|
933
1004
|
orgModelId: string;
|
|
@@ -1660,8 +1731,11 @@ declare class Customers {
|
|
|
1660
1731
|
transaction: WalletTransaction;
|
|
1661
1732
|
balanceUsd: number;
|
|
1662
1733
|
}>;
|
|
1663
|
-
/** Grant or claw back a credit balance.
|
|
1664
|
-
|
|
1734
|
+
/** Grant or claw back a credit balance. Returns the remaining balance.
|
|
1735
|
+
* `POST …/:id/credits/adjust`. */
|
|
1736
|
+
adjustCredit(id: string, input: CreditAdjustInput): Promise<{
|
|
1737
|
+
remaining: number;
|
|
1738
|
+
}>;
|
|
1665
1739
|
/** Grant or claw back an outcome balance. Returns the remaining balance. */
|
|
1666
1740
|
adjustOutcome(id: string, input: OutcomeAdjustInput): Promise<{
|
|
1667
1741
|
remaining: number;
|
|
@@ -1670,6 +1744,14 @@ declare class Customers {
|
|
|
1670
1744
|
adjustUnit(id: string, input: UnitAdjustInput): Promise<{
|
|
1671
1745
|
remaining: number;
|
|
1672
1746
|
}>;
|
|
1747
|
+
/**
|
|
1748
|
+
* Grant or claw back slots on a customer's ADVANCE composite pool for the
|
|
1749
|
+
* current billing cycle. Returns the resulting `remaining` slot count.
|
|
1750
|
+
* `POST …/:id/composites/adjust`.
|
|
1751
|
+
*/
|
|
1752
|
+
adjustComposite(id: string, input: CompositeAdjustInput): Promise<{
|
|
1753
|
+
remaining: number;
|
|
1754
|
+
}>;
|
|
1673
1755
|
}
|
|
1674
1756
|
|
|
1675
1757
|
/**
|
|
@@ -1956,6 +2038,25 @@ declare class Signals {
|
|
|
1956
2038
|
outcome(input: OutcomeInput, opts?: {
|
|
1957
2039
|
wait?: boolean;
|
|
1958
2040
|
}): Promise<TrackResult>;
|
|
2041
|
+
/**
|
|
2042
|
+
* Close ONE outcome run — declares the workflow finished and bills it. The
|
|
2043
|
+
* outcome mirror of {@link Signals.completeComposite}, on its own dedicated
|
|
2044
|
+
* route: `POST /api/v1/signal/outcome/complete`.
|
|
2045
|
+
*
|
|
2046
|
+
* An outcome bills per COMPLETION, never per step, and `signals.outcome()`
|
|
2047
|
+
* never closes one — it accepts only the step shape. Declaring the workflow
|
|
2048
|
+
* finished is always this separate, explicit, contentless call.
|
|
2049
|
+
*
|
|
2050
|
+
* This closes the RUN only. If a step of this run also carried a
|
|
2051
|
+
* `composite`, that occurrence stays open and unbilled until you separately
|
|
2052
|
+
* call {@link Signals.completeComposite} — the two completions are
|
|
2053
|
+
* independent, and neither implies the other.
|
|
2054
|
+
*
|
|
2055
|
+
* Sent immediately, never buffered. A genuinely second, independent call for
|
|
2056
|
+
* an already-closed run is a PERMANENT error (it would bill the run twice),
|
|
2057
|
+
* not a safe no-op — see {@link OutcomeCompletionResult}.
|
|
2058
|
+
*/
|
|
2059
|
+
completeOutcome(input: OutcomeCompletionInput): Promise<OutcomeCompletionResult>;
|
|
1959
2060
|
/**
|
|
1960
2061
|
* Recent usage logs + totals for a customer. `GET /api/v1/usage`.
|
|
1961
2062
|
*
|
|
@@ -1993,13 +2094,13 @@ declare class Signals {
|
|
|
1993
2094
|
* arrive in any order and the occurrence stays open and unbilled until you
|
|
1994
2095
|
* say otherwise. Put it on the line before your own `return`.
|
|
1995
2096
|
*
|
|
1996
|
-
* EVERY composite needs this, outcome-backed ones included.
|
|
1997
|
-
*
|
|
1998
|
-
*
|
|
1999
|
-
*
|
|
2000
|
-
*
|
|
2001
|
-
*
|
|
2002
|
-
*
|
|
2097
|
+
* EVERY composite needs this, outcome-backed ones included. `completeOutcome()`
|
|
2098
|
+
* closes its RUN and nothing else — it does not close the composite
|
|
2099
|
+
* occurrence the run was tagged into, whatever mix of credits, outcomes and
|
|
2100
|
+
* units that composite wraps. (Earlier versions of this SDK documented the
|
|
2101
|
+
* opposite. Believing it means the occurrence stays ONGOING forever and is
|
|
2102
|
+
* never billed, so if you tag outcome signals with a `composite`, you must
|
|
2103
|
+
* still call this.)
|
|
2003
2104
|
*
|
|
2004
2105
|
* Closing twice is safe: the second call answers `ALREADY_COMPLETED` and
|
|
2005
2106
|
* cannot bill again. Calling it EARLY is also safe — before every entitlement
|
|
@@ -2211,4 +2312,4 @@ declare class NetworkError extends ClockNextError {
|
|
|
2211
2312
|
});
|
|
2212
2313
|
}
|
|
2213
2314
|
|
|
2214
|
-
export { type AddMemberInput, AllowanceError, type ApiCustomer, AuthError, type BillingCycle, type BillingMode, ClockNext, type ClockNextConfig, ClockNextError, type ClockNextErrorCode, type ComponentType, type Composite, type CompositeCatalogueRef, type CompositeCompletionInput, type CompositeCompletionResult, type CompositeComponentInput, type CompositeTag, ConflictError, type CostPoint, type CostStats, type CreateCompositeInput, type CreateCreditInput, type CreateCustomerInput, type CreateOutcomeInput, type CreatePlanInput, type CreatePurchaseInput, type CreateUnitInput, type Credit, type CreditAdjustInput, type CreditAnalytics, type CreditBalance, type CreditComponentInput, type CreditDetail, type CreditInput, type CreditSignal, type CustomerBalances, type CustomerList, type CustomerPlan, type CustomerPlanDetails, type CustomerProfileInput, type DropReason, type FetchLike, type FlatComponentInput, type FlatUnitInput, ForbiddenError, type Invoice, type InvoiceDetail, type InvoiceLineItem, type InvoiceListRow, type InvoiceParty, type InvoicePlanSnapshot, type InvoiceStatus, type Logger, type Member, type MemberProfile, type Model, type ModelBundleEntry, NetworkError, NotFoundError, type Outcome, type OutcomeAdjustInput, type OutcomeAnalytics, type OutcomeBalance, type OutcomeComponentInput, type OutcomeDetail, type OutcomeInput, type OutcomeSignal, type OutcomeStepInput, type PayLink, type PaymentDetail, type PaymentRow, type Plan, type PlanComponent, type PlanComponentInput, type PlanDetail, PlanError, type PlanKind, type PlanRef, type PlanType, type PortalToken, type PortalTokenInput, type Purchase, type PurchaseDetail, type PurchaseStatus, RateLimitError, type RemovedMember, type SerializedOutcomeAttribution, type SerializedRuleApplication, type SerializedUnitUsage, type SerializedUsageLog, ServerError, type Signal, type SignalDelivery, type SignalStatus, type SignalType, type ThresholdKind, type TieredUnitInput, type Tokens, type TrackResult, type Unit, type UnitAdjustInput, type UnitBalance, type UnitComponentInput, type UnitCustomerRow, type UnitDetail, type UnitInput, type UnitPricingType, type UnitTier, type UnitTierInput, type UnitTrackResult, type UnitUsageList, type UnitUsageRow, type UpdateCreditInput, type UpdateMemberInput, type UpdateOutcomeInput, type UpdatePlanInput, type UpdateUnitInput, type UpsertWebhookInput, type UsageBalance, type UsageList, ValidationError, type WalletComponentInput, type WalletEntitlementKind, type WalletEntryInput, type WalletInput, type WalletList, type WalletSignal, type WalletTransaction, type WalletTransactionSource, type WalletTransactionType, type Webhook, type WorkspaceIdentity, signalToWire };
|
|
2315
|
+
export { type AddMemberInput, AllowanceError, type ApiCustomer, AuthError, type BillingCycle, type BillingMode, ClockNext, type ClockNextConfig, ClockNextError, type ClockNextErrorCode, type ComponentType, type Composite, type CompositeAdjustInput, type CompositeCatalogueRef, type CompositeCompletionInput, type CompositeCompletionResult, type CompositeComponentInput, type CompositeTag, ConflictError, type CostPoint, type CostStats, type CreateCompositeInput, type CreateCreditInput, type CreateCustomerInput, type CreateOutcomeInput, type CreatePlanInput, type CreatePurchaseInput, type CreateUnitInput, type Credit, type CreditAdjustInput, type CreditAnalytics, type CreditBalance, type CreditComponentInput, type CreditDetail, type CreditInput, type CreditSignal, type CustomerBalances, type CustomerList, type CustomerPlan, type CustomerPlanDetails, type CustomerProfileInput, type DropReason, type FetchLike, type FlatComponentInput, type FlatUnitInput, ForbiddenError, type Invoice, type InvoiceDetail, type InvoiceLineItem, type InvoiceListRow, type InvoiceParty, type InvoicePlanSnapshot, type InvoiceStatus, type Logger, type Member, type MemberProfile, type Model, type ModelBundleEntry, NetworkError, NotFoundError, type Outcome, type OutcomeAdjustInput, type OutcomeAnalytics, type OutcomeBalance, type OutcomeCompletionInput, type OutcomeCompletionResult, type OutcomeComponentInput, type OutcomeDetail, type OutcomeInput, type OutcomeSignal, type OutcomeStepInput, type PayLink, type PaymentDetail, type PaymentRow, type Plan, type PlanComponent, type PlanComponentInput, type PlanDetail, PlanError, type PlanKind, type PlanRef, type PlanType, type PortalToken, type PortalTokenInput, type Purchase, type PurchaseDetail, type PurchaseStatus, RateLimitError, type RemovedMember, type SerializedOutcomeAttribution, type SerializedRuleApplication, type SerializedUnitUsage, type SerializedUsageLog, ServerError, type Signal, type SignalDelivery, type SignalStatus, type SignalType, type ThresholdKind, type TieredUnitInput, type Tokens, type TrackResult, type Unit, type UnitAdjustInput, type UnitBalance, type UnitComponentInput, type UnitCustomerRow, type UnitDetail, type UnitInput, type UnitPricingType, type UnitTier, type UnitTierInput, type UnitTrackResult, type UnitUsageList, type UnitUsageRow, type UpdateCreditInput, type UpdateMemberInput, type UpdateOutcomeInput, type UpdatePlanInput, type UpdateUnitInput, type UpsertWebhookInput, type UsageBalance, type UsageList, ValidationError, type WalletComponentInput, type WalletEntitlementKind, type WalletEntryInput, type WalletInput, type WalletList, type WalletSignal, type WalletTransaction, type WalletTransactionSource, type WalletTransactionType, type Webhook, type WorkspaceIdentity, signalToWire };
|
package/dist/index.d.ts
CHANGED
|
@@ -123,7 +123,14 @@ interface WalletSignal extends SignalBase {
|
|
|
123
123
|
/**
|
|
124
124
|
* Records one step of a multi-call outcome run. The `agentKey` identifies the
|
|
125
125
|
* step (and the outcome); `runId` groups every signal of a single run, so a step
|
|
126
|
-
* may repeat freely. The run bills once, when the caller
|
|
126
|
+
* may repeat freely. The run bills once, when the caller closes it with
|
|
127
|
+
* `signals.completeOutcome()` — a SEPARATE, dedicated call, never a flag on a
|
|
128
|
+
* step signal.
|
|
129
|
+
*
|
|
130
|
+
* There is no `complete` field here. `POST /api/v1/signal/outcome` (what this
|
|
131
|
+
* type posts to) now accepts ONLY the step shape and rejects a body that also
|
|
132
|
+
* carries `complete` — see {@link OutcomeCompletionInput} /
|
|
133
|
+
* `signals.completeOutcome()`, its own dedicated route.
|
|
127
134
|
*/
|
|
128
135
|
interface OutcomeSignal extends SignalBase {
|
|
129
136
|
type: "outcome";
|
|
@@ -135,17 +142,6 @@ interface OutcomeSignal extends SignalBase {
|
|
|
135
142
|
* outcome). Opaque to ClockNext — any string you can correlate; unique per org.
|
|
136
143
|
*/
|
|
137
144
|
runId: string;
|
|
138
|
-
/**
|
|
139
|
-
* Set `true` on the LAST step signal to declare the run finished — completion
|
|
140
|
-
* is never inferred from step coverage. Sending it twice is a safe no-op and
|
|
141
|
-
* can't bill again.
|
|
142
|
-
*
|
|
143
|
-
* This closes the RUN only. If the signal also carries a `composite`, that
|
|
144
|
-
* occurrence stays open and unbilled until you call
|
|
145
|
-
* `signals.completeComposite()` — the two completions are separate, and
|
|
146
|
-
* neither implies the other.
|
|
147
|
-
*/
|
|
148
|
-
complete?: boolean;
|
|
149
145
|
/** Optional composite this signal belongs to. See {@link CompositeTag}. */
|
|
150
146
|
composite?: CompositeTag;
|
|
151
147
|
}
|
|
@@ -154,6 +150,56 @@ type Signal = CreditSignal | WalletSignal | OutcomeSignal;
|
|
|
154
150
|
type CreditInput = Omit<CreditSignal, "type">;
|
|
155
151
|
type WalletInput = Omit<WalletSignal, "type">;
|
|
156
152
|
type OutcomeInput = Omit<OutcomeSignal, "type">;
|
|
153
|
+
/**
|
|
154
|
+
* Input for `signals.completeOutcome()` — closes ONE outcome run, the outcome
|
|
155
|
+
* mirror of {@link CompositeCompletionInput}. No `agentKey`, no `usage`: this
|
|
156
|
+
* closes an EXISTING run that an earlier `signals.outcome()` step already
|
|
157
|
+
* opened, so there is no step behind this call and nothing here to price.
|
|
158
|
+
*
|
|
159
|
+
* This closes the RUN only. If a step of this run also carried a `composite`,
|
|
160
|
+
* that occurrence stays open and unbilled until you separately call
|
|
161
|
+
* `signals.completeComposite()` — the two completions are independent, and
|
|
162
|
+
* neither implies the other.
|
|
163
|
+
*/
|
|
164
|
+
interface OutcomeCompletionInput {
|
|
165
|
+
customerId: string;
|
|
166
|
+
/** The same `runId` the run's step signals were sent with. */
|
|
167
|
+
runId: string;
|
|
168
|
+
/** Optional member (email) this completion is attributed to. */
|
|
169
|
+
member?: string;
|
|
170
|
+
/** Idempotency key, auto-generated if omitted. Sending `complete` twice for
|
|
171
|
+
* the same run is already a safe no-op server-side, so this only collapses
|
|
172
|
+
* a retry into one attempt rather than protecting against a double bill. */
|
|
173
|
+
idempotencyKey?: string;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* The result of `signals.completeOutcome()`.
|
|
177
|
+
*
|
|
178
|
+
* Unlike {@link CompositeCompletionResult}, `ALREADY_COMPLETED` is NOT what a
|
|
179
|
+
* normal second ping for the same run gets back — that is rejected outright
|
|
180
|
+
* (a permanent error: the run has already been billed, and completing it again
|
|
181
|
+
* would bill it twice). `ALREADY_COMPLETED` is reserved for the much rarer case
|
|
182
|
+
* of two concurrent deliveries of the exact same request (e.g. a client-side
|
|
183
|
+
* retry racing the original), which really is a harmless echo.
|
|
184
|
+
*/
|
|
185
|
+
interface OutcomeCompletionResult {
|
|
186
|
+
/** How far the ping got. Never `"buffered"` — completions are always sent
|
|
187
|
+
* immediately. See {@link TrackResult.status}. */
|
|
188
|
+
delivery: Extract<SignalDelivery, "accepted" | "recorded">;
|
|
189
|
+
/** True when the ping was accepted but not yet applied (`202`). Prefer
|
|
190
|
+
* {@link OutcomeCompletionResult.delivery}. */
|
|
191
|
+
queued: boolean;
|
|
192
|
+
/** `COMPLETED` on the first close, `ALREADY_COMPLETED` only on the rare
|
|
193
|
+
* concurrent-replay case described above. Absent when the ping was queued. */
|
|
194
|
+
status?: "COMPLETED" | "ALREADY_COMPLETED";
|
|
195
|
+
/** The priced usage log, when the server closed the run inline. `null` on a
|
|
196
|
+
* `202` hand-off. */
|
|
197
|
+
usageLog?: SerializedUsageLog | null;
|
|
198
|
+
/** The durable inbox id — see {@link TrackResult.rawId}. */
|
|
199
|
+
rawId?: string;
|
|
200
|
+
/** The queue message id, present only on a `202` hand-off. */
|
|
201
|
+
messageId?: string;
|
|
202
|
+
}
|
|
157
203
|
interface SerializedRuleApplication {
|
|
158
204
|
ruleId: string | null;
|
|
159
205
|
ruleName: string;
|
|
@@ -902,17 +948,21 @@ interface WalletEntryInput {
|
|
|
902
948
|
notes?: string;
|
|
903
949
|
}
|
|
904
950
|
/** Grant (positive) or claw back (negative) a credit balance. `delta` must be a
|
|
905
|
-
* non-zero whole number. The credit is addressed by its stable `agentKey`.
|
|
951
|
+
* non-zero whole number. The credit is addressed by its stable `agentKey`. A
|
|
952
|
+
* reduce is never rejected or floored for going below 0 — the resulting
|
|
953
|
+
* balance may read negative, same as a real-usage overdraft already can. */
|
|
906
954
|
interface CreditAdjustInput {
|
|
907
955
|
/** The credit's stable agent key (the same key used to record usage). */
|
|
908
956
|
agentKey: string;
|
|
909
957
|
delta: number;
|
|
910
958
|
notes?: string;
|
|
911
959
|
}
|
|
912
|
-
/** Grant/claw an outcome balance. `delta` is a non-zero whole number
|
|
913
|
-
*
|
|
960
|
+
/** Grant/claw an outcome balance. `delta` is a non-zero whole number. The
|
|
961
|
+
* outcome is addressed here by a STEP's `agentKey`, which resolves to its
|
|
914
962
|
* parent outcome — NOT by the outcome's own `agentKey` ({@link Outcome.agentKey}),
|
|
915
|
-
* which this endpoint does not accept.
|
|
963
|
+
* which this endpoint does not accept. A reduce is never rejected or floored
|
|
964
|
+
* for going below 0 — the resulting balance may read negative, same as a
|
|
965
|
+
* real-usage overdraft already can. */
|
|
916
966
|
interface OutcomeAdjustInput {
|
|
917
967
|
/** An outcome STEP's stable agent key — identifies the parent outcome. Passing
|
|
918
968
|
* the outcome's own `agentKey` here fails with `422`. */
|
|
@@ -920,14 +970,35 @@ interface OutcomeAdjustInput {
|
|
|
920
970
|
delta: number;
|
|
921
971
|
notes?: string;
|
|
922
972
|
}
|
|
923
|
-
/** Grant/claw a unit balance. `delta` is non-zero (fractional allowed)
|
|
924
|
-
*
|
|
973
|
+
/** Grant/claw a unit balance. `delta` is non-zero (fractional allowed). The
|
|
974
|
+
* unit is addressed by its stable `agentKey`. A reduce is never rejected or
|
|
975
|
+
* floored for going below 0 — the resulting balance may read negative, same
|
|
976
|
+
* as a real-usage overdraft already can. */
|
|
925
977
|
interface UnitAdjustInput {
|
|
926
978
|
/** The unit's stable agent key (the same key used to record usage). */
|
|
927
979
|
agentKey: string;
|
|
928
980
|
delta: number;
|
|
929
981
|
notes?: string;
|
|
930
982
|
}
|
|
983
|
+
/**
|
|
984
|
+
* Grant (positive) or claw back (negative) slots on a customer's ADVANCE
|
|
985
|
+
* composite (pricing metric) pool for the CURRENT billing cycle. `delta` is a
|
|
986
|
+
* non-zero whole number. A reduce is never rejected or floored for going below
|
|
987
|
+
* 0 — same as credit/outcome/unit adjustments; the resulting pool may read
|
|
988
|
+
* negative. Fails if the customer has no active ADVANCE purchase component
|
|
989
|
+
* selling this composite.
|
|
990
|
+
*/
|
|
991
|
+
interface CompositeAdjustInput {
|
|
992
|
+
/**
|
|
993
|
+
* The composite's stable identifier — its `refId` (see {@link Composite.refId}),
|
|
994
|
+
* the same value signals tag it with, NOT `agentKey` (a composite has no
|
|
995
|
+
* `agentKey` column of its own). Named `agentKey` on the wire only so the
|
|
996
|
+
* four adjust endpoints share one request shape.
|
|
997
|
+
*/
|
|
998
|
+
agentKey: string;
|
|
999
|
+
delta: number;
|
|
1000
|
+
notes?: string;
|
|
1001
|
+
}
|
|
931
1002
|
/** A per-model token bundle attached to a credit or outcome step. */
|
|
932
1003
|
interface ModelBundleEntry {
|
|
933
1004
|
orgModelId: string;
|
|
@@ -1660,8 +1731,11 @@ declare class Customers {
|
|
|
1660
1731
|
transaction: WalletTransaction;
|
|
1661
1732
|
balanceUsd: number;
|
|
1662
1733
|
}>;
|
|
1663
|
-
/** Grant or claw back a credit balance.
|
|
1664
|
-
|
|
1734
|
+
/** Grant or claw back a credit balance. Returns the remaining balance.
|
|
1735
|
+
* `POST …/:id/credits/adjust`. */
|
|
1736
|
+
adjustCredit(id: string, input: CreditAdjustInput): Promise<{
|
|
1737
|
+
remaining: number;
|
|
1738
|
+
}>;
|
|
1665
1739
|
/** Grant or claw back an outcome balance. Returns the remaining balance. */
|
|
1666
1740
|
adjustOutcome(id: string, input: OutcomeAdjustInput): Promise<{
|
|
1667
1741
|
remaining: number;
|
|
@@ -1670,6 +1744,14 @@ declare class Customers {
|
|
|
1670
1744
|
adjustUnit(id: string, input: UnitAdjustInput): Promise<{
|
|
1671
1745
|
remaining: number;
|
|
1672
1746
|
}>;
|
|
1747
|
+
/**
|
|
1748
|
+
* Grant or claw back slots on a customer's ADVANCE composite pool for the
|
|
1749
|
+
* current billing cycle. Returns the resulting `remaining` slot count.
|
|
1750
|
+
* `POST …/:id/composites/adjust`.
|
|
1751
|
+
*/
|
|
1752
|
+
adjustComposite(id: string, input: CompositeAdjustInput): Promise<{
|
|
1753
|
+
remaining: number;
|
|
1754
|
+
}>;
|
|
1673
1755
|
}
|
|
1674
1756
|
|
|
1675
1757
|
/**
|
|
@@ -1956,6 +2038,25 @@ declare class Signals {
|
|
|
1956
2038
|
outcome(input: OutcomeInput, opts?: {
|
|
1957
2039
|
wait?: boolean;
|
|
1958
2040
|
}): Promise<TrackResult>;
|
|
2041
|
+
/**
|
|
2042
|
+
* Close ONE outcome run — declares the workflow finished and bills it. The
|
|
2043
|
+
* outcome mirror of {@link Signals.completeComposite}, on its own dedicated
|
|
2044
|
+
* route: `POST /api/v1/signal/outcome/complete`.
|
|
2045
|
+
*
|
|
2046
|
+
* An outcome bills per COMPLETION, never per step, and `signals.outcome()`
|
|
2047
|
+
* never closes one — it accepts only the step shape. Declaring the workflow
|
|
2048
|
+
* finished is always this separate, explicit, contentless call.
|
|
2049
|
+
*
|
|
2050
|
+
* This closes the RUN only. If a step of this run also carried a
|
|
2051
|
+
* `composite`, that occurrence stays open and unbilled until you separately
|
|
2052
|
+
* call {@link Signals.completeComposite} — the two completions are
|
|
2053
|
+
* independent, and neither implies the other.
|
|
2054
|
+
*
|
|
2055
|
+
* Sent immediately, never buffered. A genuinely second, independent call for
|
|
2056
|
+
* an already-closed run is a PERMANENT error (it would bill the run twice),
|
|
2057
|
+
* not a safe no-op — see {@link OutcomeCompletionResult}.
|
|
2058
|
+
*/
|
|
2059
|
+
completeOutcome(input: OutcomeCompletionInput): Promise<OutcomeCompletionResult>;
|
|
1959
2060
|
/**
|
|
1960
2061
|
* Recent usage logs + totals for a customer. `GET /api/v1/usage`.
|
|
1961
2062
|
*
|
|
@@ -1993,13 +2094,13 @@ declare class Signals {
|
|
|
1993
2094
|
* arrive in any order and the occurrence stays open and unbilled until you
|
|
1994
2095
|
* say otherwise. Put it on the line before your own `return`.
|
|
1995
2096
|
*
|
|
1996
|
-
* EVERY composite needs this, outcome-backed ones included.
|
|
1997
|
-
*
|
|
1998
|
-
*
|
|
1999
|
-
*
|
|
2000
|
-
*
|
|
2001
|
-
*
|
|
2002
|
-
*
|
|
2097
|
+
* EVERY composite needs this, outcome-backed ones included. `completeOutcome()`
|
|
2098
|
+
* closes its RUN and nothing else — it does not close the composite
|
|
2099
|
+
* occurrence the run was tagged into, whatever mix of credits, outcomes and
|
|
2100
|
+
* units that composite wraps. (Earlier versions of this SDK documented the
|
|
2101
|
+
* opposite. Believing it means the occurrence stays ONGOING forever and is
|
|
2102
|
+
* never billed, so if you tag outcome signals with a `composite`, you must
|
|
2103
|
+
* still call this.)
|
|
2003
2104
|
*
|
|
2004
2105
|
* Closing twice is safe: the second call answers `ALREADY_COMPLETED` and
|
|
2005
2106
|
* cannot bill again. Calling it EARLY is also safe — before every entitlement
|
|
@@ -2211,4 +2312,4 @@ declare class NetworkError extends ClockNextError {
|
|
|
2211
2312
|
});
|
|
2212
2313
|
}
|
|
2213
2314
|
|
|
2214
|
-
export { type AddMemberInput, AllowanceError, type ApiCustomer, AuthError, type BillingCycle, type BillingMode, ClockNext, type ClockNextConfig, ClockNextError, type ClockNextErrorCode, type ComponentType, type Composite, type CompositeCatalogueRef, type CompositeCompletionInput, type CompositeCompletionResult, type CompositeComponentInput, type CompositeTag, ConflictError, type CostPoint, type CostStats, type CreateCompositeInput, type CreateCreditInput, type CreateCustomerInput, type CreateOutcomeInput, type CreatePlanInput, type CreatePurchaseInput, type CreateUnitInput, type Credit, type CreditAdjustInput, type CreditAnalytics, type CreditBalance, type CreditComponentInput, type CreditDetail, type CreditInput, type CreditSignal, type CustomerBalances, type CustomerList, type CustomerPlan, type CustomerPlanDetails, type CustomerProfileInput, type DropReason, type FetchLike, type FlatComponentInput, type FlatUnitInput, ForbiddenError, type Invoice, type InvoiceDetail, type InvoiceLineItem, type InvoiceListRow, type InvoiceParty, type InvoicePlanSnapshot, type InvoiceStatus, type Logger, type Member, type MemberProfile, type Model, type ModelBundleEntry, NetworkError, NotFoundError, type Outcome, type OutcomeAdjustInput, type OutcomeAnalytics, type OutcomeBalance, type OutcomeComponentInput, type OutcomeDetail, type OutcomeInput, type OutcomeSignal, type OutcomeStepInput, type PayLink, type PaymentDetail, type PaymentRow, type Plan, type PlanComponent, type PlanComponentInput, type PlanDetail, PlanError, type PlanKind, type PlanRef, type PlanType, type PortalToken, type PortalTokenInput, type Purchase, type PurchaseDetail, type PurchaseStatus, RateLimitError, type RemovedMember, type SerializedOutcomeAttribution, type SerializedRuleApplication, type SerializedUnitUsage, type SerializedUsageLog, ServerError, type Signal, type SignalDelivery, type SignalStatus, type SignalType, type ThresholdKind, type TieredUnitInput, type Tokens, type TrackResult, type Unit, type UnitAdjustInput, type UnitBalance, type UnitComponentInput, type UnitCustomerRow, type UnitDetail, type UnitInput, type UnitPricingType, type UnitTier, type UnitTierInput, type UnitTrackResult, type UnitUsageList, type UnitUsageRow, type UpdateCreditInput, type UpdateMemberInput, type UpdateOutcomeInput, type UpdatePlanInput, type UpdateUnitInput, type UpsertWebhookInput, type UsageBalance, type UsageList, ValidationError, type WalletComponentInput, type WalletEntitlementKind, type WalletEntryInput, type WalletInput, type WalletList, type WalletSignal, type WalletTransaction, type WalletTransactionSource, type WalletTransactionType, type Webhook, type WorkspaceIdentity, signalToWire };
|
|
2315
|
+
export { type AddMemberInput, AllowanceError, type ApiCustomer, AuthError, type BillingCycle, type BillingMode, ClockNext, type ClockNextConfig, ClockNextError, type ClockNextErrorCode, type ComponentType, type Composite, type CompositeAdjustInput, type CompositeCatalogueRef, type CompositeCompletionInput, type CompositeCompletionResult, type CompositeComponentInput, type CompositeTag, ConflictError, type CostPoint, type CostStats, type CreateCompositeInput, type CreateCreditInput, type CreateCustomerInput, type CreateOutcomeInput, type CreatePlanInput, type CreatePurchaseInput, type CreateUnitInput, type Credit, type CreditAdjustInput, type CreditAnalytics, type CreditBalance, type CreditComponentInput, type CreditDetail, type CreditInput, type CreditSignal, type CustomerBalances, type CustomerList, type CustomerPlan, type CustomerPlanDetails, type CustomerProfileInput, type DropReason, type FetchLike, type FlatComponentInput, type FlatUnitInput, ForbiddenError, type Invoice, type InvoiceDetail, type InvoiceLineItem, type InvoiceListRow, type InvoiceParty, type InvoicePlanSnapshot, type InvoiceStatus, type Logger, type Member, type MemberProfile, type Model, type ModelBundleEntry, NetworkError, NotFoundError, type Outcome, type OutcomeAdjustInput, type OutcomeAnalytics, type OutcomeBalance, type OutcomeCompletionInput, type OutcomeCompletionResult, type OutcomeComponentInput, type OutcomeDetail, type OutcomeInput, type OutcomeSignal, type OutcomeStepInput, type PayLink, type PaymentDetail, type PaymentRow, type Plan, type PlanComponent, type PlanComponentInput, type PlanDetail, PlanError, type PlanKind, type PlanRef, type PlanType, type PortalToken, type PortalTokenInput, type Purchase, type PurchaseDetail, type PurchaseStatus, RateLimitError, type RemovedMember, type SerializedOutcomeAttribution, type SerializedRuleApplication, type SerializedUnitUsage, type SerializedUsageLog, ServerError, type Signal, type SignalDelivery, type SignalStatus, type SignalType, type ThresholdKind, type TieredUnitInput, type Tokens, type TrackResult, type Unit, type UnitAdjustInput, type UnitBalance, type UnitComponentInput, type UnitCustomerRow, type UnitDetail, type UnitInput, type UnitPricingType, type UnitTier, type UnitTierInput, type UnitTrackResult, type UnitUsageList, type UnitUsageRow, type UpdateCreditInput, type UpdateMemberInput, type UpdateOutcomeInput, type UpdatePlanInput, type UpdateUnitInput, type UpsertWebhookInput, type UsageBalance, type UsageList, ValidationError, type WalletComponentInput, type WalletEntitlementKind, type WalletEntryInput, type WalletInput, type WalletList, type WalletSignal, type WalletTransaction, type WalletTransactionSource, type WalletTransactionType, type Webhook, type WorkspaceIdentity, signalToWire };
|
package/dist/index.js
CHANGED
|
@@ -326,7 +326,7 @@ function sleep(ms) {
|
|
|
326
326
|
}
|
|
327
327
|
|
|
328
328
|
// src/http.ts
|
|
329
|
-
var SDK_VERSION = "0.
|
|
329
|
+
var SDK_VERSION = "0.13.0" ;
|
|
330
330
|
var Transport = class {
|
|
331
331
|
constructor(cfg) {
|
|
332
332
|
this.cfg = cfg;
|
|
@@ -702,13 +702,15 @@ var Customers = class {
|
|
|
702
702
|
// (PATCH …/:id) — there is no separate currency endpoint. Credit-type
|
|
703
703
|
// assignment has no public API.
|
|
704
704
|
// --- Balance adjustments -------------------------------------------------
|
|
705
|
-
/** Grant or claw back a credit balance.
|
|
705
|
+
/** Grant or claw back a credit balance. Returns the remaining balance.
|
|
706
|
+
* `POST …/:id/credits/adjust`. */
|
|
706
707
|
async adjustCredit(id, input) {
|
|
707
|
-
await this.transport.request({
|
|
708
|
+
const res = await this.transport.request({
|
|
708
709
|
method: "POST",
|
|
709
710
|
path: `/api/v1/customers/${encodeURIComponent(id)}/credits/adjust`,
|
|
710
711
|
body: input
|
|
711
712
|
});
|
|
713
|
+
return { remaining: res.remaining };
|
|
712
714
|
}
|
|
713
715
|
/** Grant or claw back an outcome balance. Returns the remaining balance. */
|
|
714
716
|
async adjustOutcome(id, input) {
|
|
@@ -728,6 +730,19 @@ var Customers = class {
|
|
|
728
730
|
});
|
|
729
731
|
return { remaining: res.remaining };
|
|
730
732
|
}
|
|
733
|
+
/**
|
|
734
|
+
* Grant or claw back slots on a customer's ADVANCE composite pool for the
|
|
735
|
+
* current billing cycle. Returns the resulting `remaining` slot count.
|
|
736
|
+
* `POST …/:id/composites/adjust`.
|
|
737
|
+
*/
|
|
738
|
+
async adjustComposite(id, input) {
|
|
739
|
+
const res = await this.transport.request({
|
|
740
|
+
method: "POST",
|
|
741
|
+
path: `/api/v1/customers/${encodeURIComponent(id)}/composites/adjust`,
|
|
742
|
+
body: input
|
|
743
|
+
});
|
|
744
|
+
return { remaining: res.remaining };
|
|
745
|
+
}
|
|
731
746
|
};
|
|
732
747
|
|
|
733
748
|
// src/resources/invoices.ts
|
|
@@ -1013,6 +1028,7 @@ var SIGNAL_PATHS = {
|
|
|
1013
1028
|
};
|
|
1014
1029
|
var UNIT_PATH = "/api/v1/signal/unit";
|
|
1015
1030
|
var COMPOSITE_COMPLETE_PATH = "/api/v1/signal/composite/complete";
|
|
1031
|
+
var OUTCOME_COMPLETE_PATH = "/api/v1/signal/outcome/complete";
|
|
1016
1032
|
function signalToWire(signal) {
|
|
1017
1033
|
const t = signal.tokens;
|
|
1018
1034
|
const body = {
|
|
@@ -1033,7 +1049,6 @@ function signalToWire(signal) {
|
|
|
1033
1049
|
}
|
|
1034
1050
|
if (signal.type === "outcome") {
|
|
1035
1051
|
body.runId = signal.runId;
|
|
1036
|
-
if (signal.complete != null) body.complete = signal.complete;
|
|
1037
1052
|
}
|
|
1038
1053
|
if (signal.type !== "wallet" && signal.composite) {
|
|
1039
1054
|
body.composite = { [signal.composite.ref]: signal.composite.value };
|
|
@@ -1103,6 +1118,48 @@ var Signals = class {
|
|
|
1103
1118
|
outcome(input, opts) {
|
|
1104
1119
|
return this.track({ ...input, type: "outcome" }, opts);
|
|
1105
1120
|
}
|
|
1121
|
+
/**
|
|
1122
|
+
* Close ONE outcome run — declares the workflow finished and bills it. The
|
|
1123
|
+
* outcome mirror of {@link Signals.completeComposite}, on its own dedicated
|
|
1124
|
+
* route: `POST /api/v1/signal/outcome/complete`.
|
|
1125
|
+
*
|
|
1126
|
+
* An outcome bills per COMPLETION, never per step, and `signals.outcome()`
|
|
1127
|
+
* never closes one — it accepts only the step shape. Declaring the workflow
|
|
1128
|
+
* finished is always this separate, explicit, contentless call.
|
|
1129
|
+
*
|
|
1130
|
+
* This closes the RUN only. If a step of this run also carried a
|
|
1131
|
+
* `composite`, that occurrence stays open and unbilled until you separately
|
|
1132
|
+
* call {@link Signals.completeComposite} — the two completions are
|
|
1133
|
+
* independent, and neither implies the other.
|
|
1134
|
+
*
|
|
1135
|
+
* Sent immediately, never buffered. A genuinely second, independent call for
|
|
1136
|
+
* an already-closed run is a PERMANENT error (it would bill the run twice),
|
|
1137
|
+
* not a safe no-op — see {@link OutcomeCompletionResult}.
|
|
1138
|
+
*/
|
|
1139
|
+
async completeOutcome(input) {
|
|
1140
|
+
const idempotencyKey = input.idempotencyKey ?? newKey();
|
|
1141
|
+
const res = await this.transport.request({
|
|
1142
|
+
method: "POST",
|
|
1143
|
+
path: OUTCOME_COMPLETE_PATH,
|
|
1144
|
+
idempotencyKey,
|
|
1145
|
+
body: {
|
|
1146
|
+
customerId: input.customerId,
|
|
1147
|
+
runId: input.runId,
|
|
1148
|
+
complete: true,
|
|
1149
|
+
...input.member ? { member: input.member } : {},
|
|
1150
|
+
idempotencyKey
|
|
1151
|
+
},
|
|
1152
|
+
retry: true
|
|
1153
|
+
});
|
|
1154
|
+
const queued = res.queued === true;
|
|
1155
|
+
return {
|
|
1156
|
+
delivery: queued ? "accepted" : "recorded",
|
|
1157
|
+
queued,
|
|
1158
|
+
...res.status != null ? { status: res.status } : {},
|
|
1159
|
+
usageLog: res.usageLog ?? null,
|
|
1160
|
+
...handles(res)
|
|
1161
|
+
};
|
|
1162
|
+
}
|
|
1106
1163
|
/**
|
|
1107
1164
|
* Recent usage logs + totals for a customer. `GET /api/v1/usage`.
|
|
1108
1165
|
*
|
|
@@ -1175,13 +1232,13 @@ var Signals = class {
|
|
|
1175
1232
|
* arrive in any order and the occurrence stays open and unbilled until you
|
|
1176
1233
|
* say otherwise. Put it on the line before your own `return`.
|
|
1177
1234
|
*
|
|
1178
|
-
* EVERY composite needs this, outcome-backed ones included.
|
|
1179
|
-
*
|
|
1180
|
-
*
|
|
1181
|
-
*
|
|
1182
|
-
*
|
|
1183
|
-
*
|
|
1184
|
-
*
|
|
1235
|
+
* EVERY composite needs this, outcome-backed ones included. `completeOutcome()`
|
|
1236
|
+
* closes its RUN and nothing else — it does not close the composite
|
|
1237
|
+
* occurrence the run was tagged into, whatever mix of credits, outcomes and
|
|
1238
|
+
* units that composite wraps. (Earlier versions of this SDK documented the
|
|
1239
|
+
* opposite. Believing it means the occurrence stays ONGOING forever and is
|
|
1240
|
+
* never billed, so if you tag outcome signals with a `composite`, you must
|
|
1241
|
+
* still call this.)
|
|
1185
1242
|
*
|
|
1186
1243
|
* Closing twice is safe: the second call answers `ALREADY_COMPLETED` and
|
|
1187
1244
|
* cannot bill again. Calling it EARLY is also safe — before every entitlement
|