express-stripe-webhook-middleware 1.0.0 → 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.
package/README.md CHANGED
@@ -282,6 +282,18 @@ app.listen(4242, () => {
282
282
 
283
283
  Contributions are welcome! Please feel free to submit a Pull Request.
284
284
 
285
+ This repository uses [pnpm](https://pnpm.io/) (the version is pinned by `packageManager` in `package.json`):
286
+
287
+ ```bash
288
+ pnpm install
289
+ pnpm run lint
290
+ pnpm run typecheck
291
+ pnpm run build
292
+ pnpm test
293
+ ```
294
+
295
+ Releases are automated: merging to `main` runs semantic-release on CircleCI, which decides the next version from [Conventional Commits](https://www.conventionalcommits.org/) since the last `v*` tag, publishes to npm, and creates the GitHub Release. Do not bump `version` in `package.json` by hand.
296
+
285
297
  ## License
286
298
 
287
299
  MIT © [Hidetaka Okamoto](https://github.com/hideokamoto)
@@ -0,0 +1,93 @@
1
+ import { default as Stripe } from 'stripe';
2
+ import { Request, RequestHandler, Response } from 'express';
3
+ export type Logger = (message?: unknown, ...optionalParams: unknown[]) => void;
4
+ export interface StripeWebhookMiddlewareOptions {
5
+ /**
6
+ * Custom logger function for error logging
7
+ * @default console.error
8
+ */
9
+ logger?: Logger;
10
+ /**
11
+ * Custom error handler function
12
+ * If not provided, sends a 400 response with the error message
13
+ */
14
+ onError?: (error: Error, req: Request, res: Response) => void;
15
+ }
16
+ /**
17
+ * Factory class for creating Express middleware that verifies Stripe webhook signatures
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * import Stripe from 'stripe';
22
+ * import express from 'express';
23
+ * import { StripeWebhookMiddlewareFactory } from 'express-stripe-webhook-middleware';
24
+ *
25
+ * const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
26
+ * const factory = new StripeWebhookMiddlewareFactory(
27
+ * process.env.STRIPE_WEBHOOK_SECRET,
28
+ * stripe
29
+ * );
30
+ *
31
+ * const app = express();
32
+ * app.post('/webhook', ...factory.create(), (req, res) => {
33
+ * const event = req.body as Stripe.Event;
34
+ * console.log('Received event:', event.type);
35
+ * res.json({ received: true });
36
+ * });
37
+ * ```
38
+ */
39
+ export declare class StripeWebhookMiddlewareFactory {
40
+ private readonly endpointSecret;
41
+ private readonly stripe;
42
+ private readonly log;
43
+ private readonly onError?;
44
+ /**
45
+ * Creates a new StripeWebhookMiddlewareFactory instance
46
+ *
47
+ * @param endpointSecret - Stripe webhook secret key (starts with `whsec_`)
48
+ * @param client - Stripe SDK client instance
49
+ * @param options - Optional configuration
50
+ */
51
+ constructor(endpointSecret: string, client: Stripe, options?: StripeWebhookMiddlewareOptions);
52
+ /**
53
+ * Creates an array of middleware handlers for Stripe webhook verification
54
+ *
55
+ * Returns an array containing:
56
+ * 1. body-parser middleware to parse raw body
57
+ * 2. Stripe signature verification middleware
58
+ *
59
+ * @returns Array of Express request handlers
60
+ */
61
+ create(): RequestHandler[];
62
+ }
63
+ /**
64
+ * Creates Stripe webhook verification middleware
65
+ *
66
+ * This is a convenience function that creates a factory and returns the middleware
67
+ *
68
+ * @param endpointSecret - Stripe webhook secret key (starts with `whsec_`)
69
+ * @param client - Stripe SDK client instance
70
+ * @param options - Optional configuration
71
+ * @returns Array of Express request handlers
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * import Stripe from 'stripe';
76
+ * import express from 'express';
77
+ * import { createStripeWebhookMiddleware } from 'express-stripe-webhook-middleware';
78
+ *
79
+ * const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
80
+ * const app = express();
81
+ *
82
+ * app.post(
83
+ * '/webhook',
84
+ * ...createStripeWebhookMiddleware(process.env.STRIPE_WEBHOOK_SECRET, stripe),
85
+ * (req, res) => {
86
+ * const event = req.body as Stripe.Event;
87
+ * res.json({ received: true });
88
+ * }
89
+ * );
90
+ * ```
91
+ */
92
+ export declare function createStripeWebhookMiddleware(endpointSecret: string, client: Stripe, options?: StripeWebhookMiddlewareOptions): RequestHandler[];
93
+ //# sourceMappingURL=index.d.ts.map
package/package.json CHANGED
@@ -1,18 +1,31 @@
1
1
  {
2
2
  "name": "express-stripe-webhook-middleware",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Express middleware for Stripe webhook signature verification",
5
5
  "license": "MIT",
6
6
  "author": "Hidetaka Okamoto",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/hideokamoto/express-stripe-webhook-middleware.git"
10
+ },
11
+ "homepage": "https://github.com/hideokamoto/express-stripe-webhook-middleware#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/hideokamoto/express-stripe-webhook-middleware/issues"
14
+ },
7
15
  "type": "module",
8
16
  "main": "./dist/index.cjs",
9
17
  "module": "./dist/index.js",
10
- "types": "./dist/index.d.ts",
18
+ "types": "./dist/index.d.cts",
11
19
  "exports": {
12
20
  ".": {
13
- "types": "./dist/index.d.ts",
14
- "import": "./dist/index.js",
15
- "require": "./dist/index.cjs"
21
+ "import": {
22
+ "types": "./dist/index.d.ts",
23
+ "default": "./dist/index.js"
24
+ },
25
+ "require": {
26
+ "types": "./dist/index.d.cts",
27
+ "default": "./dist/index.cjs"
28
+ }
16
29
  }
17
30
  },
18
31
  "files": [
@@ -29,9 +42,9 @@
29
42
  "test:coverage": "vitest run --coverage",
30
43
  "lint": "eslint src --ext .ts",
31
44
  "lint:fix": "eslint src --ext .ts --fix",
32
- "type-check": "tsc --noEmit",
45
+ "typecheck": "tsc --noEmit",
33
46
  "prepare": "npm run build",
34
- "prepublishOnly": "npm run lint && npm run type-check && npm run test",
47
+ "prepublishOnly": "npm run lint && npm run typecheck && npm run test",
35
48
  "release": "np"
36
49
  },
37
50
  "keywords": [
@@ -50,6 +63,7 @@
50
63
  "stripe": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
51
64
  },
52
65
  "devDependencies": {
66
+ "@eslint/js": "^9.39.1",
53
67
  "@types/body-parser": "^1.19.5",
54
68
  "@types/express": "^5.0.0",
55
69
  "@types/node": "^22.10.2",
@@ -78,5 +92,6 @@
78
92
  "contents": ".",
79
93
  "tests": true,
80
94
  "2fa": true
81
- }
95
+ },
96
+ "packageManager": "pnpm@10.34.9"
82
97
  }