@vercel/queue 0.0.0-alpha.22 → 0.0.0-alpha.24
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/index.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +26 -30
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -30
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.d.mts
CHANGED
|
@@ -93,6 +93,11 @@ interface PublishOptions {
|
|
|
93
93
|
* @max 86400
|
|
94
94
|
*/
|
|
95
95
|
retentionSeconds?: number;
|
|
96
|
+
/**
|
|
97
|
+
* Explicit deployment identifier to include in the `Vqs-Deployment-Id` header
|
|
98
|
+
* If provided, this takes precedence over any value from the environment
|
|
99
|
+
*/
|
|
100
|
+
deploymentId?: string;
|
|
96
101
|
}
|
|
97
102
|
interface SendMessageOptions<T = unknown> extends PublishOptions {
|
|
98
103
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -93,6 +93,11 @@ interface PublishOptions {
|
|
|
93
93
|
* @max 86400
|
|
94
94
|
*/
|
|
95
95
|
retentionSeconds?: number;
|
|
96
|
+
/**
|
|
97
|
+
* Explicit deployment identifier to include in the `Vqs-Deployment-Id` header
|
|
98
|
+
* If provided, this takes precedence over any value from the environment
|
|
99
|
+
*/
|
|
100
|
+
deploymentId?: string;
|
|
96
101
|
}
|
|
97
102
|
interface SendMessageOptions<T = unknown> extends PublishOptions {
|
|
98
103
|
/**
|
package/dist/index.js
CHANGED
|
@@ -107,16 +107,7 @@ var StreamTransport = class {
|
|
|
107
107
|
var import_mixpart = require("mixpart");
|
|
108
108
|
|
|
109
109
|
// src/oidc.ts
|
|
110
|
-
|
|
111
|
-
const SYMBOL_FOR_REQ_CONTEXT = Symbol.for("@vercel/request-context");
|
|
112
|
-
const fromSymbol = globalThis;
|
|
113
|
-
const context = fromSymbol[SYMBOL_FOR_REQ_CONTEXT]?.get?.() ?? {};
|
|
114
|
-
const token = context.headers?.["x-vercel-oidc-token"] ?? process.env.VERCEL_OIDC_TOKEN;
|
|
115
|
-
if (!token) {
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
return token;
|
|
119
|
-
}
|
|
110
|
+
var import_oidc = require("@vercel/oidc");
|
|
120
111
|
|
|
121
112
|
// src/types.ts
|
|
122
113
|
var MessageNotFoundError = class extends Error {
|
|
@@ -226,22 +217,24 @@ var QueueClient = class {
|
|
|
226
217
|
token;
|
|
227
218
|
/**
|
|
228
219
|
* Create a new Vercel Queue Service client
|
|
229
|
-
* @param options Client configuration options
|
|
220
|
+
* @param options Client configuration options
|
|
230
221
|
*/
|
|
231
222
|
constructor(options = {}) {
|
|
232
223
|
this.baseUrl = options.baseUrl || "https://vercel-queue.com";
|
|
233
224
|
this.basePath = options.basePath || "/api/v2/messages";
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
225
|
+
this.token = options.token;
|
|
226
|
+
}
|
|
227
|
+
async getToken() {
|
|
228
|
+
if (this.token) {
|
|
229
|
+
return this.token;
|
|
230
|
+
}
|
|
231
|
+
const token = await (0, import_oidc.getVercelOidcToken)();
|
|
232
|
+
if (!token) {
|
|
233
|
+
throw new Error(
|
|
234
|
+
"Failed to get OIDC token from Vercel Functions. Make sure you are running in a Vercel Function environment, or provide a token explicitly.\n\nTo set up your environment:\n1. Link your project: 'vercel link'\n2. Pull environment variables: 'vercel env pull'\n3. Run with environment: 'dotenv -e .env.local -- your-command'"
|
|
235
|
+
);
|
|
244
236
|
}
|
|
237
|
+
return token;
|
|
245
238
|
}
|
|
246
239
|
/**
|
|
247
240
|
* Send a message to a queue
|
|
@@ -256,12 +249,13 @@ var QueueClient = class {
|
|
|
256
249
|
async sendMessage(options, transport) {
|
|
257
250
|
const { queueName, payload, idempotencyKey, retentionSeconds } = options;
|
|
258
251
|
const headers = new Headers({
|
|
259
|
-
Authorization: `Bearer ${this.
|
|
252
|
+
Authorization: `Bearer ${await this.getToken()}`,
|
|
260
253
|
"Vqs-Queue-Name": queueName,
|
|
261
254
|
"Content-Type": transport.contentType
|
|
262
255
|
});
|
|
263
|
-
|
|
264
|
-
|
|
256
|
+
const deploymentId = options.deploymentId || process.env.VERCEL_DEPLOYMENT_ID;
|
|
257
|
+
if (deploymentId) {
|
|
258
|
+
headers.set("Vqs-Deployment-Id", deploymentId);
|
|
265
259
|
}
|
|
266
260
|
if (idempotencyKey) {
|
|
267
261
|
headers.set("Vqs-Idempotency-Key", idempotencyKey);
|
|
@@ -320,7 +314,7 @@ var QueueClient = class {
|
|
|
320
314
|
throw new InvalidLimitError(limit);
|
|
321
315
|
}
|
|
322
316
|
const headers = new Headers({
|
|
323
|
-
Authorization: `Bearer ${this.
|
|
317
|
+
Authorization: `Bearer ${await this.getToken()}`,
|
|
324
318
|
"Vqs-Queue-Name": queueName,
|
|
325
319
|
"Vqs-Consumer-Group": consumerGroup,
|
|
326
320
|
Accept: "multipart/mixed"
|
|
@@ -401,7 +395,7 @@ var QueueClient = class {
|
|
|
401
395
|
skipPayload
|
|
402
396
|
} = options;
|
|
403
397
|
const headers = new Headers({
|
|
404
|
-
Authorization: `Bearer ${this.
|
|
398
|
+
Authorization: `Bearer ${await this.getToken()}`,
|
|
405
399
|
"Vqs-Queue-Name": queueName,
|
|
406
400
|
"Vqs-Consumer-Group": consumerGroup,
|
|
407
401
|
Accept: "multipart/mixed"
|
|
@@ -529,7 +523,7 @@ var QueueClient = class {
|
|
|
529
523
|
{
|
|
530
524
|
method: "DELETE",
|
|
531
525
|
headers: new Headers({
|
|
532
|
-
Authorization: `Bearer ${this.
|
|
526
|
+
Authorization: `Bearer ${await this.getToken()}`,
|
|
533
527
|
"Vqs-Queue-Name": queueName,
|
|
534
528
|
"Vqs-Consumer-Group": consumerGroup,
|
|
535
529
|
"Vqs-Ticket": ticket
|
|
@@ -590,7 +584,7 @@ var QueueClient = class {
|
|
|
590
584
|
{
|
|
591
585
|
method: "PATCH",
|
|
592
586
|
headers: new Headers({
|
|
593
|
-
Authorization: `Bearer ${this.
|
|
587
|
+
Authorization: `Bearer ${await this.getToken()}`,
|
|
594
588
|
"Vqs-Queue-Name": queueName,
|
|
595
589
|
"Vqs-Consumer-Group": consumerGroup,
|
|
596
590
|
"Vqs-Ticket": ticket,
|
|
@@ -1203,7 +1197,8 @@ var Topic = class {
|
|
|
1203
1197
|
queueName: this.topicName,
|
|
1204
1198
|
payload,
|
|
1205
1199
|
idempotencyKey: options?.idempotencyKey,
|
|
1206
|
-
retentionSeconds: options?.retentionSeconds
|
|
1200
|
+
retentionSeconds: options?.retentionSeconds,
|
|
1201
|
+
deploymentId: options?.deploymentId
|
|
1207
1202
|
},
|
|
1208
1203
|
this.transport
|
|
1209
1204
|
);
|
|
@@ -1253,7 +1248,8 @@ async function send(topicName, payload, options) {
|
|
|
1253
1248
|
queueName: topicName,
|
|
1254
1249
|
payload,
|
|
1255
1250
|
idempotencyKey: options?.idempotencyKey,
|
|
1256
|
-
retentionSeconds: options?.retentionSeconds
|
|
1251
|
+
retentionSeconds: options?.retentionSeconds,
|
|
1252
|
+
deploymentId: options?.deploymentId
|
|
1257
1253
|
},
|
|
1258
1254
|
transport
|
|
1259
1255
|
);
|