@owostack/types 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 Owostack
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # @owostack/types
2
+
3
+ Shared TypeScript types for the Owostack billing infrastructure. This package provides the type definitions used across the Owostack ecosystem, including the Core SDK, CLI, and API.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @owostack/types
9
+ ```
10
+
11
+ ## Features
12
+
13
+ - **Core Configuration**: Types for SDK initialization and environment settings.
14
+ - **API Parameters & Results**: Request and response types for all Owostack endpoints (attach, check, track, etc.).
15
+ - **Catalog Definitions**: Types for declarative plan and feature configuration.
16
+ - **Database Models**: Interfaces for customers, subscriptions, entitlements, and usage records.
17
+ - **Shared Constants**: Type unions for currencies, billing intervals, and reset periods.
18
+
19
+ ## Usage
20
+
21
+ You generally do not need to install this package directly if you are using `owostack`, as it is included as a dependency. However, it can be useful for shared utility functions or when building custom integrations.
22
+
23
+ ```ts
24
+ import type {
25
+ OwostackConfig,
26
+ AttachParams,
27
+ CheckResult,
28
+ } from "@owostack/types";
29
+ ```
30
+
31
+ ## License
32
+
33
+ Apache-2.0
@@ -0,0 +1,806 @@
1
+ /**
2
+ * Core configuration types
3
+ */
4
+ interface OwostackConfig {
5
+ /** API secret key */
6
+ secretKey: string;
7
+ /** Optional: Default provider for all plans (e.g., "paystack", "dodo") */
8
+ provider?: string;
9
+ /** Optional: Environment mode (sandbox or live) */
10
+ mode?: "sandbox" | "live";
11
+ /** Optional: Custom API URL for self-hosted deployments (takes precedence over mode) */
12
+ apiUrl?: string;
13
+ /** Optional: Enable debug mode */
14
+ debug?: boolean;
15
+ /** Optional: Declarative catalog of plans and features */
16
+ catalog?: CatalogEntry[];
17
+ }
18
+ /**
19
+ * CustomerData - Passed to auto-create/update a customer on any endpoint.
20
+ * Email is always required because billing providers need it.
21
+ */
22
+ interface CustomerData {
23
+ /** Customer email (required for billing providers) */
24
+ email: string;
25
+ /** Customer display name */
26
+ name?: string;
27
+ /** Custom metadata */
28
+ metadata?: Record<string, unknown>;
29
+ }
30
+ /**
31
+ * attach() - Checkout & Subscription Management
32
+ */
33
+ interface AttachParams {
34
+ /** Customer ID or email */
35
+ customer: string;
36
+ /** Product/plan slug or ID to purchase or upgrade to */
37
+ product: string;
38
+ /** Optional: Auto-create or update the customer */
39
+ customerData?: CustomerData;
40
+ /** Optional: Custom metadata */
41
+ metadata?: Record<string, unknown>;
42
+ /** Optional: Payment channels to enable */
43
+ channels?: PaymentChannel[];
44
+ /** Optional: Currency (auto-detected if not provided) */
45
+ currency?: Currency;
46
+ /** Optional: Redirect URL after successful payment */
47
+ callbackUrl?: string;
48
+ }
49
+ interface AttachResult {
50
+ /** Checkout URL to redirect user */
51
+ checkoutUrl: string;
52
+ /** Payment reference for tracking */
53
+ reference: string;
54
+ /** Access code for inline checkout */
55
+ accessCode: string;
56
+ /** Resolved internal customer ID */
57
+ customerId: string;
58
+ /** Switch type if customer already had a subscription */
59
+ type: "new" | "upgrade" | "downgrade" | "lateral";
60
+ }
61
+ /**
62
+ * check() - Feature Gating & Access Control
63
+ */
64
+ interface CheckParams {
65
+ /** Customer ID or email */
66
+ customer: string;
67
+ /** Feature slug or ID to check access for */
68
+ feature: string;
69
+ /** Units to check against limit (default: 1) */
70
+ value?: number;
71
+ /** Optional: Auto-create customer if not found */
72
+ customerData?: CustomerData;
73
+ /** Optional: Atomically track usage if allowed (check + track in one call) */
74
+ sendEvent?: boolean;
75
+ /** Optional: Entity ID to scope usage to (e.g. seat, workspace) */
76
+ entity?: string;
77
+ }
78
+ /** Machine-readable codes returned by check() */
79
+ type CheckCode = "access_granted" | "overage_allowed" | "addon_credits_used" | "limit_exceeded" | "insufficient_credits" | "customer_not_found" | "feature_not_found" | "no_active_subscription" | "feature_not_in_plan" | "unknown_feature_type";
80
+ /** Machine-readable codes returned by track() */
81
+ type TrackCode = "tracked" | "tracked_overage" | "addon_credits_used" | "limit_exceeded" | "customer_not_found" | "feature_not_found" | "no_active_subscription" | "feature_not_in_plan" | "internal_error";
82
+ /** Overage billing details included when usage exceeds the plan limit */
83
+ interface OverageDetails {
84
+ /** Overage handling type */
85
+ type: "charge" | "notify" | "block";
86
+ /** Whether this overage will be billed */
87
+ willBeBilled: boolean;
88
+ /** Price per overage unit in minor currency units (e.g. kobo) */
89
+ pricePerUnit?: number | null;
90
+ /** Number of units per billing increment */
91
+ billingUnits?: number | null;
92
+ }
93
+ /**
94
+ * Contextual details object returned alongside standard check/track fields.
95
+ * Contains all optional/situational information that isn't part of the
96
+ * core response shape (trial status, plan info, overage billing, etc.).
97
+ */
98
+ interface ResponseDetails {
99
+ /** Human-readable explanation of the result */
100
+ message: string;
101
+ /** Name of the plan granting access */
102
+ planName?: string;
103
+ /** Whether access is via a free trial */
104
+ trial?: boolean;
105
+ /** ISO timestamp when the trial ends */
106
+ trialEndsAt?: string | null;
107
+ /** Credit system slug (when feature resolved via credit system) */
108
+ creditSystem?: string;
109
+ /** Credit cost per unit of the child feature */
110
+ creditCostPerUnit?: number;
111
+ /** Overage billing details (present when usage exceeds plan limit) */
112
+ overage?: OverageDetails;
113
+ /** Number of add-on credits used in this request */
114
+ addonCreditsUsed?: number;
115
+ /** Remaining add-on credits after this request */
116
+ addonCreditsRemaining?: number;
117
+ }
118
+ /** Plan credit breakdown for credit system features */
119
+ interface PlanCredits {
120
+ /** Credits used this period */
121
+ used: number;
122
+ /** Plan credit limit */
123
+ limit: number | null;
124
+ /** ISO timestamp when plan credits reset */
125
+ resetsAt: string;
126
+ }
127
+ interface CheckResult {
128
+ /** Whether access is allowed */
129
+ allowed: boolean;
130
+ /** Machine-readable code */
131
+ code: CheckCode | string;
132
+ /** Current usage this period (null for boolean features) */
133
+ usage: number | null;
134
+ /** Plan limit (null = unlimited) */
135
+ limit: number | null;
136
+ /** Remaining plan units: limit - usage (null = unlimited) */
137
+ balance: number | null;
138
+ /** ISO timestamp when usage resets (null for boolean/non-resetting) */
139
+ resetsAt: string | null;
140
+ /** Reset interval (null for boolean features) */
141
+ resetInterval: string | null;
142
+ /** Add-on credit balance for this credit system (only for credit system features) */
143
+ addonCredits?: number;
144
+ /** Plan credit breakdown (only for credit system features) */
145
+ planCredits?: PlanCredits;
146
+ /** Contextual details (trial info, plan name, overage, human message) */
147
+ details: ResponseDetails;
148
+ }
149
+ /**
150
+ * track() - Usage Metering & Billing
151
+ */
152
+ interface TrackParams {
153
+ /** Customer ID or email */
154
+ customer: string;
155
+ /** Feature slug or ID to track usage for */
156
+ feature: string;
157
+ /** Amount to track (default: 1) */
158
+ value?: number;
159
+ /** Optional: Auto-create customer if not found */
160
+ customerData?: CustomerData;
161
+ /** Optional: Entity ID to scope usage to (e.g. seat, workspace) */
162
+ entity?: string;
163
+ /** Optional: Event metadata */
164
+ metadata?: Record<string, unknown>;
165
+ }
166
+ interface TrackResult {
167
+ /** Whether tracking was successful */
168
+ success: boolean;
169
+ /** Whether the tracked usage was within limits */
170
+ allowed: boolean;
171
+ /** Machine-readable code */
172
+ code: TrackCode | string;
173
+ /** Current usage this period after tracking (null for unlimited) */
174
+ usage: number | null;
175
+ /** Plan limit (null = unlimited) */
176
+ limit: number | null;
177
+ /** Remaining plan units after tracking: limit - usage (null = unlimited) */
178
+ balance: number | null;
179
+ /** ISO timestamp when usage resets */
180
+ resetsAt: string | null;
181
+ /** Reset interval */
182
+ resetInterval: string | null;
183
+ /** Add-on credit balance for this credit system (only for credit system features) */
184
+ addonCredits?: number;
185
+ /** Plan credit breakdown (only for credit system features) */
186
+ planCredits?: PlanCredits;
187
+ /** Contextual details (trial info, plan name, overage, human message) */
188
+ details: ResponseDetails;
189
+ }
190
+ /**
191
+ * billing.usage() - Get Unbilled Overage Usage
192
+ */
193
+ interface BillingUsageParams {
194
+ /** Customer ID or email */
195
+ customer: string;
196
+ }
197
+ interface BillingFeatureUsage {
198
+ /** Feature ID */
199
+ featureId: string;
200
+ /** Human-readable feature name */
201
+ featureName: string;
202
+ /** Total usage this period */
203
+ usage: number;
204
+ /** Included in plan (null = unlimited) */
205
+ included: number | null;
206
+ /** Billable overage units */
207
+ billableQuantity: number;
208
+ /** Estimated overage charge in minor currency units */
209
+ estimatedAmount: number;
210
+ /** Usage billing model */
211
+ usageModel: string;
212
+ }
213
+ interface BillingUsageResult {
214
+ /** Whether the request succeeded */
215
+ success: boolean;
216
+ /** Total estimated overage amount in minor currency units */
217
+ totalEstimated: number;
218
+ /** Currency code */
219
+ currency: string;
220
+ /** Per-feature breakdown */
221
+ features: BillingFeatureUsage[];
222
+ }
223
+ /**
224
+ * billing.invoice() - Generate an Invoice
225
+ */
226
+ interface InvoiceParams {
227
+ /** Customer ID or email */
228
+ customer: string;
229
+ }
230
+ interface InvoiceLineItem {
231
+ /** Feature or item description */
232
+ description: string;
233
+ /** Quantity */
234
+ quantity: number;
235
+ /** Unit price in minor currency units */
236
+ unitPrice: number;
237
+ /** Line total in minor currency units */
238
+ amount: number;
239
+ }
240
+ interface Invoice {
241
+ /** Invoice ID */
242
+ id: string;
243
+ /** Human-readable invoice number */
244
+ number: string;
245
+ /** Total amount in minor currency units */
246
+ total: number;
247
+ /** Currency code */
248
+ currency: string;
249
+ /** Invoice status */
250
+ status: "draft" | "open" | "paid" | "void";
251
+ /** Line items */
252
+ lineItems?: InvoiceLineItem[];
253
+ /** ISO timestamp */
254
+ createdAt: string;
255
+ }
256
+ interface InvoiceResult {
257
+ /** Whether the request succeeded */
258
+ success: boolean;
259
+ /** Generated invoice */
260
+ invoice: Invoice;
261
+ }
262
+ /**
263
+ * billing.pay() - Pay an Invoice
264
+ */
265
+ interface PayInvoiceParams {
266
+ /** Invoice ID */
267
+ invoiceId: string;
268
+ /** URL to redirect to after checkout payment (used when auto-charge fails) */
269
+ callbackUrl?: string;
270
+ }
271
+ interface PayInvoiceResult {
272
+ /** Whether the request succeeded */
273
+ success: boolean;
274
+ /** Whether the invoice was auto-charged (true) or needs manual checkout (false) */
275
+ paid: boolean;
276
+ /** Checkout URL — present when paid=false (customer must pay manually) */
277
+ checkoutUrl?: string;
278
+ /** The invoice */
279
+ invoice: Invoice;
280
+ }
281
+ /**
282
+ * billing.invoices() - List Invoices
283
+ */
284
+ interface InvoicesParams {
285
+ /** Customer ID or email */
286
+ customer: string;
287
+ }
288
+ interface InvoicesResult {
289
+ /** Whether the request succeeded */
290
+ success: boolean;
291
+ /** List of invoices */
292
+ invoices: Invoice[];
293
+ }
294
+ /**
295
+ * addon() - Purchase Add-on Credit Pack
296
+ */
297
+ interface AddonParams {
298
+ /** Customer ID or email */
299
+ customer: string;
300
+ /** Credit pack slug or ID */
301
+ pack: string;
302
+ /** Number of packs to buy (default: 1) */
303
+ quantity?: number;
304
+ /** Optional: Currency override */
305
+ currency?: string;
306
+ /** Optional: Redirect URL after checkout */
307
+ callbackUrl?: string;
308
+ /** Optional: Custom metadata */
309
+ metadata?: Record<string, unknown>;
310
+ }
311
+ interface AddonResult {
312
+ /** Whether the purchase succeeded immediately */
313
+ success: boolean;
314
+ /** Whether the customer needs to complete a checkout */
315
+ requiresCheckout: boolean;
316
+ /** Total credits added (only if immediate charge succeeded) */
317
+ credits?: number;
318
+ /** Updated scoped balance (only if immediate charge succeeded) */
319
+ balance?: number;
320
+ /** Credit system the credits were added to */
321
+ creditSystemId?: string;
322
+ /** Checkout URL (only if requiresCheckout is true) */
323
+ checkoutUrl?: string;
324
+ /** Payment reference */
325
+ reference?: string;
326
+ /** Human-readable message */
327
+ message?: string;
328
+ }
329
+ /**
330
+ * Shared types
331
+ */
332
+ type PaymentChannel = "card" | "bank" | "bank_transfer" | "ussd" | "mobile_money" | "qr";
333
+ type Currency = "NGN" | "GHS" | "ZAR" | "KES" | "USD" | "CAD" | "EUR" | "GBP" | "CHF" | "SEK" | "NOK" | "DKK" | "PLN" | "CZK" | "JPY" | "CNY" | "INR" | "SGD" | "HKD" | "AUD" | "NZD" | "BRL" | "MXN" | "ARS" | "COP" | "AED" | "SAR" | "EGP" | (string & {});
334
+ type PlanInterval = "daily" | "weekly" | "monthly" | "quarterly" | "yearly";
335
+ type ResetInterval = "never" | "5min" | "15min" | "30min" | "hourly" | "daily" | "weekly" | "monthly" | "quarterly" | "yearly";
336
+ type SubscriptionStatus = "active" | "canceled" | "expired" | "incomplete" | "incomplete_expired" | "past_due" | "trialing" | "unpaid";
337
+ /**
338
+ * Plan and feature definitions
339
+ */
340
+ interface Plan {
341
+ id: string;
342
+ name: string;
343
+ description?: string;
344
+ price: number;
345
+ currency: Currency;
346
+ interval: PlanInterval;
347
+ features: Record<string, FeatureLimit>;
348
+ metadata?: Record<string, unknown>;
349
+ }
350
+ interface FeatureLimit {
351
+ /** Usage limit (null = unlimited) */
352
+ limit: number | null;
353
+ /** Reset interval */
354
+ reset: ResetInterval;
355
+ /** Overage behavior */
356
+ overage?: "block" | "charge";
357
+ /** Overage price per unit */
358
+ overagePrice?: number;
359
+ }
360
+ interface Feature {
361
+ id: string;
362
+ name: string;
363
+ description?: string;
364
+ type: "metered" | "boolean" | "seats";
365
+ unit?: string;
366
+ }
367
+ /**
368
+ * Database models
369
+ */
370
+ interface Customer {
371
+ id: string;
372
+ providerId?: string;
373
+ providerCustomerId?: string;
374
+ providerAuthorizationCode?: string;
375
+ providerMetadata?: Record<string, unknown>;
376
+ paystackCustomerId?: string;
377
+ paystackAuthorizationCode?: string;
378
+ email: string;
379
+ name?: string;
380
+ metadata?: Record<string, unknown>;
381
+ createdAt: Date;
382
+ updatedAt: Date;
383
+ }
384
+ interface Subscription {
385
+ id: string;
386
+ customerId: string;
387
+ providerId?: string;
388
+ providerSubscriptionId?: string;
389
+ providerSubscriptionCode?: string;
390
+ providerMetadata?: Record<string, unknown>;
391
+ paystackSubscriptionId?: string;
392
+ paystackSubscriptionCode?: string;
393
+ planId: string;
394
+ status: SubscriptionStatus;
395
+ currentPeriodStart: Date;
396
+ currentPeriodEnd: Date;
397
+ cancelAt?: Date;
398
+ metadata?: Record<string, unknown>;
399
+ createdAt: Date;
400
+ updatedAt: Date;
401
+ }
402
+ interface Entitlement {
403
+ id: string;
404
+ customerId: string;
405
+ featureId: string;
406
+ limit: number | null;
407
+ resetInterval: ResetInterval;
408
+ lastResetAt?: Date;
409
+ expiresAt?: Date;
410
+ createdAt: Date;
411
+ updatedAt: Date;
412
+ }
413
+ interface UsageRecord {
414
+ id: string;
415
+ customerId: string;
416
+ featureId: string;
417
+ amount: number;
418
+ periodStart: Date;
419
+ periodEnd: Date;
420
+ metadata?: Record<string, unknown>;
421
+ createdAt: Date;
422
+ }
423
+ /**
424
+ * Catalog Builder Types
425
+ * Used by metered(), boolean(), and plan() builder functions.
426
+ */
427
+ /** Union of all catalog entries passed to OwostackConfig.catalog */
428
+ type CatalogEntry = PlanDefinition | CreditSystemDefinition;
429
+ /** Configuration for a metered feature within a plan */
430
+ interface MeteredFeatureConfig {
431
+ /** Limit for this plan (null = unlimited) */
432
+ limit?: number | null;
433
+ /** Reset interval (default: "monthly") */
434
+ reset?: ResetInterval;
435
+ /** Overage behavior (default: "block") */
436
+ overage?: "block" | "charge";
437
+ /** Price per overage unit in minor currency units */
438
+ overagePrice?: number;
439
+ /** Max overage units per period */
440
+ maxOverageUnits?: number;
441
+ /** Billing units for overage */
442
+ billingUnits?: number;
443
+ /** Credit cost for credit systems */
444
+ creditCost?: number;
445
+ /** Whether feature is enabled (default: true) */
446
+ enabled?: boolean;
447
+ }
448
+ /** Configuration for a boolean feature within a plan */
449
+ interface BooleanFeatureConfig {
450
+ /** Whether feature is included in this plan (default: true) */
451
+ enabled?: boolean;
452
+ }
453
+ /** A feature entry inside a plan's features array */
454
+ interface PlanFeatureEntry {
455
+ /** @internal */
456
+ _type: "plan_feature";
457
+ /** Feature slug */
458
+ slug: string;
459
+ /** Feature type */
460
+ featureType: "metered" | "boolean";
461
+ /** Human-readable name (auto-generated from slug if omitted) */
462
+ name?: string;
463
+ /** Whether feature is included in this plan */
464
+ enabled: boolean;
465
+ /** Metered config (only for metered features) */
466
+ config?: MeteredFeatureConfig;
467
+ }
468
+ /** A plan definition in the catalog */
469
+ interface PlanDefinition {
470
+ /** @internal */
471
+ _type: "plan";
472
+ /** Plan slug (used as unique identifier) */
473
+ slug: string;
474
+ /** Human-readable plan name */
475
+ name: string;
476
+ /** Plan description */
477
+ description?: string;
478
+ /** Price in minor currency units (e.g. kobo) */
479
+ price: number;
480
+ /** Currency code */
481
+ currency: Currency;
482
+ /** Billing interval */
483
+ interval: PlanInterval;
484
+ /** Features included in this plan */
485
+ features: PlanFeatureEntry[];
486
+ /** Plan group for upgrade/downgrade logic */
487
+ planGroup?: string;
488
+ /** Trial period in days */
489
+ trialDays?: number;
490
+ /** Provider for this plan (overrides default) */
491
+ provider?: string;
492
+ /** Custom metadata */
493
+ metadata?: Record<string, unknown>;
494
+ }
495
+ /** A feature entry within a credit system */
496
+ interface CreditSystemFeatureEntry {
497
+ /** Feature slug */
498
+ feature: string;
499
+ /** Credit cost per unit of this feature */
500
+ creditCost: number;
501
+ }
502
+ /** A credit system definition in the catalog */
503
+ interface CreditSystemDefinition {
504
+ /** @internal */
505
+ _type: "credit_system";
506
+ /** Credit system slug (used as unique identifier) */
507
+ slug: string;
508
+ /** Human-readable credit system name */
509
+ name: string;
510
+ /** Credit system description */
511
+ description?: string;
512
+ /** Features that consume credits from this system with their credit costs */
513
+ features: CreditSystemFeatureEntry[];
514
+ }
515
+ /**
516
+ * wallet() - Payment Methods
517
+ */
518
+ interface CardInfo {
519
+ /** Card ID (payment method ID) */
520
+ id: string;
521
+ /** Last 4 digits */
522
+ last4: string;
523
+ /** Card brand (visa, mastercard, verve) */
524
+ brand: string;
525
+ /** Expiry as "MM/YY" */
526
+ exp: string;
527
+ /** Provider that captured this card */
528
+ provider: string;
529
+ }
530
+ interface PaymentMethodInfo {
531
+ /** Payment method ID */
532
+ id: string;
533
+ /** Type: card (Paystack/Stripe) or provider_managed (Dodo) */
534
+ type: "card" | "provider_managed";
535
+ /** Provider ID */
536
+ provider: string;
537
+ /** Whether this is the default payment method */
538
+ isDefault: boolean;
539
+ /** Whether the token is still valid for charging */
540
+ isValid: boolean;
541
+ /** Card details (null for provider_managed) */
542
+ card: CardInfo | null;
543
+ }
544
+ interface WalletResult {
545
+ /** Whether the customer has a chargeable payment method */
546
+ hasCard: boolean;
547
+ /** Default card details (shortcut for the default method's card) */
548
+ card: CardInfo | null;
549
+ /** All stored payment methods */
550
+ methods: PaymentMethodInfo[];
551
+ }
552
+ interface WalletSetupParams {
553
+ /** Customer ID or email */
554
+ customer: string;
555
+ /** Optional: Redirect URL after card setup */
556
+ callbackUrl?: string;
557
+ /** Optional: Override provider */
558
+ provider?: string;
559
+ }
560
+ interface WalletSetupResult {
561
+ /** Checkout URL to redirect user for card capture */
562
+ url: string;
563
+ /** Payment reference */
564
+ reference: string;
565
+ }
566
+ interface WalletRemoveResult {
567
+ /** Whether the removal succeeded */
568
+ success: boolean;
569
+ }
570
+ /**
571
+ * plans() - List Plans
572
+ */
573
+ interface PlansParams {
574
+ /** Optional: Filter by plan group */
575
+ group?: string;
576
+ /** Optional: Filter by billing interval */
577
+ interval?: PlanInterval;
578
+ /** Optional: Filter by currency */
579
+ currency?: string;
580
+ /** Optional: Include inactive plans (default: false) */
581
+ includeInactive?: boolean;
582
+ }
583
+ /** A plan feature as returned by the public API */
584
+ interface PublicPlanFeature {
585
+ /** Feature slug */
586
+ slug: string;
587
+ /** Human-readable feature name */
588
+ name: string;
589
+ /** Feature type */
590
+ type: "metered" | "boolean" | "static";
591
+ /** Whether this feature is enabled in this plan */
592
+ enabled: boolean;
593
+ /** Usage limit (null = unlimited) */
594
+ limit: number | null;
595
+ /** Reset interval */
596
+ resetInterval: string | null;
597
+ /** Unit label (e.g. "call", "message", "GB") */
598
+ unit: string | null;
599
+ /** Overage behavior */
600
+ overage?: "block" | "charge";
601
+ /** Overage price per unit in minor currency units */
602
+ overagePrice?: number | null;
603
+ }
604
+ /** A plan as returned by the public API — safe for client-side consumption */
605
+ interface PublicPlan {
606
+ /** Plan ID */
607
+ id: string;
608
+ /** URL-safe slug */
609
+ slug: string;
610
+ /** Human-readable name */
611
+ name: string;
612
+ /** Description */
613
+ description: string | null;
614
+ /** Price in minor currency units */
615
+ price: number;
616
+ /** Currency code */
617
+ currency: string;
618
+ /** Billing interval */
619
+ interval: PlanInterval;
620
+ /** "free" or "paid" */
621
+ type: string;
622
+ /** Whether this is a recurring or one-time plan */
623
+ billingType: string;
624
+ /** Whether this is an add-on plan */
625
+ isAddon: boolean;
626
+ /** Plan group (for upgrade/downgrade) */
627
+ planGroup: string | null;
628
+ /** Trial period in days (0 = no trial) */
629
+ trialDays: number;
630
+ /** Features included in this plan */
631
+ features: PublicPlanFeature[];
632
+ }
633
+ interface PlansResult {
634
+ /** Whether the request succeeded */
635
+ success: boolean;
636
+ /** List of plans */
637
+ plans: PublicPlan[];
638
+ }
639
+ /** Serialized catalog sent to POST /api/sync */
640
+ interface SyncPayload {
641
+ /** Optional: Default provider for all plans */
642
+ defaultProvider?: string;
643
+ features: Array<{
644
+ slug: string;
645
+ type: "metered" | "boolean";
646
+ name: string;
647
+ }>;
648
+ creditSystems: Array<{
649
+ slug: string;
650
+ name: string;
651
+ description?: string;
652
+ features: Array<{
653
+ feature: string;
654
+ creditCost: number;
655
+ }>;
656
+ }>;
657
+ plans: Array<{
658
+ slug: string;
659
+ name: string;
660
+ description?: string;
661
+ price: number;
662
+ currency: Currency;
663
+ interval: PlanInterval;
664
+ planGroup?: string;
665
+ trialDays?: number;
666
+ provider?: string;
667
+ metadata?: Record<string, unknown>;
668
+ features: Array<{
669
+ slug: string;
670
+ enabled: boolean;
671
+ limit?: number | null;
672
+ reset?: ResetInterval;
673
+ overage?: "block" | "charge";
674
+ overagePrice?: number;
675
+ maxOverageUnits?: number;
676
+ billingUnits?: number;
677
+ creditCost?: number;
678
+ }>;
679
+ }>;
680
+ }
681
+ /** Changes reported for a single resource type */
682
+ interface SyncChanges {
683
+ created: string[];
684
+ updated: string[];
685
+ unchanged: string[];
686
+ }
687
+ /** Result returned by owo.sync() */
688
+ interface SyncResult {
689
+ success: boolean;
690
+ features: SyncChanges;
691
+ creditSystems: SyncChanges;
692
+ plans: SyncChanges;
693
+ warnings: string[];
694
+ }
695
+ /**
696
+ * customer() - Create or resolve a customer
697
+ */
698
+ interface CustomerParams {
699
+ /** Customer ID (optional - auto-generated if not provided) */
700
+ id?: string;
701
+ /** Customer email (required) */
702
+ email: string;
703
+ /** Customer display name */
704
+ name?: string;
705
+ /** Custom metadata */
706
+ metadata?: Record<string, unknown>;
707
+ }
708
+ interface CustomerResult {
709
+ /** Customer ID */
710
+ id: string;
711
+ /** Customer email */
712
+ email: string;
713
+ /** Customer display name */
714
+ name?: string;
715
+ /** Custom metadata */
716
+ metadata?: Record<string, unknown>;
717
+ /** ISO timestamp when created */
718
+ createdAt: string;
719
+ /** ISO timestamp when last updated */
720
+ updatedAt: string;
721
+ }
722
+ /**
723
+ * addEntity() - Add a feature entity (e.g., seat)
724
+ */
725
+ interface AddEntityParams {
726
+ /** Customer ID or email */
727
+ customer: string;
728
+ /** Feature slug that this entity consumes (e.g., "seats") */
729
+ feature: string;
730
+ /** Entity ID (unique per feature) */
731
+ entity: string;
732
+ /** Display name for the entity */
733
+ name?: string;
734
+ /** Email for the entity */
735
+ email?: string;
736
+ /** Custom metadata */
737
+ metadata?: Record<string, unknown>;
738
+ }
739
+ interface AddEntityResult {
740
+ /** Whether the entity was created successfully */
741
+ success: boolean;
742
+ /** The entity ID */
743
+ entityId: string;
744
+ /** The feature slug */
745
+ featureId: string;
746
+ /** Current count of entities for this feature */
747
+ count: number;
748
+ /** Limit for this feature (null = unlimited) */
749
+ limit: number | null;
750
+ /** Remaining slots (null = unlimited) */
751
+ remaining: number | null;
752
+ }
753
+ /**
754
+ * removeEntity() - Remove a feature entity
755
+ */
756
+ interface RemoveEntityParams {
757
+ /** Customer ID or email */
758
+ customer: string;
759
+ /** Feature slug */
760
+ feature: string;
761
+ /** Entity ID to remove */
762
+ entity: string;
763
+ }
764
+ interface RemoveEntityResult {
765
+ /** Whether the entity was removed successfully */
766
+ success: boolean;
767
+ /** The entity ID that was removed */
768
+ entityId: string;
769
+ /** Current count of entities for this feature after removal */
770
+ count: number;
771
+ }
772
+ /**
773
+ * listEntities() - List feature entities
774
+ */
775
+ interface ListEntitiesParams {
776
+ /** Customer ID or email */
777
+ customer: string;
778
+ /** Feature slug (optional - lists all entities if not provided) */
779
+ feature?: string;
780
+ }
781
+ interface Entity {
782
+ /** Entity ID */
783
+ id: string;
784
+ /** Feature slug */
785
+ featureId: string;
786
+ /** Display name */
787
+ name?: string;
788
+ /** Email */
789
+ email?: string;
790
+ /** Custom metadata */
791
+ metadata?: Record<string, unknown>;
792
+ /** Entity status */
793
+ status: "active" | "pending_removal";
794
+ /** ISO timestamp when created */
795
+ createdAt: string;
796
+ }
797
+ interface ListEntitiesResult {
798
+ /** Whether the request succeeded */
799
+ success: boolean;
800
+ /** List of entities */
801
+ entities: Entity[];
802
+ /** Total count */
803
+ total: number;
804
+ }
805
+
806
+ export type { AddEntityParams, AddEntityResult, AddonParams, AddonResult, AttachParams, AttachResult, BillingFeatureUsage, BillingUsageParams, BillingUsageResult, BooleanFeatureConfig, CardInfo, CatalogEntry, CheckCode, CheckParams, CheckResult, CreditSystemDefinition, CreditSystemFeatureEntry, Currency, Customer, CustomerData, CustomerParams, CustomerResult, Entitlement, Entity, Feature, FeatureLimit, Invoice, InvoiceLineItem, InvoiceParams, InvoiceResult, InvoicesParams, InvoicesResult, ListEntitiesParams, ListEntitiesResult, MeteredFeatureConfig, OverageDetails, OwostackConfig, PayInvoiceParams, PayInvoiceResult, PaymentChannel, PaymentMethodInfo, Plan, PlanCredits, PlanDefinition, PlanFeatureEntry, PlanInterval, PlansParams, PlansResult, PublicPlan, PublicPlanFeature, RemoveEntityParams, RemoveEntityResult, ResetInterval, ResponseDetails, Subscription, SubscriptionStatus, SyncChanges, SyncPayload, SyncResult, TrackCode, TrackParams, TrackResult, UsageRecord, WalletRemoveResult, WalletResult, WalletSetupParams, WalletSetupResult };
package/dist/index.js ADDED
File without changes
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@owostack/types",
3
+ "version": "0.1.0",
4
+ "description": "Shared TypeScript types for Owostack",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/Abdulmumin1/owostack.git",
9
+ "directory": "packages/types"
10
+ },
11
+ "type": "module",
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "main": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js"
21
+ }
22
+ },
23
+ "scripts": {
24
+ "build": "tsup src/index.ts --format esm --dts --clean",
25
+ "dev": "tsup src/index.ts --format esm --dts --watch"
26
+ },
27
+ "devDependencies": {
28
+ "tsup": "^8.3.6",
29
+ "typescript": "^5.7.3"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
33
+ }
34
+ }