owostack 0.4.0 → 0.4.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/README.md CHANGED
@@ -70,6 +70,30 @@ await owo.track({
70
70
  });
71
71
  ```
72
72
 
73
+ ### 4. Manage customer billing controls
74
+
75
+ Inspect and update customer-specific overage behavior through the same `customer` namespace:
76
+
77
+ ```ts
78
+ const customer = await owo.customer({
79
+ email: "billing@acme.com",
80
+ name: "Acme Corporation",
81
+ });
82
+
83
+ await owo.customer.setFeatureConfig({
84
+ customer: customer.id,
85
+ feature: "api-calls",
86
+ overage: "block",
87
+ maxOverageUnits: 1000,
88
+ });
89
+
90
+ await owo.customer.setOverageLimit({
91
+ customer: customer.id,
92
+ maxOverageAmount: 500_000,
93
+ onLimitReached: "block",
94
+ });
95
+ ```
96
+
73
97
  ## Features
74
98
 
75
99
  - **Feature Gating**: Instant access control for boolean and metered features.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { CheckResult, PlanFeatureEntry, ResetInterval, CreditSystemDefinition, AddEntityResult, RemoveEntityResult, ListEntitiesResult, MeteredFeatureConfig, TrackResult, PricingTier, CatalogEntry, SyncPayload, Currency, CreditPackDefinition, PlanInterval, PlanDefinition, OwostackConfig, BillingUsageParams, BillingUsageResult, InvoiceParams, InvoiceResult, InvoicesParams, InvoicesResult, PayInvoiceParams, PayInvoiceResult, WalletResult, WalletSetupResult, WalletRemoveResult, SyncResult, AttachParams, AttachResult, CheckParams, TrackParams, AddonParams, AddonResult, CustomerParams, CustomerResult, AddEntityParams, RemoveEntityParams, ListEntitiesParams, PlansParams, PlansResult, PublicPlan } from '@owostack/types';
2
- export { AddEntityParams, AddEntityResult, AddonParams, AddonResult, AttachParams, AttachResult, BillingFeatureUsage, BillingTierBreakdown, BillingUsageParams, BillingUsageResult, BooleanFeatureConfig, CardInfo, CatalogEntry, CheckCode, CheckParams, CheckResult, CreditPlanBalance, CreditSystemBalanceDetails, CreditsBalanceDetails, CurrentPricingTier, CustomerData, CustomerParams, CustomerResult, Invoice, InvoiceLineItem, InvoiceParams, InvoiceResult, InvoicesParams, InvoicesResult, ListEntitiesParams, ListEntitiesResult, MeteredFeatureConfig, OverageDetails, OwostackConfig, PayInvoiceParams, PayInvoiceResult, PaymentMethodInfo, PlanDefinition, PlanFeatureEntry, PlansParams, PlansResult, PrepaidBalanceDetails, PricingDetails, PricingTier, PublicPlan, PublicPlanFeature, RatingModel, RemoveEntityParams, RemoveEntityResult, ResponseDetails, SyncChanges, SyncPayload, SyncResult, TrackCode, TrackParams, TrackResult, WalletRemoveResult, WalletResult, WalletSetupResult } from '@owostack/types';
1
+ import { CheckResult, PlanFeatureEntry, ResetInterval, CreditSystemDefinition, AddEntityResult, RemoveEntityResult, ListEntitiesResult, MeteredFeatureConfig, TrackResult, PricingTier, CatalogEntry, SyncPayload, Currency, CreditPackDefinition, PlanInterval, PlanDefinition, OwostackConfig, BillingUsageParams, BillingUsageResult, InvoiceParams, InvoiceResult, InvoicesParams, InvoicesResult, PayInvoiceParams, PayInvoiceResult, WalletResult, WalletSetupResult, WalletRemoveResult, CustomerParams, CustomerResult, SetCustomerFeatureConfigParams, SetCustomerOverageLimitParams, SyncResult, AttachParams, AttachResult, CheckParams, TrackParams, AddonParams, AddonResult, AddEntityParams, RemoveEntityParams, ListEntitiesParams, PlansParams, PlansResult, PublicPlan } from '@owostack/types';
2
+ export { AddEntityParams, AddEntityResult, AddonParams, AddonResult, AttachParams, AttachResult, BillingFeatureUsage, BillingTierBreakdown, BillingUsageParams, BillingUsageResult, BooleanFeatureConfig, CardInfo, CatalogEntry, CheckCode, CheckParams, CheckResult, CreditPlanBalance, CreditSystemBalanceDetails, CreditsBalanceDetails, CurrentPricingTier, CustomerBillingConfig, CustomerData, CustomerFeatureConfigResult, CustomerOverageLimitResult, CustomerParams, CustomerResult, Invoice, InvoiceLineItem, InvoiceParams, InvoiceResult, InvoicesParams, InvoicesResult, ListEntitiesParams, ListEntitiesResult, MeteredFeatureConfig, OverageDetails, OwostackConfig, PayInvoiceParams, PayInvoiceResult, PaymentMethodInfo, PlanDefinition, PlanFeatureEntry, PlansParams, PlansResult, PrepaidBalanceDetails, PricingDetails, PricingTier, PublicPlan, PublicPlanFeature, RatingModel, RemoveEntityParams, RemoveEntityResult, ResponseDetails, SetCustomerFeatureConfigParams, SetCustomerOverageLimitParams, SyncChanges, SyncPayload, SyncResult, TrackCode, TrackParams, TrackResult, WalletRemoveResult, WalletResult, WalletSetupResult } from '@owostack/types';
3
3
 
4
4
  /**
5
5
  * BooleanHandle — returned by boolean().
@@ -183,6 +183,8 @@ declare class Owostack {
183
183
  readonly billing: BillingNamespace;
184
184
  /** Wallet: payment methods — callable + namespace */
185
185
  readonly wallet: WalletFn;
186
+ /** Customer: create/resolve + billing config management */
187
+ readonly customer: CustomerFn;
186
188
  constructor(config: OwostackConfig);
187
189
  private resolveApiUrl;
188
190
  /**
@@ -290,26 +292,6 @@ declare class Owostack {
290
292
  * ```
291
293
  */
292
294
  addon(params: AddonParams): Promise<AddonResult>;
293
- /**
294
- * customer() - Create or resolve a customer
295
- *
296
- * Creates a new customer or resolves an existing one by email or ID.
297
- * If customerData is provided and customer doesn't exist, creates a new customer.
298
- *
299
- * @example
300
- * ```ts
301
- * // Create new customer
302
- * const customer = await owo.customer({
303
- * email: 'org@acme.com',
304
- * name: 'Acme Corp',
305
- * metadata: { plan: 'enterprise' }
306
- * });
307
- *
308
- * // Get existing customer
309
- * const existing = await owo.customer({ email: 'org@acme.com' });
310
- * ```
311
- */
312
- customer(params: CustomerParams): Promise<CustomerResult>;
313
295
  /**
314
296
  * addEntity() - Add a feature entity (e.g., seat)
315
297
  *
@@ -395,6 +377,11 @@ type PlansFn = {
395
377
  (params?: PlansParams): Promise<PlansResult>;
396
378
  get(slug: string): Promise<PublicPlan>;
397
379
  };
380
+ type CustomerFn = {
381
+ (params: CustomerParams): Promise<CustomerResult>;
382
+ setFeatureConfig(params: SetCustomerFeatureConfigParams): Promise<CustomerResult>;
383
+ setOverageLimit(params: SetCustomerOverageLimitParams): Promise<CustomerResult>;
384
+ };
398
385
  type WalletFn = {
399
386
  (customer: string): Promise<WalletResult>;
400
387
  setup(customer: string, opts?: {
package/dist/index.js CHANGED
@@ -574,11 +574,14 @@ var Owostack = class {
574
574
  billing;
575
575
  /** Wallet: payment methods — callable + namespace */
576
576
  wallet;
577
+ /** Customer: create/resolve + billing config management */
578
+ customer;
577
579
  constructor(config) {
578
580
  this._config = config;
579
581
  this.apiUrl = this.resolveApiUrl(config);
580
582
  this.billing = new BillingNamespace(this);
581
583
  this.wallet = buildWalletFn(this);
584
+ this.customer = buildCustomerFn(this);
582
585
  this.plans = buildPlansFn(this);
583
586
  if (config.catalog && config.catalog.length > 0) {
584
587
  bindFeatureHandles(this, config.catalog);
@@ -735,29 +738,6 @@ var Owostack = class {
735
738
  const response = await this.post("/addon", params);
736
739
  return response;
737
740
  }
738
- /**
739
- * customer() - Create or resolve a customer
740
- *
741
- * Creates a new customer or resolves an existing one by email or ID.
742
- * If customerData is provided and customer doesn't exist, creates a new customer.
743
- *
744
- * @example
745
- * ```ts
746
- * // Create new customer
747
- * const customer = await owo.customer({
748
- * email: 'org@acme.com',
749
- * name: 'Acme Corp',
750
- * metadata: { plan: 'enterprise' }
751
- * });
752
- *
753
- * // Get existing customer
754
- * const existing = await owo.customer({ email: 'org@acme.com' });
755
- * ```
756
- */
757
- async customer(params) {
758
- const response = await this.post("/customers", params);
759
- return response;
760
- }
761
741
  /**
762
742
  * addEntity() - Add a feature entity (e.g., seat)
763
743
  *
@@ -950,6 +930,12 @@ function buildPlansFn(client) {
950
930
  };
951
931
  return fn;
952
932
  }
933
+ function buildCustomerFn(client) {
934
+ const fn = ((params) => client.post("/customers", params));
935
+ fn.setFeatureConfig = (params) => client.post("/customers/feature-config", params);
936
+ fn.setOverageLimit = (params) => client.post("/customers/overage-limit", params);
937
+ return fn;
938
+ }
953
939
  function buildWalletFn(client) {
954
940
  const fn = ((customer) => client.get("/wallet", { customer }));
955
941
  fn.setup = (customer, opts) => client.post("/wallet/setup", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "owostack",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Core SDK for Owostack billing infrastructure",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -30,7 +30,7 @@
30
30
  "payments"
31
31
  ],
32
32
  "dependencies": {
33
- "@owostack/types": "0.4.0"
33
+ "@owostack/types": "0.4.2"
34
34
  },
35
35
  "devDependencies": {
36
36
  "tsup": "^8.3.6",