@openbilling/core 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 +21 -0
- package/dist/index.cjs +60 -0
- package/dist/index.d.cts +201 -0
- package/dist/index.d.ts +201 -0
- package/dist/index.js +31 -0
- package/package.json +36 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 George Dimitrov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
Payment: () => Payment,
|
|
24
|
+
Provider: () => Provider,
|
|
25
|
+
Subscription: () => Subscription,
|
|
26
|
+
Webhook: () => Webhook,
|
|
27
|
+
createBilling: () => createBilling
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(index_exports);
|
|
30
|
+
var Provider = {
|
|
31
|
+
/** Stripe provider adapter name. */
|
|
32
|
+
Stripe: "stripe",
|
|
33
|
+
/** Dodo Payments provider adapter name. */
|
|
34
|
+
Dodo: "dodo"
|
|
35
|
+
};
|
|
36
|
+
var Subscription = {
|
|
37
|
+
/** A subscription became active. */
|
|
38
|
+
Active: "subscription.active",
|
|
39
|
+
/** A subscription was cancelled. */
|
|
40
|
+
Cancelled: "subscription.cancelled"
|
|
41
|
+
};
|
|
42
|
+
var Payment = {
|
|
43
|
+
/** A payment completed successfully. */
|
|
44
|
+
Succeeded: "payment.succeeded"
|
|
45
|
+
};
|
|
46
|
+
var Webhook = {
|
|
47
|
+
/** The provider event is unsupported or cannot be safely normalized yet. */
|
|
48
|
+
Unknown: "unknown"
|
|
49
|
+
};
|
|
50
|
+
function createBilling(provider) {
|
|
51
|
+
return provider;
|
|
52
|
+
}
|
|
53
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
54
|
+
0 && (module.exports = {
|
|
55
|
+
Payment,
|
|
56
|
+
Provider,
|
|
57
|
+
Subscription,
|
|
58
|
+
Webhook,
|
|
59
|
+
createBilling
|
|
60
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in provider names supported by the portable billing surface.
|
|
3
|
+
*
|
|
4
|
+
* Prefer these constants over string literals so refactors stay type-safe.
|
|
5
|
+
*/
|
|
6
|
+
declare const Provider: {
|
|
7
|
+
/** Stripe provider adapter name. */
|
|
8
|
+
readonly Stripe: "stripe";
|
|
9
|
+
/** Dodo Payments provider adapter name. */
|
|
10
|
+
readonly Dodo: "dodo";
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Union of the provider names declared in {@link Provider}.
|
|
14
|
+
*/
|
|
15
|
+
type BillingProviderName = (typeof Provider)[keyof typeof Provider];
|
|
16
|
+
/**
|
|
17
|
+
* Portable checkout intent used across providers.
|
|
18
|
+
*
|
|
19
|
+
* Some providers model this explicitly, while others infer it from the product
|
|
20
|
+
* or price being purchased.
|
|
21
|
+
*/
|
|
22
|
+
type BillingMode = "payment" | "subscription";
|
|
23
|
+
/**
|
|
24
|
+
* Stable normalized subscription event names.
|
|
25
|
+
*/
|
|
26
|
+
declare const Subscription: {
|
|
27
|
+
/** A subscription became active. */
|
|
28
|
+
readonly Active: "subscription.active";
|
|
29
|
+
/** A subscription was cancelled. */
|
|
30
|
+
readonly Cancelled: "subscription.cancelled";
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Stable normalized payment event names.
|
|
34
|
+
*/
|
|
35
|
+
declare const Payment: {
|
|
36
|
+
/** A payment completed successfully. */
|
|
37
|
+
readonly Succeeded: "payment.succeeded";
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Fallback normalized webhook event names.
|
|
41
|
+
*/
|
|
42
|
+
declare const Webhook: {
|
|
43
|
+
/** The provider event is unsupported or cannot be safely normalized yet. */
|
|
44
|
+
readonly Unknown: "unknown";
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Shared input shape for starting a hosted checkout flow.
|
|
48
|
+
*/
|
|
49
|
+
interface CreateCheckoutInput {
|
|
50
|
+
/** Existing provider customer identifier to attach the checkout to. */
|
|
51
|
+
customerId?: string;
|
|
52
|
+
/** Customer email used when the provider needs to create or identify a customer. */
|
|
53
|
+
customerEmail?: string;
|
|
54
|
+
/** Product identifier used by product-based adapters. Dodo currently requires this field. */
|
|
55
|
+
productId?: string;
|
|
56
|
+
/** Price identifier used by price-based adapters. Stripe currently requires this field. */
|
|
57
|
+
priceId?: string;
|
|
58
|
+
/** Where the hosted checkout should redirect after a successful purchase. */
|
|
59
|
+
successUrl: string;
|
|
60
|
+
/** Where the hosted checkout should redirect if the buyer cancels. */
|
|
61
|
+
cancelUrl: string;
|
|
62
|
+
/** Whether the checkout is intended for a one-time payment or a subscription. */
|
|
63
|
+
mode: BillingMode;
|
|
64
|
+
/** Optional metadata forwarded to the billing provider when supported. */
|
|
65
|
+
metadata?: Record<string, string>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Shared result returned after creating a hosted checkout session.
|
|
69
|
+
*/
|
|
70
|
+
interface CheckoutResult {
|
|
71
|
+
/** Provider-specific checkout or session identifier. */
|
|
72
|
+
id: string;
|
|
73
|
+
/** Hosted checkout URL to redirect the user to. */
|
|
74
|
+
url: string;
|
|
75
|
+
/** Provider that created this checkout session. */
|
|
76
|
+
provider: BillingProviderName;
|
|
77
|
+
/** Escape hatch for the raw provider response payload. */
|
|
78
|
+
raw?: unknown;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Shared input shape for creating a billing portal or customer-management link.
|
|
82
|
+
*/
|
|
83
|
+
interface CreatePortalLinkInput {
|
|
84
|
+
/** Provider customer identifier that should gain access to billing management. */
|
|
85
|
+
customerId: string;
|
|
86
|
+
/** Where the portal should send the user when they exit the hosted flow. */
|
|
87
|
+
returnUrl: string;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Shared result returned after creating a hosted billing portal link.
|
|
91
|
+
*/
|
|
92
|
+
interface PortalLinkResult {
|
|
93
|
+
/** Hosted billing management URL. */
|
|
94
|
+
url: string;
|
|
95
|
+
/** Provider that created this portal link. */
|
|
96
|
+
provider: BillingProviderName;
|
|
97
|
+
/** Escape hatch for the raw provider response payload. */
|
|
98
|
+
raw?: unknown;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Shared input shape for verifying provider webhook deliveries.
|
|
102
|
+
*/
|
|
103
|
+
interface VerifyWebhookInput {
|
|
104
|
+
/** Raw request body as received by the application. */
|
|
105
|
+
payload: string | Uint8Array;
|
|
106
|
+
/** Optional direct signature value for providers that verify from a single header. */
|
|
107
|
+
signature?: string;
|
|
108
|
+
/** Optional secret override when the verification secret is chosen per request. */
|
|
109
|
+
secret?: string;
|
|
110
|
+
/** Optional raw headers for providers that require multiple verification headers. */
|
|
111
|
+
headers?: Record<string, string | undefined>;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Provider-agnostic webhook events returned by provider adapters.
|
|
115
|
+
*
|
|
116
|
+
* Unsupported provider payloads should resolve to {@link Webhook.Unknown}
|
|
117
|
+
* instead of throwing purely because the event is outside the current MVP.
|
|
118
|
+
*/
|
|
119
|
+
type NormalizedWebhookEvent = {
|
|
120
|
+
/** Stable subscription activation event name. */
|
|
121
|
+
type: typeof Subscription.Active;
|
|
122
|
+
/** Provider that emitted the event. */
|
|
123
|
+
provider: BillingProviderName;
|
|
124
|
+
/** Provider customer identifier tied to the subscription. */
|
|
125
|
+
customerId: string;
|
|
126
|
+
/** Provider subscription identifier. */
|
|
127
|
+
subscriptionId: string;
|
|
128
|
+
/** Escape hatch for the raw provider payload. */
|
|
129
|
+
raw?: unknown;
|
|
130
|
+
} | {
|
|
131
|
+
/** Stable subscription cancellation event name. */
|
|
132
|
+
type: typeof Subscription.Cancelled;
|
|
133
|
+
/** Provider that emitted the event. */
|
|
134
|
+
provider: BillingProviderName;
|
|
135
|
+
/** Provider customer identifier tied to the subscription. */
|
|
136
|
+
customerId: string;
|
|
137
|
+
/** Provider subscription identifier. */
|
|
138
|
+
subscriptionId: string;
|
|
139
|
+
/** Escape hatch for the raw provider payload. */
|
|
140
|
+
raw?: unknown;
|
|
141
|
+
} | {
|
|
142
|
+
/** Stable payment success event name. */
|
|
143
|
+
type: typeof Payment.Succeeded;
|
|
144
|
+
/** Provider that emitted the event. */
|
|
145
|
+
provider: BillingProviderName;
|
|
146
|
+
/** Provider customer identifier when the provider includes one. */
|
|
147
|
+
customerId?: string;
|
|
148
|
+
/** Provider payment identifier. */
|
|
149
|
+
paymentId: string;
|
|
150
|
+
/** Escape hatch for the raw provider payload. */
|
|
151
|
+
raw?: unknown;
|
|
152
|
+
} | {
|
|
153
|
+
/** Fallback event name for unsupported or partial provider payloads. */
|
|
154
|
+
type: typeof Webhook.Unknown;
|
|
155
|
+
/** Provider that emitted the event. */
|
|
156
|
+
provider: BillingProviderName;
|
|
157
|
+
/** Raw provider payload preserved for custom handling. */
|
|
158
|
+
raw?: unknown;
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Minimal contract implemented by every billing provider adapter.
|
|
162
|
+
*/
|
|
163
|
+
interface BillingProvider {
|
|
164
|
+
/**
|
|
165
|
+
* Starts a hosted checkout flow for a payment or subscription purchase.
|
|
166
|
+
*/
|
|
167
|
+
createCheckout(input: CreateCheckoutInput): Promise<CheckoutResult>;
|
|
168
|
+
/**
|
|
169
|
+
* Creates a hosted billing-management link for an existing customer.
|
|
170
|
+
*/
|
|
171
|
+
createPortalLink(input: CreatePortalLinkInput): Promise<PortalLinkResult>;
|
|
172
|
+
/**
|
|
173
|
+
* Verifies an incoming webhook request and returns a normalized event.
|
|
174
|
+
*/
|
|
175
|
+
verifyWebhook(input: VerifyWebhookInput): Promise<NormalizedWebhookEvent>;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Typed identity helper for provider adapters.
|
|
179
|
+
*
|
|
180
|
+
* This keeps provider-specific members on the returned adapter instead of
|
|
181
|
+
* collapsing everything down to the shared {@link BillingProvider} contract.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```ts
|
|
185
|
+
* const billing = createBilling({
|
|
186
|
+
* providerName: Provider.Dodo,
|
|
187
|
+
* async createCheckout() {
|
|
188
|
+
* // ...
|
|
189
|
+
* },
|
|
190
|
+
* async createPortalLink() {
|
|
191
|
+
* // ...
|
|
192
|
+
* },
|
|
193
|
+
* async verifyWebhook() {
|
|
194
|
+
* // ...
|
|
195
|
+
* }
|
|
196
|
+
* });
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
declare function createBilling<T extends BillingProvider>(provider: T): T;
|
|
200
|
+
|
|
201
|
+
export { type BillingMode, type BillingProvider, type BillingProviderName, type CheckoutResult, type CreateCheckoutInput, type CreatePortalLinkInput, type NormalizedWebhookEvent, Payment, type PortalLinkResult, Provider, Subscription, type VerifyWebhookInput, Webhook, createBilling };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in provider names supported by the portable billing surface.
|
|
3
|
+
*
|
|
4
|
+
* Prefer these constants over string literals so refactors stay type-safe.
|
|
5
|
+
*/
|
|
6
|
+
declare const Provider: {
|
|
7
|
+
/** Stripe provider adapter name. */
|
|
8
|
+
readonly Stripe: "stripe";
|
|
9
|
+
/** Dodo Payments provider adapter name. */
|
|
10
|
+
readonly Dodo: "dodo";
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Union of the provider names declared in {@link Provider}.
|
|
14
|
+
*/
|
|
15
|
+
type BillingProviderName = (typeof Provider)[keyof typeof Provider];
|
|
16
|
+
/**
|
|
17
|
+
* Portable checkout intent used across providers.
|
|
18
|
+
*
|
|
19
|
+
* Some providers model this explicitly, while others infer it from the product
|
|
20
|
+
* or price being purchased.
|
|
21
|
+
*/
|
|
22
|
+
type BillingMode = "payment" | "subscription";
|
|
23
|
+
/**
|
|
24
|
+
* Stable normalized subscription event names.
|
|
25
|
+
*/
|
|
26
|
+
declare const Subscription: {
|
|
27
|
+
/** A subscription became active. */
|
|
28
|
+
readonly Active: "subscription.active";
|
|
29
|
+
/** A subscription was cancelled. */
|
|
30
|
+
readonly Cancelled: "subscription.cancelled";
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Stable normalized payment event names.
|
|
34
|
+
*/
|
|
35
|
+
declare const Payment: {
|
|
36
|
+
/** A payment completed successfully. */
|
|
37
|
+
readonly Succeeded: "payment.succeeded";
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Fallback normalized webhook event names.
|
|
41
|
+
*/
|
|
42
|
+
declare const Webhook: {
|
|
43
|
+
/** The provider event is unsupported or cannot be safely normalized yet. */
|
|
44
|
+
readonly Unknown: "unknown";
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Shared input shape for starting a hosted checkout flow.
|
|
48
|
+
*/
|
|
49
|
+
interface CreateCheckoutInput {
|
|
50
|
+
/** Existing provider customer identifier to attach the checkout to. */
|
|
51
|
+
customerId?: string;
|
|
52
|
+
/** Customer email used when the provider needs to create or identify a customer. */
|
|
53
|
+
customerEmail?: string;
|
|
54
|
+
/** Product identifier used by product-based adapters. Dodo currently requires this field. */
|
|
55
|
+
productId?: string;
|
|
56
|
+
/** Price identifier used by price-based adapters. Stripe currently requires this field. */
|
|
57
|
+
priceId?: string;
|
|
58
|
+
/** Where the hosted checkout should redirect after a successful purchase. */
|
|
59
|
+
successUrl: string;
|
|
60
|
+
/** Where the hosted checkout should redirect if the buyer cancels. */
|
|
61
|
+
cancelUrl: string;
|
|
62
|
+
/** Whether the checkout is intended for a one-time payment or a subscription. */
|
|
63
|
+
mode: BillingMode;
|
|
64
|
+
/** Optional metadata forwarded to the billing provider when supported. */
|
|
65
|
+
metadata?: Record<string, string>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Shared result returned after creating a hosted checkout session.
|
|
69
|
+
*/
|
|
70
|
+
interface CheckoutResult {
|
|
71
|
+
/** Provider-specific checkout or session identifier. */
|
|
72
|
+
id: string;
|
|
73
|
+
/** Hosted checkout URL to redirect the user to. */
|
|
74
|
+
url: string;
|
|
75
|
+
/** Provider that created this checkout session. */
|
|
76
|
+
provider: BillingProviderName;
|
|
77
|
+
/** Escape hatch for the raw provider response payload. */
|
|
78
|
+
raw?: unknown;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Shared input shape for creating a billing portal or customer-management link.
|
|
82
|
+
*/
|
|
83
|
+
interface CreatePortalLinkInput {
|
|
84
|
+
/** Provider customer identifier that should gain access to billing management. */
|
|
85
|
+
customerId: string;
|
|
86
|
+
/** Where the portal should send the user when they exit the hosted flow. */
|
|
87
|
+
returnUrl: string;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Shared result returned after creating a hosted billing portal link.
|
|
91
|
+
*/
|
|
92
|
+
interface PortalLinkResult {
|
|
93
|
+
/** Hosted billing management URL. */
|
|
94
|
+
url: string;
|
|
95
|
+
/** Provider that created this portal link. */
|
|
96
|
+
provider: BillingProviderName;
|
|
97
|
+
/** Escape hatch for the raw provider response payload. */
|
|
98
|
+
raw?: unknown;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Shared input shape for verifying provider webhook deliveries.
|
|
102
|
+
*/
|
|
103
|
+
interface VerifyWebhookInput {
|
|
104
|
+
/** Raw request body as received by the application. */
|
|
105
|
+
payload: string | Uint8Array;
|
|
106
|
+
/** Optional direct signature value for providers that verify from a single header. */
|
|
107
|
+
signature?: string;
|
|
108
|
+
/** Optional secret override when the verification secret is chosen per request. */
|
|
109
|
+
secret?: string;
|
|
110
|
+
/** Optional raw headers for providers that require multiple verification headers. */
|
|
111
|
+
headers?: Record<string, string | undefined>;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Provider-agnostic webhook events returned by provider adapters.
|
|
115
|
+
*
|
|
116
|
+
* Unsupported provider payloads should resolve to {@link Webhook.Unknown}
|
|
117
|
+
* instead of throwing purely because the event is outside the current MVP.
|
|
118
|
+
*/
|
|
119
|
+
type NormalizedWebhookEvent = {
|
|
120
|
+
/** Stable subscription activation event name. */
|
|
121
|
+
type: typeof Subscription.Active;
|
|
122
|
+
/** Provider that emitted the event. */
|
|
123
|
+
provider: BillingProviderName;
|
|
124
|
+
/** Provider customer identifier tied to the subscription. */
|
|
125
|
+
customerId: string;
|
|
126
|
+
/** Provider subscription identifier. */
|
|
127
|
+
subscriptionId: string;
|
|
128
|
+
/** Escape hatch for the raw provider payload. */
|
|
129
|
+
raw?: unknown;
|
|
130
|
+
} | {
|
|
131
|
+
/** Stable subscription cancellation event name. */
|
|
132
|
+
type: typeof Subscription.Cancelled;
|
|
133
|
+
/** Provider that emitted the event. */
|
|
134
|
+
provider: BillingProviderName;
|
|
135
|
+
/** Provider customer identifier tied to the subscription. */
|
|
136
|
+
customerId: string;
|
|
137
|
+
/** Provider subscription identifier. */
|
|
138
|
+
subscriptionId: string;
|
|
139
|
+
/** Escape hatch for the raw provider payload. */
|
|
140
|
+
raw?: unknown;
|
|
141
|
+
} | {
|
|
142
|
+
/** Stable payment success event name. */
|
|
143
|
+
type: typeof Payment.Succeeded;
|
|
144
|
+
/** Provider that emitted the event. */
|
|
145
|
+
provider: BillingProviderName;
|
|
146
|
+
/** Provider customer identifier when the provider includes one. */
|
|
147
|
+
customerId?: string;
|
|
148
|
+
/** Provider payment identifier. */
|
|
149
|
+
paymentId: string;
|
|
150
|
+
/** Escape hatch for the raw provider payload. */
|
|
151
|
+
raw?: unknown;
|
|
152
|
+
} | {
|
|
153
|
+
/** Fallback event name for unsupported or partial provider payloads. */
|
|
154
|
+
type: typeof Webhook.Unknown;
|
|
155
|
+
/** Provider that emitted the event. */
|
|
156
|
+
provider: BillingProviderName;
|
|
157
|
+
/** Raw provider payload preserved for custom handling. */
|
|
158
|
+
raw?: unknown;
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Minimal contract implemented by every billing provider adapter.
|
|
162
|
+
*/
|
|
163
|
+
interface BillingProvider {
|
|
164
|
+
/**
|
|
165
|
+
* Starts a hosted checkout flow for a payment or subscription purchase.
|
|
166
|
+
*/
|
|
167
|
+
createCheckout(input: CreateCheckoutInput): Promise<CheckoutResult>;
|
|
168
|
+
/**
|
|
169
|
+
* Creates a hosted billing-management link for an existing customer.
|
|
170
|
+
*/
|
|
171
|
+
createPortalLink(input: CreatePortalLinkInput): Promise<PortalLinkResult>;
|
|
172
|
+
/**
|
|
173
|
+
* Verifies an incoming webhook request and returns a normalized event.
|
|
174
|
+
*/
|
|
175
|
+
verifyWebhook(input: VerifyWebhookInput): Promise<NormalizedWebhookEvent>;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Typed identity helper for provider adapters.
|
|
179
|
+
*
|
|
180
|
+
* This keeps provider-specific members on the returned adapter instead of
|
|
181
|
+
* collapsing everything down to the shared {@link BillingProvider} contract.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```ts
|
|
185
|
+
* const billing = createBilling({
|
|
186
|
+
* providerName: Provider.Dodo,
|
|
187
|
+
* async createCheckout() {
|
|
188
|
+
* // ...
|
|
189
|
+
* },
|
|
190
|
+
* async createPortalLink() {
|
|
191
|
+
* // ...
|
|
192
|
+
* },
|
|
193
|
+
* async verifyWebhook() {
|
|
194
|
+
* // ...
|
|
195
|
+
* }
|
|
196
|
+
* });
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
declare function createBilling<T extends BillingProvider>(provider: T): T;
|
|
200
|
+
|
|
201
|
+
export { type BillingMode, type BillingProvider, type BillingProviderName, type CheckoutResult, type CreateCheckoutInput, type CreatePortalLinkInput, type NormalizedWebhookEvent, Payment, type PortalLinkResult, Provider, Subscription, type VerifyWebhookInput, Webhook, createBilling };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var Provider = {
|
|
3
|
+
/** Stripe provider adapter name. */
|
|
4
|
+
Stripe: "stripe",
|
|
5
|
+
/** Dodo Payments provider adapter name. */
|
|
6
|
+
Dodo: "dodo"
|
|
7
|
+
};
|
|
8
|
+
var Subscription = {
|
|
9
|
+
/** A subscription became active. */
|
|
10
|
+
Active: "subscription.active",
|
|
11
|
+
/** A subscription was cancelled. */
|
|
12
|
+
Cancelled: "subscription.cancelled"
|
|
13
|
+
};
|
|
14
|
+
var Payment = {
|
|
15
|
+
/** A payment completed successfully. */
|
|
16
|
+
Succeeded: "payment.succeeded"
|
|
17
|
+
};
|
|
18
|
+
var Webhook = {
|
|
19
|
+
/** The provider event is unsupported or cannot be safely normalized yet. */
|
|
20
|
+
Unknown: "unknown"
|
|
21
|
+
};
|
|
22
|
+
function createBilling(provider) {
|
|
23
|
+
return provider;
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
Payment,
|
|
27
|
+
Provider,
|
|
28
|
+
Subscription,
|
|
29
|
+
Webhook,
|
|
30
|
+
createBilling
|
|
31
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openbilling/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"homepage": "https://github.com/gndimitro/openbilling",
|
|
5
|
+
"description": "Switch between Stripe and Dodo Payments without rewriting your billing logic",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"billing",
|
|
9
|
+
"payments",
|
|
10
|
+
"stripe",
|
|
11
|
+
"dodo"
|
|
12
|
+
],
|
|
13
|
+
"type": "module",
|
|
14
|
+
"main": "./dist/index.cjs",
|
|
15
|
+
"module": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.js",
|
|
24
|
+
"require": "./dist/index.cjs"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
32
|
+
"dev": "tsup src/index.ts --format esm,cjs --dts --clean --watch",
|
|
33
|
+
"test": "vitest run",
|
|
34
|
+
"typecheck": "tsc --project tsconfig.json --noEmit"
|
|
35
|
+
}
|
|
36
|
+
}
|