@solvapay/next 1.0.9-preview.1 → 1.0.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/index.js CHANGED
@@ -4,8 +4,8 @@ import {
4
4
  } from "./chunk-F7TBIH6W.js";
5
5
 
6
6
  // src/index.ts
7
- import { NextResponse as NextResponse9 } from "next/server";
8
- import { checkPurchaseCore, isErrorResult as isErrorResult9 } from "@solvapay/server";
7
+ import { NextResponse as NextResponse4 } from "next/server";
8
+ import { checkPurchaseCore } from "@solvapay/server";
9
9
 
10
10
  // src/cache.ts
11
11
  function createRequestDeduplicator(options = {}) {
@@ -137,16 +137,29 @@ function getPurchaseCacheStats() {
137
137
  return deduplicator.getStats();
138
138
  }
139
139
 
140
- // src/helpers/auth.ts
140
+ // src/helpers/_response.ts
141
141
  import { NextResponse } from "next/server";
142
+ import { isErrorResult } from "@solvapay/server";
143
+ function toNextRouteResponse(result) {
144
+ if (isErrorResult(result)) {
145
+ return NextResponse.json(
146
+ { error: result.error, details: result.details },
147
+ { status: result.status }
148
+ );
149
+ }
150
+ return NextResponse.json(result);
151
+ }
152
+
153
+ // src/helpers/auth.ts
154
+ import { NextResponse as NextResponse2 } from "next/server";
142
155
  import {
143
156
  getAuthenticatedUserCore,
144
- isErrorResult
157
+ isErrorResult as isErrorResult2
145
158
  } from "@solvapay/server";
146
159
  async function getAuthenticatedUser(request, options = {}) {
147
160
  const result = await getAuthenticatedUserCore(request, options);
148
- if (isErrorResult(result)) {
149
- return NextResponse.json(
161
+ if (isErrorResult2(result)) {
162
+ return NextResponse2.json(
150
163
  { error: result.error, details: result.details },
151
164
  { status: result.status }
152
165
  );
@@ -155,12 +168,12 @@ async function getAuthenticatedUser(request, options = {}) {
155
168
  }
156
169
 
157
170
  // src/helpers/customer.ts
158
- import { NextResponse as NextResponse2 } from "next/server";
159
- import { syncCustomerCore, getCustomerBalanceCore, isErrorResult as isErrorResult2 } from "@solvapay/server";
171
+ import { NextResponse as NextResponse3 } from "next/server";
172
+ import { syncCustomerCore, getCustomerBalanceCore, isErrorResult as isErrorResult3 } from "@solvapay/server";
160
173
  async function syncCustomer(request, options = {}) {
161
174
  const result = await syncCustomerCore(request, options);
162
- if (isErrorResult2(result)) {
163
- return NextResponse2.json(
175
+ if (isErrorResult3(result)) {
176
+ return NextResponse3.json(
164
177
  { error: result.error, details: result.details },
165
178
  { status: result.status }
166
179
  );
@@ -169,195 +182,130 @@ async function syncCustomer(request, options = {}) {
169
182
  }
170
183
  async function getCustomerBalance(request, options = {}) {
171
184
  const result = await getCustomerBalanceCore(request, options);
172
- if (isErrorResult2(result)) {
173
- return NextResponse2.json(
174
- { error: result.error, details: result.details },
175
- { status: result.status }
176
- );
177
- }
178
- return result;
185
+ return toNextRouteResponse(result);
179
186
  }
180
187
 
181
188
  // src/helpers/payment.ts
182
- import { NextResponse as NextResponse3 } from "next/server";
183
189
  import {
184
190
  createPaymentIntentCore,
185
191
  createTopupPaymentIntentCore,
186
192
  processPaymentIntentCore,
187
- isErrorResult as isErrorResult3
193
+ isErrorResult as isErrorResult5
188
194
  } from "@solvapay/server";
189
- import { getAuthenticatedUserCore as getAuthenticatedUserCore2 } from "@solvapay/server";
190
- async function createPaymentIntent(request, body, options = {}) {
191
- const result = await createPaymentIntentCore(request, body, options);
192
- if (isErrorResult3(result)) {
193
- return NextResponse3.json(
194
- { error: result.error, details: result.details },
195
- { status: result.status }
196
- );
197
- }
195
+
196
+ // src/helpers/_cache.ts
197
+ import { isErrorResult as isErrorResult4, getAuthenticatedUserCore as getAuthenticatedUserCore2 } from "@solvapay/server";
198
+ async function invalidatePurchaseCacheForRequest(request) {
198
199
  try {
199
200
  const userResult = await getAuthenticatedUserCore2(request);
200
- if (!isErrorResult3(userResult)) {
201
+ if (!isErrorResult4(userResult)) {
201
202
  clearPurchaseCache(userResult.userId);
202
203
  }
203
204
  } catch {
204
205
  }
205
- return result;
206
+ }
207
+
208
+ // src/helpers/payment.ts
209
+ async function createPaymentIntent(request, body, options = {}) {
210
+ const result = await createPaymentIntentCore(request, body, options);
211
+ if (!isErrorResult5(result)) {
212
+ await invalidatePurchaseCacheForRequest(request);
213
+ }
214
+ return toNextRouteResponse(result);
206
215
  }
207
216
  async function createTopupPaymentIntent(request, body, options = {}) {
208
217
  const result = await createTopupPaymentIntentCore(request, body, options);
209
- if (isErrorResult3(result)) {
210
- return NextResponse3.json(
211
- { error: result.error, details: result.details },
212
- { status: result.status }
213
- );
214
- }
215
- try {
216
- const userResult = await getAuthenticatedUserCore2(request);
217
- if (!isErrorResult3(userResult)) {
218
- clearPurchaseCache(userResult.userId);
219
- }
220
- } catch {
218
+ if (!isErrorResult5(result)) {
219
+ await invalidatePurchaseCacheForRequest(request);
221
220
  }
222
- return result;
221
+ return toNextRouteResponse(result);
223
222
  }
224
223
  async function processPaymentIntent(request, body, options = {}) {
225
224
  const result = await processPaymentIntentCore(request, body, options);
226
- if (isErrorResult3(result)) {
227
- return NextResponse3.json(
228
- { error: result.error, details: result.details },
229
- { status: result.status }
230
- );
225
+ if (!isErrorResult5(result)) {
226
+ await invalidatePurchaseCacheForRequest(request);
231
227
  }
232
- try {
233
- const userResult = await getAuthenticatedUserCore2(request);
234
- if (!isErrorResult3(userResult)) {
235
- clearPurchaseCache(userResult.userId);
236
- }
237
- } catch {
238
- }
239
- return result;
228
+ return toNextRouteResponse(result);
240
229
  }
241
230
 
242
231
  // src/helpers/checkout.ts
243
- import { NextResponse as NextResponse4 } from "next/server";
244
232
  import {
245
233
  createCheckoutSessionCore,
246
- createCustomerSessionCore,
247
- isErrorResult as isErrorResult4
234
+ createCustomerSessionCore
248
235
  } from "@solvapay/server";
249
236
  async function createCheckoutSession(request, body, options = {}) {
250
237
  const result = await createCheckoutSessionCore(request, body, options);
251
- if (isErrorResult4(result)) {
252
- return NextResponse4.json(
253
- { error: result.error, details: result.details },
254
- { status: result.status }
255
- );
256
- }
257
- return result;
238
+ return toNextRouteResponse(result);
258
239
  }
259
240
  async function createCustomerSession(request, options = {}) {
260
241
  const result = await createCustomerSessionCore(request, options);
261
- if (isErrorResult4(result)) {
262
- return NextResponse4.json(
263
- { error: result.error, details: result.details },
264
- { status: result.status }
265
- );
266
- }
267
- return result;
242
+ return toNextRouteResponse(result);
268
243
  }
269
244
 
270
245
  // src/helpers/activation.ts
271
- import { NextResponse as NextResponse5 } from "next/server";
272
- import { activatePlanCore, isErrorResult as isErrorResult5 } from "@solvapay/server";
273
- import { getAuthenticatedUserCore as getAuthenticatedUserCore3 } from "@solvapay/server";
246
+ import { activatePlanCore, isErrorResult as isErrorResult6 } from "@solvapay/server";
274
247
  async function activatePlan(request, body, options = {}) {
275
248
  const result = await activatePlanCore(request, body, options);
276
- if (isErrorResult5(result)) {
277
- return NextResponse5.json(
278
- { error: result.error, details: result.details },
279
- { status: result.status }
280
- );
281
- }
282
- try {
283
- const userResult = await getAuthenticatedUserCore3(request);
284
- if (!isErrorResult5(userResult)) {
285
- clearPurchaseCache(userResult.userId);
286
- }
287
- } catch {
249
+ if (!isErrorResult6(result)) {
250
+ await invalidatePurchaseCacheForRequest(request);
288
251
  }
289
- return result;
252
+ return toNextRouteResponse(result);
253
+ }
254
+
255
+ // src/helpers/payment-method.ts
256
+ import { getPaymentMethodCore } from "@solvapay/server";
257
+ async function getPaymentMethod(request, options = {}) {
258
+ const result = await getPaymentMethodCore(request, options);
259
+ return toNextRouteResponse(result);
290
260
  }
291
261
 
292
262
  // src/helpers/renewal.ts
293
- import { NextResponse as NextResponse6 } from "next/server";
294
263
  import {
295
264
  cancelPurchaseCore,
296
265
  reactivatePurchaseCore,
297
- isErrorResult as isErrorResult6,
298
- getAuthenticatedUserCore as getAuthenticatedUserCore4
266
+ isErrorResult as isErrorResult7
299
267
  } from "@solvapay/server";
300
268
  async function cancelRenewal(request, body, options = {}) {
301
269
  const result = await cancelPurchaseCore(request, body, options);
302
- if (isErrorResult6(result)) {
303
- return NextResponse6.json(
304
- { error: result.error, details: result.details },
305
- { status: result.status }
306
- );
307
- }
308
- try {
309
- const userResult = await getAuthenticatedUserCore4(request);
310
- if (!isErrorResult6(userResult)) {
311
- clearPurchaseCache(userResult.userId);
312
- }
313
- } catch {
270
+ if (!isErrorResult7(result)) {
271
+ await invalidatePurchaseCacheForRequest(request);
314
272
  }
315
- return result;
273
+ return toNextRouteResponse(result);
316
274
  }
317
275
  async function reactivateRenewal(request, body, options = {}) {
318
276
  const result = await reactivatePurchaseCore(request, body, options);
319
- if (isErrorResult6(result)) {
320
- return NextResponse6.json(
321
- { error: result.error, details: result.details },
322
- { status: result.status }
323
- );
324
- }
325
- try {
326
- const userResult = await getAuthenticatedUserCore4(request);
327
- if (!isErrorResult6(userResult)) {
328
- clearPurchaseCache(userResult.userId);
329
- }
330
- } catch {
277
+ if (!isErrorResult7(result)) {
278
+ await invalidatePurchaseCacheForRequest(request);
331
279
  }
332
- return result;
280
+ return toNextRouteResponse(result);
333
281
  }
334
282
 
335
283
  // src/helpers/plans.ts
336
- import { NextResponse as NextResponse7 } from "next/server";
337
- import { listPlansCore, isErrorResult as isErrorResult7 } from "@solvapay/server";
338
- async function listPlans(request) {
339
- const result = await listPlansCore(request);
340
- if (isErrorResult7(result)) {
341
- return NextResponse7.json(
342
- { error: result.error, details: result.details },
343
- { status: result.status }
344
- );
345
- }
346
- return result;
284
+ import { listPlansCore } from "@solvapay/server";
285
+ async function listPlans(request, options = {}) {
286
+ const result = await listPlansCore(request, options);
287
+ return toNextRouteResponse(result);
288
+ }
289
+
290
+ // src/helpers/merchant.ts
291
+ import { getMerchantCore } from "@solvapay/server";
292
+ async function getMerchant(request, options = {}) {
293
+ const result = await getMerchantCore(request, options);
294
+ return toNextRouteResponse(result);
295
+ }
296
+
297
+ // src/helpers/product.ts
298
+ import { getProductCore } from "@solvapay/server";
299
+ async function getProduct(request, options = {}) {
300
+ const result = await getProductCore(request, options);
301
+ return toNextRouteResponse(result);
347
302
  }
348
303
 
349
304
  // src/helpers/usage.ts
350
- import { NextResponse as NextResponse8 } from "next/server";
351
- import { trackUsageCore, isErrorResult as isErrorResult8 } from "@solvapay/server";
305
+ import { trackUsageCore } from "@solvapay/server";
352
306
  async function trackUsage(request, body, options = {}) {
353
307
  const result = await trackUsageCore(request, body, options);
354
- if (isErrorResult8(result)) {
355
- return NextResponse8.json(
356
- { error: result.error, details: result.details },
357
- { status: result.status }
358
- );
359
- }
360
- return NextResponse8.json(result);
308
+ return toNextRouteResponse(result);
361
309
  }
362
310
 
363
311
  // src/index.ts
@@ -369,7 +317,7 @@ async function checkPurchase(request, options = {}) {
369
317
  if (userIdOrError instanceof Response) {
370
318
  const clonedResponse = userIdOrError.clone();
371
319
  const body = await clonedResponse.json().catch(() => ({ error: "Unauthorized" }));
372
- return NextResponse9.json(body, { status: userIdOrError.status });
320
+ return NextResponse4.json(body, { status: userIdOrError.status });
373
321
  }
374
322
  const userId = userIdOrError;
375
323
  const response = await deduplicator.deduplicate(
@@ -382,17 +330,11 @@ async function checkPurchase(request, options = {}) {
382
330
  });
383
331
  }
384
332
  );
385
- if (isErrorResult9(response)) {
386
- return NextResponse9.json(
387
- { error: response.error, details: response.details },
388
- { status: response.status }
389
- );
390
- }
391
- return response;
333
+ return toNextRouteResponse(response);
392
334
  } catch (error) {
393
335
  console.error("Check purchase failed:", error);
394
336
  const errorMessage = error instanceof Error ? error.message : "Unknown error";
395
- return NextResponse9.json(
337
+ return NextResponse4.json(
396
338
  { error: "Failed to check purchase", details: errorMessage },
397
339
  { status: 500 }
398
340
  );
@@ -412,6 +354,9 @@ export {
412
354
  createTopupPaymentIntent,
413
355
  getAuthenticatedUser,
414
356
  getCustomerBalance,
357
+ getMerchant,
358
+ getPaymentMethod,
359
+ getProduct,
415
360
  getPurchaseCacheStats,
416
361
  listPlans,
417
362
  processPaymentIntent,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solvapay/next",
3
- "version": "1.0.9-preview.1",
3
+ "version": "1.0.9",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -34,9 +34,9 @@
34
34
  },
35
35
  "sideEffects": false,
36
36
  "dependencies": {
37
- "@solvapay/core": "1.0.9-preview.1",
38
- "@solvapay/server": "1.0.9-preview.1",
39
- "@solvapay/auth": "1.0.9-preview.1"
37
+ "@solvapay/auth": "1.0.8",
38
+ "@solvapay/core": "1.0.8",
39
+ "@solvapay/server": "1.0.10"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "next": ">=13.0.0"