@chatarmin/os 1.5.2 → 1.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  import type { AppRouter } from "@chatarmin/api";
2
+ export type { BillingDashboardContext, BillingDashboardFeatureBilling, BillingDashboardFeatureRow, GetBillingDashboardContextInput, } from "./types/billing-dashboard-context.js";
3
+ export type { ListProductFeatureCatalogInput, ProductFeatureCatalogItem } from "./types/product-feature-catalog.js";
4
+ export type { ClaimCheckoutInput, EnsureFeatureSubscriptionInput, EnsureFeatureSubscriptionResult, LinkSubscriptionInput, RelinkBillingProfileInput, SetUsageInput, SyncCompanyFromStripeInput, SyncCompanyFromStripeResult, UsageResult, } from "./types/chatarmin-os-billing-inputs.js";
2
5
  /**
3
6
  * Configuration options for the ChatarminOS SDK client.
4
7
  */
@@ -211,76 +214,6 @@ export interface FeatureSetAccessInput {
211
214
  /** When the access expires (null for no expiration) */
212
215
  validUntil?: Date | null;
213
216
  }
214
- /**
215
- * Input for tracking feature usage (increment operation).
216
- */
217
- export interface TrackUsageInput {
218
- /** Company ID */
219
- companyId: string;
220
- /** Feature code to track */
221
- featureCode: string;
222
- /**
223
- * Quantity to track (must be positive).
224
- * @default 1
225
- */
226
- quantity?: number;
227
- /**
228
- * Idempotency key to prevent duplicate tracking.
229
- * Use a unique ID per operation (e.g., message ID).
230
- */
231
- idempotencyKey?: string;
232
- /**
233
- * Additional metadata for the usage event.
234
- * Store external references here (e.g., { externalId: "msg_123", type: "message" })
235
- */
236
- metadata?: Record<string, unknown>;
237
- /**
238
- * Ensure the feature is linked to an active Stripe subscription.
239
- * If no subscription item is linked:
240
- * 1. Checks existing subscriptions for a matching price
241
- * 2. If found, links the feature_access to that subscription item
242
- * 3. If not found, adds the feature's default price to a compatible subscription
243
- *
244
- * Only works with monthly/flexible subscriptions.
245
- * @default true
246
- */
247
- ensureSubscription?: boolean;
248
- }
249
- /**
250
- * Input for tracking usage by external org ID (product link).
251
- */
252
- export interface TrackUsageByExternalOrgIdInput {
253
- /** External org ID for the linked product */
254
- externalOrgId: string;
255
- /** Feature code to track */
256
- featureCode: string;
257
- /**
258
- * Quantity to track (must be positive).
259
- * @default 1
260
- */
261
- quantity?: number;
262
- /**
263
- * Idempotency key to prevent duplicate tracking.
264
- * Use a unique ID per operation (e.g., message ID).
265
- */
266
- idempotencyKey?: string;
267
- /**
268
- * Additional metadata for the usage event.
269
- * Store external references here (e.g., { externalId: "msg_123", type: "message" })
270
- */
271
- metadata?: Record<string, unknown>;
272
- /**
273
- * Ensure the feature is linked to an active Stripe subscription.
274
- * If no subscription item is linked:
275
- * 1. Checks existing subscriptions for a matching price
276
- * 2. If found, links the feature_access to that subscription item
277
- * 3. If not found, adds the feature's default price to a compatible subscription
278
- *
279
- * Only works with monthly/flexible subscriptions.
280
- * @default true
281
- */
282
- ensureSubscription?: boolean;
283
- }
284
217
  export interface LinkedCompany {
285
218
  id: string;
286
219
  name: string;
@@ -297,115 +230,6 @@ export interface ListLinkedCompaniesResult {
297
230
  companies: LinkedCompany[];
298
231
  nextCursor?: string;
299
232
  }
300
- export interface SyncCompanyFromStripeInput {
301
- companyId: string;
302
- stripeCustomerId?: string;
303
- forceReassign?: boolean;
304
- }
305
- export interface SyncCompanyFromStripeResult {
306
- billingProfileId: string;
307
- stripeCustomerId: string;
308
- subscriptionsSynced: number;
309
- subscriptionItemsSynced: number;
310
- featuresLinked: number;
311
- matchedMeters: number;
312
- }
313
- export interface EnsureFeatureSubscriptionInput {
314
- companyId: string;
315
- featureCode: string;
316
- stripeSubscriptionId?: string;
317
- }
318
- export interface RelinkBillingProfileInput {
319
- companyId: string;
320
- stripeCustomerId: string;
321
- }
322
- export interface EnsureFeatureSubscriptionResult {
323
- success: boolean;
324
- subscriptionItemId: string | null;
325
- stripePriceId: string | null;
326
- stripeSubscriptionId: string | null;
327
- action: "already_linked" | "linked_existing" | "created_new" | "failed";
328
- error?: string;
329
- }
330
- /**
331
- * Input for setting usage to an absolute value.
332
- * Use for corrections when you know what the total usage SHOULD be.
333
- */
334
- export interface SetUsageInput {
335
- /** Company ID */
336
- companyId: string;
337
- /** Feature code */
338
- featureCode: string;
339
- /** The absolute value to set usage to (must be >= 0) */
340
- absoluteValue: number;
341
- /** Reason for the set operation (required for audit trail) */
342
- reason: string;
343
- /** Admin user who performed the operation */
344
- performedBy?: string;
345
- /** Additional metadata (e.g., { ticketId: "SUPPORT-123" }) */
346
- metadata?: Record<string, unknown>;
347
- }
348
- /**
349
- * Input for adjusting usage by a delta.
350
- * Use for explicit corrections - supports negative values for refunds.
351
- */
352
- export interface AdjustUsageInput {
353
- /** Company ID */
354
- companyId: string;
355
- /** Feature code */
356
- featureCode: string;
357
- /** The delta to apply (can be negative for refunds) */
358
- delta: number;
359
- /** Reason for the adjustment (required for audit trail) */
360
- reason: string;
361
- /** Reference to original event being adjusted (for Stripe cancellations) */
362
- adjustsEventId?: string;
363
- /** Admin user who performed the operation */
364
- performedBy?: string;
365
- /** Additional metadata (e.g., { ticketId: "REFUND-456" }) */
366
- metadata?: Record<string, unknown>;
367
- }
368
- /**
369
- * Result from usage operations (track, set, adjust).
370
- */
371
- export interface UsageResult {
372
- success: boolean;
373
- featureCode: string;
374
- previousUsage: number;
375
- currentUsage: number;
376
- delta: number;
377
- quantityLimit: number | null;
378
- remaining: number | null;
379
- isAtLimit: boolean;
380
- includedQuantity: number;
381
- billableQuantity: number;
382
- meterId: string;
383
- eventId: string | null;
384
- }
385
- /**
386
- * Input for claiming a Stripe checkout subscription.
387
- */
388
- export interface ClaimCheckoutInput {
389
- /** Company ID to link the subscription to */
390
- companyId: string;
391
- /** Stripe checkout session ID (cs_xxx) */
392
- checkoutSessionId: string;
393
- }
394
- /**
395
- * Input for linking an existing Stripe subscription.
396
- */
397
- export interface LinkSubscriptionInput {
398
- /** Company ID to link the subscription to */
399
- companyId: string;
400
- /** Stripe subscription ID (sub_xxx) */
401
- stripeSubscriptionId: string;
402
- /** Stripe customer ID (cus_xxx) - fetched from subscription if not provided */
403
- stripeCustomerId?: string;
404
- /** Tier code to apply features from (e.g., "free", "pro") */
405
- tierCode?: string;
406
- /** Display name for the subscription */
407
- displayName?: string;
408
- }
409
233
  /**
410
234
  * Input for applying a tier to a company.
411
235
  */
@@ -574,12 +398,13 @@ export interface OnboardResult {
574
398
  * console.log(result.companyId) // Use this for all future API calls
575
399
  * ```
576
400
  *
577
- * @example Track Usage
401
+ * @example Set Usage
578
402
  * ```typescript
579
- * await os.billing.trackUsage({
403
+ * await os.billing.setUsage({
580
404
  * companyId: company.id,
581
405
  * featureCode: 'ai_credit',
582
- * quantity: 1
406
+ * absoluteValue: 1,
407
+ * reason: 'Synced current usage'
583
408
  * })
584
409
  * ```
585
410
  *
@@ -660,11 +485,11 @@ export declare class ChatarminOS {
660
485
  getByProductLink: (input: {
661
486
  externalOrgId: string;
662
487
  }) => Promise<{
488
+ id: string;
489
+ name: string;
663
490
  domain: string | null;
664
491
  external_org_id: string;
665
492
  external_user_id: string | null;
666
- id: string;
667
- name: string;
668
493
  } | null>;
669
494
  /**
670
495
  * Create a new company and link it to your product.
@@ -815,15 +640,14 @@ export declare class ChatarminOS {
815
640
  } & ContactInput) => Promise<{
816
641
  isNew: boolean;
817
642
  id: string;
818
- name: string | null;
819
- metadata: unknown;
643
+ role: string | null;
820
644
  created_at: Date;
821
645
  updated_at: Date;
822
- role: string | null;
823
- email: string;
824
- company_id: string | null;
825
646
  short_id: string | null;
647
+ name: string | null;
648
+ metadata: unknown;
826
649
  is_primary: boolean;
650
+ company_id: string | null;
827
651
  avatar_url: string | null;
828
652
  }>;
829
653
  /**
@@ -871,41 +695,18 @@ export declare class ChatarminOS {
871
695
  */
872
696
  list: (companyId: string, primaryOnly?: boolean) => Promise<{
873
697
  id: string;
874
- name: string | null;
875
- metadata: unknown;
698
+ role: string | null;
876
699
  created_at: Date;
877
700
  updated_at: Date;
878
- role: string | null;
879
- email: string;
880
- company_id: string | null;
881
701
  short_id: string | null;
702
+ name: string | null;
703
+ metadata: unknown;
882
704
  is_primary: boolean;
705
+ company_id: string | null;
883
706
  avatar_url: string | null;
884
707
  }[]>;
885
708
  };
886
- /**
887
- * Feature access and entitlement operations.
888
- *
889
- * Check what features a company has access to and their current usage.
890
- * Features are defined in ChatarminOS and assigned via subscription tiers.
891
- *
892
- * @example
893
- * ```typescript
894
- * // Check if company can use a feature
895
- * const access = await os.features.check({
896
- * companyId: company.id,
897
- * featureCode: 'ai_credit'
898
- * })
899
- *
900
- * if (access.canUse) {
901
- * // Feature is available
902
- * console.log(`Remaining: ${access.remaining}`)
903
- * } else {
904
- * // Feature is disabled or limit reached
905
- * console.log('Upgrade required')
906
- * }
907
- * ```
908
- */
709
+ /** Feature access and entitlements (`check`, `listAccess`, `listForProduct`, …). */
909
710
  get features(): {
910
711
  /**
911
712
  * Check if a company has access to a specific feature.
@@ -977,7 +778,7 @@ export declare class ChatarminOS {
977
778
  * }
978
779
  * ```
979
780
  */
980
- listAccess: (input: ListFeatureAccessInput | string) => Promise<({
781
+ listAccess: (input: ListFeatureAccessInput | string) => Promise<{
981
782
  featureCode: string;
982
783
  featureName: string;
983
784
  description: string | null;
@@ -993,8 +794,7 @@ export declare class ChatarminOS {
993
794
  stripeSubscriptionId: string | null;
994
795
  meterId: string | null;
995
796
  configValues: Record<string, unknown>;
996
- } | {
997
- billing: {
797
+ billing?: {
998
798
  stripeSubscriptionItemId: string | null;
999
799
  currentPeriodStart: Date | null;
1000
800
  currentPeriodEnd: Date | null;
@@ -1004,22 +804,8 @@ export declare class ChatarminOS {
1004
804
  usageType: string | null;
1005
805
  subscriptionStatus: string | null;
1006
806
  };
1007
- featureCode: string;
1008
- featureName: string;
1009
- description: string | null;
1010
- hasQuantity: boolean;
1011
- isEnabled: boolean;
1012
- quantityLimit: number | null;
1013
- includedQuantity: number;
1014
- currentUsage: number;
1015
- source: string;
1016
- validUntil: Date | null;
1017
- stripeSubscriptionItemId: string | null;
1018
- stripePriceId: string | null;
1019
- stripeSubscriptionId: string | null;
1020
- meterId: string | null;
1021
- configValues: Record<string, unknown>;
1022
- })[]>;
807
+ }[]>;
808
+ listForProduct: (input?: import("./index.js").ListProductFeatureCatalogInput) => Promise<import("./index.js").ProductFeatureCatalogItem[]>;
1023
809
  /**
1024
810
  * Update feature access for a company with partial config merge.
1025
811
  *
@@ -1070,7 +856,9 @@ export declare class ChatarminOS {
1070
856
  isEnabled: boolean;
1071
857
  quantityLimit: number | null;
1072
858
  includedQuantity: number | null;
1073
- configValues: Record<string, unknown>;
859
+ configValues: {
860
+ [x: string]: unknown;
861
+ };
1074
862
  source: string;
1075
863
  validUntil: Date | null;
1076
864
  created: boolean;
@@ -1098,6 +886,7 @@ export declare class ChatarminOS {
1098
886
  */
1099
887
  getAccessByExternalOrgId: (externalOrgId: string) => Promise<{
1100
888
  companyId: string;
889
+ productLinkId: string;
1101
890
  externalOrgId: string;
1102
891
  features: {
1103
892
  featureCode: string;
@@ -1144,22 +933,36 @@ export declare class ChatarminOS {
1144
933
  remaining: number | null;
1145
934
  isAtLimit: boolean;
1146
935
  canUse: boolean;
936
+ configValues: {};
937
+ } | {
1147
938
  configValues: Record<string, unknown>;
939
+ featureCode: string;
940
+ isEnabled: boolean;
941
+ hasQuantity: boolean;
942
+ currentUsage: number;
943
+ quantityLimit: number | null;
944
+ includedQuantity: number;
945
+ remaining: number | null;
946
+ isAtLimit: boolean;
947
+ canUse: boolean;
948
+ companyId: string;
949
+ productLinkId: string;
950
+ externalOrgId: string;
1148
951
  }>;
1149
952
  };
1150
953
  /**
1151
954
  * Billing, usage tracking, and subscription management.
1152
955
  *
1153
- * Track feature usage for billing, claim subscriptions from Stripe checkout,
956
+ * Set feature usage for billing, claim subscriptions from Stripe checkout,
1154
957
  * or link existing Stripe subscriptions to companies.
1155
958
  *
1156
- * @example Track Usage
959
+ * @example Set Usage
1157
960
  * ```typescript
1158
- * await os.billing.trackUsage({
961
+ * await os.billing.setUsage({
1159
962
  * companyId: company.id,
1160
963
  * featureCode: 'ai_credit',
1161
- * quantity: 1,
1162
- * idempotencyKey: `msg_${messageId}` // Prevent double-counting
964
+ * absoluteValue: 42,
965
+ * reason: 'Synced current usage'
1163
966
  * })
1164
967
  * ```
1165
968
  *
@@ -1183,246 +986,37 @@ export declare class ChatarminOS {
1183
986
  * ```
1184
987
  */
1185
988
  get billing(): {
1186
- /**
1187
- * Track usage for a metered feature.
1188
- *
1189
- * Increments the usage counter for a feature and returns the
1190
- * updated usage information. Use idempotency keys to prevent
1191
- * duplicate tracking.
1192
- *
1193
- * @param input - Usage tracking parameters
1194
- * @returns Updated usage information
1195
- * @throws {TRPCError} If feature is not enabled or limit exceeded
1196
- *
1197
- * @example
1198
- * ```typescript
1199
- * const result = await os.billing.trackUsage({
1200
- * companyId: 'comp_xxx',
1201
- * featureCode: 'ai_credit',
1202
- * quantity: 5,
1203
- * idempotencyKey: `request_${requestId}`,
1204
- * metadata: { model: 'gpt-4' }
1205
- * })
1206
- *
1207
- * console.log({
1208
- * currentUsage: result.currentUsage,
1209
- * remaining: result.remaining,
1210
- * billable: result.billableQuantity,
1211
- * isAtLimit: result.isAtLimit
1212
- * })
1213
- * ```
1214
- */
1215
- trackUsage: (input: TrackUsageInput) => Promise<{
1216
- success: boolean;
1217
- featureCode: string;
1218
- currentUsage: number;
1219
- previousUsage: number;
1220
- quantityLimit: number | null;
1221
- remaining: number | null;
1222
- isAtLimit: boolean;
1223
- includedQuantity: number;
1224
- billableQuantity: number;
1225
- delta: number;
1226
- meterId: string;
1227
- eventId: string | null;
1228
- }>;
1229
- /**
1230
- * Track usage by external org ID (product link).
1231
- *
1232
- * Resolves the linked company for the current product and tracks
1233
- * usage with product-link attribution.
1234
- *
1235
- * @param input - Usage tracking parameters
1236
- * @returns Updated usage information
1237
- * @throws {TRPCError} If no linked company is found or limit exceeded
1238
- *
1239
- * @example
1240
- * ```typescript
1241
- * const result = await os.billing.trackUsageByExternalOrgId({
1242
- * externalOrgId: "org_acme_123",
1243
- * featureCode: "ai_credit",
1244
- * quantity: 1,
1245
- * idempotencyKey: `msg_${messageId}`,
1246
- * })
1247
- * ```
1248
- */
1249
- trackUsageByExternalOrgId: (input: TrackUsageByExternalOrgIdInput) => Promise<{
1250
- success: boolean;
1251
- featureCode: string;
1252
- currentUsage: number;
1253
- previousUsage: number;
1254
- quantityLimit: number | null;
1255
- remaining: number | null;
1256
- isAtLimit: boolean;
1257
- includedQuantity: number;
1258
- billableQuantity: number;
1259
- delta: number;
1260
- meterId: string;
1261
- eventId: string | null;
1262
- }>;
1263
- /**
1264
- * Set usage to an absolute value.
1265
- *
1266
- * Use this for corrections when you know what the total usage SHOULD be.
1267
- * Creates a snapshot for audit trail. The delta (difference) is calculated
1268
- * automatically and synced to Stripe.
1269
- *
1270
- * @param input - Set usage parameters
1271
- * @returns Result with previous and new usage values
1272
- *
1273
- * @example Correct usage to 100 (was 150)
1274
- * ```typescript
1275
- * const result = await os.billing.setUsage({
1276
- * companyId: 'comp_xxx',
1277
- * featureCode: 'ai_credit',
1278
- * absoluteValue: 100,
1279
- * reason: 'Corrected after customer support review',
1280
- * performedBy: 'admin@company.com'
1281
- * })
1282
- *
1283
- * console.log({
1284
- * previousUsage: result.previousUsage, // 150
1285
- * currentUsage: result.currentUsage, // 100
1286
- * delta: result.delta // -50
1287
- * })
1288
- * ```
1289
- */
1290
- setUsage: (input: SetUsageInput) => Promise<UsageResult>;
1291
- /**
1292
- * Adjust usage by a delta (positive or negative).
1293
- *
1294
- * Use this for explicit corrections. Supports negative values for
1295
- * refunds or error corrections. Creates an audit trail and syncs
1296
- * to Stripe (including meter event adjustments when possible).
1297
- *
1298
- * @param input - Adjustment parameters
1299
- * @returns Result with previous and new usage values
1300
- *
1301
- * @example Refund 50 units
1302
- * ```typescript
1303
- * const result = await os.billing.adjustUsage({
1304
- * companyId: 'comp_xxx',
1305
- * featureCode: 'ai_credit',
1306
- * delta: -50,
1307
- * reason: 'Refund for failed API calls',
1308
- * performedBy: 'support@company.com'
1309
- * })
1310
- * ```
1311
- *
1312
- * @example Add bonus units
1313
- * ```typescript
1314
- * const result = await os.billing.adjustUsage({
1315
- * companyId: 'comp_xxx',
1316
- * featureCode: 'ai_credit',
1317
- * delta: 100,
1318
- * reason: 'Promotional bonus for beta testers'
1319
- * })
1320
- * ```
1321
- */
1322
- adjustUsage: (input: AdjustUsageInput) => Promise<UsageResult>;
1323
- /**
1324
- * Get usage event history for a feature.
1325
- *
1326
- * Returns the history of usage events including increments, sets,
1327
- * and adjustments. Useful for auditing and debugging.
1328
- *
1329
- * @param companyId - Company ID
1330
- * @param featureCode - Feature code to get history for
1331
- * @param options - Query options
1332
- * @returns Array of usage events
1333
- *
1334
- * @example
1335
- * ```typescript
1336
- * const history = await os.billing.getUsageHistory(
1337
- * 'comp_xxx',
1338
- * 'ai_credit',
1339
- * { limit: 20, eventType: 'adjustment' }
1340
- * )
1341
- *
1342
- * for (const event of history) {
1343
- * console.log(`${event.event_type}: ${event.quantity} at ${event.event_time}`)
1344
- * if (event.adjustment_reason) {
1345
- * console.log(` Reason: ${event.adjustment_reason}`)
1346
- * }
1347
- * }
1348
- * ```
1349
- */
989
+ getDashboardContext: (input: import("./index.js").GetBillingDashboardContextInput) => Promise<import("./index.js").BillingDashboardContext>;
990
+ setUsage: (input: import("./index.js").SetUsageInput) => Promise<import("./index.js").UsageResult>;
1350
991
  getUsageHistory: (companyId: string, featureCode: string, options?: {
1351
992
  limit?: number;
1352
993
  includeDelivered?: boolean;
1353
994
  eventType?: "increment" | "set" | "adjustment";
1354
995
  }) => Promise<{
1355
996
  id: string;
1356
- metadata: unknown;
1357
997
  created_at: Date;
1358
- company_id: string;
998
+ metadata: unknown;
999
+ event_type: string;
1000
+ source: string;
1359
1001
  billing_profile_id: string | null;
1360
- stripe_price_id: string | null;
1361
- meter_code: string;
1002
+ idempotency_key: string;
1362
1003
  subscription_item_id: string | null;
1363
- source: string;
1004
+ feature_access_id: string | null;
1005
+ meter_code: string;
1364
1006
  quantity: number;
1365
- product_link_id: string | null;
1007
+ stripe_price_id: string | null;
1366
1008
  event_time: Date;
1367
- event_type: string;
1368
1009
  previous_value: number | null;
1369
1010
  adjustment_reason: string | null;
1370
1011
  adjusts_event_id: string | null;
1371
- idempotency_key: string;
1372
1012
  stripe_delivery_status: string;
1013
+ stripe_delivery_attempts: number;
1014
+ stripe_last_delivery_attempt_at: Date | null;
1373
1015
  stripe_event_id: string | null;
1374
1016
  stripe_delivery_error: string | null;
1375
1017
  delivered_at: Date | null;
1376
1018
  }[]>;
1377
- /**
1378
- * Get usage snapshots for a feature.
1379
- *
1380
- * Returns audit snapshots created by set operations and reconciliations.
1381
- * Useful for understanding historical usage corrections.
1382
- *
1383
- * @param companyId - Company ID
1384
- * @param featureCode - Feature code
1385
- * @param limit - Max number of snapshots to return
1386
- * @returns Array of usage snapshots
1387
- */
1388
- getUsageSnapshots: (companyId: string, featureCode: string, limit?: number) => Promise<{
1389
- id: string;
1390
- metadata: unknown;
1391
- created_at: Date;
1392
- company_id: string;
1393
- meter_code: string;
1394
- created_by: string | null;
1395
- reason: string | null;
1396
- absolute_value: number;
1397
- billable_value: number;
1398
- snapshot_type: string;
1399
- trigger_event_id: string | null;
1400
- }[]>;
1401
- /**
1402
- * Claim a subscription from a completed Stripe Checkout Session.
1403
- *
1404
- * Use this after a user completes Stripe checkout in your product.
1405
- * This links the subscription and customer to the company in OS.
1406
- *
1407
- * @param input - Claim parameters
1408
- * @returns Result with subscription ID and claim status
1409
- *
1410
- * @example
1411
- * ```typescript
1412
- * // In your Stripe checkout success handler:
1413
- * const result = await os.billing.claimCheckout({
1414
- * companyId: company.id,
1415
- * checkoutSessionId: session.id // From Stripe callback
1416
- * })
1417
- *
1418
- * if (result.alreadyClaimed) {
1419
- * console.log('Subscription was already claimed')
1420
- * } else {
1421
- * console.log(`Claimed subscription: ${result.subscriptionId}`)
1422
- * }
1423
- * ```
1424
- */
1425
- claimCheckout: (input: ClaimCheckoutInput) => Promise<{
1019
+ claimCheckout: (input: import("./index.js").ClaimCheckoutInput) => Promise<{
1426
1020
  success: boolean;
1427
1021
  subscriptionId: string;
1428
1022
  alreadyClaimed: boolean;
@@ -1433,34 +1027,7 @@ export declare class ChatarminOS {
1433
1027
  alreadyClaimed: boolean;
1434
1028
  status: import("stripe").Stripe.Subscription.Status;
1435
1029
  }>;
1436
- /**
1437
- * Link an existing Stripe subscription to a company.
1438
- *
1439
- * Use this when you create subscriptions on your product's Stripe
1440
- * account and want OS to track them. Optionally applies tier features.
1441
- *
1442
- * @param input - Link parameters
1443
- * @returns Result with subscription ID, link status, and features applied
1444
- *
1445
- * @example
1446
- * ```typescript
1447
- * // After creating subscription on your Stripe account:
1448
- * const result = await os.billing.linkSubscription({
1449
- * companyId: company.id,
1450
- * stripeSubscriptionId: 'sub_xxx',
1451
- * stripeCustomerId: 'cus_xxx', // Optional
1452
- * tierCode: 'pro', // Apply tier features
1453
- * displayName: 'Pro Plan'
1454
- * })
1455
- *
1456
- * console.log({
1457
- * subscriptionId: result.subscriptionId,
1458
- * isNew: !result.alreadyLinked,
1459
- * featuresApplied: result.featuresApplied
1460
- * })
1461
- * ```
1462
- */
1463
- linkSubscription: (input: LinkSubscriptionInput) => Promise<{
1030
+ linkSubscription: (input: import("./index.js").LinkSubscriptionInput) => Promise<{
1464
1031
  success: boolean;
1465
1032
  subscriptionId: string;
1466
1033
  alreadyLinked: boolean;
@@ -1475,36 +1042,40 @@ export declare class ChatarminOS {
1475
1042
  tierApplied: boolean;
1476
1043
  featuresApplied: number;
1477
1044
  }>;
1478
- /**
1479
- * Get billing status for a company.
1480
- *
1481
- * Quick check for subscription status, active features, and
1482
- * billing profile information.
1483
- *
1484
- * @param companyId - Company ID to check
1485
- * @returns Billing status overview
1486
- *
1487
- * @example
1488
- * ```typescript
1489
- * const status = await os.billing.getStatus(company.id)
1490
- *
1491
- * console.log({
1492
- * hasBilling: status.hasBillingProfile,
1493
- * subscriptions: status.activeSubscriptions.length,
1494
- * features: status.enabledFeaturesCount
1495
- * })
1496
- *
1497
- * // Check active tier
1498
- * if (status.activeSubscriptions[0]?.tier) {
1499
- * console.log(`Current tier: ${status.activeSubscriptions[0].tier.name}`)
1500
- * }
1501
- * ```
1502
- */
1503
1045
  getStatus: (companyId: string) => Promise<{
1504
1046
  hasBillingProfile: boolean;
1505
1047
  stripeCustomerId: string | null;
1048
+ billingProfiles: {
1049
+ id: string;
1050
+ organization_id: string;
1051
+ created_at: Date;
1052
+ updated_at: Date;
1053
+ short_id: string | null;
1054
+ name: string;
1055
+ metadata: unknown;
1056
+ status: string;
1057
+ mrr_cents: number;
1058
+ mrr_committed_cents: number;
1059
+ mrr_usage_cents: number;
1060
+ contract_start_at: Date | null;
1061
+ contract_end_at: Date | null;
1062
+ subscription_status: string;
1063
+ max_days_overdue: number;
1064
+ company_id: string | null;
1065
+ stripe_customer_id: string;
1066
+ link_status: string;
1067
+ default_currency: string;
1068
+ has_payment_method: boolean;
1069
+ open_invoices_count: number;
1070
+ open_amount_cents: number;
1071
+ past_due_invoices_count: number;
1072
+ past_due_amount_cents: number;
1073
+ last_synced_at: Date | null;
1074
+ company_group_id: string | null;
1075
+ }[];
1506
1076
  activeSubscriptions: {
1507
1077
  id: string;
1078
+ billingProfileId: string;
1508
1079
  status: string;
1509
1080
  stripeSubscriptionId: string | null;
1510
1081
  currentPeriodEnd: Date | null;
@@ -1516,14 +1087,8 @@ export declare class ChatarminOS {
1516
1087
  }[];
1517
1088
  enabledFeaturesCount: number;
1518
1089
  }>;
1519
- /**
1520
- * Sync billing profile, subscriptions, and feature access from Stripe.
1521
- */
1522
- syncCompanyFromStripe: (input: SyncCompanyFromStripeInput) => Promise<SyncCompanyFromStripeResult>;
1523
- /**
1524
- * Relink billing profile to a new Stripe customer (destructive).
1525
- */
1526
- relinkBillingProfile: (input: RelinkBillingProfileInput) => Promise<{
1090
+ syncCompanyFromStripe: (input: import("./index.js").SyncCompanyFromStripeInput) => Promise<import("./index.js").SyncCompanyFromStripeResult>;
1091
+ relinkBillingProfile: (input: import("./index.js").RelinkBillingProfileInput) => Promise<{
1527
1092
  billingProfileId: string;
1528
1093
  stripeCustomerId: string;
1529
1094
  subscriptionsSynced: number;
@@ -1531,10 +1096,7 @@ export declare class ChatarminOS {
1531
1096
  featuresLinked: number;
1532
1097
  matchedMeters: number;
1533
1098
  }>;
1534
- /**
1535
- * Ensure a feature is linked to an active Stripe subscription item.
1536
- */
1537
- ensureFeatureSubscription: (input: EnsureFeatureSubscriptionInput) => Promise<EnsureFeatureSubscriptionResult>;
1099
+ ensureFeatureSubscription: (input: import("./index.js").EnsureFeatureSubscriptionInput) => Promise<import("./index.js").EnsureFeatureSubscriptionResult>;
1538
1100
  };
1539
1101
  /**
1540
1102
  * Manual link operations for associating external IDs with companies.
@@ -1589,18 +1151,20 @@ export declare class ChatarminOS {
1589
1151
  externalUserId?: string;
1590
1152
  }) => Promise<{
1591
1153
  id: string;
1592
- metadata: unknown;
1593
1154
  created_at: Date;
1594
1155
  updated_at: Date;
1595
- company_id: string;
1156
+ metadata: unknown;
1157
+ status: string;
1596
1158
  product_id: string;
1159
+ company_id: string | null;
1597
1160
  external_org_id: string;
1598
1161
  external_user_id: string | null;
1599
1162
  confidence: number | null;
1600
1163
  sync_status: string;
1601
1164
  link_type: string;
1602
1165
  label: string | null;
1603
- } | undefined>;
1166
+ external_display_name: string | null;
1167
+ }>;
1604
1168
  /**
1605
1169
  * Delete all product links for this product.
1606
1170
  *
@@ -1722,15 +1286,15 @@ export declare class ChatarminOS {
1722
1286
  configValues: unknown;
1723
1287
  }[];
1724
1288
  id: string;
1725
- code: string;
1726
- name: string;
1727
- is_active: boolean;
1728
- metadata: unknown;
1729
1289
  created_at: Date;
1730
1290
  updated_at: Date;
1291
+ name: string;
1292
+ metadata: unknown;
1293
+ product_id: string;
1294
+ code: string;
1295
+ is_active: boolean;
1731
1296
  description: string | null;
1732
1297
  display_order: number;
1733
- product_id: string;
1734
1298
  }[]>;
1735
1299
  /**
1736
1300
  * Get detailed information about a specific tier.
@@ -1840,15 +1404,15 @@ export declare class ChatarminOS {
1840
1404
  configValues: unknown;
1841
1405
  }[];
1842
1406
  id: string;
1843
- code: string;
1844
- name: string;
1845
- is_active: boolean;
1846
- metadata: unknown;
1847
1407
  created_at: Date;
1848
1408
  updated_at: Date;
1409
+ name: string;
1410
+ metadata: unknown;
1411
+ product_id: string;
1412
+ code: string;
1413
+ is_active: boolean;
1849
1414
  description: string | null;
1850
1415
  display_order: number;
1851
- product_id: string;
1852
1416
  }[]>;
1853
1417
  /**
1854
1418
  * Get detailed tier information by code.