@vercel/queue 0.1.2 → 0.1.3
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.js +42 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -139,6 +139,7 @@ var fs = __toESM(require("fs"));
|
|
|
139
139
|
var net = __toESM(require("net"));
|
|
140
140
|
var path = __toESM(require("path"));
|
|
141
141
|
var import_minimatch = require("minimatch");
|
|
142
|
+
var import_picocolors = __toESM(require("picocolors"));
|
|
142
143
|
|
|
143
144
|
// src/types.ts
|
|
144
145
|
var MessageNotFoundError = class extends Error {
|
|
@@ -769,6 +770,10 @@ async function handleCallback(handler, request, options) {
|
|
|
769
770
|
|
|
770
771
|
// src/dev.ts
|
|
771
772
|
var import_meta = {};
|
|
773
|
+
var PREFIX = import_picocolors.default.cyan("[queue]");
|
|
774
|
+
var OK = import_picocolors.default.green("\u2713");
|
|
775
|
+
var FAIL = import_picocolors.default.red("\u2717");
|
|
776
|
+
var RETRY = import_picocolors.default.yellow("\u21BB");
|
|
772
777
|
function isDevMode() {
|
|
773
778
|
return process.env.NODE_ENV === "development";
|
|
774
779
|
}
|
|
@@ -813,7 +818,7 @@ function getDevRouteMappings() {
|
|
|
813
818
|
if (!trigger.type?.startsWith("queue/") || !trigger.topic) continue;
|
|
814
819
|
if (trigger.type !== "queue/v2beta") {
|
|
815
820
|
console.warn(
|
|
816
|
-
|
|
821
|
+
`${PREFIX} Unsupported trigger type "${trigger.type}" for topic "${trigger.topic}" in ${filePath}. Use "queue/v2beta" instead.`
|
|
817
822
|
);
|
|
818
823
|
continue;
|
|
819
824
|
}
|
|
@@ -828,7 +833,7 @@ function getDevRouteMappings() {
|
|
|
828
833
|
g[ROUTE_MAPPINGS_KEY] = mappings.length > 0 ? mappings : null;
|
|
829
834
|
return g[ROUTE_MAPPINGS_KEY];
|
|
830
835
|
} catch (error) {
|
|
831
|
-
console.warn(
|
|
836
|
+
console.warn(`${PREFIX} Failed to read vercel.json:`, error);
|
|
832
837
|
g[ROUTE_MAPPINGS_KEY] = null;
|
|
833
838
|
return null;
|
|
834
839
|
}
|
|
@@ -965,7 +970,7 @@ function registerDevHandler(handler, client, options, _testCallerPath) {
|
|
|
965
970
|
const callerPath = _testCallerPath ?? extractCallerFilePath();
|
|
966
971
|
if (!callerPath) {
|
|
967
972
|
console.warn(
|
|
968
|
-
|
|
973
|
+
`${PREFIX} Could not determine caller file path for handler registration.`
|
|
969
974
|
);
|
|
970
975
|
return;
|
|
971
976
|
}
|
|
@@ -988,7 +993,7 @@ function registerDevHandler(handler, client, options, _testCallerPath) {
|
|
|
988
993
|
relative2 = callerPath;
|
|
989
994
|
}
|
|
990
995
|
console.warn(
|
|
991
|
-
|
|
996
|
+
`${PREFIX} handleCallback() in ${relative2} has no matching experimentalTriggers in vercel.json. This handler won't receive messages.
|
|
992
997
|
|
|
993
998
|
Add a trigger to vercel.json:
|
|
994
999
|
"${relative2}": {
|
|
@@ -1205,7 +1210,7 @@ function buildNoHandlerWarning(topicName, routes, diagnostics) {
|
|
|
1205
1210
|
Import failures: ` + diagnostics.importFailures.slice(0, 2).map((f) => `${f.filePath} (${f.reason})`).join("; ") : "";
|
|
1206
1211
|
const primeSummary = diagnostics.primeFailures.length > 0 ? `
|
|
1207
1212
|
Prime failures: ` + diagnostics.primeFailures.slice(0, 3).map((f) => `${f.url} (${f.reason})`).join("; ") : "";
|
|
1208
|
-
return
|
|
1213
|
+
return `${PREFIX} No registered handler for topic "${topicName}". vercel.json maps this topic to [${files.join(", ")}] but auto-loading failed.
|
|
1209
1214
|
${portSummary}${importSummary}${primeSummary}
|
|
1210
1215
|
Ensure your dev server is running, set PORT if needed, and confirm mapped route files call handleCallback()/handleNodeCallback() at module scope.
|
|
1211
1216
|
` + (suggestedUrls.length > 0 ? `Try opening: ${suggestedUrls.join(" or ")}` : "Set PORT (or NEXT_PORT/NUXT_PORT/VITE_PORT) and try sending again.");
|
|
@@ -1222,7 +1227,7 @@ var DEFAULT_RETENTION_S = 86400;
|
|
|
1222
1227
|
function scheduleDevRedelivery(ctx, delayS) {
|
|
1223
1228
|
const cappedDelay = Math.min(Math.max(delayS, 0), DEV_REDELIVERY_MAX_DELAY_S);
|
|
1224
1229
|
console.log(
|
|
1225
|
-
|
|
1230
|
+
`${PREFIX} ${RETRY} Scheduling re-delivery in ${cappedDelay}s: topic="${ctx.topicName}" consumer="${ctx.consumerGroup}" messageId="${ctx.messageId}"`
|
|
1226
1231
|
);
|
|
1227
1232
|
setTimeout(async () => {
|
|
1228
1233
|
const nextDeliveryCount = ctx.deliveryCount + 1;
|
|
@@ -1231,13 +1236,13 @@ function scheduleDevRedelivery(ctx, delayS) {
|
|
|
1231
1236
|
);
|
|
1232
1237
|
if (Date.now() >= expiresAt.getTime()) {
|
|
1233
1238
|
console.log(
|
|
1234
|
-
|
|
1239
|
+
`${PREFIX} Message expired, stopping retries: topic="${ctx.topicName}" messageId="${ctx.messageId}"`
|
|
1235
1240
|
);
|
|
1236
1241
|
return;
|
|
1237
1242
|
}
|
|
1238
1243
|
if (nextDeliveryCount > DEV_REDELIVERY_MAX_ATTEMPTS) {
|
|
1239
1244
|
console.log(
|
|
1240
|
-
|
|
1245
|
+
`${PREFIX} Max re-deliveries (${DEV_REDELIVERY_MAX_ATTEMPTS}) reached: topic="${ctx.topicName}" messageId="${ctx.messageId}"`
|
|
1241
1246
|
);
|
|
1242
1247
|
return;
|
|
1243
1248
|
}
|
|
@@ -1251,7 +1256,7 @@ function scheduleDevRedelivery(ctx, delayS) {
|
|
|
1251
1256
|
region: ctx.region
|
|
1252
1257
|
};
|
|
1253
1258
|
console.log(
|
|
1254
|
-
|
|
1259
|
+
`${PREFIX} Re-delivering: topic="${ctx.topicName}" consumer="${ctx.consumerGroup}" messageId="${ctx.messageId}" deliveryCount=${nextDeliveryCount}`
|
|
1255
1260
|
);
|
|
1256
1261
|
let succeeded = true;
|
|
1257
1262
|
let nextRetryAfterS = null;
|
|
@@ -1265,7 +1270,7 @@ function scheduleDevRedelivery(ctx, delayS) {
|
|
|
1265
1270
|
try {
|
|
1266
1271
|
directive = ctx.retry(error, metadata);
|
|
1267
1272
|
} catch (retryErr) {
|
|
1268
|
-
console.warn(
|
|
1273
|
+
console.warn(`${PREFIX} retry handler threw:`, retryErr);
|
|
1269
1274
|
}
|
|
1270
1275
|
if (directive && "afterSeconds" in directive) {
|
|
1271
1276
|
nextRetryAfterS = directive.afterSeconds;
|
|
@@ -1275,18 +1280,18 @@ function scheduleDevRedelivery(ctx, delayS) {
|
|
|
1275
1280
|
}
|
|
1276
1281
|
if (!nextAcknowledged) {
|
|
1277
1282
|
console.error(
|
|
1278
|
-
|
|
1283
|
+
`${PREFIX} ${FAIL} Handler error on re-delivery: topic="${ctx.topicName}" messageId="${ctx.messageId}"`,
|
|
1279
1284
|
error
|
|
1280
1285
|
);
|
|
1281
1286
|
}
|
|
1282
1287
|
}
|
|
1283
1288
|
if (succeeded) {
|
|
1284
1289
|
console.log(
|
|
1285
|
-
|
|
1290
|
+
`${PREFIX} ${OK} Message processed on re-delivery: topic="${ctx.topicName}" consumer="${ctx.consumerGroup}" messageId="${ctx.messageId}"`
|
|
1286
1291
|
);
|
|
1287
1292
|
} else if (nextAcknowledged) {
|
|
1288
1293
|
console.log(
|
|
1289
|
-
|
|
1294
|
+
`${PREFIX} ${OK} Message acknowledged (will not retry): topic="${ctx.topicName}" consumer="${ctx.consumerGroup}" messageId="${ctx.messageId}"`
|
|
1290
1295
|
);
|
|
1291
1296
|
} else {
|
|
1292
1297
|
const nextDelay = nextRetryAfterS ?? ctx.defaultRetryDelayS;
|
|
@@ -1300,7 +1305,7 @@ function scheduleDevRedelivery(ctx, delayS) {
|
|
|
1300
1305
|
function invokeDevHandlers(topicName, messageId, region, delaySeconds, retentionSeconds) {
|
|
1301
1306
|
if (delaySeconds && delaySeconds > 0) {
|
|
1302
1307
|
console.log(
|
|
1303
|
-
|
|
1308
|
+
`${PREFIX} Message sent with delay: topic="${topicName}" messageId="${messageId}" delay=${delaySeconds}s`
|
|
1304
1309
|
);
|
|
1305
1310
|
setTimeout(() => {
|
|
1306
1311
|
invokeDevHandlers(
|
|
@@ -1314,7 +1319,7 @@ function invokeDevHandlers(topicName, messageId, region, delaySeconds, retention
|
|
|
1314
1319
|
return;
|
|
1315
1320
|
}
|
|
1316
1321
|
console.log(
|
|
1317
|
-
|
|
1322
|
+
`${PREFIX} Message sent: topic="${topicName}" messageId="${messageId}"`
|
|
1318
1323
|
);
|
|
1319
1324
|
(async () => {
|
|
1320
1325
|
let handlers = lookupHandlers(topicName);
|
|
@@ -1341,7 +1346,7 @@ function invokeDevHandlers(topicName, messageId, region, delaySeconds, retention
|
|
|
1341
1346
|
);
|
|
1342
1347
|
} else {
|
|
1343
1348
|
console.warn(
|
|
1344
|
-
|
|
1349
|
+
`${PREFIX} No registered handler for topic "${topicName}".
|
|
1345
1350
|
Ensure vercel.json has a matching experimentalTriggers entry and the route file calls handleCallback().`
|
|
1346
1351
|
);
|
|
1347
1352
|
}
|
|
@@ -1349,7 +1354,7 @@ Ensure vercel.json has a matching experimentalTriggers entry and the route file
|
|
|
1349
1354
|
}
|
|
1350
1355
|
const consumerGroups = handlers.map((h) => h.consumerGroup);
|
|
1351
1356
|
console.log(
|
|
1352
|
-
|
|
1357
|
+
`${PREFIX} Invoking handlers for topic="${topicName}" messageId="${messageId}" \u2192 consumers: [${consumerGroups.join(", ")}]`
|
|
1353
1358
|
);
|
|
1354
1359
|
const effectiveRetention = retentionSeconds ?? DEFAULT_RETENTION_S;
|
|
1355
1360
|
for (const entry of handlers) {
|
|
@@ -1411,11 +1416,11 @@ Ensure vercel.json has a matching experimentalTriggers entry and the route file
|
|
|
1411
1416
|
await invokeWithRetry(wrappedHandler, request, callbackOptions);
|
|
1412
1417
|
if (handlerSucceeded) {
|
|
1413
1418
|
console.log(
|
|
1414
|
-
|
|
1419
|
+
`${PREFIX} ${OK} Message processed: topic="${topicName}" consumer="${entry.consumerGroup}" messageId="${messageId}"`
|
|
1415
1420
|
);
|
|
1416
1421
|
} else if (retryAcknowledged) {
|
|
1417
1422
|
console.log(
|
|
1418
|
-
|
|
1423
|
+
`${PREFIX} ${OK} Message acknowledged (will not retry): topic="${topicName}" consumer="${entry.consumerGroup}" messageId="${messageId}"`
|
|
1419
1424
|
);
|
|
1420
1425
|
} else if (retryAfterS !== null) {
|
|
1421
1426
|
const devDelay = Math.min(retryAfterS, DEV_REDELIVERY_MAX_DELAY_S);
|
|
@@ -1423,7 +1428,7 @@ Ensure vercel.json has a matching experimentalTriggers entry and the route file
|
|
|
1423
1428
|
}
|
|
1424
1429
|
} catch (error) {
|
|
1425
1430
|
console.error(
|
|
1426
|
-
|
|
1431
|
+
`${PREFIX} ${FAIL} Handler failed: topic="${topicName}" consumer="${entry.consumerGroup}" messageId="${messageId}"`,
|
|
1427
1432
|
error
|
|
1428
1433
|
);
|
|
1429
1434
|
if (!handlerSucceeded) {
|
|
@@ -1583,13 +1588,25 @@ var ApiClient = class _ApiClient {
|
|
|
1583
1588
|
if (this.providedToken) {
|
|
1584
1589
|
return this.providedToken;
|
|
1585
1590
|
}
|
|
1586
|
-
|
|
1587
|
-
|
|
1591
|
+
try {
|
|
1592
|
+
return await (0, import_oidc.getVercelOidcToken)();
|
|
1593
|
+
} catch (err) {
|
|
1594
|
+
const cause = err instanceof Error ? err.message : String(err);
|
|
1588
1595
|
throw new Error(
|
|
1589
|
-
|
|
1596
|
+
isDevMode() ? `Failed to get OIDC token for local development.
|
|
1597
|
+
|
|
1598
|
+
To fix this, pull your environment variables with Vercel CLI:
|
|
1599
|
+
\`vercel env pull\`
|
|
1600
|
+
|
|
1601
|
+
Cause: ${cause}` : `Failed to get OIDC token. This usually means the function is running outside of a Vercel Function environment.
|
|
1602
|
+
|
|
1603
|
+
To fix this, either:
|
|
1604
|
+
- Deploy to Vercel (OIDC tokens are provisioned automatically)
|
|
1605
|
+
- Provide a token explicitly: \`new QueueClient({ token: '...' })\`
|
|
1606
|
+
|
|
1607
|
+
Cause: ${cause}`
|
|
1590
1608
|
);
|
|
1591
1609
|
}
|
|
1592
|
-
return token;
|
|
1593
1610
|
}
|
|
1594
1611
|
buildUrl(queueName, ...pathSegments) {
|
|
1595
1612
|
const encodedQueue = encodeURIComponent(queueName);
|
|
@@ -1620,7 +1637,7 @@ var ApiClient = class _ApiClient {
|
|
|
1620
1637
|
}
|
|
1621
1638
|
console.debug("[VQS Debug] Request:", JSON.stringify(logData, null, 2));
|
|
1622
1639
|
}
|
|
1623
|
-
init.headers.set("User-Agent", `@vercel/queue/${"0.1.
|
|
1640
|
+
init.headers.set("User-Agent", `@vercel/queue/${"0.1.3"}`);
|
|
1624
1641
|
init.headers.set("Vqs-Client-Ts", (/* @__PURE__ */ new Date()).toISOString());
|
|
1625
1642
|
const response = await fetch(url, init);
|
|
1626
1643
|
if (isDebugEnabled()) {
|