@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/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 +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 -634
- package/dist/index.mjs +0 -634
- package/dist/nextjs.js +0 -164
- package/dist/nextjs.mjs +0 -164
package/dist/index.js
DELETED
|
@@ -1,634 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var _chunkEROSIHWEjs = require('./chunk-EROSIHWE.js');
|
|
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 _chunkEROSIHWEjs.__async.call(void 0, 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 _chunkEROSIHWEjs.__async.call(void 0, 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 _chunkEROSIHWEjs.__async.call(void 0, 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 _chunkEROSIHWEjs.__async.call(void 0, 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 _chunkEROSIHWEjs.__async.call(void 0, 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 _chunkEROSIHWEjs.__async.call(void 0, 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
|
-
function processHeaders(req) {
|
|
187
|
-
var _a;
|
|
188
|
-
const headers = prefixHeaders(new Headers(req.headers));
|
|
189
|
-
headers.set("Upstash-Method", (_a = req.method) != null ? _a : "POST");
|
|
190
|
-
if (typeof req.delay !== "undefined") {
|
|
191
|
-
headers.set("Upstash-Delay", `${req.delay.toFixed()}s`);
|
|
192
|
-
}
|
|
193
|
-
if (typeof req.notBefore !== "undefined") {
|
|
194
|
-
headers.set("Upstash-Not-Before", req.notBefore.toFixed());
|
|
195
|
-
}
|
|
196
|
-
if (typeof req.deduplicationId !== "undefined") {
|
|
197
|
-
headers.set("Upstash-Deduplication-Id", req.deduplicationId);
|
|
198
|
-
}
|
|
199
|
-
if (typeof req.contentBasedDeduplication !== "undefined") {
|
|
200
|
-
headers.set("Upstash-Content-Based-Deduplication", "true");
|
|
201
|
-
}
|
|
202
|
-
if (typeof req.retries !== "undefined") {
|
|
203
|
-
headers.set("Upstash-Retries", req.retries.toFixed());
|
|
204
|
-
}
|
|
205
|
-
if (typeof req.callback !== "undefined") {
|
|
206
|
-
headers.set("Upstash-Callback", req.callback);
|
|
207
|
-
}
|
|
208
|
-
if (typeof req.failureCallback !== "undefined") {
|
|
209
|
-
headers.set("Upstash-Failure-Callback", req.failureCallback);
|
|
210
|
-
}
|
|
211
|
-
return headers;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// src/client/queue.ts
|
|
215
|
-
var Queue = class {
|
|
216
|
-
constructor(http, queueName) {
|
|
217
|
-
this.http = http;
|
|
218
|
-
this.queueName = queueName;
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Create or update the queue
|
|
222
|
-
*/
|
|
223
|
-
upsert(req) {
|
|
224
|
-
return _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () {
|
|
225
|
-
if (!this.queueName) {
|
|
226
|
-
throw new Error("Please provide a queue name to the Queue constructor");
|
|
227
|
-
}
|
|
228
|
-
const body = {
|
|
229
|
-
queueName: this.queueName,
|
|
230
|
-
parallelism: req.parallelism
|
|
231
|
-
};
|
|
232
|
-
yield this.http.request({
|
|
233
|
-
method: "POST",
|
|
234
|
-
path: ["v2", "queues"],
|
|
235
|
-
headers: {
|
|
236
|
-
"Content-Type": "application/json"
|
|
237
|
-
},
|
|
238
|
-
body: JSON.stringify(body),
|
|
239
|
-
parseResponseAsJson: false
|
|
240
|
-
});
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Get the queue details
|
|
245
|
-
*/
|
|
246
|
-
get() {
|
|
247
|
-
return _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () {
|
|
248
|
-
if (!this.queueName) {
|
|
249
|
-
throw new Error("Please provide a queue name to the Queue constructor");
|
|
250
|
-
}
|
|
251
|
-
return yield this.http.request({
|
|
252
|
-
method: "GET",
|
|
253
|
-
path: ["v2", "queues", this.queueName]
|
|
254
|
-
});
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* List queues
|
|
259
|
-
*/
|
|
260
|
-
list() {
|
|
261
|
-
return _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () {
|
|
262
|
-
return yield this.http.request({
|
|
263
|
-
method: "GET",
|
|
264
|
-
path: ["v2", "queues"]
|
|
265
|
-
});
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Delete the queue
|
|
270
|
-
*/
|
|
271
|
-
delete() {
|
|
272
|
-
return _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () {
|
|
273
|
-
if (!this.queueName) {
|
|
274
|
-
throw new Error("Please provide a queue name to the Queue constructor");
|
|
275
|
-
}
|
|
276
|
-
yield this.http.request({
|
|
277
|
-
method: "DELETE",
|
|
278
|
-
path: ["v2", "queues", this.queueName],
|
|
279
|
-
parseResponseAsJson: false
|
|
280
|
-
});
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Enqueue a message to a queue.
|
|
285
|
-
*/
|
|
286
|
-
enqueue(req) {
|
|
287
|
-
return _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () {
|
|
288
|
-
var _a;
|
|
289
|
-
if (!this.queueName) {
|
|
290
|
-
throw new Error("Please provide a queue name to the Queue constructor");
|
|
291
|
-
}
|
|
292
|
-
const headers = processHeaders(req);
|
|
293
|
-
const destination = (_a = req.url) != null ? _a : req.topic;
|
|
294
|
-
const res = yield this.http.request({
|
|
295
|
-
path: ["v2", "enqueue", this.queueName, destination],
|
|
296
|
-
body: req.body,
|
|
297
|
-
headers,
|
|
298
|
-
method: "POST"
|
|
299
|
-
});
|
|
300
|
-
return res;
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* Enqueue a message to a queue, serializing the body to JSON.
|
|
305
|
-
*/
|
|
306
|
-
enqueueJSON(req) {
|
|
307
|
-
return _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () {
|
|
308
|
-
const headers = prefixHeaders(new Headers(req.headers));
|
|
309
|
-
headers.set("Content-Type", "application/json");
|
|
310
|
-
const res = yield this.enqueue(_chunkEROSIHWEjs.__spreadProps.call(void 0, _chunkEROSIHWEjs.__spreadValues.call(void 0, {}, req), {
|
|
311
|
-
body: JSON.stringify(req.body),
|
|
312
|
-
headers
|
|
313
|
-
}));
|
|
314
|
-
return res;
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
};
|
|
318
|
-
|
|
319
|
-
// src/client/schedules.ts
|
|
320
|
-
var Schedules = class {
|
|
321
|
-
constructor(http) {
|
|
322
|
-
this.http = http;
|
|
323
|
-
}
|
|
324
|
-
/**
|
|
325
|
-
* Create a schedule
|
|
326
|
-
*/
|
|
327
|
-
create(req) {
|
|
328
|
-
return _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () {
|
|
329
|
-
const headers = prefixHeaders(new Headers(req.headers));
|
|
330
|
-
if (!headers.has("Content-Type")) {
|
|
331
|
-
headers.set("Content-Type", "application/json");
|
|
332
|
-
}
|
|
333
|
-
headers.set("Upstash-Cron", req.cron);
|
|
334
|
-
if (typeof req.method !== "undefined") {
|
|
335
|
-
headers.set("Upstash-Method", req.method);
|
|
336
|
-
}
|
|
337
|
-
if (typeof req.delay !== "undefined") {
|
|
338
|
-
headers.set("Upstash-Delay", `${req.delay.toFixed()}s`);
|
|
339
|
-
}
|
|
340
|
-
if (typeof req.retries !== "undefined") {
|
|
341
|
-
headers.set("Upstash-Retries", req.retries.toFixed());
|
|
342
|
-
}
|
|
343
|
-
if (typeof req.callback !== "undefined") {
|
|
344
|
-
headers.set("Upstash-Callback", req.callback);
|
|
345
|
-
}
|
|
346
|
-
if (typeof req.failureCallback !== "undefined") {
|
|
347
|
-
headers.set("Upstash-Failure-Callback", req.failureCallback);
|
|
348
|
-
}
|
|
349
|
-
return yield this.http.request({
|
|
350
|
-
method: "POST",
|
|
351
|
-
headers,
|
|
352
|
-
path: ["v2", "schedules", req.destination],
|
|
353
|
-
body: req.body
|
|
354
|
-
});
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
/**
|
|
358
|
-
* Get a schedule
|
|
359
|
-
*/
|
|
360
|
-
get(scheduleId) {
|
|
361
|
-
return _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () {
|
|
362
|
-
return yield this.http.request({
|
|
363
|
-
method: "GET",
|
|
364
|
-
path: ["v2", "schedules", scheduleId]
|
|
365
|
-
});
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
/**
|
|
369
|
-
* List your schedules
|
|
370
|
-
*/
|
|
371
|
-
list() {
|
|
372
|
-
return _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () {
|
|
373
|
-
return yield this.http.request({
|
|
374
|
-
method: "GET",
|
|
375
|
-
path: ["v2", "schedules"]
|
|
376
|
-
});
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
/**
|
|
380
|
-
* Delete a schedule
|
|
381
|
-
*/
|
|
382
|
-
delete(scheduleId) {
|
|
383
|
-
return _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () {
|
|
384
|
-
return yield this.http.request({
|
|
385
|
-
method: "DELETE",
|
|
386
|
-
path: ["v2", "schedules", scheduleId],
|
|
387
|
-
parseResponseAsJson: false
|
|
388
|
-
});
|
|
389
|
-
});
|
|
390
|
-
}
|
|
391
|
-
};
|
|
392
|
-
|
|
393
|
-
// src/client/topics.ts
|
|
394
|
-
var Topics = class {
|
|
395
|
-
constructor(http) {
|
|
396
|
-
this.http = http;
|
|
397
|
-
}
|
|
398
|
-
/**
|
|
399
|
-
* Create a new topic with the given name and endpoints
|
|
400
|
-
*/
|
|
401
|
-
addEndpoints(req) {
|
|
402
|
-
return _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () {
|
|
403
|
-
yield this.http.request({
|
|
404
|
-
method: "POST",
|
|
405
|
-
path: ["v2", "topics", req.name, "endpoints"],
|
|
406
|
-
headers: { "Content-Type": "application/json" },
|
|
407
|
-
body: JSON.stringify({ endpoints: req.endpoints }),
|
|
408
|
-
parseResponseAsJson: false
|
|
409
|
-
});
|
|
410
|
-
});
|
|
411
|
-
}
|
|
412
|
-
/**
|
|
413
|
-
* Remove endpoints from a topic.
|
|
414
|
-
*/
|
|
415
|
-
removeEndpoints(req) {
|
|
416
|
-
return _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () {
|
|
417
|
-
yield this.http.request({
|
|
418
|
-
method: "DELETE",
|
|
419
|
-
path: ["v2", "topics", req.name, "endpoints"],
|
|
420
|
-
headers: { "Content-Type": "application/json" },
|
|
421
|
-
body: JSON.stringify({ endpoints: req.endpoints }),
|
|
422
|
-
parseResponseAsJson: false
|
|
423
|
-
});
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
/**
|
|
427
|
-
* Get a list of all topics.
|
|
428
|
-
*/
|
|
429
|
-
list() {
|
|
430
|
-
return _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () {
|
|
431
|
-
return yield this.http.request({
|
|
432
|
-
method: "GET",
|
|
433
|
-
path: ["v2", "topics"]
|
|
434
|
-
});
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
|
-
/**
|
|
438
|
-
* Get a single topic
|
|
439
|
-
*/
|
|
440
|
-
get(name) {
|
|
441
|
-
return _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () {
|
|
442
|
-
return yield this.http.request({
|
|
443
|
-
method: "GET",
|
|
444
|
-
path: ["v2", "topics", name]
|
|
445
|
-
});
|
|
446
|
-
});
|
|
447
|
-
}
|
|
448
|
-
/**
|
|
449
|
-
* Delete a topic
|
|
450
|
-
*/
|
|
451
|
-
delete(name) {
|
|
452
|
-
return _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () {
|
|
453
|
-
return yield this.http.request({
|
|
454
|
-
method: "DELETE",
|
|
455
|
-
path: ["v2", "topics", name],
|
|
456
|
-
parseResponseAsJson: false
|
|
457
|
-
});
|
|
458
|
-
});
|
|
459
|
-
}
|
|
460
|
-
};
|
|
461
|
-
|
|
462
|
-
// src/client/client.ts
|
|
463
|
-
var Client = class {
|
|
464
|
-
constructor(config) {
|
|
465
|
-
this.http = new HttpClient({
|
|
466
|
-
retry: config.retry,
|
|
467
|
-
baseUrl: config.baseUrl ? config.baseUrl.replace(/\/$/, "") : "https://qstash.upstash.io",
|
|
468
|
-
authorization: `Bearer ${config.token}`
|
|
469
|
-
});
|
|
470
|
-
}
|
|
471
|
-
/**
|
|
472
|
-
* Access the topic API.
|
|
473
|
-
*
|
|
474
|
-
* Create, read, update or delete topics.
|
|
475
|
-
*/
|
|
476
|
-
get topics() {
|
|
477
|
-
return new Topics(this.http);
|
|
478
|
-
}
|
|
479
|
-
/**
|
|
480
|
-
* Access the dlq API.
|
|
481
|
-
*
|
|
482
|
-
* List or remove messages from the DLQ.
|
|
483
|
-
*/
|
|
484
|
-
get dlq() {
|
|
485
|
-
return new DLQ(this.http);
|
|
486
|
-
}
|
|
487
|
-
/**
|
|
488
|
-
* Access the message API.
|
|
489
|
-
*
|
|
490
|
-
* Read or cancel messages.
|
|
491
|
-
*/
|
|
492
|
-
get messages() {
|
|
493
|
-
return new Messages(this.http);
|
|
494
|
-
}
|
|
495
|
-
/**
|
|
496
|
-
* Access the schedule API.
|
|
497
|
-
*
|
|
498
|
-
* Create, read or delete schedules.
|
|
499
|
-
*/
|
|
500
|
-
get schedules() {
|
|
501
|
-
return new Schedules(this.http);
|
|
502
|
-
}
|
|
503
|
-
/**
|
|
504
|
-
* Access the queue API.
|
|
505
|
-
*
|
|
506
|
-
* Create, read, update or delete queues.
|
|
507
|
-
*/
|
|
508
|
-
queue(req) {
|
|
509
|
-
return new Queue(this.http, req == null ? void 0 : req.queueName);
|
|
510
|
-
}
|
|
511
|
-
publish(req) {
|
|
512
|
-
return _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () {
|
|
513
|
-
var _a;
|
|
514
|
-
const headers = processHeaders(req);
|
|
515
|
-
const res = yield this.http.request({
|
|
516
|
-
path: ["v2", "publish", (_a = req.url) != null ? _a : req.topic],
|
|
517
|
-
body: req.body,
|
|
518
|
-
headers,
|
|
519
|
-
method: "POST"
|
|
520
|
-
});
|
|
521
|
-
return res;
|
|
522
|
-
});
|
|
523
|
-
}
|
|
524
|
-
/**
|
|
525
|
-
* publishJSON is a utility wrapper around `publish` that automatically serializes the body
|
|
526
|
-
* and sets the `Content-Type` header to `application/json`.
|
|
527
|
-
*/
|
|
528
|
-
publishJSON(req) {
|
|
529
|
-
return _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () {
|
|
530
|
-
const headers = prefixHeaders(new Headers(req.headers));
|
|
531
|
-
headers.set("Content-Type", "application/json");
|
|
532
|
-
const res = yield this.publish(_chunkEROSIHWEjs.__spreadProps.call(void 0, _chunkEROSIHWEjs.__spreadValues.call(void 0, {}, req), {
|
|
533
|
-
headers,
|
|
534
|
-
body: JSON.stringify(req.body)
|
|
535
|
-
}));
|
|
536
|
-
return res;
|
|
537
|
-
});
|
|
538
|
-
}
|
|
539
|
-
/**
|
|
540
|
-
* Batch publish messages to QStash.
|
|
541
|
-
*/
|
|
542
|
-
batch(req) {
|
|
543
|
-
return _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () {
|
|
544
|
-
var _a;
|
|
545
|
-
const messages = [];
|
|
546
|
-
for (const message of req) {
|
|
547
|
-
const headers = processHeaders(message);
|
|
548
|
-
const headerEntries = Object.fromEntries(headers.entries());
|
|
549
|
-
messages.push({
|
|
550
|
-
destination: (_a = message.url) != null ? _a : message.topic,
|
|
551
|
-
headers: headerEntries,
|
|
552
|
-
body: message.body
|
|
553
|
-
});
|
|
554
|
-
}
|
|
555
|
-
const res = yield this.http.request({
|
|
556
|
-
path: ["v2", "batch"],
|
|
557
|
-
body: JSON.stringify(messages),
|
|
558
|
-
headers: {
|
|
559
|
-
"Content-Type": "application/json"
|
|
560
|
-
},
|
|
561
|
-
method: "POST"
|
|
562
|
-
});
|
|
563
|
-
return res;
|
|
564
|
-
});
|
|
565
|
-
}
|
|
566
|
-
/**
|
|
567
|
-
* Batch publish messages to QStash, serializing each body to JSON.
|
|
568
|
-
*/
|
|
569
|
-
batchJSON(req) {
|
|
570
|
-
return _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () {
|
|
571
|
-
for (const message of req) {
|
|
572
|
-
if ("body" in message) {
|
|
573
|
-
message.body = JSON.stringify(message.body);
|
|
574
|
-
}
|
|
575
|
-
message.headers = new Headers(message.headers);
|
|
576
|
-
message.headers.set("Content-Type", "application/json");
|
|
577
|
-
}
|
|
578
|
-
const res = yield this.batch(req);
|
|
579
|
-
return res;
|
|
580
|
-
});
|
|
581
|
-
}
|
|
582
|
-
/**
|
|
583
|
-
* Retrieve your logs.
|
|
584
|
-
*
|
|
585
|
-
* The logs endpoint is paginated and returns only 100 logs at a time.
|
|
586
|
-
* If you want to receive more logs, you can use the cursor to paginate.
|
|
587
|
-
*
|
|
588
|
-
* The cursor is a unix timestamp with millisecond precision
|
|
589
|
-
*
|
|
590
|
-
* @example
|
|
591
|
-
* ```ts
|
|
592
|
-
* let cursor = Date.now()
|
|
593
|
-
* const logs: Log[] = []
|
|
594
|
-
* while (cursor > 0) {
|
|
595
|
-
* const res = await qstash.logs({ cursor })
|
|
596
|
-
* logs.push(...res.logs)
|
|
597
|
-
* cursor = res.cursor ?? 0
|
|
598
|
-
* }
|
|
599
|
-
* ```
|
|
600
|
-
*/
|
|
601
|
-
events(req) {
|
|
602
|
-
return _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () {
|
|
603
|
-
var _a;
|
|
604
|
-
const query = {};
|
|
605
|
-
if ((req == null ? void 0 : req.cursor) && req.cursor > 0) {
|
|
606
|
-
query.cursor = req.cursor.toString();
|
|
607
|
-
}
|
|
608
|
-
for (const [key, value] of Object.entries((_a = req == null ? void 0 : req.filter) != null ? _a : {})) {
|
|
609
|
-
if (typeof value === "number" && value < 0) {
|
|
610
|
-
continue;
|
|
611
|
-
}
|
|
612
|
-
if (typeof value !== "undefined") {
|
|
613
|
-
query[key] = value.toString();
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
const res = yield this.http.request({
|
|
617
|
-
path: ["v2", "events"],
|
|
618
|
-
method: "GET",
|
|
619
|
-
query
|
|
620
|
-
});
|
|
621
|
-
return res;
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
};
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
exports.Client = Client; exports.Messages = Messages; exports.QstashError = QstashError; exports.QstashRatelimitError = QstashRatelimitError; exports.Receiver = _chunkEROSIHWEjs.Receiver; exports.Schedules = Schedules; exports.SignatureError = _chunkEROSIHWEjs.SignatureError; exports.Topics = Topics;
|