@chatarmin/os 1.7.0 → 1.8.1
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 +386 -8
- package/dist/billing/client.d.ts +8 -0
- package/dist/billing/client.d.ts.map +1 -0
- package/dist/billing/client.js +46 -0
- package/dist/billing/index.d.ts +3 -0
- package/dist/billing/index.d.ts.map +1 -0
- package/dist/billing/index.js +1 -0
- package/dist/billing/types.d.ts +201 -0
- package/dist/billing/types.d.ts.map +1 -0
- package/dist/billing/types.js +1 -0
- package/dist/billing/usage-breakdown-types.d.ts +132 -0
- package/dist/billing/usage-breakdown-types.d.ts.map +1 -0
- package/dist/billing/usage-breakdown-types.js +1 -0
- package/dist/companies/client.d.ts +2 -2
- package/dist/companies/client.d.ts.map +1 -1
- package/dist/companies/index.d.ts +2 -2
- package/dist/companies/index.d.ts.map +1 -1
- package/dist/companies/index.js +1 -1
- package/dist/features/client.d.ts +8 -0
- package/dist/features/client.d.ts.map +1 -0
- package/dist/features/client.js +18 -0
- package/dist/features/index.d.ts +3 -0
- package/dist/features/index.d.ts.map +1 -0
- package/dist/features/index.js +1 -0
- package/dist/features/types.d.ts +184 -0
- package/dist/features/types.d.ts.map +1 -0
- package/dist/features/types.js +1 -0
- package/dist/index.d.ts +29 -766
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -364
- package/dist/index.js.map +1 -0
- package/dist/webhooks/index.d.ts +17 -0
- package/dist/webhooks/index.d.ts.map +1 -1
- package/dist/webhooks/index.js +17 -0
- package/dist/webhooks/index.js.map +1 -0
- package/package.json +2 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import type { AppRouter } from "@chatarmin/api";
|
|
2
|
-
import { type CompaniesClient } from "./companies";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
1
|
+
import type { AppRouter } from "@chatarmin/api/trpc-types";
|
|
2
|
+
import { type CompaniesClient } from "./companies/index.js";
|
|
3
|
+
import { type BillingClient } from "./billing/index.js";
|
|
4
|
+
import { type FeaturesClient } from "./features/index.js";
|
|
5
|
+
export { webhooks, constructProductWebhookEvent, generateTestWebhookHeaders, OsWebhookSignatureVerificationError, WEBHOOK_ID_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_TIMESTAMP_HEADER, } from "./webhooks/index.js";
|
|
6
|
+
export type { ConstructProductWebhookEventOptions, ProductWebhookEventPayload, ProductWebhookHeaders, VerifiedProductWebhookEvent, } from "./webhooks/index.js";
|
|
7
|
+
export type { CompaniesClient, CompanyAssignee, CompanyAssignees, CreateCompanyInput, CreateCompanyResult, GetCompanyInput, LinkedCompany, ListCompaniesInput, ListCompaniesResult, ListLinkedCompaniesInput, ListLinkedCompaniesResult, ProductCompany, UpdateCompanyResult, } from "./companies/index.js";
|
|
8
|
+
export type { BillingClient, BillingInvoiceSummary, BillingOverview, BillingProfileSummary, BillingSubscriptionSummary, ClaimCheckoutInput, ClaimCheckoutResult, CreateBillingPortalSessionInput, EnsureFeatureSubscriptionInput, EnsureFeatureSubscriptionResult, GetBillingOverviewInput, GetUsageInput, LinkSubscriptionInput, LinkSubscriptionResult, ListBillingInvoicesOptions, PeriodOffsetRange, RelinkBillingProfileInput, ResolveInvoicePaymentUrlInput, SetUsageInput, SyncCompanyFromStripeInput, SyncCompanyFromStripeResult, UsageAggregate, UsageCycleBucket, UsageCycleSummary, UsagePoint, UsageQueryResult, UsageRecord, UsageSubscriptionItem, UsageResult, } from "./billing/index.js";
|
|
9
|
+
export type { ExternalOrgFeatureAccessItem, FeatureAccessByExternalOrgIdResult, FeatureAccessItem, FeatureBillingDetails, FeatureCheckByExternalOrgIdResult, FeatureCheckInput, FeatureCheckResult, FeatureSetAccessInput, FeatureSetAccessResult, FeaturesClient, ListFeatureAccessInput, } from "./features/index.js";
|
|
6
10
|
/**
|
|
7
11
|
* Configuration options for the ChatarminOS SDK client.
|
|
8
12
|
*/
|
|
@@ -42,202 +46,6 @@ export declare class ChatarminOSError extends Error {
|
|
|
42
46
|
details: ChatarminOSErrorDetails;
|
|
43
47
|
};
|
|
44
48
|
}
|
|
45
|
-
/**
|
|
46
|
-
* Input for checking feature access.
|
|
47
|
-
*/
|
|
48
|
-
export interface FeatureCheckInput {
|
|
49
|
-
/** Company ID to check */
|
|
50
|
-
companyId: string;
|
|
51
|
-
/** Feature code (e.g., "ai_credit", "whatsapp_messages") */
|
|
52
|
-
featureCode: string;
|
|
53
|
-
/**
|
|
54
|
-
* Verify Stripe subscription is active for this feature.
|
|
55
|
-
* When true, the response includes subscription validation fields
|
|
56
|
-
* and `canUse` will be false if no active subscription exists.
|
|
57
|
-
* @default false
|
|
58
|
-
*/
|
|
59
|
-
verifySubscription?: boolean;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Billing details for a feature (when includeBillingDetails: true)
|
|
63
|
-
*/
|
|
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
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Input for listing feature access.
|
|
84
|
-
*/
|
|
85
|
-
export interface ListFeatureAccessInput {
|
|
86
|
-
/** Company ID */
|
|
87
|
-
companyId: string;
|
|
88
|
-
/**
|
|
89
|
-
* Include billing details (Stripe price, usage, billing period).
|
|
90
|
-
* Adds a `billing` field to each feature with subscription linkage info.
|
|
91
|
-
* @default false
|
|
92
|
-
*/
|
|
93
|
-
includeBillingDetails?: boolean;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Result of a feature access check.
|
|
97
|
-
*/
|
|
98
|
-
export interface FeatureCheckResult {
|
|
99
|
-
/** Feature code */
|
|
100
|
-
featureCode: string;
|
|
101
|
-
/** Whether the feature is enabled for this company */
|
|
102
|
-
isEnabled: boolean;
|
|
103
|
-
/** Whether this feature tracks quantity/usage */
|
|
104
|
-
hasQuantity: boolean;
|
|
105
|
-
/** Current usage count (for quantity-based features) */
|
|
106
|
-
currentUsage: number;
|
|
107
|
-
/** Maximum allowed quantity (null = unlimited) */
|
|
108
|
-
quantityLimit: number | null;
|
|
109
|
-
/** Included/free quantity before overage charges */
|
|
110
|
-
includedQuantity: number;
|
|
111
|
-
/** Remaining quantity before limit (null = unlimited) */
|
|
112
|
-
remaining: number | null;
|
|
113
|
-
/** Whether usage limit has been reached */
|
|
114
|
-
isAtLimit: boolean;
|
|
115
|
-
/** Whether the company can use this feature (enabled + not at limit + subscription if verified) */
|
|
116
|
-
canUse: boolean;
|
|
117
|
-
/** Whether an active Stripe subscription exists for this feature */
|
|
118
|
-
hasActiveSubscription?: boolean;
|
|
119
|
-
/** Stripe subscription status (active, trialing, canceled, etc.) */
|
|
120
|
-
subscriptionStatus?: string | null;
|
|
121
|
-
/** Stripe price ID from the subscription item */
|
|
122
|
-
stripePriceId?: string | null;
|
|
123
|
-
/** Stripe subscription ID */
|
|
124
|
-
stripeSubscriptionId?: string | null;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Input for updating feature access with partial config merge.
|
|
128
|
-
*/
|
|
129
|
-
export interface FeatureSetAccessInput {
|
|
130
|
-
/** Company ID to update (either this or externalOrgId required) */
|
|
131
|
-
companyId?: string;
|
|
132
|
-
/** Your product's external org ID (either this or companyId required) */
|
|
133
|
-
externalOrgId?: string;
|
|
134
|
-
/** Feature code to update */
|
|
135
|
-
featureCode: string;
|
|
136
|
-
/** Enable or disable the feature */
|
|
137
|
-
isEnabled?: boolean;
|
|
138
|
-
/** Maximum quantity allowed (for quantity-based features) */
|
|
139
|
-
quantityLimit?: number | null;
|
|
140
|
-
/** Included quantity before billing kicks in */
|
|
141
|
-
includedQuantity?: number | null;
|
|
142
|
-
/**
|
|
143
|
-
* Custom config values to merge with existing config.
|
|
144
|
-
* Only specified fields will be updated - other fields remain unchanged.
|
|
145
|
-
*/
|
|
146
|
-
config?: Record<string, unknown>;
|
|
147
|
-
/** Source of the access change */
|
|
148
|
-
source?: "subscription" | "manual" | "trial" | "api";
|
|
149
|
-
/** When the access expires (null for no expiration) */
|
|
150
|
-
validUntil?: Date | null;
|
|
151
|
-
}
|
|
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;
|
|
216
|
-
}
|
|
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;
|
|
225
|
-
}
|
|
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;
|
|
240
|
-
}
|
|
241
49
|
/**
|
|
242
50
|
* Input for applying a tier to a company.
|
|
243
51
|
*/
|
|
@@ -416,8 +224,8 @@ export interface OnboardResult {
|
|
|
416
224
|
*/
|
|
417
225
|
export declare class ChatarminOS {
|
|
418
226
|
static webhooks: {
|
|
419
|
-
constructEvent: typeof import("./
|
|
420
|
-
generateTestHeaders: typeof import("./
|
|
227
|
+
constructEvent: typeof import("./index.js").constructProductWebhookEvent;
|
|
228
|
+
generateTestHeaders: typeof import("./index.js").generateTestWebhookHeaders;
|
|
421
229
|
};
|
|
422
230
|
private client;
|
|
423
231
|
private call;
|
|
@@ -524,11 +332,11 @@ export declare class ChatarminOS {
|
|
|
524
332
|
} & ContactInput) => Promise<{
|
|
525
333
|
isNew: boolean;
|
|
526
334
|
id: string;
|
|
527
|
-
|
|
335
|
+
name: string | null;
|
|
528
336
|
created_at: Date;
|
|
529
337
|
updated_at: Date;
|
|
338
|
+
role: string | null;
|
|
530
339
|
short_id: string | null;
|
|
531
|
-
name: string | null;
|
|
532
340
|
metadata: unknown;
|
|
533
341
|
is_primary: boolean;
|
|
534
342
|
avatar_url: string | null;
|
|
@@ -578,11 +386,11 @@ export declare class ChatarminOS {
|
|
|
578
386
|
*/
|
|
579
387
|
list: (companyId: string, primaryOnly?: boolean) => Promise<{
|
|
580
388
|
id: string;
|
|
581
|
-
|
|
389
|
+
name: string | null;
|
|
582
390
|
created_at: Date;
|
|
583
391
|
updated_at: Date;
|
|
392
|
+
role: string | null;
|
|
584
393
|
short_id: string | null;
|
|
585
|
-
name: string | null;
|
|
586
394
|
metadata: unknown;
|
|
587
395
|
is_primary: boolean;
|
|
588
396
|
avatar_url: string | null;
|
|
@@ -611,554 +419,9 @@ export declare class ChatarminOS {
|
|
|
611
419
|
* }
|
|
612
420
|
* ```
|
|
613
421
|
*/
|
|
614
|
-
get features():
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
*
|
|
618
|
-
* Returns detailed access information including whether the feature
|
|
619
|
-
* is enabled, current usage, limits, and whether they can use more.
|
|
620
|
-
*
|
|
621
|
-
* @param input - Check parameters
|
|
622
|
-
* @param input.companyId - Company ID to check
|
|
623
|
-
* @param input.featureCode - Feature code (e.g., "ai_credit")
|
|
624
|
-
* @returns Detailed feature access information
|
|
625
|
-
*
|
|
626
|
-
* @example
|
|
627
|
-
* ```typescript
|
|
628
|
-
* const access = await os.features.check({
|
|
629
|
-
* companyId: 'comp_xxx',
|
|
630
|
-
* featureCode: 'ai_credit'
|
|
631
|
-
* })
|
|
632
|
-
*
|
|
633
|
-
* console.log({
|
|
634
|
-
* enabled: access.isEnabled,
|
|
635
|
-
* canUse: access.canUse,
|
|
636
|
-
* usage: access.currentUsage,
|
|
637
|
-
* limit: access.quantityLimit,
|
|
638
|
-
* remaining: access.remaining,
|
|
639
|
-
* included: access.includedQuantity
|
|
640
|
-
* })
|
|
641
|
-
* ```
|
|
642
|
-
*/
|
|
643
|
-
check: (input: FeatureCheckInput) => Promise<FeatureCheckResult>;
|
|
644
|
-
/**
|
|
645
|
-
* List all features and their access status for a company.
|
|
646
|
-
*
|
|
647
|
-
* Returns a complete list of features with their current status,
|
|
648
|
-
* useful for displaying a company's full feature set or building
|
|
649
|
-
* a feature comparison view.
|
|
650
|
-
*
|
|
651
|
-
* @param input - Query parameters
|
|
652
|
-
* @returns Array of feature access records
|
|
653
|
-
*
|
|
654
|
-
* @example Basic usage
|
|
655
|
-
* ```typescript
|
|
656
|
-
* const features = await os.features.listAccess({ companyId: company.id })
|
|
657
|
-
*
|
|
658
|
-
* for (const f of features) {
|
|
659
|
-
* console.log(`${f.featureName}: ${f.isEnabled ? '✓' : '✗'}`)
|
|
660
|
-
* if (f.quantityLimit) {
|
|
661
|
-
* console.log(` Usage: ${f.currentUsage} / ${f.quantityLimit}`)
|
|
662
|
-
* }
|
|
663
|
-
* }
|
|
664
|
-
* ```
|
|
665
|
-
*
|
|
666
|
-
* @example With billing details
|
|
667
|
-
* ```typescript
|
|
668
|
-
* const features = await os.features.listAccess({
|
|
669
|
-
* companyId: company.id,
|
|
670
|
-
* includeBillingDetails: true
|
|
671
|
-
* })
|
|
672
|
-
*
|
|
673
|
-
* for (const f of features) {
|
|
674
|
-
* console.log(`${f.featureName}:`)
|
|
675
|
-
* console.log(` Usage: ${f.currentUsage} / ${f.quantityLimit}`)
|
|
676
|
-
*
|
|
677
|
-
* if (f.billing) {
|
|
678
|
-
* console.log(` Price: ${f.billing.unitAmount / 100} ${f.billing.currency}`)
|
|
679
|
-
* console.log(` Period: ${f.billing.currentPeriodStart} to ${f.billing.currentPeriodEnd}`)
|
|
680
|
-
* console.log(` Status: ${f.billing.subscriptionStatus}`)
|
|
681
|
-
* }
|
|
682
|
-
* }
|
|
683
|
-
* ```
|
|
684
|
-
*/
|
|
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
|
-
})[]>;
|
|
728
|
-
/**
|
|
729
|
-
* Update feature access for a company with partial config merge.
|
|
730
|
-
*
|
|
731
|
-
* This allows you to update individual feature configs without
|
|
732
|
-
* replacing all config values. Only the fields you specify in
|
|
733
|
-
* `config` will be updated - other fields remain unchanged.
|
|
734
|
-
*
|
|
735
|
-
* @param input - Update parameters
|
|
736
|
-
* @returns Updated feature access information
|
|
737
|
-
*
|
|
738
|
-
* @example Update by company ID
|
|
739
|
-
* ```typescript
|
|
740
|
-
* await os.features.setAccess({
|
|
741
|
-
* companyId: 'comp_xxx',
|
|
742
|
-
* featureCode: 'ai_credit',
|
|
743
|
-
* isEnabled: true,
|
|
744
|
-
* config: {
|
|
745
|
-
* included_quantity: 500,
|
|
746
|
-
* max_quantity: 1000
|
|
747
|
-
* }
|
|
748
|
-
* })
|
|
749
|
-
* ```
|
|
750
|
-
*
|
|
751
|
-
* @example Update by your product's external org ID
|
|
752
|
-
* ```typescript
|
|
753
|
-
* await os.features.setAccess({
|
|
754
|
-
* externalOrgId: 'org_abc123',
|
|
755
|
-
* featureCode: 'ai_credit',
|
|
756
|
-
* config: { tier_level: 'premium' }
|
|
757
|
-
* })
|
|
758
|
-
* ```
|
|
759
|
-
*
|
|
760
|
-
* @example Partial config update (only updates specified fields)
|
|
761
|
-
* ```typescript
|
|
762
|
-
* // Existing config: { tier_level: 'basic', max_seats: 5 }
|
|
763
|
-
* await os.features.setAccess({
|
|
764
|
-
* companyId: 'comp_xxx',
|
|
765
|
-
* featureCode: 'team_seats',
|
|
766
|
-
* config: { max_seats: 10 } // tier_level remains 'basic'
|
|
767
|
-
* })
|
|
768
|
-
* // New config: { tier_level: 'basic', max_seats: 10 }
|
|
769
|
-
* ```
|
|
770
|
-
*/
|
|
771
|
-
setAccess: (input: FeatureSetAccessInput) => Promise<{
|
|
772
|
-
success: boolean;
|
|
773
|
-
featureCode: string;
|
|
774
|
-
companyId: string;
|
|
775
|
-
isEnabled: boolean;
|
|
776
|
-
quantityLimit: number | null;
|
|
777
|
-
includedQuantity: number | null;
|
|
778
|
-
configValues: {
|
|
779
|
-
[x: string]: unknown;
|
|
780
|
-
};
|
|
781
|
-
source: string;
|
|
782
|
-
validUntil: Date | null;
|
|
783
|
-
created: boolean;
|
|
784
|
-
updated: boolean;
|
|
785
|
-
}>;
|
|
786
|
-
/**
|
|
787
|
-
* Get all feature access using your product's external org ID.
|
|
788
|
-
*
|
|
789
|
-
* Convenience method when you know the external org ID but not
|
|
790
|
-
* the ChatarminOS company ID.
|
|
791
|
-
*
|
|
792
|
-
* @param externalOrgId - Your product's organization ID
|
|
793
|
-
* @returns All features with their access status and config values
|
|
794
|
-
*
|
|
795
|
-
* @example
|
|
796
|
-
* ```typescript
|
|
797
|
-
* const result = await os.features.getAccessByExternalOrgId('org_abc123')
|
|
798
|
-
*
|
|
799
|
-
* console.log(`Company: ${result.companyId}`)
|
|
800
|
-
* for (const f of result.features) {
|
|
801
|
-
* console.log(`${f.featureCode}: ${f.isEnabled}`)
|
|
802
|
-
* console.log(` Config:`, f.configValues)
|
|
803
|
-
* }
|
|
804
|
-
* ```
|
|
805
|
-
*/
|
|
806
|
-
getAccessByExternalOrgId: (externalOrgId: string) => Promise<{
|
|
807
|
-
companyId: string;
|
|
808
|
-
productLinkId: string;
|
|
809
|
-
externalOrgId: string;
|
|
810
|
-
features: {
|
|
811
|
-
featureCode: string;
|
|
812
|
-
featureName: string;
|
|
813
|
-
description: string | null;
|
|
814
|
-
hasQuantity: boolean;
|
|
815
|
-
isEnabled: boolean;
|
|
816
|
-
quantityLimit: number | null;
|
|
817
|
-
includedQuantity: number;
|
|
818
|
-
configValues: Record<string, unknown>;
|
|
819
|
-
source: string;
|
|
820
|
-
validUntil: Date | null;
|
|
821
|
-
}[];
|
|
822
|
-
}>;
|
|
823
|
-
/**
|
|
824
|
-
* Check specific feature access using your product's external org ID.
|
|
825
|
-
*
|
|
826
|
-
* @param externalOrgId - Your product's organization ID
|
|
827
|
-
* @param featureCode - Feature code to check
|
|
828
|
-
* @returns Detailed feature access including config values
|
|
829
|
-
*
|
|
830
|
-
* @example
|
|
831
|
-
* ```typescript
|
|
832
|
-
* const access = await os.features.checkByExternalOrgId(
|
|
833
|
-
* 'org_abc123',
|
|
834
|
-
* 'ai_credit'
|
|
835
|
-
* )
|
|
836
|
-
*
|
|
837
|
-
* if (access.canUse) {
|
|
838
|
-
* console.log(`Remaining: ${access.remaining}`)
|
|
839
|
-
* console.log(`Config:`, access.configValues)
|
|
840
|
-
* }
|
|
841
|
-
* ```
|
|
842
|
-
*/
|
|
843
|
-
checkByExternalOrgId: (externalOrgId: string, featureCode: string) => Promise<{
|
|
844
|
-
featureCode: string;
|
|
845
|
-
companyId: string;
|
|
846
|
-
externalOrgId: string;
|
|
847
|
-
isEnabled: boolean;
|
|
848
|
-
hasQuantity: boolean;
|
|
849
|
-
currentUsage: number;
|
|
850
|
-
quantityLimit: number | null;
|
|
851
|
-
includedQuantity: number;
|
|
852
|
-
remaining: number | null;
|
|
853
|
-
isAtLimit: boolean;
|
|
854
|
-
canUse: boolean;
|
|
855
|
-
configValues: {};
|
|
856
|
-
} | {
|
|
857
|
-
configValues: Record<string, unknown>;
|
|
858
|
-
featureCode: string;
|
|
859
|
-
isEnabled: boolean;
|
|
860
|
-
hasQuantity: boolean;
|
|
861
|
-
currentUsage: number;
|
|
862
|
-
quantityLimit: number | null;
|
|
863
|
-
includedQuantity: number;
|
|
864
|
-
remaining: number | null;
|
|
865
|
-
isAtLimit: boolean;
|
|
866
|
-
canUse: boolean;
|
|
867
|
-
companyId: string;
|
|
868
|
-
productLinkId: string;
|
|
869
|
-
externalOrgId: string;
|
|
870
|
-
}>;
|
|
871
|
-
};
|
|
872
|
-
/**
|
|
873
|
-
* Billing, usage tracking, and subscription management.
|
|
874
|
-
*
|
|
875
|
-
* Set feature usage for billing, claim subscriptions from Stripe checkout,
|
|
876
|
-
* or link existing Stripe subscriptions to companies.
|
|
877
|
-
*
|
|
878
|
-
* @example Set Usage
|
|
879
|
-
* ```typescript
|
|
880
|
-
* await os.billing.setUsage({
|
|
881
|
-
* companyId: company.id,
|
|
882
|
-
* featureCode: 'ai_credit',
|
|
883
|
-
* absoluteValue: 42,
|
|
884
|
-
* reason: 'Synced current usage'
|
|
885
|
-
* })
|
|
886
|
-
* ```
|
|
887
|
-
*
|
|
888
|
-
* @example Claim Checkout Subscription
|
|
889
|
-
* ```typescript
|
|
890
|
-
* // After Stripe checkout completes
|
|
891
|
-
* const result = await os.billing.claimCheckout({
|
|
892
|
-
* companyId: company.id,
|
|
893
|
-
* checkoutSessionId: 'cs_xxx'
|
|
894
|
-
* })
|
|
895
|
-
* ```
|
|
896
|
-
*
|
|
897
|
-
* @example Link Existing Subscription
|
|
898
|
-
* ```typescript
|
|
899
|
-
* // When you create subscriptions on your Stripe account
|
|
900
|
-
* const result = await os.billing.linkSubscription({
|
|
901
|
-
* companyId: company.id,
|
|
902
|
-
* stripeSubscriptionId: 'sub_xxx',
|
|
903
|
-
* tierCode: 'pro' // Apply tier features
|
|
904
|
-
* })
|
|
905
|
-
* ```
|
|
906
|
-
*/
|
|
907
|
-
get billing(): {
|
|
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
|
-
*/
|
|
963
|
-
getUsageHistory: (companyId: string, featureCode: string, options?: {
|
|
964
|
-
limit?: number;
|
|
965
|
-
includeDelivered?: boolean;
|
|
966
|
-
eventType?: "increment" | "set" | "adjustment";
|
|
967
|
-
}) => Promise<{
|
|
968
|
-
id: string;
|
|
969
|
-
created_at: Date;
|
|
970
|
-
metadata: unknown;
|
|
971
|
-
billing_profile_id: string | null;
|
|
972
|
-
source: string;
|
|
973
|
-
idempotency_key: string;
|
|
974
|
-
event_type: string;
|
|
975
|
-
subscription_item_id: string | null;
|
|
976
|
-
feature_access_id: string | null;
|
|
977
|
-
meter_code: string;
|
|
978
|
-
quantity: number;
|
|
979
|
-
stripe_price_id: string | null;
|
|
980
|
-
event_time: Date;
|
|
981
|
-
previous_value: number | null;
|
|
982
|
-
adjustment_reason: string | null;
|
|
983
|
-
adjusts_event_id: string | null;
|
|
984
|
-
stripe_delivery_status: string;
|
|
985
|
-
stripe_delivery_attempts: number;
|
|
986
|
-
stripe_last_delivery_attempt_at: Date | null;
|
|
987
|
-
stripe_event_id: string | null;
|
|
988
|
-
stripe_delivery_error: string | null;
|
|
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;
|
|
994
|
-
}[]>;
|
|
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<{
|
|
1020
|
-
success: boolean;
|
|
1021
|
-
subscriptionId: string;
|
|
1022
|
-
alreadyClaimed: boolean;
|
|
1023
|
-
status?: undefined;
|
|
1024
|
-
} | {
|
|
1025
|
-
success: boolean;
|
|
1026
|
-
subscriptionId: string;
|
|
1027
|
-
alreadyClaimed: boolean;
|
|
1028
|
-
status: import("stripe").Stripe.Subscription.Status;
|
|
1029
|
-
}>;
|
|
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<{
|
|
1058
|
-
success: boolean;
|
|
1059
|
-
subscriptionId: string;
|
|
1060
|
-
alreadyLinked: boolean;
|
|
1061
|
-
status?: undefined;
|
|
1062
|
-
tierApplied?: undefined;
|
|
1063
|
-
featuresApplied?: undefined;
|
|
1064
|
-
} | {
|
|
1065
|
-
success: boolean;
|
|
1066
|
-
subscriptionId: string;
|
|
1067
|
-
alreadyLinked: boolean;
|
|
1068
|
-
status: import("stripe").Stripe.Subscription.Status;
|
|
1069
|
-
tierApplied: boolean;
|
|
1070
|
-
featuresApplied: number;
|
|
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
|
-
*/
|
|
1097
|
-
getStatus: (companyId: string) => Promise<{
|
|
1098
|
-
hasBillingProfile: boolean;
|
|
1099
|
-
stripeCustomerId: string | null;
|
|
1100
|
-
billingProfiles: {
|
|
1101
|
-
id: string;
|
|
1102
|
-
organization_id: string;
|
|
1103
|
-
created_at: Date;
|
|
1104
|
-
updated_at: Date;
|
|
1105
|
-
short_id: string | null;
|
|
1106
|
-
name: string;
|
|
1107
|
-
metadata: unknown;
|
|
1108
|
-
status: string;
|
|
1109
|
-
company_id: string | null;
|
|
1110
|
-
last_synced_at: Date | null;
|
|
1111
|
-
stripe_customer_id: string;
|
|
1112
|
-
link_status: string;
|
|
1113
|
-
default_currency: string;
|
|
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;
|
|
1121
|
-
open_invoices_count: number;
|
|
1122
|
-
open_amount_cents: number;
|
|
1123
|
-
past_due_invoices_count: number;
|
|
1124
|
-
past_due_amount_cents: number;
|
|
1125
|
-
max_days_overdue: number;
|
|
1126
|
-
company_group_id: string | null;
|
|
1127
|
-
}[];
|
|
1128
|
-
activeSubscriptions: {
|
|
1129
|
-
id: string;
|
|
1130
|
-
billingProfileId: string;
|
|
1131
|
-
status: string;
|
|
1132
|
-
stripeSubscriptionId: string | null;
|
|
1133
|
-
currentPeriodEnd: Date | null;
|
|
1134
|
-
trialEnd: Date | null;
|
|
1135
|
-
tier: {
|
|
1136
|
-
code: string;
|
|
1137
|
-
name: string | null;
|
|
1138
|
-
} | null;
|
|
1139
|
-
}[];
|
|
1140
|
-
enabledFeaturesCount: number;
|
|
1141
|
-
}>;
|
|
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<{
|
|
1150
|
-
billingProfileId: string;
|
|
1151
|
-
stripeCustomerId: string;
|
|
1152
|
-
subscriptionsSynced: number;
|
|
1153
|
-
subscriptionItemsSynced: number;
|
|
1154
|
-
featuresLinked: number;
|
|
1155
|
-
matchedMeters: number;
|
|
1156
|
-
}>;
|
|
1157
|
-
/**
|
|
1158
|
-
* Ensure a feature is linked to an active Stripe subscription item.
|
|
1159
|
-
*/
|
|
1160
|
-
ensureFeatureSubscription: (input: EnsureFeatureSubscriptionInput) => Promise<EnsureFeatureSubscriptionResult>;
|
|
1161
|
-
};
|
|
422
|
+
get features(): FeaturesClient;
|
|
423
|
+
/** Billing, usage tracking, subscriptions, and customer billing surfaces. */
|
|
424
|
+
get billing(): BillingClient;
|
|
1162
425
|
/**
|
|
1163
426
|
* Manual link operations for associating external IDs with companies.
|
|
1164
427
|
*
|
|
@@ -1211,19 +474,19 @@ export declare class ChatarminOS {
|
|
|
1211
474
|
label?: string;
|
|
1212
475
|
externalUserId?: string;
|
|
1213
476
|
}) => Promise<{
|
|
477
|
+
status: string;
|
|
1214
478
|
id: string;
|
|
1215
479
|
created_at: Date;
|
|
1216
480
|
updated_at: Date;
|
|
1217
481
|
metadata: unknown;
|
|
1218
|
-
status: string;
|
|
1219
|
-
product_id: string;
|
|
1220
482
|
company_id: string | null;
|
|
483
|
+
label: string | null;
|
|
484
|
+
product_id: string;
|
|
1221
485
|
external_org_id: string;
|
|
1222
486
|
external_user_id: string | null;
|
|
1223
487
|
confidence: number | null;
|
|
1224
488
|
sync_status: string;
|
|
1225
489
|
link_type: string;
|
|
1226
|
-
label: string | null;
|
|
1227
490
|
external_display_name: string | null;
|
|
1228
491
|
billing_profile_id: string | null;
|
|
1229
492
|
}>;
|
|
@@ -1347,15 +610,15 @@ export declare class ChatarminOS {
|
|
|
1347
610
|
hasQuantity: boolean;
|
|
1348
611
|
configValues: unknown;
|
|
1349
612
|
}[];
|
|
613
|
+
product_id: string;
|
|
614
|
+
code: string;
|
|
615
|
+
description: string | null;
|
|
1350
616
|
id: string;
|
|
617
|
+
name: string;
|
|
1351
618
|
created_at: Date;
|
|
1352
619
|
updated_at: Date;
|
|
1353
|
-
name: string;
|
|
1354
620
|
metadata: unknown;
|
|
1355
|
-
product_id: string;
|
|
1356
|
-
code: string;
|
|
1357
621
|
is_active: boolean;
|
|
1358
|
-
description: string | null;
|
|
1359
622
|
display_order: number;
|
|
1360
623
|
}[]>;
|
|
1361
624
|
/**
|
|
@@ -1465,15 +728,15 @@ export declare class ChatarminOS {
|
|
|
1465
728
|
hasQuantity: boolean;
|
|
1466
729
|
configValues: unknown;
|
|
1467
730
|
}[];
|
|
731
|
+
product_id: string;
|
|
732
|
+
code: string;
|
|
733
|
+
description: string | null;
|
|
1468
734
|
id: string;
|
|
735
|
+
name: string;
|
|
1469
736
|
created_at: Date;
|
|
1470
737
|
updated_at: Date;
|
|
1471
|
-
name: string;
|
|
1472
738
|
metadata: unknown;
|
|
1473
|
-
product_id: string;
|
|
1474
|
-
code: string;
|
|
1475
739
|
is_active: boolean;
|
|
1476
|
-
description: string | null;
|
|
1477
740
|
display_order: number;
|
|
1478
741
|
}[]>;
|
|
1479
742
|
/**
|