@solvapay/next 1.2.0 → 1.2.1-preview-ecd61384a4e849717e13d47ab2daa086cdcd91c5

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/README.md CHANGED
@@ -39,30 +39,30 @@ Example app: [`examples/checkout-demo`](../../examples/checkout-demo)
39
39
 
40
40
  ## Helper reference
41
41
 
42
- | Helper | Purpose |
43
- | --- | --- |
44
- | `checkPurchase` | Purchase status (deduped + cached) |
45
- | `syncCustomer` | Ensure customer exists |
46
- | `createPaymentIntent` / `processPayment` | Embedded checkout |
47
- | `createCheckoutSession` | Hosted redirect checkout |
48
- | `createCustomerSession` | Customer portal |
49
- | `listPlans` | Public plan listing |
50
- | `cancelRenewal` / `reactivateRenewal` / `activatePlan` | Plan lifecycle |
51
- | `trackUsage` | Server-side usage metering |
52
- | `getAuthenticatedUser` | User ID, email, name from headers |
53
- | `clearPurchaseCache` / `getPurchaseCacheStats` | Cache management |
42
+ | Helper | Purpose |
43
+ | ------------------------------------------------------ | ---------------------------------- |
44
+ | `checkPurchase` | Purchase status (deduped + cached) |
45
+ | `syncCustomer` | Ensure customer exists |
46
+ | `createPaymentIntent` / `processPayment` | Embedded checkout |
47
+ | `createCheckoutSession` | Hosted redirect checkout |
48
+ | `createCustomerSession` | Customer portal |
49
+ | `listPlans` | Public plan listing |
50
+ | `cancelRenewal` / `reactivateRenewal` / `activatePlan` | Plan lifecycle |
51
+ | `trackUsage` | Server-side usage metering |
52
+ | `getAuthenticatedUser` | User ID, email, name from headers |
53
+ | `clearPurchaseCache` / `getPurchaseCacheStats` | Cache management |
54
54
 
55
55
  Full signatures and options: [Next.js guide](https://docs.solvapay.com/sdks/typescript/guides/nextjs)
56
56
 
57
- ## Middleware
57
+ ## Proxy
58
58
 
59
- Helpers expect `x-user-id` from middleware. Quick setup with Supabase:
59
+ Helpers expect `x-user-id` from the Next.js proxy. Quick setup with Supabase:
60
60
 
61
61
  ```typescript
62
- // middleware.ts (Next.js 15) or src/proxy.ts (Next.js 16)
62
+ // proxy.ts
63
63
  import { createSupabaseAuthMiddleware } from '@solvapay/next'
64
64
 
65
- export const middleware = createSupabaseAuthMiddleware({
65
+ export const proxy = createSupabaseAuthMiddleware({
66
66
  publicRoutes: ['/api/list-plans'],
67
67
  })
68
68
 
package/dist/index.cjs CHANGED
@@ -42,7 +42,9 @@ __export(index_exports, {
42
42
  createPaymentIntent: () => createPaymentIntent,
43
43
  createSupabaseAuthMiddleware: () => createSupabaseAuthMiddleware,
44
44
  createTopupPaymentIntent: () => createTopupPaymentIntent,
45
+ disableAutoRecharge: () => disableAutoRecharge,
45
46
  getAuthenticatedUser: () => getAuthenticatedUser,
47
+ getAutoRecharge: () => getAutoRecharge,
46
48
  getCustomerBalance: () => getCustomerBalance,
47
49
  getMerchant: () => getMerchant,
48
50
  getPaymentMethod: () => getPaymentMethod,
@@ -52,12 +54,13 @@ __export(index_exports, {
52
54
  processPaymentIntent: () => processPaymentIntent,
53
55
  processTopupPaymentIntent: () => processTopupPaymentIntent,
54
56
  reactivateRenewal: () => reactivateRenewal,
57
+ saveAutoRecharge: () => saveAutoRecharge,
55
58
  syncCustomer: () => syncCustomer,
56
59
  trackUsage: () => trackUsage
57
60
  });
58
61
  module.exports = __toCommonJS(index_exports);
59
- var import_server18 = require("next/server");
60
- var import_server19 = require("@solvapay/server");
62
+ var import_server19 = require("next/server");
63
+ var import_server20 = require("@solvapay/server");
61
64
 
62
65
  // src/cache.ts
63
66
  function createRequestDeduplicator(options = {}) {
@@ -307,53 +310,71 @@ async function getPaymentMethod(request, options = {}) {
307
310
  return toNextRouteResponse(result);
308
311
  }
309
312
 
310
- // src/helpers/renewal.ts
313
+ // src/helpers/auto-recharge.ts
311
314
  var import_server12 = require("@solvapay/server");
315
+ async function getAutoRecharge(request, options = {}) {
316
+ const result = await (0, import_server12.getAutoRechargeCore)(request, options);
317
+ return toNextRouteResponse(result);
318
+ }
319
+ async function saveAutoRecharge(request, inputOrOptions = {}, maybeOptions = {}) {
320
+ const hasInput = "enabled" in inputOrOptions;
321
+ const input = hasInput ? inputOrOptions : await request.json();
322
+ const options = hasInput ? maybeOptions : inputOrOptions;
323
+ const result = await (0, import_server12.saveAutoRechargeCore)(request, input, options);
324
+ return toNextRouteResponse(result);
325
+ }
326
+ async function disableAutoRecharge(request, options = {}) {
327
+ const result = await (0, import_server12.disableAutoRechargeCore)(request, options);
328
+ return toNextRouteResponse(result);
329
+ }
330
+
331
+ // src/helpers/renewal.ts
332
+ var import_server13 = require("@solvapay/server");
312
333
  async function cancelRenewal(request, body, options = {}) {
313
- const result = await (0, import_server12.cancelPurchaseCore)(request, body, options);
314
- if (!(0, import_server12.isErrorResult)(result)) {
334
+ const result = await (0, import_server13.cancelPurchaseCore)(request, body, options);
335
+ if (!(0, import_server13.isErrorResult)(result)) {
315
336
  await invalidatePurchaseCacheForRequest(request);
316
337
  }
317
338
  return toNextRouteResponse(result);
318
339
  }
319
340
  async function reactivateRenewal(request, body, options = {}) {
320
- const result = await (0, import_server12.reactivatePurchaseCore)(request, body, options);
321
- if (!(0, import_server12.isErrorResult)(result)) {
341
+ const result = await (0, import_server13.reactivatePurchaseCore)(request, body, options);
342
+ if (!(0, import_server13.isErrorResult)(result)) {
322
343
  await invalidatePurchaseCacheForRequest(request);
323
344
  }
324
345
  return toNextRouteResponse(result);
325
346
  }
326
347
 
327
348
  // src/helpers/plans.ts
328
- var import_server13 = require("@solvapay/server");
349
+ var import_server14 = require("@solvapay/server");
329
350
  async function listPlans(request, options = {}) {
330
- const result = await (0, import_server13.listPlansCore)(request, options);
351
+ const result = await (0, import_server14.listPlansCore)(request, options);
331
352
  return toNextRouteResponse(result);
332
353
  }
333
354
 
334
355
  // src/helpers/merchant.ts
335
- var import_server14 = require("@solvapay/server");
356
+ var import_server15 = require("@solvapay/server");
336
357
  async function getMerchant(request, options = {}) {
337
- const result = await (0, import_server14.getMerchantCore)(request, options);
358
+ const result = await (0, import_server15.getMerchantCore)(request, options);
338
359
  return toNextRouteResponse(result);
339
360
  }
340
361
 
341
362
  // src/helpers/product.ts
342
- var import_server15 = require("@solvapay/server");
363
+ var import_server16 = require("@solvapay/server");
343
364
  async function getProduct(request, options = {}) {
344
- const result = await (0, import_server15.getProductCore)(request, options);
365
+ const result = await (0, import_server16.getProductCore)(request, options);
345
366
  return toNextRouteResponse(result);
346
367
  }
347
368
 
348
369
  // src/helpers/usage.ts
349
- var import_server16 = require("@solvapay/server");
370
+ var import_server17 = require("@solvapay/server");
350
371
  async function trackUsage(request, body, options = {}) {
351
- const result = await (0, import_server16.trackUsageCore)(request, body, options);
372
+ const result = await (0, import_server17.trackUsageCore)(request, body, options);
352
373
  return toNextRouteResponse(result);
353
374
  }
354
375
 
355
376
  // src/helpers/middleware.ts
356
- var import_server17 = require("next/server");
377
+ var import_server18 = require("next/server");
357
378
  var import_auth = require("@solvapay/auth");
358
379
  var import_auth0 = require("@solvapay/auth/auth0");
359
380
  function mergeSetCookies(target, source) {
@@ -381,7 +402,7 @@ function buildForwardResponse(req, userIdHeader, identity) {
381
402
  requestHeaders.set(import_auth.SOLVAPAY_AUTHORIZATION_HEADER, `Bearer ${identity.claimsToken}`);
382
403
  }
383
404
  }
384
- return import_server17.NextResponse.next({
405
+ return import_server18.NextResponse.next({
385
406
  request: {
386
407
  headers: requestHeaders
387
408
  }
@@ -405,7 +426,7 @@ function createAuthMiddleware(options) {
405
426
  const req = request;
406
427
  const pathname = getPathname(req);
407
428
  if (!processAllRoutes && !pathname.startsWith("/api")) {
408
- return import_server17.NextResponse.next();
429
+ return import_server18.NextResponse.next();
409
430
  }
410
431
  const handleResult = adapter.handleRequest ? await adapter.handleRequest(req) : null;
411
432
  if (handleResult?.ownsRequest && handleResult.response) {
@@ -416,7 +437,7 @@ function createAuthMiddleware(options) {
416
437
  const userId = identity?.userId ?? null;
417
438
  const isProtectedApiRoute = pathname.startsWith(protectedRoutePrefix) && !isPublicRoute;
418
439
  if (isProtectedApiRoute && !userId) {
419
- const unauthorized = import_server17.NextResponse.json(
440
+ const unauthorized = import_server18.NextResponse.json(
420
441
  { error: "Unauthorized", details: "Valid authentication required" },
421
442
  { status: 401 }
422
443
  );
@@ -490,13 +511,13 @@ async function checkPurchase(request, options = {}) {
490
511
  if (userIdOrError instanceof Response) {
491
512
  const clonedResponse = userIdOrError.clone();
492
513
  const body = await clonedResponse.json().catch(() => ({ error: "Unauthorized" }));
493
- return import_server18.NextResponse.json(body, { status: userIdOrError.status });
514
+ return import_server19.NextResponse.json(body, { status: userIdOrError.status });
494
515
  }
495
516
  const userId = userIdOrError;
496
517
  const response = await deduplicator.deduplicate(
497
518
  userId,
498
519
  async () => {
499
- return await (0, import_server19.checkPurchaseCore)(request, {
520
+ return await (0, import_server20.checkPurchaseCore)(request, {
500
521
  solvaPay: options.solvaPay,
501
522
  includeEmail: options.includeEmail,
502
523
  includeName: options.includeName
@@ -507,7 +528,7 @@ async function checkPurchase(request, options = {}) {
507
528
  } catch (error) {
508
529
  console.error("Check purchase failed:", error);
509
530
  const errorMessage = error instanceof Error ? error.message : "Unknown error";
510
- return import_server18.NextResponse.json(
531
+ return import_server19.NextResponse.json(
511
532
  { error: "Failed to check purchase", details: errorMessage },
512
533
  { status: 500 }
513
534
  );
@@ -527,7 +548,9 @@ async function checkPurchase(request, options = {}) {
527
548
  createPaymentIntent,
528
549
  createSupabaseAuthMiddleware,
529
550
  createTopupPaymentIntent,
551
+ disableAutoRecharge,
530
552
  getAuthenticatedUser,
553
+ getAutoRecharge,
531
554
  getCustomerBalance,
532
555
  getMerchant,
533
556
  getPaymentMethod,
@@ -537,6 +560,7 @@ async function checkPurchase(request, options = {}) {
537
560
  processPaymentIntent,
538
561
  processTopupPaymentIntent,
539
562
  reactivateRenewal,
563
+ saveAutoRecharge,
540
564
  syncCustomer,
541
565
  trackUsage
542
566
  });
package/dist/index.d.cts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { NextResponse } from 'next/server';
2
- import { AuthenticatedUser, SolvaPay } from '@solvapay/server';
2
+ import * as _solvapay_server from '@solvapay/server';
3
+ import { AuthenticatedUser, SolvaPay, AutoRechargeInput } from '@solvapay/server';
3
4
  export { Auth0AuthMiddlewareOptions, AuthMiddlewareOptions, SupabaseAuthMiddlewareOptions, createAuth0AuthMiddleware, createAuthMiddleware, createSupabaseAuthMiddleware } from './middleware.cjs';
4
5
  import '@solvapay/auth';
5
6
  import '@solvapay/auth/auth0';
@@ -227,10 +228,6 @@ declare function getCustomerBalance(request: globalThis.Request, options?: {
227
228
  solvaPay?: SolvaPay;
228
229
  }): Promise<NextResponse>;
229
230
 
230
- /**
231
- * Next.js Payment Helpers
232
- */
233
-
234
231
  /**
235
232
  * Next.js route wrapper for POST /api/create-payment-intent.
236
233
  *
@@ -271,6 +268,7 @@ declare function createTopupPaymentIntent(request: globalThis.Request, body: {
271
268
  amount: number;
272
269
  currency: string;
273
270
  description?: string;
271
+ autoRecharge?: _solvapay_server.AutoRechargeInput;
274
272
  }, options?: {
275
273
  solvaPay?: SolvaPay;
276
274
  includeEmail?: boolean;
@@ -402,6 +400,15 @@ declare function getPaymentMethod(request: globalThis.Request, options?: {
402
400
  includeName?: boolean;
403
401
  }): Promise<NextResponse>;
404
402
 
403
+ type AutoRechargeOptions = {
404
+ solvaPay?: SolvaPay;
405
+ includeEmail?: boolean;
406
+ includeName?: boolean;
407
+ };
408
+ declare function getAutoRecharge(request: globalThis.Request, options?: AutoRechargeOptions): Promise<NextResponse>;
409
+ declare function saveAutoRecharge(request: globalThis.Request, inputOrOptions?: AutoRechargeInput | AutoRechargeOptions, maybeOptions?: AutoRechargeOptions): Promise<NextResponse>;
410
+ declare function disableAutoRecharge(request: globalThis.Request, options?: AutoRechargeOptions): Promise<NextResponse>;
411
+
405
412
  /**
406
413
  * Next.js Purchase Cancellation & Reactivation Helpers
407
414
  */
@@ -572,4 +579,4 @@ interface CheckPurchaseOptions {
572
579
  */
573
580
  declare function checkPurchase(request: Request, options?: CheckPurchaseOptions): Promise<NextResponse>;
574
581
 
575
- export { type CheckPurchaseOptions, type PurchaseCheckResult, type RequestDeduplicationOptions, activatePlan, cancelRenewal, checkPurchase, clearAllPurchaseCache, clearPurchaseCache, createCheckoutSession, createCustomerSession, createPaymentIntent, createTopupPaymentIntent, getAuthenticatedUser, getCustomerBalance, getMerchant, getPaymentMethod, getProduct, getPurchaseCacheStats, listPlans, processPaymentIntent, processTopupPaymentIntent, reactivateRenewal, syncCustomer, trackUsage };
582
+ export { type CheckPurchaseOptions, type PurchaseCheckResult, type RequestDeduplicationOptions, activatePlan, cancelRenewal, checkPurchase, clearAllPurchaseCache, clearPurchaseCache, createCheckoutSession, createCustomerSession, createPaymentIntent, createTopupPaymentIntent, disableAutoRecharge, getAuthenticatedUser, getAutoRecharge, getCustomerBalance, getMerchant, getPaymentMethod, getProduct, getPurchaseCacheStats, listPlans, processPaymentIntent, processTopupPaymentIntent, reactivateRenewal, saveAutoRecharge, syncCustomer, trackUsage };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { NextResponse } from 'next/server';
2
- import { AuthenticatedUser, SolvaPay } from '@solvapay/server';
2
+ import * as _solvapay_server from '@solvapay/server';
3
+ import { AuthenticatedUser, SolvaPay, AutoRechargeInput } from '@solvapay/server';
3
4
  export { Auth0AuthMiddlewareOptions, AuthMiddlewareOptions, SupabaseAuthMiddlewareOptions, createAuth0AuthMiddleware, createAuthMiddleware, createSupabaseAuthMiddleware } from './middleware.js';
4
5
  import '@solvapay/auth';
5
6
  import '@solvapay/auth/auth0';
@@ -227,10 +228,6 @@ declare function getCustomerBalance(request: globalThis.Request, options?: {
227
228
  solvaPay?: SolvaPay;
228
229
  }): Promise<NextResponse>;
229
230
 
230
- /**
231
- * Next.js Payment Helpers
232
- */
233
-
234
231
  /**
235
232
  * Next.js route wrapper for POST /api/create-payment-intent.
236
233
  *
@@ -271,6 +268,7 @@ declare function createTopupPaymentIntent(request: globalThis.Request, body: {
271
268
  amount: number;
272
269
  currency: string;
273
270
  description?: string;
271
+ autoRecharge?: _solvapay_server.AutoRechargeInput;
274
272
  }, options?: {
275
273
  solvaPay?: SolvaPay;
276
274
  includeEmail?: boolean;
@@ -402,6 +400,15 @@ declare function getPaymentMethod(request: globalThis.Request, options?: {
402
400
  includeName?: boolean;
403
401
  }): Promise<NextResponse>;
404
402
 
403
+ type AutoRechargeOptions = {
404
+ solvaPay?: SolvaPay;
405
+ includeEmail?: boolean;
406
+ includeName?: boolean;
407
+ };
408
+ declare function getAutoRecharge(request: globalThis.Request, options?: AutoRechargeOptions): Promise<NextResponse>;
409
+ declare function saveAutoRecharge(request: globalThis.Request, inputOrOptions?: AutoRechargeInput | AutoRechargeOptions, maybeOptions?: AutoRechargeOptions): Promise<NextResponse>;
410
+ declare function disableAutoRecharge(request: globalThis.Request, options?: AutoRechargeOptions): Promise<NextResponse>;
411
+
405
412
  /**
406
413
  * Next.js Purchase Cancellation & Reactivation Helpers
407
414
  */
@@ -572,4 +579,4 @@ interface CheckPurchaseOptions {
572
579
  */
573
580
  declare function checkPurchase(request: Request, options?: CheckPurchaseOptions): Promise<NextResponse>;
574
581
 
575
- export { type CheckPurchaseOptions, type PurchaseCheckResult, type RequestDeduplicationOptions, activatePlan, cancelRenewal, checkPurchase, clearAllPurchaseCache, clearPurchaseCache, createCheckoutSession, createCustomerSession, createPaymentIntent, createTopupPaymentIntent, getAuthenticatedUser, getCustomerBalance, getMerchant, getPaymentMethod, getProduct, getPurchaseCacheStats, listPlans, processPaymentIntent, processTopupPaymentIntent, reactivateRenewal, syncCustomer, trackUsage };
582
+ export { type CheckPurchaseOptions, type PurchaseCheckResult, type RequestDeduplicationOptions, activatePlan, cancelRenewal, checkPurchase, clearAllPurchaseCache, clearPurchaseCache, createCheckoutSession, createCustomerSession, createPaymentIntent, createTopupPaymentIntent, disableAutoRecharge, getAuthenticatedUser, getAutoRecharge, getCustomerBalance, getMerchant, getPaymentMethod, getProduct, getPurchaseCacheStats, listPlans, processPaymentIntent, processTopupPaymentIntent, reactivateRenewal, saveAutoRecharge, syncCustomer, trackUsage };
package/dist/index.js CHANGED
@@ -268,6 +268,28 @@ async function getPaymentMethod(request, options = {}) {
268
268
  return toNextRouteResponse(result);
269
269
  }
270
270
 
271
+ // src/helpers/auto-recharge.ts
272
+ import {
273
+ disableAutoRechargeCore,
274
+ getAutoRechargeCore,
275
+ saveAutoRechargeCore
276
+ } from "@solvapay/server";
277
+ async function getAutoRecharge(request, options = {}) {
278
+ const result = await getAutoRechargeCore(request, options);
279
+ return toNextRouteResponse(result);
280
+ }
281
+ async function saveAutoRecharge(request, inputOrOptions = {}, maybeOptions = {}) {
282
+ const hasInput = "enabled" in inputOrOptions;
283
+ const input = hasInput ? inputOrOptions : await request.json();
284
+ const options = hasInput ? maybeOptions : inputOrOptions;
285
+ const result = await saveAutoRechargeCore(request, input, options);
286
+ return toNextRouteResponse(result);
287
+ }
288
+ async function disableAutoRecharge(request, options = {}) {
289
+ const result = await disableAutoRechargeCore(request, options);
290
+ return toNextRouteResponse(result);
291
+ }
292
+
271
293
  // src/helpers/renewal.ts
272
294
  import {
273
295
  cancelPurchaseCore,
@@ -362,7 +384,9 @@ export {
362
384
  createPaymentIntent,
363
385
  createSupabaseAuthMiddleware,
364
386
  createTopupPaymentIntent,
387
+ disableAutoRecharge,
365
388
  getAuthenticatedUser,
389
+ getAutoRecharge,
366
390
  getCustomerBalance,
367
391
  getMerchant,
368
392
  getPaymentMethod,
@@ -372,6 +396,7 @@ export {
372
396
  processPaymentIntent,
373
397
  processTopupPaymentIntent,
374
398
  reactivateRenewal,
399
+ saveAutoRecharge,
375
400
  syncCustomer,
376
401
  trackUsage
377
402
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solvapay/next",
3
- "version": "1.2.0",
3
+ "version": "1.2.1-preview-ecd61384a4e849717e13d47ab2daa086cdcd91c5",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -35,8 +35,8 @@
35
35
  "sideEffects": false,
36
36
  "dependencies": {
37
37
  "@solvapay/auth": "1.1.0",
38
- "@solvapay/core": "1.1.0",
39
- "@solvapay/server": "1.2.1"
38
+ "@solvapay/core": "1.1.1-preview-ecd61384a4e849717e13d47ab2daa086cdcd91c5",
39
+ "@solvapay/server": "1.3.0-preview-ecd61384a4e849717e13d47ab2daa086cdcd91c5"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "next": ">=13.0.0"