@chatarmin/os 1.5.8 → 1.7.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 +36 -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/index.d.ts +348 -245
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +194 -133
- package/dist/webhooks/constants.d.ts +5 -0
- package/dist/webhooks/constants.d.ts.map +1 -0
- package/dist/webhooks/constants.js +4 -0
- package/dist/webhooks/construct-event.d.ts +3 -0
- package/dist/webhooks/construct-event.d.ts.map +1 -0
- package/dist/webhooks/construct-event.js +64 -0
- package/dist/webhooks/errors.d.ts +4 -0
- package/dist/webhooks/errors.d.ts.map +1 -0
- package/dist/webhooks/errors.js +6 -0
- package/dist/webhooks/generate-test-headers.d.ts +3 -0
- package/dist/webhooks/generate-test-headers.d.ts.map +1 -0
- package/dist/webhooks/generate-test-headers.js +11 -0
- package/dist/webhooks/index.d.ts +16 -0
- package/dist/webhooks/index.d.ts.map +1 -0
- package/dist/webhooks/index.js +14 -0
- package/dist/webhooks/read-header.d.ts +3 -0
- package/dist/webhooks/read-header.d.ts.map +1 -0
- package/dist/webhooks/read-header.js +16 -0
- package/dist/webhooks/signing.d.ts +4 -0
- package/dist/webhooks/signing.d.ts.map +1 -0
- package/dist/webhooks/signing.js +16 -0
- package/dist/webhooks/types.d.ts +30 -0
- package/dist/webhooks/types.d.ts.map +1 -0
- package/package.json +10 -5
- package/CHANGELOG.md +0 -21
- package/dist/billing-get-dashboard-context.d.ts +0 -16
- package/dist/billing-get-dashboard-context.d.ts.map +0 -1
- package/dist/billing-get-dashboard-context.js +0 -7
- package/dist/chatarmin-os-billing-namespace.d.ts +0 -122
- package/dist/chatarmin-os-billing-namespace.d.ts.map +0 -1
- package/dist/chatarmin-os-billing-namespace.js +0 -24
- package/dist/features-list-for-product.d.ts +0 -26
- package/dist/features-list-for-product.d.ts.map +0 -1
- package/dist/features-list-for-product.js +0 -17
- package/dist/types/billing-dashboard-context.d.ts +0 -33
- package/dist/types/billing-dashboard-context.d.ts.map +0 -1
- package/dist/types/chatarmin-os-billing-inputs.d.ts +0 -90
- package/dist/types/chatarmin-os-billing-inputs.d.ts.map +0 -1
- package/dist/types/feature-access-list-item.d.ts +0 -7
- package/dist/types/feature-access-list-item.d.ts.map +0 -1
- package/dist/types/feature-access-list-item.js +0 -1
- package/dist/types/product-feature-catalog.d.ts +0 -24
- package/dist/types/product-feature-catalog.d.ts.map +0 -1
- package/dist/types/product-feature-catalog.js +0 -1
- /package/dist/{types/billing-dashboard-context.js → companies/types.js} +0 -0
- /package/dist/{types/chatarmin-os-billing-inputs.js → webhooks/types.js} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { AppRouter } from "@chatarmin/api";
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
export type {
|
|
5
|
-
export type {
|
|
2
|
+
import { type CompaniesClient } from "./companies";
|
|
3
|
+
export { webhooks, constructProductWebhookEvent, generateTestWebhookHeaders, OsWebhookSignatureVerificationError, WEBHOOK_ID_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_TIMESTAMP_HEADER, } from "./webhooks";
|
|
4
|
+
export type { ConstructProductWebhookEventOptions, ProductWebhookEventPayload, ProductWebhookHeaders, VerifiedProductWebhookEvent, } from "./webhooks";
|
|
5
|
+
export type { CompaniesClient, CompanyAssignee, CompanyAssignees, CreateCompanyInput, CreateCompanyResult, GetCompanyInput, LinkedCompany, ListCompaniesInput, ListCompaniesResult, ListLinkedCompaniesInput, ListLinkedCompaniesResult, ProductCompany, UpdateCompanyResult, } from "./companies";
|
|
6
6
|
/**
|
|
7
7
|
* Configuration options for the ChatarminOS SDK client.
|
|
8
8
|
*/
|
|
@@ -42,72 +42,6 @@ export declare class ChatarminOSError extends Error {
|
|
|
42
42
|
details: ChatarminOSErrorDetails;
|
|
43
43
|
};
|
|
44
44
|
}
|
|
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
45
|
/**
|
|
112
46
|
* Input for checking feature access.
|
|
113
47
|
*/
|
|
@@ -125,10 +59,26 @@ export interface FeatureCheckInput {
|
|
|
125
59
|
verifySubscription?: boolean;
|
|
126
60
|
}
|
|
127
61
|
/**
|
|
128
|
-
* Billing details for a feature when
|
|
129
|
-
* Includes Stripe period/price details and `stripeSubscriptionItemId`.
|
|
62
|
+
* Billing details for a feature (when includeBillingDetails: true)
|
|
130
63
|
*/
|
|
131
|
-
export
|
|
64
|
+
export interface FeatureBillingDetails {
|
|
65
|
+
/** Stripe subscription item ID */
|
|
66
|
+
stripeSubscriptionItemId: string | null;
|
|
67
|
+
/** Current billing period start */
|
|
68
|
+
currentPeriodStart: Date | null;
|
|
69
|
+
/** Current billing period end */
|
|
70
|
+
currentPeriodEnd: Date | null;
|
|
71
|
+
/** Unit amount in cents (e.g., 100 = $1.00) */
|
|
72
|
+
unitAmount: number | null;
|
|
73
|
+
/** Currency code (e.g., "usd") */
|
|
74
|
+
currency: string | null;
|
|
75
|
+
/** Billing interval (e.g., "month", "year") */
|
|
76
|
+
intervalUnit: string | null;
|
|
77
|
+
/** Usage type (e.g., "metered", "licensed") */
|
|
78
|
+
usageType: string | null;
|
|
79
|
+
/** Subscription status (e.g., "active", "trialing") */
|
|
80
|
+
subscriptionStatus: string | null;
|
|
81
|
+
}
|
|
132
82
|
/**
|
|
133
83
|
* Input for listing feature access.
|
|
134
84
|
*/
|
|
@@ -199,21 +149,94 @@ export interface FeatureSetAccessInput {
|
|
|
199
149
|
/** When the access expires (null for no expiration) */
|
|
200
150
|
validUntil?: Date | null;
|
|
201
151
|
}
|
|
202
|
-
export interface
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
152
|
+
export interface SyncCompanyFromStripeInput {
|
|
153
|
+
companyId: string;
|
|
154
|
+
stripeCustomerId?: string;
|
|
155
|
+
forceReassign?: boolean;
|
|
156
|
+
}
|
|
157
|
+
export interface SyncCompanyFromStripeResult {
|
|
158
|
+
billingProfileId: string;
|
|
159
|
+
stripeCustomerId: string;
|
|
160
|
+
subscriptionsSynced: number;
|
|
161
|
+
subscriptionItemsSynced: number;
|
|
162
|
+
featuresLinked: number;
|
|
163
|
+
matchedMeters: number;
|
|
164
|
+
}
|
|
165
|
+
export interface EnsureFeatureSubscriptionInput {
|
|
166
|
+
companyId: string;
|
|
167
|
+
featureCode: string;
|
|
168
|
+
stripeSubscriptionId?: string;
|
|
169
|
+
}
|
|
170
|
+
export interface RelinkBillingProfileInput {
|
|
171
|
+
companyId: string;
|
|
172
|
+
stripeCustomerId: string;
|
|
173
|
+
}
|
|
174
|
+
export interface EnsureFeatureSubscriptionResult {
|
|
175
|
+
success: boolean;
|
|
176
|
+
subscriptionItemId: string | null;
|
|
177
|
+
stripePriceId: string | null;
|
|
178
|
+
stripeSubscriptionId: string | null;
|
|
179
|
+
action: "already_linked" | "linked_existing" | "created_new" | "failed";
|
|
180
|
+
error?: string;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Input for setting usage to an absolute value.
|
|
184
|
+
* Use for corrections when you know what the total usage SHOULD be.
|
|
185
|
+
*/
|
|
186
|
+
export interface SetUsageInput {
|
|
187
|
+
/** Company ID */
|
|
188
|
+
companyId: string;
|
|
189
|
+
/** Feature code */
|
|
190
|
+
featureCode: string;
|
|
191
|
+
/** The absolute value to set usage to (must be >= 0) */
|
|
192
|
+
absoluteValue: number;
|
|
193
|
+
/** Reason for the set operation (required for audit trail) */
|
|
194
|
+
reason: string;
|
|
195
|
+
/** Admin user who performed the operation */
|
|
196
|
+
performedBy?: string;
|
|
197
|
+
/** Additional metadata (e.g., { ticketId: "SUPPORT-123" }) */
|
|
198
|
+
metadata?: Record<string, unknown>;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Result from usage operations.
|
|
202
|
+
*/
|
|
203
|
+
export interface UsageResult {
|
|
204
|
+
success: boolean;
|
|
205
|
+
featureCode: string;
|
|
206
|
+
previousUsage: number;
|
|
207
|
+
currentUsage: number;
|
|
208
|
+
delta: number;
|
|
209
|
+
quantityLimit: number | null;
|
|
210
|
+
remaining: number | null;
|
|
211
|
+
isAtLimit: boolean;
|
|
212
|
+
includedQuantity: number;
|
|
213
|
+
billableQuantity: number;
|
|
214
|
+
meterId: string;
|
|
215
|
+
eventId: string | null;
|
|
209
216
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
217
|
+
/**
|
|
218
|
+
* Input for claiming a Stripe checkout subscription.
|
|
219
|
+
*/
|
|
220
|
+
export interface ClaimCheckoutInput {
|
|
221
|
+
/** Company ID to link the subscription to */
|
|
222
|
+
companyId: string;
|
|
223
|
+
/** Stripe checkout session ID (cs_xxx) */
|
|
224
|
+
checkoutSessionId: string;
|
|
213
225
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
226
|
+
/**
|
|
227
|
+
* Input for linking an existing Stripe subscription.
|
|
228
|
+
*/
|
|
229
|
+
export interface LinkSubscriptionInput {
|
|
230
|
+
/** Company ID to link the subscription to */
|
|
231
|
+
companyId: string;
|
|
232
|
+
/** Stripe subscription ID (sub_xxx) */
|
|
233
|
+
stripeSubscriptionId: string;
|
|
234
|
+
/** Stripe customer ID (cus_xxx) - fetched from subscription if not provided */
|
|
235
|
+
stripeCustomerId?: string;
|
|
236
|
+
/** Tier code to apply features from (e.g., "free", "pro") */
|
|
237
|
+
tierCode?: string;
|
|
238
|
+
/** Display name for the subscription */
|
|
239
|
+
displayName?: string;
|
|
217
240
|
}
|
|
218
241
|
/**
|
|
219
242
|
* Input for applying a tier to a company.
|
|
@@ -277,16 +300,13 @@ export interface OnboardInput {
|
|
|
277
300
|
/** Display label for the product link (e.g., "Chatarmin CX", "Shopify") */
|
|
278
301
|
label: string;
|
|
279
302
|
/**
|
|
280
|
-
*
|
|
281
|
-
* Provide as much info as possible for best matching.
|
|
303
|
+
* Company details used when creating a new company via onboard().
|
|
282
304
|
*/
|
|
283
305
|
hints?: {
|
|
284
|
-
/** Company name
|
|
306
|
+
/** Company name for new companies */
|
|
285
307
|
companyName?: string;
|
|
286
|
-
/** Domain
|
|
308
|
+
/** Domain for new companies */
|
|
287
309
|
domain?: string;
|
|
288
|
-
/** Email addresses to match by domain */
|
|
289
|
-
emails?: string[];
|
|
290
310
|
};
|
|
291
311
|
/**
|
|
292
312
|
* Stripe checkout session ID to claim.
|
|
@@ -334,10 +354,9 @@ export interface OnboardResult {
|
|
|
334
354
|
/**
|
|
335
355
|
* How the company was linked:
|
|
336
356
|
* - `already_linked`: Company was already linked to your product
|
|
337
|
-
* - `linked`: Existing company was found and linked
|
|
338
357
|
* - `created`: New company was created
|
|
339
358
|
*/
|
|
340
|
-
linkStatus: "already_linked" | "
|
|
359
|
+
linkStatus: "already_linked" | "created";
|
|
341
360
|
/** Billing status (only present if billing was configured) */
|
|
342
361
|
billingStatus?: {
|
|
343
362
|
/** Subscription ID if created/claimed */
|
|
@@ -396,6 +415,10 @@ export interface OnboardResult {
|
|
|
396
415
|
* @see https://os.chatarmin.com/docs for full documentation
|
|
397
416
|
*/
|
|
398
417
|
export declare class ChatarminOS {
|
|
418
|
+
static webhooks: {
|
|
419
|
+
constructEvent: typeof import("./webhooks").constructProductWebhookEvent;
|
|
420
|
+
generateTestHeaders: typeof import("./webhooks").generateTestWebhookHeaders;
|
|
421
|
+
};
|
|
399
422
|
private client;
|
|
400
423
|
private call;
|
|
401
424
|
/**
|
|
@@ -424,10 +447,13 @@ export declare class ChatarminOS {
|
|
|
424
447
|
* @example
|
|
425
448
|
* ```typescript
|
|
426
449
|
* // Look up a company by your org ID
|
|
427
|
-
* const company = await os.companies.
|
|
450
|
+
* const company = await os.companies.get({
|
|
428
451
|
* externalOrgId: 'org_abc123'
|
|
429
452
|
* })
|
|
430
453
|
*
|
|
454
|
+
* // Route support mail to the assigned CSM
|
|
455
|
+
* const csmEmail = company?.assignees.csm?.email
|
|
456
|
+
*
|
|
431
457
|
* // Create a new company
|
|
432
458
|
* const newCompany = await os.companies.create({
|
|
433
459
|
* name: 'Acme Inc',
|
|
@@ -437,134 +463,7 @@ export declare class ChatarminOS {
|
|
|
437
463
|
* })
|
|
438
464
|
* ```
|
|
439
465
|
*/
|
|
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
|
-
};
|
|
466
|
+
get companies(): CompaniesClient;
|
|
568
467
|
/**
|
|
569
468
|
* Contact management operations.
|
|
570
469
|
*
|
|
@@ -689,7 +588,29 @@ export declare class ChatarminOS {
|
|
|
689
588
|
avatar_url: string | null;
|
|
690
589
|
}[]>;
|
|
691
590
|
};
|
|
692
|
-
/**
|
|
591
|
+
/**
|
|
592
|
+
* Feature access and entitlement operations.
|
|
593
|
+
*
|
|
594
|
+
* Check what features a company has access to and their current usage.
|
|
595
|
+
* Features are defined in ChatarminOS and assigned via subscription tiers.
|
|
596
|
+
*
|
|
597
|
+
* @example
|
|
598
|
+
* ```typescript
|
|
599
|
+
* // Check if company can use a feature
|
|
600
|
+
* const access = await os.features.check({
|
|
601
|
+
* companyId: company.id,
|
|
602
|
+
* featureCode: 'ai_credit'
|
|
603
|
+
* })
|
|
604
|
+
*
|
|
605
|
+
* if (access.canUse) {
|
|
606
|
+
* // Feature is available
|
|
607
|
+
* console.log(`Remaining: ${access.remaining}`)
|
|
608
|
+
* } else {
|
|
609
|
+
* // Feature is disabled or limit reached
|
|
610
|
+
* console.log('Upgrade required')
|
|
611
|
+
* }
|
|
612
|
+
* ```
|
|
613
|
+
*/
|
|
693
614
|
get features(): {
|
|
694
615
|
/**
|
|
695
616
|
* Check if a company has access to a specific feature.
|
|
@@ -761,8 +682,49 @@ export declare class ChatarminOS {
|
|
|
761
682
|
* }
|
|
762
683
|
* ```
|
|
763
684
|
*/
|
|
764
|
-
listAccess: (input: ListFeatureAccessInput | string) => Promise<
|
|
765
|
-
|
|
685
|
+
listAccess: (input: ListFeatureAccessInput | string) => Promise<({
|
|
686
|
+
featureCode: string;
|
|
687
|
+
featureName: string;
|
|
688
|
+
description: string | null;
|
|
689
|
+
hasQuantity: boolean;
|
|
690
|
+
isEnabled: boolean;
|
|
691
|
+
quantityLimit: number | null;
|
|
692
|
+
includedQuantity: number;
|
|
693
|
+
currentUsage: number;
|
|
694
|
+
source: string;
|
|
695
|
+
validUntil: Date | null;
|
|
696
|
+
stripeSubscriptionItemId: string | null;
|
|
697
|
+
stripePriceId: string | null;
|
|
698
|
+
stripeSubscriptionId: string | null;
|
|
699
|
+
meterId: string | null;
|
|
700
|
+
configValues: Record<string, unknown>;
|
|
701
|
+
} | {
|
|
702
|
+
billing: {
|
|
703
|
+
stripeSubscriptionItemId: string | null;
|
|
704
|
+
currentPeriodStart: Date | null;
|
|
705
|
+
currentPeriodEnd: Date | null;
|
|
706
|
+
unitAmount: number | null;
|
|
707
|
+
currency: string | null;
|
|
708
|
+
intervalUnit: string | null;
|
|
709
|
+
usageType: string | null;
|
|
710
|
+
subscriptionStatus: string | null;
|
|
711
|
+
};
|
|
712
|
+
featureCode: string;
|
|
713
|
+
featureName: string;
|
|
714
|
+
description: string | null;
|
|
715
|
+
hasQuantity: boolean;
|
|
716
|
+
isEnabled: boolean;
|
|
717
|
+
quantityLimit: number | null;
|
|
718
|
+
includedQuantity: number;
|
|
719
|
+
currentUsage: number;
|
|
720
|
+
source: string;
|
|
721
|
+
validUntil: Date | null;
|
|
722
|
+
stripeSubscriptionItemId: string | null;
|
|
723
|
+
stripePriceId: string | null;
|
|
724
|
+
stripeSubscriptionId: string | null;
|
|
725
|
+
meterId: string | null;
|
|
726
|
+
configValues: Record<string, unknown>;
|
|
727
|
+
})[]>;
|
|
766
728
|
/**
|
|
767
729
|
* Update feature access for a company with partial config merge.
|
|
768
730
|
*
|
|
@@ -943,8 +905,61 @@ export declare class ChatarminOS {
|
|
|
943
905
|
* ```
|
|
944
906
|
*/
|
|
945
907
|
get billing(): {
|
|
946
|
-
|
|
947
|
-
|
|
908
|
+
/**
|
|
909
|
+
* Set usage to an absolute value.
|
|
910
|
+
*
|
|
911
|
+
* Use this for corrections when you know what the total usage SHOULD be.
|
|
912
|
+
* Creates a snapshot for audit trail. The delta (difference) is calculated
|
|
913
|
+
* automatically and synced to Stripe.
|
|
914
|
+
*
|
|
915
|
+
* @param input - Set usage parameters
|
|
916
|
+
* @returns Result with previous and new usage values
|
|
917
|
+
*
|
|
918
|
+
* @example Correct usage to 100 (was 150)
|
|
919
|
+
* ```typescript
|
|
920
|
+
* const result = await os.billing.setUsage({
|
|
921
|
+
* companyId: 'comp_xxx',
|
|
922
|
+
* featureCode: 'ai_credit',
|
|
923
|
+
* absoluteValue: 100,
|
|
924
|
+
* reason: 'Corrected after customer support review',
|
|
925
|
+
* performedBy: 'admin@company.com'
|
|
926
|
+
* })
|
|
927
|
+
*
|
|
928
|
+
* console.log({
|
|
929
|
+
* previousUsage: result.previousUsage, // 150
|
|
930
|
+
* currentUsage: result.currentUsage, // 100
|
|
931
|
+
* delta: result.delta // -50
|
|
932
|
+
* })
|
|
933
|
+
* ```
|
|
934
|
+
*/
|
|
935
|
+
setUsage: (input: SetUsageInput) => Promise<UsageResult>;
|
|
936
|
+
/**
|
|
937
|
+
* Get usage event history for a feature.
|
|
938
|
+
*
|
|
939
|
+
* Returns the history of usage events including increments, sets,
|
|
940
|
+
* and adjustments. Useful for auditing and debugging.
|
|
941
|
+
*
|
|
942
|
+
* @param companyId - Company ID
|
|
943
|
+
* @param featureCode - Feature code to get history for
|
|
944
|
+
* @param options - Query options
|
|
945
|
+
* @returns Array of usage events
|
|
946
|
+
*
|
|
947
|
+
* @example
|
|
948
|
+
* ```typescript
|
|
949
|
+
* const history = await os.billing.getUsageHistory(
|
|
950
|
+
* 'comp_xxx',
|
|
951
|
+
* 'ai_credit',
|
|
952
|
+
* { limit: 20, eventType: 'adjustment' }
|
|
953
|
+
* )
|
|
954
|
+
*
|
|
955
|
+
* for (const event of history) {
|
|
956
|
+
* console.log(`${event.event_type}: ${event.quantity} at ${event.event_time}`)
|
|
957
|
+
* if (event.adjustment_reason) {
|
|
958
|
+
* console.log(` Reason: ${event.adjustment_reason}`)
|
|
959
|
+
* }
|
|
960
|
+
* }
|
|
961
|
+
* ```
|
|
962
|
+
*/
|
|
948
963
|
getUsageHistory: (companyId: string, featureCode: string, options?: {
|
|
949
964
|
limit?: number;
|
|
950
965
|
includeDelivered?: boolean;
|
|
@@ -953,10 +968,10 @@ export declare class ChatarminOS {
|
|
|
953
968
|
id: string;
|
|
954
969
|
created_at: Date;
|
|
955
970
|
metadata: unknown;
|
|
956
|
-
|
|
971
|
+
billing_profile_id: string | null;
|
|
957
972
|
source: string;
|
|
958
973
|
idempotency_key: string;
|
|
959
|
-
|
|
974
|
+
event_type: string;
|
|
960
975
|
subscription_item_id: string | null;
|
|
961
976
|
feature_access_id: string | null;
|
|
962
977
|
meter_code: string;
|
|
@@ -972,8 +987,36 @@ export declare class ChatarminOS {
|
|
|
972
987
|
stripe_event_id: string | null;
|
|
973
988
|
stripe_delivery_error: string | null;
|
|
974
989
|
delivered_at: Date | null;
|
|
990
|
+
reconcile_target_key: string | null;
|
|
991
|
+
reconcile_period_start: Date | null;
|
|
992
|
+
reconcile_period_end: Date | null;
|
|
993
|
+
reconcile_current_stripe_quantity: number | null;
|
|
975
994
|
}[]>;
|
|
976
|
-
|
|
995
|
+
/**
|
|
996
|
+
* Claim a subscription from a completed Stripe Checkout Session.
|
|
997
|
+
*
|
|
998
|
+
* Use this after a user completes Stripe checkout in your product.
|
|
999
|
+
* This links the subscription and customer to the company in OS.
|
|
1000
|
+
*
|
|
1001
|
+
* @param input - Claim parameters
|
|
1002
|
+
* @returns Result with subscription ID and claim status
|
|
1003
|
+
*
|
|
1004
|
+
* @example
|
|
1005
|
+
* ```typescript
|
|
1006
|
+
* // In your Stripe checkout success handler:
|
|
1007
|
+
* const result = await os.billing.claimCheckout({
|
|
1008
|
+
* companyId: company.id,
|
|
1009
|
+
* checkoutSessionId: session.id // From Stripe callback
|
|
1010
|
+
* })
|
|
1011
|
+
*
|
|
1012
|
+
* if (result.alreadyClaimed) {
|
|
1013
|
+
* console.log('Subscription was already claimed')
|
|
1014
|
+
* } else {
|
|
1015
|
+
* console.log(`Claimed subscription: ${result.subscriptionId}`)
|
|
1016
|
+
* }
|
|
1017
|
+
* ```
|
|
1018
|
+
*/
|
|
1019
|
+
claimCheckout: (input: ClaimCheckoutInput) => Promise<{
|
|
977
1020
|
success: boolean;
|
|
978
1021
|
subscriptionId: string;
|
|
979
1022
|
alreadyClaimed: boolean;
|
|
@@ -984,7 +1027,34 @@ export declare class ChatarminOS {
|
|
|
984
1027
|
alreadyClaimed: boolean;
|
|
985
1028
|
status: import("stripe").Stripe.Subscription.Status;
|
|
986
1029
|
}>;
|
|
987
|
-
|
|
1030
|
+
/**
|
|
1031
|
+
* Link an existing Stripe subscription to a company.
|
|
1032
|
+
*
|
|
1033
|
+
* Use this when you create subscriptions on your product's Stripe
|
|
1034
|
+
* account and want OS to track them. Optionally applies tier features.
|
|
1035
|
+
*
|
|
1036
|
+
* @param input - Link parameters
|
|
1037
|
+
* @returns Result with subscription ID, link status, and features applied
|
|
1038
|
+
*
|
|
1039
|
+
* @example
|
|
1040
|
+
* ```typescript
|
|
1041
|
+
* // After creating subscription on your Stripe account:
|
|
1042
|
+
* const result = await os.billing.linkSubscription({
|
|
1043
|
+
* companyId: company.id,
|
|
1044
|
+
* stripeSubscriptionId: 'sub_xxx',
|
|
1045
|
+
* stripeCustomerId: 'cus_xxx', // Optional
|
|
1046
|
+
* tierCode: 'pro', // Apply tier features
|
|
1047
|
+
* displayName: 'Pro Plan'
|
|
1048
|
+
* })
|
|
1049
|
+
*
|
|
1050
|
+
* console.log({
|
|
1051
|
+
* subscriptionId: result.subscriptionId,
|
|
1052
|
+
* isNew: !result.alreadyLinked,
|
|
1053
|
+
* featuresApplied: result.featuresApplied
|
|
1054
|
+
* })
|
|
1055
|
+
* ```
|
|
1056
|
+
*/
|
|
1057
|
+
linkSubscription: (input: LinkSubscriptionInput) => Promise<{
|
|
988
1058
|
success: boolean;
|
|
989
1059
|
subscriptionId: string;
|
|
990
1060
|
alreadyLinked: boolean;
|
|
@@ -999,6 +1069,31 @@ export declare class ChatarminOS {
|
|
|
999
1069
|
tierApplied: boolean;
|
|
1000
1070
|
featuresApplied: number;
|
|
1001
1071
|
}>;
|
|
1072
|
+
/**
|
|
1073
|
+
* Get billing status for a company.
|
|
1074
|
+
*
|
|
1075
|
+
* Quick check for subscription status, active features, and
|
|
1076
|
+
* billing profile information.
|
|
1077
|
+
*
|
|
1078
|
+
* @param companyId - Company ID to check
|
|
1079
|
+
* @returns Billing status overview
|
|
1080
|
+
*
|
|
1081
|
+
* @example
|
|
1082
|
+
* ```typescript
|
|
1083
|
+
* const status = await os.billing.getStatus(company.id)
|
|
1084
|
+
*
|
|
1085
|
+
* console.log({
|
|
1086
|
+
* hasBilling: status.hasBillingProfile,
|
|
1087
|
+
* subscriptions: status.activeSubscriptions.length,
|
|
1088
|
+
* features: status.enabledFeaturesCount
|
|
1089
|
+
* })
|
|
1090
|
+
*
|
|
1091
|
+
* // Check active tier
|
|
1092
|
+
* if (status.activeSubscriptions[0]?.tier) {
|
|
1093
|
+
* console.log(`Current tier: ${status.activeSubscriptions[0].tier.name}`)
|
|
1094
|
+
* }
|
|
1095
|
+
* ```
|
|
1096
|
+
*/
|
|
1002
1097
|
getStatus: (companyId: string) => Promise<{
|
|
1003
1098
|
hasBillingProfile: boolean;
|
|
1004
1099
|
stripeCustomerId: string | null;
|
|
@@ -1011,23 +1106,23 @@ export declare class ChatarminOS {
|
|
|
1011
1106
|
name: string;
|
|
1012
1107
|
metadata: unknown;
|
|
1013
1108
|
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
1109
|
company_id: string | null;
|
|
1110
|
+
last_synced_at: Date | null;
|
|
1022
1111
|
stripe_customer_id: string;
|
|
1023
1112
|
link_status: string;
|
|
1024
1113
|
default_currency: string;
|
|
1025
1114
|
has_payment_method: boolean;
|
|
1115
|
+
subscription_status: string;
|
|
1116
|
+
contract_start_at: Date | null;
|
|
1117
|
+
contract_end_at: Date | null;
|
|
1118
|
+
mrr_cents: number;
|
|
1119
|
+
mrr_committed_cents: number;
|
|
1120
|
+
mrr_usage_cents: number;
|
|
1026
1121
|
open_invoices_count: number;
|
|
1027
1122
|
open_amount_cents: number;
|
|
1028
1123
|
past_due_invoices_count: number;
|
|
1029
1124
|
past_due_amount_cents: number;
|
|
1030
|
-
|
|
1125
|
+
max_days_overdue: number;
|
|
1031
1126
|
company_group_id: string | null;
|
|
1032
1127
|
}[];
|
|
1033
1128
|
activeSubscriptions: {
|
|
@@ -1044,8 +1139,14 @@ export declare class ChatarminOS {
|
|
|
1044
1139
|
}[];
|
|
1045
1140
|
enabledFeaturesCount: number;
|
|
1046
1141
|
}>;
|
|
1047
|
-
|
|
1048
|
-
|
|
1142
|
+
/**
|
|
1143
|
+
* Sync billing profile, subscriptions, and feature access from Stripe.
|
|
1144
|
+
*/
|
|
1145
|
+
syncCompanyFromStripe: (input: SyncCompanyFromStripeInput) => Promise<SyncCompanyFromStripeResult>;
|
|
1146
|
+
/**
|
|
1147
|
+
* Relink billing profile to a new Stripe customer (destructive).
|
|
1148
|
+
*/
|
|
1149
|
+
relinkBillingProfile: (input: RelinkBillingProfileInput) => Promise<{
|
|
1049
1150
|
billingProfileId: string;
|
|
1050
1151
|
stripeCustomerId: string;
|
|
1051
1152
|
subscriptionsSynced: number;
|
|
@@ -1053,7 +1154,10 @@ export declare class ChatarminOS {
|
|
|
1053
1154
|
featuresLinked: number;
|
|
1054
1155
|
matchedMeters: number;
|
|
1055
1156
|
}>;
|
|
1056
|
-
|
|
1157
|
+
/**
|
|
1158
|
+
* Ensure a feature is linked to an active Stripe subscription item.
|
|
1159
|
+
*/
|
|
1160
|
+
ensureFeatureSubscription: (input: EnsureFeatureSubscriptionInput) => Promise<EnsureFeatureSubscriptionResult>;
|
|
1057
1161
|
};
|
|
1058
1162
|
/**
|
|
1059
1163
|
* Manual link operations for associating external IDs with companies.
|
|
@@ -1121,6 +1225,7 @@ export declare class ChatarminOS {
|
|
|
1121
1225
|
link_type: string;
|
|
1122
1226
|
label: string | null;
|
|
1123
1227
|
external_display_name: string | null;
|
|
1228
|
+
billing_profile_id: string | null;
|
|
1124
1229
|
}>;
|
|
1125
1230
|
/**
|
|
1126
1231
|
* Delete all product links for this product.
|
|
@@ -1569,8 +1674,6 @@ export declare class ChatarminOS {
|
|
|
1569
1674
|
*
|
|
1570
1675
|
* if (result.linkStatus === 'already_linked') {
|
|
1571
1676
|
* console.log('Welcome back!')
|
|
1572
|
-
* } else if (result.linkStatus === 'linked') {
|
|
1573
|
-
* console.log('Found existing company, linked!')
|
|
1574
1677
|
* } else {
|
|
1575
1678
|
* console.log('New company created!')
|
|
1576
1679
|
* }
|