@lunora/config 1.0.0-alpha.13 → 1.0.0-alpha.131

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.
Files changed (93) hide show
  1. package/LICENSE.md +6 -0
  2. package/README.md +2 -2
  3. package/__assets__/package-og.svg +1 -1
  4. package/dist/cloudflare/index.d.mts +790 -0
  5. package/dist/cloudflare/index.d.ts +790 -0
  6. package/dist/cloudflare/index.mjs +1 -0
  7. package/dist/index.d.mts +702 -855
  8. package/dist/index.d.ts +702 -855
  9. package/dist/index.mjs +1 -22
  10. package/dist/packem_shared/ACCENT-CLeV5v0K.mjs +7 -0
  11. package/dist/packem_shared/AGENT_MODE_ENV-B54hVQ_w.mjs +1 -0
  12. package/dist/packem_shared/AGENT_RULES_DIR-hP9TiDNx.mjs +1 -0
  13. package/dist/packem_shared/ALLOW_FORWARDED_ENV-DGdbCDre.mjs +1 -0
  14. package/dist/packem_shared/BINDING_MANIFEST_VERSION-DOlqQgYt.mjs +1 -0
  15. package/dist/packem_shared/CLOUDFLARE_DRIVER-B_MaIVFz.mjs +1 -0
  16. package/dist/packem_shared/DEFAULT_DEPLOY_TARGET-cfA_ogWA.mjs +1 -0
  17. package/dist/packem_shared/DEV_DAEMON_ENV-D9Z83rlU.mjs +4 -0
  18. package/dist/packem_shared/DEV_VARS_EXAMPLE_FILE-BL0hrPx3.mjs +6 -0
  19. package/dist/packem_shared/LINKED_PROJECT_DIR-CMzUvj-1.mjs +2 -0
  20. package/dist/packem_shared/LUNORA_CONFIG_FILE-11ax8L-y.mjs +1 -0
  21. package/dist/packem_shared/LUNORA_EVENT_SOURCE-ZclWASXS.mjs +1 -0
  22. package/dist/packem_shared/LUNORA_IGNORED_PATHS-DIdyP0js.mjs +19 -0
  23. package/dist/packem_shared/LunoraReporter-BnXUqh8t.mjs +6 -0
  24. package/dist/packem_shared/PACKAGE_SECRETS_REGISTRY-BgmvEPA-.mjs +1 -0
  25. package/dist/packem_shared/POLICY_SCAFFOLD_ENDPOINT-CUYWD0Mh.mjs +1 -0
  26. package/dist/packem_shared/REMOTE_ELIGIBLE_KEYS-ws6iE0y-.mjs +1 -0
  27. package/dist/packem_shared/REQUIRED_COMPATIBILITY_DATE-BN97lRmC.mjs +1 -0
  28. package/dist/packem_shared/SCHEMA_EDIT_ENDPOINT-BNB1ogaj.mjs +1 -0
  29. package/dist/packem_shared/SEED_ENDPOINT-BaYShU8q.mjs +1 -0
  30. package/dist/packem_shared/WORKERS_CACHE_MIN_DATE-B1h_wNDN.mjs +1 -0
  31. package/dist/packem_shared/WRANGLER_FILES-Bi_18Pj6.mjs +1 -0
  32. package/dist/packem_shared/applyAdditiveEdit-Cff30cSa.mjs +6 -0
  33. package/dist/packem_shared/assetContentType-DNZyUOuF.mjs +1 -0
  34. package/dist/packem_shared/buildPackageSecretsBlock-D2oDEMcf.mjs +18 -0
  35. package/dist/packem_shared/classifyPolicyEdit-BzC_MfYK.mjs +24 -0
  36. package/dist/packem_shared/cloudflare-driver-BHtz6vmK.mjs +1 -0
  37. package/dist/packem_shared/collectExportGaps-ajyIOfom.mjs +1 -0
  38. package/dist/packem_shared/collectWranglerSecretVariables-DZE0RIsW.mjs +1 -0
  39. package/dist/packem_shared/createConfirm-C5G4-dT6.mjs +7 -0
  40. package/dist/packem_shared/detectFramework-VTQfCNXy.mjs +1 -0
  41. package/dist/packem_shared/discover-info-DRQ0Ote0.mjs +1 -0
  42. package/dist/packem_shared/discoverAgentInfo-C8LTinx8.mjs +1 -0
  43. package/dist/packem_shared/discoverContainerInfo-C1zY2O8F.mjs +1 -0
  44. package/dist/packem_shared/discoverSchemaInfo-C8X9mo-i.mjs +1 -0
  45. package/dist/packem_shared/discoverWorkflowInfo-DHzCyLRj.mjs +1 -0
  46. package/dist/packem_shared/inferLunoraBindings-_ESCdL9P.mjs +1 -0
  47. package/dist/packem_shared/jsonc-edit-BZVpxVA0.mjs +1 -0
  48. package/dist/packem_shared/parseDevVariable-B193_28t.mjs +1 -0
  49. package/dist/packem_shared/parseSchema-BQjgz6bk.mjs +1 -0
  50. package/dist/packem_shared/{policy-scaffold.d-DCmwn7zQ.d.mts → policy-scaffold.d-fV3db0S_.d.mts} +23 -23
  51. package/dist/packem_shared/{policy-scaffold.d-DCmwn7zQ.d.ts → policy-scaffold.d-fV3db0S_.d.ts} +23 -23
  52. package/dist/packem_shared/reconcileWranglerCompatibilityDate-BXNiEQ7p.mjs +1 -0
  53. package/dist/packem_shared/reconcileWranglerCrons-BmQa_kGL.mjs +1 -0
  54. package/dist/packem_shared/renderStudioHtml-B2AkxcW1.mjs +15 -0
  55. package/dist/packem_shared/schema-info.d-DS0bUsWE.d.mts +375 -0
  56. package/dist/packem_shared/schema-info.d-DS0bUsWE.d.ts +375 -0
  57. package/dist/packem_shared/serveJsonHandler-DQ-Yqa4J.mjs +1 -0
  58. package/dist/packem_shared/streamContainerLogs-BPYBNrWS.mjs +2 -0
  59. package/dist/packem_shared/wranglerToAlchemy-BXagFk92.mjs +6 -0
  60. package/dist/packem_shared/write-atomic-Cdr2oQb-.mjs +1 -0
  61. package/dist/studio-host/index.d.mts +166 -92
  62. package/dist/studio-host/index.d.ts +166 -92
  63. package/dist/studio-host/index.mjs +1 -7
  64. package/package.json +15 -8
  65. package/dist/packem_shared/ACCENT-DW1XJn8i.mjs +0 -40
  66. package/dist/packem_shared/AGENT_RULES_DIR-lcgC08aE.mjs +0 -40
  67. package/dist/packem_shared/DEV_VARS_EXAMPLE_FILE-dJPNTEnK.mjs +0 -37
  68. package/dist/packem_shared/LINKED_PROJECT_DIR-CXwXzV_C.mjs +0 -52
  69. package/dist/packem_shared/LUNORA_CONFIG_FILE-CtcIcB5-.mjs +0 -34
  70. package/dist/packem_shared/LUNORA_EVENT_SOURCE-D2fDeGB6.mjs +0 -86
  71. package/dist/packem_shared/LunoraReporter-Ci-bDCK9.mjs +0 -70
  72. package/dist/packem_shared/PACKAGE_SECRETS_REGISTRY-B8t_SdoZ.mjs +0 -70
  73. package/dist/packem_shared/POLICY_SCAFFOLD_ENDPOINT-CiC2IGKx.mjs +0 -103
  74. package/dist/packem_shared/REMOTE_ELIGIBLE_KEYS-BC7_e9Bz.mjs +0 -105
  75. package/dist/packem_shared/REQUIRED_COMPATIBILITY_DATE-DRSNSOOp.mjs +0 -476
  76. package/dist/packem_shared/SCHEMA_EDIT_ENDPOINT-Df-Wrix-.mjs +0 -99
  77. package/dist/packem_shared/SEED_ENDPOINT-DVCjaGO-.mjs +0 -61
  78. package/dist/packem_shared/WRANGLER_FILES-DwSuC-Kn.mjs +0 -25
  79. package/dist/packem_shared/applyAdditiveEdit-C-snTFEV.mjs +0 -228
  80. package/dist/packem_shared/buildPackageSecretsBlock-DWDKHViT.mjs +0 -243
  81. package/dist/packem_shared/classifyPolicyEdit-BHeAqF8P.mjs +0 -99
  82. package/dist/packem_shared/createConfirm-fvpdgJ9s.mjs +0 -100
  83. package/dist/packem_shared/detectFramework-Br-BcPBq.mjs +0 -41
  84. package/dist/packem_shared/discoverContainerInfo-BXFs6Wav.mjs +0 -19
  85. package/dist/packem_shared/discoverSchemaInfo-BB-CKlTK.mjs +0 -25
  86. package/dist/packem_shared/discoverWorkflowInfo-CedvR0mn.mjs +0 -19
  87. package/dist/packem_shared/inferLunoraBindings-DIku9mTN.mjs +0 -302
  88. package/dist/packem_shared/loadStudioAssets-Csk5RS4E.mjs +0 -28
  89. package/dist/packem_shared/parseDevVariable-CJiq2IwE.mjs +0 -30
  90. package/dist/packem_shared/parseSchema-DSeyktvG.mjs +0 -107
  91. package/dist/packem_shared/reconcileWranglerBindings-DTHmqTbL.mjs +0 -277
  92. package/dist/packem_shared/renderStudioHtml-449Ysn75.mjs +0 -37
  93. package/dist/packem_shared/serveJsonHandler-B4OLTGLS.mjs +0 -86
@@ -1,277 +0,0 @@
1
- import { writeFileSync } from 'node:fs';
2
- import { containerBuildTag } from '@lunora/container';
3
- import { modify, applyEdits } from 'jsonc-parser';
4
- import { findWranglerFile, readWranglerJsonc } from './WRANGLER_FILES-DwSuC-Kn.mjs';
5
-
6
- const FORMATTING = { formattingOptions: { insertSpaces: true, tabSize: 4 } };
7
- const D1_PLACEHOLDER_ID = "<replace-with-d1-create-id>";
8
- const collectExportGaps = (inferred) => {
9
- const gaps = [];
10
- for (const container of inferred.containers) {
11
- if (!container.exported) {
12
- gaps.push({ className: container.className, exportName: container.exportName, kind: "container", module: "containers" });
13
- }
14
- }
15
- for (const workflow of inferred.workflows) {
16
- if (!workflow.exported) {
17
- gaps.push({ className: workflow.className, exportName: workflow.exportName, kind: "workflow", module: "workflows" });
18
- }
19
- }
20
- return gaps;
21
- };
22
- const collectHintBindingWarnings = (inferred, parsed) => {
23
- const rules = [
24
- [
25
- inferred.usesKv && (parsed?.kv_namespaces?.length ?? 0) === 0,
26
- "@lunora/kv is used but no kv_namespaces binding exists; add a kv_namespaces entry ({ binding, id }) and pass env.<BINDING> to createKv() — the namespace id can't be auto-provisioned."
27
- ],
28
- [
29
- inferred.usesHyperdrive && (parsed?.hyperdrive?.length ?? 0) === 0,
30
- "@lunora/hyperdrive is used but no hyperdrive binding exists; run 'wrangler hyperdrive create' and add a 'hyperdrive' binding ({ binding, id }) — the id can't be auto-provisioned."
31
- ],
32
- [
33
- inferred.usesPipelines && (parsed?.pipelines?.length ?? 0) === 0,
34
- "@lunora/pipelines is used but no pipelines binding exists; run 'wrangler pipelines create <name>' and add a 'pipelines' binding ({ binding, pipeline }) — the pipeline resource can't be auto-provisioned."
35
- ]
36
- ];
37
- return rules.filter(([active]) => active).map(([, warning]) => warning);
38
- };
39
- const collectWarnings = (inferred, parsed) => {
40
- const exported = new Set(inferred.durableObjects.map((object) => object.className));
41
- const warnings = [];
42
- const hasR2Bucket = (parsed?.r2_buckets?.length ?? 0) > 0;
43
- const hasSessionStore = (parsed?.d1_databases?.some((binding) => binding.binding === "DB") ?? false) || inferred.needsD1;
44
- if (inferred.usesStorage && !hasR2Bucket) {
45
- warnings.push(
46
- "@lunora/storage is used but R2 bucket bindings have user-defined names; add an r2_buckets entry and pass env.<BINDING> to createStorage()."
47
- );
48
- }
49
- if (inferred.usesAuth && !exported.has("SessionDO") && !hasSessionStore) {
50
- warnings.push(
51
- "@lunora/auth is used but the worker entry exports no SessionDO; sessions are D1-backed, or export SessionDO to enable DO-backed sessions."
52
- );
53
- }
54
- if (inferred.usesScheduler && !exported.has("SchedulerDO")) {
55
- warnings.push("@lunora/scheduler is used but the worker entry exports no SchedulerDO; export it so the SCHEDULER binding can be provisioned.");
56
- }
57
- for (const container of inferred.containers) {
58
- if (!container.exported) {
59
- warnings.push(
60
- `container "${container.exportName}" is declared but ${container.className} is not exported by the worker entry; add \`export * from "./lunora/_generated/containers"\` so its binding can be provisioned.`
61
- );
62
- }
63
- }
64
- for (const workflow of inferred.workflows) {
65
- if (!workflow.exported) {
66
- warnings.push(
67
- `workflow "${workflow.exportName}" is declared but ${workflow.className} is not exported by the worker entry; add \`export * from "./lunora/_generated/workflows"\` so its binding can be provisioned.`
68
- );
69
- }
70
- }
71
- if (inferred.containers.length > 0 && parsed?.observability?.enabled === false) {
72
- warnings.push("containers are declared but observability is explicitly disabled in wrangler.jsonc — container logs will not be captured.");
73
- }
74
- if (inferred.usesPayment) {
75
- warnings.push(
76
- "@lunora/payment is used; set the provider secrets in .dev.vars — STRIPE_SECRET_KEY + STRIPE_WEBHOOK_SECRET (Stripe) or POLAR_ACCESS_TOKEN + POLAR_WEBHOOK_SECRET (Polar)."
77
- );
78
- }
79
- warnings.push(...collectHintBindingWarnings(inferred, parsed));
80
- return warnings;
81
- };
82
- const applyModify = (text, path, value) => {
83
- const edits = modify(text, [...path], value, FORMATTING);
84
- return edits.length > 0 ? applyEdits(text, edits) : text;
85
- };
86
- const nextMigrationTag = (migrations) => {
87
- const used = new Set(migrations.map((migration) => migration.tag));
88
- let index = 1;
89
- while (used.has(`v${String(index)}`)) {
90
- index += 1;
91
- }
92
- return `v${String(index)}`;
93
- };
94
- const reconcileDurableObjects = (text, parsed, required) => {
95
- const existingBindings = parsed.durable_objects?.bindings ?? [];
96
- const existingNames = new Set(existingBindings.map((binding) => binding.name));
97
- const missing = required.filter((object) => !existingNames.has(object.binding));
98
- let nextText = text;
99
- const added = [];
100
- if (missing.length > 0) {
101
- const nextBindings = [
102
- ...existingBindings,
103
- ...missing.map((object) => {
104
- return { class_name: object.className, name: object.binding };
105
- })
106
- ];
107
- nextText = applyModify(nextText, ["durable_objects", "bindings"], nextBindings);
108
- added.push(...missing.map((object) => `${object.binding}/${object.className}`));
109
- }
110
- const migrations = parsed.migrations ?? [];
111
- const registered = new Set(migrations.flatMap((migration) => [...migration.new_sqlite_classes ?? [], ...migration.new_classes ?? []]));
112
- const missingClasses = required.map((object) => object.className).filter((className) => !registered.has(className));
113
- if (missingClasses.length > 0) {
114
- const nextMigrations = [...migrations, { new_sqlite_classes: missingClasses, tag: nextMigrationTag(migrations) }];
115
- nextText = applyModify(nextText, ["migrations"], nextMigrations);
116
- }
117
- return { added, text: nextText };
118
- };
119
- const reconcileD1 = (text, parsed) => {
120
- const d1Bindings = parsed.d1_databases ?? [];
121
- if (d1Bindings.some((binding) => binding.binding === "DB")) {
122
- return { added: [], text };
123
- }
124
- const databaseName = typeof parsed.name === "string" && parsed.name.length > 0 ? parsed.name : "lunora";
125
- const nextD1 = [...d1Bindings, { binding: "DB", database_id: D1_PLACEHOLDER_ID, database_name: databaseName }];
126
- return { added: ["DB (D1)"], text: applyModify(text, ["d1_databases"], nextD1) };
127
- };
128
- const reconcileSelfDescribing = (text, parsed, key, binding, label) => {
129
- const current = parsed[key]?.binding;
130
- if (typeof current === "string" && current.length > 0) {
131
- return { added: [], text };
132
- }
133
- return { added: [label], text: applyModify(text, [key], { binding }) };
134
- };
135
- const reconcileAnalytics = (text, parsed) => {
136
- if ((parsed.analytics_engine_datasets?.length ?? 0) > 0) {
137
- return { added: [], text };
138
- }
139
- const nextDatasets = [{ binding: "ANALYTICS", dataset: "ANALYTICS" }];
140
- return { added: ["ANALYTICS (Analytics Engine)"], text: applyModify(text, ["analytics_engine_datasets"], nextDatasets) };
141
- };
142
- const wranglerInstanceType = (instanceType) => {
143
- if (typeof instanceType === "string") {
144
- return instanceType;
145
- }
146
- const custom = {};
147
- if (instanceType.diskMb !== void 0) {
148
- custom.disk_mb = instanceType.diskMb;
149
- }
150
- if (instanceType.memoryMib !== void 0) {
151
- custom.memory_mib = instanceType.memoryMib;
152
- }
153
- if (instanceType.vcpu !== void 0) {
154
- custom.vcpu = instanceType.vcpu;
155
- }
156
- return custom;
157
- };
158
- const imageRefFor = (container) => {
159
- if (container.image.kind === "dockerfile") {
160
- return container.image.dockerfilePath;
161
- }
162
- if (container.image.kind === "registry") {
163
- return container.image.reference;
164
- }
165
- return containerBuildTag(container.exportName);
166
- };
167
- const containerEntryFor = (container) => {
168
- const entry = {
169
- class_name: container.className,
170
- image: imageRefFor(container)
171
- };
172
- if (container.image.kind === "dockerfile") {
173
- entry.image_build_context = container.image.buildContext;
174
- }
175
- if (container.buildArgs !== void 0 && container.image.kind !== "registry") {
176
- entry.image_vars = container.buildArgs;
177
- }
178
- if (container.instanceType !== void 0) {
179
- entry.instance_type = wranglerInstanceType(container.instanceType);
180
- }
181
- if (container.maxInstances !== void 0) {
182
- entry.max_instances = container.maxInstances;
183
- }
184
- if (container.name !== void 0) {
185
- entry.name = container.name;
186
- }
187
- if (container.rollout?.stepPercentage !== void 0) {
188
- entry.rollout_step_percentage = container.rollout.stepPercentage;
189
- }
190
- if (container.rollout?.gracePeriodSeconds !== void 0) {
191
- entry.rollout_active_grace_period = container.rollout.gracePeriodSeconds;
192
- }
193
- return entry;
194
- };
195
- const reconcileContainers = (text, parsed, containers) => {
196
- const existing = parsed.containers ?? [];
197
- const existingClasses = new Set(existing.map((entry) => entry.class_name));
198
- const missing = containers.filter((container) => !existingClasses.has(container.className));
199
- if (missing.length === 0) {
200
- return { added: [], text };
201
- }
202
- const nextText = applyModify(text, ["containers"], [...existing, ...missing.map((container) => containerEntryFor(container))]);
203
- return { added: missing.map((container) => `containers/${container.className}`), text: nextText };
204
- };
205
- const reconcileObservability = (text, parsed) => {
206
- if (parsed.observability !== void 0) {
207
- return { added: [], text };
208
- }
209
- const nextText = applyModify(text, ["observability"], { enabled: true, head_sampling_rate: 1 });
210
- return { added: ["observability"], text: nextText };
211
- };
212
- const workflowEntryFor = (workflow) => {
213
- return { binding: workflow.bindingName, class_name: workflow.className, name: workflow.name };
214
- };
215
- const reconcileWorkflows = (text, parsed, workflows) => {
216
- const existing = parsed.workflows ?? [];
217
- const existingClasses = new Set(existing.map((entry) => entry.class_name));
218
- const missing = workflows.filter((workflow) => !existingClasses.has(workflow.className));
219
- if (missing.length === 0) {
220
- return { added: [], text };
221
- }
222
- const nextText = applyModify(text, ["workflows"], [...existing, ...missing.map((workflow) => workflowEntryFor(workflow))]);
223
- return { added: missing.map((workflow) => `workflows/${workflow.className}`), text: nextText };
224
- };
225
- const reconcileWranglerBindings = (projectRoot, inferred) => {
226
- const wranglerPath = findWranglerFile(projectRoot);
227
- const exportGaps = collectExportGaps(inferred);
228
- if (!wranglerPath) {
229
- return { added: [], changed: false, exportGaps, reason: "wrangler.jsonc not found", warnings: collectWarnings(inferred) };
230
- }
231
- const { parsed, text: original } = readWranglerJsonc(wranglerPath);
232
- if (parsed === void 0) {
233
- return { added: [], changed: false, exportGaps, reason: `failed to parse ${wranglerPath} as JSONC`, warnings: collectWarnings(inferred), wranglerPath };
234
- }
235
- const warnings = collectWarnings(inferred, parsed);
236
- const exportedContainers = inferred.containers.filter((container) => container.exported);
237
- const requiredDurableObjects = [
238
- ...inferred.durableObjects,
239
- ...exportedContainers.map((container) => {
240
- return { binding: container.bindingName, className: container.className };
241
- })
242
- ];
243
- const exportedWorkflows = inferred.workflows.filter((workflow) => workflow.exported);
244
- const pipeline = [
245
- { enabled: true, run: (text2) => reconcileDurableObjects(text2, parsed, requiredDurableObjects) },
246
- { enabled: inferred.needsD1, run: (text2) => reconcileD1(text2, parsed) },
247
- { enabled: inferred.usesAi, run: (text2) => reconcileSelfDescribing(text2, parsed, "ai", "AI", "AI (Workers AI)") },
248
- { enabled: inferred.usesBrowser, run: (text2) => reconcileSelfDescribing(text2, parsed, "browser", "BROWSER", "BROWSER (Browser Rendering)") },
249
- { enabled: inferred.usesImages, run: (text2) => reconcileSelfDescribing(text2, parsed, "images", "IMAGES", "IMAGES (Cloudflare Images)") },
250
- { enabled: inferred.usesAnalytics, run: (text2) => reconcileAnalytics(text2, parsed) },
251
- { enabled: true, run: (text2) => reconcileObservability(text2, parsed) },
252
- { enabled: exportedContainers.length > 0, run: (text2) => reconcileContainers(text2, parsed, exportedContainers) },
253
- { enabled: exportedWorkflows.length > 0, run: (text2) => reconcileWorkflows(text2, parsed, exportedWorkflows) }
254
- ];
255
- let text = original;
256
- const added = [];
257
- for (const step of pipeline) {
258
- if (!step.enabled) {
259
- continue;
260
- }
261
- const result = step.run(text);
262
- text = result.text;
263
- added.push(...result.added);
264
- }
265
- if (added.includes("DB (D1)")) {
266
- warnings.push(
267
- `wrote a DB binding with a placeholder database_id ("${D1_PLACEHOLDER_ID}") — run \`wrangler d1 create <name>\` and replace it before deploying.`
268
- );
269
- }
270
- if (text === original) {
271
- return { added: [], changed: false, exportGaps, reason: "bindings already in sync", warnings, wranglerPath };
272
- }
273
- writeFileSync(wranglerPath, text, "utf8");
274
- return { added, changed: true, exportGaps, warnings, wranglerPath };
275
- };
276
-
277
- export { reconcileWranglerBindings };
@@ -1,37 +0,0 @@
1
- const forInlineScript = (value) => JSON.stringify(value).replaceAll("<", String.raw`\u003c`);
2
- const forAttribute = (value) => value.replaceAll("&", "&amp;").replaceAll('"', "&quot;").replaceAll("<", "&lt;");
3
- const renderStudioHtml = (config) => {
4
- const settings = [`window.__LUNORA_BASE_PATH__=${forInlineScript(config.basePath)};`];
5
- if (config.adminToken !== void 0 && config.adminToken !== "") {
6
- settings.push(`window.__LUNORA_ADMIN_TOKEN__=${forInlineScript(config.adminToken)};`);
7
- }
8
- if (config.dataEditable === true) {
9
- settings.push("window.__LUNORA_DATA_EDITABLE__=true;");
10
- }
11
- if (config.runAsIdentity === true) {
12
- settings.push("window.__LUNORA_RUN_AS_IDENTITY__=true;");
13
- }
14
- if (config.schemaEditable === true) {
15
- settings.push("window.__LUNORA_SCHEMA_EDITABLE__=true;");
16
- }
17
- if (config.rulesInstalled === false) {
18
- settings.push("window.__LUNORA_RULES_INSTALLED__=false;");
19
- }
20
- return `<!doctype html>
21
- <html lang="en">
22
- <head>
23
- <meta charset="UTF-8" />
24
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
25
- <title>Lunora Studio</title>
26
- <script>${settings.join("")}<\/script>
27
- <link rel="stylesheet" href="${forAttribute(config.styleHref)}" />
28
- </head>
29
- <body>
30
- <div id="root"></div>
31
- <script type="module" src="${forAttribute(config.scriptSrc)}"><\/script>
32
- </body>
33
- </html>
34
- `;
35
- };
36
-
37
- export { renderStudioHtml as default };
@@ -1,86 +0,0 @@
1
- const MAX_BODY_BYTES = 1e6;
2
- const readBody = async (request) => await new Promise((resolve, reject) => {
3
- const chunks = [];
4
- let size = 0;
5
- request.on("data", (chunk) => {
6
- size += chunk.length;
7
- if (size > MAX_BODY_BYTES) {
8
- reject(new Error("request body too large"));
9
- return;
10
- }
11
- chunks.push(chunk);
12
- });
13
- request.on("end", () => {
14
- resolve(Buffer.concat(chunks).toString("utf8"));
15
- });
16
- request.on("error", reject);
17
- });
18
- const respondJson = (response, status, body) => {
19
- response.statusCode = status;
20
- response.setHeader("Content-Type", "application/json; charset=utf-8");
21
- response.end(JSON.stringify(body));
22
- };
23
- const headerValue = (raw) => {
24
- const value = Array.isArray(raw) ? raw[0] : raw;
25
- return typeof value === "string" ? value.trim().toLowerCase() : void 0;
26
- };
27
- const SAME_SITE_FETCH_VALUES = /* @__PURE__ */ new Set(["none", "same-origin", "same-site"]);
28
- const originRejectionReason = (request) => {
29
- const secFetchSite = headerValue(request.headers["sec-fetch-site"]);
30
- if (secFetchSite !== void 0) {
31
- return SAME_SITE_FETCH_VALUES.has(secFetchSite) ? void 0 : "cross-origin request rejected";
32
- }
33
- const origin = headerValue(request.headers.origin);
34
- if (origin === void 0 || origin === "null") {
35
- return void 0;
36
- }
37
- let originHost;
38
- try {
39
- originHost = new URL(origin).host.toLowerCase();
40
- } catch {
41
- return "invalid origin header";
42
- }
43
- return originHost === headerValue(request.headers.host) ? void 0 : "cross-origin request rejected";
44
- };
45
- const csrfRejectionReason = (request) => {
46
- const method = (request.method ?? "GET").toUpperCase();
47
- const isStateChanging = method !== "GET" && method !== "HEAD";
48
- const originReason = originRejectionReason(request);
49
- if (originReason !== void 0) {
50
- return originReason;
51
- }
52
- if (isStateChanging) {
53
- const contentType = headerValue(request.headers["content-type"]);
54
- if (!contentType?.startsWith("application/json")) {
55
- return "content-type must be application/json";
56
- }
57
- }
58
- return void 0;
59
- };
60
- const serveJsonHandler = (request, response, handle, projectRoot) => {
61
- const run = async () => {
62
- try {
63
- const rejection = csrfRejectionReason(request);
64
- if (rejection !== void 0) {
65
- respondJson(response, 403, { error: rejection, ok: false });
66
- return;
67
- }
68
- const raw = request.method === "GET" ? "" : await readBody(request);
69
- let parsed;
70
- try {
71
- parsed = raw === "" ? void 0 : JSON.parse(raw);
72
- } catch {
73
- respondJson(response, 400, { error: "invalid-json", ok: false });
74
- return;
75
- }
76
- const result = handle({ body: parsed, method: request.method ?? "POST", projectRoot });
77
- respondJson(response, result.status, result.body);
78
- } catch (error) {
79
- respondJson(response, 500, { error: error instanceof Error ? error.message : String(error), ok: false });
80
- }
81
- };
82
- run().catch(() => {
83
- });
84
- };
85
-
86
- export { serveJsonHandler };