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