@upstash/qstash 2.5.0 → 2.5.1-canary

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/dist/nextjs.js DELETED
@@ -1,164 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
-
4
-
5
- var _chunkEROSIHWEjs = require('./chunk-EROSIHWE.js');
6
-
7
- // src/nextjs.ts
8
- var _server = require('next/server');
9
- function verifySignature(handler, config) {
10
- var _a, _b;
11
- const currentSigningKey = (_a = config == null ? void 0 : config.currentSigningKey) != null ? _a : process.env.QSTASH_CURRENT_SIGNING_KEY;
12
- if (!currentSigningKey) {
13
- throw new Error(
14
- "currentSigningKey is required, either in the config or as env variable QSTASH_CURRENT_SIGNING_KEY"
15
- );
16
- }
17
- const nextSigningKey = (_b = config == null ? void 0 : config.nextSigningKey) != null ? _b : process.env.QSTASH_NEXT_SIGNING_KEY;
18
- if (!nextSigningKey) {
19
- throw new Error(
20
- "nextSigningKey is required, either in the config or as env variable QSTASH_NEXT_SIGNING_KEY"
21
- );
22
- }
23
- const receiver = new (0, _chunkEROSIHWEjs.Receiver)({
24
- currentSigningKey,
25
- nextSigningKey
26
- });
27
- return (req, res) => _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () {
28
- const signature = req.headers["upstash-signature"];
29
- if (!signature) {
30
- res.status(400);
31
- res.send("`Upstash-Signature` header is missing");
32
- res.end();
33
- return;
34
- }
35
- if (typeof signature !== "string") {
36
- throw new Error("`Upstash-Signature` header is not a string");
37
- }
38
- const chunks = [];
39
- try {
40
- for (var iter = _chunkEROSIHWEjs.__forAwait.call(void 0, req), more, temp, error; more = !(temp = yield iter.next()).done; more = false) {
41
- const chunk = temp.value;
42
- chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
43
- }
44
- } catch (temp) {
45
- error = [temp];
46
- } finally {
47
- try {
48
- more && (temp = iter.return) && (yield temp.call(iter));
49
- } finally {
50
- if (error)
51
- throw error[0];
52
- }
53
- }
54
- const body = Buffer.concat(chunks).toString("utf-8");
55
- const isValid = yield receiver.verify({
56
- signature,
57
- body,
58
- clockTolerance: config == null ? void 0 : config.clockTolerance
59
- });
60
- if (!isValid) {
61
- res.status(400);
62
- res.send("Invalid signature");
63
- res.end();
64
- return;
65
- }
66
- try {
67
- if (req.headers["content-type"] === "application/json") {
68
- req.body = JSON.parse(body);
69
- } else {
70
- req.body = body;
71
- }
72
- } catch (e) {
73
- req.body = body;
74
- }
75
- return handler(req, res);
76
- });
77
- }
78
- function verifySignatureEdge(handler, config) {
79
- var _a, _b;
80
- const currentSigningKey = (_a = config == null ? void 0 : config.currentSigningKey) != null ? _a : process.env.QSTASH_CURRENT_SIGNING_KEY;
81
- if (!currentSigningKey) {
82
- throw new Error(
83
- "currentSigningKey is required, either in the config or as env variable QSTASH_CURRENT_SIGNING_KEY"
84
- );
85
- }
86
- const nextSigningKey = (_b = config == null ? void 0 : config.nextSigningKey) != null ? _b : process.env.QSTASH_NEXT_SIGNING_KEY;
87
- if (!nextSigningKey) {
88
- throw new Error(
89
- "nextSigningKey is required, either in the config or as env variable QSTASH_NEXT_SIGNING_KEY"
90
- );
91
- }
92
- const receiver = new (0, _chunkEROSIHWEjs.Receiver)({
93
- currentSigningKey,
94
- nextSigningKey
95
- });
96
- return (req, nfe) => _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () {
97
- const reqClone = req.clone();
98
- const signature = req.headers.get("upstash-signature");
99
- if (!signature) {
100
- return new (0, _server.NextResponse)(new TextEncoder().encode("`Upstash-Signature` header is missing"), {
101
- status: 403
102
- });
103
- }
104
- if (typeof signature !== "string") {
105
- throw new Error("`Upstash-Signature` header is not a string");
106
- }
107
- const body = yield req.text();
108
- const isValid = yield receiver.verify({
109
- signature,
110
- body,
111
- clockTolerance: config == null ? void 0 : config.clockTolerance
112
- });
113
- if (!isValid) {
114
- return new (0, _server.NextResponse)(new TextEncoder().encode("invalid signature"), { status: 403 });
115
- }
116
- return handler(reqClone, nfe);
117
- });
118
- }
119
- function verifySignatureAppRouter(handler, config) {
120
- var _a, _b;
121
- const currentSigningKey = (_a = config == null ? void 0 : config.currentSigningKey) != null ? _a : process.env.QSTASH_CURRENT_SIGNING_KEY;
122
- if (!currentSigningKey) {
123
- throw new Error(
124
- "currentSigningKey is required, either in the config or as env variable QSTASH_CURRENT_SIGNING_KEY"
125
- );
126
- }
127
- const nextSigningKey = (_b = config == null ? void 0 : config.nextSigningKey) != null ? _b : process.env.QSTASH_NEXT_SIGNING_KEY;
128
- if (!nextSigningKey) {
129
- throw new Error(
130
- "nextSigningKey is required, either in the config or as env variable QSTASH_NEXT_SIGNING_KEY"
131
- );
132
- }
133
- const receiver = new (0, _chunkEROSIHWEjs.Receiver)({
134
- currentSigningKey,
135
- nextSigningKey
136
- });
137
- return (req) => _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () {
138
- const reqClone = req.clone();
139
- const signature = req.headers.get("upstash-signature");
140
- if (!signature) {
141
- return new (0, _server.NextResponse)(new TextEncoder().encode("`Upstash-Signature` header is missing"), {
142
- status: 403
143
- });
144
- }
145
- if (typeof signature !== "string") {
146
- throw new Error("`Upstash-Signature` header is not a string");
147
- }
148
- const body = yield req.text();
149
- const isValid = yield receiver.verify({
150
- signature,
151
- body,
152
- clockTolerance: config == null ? void 0 : config.clockTolerance
153
- });
154
- if (!isValid) {
155
- return new (0, _server.NextResponse)(new TextEncoder().encode("invalid signature"), { status: 403 });
156
- }
157
- return handler(reqClone);
158
- });
159
- }
160
-
161
-
162
-
163
-
164
- exports.verifySignature = verifySignature; exports.verifySignatureAppRouter = verifySignatureAppRouter; exports.verifySignatureEdge = verifySignatureEdge;
package/dist/nextjs.mjs DELETED
@@ -1,164 +0,0 @@
1
- import {
2
- Receiver,
3
- __async,
4
- __forAwait
5
- } from "./chunk-FK4ORXI6.mjs";
6
-
7
- // src/nextjs.ts
8
- import { NextResponse } from "next/server";
9
- function verifySignature(handler, config) {
10
- var _a, _b;
11
- const currentSigningKey = (_a = config == null ? void 0 : config.currentSigningKey) != null ? _a : process.env.QSTASH_CURRENT_SIGNING_KEY;
12
- if (!currentSigningKey) {
13
- throw new Error(
14
- "currentSigningKey is required, either in the config or as env variable QSTASH_CURRENT_SIGNING_KEY"
15
- );
16
- }
17
- const nextSigningKey = (_b = config == null ? void 0 : config.nextSigningKey) != null ? _b : process.env.QSTASH_NEXT_SIGNING_KEY;
18
- if (!nextSigningKey) {
19
- throw new Error(
20
- "nextSigningKey is required, either in the config or as env variable QSTASH_NEXT_SIGNING_KEY"
21
- );
22
- }
23
- const receiver = new Receiver({
24
- currentSigningKey,
25
- nextSigningKey
26
- });
27
- return (req, res) => __async(this, null, function* () {
28
- const signature = req.headers["upstash-signature"];
29
- if (!signature) {
30
- res.status(400);
31
- res.send("`Upstash-Signature` header is missing");
32
- res.end();
33
- return;
34
- }
35
- if (typeof signature !== "string") {
36
- throw new Error("`Upstash-Signature` header is not a string");
37
- }
38
- const chunks = [];
39
- try {
40
- for (var iter = __forAwait(req), more, temp, error; more = !(temp = yield iter.next()).done; more = false) {
41
- const chunk = temp.value;
42
- chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
43
- }
44
- } catch (temp) {
45
- error = [temp];
46
- } finally {
47
- try {
48
- more && (temp = iter.return) && (yield temp.call(iter));
49
- } finally {
50
- if (error)
51
- throw error[0];
52
- }
53
- }
54
- const body = Buffer.concat(chunks).toString("utf-8");
55
- const isValid = yield receiver.verify({
56
- signature,
57
- body,
58
- clockTolerance: config == null ? void 0 : config.clockTolerance
59
- });
60
- if (!isValid) {
61
- res.status(400);
62
- res.send("Invalid signature");
63
- res.end();
64
- return;
65
- }
66
- try {
67
- if (req.headers["content-type"] === "application/json") {
68
- req.body = JSON.parse(body);
69
- } else {
70
- req.body = body;
71
- }
72
- } catch (e) {
73
- req.body = body;
74
- }
75
- return handler(req, res);
76
- });
77
- }
78
- function verifySignatureEdge(handler, config) {
79
- var _a, _b;
80
- const currentSigningKey = (_a = config == null ? void 0 : config.currentSigningKey) != null ? _a : process.env.QSTASH_CURRENT_SIGNING_KEY;
81
- if (!currentSigningKey) {
82
- throw new Error(
83
- "currentSigningKey is required, either in the config or as env variable QSTASH_CURRENT_SIGNING_KEY"
84
- );
85
- }
86
- const nextSigningKey = (_b = config == null ? void 0 : config.nextSigningKey) != null ? _b : process.env.QSTASH_NEXT_SIGNING_KEY;
87
- if (!nextSigningKey) {
88
- throw new Error(
89
- "nextSigningKey is required, either in the config or as env variable QSTASH_NEXT_SIGNING_KEY"
90
- );
91
- }
92
- const receiver = new Receiver({
93
- currentSigningKey,
94
- nextSigningKey
95
- });
96
- return (req, nfe) => __async(this, null, function* () {
97
- const reqClone = req.clone();
98
- const signature = req.headers.get("upstash-signature");
99
- if (!signature) {
100
- return new NextResponse(new TextEncoder().encode("`Upstash-Signature` header is missing"), {
101
- status: 403
102
- });
103
- }
104
- if (typeof signature !== "string") {
105
- throw new Error("`Upstash-Signature` header is not a string");
106
- }
107
- const body = yield req.text();
108
- const isValid = yield receiver.verify({
109
- signature,
110
- body,
111
- clockTolerance: config == null ? void 0 : config.clockTolerance
112
- });
113
- if (!isValid) {
114
- return new NextResponse(new TextEncoder().encode("invalid signature"), { status: 403 });
115
- }
116
- return handler(reqClone, nfe);
117
- });
118
- }
119
- function verifySignatureAppRouter(handler, config) {
120
- var _a, _b;
121
- const currentSigningKey = (_a = config == null ? void 0 : config.currentSigningKey) != null ? _a : process.env.QSTASH_CURRENT_SIGNING_KEY;
122
- if (!currentSigningKey) {
123
- throw new Error(
124
- "currentSigningKey is required, either in the config or as env variable QSTASH_CURRENT_SIGNING_KEY"
125
- );
126
- }
127
- const nextSigningKey = (_b = config == null ? void 0 : config.nextSigningKey) != null ? _b : process.env.QSTASH_NEXT_SIGNING_KEY;
128
- if (!nextSigningKey) {
129
- throw new Error(
130
- "nextSigningKey is required, either in the config or as env variable QSTASH_NEXT_SIGNING_KEY"
131
- );
132
- }
133
- const receiver = new Receiver({
134
- currentSigningKey,
135
- nextSigningKey
136
- });
137
- return (req) => __async(this, null, function* () {
138
- const reqClone = req.clone();
139
- const signature = req.headers.get("upstash-signature");
140
- if (!signature) {
141
- return new NextResponse(new TextEncoder().encode("`Upstash-Signature` header is missing"), {
142
- status: 403
143
- });
144
- }
145
- if (typeof signature !== "string") {
146
- throw new Error("`Upstash-Signature` header is not a string");
147
- }
148
- const body = yield req.text();
149
- const isValid = yield receiver.verify({
150
- signature,
151
- body,
152
- clockTolerance: config == null ? void 0 : config.clockTolerance
153
- });
154
- if (!isValid) {
155
- return new NextResponse(new TextEncoder().encode("invalid signature"), { status: 403 });
156
- }
157
- return handler(reqClone);
158
- });
159
- }
160
- export {
161
- verifySignature,
162
- verifySignatureAppRouter,
163
- verifySignatureEdge
164
- };