@solvapay/server 1.0.8-preview.9 → 1.0.8

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.
@@ -0,0 +1,112 @@
1
+ type WebhookEventType = 'payment.succeeded' | 'payment.failed' | 'payment.refunded' | 'payment.refund_failed' | 'purchase.created' | 'purchase.updated' | 'purchase.cancelled' | 'purchase.expired' | 'purchase.suspended' | 'customer.created' | 'customer.updated' | 'customer.deleted' | 'checkout_session.created';
2
+ interface WebhookProduct {
3
+ reference: string;
4
+ }
5
+ interface CustomerWebhookObject {
6
+ id: string;
7
+ created: number;
8
+ product: WebhookProduct | null;
9
+ reference?: string;
10
+ name?: string;
11
+ email?: string;
12
+ telephone?: string;
13
+ status?: string;
14
+ }
15
+ type WebhookPayloadObject = Record<string, unknown>;
16
+ type WebhookEventObjectMap = {
17
+ 'payment.succeeded': WebhookPayloadObject;
18
+ 'payment.failed': WebhookPayloadObject;
19
+ 'payment.refunded': WebhookPayloadObject;
20
+ 'payment.refund_failed': WebhookPayloadObject;
21
+ 'purchase.created': WebhookPayloadObject;
22
+ 'purchase.updated': WebhookPayloadObject;
23
+ 'purchase.cancelled': WebhookPayloadObject;
24
+ 'purchase.expired': WebhookPayloadObject;
25
+ 'purchase.suspended': WebhookPayloadObject;
26
+ 'customer.created': CustomerWebhookObject;
27
+ 'customer.updated': CustomerWebhookObject;
28
+ 'customer.deleted': CustomerWebhookObject;
29
+ 'checkout_session.created': WebhookPayloadObject;
30
+ };
31
+ type WebhookEventForType<TType extends WebhookEventType> = {
32
+ id: string;
33
+ type: TType;
34
+ created: number;
35
+ api_version: string;
36
+ data: {
37
+ object: WebhookEventObjectMap[TType];
38
+ previous_attributes: Record<string, unknown> | null;
39
+ };
40
+ livemode: boolean;
41
+ request: {
42
+ id: string | null;
43
+ idempotency_key: string | null;
44
+ };
45
+ };
46
+ type WebhookEvent = {
47
+ [TType in WebhookEventType]: WebhookEventForType<TType>;
48
+ }[WebhookEventType];
49
+
50
+ /**
51
+ * Fetch-first `(req: Request) => Promise<Response>` handlers for every
52
+ * SolvaPay route, plus the `solvapayWebhook` factory. Wraps the pure
53
+ * `*Core` helpers from `../helpers` with CORS + JSON serialisation so
54
+ * the edge-runtime entry point (Deno / Supabase Edge / Cloudflare
55
+ * Workers / Bun / Next edge / Vercel Functions) is a one-liner:
56
+ *
57
+ * ```ts
58
+ * import { checkPurchase } from '@solvapay/server/fetch'
59
+ * Deno.serve(checkPurchase)
60
+ * ```
61
+ *
62
+ * Lifted verbatim from `@solvapay/fetch@1.0.0` when the standalone
63
+ * package was folded into `@solvapay/server` as the `./fetch` subpath
64
+ * export. Three substantive tweaks captured in the move:
65
+ *
66
+ * 1. `*Core` imports are relative (`'../helpers'`), not self-imports
67
+ * through `'@solvapay/server'` — avoids the re-export indirection
68
+ * and keeps the build tree-shake-friendly.
69
+ * 2. `verifyWebhook` imports from `'../edge'` explicitly so the
70
+ * `./fetch` subpath is deterministically Web Crypto regardless of
71
+ * which export condition a consumer's bundler selects for
72
+ * `@solvapay/server` (the root entry's `node:crypto` variant was
73
+ * the wrong choice on edge runtimes and the bundler-selected
74
+ * default could swing either way).
75
+ * 3. `await verifyWebhook(...)` — the previous call was un-awaited.
76
+ * Worked by accident on Deno because the `deno` export condition
77
+ * resolved `@solvapay/server` to `./dist/edge.js` (async Web Crypto
78
+ * variant), and passing the Promise through `options.onEvent` got
79
+ * coerced to the event object in most handlers. Latent bug —
80
+ * surfaced as "event is a Promise" in strict TypeScript handlers
81
+ * that destructured `event.type` synchronously. The `await` makes
82
+ * the handler return the parsed `WebhookEvent` deterministically.
83
+ */
84
+
85
+ declare function checkPurchase(req: Request): Promise<Response>;
86
+ declare function trackUsage(req: Request): Promise<Response>;
87
+ declare function createPaymentIntent(req: Request): Promise<Response>;
88
+ declare function processPayment(req: Request): Promise<Response>;
89
+ declare function createTopupPaymentIntent(req: Request): Promise<Response>;
90
+ declare function customerBalance(req: Request): Promise<Response>;
91
+ declare function cancelRenewal(req: Request): Promise<Response>;
92
+ declare function reactivateRenewal(req: Request): Promise<Response>;
93
+ declare function activatePlan(req: Request): Promise<Response>;
94
+ declare function getPaymentMethod(req: Request): Promise<Response>;
95
+ declare function listPlans(req: Request): Promise<Response>;
96
+ declare function syncCustomer(req: Request): Promise<Response>;
97
+ declare function createCheckoutSession(req: Request): Promise<Response>;
98
+ declare function createCustomerSession(req: Request): Promise<Response>;
99
+ declare function getMerchant(req: Request): Promise<Response>;
100
+ declare function getProduct(req: Request): Promise<Response>;
101
+ interface SolvapayWebhookOptions {
102
+ secret?: string;
103
+ onEvent: (event: WebhookEvent) => void | Promise<void>;
104
+ }
105
+ declare function solvapayWebhook(options: SolvapayWebhookOptions): (req: Request) => Promise<Response>;
106
+
107
+ interface CorsConfig {
108
+ origins: string[];
109
+ }
110
+ declare function configureCors(config: CorsConfig): void;
111
+
112
+ export { type SolvapayWebhookOptions, activatePlan, cancelRenewal, checkPurchase, configureCors, createCheckoutSession, createCustomerSession, createPaymentIntent, createTopupPaymentIntent, customerBalance, getMerchant, getPaymentMethod, getProduct, listPlans, processPayment, reactivateRenewal, solvapayWebhook, syncCustomer, trackUsage };
@@ -0,0 +1,112 @@
1
+ type WebhookEventType = 'payment.succeeded' | 'payment.failed' | 'payment.refunded' | 'payment.refund_failed' | 'purchase.created' | 'purchase.updated' | 'purchase.cancelled' | 'purchase.expired' | 'purchase.suspended' | 'customer.created' | 'customer.updated' | 'customer.deleted' | 'checkout_session.created';
2
+ interface WebhookProduct {
3
+ reference: string;
4
+ }
5
+ interface CustomerWebhookObject {
6
+ id: string;
7
+ created: number;
8
+ product: WebhookProduct | null;
9
+ reference?: string;
10
+ name?: string;
11
+ email?: string;
12
+ telephone?: string;
13
+ status?: string;
14
+ }
15
+ type WebhookPayloadObject = Record<string, unknown>;
16
+ type WebhookEventObjectMap = {
17
+ 'payment.succeeded': WebhookPayloadObject;
18
+ 'payment.failed': WebhookPayloadObject;
19
+ 'payment.refunded': WebhookPayloadObject;
20
+ 'payment.refund_failed': WebhookPayloadObject;
21
+ 'purchase.created': WebhookPayloadObject;
22
+ 'purchase.updated': WebhookPayloadObject;
23
+ 'purchase.cancelled': WebhookPayloadObject;
24
+ 'purchase.expired': WebhookPayloadObject;
25
+ 'purchase.suspended': WebhookPayloadObject;
26
+ 'customer.created': CustomerWebhookObject;
27
+ 'customer.updated': CustomerWebhookObject;
28
+ 'customer.deleted': CustomerWebhookObject;
29
+ 'checkout_session.created': WebhookPayloadObject;
30
+ };
31
+ type WebhookEventForType<TType extends WebhookEventType> = {
32
+ id: string;
33
+ type: TType;
34
+ created: number;
35
+ api_version: string;
36
+ data: {
37
+ object: WebhookEventObjectMap[TType];
38
+ previous_attributes: Record<string, unknown> | null;
39
+ };
40
+ livemode: boolean;
41
+ request: {
42
+ id: string | null;
43
+ idempotency_key: string | null;
44
+ };
45
+ };
46
+ type WebhookEvent = {
47
+ [TType in WebhookEventType]: WebhookEventForType<TType>;
48
+ }[WebhookEventType];
49
+
50
+ /**
51
+ * Fetch-first `(req: Request) => Promise<Response>` handlers for every
52
+ * SolvaPay route, plus the `solvapayWebhook` factory. Wraps the pure
53
+ * `*Core` helpers from `../helpers` with CORS + JSON serialisation so
54
+ * the edge-runtime entry point (Deno / Supabase Edge / Cloudflare
55
+ * Workers / Bun / Next edge / Vercel Functions) is a one-liner:
56
+ *
57
+ * ```ts
58
+ * import { checkPurchase } from '@solvapay/server/fetch'
59
+ * Deno.serve(checkPurchase)
60
+ * ```
61
+ *
62
+ * Lifted verbatim from `@solvapay/fetch@1.0.0` when the standalone
63
+ * package was folded into `@solvapay/server` as the `./fetch` subpath
64
+ * export. Three substantive tweaks captured in the move:
65
+ *
66
+ * 1. `*Core` imports are relative (`'../helpers'`), not self-imports
67
+ * through `'@solvapay/server'` — avoids the re-export indirection
68
+ * and keeps the build tree-shake-friendly.
69
+ * 2. `verifyWebhook` imports from `'../edge'` explicitly so the
70
+ * `./fetch` subpath is deterministically Web Crypto regardless of
71
+ * which export condition a consumer's bundler selects for
72
+ * `@solvapay/server` (the root entry's `node:crypto` variant was
73
+ * the wrong choice on edge runtimes and the bundler-selected
74
+ * default could swing either way).
75
+ * 3. `await verifyWebhook(...)` — the previous call was un-awaited.
76
+ * Worked by accident on Deno because the `deno` export condition
77
+ * resolved `@solvapay/server` to `./dist/edge.js` (async Web Crypto
78
+ * variant), and passing the Promise through `options.onEvent` got
79
+ * coerced to the event object in most handlers. Latent bug —
80
+ * surfaced as "event is a Promise" in strict TypeScript handlers
81
+ * that destructured `event.type` synchronously. The `await` makes
82
+ * the handler return the parsed `WebhookEvent` deterministically.
83
+ */
84
+
85
+ declare function checkPurchase(req: Request): Promise<Response>;
86
+ declare function trackUsage(req: Request): Promise<Response>;
87
+ declare function createPaymentIntent(req: Request): Promise<Response>;
88
+ declare function processPayment(req: Request): Promise<Response>;
89
+ declare function createTopupPaymentIntent(req: Request): Promise<Response>;
90
+ declare function customerBalance(req: Request): Promise<Response>;
91
+ declare function cancelRenewal(req: Request): Promise<Response>;
92
+ declare function reactivateRenewal(req: Request): Promise<Response>;
93
+ declare function activatePlan(req: Request): Promise<Response>;
94
+ declare function getPaymentMethod(req: Request): Promise<Response>;
95
+ declare function listPlans(req: Request): Promise<Response>;
96
+ declare function syncCustomer(req: Request): Promise<Response>;
97
+ declare function createCheckoutSession(req: Request): Promise<Response>;
98
+ declare function createCustomerSession(req: Request): Promise<Response>;
99
+ declare function getMerchant(req: Request): Promise<Response>;
100
+ declare function getProduct(req: Request): Promise<Response>;
101
+ interface SolvapayWebhookOptions {
102
+ secret?: string;
103
+ onEvent: (event: WebhookEvent) => void | Promise<void>;
104
+ }
105
+ declare function solvapayWebhook(options: SolvapayWebhookOptions): (req: Request) => Promise<Response>;
106
+
107
+ interface CorsConfig {
108
+ origins: string[];
109
+ }
110
+ declare function configureCors(config: CorsConfig): void;
111
+
112
+ export { type SolvapayWebhookOptions, activatePlan, cancelRenewal, checkPurchase, configureCors, createCheckoutSession, createCustomerSession, createPaymentIntent, createTopupPaymentIntent, customerBalance, getMerchant, getPaymentMethod, getProduct, listPlans, processPayment, reactivateRenewal, solvapayWebhook, syncCustomer, trackUsage };