@spaire/nextjs 1.0.1

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.
Files changed (2) hide show
  1. package/README.md +94 -0
  2. package/package.json +52 -0
package/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # @spaire/nextjs
2
+
3
+ Payments and Checkouts made dead simple with Next.js.
4
+
5
+ `pnpm install @spaire/nextjs zod`
6
+
7
+ ## Checkout
8
+
9
+ Create a Checkout handler which takes care of redirections.
10
+
11
+ ```typescript
12
+ // checkout/route.ts
13
+ import { Checkout } from "@spaire/nextjs";
14
+
15
+ export const GET = Checkout({
16
+ accessToken: process.env.SPAIRE_ACCESS_TOKEN,
17
+ successUrl: process.env.SUCCESS_URL,
18
+ returnUrl: "https://myapp.com", // Optional Return URL, which renders a Back-button in the Checkout
19
+ server: "sandbox", // Use sandbox if you're testing Spaire - omit the parameter or pass 'production' otherwise
20
+ theme: "dark" // Enforces the theme - System-preferred theme will be set if left omitted
21
+ });
22
+ ```
23
+
24
+ ### Query Params
25
+
26
+ Pass query params to this route.
27
+
28
+ - products `?products=123`
29
+ - customerId (optional) `?products=123&customerId=xxx`
30
+ - customerExternalId (optional) `?products=123&customerExternalId=xxx`
31
+ - customerEmail (optional) `?products=123&customerEmail=janedoe@gmail.com`
32
+ - customerName (optional) `?products=123&customerName=Jane`
33
+ - seats (optional) `?products=123&seats=5` - Number of seats for seat-based products
34
+ - metadata (optional) `URL-Encoded JSON string`
35
+
36
+ ## Customer Portal
37
+
38
+ Create a customer portal where your customer can view orders and subscriptions.
39
+
40
+ ```typescript
41
+ // portal/route.ts
42
+ import { CustomerPortal } from "@spaire/nextjs";
43
+
44
+ export const GET = CustomerPortal({
45
+ accessToken: process.env.SPAIRE_ACCESS_TOKEN,
46
+ getCustomerId: (req: NextRequest) => "", // Fuction to resolve a Spaire Customer ID
47
+ returnUrl: "https://myapp.com", // Optional Return URL, which renders a Back-button in the Customer Portal
48
+ server: "sandbox", // Use sandbox if you're testing Spaire - omit the parameter or pass 'production' otherwise
49
+ });
50
+ ```
51
+
52
+ ## Webhooks
53
+
54
+ A simple utility which resolves incoming webhook payloads by signing the webhook secret properly.
55
+
56
+ ```typescript
57
+ // api/webhook/spaire/route.ts
58
+ import { Webhooks } from "@spaire/nextjs";
59
+
60
+ export const POST = Webhooks({
61
+ webhookSecret: process.env.SPAIRE_WEBHOOK_SECRET!,
62
+ onPayload: async (payload) => {
63
+ // Handle the payload
64
+ // No need to return an acknowledge response
65
+ },
66
+ });
67
+ ```
68
+
69
+ #### Payload Handlers
70
+
71
+ The Webhook handler also supports granular handlers for easy integration.
72
+
73
+ - onCheckoutCreated: (payload) =>
74
+ - onCheckoutUpdated: (payload) =>
75
+ - onOrderCreated: (payload) =>
76
+ - onOrderUpdated: (payload) =>
77
+ - onOrderPaid: (payload) =>
78
+ - onSubscriptionCreated: (payload) =>
79
+ - onSubscriptionUpdated: (payload) =>
80
+ - onSubscriptionActive: (payload) =>
81
+ - onSubscriptionCanceled: (payload) =>
82
+ - onSubscriptionRevoked: (payload) =>
83
+ - onProductCreated: (payload) =>
84
+ - onProductUpdated: (payload) =>
85
+ - onOrganizationUpdated: (payload) =>
86
+ - onBenefitCreated: (payload) =>
87
+ - onBenefitUpdated: (payload) =>
88
+ - onBenefitGrantCreated: (payload) =>
89
+ - onBenefitGrantUpdated: (payload) =>
90
+ - onBenefitGrantRevoked: (payload) =>
91
+ - onCustomerCreated: (payload) =>
92
+ - onCustomerUpdated: (payload) =>
93
+ - onCustomerDeleted: (payload) =>
94
+ - onCustomerStateChanged: (payload) =>
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@spaire/nextjs",
3
+ "version": "1.0.1",
4
+ "main": "./dist/index.cjs",
5
+ "module": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ "import": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js"
11
+ },
12
+ "require": {
13
+ "types": "./dist/index.d.cts",
14
+ "require": "./dist/index.cjs"
15
+ }
16
+ },
17
+ "type": "module",
18
+ "engines": {
19
+ "node": ">=16"
20
+ },
21
+ "scripts": {
22
+ "build": "tsup ./src/index.ts --format esm,cjs --dts --clean --sourcemap",
23
+ "dev": "tsc --watch",
24
+ "check": "biome check --write ./src",
25
+ "test": "vitest"
26
+ },
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "dependencies": {
31
+ "@spaire/adapter-utils": "workspace:*",
32
+ "@spaire/sdk": "^0.45.1"
33
+ },
34
+ "devDependencies": {
35
+ "@biomejs/biome": "1.9.4",
36
+ "@sindresorhus/tsconfig": "^7.0.0",
37
+ "tsup": "^8.5.1",
38
+ "vitest": "^2.1.8"
39
+ },
40
+ "ava": {
41
+ "extensions": {
42
+ "ts": "module",
43
+ "tsx": "module"
44
+ },
45
+ "nodeArguments": [
46
+ "--loader=ts-node/esm"
47
+ ]
48
+ },
49
+ "peerDependencies": {
50
+ "next": "^15.0.0 || ^16.0.0"
51
+ }
52
+ }