@chatarmin/os 1.0.2 → 1.1.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 +205 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +114 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -113,7 +113,7 @@ export interface FeatureSetAccessInput {
|
|
|
113
113
|
validUntil?: Date | null;
|
|
114
114
|
}
|
|
115
115
|
/**
|
|
116
|
-
* Input for tracking feature usage.
|
|
116
|
+
* Input for tracking feature usage (increment operation).
|
|
117
117
|
*/
|
|
118
118
|
export interface TrackUsageInput {
|
|
119
119
|
/** Company ID */
|
|
@@ -121,7 +121,7 @@ export interface TrackUsageInput {
|
|
|
121
121
|
/** Feature code to track */
|
|
122
122
|
featureCode: string;
|
|
123
123
|
/**
|
|
124
|
-
* Quantity to track.
|
|
124
|
+
* Quantity to track (must be positive).
|
|
125
125
|
* @default 1
|
|
126
126
|
*/
|
|
127
127
|
quantity?: number;
|
|
@@ -130,9 +130,67 @@ export interface TrackUsageInput {
|
|
|
130
130
|
* Use a unique ID per operation (e.g., message ID).
|
|
131
131
|
*/
|
|
132
132
|
idempotencyKey?: string;
|
|
133
|
-
/**
|
|
133
|
+
/**
|
|
134
|
+
* Additional metadata for the usage event.
|
|
135
|
+
* Store external references here (e.g., { externalId: "msg_123", type: "message" })
|
|
136
|
+
*/
|
|
137
|
+
metadata?: Record<string, unknown>;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Input for setting usage to an absolute value.
|
|
141
|
+
* Use for corrections when you know what the total usage SHOULD be.
|
|
142
|
+
*/
|
|
143
|
+
export interface SetUsageInput {
|
|
144
|
+
/** Company ID */
|
|
145
|
+
companyId: string;
|
|
146
|
+
/** Feature code */
|
|
147
|
+
featureCode: string;
|
|
148
|
+
/** The absolute value to set usage to (must be >= 0) */
|
|
149
|
+
absoluteValue: number;
|
|
150
|
+
/** Reason for the set operation (required for audit trail) */
|
|
151
|
+
reason: string;
|
|
152
|
+
/** Admin user who performed the operation */
|
|
153
|
+
performedBy?: string;
|
|
154
|
+
/** Additional metadata (e.g., { ticketId: "SUPPORT-123" }) */
|
|
155
|
+
metadata?: Record<string, unknown>;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Input for adjusting usage by a delta.
|
|
159
|
+
* Use for explicit corrections - supports negative values for refunds.
|
|
160
|
+
*/
|
|
161
|
+
export interface AdjustUsageInput {
|
|
162
|
+
/** Company ID */
|
|
163
|
+
companyId: string;
|
|
164
|
+
/** Feature code */
|
|
165
|
+
featureCode: string;
|
|
166
|
+
/** The delta to apply (can be negative for refunds) */
|
|
167
|
+
delta: number;
|
|
168
|
+
/** Reason for the adjustment (required for audit trail) */
|
|
169
|
+
reason: string;
|
|
170
|
+
/** Reference to original event being adjusted (for Stripe cancellations) */
|
|
171
|
+
adjustsEventId?: string;
|
|
172
|
+
/** Admin user who performed the operation */
|
|
173
|
+
performedBy?: string;
|
|
174
|
+
/** Additional metadata (e.g., { ticketId: "REFUND-456" }) */
|
|
134
175
|
metadata?: Record<string, unknown>;
|
|
135
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* Result from usage operations (track, set, adjust).
|
|
179
|
+
*/
|
|
180
|
+
export interface UsageResult {
|
|
181
|
+
success: boolean;
|
|
182
|
+
featureCode: string;
|
|
183
|
+
previousUsage: number;
|
|
184
|
+
currentUsage: number;
|
|
185
|
+
delta: number;
|
|
186
|
+
quantityLimit: number | null;
|
|
187
|
+
remaining: number | null;
|
|
188
|
+
isAtLimit: boolean;
|
|
189
|
+
includedQuantity: number;
|
|
190
|
+
billableQuantity: number;
|
|
191
|
+
meterId: string;
|
|
192
|
+
eventId: string | null;
|
|
193
|
+
}
|
|
136
194
|
/**
|
|
137
195
|
* Input for claiming a Stripe checkout subscription.
|
|
138
196
|
*/
|
|
@@ -401,11 +459,11 @@ export declare class ChatarminOS {
|
|
|
401
459
|
getByProductLink: (input: {
|
|
402
460
|
externalOrgId: string;
|
|
403
461
|
}) => Promise<{
|
|
462
|
+
external_org_id: string;
|
|
463
|
+
external_user_id: string | null;
|
|
404
464
|
name: string;
|
|
405
465
|
id: string;
|
|
406
466
|
domain: string | null;
|
|
407
|
-
external_org_id: string;
|
|
408
|
-
external_user_id: string | null;
|
|
409
467
|
} | null>;
|
|
410
468
|
/**
|
|
411
469
|
* Create a new company and link it to your product.
|
|
@@ -563,8 +621,8 @@ export declare class ChatarminOS {
|
|
|
563
621
|
created_at: Date;
|
|
564
622
|
updated_at: Date;
|
|
565
623
|
company_id: string | null;
|
|
566
|
-
short_id: string | null;
|
|
567
624
|
is_primary: boolean;
|
|
625
|
+
short_id: string | null;
|
|
568
626
|
avatar_url: string | null;
|
|
569
627
|
}>;
|
|
570
628
|
/**
|
|
@@ -619,8 +677,8 @@ export declare class ChatarminOS {
|
|
|
619
677
|
created_at: Date;
|
|
620
678
|
updated_at: Date;
|
|
621
679
|
company_id: string | null;
|
|
622
|
-
short_id: string | null;
|
|
623
680
|
is_primary: boolean;
|
|
681
|
+
short_id: string | null;
|
|
624
682
|
avatar_url: string | null;
|
|
625
683
|
}[]>;
|
|
626
684
|
};
|
|
@@ -923,6 +981,142 @@ export declare class ChatarminOS {
|
|
|
923
981
|
billableQuantity: number;
|
|
924
982
|
meterId: string;
|
|
925
983
|
}>;
|
|
984
|
+
/**
|
|
985
|
+
* Set usage to an absolute value.
|
|
986
|
+
*
|
|
987
|
+
* Use this for corrections when you know what the total usage SHOULD be.
|
|
988
|
+
* Creates a snapshot for audit trail. The delta (difference) is calculated
|
|
989
|
+
* automatically and synced to Stripe.
|
|
990
|
+
*
|
|
991
|
+
* @param input - Set usage parameters
|
|
992
|
+
* @returns Result with previous and new usage values
|
|
993
|
+
*
|
|
994
|
+
* @example Correct usage to 100 (was 150)
|
|
995
|
+
* ```typescript
|
|
996
|
+
* const result = await os.billing.setUsage({
|
|
997
|
+
* companyId: 'comp_xxx',
|
|
998
|
+
* featureCode: 'ai_credit',
|
|
999
|
+
* absoluteValue: 100,
|
|
1000
|
+
* reason: 'Corrected after customer support review',
|
|
1001
|
+
* performedBy: 'admin@company.com'
|
|
1002
|
+
* })
|
|
1003
|
+
*
|
|
1004
|
+
* console.log({
|
|
1005
|
+
* previousUsage: result.previousUsage, // 150
|
|
1006
|
+
* currentUsage: result.currentUsage, // 100
|
|
1007
|
+
* delta: result.delta // -50
|
|
1008
|
+
* })
|
|
1009
|
+
* ```
|
|
1010
|
+
*/
|
|
1011
|
+
setUsage: (input: SetUsageInput) => Promise<UsageResult>;
|
|
1012
|
+
/**
|
|
1013
|
+
* Adjust usage by a delta (positive or negative).
|
|
1014
|
+
*
|
|
1015
|
+
* Use this for explicit corrections. Supports negative values for
|
|
1016
|
+
* refunds or error corrections. Creates an audit trail and syncs
|
|
1017
|
+
* to Stripe (including meter event adjustments when possible).
|
|
1018
|
+
*
|
|
1019
|
+
* @param input - Adjustment parameters
|
|
1020
|
+
* @returns Result with previous and new usage values
|
|
1021
|
+
*
|
|
1022
|
+
* @example Refund 50 units
|
|
1023
|
+
* ```typescript
|
|
1024
|
+
* const result = await os.billing.adjustUsage({
|
|
1025
|
+
* companyId: 'comp_xxx',
|
|
1026
|
+
* featureCode: 'ai_credit',
|
|
1027
|
+
* delta: -50,
|
|
1028
|
+
* reason: 'Refund for failed API calls',
|
|
1029
|
+
* performedBy: 'support@company.com'
|
|
1030
|
+
* })
|
|
1031
|
+
* ```
|
|
1032
|
+
*
|
|
1033
|
+
* @example Add bonus units
|
|
1034
|
+
* ```typescript
|
|
1035
|
+
* const result = await os.billing.adjustUsage({
|
|
1036
|
+
* companyId: 'comp_xxx',
|
|
1037
|
+
* featureCode: 'ai_credit',
|
|
1038
|
+
* delta: 100,
|
|
1039
|
+
* reason: 'Promotional bonus for beta testers'
|
|
1040
|
+
* })
|
|
1041
|
+
* ```
|
|
1042
|
+
*/
|
|
1043
|
+
adjustUsage: (input: AdjustUsageInput) => Promise<UsageResult>;
|
|
1044
|
+
/**
|
|
1045
|
+
* Get usage event history for a feature.
|
|
1046
|
+
*
|
|
1047
|
+
* Returns the history of usage events including increments, sets,
|
|
1048
|
+
* and adjustments. Useful for auditing and debugging.
|
|
1049
|
+
*
|
|
1050
|
+
* @param companyId - Company ID
|
|
1051
|
+
* @param featureCode - Feature code to get history for
|
|
1052
|
+
* @param options - Query options
|
|
1053
|
+
* @returns Array of usage events
|
|
1054
|
+
*
|
|
1055
|
+
* @example
|
|
1056
|
+
* ```typescript
|
|
1057
|
+
* const history = await os.billing.getUsageHistory(
|
|
1058
|
+
* 'comp_xxx',
|
|
1059
|
+
* 'ai_credit',
|
|
1060
|
+
* { limit: 20, eventType: 'adjustment' }
|
|
1061
|
+
* )
|
|
1062
|
+
*
|
|
1063
|
+
* for (const event of history) {
|
|
1064
|
+
* console.log(`${event.event_type}: ${event.quantity} at ${event.event_time}`)
|
|
1065
|
+
* if (event.adjustment_reason) {
|
|
1066
|
+
* console.log(` Reason: ${event.adjustment_reason}`)
|
|
1067
|
+
* }
|
|
1068
|
+
* }
|
|
1069
|
+
* ```
|
|
1070
|
+
*/
|
|
1071
|
+
getUsageHistory: (companyId: string, featureCode: string, options?: {
|
|
1072
|
+
limit?: number;
|
|
1073
|
+
includeDelivered?: boolean;
|
|
1074
|
+
eventType?: "increment" | "set" | "adjustment";
|
|
1075
|
+
}) => Promise<{
|
|
1076
|
+
id: string;
|
|
1077
|
+
metadata: unknown;
|
|
1078
|
+
quantity: number;
|
|
1079
|
+
source: string;
|
|
1080
|
+
created_at: Date;
|
|
1081
|
+
company_id: string;
|
|
1082
|
+
billing_profile_id: string;
|
|
1083
|
+
meter_code: string;
|
|
1084
|
+
available_product_id: string;
|
|
1085
|
+
event_time: Date;
|
|
1086
|
+
event_type: string;
|
|
1087
|
+
previous_value: number | null;
|
|
1088
|
+
adjustment_reason: string | null;
|
|
1089
|
+
adjusts_event_id: string | null;
|
|
1090
|
+
idempotency_key: string;
|
|
1091
|
+
stripe_delivery_status: string;
|
|
1092
|
+
stripe_event_id: string | null;
|
|
1093
|
+
stripe_delivery_error: string | null;
|
|
1094
|
+
delivered_at: Date | null;
|
|
1095
|
+
}[]>;
|
|
1096
|
+
/**
|
|
1097
|
+
* Get usage snapshots for a feature.
|
|
1098
|
+
*
|
|
1099
|
+
* Returns audit snapshots created by set operations and reconciliations.
|
|
1100
|
+
* Useful for understanding historical usage corrections.
|
|
1101
|
+
*
|
|
1102
|
+
* @param companyId - Company ID
|
|
1103
|
+
* @param featureCode - Feature code
|
|
1104
|
+
* @param limit - Max number of snapshots to return
|
|
1105
|
+
* @returns Array of usage snapshots
|
|
1106
|
+
*/
|
|
1107
|
+
getUsageSnapshots: (companyId: string, featureCode: string, limit?: number) => Promise<{
|
|
1108
|
+
id: string;
|
|
1109
|
+
metadata: unknown;
|
|
1110
|
+
reason: string | null;
|
|
1111
|
+
created_at: Date;
|
|
1112
|
+
company_id: string;
|
|
1113
|
+
meter_code: string;
|
|
1114
|
+
created_by: string | null;
|
|
1115
|
+
absolute_value: number;
|
|
1116
|
+
billable_value: number;
|
|
1117
|
+
snapshot_type: string;
|
|
1118
|
+
trigger_event_id: string | null;
|
|
1119
|
+
}[]>;
|
|
926
1120
|
/**
|
|
927
1121
|
* Claim a subscription from a completed Stripe Checkout Session.
|
|
928
1122
|
*
|
|
@@ -1086,16 +1280,16 @@ export declare class ChatarminOS {
|
|
|
1086
1280
|
}) => Promise<{
|
|
1087
1281
|
id: string;
|
|
1088
1282
|
metadata: unknown;
|
|
1089
|
-
label: string | null;
|
|
1090
1283
|
confidence: number | null;
|
|
1284
|
+
label: string | null;
|
|
1091
1285
|
created_at: Date;
|
|
1092
1286
|
updated_at: Date;
|
|
1093
1287
|
company_id: string;
|
|
1094
1288
|
product_id: string;
|
|
1095
1289
|
external_org_id: string;
|
|
1096
1290
|
external_user_id: string | null;
|
|
1097
|
-
link_type: string;
|
|
1098
1291
|
sync_status: string;
|
|
1292
|
+
link_type: string;
|
|
1099
1293
|
} | undefined>;
|
|
1100
1294
|
/**
|
|
1101
1295
|
* Delete all product links for this product.
|
|
@@ -1223,9 +1417,9 @@ export declare class ChatarminOS {
|
|
|
1223
1417
|
description: string | null;
|
|
1224
1418
|
code: string;
|
|
1225
1419
|
is_active: boolean;
|
|
1226
|
-
display_order: number;
|
|
1227
1420
|
created_at: Date;
|
|
1228
1421
|
updated_at: Date;
|
|
1422
|
+
display_order: number;
|
|
1229
1423
|
product_id: string;
|
|
1230
1424
|
}[]>;
|
|
1231
1425
|
/**
|
|
@@ -1341,9 +1535,9 @@ export declare class ChatarminOS {
|
|
|
1341
1535
|
description: string | null;
|
|
1342
1536
|
code: string;
|
|
1343
1537
|
is_active: boolean;
|
|
1344
|
-
display_order: number;
|
|
1345
1538
|
created_at: Date;
|
|
1346
1539
|
updated_at: Date;
|
|
1540
|
+
display_order: number;
|
|
1347
1541
|
product_id: string;
|
|
1348
1542
|
}[]>;
|
|
1349
1543
|
/**
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAQ/C;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAA;IAEd;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAA;IACZ,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,6DAA6D;IAC7D,aAAa,EAAE,MAAM,CAAA;IACrB,wDAAwD;IACxD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,4BAA4B;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,2BAA2B;IAC3B,WAAW,CA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;OAmBG;IACH,IAAI,aAAa;QAGb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WA6BG;2BACgB,MAAM,WAAW,cAAc;;;;;QAOlD;;;;;;;;;;;;;;;;;;;WAmBG;;;;;;;;;;;;;;;;;;;;QAIH;;;;;;;;;;;;;;;;;;;;;;;WAuBG;4BACiB,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAG7B;IAMD;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,IAAI,KAAK;QAGL;;;;;;;;;;;WAWG;;;;;;;;;;;;;;;;;;;;QAGH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAsCG;wBACa,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAGtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WA8BG;0BACe,MAAM,WAAW,cAAc;;;;;MAOpD;IAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAuFG;IACG,OAAO,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;CAoF3D;AAGD,YAAY,EAAE,SAAS,EAAE,CAAA;AAGzB,eAAe,WAAW,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -555,6 +555,120 @@ export class ChatarminOS {
|
|
|
555
555
|
* ```
|
|
556
556
|
*/
|
|
557
557
|
trackUsage: (input) => client.billing.trackUsage.mutate(input),
|
|
558
|
+
/**
|
|
559
|
+
* Set usage to an absolute value.
|
|
560
|
+
*
|
|
561
|
+
* Use this for corrections when you know what the total usage SHOULD be.
|
|
562
|
+
* Creates a snapshot for audit trail. The delta (difference) is calculated
|
|
563
|
+
* automatically and synced to Stripe.
|
|
564
|
+
*
|
|
565
|
+
* @param input - Set usage parameters
|
|
566
|
+
* @returns Result with previous and new usage values
|
|
567
|
+
*
|
|
568
|
+
* @example Correct usage to 100 (was 150)
|
|
569
|
+
* ```typescript
|
|
570
|
+
* const result = await os.billing.setUsage({
|
|
571
|
+
* companyId: 'comp_xxx',
|
|
572
|
+
* featureCode: 'ai_credit',
|
|
573
|
+
* absoluteValue: 100,
|
|
574
|
+
* reason: 'Corrected after customer support review',
|
|
575
|
+
* performedBy: 'admin@company.com'
|
|
576
|
+
* })
|
|
577
|
+
*
|
|
578
|
+
* console.log({
|
|
579
|
+
* previousUsage: result.previousUsage, // 150
|
|
580
|
+
* currentUsage: result.currentUsage, // 100
|
|
581
|
+
* delta: result.delta // -50
|
|
582
|
+
* })
|
|
583
|
+
* ```
|
|
584
|
+
*/
|
|
585
|
+
setUsage: (input) => client.billing.setUsage.mutate({
|
|
586
|
+
...input,
|
|
587
|
+
source: "api",
|
|
588
|
+
}),
|
|
589
|
+
/**
|
|
590
|
+
* Adjust usage by a delta (positive or negative).
|
|
591
|
+
*
|
|
592
|
+
* Use this for explicit corrections. Supports negative values for
|
|
593
|
+
* refunds or error corrections. Creates an audit trail and syncs
|
|
594
|
+
* to Stripe (including meter event adjustments when possible).
|
|
595
|
+
*
|
|
596
|
+
* @param input - Adjustment parameters
|
|
597
|
+
* @returns Result with previous and new usage values
|
|
598
|
+
*
|
|
599
|
+
* @example Refund 50 units
|
|
600
|
+
* ```typescript
|
|
601
|
+
* const result = await os.billing.adjustUsage({
|
|
602
|
+
* companyId: 'comp_xxx',
|
|
603
|
+
* featureCode: 'ai_credit',
|
|
604
|
+
* delta: -50,
|
|
605
|
+
* reason: 'Refund for failed API calls',
|
|
606
|
+
* performedBy: 'support@company.com'
|
|
607
|
+
* })
|
|
608
|
+
* ```
|
|
609
|
+
*
|
|
610
|
+
* @example Add bonus units
|
|
611
|
+
* ```typescript
|
|
612
|
+
* const result = await os.billing.adjustUsage({
|
|
613
|
+
* companyId: 'comp_xxx',
|
|
614
|
+
* featureCode: 'ai_credit',
|
|
615
|
+
* delta: 100,
|
|
616
|
+
* reason: 'Promotional bonus for beta testers'
|
|
617
|
+
* })
|
|
618
|
+
* ```
|
|
619
|
+
*/
|
|
620
|
+
adjustUsage: (input) => client.billing.adjustUsage.mutate({
|
|
621
|
+
...input,
|
|
622
|
+
source: "api",
|
|
623
|
+
}),
|
|
624
|
+
/**
|
|
625
|
+
* Get usage event history for a feature.
|
|
626
|
+
*
|
|
627
|
+
* Returns the history of usage events including increments, sets,
|
|
628
|
+
* and adjustments. Useful for auditing and debugging.
|
|
629
|
+
*
|
|
630
|
+
* @param companyId - Company ID
|
|
631
|
+
* @param featureCode - Feature code to get history for
|
|
632
|
+
* @param options - Query options
|
|
633
|
+
* @returns Array of usage events
|
|
634
|
+
*
|
|
635
|
+
* @example
|
|
636
|
+
* ```typescript
|
|
637
|
+
* const history = await os.billing.getUsageHistory(
|
|
638
|
+
* 'comp_xxx',
|
|
639
|
+
* 'ai_credit',
|
|
640
|
+
* { limit: 20, eventType: 'adjustment' }
|
|
641
|
+
* )
|
|
642
|
+
*
|
|
643
|
+
* for (const event of history) {
|
|
644
|
+
* console.log(`${event.event_type}: ${event.quantity} at ${event.event_time}`)
|
|
645
|
+
* if (event.adjustment_reason) {
|
|
646
|
+
* console.log(` Reason: ${event.adjustment_reason}`)
|
|
647
|
+
* }
|
|
648
|
+
* }
|
|
649
|
+
* ```
|
|
650
|
+
*/
|
|
651
|
+
getUsageHistory: (companyId, featureCode, options) => client.billing.getUsageHistory.query({
|
|
652
|
+
companyId,
|
|
653
|
+
featureCode,
|
|
654
|
+
...options,
|
|
655
|
+
}),
|
|
656
|
+
/**
|
|
657
|
+
* Get usage snapshots for a feature.
|
|
658
|
+
*
|
|
659
|
+
* Returns audit snapshots created by set operations and reconciliations.
|
|
660
|
+
* Useful for understanding historical usage corrections.
|
|
661
|
+
*
|
|
662
|
+
* @param companyId - Company ID
|
|
663
|
+
* @param featureCode - Feature code
|
|
664
|
+
* @param limit - Max number of snapshots to return
|
|
665
|
+
* @returns Array of usage snapshots
|
|
666
|
+
*/
|
|
667
|
+
getUsageSnapshots: (companyId, featureCode, limit) => client.billing.getUsageSnapshots.query({
|
|
668
|
+
companyId,
|
|
669
|
+
featureCode,
|
|
670
|
+
limit,
|
|
671
|
+
}),
|
|
558
672
|
/**
|
|
559
673
|
* Claim a subscription from a completed Stripe Checkout Session.
|
|
560
674
|
*
|