@clocknext/sdk 0.4.0 → 0.6.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.cjs +44 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +218 -56
- package/dist/index.d.ts +218 -56
- package/dist/index.js +44 -18
- package/dist/index.js.map +1 -1
- package/package.json +13 -5
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 }`). */
|
|
@@ -185,7 +200,6 @@ interface CustomerProfileInput {
|
|
|
185
200
|
taxId?: string | null;
|
|
186
201
|
notes?: string | null;
|
|
187
202
|
logoUrl?: string | null;
|
|
188
|
-
creditAllowance?: number;
|
|
189
203
|
/** ISO 4217 (3 letters); must be enabled for the org. */
|
|
190
204
|
currencyCode?: string;
|
|
191
205
|
}
|
|
@@ -198,10 +212,46 @@ interface CustomerList {
|
|
|
198
212
|
customers: ApiCustomer[];
|
|
199
213
|
nextCursor: string | null;
|
|
200
214
|
}
|
|
201
|
-
type
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
215
|
+
/** One credit type's running balance for a customer (an element of
|
|
216
|
+
* `customers.balances().credits`). */
|
|
217
|
+
interface CreditBalance {
|
|
218
|
+
creditId: string;
|
|
219
|
+
/** The credit's stable agent key — the same key used to record usage and to
|
|
220
|
+
* adjust this balance. */
|
|
221
|
+
agentKey: string;
|
|
222
|
+
creditName: string;
|
|
223
|
+
granted: number;
|
|
224
|
+
used: number;
|
|
225
|
+
remaining: number;
|
|
226
|
+
}
|
|
227
|
+
/** One outcome's running balance for a customer. Unlike a credit balance it
|
|
228
|
+
* has no `used`, and it carries the outcome's ordered step list. */
|
|
229
|
+
interface OutcomeBalance {
|
|
230
|
+
outcomeId: string;
|
|
231
|
+
outcomeName: string;
|
|
232
|
+
granted: number;
|
|
233
|
+
remaining: number;
|
|
234
|
+
/** Each step's `agentKey` is what `signals.outcome()` and the outcome adjust
|
|
235
|
+
* API use to address this outcome (outcomes have no key of their own). */
|
|
236
|
+
steps: {
|
|
237
|
+
id: string;
|
|
238
|
+
name: string;
|
|
239
|
+
agentKey: string;
|
|
240
|
+
}[];
|
|
241
|
+
}
|
|
242
|
+
/** One unit's advance allowance for a customer. No `used` field. */
|
|
243
|
+
interface UnitBalance {
|
|
244
|
+
unitId: string;
|
|
245
|
+
/** The unit's stable agent key — the same key used to record usage and to
|
|
246
|
+
* adjust this balance. */
|
|
247
|
+
agentKey: string;
|
|
248
|
+
unitName: string;
|
|
249
|
+
granted: number;
|
|
250
|
+
remaining: number;
|
|
251
|
+
}
|
|
252
|
+
/** Wallet / credit / outcome / unit balances for a customer's active plan
|
|
253
|
+
* (`customers.balances()`). */
|
|
254
|
+
interface CustomerBalances {
|
|
205
255
|
customerId: string;
|
|
206
256
|
currency: {
|
|
207
257
|
code: string;
|
|
@@ -211,34 +261,40 @@ type CustomerBalances = {
|
|
|
211
261
|
wallet: {
|
|
212
262
|
balanceUsd: number;
|
|
213
263
|
} | null;
|
|
214
|
-
credits:
|
|
215
|
-
outcomes:
|
|
216
|
-
units:
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
264
|
+
credits: CreditBalance[];
|
|
265
|
+
outcomes: OutcomeBalance[];
|
|
266
|
+
units: UnitBalance[];
|
|
267
|
+
}
|
|
268
|
+
/** The customer's active plan (the `plan` field of `customers.plan()`);
|
|
269
|
+
* `null` when the customer is unsubscribed. */
|
|
270
|
+
interface CustomerPlanDetails {
|
|
271
|
+
purchaseId: string;
|
|
272
|
+
planId: string | null;
|
|
273
|
+
planName: string;
|
|
274
|
+
planType: PlanType;
|
|
275
|
+
planKind: PlanKind;
|
|
276
|
+
seatScope: "CUSTOMER" | "MEMBER" | null;
|
|
277
|
+
billingCycle: BillingCycle;
|
|
278
|
+
cost: number;
|
|
279
|
+
status: "SCHEDULED" | "ACTIVE";
|
|
280
|
+
billingDate: string;
|
|
281
|
+
spendingLimit: number | null;
|
|
282
|
+
spentThisCycle: number | null;
|
|
283
|
+
meters: {
|
|
284
|
+
wallet: boolean;
|
|
285
|
+
credit: boolean;
|
|
286
|
+
outcome: boolean;
|
|
287
|
+
unit: boolean;
|
|
223
288
|
};
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
type CustomerRevenue = {
|
|
289
|
+
}
|
|
290
|
+
interface CustomerPlan {
|
|
227
291
|
customerId: string;
|
|
228
|
-
range: RevenueRange;
|
|
229
|
-
window: unknown;
|
|
230
|
-
bucket: unknown;
|
|
231
292
|
currency: {
|
|
232
293
|
code: string;
|
|
233
294
|
rateUsd: number;
|
|
234
295
|
};
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
profit: number;
|
|
238
|
-
grossMargin: number;
|
|
239
|
-
deltas: Record<string, unknown>;
|
|
240
|
-
trend: unknown[];
|
|
241
|
-
};
|
|
296
|
+
plan: CustomerPlanDetails | null;
|
|
297
|
+
}
|
|
242
298
|
interface PortalTokenInput {
|
|
243
299
|
customerId: string;
|
|
244
300
|
ttlSeconds?: number;
|
|
@@ -354,6 +410,8 @@ interface Plan {
|
|
|
354
410
|
kind: PlanKind;
|
|
355
411
|
billingCycle: BillingCycle;
|
|
356
412
|
cost: number;
|
|
413
|
+
/** Signed adjustment applied to the plan's headline price (default 0). */
|
|
414
|
+
priceAdjustment: number;
|
|
357
415
|
currencyCode: string;
|
|
358
416
|
isActive: boolean;
|
|
359
417
|
components: PlanComponent[];
|
|
@@ -364,6 +422,7 @@ interface PlanDetail extends Plan {
|
|
|
364
422
|
createdByName: string | null;
|
|
365
423
|
customerCount: number;
|
|
366
424
|
invoiceCount: number;
|
|
425
|
+
openInvoiceCount: number;
|
|
367
426
|
stats: {
|
|
368
427
|
totalInvoiced: number;
|
|
369
428
|
totalCollected: number;
|
|
@@ -386,6 +445,7 @@ interface Purchase {
|
|
|
386
445
|
purchaseNumber: string;
|
|
387
446
|
customerId: string;
|
|
388
447
|
customerName: string;
|
|
448
|
+
customerLogoUrl: string | null;
|
|
389
449
|
planId: string | null;
|
|
390
450
|
planName: string;
|
|
391
451
|
planType: PlanType;
|
|
@@ -397,9 +457,12 @@ interface Purchase {
|
|
|
397
457
|
cost: number;
|
|
398
458
|
currencyCode: string;
|
|
399
459
|
billingDate: string;
|
|
460
|
+
nextBillingDate: string;
|
|
400
461
|
status: PurchaseStatus;
|
|
462
|
+
voidAfterMinutes: number;
|
|
401
463
|
autoPayment: boolean;
|
|
402
464
|
autoPaymentPauseReason: string | null;
|
|
465
|
+
notes: string | null;
|
|
403
466
|
createdAt: string;
|
|
404
467
|
}
|
|
405
468
|
/** The purchase returned by `purchases.get()` — a different, detail-oriented shape. */
|
|
@@ -417,7 +480,10 @@ interface PurchaseDetail {
|
|
|
417
480
|
customer: {
|
|
418
481
|
id: string;
|
|
419
482
|
name: string;
|
|
483
|
+
logoUrl: string | null;
|
|
420
484
|
};
|
|
485
|
+
voidAfterMinutes: number;
|
|
486
|
+
notes: string | null;
|
|
421
487
|
autoPayment: boolean;
|
|
422
488
|
autoPaymentPauseReason: string | null;
|
|
423
489
|
autoPaymentPausedAt: string | null;
|
|
@@ -612,21 +678,28 @@ interface WalletEntryInput {
|
|
|
612
678
|
amount: number;
|
|
613
679
|
notes?: string;
|
|
614
680
|
}
|
|
615
|
-
/** Grant (positive) or claw back (negative) a credit balance. `delta` must be a
|
|
681
|
+
/** Grant (positive) or claw back (negative) a credit balance. `delta` must be a
|
|
682
|
+
* non-zero whole number. The credit is addressed by its stable `agentKey`. */
|
|
616
683
|
interface CreditAdjustInput {
|
|
617
|
-
|
|
684
|
+
/** The credit's stable agent key (the same key used to record usage). */
|
|
685
|
+
agentKey: string;
|
|
618
686
|
delta: number;
|
|
619
687
|
notes?: string;
|
|
620
688
|
}
|
|
621
|
-
/** Grant/claw an outcome balance. `delta` is a non-zero whole number; floored at
|
|
689
|
+
/** Grant/claw an outcome balance. `delta` is a non-zero whole number; floored at
|
|
690
|
+
* 0. The outcome is addressed by a STEP's `agentKey` (outcomes have no key of
|
|
691
|
+
* their own). */
|
|
622
692
|
interface OutcomeAdjustInput {
|
|
623
|
-
|
|
693
|
+
/** An outcome step's stable agent key — identifies the parent outcome. */
|
|
694
|
+
agentKey: string;
|
|
624
695
|
delta: number;
|
|
625
696
|
notes?: string;
|
|
626
697
|
}
|
|
627
|
-
/** Grant/claw a unit balance. `delta` is non-zero (fractional allowed); floored
|
|
698
|
+
/** Grant/claw a unit balance. `delta` is non-zero (fractional allowed); floored
|
|
699
|
+
* at 0. The unit is addressed by its stable `agentKey`. */
|
|
628
700
|
interface UnitAdjustInput {
|
|
629
|
-
|
|
701
|
+
/** The unit's stable agent key (the same key used to record usage). */
|
|
702
|
+
agentKey: string;
|
|
630
703
|
delta: number;
|
|
631
704
|
notes?: string;
|
|
632
705
|
}
|
|
@@ -640,6 +713,43 @@ interface ModelBundleEntry {
|
|
|
640
713
|
output: number;
|
|
641
714
|
cache: number;
|
|
642
715
|
}
|
|
716
|
+
/** One point on a cost-over-time analytics series. */
|
|
717
|
+
interface CostPoint {
|
|
718
|
+
/** UTC day, `YYYY-MM-DD`. */
|
|
719
|
+
dateIso: string;
|
|
720
|
+
/** Short display label, e.g. "Jun 24". */
|
|
721
|
+
label: string;
|
|
722
|
+
/** Average cost that day, or `null` on days with no usage. */
|
|
723
|
+
cost: number | null;
|
|
724
|
+
reqs: number;
|
|
725
|
+
}
|
|
726
|
+
/** Summary stats across a cost-over-time series. */
|
|
727
|
+
interface CostStats {
|
|
728
|
+
activeDays: number;
|
|
729
|
+
avgCost: number | null;
|
|
730
|
+
peakCost: number | null;
|
|
731
|
+
troughCost: number | null;
|
|
732
|
+
deviationPct: number | null;
|
|
733
|
+
}
|
|
734
|
+
/** Cost-over-time analytics for a credit (`credits.get().analytics`). */
|
|
735
|
+
interface CreditAnalytics {
|
|
736
|
+
basePrice: number;
|
|
737
|
+
pricePerCredit: number;
|
|
738
|
+
marginPercent: number;
|
|
739
|
+
points: CostPoint[];
|
|
740
|
+
stats: CostStats;
|
|
741
|
+
}
|
|
742
|
+
/** Cost-over-time analytics for an outcome (`outcomes.get().analytics`).
|
|
743
|
+
* Each point adds `completions` (workflows finished that day). */
|
|
744
|
+
interface OutcomeAnalytics {
|
|
745
|
+
basePrice: number;
|
|
746
|
+
pricePerOutcome: number;
|
|
747
|
+
marginPercent: number;
|
|
748
|
+
points: (CostPoint & {
|
|
749
|
+
completions: number;
|
|
750
|
+
})[];
|
|
751
|
+
stats: CostStats;
|
|
752
|
+
}
|
|
643
753
|
interface Credit {
|
|
644
754
|
id: string;
|
|
645
755
|
name: string;
|
|
@@ -664,8 +774,7 @@ interface CreditDetail extends Credit {
|
|
|
664
774
|
revenue: number;
|
|
665
775
|
usageLogCount: number;
|
|
666
776
|
};
|
|
667
|
-
|
|
668
|
-
analytics: Record<string, unknown>;
|
|
777
|
+
analytics: CreditAnalytics;
|
|
669
778
|
}
|
|
670
779
|
interface CreateCreditInput {
|
|
671
780
|
name: string;
|
|
@@ -714,7 +823,7 @@ interface OutcomeDetail extends Outcome {
|
|
|
714
823
|
completed: number;
|
|
715
824
|
totalRemaining: number;
|
|
716
825
|
};
|
|
717
|
-
analytics:
|
|
826
|
+
analytics: OutcomeAnalytics;
|
|
718
827
|
}
|
|
719
828
|
interface CreateOutcomeInput {
|
|
720
829
|
name: string;
|
|
@@ -742,6 +851,9 @@ interface UnitTier {
|
|
|
742
851
|
}
|
|
743
852
|
interface Unit {
|
|
744
853
|
id: string;
|
|
854
|
+
/** Stable per-org report key — what `signals.unit({ agentKey })` sends.
|
|
855
|
+
* The ONLY identifier accepted when reporting unit consumption. */
|
|
856
|
+
agentKey: string;
|
|
745
857
|
name: string;
|
|
746
858
|
description: string | null;
|
|
747
859
|
pricingType: UnitPricingType;
|
|
@@ -749,10 +861,23 @@ interface Unit {
|
|
|
749
861
|
tiers: UnitTier[];
|
|
750
862
|
isActive: boolean;
|
|
751
863
|
createdAt: string;
|
|
864
|
+
createdByName: string | null;
|
|
865
|
+
}
|
|
866
|
+
/** One row in a unit's linked-customer sample (`units.get().customers`). */
|
|
867
|
+
interface UnitCustomerRow {
|
|
868
|
+
customerId: string;
|
|
869
|
+
name: string;
|
|
870
|
+
legalName: string | null;
|
|
871
|
+
slug: string;
|
|
872
|
+
logoUrl: string | null;
|
|
873
|
+
granted: number;
|
|
874
|
+
used: number;
|
|
875
|
+
remaining: number;
|
|
876
|
+
currentlyMetered: boolean;
|
|
752
877
|
}
|
|
753
|
-
/** `units.get()` — adds linked-customer sample plus stats.
|
|
878
|
+
/** `units.get()` — adds linked-customer sample plus stats.
|
|
879
|
+
* `createdByName` is inherited from `Unit`. */
|
|
754
880
|
interface UnitDetail extends Unit {
|
|
755
|
-
createdByName: string | null;
|
|
756
881
|
stats: {
|
|
757
882
|
planCount: number;
|
|
758
883
|
customerCount: number;
|
|
@@ -760,7 +885,7 @@ interface UnitDetail extends Unit {
|
|
|
760
885
|
totalUsed: number;
|
|
761
886
|
};
|
|
762
887
|
/** First page (≤10) of customers currently metered on this unit. */
|
|
763
|
-
customers:
|
|
888
|
+
customers: UnitCustomerRow[];
|
|
764
889
|
}
|
|
765
890
|
/** Flat per-event pricing — a single `flatPrice` (defaults to 0), no tiers. */
|
|
766
891
|
interface FlatUnitInput {
|
|
@@ -802,6 +927,22 @@ interface UnitInput {
|
|
|
802
927
|
agentKey: string;
|
|
803
928
|
member?: string;
|
|
804
929
|
}
|
|
930
|
+
/** One serialized unit-consumption event — the result of `signals.unit()` and
|
|
931
|
+
* each element of `UnitUsageList.events`. */
|
|
932
|
+
interface SerializedUnitUsage {
|
|
933
|
+
id: string;
|
|
934
|
+
customerId: string;
|
|
935
|
+
/** Display name of the unit. */
|
|
936
|
+
unit: string;
|
|
937
|
+
/** The unit's stable agent key; `null` if the unit was deleted. */
|
|
938
|
+
agentKey: string | null;
|
|
939
|
+
billingMode: BillingMode;
|
|
940
|
+
/** Remaining ADVANCE allowance after this event; `null` for ARREAR. */
|
|
941
|
+
remaining: number | null;
|
|
942
|
+
customerCost: number;
|
|
943
|
+
member: string | null;
|
|
944
|
+
createdAt: string;
|
|
945
|
+
}
|
|
805
946
|
interface UnitUsageRow {
|
|
806
947
|
unit: string;
|
|
807
948
|
/** The unit's stable agent key — what to send to report against it. */
|
|
@@ -817,7 +958,7 @@ interface UnitUsageList {
|
|
|
817
958
|
name: string;
|
|
818
959
|
};
|
|
819
960
|
units: UnitUsageRow[];
|
|
820
|
-
events:
|
|
961
|
+
events: SerializedUnitUsage[];
|
|
821
962
|
}
|
|
822
963
|
type ThresholdKind = "CREDIT" | "OUTCOME" | "WALLET";
|
|
823
964
|
interface Webhook {
|
|
@@ -959,12 +1100,12 @@ declare class Credits {
|
|
|
959
1100
|
list(params?: {
|
|
960
1101
|
active?: boolean;
|
|
961
1102
|
}): Promise<Credit[]>;
|
|
962
|
-
/** Create a credit type. `POST /api/v1/credits`. */
|
|
963
|
-
create(input: CreateCreditInput): Promise<
|
|
1103
|
+
/** Create a credit type; returns the created credit. `POST /api/v1/credits`. */
|
|
1104
|
+
create(input: CreateCreditInput): Promise<Credit>;
|
|
964
1105
|
/** Fetch one credit type with usage stats. `GET /api/v1/credits/:id`. */
|
|
965
1106
|
get(id: string): Promise<CreditDetail>;
|
|
966
|
-
/** Update a credit type's definition. `PATCH /api/v1/credits/:id`. */
|
|
967
|
-
update(id: string, input: UpdateCreditInput): Promise<
|
|
1107
|
+
/** Update a credit type's definition; returns the updated credit. `PATCH /api/v1/credits/:id`. */
|
|
1108
|
+
update(id: string, input: UpdateCreditInput): Promise<Credit>;
|
|
968
1109
|
/** Activate or deactivate a credit type. */
|
|
969
1110
|
setActive(id: string, isActive: boolean): Promise<Credit>;
|
|
970
1111
|
/** Delete a credit type. Refused while a customer is linked to it. */
|
|
@@ -973,9 +1114,9 @@ declare class Credits {
|
|
|
973
1114
|
|
|
974
1115
|
/**
|
|
975
1116
|
* The `customers` resource — full CRUD over the org's customers plus the
|
|
976
|
-
* read-only insight endpoints (usage / balances / plan
|
|
977
|
-
*
|
|
978
|
-
*
|
|
1117
|
+
* read-only insight endpoints (usage / balances / plan). Every call is scoped
|
|
1118
|
+
* to the API key's organisation server-side; a customer in another org
|
|
1119
|
+
* resolves as a NotFoundError.
|
|
979
1120
|
*/
|
|
980
1121
|
declare class Customers {
|
|
981
1122
|
private readonly transport;
|
|
@@ -1002,18 +1143,39 @@ declare class Customers {
|
|
|
1002
1143
|
update(id: string, input: CustomerProfileInput): Promise<ApiCustomer>;
|
|
1003
1144
|
/** Delete a customer (members, invitations, usage logs cascade). */
|
|
1004
1145
|
delete(id: string): Promise<void>;
|
|
1005
|
-
/** A customer's usage history. `GET /api/v1/
|
|
1146
|
+
/** A customer's usage history. `GET /api/v1/usage?customerId=`. */
|
|
1006
1147
|
usage(id: string, params?: {
|
|
1007
1148
|
limit?: number;
|
|
1008
1149
|
}): Promise<UsageList>;
|
|
1009
1150
|
/** Wallet / credit / outcome / unit balances. `GET …/:id/balances`. */
|
|
1010
1151
|
balances(id: string): Promise<CustomerBalances>;
|
|
1152
|
+
/**
|
|
1153
|
+
* One credit balance for a customer, matched by `creditId` or `creditName`;
|
|
1154
|
+
* `null` when the customer has no plan or no matching credit. Convenience
|
|
1155
|
+
* over `balances()` + `Array.find` — it fetches the FULL balances under the
|
|
1156
|
+
* hood (there is no server-side scoped read), so prefer `balances()` when you
|
|
1157
|
+
* need several rows from the same customer.
|
|
1158
|
+
*/
|
|
1159
|
+
creditBalance(customerId: string, match: {
|
|
1160
|
+
creditId?: string;
|
|
1161
|
+
creditName?: string;
|
|
1162
|
+
}): Promise<CreditBalance | null>;
|
|
1163
|
+
/** One outcome balance for a customer, matched by `outcomeId` or
|
|
1164
|
+
* `outcomeName`; `null` when absent. See {@link creditBalance} for the
|
|
1165
|
+
* fetch-then-filter caveat. */
|
|
1166
|
+
outcomeBalance(customerId: string, match: {
|
|
1167
|
+
outcomeId?: string;
|
|
1168
|
+
outcomeName?: string;
|
|
1169
|
+
}): Promise<OutcomeBalance | null>;
|
|
1170
|
+
/** One unit balance for a customer, matched by `unitId` or `unitName`;
|
|
1171
|
+
* `null` when absent. See {@link creditBalance} for the fetch-then-filter
|
|
1172
|
+
* caveat. */
|
|
1173
|
+
unitBalance(customerId: string, match: {
|
|
1174
|
+
unitId?: string;
|
|
1175
|
+
unitName?: string;
|
|
1176
|
+
}): Promise<UnitBalance | null>;
|
|
1011
1177
|
/** The customer's current plan. `GET …/:id/plan`. */
|
|
1012
1178
|
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
1179
|
/** List a customer's members. `GET …/:id/members`. */
|
|
1018
1180
|
listMembers(id: string): Promise<Member[]>;
|
|
1019
1181
|
/** Add a member to a customer. Duplicate `employeeId` → ConflictError. */
|
|
@@ -1087,8 +1249,8 @@ declare class Outcomes {
|
|
|
1087
1249
|
get(id: string): Promise<OutcomeDetail>;
|
|
1088
1250
|
/** Update an outcome type's definition. `PATCH /api/v1/outcomes/:id`. */
|
|
1089
1251
|
update(id: string, input: UpdateOutcomeInput): Promise<Outcome>;
|
|
1090
|
-
/** Activate or deactivate an outcome type. */
|
|
1091
|
-
setActive(id: string, isActive: boolean): Promise<
|
|
1252
|
+
/** Activate or deactivate an outcome type; returns the updated outcome. */
|
|
1253
|
+
setActive(id: string, isActive: boolean): Promise<Outcome>;
|
|
1092
1254
|
/** Delete an outcome type. */
|
|
1093
1255
|
delete(id: string): Promise<void>;
|
|
1094
1256
|
}
|
|
@@ -1263,7 +1425,7 @@ declare class Signals {
|
|
|
1263
1425
|
* events are not buffered. `POST /api/v1/units`.
|
|
1264
1426
|
*/
|
|
1265
1427
|
unit(input: UnitInput): Promise<{
|
|
1266
|
-
unitUsage:
|
|
1428
|
+
unitUsage: SerializedUnitUsage;
|
|
1267
1429
|
}>;
|
|
1268
1430
|
/** A customer's unit balances + recent unit events. `GET /api/v1/units`. */
|
|
1269
1431
|
unitUsage(params: {
|
|
@@ -1430,4 +1592,4 @@ declare class NetworkError extends ClockNextError {
|
|
|
1430
1592
|
constructor(message: string);
|
|
1431
1593
|
}
|
|
1432
1594
|
|
|
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
|
|
1595
|
+
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.
|
|
230
|
+
var SDK_VERSION = "0.6.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/
|
|
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/
|
|
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) {
|