owostack 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 +190 -0
- package/README.md +88 -0
- package/dist/index.d.ts +414 -0
- package/dist/index.js +727 -0
- package/package.json +49 -0
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,88 @@
|
|
|
1
|
+
# owostack
|
|
2
|
+
|
|
3
|
+
Core SDK for the Owostack billing infrastructure. Build a working billing flow for your AI SaaS or platform in minutes.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install owostack
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quickstart
|
|
12
|
+
|
|
13
|
+
Initialize the SDK with your API key from the Owostack dashboard:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { Owostack } from "owostack";
|
|
17
|
+
|
|
18
|
+
const owo = new Owostack({
|
|
19
|
+
secretKey: process.env.OWOSTACK_SECRET_KEY,
|
|
20
|
+
mode: "sandbox", // use "live" for production
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### 1. Attach a customer to a plan
|
|
25
|
+
|
|
26
|
+
Create a checkout session or manage an existing subscription:
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
const attach = await owo.attach({
|
|
30
|
+
customer: "user_123",
|
|
31
|
+
product: "starter_plan",
|
|
32
|
+
customerData: { email: "user@example.com" },
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
if (attach.checkoutUrl) {
|
|
36
|
+
// Redirect your user to checkout
|
|
37
|
+
window.location.href = attach.checkoutUrl;
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### 2. Check feature access
|
|
42
|
+
|
|
43
|
+
Verify if a customer has access to a feature based on their plan:
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
const access = await owo.check({
|
|
47
|
+
customer: "user_123",
|
|
48
|
+
feature: "api-calls",
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
if (access.allowed) {
|
|
52
|
+
// Allow request
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### 3. Track usage
|
|
57
|
+
|
|
58
|
+
Record usage for metered features:
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
await owo.track({
|
|
62
|
+
customer: "user_123",
|
|
63
|
+
feature: "api-calls",
|
|
64
|
+
value: 1,
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Features
|
|
69
|
+
|
|
70
|
+
- **Feature Gating**: Instant access control for boolean and metered features.
|
|
71
|
+
- **Usage Metering**: Record usage and enforce limits automatically.
|
|
72
|
+
- **Checkout Flows**: Generate checkout sessions for new subscriptions or plan upgrades.
|
|
73
|
+
- **Catalog Synchronization**: Define plans and features declaratively in your codebase and sync to the cloud.
|
|
74
|
+
- **Multi-Provider Support**: Built-in support for Paystack and Dodo Payments.
|
|
75
|
+
- **Full TypeScript Support**: Comprehensive type definitions for all methods and responses.
|
|
76
|
+
|
|
77
|
+
## Related Packages
|
|
78
|
+
|
|
79
|
+
- [owocli](https://www.npmjs.com/package/owocli) - CLI for catalog sync and project initialization.
|
|
80
|
+
- [@owostack/types](https://www.npmjs.com/package/@owostack/types) - Shared type definitions.
|
|
81
|
+
|
|
82
|
+
## Documentation
|
|
83
|
+
|
|
84
|
+
For full documentation and guides, visit [docs.owostack.com](https://docs.owostack.com).
|
|
85
|
+
|
|
86
|
+
## License
|
|
87
|
+
|
|
88
|
+
Apache-2.0
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
import { CheckResult, PlanFeatureEntry, ResetInterval, CreditSystemDefinition, TrackResult, MeteredFeatureConfig, CatalogEntry, SyncPayload, Currency, PlanInterval, PlanDefinition, OwostackConfig, BillingUsageParams, BillingUsageResult, InvoiceParams, InvoiceResult, InvoicesParams, InvoicesResult, PayInvoiceParams, PayInvoiceResult, WalletResult, WalletSetupResult, WalletRemoveResult, SyncResult, AttachParams, AttachResult, CheckParams, TrackParams, AddonParams, AddonResult, CustomerParams, CustomerResult, AddEntityParams, AddEntityResult, RemoveEntityParams, RemoveEntityResult, ListEntitiesParams, ListEntitiesResult, PlansParams, PlansResult, PublicPlan } from '@owostack/types';
|
|
2
|
+
export { AddEntityParams, AddEntityResult, AddonParams, AddonResult, AttachParams, AttachResult, BillingFeatureUsage, BillingUsageParams, BillingUsageResult, BooleanFeatureConfig, CardInfo, CatalogEntry, CheckCode, CheckParams, CheckResult, CustomerData, CustomerParams, CustomerResult, Invoice, InvoiceLineItem, InvoiceParams, InvoiceResult, InvoicesParams, InvoicesResult, ListEntitiesParams, ListEntitiesResult, MeteredFeatureConfig, OverageDetails, OwostackConfig, PayInvoiceParams, PayInvoiceResult, PaymentMethodInfo, PlanCredits, PlanDefinition, PlanFeatureEntry, PlansParams, PlansResult, PublicPlan, PublicPlanFeature, RemoveEntityParams, RemoveEntityResult, ResponseDetails, SyncChanges, SyncPayload, SyncResult, TrackCode, TrackParams, TrackResult, WalletRemoveResult, WalletResult, WalletSetupResult } from '@owostack/types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* BooleanHandle — returned by boolean().
|
|
6
|
+
*/
|
|
7
|
+
declare class BooleanHandle {
|
|
8
|
+
readonly slug: string;
|
|
9
|
+
readonly featureType: "boolean";
|
|
10
|
+
readonly featureName: string | undefined;
|
|
11
|
+
_client: any;
|
|
12
|
+
constructor(slug: string, name?: string);
|
|
13
|
+
check(customer: string, opts?: {
|
|
14
|
+
value?: number;
|
|
15
|
+
entity?: string;
|
|
16
|
+
sendEvent?: boolean;
|
|
17
|
+
}): Promise<CheckResult>;
|
|
18
|
+
on(): PlanFeatureEntry;
|
|
19
|
+
off(): PlanFeatureEntry;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* MeteredHandle — returned by metered().
|
|
23
|
+
*/
|
|
24
|
+
interface MeteredHandle {
|
|
25
|
+
readonly slug: string;
|
|
26
|
+
readonly featureType: "metered";
|
|
27
|
+
readonly featureName: string | undefined;
|
|
28
|
+
_client: any;
|
|
29
|
+
check(customer: string, opts?: {
|
|
30
|
+
value?: number;
|
|
31
|
+
entity?: string;
|
|
32
|
+
sendEvent?: boolean;
|
|
33
|
+
}): Promise<CheckResult>;
|
|
34
|
+
track(customer: string, value?: number, opts?: {
|
|
35
|
+
entity?: string;
|
|
36
|
+
}): Promise<TrackResult>;
|
|
37
|
+
limit(value: number, config?: Omit<MeteredFeatureConfig, "limit">): PlanFeatureEntry;
|
|
38
|
+
included(value: number, config?: Omit<MeteredFeatureConfig, "limit">): PlanFeatureEntry;
|
|
39
|
+
unlimited(config?: Omit<MeteredFeatureConfig, "limit">): PlanFeatureEntry;
|
|
40
|
+
config(opts: MeteredFeatureConfig): PlanFeatureEntry;
|
|
41
|
+
(creditCost: number): {
|
|
42
|
+
feature: string;
|
|
43
|
+
creditCost: number;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Create a metered feature handle.
|
|
48
|
+
*/
|
|
49
|
+
declare function metered(slug: string, opts?: {
|
|
50
|
+
name?: string;
|
|
51
|
+
}): MeteredHandle;
|
|
52
|
+
/**
|
|
53
|
+
* Create a boolean feature handle.
|
|
54
|
+
*/
|
|
55
|
+
declare function boolean(slug: string, opts?: {
|
|
56
|
+
name?: string;
|
|
57
|
+
}): BooleanHandle;
|
|
58
|
+
/**
|
|
59
|
+
* CreditSystemHandle — returned by creditSystem().
|
|
60
|
+
*/
|
|
61
|
+
declare class CreditSystemHandle {
|
|
62
|
+
readonly slug: string;
|
|
63
|
+
readonly name: string | undefined;
|
|
64
|
+
readonly description: string | undefined;
|
|
65
|
+
private featureCosts;
|
|
66
|
+
constructor(slug: string, featureCosts: Map<string, number>, opts?: {
|
|
67
|
+
name?: string;
|
|
68
|
+
description?: string;
|
|
69
|
+
});
|
|
70
|
+
credits(amount: number, config?: {
|
|
71
|
+
reset?: ResetInterval;
|
|
72
|
+
overage?: "block" | "charge";
|
|
73
|
+
}): PlanFeatureEntry;
|
|
74
|
+
_buildDefinition(): CreditSystemDefinition;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Create a credit system handle.
|
|
78
|
+
*/
|
|
79
|
+
declare function creditSystem(slug: string, opts: {
|
|
80
|
+
name?: string;
|
|
81
|
+
description?: string;
|
|
82
|
+
features: Array<{
|
|
83
|
+
feature: string;
|
|
84
|
+
creditCost: number;
|
|
85
|
+
}>;
|
|
86
|
+
}): CreditSystemHandle;
|
|
87
|
+
/**
|
|
88
|
+
* Create a plan definition.
|
|
89
|
+
*/
|
|
90
|
+
declare function plan(slug: string, config: {
|
|
91
|
+
name: string;
|
|
92
|
+
description?: string;
|
|
93
|
+
price: number;
|
|
94
|
+
currency: Currency;
|
|
95
|
+
interval: PlanInterval;
|
|
96
|
+
features: PlanFeatureEntry[];
|
|
97
|
+
planGroup?: string;
|
|
98
|
+
trialDays?: number;
|
|
99
|
+
provider?: string;
|
|
100
|
+
metadata?: Record<string, unknown>;
|
|
101
|
+
}): PlanDefinition;
|
|
102
|
+
/**
|
|
103
|
+
* Extract SyncPayload from catalog.
|
|
104
|
+
*/
|
|
105
|
+
declare function buildSyncPayload(catalog: CatalogEntry[], defaultProvider?: string): SyncPayload;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Owostack - Billing infrastructure for modern SaaS
|
|
109
|
+
*
|
|
110
|
+
* Three methods to rule them all:
|
|
111
|
+
* - attach(): Start checkout or manage subscriptions
|
|
112
|
+
* - check(): Verify feature access and usage limits
|
|
113
|
+
* - track(): Record usage and trigger billing
|
|
114
|
+
*
|
|
115
|
+
* Customers are auto-created when you pass customerData to any endpoint.
|
|
116
|
+
*/
|
|
117
|
+
declare class Owostack {
|
|
118
|
+
/** @internal — exposed for CLI tooling */
|
|
119
|
+
readonly _config: OwostackConfig;
|
|
120
|
+
private apiUrl;
|
|
121
|
+
/** Billing: unbilled usage, invoices, and invoice generation */
|
|
122
|
+
readonly billing: BillingNamespace;
|
|
123
|
+
/** Wallet: payment methods — callable + namespace */
|
|
124
|
+
readonly wallet: WalletFn;
|
|
125
|
+
constructor(config: OwostackConfig);
|
|
126
|
+
private resolveApiUrl;
|
|
127
|
+
/**
|
|
128
|
+
* Override the API key at runtime (used by CLI).
|
|
129
|
+
* @internal
|
|
130
|
+
*/
|
|
131
|
+
setSecretKey(key: string): void;
|
|
132
|
+
/**
|
|
133
|
+
* Override the API URL at runtime (used by CLI).
|
|
134
|
+
* @internal
|
|
135
|
+
*/
|
|
136
|
+
setApiUrl(url: string): void;
|
|
137
|
+
/**
|
|
138
|
+
* sync() - Push catalog to the API
|
|
139
|
+
*
|
|
140
|
+
* Reconciles features and plans defined in the catalog with the server.
|
|
141
|
+
* Idempotent — safe to call multiple times with the same config.
|
|
142
|
+
* Only creates/updates; never deletes.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* const result = await owo.sync();
|
|
147
|
+
* console.log(`Created ${result.features.created.length} features`);
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
sync(): Promise<SyncResult>;
|
|
151
|
+
/**
|
|
152
|
+
* attach() - Checkout & Subscription Management
|
|
153
|
+
*
|
|
154
|
+
* Creates checkout sessions, handles upgrades/downgrades, manages subscriptions.
|
|
155
|
+
* Auto-creates the customer if customerData is provided and the customer doesn't exist.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* const result = await owo.attach({
|
|
160
|
+
* customer: 'user_123',
|
|
161
|
+
* product: 'pro_plan',
|
|
162
|
+
* customerData: { email: 'user@example.com', name: 'Jane' },
|
|
163
|
+
* });
|
|
164
|
+
*
|
|
165
|
+
* // Redirect user to checkout
|
|
166
|
+
* window.location.href = result.url;
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
attach(params: AttachParams): Promise<AttachResult>;
|
|
170
|
+
/**
|
|
171
|
+
* check() - Feature Gating & Access Control
|
|
172
|
+
*
|
|
173
|
+
* Queries whether a customer can access a feature based on their plan,
|
|
174
|
+
* payment status, and usage limits.
|
|
175
|
+
*
|
|
176
|
+
* Pass sendEvent: true to atomically check AND track usage in one call.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```ts
|
|
180
|
+
* const access = await owo.check({
|
|
181
|
+
* customer: 'user_123',
|
|
182
|
+
* feature: 'api_calls',
|
|
183
|
+
* customerData: { email: 'user@example.com' },
|
|
184
|
+
* });
|
|
185
|
+
*
|
|
186
|
+
* if (!access.allowed) {
|
|
187
|
+
* throw new Error(access.code);
|
|
188
|
+
* }
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
check(params: CheckParams): Promise<CheckResult>;
|
|
192
|
+
/**
|
|
193
|
+
* track() - Usage Metering & Billing
|
|
194
|
+
*
|
|
195
|
+
* Records usage events, decrements quotas, and triggers billing for
|
|
196
|
+
* pay-as-you-go features.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```ts
|
|
200
|
+
* await owo.track({
|
|
201
|
+
* customer: 'user_123',
|
|
202
|
+
* feature: 'api_calls',
|
|
203
|
+
* value: 1,
|
|
204
|
+
* customerData: { email: 'user@example.com' },
|
|
205
|
+
* });
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
track(params: TrackParams): Promise<TrackResult>;
|
|
209
|
+
/**
|
|
210
|
+
* addon() - Purchase Add-on Credit Pack
|
|
211
|
+
*
|
|
212
|
+
* Buy additional credits scoped to a credit system.
|
|
213
|
+
* If the customer has a card on file, charges immediately.
|
|
214
|
+
* Otherwise returns a checkout URL.
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* ```ts
|
|
218
|
+
* const result = await owo.addon({
|
|
219
|
+
* customer: 'user_123',
|
|
220
|
+
* pack: '250-credits',
|
|
221
|
+
* quantity: 2,
|
|
222
|
+
* });
|
|
223
|
+
*
|
|
224
|
+
* if (result.requiresCheckout) {
|
|
225
|
+
* window.location.href = result.checkoutUrl!;
|
|
226
|
+
* } else {
|
|
227
|
+
* console.log(`Balance: ${result.balance} credits`);
|
|
228
|
+
* }
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
addon(params: AddonParams): Promise<AddonResult>;
|
|
232
|
+
/**
|
|
233
|
+
* customer() - Create or resolve a customer
|
|
234
|
+
*
|
|
235
|
+
* Creates a new customer or resolves an existing one by email or ID.
|
|
236
|
+
* If customerData is provided and customer doesn't exist, creates a new customer.
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* ```ts
|
|
240
|
+
* // Create new customer
|
|
241
|
+
* const customer = await owo.customer({
|
|
242
|
+
* email: 'org@acme.com',
|
|
243
|
+
* name: 'Acme Corp',
|
|
244
|
+
* metadata: { plan: 'enterprise' }
|
|
245
|
+
* });
|
|
246
|
+
*
|
|
247
|
+
* // Get existing customer
|
|
248
|
+
* const existing = await owo.customer({ email: 'org@acme.com' });
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
customer(params: CustomerParams): Promise<CustomerResult>;
|
|
252
|
+
/**
|
|
253
|
+
* addEntity() - Add a feature entity (e.g., seat)
|
|
254
|
+
*
|
|
255
|
+
* Creates a new entity scoped to a feature. Validates against the feature limit.
|
|
256
|
+
* Throws if the limit would be exceeded.
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* ```ts
|
|
260
|
+
* await owo.addEntity({
|
|
261
|
+
* customer: 'org@acme.com',
|
|
262
|
+
* feature: 'seats',
|
|
263
|
+
* entity: 'user_123',
|
|
264
|
+
* name: 'John Doe',
|
|
265
|
+
* metadata: { role: 'admin' }
|
|
266
|
+
* });
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
addEntity(params: AddEntityParams): Promise<AddEntityResult>;
|
|
270
|
+
/**
|
|
271
|
+
* removeEntity() - Remove a feature entity
|
|
272
|
+
*
|
|
273
|
+
* Removes an entity and frees up the slot for the feature limit.
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* ```ts
|
|
277
|
+
* await owo.removeEntity({
|
|
278
|
+
* customer: 'org@acme.com',
|
|
279
|
+
* feature: 'seats',
|
|
280
|
+
* entity: 'user_123'
|
|
281
|
+
* });
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
284
|
+
removeEntity(params: RemoveEntityParams): Promise<RemoveEntityResult>;
|
|
285
|
+
/**
|
|
286
|
+
* listEntities() - List feature entities
|
|
287
|
+
*
|
|
288
|
+
* Returns all entities for a customer, optionally filtered by feature.
|
|
289
|
+
*
|
|
290
|
+
* @example
|
|
291
|
+
* ```ts
|
|
292
|
+
* // List all entities
|
|
293
|
+
* const { entities } = await owo.listEntities({ customer: 'org@acme.com' });
|
|
294
|
+
*
|
|
295
|
+
* // List seats only
|
|
296
|
+
* const { entities: seats } = await owo.listEntities({
|
|
297
|
+
* customer: 'org@acme.com',
|
|
298
|
+
* feature: 'seats'
|
|
299
|
+
* });
|
|
300
|
+
* ```
|
|
301
|
+
*/
|
|
302
|
+
listEntities(params: ListEntitiesParams): Promise<ListEntitiesResult>;
|
|
303
|
+
/**
|
|
304
|
+
* plans() - List Plans
|
|
305
|
+
*
|
|
306
|
+
* Returns all active plans for the organization. Useful for building
|
|
307
|
+
* pricing pages and plan selection UIs.
|
|
308
|
+
*
|
|
309
|
+
* @example
|
|
310
|
+
* ```ts
|
|
311
|
+
* const { plans } = await owo.plans();
|
|
312
|
+
* plans.forEach(p => console.log(p.name, p.price));
|
|
313
|
+
*
|
|
314
|
+
* // Filter by group
|
|
315
|
+
* const { plans: support } = await owo.plans({ group: 'support' });
|
|
316
|
+
*
|
|
317
|
+
* // Get a single plan by slug
|
|
318
|
+
* const plan = await owo.plans.get('pro');
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
321
|
+
readonly plans: PlansFn;
|
|
322
|
+
/**
|
|
323
|
+
* Internal POST request handler
|
|
324
|
+
* @internal
|
|
325
|
+
*/
|
|
326
|
+
post(endpoint: string, body: unknown): Promise<unknown>;
|
|
327
|
+
/**
|
|
328
|
+
* Internal GET request handler
|
|
329
|
+
* @internal
|
|
330
|
+
*/
|
|
331
|
+
get(endpoint: string, query?: Record<string, string>): Promise<unknown>;
|
|
332
|
+
}
|
|
333
|
+
type PlansFn = {
|
|
334
|
+
(params?: PlansParams): Promise<PlansResult>;
|
|
335
|
+
get(slug: string): Promise<PublicPlan>;
|
|
336
|
+
};
|
|
337
|
+
type WalletFn = {
|
|
338
|
+
(customer: string): Promise<WalletResult>;
|
|
339
|
+
setup(customer: string, opts?: {
|
|
340
|
+
callbackUrl?: string;
|
|
341
|
+
provider?: string;
|
|
342
|
+
}): Promise<WalletSetupResult>;
|
|
343
|
+
list(customer: string): Promise<WalletResult>;
|
|
344
|
+
remove(customer: string, id: string): Promise<WalletRemoveResult>;
|
|
345
|
+
};
|
|
346
|
+
/**
|
|
347
|
+
* Billing namespace — unbilled usage, invoice generation, invoice history
|
|
348
|
+
*/
|
|
349
|
+
declare class BillingNamespace {
|
|
350
|
+
private client;
|
|
351
|
+
constructor(client: Owostack);
|
|
352
|
+
/**
|
|
353
|
+
* usage() - Get Unbilled Overage Usage
|
|
354
|
+
*
|
|
355
|
+
* Returns a breakdown of all billable usage that hasn't been invoiced yet.
|
|
356
|
+
*
|
|
357
|
+
* @example
|
|
358
|
+
* ```ts
|
|
359
|
+
* const usage = await owo.billing.usage({ customer: 'user_123' });
|
|
360
|
+
* console.log(`Owes: ${usage.currency} ${usage.totalEstimated / 100}`);
|
|
361
|
+
* ```
|
|
362
|
+
*/
|
|
363
|
+
usage(params: BillingUsageParams): Promise<BillingUsageResult>;
|
|
364
|
+
/**
|
|
365
|
+
* invoice() - Generate an Invoice
|
|
366
|
+
*
|
|
367
|
+
* Creates an invoice for the customer's unbilled overage usage.
|
|
368
|
+
* Fails if there's no unbilled usage to invoice.
|
|
369
|
+
*
|
|
370
|
+
* @example
|
|
371
|
+
* ```ts
|
|
372
|
+
* const result = await owo.billing.invoice({ customer: 'user_123' });
|
|
373
|
+
* console.log(`Invoice ${result.invoice.number}: ${result.invoice.total}`);
|
|
374
|
+
* ```
|
|
375
|
+
*/
|
|
376
|
+
invoice(params: InvoiceParams): Promise<InvoiceResult>;
|
|
377
|
+
/**
|
|
378
|
+
* invoices() - List Past Invoices
|
|
379
|
+
*
|
|
380
|
+
* Returns all invoices for a customer.
|
|
381
|
+
*
|
|
382
|
+
* @example
|
|
383
|
+
* ```ts
|
|
384
|
+
* const result = await owo.billing.invoices({ customer: 'user_123' });
|
|
385
|
+
* result.invoices.forEach(inv => console.log(inv.number, inv.status));
|
|
386
|
+
* ```
|
|
387
|
+
*/
|
|
388
|
+
invoices(params: InvoicesParams): Promise<InvoicesResult>;
|
|
389
|
+
/**
|
|
390
|
+
* pay() - Pay an Invoice
|
|
391
|
+
*
|
|
392
|
+
* Attempts to auto-charge the customer's saved payment method.
|
|
393
|
+
* If no card on file or charge fails, returns a checkout URL instead.
|
|
394
|
+
*
|
|
395
|
+
* @example
|
|
396
|
+
* ```ts
|
|
397
|
+
* const result = await owo.billing.pay({ invoiceId: 'inv_xxx' });
|
|
398
|
+
* if (!result.paid) {
|
|
399
|
+
* // Redirect customer to checkout
|
|
400
|
+
* window.location.href = result.checkoutUrl!;
|
|
401
|
+
* }
|
|
402
|
+
* ```
|
|
403
|
+
*/
|
|
404
|
+
pay(params: PayInvoiceParams): Promise<PayInvoiceResult>;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Custom error class for Owostack-specific errors
|
|
408
|
+
*/
|
|
409
|
+
declare class OwostackError extends Error {
|
|
410
|
+
code: string;
|
|
411
|
+
constructor(code: string, message: string);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
export { BooleanHandle, CreditSystemHandle, type MeteredHandle, Owostack, OwostackError, boolean, buildSyncPayload, creditSystem, metered, plan };
|