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