@upstash/qstash 2.4.3 → 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/README.md +1 -1
- package/chunk-CP4IU45K.mjs +59 -0
- package/chunk-UUR7N6E6.js +59 -0
- package/{dist/index.d.mts → index.d.mts} +80 -17
- package/{dist/index.d.ts → index.d.ts} +80 -17
- package/index.js +583 -0
- package/index.mjs +583 -0
- package/{dist/nextjs.d.mts → nextjs.d.mts} +4 -4
- package/{dist/nextjs.d.ts → nextjs.d.ts} +4 -4
- package/nextjs.js +144 -0
- package/nextjs.mjs +144 -0
- package/package.json +1 -54
- package/dist/chunk-EROSIHWE.js +0 -111
- package/dist/chunk-FK4ORXI6.mjs +0 -111
- package/dist/index.js +0 -512
- package/dist/index.mjs +0 -512
- package/dist/nextjs.js +0 -164
- package/dist/nextjs.mjs +0 -164
package/dist/index.mjs
DELETED
|
@@ -1,512 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Receiver,
|
|
3
|
-
SignatureError,
|
|
4
|
-
__async,
|
|
5
|
-
__spreadProps,
|
|
6
|
-
__spreadValues
|
|
7
|
-
} from "./chunk-FK4ORXI6.mjs";
|
|
8
|
-
|
|
9
|
-
// src/client/dlq.ts
|
|
10
|
-
var DLQ = class {
|
|
11
|
-
constructor(http) {
|
|
12
|
-
this.http = http;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* List messages in the dlq
|
|
16
|
-
*/
|
|
17
|
-
listMessages(opts) {
|
|
18
|
-
return __async(this, null, function* () {
|
|
19
|
-
return yield this.http.request({
|
|
20
|
-
method: "GET",
|
|
21
|
-
path: ["v2", "dlq"],
|
|
22
|
-
query: { cursor: opts == null ? void 0 : opts.cursor }
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Remove a message from the dlq using it's `dlqId`
|
|
28
|
-
*/
|
|
29
|
-
delete(dlqMessageId) {
|
|
30
|
-
return __async(this, null, function* () {
|
|
31
|
-
return yield this.http.request({
|
|
32
|
-
method: "DELETE",
|
|
33
|
-
path: ["v2", "dlq", dlqMessageId],
|
|
34
|
-
parseResponseAsJson: false
|
|
35
|
-
// there is no response
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Remove multiple messages from the dlq using their `dlqId`s
|
|
41
|
-
*/
|
|
42
|
-
deleteMany(req) {
|
|
43
|
-
return __async(this, null, function* () {
|
|
44
|
-
return yield this.http.request({
|
|
45
|
-
method: "DELETE",
|
|
46
|
-
path: ["v2", "dlq"],
|
|
47
|
-
headers: { "Content-Type": "application/json" },
|
|
48
|
-
body: JSON.stringify({ dlqIds: req.dlqIds })
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
// src/client/error.ts
|
|
55
|
-
var QstashError = class extends Error {
|
|
56
|
-
constructor(message) {
|
|
57
|
-
super(message);
|
|
58
|
-
this.name = "QstashError";
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
var QstashRatelimitError = class extends QstashError {
|
|
62
|
-
constructor(args) {
|
|
63
|
-
super(`You have been ratelimited. ${JSON.stringify(args)} `);
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
// src/client/http.ts
|
|
68
|
-
var HttpClient = class {
|
|
69
|
-
constructor(config) {
|
|
70
|
-
var _a, _b, _c;
|
|
71
|
-
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
72
|
-
this.authorization = config.authorization;
|
|
73
|
-
if (typeof (config == null ? void 0 : config.retry) === "boolean" && (config == null ? void 0 : config.retry) === false) {
|
|
74
|
-
this.retry = {
|
|
75
|
-
attempts: 1,
|
|
76
|
-
backoff: () => 0
|
|
77
|
-
};
|
|
78
|
-
} else {
|
|
79
|
-
this.retry = {
|
|
80
|
-
attempts: ((_a = config.retry) == null ? void 0 : _a.retries) ? config.retry.retries + 1 : 5,
|
|
81
|
-
backoff: (_c = (_b = config.retry) == null ? void 0 : _b.backoff) != null ? _c : (retryCount) => Math.exp(retryCount) * 50
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
request(req) {
|
|
86
|
-
return __async(this, null, function* () {
|
|
87
|
-
var _a;
|
|
88
|
-
const headers = new Headers(req.headers);
|
|
89
|
-
headers.set("Authorization", this.authorization);
|
|
90
|
-
const requestOptions = {
|
|
91
|
-
method: req.method,
|
|
92
|
-
headers,
|
|
93
|
-
body: req.body,
|
|
94
|
-
keepalive: req.keepalive
|
|
95
|
-
};
|
|
96
|
-
const url = new URL([this.baseUrl, ...(_a = req.path) != null ? _a : []].join("/"));
|
|
97
|
-
if (req.query) {
|
|
98
|
-
for (const [key, value] of Object.entries(req.query)) {
|
|
99
|
-
if (typeof value !== "undefined") {
|
|
100
|
-
url.searchParams.set(key, value.toString());
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
let res = null;
|
|
105
|
-
let error = null;
|
|
106
|
-
for (let i = 0; i < this.retry.attempts; i++) {
|
|
107
|
-
try {
|
|
108
|
-
res = yield fetch(url.toString(), requestOptions);
|
|
109
|
-
break;
|
|
110
|
-
} catch (err) {
|
|
111
|
-
error = err;
|
|
112
|
-
yield new Promise((r) => setTimeout(r, this.retry.backoff(i)));
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
if (!res) {
|
|
116
|
-
throw error != null ? error : new Error("Exhausted all retries");
|
|
117
|
-
}
|
|
118
|
-
if (res.status === 429) {
|
|
119
|
-
throw new QstashRatelimitError({
|
|
120
|
-
limit: res.headers.get("Burst-RateLimit-Limit"),
|
|
121
|
-
remaining: res.headers.get("Burst-RateLimit-Remaining"),
|
|
122
|
-
reset: res.headers.get("Burst-RateLimit-Reset")
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
if (res.status < 200 || res.status >= 300) {
|
|
126
|
-
const body = yield res.text();
|
|
127
|
-
throw new QstashError(body.length > 0 ? body : `Error: status=${res.status}`);
|
|
128
|
-
}
|
|
129
|
-
if (req.parseResponseAsJson === false) {
|
|
130
|
-
return void 0;
|
|
131
|
-
} else {
|
|
132
|
-
return yield res.json();
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
// src/client/messages.ts
|
|
139
|
-
var Messages = class {
|
|
140
|
-
constructor(http) {
|
|
141
|
-
this.http = http;
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Get a message
|
|
145
|
-
*/
|
|
146
|
-
get(messageId) {
|
|
147
|
-
return __async(this, null, function* () {
|
|
148
|
-
return yield this.http.request({
|
|
149
|
-
method: "GET",
|
|
150
|
-
path: ["v2", "messages", messageId]
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Cancel a message
|
|
156
|
-
*/
|
|
157
|
-
delete(messageId) {
|
|
158
|
-
return __async(this, null, function* () {
|
|
159
|
-
return yield this.http.request({
|
|
160
|
-
method: "DELETE",
|
|
161
|
-
path: ["v2", "messages", messageId],
|
|
162
|
-
parseResponseAsJson: false
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
// src/client/utils.ts
|
|
169
|
-
function prefixHeaders(headers) {
|
|
170
|
-
const isIgnoredHeader = (header) => {
|
|
171
|
-
const lowerCaseHeader = header.toLowerCase();
|
|
172
|
-
return lowerCaseHeader.startsWith("content-type") || lowerCaseHeader.startsWith("upstash-");
|
|
173
|
-
};
|
|
174
|
-
const keysToBePrefixed = Array.from(headers.keys()).filter(
|
|
175
|
-
(key) => !isIgnoredHeader(key)
|
|
176
|
-
);
|
|
177
|
-
for (const key of keysToBePrefixed) {
|
|
178
|
-
const value = headers.get(key);
|
|
179
|
-
if (value !== null) {
|
|
180
|
-
headers.set(`Upstash-Forward-${key}`, value);
|
|
181
|
-
}
|
|
182
|
-
headers.delete(key);
|
|
183
|
-
}
|
|
184
|
-
return headers;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// src/client/schedules.ts
|
|
188
|
-
var Schedules = class {
|
|
189
|
-
constructor(http) {
|
|
190
|
-
this.http = http;
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Create a schedule
|
|
194
|
-
*/
|
|
195
|
-
create(req) {
|
|
196
|
-
return __async(this, null, function* () {
|
|
197
|
-
const headers = prefixHeaders(new Headers(req.headers));
|
|
198
|
-
if (!headers.has("Content-Type")) {
|
|
199
|
-
headers.set("Content-Type", "application/json");
|
|
200
|
-
}
|
|
201
|
-
headers.set("Upstash-Cron", req.cron);
|
|
202
|
-
if (typeof req.method !== "undefined") {
|
|
203
|
-
headers.set("Upstash-Method", req.method);
|
|
204
|
-
}
|
|
205
|
-
if (typeof req.delay !== "undefined") {
|
|
206
|
-
headers.set("Upstash-Delay", `${req.delay.toFixed()}s`);
|
|
207
|
-
}
|
|
208
|
-
if (typeof req.retries !== "undefined") {
|
|
209
|
-
headers.set("Upstash-Retries", req.retries.toFixed());
|
|
210
|
-
}
|
|
211
|
-
if (typeof req.callback !== "undefined") {
|
|
212
|
-
headers.set("Upstash-Callback", req.callback);
|
|
213
|
-
}
|
|
214
|
-
if (typeof req.failureCallback !== "undefined") {
|
|
215
|
-
headers.set("Upstash-Failure-Callback", req.failureCallback);
|
|
216
|
-
}
|
|
217
|
-
return yield this.http.request({
|
|
218
|
-
method: "POST",
|
|
219
|
-
headers,
|
|
220
|
-
path: ["v2", "schedules", req.destination],
|
|
221
|
-
body: req.body
|
|
222
|
-
});
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Get a schedule
|
|
227
|
-
*/
|
|
228
|
-
get(scheduleId) {
|
|
229
|
-
return __async(this, null, function* () {
|
|
230
|
-
return yield this.http.request({
|
|
231
|
-
method: "GET",
|
|
232
|
-
path: ["v2", "schedules", scheduleId]
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* List your schedules
|
|
238
|
-
*/
|
|
239
|
-
list() {
|
|
240
|
-
return __async(this, null, function* () {
|
|
241
|
-
return yield this.http.request({
|
|
242
|
-
method: "GET",
|
|
243
|
-
path: ["v2", "schedules"]
|
|
244
|
-
});
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Delete a schedule
|
|
249
|
-
*/
|
|
250
|
-
delete(scheduleId) {
|
|
251
|
-
return __async(this, null, function* () {
|
|
252
|
-
return yield this.http.request({
|
|
253
|
-
method: "DELETE",
|
|
254
|
-
path: ["v2", "schedules", scheduleId],
|
|
255
|
-
parseResponseAsJson: false
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
// src/client/topics.ts
|
|
262
|
-
var Topics = class {
|
|
263
|
-
constructor(http) {
|
|
264
|
-
this.http = http;
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* Create a new topic with the given name and endpoints
|
|
268
|
-
*/
|
|
269
|
-
addEndpoints(req) {
|
|
270
|
-
return __async(this, null, function* () {
|
|
271
|
-
yield this.http.request({
|
|
272
|
-
method: "POST",
|
|
273
|
-
path: ["v2", "topics", req.name, "endpoints"],
|
|
274
|
-
headers: { "Content-Type": "application/json" },
|
|
275
|
-
body: JSON.stringify({ endpoints: req.endpoints }),
|
|
276
|
-
parseResponseAsJson: false
|
|
277
|
-
});
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* Remove endpoints from a topic.
|
|
282
|
-
*/
|
|
283
|
-
removeEndpoints(req) {
|
|
284
|
-
return __async(this, null, function* () {
|
|
285
|
-
yield this.http.request({
|
|
286
|
-
method: "DELETE",
|
|
287
|
-
path: ["v2", "topics", req.name, "endpoints"],
|
|
288
|
-
headers: { "Content-Type": "application/json" },
|
|
289
|
-
body: JSON.stringify({ endpoints: req.endpoints }),
|
|
290
|
-
parseResponseAsJson: false
|
|
291
|
-
});
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* Get a list of all topics.
|
|
296
|
-
*/
|
|
297
|
-
list() {
|
|
298
|
-
return __async(this, null, function* () {
|
|
299
|
-
return yield this.http.request({
|
|
300
|
-
method: "GET",
|
|
301
|
-
path: ["v2", "topics"]
|
|
302
|
-
});
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
/**
|
|
306
|
-
* Get a single topic
|
|
307
|
-
*/
|
|
308
|
-
get(name) {
|
|
309
|
-
return __async(this, null, function* () {
|
|
310
|
-
return yield this.http.request({
|
|
311
|
-
method: "GET",
|
|
312
|
-
path: ["v2", "topics", name]
|
|
313
|
-
});
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* Delete a topic
|
|
318
|
-
*/
|
|
319
|
-
delete(name) {
|
|
320
|
-
return __async(this, null, function* () {
|
|
321
|
-
return yield this.http.request({
|
|
322
|
-
method: "DELETE",
|
|
323
|
-
path: ["v2", "topics", name],
|
|
324
|
-
parseResponseAsJson: false
|
|
325
|
-
});
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
// src/client/client.ts
|
|
331
|
-
var Client = class {
|
|
332
|
-
constructor(config) {
|
|
333
|
-
this.http = new HttpClient({
|
|
334
|
-
retry: config.retry,
|
|
335
|
-
baseUrl: config.baseUrl ? config.baseUrl.replace(/\/$/, "") : "https://qstash.upstash.io",
|
|
336
|
-
authorization: `Bearer ${config.token}`
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
/**
|
|
340
|
-
* Access the topic API.
|
|
341
|
-
*
|
|
342
|
-
* Create, read, update or delete topics.
|
|
343
|
-
*/
|
|
344
|
-
get topics() {
|
|
345
|
-
return new Topics(this.http);
|
|
346
|
-
}
|
|
347
|
-
/**
|
|
348
|
-
* Access the dlq API.
|
|
349
|
-
*
|
|
350
|
-
* List or remove messages from the DLQ.
|
|
351
|
-
*/
|
|
352
|
-
get dlq() {
|
|
353
|
-
return new DLQ(this.http);
|
|
354
|
-
}
|
|
355
|
-
/**
|
|
356
|
-
* Access the message API.
|
|
357
|
-
*
|
|
358
|
-
* Read or cancel messages.
|
|
359
|
-
*/
|
|
360
|
-
get messages() {
|
|
361
|
-
return new Messages(this.http);
|
|
362
|
-
}
|
|
363
|
-
/**
|
|
364
|
-
* Access the schedule API.
|
|
365
|
-
*
|
|
366
|
-
* Create, read or delete schedules.
|
|
367
|
-
*/
|
|
368
|
-
get schedules() {
|
|
369
|
-
return new Schedules(this.http);
|
|
370
|
-
}
|
|
371
|
-
processHeaders(req) {
|
|
372
|
-
var _a;
|
|
373
|
-
const headers = prefixHeaders(new Headers(req.headers));
|
|
374
|
-
headers.set("Upstash-Method", (_a = req.method) != null ? _a : "POST");
|
|
375
|
-
if (typeof req.delay !== "undefined") {
|
|
376
|
-
headers.set("Upstash-Delay", `${req.delay.toFixed()}s`);
|
|
377
|
-
}
|
|
378
|
-
if (typeof req.notBefore !== "undefined") {
|
|
379
|
-
headers.set("Upstash-Not-Before", req.notBefore.toFixed());
|
|
380
|
-
}
|
|
381
|
-
if (typeof req.deduplicationId !== "undefined") {
|
|
382
|
-
headers.set("Upstash-Deduplication-Id", req.deduplicationId);
|
|
383
|
-
}
|
|
384
|
-
if (typeof req.contentBasedDeduplication !== "undefined") {
|
|
385
|
-
headers.set("Upstash-Content-Based-Deduplication", "true");
|
|
386
|
-
}
|
|
387
|
-
if (typeof req.retries !== "undefined") {
|
|
388
|
-
headers.set("Upstash-Retries", req.retries.toFixed());
|
|
389
|
-
}
|
|
390
|
-
if (typeof req.callback !== "undefined") {
|
|
391
|
-
headers.set("Upstash-Callback", req.callback);
|
|
392
|
-
}
|
|
393
|
-
if (typeof req.failureCallback !== "undefined") {
|
|
394
|
-
headers.set("Upstash-Failure-Callback", req.failureCallback);
|
|
395
|
-
}
|
|
396
|
-
return headers;
|
|
397
|
-
}
|
|
398
|
-
publish(req) {
|
|
399
|
-
return __async(this, null, function* () {
|
|
400
|
-
var _a;
|
|
401
|
-
const headers = this.processHeaders(req);
|
|
402
|
-
const res = yield this.http.request({
|
|
403
|
-
path: ["v2", "publish", (_a = req.url) != null ? _a : req.topic],
|
|
404
|
-
body: req.body,
|
|
405
|
-
headers,
|
|
406
|
-
method: "POST"
|
|
407
|
-
});
|
|
408
|
-
return res;
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
|
-
/**
|
|
412
|
-
* publishJSON is a utility wrapper around `publish` that automatically serializes the body
|
|
413
|
-
* and sets the `Content-Type` header to `application/json`.
|
|
414
|
-
*/
|
|
415
|
-
publishJSON(req) {
|
|
416
|
-
return __async(this, null, function* () {
|
|
417
|
-
const headers = prefixHeaders(new Headers(req.headers));
|
|
418
|
-
headers.set("Content-Type", "application/json");
|
|
419
|
-
const res = yield this.publish(__spreadProps(__spreadValues({}, req), {
|
|
420
|
-
headers,
|
|
421
|
-
body: JSON.stringify(req.body)
|
|
422
|
-
}));
|
|
423
|
-
return res;
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
/**
|
|
427
|
-
* Batch publish messages to QStash.
|
|
428
|
-
*/
|
|
429
|
-
batch(req) {
|
|
430
|
-
return __async(this, null, function* () {
|
|
431
|
-
var _a;
|
|
432
|
-
const messages = [];
|
|
433
|
-
for (const message of req) {
|
|
434
|
-
const headers = this.processHeaders(message);
|
|
435
|
-
const headerEntries = Object.fromEntries(headers.entries());
|
|
436
|
-
messages.push({
|
|
437
|
-
destination: (_a = message.url) != null ? _a : message.topic,
|
|
438
|
-
headers: headerEntries,
|
|
439
|
-
body: message.body
|
|
440
|
-
});
|
|
441
|
-
}
|
|
442
|
-
const res = yield this.http.request({
|
|
443
|
-
path: ["v2", "batch"],
|
|
444
|
-
body: JSON.stringify(messages),
|
|
445
|
-
headers: {
|
|
446
|
-
"Content-Type": "application/json"
|
|
447
|
-
},
|
|
448
|
-
method: "POST"
|
|
449
|
-
});
|
|
450
|
-
return res;
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
/**
|
|
454
|
-
* Batch publish messages to QStash, serializing each body to JSON.
|
|
455
|
-
*/
|
|
456
|
-
batchJSON(req) {
|
|
457
|
-
return __async(this, null, function* () {
|
|
458
|
-
for (const message of req) {
|
|
459
|
-
if ("body" in message) {
|
|
460
|
-
message.body = JSON.stringify(message.body);
|
|
461
|
-
}
|
|
462
|
-
message.headers = new Headers(message.headers);
|
|
463
|
-
message.headers.set("Content-Type", "application/json");
|
|
464
|
-
}
|
|
465
|
-
const res = yield this.batch(req);
|
|
466
|
-
return res;
|
|
467
|
-
});
|
|
468
|
-
}
|
|
469
|
-
/**
|
|
470
|
-
* Retrieve your logs.
|
|
471
|
-
*
|
|
472
|
-
* The logs endpoint is paginated and returns only 100 logs at a time.
|
|
473
|
-
* If you want to receive more logs, you can use the cursor to paginate.
|
|
474
|
-
*
|
|
475
|
-
* The cursor is a unix timestamp with millisecond precision
|
|
476
|
-
*
|
|
477
|
-
* @example
|
|
478
|
-
* ```ts
|
|
479
|
-
* let cursor = Date.now()
|
|
480
|
-
* const logs: Log[] = []
|
|
481
|
-
* while (cursor > 0) {
|
|
482
|
-
* const res = await qstash.logs({ cursor })
|
|
483
|
-
* logs.push(...res.logs)
|
|
484
|
-
* cursor = res.cursor ?? 0
|
|
485
|
-
* }
|
|
486
|
-
* ```
|
|
487
|
-
*/
|
|
488
|
-
events(req) {
|
|
489
|
-
return __async(this, null, function* () {
|
|
490
|
-
const query = {};
|
|
491
|
-
if ((req == null ? void 0 : req.cursor) && req.cursor > 0) {
|
|
492
|
-
query.cursor = req.cursor;
|
|
493
|
-
}
|
|
494
|
-
const res = yield this.http.request({
|
|
495
|
-
path: ["v2", "events"],
|
|
496
|
-
method: "GET",
|
|
497
|
-
query
|
|
498
|
-
});
|
|
499
|
-
return res;
|
|
500
|
-
});
|
|
501
|
-
}
|
|
502
|
-
};
|
|
503
|
-
export {
|
|
504
|
-
Client,
|
|
505
|
-
Messages,
|
|
506
|
-
QstashError,
|
|
507
|
-
QstashRatelimitError,
|
|
508
|
-
Receiver,
|
|
509
|
-
Schedules,
|
|
510
|
-
SignatureError,
|
|
511
|
-
Topics
|
|
512
|
-
};
|
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;
|