@solvapay/server 1.0.8-preview.8 → 1.0.8-preview.9
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/edge.d.ts +24 -1
- package/dist/edge.js +72 -0
- package/dist/index.cjs +12 -307
- package/dist/index.d.cts +3 -35
- package/dist/index.d.ts +3 -35
- package/dist/index.js +12 -303
- package/package.json +7 -7
- package/dist/chunk-R5U7XKVJ.js +0 -16
- package/dist/dist-EPVKJAIP.js +0 -94
- package/dist/dist-JBJ4HMP7.js +0 -94
- package/dist/esm-5GYCIXIY.js +0 -3475
- package/dist/esm-UW7WCMEK.js +0 -3475
- package/dist/src/adapters/base.d.ts +0 -57
- package/dist/src/adapters/base.d.ts.map +0 -1
- package/dist/src/adapters/base.js +0 -73
- package/dist/src/adapters/base.js.map +0 -1
- package/dist/src/adapters/http.d.ts +0 -25
- package/dist/src/adapters/http.d.ts.map +0 -1
- package/dist/src/adapters/http.js +0 -99
- package/dist/src/adapters/http.js.map +0 -1
- package/dist/src/adapters/index.d.ts +0 -11
- package/dist/src/adapters/index.d.ts.map +0 -1
- package/dist/src/adapters/index.js +0 -10
- package/dist/src/adapters/index.js.map +0 -1
- package/dist/src/adapters/mcp.d.ts +0 -24
- package/dist/src/adapters/mcp.d.ts.map +0 -1
- package/dist/src/adapters/mcp.js +0 -75
- package/dist/src/adapters/mcp.js.map +0 -1
- package/dist/src/adapters/next.d.ts +0 -24
- package/dist/src/adapters/next.d.ts.map +0 -1
- package/dist/src/adapters/next.js +0 -109
- package/dist/src/adapters/next.js.map +0 -1
- package/dist/src/client.d.ts +0 -58
- package/dist/src/client.d.ts.map +0 -1
- package/dist/src/client.js +0 -495
- package/dist/src/client.js.map +0 -1
- package/dist/src/edge.d.ts +0 -22
- package/dist/src/edge.d.ts.map +0 -1
- package/dist/src/edge.js +0 -91
- package/dist/src/edge.js.map +0 -1
- package/dist/src/factory.d.ts +0 -605
- package/dist/src/factory.d.ts.map +0 -1
- package/dist/src/factory.js +0 -215
- package/dist/src/factory.js.map +0 -1
- package/dist/src/helpers/auth.d.ts +0 -47
- package/dist/src/helpers/auth.d.ts.map +0 -1
- package/dist/src/helpers/auth.js +0 -73
- package/dist/src/helpers/auth.js.map +0 -1
- package/dist/src/helpers/checkout.d.ts +0 -45
- package/dist/src/helpers/checkout.d.ts.map +0 -1
- package/dist/src/helpers/checkout.js +0 -89
- package/dist/src/helpers/checkout.js.map +0 -1
- package/dist/src/helpers/customer.d.ts +0 -51
- package/dist/src/helpers/customer.d.ts.map +0 -1
- package/dist/src/helpers/customer.js +0 -77
- package/dist/src/helpers/customer.js.map +0 -1
- package/dist/src/helpers/error.d.ts +0 -15
- package/dist/src/helpers/error.d.ts.map +0 -1
- package/dist/src/helpers/error.js +0 -35
- package/dist/src/helpers/error.js.map +0 -1
- package/dist/src/helpers/index.d.ts +0 -17
- package/dist/src/helpers/index.d.ts.map +0 -1
- package/dist/src/helpers/index.js +0 -23
- package/dist/src/helpers/index.js.map +0 -1
- package/dist/src/helpers/payment.d.ts +0 -107
- package/dist/src/helpers/payment.d.ts.map +0 -1
- package/dist/src/helpers/payment.js +0 -150
- package/dist/src/helpers/payment.js.map +0 -1
- package/dist/src/helpers/plans.d.ts +0 -19
- package/dist/src/helpers/plans.d.ts.map +0 -1
- package/dist/src/helpers/plans.js +0 -53
- package/dist/src/helpers/plans.js.map +0 -1
- package/dist/src/helpers/renewal.d.ts +0 -23
- package/dist/src/helpers/renewal.d.ts.map +0 -1
- package/dist/src/helpers/renewal.js +0 -90
- package/dist/src/helpers/renewal.js.map +0 -1
- package/dist/src/helpers/subscription.d.ts +0 -23
- package/dist/src/helpers/subscription.d.ts.map +0 -1
- package/dist/src/helpers/subscription.js +0 -101
- package/dist/src/helpers/subscription.js.map +0 -1
- package/dist/src/helpers/types.d.ts +0 -22
- package/dist/src/helpers/types.d.ts.map +0 -1
- package/dist/src/helpers/types.js +0 -7
- package/dist/src/helpers/types.js.map +0 -1
- package/dist/src/index.d.ts +0 -73
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -106
- package/dist/src/index.js.map +0 -1
- package/dist/src/mcp/auth-bridge.d.ts +0 -9
- package/dist/src/mcp/auth-bridge.d.ts.map +0 -1
- package/dist/src/mcp/auth-bridge.js +0 -46
- package/dist/src/mcp/auth-bridge.js.map +0 -1
- package/dist/src/mcp/oauth-bridge.d.ts +0 -48
- package/dist/src/mcp/oauth-bridge.d.ts.map +0 -1
- package/dist/src/mcp/oauth-bridge.js +0 -110
- package/dist/src/mcp/oauth-bridge.js.map +0 -1
- package/dist/src/mcp-auth.d.ts +0 -17
- package/dist/src/mcp-auth.d.ts.map +0 -1
- package/dist/src/mcp-auth.js +0 -57
- package/dist/src/mcp-auth.js.map +0 -1
- package/dist/src/paywall.d.ts +0 -119
- package/dist/src/paywall.d.ts.map +0 -1
- package/dist/src/paywall.js +0 -700
- package/dist/src/paywall.js.map +0 -1
- package/dist/src/register-virtual-tools-mcp.d.ts +0 -23
- package/dist/src/register-virtual-tools-mcp.d.ts.map +0 -1
- package/dist/src/register-virtual-tools-mcp.js +0 -86
- package/dist/src/register-virtual-tools-mcp.js.map +0 -1
- package/dist/src/types/client.d.ts +0 -216
- package/dist/src/types/client.d.ts.map +0 -1
- package/dist/src/types/client.js +0 -7
- package/dist/src/types/client.js.map +0 -1
- package/dist/src/types/generated.d.ts +0 -2834
- package/dist/src/types/generated.d.ts.map +0 -1
- package/dist/src/types/generated.js +0 -6
- package/dist/src/types/generated.js.map +0 -1
- package/dist/src/types/index.d.ts +0 -13
- package/dist/src/types/index.d.ts.map +0 -1
- package/dist/src/types/index.js +0 -8
- package/dist/src/types/index.js.map +0 -1
- package/dist/src/types/options.d.ts +0 -126
- package/dist/src/types/options.d.ts.map +0 -1
- package/dist/src/types/options.js +0 -8
- package/dist/src/types/options.js.map +0 -1
- package/dist/src/types/paywall.d.ts +0 -64
- package/dist/src/types/paywall.d.ts.map +0 -1
- package/dist/src/types/paywall.js +0 -7
- package/dist/src/types/paywall.js.map +0 -1
- package/dist/src/types/webhook.d.ts +0 -50
- package/dist/src/types/webhook.d.ts.map +0 -1
- package/dist/src/types/webhook.js +0 -2
- package/dist/src/types/webhook.js.map +0 -1
- package/dist/src/utils.d.ts +0 -110
- package/dist/src/utils.d.ts.map +0 -1
- package/dist/src/utils.js +0 -217
- package/dist/src/utils.js.map +0 -1
- package/dist/src/virtual-tools.d.ts +0 -44
- package/dist/src/virtual-tools.d.ts.map +0 -1
- package/dist/src/virtual-tools.js +0 -140
- package/dist/src/virtual-tools.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
package/dist/src/factory.js
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SolvaPay Factory
|
|
3
|
-
*
|
|
4
|
-
* Main entry point for creating SolvaPay instances with the unified payable API
|
|
5
|
-
*/
|
|
6
|
-
import { createSolvaPayClient } from './client';
|
|
7
|
-
import { SolvaPayPaywall } from './paywall';
|
|
8
|
-
import { HttpAdapter, NextAdapter, McpAdapter, createAdapterHandler } from './adapters';
|
|
9
|
-
import { SolvaPayError, getSolvaPayConfig } from '@solvapay/core';
|
|
10
|
-
import { createVirtualTools } from './virtual-tools';
|
|
11
|
-
import { registerVirtualToolsMcpImpl, } from './register-virtual-tools-mcp';
|
|
12
|
-
/**
|
|
13
|
-
* Create a SolvaPay instance with paywall protection capabilities.
|
|
14
|
-
*
|
|
15
|
-
* This factory function creates a SolvaPay instance that can be used to
|
|
16
|
-
* protect API endpoints, functions, and MCP tools with usage limits and
|
|
17
|
-
* purchase checks.
|
|
18
|
-
*
|
|
19
|
-
* @param config - Optional configuration object
|
|
20
|
-
* @param config.apiKey - API key for production use (defaults to `SOLVAPAY_SECRET_KEY` env var)
|
|
21
|
-
* @param config.apiClient - Custom API client for testing or advanced use cases
|
|
22
|
-
* @param config.apiBaseUrl - Optional API base URL override
|
|
23
|
-
* @returns SolvaPay instance with payable() method and API client access
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```typescript
|
|
27
|
-
* // Production: Use environment variable (recommended)
|
|
28
|
-
* const solvaPay = createSolvaPay();
|
|
29
|
-
*
|
|
30
|
-
* // Production: Pass API key explicitly
|
|
31
|
-
* const solvaPay = createSolvaPay({
|
|
32
|
-
* apiKey: process.env.SOLVAPAY_SECRET_KEY
|
|
33
|
-
* });
|
|
34
|
-
*
|
|
35
|
-
* // Testing: Use mock client
|
|
36
|
-
* const solvaPay = createSolvaPay({
|
|
37
|
-
* apiClient: mockClient
|
|
38
|
-
* });
|
|
39
|
-
*
|
|
40
|
-
* // Create payable handlers for your product
|
|
41
|
-
* const payable = solvaPay.payable({
|
|
42
|
-
* product: 'prd_myapi',
|
|
43
|
-
* plan: 'pln_premium'
|
|
44
|
-
* });
|
|
45
|
-
*
|
|
46
|
-
* // Protect endpoints with framework-specific adapters
|
|
47
|
-
* app.post('/tasks', payable.http(createTask)); // Express/Fastify
|
|
48
|
-
* export const POST = payable.next(createTask); // Next.js App Router
|
|
49
|
-
* const handler = payable.mcp(createTask); // MCP servers
|
|
50
|
-
* ```
|
|
51
|
-
*
|
|
52
|
-
* @see {@link SolvaPay} for the returned instance interface
|
|
53
|
-
* @see {@link CreateSolvaPayConfig} for configuration options
|
|
54
|
-
* @since 1.0.0
|
|
55
|
-
*/
|
|
56
|
-
export function createSolvaPay(config) {
|
|
57
|
-
// If no config provided, read from environment variables
|
|
58
|
-
let resolvedConfig;
|
|
59
|
-
if (!config) {
|
|
60
|
-
const envConfig = getSolvaPayConfig();
|
|
61
|
-
resolvedConfig = {
|
|
62
|
-
apiKey: envConfig.apiKey,
|
|
63
|
-
apiBaseUrl: envConfig.apiBaseUrl,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
resolvedConfig = config;
|
|
68
|
-
}
|
|
69
|
-
// Create or use provided API client
|
|
70
|
-
const apiClient = resolvedConfig.apiClient ||
|
|
71
|
-
createSolvaPayClient({
|
|
72
|
-
apiKey: resolvedConfig.apiKey,
|
|
73
|
-
apiBaseUrl: resolvedConfig.apiBaseUrl,
|
|
74
|
-
});
|
|
75
|
-
// Create paywall instance with debug flag controlled by environment variable
|
|
76
|
-
const paywall = new SolvaPayPaywall(apiClient, {
|
|
77
|
-
debug: process.env.SOLVAPAY_DEBUG !== 'false',
|
|
78
|
-
limitsCacheTTL: resolvedConfig.limitsCacheTTL,
|
|
79
|
-
});
|
|
80
|
-
return {
|
|
81
|
-
// Direct access to API client for advanced operations
|
|
82
|
-
apiClient,
|
|
83
|
-
// Common API methods exposed directly for convenience
|
|
84
|
-
ensureCustomer(customerRef, externalRef, options) {
|
|
85
|
-
return paywall.ensureCustomer(customerRef, externalRef, options);
|
|
86
|
-
},
|
|
87
|
-
createPaymentIntent(params) {
|
|
88
|
-
if (!apiClient.createPaymentIntent) {
|
|
89
|
-
throw new SolvaPayError('createPaymentIntent is not available on this API client');
|
|
90
|
-
}
|
|
91
|
-
return apiClient.createPaymentIntent(params);
|
|
92
|
-
},
|
|
93
|
-
processPaymentIntent(params) {
|
|
94
|
-
if (!apiClient.processPaymentIntent) {
|
|
95
|
-
throw new SolvaPayError('processPaymentIntent is not available on this API client');
|
|
96
|
-
}
|
|
97
|
-
return apiClient.processPaymentIntent(params);
|
|
98
|
-
},
|
|
99
|
-
checkLimits(params) {
|
|
100
|
-
return apiClient.checkLimits(params);
|
|
101
|
-
},
|
|
102
|
-
trackUsage(params) {
|
|
103
|
-
return apiClient.trackUsage(params);
|
|
104
|
-
},
|
|
105
|
-
createCustomer(params) {
|
|
106
|
-
if (!apiClient.createCustomer) {
|
|
107
|
-
throw new SolvaPayError('createCustomer is not available on this API client');
|
|
108
|
-
}
|
|
109
|
-
return apiClient.createCustomer({ ...params, metadata: params.metadata ?? {} });
|
|
110
|
-
},
|
|
111
|
-
getCustomer(params) {
|
|
112
|
-
return apiClient.getCustomer(params);
|
|
113
|
-
},
|
|
114
|
-
createCheckoutSession(params) {
|
|
115
|
-
return apiClient.createCheckoutSession({
|
|
116
|
-
customerRef: params.customerRef,
|
|
117
|
-
productRef: params.productRef,
|
|
118
|
-
planRef: params.planRef,
|
|
119
|
-
});
|
|
120
|
-
},
|
|
121
|
-
createCustomerSession(params) {
|
|
122
|
-
return apiClient.createCustomerSession(params);
|
|
123
|
-
},
|
|
124
|
-
bootstrapMcpProduct(params) {
|
|
125
|
-
if (!apiClient.bootstrapMcpProduct) {
|
|
126
|
-
throw new SolvaPayError('bootstrapMcpProduct is not available on this API client');
|
|
127
|
-
}
|
|
128
|
-
return apiClient.bootstrapMcpProduct(params);
|
|
129
|
-
},
|
|
130
|
-
configureMcpPlans(productRef, params) {
|
|
131
|
-
if (!apiClient.configureMcpPlans) {
|
|
132
|
-
throw new SolvaPayError('configureMcpPlans is not available on this API client');
|
|
133
|
-
}
|
|
134
|
-
return apiClient.configureMcpPlans(productRef, params);
|
|
135
|
-
},
|
|
136
|
-
getVirtualTools(options) {
|
|
137
|
-
return createVirtualTools(apiClient, options);
|
|
138
|
-
},
|
|
139
|
-
async registerVirtualToolsMcp(server, options) {
|
|
140
|
-
await registerVirtualToolsMcpImpl(server, apiClient, options);
|
|
141
|
-
},
|
|
142
|
-
// Payable API for framework-specific handlers
|
|
143
|
-
payable(options = {}) {
|
|
144
|
-
// Resolve product name (support both productRef and product)
|
|
145
|
-
const product = options.productRef ||
|
|
146
|
-
options.product ||
|
|
147
|
-
process.env.SOLVAPAY_PRODUCT ||
|
|
148
|
-
'default-product';
|
|
149
|
-
// Resolve plan (support both planRef and plan)
|
|
150
|
-
const plan = options.planRef || options.plan;
|
|
151
|
-
const usageType = options.usageType || 'requests';
|
|
152
|
-
const metadata = { product, plan, usageType };
|
|
153
|
-
return {
|
|
154
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
155
|
-
http(
|
|
156
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
157
|
-
businessLogic, adapterOptions) {
|
|
158
|
-
const adapter = new HttpAdapter({
|
|
159
|
-
...adapterOptions,
|
|
160
|
-
getCustomerRef: adapterOptions?.getCustomerRef || options.getCustomerRef,
|
|
161
|
-
});
|
|
162
|
-
const handlerPromise = createAdapterHandler(adapter, paywall, metadata, businessLogic);
|
|
163
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
164
|
-
return async (req, reply) => {
|
|
165
|
-
const handler = await handlerPromise;
|
|
166
|
-
return handler([req, reply]);
|
|
167
|
-
};
|
|
168
|
-
},
|
|
169
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
170
|
-
next(
|
|
171
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
172
|
-
businessLogic, adapterOptions) {
|
|
173
|
-
const adapter = new NextAdapter({
|
|
174
|
-
...adapterOptions,
|
|
175
|
-
getCustomerRef: adapterOptions?.getCustomerRef || options.getCustomerRef,
|
|
176
|
-
});
|
|
177
|
-
const handlerPromise = createAdapterHandler(adapter, paywall, metadata, businessLogic);
|
|
178
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
179
|
-
return async (request, context) => {
|
|
180
|
-
const handler = await handlerPromise;
|
|
181
|
-
return handler([request, context]);
|
|
182
|
-
};
|
|
183
|
-
},
|
|
184
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
185
|
-
mcp(
|
|
186
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
187
|
-
businessLogic, adapterOptions) {
|
|
188
|
-
const adapter = new McpAdapter({
|
|
189
|
-
...adapterOptions,
|
|
190
|
-
getCustomerRef: adapterOptions?.getCustomerRef || options.getCustomerRef,
|
|
191
|
-
});
|
|
192
|
-
const handlerPromise = createAdapterHandler(adapter, paywall, metadata, businessLogic);
|
|
193
|
-
return async (args, extra) => {
|
|
194
|
-
const handler = await handlerPromise;
|
|
195
|
-
return handler(args, extra);
|
|
196
|
-
};
|
|
197
|
-
},
|
|
198
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
199
|
-
async function(
|
|
200
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
201
|
-
businessLogic) {
|
|
202
|
-
const getCustomerRef = (args) => {
|
|
203
|
-
const configuredRef = options.getCustomerRef?.(args);
|
|
204
|
-
if (typeof configuredRef === 'string') {
|
|
205
|
-
return configuredRef;
|
|
206
|
-
}
|
|
207
|
-
return args.auth?.customer_ref || 'anonymous';
|
|
208
|
-
};
|
|
209
|
-
return paywall.protect(businessLogic, metadata, getCustomerRef);
|
|
210
|
-
},
|
|
211
|
-
};
|
|
212
|
-
},
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
//# sourceMappingURL=factory.js.map
|
package/dist/src/factory.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../src/factory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAgBH,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AACvF,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAEpD,OAAO,EACL,2BAA2B,GAG5B,MAAM,8BAA8B,CAAA;AAwlBrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,MAAM,UAAU,cAAc,CAAC,MAA6B;IAC1D,yDAAyD;IACzD,IAAI,cAAoC,CAAA;IACxC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,SAAS,GAAG,iBAAiB,EAAE,CAAA;QACrC,cAAc,GAAG;YACf,MAAM,EAAE,SAAS,CAAC,MAAM;YACxB,UAAU,EAAE,SA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O,OAAO,CAAC,OAAO,CAAC,aAAa,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAA;gBACjE,CAAC;aACF,CAAA;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Authentication Helper (Core)
|
|
3
|
-
*
|
|
4
|
-
* Generic helper for extracting authenticated user information from requests.
|
|
5
|
-
* Works with standard Web API Request (works everywhere).
|
|
6
|
-
*/
|
|
7
|
-
import type { AuthenticatedUser, ErrorResult } from './types';
|
|
8
|
-
/**
|
|
9
|
-
* Extract authenticated user information from a standard Web API Request.
|
|
10
|
-
*
|
|
11
|
-
* This is a generic, framework-agnostic helper that extracts user ID, email,
|
|
12
|
-
* and name from authenticated requests. Works with any framework that uses
|
|
13
|
-
* the standard Web API Request (Express, Fastify, Next.js, Edge Functions, etc.).
|
|
14
|
-
*
|
|
15
|
-
* Uses dynamic imports to avoid requiring @solvapay/auth at build time,
|
|
16
|
-
* making it suitable for edge runtime environments.
|
|
17
|
-
*
|
|
18
|
-
* @param request - Standard Web API Request object
|
|
19
|
-
* @param options - Configuration options
|
|
20
|
-
* @param options.includeEmail - Whether to extract email from JWT token (default: true)
|
|
21
|
-
* @param options.includeName - Whether to extract name from JWT token (default: true)
|
|
22
|
-
* @returns Authenticated user info or error result
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```typescript
|
|
26
|
-
* // In an API route handler
|
|
27
|
-
* export async function GET(request: Request) {
|
|
28
|
-
* const userResult = await getAuthenticatedUserCore(request);
|
|
29
|
-
*
|
|
30
|
-
* if (isErrorResult(userResult)) {
|
|
31
|
-
* return Response.json(userResult, { status: userResult.status });
|
|
32
|
-
* }
|
|
33
|
-
*
|
|
34
|
-
* const { userId, email, name } = userResult;
|
|
35
|
-
* // Use user info...
|
|
36
|
-
* }
|
|
37
|
-
* ```
|
|
38
|
-
*
|
|
39
|
-
* @see {@link AuthenticatedUser} for the return type
|
|
40
|
-
* @see {@link ErrorResult} for error handling
|
|
41
|
-
* @since 1.0.0
|
|
42
|
-
*/
|
|
43
|
-
export declare function getAuthenticatedUserCore(request: Request, options?: {
|
|
44
|
-
includeEmail?: boolean;
|
|
45
|
-
includeName?: boolean;
|
|
46
|
-
}): Promise<AuthenticatedUser | ErrorResult>;
|
|
47
|
-
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/helpers/auth.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAG7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE;IACP,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,WAAW,CAAC,EAAE,OAAO,CAAA;CACjB,GACL,OAAO,CAAC,iBAAiB,GAAG,WAAW,CAAC,CAiC1C"}
|
package/dist/src/helpers/auth.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Authentication Helper (Core)
|
|
3
|
-
*
|
|
4
|
-
* Generic helper for extracting authenticated user information from requests.
|
|
5
|
-
* Works with standard Web API Request (works everywhere).
|
|
6
|
-
*/
|
|
7
|
-
import { handleRouteError } from './error';
|
|
8
|
-
/**
|
|
9
|
-
* Extract authenticated user information from a standard Web API Request.
|
|
10
|
-
*
|
|
11
|
-
* This is a generic, framework-agnostic helper that extracts user ID, email,
|
|
12
|
-
* and name from authenticated requests. Works with any framework that uses
|
|
13
|
-
* the standard Web API Request (Express, Fastify, Next.js, Edge Functions, etc.).
|
|
14
|
-
*
|
|
15
|
-
* Uses dynamic imports to avoid requiring @solvapay/auth at build time,
|
|
16
|
-
* making it suitable for edge runtime environments.
|
|
17
|
-
*
|
|
18
|
-
* @param request - Standard Web API Request object
|
|
19
|
-
* @param options - Configuration options
|
|
20
|
-
* @param options.includeEmail - Whether to extract email from JWT token (default: true)
|
|
21
|
-
* @param options.includeName - Whether to extract name from JWT token (default: true)
|
|
22
|
-
* @returns Authenticated user info or error result
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```typescript
|
|
26
|
-
* // In an API route handler
|
|
27
|
-
* export async function GET(request: Request) {
|
|
28
|
-
* const userResult = await getAuthenticatedUserCore(request);
|
|
29
|
-
*
|
|
30
|
-
* if (isErrorResult(userResult)) {
|
|
31
|
-
* return Response.json(userResult, { status: userResult.status });
|
|
32
|
-
* }
|
|
33
|
-
*
|
|
34
|
-
* const { userId, email, name } = userResult;
|
|
35
|
-
* // Use user info...
|
|
36
|
-
* }
|
|
37
|
-
* ```
|
|
38
|
-
*
|
|
39
|
-
* @see {@link AuthenticatedUser} for the return type
|
|
40
|
-
* @see {@link ErrorResult} for error handling
|
|
41
|
-
* @since 1.0.0
|
|
42
|
-
*/
|
|
43
|
-
export async function getAuthenticatedUserCore(request, options = {}) {
|
|
44
|
-
try {
|
|
45
|
-
// Dynamic import to avoid requiring auth package if not needed
|
|
46
|
-
const { requireUserId, getUserEmailFromRequest, getUserNameFromRequest } = await import('@solvapay/auth');
|
|
47
|
-
// Get userId from middleware/auth (set by middleware.ts or auth adapter)
|
|
48
|
-
const userIdOrError = requireUserId(request);
|
|
49
|
-
if (userIdOrError instanceof Response) {
|
|
50
|
-
// Convert Response to ErrorResult
|
|
51
|
-
const clonedResponse = userIdOrError.clone();
|
|
52
|
-
const body = await clonedResponse.json().catch(() => ({ error: 'Unauthorized' }));
|
|
53
|
-
return {
|
|
54
|
-
error: body.error || 'Unauthorized',
|
|
55
|
-
status: userIdOrError.status,
|
|
56
|
-
details: body.error || 'Unauthorized',
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
const userId = userIdOrError;
|
|
60
|
-
// Get user email and name from JWT token if requested
|
|
61
|
-
const email = options.includeEmail !== false ? await getUserEmailFromRequest(request) : null;
|
|
62
|
-
const name = options.includeName !== false ? await getUserNameFromRequest(request) : null;
|
|
63
|
-
return {
|
|
64
|
-
userId,
|
|
65
|
-
email,
|
|
66
|
-
name,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
return handleRouteError(error, 'Get authenticated user', 'Authentication failed');
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
//# sourceMappingURL=auth.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/helpers/auth.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,OAAgB,EAChB,UAGI,EAAE;IAEN,IAAI,CAAC;QACH,+DAA+D;QAC/D,MAAM,EAAE,aAAa,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,GAAG,MAAM,MAAM,CACrF,gBAAgB,CACjB,CAAA;QAED,yEAAyE;QACzE,MAAM,aAAa,GAAG,aAAa,CAAC,OAAO,CAAC,CAAA;QAC5C,IAAI,aAAa,YAAY,QAAQ,EAAE,CAAC;YACtC,kCAAkC;YAClC,MAAM,cAAc,GAAG,aAAa,CAAC,KAAK,EAAE,CAAA;YAC5C,MAAM,IAAI,GAAG,MAAM,cAAc,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,CAAC,CAAA;YACjF,OAAO;gBACL,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,cAAc;gBACnC,MAAM,EAAE,aAAa,CAAC,MAAM;gBAC5B,OAAO,EAAE,IAAI,CAAC,KAAK,IAAI,cAAc;aACtC,CAAA;QACH,CAAC;QACD,MAAM,MAAM,GAAG,aAAa,CAAA;QAE5B,sDAAsD;QACtD,MAAM,KAAK,GAAG,OAAO,CAAC,YAAY,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,uBAAuB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;QAC5F,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,sBAAsB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;QAEzF,OAAO;YACL,MAAM;YACN,KAAK;YACL,IAAI;SACL,CAAA;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,gBAAgB,CAAC,KAAK,EAAE,wBAAwB,EAAE,uBAAuB,CAAC,CAAA;IACnF,CAAC;AACH,CAAC"}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checkout Helpers (Core)
|
|
3
|
-
*
|
|
4
|
-
* Generic helpers for checkout session operations.
|
|
5
|
-
* Works with standard Web API Request (works everywhere).
|
|
6
|
-
*/
|
|
7
|
-
import type { SolvaPay } from '../factory';
|
|
8
|
-
import type { ErrorResult } from './types';
|
|
9
|
-
/**
|
|
10
|
-
* Create checkout session - core implementation
|
|
11
|
-
*
|
|
12
|
-
* @param request - Standard Web API Request
|
|
13
|
-
* @param body - Checkout session parameters
|
|
14
|
-
* @param options - Configuration options
|
|
15
|
-
* @returns Checkout session response or error result
|
|
16
|
-
*/
|
|
17
|
-
export declare function createCheckoutSessionCore(request: Request, body: {
|
|
18
|
-
productRef: string;
|
|
19
|
-
planRef?: string;
|
|
20
|
-
returnUrl?: string;
|
|
21
|
-
}, options?: {
|
|
22
|
-
solvaPay?: SolvaPay;
|
|
23
|
-
includeEmail?: boolean;
|
|
24
|
-
includeName?: boolean;
|
|
25
|
-
returnUrl?: string;
|
|
26
|
-
}): Promise<{
|
|
27
|
-
sessionId: string;
|
|
28
|
-
checkoutUrl: string;
|
|
29
|
-
} | ErrorResult>;
|
|
30
|
-
/**
|
|
31
|
-
* Create customer session - core implementation
|
|
32
|
-
*
|
|
33
|
-
* @param request - Standard Web API Request
|
|
34
|
-
* @param options - Configuration options
|
|
35
|
-
* @returns Customer session response or error result
|
|
36
|
-
*/
|
|
37
|
-
export declare function createCustomerSessionCore(request: Request, options?: {
|
|
38
|
-
solvaPay?: SolvaPay;
|
|
39
|
-
includeEmail?: boolean;
|
|
40
|
-
includeName?: boolean;
|
|
41
|
-
}): Promise<{
|
|
42
|
-
sessionId: string;
|
|
43
|
-
customerUrl: string;
|
|
44
|
-
} | ErrorResult>;
|
|
45
|
-
//# sourceMappingURL=checkout.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../../../src/helpers/checkout.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAK1C;;;;;;;GAOG;AACH,wBAAsB,yBAAyB,CAC7C,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE;IACJ,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,EACD,OAAO,GAAE;IACP,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,SAAS,CAAC,EAAE,MAAM,CAAA;CACd,GACL,OAAO,CACN;IACE,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;CACpB,GACD,WAAW,CACd,CA+CA;AAED;;;;;;GAMG;AACH,wBAAsB,yBAAyB,CAC7C,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE;IACP,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,WAAW,CAAC,EAAE,OAAO,CAAA;CACjB,GACL,OAAO,CACN;IACE,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;CACpB,GACD,WAAW,CACd,CAwBA"}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checkout Helpers (Core)
|
|
3
|
-
*
|
|
4
|
-
* Generic helpers for checkout session operations.
|
|
5
|
-
* Works with standard Web API Request (works everywhere).
|
|
6
|
-
*/
|
|
7
|
-
import { createSolvaPay } from '../factory';
|
|
8
|
-
import { handleRouteError, isErrorResult } from './error';
|
|
9
|
-
import { syncCustomerCore } from './customer';
|
|
10
|
-
/**
|
|
11
|
-
* Create checkout session - core implementation
|
|
12
|
-
*
|
|
13
|
-
* @param request - Standard Web API Request
|
|
14
|
-
* @param body - Checkout session parameters
|
|
15
|
-
* @param options - Configuration options
|
|
16
|
-
* @returns Checkout session response or error result
|
|
17
|
-
*/
|
|
18
|
-
export async function createCheckoutSessionCore(request, body, options = {}) {
|
|
19
|
-
try {
|
|
20
|
-
if (!body.productRef) {
|
|
21
|
-
return {
|
|
22
|
-
error: 'Missing required parameter: productRef is required',
|
|
23
|
-
status: 400,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
const customerResult = await syncCustomerCore(request, {
|
|
27
|
-
solvaPay: options.solvaPay,
|
|
28
|
-
includeEmail: options.includeEmail,
|
|
29
|
-
includeName: options.includeName,
|
|
30
|
-
});
|
|
31
|
-
if (isErrorResult(customerResult)) {
|
|
32
|
-
return customerResult;
|
|
33
|
-
}
|
|
34
|
-
const customerRef = customerResult;
|
|
35
|
-
let returnUrl = body.returnUrl || options.returnUrl;
|
|
36
|
-
if (!returnUrl) {
|
|
37
|
-
try {
|
|
38
|
-
const url = new URL(request.url);
|
|
39
|
-
returnUrl = url.origin;
|
|
40
|
-
}
|
|
41
|
-
catch {
|
|
42
|
-
// If URL parsing fails, continue without returnUrl
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
const solvaPay = options.solvaPay || createSolvaPay();
|
|
46
|
-
const session = await solvaPay.createCheckoutSession({
|
|
47
|
-
productRef: body.productRef,
|
|
48
|
-
customerRef,
|
|
49
|
-
planRef: body.planRef || undefined,
|
|
50
|
-
returnUrl: returnUrl,
|
|
51
|
-
});
|
|
52
|
-
return {
|
|
53
|
-
sessionId: session.sessionId,
|
|
54
|
-
checkoutUrl: session.checkoutUrl,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
return handleRouteError(error, 'Create checkout session', 'Checkout session creation failed');
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Create customer session - core implementation
|
|
63
|
-
*
|
|
64
|
-
* @param request - Standard Web API Request
|
|
65
|
-
* @param options - Configuration options
|
|
66
|
-
* @returns Customer session response or error result
|
|
67
|
-
*/
|
|
68
|
-
export async function createCustomerSessionCore(request, options = {}) {
|
|
69
|
-
try {
|
|
70
|
-
const customerResult = await syncCustomerCore(request, {
|
|
71
|
-
solvaPay: options.solvaPay,
|
|
72
|
-
includeEmail: options.includeEmail,
|
|
73
|
-
includeName: options.includeName,
|
|
74
|
-
});
|
|
75
|
-
if (isErrorResult(customerResult)) {
|
|
76
|
-
return customerResult;
|
|
77
|
-
}
|
|
78
|
-
const customerRef = customerResult;
|
|
79
|
-
const solvaPay = options.solvaPay || createSolvaPay();
|
|
80
|
-
const session = await solvaPay.createCustomerSession({
|
|
81
|
-
customerRef,
|
|
82
|
-
});
|
|
83
|
-
return session;
|
|
84
|
-
}
|
|
85
|
-
catch (error) {
|
|
86
|
-
return handleRouteError(error, 'Create customer session', 'Customer session creation failed');
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
//# sourceMappingURL=checkout.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,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
-
* Works with standard Web API Request (works everywhere).
|
|
6
|
-
*/
|
|
7
|
-
import type { SolvaPay } from '../factory';
|
|
8
|
-
import type { ErrorResult } from './types';
|
|
9
|
-
/**
|
|
10
|
-
* Sync customer with SolvaPay backend (ensure customer exists).
|
|
11
|
-
*
|
|
12
|
-
* This helper ensures a customer exists in the SolvaPay backend by:
|
|
13
|
-
* 1. Extracting authenticated user information from the request
|
|
14
|
-
* 2. Creating or retrieving the customer using the user ID as external reference
|
|
15
|
-
* 3. Syncing customer data (email, name) if provided
|
|
16
|
-
*
|
|
17
|
-
* Uses `externalRef` for consistent lookup and prevents duplicate customers.
|
|
18
|
-
* The returned customer reference is the SolvaPay backend customer ID.
|
|
19
|
-
*
|
|
20
|
-
* @param request - Standard Web API Request object
|
|
21
|
-
* @param options - Configuration options
|
|
22
|
-
* @param options.solvaPay - Optional SolvaPay instance (creates new one if not provided)
|
|
23
|
-
* @param options.includeEmail - Whether to include email in customer data (default: true)
|
|
24
|
-
* @param options.includeName - Whether to include name in customer data (default: true)
|
|
25
|
-
* @returns Customer reference (backend customer ID) or error result
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```typescript
|
|
29
|
-
* // In an API route handler
|
|
30
|
-
* export async function POST(request: Request) {
|
|
31
|
-
* const customerResult = await syncCustomerCore(request);
|
|
32
|
-
*
|
|
33
|
-
* if (isErrorResult(customerResult)) {
|
|
34
|
-
* return Response.json(customerResult, { status: customerResult.status });
|
|
35
|
-
* }
|
|
36
|
-
*
|
|
37
|
-
* const customerRef = customerResult;
|
|
38
|
-
* // Use customer reference...
|
|
39
|
-
* }
|
|
40
|
-
* ```
|
|
41
|
-
*
|
|
42
|
-
* @see {@link getAuthenticatedUserCore} for user extraction
|
|
43
|
-
* @see {@link ErrorResult} for error handling
|
|
44
|
-
* @since 1.0.0
|
|
45
|
-
*/
|
|
46
|
-
export declare function syncCustomerCore(request: Request, options?: {
|
|
47
|
-
solvaPay?: SolvaPay;
|
|
48
|
-
includeEmail?: boolean;
|
|
49
|
-
includeName?: boolean;
|
|
50
|
-
}): Promise<string | ErrorResult>;
|
|
51
|
-
//# sourceMappingURL=customer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"customer.d.ts","sourceRoot":"","sources":["../../../src/helpers/customer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAK1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE;IACP,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,WAAW,CAAC,EAAE,OAAO,CAAA;CACjB,GACL,OAAO,CAAC,MAAM,GAAG,WAAW,CAAC,CAiC/B"}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Customer Helper (Core)
|
|
3
|
-
*
|
|
4
|
-
* Generic helper for syncing customers with SolvaPay backend.
|
|
5
|
-
* Works with standard Web API Request (works everywhere).
|
|
6
|
-
*/
|
|
7
|
-
import { createSolvaPay } from '../factory';
|
|
8
|
-
import { handleRouteError, isErrorResult } from './error';
|
|
9
|
-
import { getAuthenticatedUserCore } from './auth';
|
|
10
|
-
/**
|
|
11
|
-
* Sync customer with SolvaPay backend (ensure customer exists).
|
|
12
|
-
*
|
|
13
|
-
* This helper ensures a customer exists in the SolvaPay backend by:
|
|
14
|
-
* 1. Extracting authenticated user information from the request
|
|
15
|
-
* 2. Creating or retrieving the customer using the user ID as external reference
|
|
16
|
-
* 3. Syncing customer data (email, name) if provided
|
|
17
|
-
*
|
|
18
|
-
* Uses `externalRef` for consistent lookup and prevents duplicate customers.
|
|
19
|
-
* The returned customer reference is the SolvaPay backend customer ID.
|
|
20
|
-
*
|
|
21
|
-
* @param request - Standard Web API Request object
|
|
22
|
-
* @param options - Configuration options
|
|
23
|
-
* @param options.solvaPay - Optional SolvaPay instance (creates new one if not provided)
|
|
24
|
-
* @param options.includeEmail - Whether to include email in customer data (default: true)
|
|
25
|
-
* @param options.includeName - Whether to include name in customer data (default: true)
|
|
26
|
-
* @returns Customer reference (backend customer ID) or error result
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```typescript
|
|
30
|
-
* // In an API route handler
|
|
31
|
-
* export async function POST(request: Request) {
|
|
32
|
-
* const customerResult = await syncCustomerCore(request);
|
|
33
|
-
*
|
|
34
|
-
* if (isErrorResult(customerResult)) {
|
|
35
|
-
* return Response.json(customerResult, { status: customerResult.status });
|
|
36
|
-
* }
|
|
37
|
-
*
|
|
38
|
-
* const customerRef = customerResult;
|
|
39
|
-
* // Use customer reference...
|
|
40
|
-
* }
|
|
41
|
-
* ```
|
|
42
|
-
*
|
|
43
|
-
* @see {@link getAuthenticatedUserCore} for user extraction
|
|
44
|
-
* @see {@link ErrorResult} for error handling
|
|
45
|
-
* @since 1.0.0
|
|
46
|
-
*/
|
|
47
|
-
export async function syncCustomerCore(request, options = {}) {
|
|
48
|
-
try {
|
|
49
|
-
// Get authenticated user
|
|
50
|
-
const userResult = await getAuthenticatedUserCore(request, {
|
|
51
|
-
includeEmail: options.includeEmail,
|
|
52
|
-
includeName: options.includeName,
|
|
53
|
-
});
|
|
54
|
-
if (isErrorResult(userResult)) {
|
|
55
|
-
return userResult;
|
|
56
|
-
}
|
|
57
|
-
const { userId, email, name } = userResult;
|
|
58
|
-
// Use provided SolvaPay instance or create new one
|
|
59
|
-
const solvaPay = options.solvaPay || createSolvaPay();
|
|
60
|
-
// Use userId as cache key (first param) and externalRef (second param)
|
|
61
|
-
// The first parameter (customerRef) is used as a cache key
|
|
62
|
-
// The second parameter (externalRef) is stored on the SolvaPay backend for customer lookup
|
|
63
|
-
// This ensures consistent lookup and prevents duplicate customers
|
|
64
|
-
// Pass email and name to ensure correct customer data
|
|
65
|
-
// Note: Customer lookup deduplication is handled automatically by the SDK
|
|
66
|
-
// The returned customerRef is the SolvaPay backend customer reference (different from Supabase user ID)
|
|
67
|
-
const customerRef = await solvaPay.ensureCustomer(userId, userId, {
|
|
68
|
-
email: email || undefined,
|
|
69
|
-
name: name || undefined,
|
|
70
|
-
});
|
|
71
|
-
return customerRef;
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
return handleRouteError(error, 'Sync customer', 'Failed to sync customer');
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
//# sourceMappingURL=customer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"customer.js","sourceRoot":"","sources":["../../../src/helpers/customer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,QAAQ,CAAA;AAEjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAAgB,EAChB,UAII,EAAE;IAEN,IAAI,CAAC;QACH,yBAAyB;QACzB,MAAM,UAAU,GAAG,MAAM,wBAAwB,CAAC,OAAO,EAAE;YACzD,YAAY,EAAE,OAAO,CAAC,YAAY;YAClC,WAAW,EAAE,OAAO,CAAC,WAAW;SACjC,CAAC,CAAA;QAEF,IAAI,aAAa,CAAC,UAAU,CAAC,EAAE,CAAC;YAC9B,OAAO,UAAU,CAAA;QACnB,CAAC;QAED,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,UAAU,CAAA;QAE1C,mDAAmD;QACnD,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,cAAc,EAAE,CAAA;QAErD,uEAAuE;QACvE,2DAA2D;QAC3D,2FAA2F;QAC3F,kEAAkE;QAClE,sDAAsD;QACtD,0EAA0E;QAC1E,wGAAwG;QACxG,MAAM,WAAW,GAAG,MAAM,QAAQ,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE;YAChE,KAAK,EAAE,KAAK,IAAI,SAAS;YACzB,IAAI,EAAE,IAAI,IAAI,SAAS;SACxB,CAAC,CAAA;QAEF,OAAO,WAAW,CAAA;IACpB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,gBAAgB,CAAC,KAAK,EAAE,eAAe,EAAE,yBAAyB,CAAC,CAAA;IAC5E,CAAC;AACH,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Error Handling Helper
|
|
3
|
-
*
|
|
4
|
-
* Generic error handling utilities for route helpers
|
|
5
|
-
*/
|
|
6
|
-
import type { ErrorResult } from './types';
|
|
7
|
-
/**
|
|
8
|
-
* Check if a result is an error result
|
|
9
|
-
*/
|
|
10
|
-
export declare function isErrorResult(result: unknown): result is ErrorResult;
|
|
11
|
-
/**
|
|
12
|
-
* Handle route errors and convert to ErrorResult
|
|
13
|
-
*/
|
|
14
|
-
export declare function handleRouteError(error: unknown, operationName: string, defaultMessage?: string): ErrorResult;
|
|
15
|
-
//# sourceMappingURL=error.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../src/helpers/error.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE1C;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,WAAW,CAEpE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,OAAO,EACd,aAAa,EAAE,MAAM,EACrB,cAAc,CAAC,EAAE,MAAM,GACtB,WAAW,CAqBb"}
|