@crvouga/mockingbird-service-posthog 3.6.0 → 3.7.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/CHANGELOG.md +7 -1
- package/dist/{chunk-YTVQ24KD.js → chunk-2ZTMN4SX.js} +112 -28
- package/dist/chunk-2ZTMN4SX.js.map +7 -0
- package/dist/{chunk-GW65C4DF.js → chunk-E3VNLDYM.js} +103 -12
- package/dist/chunk-E3VNLDYM.js.map +7 -0
- package/dist/cli.js +2 -2
- package/dist/index.d.ts +28 -0
- package/dist/index.js +1 -1
- package/dist/server.d.ts +69 -0
- package/dist/server.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-GW65C4DF.js.map +0 -7
- package/dist/chunk-YTVQ24KD.js.map +0 -7
|
@@ -4,18 +4,32 @@ import {
|
|
|
4
4
|
createRuntime,
|
|
5
5
|
normalizeBootControls,
|
|
6
6
|
normalizeControls,
|
|
7
|
+
normalizeIdBase,
|
|
7
8
|
ownedTransport,
|
|
8
9
|
parseDuration,
|
|
9
10
|
parseFaultHeader,
|
|
10
11
|
resolveAdminPrefix,
|
|
11
12
|
restoreClock,
|
|
12
13
|
specsFromState
|
|
13
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-2ZTMN4SX.js";
|
|
14
15
|
|
|
15
16
|
// ../../adapters/node/dist/cli.js
|
|
16
17
|
import { readFile as readFile5 } from "node:fs/promises";
|
|
17
18
|
import { parseArgs } from "node:util";
|
|
18
19
|
|
|
20
|
+
// ../../adapters/node/dist/boot-settings.js
|
|
21
|
+
var checkSettings = (target, settings, label) => {
|
|
22
|
+
if (!target.parseSettings)
|
|
23
|
+
throw new Error(`${label}: ${target.name} takes no boot settings`);
|
|
24
|
+
try {
|
|
25
|
+
return target.parseSettings(settings);
|
|
26
|
+
} catch (error) {
|
|
27
|
+
throw new Error(`${label}: ${error instanceof Error ? error.message : String(error)}`, {
|
|
28
|
+
cause: error
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
19
33
|
// ../../adapters/node/dist/fleet.js
|
|
20
34
|
import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
|
|
21
35
|
import { createHash as createHash4, randomUUID as randomUUID4 } from "node:crypto";
|
|
@@ -2665,6 +2679,9 @@ var fleet_config_schema_default = {
|
|
|
2665
2679
|
adminControls: {
|
|
2666
2680
|
$ref: "#/$defs/controls"
|
|
2667
2681
|
},
|
|
2682
|
+
idBase: {
|
|
2683
|
+
$ref: "#/$defs/idBase"
|
|
2684
|
+
},
|
|
2668
2685
|
namespace: {
|
|
2669
2686
|
type: "string",
|
|
2670
2687
|
pattern: "^[A-Za-z0-9_.-]{1,64}$"
|
|
@@ -2754,6 +2771,12 @@ var fleet_config_schema_default = {
|
|
|
2754
2771
|
adminControls: {
|
|
2755
2772
|
$ref: "#/$defs/controls"
|
|
2756
2773
|
},
|
|
2774
|
+
idBase: {
|
|
2775
|
+
$ref: "#/$defs/idBase"
|
|
2776
|
+
},
|
|
2777
|
+
settings: {
|
|
2778
|
+
type: "object"
|
|
2779
|
+
},
|
|
2757
2780
|
fixtures: {
|
|
2758
2781
|
type: "object"
|
|
2759
2782
|
},
|
|
@@ -2800,6 +2823,18 @@ var fleet_config_schema_default = {
|
|
|
2800
2823
|
}
|
|
2801
2824
|
}
|
|
2802
2825
|
},
|
|
2826
|
+
idBase: {
|
|
2827
|
+
anyOf: [
|
|
2828
|
+
{
|
|
2829
|
+
type: "integer",
|
|
2830
|
+
minimum: 0
|
|
2831
|
+
},
|
|
2832
|
+
{
|
|
2833
|
+
type: "string",
|
|
2834
|
+
pattern: "^(boot|[0-9]+)$"
|
|
2835
|
+
}
|
|
2836
|
+
]
|
|
2837
|
+
},
|
|
2803
2838
|
controls: {
|
|
2804
2839
|
type: "object",
|
|
2805
2840
|
additionalProperties: false,
|
|
@@ -2949,6 +2984,8 @@ async function preflightFleet(config, options) {
|
|
|
2949
2984
|
throw new Error("protected archive policy requires a protected repository; configure its protector before startup");
|
|
2950
2985
|
resolveAdminPrefix(config.adminPrefix);
|
|
2951
2986
|
normalizeBootControls(config.adminControls);
|
|
2987
|
+
if (config.idBase !== void 0)
|
|
2988
|
+
normalizeIdBase(config.idBase, "idBase");
|
|
2952
2989
|
const targets = /* @__PURE__ */ new Map();
|
|
2953
2990
|
const ports = /* @__PURE__ */ new Set();
|
|
2954
2991
|
for (const [name, entry] of Object.entries(config.services)) {
|
|
@@ -2980,6 +3017,13 @@ async function preflightFleet(config, options) {
|
|
|
2980
3017
|
throw new Error("invalid protocol namespace selector");
|
|
2981
3018
|
}
|
|
2982
3019
|
}
|
|
3020
|
+
if (entry.idBase !== void 0)
|
|
3021
|
+
normalizeIdBase(entry.idBase, "idBase");
|
|
3022
|
+
if (entry.settings !== void 0) {
|
|
3023
|
+
if (protocol !== "http" || !("create" in target))
|
|
3024
|
+
throw new Error("settings: only HTTP services take boot settings");
|
|
3025
|
+
checkSettings(target, entry.settings, "settings");
|
|
3026
|
+
}
|
|
2983
3027
|
const port = entry.port ?? target.defaultPort;
|
|
2984
3028
|
if (port !== 0) {
|
|
2985
3029
|
const key = `${entry.host ?? "127.0.0.1"}:${port}`;
|
|
@@ -3015,7 +3059,7 @@ async function preflightFleet(config, options) {
|
|
|
3015
3059
|
break;
|
|
3016
3060
|
}
|
|
3017
3061
|
}
|
|
3018
|
-
targets.set(name, { ...target, packageVersion: packageVersion ?? "3.
|
|
3062
|
+
targets.set(name, { ...target, packageVersion: packageVersion ?? "3.7.0" });
|
|
3019
3063
|
} catch (error) {
|
|
3020
3064
|
throw new Error(`service ${name}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
3021
3065
|
}
|
|
@@ -3335,6 +3379,7 @@ var httpChild = async (target, entry, options, admission, generation, privateAcc
|
|
|
3335
3379
|
options.onLog?.(entry2);
|
|
3336
3380
|
},
|
|
3337
3381
|
...entry.adminControls !== void 0 ? { adminControls: entry.adminControls } : {},
|
|
3382
|
+
...entry.settings !== void 0 ? { settings: checkSettings(target, entry.settings, "settings") } : {},
|
|
3338
3383
|
...entry.fixtures !== void 0 ? { fixtures: entry.fixtures } : {},
|
|
3339
3384
|
...(advertisedHttpBase(entry) ?? entry.baseUrl) !== void 0 ? { baseUrl: advertisedHttpBase(entry) ?? entry.baseUrl } : {}
|
|
3340
3385
|
});
|
|
@@ -3353,6 +3398,8 @@ var httpChild = async (target, entry, options, admission, generation, privateAcc
|
|
|
3353
3398
|
].some((method) => typeof created[method] !== "function"))
|
|
3354
3399
|
throw new Error("HTTP target does not implement the fleet runtime protocol; build/install matching supported service versions");
|
|
3355
3400
|
const runtime = created;
|
|
3401
|
+
if (entry.idBase !== void 0)
|
|
3402
|
+
runtime.setIdBase?.(entry.idBase);
|
|
3356
3403
|
const unobserve = runtime.webhooks?.observeDeliveries(observer.delivery);
|
|
3357
3404
|
if (options.outbound && runtime.webhooks)
|
|
3358
3405
|
runtime.webhooks.setTransportPolicy(ownedTransport(options.outbound));
|
|
@@ -3951,6 +3998,7 @@ async function startFleet(config, options) {
|
|
|
3951
3998
|
...entry,
|
|
3952
3999
|
adminPrefix: resolveAdminPrefix(entry.adminPrefix ?? adminPrefix),
|
|
3953
4000
|
...adminKey !== void 0 ? { adminKey } : {},
|
|
4001
|
+
...(entry.idBase ?? config.idBase) !== void 0 ? { idBase: entry.idBase ?? config.idBase } : {},
|
|
3954
4002
|
// Fleet-wide controls, with the service's own keys replacing them.
|
|
3955
4003
|
...config.adminControls !== void 0 || entry.adminControls !== void 0 ? { adminControls: { ...config.adminControls, ...entry.adminControls } } : {}
|
|
3956
4004
|
}, options, (namespace, request) => management?.admit(namespace, request), (namespace) => management?.generation(namespace), (namespace, request) => management?.privateRequest(namespace, request) ?? false, {
|
|
@@ -4635,6 +4683,16 @@ var COMMON_SERVE_OPTIONS = {
|
|
|
4635
4683
|
value: "<seed>",
|
|
4636
4684
|
description: "Seed for every random choice (env MOCKINGBIRD_SEED)"
|
|
4637
4685
|
},
|
|
4686
|
+
"id-base": {
|
|
4687
|
+
type: "string",
|
|
4688
|
+
value: "<n|boot>",
|
|
4689
|
+
description: "Start generated ids at this base so a restart does not reissue the last boot's ids; boot derives one from the clock (env MOCKINGBIRD_ID_BASE; default 0, the same ids every boot)"
|
|
4690
|
+
},
|
|
4691
|
+
settings: {
|
|
4692
|
+
type: "string",
|
|
4693
|
+
value: "<json|file>",
|
|
4694
|
+
description: "Service settings to boot with, as JSON or a JSON file; every namespace starts from them (env MOCKINGBIRD_SETTINGS; only for services that declare settings)"
|
|
4695
|
+
},
|
|
4638
4696
|
"admin-controls": {
|
|
4639
4697
|
type: "string",
|
|
4640
4698
|
value: "<json|file>",
|
|
@@ -4729,19 +4787,40 @@ var readJsonFile = async (path, label) => {
|
|
|
4729
4787
|
}
|
|
4730
4788
|
};
|
|
4731
4789
|
var isObject2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4790
|
+
var readJsonOption = async (source, label) => {
|
|
4791
|
+
const trimmed = source.trim();
|
|
4792
|
+
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
4793
|
+
try {
|
|
4794
|
+
return JSON.parse(trimmed);
|
|
4795
|
+
} catch {
|
|
4796
|
+
throw new Error(`${label}: not valid JSON`);
|
|
4797
|
+
}
|
|
4798
|
+
}
|
|
4799
|
+
return readJsonFile(source, label);
|
|
4800
|
+
};
|
|
4801
|
+
var resolveServeIdBase = (values, env = process.env) => {
|
|
4802
|
+
const source = asString(values["id-base"]) ?? env.MOCKINGBIRD_ID_BASE;
|
|
4803
|
+
if (source === void 0 || source.trim() === "")
|
|
4804
|
+
return void 0;
|
|
4805
|
+
normalizeIdBase(source.trim(), "--id-base");
|
|
4806
|
+
return source.trim();
|
|
4807
|
+
};
|
|
4808
|
+
var resolveServeSettings = async (target, values, env = process.env) => {
|
|
4809
|
+
const flag = asString(values.settings);
|
|
4810
|
+
const source = flag ?? env.MOCKINGBIRD_SETTINGS;
|
|
4811
|
+
if (source === void 0 || source.trim() === "")
|
|
4812
|
+
return void 0;
|
|
4813
|
+
const label = flag !== void 0 ? "--settings" : "MOCKINGBIRD_SETTINGS";
|
|
4814
|
+
const parsed = await readJsonOption(source, label);
|
|
4815
|
+
if (!isObject2(parsed))
|
|
4816
|
+
throw new Error(`${label}: expected a JSON object`);
|
|
4817
|
+
return checkSettings(target, parsed, label);
|
|
4818
|
+
};
|
|
4732
4819
|
var resolveServeControls = async (values, env = process.env, base) => {
|
|
4733
4820
|
const source = asString(values["admin-controls"]) ?? env.MOCKINGBIRD_ADMIN_CONTROLS;
|
|
4734
4821
|
let document = isObject2(base) ? { ...base } : {};
|
|
4735
4822
|
if (source !== void 0 && source.trim() !== "") {
|
|
4736
|
-
|
|
4737
|
-
if (source.trim().startsWith("{")) {
|
|
4738
|
-
try {
|
|
4739
|
-
parsed = JSON.parse(source);
|
|
4740
|
-
} catch {
|
|
4741
|
-
throw new Error("--admin-controls: not valid JSON");
|
|
4742
|
-
}
|
|
4743
|
-
} else
|
|
4744
|
-
parsed = await readJsonFile(source, "--admin-controls");
|
|
4823
|
+
const parsed = source.trim().startsWith("{") ? await readJsonOption(source, "--admin-controls") : await readJsonFile(source, "--admin-controls");
|
|
4745
4824
|
if (!isObject2(parsed))
|
|
4746
4825
|
throw new Error("--admin-controls: expected a JSON object");
|
|
4747
4826
|
document = { ...document, ...parsed };
|
|
@@ -4791,8 +4870,11 @@ var start = async (target, values, config) => {
|
|
|
4791
4870
|
adminKey: config.adminKey,
|
|
4792
4871
|
seed: config.seed,
|
|
4793
4872
|
onLog: formatLog(config.log),
|
|
4873
|
+
...config.settings !== void 0 ? { settings: config.settings } : {},
|
|
4794
4874
|
...config.adminControls !== void 0 ? { adminControls: config.adminControls } : {}
|
|
4795
4875
|
});
|
|
4876
|
+
if (config.idBase !== void 0)
|
|
4877
|
+
runtime.setIdBase?.(config.idBase);
|
|
4796
4878
|
const listening = await listen(runtime, { port: config.port, host: config.host });
|
|
4797
4879
|
target.listening?.(listening);
|
|
4798
4880
|
console.log(`${target.name} emulator listening on ${listening.url}`);
|
|
@@ -4838,6 +4920,11 @@ var serveCommand = (target) => ({
|
|
|
4838
4920
|
const adminControls = await resolveServeControls(values, process.env, config.adminControls);
|
|
4839
4921
|
if (adminControls !== void 0)
|
|
4840
4922
|
config.adminControls = adminControls;
|
|
4923
|
+
if (values.settings !== void 0)
|
|
4924
|
+
throw new Error("--settings serves a single service; give each service its own `settings` in the config");
|
|
4925
|
+
const idBase = config.idBase ?? resolveServeIdBase(values);
|
|
4926
|
+
if (idBase !== void 0)
|
|
4927
|
+
config.idBase = idBase;
|
|
4841
4928
|
const fleet = await startFleet(config, {
|
|
4842
4929
|
load: (name) => loadTarget(name, target),
|
|
4843
4930
|
onLog: formatLog(config.log ?? log),
|
|
@@ -4867,8 +4954,12 @@ var serveCommand = (target) => ({
|
|
|
4867
4954
|
let listening;
|
|
4868
4955
|
try {
|
|
4869
4956
|
const adminControls = await resolveServeControls(values);
|
|
4957
|
+
const idBase = resolveServeIdBase(values);
|
|
4958
|
+
const settings = await resolveServeSettings(target, values);
|
|
4870
4959
|
listening = await start(target, values, {
|
|
4871
4960
|
...adminControls !== void 0 ? { adminControls } : {},
|
|
4961
|
+
...idBase !== void 0 ? { idBase } : {},
|
|
4962
|
+
...settings !== void 0 ? { settings } : {},
|
|
4872
4963
|
adminPrefix: resolveAdminPrefix(asString(values["admin-prefix"]) ?? process.env.MOCKINGBIRD_ADMIN_PREFIX),
|
|
4873
4964
|
port: port === void 0 ? target.defaultPort : Number.parseInt(port, 10),
|
|
4874
4965
|
host: asString(values.host) ?? "127.0.0.1",
|
|
@@ -4938,4 +5029,4 @@ export {
|
|
|
4938
5029
|
createServer2 as createServer,
|
|
4939
5030
|
serveTarget
|
|
4940
5031
|
};
|
|
4941
|
-
//# sourceMappingURL=chunk-
|
|
5032
|
+
//# sourceMappingURL=chunk-E3VNLDYM.js.map
|