@revealui/services 0.3.2 → 0.3.4
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/stripe/payment-intent.d.ts.map +1 -1
- package/dist/stripe/payment-intent.js +6 -1
- package/dist/stripe/payment-intent.js.map +1 -1
- package/dist/supabase/types.d.ts.map +1 -1
- package/package.json +6 -6
- package/LICENSE.commercial +0 -111
- package/dist/api/create-checkout-session/index.d.ts +0 -2
- package/dist/api/create-checkout-session/index.d.ts.map +0 -1
- package/dist/api/create-checkout-session/index.js +0 -61
- package/dist/api/create-checkout-session/index.js.map +0 -1
- package/dist/api/create-portal-link/index.d.ts +0 -2
- package/dist/api/create-portal-link/index.d.ts.map +0 -1
- package/dist/api/create-portal-link/index.js +0 -37
- package/dist/api/create-portal-link/index.js.map +0 -1
- package/dist/api/handlers/customer-handlers.d.ts +0 -27
- package/dist/api/handlers/customer-handlers.d.ts.map +0 -1
- package/dist/api/handlers/customer-handlers.js +0 -82
- package/dist/api/handlers/customer-handlers.js.map +0 -1
- package/dist/api/handlers/index.d.ts +0 -18
- package/dist/api/handlers/index.d.ts.map +0 -1
- package/dist/api/handlers/index.js +0 -18
- package/dist/api/handlers/index.js.map +0 -1
- package/dist/api/handlers/invoice-handlers.d.ts +0 -9
- package/dist/api/handlers/invoice-handlers.d.ts.map +0 -1
- package/dist/api/handlers/invoice-handlers.js +0 -52
- package/dist/api/handlers/invoice-handlers.js.map +0 -1
- package/dist/api/handlers/payment-handlers.d.ts +0 -13
- package/dist/api/handlers/payment-handlers.d.ts.map +0 -1
- package/dist/api/handlers/payment-handlers.js +0 -133
- package/dist/api/handlers/payment-handlers.js.map +0 -1
- package/dist/api/handlers/payment-intent.d.ts +0 -21
- package/dist/api/handlers/payment-intent.d.ts.map +0 -1
- package/dist/api/handlers/payment-intent.js +0 -87
- package/dist/api/handlers/payment-intent.js.map +0 -1
- package/dist/api/handlers/product-handlers.d.ts +0 -11
- package/dist/api/handlers/product-handlers.d.ts.map +0 -1
- package/dist/api/handlers/product-handlers.js +0 -43
- package/dist/api/handlers/product-handlers.js.map +0 -1
- package/dist/api/handlers/subscription-handlers.d.ts +0 -17
- package/dist/api/handlers/subscription-handlers.d.ts.map +0 -1
- package/dist/api/handlers/subscription-handlers.js +0 -119
- package/dist/api/handlers/subscription-handlers.js.map +0 -1
- package/dist/api/index.d.ts +0 -7
- package/dist/api/index.d.ts.map +0 -1
- package/dist/api/index.js +0 -7
- package/dist/api/index.js.map +0 -1
- package/dist/api/types/stripe.d.ts +0 -42
- package/dist/api/types/stripe.d.ts.map +0 -1
- package/dist/api/types/stripe.js +0 -72
- package/dist/api/types/stripe.js.map +0 -1
- package/dist/api/update-price/index.d.ts +0 -42
- package/dist/api/update-price/index.d.ts.map +0 -1
- package/dist/api/update-price/index.js +0 -78
- package/dist/api/update-price/index.js.map +0 -1
- package/dist/api/update-product/index.d.ts +0 -44
- package/dist/api/update-product/index.d.ts.map +0 -1
- package/dist/api/update-product/index.js +0 -85
- package/dist/api/update-product/index.js.map +0 -1
- package/dist/api/utils.d.ts +0 -34
- package/dist/api/utils.d.ts.map +0 -1
- package/dist/api/utils.js +0 -66
- package/dist/api/utils.js.map +0 -1
- package/dist/api/webhooks/index.d.ts +0 -12
- package/dist/api/webhooks/index.d.ts.map +0 -1
- package/dist/api/webhooks/index.js +0 -280
- package/dist/api/webhooks/index.js.map +0 -1
- package/dist/stripe/billing.d.ts +0 -121
- package/dist/stripe/billing.d.ts.map +0 -1
- package/dist/stripe/billing.js +0 -157
- package/dist/stripe/billing.js.map +0 -1
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Payment method and setup intent handlers for Stripe webhooks
|
|
3
|
-
*/
|
|
4
|
-
import { logger } from '@revealui/core/utils/logger';
|
|
5
|
-
import { extractCustomerId, isStripePaymentMethod } from '../types/stripe.js';
|
|
6
|
-
import { copyBillingDetailsToCustomer } from './customer-handlers.js';
|
|
7
|
-
import { handleSupabaseError } from './subscription-handlers.js';
|
|
8
|
-
async function lookupUserByCustomerId(supabase, customerId) {
|
|
9
|
-
const { data: userData } = await supabase
|
|
10
|
-
.from('users')
|
|
11
|
-
.select('id')
|
|
12
|
-
.eq('stripe_customer_id', customerId)
|
|
13
|
-
.single();
|
|
14
|
-
if (!userData) {
|
|
15
|
-
throw new Error('User not found for customer');
|
|
16
|
-
}
|
|
17
|
-
const userId = userData.id;
|
|
18
|
-
if (!userId) {
|
|
19
|
-
throw new Error('User missing id');
|
|
20
|
-
}
|
|
21
|
-
return userId;
|
|
22
|
-
}
|
|
23
|
-
export const handlePaymentMethodAttached = async (event, supabase) => {
|
|
24
|
-
const paymentMethod = event.data.object;
|
|
25
|
-
if (!isStripePaymentMethod(paymentMethod)) {
|
|
26
|
-
throw new Error('Invalid payment method in event');
|
|
27
|
-
}
|
|
28
|
-
const customerId = extractCustomerId(paymentMethod.customer);
|
|
29
|
-
if (!customerId) {
|
|
30
|
-
throw new Error('Payment method missing customer');
|
|
31
|
-
}
|
|
32
|
-
const userId = await lookupUserByCustomerId(supabase, customerId);
|
|
33
|
-
try {
|
|
34
|
-
await copyBillingDetailsToCustomer(userId, paymentMethod, supabase);
|
|
35
|
-
}
|
|
36
|
-
catch (error) {
|
|
37
|
-
if (error instanceof Error) {
|
|
38
|
-
handleSupabaseError(error);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
handleSupabaseError(new Error(String(error)));
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
export const handlePaymentMethodDetached = async (event, supabase) => {
|
|
46
|
-
const paymentMethod = event.data.object;
|
|
47
|
-
if (!isStripePaymentMethod(paymentMethod)) {
|
|
48
|
-
throw new Error('Invalid payment method in event');
|
|
49
|
-
}
|
|
50
|
-
const customerId = extractCustomerId(paymentMethod.customer);
|
|
51
|
-
if (!customerId) {
|
|
52
|
-
throw new Error('Payment method missing customer');
|
|
53
|
-
}
|
|
54
|
-
const userId = await lookupUserByCustomerId(supabase, customerId);
|
|
55
|
-
try {
|
|
56
|
-
await copyBillingDetailsToCustomer(userId, paymentMethod, supabase);
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
if (error instanceof Error) {
|
|
60
|
-
handleSupabaseError(error);
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
handleSupabaseError(new Error(String(error)));
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
export const handlePaymentMethodCreated = async (event, supabase) => {
|
|
68
|
-
const paymentMethod = event.data.object;
|
|
69
|
-
if (!isStripePaymentMethod(paymentMethod)) {
|
|
70
|
-
throw new Error('Invalid payment method in event');
|
|
71
|
-
}
|
|
72
|
-
const customerId = extractCustomerId(paymentMethod.customer);
|
|
73
|
-
if (!customerId) {
|
|
74
|
-
throw new Error('Payment method missing customer');
|
|
75
|
-
}
|
|
76
|
-
const userId = await lookupUserByCustomerId(supabase, customerId);
|
|
77
|
-
try {
|
|
78
|
-
await copyBillingDetailsToCustomer(userId, paymentMethod, supabase);
|
|
79
|
-
}
|
|
80
|
-
catch (error) {
|
|
81
|
-
if (error instanceof Error) {
|
|
82
|
-
handleSupabaseError(error);
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
handleSupabaseError(new Error(String(error)));
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
export const handlePaymentMethodUpdated = async (event, supabase) => {
|
|
90
|
-
const paymentMethod = event.data.object;
|
|
91
|
-
if (!isStripePaymentMethod(paymentMethod)) {
|
|
92
|
-
throw new Error('Invalid payment method in event');
|
|
93
|
-
}
|
|
94
|
-
const customerId = extractCustomerId(paymentMethod.customer);
|
|
95
|
-
if (!customerId) {
|
|
96
|
-
throw new Error('Payment method missing customer');
|
|
97
|
-
}
|
|
98
|
-
const userId = await lookupUserByCustomerId(supabase, customerId);
|
|
99
|
-
try {
|
|
100
|
-
await copyBillingDetailsToCustomer(userId, paymentMethod, supabase);
|
|
101
|
-
}
|
|
102
|
-
catch (error) {
|
|
103
|
-
if (error instanceof Error) {
|
|
104
|
-
handleSupabaseError(error);
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
handleSupabaseError(new Error(String(error)));
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
export const handleSetupIntentSucceeded = (event, _supabase) => {
|
|
112
|
-
void _supabase;
|
|
113
|
-
const setupIntent = event.data.object;
|
|
114
|
-
const paymentMethodId = typeof setupIntent.payment_method === 'string'
|
|
115
|
-
? setupIntent.payment_method
|
|
116
|
-
: setupIntent.payment_method?.id;
|
|
117
|
-
if (!paymentMethodId) {
|
|
118
|
-
throw new Error('Setup intent missing payment method');
|
|
119
|
-
}
|
|
120
|
-
logger.info('Setup intent succeeded', {
|
|
121
|
-
setupIntentId: setupIntent.id,
|
|
122
|
-
paymentMethodId,
|
|
123
|
-
});
|
|
124
|
-
};
|
|
125
|
-
export const handleSetupIntentFailed = (event, _supabase) => {
|
|
126
|
-
void _supabase;
|
|
127
|
-
const setupIntent = event.data.object;
|
|
128
|
-
logger.error('Setup intent failed', {
|
|
129
|
-
setupIntentId: setupIntent.id,
|
|
130
|
-
error: setupIntent.last_setup_error,
|
|
131
|
-
});
|
|
132
|
-
};
|
|
133
|
-
//# sourceMappingURL=payment-handlers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"payment-handlers.js","sourceRoot":"","sources":["../../../src/api/handlers/payment-handlers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAKrD,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE,KAAK,UAAU,sBAAsB,CACnC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ui/core';
|
|
5
|
-
interface CreatePaymentIntentArgs {
|
|
6
|
-
req: RevealRequest;
|
|
7
|
-
res?: Response;
|
|
8
|
-
next?: () => void;
|
|
9
|
-
revealui?: RevealUIInstance;
|
|
10
|
-
}
|
|
11
|
-
export declare const createPaymentIntent: (args: CreatePaymentIntentArgs) => Promise<Response | {
|
|
12
|
-
status: number;
|
|
13
|
-
json?: {
|
|
14
|
-
error: string;
|
|
15
|
-
};
|
|
16
|
-
send?: {
|
|
17
|
-
client_secret: string | null;
|
|
18
|
-
};
|
|
19
|
-
}>;
|
|
20
|
-
export {};
|
|
21
|
-
//# sourceMappingURL=payment-intent.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"payment-intent.d.ts","sourceRoot":"","sources":["../../../src/api/handlers/payment-intent.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAmBtE,UAAU,uBAAuB;IAC/B,GAAG,EAAE,aAAa,CAAC;IACnB,GAAG,CAAC,EAAE,QAAQ,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,IAAI,CAAC;IAClB,QAAQ,CAAC,EAAE,gBAAgB,CAAC;CAC7B;AAED,eAAO,MAAM,mBAAmB,GAC9B,MAAM,uBAAuB,KAC5B,OAAO,CACN,QAAQ,GACR;IACE,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACzB,IAAI,CAAC,EAAE;QAAE,aAAa,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;CACzC,CAyGJ,CAAC"}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Payment intent creation handler
|
|
3
|
-
*/
|
|
4
|
-
import { protectedStripe } from '../../stripe/stripeClient.js';
|
|
5
|
-
export const createPaymentIntent = async (args) => {
|
|
6
|
-
const { req } = args;
|
|
7
|
-
const { user, revealui } = req;
|
|
8
|
-
if (!user || typeof user.email !== 'string') {
|
|
9
|
-
return { status: 401, json: { error: 'Unauthorized' } };
|
|
10
|
-
}
|
|
11
|
-
if (!revealui) {
|
|
12
|
-
return { status: 500, json: { error: 'RevealUI instance not available' } };
|
|
13
|
-
}
|
|
14
|
-
const fullUser = await revealui.findByID({
|
|
15
|
-
collection: 'users',
|
|
16
|
-
id: user.id,
|
|
17
|
-
});
|
|
18
|
-
if (!fullUser || typeof fullUser !== 'object') {
|
|
19
|
-
return { status: 404, json: { error: 'User not found' } };
|
|
20
|
-
}
|
|
21
|
-
const typedUser = fullUser;
|
|
22
|
-
try {
|
|
23
|
-
let stripeCustomerID = typedUser.stripeCustomerID;
|
|
24
|
-
if (!stripeCustomerID) {
|
|
25
|
-
const customerParams = {
|
|
26
|
-
email: user.email,
|
|
27
|
-
name: typeof typedUser.name === 'string' ? typedUser.name : undefined,
|
|
28
|
-
};
|
|
29
|
-
const customer = await protectedStripe.customers.create(customerParams);
|
|
30
|
-
stripeCustomerID = customer.id;
|
|
31
|
-
await revealui.update({
|
|
32
|
-
collection: 'users',
|
|
33
|
-
id: user.id,
|
|
34
|
-
data: {
|
|
35
|
-
stripeCustomerID,
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
let total = 0;
|
|
40
|
-
const cart = typedUser.cart;
|
|
41
|
-
if (!(cart && Array.isArray(cart.items)) || cart.items.length === 0) {
|
|
42
|
-
return { status: 400, json: { error: 'No items in cart' } };
|
|
43
|
-
}
|
|
44
|
-
await Promise.allSettled(cart.items.map(async (item) => {
|
|
45
|
-
const { product, quantity } = item;
|
|
46
|
-
if (!quantity ||
|
|
47
|
-
typeof product !== 'object' ||
|
|
48
|
-
typeof product.stripeProductID !== 'string') {
|
|
49
|
-
throw new Error('Invalid product or quantity');
|
|
50
|
-
}
|
|
51
|
-
const prices = await protectedStripe.prices.list({
|
|
52
|
-
product: product.stripeProductID,
|
|
53
|
-
limit: 100,
|
|
54
|
-
});
|
|
55
|
-
if (prices.data.length === 0) {
|
|
56
|
-
throw new Error('No prices found for product');
|
|
57
|
-
}
|
|
58
|
-
const price = prices.data[0];
|
|
59
|
-
if (price && price.unit_amount !== null && typeof price.unit_amount === 'number') {
|
|
60
|
-
total += price.unit_amount * quantity;
|
|
61
|
-
}
|
|
62
|
-
}));
|
|
63
|
-
if (total === 0) {
|
|
64
|
-
throw new Error('There is nothing to pay for, add some items to your cart and try again.');
|
|
65
|
-
}
|
|
66
|
-
const paymentIntentParams = {
|
|
67
|
-
customer: stripeCustomerID,
|
|
68
|
-
amount: total,
|
|
69
|
-
currency: 'usd',
|
|
70
|
-
payment_method_types: ['card'],
|
|
71
|
-
};
|
|
72
|
-
const paymentIntent = await protectedStripe.paymentIntents.create(paymentIntentParams);
|
|
73
|
-
return {
|
|
74
|
-
status: 200,
|
|
75
|
-
send: { client_secret: paymentIntent.client_secret },
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
catch (err) {
|
|
79
|
-
const message = err instanceof Error ? err.message : 'Unknown error';
|
|
80
|
-
const revealuiInstance = revealui;
|
|
81
|
-
if (revealuiInstance?.logger) {
|
|
82
|
-
revealuiInstance.logger.error(message);
|
|
83
|
-
}
|
|
84
|
-
return { status: 500, json: { error: message } };
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
//# sourceMappingURL=payment-intent.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"payment-intent.js","sourceRoot":"","sources":["../../../src/api/handlers/payment-intent.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAwB/D,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EACtC,IAA6B,EAQ7B,EAAE;IACF,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IACrB,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,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K,IAAI,KAAK,CAAC,WAAW,GAAG,QAAQ,CAAC;YACxC,CAAC;QACH,CAAC,CAAC,CACH,CAAC;QAEF,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,yEAAyE,CAAC,CAAC;QAC7F,CAAC;QAED,MAAM,mBAAmB,GAAqC;YAC5D,QAAQ,EAAE,gBAAgB;YAC1B,MAAM,EAAE,KAAK;YACb,QAAQ,EAAE,KAAK;YACf,oBAAoB,EAAE,CAAC,MAAM,CAAC;SAC/B,CAAC;QAEF,MAAM,aAAa,GAAG,MAAM,eAAe,CAAC,cAAc,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;QAEvF,OAAO;YACL,MAAM,EAAE,GAAG;YACX,IAAI,EAAE,EAAE,aAAa,EAAE,aAAa,CAAC,aAAa,EAAE;SACrD,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC;QACrE,MAAM,gBAAgB,GAAG,QAAQ,CAAC;QAClC,IAAI,gBAAgB,EAAE,MAAM,EAAE,CAAC;YAC7B,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACzC,CAAC;QACD,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC;IACnD,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Product and price record handlers for Stripe webhooks
|
|
3
|
-
*/
|
|
4
|
-
import type Stripe from 'stripe';
|
|
5
|
-
import type { SupabaseClient } from '../../supabase/index.js';
|
|
6
|
-
import type { Database } from '../../supabase/types.js';
|
|
7
|
-
export declare const upsertRecord: <TTable extends keyof Database["public"]["Tables"]>(supabase: SupabaseClient<Database>, table: TTable, record: Database["public"]["Tables"][TTable]["Insert"]) => Promise<void>;
|
|
8
|
-
export declare const upsertProductRecord: (supabase: SupabaseClient<Database>, product: Stripe.Product) => Promise<void>;
|
|
9
|
-
export declare const upsertPriceRecord: (supabase: SupabaseClient<Database>, price: Stripe.Price) => Promise<void>;
|
|
10
|
-
export declare const toDateTime: (secs: number) => Date;
|
|
11
|
-
//# sourceMappingURL=product-handlers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"product-handlers.d.ts","sourceRoot":"","sources":["../../../src/api/handlers/product-handlers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,KAAK,EAAE,QAAQ,EAAgB,MAAM,yBAAyB,CAAC;AAEtE,eAAO,MAAM,YAAY,GAAU,MAAM,SAAS,MAAM,QAAQ,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,EAClF,UAAU,cAAc,CAAC,QAAQ,CAAC,EAClC,OAAO,MAAM,EACb,QAAQ,QAAQ,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,KACrD,OAAO,CAAC,IAAI,CAQd,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAC9B,UAAU,cAAc,CAAC,QAAQ,CAAC,EAClC,SAAS,MAAM,CAAC,OAAO,KACtB,OAAO,CAAC,IAAI,CAkBd,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,UAAU,cAAc,CAAC,QAAQ,CAAC,EAClC,OAAO,MAAM,CAAC,KAAK,KAClB,OAAO,CAAC,IAAI,CAMd,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,KAAG,IAIzC,CAAC"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Product and price record handlers for Stripe webhooks
|
|
3
|
-
*/
|
|
4
|
-
import { logger } from '@revealui/core/utils/logger';
|
|
5
|
-
export const upsertRecord = async (supabase, table, record) => {
|
|
6
|
-
// biome-ignore lint/suspicious/noExplicitAny: Supabase upsert type doesn't perfectly match our generated types, but is runtime-compatible
|
|
7
|
-
const { error } = await supabase.from(table).upsert([record]); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
8
|
-
if (error) {
|
|
9
|
-
logger.error('Error upserting record', { table: String(table), error });
|
|
10
|
-
throw error;
|
|
11
|
-
}
|
|
12
|
-
logger.info('Record upserted', { table: String(table), record });
|
|
13
|
-
};
|
|
14
|
-
export const upsertProductRecord = async (supabase, product) => {
|
|
15
|
-
const productData = {
|
|
16
|
-
stripe_product_i_d: product.id,
|
|
17
|
-
title: typeof product.name === 'string' ? product.name : product.name,
|
|
18
|
-
created_at: new Date(product.created * 1000).toISOString(),
|
|
19
|
-
updated_at: new Date(product.updated * 1000).toISOString(),
|
|
20
|
-
price_j_s_o_n: product.default_price
|
|
21
|
-
? typeof product.default_price === 'string'
|
|
22
|
-
? product.default_price
|
|
23
|
-
: typeof product.default_price === 'object' &&
|
|
24
|
-
product.default_price !== null &&
|
|
25
|
-
'id' in product.default_price
|
|
26
|
-
? String(product.default_price.id)
|
|
27
|
-
: String(product.default_price)
|
|
28
|
-
: null,
|
|
29
|
-
};
|
|
30
|
-
await upsertRecord(supabase, 'products', productData);
|
|
31
|
-
};
|
|
32
|
-
export const upsertPriceRecord = async (supabase, price) => {
|
|
33
|
-
const priceData = {
|
|
34
|
-
price_j_s_o_n: price.id.toString(),
|
|
35
|
-
};
|
|
36
|
-
await upsertRecord(supabase, 'prices', priceData);
|
|
37
|
-
};
|
|
38
|
-
export const toDateTime = (secs) => {
|
|
39
|
-
const t = new Date(1970, 0, 1);
|
|
40
|
-
t.setSeconds(secs);
|
|
41
|
-
return t;
|
|
42
|
-
};
|
|
43
|
-
//# sourceMappingURL=product-handlers.js.map
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aAAa;YAClC,CAAC,CAAC,OAAO,OAAO,CAAC,aAAa,KAAK,QAAQ;gBACzC,CAAC,CAAC,OAAO,CAAC,aAAa;gBACvB,CAAC,CAAC,OAAO,OAAO,CAAC,aAAa,KAAK,QAAQ;oBACvC,OAAO,CAAC,aAAa,KAAK,IAAI;oBAC9B,IAAI,IAAI,OAAO,CAAC,aAAa;oBAC/B,CAAC,CAAC,MAAM,CAAE,OAAO,CAAC,aAAgC,CAAC,EAAE,CAAC;oBACtD,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC;YACnC,CAAC,CAAC,IAAI;KACT,CAAC;IAEF,MAAM,YAAY,CAAC,QAAQ,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;AACxD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EACpC,QAAkC,EAClC,KAAmB,EACJ,EAAE;IACjB,MAAM,SAAS,GAA2B;QACxC,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE;KACnC,CAAC;IAEF,MAAM,YAAY,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;AACpD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAY,EAAQ,EAAE;IAC/C,MAAM,CAAC,GAAG,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC/B,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IACnB,OAAO,CAAC,CAAC;AACX,CAAC,CAAC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Subscription event handlers for Stripe webhooks.
|
|
3
|
-
*
|
|
4
|
-
* @deprecated These handlers use Supabase and are NOT used by the API app.
|
|
5
|
-
* The production webhook handler is in apps/api/src/routes/webhooks.ts,
|
|
6
|
-
* which uses NeonDB (Drizzle ORM) directly.
|
|
7
|
-
*/
|
|
8
|
-
import type { SupabaseClient } from '../../supabase/index.js';
|
|
9
|
-
import type { Database } from '../../supabase/types.js';
|
|
10
|
-
import type { StripeWebhookEvent } from '../types/stripe.js';
|
|
11
|
-
export declare const manageSubscriptionStatusChange: (subscriptionId: string, customerId: string | number, createAction: boolean | undefined, supabase: SupabaseClient<Database>) => Promise<void>;
|
|
12
|
-
export declare const handleCheckoutSessionCompleted: (event: StripeWebhookEvent<"checkout.session.completed">, supabase: SupabaseClient<Database>) => Promise<void>;
|
|
13
|
-
export declare const handleCustomerSubscriptionDeleted: (event: StripeWebhookEvent<"customer.subscription.deleted">, supabase: SupabaseClient<Database>) => Promise<void>;
|
|
14
|
-
export declare const handleCustomerSubscriptionCreated: (event: StripeWebhookEvent<"customer.subscription.created">, supabase: SupabaseClient<Database>) => Promise<void>;
|
|
15
|
-
export declare const handleCustomerSubscriptionUpdated: (event: StripeWebhookEvent<"customer.subscription.updated">, supabase: SupabaseClient<Database>) => Promise<void>;
|
|
16
|
-
export declare const handleSupabaseError: (error: Error) => void;
|
|
17
|
-
//# sourceMappingURL=subscription-handlers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"subscription-handlers.d.ts","sourceRoot":"","sources":["../../../src/api/handlers/subscription-handlers.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAG7D,eAAO,MAAM,8BAA8B,GACzC,gBAAgB,MAAM,EACtB,YAAY,MAAM,GAAG,MAAM,EAC3B,iCAAoB,EACpB,UAAU,cAAc,CAAC,QAAQ,CAAC,KACjC,OAAO,CAAC,IAAI,CAkCd,CAAC;AAEF,eAAO,MAAM,8BAA8B,GACzC,OAAO,kBAAkB,CAAC,4BAA4B,CAAC,EACvD,UAAU,cAAc,CAAC,QAAQ,CAAC,KACjC,OAAO,CAAC,IAAI,CAqBd,CAAC;AAEF,eAAO,MAAM,iCAAiC,GAC5C,OAAO,kBAAkB,CAAC,+BAA+B,CAAC,EAC1D,UAAU,cAAc,CAAC,QAAQ,CAAC,KACjC,OAAO,CAAC,IAAI,CAiBd,CAAC;AAEF,eAAO,MAAM,iCAAiC,GAC5C,OAAO,kBAAkB,CAAC,+BAA+B,CAAC,EAC1D,UAAU,cAAc,CAAC,QAAQ,CAAC,KACjC,OAAO,CAAC,IAAI,CAiBd,CAAC;AAEF,eAAO,MAAM,iCAAiC,GAC5C,OAAO,kBAAkB,CAAC,+BAA+B,CAAC,EAC1D,UAAU,cAAc,CAAC,QAAQ,CAAC,KACjC,OAAO,CAAC,IAAI,CAiBd,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,OAAO,KAAK,KAAG,IAElD,CAAC"}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Subscription event handlers for Stripe webhooks.
|
|
3
|
-
*
|
|
4
|
-
* @deprecated These handlers use Supabase and are NOT used by the API app.
|
|
5
|
-
* The production webhook handler is in apps/api/src/routes/webhooks.ts,
|
|
6
|
-
* which uses NeonDB (Drizzle ORM) directly.
|
|
7
|
-
*/
|
|
8
|
-
import { logger } from '@revealui/core/utils/logger';
|
|
9
|
-
import { protectedStripe } from '../../stripe/stripeClient.js';
|
|
10
|
-
import { extractCustomerId } from '../types/stripe.js';
|
|
11
|
-
export const manageSubscriptionStatusChange = async (subscriptionId, customerId, createAction = false, supabase) => {
|
|
12
|
-
const { data: customerData, error: noCustomerError } = await supabase
|
|
13
|
-
.from('users')
|
|
14
|
-
.select('id')
|
|
15
|
-
.eq('stripe_customer_id', String(customerId))
|
|
16
|
-
.single();
|
|
17
|
-
if (noCustomerError)
|
|
18
|
-
throw noCustomerError;
|
|
19
|
-
const { id: uuid } = customerData;
|
|
20
|
-
const subscription = await protectedStripe.subscriptions.retrieve(subscriptionId);
|
|
21
|
-
const typedSubscription = subscription;
|
|
22
|
-
const subscriptionData = {
|
|
23
|
-
id: typedSubscription.id,
|
|
24
|
-
user_id: uuid,
|
|
25
|
-
metadata: typedSubscription.metadata,
|
|
26
|
-
status: typedSubscription.status,
|
|
27
|
-
price_id: typedSubscription.items.data[0]?.price?.id || null,
|
|
28
|
-
stripe_subscription_id: typedSubscription.id,
|
|
29
|
-
};
|
|
30
|
-
const { error } = await supabase.from('subscriptions').upsert([subscriptionData]);
|
|
31
|
-
if (error)
|
|
32
|
-
throw error;
|
|
33
|
-
logger.info('Inserted/updated subscription', {
|
|
34
|
-
subscriptionId: typedSubscription.id,
|
|
35
|
-
userId: uuid,
|
|
36
|
-
});
|
|
37
|
-
if (createAction && typedSubscription.default_payment_method && uuid) {
|
|
38
|
-
// Payment method update logic would go here
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
export const handleCheckoutSessionCompleted = async (event, supabase) => {
|
|
42
|
-
const checkoutSession = event.data.object;
|
|
43
|
-
const subscriptionId = typeof checkoutSession.subscription === 'string'
|
|
44
|
-
? checkoutSession.subscription
|
|
45
|
-
: checkoutSession.subscription?.id;
|
|
46
|
-
const customerId = extractCustomerId(checkoutSession.customer);
|
|
47
|
-
if (!(subscriptionId && customerId)) {
|
|
48
|
-
throw new Error('Checkout session missing subscription or customer');
|
|
49
|
-
}
|
|
50
|
-
try {
|
|
51
|
-
await manageSubscriptionStatusChange(subscriptionId, customerId, true, supabase);
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
54
|
-
if (error instanceof Error) {
|
|
55
|
-
handleSupabaseError(error);
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
handleSupabaseError(new Error(String(error)));
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
export const handleCustomerSubscriptionDeleted = async (event, supabase) => {
|
|
63
|
-
const subscription = event.data.object;
|
|
64
|
-
const customerId = extractCustomerId(subscription.customer);
|
|
65
|
-
if (!customerId) {
|
|
66
|
-
throw new Error('Subscription missing customer');
|
|
67
|
-
}
|
|
68
|
-
try {
|
|
69
|
-
await manageSubscriptionStatusChange(subscription.id, customerId, false, supabase);
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
72
|
-
if (error instanceof Error) {
|
|
73
|
-
handleSupabaseError(error);
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
handleSupabaseError(new Error(String(error)));
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
export const handleCustomerSubscriptionCreated = async (event, supabase) => {
|
|
81
|
-
const subscription = event.data.object;
|
|
82
|
-
const customerId = extractCustomerId(subscription.customer);
|
|
83
|
-
if (!customerId) {
|
|
84
|
-
throw new Error('Subscription missing customer');
|
|
85
|
-
}
|
|
86
|
-
try {
|
|
87
|
-
await manageSubscriptionStatusChange(subscription.id, customerId, true, supabase);
|
|
88
|
-
}
|
|
89
|
-
catch (error) {
|
|
90
|
-
if (error instanceof Error) {
|
|
91
|
-
handleSupabaseError(error);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
handleSupabaseError(new Error(String(error)));
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
export const handleCustomerSubscriptionUpdated = async (event, supabase) => {
|
|
99
|
-
const subscription = event.data.object;
|
|
100
|
-
const customerId = extractCustomerId(subscription.customer);
|
|
101
|
-
if (!customerId) {
|
|
102
|
-
throw new Error('Subscription missing customer');
|
|
103
|
-
}
|
|
104
|
-
try {
|
|
105
|
-
await manageSubscriptionStatusChange(subscription.id, customerId, false, supabase);
|
|
106
|
-
}
|
|
107
|
-
catch (error) {
|
|
108
|
-
if (error instanceof Error) {
|
|
109
|
-
handleSupabaseError(error);
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
handleSupabaseError(new Error(String(error)));
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
export const handleSupabaseError = (error) => {
|
|
117
|
-
logger.error('Supabase error', { error });
|
|
118
|
-
};
|
|
119
|
-
//# sourceMappingURL=subscription-handlers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"subscription-handlers.js","sourceRoot":"","sources":["../../../src/api/handlers/subscription-handlers.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAErD,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAI/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,MAAM,CAAC,MAAM,8BAA8B,GAAG,KAAK,EACjD,cAAsB,EACtB,UAA2B,EAC3B,YAAY,GAAG,KAAK,EACpB,QAAkC,EACnB,EAAE;IACjB,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,eAAe,EAAE,GAAG,MAAM,QAAQ;SAClE,IAAI,CAAC,OAAO,CAAC;SACb,MAAM,CAAC,IAAI,CAAC;SACZ,EAAE,CAAC,oBAAoB,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;SAC5C,MAAM,EAAE,CAAC;IACZ,IAAI,eAAe;QAAE,MAAM,eAAe,CAAC;IAE3C,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,YAAY,CAAC;IAElC,MAAM,YAAY,GAAG,MAAM,eAAe,CAAC,aAAa,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;IAClF,MAAM,iBAAiB,GAAG,YAGzB,CAAC;IACF,MAAM,gBAAgB,GAA4D;QAChF,EAAE,EAAE,iBAAiB,CAAC,EAAE;QACxB,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,iBAAiB,CAAC,QAAQ;QACpC,MAAM,EAAE,iBAAiB,CAAC,MAAM;QAChC,QAAQ,EAAE,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,E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AC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YAC3B,mBAAmB,CAAC,KAAK,CAAC,CAAC;QAC7B,CAAC;aAAM,CAAC;YACN,mBAAmB,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iCAAiC,GAAG,KAAK,EACpD,KAA0D,EAC1D,QAAkC,EACnB,EAAE;IACjB,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC;IACvC,MAAM,UAAU,GAAG,iBAAiB,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;IAE5D,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACnD,CAAC;IAED,IAAI,CAAC;QACH,MAAM,8BAA8B,CAAC,YAAY,CAAC,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;IACrF,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YAC3B,mBAAmB,CAAC,KAAK,CAAC,CAAC;QAC7B,CAAC;aAAM,CAAC;YACN,mBAAmB,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,KAAY,EAAQ,EAAE;IACxD,MAAM,CAAC,KAAK,CAAC,gBAAgB,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;AAC5C,CAAC,CAAC"}
|
package/dist/api/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { POST as createCheckoutSession } from './create-checkout-session/index.js';
|
|
2
|
-
import { POST as createPortalLink } from './create-portal-link/index.js';
|
|
3
|
-
import { POST as updatePrice } from './update-price/index.js';
|
|
4
|
-
import { POST as updateProduct } from './update-product/index.js';
|
|
5
|
-
import { createPaymentIntent } from './utils.js';
|
|
6
|
-
export { createCheckoutSession, createPaymentIntent, createPortalLink, updatePrice, updateProduct, };
|
|
7
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/api/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AACnF,OAAO,EAAE,IAAI,IAAI,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,IAAI,IAAI,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,IAAI,IAAI,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,gBAAgB,EAChB,WAAW,EACX,aAAa,GACd,CAAC"}
|
package/dist/api/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { POST as createCheckoutSession } from './create-checkout-session/index.js';
|
|
2
|
-
import { POST as createPortalLink } from './create-portal-link/index.js';
|
|
3
|
-
import { POST as updatePrice } from './update-price/index.js';
|
|
4
|
-
import { POST as updateProduct } from './update-product/index.js';
|
|
5
|
-
import { createPaymentIntent } from './utils.js';
|
|
6
|
-
export { createCheckoutSession, createPaymentIntent, createPortalLink, updatePrice, updateProduct, };
|
|
7
|
-
//# sourceMappingURL=index.js.map
|
package/dist/api/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AACnF,OAAO,EAAE,IAAI,IAAI,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,IAAI,IAAI,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,IAAI,IAAI,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,gBAAgB,EAChB,WAAW,EACX,aAAa,GACd,CAAC"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { Stripe } from 'stripe';
|
|
2
|
-
/**
|
|
3
|
-
* Typed Stripe webhook event helper
|
|
4
|
-
* Ensures type safety when accessing event.data.object
|
|
5
|
-
*/
|
|
6
|
-
export type StripeWebhookEvent<T extends Stripe.Event.Type> = Stripe.Event & {
|
|
7
|
-
type: T;
|
|
8
|
-
data: {
|
|
9
|
-
object: T extends keyof Stripe.Event.Data.Object ? Stripe.Event.Data.Object[T] : unknown;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Extended webhook event type for events not in standard Stripe.Event.Type
|
|
14
|
-
* Used for payment_method and setup_intent events
|
|
15
|
-
*/
|
|
16
|
-
export type ExtendedStripeWebhookEvent<T extends string> = Omit<Stripe.Event, 'type' | 'data'> & {
|
|
17
|
-
type: T;
|
|
18
|
-
data: {
|
|
19
|
-
object: unknown;
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Type guard to check if an object is a Stripe Customer
|
|
24
|
-
*/
|
|
25
|
-
export declare function isStripeCustomer(obj: unknown): obj is Stripe.Customer;
|
|
26
|
-
/**
|
|
27
|
-
* Type guard to check if an object is a Stripe PaymentMethod
|
|
28
|
-
*/
|
|
29
|
-
export declare function isStripePaymentMethod(obj: unknown): obj is Stripe.PaymentMethod;
|
|
30
|
-
/**
|
|
31
|
-
* Type guard to check if an object is a Stripe Subscription
|
|
32
|
-
*/
|
|
33
|
-
export declare function isStripeSubscription(obj: unknown): obj is Stripe.Subscription;
|
|
34
|
-
/**
|
|
35
|
-
* Type guard to check if an object is a Stripe CheckoutSession
|
|
36
|
-
*/
|
|
37
|
-
export declare function isStripeCheckoutSession(obj: unknown): obj is Stripe.Checkout.Session;
|
|
38
|
-
/**
|
|
39
|
-
* Helper to safely extract customer ID from various Stripe objects
|
|
40
|
-
*/
|
|
41
|
-
export declare function extractCustomerId(obj: Stripe.Customer | Stripe.DeletedCustomer | Stripe.PaymentMethod | Stripe.Subscription | Stripe.Checkout.Session | string | null | undefined): string | null;
|
|
42
|
-
//# sourceMappingURL=stripe.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stripe.d.ts","sourceRoot":"","sources":["../../../src/api/types/stripe.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC;;;GAGG;AACH,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,MAAM,CAAC,KAAK,CAAC,IAAI,IAAI,MAAM,CAAC,KAAK,GAAG;IAC3E,IAAI,EAAE,CAAC,CAAC;IACR,IAAI,EAAE;QACJ,MAAM,EAAE,CAAC,SAAS,MAAM,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;KAC1F,CAAC;CACH,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,0BAA0B,CAAC,CAAC,SAAS,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,GAAG;IAC/F,IAAI,EAAE,CAAC,CAAC;IACR,IAAI,EAAE;QACJ,MAAM,EAAE,OAAO,CAAC;KACjB,CAAC;CACH,CAAC;AAEF;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM,CAAC,QAAQ,CAQrE;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM,CAAC,aAAa,CAQ/E;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM,CAAC,YAAY,CAQ7E;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM,CAAC,QAAQ,CAAC,OAAO,CAQpF;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EACC,MAAM,CAAC,QAAQ,GACf,MAAM,CAAC,eAAe,GACtB,MAAM,CAAC,aAAa,GACpB,MAAM,CAAC,YAAY,GACnB,MAAM,CAAC,QAAQ,CAAC,OAAO,GACvB,MAAM,GACN,IAAI,GACJ,SAAS,GACZ,MAAM,GAAG,IAAI,CA2Bf"}
|
package/dist/api/types/stripe.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type guard to check if an object is a Stripe Customer
|
|
3
|
-
*/
|
|
4
|
-
export function isStripeCustomer(obj) {
|
|
5
|
-
return (typeof obj === 'object' &&
|
|
6
|
-
obj !== null &&
|
|
7
|
-
'id' in obj &&
|
|
8
|
-
'object' in obj &&
|
|
9
|
-
obj.object === 'customer');
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Type guard to check if an object is a Stripe PaymentMethod
|
|
13
|
-
*/
|
|
14
|
-
export function isStripePaymentMethod(obj) {
|
|
15
|
-
return (typeof obj === 'object' &&
|
|
16
|
-
obj !== null &&
|
|
17
|
-
'id' in obj &&
|
|
18
|
-
'object' in obj &&
|
|
19
|
-
obj.object === 'payment_method');
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Type guard to check if an object is a Stripe Subscription
|
|
23
|
-
*/
|
|
24
|
-
export function isStripeSubscription(obj) {
|
|
25
|
-
return (typeof obj === 'object' &&
|
|
26
|
-
obj !== null &&
|
|
27
|
-
'id' in obj &&
|
|
28
|
-
'object' in obj &&
|
|
29
|
-
obj.object === 'subscription');
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Type guard to check if an object is a Stripe CheckoutSession
|
|
33
|
-
*/
|
|
34
|
-
export function isStripeCheckoutSession(obj) {
|
|
35
|
-
return (typeof obj === 'object' &&
|
|
36
|
-
obj !== null &&
|
|
37
|
-
'id' in obj &&
|
|
38
|
-
'object' in obj &&
|
|
39
|
-
obj.object === 'checkout.session');
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Helper to safely extract customer ID from various Stripe objects
|
|
43
|
-
*/
|
|
44
|
-
export function extractCustomerId(obj) {
|
|
45
|
-
if (typeof obj === 'string') {
|
|
46
|
-
return obj;
|
|
47
|
-
}
|
|
48
|
-
if (obj === null || obj === undefined) {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
if (typeof obj === 'object' && 'customer' in obj) {
|
|
52
|
-
const customer = obj.customer;
|
|
53
|
-
if (typeof customer === 'string') {
|
|
54
|
-
return customer;
|
|
55
|
-
}
|
|
56
|
-
if (typeof customer === 'object' && customer !== null) {
|
|
57
|
-
// Handle both Customer and DeletedCustomer
|
|
58
|
-
if ('id' in customer && typeof customer.id === 'string') {
|
|
59
|
-
return customer.id;
|
|
60
|
-
}
|
|
61
|
-
// DeletedCustomer has 'deleted' property
|
|
62
|
-
if ('deleted' in customer && customer.deleted === true && 'id' in customer) {
|
|
63
|
-
return typeof customer.id === 'string' ? customer.id : null;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
if (typeof obj === 'object' && 'id' in obj && typeof obj.id === 'string') {
|
|
68
|
-
return obj.id;
|
|
69
|
-
}
|
|
70
|
-
return null;
|
|
71
|
-
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