@chatarmin/os 0.3.0 → 0.3.2

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
@@ -84,6 +84,32 @@ export interface FeatureCheckInput {
84
84
  /** Feature code (e.g., "ai_credit", "whatsapp_messages") */
85
85
  featureCode: string;
86
86
  }
87
+ /**
88
+ * Input for updating feature access with partial config merge.
89
+ */
90
+ export interface FeatureSetAccessInput {
91
+ /** Company ID to update (either this or externalOrgId required) */
92
+ companyId?: string;
93
+ /** Your product's external org ID (either this or companyId required) */
94
+ externalOrgId?: string;
95
+ /** Feature code to update */
96
+ featureCode: string;
97
+ /** Enable or disable the feature */
98
+ isEnabled?: boolean;
99
+ /** Maximum quantity allowed (for quantity-based features) */
100
+ quantityLimit?: number | null;
101
+ /** Included quantity before billing kicks in */
102
+ includedQuantity?: number | null;
103
+ /**
104
+ * Custom config values to merge with existing config.
105
+ * Only specified fields will be updated - other fields remain unchanged.
106
+ */
107
+ config?: Record<string, unknown>;
108
+ /** Source of the access change */
109
+ source?: "subscription" | "manual" | "trial" | "api";
110
+ /** When the access expires (null for no expiration) */
111
+ validUntil?: Date | null;
112
+ }
87
113
  /**
88
114
  * Input for tracking feature usage.
89
115
  */
@@ -490,6 +516,132 @@ export declare class ChatarminOS {
490
516
  source: string;
491
517
  validUntil: Date | null;
492
518
  }[]>;
519
+ /**
520
+ * Update feature access for a company with partial config merge.
521
+ *
522
+ * This allows you to update individual feature configs without
523
+ * replacing all config values. Only the fields you specify in
524
+ * `config` will be updated - other fields remain unchanged.
525
+ *
526
+ * @param input - Update parameters
527
+ * @returns Updated feature access information
528
+ *
529
+ * @example Update by company ID
530
+ * ```typescript
531
+ * await os.features.setAccess({
532
+ * companyId: 'comp_xxx',
533
+ * featureCode: 'ai_credit',
534
+ * isEnabled: true,
535
+ * config: {
536
+ * included_quantity: 500,
537
+ * max_quantity: 1000
538
+ * }
539
+ * })
540
+ * ```
541
+ *
542
+ * @example Update by your product's external org ID
543
+ * ```typescript
544
+ * await os.features.setAccess({
545
+ * externalOrgId: 'org_abc123',
546
+ * featureCode: 'ai_credit',
547
+ * config: { tier_level: 'premium' }
548
+ * })
549
+ * ```
550
+ *
551
+ * @example Partial config update (only updates specified fields)
552
+ * ```typescript
553
+ * // Existing config: { tier_level: 'basic', max_seats: 5 }
554
+ * await os.features.setAccess({
555
+ * companyId: 'comp_xxx',
556
+ * featureCode: 'team_seats',
557
+ * config: { max_seats: 10 } // tier_level remains 'basic'
558
+ * })
559
+ * // New config: { tier_level: 'basic', max_seats: 10 }
560
+ * ```
561
+ */
562
+ setAccess: (input: FeatureSetAccessInput) => Promise<{
563
+ success: boolean;
564
+ featureCode: string;
565
+ companyId: string;
566
+ isEnabled: boolean;
567
+ quantityLimit: number | null;
568
+ includedQuantity: number | null;
569
+ configValues: Record<string, unknown>;
570
+ source: string;
571
+ validUntil: Date | null;
572
+ created: boolean;
573
+ updated: boolean;
574
+ }>;
575
+ /**
576
+ * Get all feature access using your product's external org ID.
577
+ *
578
+ * Convenience method when you know the external org ID but not
579
+ * the ChatarminOS company ID.
580
+ *
581
+ * @param externalOrgId - Your product's organization ID
582
+ * @returns All features with their access status and config values
583
+ *
584
+ * @example
585
+ * ```typescript
586
+ * const result = await os.features.getAccessByExternalOrgId('org_abc123')
587
+ *
588
+ * console.log(`Company: ${result.companyId}`)
589
+ * for (const f of result.features) {
590
+ * console.log(`${f.featureCode}: ${f.isEnabled}`)
591
+ * console.log(` Config:`, f.configValues)
592
+ * }
593
+ * ```
594
+ */
595
+ getAccessByExternalOrgId: (externalOrgId: string) => Promise<{
596
+ companyId: string;
597
+ externalOrgId: string;
598
+ features: {
599
+ featureCode: string;
600
+ featureName: string;
601
+ description: string | null;
602
+ hasQuantity: boolean;
603
+ isEnabled: boolean;
604
+ quantityLimit: number | null;
605
+ includedQuantity: number;
606
+ configValues: Record<string, unknown>;
607
+ source: string;
608
+ validUntil: Date | null;
609
+ }[];
610
+ }>;
611
+ /**
612
+ * Check specific feature access using your product's external org ID.
613
+ *
614
+ * @param externalOrgId - Your product's organization ID
615
+ * @param featureCode - Feature code to check
616
+ * @returns Detailed feature access including config values
617
+ *
618
+ * @example
619
+ * ```typescript
620
+ * const access = await os.features.checkByExternalOrgId(
621
+ * 'org_abc123',
622
+ * 'ai_credit'
623
+ * )
624
+ *
625
+ * if (access.canUse) {
626
+ * console.log(`Remaining: ${access.remaining}`)
627
+ * console.log(`Config:`, access.configValues)
628
+ * }
629
+ * ```
630
+ */
631
+ checkByExternalOrgId: (externalOrgId: string, featureCode: string) => Promise<{
632
+ featureCode: string;
633
+ companyId: string;
634
+ externalOrgId: string;
635
+ isEnabled: boolean;
636
+ hasQuantity: boolean;
637
+ currentUsage: number;
638
+ quantityLimit: number | null;
639
+ includedQuantity: number;
640
+ remaining: number | null;
641
+ isAtLimit: boolean;
642
+ canUse: boolean;
643
+ configValues: Record<string, unknown>;
644
+ }>;
493
645
  };
494
646
  /**
495
647
  * Billing, usage tracking, and subscription management.
@@ -862,6 +1014,18 @@ export declare class ChatarminOS {
862
1014
  id: string;
863
1015
  code: string;
864
1016
  name: string;
1017
+ description: string | null;
1018
+ baseFee: {
1019
+ catalogPriceId: string | null;
1020
+ stripe: {
1021
+ priceId: string;
1022
+ productId: string | null;
1023
+ productName: string | null;
1024
+ unitAmount: number | null;
1025
+ currency: string | null;
1026
+ interval: string | null;
1027
+ };
1028
+ } | null;
865
1029
  features: {
866
1030
  id: string;
867
1031
  code: string;
@@ -944,38 +1108,57 @@ export declare class ChatarminOS {
944
1108
  * Get detailed tier information by code.
945
1109
  *
946
1110
  * Returns full tier details including:
1111
+ * - Base fee price (if configured)
947
1112
  * - Features with config values
948
- * - Stripe price IDs for subscription creation
1113
+ * - Stripe price IDs for subscription creation (base fee + feature prices)
949
1114
  * - Stripe product info
950
1115
  *
951
1116
  * @param tierCode - Tier code (e.g., "free", "pro")
952
- * @returns Tier with features and Stripe prices
1117
+ * @returns Tier with features, base fee, and Stripe prices
953
1118
  *
954
1119
  * @example
955
1120
  * ```typescript
956
1121
  * const tier = await os.tiers.get('pro')
957
1122
  *
1123
+ * // Check base fee (for features without individual prices)
1124
+ * if (tier.baseFee) {
1125
+ * console.log(`Base fee: ${tier.baseFee.stripe.priceId}`)
1126
+ * console.log(`Amount: ${tier.baseFee.stripe.unitAmount / 100}€`)
1127
+ * }
1128
+ *
958
1129
  * // Access features
959
1130
  * for (const feature of tier.features) {
960
1131
  * console.log(feature.code, feature.configValues)
961
1132
  * }
962
1133
  *
963
1134
  * // Get Stripe prices for subscription creation
1135
+ * // Includes base fee + all feature prices
964
1136
  * console.log(tier.stripePriceIds)
965
- * // ['price_xxx', 'price_yyy']
1137
+ * // ['price_base', 'price_feature1', 'price_feature2']
966
1138
  *
967
- * // Feature-level Stripe info
968
- * const aiFeature = tier.features.find(f => f.code === 'ai_credit')
969
- * if (aiFeature?.stripe) {
970
- * console.log(aiFeature.stripe.priceId)
971
- * console.log(aiFeature.stripe.unitAmount) // in cents
972
- * }
1139
+ * // Create Stripe subscription with all prices
1140
+ * const sub = await stripe.subscriptions.create({
1141
+ * customer: stripeCustomerId,
1142
+ * items: tier.stripePriceIds.map(price => ({ price }))
1143
+ * })
973
1144
  * ```
974
1145
  */
975
1146
  get: (tierCode: string) => Promise<{
976
1147
  id: string;
977
1148
  code: string;
978
1149
  name: string;
1150
+ description: string | null;
1151
+ baseFee: {
1152
+ catalogPriceId: string | null;
1153
+ stripe: {
1154
+ priceId: string;
1155
+ productId: string | null;
1156
+ productName: string | null;
1157
+ unitAmount: number | null;
1158
+ currency: string | null;
1159
+ interval: string | null;
1160
+ };
1161
+ } | null;
979
1162
  features: {
980
1163
  id: string;
981
1164
  code: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAQ/C;;GAEG;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iBG;wBACa;YACd,SAAS,EAAE,MAAM,CAAA;YACjB,aAAa,EAAE,MAAM,CAAA;YACrB,cAAc,CAAC,EAAE,MAAM,CAAA;SACxB;;;;;;;;;;;;;MASJ;IAMD;;;;;;;;;;;;;;;;;;;OAmBG;IACH,IAAI,aAAa;QAGb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WA6BG;2BACgB,MAAM,WAAW,cAAc;;;;;QAOlD;;;;;;;;;;;;;;;;;;;WAmBG;;;;;;;;;;;;;;;;;;;;QAIH;;;;;;;;;;;;;;;;;;;;;;;WAuBG;4BACiB,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAG7B;IAMD;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,IAAI,KAAK;QAGL;;;;;;;;;;;WAWG;;;;;;;;;;;;;;;;;;;;QAGH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAsCG;wBACa,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAGtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WA8BG;0BACe,MAAM,WAAW,cAAc;;;;;MAOpD;IAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAuFG;IACG,OAAO,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;CA0E3D;AAGD,YAAY,EAAE,SAAS,EAAE,CAAA;AAGzB,eAAe,WAAW,CAAA"}
package/dist/index.js CHANGED
@@ -272,6 +272,95 @@ export class ChatarminOS {
272
272
  * ```
273
273
  */
274
274
  listAccess: (companyId) => client.features.getAccess.query({ companyId }),
275
+ /**
276
+ * Update feature access for a company with partial config merge.
277
+ *
278
+ * This allows you to update individual feature configs without
279
+ * replacing all config values. Only the fields you specify in
280
+ * `config` will be updated - other fields remain unchanged.
281
+ *
282
+ * @param input - Update parameters
283
+ * @returns Updated feature access information
284
+ *
285
+ * @example Update by company ID
286
+ * ```typescript
287
+ * await os.features.setAccess({
288
+ * companyId: 'comp_xxx',
289
+ * featureCode: 'ai_credit',
290
+ * isEnabled: true,
291
+ * config: {
292
+ * included_quantity: 500,
293
+ * max_quantity: 1000
294
+ * }
295
+ * })
296
+ * ```
297
+ *
298
+ * @example Update by your product's external org ID
299
+ * ```typescript
300
+ * await os.features.setAccess({
301
+ * externalOrgId: 'org_abc123',
302
+ * featureCode: 'ai_credit',
303
+ * config: { tier_level: 'premium' }
304
+ * })
305
+ * ```
306
+ *
307
+ * @example Partial config update (only updates specified fields)
308
+ * ```typescript
309
+ * // Existing config: { tier_level: 'basic', max_seats: 5 }
310
+ * await os.features.setAccess({
311
+ * companyId: 'comp_xxx',
312
+ * featureCode: 'team_seats',
313
+ * config: { max_seats: 10 } // tier_level remains 'basic'
314
+ * })
315
+ * // New config: { tier_level: 'basic', max_seats: 10 }
316
+ * ```
317
+ */
318
+ setAccess: (input) => client.features.updateAccess.mutate(input),
319
+ /**
320
+ * Get all feature access using your product's external org ID.
321
+ *
322
+ * Convenience method when you know the external org ID but not
323
+ * the ChatarminOS company ID.
324
+ *
325
+ * @param externalOrgId - Your product's organization ID
326
+ * @returns All features with their access status and config values
327
+ *
328
+ * @example
329
+ * ```typescript
330
+ * const result = await os.features.getAccessByExternalOrgId('org_abc123')
331
+ *
332
+ * console.log(`Company: ${result.companyId}`)
333
+ * for (const f of result.features) {
334
+ * console.log(`${f.featureCode}: ${f.isEnabled}`)
335
+ * console.log(` Config:`, f.configValues)
336
+ * }
337
+ * ```
338
+ */
339
+ getAccessByExternalOrgId: (externalOrgId) => client.features.getAccessByExternalOrgId.query({ externalOrgId }),
340
+ /**
341
+ * Check specific feature access using your product's external org ID.
342
+ *
343
+ * @param externalOrgId - Your product's organization ID
344
+ * @param featureCode - Feature code to check
345
+ * @returns Detailed feature access including config values
346
+ *
347
+ * @example
348
+ * ```typescript
349
+ * const access = await os.features.checkByExternalOrgId(
350
+ * 'org_abc123',
351
+ * 'ai_credit'
352
+ * )
353
+ *
354
+ * if (access.canUse) {
355
+ * console.log(`Remaining: ${access.remaining}`)
356
+ * console.log(`Config:`, access.configValues)
357
+ * }
358
+ * ```
359
+ */
360
+ checkByExternalOrgId: (externalOrgId, featureCode) => client.features.checkByExternalOrgId.query({
361
+ externalOrgId,
362
+ featureCode,
363
+ }),
275
364
  };
276
365
  }
277
366
  // ==========================================================================
@@ -631,32 +720,39 @@ export class ChatarminOS {
631
720
  * Get detailed tier information by code.
632
721
  *
633
722
  * Returns full tier details including:
723
+ * - Base fee price (if configured)
634
724
  * - Features with config values
635
- * - Stripe price IDs for subscription creation
725
+ * - Stripe price IDs for subscription creation (base fee + feature prices)
636
726
  * - Stripe product info
637
727
  *
638
728
  * @param tierCode - Tier code (e.g., "free", "pro")
639
- * @returns Tier with features and Stripe prices
729
+ * @returns Tier with features, base fee, and Stripe prices
640
730
  *
641
731
  * @example
642
732
  * ```typescript
643
733
  * const tier = await os.tiers.get('pro')
644
734
  *
735
+ * // Check base fee (for features without individual prices)
736
+ * if (tier.baseFee) {
737
+ * console.log(`Base fee: ${tier.baseFee.stripe.priceId}`)
738
+ * console.log(`Amount: ${tier.baseFee.stripe.unitAmount / 100}€`)
739
+ * }
740
+ *
645
741
  * // Access features
646
742
  * for (const feature of tier.features) {
647
743
  * console.log(feature.code, feature.configValues)
648
744
  * }
649
745
  *
650
746
  * // Get Stripe prices for subscription creation
747
+ * // Includes base fee + all feature prices
651
748
  * console.log(tier.stripePriceIds)
652
- * // ['price_xxx', 'price_yyy']
749
+ * // ['price_base', 'price_feature1', 'price_feature2']
653
750
  *
654
- * // Feature-level Stripe info
655
- * const aiFeature = tier.features.find(f => f.code === 'ai_credit')
656
- * if (aiFeature?.stripe) {
657
- * console.log(aiFeature.stripe.priceId)
658
- * console.log(aiFeature.stripe.unitAmount) // in cents
659
- * }
751
+ * // Create Stripe subscription with all prices
752
+ * const sub = await stripe.subscriptions.create({
753
+ * customer: stripeCustomerId,
754
+ * items: tier.stripePriceIds.map(price => ({ price }))
755
+ * })
660
756
  * ```
661
757
  */
662
758
  get: (tierCode) => client.tiers.getByCode.query({ code: tierCode }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chatarmin/os",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Type-safe SDK for ChatarminOS - Customer & Subscription Management",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -24,11 +24,11 @@
24
24
  "typecheck": "tsc --noEmit --skipLibCheck",
25
25
  "test": "tsx test-sdk.ts",
26
26
  "prepublishOnly": "pnpm build",
27
- "publish": "./scripts/publish.sh",
28
- "publish:patch": "./scripts/publish.sh patch",
29
- "publish:minor": "./scripts/publish.sh minor",
30
- "publish:major": "./scripts/publish.sh major",
31
- "publish:dry": "npm publish --dry-run"
27
+ "release": "./scripts/publish.sh",
28
+ "release:patch": "./scripts/publish.sh patch",
29
+ "release:minor": "./scripts/publish.sh minor",
30
+ "release:major": "./scripts/publish.sh major",
31
+ "release:dry": "npm publish --dry-run"
32
32
  },
33
33
  "keywords": [
34
34
  "chatarmin",