@clocknext/sdk 0.17.0 → 0.19.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/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
@@ -342,8 +344,6 @@ interface TrackResult {
342
344
  */
343
345
  rawId?: string;
344
346
  }
345
- /** A preset time window, or `"custom"` for an explicit `from`/`to` range. */
346
- type UsageLogPeriod = "all" | "today" | "7d" | "30d" | "90d" | "custom";
347
347
  interface UsageLogListParams {
348
348
  customerId: string;
349
349
  /** Default 50, max 200. */
@@ -351,11 +351,11 @@ interface UsageLogListParams {
351
351
  /** Pass back a previous page's `nextCursor` to fetch the next page. Omit for
352
352
  * the first page. */
353
353
  cursor?: string;
354
- /** Default `"all"`. Pair `"custom"` with `from`/`to`. */
355
- period?: UsageLogPeriod;
356
- /** `YYYY-MM-DD`, only used when `period` is `"custom"`. */
354
+ /** First day to include, `YYYY-MM-DD` (UTC). The whole day is included.
355
+ * Keep sending the same value while paging with `cursor`. */
357
356
  from?: string;
358
- /** `YYYY-MM-DD`, only used when `period` is `"custom"`. */
357
+ /** Last day to include, `YYYY-MM-DD` (UTC). The whole day is included.
358
+ * Must not be before `from`. */
359
359
  to?: string;
360
360
  }
361
361
  interface UsageLogAppliedRule {
@@ -381,13 +381,15 @@ interface UsageLogOutcomeAttribution {
381
381
  * One row of a customer's usage history, merged from every meter kind
382
382
  * (`UsageLog`, `UnitUsageLog`, completed composite occurrences) into one
383
383
  * feed and sorted by time — the same rows the customer portal's own "Usage
384
- * logs" table shows. `model`, `credit`, `outcome`, `unit` and `composite` are
385
- * each `null` unless `kind` matches that group.
384
+ * logs" table shows. `credit`, `outcome`, `unit` and `composite` are each
385
+ * `null` unless `type` matches that group.
386
386
  */
387
387
  interface UsageLogEntry {
388
388
  id: string;
389
389
  createdAt: string;
390
- kind: "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";
391
393
  status: SignalStatus;
392
394
  typeName: string | null;
393
395
  member: string | null;
@@ -408,23 +410,40 @@ interface UsageLogEntry {
408
410
  providedCost: string;
409
411
  customerCost: string;
410
412
  };
411
- /** Populated only when `kind === "credit"`. `amount` is a formatted credit
413
+ /** Populated only when `type === "credit"`. `amount` is a formatted credit
412
414
  * value, honouring the org's credit-decimals display setting. */
413
415
  credit: {
414
416
  amount: string;
415
417
  appliedRules: UsageLogAppliedRule[];
416
418
  } | null;
417
- /** Populated only when `kind === "outcome"`. */
419
+ /** Populated only when `type === "outcome"`. */
418
420
  outcome: UsageLogOutcomeAttribution | null;
419
- /** Populated only when `kind === "unit"`. `quantity` is formatted. */
421
+ /** Populated only when `type === "unit"`. `quantity` is formatted. */
420
422
  unit: {
421
423
  quantity: string;
422
424
  } | null;
423
- /** Populated only when `kind === "composite"`. `amount` is a formatted USD
425
+ /** Populated only when `type === "composite"`. `amount` is a formatted USD
424
426
  * price — the composite's flat price, read live, not stored per row. */
425
427
  composite: {
426
428
  amount: string;
427
429
  } | null;
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. */
446
+ custom: Record<string, unknown> | null;
428
447
  }
429
448
  interface UsageLogPage {
430
449
  usageLogs: UsageLogEntry[];
@@ -452,8 +471,6 @@ interface ApiCustomer {
452
471
  taxId: string | null;
453
472
  currencyCode: string;
454
473
  creditAllowance: number;
455
- recurringTransactionEmail: boolean;
456
- autoRecurring: boolean;
457
474
  createdAt: string;
458
475
  updatedAt: string;
459
476
  }
@@ -483,10 +500,6 @@ interface CustomerProfileInput {
483
500
  taxId?: string | null;
484
501
  /** ISO 4217 (3 letters); must be enabled for the org. */
485
502
  currencyCode?: string;
486
- /** Send the invoice, payment receipt and card-payment-failed emails for recurring invoices. Defaults to `true` on create. */
487
- recurringTransactionEmail?: boolean;
488
- /** Issue every recurring invoice as `AUTO_CLOSED` (applied as if paid, never payable). Defaults to `false` on create. */
489
- autoRecurring?: boolean;
490
503
  }
491
504
  /** `name` and `email` are required on create; every other field is optional. */
492
505
  type CreateCustomerInput = CustomerProfileInput & {
@@ -578,6 +591,79 @@ interface CustomerBalances {
578
591
  * isn't listed. */
579
592
  composites: CompositeBalance[];
580
593
  }
594
+ /** What caused a wallet ledger row (`WalletTransaction.source`). */
595
+ type WalletTransactionSource =
596
+ /** Wallet money from a new plan purchase. */
597
+ "SUBSCRIPTION"
598
+ /** Wallet money from a plan renewal, or unused money removed at renewal. */
599
+ | "RENEWAL"
600
+ /** Changed in the ClockNext dashboard. */
601
+ | "MANUAL"
602
+ /** Changed with `customers.adjustWallet()`. */
603
+ | "API"
604
+ /** Top-up paid by the customer in the customer portal. */
605
+ | "CUSTOMER_PORTAL"
606
+ /** Charged by a signal; `usageLogId` links the signal. */
607
+ | "USAGE_LOG"
608
+ /** Usage cleared by a paid pay-as-you-go invoice. */
609
+ | "INVOICE_SETTLEMENT"
610
+ /** Settlement undone by a voided invoice. */
611
+ | "INVOICE_VOID";
612
+ /** One row of a customer's wallet ledger (`customers.wallet()`). */
613
+ interface WalletTransaction {
614
+ id: string;
615
+ /** ISO 8601. */
616
+ createdAt: string;
617
+ /** `CREDIT` adds money, `DEBIT` takes it out. */
618
+ type: "CREDIT" | "DEBIT";
619
+ /** Which balance moved: the ordinary wallet or the Reserved Wallet. */
620
+ pool: "main" | "reserved";
621
+ source: WalletTransactionSource;
622
+ /** Always positive — `type` gives the direction. In `currencyCode`. */
623
+ amount: number;
624
+ /** The same amount in USD. */
625
+ amountUsd: number;
626
+ currencyCode: string;
627
+ /** 1 USD = this many units of `currencyCode`, at write time. */
628
+ currencyRateUsd: number;
629
+ /** Only text a person wrote: your own note on an `API` row, the admin's
630
+ * note on a `MANUAL` row. `null` on every row the system writes itself —
631
+ * `source` says what those are. */
632
+ notes: string | null;
633
+ /** On a usage charge for an entitlement: which kind. `null` otherwise. */
634
+ entitlementType: "CREDIT" | "OUTCOME" | "UNIT" | "COMPOSITE" | null;
635
+ /** Id of that credit / outcome / unit / composite. */
636
+ entitlementId: string | null;
637
+ /** Its name when the row was written. */
638
+ entitlementName: string | null;
639
+ /** On a `USAGE_LOG` row: the id of the matching row in
640
+ * `signals.usageLog()`. */
641
+ usageLogId: string | null;
642
+ /** On a `SUBSCRIPTION` / `RENEWAL` grant: the purchase it came from. */
643
+ purchaseId: string | null;
644
+ purchaseNumber: string | null;
645
+ }
646
+ /** One page of a customer's wallet ledger, newest first. */
647
+ interface WalletLedgerPage {
648
+ /** Ordinary wallet balance, USD. May be negative. */
649
+ balanceUsd: number;
650
+ /** Reserved Wallet balance, USD; `null` when the workspace hasn't enabled
651
+ * it. */
652
+ reservedBalanceUsd: number | null;
653
+ transactions: WalletTransaction[];
654
+ /** Pass back as `cursor` for the next page; `null` on the last page. */
655
+ nextCursor: string | null;
656
+ }
657
+ interface WalletLedgerParams {
658
+ /** Default 50, max 200. */
659
+ limit?: number;
660
+ /** A previous page's `nextCursor`. Omit for the first page. */
661
+ cursor?: string;
662
+ /** First day to include, `YYYY-MM-DD` (UTC). The whole day is included. */
663
+ from?: string;
664
+ /** Last day to include, `YYYY-MM-DD` (UTC). The whole day is included. */
665
+ to?: string;
666
+ }
581
667
  /** The customer's active plan (the `plan` field of `customers.plan()`);
582
668
  * `null` when the customer is unsubscribed. */
583
669
  interface CustomerPlanDetails {
@@ -878,6 +964,42 @@ interface CreateUnitInput {
878
964
  }
879
965
  /** `units.update()` body — PARTIAL. `tiers`, when sent, is the complete list. */
880
966
  type UpdateUnitInput = Partial<CreateUnitInput>;
967
+ /** How a tax applies: `"inclusive"` — already inside the price;
968
+ * `"exclusive"` — added on top. Lower case only. */
969
+ type TaxBehavior = "inclusive" | "exclusive";
970
+ /** A tax rate, charged to customers whose billing country matches. */
971
+ interface Tax {
972
+ id: string;
973
+ /** Shown on invoices. Unique among active taxes in the same country,
974
+ * ignoring case. */
975
+ name: string;
976
+ /** A note for your team; not shown to customers. */
977
+ description: string | null;
978
+ /** 0–100. */
979
+ percentage: number;
980
+ /** ISO 3166-1 alpha-2, upper case (e.g. `"IN"`). */
981
+ countryCode: string;
982
+ behavior: TaxBehavior;
983
+ /** `false` once archived in the dashboard (Settings → Taxes): it no longer
984
+ * applies to new invoices. */
985
+ isActive: boolean;
986
+ createdAt: string;
987
+ updatedAt: string;
988
+ }
989
+ /** `taxes.create()` body. */
990
+ interface CreateTaxInput {
991
+ /** 1–100 characters. */
992
+ name: string;
993
+ /** 0–100. */
994
+ percentage: number;
995
+ /** ISO 3166-1 alpha-2 (lower case is accepted). A country name is refused. */
996
+ countryCode: string;
997
+ behavior: TaxBehavior;
998
+ /** Up to 500 characters. */
999
+ description?: string | null;
1000
+ }
1001
+ /** `taxes.update()` body — PARTIAL: only the fields you send change. */
1002
+ type UpdateTaxInput = Partial<CreateTaxInput>;
881
1003
  /** A catalogue item a composite wraps. */
882
1004
  interface CompositeItem {
883
1005
  id: string;
@@ -987,7 +1109,8 @@ interface PurchaseDetail {
987
1109
  paidCount: number;
988
1110
  };
989
1111
  }
990
- /** `AUTO_CLOSED` — a recurring invoice for a customer with `autoRecurring` on:
1112
+ /** `AUTO_CLOSED` — a recurring invoice of an organisation with "Auto close
1113
+ * invoices on recurring" on (dashboard: Settings → Organisation → Billing):
991
1114
  * applied as if paid, but never payable. */
992
1115
  type InvoiceStatus = "OPEN" | "PAID" | "VOID" | "AUTO_CLOSED";
993
1116
  /** Trimmed row from `invoices.list()`. */
@@ -1360,6 +1483,8 @@ type UnitInput = CustomerRef & {
1360
1483
  quantity?: number;
1361
1484
  /** Optional composite this unit report belongs to. See {@link CompositeTag}. */
1362
1485
  composite?: CompositeTag;
1486
+ /** Free-form metadata, stored as-is with this unit report. Never priced. */
1487
+ custom?: Record<string, unknown>;
1363
1488
  /**
1364
1489
  * Idempotency key for safe retries — a repeat carrying the same key returns
1365
1490
  * the original result instead of drawing the balance down twice.
@@ -1409,6 +1534,9 @@ type CompositeCompletionInput = CustomerRef & {
1409
1534
  /** Which occurrence to close: the composite's `refId` and the correlation
1410
1535
  * value the signals were tagged with. */
1411
1536
  composite: CompositeTag;
1537
+ /** Free-form metadata, stored as-is on the occurrence this call closes.
1538
+ * Never priced. */
1539
+ custom?: Record<string, unknown>;
1412
1540
  /** Idempotency key, auto-generated if omitted. Closing twice is already a
1413
1541
  * safe no-op, so this only collapses retries into one recorded attempt
1414
1542
  * rather than protecting against a double charge. */
@@ -1709,6 +1837,22 @@ declare class Customers {
1709
1837
  delete(id: string): Promise<void>;
1710
1838
  /** Wallet / credit / outcome / unit balances. `GET …/:id/balances`. */
1711
1839
  balances(id: string): Promise<CustomerBalances>;
1840
+ /**
1841
+ * One page of the customer's wallet ledger — every movement of wallet
1842
+ * money, newest first — plus both wallet balances. Cursor-paginated: pass
1843
+ * back `nextCursor` as `cursor`. `GET /api/v1/customers/:id/wallet`.
1844
+ */
1845
+ wallet(id: string, params?: WalletLedgerParams): Promise<WalletLedgerPage>;
1846
+ /** {@link wallet}, addressing the customer by its `externalId`.
1847
+ * `GET /api/v1/customers/ext/:externalId/wallet`. */
1848
+ walletByExternalId(externalId: string, params?: WalletLedgerParams): Promise<WalletLedgerPage>;
1849
+ /**
1850
+ * Async iterator over the customer's WHOLE wallet ledger, newest first,
1851
+ * following the cursor. `params.cursor` is ignored.
1852
+ * `for await (const t of cnk.customers.iterateWallet(id)) { … }`
1853
+ */
1854
+ iterateWallet(id: string, params?: Omit<WalletLedgerParams, "cursor">): AsyncGenerator<WalletTransaction>;
1855
+ private walletPage;
1712
1856
  /** {@link balances}, addressing the customer by its `externalId`.
1713
1857
  * `GET /api/v1/customers/ext/:externalId/balances`. */
1714
1858
  balancesByExternalId(externalId: string): Promise<CustomerBalances>;
@@ -2211,6 +2355,34 @@ declare class Units {
2211
2355
  unarchive(id: string): Promise<Unit>;
2212
2356
  }
2213
2357
 
2358
+ /**
2359
+ * The `taxes` resource — the tax rates charged to customers by billing
2360
+ * country (the same rates as Settings → Taxes). `/api/v1/taxes`.
2361
+ *
2362
+ * Every active tax for a customer's country is applied to their invoices and
2363
+ * portal purchases automatically. There is no `delete()`, `archive()` or
2364
+ * `unarchive()` — archiving and restoring a tax is done in the dashboard.
2365
+ */
2366
+ declare class Taxes {
2367
+ private readonly transport;
2368
+ constructor(transport: Transport);
2369
+ /** List them, oldest first. `{ active: true }` returns only active ones,
2370
+ * `{ active: false }` only archived ones; omit it for both. */
2371
+ list(params?: {
2372
+ active?: boolean;
2373
+ }): Promise<Tax[]>;
2374
+ /** One tax. */
2375
+ get(id: string): Promise<Tax>;
2376
+ /** Create one. It starts active. Two active taxes can't share a name
2377
+ * (ignoring case) in the same country — that's a `ConflictError`. Not
2378
+ * retried on failure — a retry could create a second row. */
2379
+ create(input: CreateTaxInput): Promise<Tax>;
2380
+ /** PARTIAL update: only the fields you send change. Archived taxes can be
2381
+ * edited and stay archived. Only invoices issued afterwards use the new
2382
+ * values. */
2383
+ update(id: string, input: UpdateTaxInput): Promise<Tax>;
2384
+ }
2385
+
2214
2386
  /**
2215
2387
  * The ClockNext client.
2216
2388
  *
@@ -2243,6 +2415,8 @@ declare class ClockNext {
2243
2415
  readonly units: Units;
2244
2416
  /** Composites: list, get, create, update, archive, unarchive (no delete). */
2245
2417
  readonly composites: Composites;
2418
+ /** Tax rates by country: list, get, create, update (archive in the dashboard). */
2419
+ readonly taxes: Taxes;
2246
2420
  /** Subscribe customers to plans (purchases). */
2247
2421
  readonly purchases: Purchases;
2248
2422
  /** Read invoices and mint hosted pay links. */
@@ -2338,4 +2512,4 @@ declare class NetworkError extends ClockNextError {
2338
2512
  });
2339
2513
  }
2340
2514
 
2341
- 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 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 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 UpdateUnitInput, type UsageBalance, type UsageLogAppliedRule, type UsageLogEntry, type UsageLogListParams, type UsageLogOutcomeAttribution, type UsageLogPage, type UsageLogPeriod, ValidationError, type WalletAdjustInput, type WalletInput, type WalletPool, type WalletSignal, signalToWire };
2515
+ 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 WalletLedgerPage, type WalletLedgerParams, type WalletPool, type WalletSignal, type WalletTransaction, type WalletTransactionSource, signalToWire };