@clocknext/sdk 0.4.0 → 0.5.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.ts CHANGED
@@ -103,6 +103,18 @@ interface SerializedOutcomeAttribution {
103
103
  progressSteps: string[];
104
104
  totalSteps: number;
105
105
  }
106
+ /** The customer's remaining balance for the dimension a signal metered, AFTER
107
+ * the signal was applied — update an on-screen meter straight from the record
108
+ * response. Populated on recorded (inline / `{ wait: true }`) signals; `null`
109
+ * on dry runs and on read-back. */
110
+ interface UsageBalance {
111
+ dimension: "credit" | "outcome" | "wallet";
112
+ /** Post-signal remaining. `null` when the meter is uncapped — an ARREAR
113
+ * (pay-as-you-go) credit or outcome has no fixed allowance. */
114
+ remaining: number | null;
115
+ /** The credit / outcome name; `null` for the wallet. */
116
+ name: string | null;
117
+ }
106
118
  interface SerializedUsageLog {
107
119
  id: string;
108
120
  customerId: string;
@@ -121,6 +133,9 @@ interface SerializedUsageLog {
121
133
  status: SignalStatus;
122
134
  appliedRules: SerializedRuleApplication[];
123
135
  outcome: SerializedOutcomeAttribution | null;
136
+ /** Post-signal balance for the metered dimension. Null on dry runs and
137
+ * read-back. */
138
+ balance: UsageBalance | null;
124
139
  createdAt: string;
125
140
  }
126
141
  /** Result of a single signal send (sync mode, or `{ wait: true }`). */
@@ -198,10 +213,46 @@ interface CustomerList {
198
213
  customers: ApiCustomer[];
199
214
  nextCursor: string | null;
200
215
  }
201
- type RevenueRange = "30d" | "6m" | "1y" | "all";
202
- /** Loosely typed insight payloads (revenue/balances/plan) — server shapes the
203
- * detail; we surface the whole envelope minus the `ok` flag. */
204
- type CustomerBalances = {
216
+ /** One credit type's running balance for a customer (an element of
217
+ * `customers.balances().credits`). */
218
+ interface CreditBalance {
219
+ creditId: string;
220
+ /** The credit's stable agent key — the same key used to record usage and to
221
+ * adjust this balance. */
222
+ agentKey: string;
223
+ creditName: string;
224
+ granted: number;
225
+ used: number;
226
+ remaining: number;
227
+ }
228
+ /** One outcome's running balance for a customer. Unlike a credit balance it
229
+ * has no `used`, and it carries the outcome's ordered step list. */
230
+ interface OutcomeBalance {
231
+ outcomeId: string;
232
+ outcomeName: string;
233
+ granted: number;
234
+ remaining: number;
235
+ /** Each step's `agentKey` is what `signals.outcome()` and the outcome adjust
236
+ * API use to address this outcome (outcomes have no key of their own). */
237
+ steps: {
238
+ id: string;
239
+ name: string;
240
+ agentKey: string;
241
+ }[];
242
+ }
243
+ /** One unit's advance allowance for a customer. No `used` field. */
244
+ interface UnitBalance {
245
+ unitId: string;
246
+ /** The unit's stable agent key — the same key used to record usage and to
247
+ * adjust this balance. */
248
+ agentKey: string;
249
+ unitName: string;
250
+ granted: number;
251
+ remaining: number;
252
+ }
253
+ /** Wallet / credit / outcome / unit balances for a customer's active plan
254
+ * (`customers.balances()`). */
255
+ interface CustomerBalances {
205
256
  customerId: string;
206
257
  currency: {
207
258
  code: string;
@@ -211,34 +262,40 @@ type CustomerBalances = {
211
262
  wallet: {
212
263
  balanceUsd: number;
213
264
  } | null;
214
- credits: unknown[];
215
- outcomes: unknown[];
216
- units: unknown[];
217
- };
218
- type CustomerPlan = {
219
- customerId: string;
220
- currency: {
221
- code: string;
222
- rateUsd: number;
265
+ credits: CreditBalance[];
266
+ outcomes: OutcomeBalance[];
267
+ units: UnitBalance[];
268
+ }
269
+ /** The customer's active plan (the `plan` field of `customers.plan()`);
270
+ * `null` when the customer is unsubscribed. */
271
+ interface CustomerPlanDetails {
272
+ purchaseId: string;
273
+ planId: string | null;
274
+ planName: string;
275
+ planType: PlanType;
276
+ planKind: PlanKind;
277
+ seatScope: "CUSTOMER" | "MEMBER" | null;
278
+ billingCycle: BillingCycle;
279
+ cost: number;
280
+ status: "SCHEDULED" | "ACTIVE";
281
+ billingDate: string;
282
+ spendingLimit: number | null;
283
+ spentThisCycle: number | null;
284
+ meters: {
285
+ wallet: boolean;
286
+ credit: boolean;
287
+ outcome: boolean;
288
+ unit: boolean;
223
289
  };
224
- plan: Record<string, unknown> | null;
225
- };
226
- type CustomerRevenue = {
290
+ }
291
+ interface CustomerPlan {
227
292
  customerId: string;
228
- range: RevenueRange;
229
- window: unknown;
230
- bucket: unknown;
231
293
  currency: {
232
294
  code: string;
233
295
  rateUsd: number;
234
296
  };
235
- revenue: number;
236
- cost: number;
237
- profit: number;
238
- grossMargin: number;
239
- deltas: Record<string, unknown>;
240
- trend: unknown[];
241
- };
297
+ plan: CustomerPlanDetails | null;
298
+ }
242
299
  interface PortalTokenInput {
243
300
  customerId: string;
244
301
  ttlSeconds?: number;
@@ -354,6 +411,8 @@ interface Plan {
354
411
  kind: PlanKind;
355
412
  billingCycle: BillingCycle;
356
413
  cost: number;
414
+ /** Signed adjustment applied to the plan's headline price (default 0). */
415
+ priceAdjustment: number;
357
416
  currencyCode: string;
358
417
  isActive: boolean;
359
418
  components: PlanComponent[];
@@ -364,6 +423,7 @@ interface PlanDetail extends Plan {
364
423
  createdByName: string | null;
365
424
  customerCount: number;
366
425
  invoiceCount: number;
426
+ openInvoiceCount: number;
367
427
  stats: {
368
428
  totalInvoiced: number;
369
429
  totalCollected: number;
@@ -386,6 +446,7 @@ interface Purchase {
386
446
  purchaseNumber: string;
387
447
  customerId: string;
388
448
  customerName: string;
449
+ customerLogoUrl: string | null;
389
450
  planId: string | null;
390
451
  planName: string;
391
452
  planType: PlanType;
@@ -397,9 +458,12 @@ interface Purchase {
397
458
  cost: number;
398
459
  currencyCode: string;
399
460
  billingDate: string;
461
+ nextBillingDate: string;
400
462
  status: PurchaseStatus;
463
+ voidAfterMinutes: number;
401
464
  autoPayment: boolean;
402
465
  autoPaymentPauseReason: string | null;
466
+ notes: string | null;
403
467
  createdAt: string;
404
468
  }
405
469
  /** The purchase returned by `purchases.get()` — a different, detail-oriented shape. */
@@ -417,7 +481,10 @@ interface PurchaseDetail {
417
481
  customer: {
418
482
  id: string;
419
483
  name: string;
484
+ logoUrl: string | null;
420
485
  };
486
+ voidAfterMinutes: number;
487
+ notes: string | null;
421
488
  autoPayment: boolean;
422
489
  autoPaymentPauseReason: string | null;
423
490
  autoPaymentPausedAt: string | null;
@@ -612,21 +679,28 @@ interface WalletEntryInput {
612
679
  amount: number;
613
680
  notes?: string;
614
681
  }
615
- /** Grant (positive) or claw back (negative) a credit balance. `delta` must be a non-zero whole number. */
682
+ /** Grant (positive) or claw back (negative) a credit balance. `delta` must be a
683
+ * non-zero whole number. The credit is addressed by its stable `agentKey`. */
616
684
  interface CreditAdjustInput {
617
- creditId: string;
685
+ /** The credit's stable agent key (the same key used to record usage). */
686
+ agentKey: string;
618
687
  delta: number;
619
688
  notes?: string;
620
689
  }
621
- /** Grant/claw an outcome balance. `delta` is a non-zero whole number; floored at 0. */
690
+ /** Grant/claw an outcome balance. `delta` is a non-zero whole number; floored at
691
+ * 0. The outcome is addressed by a STEP's `agentKey` (outcomes have no key of
692
+ * their own). */
622
693
  interface OutcomeAdjustInput {
623
- outcomeId: string;
694
+ /** An outcome step's stable agent key — identifies the parent outcome. */
695
+ agentKey: string;
624
696
  delta: number;
625
697
  notes?: string;
626
698
  }
627
- /** Grant/claw a unit balance. `delta` is non-zero (fractional allowed); floored at 0. */
699
+ /** Grant/claw a unit balance. `delta` is non-zero (fractional allowed); floored
700
+ * at 0. The unit is addressed by its stable `agentKey`. */
628
701
  interface UnitAdjustInput {
629
- unitId: string;
702
+ /** The unit's stable agent key (the same key used to record usage). */
703
+ agentKey: string;
630
704
  delta: number;
631
705
  notes?: string;
632
706
  }
@@ -640,6 +714,43 @@ interface ModelBundleEntry {
640
714
  output: number;
641
715
  cache: number;
642
716
  }
717
+ /** One point on a cost-over-time analytics series. */
718
+ interface CostPoint {
719
+ /** UTC day, `YYYY-MM-DD`. */
720
+ dateIso: string;
721
+ /** Short display label, e.g. "Jun 24". */
722
+ label: string;
723
+ /** Average cost that day, or `null` on days with no usage. */
724
+ cost: number | null;
725
+ reqs: number;
726
+ }
727
+ /** Summary stats across a cost-over-time series. */
728
+ interface CostStats {
729
+ activeDays: number;
730
+ avgCost: number | null;
731
+ peakCost: number | null;
732
+ troughCost: number | null;
733
+ deviationPct: number | null;
734
+ }
735
+ /** Cost-over-time analytics for a credit (`credits.get().analytics`). */
736
+ interface CreditAnalytics {
737
+ basePrice: number;
738
+ pricePerCredit: number;
739
+ marginPercent: number;
740
+ points: CostPoint[];
741
+ stats: CostStats;
742
+ }
743
+ /** Cost-over-time analytics for an outcome (`outcomes.get().analytics`).
744
+ * Each point adds `completions` (workflows finished that day). */
745
+ interface OutcomeAnalytics {
746
+ basePrice: number;
747
+ pricePerOutcome: number;
748
+ marginPercent: number;
749
+ points: (CostPoint & {
750
+ completions: number;
751
+ })[];
752
+ stats: CostStats;
753
+ }
643
754
  interface Credit {
644
755
  id: string;
645
756
  name: string;
@@ -664,8 +775,7 @@ interface CreditDetail extends Credit {
664
775
  revenue: number;
665
776
  usageLogCount: number;
666
777
  };
667
- /** Cost-over-time analytics; shape is server-defined. */
668
- analytics: Record<string, unknown>;
778
+ analytics: CreditAnalytics;
669
779
  }
670
780
  interface CreateCreditInput {
671
781
  name: string;
@@ -714,7 +824,7 @@ interface OutcomeDetail extends Outcome {
714
824
  completed: number;
715
825
  totalRemaining: number;
716
826
  };
717
- analytics: Record<string, unknown>;
827
+ analytics: OutcomeAnalytics;
718
828
  }
719
829
  interface CreateOutcomeInput {
720
830
  name: string;
@@ -742,6 +852,9 @@ interface UnitTier {
742
852
  }
743
853
  interface Unit {
744
854
  id: string;
855
+ /** Stable per-org report key — what `signals.unit({ agentKey })` sends.
856
+ * The ONLY identifier accepted when reporting unit consumption. */
857
+ agentKey: string;
745
858
  name: string;
746
859
  description: string | null;
747
860
  pricingType: UnitPricingType;
@@ -749,10 +862,23 @@ interface Unit {
749
862
  tiers: UnitTier[];
750
863
  isActive: boolean;
751
864
  createdAt: string;
865
+ createdByName: string | null;
866
+ }
867
+ /** One row in a unit's linked-customer sample (`units.get().customers`). */
868
+ interface UnitCustomerRow {
869
+ customerId: string;
870
+ name: string;
871
+ legalName: string | null;
872
+ slug: string;
873
+ logoUrl: string | null;
874
+ granted: number;
875
+ used: number;
876
+ remaining: number;
877
+ currentlyMetered: boolean;
752
878
  }
753
- /** `units.get()` — adds linked-customer sample plus stats. */
879
+ /** `units.get()` — adds linked-customer sample plus stats.
880
+ * `createdByName` is inherited from `Unit`. */
754
881
  interface UnitDetail extends Unit {
755
- createdByName: string | null;
756
882
  stats: {
757
883
  planCount: number;
758
884
  customerCount: number;
@@ -760,7 +886,7 @@ interface UnitDetail extends Unit {
760
886
  totalUsed: number;
761
887
  };
762
888
  /** First page (≤10) of customers currently metered on this unit. */
763
- customers: Record<string, unknown>[];
889
+ customers: UnitCustomerRow[];
764
890
  }
765
891
  /** Flat per-event pricing — a single `flatPrice` (defaults to 0), no tiers. */
766
892
  interface FlatUnitInput {
@@ -802,6 +928,22 @@ interface UnitInput {
802
928
  agentKey: string;
803
929
  member?: string;
804
930
  }
931
+ /** One serialized unit-consumption event — the result of `signals.unit()` and
932
+ * each element of `UnitUsageList.events`. */
933
+ interface SerializedUnitUsage {
934
+ id: string;
935
+ customerId: string;
936
+ /** Display name of the unit. */
937
+ unit: string;
938
+ /** The unit's stable agent key; `null` if the unit was deleted. */
939
+ agentKey: string | null;
940
+ billingMode: BillingMode;
941
+ /** Remaining ADVANCE allowance after this event; `null` for ARREAR. */
942
+ remaining: number | null;
943
+ customerCost: number;
944
+ member: string | null;
945
+ createdAt: string;
946
+ }
805
947
  interface UnitUsageRow {
806
948
  unit: string;
807
949
  /** The unit's stable agent key — what to send to report against it. */
@@ -817,7 +959,7 @@ interface UnitUsageList {
817
959
  name: string;
818
960
  };
819
961
  units: UnitUsageRow[];
820
- events: unknown[];
962
+ events: SerializedUnitUsage[];
821
963
  }
822
964
  type ThresholdKind = "CREDIT" | "OUTCOME" | "WALLET";
823
965
  interface Webhook {
@@ -959,12 +1101,12 @@ declare class Credits {
959
1101
  list(params?: {
960
1102
  active?: boolean;
961
1103
  }): Promise<Credit[]>;
962
- /** Create a credit type. `POST /api/v1/credits`. */
963
- create(input: CreateCreditInput): Promise<void>;
1104
+ /** Create a credit type; returns the created credit. `POST /api/v1/credits`. */
1105
+ create(input: CreateCreditInput): Promise<Credit>;
964
1106
  /** Fetch one credit type with usage stats. `GET /api/v1/credits/:id`. */
965
1107
  get(id: string): Promise<CreditDetail>;
966
- /** Update a credit type's definition. `PATCH /api/v1/credits/:id`. */
967
- update(id: string, input: UpdateCreditInput): Promise<void>;
1108
+ /** Update a credit type's definition; returns the updated credit. `PATCH /api/v1/credits/:id`. */
1109
+ update(id: string, input: UpdateCreditInput): Promise<Credit>;
968
1110
  /** Activate or deactivate a credit type. */
969
1111
  setActive(id: string, isActive: boolean): Promise<Credit>;
970
1112
  /** Delete a credit type. Refused while a customer is linked to it. */
@@ -973,9 +1115,9 @@ declare class Credits {
973
1115
 
974
1116
  /**
975
1117
  * The `customers` resource — full CRUD over the org's customers plus the
976
- * read-only insight endpoints (usage / balances / plan / revenue). Every call
977
- * is scoped to the API key's organisation server-side; a customer in another
978
- * org resolves as a NotFoundError.
1118
+ * read-only insight endpoints (usage / balances / plan). Every call is scoped
1119
+ * to the API key's organisation server-side; a customer in another org
1120
+ * resolves as a NotFoundError.
979
1121
  */
980
1122
  declare class Customers {
981
1123
  private readonly transport;
@@ -1002,18 +1144,39 @@ declare class Customers {
1002
1144
  update(id: string, input: CustomerProfileInput): Promise<ApiCustomer>;
1003
1145
  /** Delete a customer (members, invitations, usage logs cascade). */
1004
1146
  delete(id: string): Promise<void>;
1005
- /** A customer's usage history. `GET /api/v1/customers/:id/usage`. */
1147
+ /** A customer's usage history. `GET /api/v1/usage?customerId=`. */
1006
1148
  usage(id: string, params?: {
1007
1149
  limit?: number;
1008
1150
  }): Promise<UsageList>;
1009
1151
  /** Wallet / credit / outcome / unit balances. `GET …/:id/balances`. */
1010
1152
  balances(id: string): Promise<CustomerBalances>;
1153
+ /**
1154
+ * One credit balance for a customer, matched by `creditId` or `creditName`;
1155
+ * `null` when the customer has no plan or no matching credit. Convenience
1156
+ * over `balances()` + `Array.find` — it fetches the FULL balances under the
1157
+ * hood (there is no server-side scoped read), so prefer `balances()` when you
1158
+ * need several rows from the same customer.
1159
+ */
1160
+ creditBalance(customerId: string, match: {
1161
+ creditId?: string;
1162
+ creditName?: string;
1163
+ }): Promise<CreditBalance | null>;
1164
+ /** One outcome balance for a customer, matched by `outcomeId` or
1165
+ * `outcomeName`; `null` when absent. See {@link creditBalance} for the
1166
+ * fetch-then-filter caveat. */
1167
+ outcomeBalance(customerId: string, match: {
1168
+ outcomeId?: string;
1169
+ outcomeName?: string;
1170
+ }): Promise<OutcomeBalance | null>;
1171
+ /** One unit balance for a customer, matched by `unitId` or `unitName`;
1172
+ * `null` when absent. See {@link creditBalance} for the fetch-then-filter
1173
+ * caveat. */
1174
+ unitBalance(customerId: string, match: {
1175
+ unitId?: string;
1176
+ unitName?: string;
1177
+ }): Promise<UnitBalance | null>;
1011
1178
  /** The customer's current plan. `GET …/:id/plan`. */
1012
1179
  plan(id: string): Promise<CustomerPlan>;
1013
- /** Revenue / cost / profit / margin over a window. `GET …/:id/revenue`. */
1014
- revenue(id: string, params?: {
1015
- range?: RevenueRange;
1016
- }): Promise<CustomerRevenue>;
1017
1180
  /** List a customer's members. `GET …/:id/members`. */
1018
1181
  listMembers(id: string): Promise<Member[]>;
1019
1182
  /** Add a member to a customer. Duplicate `employeeId` → ConflictError. */
@@ -1087,8 +1250,8 @@ declare class Outcomes {
1087
1250
  get(id: string): Promise<OutcomeDetail>;
1088
1251
  /** Update an outcome type's definition. `PATCH /api/v1/outcomes/:id`. */
1089
1252
  update(id: string, input: UpdateOutcomeInput): Promise<Outcome>;
1090
- /** Activate or deactivate an outcome type. */
1091
- setActive(id: string, isActive: boolean): Promise<void>;
1253
+ /** Activate or deactivate an outcome type; returns the updated outcome. */
1254
+ setActive(id: string, isActive: boolean): Promise<Outcome>;
1092
1255
  /** Delete an outcome type. */
1093
1256
  delete(id: string): Promise<void>;
1094
1257
  }
@@ -1263,7 +1426,7 @@ declare class Signals {
1263
1426
  * events are not buffered. `POST /api/v1/units`.
1264
1427
  */
1265
1428
  unit(input: UnitInput): Promise<{
1266
- unitUsage: Record<string, unknown>;
1429
+ unitUsage: SerializedUnitUsage;
1267
1430
  }>;
1268
1431
  /** A customer's unit balances + recent unit events. `GET /api/v1/units`. */
1269
1432
  unitUsage(params: {
@@ -1430,4 +1593,4 @@ declare class NetworkError extends ClockNextError {
1430
1593
  constructor(message: string);
1431
1594
  }
1432
1595
 
1433
- export { type AddMemberInput, AllowanceError, type ApiCustomer, AuthError, type BillingCycle, type BillingMode, ClockNext, type ClockNextConfig, ClockNextError, type ComponentType, ConflictError, type CreateCreditInput, type CreateCustomerInput, type CreateOutcomeInput, type CreatePlanInput, type CreatePurchaseInput, type CreateUnitInput, type Credit, type CreditAdjustInput, type CreditComponentInput, type CreditDetail, type CreditInput, type CreditSignal, type CustomerBalances, type CustomerList, type CustomerPlan, type CustomerProfileInput, type CustomerRevenue, type DropReason, type FetchLike, type FlatComponentInput, type FlatUnitInput, type Invoice, type InvoiceDetail, type InvoiceLineItem, type InvoiceListRow, type InvoiceParty, type InvoicePlanSnapshot, type InvoiceStatus, type Logger, type Member, type MemberRole, type Model, type ModelBundleEntry, NetworkError, NotFoundError, type Outcome, type OutcomeAdjustInput, 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 RevenueRange, type SerializedOutcomeAttribution, type SerializedRuleApplication, type SerializedUsageLog, ServerError, type Signal, type SignalStatus, type SignalType, type ThresholdKind, type TieredUnitInput, type Tokens, type TrackResult, type Unit, type UnitAdjustInput, type UnitComponentInput, type UnitDetail, type UnitInput, type UnitPricingType, type UnitTier, type UnitTierInput, type UnitUsageList, type UnitUsageRow, type UpdateCreditInput, type UpdateMemberInput, type UpdateOutcomeInput, type UpdatePlanInput, type UpdateUnitInput, type UpsertWebhookInput, type UsageList, ValidationError, type WalletComponentInput, type WalletEntryInput, type WalletInput, type WalletList, type WalletSignal, type WalletTransaction, type WalletTransactionType, type Webhook, type WorkspaceIdentity, signalToWire };
1596
+ export { type AddMemberInput, AllowanceError, type ApiCustomer, AuthError, type BillingCycle, type BillingMode, ClockNext, type ClockNextConfig, ClockNextError, type ComponentType, ConflictError, type CostPoint, type CostStats, 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, type Invoice, type InvoiceDetail, type InvoiceLineItem, type InvoiceListRow, type InvoiceParty, type InvoicePlanSnapshot, type InvoiceStatus, type Logger, type Member, type MemberRole, 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 SerializedOutcomeAttribution, type SerializedRuleApplication, type SerializedUnitUsage, type SerializedUsageLog, ServerError, type Signal, 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 UnitUsageList, type UnitUsageRow, type UpdateCreditInput, type UpdateMemberInput, type UpdateOutcomeInput, type UpdatePlanInput, type UpdateUnitInput, type UpsertWebhookInput, type UsageBalance, type UsageList, ValidationError, type WalletComponentInput, type WalletEntryInput, type WalletInput, type WalletList, type WalletSignal, type WalletTransaction, type WalletTransactionType, type Webhook, type WorkspaceIdentity, signalToWire };
package/dist/index.js CHANGED
@@ -227,7 +227,7 @@ function sleep(ms) {
227
227
  }
228
228
 
229
229
  // src/http.ts
230
- var SDK_VERSION = "0.4.0" ;
230
+ var SDK_VERSION = "0.5.0" ;
231
231
  var Transport = class {
232
232
  constructor(cfg) {
233
233
  this.cfg = cfg;
@@ -337,13 +337,14 @@ var Credits = class {
337
337
  });
338
338
  return res.credits;
339
339
  }
340
- /** Create a credit type. `POST /api/v1/credits`. */
340
+ /** Create a credit type; returns the created credit. `POST /api/v1/credits`. */
341
341
  async create(input) {
342
- await this.transport.request({
342
+ const res = await this.transport.request({
343
343
  method: "POST",
344
344
  path: "/api/v1/credits",
345
345
  body: input
346
346
  });
347
+ return res.credit;
347
348
  }
348
349
  /** Fetch one credit type with usage stats. `GET /api/v1/credits/:id`. */
349
350
  async get(id) {
@@ -353,13 +354,14 @@ var Credits = class {
353
354
  });
354
355
  return res.credit;
355
356
  }
356
- /** Update a credit type's definition. `PATCH /api/v1/credits/:id`. */
357
+ /** Update a credit type's definition; returns the updated credit. `PATCH /api/v1/credits/:id`. */
357
358
  async update(id, input) {
358
- await this.transport.request({
359
+ const res = await this.transport.request({
359
360
  method: "PATCH",
360
361
  path: `/api/v1/credits/${encodeURIComponent(id)}`,
361
362
  body: input
362
363
  });
364
+ return res.credit;
363
365
  }
364
366
  /** Activate or deactivate a credit type. */
365
367
  async setActive(id, isActive) {
@@ -439,12 +441,12 @@ var Customers = class {
439
441
  path: `/api/v1/customers/${encodeURIComponent(id)}`
440
442
  });
441
443
  }
442
- /** A customer's usage history. `GET /api/v1/customers/:id/usage`. */
444
+ /** A customer's usage history. `GET /api/v1/usage?customerId=`. */
443
445
  async usage(id, params = {}) {
444
446
  const res = await this.transport.request({
445
447
  method: "GET",
446
- path: `/api/v1/customers/${encodeURIComponent(id)}/usage`,
447
- query: { limit: params.limit }
448
+ path: `/api/v1/usage`,
449
+ query: { customerId: id, limit: params.limit }
448
450
  });
449
451
  return { customer: res.customer, totals: res.totals, logs: res.logs };
450
452
  }
@@ -455,6 +457,37 @@ var Customers = class {
455
457
  path: `/api/v1/customers/${encodeURIComponent(id)}/balances`
456
458
  });
457
459
  }
460
+ /**
461
+ * One credit balance for a customer, matched by `creditId` or `creditName`;
462
+ * `null` when the customer has no plan or no matching credit. Convenience
463
+ * over `balances()` + `Array.find` — it fetches the FULL balances under the
464
+ * hood (there is no server-side scoped read), so prefer `balances()` when you
465
+ * need several rows from the same customer.
466
+ */
467
+ async creditBalance(customerId, match) {
468
+ const { credits } = await this.balances(customerId);
469
+ return credits.find(
470
+ (c) => match.creditId != null && c.creditId === match.creditId || match.creditName != null && c.creditName === match.creditName
471
+ ) ?? null;
472
+ }
473
+ /** One outcome balance for a customer, matched by `outcomeId` or
474
+ * `outcomeName`; `null` when absent. See {@link creditBalance} for the
475
+ * fetch-then-filter caveat. */
476
+ async outcomeBalance(customerId, match) {
477
+ const { outcomes } = await this.balances(customerId);
478
+ return outcomes.find(
479
+ (o) => match.outcomeId != null && o.outcomeId === match.outcomeId || match.outcomeName != null && o.outcomeName === match.outcomeName
480
+ ) ?? null;
481
+ }
482
+ /** One unit balance for a customer, matched by `unitId` or `unitName`;
483
+ * `null` when absent. See {@link creditBalance} for the fetch-then-filter
484
+ * caveat. */
485
+ async unitBalance(customerId, match) {
486
+ const { units } = await this.balances(customerId);
487
+ return units.find(
488
+ (u) => match.unitId != null && u.unitId === match.unitId || match.unitName != null && u.unitName === match.unitName
489
+ ) ?? null;
490
+ }
458
491
  /** The customer's current plan. `GET …/:id/plan`. */
459
492
  plan(id) {
460
493
  return this.transport.request({
@@ -462,14 +495,6 @@ var Customers = class {
462
495
  path: `/api/v1/customers/${encodeURIComponent(id)}/plan`
463
496
  });
464
497
  }
465
- /** Revenue / cost / profit / margin over a window. `GET …/:id/revenue`. */
466
- revenue(id, params = {}) {
467
- return this.transport.request({
468
- method: "GET",
469
- path: `/api/v1/customers/${encodeURIComponent(id)}/revenue`,
470
- query: { range: params.range }
471
- });
472
- }
473
498
  // --- Members -------------------------------------------------------------
474
499
  /** List a customer's members. `GET …/:id/members`. */
475
500
  async listMembers(id) {
@@ -635,13 +660,14 @@ var Outcomes = class {
635
660
  });
636
661
  return res.outcome;
637
662
  }
638
- /** Activate or deactivate an outcome type. */
663
+ /** Activate or deactivate an outcome type; returns the updated outcome. */
639
664
  async setActive(id, isActive) {
640
- await this.transport.request({
665
+ const res = await this.transport.request({
641
666
  method: "PATCH",
642
667
  path: `/api/v1/outcomes/${encodeURIComponent(id)}`,
643
668
  body: { isActive }
644
669
  });
670
+ return res.outcome;
645
671
  }
646
672
  /** Delete an outcome type. */
647
673
  async delete(id) {