@upstash/qstash 2.10.1 → 2.11.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 +20 -0
- package/{chunk-Z37KJCW7.mjs → chunk-ATX5KA4T.mjs} +1 -1
- package/{chunk-PIBVA43B.mjs → chunk-KGYBZXTJ.mjs} +1 -1
- package/{chunk-35B33QW3.mjs → chunk-T3Z5YUS4.mjs} +492 -12
- package/{client-CsM1dTnz.d.ts → client-BHOXiX0H.d.mts} +52 -2
- package/{client-CsM1dTnz.d.mts → client-BHOXiX0H.d.ts} +52 -2
- package/cloudflare.d.mts +1 -1
- package/cloudflare.d.ts +1 -1
- package/cloudflare.js +490 -12
- package/cloudflare.mjs +1 -1
- package/h3.d.mts +1 -1
- package/h3.d.ts +1 -1
- package/h3.js +490 -12
- package/h3.mjs +3 -3
- package/hono.d.mts +1 -1
- package/hono.d.ts +1 -1
- package/hono.js +490 -12
- package/hono.mjs +1 -1
- package/index.d.mts +2 -2
- package/index.d.ts +2 -2
- package/index.js +490 -12
- package/index.mjs +2 -2
- package/nextjs.d.mts +33 -2
- package/nextjs.d.ts +33 -2
- package/nextjs.js +511 -18
- package/nextjs.mjs +24 -8
- package/nuxt.js +70 -3
- package/nuxt.mjs +3 -3
- package/package.json +1 -1
- package/solidjs.d.mts +1 -1
- package/solidjs.d.ts +1 -1
- package/solidjs.js +490 -12
- package/solidjs.mjs +2 -2
- package/svelte.d.mts +1 -1
- package/svelte.d.ts +1 -1
- package/svelte.js +490 -12
- package/svelte.mjs +2 -2
- package/workflow.d.mts +1 -1
- package/workflow.d.ts +1 -1
- package/workflow.js +490 -12
- package/workflow.mjs +1 -1
package/h3.js
CHANGED
|
@@ -600,6 +600,9 @@ var formatWorkflowError = (error) => {
|
|
|
600
600
|
|
|
601
601
|
// src/client/utils.ts
|
|
602
602
|
var DEFAULT_BULK_COUNT = 100;
|
|
603
|
+
function serializeLabel(label) {
|
|
604
|
+
return Array.isArray(label) ? label.join(",") : label;
|
|
605
|
+
}
|
|
603
606
|
var isIgnoredHeader = (header) => {
|
|
604
607
|
const lowerCaseHeader = header.toLowerCase();
|
|
605
608
|
return lowerCaseHeader.startsWith("content-type") || lowerCaseHeader.startsWith("upstash-");
|
|
@@ -684,7 +687,7 @@ function processHeaders(request) {
|
|
|
684
687
|
headers.set("Upstash-Flow-Control-Value", controlValue.join(", "));
|
|
685
688
|
}
|
|
686
689
|
if (request.label !== void 0) {
|
|
687
|
-
headers.set("Upstash-Label", request.label);
|
|
690
|
+
headers.set("Upstash-Label", serializeLabel(request.label));
|
|
688
691
|
}
|
|
689
692
|
if (request.redact !== void 0) {
|
|
690
693
|
const redactParts = [];
|
|
@@ -781,17 +784,23 @@ function normalizeCursor(response) {
|
|
|
781
784
|
const cursor = response.cursor;
|
|
782
785
|
return { ...response, cursor: cursor || void 0 };
|
|
783
786
|
}
|
|
787
|
+
function _processGlobal() {
|
|
788
|
+
const proc = globalThis["process"];
|
|
789
|
+
return proc;
|
|
790
|
+
}
|
|
784
791
|
function getRuntime() {
|
|
785
|
-
|
|
786
|
-
|
|
792
|
+
const proc = _processGlobal();
|
|
793
|
+
if (proc?.versions?.bun)
|
|
794
|
+
return `bun@${proc.versions.bun}`;
|
|
787
795
|
if (typeof EdgeRuntime === "string")
|
|
788
796
|
return "edge-light";
|
|
789
|
-
|
|
790
|
-
return `node@${
|
|
797
|
+
if (typeof proc?.version === "string")
|
|
798
|
+
return `node@${proc.version}`;
|
|
791
799
|
return "";
|
|
792
800
|
}
|
|
793
801
|
function getSafeEnvironment() {
|
|
794
|
-
|
|
802
|
+
const proc = _processGlobal();
|
|
803
|
+
return proc?.env ?? {};
|
|
795
804
|
}
|
|
796
805
|
|
|
797
806
|
// src/client/multi-region/utils.ts
|
|
@@ -835,12 +844,453 @@ function normalizeRegionHeader(region) {
|
|
|
835
844
|
return void 0;
|
|
836
845
|
}
|
|
837
846
|
|
|
847
|
+
// src/dev-server/constants.ts
|
|
848
|
+
var DEFAULT_DEV_PORT = 8080;
|
|
849
|
+
var DEV_CREDENTIALS = {
|
|
850
|
+
token: "eyJVc2VySUQiOiJkZWZhdWx0VXNlciIsIlBhc3N3b3JkIjoiZGVmYXVsdFBhc3N3b3JkIn0=",
|
|
851
|
+
currentSigningKey: "sig_7kYjw48mhY7kAjqNGcy6cr29RJ6r",
|
|
852
|
+
nextSigningKey: "sig_5ZB6DVzB1wjE8S6rZ7eenA8Pdnhs"
|
|
853
|
+
};
|
|
854
|
+
var GITHUB_RELEASES_URL = "https://api.github.com/repos/upstash/qstash-cli/releases/latest";
|
|
855
|
+
var BINARY_URL_BASE = "https://artifacts.upstash.com/qstash/versions";
|
|
856
|
+
var CONSOLE_URL = "https://console.upstash.com/qstash/local-mode-user";
|
|
857
|
+
var DEV_PREFIX = "\x1B[2m[QStash Dev]\x1B[0m";
|
|
858
|
+
var CLI_PREFIX = "\x1B[2m[QStash CLI]\x1B[0m";
|
|
859
|
+
var _n = (m) => `node:${m}`;
|
|
860
|
+
var importHttp = () => import(
|
|
861
|
+
/* webpackIgnore: true */
|
|
862
|
+
_n("http")
|
|
863
|
+
);
|
|
864
|
+
var importHttps = () => import(
|
|
865
|
+
/* webpackIgnore: true */
|
|
866
|
+
_n("https")
|
|
867
|
+
);
|
|
868
|
+
var importFs = () => import(
|
|
869
|
+
/* webpackIgnore: true */
|
|
870
|
+
_n("fs")
|
|
871
|
+
);
|
|
872
|
+
var importChildProcess = () => import(
|
|
873
|
+
/* webpackIgnore: true */
|
|
874
|
+
_n("child_process")
|
|
875
|
+
);
|
|
876
|
+
var importOs = () => import(
|
|
877
|
+
/* webpackIgnore: true */
|
|
878
|
+
_n("os")
|
|
879
|
+
);
|
|
880
|
+
|
|
881
|
+
// src/dev-server/http.ts
|
|
882
|
+
var HTTP_OK = 200;
|
|
883
|
+
var HTTP_MULTI_CHOICE = 300;
|
|
884
|
+
var nativeGet = async (url, headers, timeoutMs) => {
|
|
885
|
+
const parsedUrl = new URL(url);
|
|
886
|
+
const httpModule = parsedUrl.protocol === "https:" ? await importHttps() : await importHttp();
|
|
887
|
+
return new Promise((resolve, reject) => {
|
|
888
|
+
const request = httpModule.get(url, { headers }, (response) => {
|
|
889
|
+
const chunks = [];
|
|
890
|
+
response.on("data", (chunk) => chunks.push(chunk));
|
|
891
|
+
response.on("end", () => {
|
|
892
|
+
const statusCode = response.statusCode ?? 0;
|
|
893
|
+
resolve({
|
|
894
|
+
ok: statusCode >= HTTP_OK && statusCode < HTTP_MULTI_CHOICE,
|
|
895
|
+
statusCode,
|
|
896
|
+
body: Buffer.concat(chunks)
|
|
897
|
+
});
|
|
898
|
+
});
|
|
899
|
+
response.on("error", reject);
|
|
900
|
+
});
|
|
901
|
+
if (timeoutMs) {
|
|
902
|
+
request.setTimeout(timeoutMs, () => {
|
|
903
|
+
request.destroy(new Error("Request timed out"));
|
|
904
|
+
});
|
|
905
|
+
}
|
|
906
|
+
request.on("error", reject);
|
|
907
|
+
});
|
|
908
|
+
};
|
|
909
|
+
|
|
910
|
+
// src/dev-server/health.ts
|
|
911
|
+
var HEALTH_CHECK_TIMEOUT_MS = 2e3;
|
|
912
|
+
var isDevServerRunning = async (baseUrl) => {
|
|
913
|
+
try {
|
|
914
|
+
const { ok: ok4, body } = await nativeGet(
|
|
915
|
+
`${baseUrl}/v2/keys`,
|
|
916
|
+
{ Authorization: `Bearer ${DEV_CREDENTIALS.token}` },
|
|
917
|
+
HEALTH_CHECK_TIMEOUT_MS
|
|
918
|
+
);
|
|
919
|
+
if (!ok4)
|
|
920
|
+
return false;
|
|
921
|
+
const data = JSON.parse(body.toString());
|
|
922
|
+
return data.current === DEV_CREDENTIALS.currentSigningKey && data.next === DEV_CREDENTIALS.nextSigningKey;
|
|
923
|
+
} catch {
|
|
924
|
+
return false;
|
|
925
|
+
}
|
|
926
|
+
};
|
|
927
|
+
var _didLogUnreachable = false;
|
|
928
|
+
var checkDevServerReachable = async (baseUrl, runtime) => {
|
|
929
|
+
if (await pingEdge(baseUrl))
|
|
930
|
+
return;
|
|
931
|
+
if (!_didLogUnreachable) {
|
|
932
|
+
console.error(unreachableMessage(baseUrl, runtime));
|
|
933
|
+
_didLogUnreachable = true;
|
|
934
|
+
}
|
|
935
|
+
throw new Error(`${DEV_PREFIX} dev server unreachable at ${baseUrl}`);
|
|
936
|
+
};
|
|
937
|
+
var pingEdge = async (baseUrl) => {
|
|
938
|
+
try {
|
|
939
|
+
const controller = new AbortController();
|
|
940
|
+
const timeout = setTimeout(() => {
|
|
941
|
+
controller.abort();
|
|
942
|
+
}, HEALTH_CHECK_TIMEOUT_MS);
|
|
943
|
+
const response = await fetch(`${baseUrl}/v2/keys`, {
|
|
944
|
+
headers: { Authorization: `Bearer ${DEV_CREDENTIALS.token}` },
|
|
945
|
+
signal: controller.signal
|
|
946
|
+
});
|
|
947
|
+
clearTimeout(timeout);
|
|
948
|
+
return response.ok;
|
|
949
|
+
} catch {
|
|
950
|
+
return false;
|
|
951
|
+
}
|
|
952
|
+
};
|
|
953
|
+
var unreachableMessage = (baseUrl, runtime) => {
|
|
954
|
+
const port = new URL(baseUrl).port;
|
|
955
|
+
const manualStartCmd = `npx @upstash/qstash-cli dev --port ${port}`;
|
|
956
|
+
const header = `
|
|
957
|
+
${DEV_PREFIX} The dev server is not running at ${baseUrl}.
|
|
958
|
+
|
|
959
|
+
`;
|
|
960
|
+
if (runtime === "cloudflare-workers") {
|
|
961
|
+
return header + `Cloudflare Workers cannot start the dev server automatically.
|
|
962
|
+
Start it manually before running wrangler dev:
|
|
963
|
+
|
|
964
|
+
${manualStartCmd}
|
|
965
|
+
`;
|
|
966
|
+
}
|
|
967
|
+
return header + `Edge runtimes cannot start the dev server automatically.
|
|
968
|
+
Either:
|
|
969
|
+
1. Add the instrumentation hook to start it with your app:
|
|
970
|
+
|
|
971
|
+
// instrumentation.ts
|
|
972
|
+
import { registerQStashDev } from "@upstash/qstash/nextjs";
|
|
973
|
+
export async function register() { await registerQStashDev(); }
|
|
974
|
+
|
|
975
|
+
2. Or start it manually:
|
|
976
|
+
|
|
977
|
+
${manualStartCmd}
|
|
978
|
+
`;
|
|
979
|
+
};
|
|
980
|
+
|
|
981
|
+
// src/dev-server/binary.ts
|
|
982
|
+
var ensureBinary = async () => {
|
|
983
|
+
const fs = await importFs();
|
|
984
|
+
const os = await importOs();
|
|
985
|
+
const cacheDirectory = await findCacheDirectory();
|
|
986
|
+
const isWindows = os.platform() === "win32";
|
|
987
|
+
const binaryName = isWindows ? "qstash.exe" : "qstash";
|
|
988
|
+
const binaryPath = `${cacheDirectory}/${binaryName}`;
|
|
989
|
+
const versionFile = `${cacheDirectory}/.version`;
|
|
990
|
+
let version;
|
|
991
|
+
try {
|
|
992
|
+
version = await fetchLatestVersion();
|
|
993
|
+
} catch (error) {
|
|
994
|
+
if (fs.existsSync(binaryPath)) {
|
|
995
|
+
const cachedVersion = fs.existsSync(versionFile) ? fs.readFileSync(versionFile, "utf8").trim() : "unknown";
|
|
996
|
+
console.log(`${DEV_PREFIX} Offline, using local v${cachedVersion}`);
|
|
997
|
+
return binaryPath;
|
|
998
|
+
}
|
|
999
|
+
throw error;
|
|
1000
|
+
}
|
|
1001
|
+
return downloadBinary(version, cacheDirectory);
|
|
1002
|
+
};
|
|
1003
|
+
var fetchLatestVersion = async () => {
|
|
1004
|
+
const { ok: ok4, statusCode, body } = await nativeGet(GITHUB_RELEASES_URL, {
|
|
1005
|
+
Accept: "application/vnd.github.v3+json",
|
|
1006
|
+
"User-Agent": "upstash-qstash-js"
|
|
1007
|
+
});
|
|
1008
|
+
if (!ok4) {
|
|
1009
|
+
throw new Error(`[QStash Dev] Failed to fetch latest version: HTTP ${statusCode}`);
|
|
1010
|
+
}
|
|
1011
|
+
const data = JSON.parse(body.toString());
|
|
1012
|
+
return data.tag_name.replace(/^v/, "");
|
|
1013
|
+
};
|
|
1014
|
+
var findCacheDirectory = async () => {
|
|
1015
|
+
const fs = await importFs();
|
|
1016
|
+
const os = await importOs();
|
|
1017
|
+
const home = os.homedir();
|
|
1018
|
+
const platform = os.platform();
|
|
1019
|
+
let base;
|
|
1020
|
+
if (platform === "darwin") {
|
|
1021
|
+
base = `${home}/Library/Caches/upstash`;
|
|
1022
|
+
} else if (platform === "win32") {
|
|
1023
|
+
base = `${process.env.LOCALAPPDATA ?? `${home}/AppData/Local`}/upstash`;
|
|
1024
|
+
} else {
|
|
1025
|
+
base = `${home}/.cache/upstash`;
|
|
1026
|
+
}
|
|
1027
|
+
const cacheDirectory = `${base}/qstash-dev`;
|
|
1028
|
+
await fs.promises.mkdir(cacheDirectory, { recursive: true });
|
|
1029
|
+
return cacheDirectory;
|
|
1030
|
+
};
|
|
1031
|
+
var downloadBinary = async (version, cacheDirectory) => {
|
|
1032
|
+
const fs = await importFs();
|
|
1033
|
+
const childProcess = await importChildProcess();
|
|
1034
|
+
const os = await importOs();
|
|
1035
|
+
const osPlatform = os.platform();
|
|
1036
|
+
const isWindows = osPlatform === "win32";
|
|
1037
|
+
const platform = isWindows ? "windows" : osPlatform === "darwin" ? "darwin" : "linux";
|
|
1038
|
+
const arch = os.arch() === "arm64" ? "arm64" : "amd64";
|
|
1039
|
+
const archiveName = `qstash-server_${version}_${platform}_${arch}`;
|
|
1040
|
+
const binaryName = isWindows ? "qstash.exe" : "qstash";
|
|
1041
|
+
const binaryPath = `${cacheDirectory}/${binaryName}`;
|
|
1042
|
+
const versionFile = `${cacheDirectory}/.version`;
|
|
1043
|
+
if (fs.existsSync(binaryPath) && fs.existsSync(versionFile)) {
|
|
1044
|
+
const cachedVersion = fs.readFileSync(versionFile, "utf8").trim();
|
|
1045
|
+
if (cachedVersion === version) {
|
|
1046
|
+
return binaryPath;
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
await fs.promises.rm(cacheDirectory, { recursive: true, force: true });
|
|
1050
|
+
await fs.promises.mkdir(cacheDirectory, { recursive: true });
|
|
1051
|
+
const extension = isWindows ? "zip" : "tar.gz";
|
|
1052
|
+
const archiveUrl = `${BINARY_URL_BASE}/${version}/${archiveName}.${extension}`;
|
|
1053
|
+
console.log(`${DEV_PREFIX} Downloading dev server v${version}...`);
|
|
1054
|
+
const { ok: ok4, statusCode, body } = await nativeGet(archiveUrl);
|
|
1055
|
+
if (!ok4) {
|
|
1056
|
+
throw new Error(`[QStash Dev] Failed to download binary: HTTP ${statusCode}`);
|
|
1057
|
+
}
|
|
1058
|
+
const archivePath = `${cacheDirectory}/${archiveName}.${extension}`;
|
|
1059
|
+
await fs.promises.writeFile(archivePath, new Uint8Array(body));
|
|
1060
|
+
childProcess.execFileSync("tar", ["-xf", archivePath, "-C", cacheDirectory], {
|
|
1061
|
+
stdio: "pipe"
|
|
1062
|
+
});
|
|
1063
|
+
if (!isWindows) {
|
|
1064
|
+
const EXECUTABLE_PERMISSION = 493;
|
|
1065
|
+
await fs.promises.chmod(binaryPath, EXECUTABLE_PERMISSION);
|
|
1066
|
+
}
|
|
1067
|
+
await fs.promises.writeFile(versionFile, version);
|
|
1068
|
+
await fs.promises.unlink(archivePath).catch(() => {
|
|
1069
|
+
});
|
|
1070
|
+
return binaryPath;
|
|
1071
|
+
};
|
|
1072
|
+
|
|
1073
|
+
// src/dev-server/process.ts
|
|
1074
|
+
var STARTUP_TIMEOUT_MS = 3e4;
|
|
1075
|
+
var _proc = () => {
|
|
1076
|
+
return globalThis["process"] ?? {};
|
|
1077
|
+
};
|
|
1078
|
+
var spawnServer = async (binaryPath, port, onUnexpectedExit) => {
|
|
1079
|
+
const childProcess = await importChildProcess();
|
|
1080
|
+
const child = await new Promise((resolve, reject) => {
|
|
1081
|
+
const child2 = childProcess.spawn(binaryPath, ["dev", "--port", String(port)], {
|
|
1082
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
1083
|
+
});
|
|
1084
|
+
const timeout = setTimeout(() => {
|
|
1085
|
+
child2.kill();
|
|
1086
|
+
reject(new Error("[QStash Dev] Server failed to start within 30 seconds"));
|
|
1087
|
+
}, STARTUP_TIMEOUT_MS);
|
|
1088
|
+
let startupOutput = "";
|
|
1089
|
+
let started = false;
|
|
1090
|
+
const bufferLine = (line) => {
|
|
1091
|
+
if (!started)
|
|
1092
|
+
startupOutput += `${line}
|
|
1093
|
+
`;
|
|
1094
|
+
};
|
|
1095
|
+
forwardWithPrefix(child2.stdout, _proc().stdout, (line) => {
|
|
1096
|
+
bufferLine(line);
|
|
1097
|
+
if (!started && /runn+ing( at|\.)/i.test(line)) {
|
|
1098
|
+
clearTimeout(timeout);
|
|
1099
|
+
started = true;
|
|
1100
|
+
resolve(child2);
|
|
1101
|
+
}
|
|
1102
|
+
});
|
|
1103
|
+
forwardWithPrefix(child2.stderr, _proc().stderr, bufferLine);
|
|
1104
|
+
child2.on("error", (error) => {
|
|
1105
|
+
clearTimeout(timeout);
|
|
1106
|
+
reject(new Error(`[QStash Dev] Failed to start server: ${error.message}`));
|
|
1107
|
+
});
|
|
1108
|
+
child2.on("close", (code, _signal) => {
|
|
1109
|
+
if (started) {
|
|
1110
|
+
onUnexpectedExit?.();
|
|
1111
|
+
return;
|
|
1112
|
+
}
|
|
1113
|
+
clearTimeout(timeout);
|
|
1114
|
+
reject(new Error(formatStartupError(code, startupOutput)));
|
|
1115
|
+
});
|
|
1116
|
+
});
|
|
1117
|
+
registerCleanup(child);
|
|
1118
|
+
child.unref?.();
|
|
1119
|
+
child.stdout?.unref?.();
|
|
1120
|
+
child.stderr?.unref?.();
|
|
1121
|
+
};
|
|
1122
|
+
var formatStartupError = (code, startupOutput) => {
|
|
1123
|
+
const cleaned = startupOutput.replaceAll(/\u001B\[[\d;]*m/g, "").replaceAll(/^\d{1,2}:\d{2}(AM|PM)\s+\w{3}\s+/gm, "").trim();
|
|
1124
|
+
if (/address already in use/i.test(cleaned)) {
|
|
1125
|
+
const match = /:(\d+)\s*$/.exec(cleaned);
|
|
1126
|
+
const portHint = match ? ` on port ${match[1]}` : "";
|
|
1127
|
+
return `[QStash Dev] Port already in use${portHint}. Set QSTASH_DEV_PORT to use a different port, or stop the process holding it.`;
|
|
1128
|
+
}
|
|
1129
|
+
const codeSuffix = code ? ` with code ${code}` : "";
|
|
1130
|
+
const detail = cleaned ? `: ${cleaned}` : "";
|
|
1131
|
+
return `[QStash Dev] Server exited unexpectedly${codeSuffix}${detail}`;
|
|
1132
|
+
};
|
|
1133
|
+
var forwardWithPrefix = (source, destination, onLine) => {
|
|
1134
|
+
if (!source)
|
|
1135
|
+
return;
|
|
1136
|
+
let buffer = "";
|
|
1137
|
+
const flushLine = (line) => {
|
|
1138
|
+
destination?.write(`${CLI_PREFIX} ${line}
|
|
1139
|
+
`);
|
|
1140
|
+
onLine(line);
|
|
1141
|
+
};
|
|
1142
|
+
source.on("data", (data) => {
|
|
1143
|
+
buffer += data.toString();
|
|
1144
|
+
let newlineIndex = buffer.indexOf("\n");
|
|
1145
|
+
while (newlineIndex !== -1) {
|
|
1146
|
+
flushLine(buffer.slice(0, newlineIndex));
|
|
1147
|
+
buffer = buffer.slice(newlineIndex + 1);
|
|
1148
|
+
newlineIndex = buffer.indexOf("\n");
|
|
1149
|
+
}
|
|
1150
|
+
});
|
|
1151
|
+
source.on("end", () => {
|
|
1152
|
+
if (buffer.length > 0) {
|
|
1153
|
+
flushLine(buffer);
|
|
1154
|
+
buffer = "";
|
|
1155
|
+
}
|
|
1156
|
+
});
|
|
1157
|
+
source.on("error", () => {
|
|
1158
|
+
});
|
|
1159
|
+
};
|
|
1160
|
+
var currentChild;
|
|
1161
|
+
var processHandlersRegistered = false;
|
|
1162
|
+
var killCurrentChild = () => {
|
|
1163
|
+
if (!currentChild)
|
|
1164
|
+
return;
|
|
1165
|
+
try {
|
|
1166
|
+
currentChild.kill("SIGTERM");
|
|
1167
|
+
} catch {
|
|
1168
|
+
}
|
|
1169
|
+
currentChild = void 0;
|
|
1170
|
+
};
|
|
1171
|
+
var registerCleanup = (child) => {
|
|
1172
|
+
currentChild = child;
|
|
1173
|
+
if (!processHandlersRegistered) {
|
|
1174
|
+
processHandlersRegistered = true;
|
|
1175
|
+
const proc = _proc();
|
|
1176
|
+
proc.on?.("exit", killCurrentChild);
|
|
1177
|
+
proc.on?.("SIGINT", () => {
|
|
1178
|
+
killCurrentChild();
|
|
1179
|
+
proc.exit?.(0);
|
|
1180
|
+
});
|
|
1181
|
+
proc.on?.("SIGTERM", () => {
|
|
1182
|
+
killCurrentChild();
|
|
1183
|
+
proc.exit?.(0);
|
|
1184
|
+
});
|
|
1185
|
+
}
|
|
1186
|
+
};
|
|
1187
|
+
|
|
1188
|
+
// src/dev-server/index.ts
|
|
1189
|
+
var _processGlobal2 = () => {
|
|
1190
|
+
const proc = globalThis["process"];
|
|
1191
|
+
return proc;
|
|
1192
|
+
};
|
|
1193
|
+
var devServerPromise;
|
|
1194
|
+
var ensureDevelopmentServer = (env, devMode) => {
|
|
1195
|
+
if (!shouldUseDevelopmentMode(devMode, env))
|
|
1196
|
+
return Promise.resolve();
|
|
1197
|
+
const procEnv = _processGlobal2()?.env;
|
|
1198
|
+
if (procEnv?.NEXT_PHASE === "phase-production-build")
|
|
1199
|
+
return Promise.resolve();
|
|
1200
|
+
if (procEnv?.NODE_ENV === "production")
|
|
1201
|
+
return Promise.resolve();
|
|
1202
|
+
const runtime = getRuntime2();
|
|
1203
|
+
if (runtime !== "nodejs") {
|
|
1204
|
+
return checkDevServerReachable(getDevUrl(env), runtime);
|
|
1205
|
+
}
|
|
1206
|
+
if (!devServerPromise) {
|
|
1207
|
+
devServerPromise = startPipeline(env).catch((error) => {
|
|
1208
|
+
devServerPromise = void 0;
|
|
1209
|
+
throw error;
|
|
1210
|
+
});
|
|
1211
|
+
}
|
|
1212
|
+
return devServerPromise;
|
|
1213
|
+
};
|
|
1214
|
+
var startPipeline = async (env) => {
|
|
1215
|
+
const baseUrl = getDevUrl(env);
|
|
1216
|
+
const port = new URL(baseUrl).port;
|
|
1217
|
+
const consoleLink = `\x1B[36m${CONSOLE_URL}?port=${port}\x1B[0m`;
|
|
1218
|
+
if (await isDevServerRunning(baseUrl)) {
|
|
1219
|
+
console.log(
|
|
1220
|
+
`${DEV_PREFIX} Server already running at ${baseUrl}
|
|
1221
|
+
${DEV_PREFIX} Console: ${consoleLink}`
|
|
1222
|
+
);
|
|
1223
|
+
return;
|
|
1224
|
+
}
|
|
1225
|
+
const binaryPath = await ensureBinary();
|
|
1226
|
+
await spawnServer(binaryPath, port, () => {
|
|
1227
|
+
devServerPromise = void 0;
|
|
1228
|
+
});
|
|
1229
|
+
};
|
|
1230
|
+
var shouldUseDevelopmentMode = (devMode, env) => {
|
|
1231
|
+
if (devMode !== void 0)
|
|
1232
|
+
return devMode;
|
|
1233
|
+
const value = env?.QSTASH_DEV ?? getProcessEnvironment("QSTASH_DEV");
|
|
1234
|
+
if (value === void 0 || value === "" || value === "false" || value === "0")
|
|
1235
|
+
return false;
|
|
1236
|
+
if (value === "true" || value === "1")
|
|
1237
|
+
return true;
|
|
1238
|
+
throw new Error(`[QStash Dev] Invalid value for QSTASH_DEV in environment: ${value}`);
|
|
1239
|
+
};
|
|
1240
|
+
var getDevelopmentCredentials = (env) => {
|
|
1241
|
+
return {
|
|
1242
|
+
...DEV_CREDENTIALS,
|
|
1243
|
+
baseUrl: getDevUrl(env)
|
|
1244
|
+
};
|
|
1245
|
+
};
|
|
1246
|
+
var getDevUrl = (env) => {
|
|
1247
|
+
const portString = env?.QSTASH_DEV_PORT ?? getProcessEnvironment("QSTASH_DEV_PORT");
|
|
1248
|
+
let port = DEFAULT_DEV_PORT;
|
|
1249
|
+
if (portString) {
|
|
1250
|
+
const parsed = Number.parseInt(portString, 10);
|
|
1251
|
+
if (!Number.isNaN(parsed) && parsed > 0) {
|
|
1252
|
+
port = parsed;
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
return `http://127.0.0.1:${port}`;
|
|
1256
|
+
};
|
|
1257
|
+
var getRuntime2 = () => {
|
|
1258
|
+
if (typeof navigator !== "undefined" && navigator.userAgent === "Cloudflare-Workers") {
|
|
1259
|
+
return "cloudflare-workers";
|
|
1260
|
+
}
|
|
1261
|
+
const proc = _processGlobal2();
|
|
1262
|
+
if (!proc) {
|
|
1263
|
+
return "browser";
|
|
1264
|
+
}
|
|
1265
|
+
if (!proc.release?.name) {
|
|
1266
|
+
return "edge";
|
|
1267
|
+
}
|
|
1268
|
+
return "nodejs";
|
|
1269
|
+
};
|
|
1270
|
+
var getProcessEnvironment = (key) => {
|
|
1271
|
+
const proc = _processGlobal2();
|
|
1272
|
+
return proc?.env ? proc.env[key] : void 0;
|
|
1273
|
+
};
|
|
1274
|
+
|
|
838
1275
|
// src/client/multi-region/incoming.ts
|
|
839
1276
|
var getReceiverSigningKeys = ({
|
|
840
1277
|
environment,
|
|
841
1278
|
regionFromHeader,
|
|
842
|
-
config
|
|
1279
|
+
config,
|
|
1280
|
+
devMode
|
|
843
1281
|
}) => {
|
|
1282
|
+
if (shouldUseDevelopmentMode(devMode, environment)) {
|
|
1283
|
+
if (config?.currentSigningKey || config?.nextSigningKey) {
|
|
1284
|
+
console.warn(
|
|
1285
|
+
`${DEV_PREFIX} Dev mode is active. Ignoring signing keys from config. Set devMode: false to use your own keys.`
|
|
1286
|
+
);
|
|
1287
|
+
}
|
|
1288
|
+
const developmentCreds = getDevelopmentCredentials(environment);
|
|
1289
|
+
return {
|
|
1290
|
+
currentSigningKey: developmentCreds.currentSigningKey,
|
|
1291
|
+
nextSigningKey: developmentCreds.nextSigningKey
|
|
1292
|
+
};
|
|
1293
|
+
}
|
|
844
1294
|
if (config?.currentSigningKey && config.nextSigningKey) {
|
|
845
1295
|
return {
|
|
846
1296
|
currentSigningKey: config.currentSigningKey,
|
|
@@ -885,8 +1335,21 @@ var getClientCredentials = (clientCredentialConfig) => {
|
|
|
885
1335
|
};
|
|
886
1336
|
var resolveCredentials = ({
|
|
887
1337
|
environment,
|
|
888
|
-
config
|
|
1338
|
+
config,
|
|
1339
|
+
devMode
|
|
889
1340
|
}) => {
|
|
1341
|
+
if (shouldUseDevelopmentMode(devMode, environment)) {
|
|
1342
|
+
if (config?.baseUrl || config?.token) {
|
|
1343
|
+
console.warn(
|
|
1344
|
+
`${DEV_PREFIX} Dev mode is active. Ignoring baseUrl/token from config. Set devMode: false to use your own credentials.`
|
|
1345
|
+
);
|
|
1346
|
+
}
|
|
1347
|
+
const developmentCreds = getDevelopmentCredentials(environment);
|
|
1348
|
+
return {
|
|
1349
|
+
baseUrl: developmentCreds.baseUrl,
|
|
1350
|
+
token: developmentCreds.token
|
|
1351
|
+
};
|
|
1352
|
+
}
|
|
890
1353
|
if (config?.baseUrl && config.token) {
|
|
891
1354
|
return {
|
|
892
1355
|
baseUrl: config.baseUrl,
|
|
@@ -939,9 +1402,11 @@ var SignatureError = class extends Error {
|
|
|
939
1402
|
var Receiver = class {
|
|
940
1403
|
currentSigningKey;
|
|
941
1404
|
nextSigningKey;
|
|
1405
|
+
devMode;
|
|
942
1406
|
constructor(config) {
|
|
943
1407
|
this.currentSigningKey = config?.currentSigningKey;
|
|
944
1408
|
this.nextSigningKey = config?.nextSigningKey;
|
|
1409
|
+
this.devMode = config?.devMode;
|
|
945
1410
|
}
|
|
946
1411
|
/**
|
|
947
1412
|
* Verify the signature of a request.
|
|
@@ -960,7 +1425,8 @@ var Receiver = class {
|
|
|
960
1425
|
config: {
|
|
961
1426
|
currentSigningKey: this.currentSigningKey,
|
|
962
1427
|
nextSigningKey: this.nextSigningKey
|
|
963
|
-
}
|
|
1428
|
+
},
|
|
1429
|
+
devMode: this.devMode
|
|
964
1430
|
});
|
|
965
1431
|
if (!signingKeys) {
|
|
966
1432
|
throw new Error(
|
|
@@ -1226,12 +1692,14 @@ var HttpClient = class {
|
|
|
1226
1692
|
baseUrl;
|
|
1227
1693
|
authorization;
|
|
1228
1694
|
options;
|
|
1695
|
+
devMode;
|
|
1229
1696
|
retry;
|
|
1230
1697
|
headers;
|
|
1231
1698
|
telemetryHeaders;
|
|
1232
1699
|
constructor(config) {
|
|
1233
1700
|
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
1234
1701
|
this.authorization = config.authorization;
|
|
1702
|
+
this.devMode = config.devMode;
|
|
1235
1703
|
this.retry = // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
1236
1704
|
typeof config.retry === "boolean" && !config.retry ? {
|
|
1237
1705
|
attempts: 1,
|
|
@@ -1244,6 +1712,7 @@ var HttpClient = class {
|
|
|
1244
1712
|
this.telemetryHeaders = config.telemetryHeaders;
|
|
1245
1713
|
}
|
|
1246
1714
|
async request(request) {
|
|
1715
|
+
await ensureDevelopmentServer(void 0, this.devMode);
|
|
1247
1716
|
const { response } = await this.requestWithBackoff(request);
|
|
1248
1717
|
if (request.parseResponseAsJson === false) {
|
|
1249
1718
|
return void 0;
|
|
@@ -1251,6 +1720,7 @@ var HttpClient = class {
|
|
|
1251
1720
|
return await response.json();
|
|
1252
1721
|
}
|
|
1253
1722
|
async *requestStream(request) {
|
|
1723
|
+
await ensureDevelopmentServer(void 0, this.devMode);
|
|
1254
1724
|
const { response } = await this.requestWithBackoff(request);
|
|
1255
1725
|
if (!response.body) {
|
|
1256
1726
|
throw new Error("No response body");
|
|
@@ -3359,7 +3829,7 @@ var Workflow = class {
|
|
|
3359
3829
|
};
|
|
3360
3830
|
|
|
3361
3831
|
// version.ts
|
|
3362
|
-
var VERSION = "2.
|
|
3832
|
+
var VERSION = "2.11.1";
|
|
3363
3833
|
|
|
3364
3834
|
// src/client/client.ts
|
|
3365
3835
|
var Client = class {
|
|
@@ -3367,7 +3837,14 @@ var Client = class {
|
|
|
3367
3837
|
token;
|
|
3368
3838
|
constructor(config) {
|
|
3369
3839
|
const environment = getSafeEnvironment();
|
|
3370
|
-
const { baseUrl, token } = getClientCredentials({
|
|
3840
|
+
const { baseUrl, token } = getClientCredentials({
|
|
3841
|
+
environment,
|
|
3842
|
+
config,
|
|
3843
|
+
devMode: config?.devMode
|
|
3844
|
+
});
|
|
3845
|
+
if (shouldUseDevelopmentMode(config?.devMode, environment)) {
|
|
3846
|
+
void ensureDevelopmentServer(environment, config?.devMode);
|
|
3847
|
+
}
|
|
3371
3848
|
const enableTelemetry = environment.UPSTASH_DISABLE_TELEMETRY ? false : config?.enableTelemetry ?? true;
|
|
3372
3849
|
const isCloudflare = typeof caches !== "undefined" && "default" in caches;
|
|
3373
3850
|
const telemetryHeaders = new Headers(
|
|
@@ -3384,7 +3861,8 @@ var Client = class {
|
|
|
3384
3861
|
//@ts-expect-error caused by undici and bunjs type overlap
|
|
3385
3862
|
headers: prefixHeaders(new Headers(config?.headers ?? {})),
|
|
3386
3863
|
//@ts-expect-error caused by undici and bunjs type overlap
|
|
3387
|
-
telemetryHeaders
|
|
3864
|
+
telemetryHeaders,
|
|
3865
|
+
devMode: config?.devMode
|
|
3388
3866
|
});
|
|
3389
3867
|
this.token = token;
|
|
3390
3868
|
}
|
package/h3.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
serve,
|
|
3
3
|
verifySignatureH3
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
6
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-KGYBZXTJ.mjs";
|
|
5
|
+
import "./chunk-ATX5KA4T.mjs";
|
|
6
|
+
import "./chunk-T3Z5YUS4.mjs";
|
|
7
7
|
export {
|
|
8
8
|
serve,
|
|
9
9
|
verifySignatureH3
|
package/hono.d.mts
CHANGED
package/hono.d.ts
CHANGED