@venturekit/billing 0.0.47 → 0.0.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.ts +8 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +10 -1
- package/dist/client.js.map +1 -1
- package/dist/events.d.ts +46 -2
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/provider.d.ts +45 -1
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +9 -0
- package/dist/provider.js.map +1 -1
- package/dist/providers/index.d.ts +1 -0
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +1 -0
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/stripe/adapter.d.ts +28 -0
- package/dist/providers/stripe/adapter.d.ts.map +1 -0
- package/dist/providers/stripe/adapter.js +192 -0
- package/dist/providers/stripe/adapter.js.map +1 -0
- package/dist/providers/stripe/client.d.ts +26 -0
- package/dist/providers/stripe/client.d.ts.map +1 -0
- package/dist/providers/stripe/client.js +84 -0
- package/dist/providers/stripe/client.js.map +1 -0
- package/dist/providers/stripe/config.d.ts +28 -0
- package/dist/providers/stripe/config.d.ts.map +1 -0
- package/dist/providers/stripe/config.js +33 -0
- package/dist/providers/stripe/config.js.map +1 -0
- package/dist/providers/stripe/index.d.ts +13 -0
- package/dist/providers/stripe/index.d.ts.map +1 -0
- package/dist/providers/stripe/index.js +16 -0
- package/dist/providers/stripe/index.js.map +1 -0
- package/dist/providers/stripe/maps.d.ts +165 -0
- package/dist/providers/stripe/maps.d.ts.map +1 -0
- package/dist/providers/stripe/maps.js +179 -0
- package/dist/providers/stripe/maps.js.map +1 -0
- package/dist/providers/stripe/webhooks.d.ts +34 -0
- package/dist/providers/stripe/webhooks.d.ts.map +1 -0
- package/dist/providers/stripe/webhooks.js +123 -0
- package/dist/providers/stripe/webhooks.js.map +1 -0
- package/dist/types.d.ts +124 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +7 -3
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/billing — Stripe adapter
|
|
3
|
+
*
|
|
4
|
+
* Core flows (Checkout sessions, payment links, webhooks) plus three
|
|
5
|
+
* optional capabilities: customers, saved cards (SetupIntents for "card
|
|
6
|
+
* upfront", PaymentIntents for one-off charges) and provider-run
|
|
7
|
+
* subscriptions (Stripe charges every period, retries failed payments and
|
|
8
|
+
* emails the receipts). Prices are created inline against a product
|
|
9
|
+
* (`price_data`), so there is no Stripe price catalogue to keep in sync
|
|
10
|
+
* with yours.
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { createStripeAdapter } from '@venturekit/billing/providers/stripe';
|
|
14
|
+
* const stripe = createStripeAdapter(); // STRIPE_SECRET_KEY, STRIPE_WEBHOOK_SECRET
|
|
15
|
+
* const intent = await stripe.createSetupIntent({ customerId });
|
|
16
|
+
* // → confirm intent.clientSecret in the browser with Stripe Elements
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
import { MissingConfigError } from '../../errors.js';
|
|
20
|
+
import { createStripeHttpClient } from './client.js';
|
|
21
|
+
import { resolveStripeConfig } from './config.js';
|
|
22
|
+
import { customerParams, mapCheckoutSession, mapCustomer, mapInvoice, mapPaymentIntent, mapPaymentLink, mapPaymentMethod, mapSetupIntent, mapSubscription, metadataOf, priceData, toMinor, unix, fromMinor, } from './maps.js';
|
|
23
|
+
import { handleStripeWebhook } from './webhooks.js';
|
|
24
|
+
export function createStripeAdapter(overrides = {}) {
|
|
25
|
+
const config = resolveStripeConfig(overrides);
|
|
26
|
+
const http = createStripeHttpClient(config);
|
|
27
|
+
const sub = async (path, body) => mapSubscription(await http.post(path, body));
|
|
28
|
+
const getSubscription = async (id) => mapSubscription(await http.get(`/subscriptions/${encodeURIComponent(id)}`));
|
|
29
|
+
return {
|
|
30
|
+
name: 'stripe',
|
|
31
|
+
publishableKey: config.publishableKey ?? null,
|
|
32
|
+
correlationSupport(flow) {
|
|
33
|
+
return flow === 'transfer' ? { reference: false, metadata: false, channel: 'none' } : { reference: true, metadata: true, channel: 'metadata' };
|
|
34
|
+
},
|
|
35
|
+
// ─── Checkout sessions (one-off payments on Stripe's hosted page) ──
|
|
36
|
+
async createCheckoutSession(input) {
|
|
37
|
+
const raw = await http.post('/checkout/sessions', {
|
|
38
|
+
mode: 'payment',
|
|
39
|
+
success_url: input.successUrl,
|
|
40
|
+
cancel_url: input.cancelUrl,
|
|
41
|
+
customer_email: input.customerEmail,
|
|
42
|
+
client_reference_id: input.correlation?.reference,
|
|
43
|
+
metadata: metadataOf(input.correlation),
|
|
44
|
+
payment_intent_data: { metadata: metadataOf(input.correlation), description: input.description },
|
|
45
|
+
line_items: [{ quantity: 1, price_data: { currency: input.amount.currency.toLowerCase(), unit_amount: toMinor(input.amount), product_data: { name: input.description ?? 'Payment' } } }],
|
|
46
|
+
...(input.expiresAt ? { expires_at: unix(input.expiresAt) } : {}),
|
|
47
|
+
});
|
|
48
|
+
return mapCheckoutSession(raw);
|
|
49
|
+
},
|
|
50
|
+
async getCheckoutSession(id) {
|
|
51
|
+
return mapCheckoutSession(await http.get(`/checkout/sessions/${encodeURIComponent(id)}`));
|
|
52
|
+
},
|
|
53
|
+
// ─── Payment links (reusable; a price created inline) ────────────
|
|
54
|
+
async createPaymentLink(input) {
|
|
55
|
+
const price = await http.post('/prices', { currency: input.amount.currency.toLowerCase(), unit_amount: toMinor(input.amount), product_data: { name: input.description ?? 'Payment' } });
|
|
56
|
+
const raw = await http.post('/payment_links', {
|
|
57
|
+
line_items: [{ price: price.id, quantity: 1 }],
|
|
58
|
+
metadata: metadataOf(input.correlation),
|
|
59
|
+
payment_intent_data: { metadata: metadataOf(input.correlation) },
|
|
60
|
+
...(input.redirectUrl ? { after_completion: { type: 'redirect', redirect: { url: input.redirectUrl } } } : {}),
|
|
61
|
+
});
|
|
62
|
+
return mapPaymentLink(raw, input.amount);
|
|
63
|
+
},
|
|
64
|
+
async getPaymentLink(id) {
|
|
65
|
+
const [raw, items] = await Promise.all([
|
|
66
|
+
http.get(`/payment_links/${encodeURIComponent(id)}`),
|
|
67
|
+
http.get(`/payment_links/${encodeURIComponent(id)}/line_items`),
|
|
68
|
+
]);
|
|
69
|
+
const first = items.data[0];
|
|
70
|
+
return mapPaymentLink(raw, first ? fromMinor(first.amount_total, first.currency) : { amount: '0.00', currency: 'USD' });
|
|
71
|
+
},
|
|
72
|
+
async listPaymentLinks(params) {
|
|
73
|
+
const page = await http.get('/payment_links', { limit: params?.limit ?? 20, starting_after: params?.cursor });
|
|
74
|
+
return { data: page.data.map((l) => mapPaymentLink(l, { amount: '0.00', currency: 'USD' })), hasMore: page.has_more, ...(page.has_more && page.data.length ? { nextCursor: page.data.at(-1).id } : {}) };
|
|
75
|
+
},
|
|
76
|
+
async cancelPaymentLink(id) {
|
|
77
|
+
const raw = await http.post(`/payment_links/${encodeURIComponent(id)}`, { active: false });
|
|
78
|
+
return mapPaymentLink(raw, { amount: '0.00', currency: 'USD' });
|
|
79
|
+
},
|
|
80
|
+
// ─── Webhooks ────────────────────────────────────────────────────
|
|
81
|
+
async handleWebhookEvent(request) {
|
|
82
|
+
if (!config.webhookSecret)
|
|
83
|
+
throw new MissingConfigError('STRIPE_WEBHOOK_SECRET', 'Set the webhook endpoint’s signing secret (whsec_…).');
|
|
84
|
+
return handleStripeWebhook(request, { secret: config.webhookSecret, toleranceSeconds: config.webhookToleranceSeconds });
|
|
85
|
+
},
|
|
86
|
+
// ─── Customers ───────────────────────────────────────────────────
|
|
87
|
+
async createCustomer(input) {
|
|
88
|
+
return mapCustomer(await http.post('/customers', customerParams(input)));
|
|
89
|
+
},
|
|
90
|
+
async getCustomer(id) {
|
|
91
|
+
return mapCustomer(await http.get(`/customers/${encodeURIComponent(id)}`));
|
|
92
|
+
},
|
|
93
|
+
async updateCustomer(id, input) {
|
|
94
|
+
return mapCustomer(await http.post(`/customers/${encodeURIComponent(id)}`, customerParams(input)));
|
|
95
|
+
},
|
|
96
|
+
// ─── Saved cards & one-off charges ───────────────────────────────
|
|
97
|
+
async createSetupIntent(input) {
|
|
98
|
+
return mapSetupIntent(await http.post('/setup_intents', { customer: input.customerId, usage: 'off_session', payment_method_types: ['card'], metadata: input.metadata }, input.idempotencyKey ? { idempotencyKey: input.idempotencyKey } : {}));
|
|
99
|
+
},
|
|
100
|
+
async getSetupIntent(id) {
|
|
101
|
+
return mapSetupIntent(await http.get(`/setup_intents/${encodeURIComponent(id)}`));
|
|
102
|
+
},
|
|
103
|
+
async createPaymentIntent(input) {
|
|
104
|
+
return mapPaymentIntent(await http.post('/payment_intents', {
|
|
105
|
+
amount: toMinor(input.amount),
|
|
106
|
+
currency: input.amount.currency.toLowerCase(),
|
|
107
|
+
customer: input.customerId,
|
|
108
|
+
payment_method: input.paymentMethodId,
|
|
109
|
+
confirm: input.confirm,
|
|
110
|
+
off_session: input.confirm ? input.offSession : undefined,
|
|
111
|
+
description: input.description,
|
|
112
|
+
receipt_email: input.receiptEmail,
|
|
113
|
+
metadata: metadataOf(input.correlation),
|
|
114
|
+
// Card only: no redirect-based methods to come back from.
|
|
115
|
+
...(input.paymentMethodId || input.confirm ? { payment_method_types: ['card'] } : { automatic_payment_methods: { enabled: true, allow_redirects: 'never' } }),
|
|
116
|
+
}, input.idempotencyKey ? { idempotencyKey: input.idempotencyKey } : {}));
|
|
117
|
+
},
|
|
118
|
+
async getPaymentIntent(id) {
|
|
119
|
+
return mapPaymentIntent(await http.get(`/payment_intents/${encodeURIComponent(id)}`));
|
|
120
|
+
},
|
|
121
|
+
async getPaymentMethod(id) {
|
|
122
|
+
return mapPaymentMethod(await http.get(`/payment_methods/${encodeURIComponent(id)}`));
|
|
123
|
+
},
|
|
124
|
+
async setDefaultPaymentMethod(customerId, paymentMethodId) {
|
|
125
|
+
await http.post(`/customers/${encodeURIComponent(customerId)}`, { invoice_settings: { default_payment_method: paymentMethodId } });
|
|
126
|
+
},
|
|
127
|
+
// ─── Subscriptions ───────────────────────────────────────────────
|
|
128
|
+
async ensureProduct({ id, name }) {
|
|
129
|
+
try {
|
|
130
|
+
return await http.get(`/products/${encodeURIComponent(id)}`);
|
|
131
|
+
}
|
|
132
|
+
catch (e) {
|
|
133
|
+
if (e.status !== 404)
|
|
134
|
+
throw e;
|
|
135
|
+
return http.post('/products', { id, name }, { idempotencyKey: `vk-product-${id}` });
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
async createSubscription(input) {
|
|
139
|
+
return mapSubscription(await http.post('/subscriptions', {
|
|
140
|
+
customer: input.customerId,
|
|
141
|
+
items: [{ price_data: priceData(input.price) }],
|
|
142
|
+
...(input.trialEnd ? { trial_end: unix(input.trialEnd) } : input.trialDays ? { trial_period_days: input.trialDays } : {}),
|
|
143
|
+
default_payment_method: input.defaultPaymentMethodId,
|
|
144
|
+
collection_method: input.collectionMethod,
|
|
145
|
+
days_until_due: input.collectionMethod === 'send_invoice' ? (input.daysUntilDue ?? 30) : undefined,
|
|
146
|
+
metadata: metadataOf(input.correlation),
|
|
147
|
+
// No card yet (a sales-led invoice account): don't fail on the first charge.
|
|
148
|
+
payment_behavior: input.defaultPaymentMethodId || input.collectionMethod === 'send_invoice' ? undefined : 'default_incomplete',
|
|
149
|
+
...(input.trialDays || input.trialEnd ? { trial_settings: { end_behavior: { missing_payment_method: 'pause' } } } : {}),
|
|
150
|
+
}, input.idempotencyKey ? { idempotencyKey: input.idempotencyKey } : {}));
|
|
151
|
+
},
|
|
152
|
+
getSubscription,
|
|
153
|
+
async updateSubscription(id, input) {
|
|
154
|
+
let itemId;
|
|
155
|
+
if (input.price)
|
|
156
|
+
itemId = (await getSubscription(id)).itemId;
|
|
157
|
+
return sub(`/subscriptions/${encodeURIComponent(id)}`, {
|
|
158
|
+
...(input.price ? { items: [{ ...(itemId ? { id: itemId } : {}), price_data: priceData(input.price) }], proration_behavior: input.prorate === false ? 'none' : 'create_prorations' } : {}),
|
|
159
|
+
cancel_at_period_end: input.cancelAtPeriodEnd,
|
|
160
|
+
default_payment_method: input.defaultPaymentMethodId,
|
|
161
|
+
trial_end: input.trialEnd === 'now' ? 'now' : input.trialEnd ? unix(input.trialEnd) : undefined,
|
|
162
|
+
metadata: metadataOf(input.correlation),
|
|
163
|
+
});
|
|
164
|
+
},
|
|
165
|
+
async cancelSubscription(id, options) {
|
|
166
|
+
if (options?.atPeriodEnd)
|
|
167
|
+
return sub(`/subscriptions/${encodeURIComponent(id)}`, { cancel_at_period_end: true });
|
|
168
|
+
return mapSubscription(await http.delete(`/subscriptions/${encodeURIComponent(id)}`));
|
|
169
|
+
},
|
|
170
|
+
async createSubscriptionCheckout(input) {
|
|
171
|
+
const raw = await http.post('/checkout/sessions', {
|
|
172
|
+
mode: 'subscription',
|
|
173
|
+
success_url: input.successUrl,
|
|
174
|
+
cancel_url: input.cancelUrl,
|
|
175
|
+
customer: input.customerId,
|
|
176
|
+
customer_email: input.customerId ? undefined : input.customerEmail,
|
|
177
|
+
client_reference_id: input.correlation?.reference,
|
|
178
|
+
metadata: metadataOf(input.correlation),
|
|
179
|
+
line_items: [{ quantity: 1, price_data: priceData(input.price) }],
|
|
180
|
+
subscription_data: { metadata: metadataOf(input.correlation), ...(input.trialDays ? { trial_period_days: input.trialDays } : {}) },
|
|
181
|
+
});
|
|
182
|
+
return { id: raw.id, url: raw.url };
|
|
183
|
+
},
|
|
184
|
+
async listSubscriptionInvoices({ customerId, limit }) {
|
|
185
|
+
const page = await http.get('/invoices', { customer: customerId, limit: limit ?? 12 });
|
|
186
|
+
return page.data.map(mapInvoice);
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/** The money a Stripe minor-unit amount stands for (exported for apps reading raw events). */
|
|
191
|
+
export const stripeAmount = (minor, currency) => fromMinor(minor, currency);
|
|
192
|
+
//# sourceMappingURL=adapter.js.map
|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K,EAAE,QAAQ,CAAC,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/billing — Stripe HTTP client
|
|
3
|
+
*
|
|
4
|
+
* Stripe takes `application/x-www-form-urlencoded` bodies with bracketed
|
|
5
|
+
* keys (`items[0][price_data][currency]=usd`) and answers JSON. Writes
|
|
6
|
+
* carry an `Idempotency-Key` (derived from the body when the caller gives
|
|
7
|
+
* none) so a retried request never charges twice; reads retry on
|
|
8
|
+
* network errors and 5xx / 429.
|
|
9
|
+
*/
|
|
10
|
+
import type { StripeConfig } from './config.js';
|
|
11
|
+
type Primitive = string | number | boolean;
|
|
12
|
+
export type FormValue = Primitive | null | undefined | FormValue[] | {
|
|
13
|
+
[key: string]: FormValue;
|
|
14
|
+
};
|
|
15
|
+
/** Stripe's form encoding: nested objects and arrays become bracketed keys; null/undefined are left out. */
|
|
16
|
+
export declare function encodeForm(params: Record<string, FormValue>): string;
|
|
17
|
+
export interface StripeHttpClient {
|
|
18
|
+
get<T>(path: string, query?: Record<string, FormValue>): Promise<T>;
|
|
19
|
+
post<T>(path: string, body?: Record<string, FormValue>, options?: {
|
|
20
|
+
idempotencyKey?: string;
|
|
21
|
+
}): Promise<T>;
|
|
22
|
+
delete<T>(path: string): Promise<T>;
|
|
23
|
+
}
|
|
24
|
+
export declare function createStripeHttpClient(config: StripeConfig): StripeHttpClient;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/providers/stripe/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAC3C,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,IAAI,GAAG,SAAS,GAAG,SAAS,EAAE,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAElG,4GAA4G;AAC5G,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,MAAM,CAUpE;AAED,MAAM,WAAW,gBAAgB;IAC/B,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACpE,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,OAAO,CAAC,EAAE;QAAE,cAAc,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC3G,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACrC;AAMD,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,YAAY,GAAG,gBAAgB,CAkD7E"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/billing — Stripe HTTP client
|
|
3
|
+
*
|
|
4
|
+
* Stripe takes `application/x-www-form-urlencoded` bodies with bracketed
|
|
5
|
+
* keys (`items[0][price_data][currency]=usd`) and answers JSON. Writes
|
|
6
|
+
* carry an `Idempotency-Key` (derived from the body when the caller gives
|
|
7
|
+
* none) so a retried request never charges twice; reads retry on
|
|
8
|
+
* network errors and 5xx / 429.
|
|
9
|
+
*/
|
|
10
|
+
import { createHash } from 'node:crypto';
|
|
11
|
+
import { ProviderError } from '../../errors.js';
|
|
12
|
+
/** Stripe's form encoding: nested objects and arrays become bracketed keys; null/undefined are left out. */
|
|
13
|
+
export function encodeForm(params) {
|
|
14
|
+
const out = [];
|
|
15
|
+
const walk = (key, value) => {
|
|
16
|
+
if (value === null || value === undefined)
|
|
17
|
+
return;
|
|
18
|
+
if (Array.isArray(value))
|
|
19
|
+
value.forEach((v, i) => walk(`${key}[${i}]`, v));
|
|
20
|
+
else if (typeof value === 'object')
|
|
21
|
+
for (const [k, v] of Object.entries(value))
|
|
22
|
+
walk(`${key}[${k}]`, v);
|
|
23
|
+
else
|
|
24
|
+
out.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
|
|
25
|
+
};
|
|
26
|
+
for (const [k, v] of Object.entries(params))
|
|
27
|
+
walk(k, v);
|
|
28
|
+
return out.join('&');
|
|
29
|
+
}
|
|
30
|
+
export function createStripeHttpClient(config) {
|
|
31
|
+
const doFetch = config.fetch ?? fetch;
|
|
32
|
+
async function call(method, path, form, idempotencyKey, attempt = 0) {
|
|
33
|
+
const url = `${config.baseUrl}/v1${path}${method === 'GET' && form ? `?${form}` : ''}`;
|
|
34
|
+
const headers = { Authorization: `Bearer ${config.secretKey}` };
|
|
35
|
+
if (config.apiVersion)
|
|
36
|
+
headers['Stripe-Version'] = config.apiVersion;
|
|
37
|
+
if (method === 'POST') {
|
|
38
|
+
headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
39
|
+
headers['Idempotency-Key'] = idempotencyKey ?? `vk-${createHash('sha256').update(`${path}\n${form ?? ''}`).digest('hex').slice(0, 40)}`;
|
|
40
|
+
}
|
|
41
|
+
const controller = new AbortController();
|
|
42
|
+
const timer = setTimeout(() => controller.abort(), config.timeoutMs);
|
|
43
|
+
let res;
|
|
44
|
+
try {
|
|
45
|
+
res = await doFetch(url, { method, headers, ...(method === 'POST' ? { body: form ?? '' } : {}), signal: controller.signal });
|
|
46
|
+
}
|
|
47
|
+
catch (cause) {
|
|
48
|
+
clearTimeout(timer);
|
|
49
|
+
// A write may have reached Stripe; the idempotency key makes the retry safe.
|
|
50
|
+
if (attempt < 2)
|
|
51
|
+
return call(method, path, form, headers['Idempotency-Key'], attempt + 1);
|
|
52
|
+
throw new ProviderError({ message: `Stripe is unreachable: ${cause instanceof Error ? cause.message : String(cause)}`, status: 0, transient: true, cause });
|
|
53
|
+
}
|
|
54
|
+
clearTimeout(timer);
|
|
55
|
+
const text = await res.text();
|
|
56
|
+
let body;
|
|
57
|
+
try {
|
|
58
|
+
body = text ? JSON.parse(text) : null;
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
body = text;
|
|
62
|
+
}
|
|
63
|
+
if (res.ok)
|
|
64
|
+
return body;
|
|
65
|
+
const transient = res.status === 429 || res.status >= 500;
|
|
66
|
+
if (transient && attempt < 2) {
|
|
67
|
+
await new Promise((r) => setTimeout(r, 250 * 2 ** attempt));
|
|
68
|
+
return call(method, path, form, headers['Idempotency-Key'], attempt + 1);
|
|
69
|
+
}
|
|
70
|
+
const err = body?.error;
|
|
71
|
+
throw new ProviderError({
|
|
72
|
+
message: `Stripe ${res.status}: ${err?.message ?? res.statusText}${err?.code ? ` (${err.code})` : ''}`,
|
|
73
|
+
status: res.status,
|
|
74
|
+
transient,
|
|
75
|
+
providerData: body,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
get: (path, query) => call('GET', path, query ? encodeForm(query) : null),
|
|
80
|
+
post: (path, body, options) => call('POST', path, body ? encodeForm(body) : '', options?.idempotencyKey),
|
|
81
|
+
delete: (path) => call('DELETE', path, null),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/providers/stripe/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAMhD,4GAA4G;AAC5G,MAAM,UAAU,UAAU,CAAC,MAAiC;IAC1D,MAAM,GAAG,GAAa,EAAE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,EAAE,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YACtG,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,SAAS;YACT,YAAY,EAAE,IAAI;SACnB,CAAC,CAAC;IACL,CAAC;IAED,OAAO;QACL,GAAG,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACzE,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,OAAO,EAAE,cAAc,CAAC;QACxG,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC;KAC7C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/billing — Stripe configuration
|
|
3
|
+
*
|
|
4
|
+
* Every value resolves from an explicit argument first, then the
|
|
5
|
+
* environment, so secrets never live in source:
|
|
6
|
+
*
|
|
7
|
+
* | Variable | Purpose |
|
|
8
|
+
* | --- | --- |
|
|
9
|
+
* | `STRIPE_SECRET_KEY` | API key (`sk_live_…` / `sk_test_…`, or a restricted `rk_…`). Required. |
|
|
10
|
+
* | `STRIPE_WEBHOOK_SECRET` | The webhook endpoint's signing secret (`whsec_…`). Required to accept webhooks. |
|
|
11
|
+
* | `STRIPE_PUBLISHABLE_KEY` | `pk_…`, handed to the browser for card fields. Optional here. |
|
|
12
|
+
* | `STRIPE_API_VERSION` | Pin an API version; the account's default otherwise. |
|
|
13
|
+
* | `STRIPE_WEBHOOK_TOLERANCE_SECONDS` | Replay window for signatures, default 300. |
|
|
14
|
+
*/
|
|
15
|
+
export interface StripeConfig {
|
|
16
|
+
secretKey: string;
|
|
17
|
+
webhookSecret?: string;
|
|
18
|
+
publishableKey?: string;
|
|
19
|
+
apiVersion?: string;
|
|
20
|
+
/** Default `https://api.stripe.com`; override for stripe-mock in tests. */
|
|
21
|
+
baseUrl: string;
|
|
22
|
+
timeoutMs: number;
|
|
23
|
+
webhookToleranceSeconds: number;
|
|
24
|
+
/** Injectable fetch (tests). */
|
|
25
|
+
fetch?: typeof fetch;
|
|
26
|
+
}
|
|
27
|
+
export declare function resolveStripeConfig(overrides?: Partial<StripeConfig>): StripeConfig;
|
|
28
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/providers/stripe/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,2EAA2E;IAC3E,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,uBAAuB,EAAE,MAAM,CAAC;IAChC,gCAAgC;IAChC,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB;AAED,wBAAgB,mBAAmB,CAAC,SAAS,GAAE,OAAO,CAAC,YAAY,CAAM,GAAG,YAAY,CAevF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/billing — Stripe configuration
|
|
3
|
+
*
|
|
4
|
+
* Every value resolves from an explicit argument first, then the
|
|
5
|
+
* environment, so secrets never live in source:
|
|
6
|
+
*
|
|
7
|
+
* | Variable | Purpose |
|
|
8
|
+
* | --- | --- |
|
|
9
|
+
* | `STRIPE_SECRET_KEY` | API key (`sk_live_…` / `sk_test_…`, or a restricted `rk_…`). Required. |
|
|
10
|
+
* | `STRIPE_WEBHOOK_SECRET` | The webhook endpoint's signing secret (`whsec_…`). Required to accept webhooks. |
|
|
11
|
+
* | `STRIPE_PUBLISHABLE_KEY` | `pk_…`, handed to the browser for card fields. Optional here. |
|
|
12
|
+
* | `STRIPE_API_VERSION` | Pin an API version; the account's default otherwise. |
|
|
13
|
+
* | `STRIPE_WEBHOOK_TOLERANCE_SECONDS` | Replay window for signatures, default 300. |
|
|
14
|
+
*/
|
|
15
|
+
import { MissingConfigError } from '../../errors.js';
|
|
16
|
+
export function resolveStripeConfig(overrides = {}) {
|
|
17
|
+
const env = typeof process !== 'undefined' ? process.env : {};
|
|
18
|
+
const secretKey = overrides.secretKey ?? env.STRIPE_SECRET_KEY;
|
|
19
|
+
if (!secretKey)
|
|
20
|
+
throw new MissingConfigError('STRIPE_SECRET_KEY');
|
|
21
|
+
const tolerance = overrides.webhookToleranceSeconds ?? (env.STRIPE_WEBHOOK_TOLERANCE_SECONDS ? Number(env.STRIPE_WEBHOOK_TOLERANCE_SECONDS) : 300);
|
|
22
|
+
return {
|
|
23
|
+
secretKey,
|
|
24
|
+
webhookSecret: overrides.webhookSecret ?? env.STRIPE_WEBHOOK_SECRET,
|
|
25
|
+
publishableKey: overrides.publishableKey ?? env.STRIPE_PUBLISHABLE_KEY,
|
|
26
|
+
apiVersion: overrides.apiVersion ?? env.STRIPE_API_VERSION,
|
|
27
|
+
baseUrl: (overrides.baseUrl ?? env.STRIPE_BASE_URL ?? 'https://api.stripe.com').replace(/\/+$/, ''),
|
|
28
|
+
timeoutMs: overrides.timeoutMs ?? 20_000,
|
|
29
|
+
webhookToleranceSeconds: Number.isFinite(tolerance) ? tolerance : 300,
|
|
30
|
+
...(overrides.fetch ? { fetch: overrides.fetch } : {}),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
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CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACvD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/billing — Stripe provider barrel
|
|
3
|
+
*
|
|
4
|
+
* Importing this module self-registers the provider under `'stripe'`, so
|
|
5
|
+
* `createProvider('stripe')` and `createBillingClientFromEnv({ provider:
|
|
6
|
+
* 'stripe' })` find it.
|
|
7
|
+
*/
|
|
8
|
+
export { createStripeAdapter, stripeAmount, type StripeAdapter } from './adapter.js';
|
|
9
|
+
export { createStripeHttpClient, encodeForm, type StripeHttpClient, type FormValue } from './client.js';
|
|
10
|
+
export { resolveStripeConfig, type StripeConfig } from './config.js';
|
|
11
|
+
export { verifyStripeSignature, parseStripeEvent, handleStripeWebhook, STRIPE_SIGNATURE_HEADER, type HandleStripeWebhookOptions } from './webhooks.js';
|
|
12
|
+
export { toMinor, fromMinor } from './maps.js';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/stripe/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAQH,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AACrF,OAAO,EAAE,sBAAsB,EAAE,UAAU,EAAE,KAAK,gBAAgB,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AACxG,OAAO,EAAE,mBAAmB,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,KAAK,0BAA0B,EAAE,MAAM,eAAe,CAAC;AACvJ,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/billing — Stripe provider barrel
|
|
3
|
+
*
|
|
4
|
+
* Importing this module self-registers the provider under `'stripe'`, so
|
|
5
|
+
* `createProvider('stripe')` and `createBillingClientFromEnv({ provider:
|
|
6
|
+
* 'stripe' })` find it.
|
|
7
|
+
*/
|
|
8
|
+
import { registerProvider } from '../../provider.js';
|
|
9
|
+
import { createStripeAdapter } from './adapter.js';
|
|
10
|
+
registerProvider('stripe', (cfg) => createStripeAdapter(cfg));
|
|
11
|
+
export { createStripeAdapter, stripeAmount } from './adapter.js';
|
|
12
|
+
export { createStripeHttpClient, encodeForm } from './client.js';
|
|
13
|
+
export { resolveStripeConfig } from './config.js';
|
|
14
|
+
export { verifyStripeSignature, parseStripeEvent, handleStripeWebhook, STRIPE_SIGNATURE_HEADER } from './webhooks.js';
|
|
15
|
+
export { toMinor, fromMinor } from './maps.js';
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/providers/stripe/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAGnD,gBAAgB,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,mBAAmB,CAAC,GAAwC,CAAC,CAAC,CAAC;AAEnG,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAsB,MAAM,cAAc,CAAC;AACrF,OAAO,EAAE,sBAAsB,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAC;AACxG,OAAO,EAAE,mBAAmB,EAAqB,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,uBAAuB,EAAmC,MAAM,eAAe,CAAC;AACvJ,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/billing — Stripe ⇄ domain mapping
|
|
3
|
+
*
|
|
4
|
+
* Stripe amounts are integers in the currency's minor unit; the domain's
|
|
5
|
+
* `Money.amount` is a decimal string. Correlation rides on each object's
|
|
6
|
+
* `metadata` (`reference` plus the caller's keys) and, for Checkout,
|
|
7
|
+
* `client_reference_id`.
|
|
8
|
+
*
|
|
9
|
+
* Field moves across API versions are read both ways: the subscription's
|
|
10
|
+
* current period sits on the subscription (older versions) or on its item
|
|
11
|
+
* (2025-03-31 and later); an invoice's subscription is `invoice.subscription`
|
|
12
|
+
* or `invoice.parent.subscription_details.subscription`.
|
|
13
|
+
*/
|
|
14
|
+
import type { CheckoutSession, CorrelationRef, Customer, CreateCustomerInput, IntentStatus, Money, PaymentIntent, PaymentLink, PaymentMethodSummary, ProviderSubscription, SetupIntent, SubscriptionInvoice, SubscriptionPrice, UpdateCustomerInput } from '../../types.js';
|
|
15
|
+
import type { FormValue } from './client.js';
|
|
16
|
+
/** `{ amount: '299.00', currency: 'USD' }` → 29900. */
|
|
17
|
+
export declare function toMinor(money: Money): number;
|
|
18
|
+
export declare function fromMinor(minor: number, currency: string): Money;
|
|
19
|
+
export declare const iso: (unix: number | null | undefined) => string | undefined;
|
|
20
|
+
export declare const unix: (isoDate: string) => number;
|
|
21
|
+
/** Correlation → Stripe metadata (reference included). */
|
|
22
|
+
export declare function metadataOf(correlation?: CorrelationRef): Record<string, string> | undefined;
|
|
23
|
+
export declare function correlationOf(metadata: Record<string, string> | null | undefined, clientReferenceId: string | null | undefined): CorrelationRef | null;
|
|
24
|
+
export declare function priceData(price: SubscriptionPrice): Record<string, FormValue>;
|
|
25
|
+
export interface RawStripeCustomer {
|
|
26
|
+
id: string;
|
|
27
|
+
email: string | null;
|
|
28
|
+
name: string | null;
|
|
29
|
+
phone: string | null;
|
|
30
|
+
address: {
|
|
31
|
+
line1: string | null;
|
|
32
|
+
city: string | null;
|
|
33
|
+
postal_code: string | null;
|
|
34
|
+
country: string | null;
|
|
35
|
+
} | null;
|
|
36
|
+
metadata: Record<string, string>;
|
|
37
|
+
created: number;
|
|
38
|
+
}
|
|
39
|
+
export interface RawStripeSubscription {
|
|
40
|
+
id: string;
|
|
41
|
+
customer: string | {
|
|
42
|
+
id: string;
|
|
43
|
+
};
|
|
44
|
+
status: ProviderSubscription['status'];
|
|
45
|
+
current_period_start?: number;
|
|
46
|
+
current_period_end?: number;
|
|
47
|
+
trial_end: number | null;
|
|
48
|
+
cancel_at_period_end: boolean;
|
|
49
|
+
canceled_at: number | null;
|
|
50
|
+
latest_invoice: string | {
|
|
51
|
+
id: string;
|
|
52
|
+
} | null;
|
|
53
|
+
default_payment_method: string | {
|
|
54
|
+
id: string;
|
|
55
|
+
} | null;
|
|
56
|
+
metadata: Record<string, string>;
|
|
57
|
+
items?: {
|
|
58
|
+
data: Array<{
|
|
59
|
+
id: string;
|
|
60
|
+
current_period_start?: number;
|
|
61
|
+
current_period_end?: number;
|
|
62
|
+
}>;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export interface RawStripeInvoice {
|
|
66
|
+
id: string;
|
|
67
|
+
number: string | null;
|
|
68
|
+
status: SubscriptionInvoice['status'] | null;
|
|
69
|
+
currency: string;
|
|
70
|
+
amount_due: number;
|
|
71
|
+
amount_paid: number;
|
|
72
|
+
created: number;
|
|
73
|
+
customer: string | {
|
|
74
|
+
id: string;
|
|
75
|
+
} | null;
|
|
76
|
+
subscription?: string | {
|
|
77
|
+
id: string;
|
|
78
|
+
} | null;
|
|
79
|
+
subscription_details?: {
|
|
80
|
+
metadata?: Record<string, string>;
|
|
81
|
+
} | null;
|
|
82
|
+
parent?: {
|
|
83
|
+
subscription_details?: {
|
|
84
|
+
subscription?: string | {
|
|
85
|
+
id: string;
|
|
86
|
+
};
|
|
87
|
+
metadata?: Record<string, string>;
|
|
88
|
+
} | null;
|
|
89
|
+
} | null;
|
|
90
|
+
status_transitions?: {
|
|
91
|
+
paid_at: number | null;
|
|
92
|
+
} | null;
|
|
93
|
+
invoice_pdf: string | null;
|
|
94
|
+
hosted_invoice_url: string | null;
|
|
95
|
+
attempt_count?: number;
|
|
96
|
+
next_payment_attempt?: number | null;
|
|
97
|
+
lines?: {
|
|
98
|
+
data: Array<{
|
|
99
|
+
description: string | null;
|
|
100
|
+
}>;
|
|
101
|
+
};
|
|
102
|
+
metadata?: Record<string, string> | null;
|
|
103
|
+
}
|
|
104
|
+
export declare function mapCustomer(raw: RawStripeCustomer): Customer;
|
|
105
|
+
/** Customer fields → Stripe's customer params; tax ids ride on metadata (Stripe's tax-id objects need a type per country). */
|
|
106
|
+
export declare function customerParams(input: CreateCustomerInput | UpdateCustomerInput): Record<string, FormValue>;
|
|
107
|
+
export declare function mapSetupIntent(raw: {
|
|
108
|
+
id: string;
|
|
109
|
+
status: IntentStatus;
|
|
110
|
+
client_secret: string;
|
|
111
|
+
customer: string | {
|
|
112
|
+
id: string;
|
|
113
|
+
} | null;
|
|
114
|
+
payment_method: string | {
|
|
115
|
+
id: string;
|
|
116
|
+
} | null;
|
|
117
|
+
metadata: Record<string, string>;
|
|
118
|
+
}): SetupIntent;
|
|
119
|
+
export declare function mapPaymentIntent(raw: {
|
|
120
|
+
id: string;
|
|
121
|
+
status: IntentStatus;
|
|
122
|
+
client_secret: string;
|
|
123
|
+
amount: number;
|
|
124
|
+
currency: string;
|
|
125
|
+
customer: string | {
|
|
126
|
+
id: string;
|
|
127
|
+
} | null;
|
|
128
|
+
payment_method: string | {
|
|
129
|
+
id: string;
|
|
130
|
+
} | null;
|
|
131
|
+
description: string | null;
|
|
132
|
+
metadata: Record<string, string>;
|
|
133
|
+
created: number;
|
|
134
|
+
}): PaymentIntent;
|
|
135
|
+
export declare function mapPaymentMethod(raw: {
|
|
136
|
+
id: string;
|
|
137
|
+
card?: {
|
|
138
|
+
brand: string;
|
|
139
|
+
last4: string;
|
|
140
|
+
exp_month: number;
|
|
141
|
+
exp_year: number;
|
|
142
|
+
} | null;
|
|
143
|
+
}): PaymentMethodSummary;
|
|
144
|
+
export declare function mapSubscription(raw: RawStripeSubscription): ProviderSubscription;
|
|
145
|
+
export declare function mapInvoice(raw: RawStripeInvoice): SubscriptionInvoice;
|
|
146
|
+
export declare function mapCheckoutSession(raw: {
|
|
147
|
+
id: string;
|
|
148
|
+
status: 'open' | 'complete' | 'expired' | null;
|
|
149
|
+
amount_total: number | null;
|
|
150
|
+
currency: string | null;
|
|
151
|
+
url: string | null;
|
|
152
|
+
success_url: string | null;
|
|
153
|
+
cancel_url: string | null;
|
|
154
|
+
customer_email: string | null;
|
|
155
|
+
metadata: Record<string, string> | null;
|
|
156
|
+
created: number;
|
|
157
|
+
expires_at: number | null;
|
|
158
|
+
}): CheckoutSession;
|
|
159
|
+
export declare function mapPaymentLink(raw: {
|
|
160
|
+
id: string;
|
|
161
|
+
url: string;
|
|
162
|
+
active: boolean;
|
|
163
|
+
metadata: Record<string, string> | null;
|
|
164
|
+
}, amount: Money): PaymentLink;
|
|
165
|
+
//# sourceMappingURL=maps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"maps.d.ts","sourceRoot":"","sources":["../../../src/providers/stripe/maps.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,QAAQ,EACR,mBAAmB,EACnB,YAAY,EACZ,KAAK,EACL,aAAa,EACb,WAAW,EACX,oBAAoB,EACpB,oBAAoB,EACpB,WAAW,EACX,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAM7C,uDAAuD;AACvD,wBAAgB,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAK5C;AAED,wBAAgB,SAAS,C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