@commet/next 0.1.0
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 +57 -0
- package/dist/index.d.mts +149 -0
- package/dist/index.d.ts +149 -0
- package/dist/index.js +142 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +115 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +53 -0
package/README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<p align="center">
|
|
3
|
+
<a href="https://commet.co">
|
|
4
|
+
<img src="https://commet.co/logo-bg-dark.png" height="96">
|
|
5
|
+
<h3 align="center">@commet/next</h3>
|
|
6
|
+
</a>
|
|
7
|
+
</p>
|
|
8
|
+
<p>Next.js integration for Commet webhooks</p>
|
|
9
|
+
|
|
10
|
+
<a href="https://www.npmjs.com/package/@commet/next"><img alt="NPM version" src="https://img.shields.io/npm/v/@commet/next.svg?style=for-the-badge&labelColor=000000"></a>
|
|
11
|
+
<a href="https://docs.commet.co/docs/library/installation/webhooks"><img alt="Documentation" src="https://img.shields.io/badge/docs-webhooks-blue.svg?style=for-the-badge&labelColor=000000"></a>
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
<br/>
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @commet/next
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
// app/api/webhooks/commet/route.ts
|
|
26
|
+
import { Webhooks } from "@commet/next";
|
|
27
|
+
|
|
28
|
+
export const POST = Webhooks({
|
|
29
|
+
webhookSecret: process.env.COMMET_WEBHOOK_SECRET!,
|
|
30
|
+
|
|
31
|
+
onSubscriptionActivated: async (payload) => {
|
|
32
|
+
// Handle subscription activation
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Documentation
|
|
38
|
+
|
|
39
|
+
Visit [docs.commet.co/docs/library/installation/webhooks](https://docs.commet.co/docs/library/installation/webhooks) for:
|
|
40
|
+
|
|
41
|
+
- Complete setup guide
|
|
42
|
+
- Event handler reference
|
|
43
|
+
- TypeScript integration
|
|
44
|
+
- Error handling patterns
|
|
45
|
+
- Testing strategies
|
|
46
|
+
|
|
47
|
+
## Resources
|
|
48
|
+
|
|
49
|
+
- [Webhook Documentation](https://docs.commet.co/docs/library/installation/webhooks)
|
|
50
|
+
- [SDK Reference](https://docs.commet.co/docs/library/quickstart)
|
|
51
|
+
- [GitHub](https://github.com/commet-labs/commet)
|
|
52
|
+
- [Issues](https://github.com/commet-labs/commet/issues)
|
|
53
|
+
|
|
54
|
+
## License
|
|
55
|
+
|
|
56
|
+
MIT
|
|
57
|
+
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import { WebhookPayload } from '@commet/node';
|
|
3
|
+
export { WebhookData, WebhookEvent, WebhookPayload } from '@commet/node';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for the Commet webhook handler
|
|
7
|
+
*/
|
|
8
|
+
interface WebhooksConfig {
|
|
9
|
+
/**
|
|
10
|
+
* Webhook secret from your Commet dashboard
|
|
11
|
+
* Used to verify webhook signatures
|
|
12
|
+
*/
|
|
13
|
+
webhookSecret: string;
|
|
14
|
+
/**
|
|
15
|
+
* Handles the `subscription.activated` webhook event
|
|
16
|
+
*
|
|
17
|
+
* Fired when a subscription payment is successful and the subscription becomes active.
|
|
18
|
+
* This is when you should grant access to your product.
|
|
19
|
+
*
|
|
20
|
+
* @param payload - The webhook payload containing subscription data
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* onSubscriptionActivated: async (payload) => {
|
|
25
|
+
* await db.update(users)
|
|
26
|
+
* .set({ isPaid: true })
|
|
27
|
+
* .where(eq(users.id, payload.data.externalId));
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
onSubscriptionActivated?: (payload: WebhookPayload) => Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Handles the `subscription.canceled` webhook event
|
|
34
|
+
*
|
|
35
|
+
* Fired when a subscription is canceled (either by the customer or administratively).
|
|
36
|
+
* This is when you should revoke access to your product.
|
|
37
|
+
*
|
|
38
|
+
* @param payload - The webhook payload containing subscription data
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* onSubscriptionCanceled: async (payload) => {
|
|
43
|
+
* await db.update(users)
|
|
44
|
+
* .set({ isPaid: false })
|
|
45
|
+
* .where(eq(users.id, payload.data.externalId));
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
onSubscriptionCanceled?: (payload: WebhookPayload) => Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Handles the `subscription.created` webhook event
|
|
52
|
+
*
|
|
53
|
+
* Fired when a new subscription is created, but before payment is processed.
|
|
54
|
+
* Typically used for logging or analytics, not for granting access.
|
|
55
|
+
*
|
|
56
|
+
* @param payload - The webhook payload containing subscription data
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* onSubscriptionCreated: async (payload) => {
|
|
61
|
+
* console.log(`New subscription: ${payload.data.subscriptionId}`);
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
onSubscriptionCreated?: (payload: WebhookPayload) => Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Handles the `subscription.updated` webhook event
|
|
68
|
+
*
|
|
69
|
+
* Fired when subscription details change (plan, quantity, status, etc.).
|
|
70
|
+
* Use this to handle upgrades, downgrades, or status transitions.
|
|
71
|
+
*
|
|
72
|
+
* @param payload - The webhook payload containing subscription data
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* onSubscriptionUpdated: async (payload) => {
|
|
77
|
+
* if (payload.data.status === 'active') {
|
|
78
|
+
* await handleActivation(payload);
|
|
79
|
+
* }
|
|
80
|
+
* }
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
onSubscriptionUpdated?: (payload: WebhookPayload) => Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Catch-all handler that receives all webhook events
|
|
86
|
+
*
|
|
87
|
+
* Useful for logging, analytics, or handling events without specific handlers.
|
|
88
|
+
* Called in addition to specific event handlers.
|
|
89
|
+
*
|
|
90
|
+
* @param payload - The webhook payload
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* onPayload: async (payload) => {
|
|
95
|
+
* console.log(`Webhook received: ${payload.event}`);
|
|
96
|
+
* await analytics.track('webhook_received', { event: payload.event });
|
|
97
|
+
* }
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
onPayload?: (payload: WebhookPayload) => Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Error handler for webhook processing failures
|
|
103
|
+
*
|
|
104
|
+
* Called when signature verification fails or handlers throw errors.
|
|
105
|
+
* Use this for custom error logging or alerting.
|
|
106
|
+
*
|
|
107
|
+
* @param error - The error that occurred
|
|
108
|
+
* @param payload - The raw payload (may be undefined if parsing failed)
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* onError: async (error, payload) => {
|
|
113
|
+
* console.error('Webhook error:', error);
|
|
114
|
+
* await logger.error('webhook_failed', { error, payload });
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
onError?: (error: Error, payload: unknown) => Promise<void>;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Create a Next.js webhook handler for Commet events
|
|
123
|
+
*
|
|
124
|
+
* Automatically verifies signatures, routes events to handlers, and returns proper responses.
|
|
125
|
+
*
|
|
126
|
+
* @param config - Webhook configuration with secret and event handlers
|
|
127
|
+
* @returns Next.js route handler function
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* // app/api/webhooks/commet/route.ts
|
|
132
|
+
* import { Webhooks } from "@commet/next";
|
|
133
|
+
*
|
|
134
|
+
* export const POST = Webhooks({
|
|
135
|
+
* webhookSecret: process.env.COMMET_WEBHOOK_SECRET!,
|
|
136
|
+
* onSubscriptionActivated: async (payload) => {
|
|
137
|
+
* // Grant access to user
|
|
138
|
+
* },
|
|
139
|
+
* onSubscriptionCanceled: async (payload) => {
|
|
140
|
+
* // Revoke access from user
|
|
141
|
+
* },
|
|
142
|
+
* });
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
declare const Webhooks: (config: WebhooksConfig) => (request: NextRequest) => Promise<NextResponse<{
|
|
146
|
+
received: boolean;
|
|
147
|
+
}>>;
|
|
148
|
+
|
|
149
|
+
export { Webhooks, type WebhooksConfig };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import { WebhookPayload } from '@commet/node';
|
|
3
|
+
export { WebhookData, WebhookEvent, WebhookPayload } from '@commet/node';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for the Commet webhook handler
|
|
7
|
+
*/
|
|
8
|
+
interface WebhooksConfig {
|
|
9
|
+
/**
|
|
10
|
+
* Webhook secret from your Commet dashboard
|
|
11
|
+
* Used to verify webhook signatures
|
|
12
|
+
*/
|
|
13
|
+
webhookSecret: string;
|
|
14
|
+
/**
|
|
15
|
+
* Handles the `subscription.activated` webhook event
|
|
16
|
+
*
|
|
17
|
+
* Fired when a subscription payment is successful and the subscription becomes active.
|
|
18
|
+
* This is when you should grant access to your product.
|
|
19
|
+
*
|
|
20
|
+
* @param payload - The webhook payload containing subscription data
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* onSubscriptionActivated: async (payload) => {
|
|
25
|
+
* await db.update(users)
|
|
26
|
+
* .set({ isPaid: true })
|
|
27
|
+
* .where(eq(users.id, payload.data.externalId));
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
onSubscriptionActivated?: (payload: WebhookPayload) => Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Handles the `subscription.canceled` webhook event
|
|
34
|
+
*
|
|
35
|
+
* Fired when a subscription is canceled (either by the customer or administratively).
|
|
36
|
+
* This is when you should revoke access to your product.
|
|
37
|
+
*
|
|
38
|
+
* @param payload - The webhook payload containing subscription data
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* onSubscriptionCanceled: async (payload) => {
|
|
43
|
+
* await db.update(users)
|
|
44
|
+
* .set({ isPaid: false })
|
|
45
|
+
* .where(eq(users.id, payload.data.externalId));
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
onSubscriptionCanceled?: (payload: WebhookPayload) => Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Handles the `subscription.created` webhook event
|
|
52
|
+
*
|
|
53
|
+
* Fired when a new subscription is created, but before payment is processed.
|
|
54
|
+
* Typically used for logging or analytics, not for granting access.
|
|
55
|
+
*
|
|
56
|
+
* @param payload - The webhook payload containing subscription data
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* onSubscriptionCreated: async (payload) => {
|
|
61
|
+
* console.log(`New subscription: ${payload.data.subscriptionId}`);
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
onSubscriptionCreated?: (payload: WebhookPayload) => Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Handles the `subscription.updated` webhook event
|
|
68
|
+
*
|
|
69
|
+
* Fired when subscription details change (plan, quantity, status, etc.).
|
|
70
|
+
* Use this to handle upgrades, downgrades, or status transitions.
|
|
71
|
+
*
|
|
72
|
+
* @param payload - The webhook payload containing subscription data
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* onSubscriptionUpdated: async (payload) => {
|
|
77
|
+
* if (payload.data.status === 'active') {
|
|
78
|
+
* await handleActivation(payload);
|
|
79
|
+
* }
|
|
80
|
+
* }
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
onSubscriptionUpdated?: (payload: WebhookPayload) => Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Catch-all handler that receives all webhook events
|
|
86
|
+
*
|
|
87
|
+
* Useful for logging, analytics, or handling events without specific handlers.
|
|
88
|
+
* Called in addition to specific event handlers.
|
|
89
|
+
*
|
|
90
|
+
* @param payload - The webhook payload
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* onPayload: async (payload) => {
|
|
95
|
+
* console.log(`Webhook received: ${payload.event}`);
|
|
96
|
+
* await analytics.track('webhook_received', { event: payload.event });
|
|
97
|
+
* }
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
onPayload?: (payload: WebhookPayload) => Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Error handler for webhook processing failures
|
|
103
|
+
*
|
|
104
|
+
* Called when signature verification fails or handlers throw errors.
|
|
105
|
+
* Use this for custom error logging or alerting.
|
|
106
|
+
*
|
|
107
|
+
* @param error - The error that occurred
|
|
108
|
+
* @param payload - The raw payload (may be undefined if parsing failed)
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* onError: async (error, payload) => {
|
|
113
|
+
* console.error('Webhook error:', error);
|
|
114
|
+
* await logger.error('webhook_failed', { error, payload });
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
onError?: (error: Error, payload: unknown) => Promise<void>;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Create a Next.js webhook handler for Commet events
|
|
123
|
+
*
|
|
124
|
+
* Automatically verifies signatures, routes events to handlers, and returns proper responses.
|
|
125
|
+
*
|
|
126
|
+
* @param config - Webhook configuration with secret and event handlers
|
|
127
|
+
* @returns Next.js route handler function
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* // app/api/webhooks/commet/route.ts
|
|
132
|
+
* import { Webhooks } from "@commet/next";
|
|
133
|
+
*
|
|
134
|
+
* export const POST = Webhooks({
|
|
135
|
+
* webhookSecret: process.env.COMMET_WEBHOOK_SECRET!,
|
|
136
|
+
* onSubscriptionActivated: async (payload) => {
|
|
137
|
+
* // Grant access to user
|
|
138
|
+
* },
|
|
139
|
+
* onSubscriptionCanceled: async (payload) => {
|
|
140
|
+
* // Revoke access from user
|
|
141
|
+
* },
|
|
142
|
+
* });
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
declare const Webhooks: (config: WebhooksConfig) => (request: NextRequest) => Promise<NextResponse<{
|
|
146
|
+
received: boolean;
|
|
147
|
+
}>>;
|
|
148
|
+
|
|
149
|
+
export { Webhooks, type WebhooksConfig };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
Webhooks: () => Webhooks
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/webhooks.ts
|
|
28
|
+
var import_node = require("@commet/node");
|
|
29
|
+
var import_server = require("next/server");
|
|
30
|
+
var Webhooks = (config) => {
|
|
31
|
+
const {
|
|
32
|
+
webhookSecret,
|
|
33
|
+
onSubscriptionActivated,
|
|
34
|
+
onSubscriptionCanceled,
|
|
35
|
+
onSubscriptionCreated,
|
|
36
|
+
onSubscriptionUpdated,
|
|
37
|
+
onPayload,
|
|
38
|
+
onError
|
|
39
|
+
} = config;
|
|
40
|
+
const webhooks = new import_node.Webhooks();
|
|
41
|
+
return async (request) => {
|
|
42
|
+
try {
|
|
43
|
+
const rawBody = await request.text();
|
|
44
|
+
const signature = request.headers.get("x-commet-signature");
|
|
45
|
+
const isValid = webhooks.verify(rawBody, signature, webhookSecret);
|
|
46
|
+
if (!isValid) {
|
|
47
|
+
console.error("[Commet Webhook] Invalid signature");
|
|
48
|
+
return import_server.NextResponse.json(
|
|
49
|
+
{ received: false, error: "Invalid signature" },
|
|
50
|
+
{ status: 403 }
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
let payload;
|
|
54
|
+
try {
|
|
55
|
+
payload = JSON.parse(rawBody);
|
|
56
|
+
} catch (parseError) {
|
|
57
|
+
console.error("[Commet Webhook] Failed to parse payload:", parseError);
|
|
58
|
+
if (onError) {
|
|
59
|
+
await onError(
|
|
60
|
+
parseError instanceof Error ? parseError : new Error("Failed to parse webhook payload"),
|
|
61
|
+
rawBody
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
return import_server.NextResponse.json(
|
|
65
|
+
{ received: false, error: "Invalid payload" },
|
|
66
|
+
{ status: 400 }
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
const promises = [];
|
|
70
|
+
if (onPayload) {
|
|
71
|
+
promises.push(onPayload(payload));
|
|
72
|
+
}
|
|
73
|
+
switch (payload.event) {
|
|
74
|
+
case "subscription.activated":
|
|
75
|
+
if (onSubscriptionActivated) {
|
|
76
|
+
promises.push(onSubscriptionActivated(payload));
|
|
77
|
+
}
|
|
78
|
+
break;
|
|
79
|
+
case "subscription.canceled":
|
|
80
|
+
if (onSubscriptionCanceled) {
|
|
81
|
+
promises.push(onSubscriptionCanceled(payload));
|
|
82
|
+
}
|
|
83
|
+
break;
|
|
84
|
+
case "subscription.created":
|
|
85
|
+
if (onSubscriptionCreated) {
|
|
86
|
+
promises.push(onSubscriptionCreated(payload));
|
|
87
|
+
}
|
|
88
|
+
break;
|
|
89
|
+
case "subscription.updated":
|
|
90
|
+
if (onSubscriptionUpdated) {
|
|
91
|
+
promises.push(onSubscriptionUpdated(payload));
|
|
92
|
+
}
|
|
93
|
+
break;
|
|
94
|
+
default:
|
|
95
|
+
console.log(`[Commet Webhook] Unhandled event: ${payload.event}`);
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
await Promise.all(promises);
|
|
99
|
+
} catch (handlerError) {
|
|
100
|
+
console.error(
|
|
101
|
+
"[Commet Webhook] Handler error:",
|
|
102
|
+
handlerError instanceof Error ? handlerError.message : handlerError
|
|
103
|
+
);
|
|
104
|
+
if (onError) {
|
|
105
|
+
await onError(
|
|
106
|
+
handlerError instanceof Error ? handlerError : new Error("Handler execution failed"),
|
|
107
|
+
payload
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
return import_server.NextResponse.json(
|
|
111
|
+
{ received: true, warning: "Handler failed" },
|
|
112
|
+
{ status: 200 }
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
return import_server.NextResponse.json({ received: true }, { status: 200 });
|
|
116
|
+
} catch (error) {
|
|
117
|
+
console.error("[Commet Webhook] Unexpected error:", error);
|
|
118
|
+
if (onError) {
|
|
119
|
+
try {
|
|
120
|
+
await onError(
|
|
121
|
+
error instanceof Error ? error : new Error("Unexpected error"),
|
|
122
|
+
void 0
|
|
123
|
+
);
|
|
124
|
+
} catch (errorHandlerError) {
|
|
125
|
+
console.error(
|
|
126
|
+
"[Commet Webhook] Error handler failed:",
|
|
127
|
+
errorHandlerError
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return import_server.NextResponse.json(
|
|
132
|
+
{ received: false, error: "Internal error" },
|
|
133
|
+
{ status: 500 }
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
139
|
+
0 && (module.exports = {
|
|
140
|
+
Webhooks
|
|
141
|
+
});
|
|
142
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/webhooks.ts"],"sourcesContent":["/**\n * @commet/next - Next.js integration for Commet webhooks\n *\n * @example\n * ```typescript\n * import { Webhooks } from \"@commet/next\";\n *\n * export const POST = Webhooks({\n * webhookSecret: process.env.COMMET_WEBHOOK_SECRET!,\n * onSubscriptionActivated: async (payload) => {\n * // Handle activation\n * },\n * });\n * ```\n *\n * @packageDocumentation\n */\n\nexport { Webhooks } from \"./webhooks\";\nexport type {\n WebhooksConfig,\n WebhookPayload,\n WebhookData,\n WebhookEvent,\n} from \"./types\";\n","import { Webhooks as CommetWebhooks } from \"@commet/node\";\nimport type { WebhookPayload } from \"@commet/node\";\nimport { type NextRequest, NextResponse } from \"next/server\";\nimport type { WebhooksConfig } from \"./types\";\n\n/**\n * Create a Next.js webhook handler for Commet events\n *\n * Automatically verifies signatures, routes events to handlers, and returns proper responses.\n *\n * @param config - Webhook configuration with secret and event handlers\n * @returns Next.js route handler function\n *\n * @example\n * ```typescript\n * // app/api/webhooks/commet/route.ts\n * import { Webhooks } from \"@commet/next\";\n *\n * export const POST = Webhooks({\n * webhookSecret: process.env.COMMET_WEBHOOK_SECRET!,\n * onSubscriptionActivated: async (payload) => {\n * // Grant access to user\n * },\n * onSubscriptionCanceled: async (payload) => {\n * // Revoke access from user\n * },\n * });\n * ```\n */\nexport const Webhooks = (config: WebhooksConfig) => {\n const {\n webhookSecret,\n onSubscriptionActivated,\n onSubscriptionCanceled,\n onSubscriptionCreated,\n onSubscriptionUpdated,\n onPayload,\n onError,\n } = config;\n\n // Create webhook verifier instance\n const webhooks = new CommetWebhooks();\n\n return async (request: NextRequest) => {\n try {\n // 1. Read raw request body\n const rawBody = await request.text();\n\n // 2. Extract signature from headers\n const signature = request.headers.get(\"x-commet-signature\");\n\n // 3. Verify signature\n const isValid = webhooks.verify(rawBody, signature, webhookSecret);\n\n if (!isValid) {\n console.error(\"[Commet Webhook] Invalid signature\");\n return NextResponse.json(\n { received: false, error: \"Invalid signature\" },\n { status: 403 },\n );\n }\n\n // 4. Parse payload\n let payload: WebhookPayload;\n try {\n payload = JSON.parse(rawBody) as WebhookPayload;\n } catch (parseError) {\n console.error(\"[Commet Webhook] Failed to parse payload:\", parseError);\n if (onError) {\n await onError(\n parseError instanceof Error\n ? parseError\n : new Error(\"Failed to parse webhook payload\"),\n rawBody,\n );\n }\n return NextResponse.json(\n { received: false, error: \"Invalid payload\" },\n { status: 400 },\n );\n }\n\n // 5. Collect promises for parallel execution\n const promises: Promise<void>[] = [];\n\n // Call catch-all handler if provided\n if (onPayload) {\n promises.push(onPayload(payload));\n }\n\n // 6. Route to specific event handler\n switch (payload.event) {\n case \"subscription.activated\":\n if (onSubscriptionActivated) {\n promises.push(onSubscriptionActivated(payload));\n }\n break;\n\n case \"subscription.canceled\":\n if (onSubscriptionCanceled) {\n promises.push(onSubscriptionCanceled(payload));\n }\n break;\n\n case \"subscription.created\":\n if (onSubscriptionCreated) {\n promises.push(onSubscriptionCreated(payload));\n }\n break;\n\n case \"subscription.updated\":\n if (onSubscriptionUpdated) {\n promises.push(onSubscriptionUpdated(payload));\n }\n break;\n\n default:\n console.log(`[Commet Webhook] Unhandled event: ${payload.event}`);\n }\n\n // 7. Execute all handlers in parallel\n try {\n await Promise.all(promises);\n } catch (handlerError) {\n console.error(\n \"[Commet Webhook] Handler error:\",\n handlerError instanceof Error ? handlerError.message : handlerError,\n );\n if (onError) {\n await onError(\n handlerError instanceof Error\n ? handlerError\n : new Error(\"Handler execution failed\"),\n payload,\n );\n }\n // Still return 200 to prevent retries for handler errors\n return NextResponse.json(\n { received: true, warning: \"Handler failed\" },\n { status: 200 },\n );\n }\n\n // 8. Success response\n return NextResponse.json({ received: true }, { status: 200 });\n } catch (error) {\n console.error(\"[Commet Webhook] Unexpected error:\", error);\n if (onError) {\n try {\n await onError(\n error instanceof Error ? error : new Error(\"Unexpected error\"),\n undefined,\n );\n } catch (errorHandlerError) {\n console.error(\n \"[Commet Webhook] Error handler failed:\",\n errorHandlerError,\n );\n }\n }\n return NextResponse.json(\n { received: false, error: \"Internal error\" },\n { status: 500 },\n );\n }\n };\n};\n"],"mappings":"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","names":["CommetWebhooks"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// src/webhooks.ts
|
|
2
|
+
import { Webhooks as CommetWebhooks } from "@commet/node";
|
|
3
|
+
import { NextResponse } from "next/server";
|
|
4
|
+
var Webhooks = (config) => {
|
|
5
|
+
const {
|
|
6
|
+
webhookSecret,
|
|
7
|
+
onSubscriptionActivated,
|
|
8
|
+
onSubscriptionCanceled,
|
|
9
|
+
onSubscriptionCreated,
|
|
10
|
+
onSubscriptionUpdated,
|
|
11
|
+
onPayload,
|
|
12
|
+
onError
|
|
13
|
+
} = config;
|
|
14
|
+
const webhooks = new CommetWebhooks();
|
|
15
|
+
return async (request) => {
|
|
16
|
+
try {
|
|
17
|
+
const rawBody = await request.text();
|
|
18
|
+
const signature = request.headers.get("x-commet-signature");
|
|
19
|
+
const isValid = webhooks.verify(rawBody, signature, webhookSecret);
|
|
20
|
+
if (!isValid) {
|
|
21
|
+
console.error("[Commet Webhook] Invalid signature");
|
|
22
|
+
return NextResponse.json(
|
|
23
|
+
{ received: false, error: "Invalid signature" },
|
|
24
|
+
{ status: 403 }
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
let payload;
|
|
28
|
+
try {
|
|
29
|
+
payload = JSON.parse(rawBody);
|
|
30
|
+
} catch (parseError) {
|
|
31
|
+
console.error("[Commet Webhook] Failed to parse payload:", parseError);
|
|
32
|
+
if (onError) {
|
|
33
|
+
await onError(
|
|
34
|
+
parseError instanceof Error ? parseError : new Error("Failed to parse webhook payload"),
|
|
35
|
+
rawBody
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
return NextResponse.json(
|
|
39
|
+
{ received: false, error: "Invalid payload" },
|
|
40
|
+
{ status: 400 }
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
const promises = [];
|
|
44
|
+
if (onPayload) {
|
|
45
|
+
promises.push(onPayload(payload));
|
|
46
|
+
}
|
|
47
|
+
switch (payload.event) {
|
|
48
|
+
case "subscription.activated":
|
|
49
|
+
if (onSubscriptionActivated) {
|
|
50
|
+
promises.push(onSubscriptionActivated(payload));
|
|
51
|
+
}
|
|
52
|
+
break;
|
|
53
|
+
case "subscription.canceled":
|
|
54
|
+
if (onSubscriptionCanceled) {
|
|
55
|
+
promises.push(onSubscriptionCanceled(payload));
|
|
56
|
+
}
|
|
57
|
+
break;
|
|
58
|
+
case "subscription.created":
|
|
59
|
+
if (onSubscriptionCreated) {
|
|
60
|
+
promises.push(onSubscriptionCreated(payload));
|
|
61
|
+
}
|
|
62
|
+
break;
|
|
63
|
+
case "subscription.updated":
|
|
64
|
+
if (onSubscriptionUpdated) {
|
|
65
|
+
promises.push(onSubscriptionUpdated(payload));
|
|
66
|
+
}
|
|
67
|
+
break;
|
|
68
|
+
default:
|
|
69
|
+
console.log(`[Commet Webhook] Unhandled event: ${payload.event}`);
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
await Promise.all(promises);
|
|
73
|
+
} catch (handlerError) {
|
|
74
|
+
console.error(
|
|
75
|
+
"[Commet Webhook] Handler error:",
|
|
76
|
+
handlerError instanceof Error ? handlerError.message : handlerError
|
|
77
|
+
);
|
|
78
|
+
if (onError) {
|
|
79
|
+
await onError(
|
|
80
|
+
handlerError instanceof Error ? handlerError : new Error("Handler execution failed"),
|
|
81
|
+
payload
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
return NextResponse.json(
|
|
85
|
+
{ received: true, warning: "Handler failed" },
|
|
86
|
+
{ status: 200 }
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
return NextResponse.json({ received: true }, { status: 200 });
|
|
90
|
+
} catch (error) {
|
|
91
|
+
console.error("[Commet Webhook] Unexpected error:", error);
|
|
92
|
+
if (onError) {
|
|
93
|
+
try {
|
|
94
|
+
await onError(
|
|
95
|
+
error instanceof Error ? error : new Error("Unexpected error"),
|
|
96
|
+
void 0
|
|
97
|
+
);
|
|
98
|
+
} catch (errorHandlerError) {
|
|
99
|
+
console.error(
|
|
100
|
+
"[Commet Webhook] Error handler failed:",
|
|
101
|
+
errorHandlerError
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return NextResponse.json(
|
|
106
|
+
{ received: false, error: "Internal error" },
|
|
107
|
+
{ status: 500 }
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
export {
|
|
113
|
+
Webhooks
|
|
114
|
+
};
|
|
115
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/webhooks.ts"],"sourcesContent":["import { Webhooks as CommetWebhooks } from \"@commet/node\";\nimport type { WebhookPayload } from \"@commet/node\";\nimport { type NextRequest, NextResponse } from \"next/server\";\nimport type { WebhooksConfig } from \"./types\";\n\n/**\n * Create a Next.js webhook handler for Commet events\n *\n * Automatically verifies signatures, routes events to handlers, and returns proper responses.\n *\n * @param config - Webhook configuration with secret and event handlers\n * @returns Next.js route handler function\n *\n * @example\n * ```typescript\n * // app/api/webhooks/commet/route.ts\n * import { Webhooks } from \"@commet/next\";\n *\n * export const POST = Webhooks({\n * webhookSecret: process.env.COMMET_WEBHOOK_SECRET!,\n * onSubscriptionActivated: async (payload) => {\n * // Grant access to user\n * },\n * onSubscriptionCanceled: async (payload) => {\n * // Revoke access from user\n * },\n * });\n * ```\n */\nexport const Webhooks = (config: WebhooksConfig) => {\n const {\n webhookSecret,\n onSubscriptionActivated,\n onSubscriptionCanceled,\n onSubscriptionCreated,\n onSubscriptionUpdated,\n onPayload,\n onError,\n } = config;\n\n // Create webhook verifier instance\n const webhooks = new CommetWebhooks();\n\n return async (request: NextRequest) => {\n try {\n // 1. Read raw request body\n const rawBody = await request.text();\n\n // 2. Extract signature from headers\n const signature = request.headers.get(\"x-commet-signature\");\n\n // 3. Verify signature\n const isValid = webhooks.verify(rawBody, signature, webhookSecret);\n\n if (!isValid) {\n console.error(\"[Commet Webhook] Invalid signature\");\n return NextResponse.json(\n { received: false, error: \"Invalid signature\" },\n { status: 403 },\n );\n }\n\n // 4. Parse payload\n let payload: WebhookPayload;\n try {\n payload = JSON.parse(rawBody) as WebhookPayload;\n } catch (parseError) {\n console.error(\"[Commet Webhook] Failed to parse payload:\", parseError);\n if (onError) {\n await onError(\n parseError instanceof Error\n ? parseError\n : new Error(\"Failed to parse webhook payload\"),\n rawBody,\n );\n }\n return NextResponse.json(\n { received: false, error: \"Invalid payload\" },\n { status: 400 },\n );\n }\n\n // 5. Collect promises for parallel execution\n const promises: Promise<void>[] = [];\n\n // Call catch-all handler if provided\n if (onPayload) {\n promises.push(onPayload(payload));\n }\n\n // 6. Route to specific event handler\n switch (payload.event) {\n case \"subscription.activated\":\n if (onSubscriptionActivated) {\n promises.push(onSubscriptionActivated(payload));\n }\n break;\n\n case \"subscription.canceled\":\n if (onSubscriptionCanceled) {\n promises.push(onSubscriptionCanceled(payload));\n }\n break;\n\n case \"subscription.created\":\n if (onSubscriptionCreated) {\n promises.push(onSubscriptionCreated(payload));\n }\n break;\n\n case \"subscription.updated\":\n if (onSubscriptionUpdated) {\n promises.push(onSubscriptionUpdated(payload));\n }\n break;\n\n default:\n console.log(`[Commet Webhook] Unhandled event: ${payload.event}`);\n }\n\n // 7. Execute all handlers in parallel\n try {\n await Promise.all(promises);\n } catch (handlerError) {\n console.error(\n \"[Commet Webhook] Handler error:\",\n handlerError instanceof Error ? handlerError.message : handlerError,\n );\n if (onError) {\n await onError(\n handlerError instanceof Error\n ? handlerError\n : new Error(\"Handler execution failed\"),\n payload,\n );\n }\n // Still return 200 to prevent retries for handler errors\n return NextResponse.json(\n { received: true, warning: \"Handler failed\" },\n { status: 200 },\n );\n }\n\n // 8. Success response\n return NextResponse.json({ received: true }, { status: 200 });\n } catch (error) {\n console.error(\"[Commet Webhook] Unexpected error:\", error);\n if (onError) {\n try {\n await onError(\n error instanceof Error ? error : new Error(\"Unexpected error\"),\n undefined,\n );\n } catch (errorHandlerError) {\n console.error(\n \"[Commet Webhook] Error handler failed:\",\n errorHandlerError,\n );\n }\n }\n return NextResponse.json(\n { received: false, error: \"Internal error\" },\n { status: 500 },\n );\n }\n };\n};\n"],"mappings":";AAAA,SAAS,YAAY,sBAAsB;AAE3C,SAA2B,oBAAoB;AA2BxC,IAAM,WAAW,CAAC,WAA2B;AAClD,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AAGJ,QAAM,WAAW,IAAI,eAAe;AAEpC,SAAO,OAAO,YAAyB;AACrC,QAAI;AAEF,YAAM,UAAU,MAAM,QAAQ,KAAK;AAGnC,YAAM,YAAY,QAAQ,QAAQ,IAAI,oBAAoB;AAG1D,YAAM,UAAU,SAAS,OAAO,SAAS,WAAW,aAAa;AAEjE,UAAI,CAAC,SAAS;AACZ,gBAAQ,MAAM,oCAAoC;AAClD,eAAO,aAAa;AAAA,UAClB,EAAE,UAAU,OAAO,OAAO,oBAAoB;AAAA,UAC9C,EAAE,QAAQ,IAAI;AAAA,QAChB;AAAA,MACF;AAGA,UAAI;AACJ,UAAI;AACF,kBAAU,KAAK,MAAM,OAAO;AAAA,MAC9B,SAAS,YAAY;AACnB,gBAAQ,MAAM,6CAA6C,UAAU;AACrE,YAAI,SAAS;AACX,gBAAM;AAAA,YACJ,sBAAsB,QAClB,aACA,IAAI,MAAM,iCAAiC;AAAA,YAC/C;AAAA,UACF;AAAA,QACF;AACA,eAAO,aAAa;AAAA,UAClB,EAAE,UAAU,OAAO,OAAO,kBAAkB;AAAA,UAC5C,EAAE,QAAQ,IAAI;AAAA,QAChB;AAAA,MACF;AAGA,YAAM,WAA4B,CAAC;AAGnC,UAAI,WAAW;AACb,iBAAS,KAAK,UAAU,OAAO,CAAC;AAAA,MAClC;AAGA,cAAQ,QAAQ,OAAO;AAAA,QACrB,KAAK;AACH,cAAI,yBAAyB;AAC3B,qBAAS,KAAK,wBAAwB,OAAO,CAAC;AAAA,UAChD;AACA;AAAA,QAEF,KAAK;AACH,cAAI,wBAAwB;AAC1B,qBAAS,KAAK,uBAAuB,OAAO,CAAC;AAAA,UAC/C;AACA;AAAA,QAEF,KAAK;AACH,cAAI,uBAAuB;AACzB,qBAAS,KAAK,sBAAsB,OAAO,CAAC;AAAA,UAC9C;AACA;AAAA,QAEF,KAAK;AACH,cAAI,uBAAuB;AACzB,qBAAS,KAAK,sBAAsB,OAAO,CAAC;AAAA,UAC9C;AACA;AAAA,QAEF;AACE,kBAAQ,IAAI,qCAAqC,QAAQ,KAAK,EAAE;AAAA,MACpE;AAGA,UAAI;AACF,cAAM,QAAQ,IAAI,QAAQ;AAAA,MAC5B,SAAS,cAAc;AACrB,gBAAQ;AAAA,UACN;AAAA,UACA,wBAAwB,QAAQ,aAAa,UAAU;AAAA,QACzD;AACA,YAAI,SAAS;AACX,gBAAM;AAAA,YACJ,wBAAwB,QACpB,eACA,IAAI,MAAM,0BAA0B;AAAA,YACxC;AAAA,UACF;AAAA,QACF;AAEA,eAAO,aAAa;AAAA,UAClB,EAAE,UAAU,MAAM,SAAS,iBAAiB;AAAA,UAC5C,EAAE,QAAQ,IAAI;AAAA,QAChB;AAAA,MACF;AAGA,aAAO,aAAa,KAAK,EAAE,UAAU,KAAK,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,IAC9D,SAAS,OAAO;AACd,cAAQ,MAAM,sCAAsC,KAAK;AACzD,UAAI,SAAS;AACX,YAAI;AACF,gBAAM;AAAA,YACJ,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,kBAAkB;AAAA,YAC7D;AAAA,UACF;AAAA,QACF,SAAS,mBAAmB;AAC1B,kBAAQ;AAAA,YACN;AAAA,YACA;AAAA,UACF;AAAA,QACF;AAAA,MACF;AACA,aAAO,aAAa;AAAA,QAClB,EAAE,UAAU,OAAO,OAAO,iBAAiB;AAAA,QAC3C,EAAE,QAAQ,IAAI;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@commet/next",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Next.js integration for Commet billing platform",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": ["dist", "README.md"],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsup",
|
|
18
|
+
"dev": "tsup --watch",
|
|
19
|
+
"lint": "biome lint src/",
|
|
20
|
+
"lint:fix": "biome lint --write src/",
|
|
21
|
+
"typecheck": "tsc --noEmit",
|
|
22
|
+
"test": "vitest run",
|
|
23
|
+
"test:watch": "vitest"
|
|
24
|
+
},
|
|
25
|
+
"keywords": ["commet", "billing", "nextjs", "webhooks", "typescript"],
|
|
26
|
+
"author": "Commet Team",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@commet/node": "workspace:*"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/node": "24.10.1",
|
|
33
|
+
"next": "15.1.3",
|
|
34
|
+
"tsup": "8.5.0",
|
|
35
|
+
"typescript": "5.9.3",
|
|
36
|
+
"vitest": "2.1.8"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"next": ">=14.0.0"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=18.0.0"
|
|
43
|
+
},
|
|
44
|
+
"homepage": "https://commet.co",
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "https://github.com/commet-labs/commet.git",
|
|
48
|
+
"directory": "packages/next"
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
}
|
|
53
|
+
}
|