@clocknext/sdk 0.18.0 → 0.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -164,6 +164,8 @@ type OutcomeCompletionInput = CustomerRef & {
164
164
  runId: string;
165
165
  /** Optional member (email) this completion is attributed to. */
166
166
  member?: string;
167
+ /** Free-form metadata, stored as-is with this completion. Never priced. */
168
+ custom?: Record<string, unknown>;
167
169
  /** Idempotency key, auto-generated if omitted. Sending this completion twice
168
170
  * for the same run is already a safe no-op server-side, so this only
169
171
  * collapses a retry into one attempt rather than protecting against a
@@ -385,8 +387,9 @@ interface UsageLogOutcomeAttribution {
385
387
  interface UsageLogEntry {
386
388
  id: string;
387
389
  createdAt: string;
388
- /** Which meter this row is. */
389
- type: "credit" | "outcome" | "unit" | "wallet" | "composite";
390
+ /** Which meter this row is. `"outcome"` is one step of a run;
391
+ * `"outcome_completion"` is the finished run itself (one per run). */
392
+ type: "credit" | "outcome" | "outcome_completion" | "unit" | "wallet" | "composite";
390
393
  status: SignalStatus;
391
394
  typeName: string | null;
392
395
  member: string | null;
@@ -424,8 +427,22 @@ interface UsageLogEntry {
424
427
  composite: {
425
428
  amount: string;
426
429
  } | null;
427
- /** The `custom` object sent on the signal, as sent. `null` when none was
428
- * sent, and always `null` for unit and composite rows. */
430
+ /** Populated only when `type === "outcome_completion"`. `amount` is the
431
+ * price frozen when the run completed (your plan price, else the catalogue
432
+ * price). */
433
+ outcomeCompletion: {
434
+ runId: string | null;
435
+ amount: string;
436
+ runSignals: number;
437
+ } | null;
438
+ /** The composite that covers this row's billing, by name — the row's price
439
+ * is then included in that composite's own charge, not billed on top. Set
440
+ * on credit / outcome / unit / outcome_completion rows tagged into a
441
+ * composite on the customer's plan; `null` otherwise. */
442
+ coveredByComposite: string | null;
443
+ /** The `custom` object sent, as sent — on the signal itself, or on the
444
+ * `completeComposite()` / `completeOutcome()` call that closed a composite /
445
+ * outcome_completion row. `null` when none was sent. */
429
446
  custom: Record<string, unknown> | null;
430
447
  }
431
448
  interface UsageLogPage {
@@ -434,6 +451,104 @@ interface UsageLogPage {
434
451
  * page. */
435
452
  nextCursor: string | null;
436
453
  }
454
+ /** What a {@link UsageLogLookupEntry} row is. `"outcome"` is one step of a
455
+ * run; `"outcome_completion"` and `"composite_completion"` are the finished
456
+ * runs themselves. */
457
+ type UsageLogLookupEntitlementType = "credit" | "outcome" | "outcome_completion" | "unit" | "composite_completion" | "wallet";
458
+ /**
459
+ * One row of `signals.lookupUsageLogs()`. Only the group that matches
460
+ * `entitlement.type` holds data; the others are `null`.
461
+ */
462
+ interface UsageLogLookupEntry {
463
+ id: string;
464
+ /** The customer this row belongs to — a lookup can span customers. */
465
+ customerId: string;
466
+ /** For a finished run (`outcome_completion`, `composite_completion`), when
467
+ * it completed. */
468
+ createdAt: string;
469
+ status: SignalStatus;
470
+ /** The credit / outcome / unit / composite this row is for. A wallet row has
471
+ * `id: null` and `name: "Wallet"`. */
472
+ entitlement: {
473
+ type: UsageLogLookupEntitlementType;
474
+ id: string | null;
475
+ name: string | null;
476
+ };
477
+ member: string | null;
478
+ model: {
479
+ name: string | null;
480
+ provider: string | null;
481
+ } | null;
482
+ usage: {
483
+ inputTokens: number;
484
+ outputTokens: number;
485
+ /** Cache-read tokens. */
486
+ cacheTokens: number;
487
+ /** Cache-write tokens, priced separately from cache reads. */
488
+ cacheWriteTokens: number;
489
+ };
490
+ /** Formatted USD strings. `customerCost` is what this row charged:
491
+ * `"$0.00"` on an outcome step (the run is billed at completion) and on any
492
+ * row a composite pays for. On a unit row it is what the wallet paid for
493
+ * that report (debits minus refunds), `"$0.00"` when the wallet paid
494
+ * nothing. */
495
+ cost: {
496
+ providedCost: string;
497
+ customerCost: string;
498
+ };
499
+ /** `entitlement.type === "credit"`. */
500
+ credit: {
501
+ amount: string;
502
+ appliedRules: UsageLogAppliedRule[];
503
+ } | null;
504
+ /** `entitlement.type === "outcome"`. `runCompleted` is true once the run is
505
+ * finished — on every step row of that run. */
506
+ outcome: {
507
+ step: string | null;
508
+ stepName: string | null;
509
+ runId: string | null;
510
+ runCompleted: boolean;
511
+ } | null;
512
+ /** `entitlement.type === "outcome_completion"`. `amount` is the price frozen
513
+ * when the run completed. */
514
+ outcomeCompletion: {
515
+ runId: string | null;
516
+ amount: string;
517
+ } | null;
518
+ /** `entitlement.type === "unit"`. `quantity` is formatted. */
519
+ unit: {
520
+ quantity: string;
521
+ } | null;
522
+ /** `entitlement.type === "composite_completion"`. `refId` is the
523
+ * composite's tag key, `runId` the tag value you sent. */
524
+ compositeCompletion: {
525
+ refId: string | null;
526
+ runId: string | null;
527
+ amount: string;
528
+ startedAt: string;
529
+ } | null;
530
+ /** `entitlement.type === "wallet"`. What the wallet paid, formatted USD —
531
+ * the same value as `cost.customerCost`. */
532
+ wallet: {
533
+ amount: string;
534
+ } | null;
535
+ /** The composite that pays for this row — its id, its tag key (`refId`) and
536
+ * the tag value you sent (`runId`). `null` when the row is billed by
537
+ * itself. */
538
+ composite: {
539
+ id: string | null;
540
+ refId: string | null;
541
+ runId: string | null;
542
+ } | null;
543
+ /** The `custom` object sent, as sent. `null` when none was sent. */
544
+ custom: Record<string, unknown> | null;
545
+ }
546
+ interface UsageLogLookupResult {
547
+ /** The rows found, in the order of the ids you asked for. */
548
+ usageLogs: UsageLogLookupEntry[];
549
+ /** The ids that matched nothing in your org, in the order you asked. */
550
+ notFound: string[];
551
+ }
437
552
  interface ApiCustomer {
438
553
  id: string;
439
554
  /** Your own id for this customer, or `null` when unset. See
@@ -454,8 +569,6 @@ interface ApiCustomer {
454
569
  taxId: string | null;
455
570
  currencyCode: string;
456
571
  creditAllowance: number;
457
- recurringTransactionEmail: boolean;
458
- autoRecurring: boolean;
459
572
  createdAt: string;
460
573
  updatedAt: string;
461
574
  }
@@ -485,10 +598,6 @@ interface CustomerProfileInput {
485
598
  taxId?: string | null;
486
599
  /** ISO 4217 (3 letters); must be enabled for the org. */
487
600
  currencyCode?: string;
488
- /** Send the invoice, payment receipt and card-payment-failed emails for recurring invoices. Defaults to `true` on create. */
489
- recurringTransactionEmail?: boolean;
490
- /** Issue every recurring invoice as `AUTO_CLOSED` (applied as if paid, never payable). Defaults to `false` on create. */
491
- autoRecurring?: boolean;
492
601
  }
493
602
  /** `name` and `email` are required on create; every other field is optional. */
494
603
  type CreateCustomerInput = CustomerProfileInput & {
@@ -580,6 +689,79 @@ interface CustomerBalances {
580
689
  * isn't listed. */
581
690
  composites: CompositeBalance[];
582
691
  }
692
+ /** What caused a wallet ledger row (`WalletTransaction.source`). */
693
+ type WalletTransactionSource =
694
+ /** Wallet money from a new plan purchase. */
695
+ "SUBSCRIPTION"
696
+ /** Wallet money from a plan renewal, or unused money removed at renewal. */
697
+ | "RENEWAL"
698
+ /** Changed in the ClockNext dashboard. */
699
+ | "MANUAL"
700
+ /** Changed with `customers.adjustWallet()`. */
701
+ | "API"
702
+ /** Top-up paid by the customer in the customer portal. */
703
+ | "CUSTOMER_PORTAL"
704
+ /** Charged by a signal; `usageLogId` links the signal. */
705
+ | "USAGE_LOG"
706
+ /** Usage cleared by a paid pay-as-you-go invoice. */
707
+ | "INVOICE_SETTLEMENT"
708
+ /** Settlement undone by a voided invoice. */
709
+ | "INVOICE_VOID";
710
+ /** One row of a customer's wallet ledger (`customers.wallet()`). */
711
+ interface WalletTransaction {
712
+ id: string;
713
+ /** ISO 8601. */
714
+ createdAt: string;
715
+ /** `CREDIT` adds money, `DEBIT` takes it out. */
716
+ type: "CREDIT" | "DEBIT";
717
+ /** Which balance moved: the ordinary wallet or the Reserved Wallet. */
718
+ pool: "main" | "reserved";
719
+ source: WalletTransactionSource;
720
+ /** Always positive — `type` gives the direction. In `currencyCode`. */
721
+ amount: number;
722
+ /** The same amount in USD. */
723
+ amountUsd: number;
724
+ currencyCode: string;
725
+ /** 1 USD = this many units of `currencyCode`, at write time. */
726
+ currencyRateUsd: number;
727
+ /** Only text a person wrote: your own note on an `API` row, the admin's
728
+ * note on a `MANUAL` row. `null` on every row the system writes itself —
729
+ * `source` says what those are. */
730
+ notes: string | null;
731
+ /** On a usage charge for an entitlement: which kind. `null` otherwise. */
732
+ entitlementType: "CREDIT" | "OUTCOME" | "UNIT" | "COMPOSITE" | null;
733
+ /** Id of that credit / outcome / unit / composite. */
734
+ entitlementId: string | null;
735
+ /** Its name when the row was written. */
736
+ entitlementName: string | null;
737
+ /** On a `USAGE_LOG` row: the id of the matching row in
738
+ * `signals.usageLog()`. */
739
+ usageLogId: string | null;
740
+ /** On a `SUBSCRIPTION` / `RENEWAL` grant: the purchase it came from. */
741
+ purchaseId: string | null;
742
+ purchaseNumber: string | null;
743
+ }
744
+ /** One page of a customer's wallet ledger, newest first. */
745
+ interface WalletLedgerPage {
746
+ /** Ordinary wallet balance, USD. May be negative. */
747
+ balanceUsd: number;
748
+ /** Reserved Wallet balance, USD; `null` when the workspace hasn't enabled
749
+ * it. */
750
+ reservedBalanceUsd: number | null;
751
+ transactions: WalletTransaction[];
752
+ /** Pass back as `cursor` for the next page; `null` on the last page. */
753
+ nextCursor: string | null;
754
+ }
755
+ interface WalletLedgerParams {
756
+ /** Default 50, max 200. */
757
+ limit?: number;
758
+ /** A previous page's `nextCursor`. Omit for the first page. */
759
+ cursor?: string;
760
+ /** First day to include, `YYYY-MM-DD` (UTC). The whole day is included. */
761
+ from?: string;
762
+ /** Last day to include, `YYYY-MM-DD` (UTC). The whole day is included. */
763
+ to?: string;
764
+ }
583
765
  /** The customer's active plan (the `plan` field of `customers.plan()`);
584
766
  * `null` when the customer is unsubscribed. */
585
767
  interface CustomerPlanDetails {
@@ -1025,7 +1207,8 @@ interface PurchaseDetail {
1025
1207
  paidCount: number;
1026
1208
  };
1027
1209
  }
1028
- /** `AUTO_CLOSED` — a recurring invoice for a customer with `autoRecurring` on:
1210
+ /** `AUTO_CLOSED` — a recurring invoice of an organisation with "Auto close
1211
+ * invoices on recurring" on (dashboard: Settings → Organisation → Billing):
1029
1212
  * applied as if paid, but never payable. */
1030
1213
  type InvoiceStatus = "OPEN" | "PAID" | "VOID" | "AUTO_CLOSED";
1031
1214
  /** Trimmed row from `invoices.list()`. */
@@ -1398,6 +1581,8 @@ type UnitInput = CustomerRef & {
1398
1581
  quantity?: number;
1399
1582
  /** Optional composite this unit report belongs to. See {@link CompositeTag}. */
1400
1583
  composite?: CompositeTag;
1584
+ /** Free-form metadata, stored as-is with this unit report. Never priced. */
1585
+ custom?: Record<string, unknown>;
1401
1586
  /**
1402
1587
  * Idempotency key for safe retries — a repeat carrying the same key returns
1403
1588
  * the original result instead of drawing the balance down twice.
@@ -1447,6 +1632,9 @@ type CompositeCompletionInput = CustomerRef & {
1447
1632
  /** Which occurrence to close: the composite's `refId` and the correlation
1448
1633
  * value the signals were tagged with. */
1449
1634
  composite: CompositeTag;
1635
+ /** Free-form metadata, stored as-is on the occurrence this call closes.
1636
+ * Never priced. */
1637
+ custom?: Record<string, unknown>;
1450
1638
  /** Idempotency key, auto-generated if omitted. Closing twice is already a
1451
1639
  * safe no-op, so this only collapses retries into one recorded attempt
1452
1640
  * rather than protecting against a double charge. */
@@ -1747,6 +1935,22 @@ declare class Customers {
1747
1935
  delete(id: string): Promise<void>;
1748
1936
  /** Wallet / credit / outcome / unit balances. `GET …/:id/balances`. */
1749
1937
  balances(id: string): Promise<CustomerBalances>;
1938
+ /**
1939
+ * One page of the customer's wallet ledger — every movement of wallet
1940
+ * money, newest first — plus both wallet balances. Cursor-paginated: pass
1941
+ * back `nextCursor` as `cursor`. `GET /api/v1/customers/:id/wallet`.
1942
+ */
1943
+ wallet(id: string, params?: WalletLedgerParams): Promise<WalletLedgerPage>;
1944
+ /** {@link wallet}, addressing the customer by its `externalId`.
1945
+ * `GET /api/v1/customers/ext/:externalId/wallet`. */
1946
+ walletByExternalId(externalId: string, params?: WalletLedgerParams): Promise<WalletLedgerPage>;
1947
+ /**
1948
+ * Async iterator over the customer's WHOLE wallet ledger, newest first,
1949
+ * following the cursor. `params.cursor` is ignored.
1950
+ * `for await (const t of cnk.customers.iterateWallet(id)) { … }`
1951
+ */
1952
+ iterateWallet(id: string, params?: Omit<WalletLedgerParams, "cursor">): AsyncGenerator<WalletTransaction>;
1953
+ private walletPage;
1750
1954
  /** {@link balances}, addressing the customer by its `externalId`.
1751
1955
  * `GET /api/v1/customers/ext/:externalId/balances`. */
1752
1956
  balancesByExternalId(externalId: string): Promise<CustomerBalances>;
@@ -2218,6 +2422,20 @@ declare class Signals {
2218
2422
  * buffer or retry here.
2219
2423
  */
2220
2424
  usageLog(params: UsageLogListParams): Promise<UsageLogPage>;
2425
+ /**
2426
+ * Fetches up to 100 usage-log rows by id, in one call.
2427
+ * `GET /api/v1/signal/usage-log/lookup`.
2428
+ *
2429
+ * Built for linking a wallet debit to its usage: pass the `usageLogId`s
2430
+ * from `customers.wallet()` instead of paging through
2431
+ * {@link usageLog}. Scoped to your org, not to one customer — every row
2432
+ * carries its own `customerId`.
2433
+ *
2434
+ * Rows come back in the order of `ids`; duplicates are removed. Ids that
2435
+ * match nothing in your org are listed in `notFound`. More than 100
2436
+ * distinct ids is a 400.
2437
+ */
2438
+ lookupUsageLogs(ids: string[]): Promise<UsageLogLookupResult>;
2221
2439
  }
2222
2440
 
2223
2441
  /**
@@ -2406,4 +2624,4 @@ declare class NetworkError extends ClockNextError {
2406
2624
  });
2407
2625
  }
2408
2626
 
2409
- export { type AddMemberInput, type AdjustResult, AllowanceError, type ApiCustomer, AuthError, type BillingCycle, type BillingMode, ClockNext, type ClockNextConfig, ClockNextError, type ClockNextErrorCode, type ComponentType, type Composite, type CompositeAdjustInput, type CompositeBalance, type CompositeCompletionInput, type CompositeCompletionResult, type CompositeItem, type CompositeTag, ConflictError, type CreateCompositeInput, type CreateCreditInput, type CreateCustomerInput, type CreateOutcomeInput, type CreatePlanInput, type CreatePurchaseInput, type CreateTaxInput, type CreateUnitInput, type Credit, 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, type ModelBundleLine, type ModelBundleLineInput, NetworkError, NotFoundError, type Outcome, type OutcomeAdjustInput, type OutcomeBalance, type OutcomeCompletionInput, type OutcomeCompletionResult, type OutcomeInput, type OutcomeSignal, type OutcomeStep, type OutcomeStepInput, type OutcomeWithSteps, type PayLink, type PaymentDetail, type PaymentRow, type Plan, type PlanComponent, type PlanEntitlement, type PlanEntitlementInput, 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 Tax, type TaxBehavior, type Tokens, type TrackResult, type Unit, type UnitAdjustInput, type UnitBalance, type UnitInput, type UnitPricingType, type UnitTier, type UnitTrackResult, type UpdateCompositeInput, type UpdateCreditInput, type UpdateMemberInput, type UpdateOutcomeInput, type UpdatePlanInput, type UpdateTaxInput, type UpdateUnitInput, type UsageBalance, type UsageLogAppliedRule, type UsageLogEntry, type UsageLogListParams, type UsageLogOutcomeAttribution, type UsageLogPage, ValidationError, type WalletAdjustInput, type WalletInput, type WalletPool, type WalletSignal, signalToWire };
2627
+ export { type AddMemberInput, type AdjustResult, AllowanceError, type ApiCustomer, AuthError, type BillingCycle, type BillingMode, ClockNext, type ClockNextConfig, ClockNextError, type ClockNextErrorCode, type ComponentType, type Composite, type CompositeAdjustInput, type CompositeBalance, type CompositeCompletionInput, type CompositeCompletionResult, type CompositeItem, type CompositeTag, ConflictError, type CreateCompositeInput, type CreateCreditInput, type CreateCustomerInput, type CreateOutcomeInput, type CreatePlanInput, type CreatePurchaseInput, type CreateTaxInput, type CreateUnitInput, type Credit, 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, type ModelBundleLine, type ModelBundleLineInput, NetworkError, NotFoundError, type Outcome, type OutcomeAdjustInput, type OutcomeBalance, type OutcomeCompletionInput, type OutcomeCompletionResult, type OutcomeInput, type OutcomeSignal, type OutcomeStep, type OutcomeStepInput, type OutcomeWithSteps, type PayLink, type PaymentDetail, type PaymentRow, type Plan, type PlanComponent, type PlanEntitlement, type PlanEntitlementInput, 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 Tax, type TaxBehavior, type Tokens, type TrackResult, type Unit, type UnitAdjustInput, type UnitBalance, type UnitInput, type UnitPricingType, type UnitTier, type UnitTrackResult, type UpdateCompositeInput, type UpdateCreditInput, type UpdateMemberInput, type UpdateOutcomeInput, type UpdatePlanInput, type UpdateTaxInput, type UpdateUnitInput, type UsageBalance, type UsageLogAppliedRule, type UsageLogEntry, type UsageLogListParams, type UsageLogLookupEntitlementType, type UsageLogLookupEntry, type UsageLogLookupResult, type UsageLogOutcomeAttribution, type UsageLogPage, ValidationError, type WalletAdjustInput, type WalletInput, type WalletLedgerPage, type WalletLedgerParams, type WalletPool, type WalletSignal, type WalletTransaction, type WalletTransactionSource, signalToWire };
package/dist/index.d.ts CHANGED
@@ -164,6 +164,8 @@ type OutcomeCompletionInput = CustomerRef & {
164
164
  runId: string;
165
165
  /** Optional member (email) this completion is attributed to. */
166
166
  member?: string;
167
+ /** Free-form metadata, stored as-is with this completion. Never priced. */
168
+ custom?: Record<string, unknown>;
167
169
  /** Idempotency key, auto-generated if omitted. Sending this completion twice
168
170
  * for the same run is already a safe no-op server-side, so this only
169
171
  * collapses a retry into one attempt rather than protecting against a
@@ -385,8 +387,9 @@ interface UsageLogOutcomeAttribution {
385
387
  interface UsageLogEntry {
386
388
  id: string;
387
389
  createdAt: string;
388
- /** Which meter this row is. */
389
- type: "credit" | "outcome" | "unit" | "wallet" | "composite";
390
+ /** Which meter this row is. `"outcome"` is one step of a run;
391
+ * `"outcome_completion"` is the finished run itself (one per run). */
392
+ type: "credit" | "outcome" | "outcome_completion" | "unit" | "wallet" | "composite";
390
393
  status: SignalStatus;
391
394
  typeName: string | null;
392
395
  member: string | null;
@@ -424,8 +427,22 @@ interface UsageLogEntry {
424
427
  composite: {
425
428
  amount: string;
426
429
  } | null;
427
- /** The `custom` object sent on the signal, as sent. `null` when none was
428
- * sent, and always `null` for unit and composite rows. */
430
+ /** Populated only when `type === "outcome_completion"`. `amount` is the
431
+ * price frozen when the run completed (your plan price, else the catalogue
432
+ * price). */
433
+ outcomeCompletion: {
434
+ runId: string | null;
435
+ amount: string;
436
+ runSignals: number;
437
+ } | null;
438
+ /** The composite that covers this row's billing, by name — the row's price
439
+ * is then included in that composite's own charge, not billed on top. Set
440
+ * on credit / outcome / unit / outcome_completion rows tagged into a
441
+ * composite on the customer's plan; `null` otherwise. */
442
+ coveredByComposite: string | null;
443
+ /** The `custom` object sent, as sent — on the signal itself, or on the
444
+ * `completeComposite()` / `completeOutcome()` call that closed a composite /
445
+ * outcome_completion row. `null` when none was sent. */
429
446
  custom: Record<string, unknown> | null;
430
447
  }
431
448
  interface UsageLogPage {
@@ -434,6 +451,104 @@ interface UsageLogPage {
434
451
  * page. */
435
452
  nextCursor: string | null;
436
453
  }
454
+ /** What a {@link UsageLogLookupEntry} row is. `"outcome"` is one step of a
455
+ * run; `"outcome_completion"` and `"composite_completion"` are the finished
456
+ * runs themselves. */
457
+ type UsageLogLookupEntitlementType = "credit" | "outcome" | "outcome_completion" | "unit" | "composite_completion" | "wallet";
458
+ /**
459
+ * One row of `signals.lookupUsageLogs()`. Only the group that matches
460
+ * `entitlement.type` holds data; the others are `null`.
461
+ */
462
+ interface UsageLogLookupEntry {
463
+ id: string;
464
+ /** The customer this row belongs to — a lookup can span customers. */
465
+ customerId: string;
466
+ /** For a finished run (`outcome_completion`, `composite_completion`), when
467
+ * it completed. */
468
+ createdAt: string;
469
+ status: SignalStatus;
470
+ /** The credit / outcome / unit / composite this row is for. A wallet row has
471
+ * `id: null` and `name: "Wallet"`. */
472
+ entitlement: {
473
+ type: UsageLogLookupEntitlementType;
474
+ id: string | null;
475
+ name: string | null;
476
+ };
477
+ member: string | null;
478
+ model: {
479
+ name: string | null;
480
+ provider: string | null;
481
+ } | null;
482
+ usage: {
483
+ inputTokens: number;
484
+ outputTokens: number;
485
+ /** Cache-read tokens. */
486
+ cacheTokens: number;
487
+ /** Cache-write tokens, priced separately from cache reads. */
488
+ cacheWriteTokens: number;
489
+ };
490
+ /** Formatted USD strings. `customerCost` is what this row charged:
491
+ * `"$0.00"` on an outcome step (the run is billed at completion) and on any
492
+ * row a composite pays for. On a unit row it is what the wallet paid for
493
+ * that report (debits minus refunds), `"$0.00"` when the wallet paid
494
+ * nothing. */
495
+ cost: {
496
+ providedCost: string;
497
+ customerCost: string;
498
+ };
499
+ /** `entitlement.type === "credit"`. */
500
+ credit: {
501
+ amount: string;
502
+ appliedRules: UsageLogAppliedRule[];
503
+ } | null;
504
+ /** `entitlement.type === "outcome"`. `runCompleted` is true once the run is
505
+ * finished — on every step row of that run. */
506
+ outcome: {
507
+ step: string | null;
508
+ stepName: string | null;
509
+ runId: string | null;
510
+ runCompleted: boolean;
511
+ } | null;
512
+ /** `entitlement.type === "outcome_completion"`. `amount` is the price frozen
513
+ * when the run completed. */
514
+ outcomeCompletion: {
515
+ runId: string | null;
516
+ amount: string;
517
+ } | null;
518
+ /** `entitlement.type === "unit"`. `quantity` is formatted. */
519
+ unit: {
520
+ quantity: string;
521
+ } | null;
522
+ /** `entitlement.type === "composite_completion"`. `refId` is the
523
+ * composite's tag key, `runId` the tag value you sent. */
524
+ compositeCompletion: {
525
+ refId: string | null;
526
+ runId: string | null;
527
+ amount: string;
528
+ startedAt: string;
529
+ } | null;
530
+ /** `entitlement.type === "wallet"`. What the wallet paid, formatted USD —
531
+ * the same value as `cost.customerCost`. */
532
+ wallet: {
533
+ amount: string;
534
+ } | null;
535
+ /** The composite that pays for this row — its id, its tag key (`refId`) and
536
+ * the tag value you sent (`runId`). `null` when the row is billed by
537
+ * itself. */
538
+ composite: {
539
+ id: string | null;
540
+ refId: string | null;
541
+ runId: string | null;
542
+ } | null;
543
+ /** The `custom` object sent, as sent. `null` when none was sent. */
544
+ custom: Record<string, unknown> | null;
545
+ }
546
+ interface UsageLogLookupResult {
547
+ /** The rows found, in the order of the ids you asked for. */
548
+ usageLogs: UsageLogLookupEntry[];
549
+ /** The ids that matched nothing in your org, in the order you asked. */
550
+ notFound: string[];
551
+ }
437
552
  interface ApiCustomer {
438
553
  id: string;
439
554
  /** Your own id for this customer, or `null` when unset. See
@@ -454,8 +569,6 @@ interface ApiCustomer {
454
569
  taxId: string | null;
455
570
  currencyCode: string;
456
571
  creditAllowance: number;
457
- recurringTransactionEmail: boolean;
458
- autoRecurring: boolean;
459
572
  createdAt: string;
460
573
  updatedAt: string;
461
574
  }
@@ -485,10 +598,6 @@ interface CustomerProfileInput {
485
598
  taxId?: string | null;
486
599
  /** ISO 4217 (3 letters); must be enabled for the org. */
487
600
  currencyCode?: string;
488
- /** Send the invoice, payment receipt and card-payment-failed emails for recurring invoices. Defaults to `true` on create. */
489
- recurringTransactionEmail?: boolean;
490
- /** Issue every recurring invoice as `AUTO_CLOSED` (applied as if paid, never payable). Defaults to `false` on create. */
491
- autoRecurring?: boolean;
492
601
  }
493
602
  /** `name` and `email` are required on create; every other field is optional. */
494
603
  type CreateCustomerInput = CustomerProfileInput & {
@@ -580,6 +689,79 @@ interface CustomerBalances {
580
689
  * isn't listed. */
581
690
  composites: CompositeBalance[];
582
691
  }
692
+ /** What caused a wallet ledger row (`WalletTransaction.source`). */
693
+ type WalletTransactionSource =
694
+ /** Wallet money from a new plan purchase. */
695
+ "SUBSCRIPTION"
696
+ /** Wallet money from a plan renewal, or unused money removed at renewal. */
697
+ | "RENEWAL"
698
+ /** Changed in the ClockNext dashboard. */
699
+ | "MANUAL"
700
+ /** Changed with `customers.adjustWallet()`. */
701
+ | "API"
702
+ /** Top-up paid by the customer in the customer portal. */
703
+ | "CUSTOMER_PORTAL"
704
+ /** Charged by a signal; `usageLogId` links the signal. */
705
+ | "USAGE_LOG"
706
+ /** Usage cleared by a paid pay-as-you-go invoice. */
707
+ | "INVOICE_SETTLEMENT"
708
+ /** Settlement undone by a voided invoice. */
709
+ | "INVOICE_VOID";
710
+ /** One row of a customer's wallet ledger (`customers.wallet()`). */
711
+ interface WalletTransaction {
712
+ id: string;
713
+ /** ISO 8601. */
714
+ createdAt: string;
715
+ /** `CREDIT` adds money, `DEBIT` takes it out. */
716
+ type: "CREDIT" | "DEBIT";
717
+ /** Which balance moved: the ordinary wallet or the Reserved Wallet. */
718
+ pool: "main" | "reserved";
719
+ source: WalletTransactionSource;
720
+ /** Always positive — `type` gives the direction. In `currencyCode`. */
721
+ amount: number;
722
+ /** The same amount in USD. */
723
+ amountUsd: number;
724
+ currencyCode: string;
725
+ /** 1 USD = this many units of `currencyCode`, at write time. */
726
+ currencyRateUsd: number;
727
+ /** Only text a person wrote: your own note on an `API` row, the admin's
728
+ * note on a `MANUAL` row. `null` on every row the system writes itself —
729
+ * `source` says what those are. */
730
+ notes: string | null;
731
+ /** On a usage charge for an entitlement: which kind. `null` otherwise. */
732
+ entitlementType: "CREDIT" | "OUTCOME" | "UNIT" | "COMPOSITE" | null;
733
+ /** Id of that credit / outcome / unit / composite. */
734
+ entitlementId: string | null;
735
+ /** Its name when the row was written. */
736
+ entitlementName: string | null;
737
+ /** On a `USAGE_LOG` row: the id of the matching row in
738
+ * `signals.usageLog()`. */
739
+ usageLogId: string | null;
740
+ /** On a `SUBSCRIPTION` / `RENEWAL` grant: the purchase it came from. */
741
+ purchaseId: string | null;
742
+ purchaseNumber: string | null;
743
+ }
744
+ /** One page of a customer's wallet ledger, newest first. */
745
+ interface WalletLedgerPage {
746
+ /** Ordinary wallet balance, USD. May be negative. */
747
+ balanceUsd: number;
748
+ /** Reserved Wallet balance, USD; `null` when the workspace hasn't enabled
749
+ * it. */
750
+ reservedBalanceUsd: number | null;
751
+ transactions: WalletTransaction[];
752
+ /** Pass back as `cursor` for the next page; `null` on the last page. */
753
+ nextCursor: string | null;
754
+ }
755
+ interface WalletLedgerParams {
756
+ /** Default 50, max 200. */
757
+ limit?: number;
758
+ /** A previous page's `nextCursor`. Omit for the first page. */
759
+ cursor?: string;
760
+ /** First day to include, `YYYY-MM-DD` (UTC). The whole day is included. */
761
+ from?: string;
762
+ /** Last day to include, `YYYY-MM-DD` (UTC). The whole day is included. */
763
+ to?: string;
764
+ }
583
765
  /** The customer's active plan (the `plan` field of `customers.plan()`);
584
766
  * `null` when the customer is unsubscribed. */
585
767
  interface CustomerPlanDetails {
@@ -1025,7 +1207,8 @@ interface PurchaseDetail {
1025
1207
  paidCount: number;
1026
1208
  };
1027
1209
  }
1028
- /** `AUTO_CLOSED` — a recurring invoice for a customer with `autoRecurring` on:
1210
+ /** `AUTO_CLOSED` — a recurring invoice of an organisation with "Auto close
1211
+ * invoices on recurring" on (dashboard: Settings → Organisation → Billing):
1029
1212
  * applied as if paid, but never payable. */
1030
1213
  type InvoiceStatus = "OPEN" | "PAID" | "VOID" | "AUTO_CLOSED";
1031
1214
  /** Trimmed row from `invoices.list()`. */
@@ -1398,6 +1581,8 @@ type UnitInput = CustomerRef & {
1398
1581
  quantity?: number;
1399
1582
  /** Optional composite this unit report belongs to. See {@link CompositeTag}. */
1400
1583
  composite?: CompositeTag;
1584
+ /** Free-form metadata, stored as-is with this unit report. Never priced. */
1585
+ custom?: Record<string, unknown>;
1401
1586
  /**
1402
1587
  * Idempotency key for safe retries — a repeat carrying the same key returns
1403
1588
  * the original result instead of drawing the balance down twice.
@@ -1447,6 +1632,9 @@ type CompositeCompletionInput = CustomerRef & {
1447
1632
  /** Which occurrence to close: the composite's `refId` and the correlation
1448
1633
  * value the signals were tagged with. */
1449
1634
  composite: CompositeTag;
1635
+ /** Free-form metadata, stored as-is on the occurrence this call closes.
1636
+ * Never priced. */
1637
+ custom?: Record<string, unknown>;
1450
1638
  /** Idempotency key, auto-generated if omitted. Closing twice is already a
1451
1639
  * safe no-op, so this only collapses retries into one recorded attempt
1452
1640
  * rather than protecting against a double charge. */
@@ -1747,6 +1935,22 @@ declare class Customers {
1747
1935
  delete(id: string): Promise<void>;
1748
1936
  /** Wallet / credit / outcome / unit balances. `GET …/:id/balances`. */
1749
1937
  balances(id: string): Promise<CustomerBalances>;
1938
+ /**
1939
+ * One page of the customer's wallet ledger — every movement of wallet
1940
+ * money, newest first — plus both wallet balances. Cursor-paginated: pass
1941
+ * back `nextCursor` as `cursor`. `GET /api/v1/customers/:id/wallet`.
1942
+ */
1943
+ wallet(id: string, params?: WalletLedgerParams): Promise<WalletLedgerPage>;
1944
+ /** {@link wallet}, addressing the customer by its `externalId`.
1945
+ * `GET /api/v1/customers/ext/:externalId/wallet`. */
1946
+ walletByExternalId(externalId: string, params?: WalletLedgerParams): Promise<WalletLedgerPage>;
1947
+ /**
1948
+ * Async iterator over the customer's WHOLE wallet ledger, newest first,
1949
+ * following the cursor. `params.cursor` is ignored.
1950
+ * `for await (const t of cnk.customers.iterateWallet(id)) { … }`
1951
+ */
1952
+ iterateWallet(id: string, params?: Omit<WalletLedgerParams, "cursor">): AsyncGenerator<WalletTransaction>;
1953
+ private walletPage;
1750
1954
  /** {@link balances}, addressing the customer by its `externalId`.
1751
1955
  * `GET /api/v1/customers/ext/:externalId/balances`. */
1752
1956
  balancesByExternalId(externalId: string): Promise<CustomerBalances>;
@@ -2218,6 +2422,20 @@ declare class Signals {
2218
2422
  * buffer or retry here.
2219
2423
  */
2220
2424
  usageLog(params: UsageLogListParams): Promise<UsageLogPage>;
2425
+ /**
2426
+ * Fetches up to 100 usage-log rows by id, in one call.
2427
+ * `GET /api/v1/signal/usage-log/lookup`.
2428
+ *
2429
+ * Built for linking a wallet debit to its usage: pass the `usageLogId`s
2430
+ * from `customers.wallet()` instead of paging through
2431
+ * {@link usageLog}. Scoped to your org, not to one customer — every row
2432
+ * carries its own `customerId`.
2433
+ *
2434
+ * Rows come back in the order of `ids`; duplicates are removed. Ids that
2435
+ * match nothing in your org are listed in `notFound`. More than 100
2436
+ * distinct ids is a 400.
2437
+ */
2438
+ lookupUsageLogs(ids: string[]): Promise<UsageLogLookupResult>;
2221
2439
  }
2222
2440
 
2223
2441
  /**
@@ -2406,4 +2624,4 @@ declare class NetworkError extends ClockNextError {
2406
2624
  });
2407
2625
  }
2408
2626
 
2409
- export { type AddMemberInput, type AdjustResult, AllowanceError, type ApiCustomer, AuthError, type BillingCycle, type BillingMode, ClockNext, type ClockNextConfig, ClockNextError, type ClockNextErrorCode, type ComponentType, type Composite, type CompositeAdjustInput, type CompositeBalance, type CompositeCompletionInput, type CompositeCompletionResult, type CompositeItem, type CompositeTag, ConflictError, type CreateCompositeInput, type CreateCreditInput, type CreateCustomerInput, type CreateOutcomeInput, type CreatePlanInput, type CreatePurchaseInput, type CreateTaxInput, type CreateUnitInput, type Credit, 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, type ModelBundleLine, type ModelBundleLineInput, NetworkError, NotFoundError, type Outcome, type OutcomeAdjustInput, type OutcomeBalance, type OutcomeCompletionInput, type OutcomeCompletionResult, type OutcomeInput, type OutcomeSignal, type OutcomeStep, type OutcomeStepInput, type OutcomeWithSteps, type PayLink, type PaymentDetail, type PaymentRow, type Plan, type PlanComponent, type PlanEntitlement, type PlanEntitlementInput, 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 Tax, type TaxBehavior, type Tokens, type TrackResult, type Unit, type UnitAdjustInput, type UnitBalance, type UnitInput, type UnitPricingType, type UnitTier, type UnitTrackResult, type UpdateCompositeInput, type UpdateCreditInput, type UpdateMemberInput, type UpdateOutcomeInput, type UpdatePlanInput, type UpdateTaxInput, type UpdateUnitInput, type UsageBalance, type UsageLogAppliedRule, type UsageLogEntry, type UsageLogListParams, type UsageLogOutcomeAttribution, type UsageLogPage, ValidationError, type WalletAdjustInput, type WalletInput, type WalletPool, type WalletSignal, signalToWire };
2627
+ export { type AddMemberInput, type AdjustResult, AllowanceError, type ApiCustomer, AuthError, type BillingCycle, type BillingMode, ClockNext, type ClockNextConfig, ClockNextError, type ClockNextErrorCode, type ComponentType, type Composite, type CompositeAdjustInput, type CompositeBalance, type CompositeCompletionInput, type CompositeCompletionResult, type CompositeItem, type CompositeTag, ConflictError, type CreateCompositeInput, type CreateCreditInput, type CreateCustomerInput, type CreateOutcomeInput, type CreatePlanInput, type CreatePurchaseInput, type CreateTaxInput, type CreateUnitInput, type Credit, 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, type ModelBundleLine, type ModelBundleLineInput, NetworkError, NotFoundError, type Outcome, type OutcomeAdjustInput, type OutcomeBalance, type OutcomeCompletionInput, type OutcomeCompletionResult, type OutcomeInput, type OutcomeSignal, type OutcomeStep, type OutcomeStepInput, type OutcomeWithSteps, type PayLink, type PaymentDetail, type PaymentRow, type Plan, type PlanComponent, type PlanEntitlement, type PlanEntitlementInput, 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 Tax, type TaxBehavior, type Tokens, type TrackResult, type Unit, type UnitAdjustInput, type UnitBalance, type UnitInput, type UnitPricingType, type UnitTier, type UnitTrackResult, type UpdateCompositeInput, type UpdateCreditInput, type UpdateMemberInput, type UpdateOutcomeInput, type UpdatePlanInput, type UpdateTaxInput, type UpdateUnitInput, type UsageBalance, type UsageLogAppliedRule, type UsageLogEntry, type UsageLogListParams, type UsageLogLookupEntitlementType, type UsageLogLookupEntry, type UsageLogLookupResult, type UsageLogOutcomeAttribution, type UsageLogPage, ValidationError, type WalletAdjustInput, type WalletInput, type WalletLedgerPage, type WalletLedgerParams, type WalletPool, type WalletSignal, type WalletTransaction, type WalletTransactionSource, signalToWire };