@chatarmin/os 1.0.2 → 1.2.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/README.md +11 -1
- package/dist/index.d.ts +282 -25
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +134 -4
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -63,6 +63,7 @@ const os = new ChatarminOS({
|
|
|
63
63
|
// Onboard a new customer (single call does everything!)
|
|
64
64
|
const result = await os.onboard({
|
|
65
65
|
externalOrgId: "org_abc123", // Your product's org ID
|
|
66
|
+
label: "My Product", // Display label for the product link (required)
|
|
66
67
|
hints: {
|
|
67
68
|
companyName: "Acme Inc",
|
|
68
69
|
domain: "acme.com",
|
|
@@ -109,6 +110,7 @@ const company = await os.companies.create({
|
|
|
109
110
|
name: "Acme Inc",
|
|
110
111
|
domain: "acme.com",
|
|
111
112
|
externalOrgId: "org_abc123",
|
|
113
|
+
label: "My Product", // Display label for the product link
|
|
112
114
|
contactEmail: "admin@acme.com",
|
|
113
115
|
contactName: "John Doe",
|
|
114
116
|
createdAt: "2024-01-15T10:30:00.000Z", // Optional: historical date
|
|
@@ -136,12 +138,13 @@ Intelligently find and link a company using hints.
|
|
|
136
138
|
```typescript
|
|
137
139
|
const result = await os.companies.smartLink({
|
|
138
140
|
externalOrgId: "org_abc123",
|
|
141
|
+
label: "My Product", // Display label for the product link (required)
|
|
139
142
|
hints: {
|
|
140
143
|
companyName: "Acme Inc",
|
|
141
144
|
domain: "acme.com",
|
|
142
145
|
emails: ["john@acme.com", "jane@acme.com"],
|
|
143
146
|
},
|
|
144
|
-
minConfidence: 0.7, // Default: 0.
|
|
147
|
+
minConfidence: 0.7, // Default: 0.8
|
|
145
148
|
})
|
|
146
149
|
|
|
147
150
|
switch (result.status) {
|
|
@@ -542,6 +545,7 @@ The `onboard()` method handles:
|
|
|
542
545
|
```typescript
|
|
543
546
|
const result = await os.onboard({
|
|
544
547
|
externalOrgId: "org_abc123", // Your product's org ID (required)
|
|
548
|
+
label: "My Product", // Display label for the product link (required)
|
|
545
549
|
hints: {
|
|
546
550
|
companyName: "Acme Inc",
|
|
547
551
|
domain: "acme.com",
|
|
@@ -566,6 +570,7 @@ console.log({
|
|
|
566
570
|
```typescript
|
|
567
571
|
const result = await os.onboard({
|
|
568
572
|
externalOrgId: "org_abc123",
|
|
573
|
+
label: "My Product",
|
|
569
574
|
hints: { companyName: "Acme Inc", domain: "acme.com" },
|
|
570
575
|
checkoutSessionId: "cs_test_xxx", // From Stripe checkout callback
|
|
571
576
|
})
|
|
@@ -579,6 +584,7 @@ const result = await os.onboard({
|
|
|
579
584
|
```typescript
|
|
580
585
|
const result = await os.onboard({
|
|
581
586
|
externalOrgId: "org_abc123",
|
|
587
|
+
label: "My Product",
|
|
582
588
|
hints: { companyName: "Acme Inc" },
|
|
583
589
|
tierCode: "free",
|
|
584
590
|
contactEmail: "admin@acme.com",
|
|
@@ -602,6 +608,7 @@ const stripeSub = await stripe.subscriptions.create({
|
|
|
602
608
|
// 3. Onboard with the subscription
|
|
603
609
|
const result = await os.onboard({
|
|
604
610
|
externalOrgId: "org_abc123",
|
|
611
|
+
label: "My Product",
|
|
605
612
|
hints: { companyName: "Acme Inc" },
|
|
606
613
|
stripeSubscriptionId: stripeSub.id,
|
|
607
614
|
stripeCustomerId: stripeCustomerId,
|
|
@@ -617,6 +624,7 @@ const result = await os.onboard({
|
|
|
617
624
|
```typescript
|
|
618
625
|
const result = await os.onboard({
|
|
619
626
|
externalOrgId: "org_abc123",
|
|
627
|
+
label: "My Product",
|
|
620
628
|
hints: { companyName: "Acme Inc" },
|
|
621
629
|
})
|
|
622
630
|
|
|
@@ -684,6 +692,7 @@ const session = await stripe.checkout.sessions.create({
|
|
|
684
692
|
// 3. After checkout completes → Claim subscription
|
|
685
693
|
const result = await os.onboard({
|
|
686
694
|
externalOrgId: "org_abc123",
|
|
695
|
+
label: "My Product",
|
|
687
696
|
checkoutSessionId: session.id,
|
|
688
697
|
})
|
|
689
698
|
```
|
|
@@ -700,6 +709,7 @@ for (const org of historicalData) {
|
|
|
700
709
|
// Create company with historical date
|
|
701
710
|
const result = await os.onboard({
|
|
702
711
|
externalOrgId: org.id,
|
|
712
|
+
label: "Imported", // Display label for historical import
|
|
703
713
|
hints: {
|
|
704
714
|
companyName: org.name,
|
|
705
715
|
domain: org.domain,
|
package/dist/index.d.ts
CHANGED
|
@@ -27,6 +27,8 @@ export interface CreateCompanyInput {
|
|
|
27
27
|
externalOrgId: string;
|
|
28
28
|
/** Optional user ID who created this in your product */
|
|
29
29
|
externalUserId?: string;
|
|
30
|
+
/** Display label for the product link (e.g., "Chatarmin CX", "Shopify") */
|
|
31
|
+
label?: string;
|
|
30
32
|
/** Primary contact email */
|
|
31
33
|
contactEmail?: string;
|
|
32
34
|
/** Primary contact name */
|
|
@@ -40,6 +42,8 @@ export interface CreateCompanyInput {
|
|
|
40
42
|
export interface SmartLinkInput {
|
|
41
43
|
/** Your product's unique organization ID for this company */
|
|
42
44
|
externalOrgId: string;
|
|
45
|
+
/** Display label for the product link (e.g., "Chatarmin CX", "Shopify") */
|
|
46
|
+
label: string;
|
|
43
47
|
/** Hints to help match existing companies */
|
|
44
48
|
hints: {
|
|
45
49
|
/** Company name to match against */
|
|
@@ -51,7 +55,7 @@ export interface SmartLinkInput {
|
|
|
51
55
|
};
|
|
52
56
|
/**
|
|
53
57
|
* Minimum confidence score (0-1) required for auto-linking.
|
|
54
|
-
* @default 0.
|
|
58
|
+
* @default 0.8
|
|
55
59
|
*/
|
|
56
60
|
minConfidence?: number;
|
|
57
61
|
}
|
|
@@ -85,6 +89,44 @@ export interface FeatureCheckInput {
|
|
|
85
89
|
companyId: string;
|
|
86
90
|
/** Feature code (e.g., "ai_credit", "whatsapp_messages") */
|
|
87
91
|
featureCode: string;
|
|
92
|
+
/**
|
|
93
|
+
* Verify Stripe subscription is active for this feature.
|
|
94
|
+
* When true, the response includes subscription validation fields
|
|
95
|
+
* and `canUse` will be false if no active subscription exists.
|
|
96
|
+
* @default false
|
|
97
|
+
*/
|
|
98
|
+
verifySubscription?: boolean;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Result of a feature access check.
|
|
102
|
+
*/
|
|
103
|
+
export interface FeatureCheckResult {
|
|
104
|
+
/** Feature code */
|
|
105
|
+
featureCode: string;
|
|
106
|
+
/** Whether the feature is enabled for this company */
|
|
107
|
+
isEnabled: boolean;
|
|
108
|
+
/** Whether this feature tracks quantity/usage */
|
|
109
|
+
hasQuantity: boolean;
|
|
110
|
+
/** Current usage count (for quantity-based features) */
|
|
111
|
+
currentUsage: number;
|
|
112
|
+
/** Maximum allowed quantity (null = unlimited) */
|
|
113
|
+
quantityLimit: number | null;
|
|
114
|
+
/** Included/free quantity before overage charges */
|
|
115
|
+
includedQuantity: number;
|
|
116
|
+
/** Remaining quantity before limit (null = unlimited) */
|
|
117
|
+
remaining: number | null;
|
|
118
|
+
/** Whether usage limit has been reached */
|
|
119
|
+
isAtLimit: boolean;
|
|
120
|
+
/** Whether the company can use this feature (enabled + not at limit + subscription if verified) */
|
|
121
|
+
canUse: boolean;
|
|
122
|
+
/** Whether an active Stripe subscription exists for this feature */
|
|
123
|
+
hasActiveSubscription?: boolean;
|
|
124
|
+
/** Stripe subscription status (active, trialing, canceled, etc.) */
|
|
125
|
+
subscriptionStatus?: string | null;
|
|
126
|
+
/** Stripe price ID from the subscription item */
|
|
127
|
+
stripePriceId?: string | null;
|
|
128
|
+
/** Stripe subscription ID */
|
|
129
|
+
stripeSubscriptionId?: string | null;
|
|
88
130
|
}
|
|
89
131
|
/**
|
|
90
132
|
* Input for updating feature access with partial config merge.
|
|
@@ -113,7 +155,7 @@ export interface FeatureSetAccessInput {
|
|
|
113
155
|
validUntil?: Date | null;
|
|
114
156
|
}
|
|
115
157
|
/**
|
|
116
|
-
* Input for tracking feature usage.
|
|
158
|
+
* Input for tracking feature usage (increment operation).
|
|
117
159
|
*/
|
|
118
160
|
export interface TrackUsageInput {
|
|
119
161
|
/** Company ID */
|
|
@@ -121,7 +163,7 @@ export interface TrackUsageInput {
|
|
|
121
163
|
/** Feature code to track */
|
|
122
164
|
featureCode: string;
|
|
123
165
|
/**
|
|
124
|
-
* Quantity to track.
|
|
166
|
+
* Quantity to track (must be positive).
|
|
125
167
|
* @default 1
|
|
126
168
|
*/
|
|
127
169
|
quantity?: number;
|
|
@@ -130,8 +172,77 @@ export interface TrackUsageInput {
|
|
|
130
172
|
* Use a unique ID per operation (e.g., message ID).
|
|
131
173
|
*/
|
|
132
174
|
idempotencyKey?: string;
|
|
133
|
-
/**
|
|
175
|
+
/**
|
|
176
|
+
* Additional metadata for the usage event.
|
|
177
|
+
* Store external references here (e.g., { externalId: "msg_123", type: "message" })
|
|
178
|
+
*/
|
|
134
179
|
metadata?: Record<string, unknown>;
|
|
180
|
+
/**
|
|
181
|
+
* Ensure the feature is linked to an active Stripe subscription.
|
|
182
|
+
* If no subscription item is linked:
|
|
183
|
+
* 1. Checks existing subscriptions for a matching price
|
|
184
|
+
* 2. If found, links the feature_access to that subscription item
|
|
185
|
+
* 3. If not found, adds the feature's default price to a compatible subscription
|
|
186
|
+
*
|
|
187
|
+
* Only works with monthly/flexible subscriptions.
|
|
188
|
+
* @default false
|
|
189
|
+
*/
|
|
190
|
+
ensureSubscription?: boolean;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Input for setting usage to an absolute value.
|
|
194
|
+
* Use for corrections when you know what the total usage SHOULD be.
|
|
195
|
+
*/
|
|
196
|
+
export interface SetUsageInput {
|
|
197
|
+
/** Company ID */
|
|
198
|
+
companyId: string;
|
|
199
|
+
/** Feature code */
|
|
200
|
+
featureCode: string;
|
|
201
|
+
/** The absolute value to set usage to (must be >= 0) */
|
|
202
|
+
absoluteValue: number;
|
|
203
|
+
/** Reason for the set operation (required for audit trail) */
|
|
204
|
+
reason: string;
|
|
205
|
+
/** Admin user who performed the operation */
|
|
206
|
+
performedBy?: string;
|
|
207
|
+
/** Additional metadata (e.g., { ticketId: "SUPPORT-123" }) */
|
|
208
|
+
metadata?: Record<string, unknown>;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Input for adjusting usage by a delta.
|
|
212
|
+
* Use for explicit corrections - supports negative values for refunds.
|
|
213
|
+
*/
|
|
214
|
+
export interface AdjustUsageInput {
|
|
215
|
+
/** Company ID */
|
|
216
|
+
companyId: string;
|
|
217
|
+
/** Feature code */
|
|
218
|
+
featureCode: string;
|
|
219
|
+
/** The delta to apply (can be negative for refunds) */
|
|
220
|
+
delta: number;
|
|
221
|
+
/** Reason for the adjustment (required for audit trail) */
|
|
222
|
+
reason: string;
|
|
223
|
+
/** Reference to original event being adjusted (for Stripe cancellations) */
|
|
224
|
+
adjustsEventId?: string;
|
|
225
|
+
/** Admin user who performed the operation */
|
|
226
|
+
performedBy?: string;
|
|
227
|
+
/** Additional metadata (e.g., { ticketId: "REFUND-456" }) */
|
|
228
|
+
metadata?: Record<string, unknown>;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Result from usage operations (track, set, adjust).
|
|
232
|
+
*/
|
|
233
|
+
export interface UsageResult {
|
|
234
|
+
success: boolean;
|
|
235
|
+
featureCode: string;
|
|
236
|
+
previousUsage: number;
|
|
237
|
+
currentUsage: number;
|
|
238
|
+
delta: number;
|
|
239
|
+
quantityLimit: number | null;
|
|
240
|
+
remaining: number | null;
|
|
241
|
+
isAtLimit: boolean;
|
|
242
|
+
includedQuantity: number;
|
|
243
|
+
billableQuantity: number;
|
|
244
|
+
meterId: string;
|
|
245
|
+
eventId: string | null;
|
|
135
246
|
}
|
|
136
247
|
/**
|
|
137
248
|
* Input for claiming a Stripe checkout subscription.
|
|
@@ -216,6 +327,8 @@ export interface BulkContactResult {
|
|
|
216
327
|
export interface OnboardInput {
|
|
217
328
|
/** Your product's unique organization ID for this customer */
|
|
218
329
|
externalOrgId: string;
|
|
330
|
+
/** Display label for the product link (e.g., "Chatarmin CX", "Shopify") */
|
|
331
|
+
label: string;
|
|
219
332
|
/**
|
|
220
333
|
* Hints for smart company matching.
|
|
221
334
|
* Provide as much info as possible for best matching.
|
|
@@ -312,6 +425,7 @@ export interface OnboardResult {
|
|
|
312
425
|
* // When a new user signs up in your product:
|
|
313
426
|
* const result = await os.onboard({
|
|
314
427
|
* externalOrgId: 'org_abc123',
|
|
428
|
+
* label: 'My Product',
|
|
315
429
|
* hints: {
|
|
316
430
|
* companyName: 'Acme Inc',
|
|
317
431
|
* domain: 'acme.com'
|
|
@@ -401,11 +515,11 @@ export declare class ChatarminOS {
|
|
|
401
515
|
getByProductLink: (input: {
|
|
402
516
|
externalOrgId: string;
|
|
403
517
|
}) => Promise<{
|
|
518
|
+
external_org_id: string;
|
|
519
|
+
external_user_id: string | null;
|
|
404
520
|
name: string;
|
|
405
521
|
id: string;
|
|
406
522
|
domain: string | null;
|
|
407
|
-
external_org_id: string;
|
|
408
|
-
external_user_id: string | null;
|
|
409
523
|
} | null>;
|
|
410
524
|
/**
|
|
411
525
|
* Create a new company and link it to your product.
|
|
@@ -676,17 +790,7 @@ export declare class ChatarminOS {
|
|
|
676
790
|
* })
|
|
677
791
|
* ```
|
|
678
792
|
*/
|
|
679
|
-
check: (input: FeatureCheckInput) => Promise<
|
|
680
|
-
featureCode: string;
|
|
681
|
-
isEnabled: boolean;
|
|
682
|
-
hasQuantity: boolean;
|
|
683
|
-
currentUsage: number;
|
|
684
|
-
quantityLimit: number | null;
|
|
685
|
-
includedQuantity: number;
|
|
686
|
-
remaining: number | null;
|
|
687
|
-
isAtLimit: boolean;
|
|
688
|
-
canUse: boolean;
|
|
689
|
-
}>;
|
|
793
|
+
check: (input: FeatureCheckInput) => Promise<FeatureCheckResult>;
|
|
690
794
|
/**
|
|
691
795
|
* List all features and their access status for a company.
|
|
692
796
|
*
|
|
@@ -916,13 +1020,152 @@ export declare class ChatarminOS {
|
|
|
916
1020
|
success: boolean;
|
|
917
1021
|
featureCode: string;
|
|
918
1022
|
currentUsage: number;
|
|
1023
|
+
previousUsage: number;
|
|
919
1024
|
quantityLimit: number | null;
|
|
920
1025
|
remaining: number | null;
|
|
921
1026
|
isAtLimit: boolean;
|
|
922
1027
|
includedQuantity: number;
|
|
923
1028
|
billableQuantity: number;
|
|
1029
|
+
delta: number;
|
|
924
1030
|
meterId: string;
|
|
1031
|
+
eventId: string | null;
|
|
925
1032
|
}>;
|
|
1033
|
+
/**
|
|
1034
|
+
* Set usage to an absolute value.
|
|
1035
|
+
*
|
|
1036
|
+
* Use this for corrections when you know what the total usage SHOULD be.
|
|
1037
|
+
* Creates a snapshot for audit trail. The delta (difference) is calculated
|
|
1038
|
+
* automatically and synced to Stripe.
|
|
1039
|
+
*
|
|
1040
|
+
* @param input - Set usage parameters
|
|
1041
|
+
* @returns Result with previous and new usage values
|
|
1042
|
+
*
|
|
1043
|
+
* @example Correct usage to 100 (was 150)
|
|
1044
|
+
* ```typescript
|
|
1045
|
+
* const result = await os.billing.setUsage({
|
|
1046
|
+
* companyId: 'comp_xxx',
|
|
1047
|
+
* featureCode: 'ai_credit',
|
|
1048
|
+
* absoluteValue: 100,
|
|
1049
|
+
* reason: 'Corrected after customer support review',
|
|
1050
|
+
* performedBy: 'admin@company.com'
|
|
1051
|
+
* })
|
|
1052
|
+
*
|
|
1053
|
+
* console.log({
|
|
1054
|
+
* previousUsage: result.previousUsage, // 150
|
|
1055
|
+
* currentUsage: result.currentUsage, // 100
|
|
1056
|
+
* delta: result.delta // -50
|
|
1057
|
+
* })
|
|
1058
|
+
* ```
|
|
1059
|
+
*/
|
|
1060
|
+
setUsage: (input: SetUsageInput) => Promise<UsageResult>;
|
|
1061
|
+
/**
|
|
1062
|
+
* Adjust usage by a delta (positive or negative).
|
|
1063
|
+
*
|
|
1064
|
+
* Use this for explicit corrections. Supports negative values for
|
|
1065
|
+
* refunds or error corrections. Creates an audit trail and syncs
|
|
1066
|
+
* to Stripe (including meter event adjustments when possible).
|
|
1067
|
+
*
|
|
1068
|
+
* @param input - Adjustment parameters
|
|
1069
|
+
* @returns Result with previous and new usage values
|
|
1070
|
+
*
|
|
1071
|
+
* @example Refund 50 units
|
|
1072
|
+
* ```typescript
|
|
1073
|
+
* const result = await os.billing.adjustUsage({
|
|
1074
|
+
* companyId: 'comp_xxx',
|
|
1075
|
+
* featureCode: 'ai_credit',
|
|
1076
|
+
* delta: -50,
|
|
1077
|
+
* reason: 'Refund for failed API calls',
|
|
1078
|
+
* performedBy: 'support@company.com'
|
|
1079
|
+
* })
|
|
1080
|
+
* ```
|
|
1081
|
+
*
|
|
1082
|
+
* @example Add bonus units
|
|
1083
|
+
* ```typescript
|
|
1084
|
+
* const result = await os.billing.adjustUsage({
|
|
1085
|
+
* companyId: 'comp_xxx',
|
|
1086
|
+
* featureCode: 'ai_credit',
|
|
1087
|
+
* delta: 100,
|
|
1088
|
+
* reason: 'Promotional bonus for beta testers'
|
|
1089
|
+
* })
|
|
1090
|
+
* ```
|
|
1091
|
+
*/
|
|
1092
|
+
adjustUsage: (input: AdjustUsageInput) => Promise<UsageResult>;
|
|
1093
|
+
/**
|
|
1094
|
+
* Get usage event history for a feature.
|
|
1095
|
+
*
|
|
1096
|
+
* Returns the history of usage events including increments, sets,
|
|
1097
|
+
* and adjustments. Useful for auditing and debugging.
|
|
1098
|
+
*
|
|
1099
|
+
* @param companyId - Company ID
|
|
1100
|
+
* @param featureCode - Feature code to get history for
|
|
1101
|
+
* @param options - Query options
|
|
1102
|
+
* @returns Array of usage events
|
|
1103
|
+
*
|
|
1104
|
+
* @example
|
|
1105
|
+
* ```typescript
|
|
1106
|
+
* const history = await os.billing.getUsageHistory(
|
|
1107
|
+
* 'comp_xxx',
|
|
1108
|
+
* 'ai_credit',
|
|
1109
|
+
* { limit: 20, eventType: 'adjustment' }
|
|
1110
|
+
* )
|
|
1111
|
+
*
|
|
1112
|
+
* for (const event of history) {
|
|
1113
|
+
* console.log(`${event.event_type}: ${event.quantity} at ${event.event_time}`)
|
|
1114
|
+
* if (event.adjustment_reason) {
|
|
1115
|
+
* console.log(` Reason: ${event.adjustment_reason}`)
|
|
1116
|
+
* }
|
|
1117
|
+
* }
|
|
1118
|
+
* ```
|
|
1119
|
+
*/
|
|
1120
|
+
getUsageHistory: (companyId: string, featureCode: string, options?: {
|
|
1121
|
+
limit?: number;
|
|
1122
|
+
includeDelivered?: boolean;
|
|
1123
|
+
eventType?: "increment" | "set" | "adjustment";
|
|
1124
|
+
}) => Promise<{
|
|
1125
|
+
id: string;
|
|
1126
|
+
metadata: unknown;
|
|
1127
|
+
source: string;
|
|
1128
|
+
quantity: number;
|
|
1129
|
+
created_at: Date;
|
|
1130
|
+
company_id: string;
|
|
1131
|
+
billing_profile_id: string;
|
|
1132
|
+
meter_code: string;
|
|
1133
|
+
available_product_id: string;
|
|
1134
|
+
event_time: Date;
|
|
1135
|
+
event_type: string;
|
|
1136
|
+
previous_value: number | null;
|
|
1137
|
+
adjustment_reason: string | null;
|
|
1138
|
+
adjusts_event_id: string | null;
|
|
1139
|
+
idempotency_key: string;
|
|
1140
|
+
stripe_delivery_status: string;
|
|
1141
|
+
stripe_event_id: string | null;
|
|
1142
|
+
stripe_delivery_error: string | null;
|
|
1143
|
+
delivered_at: Date | null;
|
|
1144
|
+
}[]>;
|
|
1145
|
+
/**
|
|
1146
|
+
* Get usage snapshots for a feature.
|
|
1147
|
+
*
|
|
1148
|
+
* Returns audit snapshots created by set operations and reconciliations.
|
|
1149
|
+
* Useful for understanding historical usage corrections.
|
|
1150
|
+
*
|
|
1151
|
+
* @param companyId - Company ID
|
|
1152
|
+
* @param featureCode - Feature code
|
|
1153
|
+
* @param limit - Max number of snapshots to return
|
|
1154
|
+
* @returns Array of usage snapshots
|
|
1155
|
+
*/
|
|
1156
|
+
getUsageSnapshots: (companyId: string, featureCode: string, limit?: number) => Promise<{
|
|
1157
|
+
id: string;
|
|
1158
|
+
metadata: unknown;
|
|
1159
|
+
reason: string | null;
|
|
1160
|
+
created_at: Date;
|
|
1161
|
+
company_id: string;
|
|
1162
|
+
meter_code: string;
|
|
1163
|
+
created_by: string | null;
|
|
1164
|
+
absolute_value: number;
|
|
1165
|
+
billable_value: number;
|
|
1166
|
+
snapshot_type: string;
|
|
1167
|
+
trigger_event_id: string | null;
|
|
1168
|
+
}[]>;
|
|
926
1169
|
/**
|
|
927
1170
|
* Claim a subscription from a completed Stripe Checkout Session.
|
|
928
1171
|
*
|
|
@@ -1066,19 +1309,29 @@ export declare class ChatarminOS {
|
|
|
1066
1309
|
* a direct link without smart matching.
|
|
1067
1310
|
*
|
|
1068
1311
|
* @param input - Link parameters
|
|
1312
|
+
* @param input.companyId - Company UUID or short_id (e.g., "acme-corp")
|
|
1069
1313
|
* @returns The created link record
|
|
1070
1314
|
*
|
|
1071
|
-
* @example
|
|
1315
|
+
* @example Using UUID
|
|
1072
1316
|
* ```typescript
|
|
1073
1317
|
* const link = await os.links.create({
|
|
1074
|
-
* companyId: '
|
|
1318
|
+
* companyId: 'a1b2c3d4-e5f6-...',
|
|
1075
1319
|
* externalOrgId: 'org_abc123',
|
|
1076
|
-
* label: 'Store Vienna'
|
|
1077
|
-
*
|
|
1320
|
+
* label: 'Store Vienna'
|
|
1321
|
+
* })
|
|
1322
|
+
* ```
|
|
1323
|
+
*
|
|
1324
|
+
* @example Using short_id
|
|
1325
|
+
* ```typescript
|
|
1326
|
+
* const link = await os.links.create({
|
|
1327
|
+
* companyId: 'acme-corp', // short_id works too!
|
|
1328
|
+
* externalOrgId: 'org_abc123',
|
|
1329
|
+
* label: 'Store Vienna'
|
|
1078
1330
|
* })
|
|
1079
1331
|
* ```
|
|
1080
1332
|
*/
|
|
1081
1333
|
create: (input: {
|
|
1334
|
+
/** Company UUID or short_id */
|
|
1082
1335
|
companyId: string;
|
|
1083
1336
|
externalOrgId: string;
|
|
1084
1337
|
label?: string;
|
|
@@ -1086,16 +1339,16 @@ export declare class ChatarminOS {
|
|
|
1086
1339
|
}) => Promise<{
|
|
1087
1340
|
id: string;
|
|
1088
1341
|
metadata: unknown;
|
|
1089
|
-
label: string | null;
|
|
1090
1342
|
confidence: number | null;
|
|
1343
|
+
label: string | null;
|
|
1091
1344
|
created_at: Date;
|
|
1092
1345
|
updated_at: Date;
|
|
1093
1346
|
company_id: string;
|
|
1094
1347
|
product_id: string;
|
|
1095
1348
|
external_org_id: string;
|
|
1096
1349
|
external_user_id: string | null;
|
|
1097
|
-
link_type: string;
|
|
1098
1350
|
sync_status: string;
|
|
1351
|
+
link_type: string;
|
|
1099
1352
|
} | undefined>;
|
|
1100
1353
|
/**
|
|
1101
1354
|
* Delete all product links for this product.
|
|
@@ -1223,9 +1476,9 @@ export declare class ChatarminOS {
|
|
|
1223
1476
|
description: string | null;
|
|
1224
1477
|
code: string;
|
|
1225
1478
|
is_active: boolean;
|
|
1226
|
-
display_order: number;
|
|
1227
1479
|
created_at: Date;
|
|
1228
1480
|
updated_at: Date;
|
|
1481
|
+
display_order: number;
|
|
1229
1482
|
product_id: string;
|
|
1230
1483
|
}[]>;
|
|
1231
1484
|
/**
|
|
@@ -1341,9 +1594,9 @@ export declare class ChatarminOS {
|
|
|
1341
1594
|
description: string | null;
|
|
1342
1595
|
code: string;
|
|
1343
1596
|
is_active: boolean;
|
|
1344
|
-
display_order: number;
|
|
1345
1597
|
created_at: Date;
|
|
1346
1598
|
updated_at: Date;
|
|
1599
|
+
display_order: number;
|
|
1347
1600
|
product_id: string;
|
|
1348
1601
|
}[]>;
|
|
1349
1602
|
/**
|
|
@@ -1481,6 +1734,7 @@ export declare class ChatarminOS {
|
|
|
1481
1734
|
* ```typescript
|
|
1482
1735
|
* const result = await os.onboard({
|
|
1483
1736
|
* externalOrgId: 'org_abc123',
|
|
1737
|
+
* label: 'My Product',
|
|
1484
1738
|
* hints: {
|
|
1485
1739
|
* companyName: 'Acme Inc',
|
|
1486
1740
|
* domain: 'acme.com'
|
|
@@ -1495,6 +1749,7 @@ export declare class ChatarminOS {
|
|
|
1495
1749
|
* ```typescript
|
|
1496
1750
|
* const result = await os.onboard({
|
|
1497
1751
|
* externalOrgId: 'org_abc123',
|
|
1752
|
+
* label: 'My Product',
|
|
1498
1753
|
* hints: {
|
|
1499
1754
|
* companyName: 'Acme Inc',
|
|
1500
1755
|
* domain: 'acme.com'
|
|
@@ -1521,6 +1776,7 @@ export declare class ChatarminOS {
|
|
|
1521
1776
|
* // Then onboard with the subscription
|
|
1522
1777
|
* const result = await os.onboard({
|
|
1523
1778
|
* externalOrgId: 'org_abc123',
|
|
1779
|
+
* label: 'My Product',
|
|
1524
1780
|
* hints: { companyName: 'Acme Inc' },
|
|
1525
1781
|
* stripeSubscriptionId: stripeSub.id,
|
|
1526
1782
|
* stripeCustomerId: stripeCustomerId,
|
|
@@ -1535,6 +1791,7 @@ export declare class ChatarminOS {
|
|
|
1535
1791
|
* ```typescript
|
|
1536
1792
|
* const result = await os.onboard({
|
|
1537
1793
|
* externalOrgId: 'org_abc123',
|
|
1794
|
+
* label: 'My Product',
|
|
1538
1795
|
* hints: { companyName: 'Acme Inc' }
|
|
1539
1796
|
* })
|
|
1540
1797
|
*
|
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,EAA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AAM,CAAA;YACd,cAAc,CAAC,EAAE,MAAM,CAAA;SACxB;;;;;;;;;;;;;;QAQD;;;;;;;;;;;;;;;;;;;;;;;;;;WA0BG;0BACe;YAAE,cAAc,CAAC,EAAE,OAAO,CAAC;YAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;SAAE;;;;;MAGrE;IAMD;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2FG;IACG,OAAO,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;CAsF3D;AAGD,YAAY,EAAE,SAAS,EAAE,CAAA;AAGzB,eAAe,WAAW,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ import superjson from "superjson";
|
|
|
23
23
|
* // When a new user signs up in your product:
|
|
24
24
|
* const result = await os.onboard({
|
|
25
25
|
* externalOrgId: 'org_abc123',
|
|
26
|
+
* label: 'My Product',
|
|
26
27
|
* hints: {
|
|
27
28
|
* companyName: 'Acme Inc',
|
|
28
29
|
* domain: 'acme.com'
|
|
@@ -555,6 +556,120 @@ export class ChatarminOS {
|
|
|
555
556
|
* ```
|
|
556
557
|
*/
|
|
557
558
|
trackUsage: (input) => client.billing.trackUsage.mutate(input),
|
|
559
|
+
/**
|
|
560
|
+
* Set usage to an absolute value.
|
|
561
|
+
*
|
|
562
|
+
* Use this for corrections when you know what the total usage SHOULD be.
|
|
563
|
+
* Creates a snapshot for audit trail. The delta (difference) is calculated
|
|
564
|
+
* automatically and synced to Stripe.
|
|
565
|
+
*
|
|
566
|
+
* @param input - Set usage parameters
|
|
567
|
+
* @returns Result with previous and new usage values
|
|
568
|
+
*
|
|
569
|
+
* @example Correct usage to 100 (was 150)
|
|
570
|
+
* ```typescript
|
|
571
|
+
* const result = await os.billing.setUsage({
|
|
572
|
+
* companyId: 'comp_xxx',
|
|
573
|
+
* featureCode: 'ai_credit',
|
|
574
|
+
* absoluteValue: 100,
|
|
575
|
+
* reason: 'Corrected after customer support review',
|
|
576
|
+
* performedBy: 'admin@company.com'
|
|
577
|
+
* })
|
|
578
|
+
*
|
|
579
|
+
* console.log({
|
|
580
|
+
* previousUsage: result.previousUsage, // 150
|
|
581
|
+
* currentUsage: result.currentUsage, // 100
|
|
582
|
+
* delta: result.delta // -50
|
|
583
|
+
* })
|
|
584
|
+
* ```
|
|
585
|
+
*/
|
|
586
|
+
setUsage: (input) => client.billing.setUsage.mutate({
|
|
587
|
+
...input,
|
|
588
|
+
source: "api",
|
|
589
|
+
}),
|
|
590
|
+
/**
|
|
591
|
+
* Adjust usage by a delta (positive or negative).
|
|
592
|
+
*
|
|
593
|
+
* Use this for explicit corrections. Supports negative values for
|
|
594
|
+
* refunds or error corrections. Creates an audit trail and syncs
|
|
595
|
+
* to Stripe (including meter event adjustments when possible).
|
|
596
|
+
*
|
|
597
|
+
* @param input - Adjustment parameters
|
|
598
|
+
* @returns Result with previous and new usage values
|
|
599
|
+
*
|
|
600
|
+
* @example Refund 50 units
|
|
601
|
+
* ```typescript
|
|
602
|
+
* const result = await os.billing.adjustUsage({
|
|
603
|
+
* companyId: 'comp_xxx',
|
|
604
|
+
* featureCode: 'ai_credit',
|
|
605
|
+
* delta: -50,
|
|
606
|
+
* reason: 'Refund for failed API calls',
|
|
607
|
+
* performedBy: 'support@company.com'
|
|
608
|
+
* })
|
|
609
|
+
* ```
|
|
610
|
+
*
|
|
611
|
+
* @example Add bonus units
|
|
612
|
+
* ```typescript
|
|
613
|
+
* const result = await os.billing.adjustUsage({
|
|
614
|
+
* companyId: 'comp_xxx',
|
|
615
|
+
* featureCode: 'ai_credit',
|
|
616
|
+
* delta: 100,
|
|
617
|
+
* reason: 'Promotional bonus for beta testers'
|
|
618
|
+
* })
|
|
619
|
+
* ```
|
|
620
|
+
*/
|
|
621
|
+
adjustUsage: (input) => client.billing.adjustUsage.mutate({
|
|
622
|
+
...input,
|
|
623
|
+
source: "api",
|
|
624
|
+
}),
|
|
625
|
+
/**
|
|
626
|
+
* Get usage event history for a feature.
|
|
627
|
+
*
|
|
628
|
+
* Returns the history of usage events including increments, sets,
|
|
629
|
+
* and adjustments. Useful for auditing and debugging.
|
|
630
|
+
*
|
|
631
|
+
* @param companyId - Company ID
|
|
632
|
+
* @param featureCode - Feature code to get history for
|
|
633
|
+
* @param options - Query options
|
|
634
|
+
* @returns Array of usage events
|
|
635
|
+
*
|
|
636
|
+
* @example
|
|
637
|
+
* ```typescript
|
|
638
|
+
* const history = await os.billing.getUsageHistory(
|
|
639
|
+
* 'comp_xxx',
|
|
640
|
+
* 'ai_credit',
|
|
641
|
+
* { limit: 20, eventType: 'adjustment' }
|
|
642
|
+
* )
|
|
643
|
+
*
|
|
644
|
+
* for (const event of history) {
|
|
645
|
+
* console.log(`${event.event_type}: ${event.quantity} at ${event.event_time}`)
|
|
646
|
+
* if (event.adjustment_reason) {
|
|
647
|
+
* console.log(` Reason: ${event.adjustment_reason}`)
|
|
648
|
+
* }
|
|
649
|
+
* }
|
|
650
|
+
* ```
|
|
651
|
+
*/
|
|
652
|
+
getUsageHistory: (companyId, featureCode, options) => client.billing.getUsageHistory.query({
|
|
653
|
+
companyId,
|
|
654
|
+
featureCode,
|
|
655
|
+
...options,
|
|
656
|
+
}),
|
|
657
|
+
/**
|
|
658
|
+
* Get usage snapshots for a feature.
|
|
659
|
+
*
|
|
660
|
+
* Returns audit snapshots created by set operations and reconciliations.
|
|
661
|
+
* Useful for understanding historical usage corrections.
|
|
662
|
+
*
|
|
663
|
+
* @param companyId - Company ID
|
|
664
|
+
* @param featureCode - Feature code
|
|
665
|
+
* @param limit - Max number of snapshots to return
|
|
666
|
+
* @returns Array of usage snapshots
|
|
667
|
+
*/
|
|
668
|
+
getUsageSnapshots: (companyId, featureCode, limit) => client.billing.getUsageSnapshots.query({
|
|
669
|
+
companyId,
|
|
670
|
+
featureCode,
|
|
671
|
+
limit,
|
|
672
|
+
}),
|
|
558
673
|
/**
|
|
559
674
|
* Claim a subscription from a completed Stripe Checkout Session.
|
|
560
675
|
*
|
|
@@ -665,15 +780,24 @@ export class ChatarminOS {
|
|
|
665
780
|
* a direct link without smart matching.
|
|
666
781
|
*
|
|
667
782
|
* @param input - Link parameters
|
|
783
|
+
* @param input.companyId - Company UUID or short_id (e.g., "acme-corp")
|
|
668
784
|
* @returns The created link record
|
|
669
785
|
*
|
|
670
|
-
* @example
|
|
786
|
+
* @example Using UUID
|
|
671
787
|
* ```typescript
|
|
672
788
|
* const link = await os.links.create({
|
|
673
|
-
* companyId: '
|
|
789
|
+
* companyId: 'a1b2c3d4-e5f6-...',
|
|
674
790
|
* externalOrgId: 'org_abc123',
|
|
675
|
-
* label: 'Store Vienna'
|
|
676
|
-
*
|
|
791
|
+
* label: 'Store Vienna'
|
|
792
|
+
* })
|
|
793
|
+
* ```
|
|
794
|
+
*
|
|
795
|
+
* @example Using short_id
|
|
796
|
+
* ```typescript
|
|
797
|
+
* const link = await os.links.create({
|
|
798
|
+
* companyId: 'acme-corp', // short_id works too!
|
|
799
|
+
* externalOrgId: 'org_abc123',
|
|
800
|
+
* label: 'Store Vienna'
|
|
677
801
|
* })
|
|
678
802
|
* ```
|
|
679
803
|
*/
|
|
@@ -968,6 +1092,7 @@ export class ChatarminOS {
|
|
|
968
1092
|
* ```typescript
|
|
969
1093
|
* const result = await os.onboard({
|
|
970
1094
|
* externalOrgId: 'org_abc123',
|
|
1095
|
+
* label: 'My Product',
|
|
971
1096
|
* hints: {
|
|
972
1097
|
* companyName: 'Acme Inc',
|
|
973
1098
|
* domain: 'acme.com'
|
|
@@ -982,6 +1107,7 @@ export class ChatarminOS {
|
|
|
982
1107
|
* ```typescript
|
|
983
1108
|
* const result = await os.onboard({
|
|
984
1109
|
* externalOrgId: 'org_abc123',
|
|
1110
|
+
* label: 'My Product',
|
|
985
1111
|
* hints: {
|
|
986
1112
|
* companyName: 'Acme Inc',
|
|
987
1113
|
* domain: 'acme.com'
|
|
@@ -1008,6 +1134,7 @@ export class ChatarminOS {
|
|
|
1008
1134
|
* // Then onboard with the subscription
|
|
1009
1135
|
* const result = await os.onboard({
|
|
1010
1136
|
* externalOrgId: 'org_abc123',
|
|
1137
|
+
* label: 'My Product',
|
|
1011
1138
|
* hints: { companyName: 'Acme Inc' },
|
|
1012
1139
|
* stripeSubscriptionId: stripeSub.id,
|
|
1013
1140
|
* stripeCustomerId: stripeCustomerId,
|
|
@@ -1022,6 +1149,7 @@ export class ChatarminOS {
|
|
|
1022
1149
|
* ```typescript
|
|
1023
1150
|
* const result = await os.onboard({
|
|
1024
1151
|
* externalOrgId: 'org_abc123',
|
|
1152
|
+
* label: 'My Product',
|
|
1025
1153
|
* hints: { companyName: 'Acme Inc' }
|
|
1026
1154
|
* })
|
|
1027
1155
|
*
|
|
@@ -1041,6 +1169,7 @@ export class ChatarminOS {
|
|
|
1041
1169
|
let linkStatus;
|
|
1042
1170
|
const smartLinkResult = await this.companies.smartLink({
|
|
1043
1171
|
externalOrgId: input.externalOrgId,
|
|
1172
|
+
label: input.label,
|
|
1044
1173
|
hints: input.hints ?? {},
|
|
1045
1174
|
});
|
|
1046
1175
|
if (smartLinkResult.status === "already_linked") {
|
|
@@ -1059,6 +1188,7 @@ export class ChatarminOS {
|
|
|
1059
1188
|
name: input.hints?.companyName ?? `Company ${input.externalOrgId}`,
|
|
1060
1189
|
domain: input.hints?.domain,
|
|
1061
1190
|
externalOrgId: input.externalOrgId,
|
|
1191
|
+
label: input.label,
|
|
1062
1192
|
contactEmail: input.contactEmail,
|
|
1063
1193
|
contactName: input.contactName,
|
|
1064
1194
|
createdAt: input.createdAt,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chatarmin/os",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Type-safe SDK for ChatarminOS - Customer & Subscription Management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"typecheck": "tsc --noEmit --skipLibCheck",
|
|
26
26
|
"test": "tsx test-sdk.ts",
|
|
27
27
|
"sync": "tsx scripts/sync-orgs.ts",
|
|
28
|
+
"sync:interactive": "tsx scripts/sync-interactive.ts",
|
|
28
29
|
"sync:example": "tsx scripts/sync-orgs.ts ./scripts/data/orgs.example.json --dry-run --verbose",
|
|
29
30
|
"prepublishOnly": "pnpm build",
|
|
30
31
|
"release": "./scripts/publish.sh",
|