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