@samva/vite 0.4.0 → 0.5.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/AGENTS.md +5 -0
- package/dist/build.js +8 -1
- package/dist/editor/assets/index-BZ-5-1V0.js +31 -0
- package/dist/editor/index.html +1 -1
- package/dist/emit.js +4 -4
- package/dist/index.js +8 -5
- package/package.json +3 -3
- package/dist/editor/assets/index-Cot9JDdw.js +0 -30
package/dist/editor/index.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="utf-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
6
|
<title>Samva editor</title>
|
|
7
|
-
<script type="module" crossorigin src="./assets/index-
|
|
7
|
+
<script type="module" crossorigin src="./assets/index-BZ-5-1V0.js"></script>
|
|
8
8
|
<link rel="stylesheet" crossorigin href="./assets/index-Cg4x6ewh.css">
|
|
9
9
|
</head>
|
|
10
10
|
<body>
|
package/dist/emit.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Result } from "effect";
|
|
2
1
|
import { COMPILER_VERSION, compileSource } from "@samva/markup/compile";
|
|
3
2
|
import { emitModule } from "@samva/markup/emit";
|
|
3
|
+
import { Result } from "better-result";
|
|
4
4
|
//#region src/emit.ts
|
|
5
5
|
const countRepairable = (diagnostics) => diagnostics.filter((diagnostic) => diagnostic.repair !== void 0).length;
|
|
6
6
|
const uniquePlaceholders = (source) => source === void 0 ? [] : [...new Set([...source.matchAll(/{{\s*([A-Za-z_][\w.-]*)\s*}}/g)].map((match) => match[1] ?? ""))].filter(Boolean).sort();
|
|
@@ -20,16 +20,16 @@ const validationSummary = (source, emitDiagnostics, compiled) => {
|
|
|
20
20
|
/** Compile one source into its channel-polymorphic preview. */
|
|
21
21
|
const compiledPreview = (source) => {
|
|
22
22
|
const probe = compileSource(source);
|
|
23
|
-
if (Result.
|
|
23
|
+
if (Result.isError(probe)) return {
|
|
24
24
|
channel: "unknown",
|
|
25
25
|
compileOk: false,
|
|
26
26
|
compiled: {
|
|
27
27
|
channel: "unknown",
|
|
28
28
|
ok: false,
|
|
29
|
-
diagnostics: probe.
|
|
29
|
+
diagnostics: probe.error.diagnostics
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
|
-
const compiled = probe.
|
|
32
|
+
const compiled = probe.value;
|
|
33
33
|
if (compiled.channel === "sms") return {
|
|
34
34
|
channel: "sms",
|
|
35
35
|
compileOk: true,
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,6 @@ import { open, readFile, realpath, rename, rm, stat } from "node:fs/promises";
|
|
|
7
7
|
import { extname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
9
9
|
import { checkEmailCompatibility, emailSelections } from "@samva/markup/compiler";
|
|
10
|
-
import { Predicate } from "effect";
|
|
11
10
|
import { createServerModuleRunner, loadEnv } from "vite";
|
|
12
11
|
import { createHash, randomUUID } from "node:crypto";
|
|
13
12
|
const hashSource = (source) => createHash("sha256").update(source, "utf8").digest("hex").slice(0, 16);
|
|
@@ -448,6 +447,10 @@ var EditorFileStore = class {
|
|
|
448
447
|
}
|
|
449
448
|
};
|
|
450
449
|
//#endregion
|
|
450
|
+
//#region src/internal/guards.ts
|
|
451
|
+
/** A non-null, non-array object, narrowed for property access. */
|
|
452
|
+
const isObject = (input) => typeof input === "object" && input !== null && !Array.isArray(input);
|
|
453
|
+
//#endregion
|
|
451
454
|
//#region src/editor.ts
|
|
452
455
|
const DEFAULT_ROUTE = "/";
|
|
453
456
|
const MODULE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
@@ -571,11 +574,11 @@ const LOCAL_RENDER = { relativeUrls: true };
|
|
|
571
574
|
*/
|
|
572
575
|
const variablesOf = (definition) => {
|
|
573
576
|
const properties = definition.schema.schema["properties"];
|
|
574
|
-
if (!
|
|
577
|
+
if (!isObject(properties)) return [];
|
|
575
578
|
const required = definition.schema.schema["required"];
|
|
576
579
|
const names = Array.isArray(required) ? required : [];
|
|
577
580
|
return Object.entries(properties).map(([name, property]) => {
|
|
578
|
-
const examples =
|
|
581
|
+
const examples = isObject(property) ? property["examples"] : void 0;
|
|
579
582
|
const example = Array.isArray(examples) ? examples[0] : void 0;
|
|
580
583
|
return {
|
|
581
584
|
name,
|
|
@@ -901,7 +904,7 @@ const samvaEditor = (options = {}) => {
|
|
|
901
904
|
if (error instanceof EditorBodyTooLarge) return sendJson(res, 413, { error: error.message });
|
|
902
905
|
return sendJson(res, 400, { error: "malformed JSON body" });
|
|
903
906
|
}
|
|
904
|
-
if (!
|
|
907
|
+
if (!isObject(body) || body["kind"] !== "authoredSource" || typeof body["baseRev"] !== "string" || typeof body["authoredSource"] !== "string") return sendJson(res, 400, { error: "Expected a revision-bound authored source update." });
|
|
905
908
|
if (Buffer.byteLength(body["authoredSource"], "utf8") > 1048576) return sendJson(res, 413, { error: "Authored source exceeds the 1 MiB limit." });
|
|
906
909
|
const outcome = await store.saveSource(id, body["baseRev"], body["authoredSource"], query.get("client") ?? void 0);
|
|
907
910
|
if (outcome.ok) return sendJson(res, 200, { rev: outcome.rev });
|
|
@@ -923,7 +926,7 @@ const samvaEditor = (options = {}) => {
|
|
|
923
926
|
} catch {
|
|
924
927
|
return sendJson(res, 400, { error: "malformed JSON body" });
|
|
925
928
|
}
|
|
926
|
-
if (!
|
|
929
|
+
if (!isObject(body) || typeof body["fixture"] !== "string") return sendJson(res, 400, { error: "malformed JSON body" });
|
|
927
930
|
const outcome = await store.viewFixture(id, body["fixture"], query.get("client") ?? void 0);
|
|
928
931
|
if (outcome.ok) return sendJson(res, 200, {});
|
|
929
932
|
return sendJson(res, outcome.kind === "missing" ? 404 : 422, { error: outcome.error });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@samva/vite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Unified Vite editor for Samva email, SMS, and WhatsApp templates",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"email",
|
|
@@ -70,10 +70,10 @@
|
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
72
|
"@babel/parser": "^8.0.4",
|
|
73
|
-
"@samva/markup": "^0.
|
|
73
|
+
"@samva/markup": "^0.5.0",
|
|
74
|
+
"better-result": "3.0.1",
|
|
74
75
|
"caniemail": "2.0.2",
|
|
75
76
|
"css-tree": "3.2.1",
|
|
76
|
-
"effect": "4.0.0-rc.112",
|
|
77
77
|
"tailwindcss": "^4.3.3"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|