@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/workflow.js
CHANGED
|
@@ -282,6 +282,9 @@ var formatWorkflowError = (error) => {
|
|
|
282
282
|
|
|
283
283
|
// src/client/utils.ts
|
|
284
284
|
var DEFAULT_BULK_COUNT = 100;
|
|
285
|
+
function serializeLabel(label) {
|
|
286
|
+
return Array.isArray(label) ? label.join(",") : label;
|
|
287
|
+
}
|
|
285
288
|
var isIgnoredHeader = (header) => {
|
|
286
289
|
const lowerCaseHeader = header.toLowerCase();
|
|
287
290
|
return lowerCaseHeader.startsWith("content-type") || lowerCaseHeader.startsWith("upstash-");
|
|
@@ -366,7 +369,7 @@ function processHeaders(request) {
|
|
|
366
369
|
headers.set("Upstash-Flow-Control-Value", controlValue.join(", "));
|
|
367
370
|
}
|
|
368
371
|
if (request.label !== void 0) {
|
|
369
|
-
headers.set("Upstash-Label", request.label);
|
|
372
|
+
headers.set("Upstash-Label", serializeLabel(request.label));
|
|
370
373
|
}
|
|
371
374
|
if (request.redact !== void 0) {
|
|
372
375
|
const redactParts = [];
|
|
@@ -463,17 +466,23 @@ function normalizeCursor(response) {
|
|
|
463
466
|
const cursor = response.cursor;
|
|
464
467
|
return { ...response, cursor: cursor || void 0 };
|
|
465
468
|
}
|
|
469
|
+
function _processGlobal() {
|
|
470
|
+
const proc = globalThis["process"];
|
|
471
|
+
return proc;
|
|
472
|
+
}
|
|
466
473
|
function getRuntime() {
|
|
467
|
-
|
|
468
|
-
|
|
474
|
+
const proc = _processGlobal();
|
|
475
|
+
if (proc?.versions?.bun)
|
|
476
|
+
return `bun@${proc.versions.bun}`;
|
|
469
477
|
if (typeof EdgeRuntime === "string")
|
|
470
478
|
return "edge-light";
|
|
471
|
-
|
|
472
|
-
return `node@${
|
|
479
|
+
if (typeof proc?.version === "string")
|
|
480
|
+
return `node@${proc.version}`;
|
|
473
481
|
return "";
|
|
474
482
|
}
|
|
475
483
|
function getSafeEnvironment() {
|
|
476
|
-
|
|
484
|
+
const proc = _processGlobal();
|
|
485
|
+
return proc?.env ?? {};
|
|
477
486
|
}
|
|
478
487
|
|
|
479
488
|
// src/client/multi-region/utils.ts
|
|
@@ -517,12 +526,453 @@ function normalizeRegionHeader(region) {
|
|
|
517
526
|
return void 0;
|
|
518
527
|
}
|
|
519
528
|
|
|
529
|
+
// src/dev-server/constants.ts
|
|
530
|
+
var DEFAULT_DEV_PORT = 8080;
|
|
531
|
+
var DEV_CREDENTIALS = {
|
|
532
|
+
token: "eyJVc2VySUQiOiJkZWZhdWx0VXNlciIsIlBhc3N3b3JkIjoiZGVmYXVsdFBhc3N3b3JkIn0=",
|
|
533
|
+
currentSigningKey: "sig_7kYjw48mhY7kAjqNGcy6cr29RJ6r",
|
|
534
|
+
nextSigningKey: "sig_5ZB6DVzB1wjE8S6rZ7eenA8Pdnhs"
|
|
535
|
+
};
|
|
536
|
+
var GITHUB_RELEASES_URL = "https://api.github.com/repos/upstash/qstash-cli/releases/latest";
|
|
537
|
+
var BINARY_URL_BASE = "https://artifacts.upstash.com/qstash/versions";
|
|
538
|
+
var CONSOLE_URL = "https://console.upstash.com/qstash/local-mode-user";
|
|
539
|
+
var DEV_PREFIX = "\x1B[2m[QStash Dev]\x1B[0m";
|
|
540
|
+
var CLI_PREFIX = "\x1B[2m[QStash CLI]\x1B[0m";
|
|
541
|
+
var _n = (m) => `node:${m}`;
|
|
542
|
+
var importHttp = () => import(
|
|
543
|
+
/* webpackIgnore: true */
|
|
544
|
+
_n("http")
|
|
545
|
+
);
|
|
546
|
+
var importHttps = () => import(
|
|
547
|
+
/* webpackIgnore: true */
|
|
548
|
+
_n("https")
|
|
549
|
+
);
|
|
550
|
+
var importFs = () => import(
|
|
551
|
+
/* webpackIgnore: true */
|
|
552
|
+
_n("fs")
|
|
553
|
+
);
|
|
554
|
+
var importChildProcess = () => import(
|
|
555
|
+
/* webpackIgnore: true */
|
|
556
|
+
_n("child_process")
|
|
557
|
+
);
|
|
558
|
+
var importOs = () => import(
|
|
559
|
+
/* webpackIgnore: true */
|
|
560
|
+
_n("os")
|
|
561
|
+
);
|
|
562
|
+
|
|
563
|
+
// src/dev-server/http.ts
|
|
564
|
+
var HTTP_OK = 200;
|
|
565
|
+
var HTTP_MULTI_CHOICE = 300;
|
|
566
|
+
var nativeGet = async (url, headers, timeoutMs) => {
|
|
567
|
+
const parsedUrl = new URL(url);
|
|
568
|
+
const httpModule = parsedUrl.protocol === "https:" ? await importHttps() : await importHttp();
|
|
569
|
+
return new Promise((resolve, reject) => {
|
|
570
|
+
const request = httpModule.get(url, { headers }, (response) => {
|
|
571
|
+
const chunks = [];
|
|
572
|
+
response.on("data", (chunk) => chunks.push(chunk));
|
|
573
|
+
response.on("end", () => {
|
|
574
|
+
const statusCode = response.statusCode ?? 0;
|
|
575
|
+
resolve({
|
|
576
|
+
ok: statusCode >= HTTP_OK && statusCode < HTTP_MULTI_CHOICE,
|
|
577
|
+
statusCode,
|
|
578
|
+
body: Buffer.concat(chunks)
|
|
579
|
+
});
|
|
580
|
+
});
|
|
581
|
+
response.on("error", reject);
|
|
582
|
+
});
|
|
583
|
+
if (timeoutMs) {
|
|
584
|
+
request.setTimeout(timeoutMs, () => {
|
|
585
|
+
request.destroy(new Error("Request timed out"));
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
request.on("error", reject);
|
|
589
|
+
});
|
|
590
|
+
};
|
|
591
|
+
|
|
592
|
+
// src/dev-server/health.ts
|
|
593
|
+
var HEALTH_CHECK_TIMEOUT_MS = 2e3;
|
|
594
|
+
var isDevServerRunning = async (baseUrl) => {
|
|
595
|
+
try {
|
|
596
|
+
const { ok: ok4, body } = await nativeGet(
|
|
597
|
+
`${baseUrl}/v2/keys`,
|
|
598
|
+
{ Authorization: `Bearer ${DEV_CREDENTIALS.token}` },
|
|
599
|
+
HEALTH_CHECK_TIMEOUT_MS
|
|
600
|
+
);
|
|
601
|
+
if (!ok4)
|
|
602
|
+
return false;
|
|
603
|
+
const data = JSON.parse(body.toString());
|
|
604
|
+
return data.current === DEV_CREDENTIALS.currentSigningKey && data.next === DEV_CREDENTIALS.nextSigningKey;
|
|
605
|
+
} catch {
|
|
606
|
+
return false;
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
var _didLogUnreachable = false;
|
|
610
|
+
var checkDevServerReachable = async (baseUrl, runtime) => {
|
|
611
|
+
if (await pingEdge(baseUrl))
|
|
612
|
+
return;
|
|
613
|
+
if (!_didLogUnreachable) {
|
|
614
|
+
console.error(unreachableMessage(baseUrl, runtime));
|
|
615
|
+
_didLogUnreachable = true;
|
|
616
|
+
}
|
|
617
|
+
throw new Error(`${DEV_PREFIX} dev server unreachable at ${baseUrl}`);
|
|
618
|
+
};
|
|
619
|
+
var pingEdge = async (baseUrl) => {
|
|
620
|
+
try {
|
|
621
|
+
const controller = new AbortController();
|
|
622
|
+
const timeout = setTimeout(() => {
|
|
623
|
+
controller.abort();
|
|
624
|
+
}, HEALTH_CHECK_TIMEOUT_MS);
|
|
625
|
+
const response = await fetch(`${baseUrl}/v2/keys`, {
|
|
626
|
+
headers: { Authorization: `Bearer ${DEV_CREDENTIALS.token}` },
|
|
627
|
+
signal: controller.signal
|
|
628
|
+
});
|
|
629
|
+
clearTimeout(timeout);
|
|
630
|
+
return response.ok;
|
|
631
|
+
} catch {
|
|
632
|
+
return false;
|
|
633
|
+
}
|
|
634
|
+
};
|
|
635
|
+
var unreachableMessage = (baseUrl, runtime) => {
|
|
636
|
+
const port = new URL(baseUrl).port;
|
|
637
|
+
const manualStartCmd = `npx @upstash/qstash-cli dev --port ${port}`;
|
|
638
|
+
const header = `
|
|
639
|
+
${DEV_PREFIX} The dev server is not running at ${baseUrl}.
|
|
640
|
+
|
|
641
|
+
`;
|
|
642
|
+
if (runtime === "cloudflare-workers") {
|
|
643
|
+
return header + `Cloudflare Workers cannot start the dev server automatically.
|
|
644
|
+
Start it manually before running wrangler dev:
|
|
645
|
+
|
|
646
|
+
${manualStartCmd}
|
|
647
|
+
`;
|
|
648
|
+
}
|
|
649
|
+
return header + `Edge runtimes cannot start the dev server automatically.
|
|
650
|
+
Either:
|
|
651
|
+
1. Add the instrumentation hook to start it with your app:
|
|
652
|
+
|
|
653
|
+
// instrumentation.ts
|
|
654
|
+
import { registerQStashDev } from "@upstash/qstash/nextjs";
|
|
655
|
+
export async function register() { await registerQStashDev(); }
|
|
656
|
+
|
|
657
|
+
2. Or start it manually:
|
|
658
|
+
|
|
659
|
+
${manualStartCmd}
|
|
660
|
+
`;
|
|
661
|
+
};
|
|
662
|
+
|
|
663
|
+
// src/dev-server/binary.ts
|
|
664
|
+
var ensureBinary = async () => {
|
|
665
|
+
const fs = await importFs();
|
|
666
|
+
const os = await importOs();
|
|
667
|
+
const cacheDirectory = await findCacheDirectory();
|
|
668
|
+
const isWindows = os.platform() === "win32";
|
|
669
|
+
const binaryName = isWindows ? "qstash.exe" : "qstash";
|
|
670
|
+
const binaryPath = `${cacheDirectory}/${binaryName}`;
|
|
671
|
+
const versionFile = `${cacheDirectory}/.version`;
|
|
672
|
+
let version;
|
|
673
|
+
try {
|
|
674
|
+
version = await fetchLatestVersion();
|
|
675
|
+
} catch (error) {
|
|
676
|
+
if (fs.existsSync(binaryPath)) {
|
|
677
|
+
const cachedVersion = fs.existsSync(versionFile) ? fs.readFileSync(versionFile, "utf8").trim() : "unknown";
|
|
678
|
+
console.log(`${DEV_PREFIX} Offline, using local v${cachedVersion}`);
|
|
679
|
+
return binaryPath;
|
|
680
|
+
}
|
|
681
|
+
throw error;
|
|
682
|
+
}
|
|
683
|
+
return downloadBinary(version, cacheDirectory);
|
|
684
|
+
};
|
|
685
|
+
var fetchLatestVersion = async () => {
|
|
686
|
+
const { ok: ok4, statusCode, body } = await nativeGet(GITHUB_RELEASES_URL, {
|
|
687
|
+
Accept: "application/vnd.github.v3+json",
|
|
688
|
+
"User-Agent": "upstash-qstash-js"
|
|
689
|
+
});
|
|
690
|
+
if (!ok4) {
|
|
691
|
+
throw new Error(`[QStash Dev] Failed to fetch latest version: HTTP ${statusCode}`);
|
|
692
|
+
}
|
|
693
|
+
const data = JSON.parse(body.toString());
|
|
694
|
+
return data.tag_name.replace(/^v/, "");
|
|
695
|
+
};
|
|
696
|
+
var findCacheDirectory = async () => {
|
|
697
|
+
const fs = await importFs();
|
|
698
|
+
const os = await importOs();
|
|
699
|
+
const home = os.homedir();
|
|
700
|
+
const platform = os.platform();
|
|
701
|
+
let base;
|
|
702
|
+
if (platform === "darwin") {
|
|
703
|
+
base = `${home}/Library/Caches/upstash`;
|
|
704
|
+
} else if (platform === "win32") {
|
|
705
|
+
base = `${process.env.LOCALAPPDATA ?? `${home}/AppData/Local`}/upstash`;
|
|
706
|
+
} else {
|
|
707
|
+
base = `${home}/.cache/upstash`;
|
|
708
|
+
}
|
|
709
|
+
const cacheDirectory = `${base}/qstash-dev`;
|
|
710
|
+
await fs.promises.mkdir(cacheDirectory, { recursive: true });
|
|
711
|
+
return cacheDirectory;
|
|
712
|
+
};
|
|
713
|
+
var downloadBinary = async (version, cacheDirectory) => {
|
|
714
|
+
const fs = await importFs();
|
|
715
|
+
const childProcess = await importChildProcess();
|
|
716
|
+
const os = await importOs();
|
|
717
|
+
const osPlatform = os.platform();
|
|
718
|
+
const isWindows = osPlatform === "win32";
|
|
719
|
+
const platform = isWindows ? "windows" : osPlatform === "darwin" ? "darwin" : "linux";
|
|
720
|
+
const arch = os.arch() === "arm64" ? "arm64" : "amd64";
|
|
721
|
+
const archiveName = `qstash-server_${version}_${platform}_${arch}`;
|
|
722
|
+
const binaryName = isWindows ? "qstash.exe" : "qstash";
|
|
723
|
+
const binaryPath = `${cacheDirectory}/${binaryName}`;
|
|
724
|
+
const versionFile = `${cacheDirectory}/.version`;
|
|
725
|
+
if (fs.existsSync(binaryPath) && fs.existsSync(versionFile)) {
|
|
726
|
+
const cachedVersion = fs.readFileSync(versionFile, "utf8").trim();
|
|
727
|
+
if (cachedVersion === version) {
|
|
728
|
+
return binaryPath;
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
await fs.promises.rm(cacheDirectory, { recursive: true, force: true });
|
|
732
|
+
await fs.promises.mkdir(cacheDirectory, { recursive: true });
|
|
733
|
+
const extension = isWindows ? "zip" : "tar.gz";
|
|
734
|
+
const archiveUrl = `${BINARY_URL_BASE}/${version}/${archiveName}.${extension}`;
|
|
735
|
+
console.log(`${DEV_PREFIX} Downloading dev server v${version}...`);
|
|
736
|
+
const { ok: ok4, statusCode, body } = await nativeGet(archiveUrl);
|
|
737
|
+
if (!ok4) {
|
|
738
|
+
throw new Error(`[QStash Dev] Failed to download binary: HTTP ${statusCode}`);
|
|
739
|
+
}
|
|
740
|
+
const archivePath = `${cacheDirectory}/${archiveName}.${extension}`;
|
|
741
|
+
await fs.promises.writeFile(archivePath, new Uint8Array(body));
|
|
742
|
+
childProcess.execFileSync("tar", ["-xf", archivePath, "-C", cacheDirectory], {
|
|
743
|
+
stdio: "pipe"
|
|
744
|
+
});
|
|
745
|
+
if (!isWindows) {
|
|
746
|
+
const EXECUTABLE_PERMISSION = 493;
|
|
747
|
+
await fs.promises.chmod(binaryPath, EXECUTABLE_PERMISSION);
|
|
748
|
+
}
|
|
749
|
+
await fs.promises.writeFile(versionFile, version);
|
|
750
|
+
await fs.promises.unlink(archivePath).catch(() => {
|
|
751
|
+
});
|
|
752
|
+
return binaryPath;
|
|
753
|
+
};
|
|
754
|
+
|
|
755
|
+
// src/dev-server/process.ts
|
|
756
|
+
var STARTUP_TIMEOUT_MS = 3e4;
|
|
757
|
+
var _proc = () => {
|
|
758
|
+
return globalThis["process"] ?? {};
|
|
759
|
+
};
|
|
760
|
+
var spawnServer = async (binaryPath, port, onUnexpectedExit) => {
|
|
761
|
+
const childProcess = await importChildProcess();
|
|
762
|
+
const child = await new Promise((resolve, reject) => {
|
|
763
|
+
const child2 = childProcess.spawn(binaryPath, ["dev", "--port", String(port)], {
|
|
764
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
765
|
+
});
|
|
766
|
+
const timeout = setTimeout(() => {
|
|
767
|
+
child2.kill();
|
|
768
|
+
reject(new Error("[QStash Dev] Server failed to start within 30 seconds"));
|
|
769
|
+
}, STARTUP_TIMEOUT_MS);
|
|
770
|
+
let startupOutput = "";
|
|
771
|
+
let started = false;
|
|
772
|
+
const bufferLine = (line) => {
|
|
773
|
+
if (!started)
|
|
774
|
+
startupOutput += `${line}
|
|
775
|
+
`;
|
|
776
|
+
};
|
|
777
|
+
forwardWithPrefix(child2.stdout, _proc().stdout, (line) => {
|
|
778
|
+
bufferLine(line);
|
|
779
|
+
if (!started && /runn+ing( at|\.)/i.test(line)) {
|
|
780
|
+
clearTimeout(timeout);
|
|
781
|
+
started = true;
|
|
782
|
+
resolve(child2);
|
|
783
|
+
}
|
|
784
|
+
});
|
|
785
|
+
forwardWithPrefix(child2.stderr, _proc().stderr, bufferLine);
|
|
786
|
+
child2.on("error", (error) => {
|
|
787
|
+
clearTimeout(timeout);
|
|
788
|
+
reject(new Error(`[QStash Dev] Failed to start server: ${error.message}`));
|
|
789
|
+
});
|
|
790
|
+
child2.on("close", (code, _signal) => {
|
|
791
|
+
if (started) {
|
|
792
|
+
onUnexpectedExit?.();
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
clearTimeout(timeout);
|
|
796
|
+
reject(new Error(formatStartupError(code, startupOutput)));
|
|
797
|
+
});
|
|
798
|
+
});
|
|
799
|
+
registerCleanup(child);
|
|
800
|
+
child.unref?.();
|
|
801
|
+
child.stdout?.unref?.();
|
|
802
|
+
child.stderr?.unref?.();
|
|
803
|
+
};
|
|
804
|
+
var formatStartupError = (code, startupOutput) => {
|
|
805
|
+
const cleaned = startupOutput.replaceAll(/\u001B\[[\d;]*m/g, "").replaceAll(/^\d{1,2}:\d{2}(AM|PM)\s+\w{3}\s+/gm, "").trim();
|
|
806
|
+
if (/address already in use/i.test(cleaned)) {
|
|
807
|
+
const match = /:(\d+)\s*$/.exec(cleaned);
|
|
808
|
+
const portHint = match ? ` on port ${match[1]}` : "";
|
|
809
|
+
return `[QStash Dev] Port already in use${portHint}. Set QSTASH_DEV_PORT to use a different port, or stop the process holding it.`;
|
|
810
|
+
}
|
|
811
|
+
const codeSuffix = code ? ` with code ${code}` : "";
|
|
812
|
+
const detail = cleaned ? `: ${cleaned}` : "";
|
|
813
|
+
return `[QStash Dev] Server exited unexpectedly${codeSuffix}${detail}`;
|
|
814
|
+
};
|
|
815
|
+
var forwardWithPrefix = (source, destination, onLine) => {
|
|
816
|
+
if (!source)
|
|
817
|
+
return;
|
|
818
|
+
let buffer = "";
|
|
819
|
+
const flushLine = (line) => {
|
|
820
|
+
destination?.write(`${CLI_PREFIX} ${line}
|
|
821
|
+
`);
|
|
822
|
+
onLine(line);
|
|
823
|
+
};
|
|
824
|
+
source.on("data", (data) => {
|
|
825
|
+
buffer += data.toString();
|
|
826
|
+
let newlineIndex = buffer.indexOf("\n");
|
|
827
|
+
while (newlineIndex !== -1) {
|
|
828
|
+
flushLine(buffer.slice(0, newlineIndex));
|
|
829
|
+
buffer = buffer.slice(newlineIndex + 1);
|
|
830
|
+
newlineIndex = buffer.indexOf("\n");
|
|
831
|
+
}
|
|
832
|
+
});
|
|
833
|
+
source.on("end", () => {
|
|
834
|
+
if (buffer.length > 0) {
|
|
835
|
+
flushLine(buffer);
|
|
836
|
+
buffer = "";
|
|
837
|
+
}
|
|
838
|
+
});
|
|
839
|
+
source.on("error", () => {
|
|
840
|
+
});
|
|
841
|
+
};
|
|
842
|
+
var currentChild;
|
|
843
|
+
var processHandlersRegistered = false;
|
|
844
|
+
var killCurrentChild = () => {
|
|
845
|
+
if (!currentChild)
|
|
846
|
+
return;
|
|
847
|
+
try {
|
|
848
|
+
currentChild.kill("SIGTERM");
|
|
849
|
+
} catch {
|
|
850
|
+
}
|
|
851
|
+
currentChild = void 0;
|
|
852
|
+
};
|
|
853
|
+
var registerCleanup = (child) => {
|
|
854
|
+
currentChild = child;
|
|
855
|
+
if (!processHandlersRegistered) {
|
|
856
|
+
processHandlersRegistered = true;
|
|
857
|
+
const proc = _proc();
|
|
858
|
+
proc.on?.("exit", killCurrentChild);
|
|
859
|
+
proc.on?.("SIGINT", () => {
|
|
860
|
+
killCurrentChild();
|
|
861
|
+
proc.exit?.(0);
|
|
862
|
+
});
|
|
863
|
+
proc.on?.("SIGTERM", () => {
|
|
864
|
+
killCurrentChild();
|
|
865
|
+
proc.exit?.(0);
|
|
866
|
+
});
|
|
867
|
+
}
|
|
868
|
+
};
|
|
869
|
+
|
|
870
|
+
// src/dev-server/index.ts
|
|
871
|
+
var _processGlobal2 = () => {
|
|
872
|
+
const proc = globalThis["process"];
|
|
873
|
+
return proc;
|
|
874
|
+
};
|
|
875
|
+
var devServerPromise;
|
|
876
|
+
var ensureDevelopmentServer = (env, devMode) => {
|
|
877
|
+
if (!shouldUseDevelopmentMode(devMode, env))
|
|
878
|
+
return Promise.resolve();
|
|
879
|
+
const procEnv = _processGlobal2()?.env;
|
|
880
|
+
if (procEnv?.NEXT_PHASE === "phase-production-build")
|
|
881
|
+
return Promise.resolve();
|
|
882
|
+
if (procEnv?.NODE_ENV === "production")
|
|
883
|
+
return Promise.resolve();
|
|
884
|
+
const runtime = getRuntime2();
|
|
885
|
+
if (runtime !== "nodejs") {
|
|
886
|
+
return checkDevServerReachable(getDevUrl(env), runtime);
|
|
887
|
+
}
|
|
888
|
+
if (!devServerPromise) {
|
|
889
|
+
devServerPromise = startPipeline(env).catch((error) => {
|
|
890
|
+
devServerPromise = void 0;
|
|
891
|
+
throw error;
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
return devServerPromise;
|
|
895
|
+
};
|
|
896
|
+
var startPipeline = async (env) => {
|
|
897
|
+
const baseUrl = getDevUrl(env);
|
|
898
|
+
const port = new URL(baseUrl).port;
|
|
899
|
+
const consoleLink = `\x1B[36m${CONSOLE_URL}?port=${port}\x1B[0m`;
|
|
900
|
+
if (await isDevServerRunning(baseUrl)) {
|
|
901
|
+
console.log(
|
|
902
|
+
`${DEV_PREFIX} Server already running at ${baseUrl}
|
|
903
|
+
${DEV_PREFIX} Console: ${consoleLink}`
|
|
904
|
+
);
|
|
905
|
+
return;
|
|
906
|
+
}
|
|
907
|
+
const binaryPath = await ensureBinary();
|
|
908
|
+
await spawnServer(binaryPath, port, () => {
|
|
909
|
+
devServerPromise = void 0;
|
|
910
|
+
});
|
|
911
|
+
};
|
|
912
|
+
var shouldUseDevelopmentMode = (devMode, env) => {
|
|
913
|
+
if (devMode !== void 0)
|
|
914
|
+
return devMode;
|
|
915
|
+
const value = env?.QSTASH_DEV ?? getProcessEnvironment("QSTASH_DEV");
|
|
916
|
+
if (value === void 0 || value === "" || value === "false" || value === "0")
|
|
917
|
+
return false;
|
|
918
|
+
if (value === "true" || value === "1")
|
|
919
|
+
return true;
|
|
920
|
+
throw new Error(`[QStash Dev] Invalid value for QSTASH_DEV in environment: ${value}`);
|
|
921
|
+
};
|
|
922
|
+
var getDevelopmentCredentials = (env) => {
|
|
923
|
+
return {
|
|
924
|
+
...DEV_CREDENTIALS,
|
|
925
|
+
baseUrl: getDevUrl(env)
|
|
926
|
+
};
|
|
927
|
+
};
|
|
928
|
+
var getDevUrl = (env) => {
|
|
929
|
+
const portString = env?.QSTASH_DEV_PORT ?? getProcessEnvironment("QSTASH_DEV_PORT");
|
|
930
|
+
let port = DEFAULT_DEV_PORT;
|
|
931
|
+
if (portString) {
|
|
932
|
+
const parsed = Number.parseInt(portString, 10);
|
|
933
|
+
if (!Number.isNaN(parsed) && parsed > 0) {
|
|
934
|
+
port = parsed;
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
return `http://127.0.0.1:${port}`;
|
|
938
|
+
};
|
|
939
|
+
var getRuntime2 = () => {
|
|
940
|
+
if (typeof navigator !== "undefined" && navigator.userAgent === "Cloudflare-Workers") {
|
|
941
|
+
return "cloudflare-workers";
|
|
942
|
+
}
|
|
943
|
+
const proc = _processGlobal2();
|
|
944
|
+
if (!proc) {
|
|
945
|
+
return "browser";
|
|
946
|
+
}
|
|
947
|
+
if (!proc.release?.name) {
|
|
948
|
+
return "edge";
|
|
949
|
+
}
|
|
950
|
+
return "nodejs";
|
|
951
|
+
};
|
|
952
|
+
var getProcessEnvironment = (key) => {
|
|
953
|
+
const proc = _processGlobal2();
|
|
954
|
+
return proc?.env ? proc.env[key] : void 0;
|
|
955
|
+
};
|
|
956
|
+
|
|
520
957
|
// src/client/multi-region/incoming.ts
|
|
521
958
|
var getReceiverSigningKeys = ({
|
|
522
959
|
environment,
|
|
523
960
|
regionFromHeader,
|
|
524
|
-
config
|
|
961
|
+
config,
|
|
962
|
+
devMode
|
|
525
963
|
}) => {
|
|
964
|
+
if (shouldUseDevelopmentMode(devMode, environment)) {
|
|
965
|
+
if (config?.currentSigningKey || config?.nextSigningKey) {
|
|
966
|
+
console.warn(
|
|
967
|
+
`${DEV_PREFIX} Dev mode is active. Ignoring signing keys from config. Set devMode: false to use your own keys.`
|
|
968
|
+
);
|
|
969
|
+
}
|
|
970
|
+
const developmentCreds = getDevelopmentCredentials(environment);
|
|
971
|
+
return {
|
|
972
|
+
currentSigningKey: developmentCreds.currentSigningKey,
|
|
973
|
+
nextSigningKey: developmentCreds.nextSigningKey
|
|
974
|
+
};
|
|
975
|
+
}
|
|
526
976
|
if (config?.currentSigningKey && config.nextSigningKey) {
|
|
527
977
|
return {
|
|
528
978
|
currentSigningKey: config.currentSigningKey,
|
|
@@ -567,8 +1017,21 @@ var getClientCredentials = (clientCredentialConfig) => {
|
|
|
567
1017
|
};
|
|
568
1018
|
var resolveCredentials = ({
|
|
569
1019
|
environment,
|
|
570
|
-
config
|
|
1020
|
+
config,
|
|
1021
|
+
devMode
|
|
571
1022
|
}) => {
|
|
1023
|
+
if (shouldUseDevelopmentMode(devMode, environment)) {
|
|
1024
|
+
if (config?.baseUrl || config?.token) {
|
|
1025
|
+
console.warn(
|
|
1026
|
+
`${DEV_PREFIX} Dev mode is active. Ignoring baseUrl/token from config. Set devMode: false to use your own credentials.`
|
|
1027
|
+
);
|
|
1028
|
+
}
|
|
1029
|
+
const developmentCreds = getDevelopmentCredentials(environment);
|
|
1030
|
+
return {
|
|
1031
|
+
baseUrl: developmentCreds.baseUrl,
|
|
1032
|
+
token: developmentCreds.token
|
|
1033
|
+
};
|
|
1034
|
+
}
|
|
572
1035
|
if (config?.baseUrl && config.token) {
|
|
573
1036
|
return {
|
|
574
1037
|
baseUrl: config.baseUrl,
|
|
@@ -621,9 +1084,11 @@ var SignatureError = class extends Error {
|
|
|
621
1084
|
var Receiver = class {
|
|
622
1085
|
currentSigningKey;
|
|
623
1086
|
nextSigningKey;
|
|
1087
|
+
devMode;
|
|
624
1088
|
constructor(config) {
|
|
625
1089
|
this.currentSigningKey = config?.currentSigningKey;
|
|
626
1090
|
this.nextSigningKey = config?.nextSigningKey;
|
|
1091
|
+
this.devMode = config?.devMode;
|
|
627
1092
|
}
|
|
628
1093
|
/**
|
|
629
1094
|
* Verify the signature of a request.
|
|
@@ -642,7 +1107,8 @@ var Receiver = class {
|
|
|
642
1107
|
config: {
|
|
643
1108
|
currentSigningKey: this.currentSigningKey,
|
|
644
1109
|
nextSigningKey: this.nextSigningKey
|
|
645
|
-
}
|
|
1110
|
+
},
|
|
1111
|
+
devMode: this.devMode
|
|
646
1112
|
});
|
|
647
1113
|
if (!signingKeys) {
|
|
648
1114
|
throw new Error(
|
|
@@ -908,12 +1374,14 @@ var HttpClient = class {
|
|
|
908
1374
|
baseUrl;
|
|
909
1375
|
authorization;
|
|
910
1376
|
options;
|
|
1377
|
+
devMode;
|
|
911
1378
|
retry;
|
|
912
1379
|
headers;
|
|
913
1380
|
telemetryHeaders;
|
|
914
1381
|
constructor(config) {
|
|
915
1382
|
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
916
1383
|
this.authorization = config.authorization;
|
|
1384
|
+
this.devMode = config.devMode;
|
|
917
1385
|
this.retry = // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
918
1386
|
typeof config.retry === "boolean" && !config.retry ? {
|
|
919
1387
|
attempts: 1,
|
|
@@ -926,6 +1394,7 @@ var HttpClient = class {
|
|
|
926
1394
|
this.telemetryHeaders = config.telemetryHeaders;
|
|
927
1395
|
}
|
|
928
1396
|
async request(request) {
|
|
1397
|
+
await ensureDevelopmentServer(void 0, this.devMode);
|
|
929
1398
|
const { response } = await this.requestWithBackoff(request);
|
|
930
1399
|
if (request.parseResponseAsJson === false) {
|
|
931
1400
|
return void 0;
|
|
@@ -933,6 +1402,7 @@ var HttpClient = class {
|
|
|
933
1402
|
return await response.json();
|
|
934
1403
|
}
|
|
935
1404
|
async *requestStream(request) {
|
|
1405
|
+
await ensureDevelopmentServer(void 0, this.devMode);
|
|
936
1406
|
const { response } = await this.requestWithBackoff(request);
|
|
937
1407
|
if (!response.body) {
|
|
938
1408
|
throw new Error("No response body");
|
|
@@ -1655,7 +2125,7 @@ var UrlGroups = class {
|
|
|
1655
2125
|
};
|
|
1656
2126
|
|
|
1657
2127
|
// version.ts
|
|
1658
|
-
var VERSION = "2.
|
|
2128
|
+
var VERSION = "2.11.1";
|
|
1659
2129
|
|
|
1660
2130
|
// src/client/client.ts
|
|
1661
2131
|
var Client = class {
|
|
@@ -1663,7 +2133,14 @@ var Client = class {
|
|
|
1663
2133
|
token;
|
|
1664
2134
|
constructor(config) {
|
|
1665
2135
|
const environment = getSafeEnvironment();
|
|
1666
|
-
const { baseUrl, token } = getClientCredentials({
|
|
2136
|
+
const { baseUrl, token } = getClientCredentials({
|
|
2137
|
+
environment,
|
|
2138
|
+
config,
|
|
2139
|
+
devMode: config?.devMode
|
|
2140
|
+
});
|
|
2141
|
+
if (shouldUseDevelopmentMode(config?.devMode, environment)) {
|
|
2142
|
+
void ensureDevelopmentServer(environment, config?.devMode);
|
|
2143
|
+
}
|
|
1667
2144
|
const enableTelemetry = environment.UPSTASH_DISABLE_TELEMETRY ? false : config?.enableTelemetry ?? true;
|
|
1668
2145
|
const isCloudflare = typeof caches !== "undefined" && "default" in caches;
|
|
1669
2146
|
const telemetryHeaders = new Headers(
|
|
@@ -1680,7 +2157,8 @@ var Client = class {
|
|
|
1680
2157
|
//@ts-expect-error caused by undici and bunjs type overlap
|
|
1681
2158
|
headers: prefixHeaders(new Headers(config?.headers ?? {})),
|
|
1682
2159
|
//@ts-expect-error caused by undici and bunjs type overlap
|
|
1683
|
-
telemetryHeaders
|
|
2160
|
+
telemetryHeaders,
|
|
2161
|
+
devMode: config?.devMode
|
|
1684
2162
|
});
|
|
1685
2163
|
this.token = token;
|
|
1686
2164
|
}
|