hazo_blog 2.0.0 → 2.16.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.
Files changed (165) hide show
  1. package/CHANGE_LOG.md +867 -0
  2. package/README.md +1 -0
  3. package/db_setup_postgres.sql +652 -0
  4. package/db_setup_sqlite.sql +341 -0
  5. package/dist/index.d.ts +24 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +24 -0
  8. package/dist/jobs/maintenance-jobs.d.ts +83 -0
  9. package/dist/jobs/maintenance-jobs.d.ts.map +1 -0
  10. package/dist/jobs/maintenance-jobs.js +123 -0
  11. package/dist/lib/domain-dns.d.ts +15 -0
  12. package/dist/lib/domain-dns.d.ts.map +1 -0
  13. package/dist/lib/domain-dns.js +27 -0
  14. package/dist/lib/domain-token.d.ts +23 -0
  15. package/dist/lib/domain-token.d.ts.map +1 -0
  16. package/dist/lib/domain-token.js +42 -0
  17. package/dist/lib/hook-bus.d.ts +165 -0
  18. package/dist/lib/hook-bus.d.ts.map +1 -0
  19. package/dist/lib/hook-bus.js +90 -0
  20. package/dist/lib/index.d.ts +8 -0
  21. package/dist/lib/index.d.ts.map +1 -1
  22. package/dist/lib/index.js +8 -0
  23. package/dist/lib/revisions.d.ts +10 -0
  24. package/dist/lib/revisions.d.ts.map +1 -0
  25. package/dist/lib/revisions.js +18 -0
  26. package/dist/lib/safe-url.d.ts +8 -0
  27. package/dist/lib/safe-url.d.ts.map +1 -0
  28. package/dist/lib/safe-url.js +32 -0
  29. package/dist/lib/sections.d.ts +59 -0
  30. package/dist/lib/sections.d.ts.map +1 -0
  31. package/dist/lib/sections.js +303 -0
  32. package/dist/lib/site-identity.d.ts +45 -0
  33. package/dist/lib/site-identity.d.ts.map +1 -0
  34. package/dist/lib/site-identity.js +116 -0
  35. package/dist/lib/status.d.ts +25 -0
  36. package/dist/lib/status.d.ts.map +1 -0
  37. package/dist/lib/status.js +58 -0
  38. package/dist/lib/theme-schema.d.ts +51 -0
  39. package/dist/lib/theme-schema.d.ts.map +1 -0
  40. package/dist/lib/theme-schema.js +112 -0
  41. package/dist/lib/theme-validate.d.ts +48 -0
  42. package/dist/lib/theme-validate.d.ts.map +1 -0
  43. package/dist/lib/theme-validate.js +149 -0
  44. package/dist/next/byline-routes.d.ts +67 -0
  45. package/dist/next/byline-routes.d.ts.map +1 -0
  46. package/dist/next/byline-routes.js +235 -0
  47. package/dist/next/domain-routes.d.ts +9 -0
  48. package/dist/next/domain-routes.d.ts.map +1 -0
  49. package/dist/next/domain-routes.js +39 -0
  50. package/dist/next/post-routes.d.ts +100 -0
  51. package/dist/next/post-routes.d.ts.map +1 -0
  52. package/dist/next/post-routes.js +291 -0
  53. package/dist/render/engine.d.ts +41 -0
  54. package/dist/render/engine.d.ts.map +1 -0
  55. package/dist/render/engine.js +91 -0
  56. package/dist/render/fallback-theme/templates/404.liquid +1 -0
  57. package/dist/render/fallback-theme/templates/default.liquid +1 -0
  58. package/dist/render/fallback-theme.d.ts +3 -0
  59. package/dist/render/fallback-theme.d.ts.map +1 -0
  60. package/dist/render/fallback-theme.js +34 -0
  61. package/dist/render/html.d.ts +10 -0
  62. package/dist/render/html.d.ts.map +1 -0
  63. package/dist/render/html.js +29 -0
  64. package/dist/render/index.d.ts +13 -0
  65. package/dist/render/index.d.ts.map +1 -0
  66. package/dist/render/index.js +23 -0
  67. package/dist/render/resolve.d.ts +23 -0
  68. package/dist/render/resolve.d.ts.map +1 -0
  69. package/dist/render/resolve.js +32 -0
  70. package/dist/render/tags/faq.d.ts +9 -0
  71. package/dist/render/tags/faq.d.ts.map +1 -0
  72. package/dist/render/tags/faq.js +31 -0
  73. package/dist/render/tags/image.d.ts +12 -0
  74. package/dist/render/tags/image.d.ts.map +1 -0
  75. package/dist/render/tags/image.js +56 -0
  76. package/dist/render/tags/index.d.ts +3 -0
  77. package/dist/render/tags/index.d.ts.map +1 -0
  78. package/dist/render/tags/index.js +16 -0
  79. package/dist/render/tags/menu.d.ts +11 -0
  80. package/dist/render/tags/menu.d.ts.map +1 -0
  81. package/dist/render/tags/menu.js +74 -0
  82. package/dist/render/tags/related-posts.d.ts +11 -0
  83. package/dist/render/tags/related-posts.d.ts.map +1 -0
  84. package/dist/render/tags/related-posts.js +34 -0
  85. package/dist/render/tags/section-list.d.ts +9 -0
  86. package/dist/render/tags/section-list.d.ts.map +1 -0
  87. package/dist/render/tags/section-list.js +71 -0
  88. package/dist/render/tags/seo-head.d.ts +16 -0
  89. package/dist/render/tags/seo-head.d.ts.map +1 -0
  90. package/dist/render/tags/seo-head.js +73 -0
  91. package/dist/render/tags/toc.d.ts +15 -0
  92. package/dist/render/tags/toc.d.ts.map +1 -0
  93. package/dist/render/tags/toc.js +72 -0
  94. package/dist/render/types.d.ts +167 -0
  95. package/dist/render/types.d.ts.map +1 -0
  96. package/dist/render/types.js +13 -0
  97. package/dist/repository/bylines.d.ts +56 -0
  98. package/dist/repository/bylines.d.ts.map +1 -0
  99. package/dist/repository/bylines.js +284 -0
  100. package/dist/repository/domains.d.ts +67 -0
  101. package/dist/repository/domains.d.ts.map +1 -0
  102. package/dist/repository/domains.js +173 -0
  103. package/dist/repository/media.d.ts +45 -0
  104. package/dist/repository/media.d.ts.map +1 -0
  105. package/dist/repository/media.js +248 -0
  106. package/dist/repository/menus.d.ts +58 -0
  107. package/dist/repository/menus.d.ts.map +1 -0
  108. package/dist/repository/menus.js +311 -0
  109. package/dist/repository/posts.d.ts +171 -0
  110. package/dist/repository/posts.d.ts.map +1 -0
  111. package/dist/repository/posts.js +791 -0
  112. package/dist/repository/site-files.d.ts +15 -0
  113. package/dist/repository/site-files.d.ts.map +1 -0
  114. package/dist/repository/site-files.js +73 -0
  115. package/dist/repository/tags.d.ts +51 -0
  116. package/dist/repository/tags.d.ts.map +1 -0
  117. package/dist/repository/tags.js +282 -0
  118. package/dist/repository/themes.d.ts +45 -0
  119. package/dist/repository/themes.d.ts.map +1 -0
  120. package/dist/repository/themes.js +285 -0
  121. package/dist/seo/hazo-seo-sitemap-source.d.ts +63 -0
  122. package/dist/seo/hazo-seo-sitemap-source.d.ts.map +1 -0
  123. package/dist/seo/hazo-seo-sitemap-source.js +85 -0
  124. package/dist/seo/index.d.ts +1 -0
  125. package/dist/seo/index.d.ts.map +1 -1
  126. package/dist/seo/index.js +6 -0
  127. package/dist/service/bylines.d.ts +21 -0
  128. package/dist/service/bylines.d.ts.map +1 -0
  129. package/dist/service/bylines.js +48 -0
  130. package/dist/service/cdn-hooks.d.ts +20 -0
  131. package/dist/service/cdn-hooks.d.ts.map +1 -0
  132. package/dist/service/cdn-hooks.js +38 -0
  133. package/dist/service/domains.d.ts +49 -0
  134. package/dist/service/domains.d.ts.map +1 -0
  135. package/dist/service/domains.js +98 -0
  136. package/dist/service/media.d.ts +79 -0
  137. package/dist/service/media.d.ts.map +1 -0
  138. package/dist/service/media.js +225 -0
  139. package/dist/service/menus.d.ts +43 -0
  140. package/dist/service/menus.d.ts.map +1 -0
  141. package/dist/service/menus.js +165 -0
  142. package/dist/service/posts.d.ts +70 -0
  143. package/dist/service/posts.d.ts.map +1 -0
  144. package/dist/service/posts.js +291 -0
  145. package/dist/service/seo-hooks.d.ts +18 -0
  146. package/dist/service/seo-hooks.d.ts.map +1 -0
  147. package/dist/service/seo-hooks.js +108 -0
  148. package/dist/service/site-files.d.ts +20 -0
  149. package/dist/service/site-files.d.ts.map +1 -0
  150. package/dist/service/site-files.js +71 -0
  151. package/dist/service/tags.d.ts +20 -0
  152. package/dist/service/tags.d.ts.map +1 -0
  153. package/dist/service/tags.js +41 -0
  154. package/dist/service/themes.d.ts +85 -0
  155. package/dist/service/themes.d.ts.map +1 -0
  156. package/dist/service/themes.js +416 -0
  157. package/dist/types/index.d.ts +953 -0
  158. package/dist/types/index.d.ts.map +1 -1
  159. package/dist/ui/content-status-badge.d.ts +7 -0
  160. package/dist/ui/content-status-badge.d.ts.map +1 -0
  161. package/dist/ui/content-status-badge.js +16 -0
  162. package/dist/ui/index.d.ts +1 -0
  163. package/dist/ui/index.d.ts.map +1 -1
  164. package/dist/ui/index.js +1 -0
  165. package/package.json +37 -26
@@ -0,0 +1,51 @@
1
+ import { z, type ZodTypeAny } from "zod";
2
+ import type { ThemeJson, ThemeSettingsField } from "../types/index.js";
3
+ export declare class ThemeJsonValidationError extends Error {
4
+ readonly issues: string[];
5
+ constructor(issues: string[]);
6
+ }
7
+ export declare const themeJsonSchema: z.ZodObject<{
8
+ name: z.ZodString;
9
+ version: z.ZodString;
10
+ author: z.ZodString;
11
+ licence: z.ZodString;
12
+ description: z.ZodDefault<z.ZodOptional<z.ZodString>>;
13
+ screenshots: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString>>>;
14
+ settings: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodObject<{
15
+ key: z.ZodString;
16
+ label: z.ZodString;
17
+ type: z.ZodEnum<{
18
+ image: "image";
19
+ text: "text";
20
+ colour: "colour";
21
+ font: "font";
22
+ select: "select";
23
+ toggle: "toggle";
24
+ range: "range";
25
+ }>;
26
+ default: z.ZodOptional<z.ZodUnknown>;
27
+ helpText: z.ZodOptional<z.ZodString>;
28
+ options: z.ZodOptional<z.ZodArray<z.ZodObject<{
29
+ value: z.ZodString;
30
+ label: z.ZodString;
31
+ }, z.core.$strip>>>;
32
+ min: z.ZodOptional<z.ZodNumber>;
33
+ max: z.ZodOptional<z.ZodNumber>;
34
+ step: z.ZodOptional<z.ZodNumber>;
35
+ }, z.core.$strip>>>>;
36
+ allowedSections: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>;
37
+ }, z.core.$strip>;
38
+ /** Parses+validates a raw `theme.json` payload (already `JSON.parse`d). Throws `ThemeJsonValidationError` with every issue found, never just the first. */
39
+ export declare function parseThemeJson(raw: unknown): ThemeJson;
40
+ /**
41
+ * Resolves `themeJson.allowedSections` for one template name. `null` means
42
+ * "no restriction configured — every section type is allowed", the SAME
43
+ * fallback `../lib/sections.ts`'s own bridge comment documents; a theme
44
+ * that never sets `allowedSections` at all behaves identically to today
45
+ * (nothing narrows). See this module's header comment for why nothing
46
+ * calls this yet.
47
+ */
48
+ export declare function getAllowedSectionsForTemplate(themeJson: ThemeJson, template: string): string[] | null;
49
+ /** Builds a Zod schema for validating a settings PATCH against one field's declared type — see `zodForSettingsField`'s own per-type mapping. Every field is `.optional()`: a partial settings update (one key at a time) is the expected shape (`ThemeService.updateThemeSettings` merges onto existing settings, it never requires the full set). */
50
+ export declare function buildThemeSettingsSchema(fields: ThemeSettingsField[]): ZodTypeAny;
51
+ //# sourceMappingURL=theme-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme-schema.d.ts","sourceRoot":"","sources":["../../src/lib/theme-schema.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,CAAC,EAAE,KAAK,UAAU,EAAE,MAAM,KAAK,CAAC;AACzC,OAAO,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAA0B,MAAM,mBAAmB,CAAC;AAE/F,qBAAa,wBAAyB,SAAQ,KAAK;IACjD,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;gBACd,MAAM,EAAE,MAAM,EAAE;CAK7B;AAoCD,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAS1B,CAAC;AAEH,2JAA2J;AAC3J,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,SAAS,CAMtD;AAED;;;;;;;GAOG;AACH,wBAAgB,6BAA6B,CAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CAErG;AAED,sVAAsV;AACtV,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,kBAAkB,EAAE,GAAG,UAAU,CAMjF"}
@@ -0,0 +1,112 @@
1
+ // hazo_blog/src/lib/theme-schema.ts — `theme.json` schema (Phase 1b ticket
2
+ // 06). Pure/server-safe (no fs/db/network) — the actual file-presence/
3
+ // Liquid-parse/size/asset-type checks live in `./theme-validate.ts`, which
4
+ // calls `parseThemeJson` here as its first step.
5
+ //
6
+ // `allowedSections` BRIDGE (see `ThemeJson`'s own doc-comment in
7
+ // `../types/index.ts`): this module parses + validates the field, and
8
+ // `getAllowedSectionsForTemplate` below is the one helper a future caller
9
+ // needs to actually narrow a template's allowed section types — but NOTHING
10
+ // in this ticket calls it yet. `../lib/sections.ts`'s `validateSections`
11
+ // (ticket 05) still allows every `SECTION_TYPE_REGISTRY` type on every page,
12
+ // by that ticket's own explicit design ("Default: all types allowed" until
13
+ // a real theme-management system exists). Wiring `getAllowedSectionsForTemplate`
14
+ // into `validateSections` would require THREADING the active theme's
15
+ // `ThemeJson` into every `createPost`/`updatePost` call (today those only
16
+ // see `BlogConfig`, never a theme) — a real, cross-cutting change to the
17
+ // post-save path that's bigger than "parse one more field of theme.json",
18
+ // so it's EXPLICITLY handed off to ticket 07/08 (per this ticket's own
19
+ // instructions) rather than half-wired here.
20
+ import { z } from "zod";
21
+ export class ThemeJsonValidationError extends Error {
22
+ constructor(issues) {
23
+ super(`theme.json failed validation: ${issues.join("; ")}`);
24
+ this.name = "ThemeJsonValidationError";
25
+ this.issues = issues;
26
+ }
27
+ }
28
+ const SETTINGS_FIELD_TYPES = ["colour", "font", "image", "select", "toggle", "text", "range"];
29
+ const settingsOptionSchema = z.object({
30
+ value: z.string().min(1),
31
+ label: z.string().min(1),
32
+ });
33
+ const settingsFieldSchema = z
34
+ .object({
35
+ key: z.string().min(1, "key is required"),
36
+ label: z.string().min(1, "label is required"),
37
+ type: z.enum(SETTINGS_FIELD_TYPES),
38
+ default: z.unknown().optional(),
39
+ helpText: z.string().optional(),
40
+ options: z.array(settingsOptionSchema).optional(),
41
+ min: z.number().optional(),
42
+ max: z.number().optional(),
43
+ step: z.number().optional(),
44
+ })
45
+ .refine((field) => field.type !== "select" || (Array.isArray(field.options) && field.options.length > 0), {
46
+ message: "a 'select' field requires a non-empty options array",
47
+ path: ["options"],
48
+ });
49
+ // Loose semver-ish check (`1.2.3`, optional pre-release/build metadata) —
50
+ // not a full semver grammar, just enough to reject obviously-wrong values
51
+ // like "latest" or "v1".
52
+ // Strict semver, no path-traversal-capable characters: `version` ends up
53
+ // directly inside filesystem/storage paths (theme cache dir, R2 key
54
+ // prefix) in `service/themes.ts`'s `materializeUploadedTheme`/
55
+ // `installThemeFromFiles` — the old `(?:[-+].+)?` tail let `.+` match
56
+ // literally anything, including `/`/`..`, after a `-` or `+`.
57
+ const VERSION_PATTERN = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
58
+ export const themeJsonSchema = z.object({
59
+ name: z.string().min(1, "name is required"),
60
+ version: z.string().regex(VERSION_PATTERN, "version must look like a semver string, e.g. \"1.0.0\""),
61
+ author: z.string().min(1, "author is required"),
62
+ licence: z.string().min(1, "licence is required"),
63
+ description: z.string().optional().default(""),
64
+ screenshots: z.array(z.string()).optional().default([]),
65
+ settings: z.array(settingsFieldSchema).optional().default([]),
66
+ allowedSections: z.record(z.string(), z.array(z.string())).optional(),
67
+ });
68
+ /** Parses+validates a raw `theme.json` payload (already `JSON.parse`d). Throws `ThemeJsonValidationError` with every issue found, never just the first. */
69
+ export function parseThemeJson(raw) {
70
+ const result = themeJsonSchema.safeParse(raw);
71
+ if (!result.success) {
72
+ throw new ThemeJsonValidationError(result.error.issues.map((i) => `${i.path.join(".") || "(root)"}: ${i.message}`));
73
+ }
74
+ return result.data;
75
+ }
76
+ /**
77
+ * Resolves `themeJson.allowedSections` for one template name. `null` means
78
+ * "no restriction configured — every section type is allowed", the SAME
79
+ * fallback `../lib/sections.ts`'s own bridge comment documents; a theme
80
+ * that never sets `allowedSections` at all behaves identically to today
81
+ * (nothing narrows). See this module's header comment for why nothing
82
+ * calls this yet.
83
+ */
84
+ export function getAllowedSectionsForTemplate(themeJson, template) {
85
+ return themeJson.allowedSections?.[template] ?? null;
86
+ }
87
+ /** Builds a Zod schema for validating a settings PATCH against one field's declared type — see `zodForSettingsField`'s own per-type mapping. Every field is `.optional()`: a partial settings update (one key at a time) is the expected shape (`ThemeService.updateThemeSettings` merges onto existing settings, it never requires the full set). */
88
+ export function buildThemeSettingsSchema(fields) {
89
+ const shape = {};
90
+ for (const field of fields) {
91
+ shape[field.key] = zodForSettingsField(field).optional();
92
+ }
93
+ return z.object(shape);
94
+ }
95
+ function zodForSettingsField(field) {
96
+ switch (field.type) {
97
+ case "toggle":
98
+ return z.boolean();
99
+ case "range":
100
+ return z.number();
101
+ case "select": {
102
+ const values = (field.options ?? []).map((o) => o.value);
103
+ return values.length > 0 ? z.enum(values) : z.string();
104
+ }
105
+ case "colour":
106
+ case "font":
107
+ case "image":
108
+ case "text":
109
+ default:
110
+ return z.string();
111
+ }
112
+ }
@@ -0,0 +1,48 @@
1
+ import type { ThemeJson } from "../types/index.js";
2
+ export interface ThemeFile {
3
+ /** Forward-slash-separated, relative to the theme's own root (e.g. `"theme.json"`, `"templates/home.liquid"`, `"assets/style.css"`). Never absolute, never containing a `..` segment — see `isSafeThemeFilePath`. */
4
+ path: string;
5
+ content: Buffer;
6
+ }
7
+ export declare class ThemeValidationError extends Error {
8
+ readonly issues: string[];
9
+ constructor(issues: string[]);
10
+ }
11
+ /** The ticket's own exact required-template list. */
12
+ export declare const REQUIRED_THEME_TEMPLATES: readonly string[];
13
+ /** Asset file types the ticket restricts non-template/non-`theme.json` files to: CSS, JS, images, fonts. */
14
+ export declare const ALLOWED_THEME_ASSET_EXTENSIONS: ReadonlySet<string>;
15
+ /** Default total-uncompressed-size cap — overridable via `BlogConfig.themes.maxUploadBytes`. */
16
+ export declare const DEFAULT_MAX_THEME_UPLOAD_BYTES: number;
17
+ /**
18
+ * Zip-slip guard — re-checked HERE regardless of whether the caller already
19
+ * checked it during zip extraction (defence in depth, same spirit as
20
+ * `rehype-sanitize` being the real XSS boundary even though `sanitizeMdx`
21
+ * already ran first upstream — see the platform's
22
+ * `lib/render-public-post.ts`). Rejects: absolute paths, any `..` segment,
23
+ * any empty segment (leading/trailing/doubled `/`), and backslashes (a
24
+ * Windows-style separator that some zip tools emit, which would otherwise
25
+ * slip past a forward-slash-only `..` check on a platform that still
26
+ * honours it as a separator).
27
+ */
28
+ export declare function isSafeThemeFilePath(rawPath: string): boolean;
29
+ export interface ValidateThemeFilesOptions {
30
+ /** Default `DEFAULT_MAX_THEME_UPLOAD_BYTES`. */
31
+ maxTotalBytes?: number;
32
+ }
33
+ export interface ValidateThemeFilesResult {
34
+ themeJson: ThemeJson;
35
+ }
36
+ /**
37
+ * The full upload-validation pipeline (ticket's own checklist, in order):
38
+ * path safety → `theme.json` present + parses → required templates present
39
+ * → every `.liquid` file parses → total size under the cap → every
40
+ * non-template/non-`theme.json` file is an allowed asset type. Collects
41
+ * EVERY issue found (not just the first) and throws `ThemeValidationError`
42
+ * once, at the end — same "whole input is one all-or-nothing unit"
43
+ * contract as `../lib/sections.ts`'s `SectionValidationError`. Returns the
44
+ * parsed `theme.json` on success, so the caller (`ThemeService.
45
+ * installThemeFromFiles`) doesn't have to parse it a second time.
46
+ */
47
+ export declare function validateThemeFiles(files: ThemeFile[], options?: ValidateThemeFilesOptions): Promise<ValidateThemeFilesResult>;
48
+ //# sourceMappingURL=theme-validate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme-validate.d.ts","sourceRoot":"","sources":["../../src/lib/theme-validate.ts"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,MAAM,WAAW,SAAS;IACxB,qNAAqN;IACrN,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;gBACd,MAAM,EAAE,MAAM,EAAE;CAK7B;AAED,qDAAqD;AACrD,eAAO,MAAM,wBAAwB,EAAE,SAAS,MAAM,EAAoC,CAAC;AAE3F,4GAA4G;AAC5G,eAAO,MAAM,8BAA8B,EAAE,WAAW,CAAC,MAAM,CAiB7D,CAAC;AAEH,gGAAgG;AAChG,eAAO,MAAM,8BAA8B,QAAmB,CAAC;AAE/D;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAK5D;AAMD,MAAM,WAAW,yBAAyB;IACxC,gDAAgD;IAChD,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,wBAAwB;IACvC,SAAS,EAAE,SAAS,CAAC;CACtB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,SAAS,EAAE,EAClB,OAAO,GAAE,yBAA8B,GACtC,OAAO,CAAC,wBAAwB,CAAC,CA6DnC"}
@@ -0,0 +1,149 @@
1
+ // hazo_blog/src/lib/theme-validate.ts — upload validation pipeline (Phase
2
+ // 1b ticket 06). Operates on an already-extracted, in-memory file list
3
+ // (`ThemeFile[]`) — this module never unzips anything itself. The PLATFORM
4
+ // repo owns zip extraction (`uzip`, already available there with no native
5
+ // deps — see the platform's own `lib/theme-zip.ts`), because the ticket's
6
+ // own instruction is to use that rather than adding a zip dependency to
7
+ // this package. Testing this module therefore needs no zip library either:
8
+ // every test here builds a plain `ThemeFile[]` fixture directly.
9
+ //
10
+ // ISOLATION NOTE: this file lazily, dynamically imports `../render/engine.js`
11
+ // (NOT the public `hazo_blog/render` subpath, a direct relative import of
12
+ // this package's own internal module) to reuse `parseLiquidSource` — see
13
+ // that function's own doc-comment for why reusing the real engine's parser
14
+ // matters. The import is a lazy `await import(...)` INSIDE `validateThemeFiles`,
15
+ // never a top-level import, so `liquidjs` is only ever loaded into memory
16
+ // when a theme upload is actually being validated — a host that never
17
+ // installs/activates an uploaded theme (e.g. an add-on consumer on `~1.6`,
18
+ // or a `2.x+` consumer that only uses built-in themes) never pays for it.
19
+ // This is the exact same "keep `./render`'s heavy dependency out of the
20
+ // main entry point's hot path" concern `../render/index.ts`'s own header
21
+ // comment documents — satisfied here via laziness rather than via the
22
+ // `hazo_blog/render` subpath boundary, since this code genuinely needs db-
23
+ // free, fs-free Liquid PARSING (not rendering) from inside the main
24
+ // `hazo_blog` entry point's own tenant-aware theme service.
25
+ import * as path from "node:path";
26
+ import { parseThemeJson } from "./theme-schema.js";
27
+ export class ThemeValidationError extends Error {
28
+ constructor(issues) {
29
+ super(`Theme validation failed: ${issues.join("; ")}`);
30
+ this.name = "ThemeValidationError";
31
+ this.issues = issues;
32
+ }
33
+ }
34
+ /** The ticket's own exact required-template list. */
35
+ export const REQUIRED_THEME_TEMPLATES = ["home", "post", "page", "404"];
36
+ /** Asset file types the ticket restricts non-template/non-`theme.json` files to: CSS, JS, images, fonts. */
37
+ export const ALLOWED_THEME_ASSET_EXTENSIONS = new Set([
38
+ ".css",
39
+ ".js",
40
+ ".mjs",
41
+ ".png",
42
+ ".jpg",
43
+ ".jpeg",
44
+ ".gif",
45
+ ".svg",
46
+ ".webp",
47
+ ".avif",
48
+ ".ico",
49
+ ".woff",
50
+ ".woff2",
51
+ ".ttf",
52
+ ".otf",
53
+ ".eot",
54
+ ]);
55
+ /** Default total-uncompressed-size cap — overridable via `BlogConfig.themes.maxUploadBytes`. */
56
+ export const DEFAULT_MAX_THEME_UPLOAD_BYTES = 20 * 1024 * 1024; // 20 MiB
57
+ /**
58
+ * Zip-slip guard — re-checked HERE regardless of whether the caller already
59
+ * checked it during zip extraction (defence in depth, same spirit as
60
+ * `rehype-sanitize` being the real XSS boundary even though `sanitizeMdx`
61
+ * already ran first upstream — see the platform's
62
+ * `lib/render-public-post.ts`). Rejects: absolute paths, any `..` segment,
63
+ * any empty segment (leading/trailing/doubled `/`), and backslashes (a
64
+ * Windows-style separator that some zip tools emit, which would otherwise
65
+ * slip past a forward-slash-only `..` check on a platform that still
66
+ * honours it as a separator).
67
+ */
68
+ export function isSafeThemeFilePath(rawPath) {
69
+ if (!rawPath || rawPath.includes("\\"))
70
+ return false;
71
+ if (path.posix.isAbsolute(rawPath) || path.win32.isAbsolute(rawPath))
72
+ return false;
73
+ const segments = rawPath.split("/");
74
+ return segments.every((segment) => segment !== "" && segment !== "." && segment !== "..");
75
+ }
76
+ function findFile(files, wantedPath) {
77
+ return files.find((f) => f.path === wantedPath);
78
+ }
79
+ /**
80
+ * The full upload-validation pipeline (ticket's own checklist, in order):
81
+ * path safety → `theme.json` present + parses → required templates present
82
+ * → every `.liquid` file parses → total size under the cap → every
83
+ * non-template/non-`theme.json` file is an allowed asset type. Collects
84
+ * EVERY issue found (not just the first) and throws `ThemeValidationError`
85
+ * once, at the end — same "whole input is one all-or-nothing unit"
86
+ * contract as `../lib/sections.ts`'s `SectionValidationError`. Returns the
87
+ * parsed `theme.json` on success, so the caller (`ThemeService.
88
+ * installThemeFromFiles`) doesn't have to parse it a second time.
89
+ */
90
+ export async function validateThemeFiles(files, options = {}) {
91
+ const issues = [];
92
+ const maxTotalBytes = options.maxTotalBytes ?? DEFAULT_MAX_THEME_UPLOAD_BYTES;
93
+ // Path safety first, and fatal on its own: nothing below can be trusted
94
+ // to mean what it says (e.g. "required template present") if a path
95
+ // might actually point outside the theme's own root.
96
+ const unsafePaths = files.filter((f) => !isSafeThemeFilePath(f.path));
97
+ if (unsafePaths.length > 0) {
98
+ throw new ThemeValidationError(unsafePaths.map((f) => `unsafe file path: "${f.path}"`));
99
+ }
100
+ const totalBytes = files.reduce((sum, f) => sum + f.content.byteLength, 0);
101
+ if (totalBytes > maxTotalBytes) {
102
+ issues.push(`theme exceeds the maximum upload size (${totalBytes} bytes > ${maxTotalBytes} bytes)`);
103
+ }
104
+ let themeJson = null;
105
+ const themeJsonFile = findFile(files, "theme.json");
106
+ if (!themeJsonFile) {
107
+ issues.push('missing required file: "theme.json"');
108
+ }
109
+ else {
110
+ try {
111
+ const raw = JSON.parse(themeJsonFile.content.toString("utf-8"));
112
+ themeJson = parseThemeJson(raw);
113
+ }
114
+ catch (err) {
115
+ const message = err instanceof Error ? err.message : String(err);
116
+ issues.push(`"theme.json" is invalid: ${message}`);
117
+ }
118
+ }
119
+ for (const name of REQUIRED_THEME_TEMPLATES) {
120
+ if (!findFile(files, `templates/${name}.liquid`)) {
121
+ issues.push(`missing required template: "templates/${name}.liquid"`);
122
+ }
123
+ }
124
+ const liquidFiles = files.filter((f) => f.path.endsWith(".liquid"));
125
+ if (liquidFiles.length > 0) {
126
+ // Lazy — see this module's header comment.
127
+ const { parseLiquidSource } = await import("../render/engine.js");
128
+ for (const f of liquidFiles) {
129
+ try {
130
+ parseLiquidSource(f.content.toString("utf-8"));
131
+ }
132
+ catch (err) {
133
+ const message = err instanceof Error ? err.message : String(err);
134
+ issues.push(`"${f.path}" failed to parse as Liquid: ${message}`);
135
+ }
136
+ }
137
+ }
138
+ for (const f of files) {
139
+ if (f.path === "theme.json" || f.path.endsWith(".liquid"))
140
+ continue;
141
+ const ext = path.extname(f.path).toLowerCase();
142
+ if (!ALLOWED_THEME_ASSET_EXTENSIONS.has(ext)) {
143
+ issues.push(`disallowed asset file type: "${f.path}" (only CSS/JS/images/fonts are allowed)`);
144
+ }
145
+ }
146
+ if (issues.length > 0)
147
+ throw new ThemeValidationError(issues);
148
+ return { themeJson: themeJson };
149
+ }
@@ -0,0 +1,67 @@
1
+ import type { BlogConfig } from "../types/index.js";
2
+ type RouteCtx = {
3
+ params: Promise<Record<string, string>>;
4
+ } | {
5
+ params: Record<string, string>;
6
+ };
7
+ /**
8
+ * Collection routes for a Next.js `/api/.../bylines` route.
9
+ * GET — list every byline in scope (scope: blog:read)
10
+ * POST — create a byline (scope: blog:write)
11
+ */
12
+ export declare function createBylineManageRoutes(config: BlogConfig): {
13
+ GET: (req: Request) => Promise<Response>;
14
+ POST: (req: Request) => Promise<Response>;
15
+ };
16
+ /**
17
+ * Single-byline routes for a Next.js `/api/.../bylines/[id]` dynamic route.
18
+ * GET — fetch one byline by id (scope: blog:read)
19
+ * PATCH — update by id (scope: blog:write)
20
+ * DELETE — hard delete by id — also removes every post assignment via the
21
+ * DB's `ON DELETE CASCADE` on `hazo_blog_post_bylines.byline_id` (scope: blog:write)
22
+ */
23
+ export declare function createBylineItemRoutes(config: BlogConfig): {
24
+ GET: (req: Request, ctx?: RouteCtx | undefined) => Promise<Response>;
25
+ PATCH: (req: Request, ctx?: RouteCtx | undefined) => Promise<Response>;
26
+ DELETE: (req: Request, ctx?: RouteCtx | undefined) => Promise<Response>;
27
+ };
28
+ /**
29
+ * List posts carrying a given byline — `/api/.../bylines/[id]/posts`.
30
+ * GET — paginated `PaginatedPostsResult` (scope: blog:read). 404
31
+ * `NOT_FOUND` if the byline id doesn't resolve in scope.
32
+ */
33
+ export declare function createBylinePostsRoutes(config: BlogConfig): {
34
+ GET: (req: Request, ctx?: RouteCtx | undefined) => Promise<Response>;
35
+ };
36
+ /**
37
+ * A post's bylines — `/api/.../posts/[id]/bylines`.
38
+ * GET — bylines assigned to the post, ordered by position (scope: blog:read)
39
+ * POST — assign a byline to the post; body `{ bylineId, position? }` (scope: blog:write).
40
+ * 404 `NOT_FOUND` if either the post or the byline doesn't resolve in scope.
41
+ */
42
+ export declare function createPostBylinesRoutes(config: BlogConfig): {
43
+ GET: (req: Request, ctx?: RouteCtx | undefined) => Promise<Response>;
44
+ POST: (req: Request, ctx?: RouteCtx | undefined) => Promise<Response>;
45
+ };
46
+ /**
47
+ * Remove one byline from a post — `/api/.../posts/[id]/bylines/[bylineId]`.
48
+ * DELETE — idempotent (scope: blog:write). 404 `NOT_FOUND` if the post
49
+ * doesn't resolve in scope (removing an assignment that was never there is
50
+ * a no-op, not an error — see `BylineRepository.removeBylineFromPost`).
51
+ */
52
+ export declare function createPostBylineItemRoutes(config: BlogConfig): {
53
+ DELETE: (req: Request, ctx?: RouteCtx | undefined) => Promise<Response>;
54
+ };
55
+ /**
56
+ * Reorder a post's bylines — `/api/.../posts/[id]/bylines/reorder`. Mounted
57
+ * on its own resource rather than another method on `[id]/bylines`, same
58
+ * reasoning as `createPostCompareRoutes` in `../next/post-routes.ts`.
59
+ * POST — body `{ orderedBylineIds: string[] }` → the post's bylines in
60
+ * their new order (scope: blog:write). 404 `NOT_FOUND` if the post doesn't
61
+ * resolve in scope.
62
+ */
63
+ export declare function createPostBylinesReorderRoutes(config: BlogConfig): {
64
+ POST: (req: Request, ctx?: RouteCtx | undefined) => Promise<Response>;
65
+ };
66
+ export {};
67
+ //# sourceMappingURL=byline-routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"byline-routes.d.ts","sourceRoot":"","sources":["../../src/next/byline-routes.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,UAAU,EAAwC,MAAM,mBAAmB,CAAC;AAE1F,KAAK,QAAQ,GAAG;IAAE,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,CAAC;AAoBjG;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,UAAU;;;EAgC1D;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,UAAU;;;;EAmDxD;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,UAAU;;EAqBzD;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,UAAU;;;EAyCzD;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,UAAU;;EAkB5D;AAED;;;;;;;GAOG;AACH,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,UAAU;;EA8BhE"}