@crvouga/mockingbird-service-twilio 3.1.0 → 3.3.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.
@@ -0,0 +1,97 @@
1
+ // ../../http/provider/dist/vendor/core/crypto.js
2
+ import { hmac } from "@noble/hashes/hmac.js";
3
+ import { sha1 } from "@noble/hashes/legacy.js";
4
+ import { md5 } from "@noble/hashes/legacy.js";
5
+ import { sha256 } from "@noble/hashes/sha2.js";
6
+ import { Buffer } from "buffer";
7
+ var digest = (algorithm) => {
8
+ if (algorithm === "sha256")
9
+ return sha256;
10
+ if (algorithm === "sha1")
11
+ return sha1;
12
+ if (algorithm === "md5")
13
+ return md5;
14
+ throw new Error(`Unsupported digest ${algorithm}`);
15
+ };
16
+ var bytes = (input) => typeof input === "string" ? new TextEncoder().encode(input) : input;
17
+ function createHash(algorithm) {
18
+ const parts = [];
19
+ const hash = {
20
+ update(input) {
21
+ parts.push(bytes(input));
22
+ return hash;
23
+ },
24
+ digest(encoding) {
25
+ const result = Buffer.from(digest(algorithm)(Buffer.concat(parts)));
26
+ return encoding === "base64url" ? result.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "") : encoding ? result.toString(encoding) : result;
27
+ }
28
+ };
29
+ return hash;
30
+ }
31
+ function createHmac(algorithm, key) {
32
+ const parts = [];
33
+ const hash = {
34
+ update(input) {
35
+ parts.push(bytes(input));
36
+ return hash;
37
+ },
38
+ digest(encoding) {
39
+ const result = Buffer.from(hmac(digest(algorithm), bytes(key), Buffer.concat(parts)));
40
+ return encoding === "base64url" ? result.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "") : encoding ? result.toString(encoding) : result;
41
+ }
42
+ };
43
+ return hash;
44
+ }
45
+ var source;
46
+ function useRandom(next) {
47
+ source = next;
48
+ }
49
+ function withRandom(next, run) {
50
+ const previous = source;
51
+ source = next;
52
+ try {
53
+ return run();
54
+ } finally {
55
+ source = previous;
56
+ }
57
+ }
58
+ function random() {
59
+ return source ? source() : Math.random();
60
+ }
61
+ function randomBytes(length) {
62
+ if (!source)
63
+ return Buffer.from(crypto.getRandomValues(new Uint8Array(length)));
64
+ const out = new Uint8Array(length);
65
+ for (let i = 0; i < length; i++)
66
+ out[i] = Math.floor(source() * 256);
67
+ return Buffer.from(out);
68
+ }
69
+ function randomUUID() {
70
+ if (!source)
71
+ return crypto.randomUUID();
72
+ const b = randomBytes(16);
73
+ b[6] = b[6] & 15 | 64;
74
+ b[8] = b[8] & 63 | 128;
75
+ const hex = b.toString("hex");
76
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
77
+ }
78
+ function timingSafeEqual(a, b) {
79
+ if (a.length !== b.length)
80
+ throw new Error("Buffers must have equal lengths");
81
+ let difference = 0;
82
+ for (let i = 0; i < a.length; i++)
83
+ difference |= a[i] ^ b[i];
84
+ return difference === 0;
85
+ }
86
+
87
+ export {
88
+ createHash,
89
+ createHmac,
90
+ useRandom,
91
+ withRandom,
92
+ random,
93
+ randomBytes,
94
+ randomUUID,
95
+ timingSafeEqual
96
+ };
97
+ //# sourceMappingURL=chunk-6Z2MR3PO.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../http/provider/src/vendor/core/crypto.ts"],
4
+ "sourcesContent": ["import { hmac } from \"@noble/hashes/hmac.js\"\nimport { sha1 } from \"@noble/hashes/legacy.js\"\nimport { md5 } from \"@noble/hashes/legacy.js\"\nimport { sha256 } from \"@noble/hashes/sha2.js\"\nimport { Buffer } from \"buffer\"\n\nconst digest = (algorithm: string) => {\n if (algorithm === \"sha256\") return sha256\n if (algorithm === \"sha1\") return sha1\n if (algorithm === \"md5\") return md5\n throw new Error(`Unsupported digest ${algorithm}`)\n}\nconst bytes = (input: string | Uint8Array) => typeof input === \"string\" ? new TextEncoder().encode(input) : input\ninterface Hash {\n update(input: string | Uint8Array): Hash\n digest(): Buffer\n digest(encoding: string): string\n}\nexport function createHash(algorithm: string): Hash {\n const parts: Uint8Array[] = []\n const hash = {\n update(input: string | Uint8Array) { parts.push(bytes(input)); return hash },\n digest(encoding?: string): Buffer | string {\n const result = Buffer.from(digest(algorithm)(Buffer.concat(parts)))\n return encoding === \"base64url\" ? result.toString(\"base64\").replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\") : encoding ? result.toString(encoding as BufferEncoding) : result\n },\n }\n return hash as Hash\n}\nexport function createHmac(algorithm: string, key: string | Uint8Array): Hash {\n const parts: Uint8Array[] = []\n const hash = {\n update(input: string | Uint8Array) { parts.push(bytes(input)); return hash },\n digest(encoding?: string): Buffer | string {\n const result = Buffer.from(hmac(digest(algorithm), bytes(key), Buffer.concat(parts)))\n return encoding === \"base64url\" ? result.toString(\"base64\").replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\") : encoding ? result.toString(encoding as BufferEncoding) : result\n },\n }\n return hash as Hash\n}\n/**\n * Mockingbird: where ids and tokens come from. With a seeded stream in place, everything the\n * vendor code mints replays from the seed; without one it is the platform's own randomness.\n */\nlet source: (() => number) | undefined\n/** Mint from `next` (a seeded stream of `[0, 1)`) until told otherwise. */\nexport function useRandom(next: (() => number) | undefined): void { source = next }\n/** Mint from `next` for one synchronous section, then put the previous source back. */\nexport function withRandom<T>(next: (() => number) | undefined, run: () => T): T {\n const previous = source\n source = next\n try { return run() } finally { source = previous }\n}\n/** `Math.random`, from the seeded stream when one is in place. */\nexport function random(): number { return source ? source() : Math.random() }\nexport function randomBytes(length: number): Buffer {\n if (!source) return Buffer.from(crypto.getRandomValues(new Uint8Array(length)))\n const out = new Uint8Array(length)\n for (let i = 0; i < length; i++) out[i] = Math.floor(source() * 256)\n return Buffer.from(out)\n}\nexport function randomUUID(): string {\n if (!source) return crypto.randomUUID()\n const b = randomBytes(16)\n b[6] = (b[6] & 0x0f) | 0x40\n b[8] = (b[8] & 0x3f) | 0x80\n const hex = b.toString(\"hex\")\n return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`\n}\nexport function timingSafeEqual(a: Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) throw new Error(\"Buffers must have equal lengths\")\n let difference = 0\n for (let i = 0; i < a.length; i++) difference |= a[i] ^ b[i]\n return difference === 0\n}\n"],
5
+ "mappings": "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",
6
+ "names": []
7
+ }
@@ -1,9 +1,12 @@
1
1
  import {
2
2
  createClock,
3
3
  createRuntime,
4
+ normalizeBootControls,
4
5
  parseDuration,
5
- resolveAdminPrefix
6
- } from "./chunk-BNNWT54B.js";
6
+ parseFaultHeader,
7
+ resolveAdminPrefix,
8
+ restoreClock
9
+ } from "./chunk-55BRX56F.js";
7
10
 
8
11
  // ../../adapters/node/dist/cli.js
9
12
  import { readFile as readFile2 } from "node:fs/promises";
@@ -50,6 +53,8 @@ var serve = async (api, options = {}) => {
50
53
  req.socket.destroy();
51
54
  return;
52
55
  }
56
+ if (aborted.signal.aborted)
57
+ return;
53
58
  res.writeHead(500, { "content-type": "application/json" });
54
59
  res.end(JSON.stringify({
55
60
  error: {
@@ -81,6 +86,7 @@ var serve = async (api, options = {}) => {
81
86
  }
82
87
  res.end();
83
88
  } catch {
89
+ await new Promise((resolve2) => setImmediate(resolve2));
84
90
  res.destroy();
85
91
  } finally {
86
92
  reader.releaseLock();
@@ -163,10 +169,12 @@ var httpChild = async (target, entry, options) => {
163
169
  adminPrefix: resolveAdminPrefix(entry.adminPrefix),
164
170
  adminKey: entry.adminKey,
165
171
  seed: entry.seed,
166
- onLog: options.onLog
172
+ onLog: options.onLog,
173
+ ...entry.adminControls !== void 0 ? { adminControls: entry.adminControls } : {},
174
+ ...entry.fixtures !== void 0 ? { fixtures: entry.fixtures } : {},
175
+ ...entry.baseUrl !== void 0 ? { baseUrl: entry.baseUrl } : {}
167
176
  });
168
177
  const adminPrefix = resolveAdminPrefix(entry.adminPrefix);
169
- runtime.isolateNamespaces();
170
178
  const locked = /* @__PURE__ */ new Set();
171
179
  const active = /* @__PURE__ */ new Map();
172
180
  const api = {
@@ -428,19 +436,12 @@ async function startFleet(config, options) {
428
436
  return json(400, { error: "freeze must be boolean" });
429
437
  const response2 = await transaction(namespace, selected, async (_name, child) => {
430
438
  const childClock = child.clock(namespace);
431
- childClock.freeze();
432
- childClock.set(target);
433
- if (!frozen)
434
- childClock.unfreeze();
439
+ restoreClock(childClock, { now: target, frozen });
435
440
  await child.settle?.(namespace);
436
441
  return childClock.state();
437
442
  });
438
- if (response2.ok) {
439
- current.freeze();
440
- current.set(target);
441
- if (!frozen)
442
- current.unfreeze();
443
- }
443
+ if (response2.ok)
444
+ restoreClock(current, { now: target, frozen });
444
445
  return response2;
445
446
  }
446
447
  if (!route)
@@ -459,13 +460,8 @@ async function startFleet(config, options) {
459
460
  return json(404, { error: "no snapshot in this namespace" });
460
461
  const restored = new Map([...point.values].map(([name]) => [name, children.get(name)]));
461
462
  const response2 = await transaction(namespace, restored, async (name, child) => child.restore(namespace, point.values.get(name)));
462
- if (response2.ok) {
463
- const current = clock(namespace);
464
- current.freeze();
465
- current.set(point.clock.now);
466
- if (!point.clock.frozen)
467
- current.unfreeze();
468
- }
463
+ if (response2.ok)
464
+ restoreClock(clock(namespace), point.clock);
469
465
  return response2;
470
466
  }
471
467
  const snapshotId = randomUUID();
@@ -491,6 +487,8 @@ async function startFleet(config, options) {
491
487
  for (const [name, entry] of Object.entries(config.services)) {
492
488
  if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(name))
493
489
  throw new Error("invalid service name");
490
+ if (config.adminControls !== void 0 || entry.adminControls !== void 0)
491
+ normalizeBootControls({ ...config.adminControls, ...entry.adminControls }, `services.${name}.adminControls`);
494
492
  try {
495
493
  const target = await options.load(name);
496
494
  if (entry.protocol && entry.protocol !== ("protocol" in target ? target.protocol : "http"))
@@ -499,7 +497,9 @@ async function startFleet(config, options) {
499
497
  const child = "start" in target ? await target.start(entry) : await httpChild(target, {
500
498
  ...entry,
501
499
  adminPrefix: resolveAdminPrefix(entry.adminPrefix ?? adminPrefix),
502
- ...adminKey !== void 0 ? { adminKey } : {}
500
+ ...adminKey !== void 0 ? { adminKey } : {},
501
+ // Fleet-wide controls, with the service's own keys replacing them.
502
+ ...config.adminControls !== void 0 || entry.adminControls !== void 0 ? { adminControls: { ...config.adminControls, ...entry.adminControls } } : {}
503
503
  }, options);
504
504
  children.set(name, child);
505
505
  if (!await child.ready())
@@ -632,7 +632,51 @@ var COMMON_SERVE_OPTIONS = {
632
632
  value: "<key>",
633
633
  description: "Require x-mockingbird-admin-key on /__admin/* (env MOCKINGBIRD_ADMIN_KEY)"
634
634
  },
635
- seed: { type: "string", value: "<seed>", description: "Seed for every random choice" },
635
+ seed: {
636
+ type: "string",
637
+ value: "<seed>",
638
+ description: "Seed for every random choice (env MOCKINGBIRD_SEED)"
639
+ },
640
+ "admin-controls": {
641
+ type: "string",
642
+ value: "<json|file>",
643
+ description: "Admin controls to boot with, as JSON or a JSON file: clock, latency, faults, snapshot, namespaces (env MOCKINGBIRD_ADMIN_CONTROLS)"
644
+ },
645
+ clock: {
646
+ type: "string",
647
+ value: "<instant>",
648
+ description: "Start the clock at this instant (epoch ms or ISO-8601)"
649
+ },
650
+ freeze: { type: "boolean", description: "Freeze the clock: it moves only when told to" },
651
+ "auto-advance": {
652
+ type: "string",
653
+ value: "<duration>",
654
+ description: "Step the clock this much before every request (e.g. 1s)"
655
+ },
656
+ latency: {
657
+ type: "string",
658
+ value: "<duration>",
659
+ description: "Baseline response time for every request (e.g. 250ms)"
660
+ },
661
+ jitter: {
662
+ type: "string",
663
+ value: "<duration>",
664
+ description: "Seeded extra latency between 0 and this"
665
+ },
666
+ "virtual-time": {
667
+ type: "boolean",
668
+ description: "Spend latency, delays and timeouts on the mock clock instead of really waiting"
669
+ },
670
+ fault: {
671
+ type: "string",
672
+ value: "<fault>",
673
+ description: 'A fault to boot with, as in x-mockingbird-fault: 503, rate_limited, "status=503; delay=2s"'
674
+ },
675
+ snapshot: {
676
+ type: "string",
677
+ value: "<file>",
678
+ description: "Start from a snapshot document (GET /__admin/snapshots/:id)"
679
+ },
636
680
  log: {
637
681
  type: "string",
638
682
  value: "<pretty|json|off>",
@@ -679,6 +723,68 @@ var formatLog = (format) => {
679
723
  };
680
724
  };
681
725
  var asString = (value) => typeof value === "string" ? value : void 0;
726
+ var readJsonFile = async (path, label) => {
727
+ try {
728
+ return JSON.parse(await readFile2(path, "utf8"));
729
+ } catch (error) {
730
+ throw new Error(`${label}: cannot read ${path}: ${error instanceof Error ? error.message : error}`);
731
+ }
732
+ };
733
+ var isObject2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
734
+ var resolveServeControls = async (values, env = process.env, base) => {
735
+ const source = asString(values["admin-controls"]) ?? env.MOCKINGBIRD_ADMIN_CONTROLS;
736
+ let document = isObject2(base) ? { ...base } : {};
737
+ if (source !== void 0 && source.trim() !== "") {
738
+ let parsed;
739
+ if (source.trim().startsWith("{")) {
740
+ try {
741
+ parsed = JSON.parse(source);
742
+ } catch {
743
+ throw new Error("--admin-controls: not valid JSON");
744
+ }
745
+ } else
746
+ parsed = await readJsonFile(source, "--admin-controls");
747
+ if (!isObject2(parsed))
748
+ throw new Error("--admin-controls: expected a JSON object");
749
+ document = { ...document, ...parsed };
750
+ }
751
+ const clock = isObject2(document.clock) ? { ...document.clock } : {};
752
+ const now = asString(values.clock);
753
+ if (now !== void 0)
754
+ clock.now = now;
755
+ if (values.freeze === true)
756
+ clock.frozen = true;
757
+ const autoAdvance = asString(values["auto-advance"]);
758
+ if (autoAdvance !== void 0)
759
+ clock.autoAdvance = autoAdvance;
760
+ if (Object.keys(clock).length > 0)
761
+ document.clock = clock;
762
+ const delay = asString(values.latency);
763
+ const jitter = asString(values.jitter);
764
+ if (delay !== void 0 || jitter !== void 0) {
765
+ const latency = isObject2(document.latency) ? { ...document.latency } : document.latency !== void 0 ? { delay: document.latency } : {};
766
+ if (delay !== void 0)
767
+ latency.delay = delay;
768
+ if (jitter !== void 0)
769
+ latency.jitter = jitter;
770
+ document.latency = latency;
771
+ }
772
+ if (values["virtual-time"] === true)
773
+ document.virtualTime = true;
774
+ const fault = asString(values.fault);
775
+ if (fault !== void 0)
776
+ document.faults = [
777
+ ...Array.isArray(document.faults) ? document.faults : [],
778
+ parseFaultHeader(fault, "--fault")
779
+ ];
780
+ const snapshot = asString(values.snapshot);
781
+ if (snapshot !== void 0)
782
+ document.snapshot = await readJsonFile(snapshot, "--snapshot");
783
+ if (Object.keys(document).length === 0)
784
+ return void 0;
785
+ normalizeBootControls(document, "adminControls");
786
+ return document;
787
+ };
682
788
  var loadTarget = async (name, own) => {
683
789
  if (name === own.name)
684
790
  return own;
@@ -705,7 +811,8 @@ var start = async (target, values, config) => {
705
811
  adminPrefix,
706
812
  adminKey: config.adminKey,
707
813
  seed: config.seed,
708
- onLog: formatLog(config.log)
814
+ onLog: formatLog(config.log),
815
+ ...config.adminControls !== void 0 ? { adminControls: config.adminControls } : {}
709
816
  });
710
817
  const listening = await listen(runtime, { port: config.port, host: config.host });
711
818
  target.listening?.(listening);
@@ -745,6 +852,9 @@ var serveCommand = (target) => ({
745
852
  const adminKey2 = config.adminKey ?? asString(values["admin-key"]) ?? process.env.MOCKINGBIRD_ADMIN_KEY;
746
853
  if (adminKey2 !== void 0)
747
854
  config.adminKey = adminKey2;
855
+ const adminControls = await resolveServeControls(values, process.env, config.adminControls);
856
+ if (adminControls !== void 0)
857
+ config.adminControls = adminControls;
748
858
  const fleet = await startFleet(config, {
749
859
  load: (name) => loadTarget(name, target),
750
860
  onLog: formatLog(config.log ?? log),
@@ -770,10 +880,12 @@ var serveCommand = (target) => ({
770
880
  }
771
881
  const port = asString(values.port);
772
882
  const adminKey = asString(values["admin-key"]) ?? process.env.MOCKINGBIRD_ADMIN_KEY;
773
- const seed = asString(values.seed);
883
+ const seed = asString(values.seed) ?? process.env.MOCKINGBIRD_SEED;
774
884
  let listening;
775
885
  try {
886
+ const adminControls = await resolveServeControls(values);
776
887
  listening = await start(target, values, {
888
+ ...adminControls !== void 0 ? { adminControls } : {},
777
889
  adminPrefix: resolveAdminPrefix(asString(values["admin-prefix"]) ?? process.env.MOCKINGBIRD_ADMIN_PREFIX),
778
890
  port: port === void 0 ? target.defaultPort : Number.parseInt(port, 10),
779
891
  host: asString(values.host) ?? "127.0.0.1",
@@ -789,6 +901,56 @@ var serveCommand = (target) => ({
789
901
  }
790
902
  });
791
903
 
904
+ // ../../adapters/node/dist/fixtures.js
905
+ import { readFile as readFile3 } from "node:fs/promises";
906
+ var providerServeOptions = {
907
+ fixtures: {
908
+ type: "string",
909
+ value: "<json-file>",
910
+ description: "Load synthetic provider fixtures from a JSON object"
911
+ },
912
+ "base-url": {
913
+ type: "string",
914
+ value: "<url>",
915
+ description: "Public HTTP(S) base URL advertised in provider responses"
916
+ }
917
+ };
918
+ async function providerServeValues(values, defaults = {}) {
919
+ const options = {};
920
+ if (values.fixtures !== void 0) {
921
+ if (typeof values.fixtures !== "string")
922
+ throw new Error("--fixtures requires a JSON file");
923
+ let parsed;
924
+ try {
925
+ parsed = JSON.parse(await readFile3(values.fixtures, "utf8"));
926
+ } catch {
927
+ throw new Error("Cannot read --fixtures as JSON; supply a synthetic provider fixture object");
928
+ }
929
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed))
930
+ throw new Error("--fixtures must contain a JSON object");
931
+ options.fixtures = parsed;
932
+ } else if (defaults.fixtures !== void 0) {
933
+ if (defaults.fixtures === null || typeof defaults.fixtures !== "object" || Array.isArray(defaults.fixtures))
934
+ throw new Error("fleet fixtures must contain a JSON object");
935
+ options.fixtures = defaults.fixtures;
936
+ }
937
+ const advertised = values["base-url"] ?? defaults.baseUrl;
938
+ if (advertised !== void 0) {
939
+ let url;
940
+ try {
941
+ if (typeof advertised !== "string")
942
+ throw new Error();
943
+ url = new URL(advertised);
944
+ } catch {
945
+ throw new Error("--base-url must be an absolute HTTP(S) URL");
946
+ }
947
+ if (!["http:", "https:"].includes(url.protocol) || url.username || url.password || url.search || url.hash)
948
+ throw new Error("--base-url must be HTTP(S) without credentials, query or fragment");
949
+ options.baseUrl = url.href.replace(/\/+$/, "");
950
+ }
951
+ return options;
952
+ }
953
+
792
954
  // src/server.ts
793
955
  var DEFAULT_PORT = 8798;
794
956
  var createServer2 = async (options = {}) => {
@@ -805,6 +967,7 @@ var serveTarget = {
805
967
  name: "twilio",
806
968
  defaultPort: DEFAULT_PORT,
807
969
  options: {
970
+ ...providerServeOptions,
808
971
  "app-url": {
809
972
  type: "string",
810
973
  value: "<url>",
@@ -836,7 +999,7 @@ var serveTarget = {
836
999
  description: "Every Verify code is this (default: random 6 digits, read via /__admin)"
837
1000
  }
838
1001
  },
839
- create: (values, common) => {
1002
+ create: async (values, common) => {
840
1003
  const appUrl = text(values["app-url"]);
841
1004
  const accountSid = text(values["account-sid"]);
842
1005
  const authToken = text(values["auth-token"]);
@@ -845,6 +1008,7 @@ var serveTarget = {
845
1008
  const fixedCode = text(values["fixed-code"]);
846
1009
  if (appUrl && !authToken) throw new Error("--app-url needs --auth-token (the signing key)");
847
1010
  return createRuntime({
1011
+ ...await providerServeValues(values, common),
848
1012
  ...appUrl && authToken ? {
849
1013
  app: {
850
1014
  url: appUrl,
@@ -858,6 +1022,7 @@ var serveTarget = {
858
1022
  ...fixedCode ? { verify: { fixedCode } } : {},
859
1023
  ...common.adminPrefix !== void 0 ? { adminPrefix: common.adminPrefix } : {},
860
1024
  ...common.adminKey !== void 0 ? { adminKey: common.adminKey } : {},
1025
+ ...common.adminControls !== void 0 ? { adminControls: common.adminControls } : {},
861
1026
  ...common.seed !== void 0 ? { seed: common.seed } : {},
862
1027
  ...common.onLog ? { onLog: common.onLog } : {}
863
1028
  });
@@ -876,4 +1041,4 @@ export {
876
1041
  createServer2 as createServer,
877
1042
  serveTarget
878
1043
  };
879
- //# sourceMappingURL=chunk-JFINJ7VN.js.map
1044
+ //# sourceMappingURL=chunk-PTLAPOYJ.js.map