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