@chatarmin/os 1.5.8 → 1.5.9
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 +5 -122
- package/dist/companies/client.d.ts +8 -0
- package/dist/companies/client.d.ts.map +1 -0
- package/dist/companies/client.js +8 -0
- package/dist/companies/index.d.ts +3 -0
- package/dist/companies/index.d.ts.map +1 -0
- package/dist/companies/index.js +1 -0
- package/dist/companies/types.d.ts +66 -0
- package/dist/companies/types.d.ts.map +1 -0
- package/dist/companies/types.js +1 -0
- package/dist/index.d.ts +341 -244
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +191 -133
- package/package.json +2 -4
- package/CHANGELOG.md +0 -21
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { AppRouter } from "@chatarmin/api";
|
|
2
|
-
|
|
3
|
-
export type {
|
|
4
|
-
export type { ListProductFeatureCatalogInput, ProductFeatureCatalogItem } from "./types/product-feature-catalog.js";
|
|
5
|
-
export type { ClaimCheckoutInput, EnsureFeatureSubscriptionInput, EnsureFeatureSubscriptionResult, LinkSubscriptionInput, RelinkBillingProfileInput, SetUsageInput, SyncCompanyFromStripeInput, SyncCompanyFromStripeResult, UsageResult, } from "./types/chatarmin-os-billing-inputs.js";
|
|
2
|
+
import { type CompaniesClient } from "./companies";
|
|
3
|
+
export type { CompaniesClient, CompanyAssignee, CompanyAssignees, CreateCompanyInput, CreateCompanyResult, GetCompanyInput, LinkedCompany, ListCompaniesInput, ListCompaniesResult, ListLinkedCompaniesInput, ListLinkedCompaniesResult, ProductCompany, UpdateCompanyResult, } from "./companies";
|
|
6
4
|
/**
|
|
7
5
|
* Configuration options for the ChatarminOS SDK client.
|
|
8
6
|
*/
|
|
@@ -42,72 +40,6 @@ export declare class ChatarminOSError extends Error {
|
|
|
42
40
|
details: ChatarminOSErrorDetails;
|
|
43
41
|
};
|
|
44
42
|
}
|
|
45
|
-
/**
|
|
46
|
-
* Input for creating a new company with product link.
|
|
47
|
-
*/
|
|
48
|
-
export interface CreateCompanyInput {
|
|
49
|
-
/** Company name (e.g., "Acme Inc") */
|
|
50
|
-
name: string;
|
|
51
|
-
/** Company domain for matching (e.g., "acme.com") */
|
|
52
|
-
domain?: string;
|
|
53
|
-
/** Your product's unique organization ID for this company */
|
|
54
|
-
externalOrgId: string;
|
|
55
|
-
/** Optional user ID who created this in your product */
|
|
56
|
-
externalUserId?: string;
|
|
57
|
-
/** Display label for the product link (e.g., "Chatarmin CX", "Shopify") */
|
|
58
|
-
label?: string;
|
|
59
|
-
/** Primary contact email */
|
|
60
|
-
contactEmail?: string;
|
|
61
|
-
/** Primary contact name */
|
|
62
|
-
contactName?: string;
|
|
63
|
-
/** Optional: Set a historical created_at timestamp (ISO 8601 format) */
|
|
64
|
-
createdAt?: string;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Input for smart linking a company.
|
|
68
|
-
*/
|
|
69
|
-
export interface SmartLinkInput {
|
|
70
|
-
/** Your product's unique organization ID for this company */
|
|
71
|
-
externalOrgId: string;
|
|
72
|
-
/** Display label for the product link (e.g., "Chatarmin CX", "Shopify") */
|
|
73
|
-
label: string;
|
|
74
|
-
/** Hints to help match existing companies */
|
|
75
|
-
hints: {
|
|
76
|
-
/** Company name to match against */
|
|
77
|
-
companyName?: string;
|
|
78
|
-
/** Domain to match (highest confidence) */
|
|
79
|
-
domain?: string;
|
|
80
|
-
/** Email addresses to match by domain */
|
|
81
|
-
emails?: string[];
|
|
82
|
-
};
|
|
83
|
-
/**
|
|
84
|
-
* Minimum confidence score (0-1) required for auto-linking.
|
|
85
|
-
* @default 0.8
|
|
86
|
-
*/
|
|
87
|
-
minConfidence?: number;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Result from smart link operation.
|
|
91
|
-
*/
|
|
92
|
-
export interface SmartLinkResult {
|
|
93
|
-
/** Status of the link operation */
|
|
94
|
-
status: "already_linked" | "linked" | "no_match" | "suggestions";
|
|
95
|
-
/** Company ID if linked */
|
|
96
|
-
customerId?: string;
|
|
97
|
-
/** Company name if linked */
|
|
98
|
-
customerName?: string;
|
|
99
|
-
/** Confidence score of the match */
|
|
100
|
-
confidence?: number;
|
|
101
|
-
/** Reason for the match (e.g., "domain_match", "name_match") */
|
|
102
|
-
reason?: string;
|
|
103
|
-
/** Suggestions if no auto-link (when status is "suggestions") */
|
|
104
|
-
suggestions?: Array<{
|
|
105
|
-
customerId: string;
|
|
106
|
-
customerName: string;
|
|
107
|
-
confidence: number;
|
|
108
|
-
reason: string;
|
|
109
|
-
}>;
|
|
110
|
-
}
|
|
111
43
|
/**
|
|
112
44
|
* Input for checking feature access.
|
|
113
45
|
*/
|
|
@@ -125,10 +57,26 @@ export interface FeatureCheckInput {
|
|
|
125
57
|
verifySubscription?: boolean;
|
|
126
58
|
}
|
|
127
59
|
/**
|
|
128
|
-
* Billing details for a feature when
|
|
129
|
-
* Includes Stripe period/price details and `stripeSubscriptionItemId`.
|
|
60
|
+
* Billing details for a feature (when includeBillingDetails: true)
|
|
130
61
|
*/
|
|
131
|
-
export
|
|
62
|
+
export interface FeatureBillingDetails {
|
|
63
|
+
/** Stripe subscription item ID */
|
|
64
|
+
stripeSubscriptionItemId: string | null;
|
|
65
|
+
/** Current billing period start */
|
|
66
|
+
currentPeriodStart: Date | null;
|
|
67
|
+
/** Current billing period end */
|
|
68
|
+
currentPeriodEnd: Date | null;
|
|
69
|
+
/** Unit amount in cents (e.g., 100 = $1.00) */
|
|
70
|
+
unitAmount: number | null;
|
|
71
|
+
/** Currency code (e.g., "usd") */
|
|
72
|
+
currency: string | null;
|
|
73
|
+
/** Billing interval (e.g., "month", "year") */
|
|
74
|
+
intervalUnit: string | null;
|
|
75
|
+
/** Usage type (e.g., "metered", "licensed") */
|
|
76
|
+
usageType: string | null;
|
|
77
|
+
/** Subscription status (e.g., "active", "trialing") */
|
|
78
|
+
subscriptionStatus: string | null;
|
|
79
|
+
}
|
|
132
80
|
/**
|
|
133
81
|
* Input for listing feature access.
|
|
134
82
|
*/
|
|
@@ -199,21 +147,94 @@ export interface FeatureSetAccessInput {
|
|
|
199
147
|
/** When the access expires (null for no expiration) */
|
|
200
148
|
validUntil?: Date | null;
|
|
201
149
|
}
|
|
202
|
-
export interface
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
domain: string | null;
|
|
207
|
-
externalOrgId: string;
|
|
208
|
-
label: string | null;
|
|
150
|
+
export interface SyncCompanyFromStripeInput {
|
|
151
|
+
companyId: string;
|
|
152
|
+
stripeCustomerId?: string;
|
|
153
|
+
forceReassign?: boolean;
|
|
209
154
|
}
|
|
210
|
-
export interface
|
|
211
|
-
|
|
212
|
-
|
|
155
|
+
export interface SyncCompanyFromStripeResult {
|
|
156
|
+
billingProfileId: string;
|
|
157
|
+
stripeCustomerId: string;
|
|
158
|
+
subscriptionsSynced: number;
|
|
159
|
+
subscriptionItemsSynced: number;
|
|
160
|
+
featuresLinked: number;
|
|
161
|
+
matchedMeters: number;
|
|
213
162
|
}
|
|
214
|
-
export interface
|
|
215
|
-
|
|
216
|
-
|
|
163
|
+
export interface EnsureFeatureSubscriptionInput {
|
|
164
|
+
companyId: string;
|
|
165
|
+
featureCode: string;
|
|
166
|
+
stripeSubscriptionId?: string;
|
|
167
|
+
}
|
|
168
|
+
export interface RelinkBillingProfileInput {
|
|
169
|
+
companyId: string;
|
|
170
|
+
stripeCustomerId: string;
|
|
171
|
+
}
|
|
172
|
+
export interface EnsureFeatureSubscriptionResult {
|
|
173
|
+
success: boolean;
|
|
174
|
+
subscriptionItemId: string | null;
|
|
175
|
+
stripePriceId: string | null;
|
|
176
|
+
stripeSubscriptionId: string | null;
|
|
177
|
+
action: "already_linked" | "linked_existing" | "created_new" | "failed";
|
|
178
|
+
error?: string;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Input for setting usage to an absolute value.
|
|
182
|
+
* Use for corrections when you know what the total usage SHOULD be.
|
|
183
|
+
*/
|
|
184
|
+
export interface SetUsageInput {
|
|
185
|
+
/** Company ID */
|
|
186
|
+
companyId: string;
|
|
187
|
+
/** Feature code */
|
|
188
|
+
featureCode: string;
|
|
189
|
+
/** The absolute value to set usage to (must be >= 0) */
|
|
190
|
+
absoluteValue: number;
|
|
191
|
+
/** Reason for the set operation (required for audit trail) */
|
|
192
|
+
reason: string;
|
|
193
|
+
/** Admin user who performed the operation */
|
|
194
|
+
performedBy?: string;
|
|
195
|
+
/** Additional metadata (e.g., { ticketId: "SUPPORT-123" }) */
|
|
196
|
+
metadata?: Record<string, unknown>;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Result from usage operations.
|
|
200
|
+
*/
|
|
201
|
+
export interface UsageResult {
|
|
202
|
+
success: boolean;
|
|
203
|
+
featureCode: string;
|
|
204
|
+
previousUsage: number;
|
|
205
|
+
currentUsage: number;
|
|
206
|
+
delta: number;
|
|
207
|
+
quantityLimit: number | null;
|
|
208
|
+
remaining: number | null;
|
|
209
|
+
isAtLimit: boolean;
|
|
210
|
+
includedQuantity: number;
|
|
211
|
+
billableQuantity: number;
|
|
212
|
+
meterId: string;
|
|
213
|
+
eventId: string | null;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Input for claiming a Stripe checkout subscription.
|
|
217
|
+
*/
|
|
218
|
+
export interface ClaimCheckoutInput {
|
|
219
|
+
/** Company ID to link the subscription to */
|
|
220
|
+
companyId: string;
|
|
221
|
+
/** Stripe checkout session ID (cs_xxx) */
|
|
222
|
+
checkoutSessionId: string;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Input for linking an existing Stripe subscription.
|
|
226
|
+
*/
|
|
227
|
+
export interface LinkSubscriptionInput {
|
|
228
|
+
/** Company ID to link the subscription to */
|
|
229
|
+
companyId: string;
|
|
230
|
+
/** Stripe subscription ID (sub_xxx) */
|
|
231
|
+
stripeSubscriptionId: string;
|
|
232
|
+
/** Stripe customer ID (cus_xxx) - fetched from subscription if not provided */
|
|
233
|
+
stripeCustomerId?: string;
|
|
234
|
+
/** Tier code to apply features from (e.g., "free", "pro") */
|
|
235
|
+
tierCode?: string;
|
|
236
|
+
/** Display name for the subscription */
|
|
237
|
+
displayName?: string;
|
|
217
238
|
}
|
|
218
239
|
/**
|
|
219
240
|
* Input for applying a tier to a company.
|
|
@@ -277,16 +298,13 @@ export interface OnboardInput {
|
|
|
277
298
|
/** Display label for the product link (e.g., "Chatarmin CX", "Shopify") */
|
|
278
299
|
label: string;
|
|
279
300
|
/**
|
|
280
|
-
*
|
|
281
|
-
* Provide as much info as possible for best matching.
|
|
301
|
+
* Company details used when creating a new company via onboard().
|
|
282
302
|
*/
|
|
283
303
|
hints?: {
|
|
284
|
-
/** Company name
|
|
304
|
+
/** Company name for new companies */
|
|
285
305
|
companyName?: string;
|
|
286
|
-
/** Domain
|
|
306
|
+
/** Domain for new companies */
|
|
287
307
|
domain?: string;
|
|
288
|
-
/** Email addresses to match by domain */
|
|
289
|
-
emails?: string[];
|
|
290
308
|
};
|
|
291
309
|
/**
|
|
292
310
|
* Stripe checkout session ID to claim.
|
|
@@ -334,10 +352,9 @@ export interface OnboardResult {
|
|
|
334
352
|
/**
|
|
335
353
|
* How the company was linked:
|
|
336
354
|
* - `already_linked`: Company was already linked to your product
|
|
337
|
-
* - `linked`: Existing company was found and linked
|
|
338
355
|
* - `created`: New company was created
|
|
339
356
|
*/
|
|
340
|
-
linkStatus: "already_linked" | "
|
|
357
|
+
linkStatus: "already_linked" | "created";
|
|
341
358
|
/** Billing status (only present if billing was configured) */
|
|
342
359
|
billingStatus?: {
|
|
343
360
|
/** Subscription ID if created/claimed */
|
|
@@ -424,10 +441,13 @@ export declare class ChatarminOS {
|
|
|
424
441
|
* @example
|
|
425
442
|
* ```typescript
|
|
426
443
|
* // Look up a company by your org ID
|
|
427
|
-
* const company = await os.companies.
|
|
444
|
+
* const company = await os.companies.get({
|
|
428
445
|
* externalOrgId: 'org_abc123'
|
|
429
446
|
* })
|
|
430
447
|
*
|
|
448
|
+
* // Route support mail to the assigned CSM
|
|
449
|
+
* const csmEmail = company?.assignees.csm?.email
|
|
450
|
+
*
|
|
431
451
|
* // Create a new company
|
|
432
452
|
* const newCompany = await os.companies.create({
|
|
433
453
|
* name: 'Acme Inc',
|
|
@@ -437,134 +457,7 @@ export declare class ChatarminOS {
|
|
|
437
457
|
* })
|
|
438
458
|
* ```
|
|
439
459
|
*/
|
|
440
|
-
get companies():
|
|
441
|
-
/**
|
|
442
|
-
* List companies linked to your product.
|
|
443
|
-
*
|
|
444
|
-
* Use cursor pagination to iterate through all linked companies.
|
|
445
|
-
*/
|
|
446
|
-
listLinked: (input?: ListLinkedCompaniesInput) => Promise<ListLinkedCompaniesResult>;
|
|
447
|
-
/**
|
|
448
|
-
* Look up a company by their external organization ID in your product.
|
|
449
|
-
*
|
|
450
|
-
* Use this to resolve your product's org ID to a ChatarminOS company.
|
|
451
|
-
* Returns `null` if no company is linked with this external ID.
|
|
452
|
-
*
|
|
453
|
-
* @param input - The lookup parameters
|
|
454
|
-
* @param input.externalOrgId - Your product's organization ID
|
|
455
|
-
* @returns The company if found, or `null`
|
|
456
|
-
*
|
|
457
|
-
* @example
|
|
458
|
-
* ```typescript
|
|
459
|
-
* const company = await os.companies.getByProductLink({
|
|
460
|
-
* externalOrgId: 'org_abc123'
|
|
461
|
-
* })
|
|
462
|
-
*
|
|
463
|
-
* if (company) {
|
|
464
|
-
* console.log(`Found: ${company.name}`)
|
|
465
|
-
* } else {
|
|
466
|
-
* console.log('Company not linked yet')
|
|
467
|
-
* }
|
|
468
|
-
* ```
|
|
469
|
-
*/
|
|
470
|
-
getByProductLink: (input: {
|
|
471
|
-
externalOrgId: string;
|
|
472
|
-
}) => Promise<{
|
|
473
|
-
id: string;
|
|
474
|
-
name: string;
|
|
475
|
-
domain: string | null;
|
|
476
|
-
external_org_id: string;
|
|
477
|
-
external_user_id: string | null;
|
|
478
|
-
} | null>;
|
|
479
|
-
/**
|
|
480
|
-
* Create a new company and link it to your product.
|
|
481
|
-
*
|
|
482
|
-
* This creates a company in ChatarminOS and automatically links it
|
|
483
|
-
* to your product using the provided external organization ID.
|
|
484
|
-
*
|
|
485
|
-
* @param input - Company creation parameters
|
|
486
|
-
* @returns The created company with ID and short ID
|
|
487
|
-
*
|
|
488
|
-
* @example
|
|
489
|
-
* ```typescript
|
|
490
|
-
* const company = await os.companies.create({
|
|
491
|
-
* name: 'Acme Inc',
|
|
492
|
-
* domain: 'acme.com',
|
|
493
|
-
* externalOrgId: 'org_abc123',
|
|
494
|
-
* contactEmail: 'admin@acme.com',
|
|
495
|
-
* contactName: 'John Doe'
|
|
496
|
-
* })
|
|
497
|
-
*
|
|
498
|
-
* console.log(company.id) // UUID
|
|
499
|
-
* console.log(company.shortId) // e.g., "acme-inc"
|
|
500
|
-
* ```
|
|
501
|
-
*/
|
|
502
|
-
create: (input: CreateCompanyInput) => Promise<{
|
|
503
|
-
id: string;
|
|
504
|
-
shortId: string | null;
|
|
505
|
-
name: string;
|
|
506
|
-
externalOrgId: string;
|
|
507
|
-
}>;
|
|
508
|
-
/**
|
|
509
|
-
* Update company metadata.
|
|
510
|
-
*
|
|
511
|
-
* Used for backfilling data like historical created_at dates.
|
|
512
|
-
*
|
|
513
|
-
* @param input - Update parameters
|
|
514
|
-
* @returns Whether the update was applied
|
|
515
|
-
*
|
|
516
|
-
* @example
|
|
517
|
-
* ```typescript
|
|
518
|
-
* await os.companies.update({
|
|
519
|
-
* companyId: 'uuid-here',
|
|
520
|
-
* createdAt: '2023-01-15T10:30:00.000Z'
|
|
521
|
-
* })
|
|
522
|
-
* ```
|
|
523
|
-
*/
|
|
524
|
-
update: (input: {
|
|
525
|
-
companyId: string;
|
|
526
|
-
createdAt?: string;
|
|
527
|
-
}) => Promise<{
|
|
528
|
-
updated: boolean;
|
|
529
|
-
}>;
|
|
530
|
-
/**
|
|
531
|
-
* Smart link - intelligently find and link a company using hints.
|
|
532
|
-
*
|
|
533
|
-
* This method attempts to find an existing company in ChatarminOS
|
|
534
|
-
* that matches the provided hints (domain, name, emails). If found
|
|
535
|
-
* with sufficient confidence, it automatically creates a link.
|
|
536
|
-
*
|
|
537
|
-
* **Matching priority:**
|
|
538
|
-
* 1. Domain match (95% confidence)
|
|
539
|
-
* 2. Name match (up to 80% confidence)
|
|
540
|
-
* 3. Email domain match (70% confidence)
|
|
541
|
-
*
|
|
542
|
-
* @param input - Smart link parameters
|
|
543
|
-
* @returns Result with status and company info if linked
|
|
544
|
-
*
|
|
545
|
-
* @example
|
|
546
|
-
* ```typescript
|
|
547
|
-
* const result = await os.companies.smartLink({
|
|
548
|
-
* externalOrgId: 'org_abc123',
|
|
549
|
-
* hints: {
|
|
550
|
-
* companyName: 'Acme Inc',
|
|
551
|
-
* domain: 'acme.com',
|
|
552
|
-
* emails: ['john@acme.com']
|
|
553
|
-
* },
|
|
554
|
-
* minConfidence: 0.7
|
|
555
|
-
* })
|
|
556
|
-
*
|
|
557
|
-
* if (result.status === 'linked') {
|
|
558
|
-
* console.log(`Linked to ${result.customerName}`)
|
|
559
|
-
* } else if (result.status === 'suggestions') {
|
|
560
|
-
* console.log('Possible matches:', result.suggestions)
|
|
561
|
-
* }
|
|
562
|
-
* ```
|
|
563
|
-
*
|
|
564
|
-
* @experimental This API may change in future versions
|
|
565
|
-
*/
|
|
566
|
-
smartLink: (input: SmartLinkInput) => Promise<SmartLinkResult>;
|
|
567
|
-
};
|
|
460
|
+
get companies(): CompaniesClient;
|
|
568
461
|
/**
|
|
569
462
|
* Contact management operations.
|
|
570
463
|
*
|
|
@@ -689,7 +582,29 @@ export declare class ChatarminOS {
|
|
|
689
582
|
avatar_url: string | null;
|
|
690
583
|
}[]>;
|
|
691
584
|
};
|
|
692
|
-
/**
|
|
585
|
+
/**
|
|
586
|
+
* Feature access and entitlement operations.
|
|
587
|
+
*
|
|
588
|
+
* Check what features a company has access to and their current usage.
|
|
589
|
+
* Features are defined in ChatarminOS and assigned via subscription tiers.
|
|
590
|
+
*
|
|
591
|
+
* @example
|
|
592
|
+
* ```typescript
|
|
593
|
+
* // Check if company can use a feature
|
|
594
|
+
* const access = await os.features.check({
|
|
595
|
+
* companyId: company.id,
|
|
596
|
+
* featureCode: 'ai_credit'
|
|
597
|
+
* })
|
|
598
|
+
*
|
|
599
|
+
* if (access.canUse) {
|
|
600
|
+
* // Feature is available
|
|
601
|
+
* console.log(`Remaining: ${access.remaining}`)
|
|
602
|
+
* } else {
|
|
603
|
+
* // Feature is disabled or limit reached
|
|
604
|
+
* console.log('Upgrade required')
|
|
605
|
+
* }
|
|
606
|
+
* ```
|
|
607
|
+
*/
|
|
693
608
|
get features(): {
|
|
694
609
|
/**
|
|
695
610
|
* Check if a company has access to a specific feature.
|
|
@@ -761,8 +676,49 @@ export declare class ChatarminOS {
|
|
|
761
676
|
* }
|
|
762
677
|
* ```
|
|
763
678
|
*/
|
|
764
|
-
listAccess: (input: ListFeatureAccessInput | string) => Promise<
|
|
765
|
-
|
|
679
|
+
listAccess: (input: ListFeatureAccessInput | string) => Promise<({
|
|
680
|
+
featureCode: string;
|
|
681
|
+
featureName: string;
|
|
682
|
+
description: string | null;
|
|
683
|
+
hasQuantity: boolean;
|
|
684
|
+
isEnabled: boolean;
|
|
685
|
+
quantityLimit: number | null;
|
|
686
|
+
includedQuantity: number;
|
|
687
|
+
currentUsage: number;
|
|
688
|
+
source: string;
|
|
689
|
+
validUntil: Date | null;
|
|
690
|
+
stripeSubscriptionItemId: string | null;
|
|
691
|
+
stripePriceId: string | null;
|
|
692
|
+
stripeSubscriptionId: string | null;
|
|
693
|
+
meterId: string | null;
|
|
694
|
+
configValues: Record<string, unknown>;
|
|
695
|
+
} | {
|
|
696
|
+
billing: {
|
|
697
|
+
stripeSubscriptionItemId: string | null;
|
|
698
|
+
currentPeriodStart: Date | null;
|
|
699
|
+
currentPeriodEnd: Date | null;
|
|
700
|
+
unitAmount: number | null;
|
|
701
|
+
currency: string | null;
|
|
702
|
+
intervalUnit: string | null;
|
|
703
|
+
usageType: string | null;
|
|
704
|
+
subscriptionStatus: string | null;
|
|
705
|
+
};
|
|
706
|
+
featureCode: string;
|
|
707
|
+
featureName: string;
|
|
708
|
+
description: string | null;
|
|
709
|
+
hasQuantity: boolean;
|
|
710
|
+
isEnabled: boolean;
|
|
711
|
+
quantityLimit: number | null;
|
|
712
|
+
includedQuantity: number;
|
|
713
|
+
currentUsage: number;
|
|
714
|
+
source: string;
|
|
715
|
+
validUntil: Date | null;
|
|
716
|
+
stripeSubscriptionItemId: string | null;
|
|
717
|
+
stripePriceId: string | null;
|
|
718
|
+
stripeSubscriptionId: string | null;
|
|
719
|
+
meterId: string | null;
|
|
720
|
+
configValues: Record<string, unknown>;
|
|
721
|
+
})[]>;
|
|
766
722
|
/**
|
|
767
723
|
* Update feature access for a company with partial config merge.
|
|
768
724
|
*
|
|
@@ -943,8 +899,61 @@ export declare class ChatarminOS {
|
|
|
943
899
|
* ```
|
|
944
900
|
*/
|
|
945
901
|
get billing(): {
|
|
946
|
-
|
|
947
|
-
|
|
902
|
+
/**
|
|
903
|
+
* Set usage to an absolute value.
|
|
904
|
+
*
|
|
905
|
+
* Use this for corrections when you know what the total usage SHOULD be.
|
|
906
|
+
* Creates a snapshot for audit trail. The delta (difference) is calculated
|
|
907
|
+
* automatically and synced to Stripe.
|
|
908
|
+
*
|
|
909
|
+
* @param input - Set usage parameters
|
|
910
|
+
* @returns Result with previous and new usage values
|
|
911
|
+
*
|
|
912
|
+
* @example Correct usage to 100 (was 150)
|
|
913
|
+
* ```typescript
|
|
914
|
+
* const result = await os.billing.setUsage({
|
|
915
|
+
* companyId: 'comp_xxx',
|
|
916
|
+
* featureCode: 'ai_credit',
|
|
917
|
+
* absoluteValue: 100,
|
|
918
|
+
* reason: 'Corrected after customer support review',
|
|
919
|
+
* performedBy: 'admin@company.com'
|
|
920
|
+
* })
|
|
921
|
+
*
|
|
922
|
+
* console.log({
|
|
923
|
+
* previousUsage: result.previousUsage, // 150
|
|
924
|
+
* currentUsage: result.currentUsage, // 100
|
|
925
|
+
* delta: result.delta // -50
|
|
926
|
+
* })
|
|
927
|
+
* ```
|
|
928
|
+
*/
|
|
929
|
+
setUsage: (input: SetUsageInput) => Promise<UsageResult>;
|
|
930
|
+
/**
|
|
931
|
+
* Get usage event history for a feature.
|
|
932
|
+
*
|
|
933
|
+
* Returns the history of usage events including increments, sets,
|
|
934
|
+
* and adjustments. Useful for auditing and debugging.
|
|
935
|
+
*
|
|
936
|
+
* @param companyId - Company ID
|
|
937
|
+
* @param featureCode - Feature code to get history for
|
|
938
|
+
* @param options - Query options
|
|
939
|
+
* @returns Array of usage events
|
|
940
|
+
*
|
|
941
|
+
* @example
|
|
942
|
+
* ```typescript
|
|
943
|
+
* const history = await os.billing.getUsageHistory(
|
|
944
|
+
* 'comp_xxx',
|
|
945
|
+
* 'ai_credit',
|
|
946
|
+
* { limit: 20, eventType: 'adjustment' }
|
|
947
|
+
* )
|
|
948
|
+
*
|
|
949
|
+
* for (const event of history) {
|
|
950
|
+
* console.log(`${event.event_type}: ${event.quantity} at ${event.event_time}`)
|
|
951
|
+
* if (event.adjustment_reason) {
|
|
952
|
+
* console.log(` Reason: ${event.adjustment_reason}`)
|
|
953
|
+
* }
|
|
954
|
+
* }
|
|
955
|
+
* ```
|
|
956
|
+
*/
|
|
948
957
|
getUsageHistory: (companyId: string, featureCode: string, options?: {
|
|
949
958
|
limit?: number;
|
|
950
959
|
includeDelivered?: boolean;
|
|
@@ -953,10 +962,10 @@ export declare class ChatarminOS {
|
|
|
953
962
|
id: string;
|
|
954
963
|
created_at: Date;
|
|
955
964
|
metadata: unknown;
|
|
956
|
-
|
|
965
|
+
billing_profile_id: string | null;
|
|
957
966
|
source: string;
|
|
958
967
|
idempotency_key: string;
|
|
959
|
-
|
|
968
|
+
event_type: string;
|
|
960
969
|
subscription_item_id: string | null;
|
|
961
970
|
feature_access_id: string | null;
|
|
962
971
|
meter_code: string;
|
|
@@ -972,8 +981,36 @@ export declare class ChatarminOS {
|
|
|
972
981
|
stripe_event_id: string | null;
|
|
973
982
|
stripe_delivery_error: string | null;
|
|
974
983
|
delivered_at: Date | null;
|
|
984
|
+
reconcile_target_key: string | null;
|
|
985
|
+
reconcile_period_start: Date | null;
|
|
986
|
+
reconcile_period_end: Date | null;
|
|
987
|
+
reconcile_current_stripe_quantity: number | null;
|
|
975
988
|
}[]>;
|
|
976
|
-
|
|
989
|
+
/**
|
|
990
|
+
* Claim a subscription from a completed Stripe Checkout Session.
|
|
991
|
+
*
|
|
992
|
+
* Use this after a user completes Stripe checkout in your product.
|
|
993
|
+
* This links the subscription and customer to the company in OS.
|
|
994
|
+
*
|
|
995
|
+
* @param input - Claim parameters
|
|
996
|
+
* @returns Result with subscription ID and claim status
|
|
997
|
+
*
|
|
998
|
+
* @example
|
|
999
|
+
* ```typescript
|
|
1000
|
+
* // In your Stripe checkout success handler:
|
|
1001
|
+
* const result = await os.billing.claimCheckout({
|
|
1002
|
+
* companyId: company.id,
|
|
1003
|
+
* checkoutSessionId: session.id // From Stripe callback
|
|
1004
|
+
* })
|
|
1005
|
+
*
|
|
1006
|
+
* if (result.alreadyClaimed) {
|
|
1007
|
+
* console.log('Subscription was already claimed')
|
|
1008
|
+
* } else {
|
|
1009
|
+
* console.log(`Claimed subscription: ${result.subscriptionId}`)
|
|
1010
|
+
* }
|
|
1011
|
+
* ```
|
|
1012
|
+
*/
|
|
1013
|
+
claimCheckout: (input: ClaimCheckoutInput) => Promise<{
|
|
977
1014
|
success: boolean;
|
|
978
1015
|
subscriptionId: string;
|
|
979
1016
|
alreadyClaimed: boolean;
|
|
@@ -984,7 +1021,34 @@ export declare class ChatarminOS {
|
|
|
984
1021
|
alreadyClaimed: boolean;
|
|
985
1022
|
status: import("stripe").Stripe.Subscription.Status;
|
|
986
1023
|
}>;
|
|
987
|
-
|
|
1024
|
+
/**
|
|
1025
|
+
* Link an existing Stripe subscription to a company.
|
|
1026
|
+
*
|
|
1027
|
+
* Use this when you create subscriptions on your product's Stripe
|
|
1028
|
+
* account and want OS to track them. Optionally applies tier features.
|
|
1029
|
+
*
|
|
1030
|
+
* @param input - Link parameters
|
|
1031
|
+
* @returns Result with subscription ID, link status, and features applied
|
|
1032
|
+
*
|
|
1033
|
+
* @example
|
|
1034
|
+
* ```typescript
|
|
1035
|
+
* // After creating subscription on your Stripe account:
|
|
1036
|
+
* const result = await os.billing.linkSubscription({
|
|
1037
|
+
* companyId: company.id,
|
|
1038
|
+
* stripeSubscriptionId: 'sub_xxx',
|
|
1039
|
+
* stripeCustomerId: 'cus_xxx', // Optional
|
|
1040
|
+
* tierCode: 'pro', // Apply tier features
|
|
1041
|
+
* displayName: 'Pro Plan'
|
|
1042
|
+
* })
|
|
1043
|
+
*
|
|
1044
|
+
* console.log({
|
|
1045
|
+
* subscriptionId: result.subscriptionId,
|
|
1046
|
+
* isNew: !result.alreadyLinked,
|
|
1047
|
+
* featuresApplied: result.featuresApplied
|
|
1048
|
+
* })
|
|
1049
|
+
* ```
|
|
1050
|
+
*/
|
|
1051
|
+
linkSubscription: (input: LinkSubscriptionInput) => Promise<{
|
|
988
1052
|
success: boolean;
|
|
989
1053
|
subscriptionId: string;
|
|
990
1054
|
alreadyLinked: boolean;
|
|
@@ -999,6 +1063,31 @@ export declare class ChatarminOS {
|
|
|
999
1063
|
tierApplied: boolean;
|
|
1000
1064
|
featuresApplied: number;
|
|
1001
1065
|
}>;
|
|
1066
|
+
/**
|
|
1067
|
+
* Get billing status for a company.
|
|
1068
|
+
*
|
|
1069
|
+
* Quick check for subscription status, active features, and
|
|
1070
|
+
* billing profile information.
|
|
1071
|
+
*
|
|
1072
|
+
* @param companyId - Company ID to check
|
|
1073
|
+
* @returns Billing status overview
|
|
1074
|
+
*
|
|
1075
|
+
* @example
|
|
1076
|
+
* ```typescript
|
|
1077
|
+
* const status = await os.billing.getStatus(company.id)
|
|
1078
|
+
*
|
|
1079
|
+
* console.log({
|
|
1080
|
+
* hasBilling: status.hasBillingProfile,
|
|
1081
|
+
* subscriptions: status.activeSubscriptions.length,
|
|
1082
|
+
* features: status.enabledFeaturesCount
|
|
1083
|
+
* })
|
|
1084
|
+
*
|
|
1085
|
+
* // Check active tier
|
|
1086
|
+
* if (status.activeSubscriptions[0]?.tier) {
|
|
1087
|
+
* console.log(`Current tier: ${status.activeSubscriptions[0].tier.name}`)
|
|
1088
|
+
* }
|
|
1089
|
+
* ```
|
|
1090
|
+
*/
|
|
1002
1091
|
getStatus: (companyId: string) => Promise<{
|
|
1003
1092
|
hasBillingProfile: boolean;
|
|
1004
1093
|
stripeCustomerId: string | null;
|
|
@@ -1011,22 +1100,22 @@ export declare class ChatarminOS {
|
|
|
1011
1100
|
name: string;
|
|
1012
1101
|
metadata: unknown;
|
|
1013
1102
|
status: string;
|
|
1014
|
-
mrr_cents: number;
|
|
1015
|
-
mrr_committed_cents: number;
|
|
1016
|
-
mrr_usage_cents: number;
|
|
1017
|
-
contract_start_at: Date | null;
|
|
1018
|
-
contract_end_at: Date | null;
|
|
1019
|
-
subscription_status: string;
|
|
1020
|
-
max_days_overdue: number;
|
|
1021
1103
|
company_id: string | null;
|
|
1022
1104
|
stripe_customer_id: string;
|
|
1023
1105
|
link_status: string;
|
|
1024
1106
|
default_currency: string;
|
|
1025
1107
|
has_payment_method: boolean;
|
|
1108
|
+
subscription_status: string;
|
|
1109
|
+
contract_start_at: Date | null;
|
|
1110
|
+
contract_end_at: Date | null;
|
|
1111
|
+
mrr_cents: number;
|
|
1112
|
+
mrr_committed_cents: number;
|
|
1113
|
+
mrr_usage_cents: number;
|
|
1026
1114
|
open_invoices_count: number;
|
|
1027
1115
|
open_amount_cents: number;
|
|
1028
1116
|
past_due_invoices_count: number;
|
|
1029
1117
|
past_due_amount_cents: number;
|
|
1118
|
+
max_days_overdue: number;
|
|
1030
1119
|
last_synced_at: Date | null;
|
|
1031
1120
|
company_group_id: string | null;
|
|
1032
1121
|
}[];
|
|
@@ -1044,8 +1133,14 @@ export declare class ChatarminOS {
|
|
|
1044
1133
|
}[];
|
|
1045
1134
|
enabledFeaturesCount: number;
|
|
1046
1135
|
}>;
|
|
1047
|
-
|
|
1048
|
-
|
|
1136
|
+
/**
|
|
1137
|
+
* Sync billing profile, subscriptions, and feature access from Stripe.
|
|
1138
|
+
*/
|
|
1139
|
+
syncCompanyFromStripe: (input: SyncCompanyFromStripeInput) => Promise<SyncCompanyFromStripeResult>;
|
|
1140
|
+
/**
|
|
1141
|
+
* Relink billing profile to a new Stripe customer (destructive).
|
|
1142
|
+
*/
|
|
1143
|
+
relinkBillingProfile: (input: RelinkBillingProfileInput) => Promise<{
|
|
1049
1144
|
billingProfileId: string;
|
|
1050
1145
|
stripeCustomerId: string;
|
|
1051
1146
|
subscriptionsSynced: number;
|
|
@@ -1053,7 +1148,10 @@ export declare class ChatarminOS {
|
|
|
1053
1148
|
featuresLinked: number;
|
|
1054
1149
|
matchedMeters: number;
|
|
1055
1150
|
}>;
|
|
1056
|
-
|
|
1151
|
+
/**
|
|
1152
|
+
* Ensure a feature is linked to an active Stripe subscription item.
|
|
1153
|
+
*/
|
|
1154
|
+
ensureFeatureSubscription: (input: EnsureFeatureSubscriptionInput) => Promise<EnsureFeatureSubscriptionResult>;
|
|
1057
1155
|
};
|
|
1058
1156
|
/**
|
|
1059
1157
|
* Manual link operations for associating external IDs with companies.
|
|
@@ -1121,6 +1219,7 @@ export declare class ChatarminOS {
|
|
|
1121
1219
|
link_type: string;
|
|
1122
1220
|
label: string | null;
|
|
1123
1221
|
external_display_name: string | null;
|
|
1222
|
+
billing_profile_id: string | null;
|
|
1124
1223
|
}>;
|
|
1125
1224
|
/**
|
|
1126
1225
|
* Delete all product links for this product.
|
|
@@ -1569,8 +1668,6 @@ export declare class ChatarminOS {
|
|
|
1569
1668
|
*
|
|
1570
1669
|
* if (result.linkStatus === 'already_linked') {
|
|
1571
1670
|
* console.log('Welcome back!')
|
|
1572
|
-
* } else if (result.linkStatus === 'linked') {
|
|
1573
|
-
* console.log('Found existing company, linked!')
|
|
1574
1671
|
* } else {
|
|
1575
1672
|
* console.log('New company created!')
|
|
1576
1673
|
* }
|