@platformos/platformos-check-common 0.0.16 → 0.0.18
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 +14 -0
- package/dist/checks/index.d.ts +1 -1
- package/dist/checks/index.js +6 -2
- package/dist/checks/index.js.map +1 -1
- package/dist/checks/json-literal-quote-style/index.d.ts +2 -0
- package/dist/checks/json-literal-quote-style/index.js +42 -0
- package/dist/checks/json-literal-quote-style/index.js.map +1 -0
- package/dist/checks/liquid-html-syntax-error/checks/InvalidAssignSyntax.d.ts +21 -0
- package/dist/checks/liquid-html-syntax-error/checks/InvalidAssignSyntax.js +60 -0
- package/dist/checks/liquid-html-syntax-error/checks/InvalidAssignSyntax.js.map +1 -0
- package/dist/checks/liquid-html-syntax-error/checks/InvalidOutputPush.d.ts +17 -0
- package/dist/checks/liquid-html-syntax-error/checks/InvalidOutputPush.js +37 -0
- package/dist/checks/liquid-html-syntax-error/checks/InvalidOutputPush.js.map +1 -0
- package/dist/checks/liquid-html-syntax-error/checks/InvalidTagSyntax.js +1 -1
- package/dist/checks/liquid-html-syntax-error/index.js +17 -0
- package/dist/checks/liquid-html-syntax-error/index.js.map +1 -1
- package/dist/checks/partial-call-arguments/extract-undefined-variables.d.ts +14 -0
- package/dist/checks/partial-call-arguments/extract-undefined-variables.js +234 -0
- package/dist/checks/partial-call-arguments/extract-undefined-variables.js.map +1 -0
- package/dist/checks/partial-call-arguments/index.d.ts +2 -0
- package/dist/checks/partial-call-arguments/index.js +117 -0
- package/dist/checks/partial-call-arguments/index.js.map +1 -0
- package/dist/checks/unknown-property/index.js +22 -2
- package/dist/checks/unknown-property/index.js.map +1 -1
- package/dist/checks/valid-frontmatter/index.d.ts +2 -0
- package/dist/checks/valid-frontmatter/index.js +279 -0
- package/dist/checks/valid-frontmatter/index.js.map +1 -0
- package/dist/frontmatter/index.d.ts +1 -59
- package/dist/frontmatter/index.js +6 -298
- package/dist/frontmatter/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/checks/index.ts +6 -2
- package/src/checks/json-literal-quote-style/index.spec.ts +129 -0
- package/src/checks/json-literal-quote-style/index.ts +45 -0
- package/src/checks/liquid-html-syntax-error/checks/InvalidAssignSyntax.spec.ts +422 -0
- package/src/checks/liquid-html-syntax-error/checks/InvalidAssignSyntax.ts +63 -0
- package/src/checks/liquid-html-syntax-error/checks/InvalidOutputPush.spec.ts +104 -0
- package/src/checks/liquid-html-syntax-error/checks/InvalidOutputPush.ts +39 -0
- package/src/checks/liquid-html-syntax-error/checks/InvalidTagSyntax.spec.ts +86 -2
- package/src/checks/liquid-html-syntax-error/checks/InvalidTagSyntax.ts +1 -1
- package/src/checks/liquid-html-syntax-error/index.ts +19 -0
- package/src/checks/partial-call-arguments/extract-undefined-variables.spec.ts +218 -0
- package/src/checks/{metadata-params → partial-call-arguments}/extract-undefined-variables.ts +31 -6
- package/src/checks/partial-call-arguments/index.spec.ts +436 -0
- package/src/checks/{metadata-params → partial-call-arguments}/index.ts +18 -11
- package/src/checks/undefined-object/index.spec.ts +101 -0
- package/src/checks/unknown-property/index.spec.ts +42 -0
- package/src/checks/unknown-property/index.ts +24 -2
- package/src/checks/valid-frontmatter/index.spec.ts +666 -0
- package/src/checks/valid-frontmatter/index.ts +344 -0
- package/src/frontmatter/index.ts +9 -344
- package/src/checks/metadata-params/extract-undefined-variables.spec.ts +0 -115
- package/src/checks/metadata-params/index.spec.ts +0 -257
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import { isMap, isScalar, isSeq, parseDocument } from 'yaml';
|
|
2
|
+
import { LiquidCheckDefinition, RelativePath, Severity, SourceCodeType } from '../../types';
|
|
3
|
+
import {
|
|
4
|
+
containsLiquid,
|
|
5
|
+
FRONTMATTER_ASSOCIATION_DIRS,
|
|
6
|
+
getFrontmatterSchema,
|
|
7
|
+
getFileType,
|
|
8
|
+
PlatformOSFileType,
|
|
9
|
+
} from '@platformos/platformos-common';
|
|
10
|
+
import { doesFileExist } from '../../utils/file-utils';
|
|
11
|
+
|
|
12
|
+
export const ValidFrontmatter: LiquidCheckDefinition = {
|
|
13
|
+
meta: {
|
|
14
|
+
code: 'ValidFrontmatter',
|
|
15
|
+
name: 'Valid Frontmatter',
|
|
16
|
+
docs: {
|
|
17
|
+
description:
|
|
18
|
+
'Validates YAML frontmatter properties (required fields, allowed values, deprecated keys) for known platformOS file types.',
|
|
19
|
+
recommended: true,
|
|
20
|
+
url: undefined,
|
|
21
|
+
},
|
|
22
|
+
type: SourceCodeType.LiquidHtml,
|
|
23
|
+
severity: Severity.WARNING,
|
|
24
|
+
schema: {},
|
|
25
|
+
targets: [],
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
create(context) {
|
|
29
|
+
return {
|
|
30
|
+
async onCodePathStart(file) {
|
|
31
|
+
const source = file.source;
|
|
32
|
+
|
|
33
|
+
if (/(?:^|\/)home\.html\.liquid$/.test(file.uri)) {
|
|
34
|
+
context.report({
|
|
35
|
+
message:
|
|
36
|
+
"'home.html.liquid' is deprecated. Rename to 'index.html.liquid' to serve as the root page.",
|
|
37
|
+
startIndex: 0,
|
|
38
|
+
endIndex: 0,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Locate the frontmatter block — may be preceded by whitespace
|
|
43
|
+
const trimmed = source.trimStart();
|
|
44
|
+
if (!trimmed.startsWith('---')) return;
|
|
45
|
+
|
|
46
|
+
const leadingLen = source.length - trimmed.length;
|
|
47
|
+
const firstNewline = trimmed.indexOf('\n');
|
|
48
|
+
if (firstNewline === -1) return;
|
|
49
|
+
|
|
50
|
+
const afterOpening = trimmed.slice(firstNewline + 1);
|
|
51
|
+
|
|
52
|
+
// The closing `---` may be the very first line of afterOpening (empty frontmatter)
|
|
53
|
+
// or may follow a newline (normal frontmatter with content).
|
|
54
|
+
let yamlBody: string;
|
|
55
|
+
if (afterOpening.startsWith('---')) {
|
|
56
|
+
yamlBody = '';
|
|
57
|
+
} else {
|
|
58
|
+
const closeIdx = afterOpening.indexOf('\n---');
|
|
59
|
+
if (closeIdx === -1) return;
|
|
60
|
+
yamlBody = afterOpening.slice(0, closeIdx);
|
|
61
|
+
}
|
|
62
|
+
// Absolute offset of the first character of yamlBody in source
|
|
63
|
+
const bodyOffset = leadingLen + firstNewline + 1;
|
|
64
|
+
|
|
65
|
+
const fileType = getFileType(file.uri);
|
|
66
|
+
const schema = getFrontmatterSchema(fileType);
|
|
67
|
+
if (!schema) return;
|
|
68
|
+
|
|
69
|
+
// Parse YAML with position tracking (yaml v2 provides range arrays).
|
|
70
|
+
// Continue even when the document has parse errors — parseDocument is
|
|
71
|
+
// lenient and still builds a partial map for the valid pairs it finds.
|
|
72
|
+
// Normalize CRLF → LF so YAML values don't contain stray \r characters.
|
|
73
|
+
const doc = parseDocument(yamlBody.replace(/\r\n/g, '\n').replace(/\r/g, '\n'));
|
|
74
|
+
|
|
75
|
+
// Build lookup: key → { jsValue, absStart, absEnd, valueAbsStart, valueAbsEnd }
|
|
76
|
+
type Entry = {
|
|
77
|
+
jsValue: unknown;
|
|
78
|
+
absStart: number;
|
|
79
|
+
absEnd: number;
|
|
80
|
+
valueAbsStart: number;
|
|
81
|
+
valueAbsEnd: number;
|
|
82
|
+
};
|
|
83
|
+
const entries = new Map<string, Entry>();
|
|
84
|
+
|
|
85
|
+
// Only populate entries when the document parsed to a map (non-empty frontmatter).
|
|
86
|
+
// When frontmatter is empty (`---\n---\n`) doc.contents is null — entries stays empty
|
|
87
|
+
// and required-field validation below will still fire correctly.
|
|
88
|
+
if (isMap(doc.contents)) {
|
|
89
|
+
for (const pair of doc.contents.items) {
|
|
90
|
+
const keyNode = pair.key;
|
|
91
|
+
if (!isScalar(keyNode) || typeof keyNode.value !== 'string') continue;
|
|
92
|
+
const [ks = 0, ke = 0] = keyNode.range ?? [];
|
|
93
|
+
const valNode = isScalar(pair.value) ? pair.value : undefined;
|
|
94
|
+
const jsValue = valNode?.value;
|
|
95
|
+
const [vs = 0, ve = 0] = valNode?.range ?? [];
|
|
96
|
+
entries.set(keyNode.value, {
|
|
97
|
+
jsValue,
|
|
98
|
+
absStart: bodyOffset + ks,
|
|
99
|
+
absEnd: bodyOffset + ke,
|
|
100
|
+
valueAbsStart: bodyOffset + vs,
|
|
101
|
+
valueAbsEnd: bodyOffset + ve,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const frontmatterStart = leadingLen; // position of opening `---`
|
|
107
|
+
|
|
108
|
+
// 1. Required field validation
|
|
109
|
+
for (const [fieldName, fieldSchema] of Object.entries(schema.fields)) {
|
|
110
|
+
if (fieldSchema.required && !entries.has(fieldName)) {
|
|
111
|
+
context.report({
|
|
112
|
+
message: `Missing required frontmatter field '${fieldName}' in ${schema.name} file`,
|
|
113
|
+
startIndex: frontmatterStart,
|
|
114
|
+
endIndex: frontmatterStart + 3,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// 2. Unrecognized key warnings
|
|
120
|
+
for (const [key, entry] of entries) {
|
|
121
|
+
if (!(key in schema.fields)) {
|
|
122
|
+
context.report({
|
|
123
|
+
message: `Unknown frontmatter field '${key}' in ${schema.name} file`,
|
|
124
|
+
startIndex: entry.absStart,
|
|
125
|
+
endIndex: entry.absEnd,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// 3. Deprecated field warnings
|
|
131
|
+
for (const [key, entry] of entries) {
|
|
132
|
+
const fieldSchema = schema.fields[key];
|
|
133
|
+
if (fieldSchema?.deprecated) {
|
|
134
|
+
context.report({
|
|
135
|
+
message: fieldSchema.deprecatedMessage ?? `'${key}' is deprecated`,
|
|
136
|
+
startIndex: entry.absStart,
|
|
137
|
+
endIndex: entry.absEnd,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// 4. Enum validation — allowed values are defined in the schema.
|
|
143
|
+
// Comparison is case-insensitive for string values: both the field value and
|
|
144
|
+
// each enum entry are lowercased before comparing, so `GET` matches `get` etc.
|
|
145
|
+
for (const [key, entry] of entries) {
|
|
146
|
+
const fieldSchema = schema.fields[key];
|
|
147
|
+
if (!fieldSchema?.enumValues) continue;
|
|
148
|
+
const { jsValue, absStart, absEnd } = entry;
|
|
149
|
+
// Skip enum validation for Liquid expressions — they're dynamic and can't be statically checked.
|
|
150
|
+
if (typeof jsValue === 'string' && containsLiquid(jsValue)) continue;
|
|
151
|
+
const normalizedValue = typeof jsValue === 'string' ? jsValue.toLowerCase() : jsValue;
|
|
152
|
+
const matches = fieldSchema.enumValues.some((allowed) =>
|
|
153
|
+
typeof allowed === 'string'
|
|
154
|
+
? allowed.toLowerCase() === normalizedValue
|
|
155
|
+
: allowed === normalizedValue,
|
|
156
|
+
);
|
|
157
|
+
if (!matches) {
|
|
158
|
+
context.report({
|
|
159
|
+
message: `Invalid value '${jsValue}' for '${key}'. Must be one of: ${fieldSchema.enumValues.join(', ')}`,
|
|
160
|
+
startIndex: absStart,
|
|
161
|
+
endIndex: absEnd,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// 5. Layout association validation (Page and Email).
|
|
167
|
+
// Both types share the primary `layout` key; deprecated aliases differ per type.
|
|
168
|
+
if (fileType === PlatformOSFileType.Page || fileType === PlatformOSFileType.Email) {
|
|
169
|
+
const deprecatedAlias =
|
|
170
|
+
fileType === PlatformOSFileType.Page ? 'layout_name' : 'layout_path';
|
|
171
|
+
const layoutEntry = entries.get('layout') ?? entries.get(deprecatedAlias);
|
|
172
|
+
if (layoutEntry) {
|
|
173
|
+
if (layoutEntry.jsValue === false) {
|
|
174
|
+
// `layout: false` (YAML boolean) does NOT disable the layout — it falls back to the
|
|
175
|
+
// instance default. Use `layout: ''` to explicitly disable layout rendering.
|
|
176
|
+
context.report({
|
|
177
|
+
message:
|
|
178
|
+
"`layout: false` falls back to the default layout. Use `layout: ''` to disable layout rendering.",
|
|
179
|
+
startIndex: layoutEntry.valueAbsStart,
|
|
180
|
+
endIndex: layoutEntry.valueAbsEnd,
|
|
181
|
+
suggest: [
|
|
182
|
+
{
|
|
183
|
+
message: "Replace with `layout: ''`",
|
|
184
|
+
fix: (corrector) => {
|
|
185
|
+
corrector.replace(layoutEntry.valueAbsStart, layoutEntry.valueAbsEnd, "''");
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
});
|
|
190
|
+
} else if (
|
|
191
|
+
typeof layoutEntry.jsValue === 'string' &&
|
|
192
|
+
layoutEntry.jsValue !== '' &&
|
|
193
|
+
!containsLiquid(layoutEntry.jsValue)
|
|
194
|
+
) {
|
|
195
|
+
await checkLayoutExists(layoutEntry.jsValue, layoutEntry, context);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// 6. Authorization policy association validation (Page)
|
|
201
|
+
if (fileType === PlatformOSFileType.Page) {
|
|
202
|
+
await checkNotificationArray(
|
|
203
|
+
doc,
|
|
204
|
+
bodyOffset,
|
|
205
|
+
'authorization_policies',
|
|
206
|
+
`app/${FRONTMATTER_ASSOCIATION_DIRS['authorization_policies']}`,
|
|
207
|
+
'Authorization policy',
|
|
208
|
+
context,
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// 7. Notification association validation (FormConfiguration)
|
|
213
|
+
if (fileType === PlatformOSFileType.FormConfiguration) {
|
|
214
|
+
for (const [field, dir] of Object.entries(FRONTMATTER_ASSOCIATION_DIRS)) {
|
|
215
|
+
if (field === 'authorization_policies') continue; // only on Page, handled above
|
|
216
|
+
await checkNotificationArray(
|
|
217
|
+
doc,
|
|
218
|
+
bodyOffset,
|
|
219
|
+
field,
|
|
220
|
+
`app/${dir}`,
|
|
221
|
+
fieldLabel(field),
|
|
222
|
+
context,
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
},
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Checks each string item of a YAML sequence field against the filesystem.
|
|
233
|
+
*
|
|
234
|
+
* App-level items (e.g. `require_login`) are looked up at `{dir}/{name}.liquid`.
|
|
235
|
+
* Module-prefixed items (e.g. `modules/community/require_login`) are looked up
|
|
236
|
+
* at modules/{mod}/{public|private}/{moduleDir}/{name}.liquid where moduleDir
|
|
237
|
+
* is derived from dir by stripping the leading `app/` segment.
|
|
238
|
+
*/
|
|
239
|
+
async function checkNotificationArray(
|
|
240
|
+
doc: ReturnType<typeof parseDocument>,
|
|
241
|
+
bodyOffset: number,
|
|
242
|
+
fieldName: string,
|
|
243
|
+
dir: string,
|
|
244
|
+
label: string,
|
|
245
|
+
context: Parameters<LiquidCheckDefinition['create']>[0],
|
|
246
|
+
) {
|
|
247
|
+
if (!isMap(doc.contents)) return;
|
|
248
|
+
const pair = doc.contents.items.find((p) => isScalar(p.key) && p.key.value === fieldName);
|
|
249
|
+
if (!pair || !isSeq(pair.value)) return;
|
|
250
|
+
|
|
251
|
+
// Module-relative dir: strip leading 'app/' (e.g. 'app/authorization_policies' → 'authorization_policies')
|
|
252
|
+
const moduleDir = dir.slice('app/'.length);
|
|
253
|
+
|
|
254
|
+
for (const item of pair.value.items) {
|
|
255
|
+
if (!isScalar(item) || typeof item.value !== 'string') continue;
|
|
256
|
+
const name = item.value;
|
|
257
|
+
if (containsLiquid(name)) continue;
|
|
258
|
+
const [is = 0, ie = 0] = item.range ?? [];
|
|
259
|
+
|
|
260
|
+
let exists: boolean;
|
|
261
|
+
if (name.startsWith('modules/')) {
|
|
262
|
+
const match = name.match(/^modules\/([^/]+)\/(.+)$/);
|
|
263
|
+
if (!match) {
|
|
264
|
+
exists = false;
|
|
265
|
+
} else {
|
|
266
|
+
const [, mod, rest] = match;
|
|
267
|
+
exists =
|
|
268
|
+
(await doesFileExist(
|
|
269
|
+
context,
|
|
270
|
+
`modules/${mod}/public/${moduleDir}/${rest}.liquid` as RelativePath,
|
|
271
|
+
)) ||
|
|
272
|
+
(await doesFileExist(
|
|
273
|
+
context,
|
|
274
|
+
`modules/${mod}/private/${moduleDir}/${rest}.liquid` as RelativePath,
|
|
275
|
+
));
|
|
276
|
+
}
|
|
277
|
+
} else {
|
|
278
|
+
exists = await doesFileExist(context, `${dir}/${name}.liquid` as RelativePath);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (!exists) {
|
|
282
|
+
context.report({
|
|
283
|
+
message: `${label} '${name}' does not exist`,
|
|
284
|
+
startIndex: bodyOffset + is,
|
|
285
|
+
endIndex: bodyOffset + ie,
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Tries both `{base}.liquid` and `{base}.html.liquid` since layout files may
|
|
293
|
+
* carry a format extension (e.g. `application.html.liquid`).
|
|
294
|
+
*/
|
|
295
|
+
async function layoutFileExists(
|
|
296
|
+
context: Parameters<LiquidCheckDefinition['create']>[0],
|
|
297
|
+
base: string,
|
|
298
|
+
): Promise<boolean> {
|
|
299
|
+
return (
|
|
300
|
+
(await doesFileExist(context, `${base}.liquid` as RelativePath)) ||
|
|
301
|
+
(await doesFileExist(context, `${base}.html.liquid` as RelativePath))
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
async function checkLayoutExists(
|
|
306
|
+
layoutName: string,
|
|
307
|
+
entry: { absStart: number; absEnd: number },
|
|
308
|
+
context: Parameters<LiquidCheckDefinition['create']>[0],
|
|
309
|
+
) {
|
|
310
|
+
let exists: boolean;
|
|
311
|
+
|
|
312
|
+
if (layoutName.startsWith('modules/')) {
|
|
313
|
+
// modules/{mod}/rest → modules/{mod}/{public,private}/views/layouts/{rest}.{html.}liquid
|
|
314
|
+
const match = layoutName.match(/^modules\/([^/]+)\/(.+)$/);
|
|
315
|
+
if (!match) return;
|
|
316
|
+
const [, mod, rest] = match;
|
|
317
|
+
exists =
|
|
318
|
+
(await layoutFileExists(context, `modules/${mod}/public/views/layouts/${rest}`)) ||
|
|
319
|
+
(await layoutFileExists(context, `modules/${mod}/private/views/layouts/${rest}`));
|
|
320
|
+
} else {
|
|
321
|
+
exists = await layoutFileExists(context, `app/views/layouts/${layoutName}`);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
if (!exists) {
|
|
325
|
+
context.report({
|
|
326
|
+
message: `Layout '${layoutName}' does not exist`,
|
|
327
|
+
startIndex: entry.absStart,
|
|
328
|
+
endIndex: entry.absEnd,
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function fieldLabel(field: string): string {
|
|
334
|
+
switch (field) {
|
|
335
|
+
case 'email_notifications':
|
|
336
|
+
return 'Email notification';
|
|
337
|
+
case 'sms_notifications':
|
|
338
|
+
return 'SMS notification';
|
|
339
|
+
case 'api_call_notifications':
|
|
340
|
+
return 'API call notification';
|
|
341
|
+
default:
|
|
342
|
+
return field;
|
|
343
|
+
}
|
|
344
|
+
}
|
package/src/frontmatter/index.ts
CHANGED
|
@@ -1,344 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* - FrontmatterSchema — type definition for a complete schema
|
|
11
|
-
* - FRONTMATTER_SCHEMAS — per-type schemas keyed by PlatformOSFileType
|
|
12
|
-
* - getFrontmatterSchema() — convenience lookup that returns undefined for
|
|
13
|
-
* types without a frontmatter schema
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { PlatformOSFileType } from '@platformos/platformos-common';
|
|
17
|
-
|
|
18
|
-
// ─── Types ────────────────────────────────────────────────────────────────────
|
|
19
|
-
|
|
20
|
-
export type FrontmatterFieldType = 'string' | 'boolean' | 'integer' | 'number' | 'array' | 'object';
|
|
21
|
-
|
|
22
|
-
export interface FrontmatterFieldSchema {
|
|
23
|
-
/** The expected YAML type(s) for this field's value. */
|
|
24
|
-
type: FrontmatterFieldType | FrontmatterFieldType[];
|
|
25
|
-
/** Whether this field must be present. */
|
|
26
|
-
required?: boolean;
|
|
27
|
-
/** Human-readable description of this field. */
|
|
28
|
-
description?: string;
|
|
29
|
-
/** Whether this field name is deprecated in favour of a newer one. */
|
|
30
|
-
deprecated?: boolean;
|
|
31
|
-
/** Message shown when this deprecated field is used. */
|
|
32
|
-
deprecatedMessage?: string;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface FrontmatterSchema {
|
|
36
|
-
/** Human-readable name of the file type, used in diagnostics. */
|
|
37
|
-
name: string;
|
|
38
|
-
/**
|
|
39
|
-
* Known frontmatter fields.
|
|
40
|
-
* Checks can use this to surface unknown keys or missing required keys.
|
|
41
|
-
*/
|
|
42
|
-
fields: Record<string, FrontmatterFieldSchema>;
|
|
43
|
-
/**
|
|
44
|
-
* Whether fields not listed in `fields` are allowed without a warning.
|
|
45
|
-
* Defaults to true — schemas are additive and may not be exhaustive.
|
|
46
|
-
*/
|
|
47
|
-
allowAdditionalFields?: boolean;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// ─── Schemas ──────────────────────────────────────────────────────────────────
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Per-type frontmatter schemas.
|
|
54
|
-
*
|
|
55
|
-
* Only Liquid file types are present here — GraphQL, YAML, and Asset types
|
|
56
|
-
* do not use frontmatter.
|
|
57
|
-
*
|
|
58
|
-
* Field lists are based on real-world usage in platformOS apps. Set
|
|
59
|
-
* `allowAdditionalFields: true` (the default) everywhere so that apps using
|
|
60
|
-
* custom/undocumented keys don't get false-positive warnings until the schemas
|
|
61
|
-
* are finalised.
|
|
62
|
-
*/
|
|
63
|
-
export const FRONTMATTER_SCHEMAS: Partial<Record<PlatformOSFileType, FrontmatterSchema>> = {
|
|
64
|
-
// ── Page ─────────────────────────────────────────────────────────────────────
|
|
65
|
-
[PlatformOSFileType.Page]: {
|
|
66
|
-
name: 'Page',
|
|
67
|
-
fields: {
|
|
68
|
-
slug: {
|
|
69
|
-
type: 'string',
|
|
70
|
-
description: 'URL slug for this page. Supports dynamic segments (e.g. users/:id).',
|
|
71
|
-
},
|
|
72
|
-
layout: {
|
|
73
|
-
type: 'string',
|
|
74
|
-
description: 'Layout template to wrap this page (path relative to app root, no extension).',
|
|
75
|
-
},
|
|
76
|
-
layout_name: {
|
|
77
|
-
type: 'string',
|
|
78
|
-
description: 'Alias for layout.',
|
|
79
|
-
deprecated: true,
|
|
80
|
-
deprecatedMessage: 'Use `layout` instead of `layout_name`.',
|
|
81
|
-
},
|
|
82
|
-
method: {
|
|
83
|
-
type: 'string',
|
|
84
|
-
description: 'HTTP method this page responds to (get, post, put, patch, delete).',
|
|
85
|
-
},
|
|
86
|
-
authorization_policies: {
|
|
87
|
-
type: 'array',
|
|
88
|
-
description: 'List of authorization policy names that must pass before rendering.',
|
|
89
|
-
},
|
|
90
|
-
response_headers: {
|
|
91
|
-
type: 'string',
|
|
92
|
-
description: 'Liquid template that renders a JSON object of HTTP response headers.',
|
|
93
|
-
},
|
|
94
|
-
metadata: {
|
|
95
|
-
type: 'object',
|
|
96
|
-
description: 'Arbitrary metadata object (e.g. SEO title/description, robots directives).',
|
|
97
|
-
},
|
|
98
|
-
max_deep_level: {
|
|
99
|
-
type: 'integer',
|
|
100
|
-
description: 'Maximum number of dynamic URL segments to capture.',
|
|
101
|
-
},
|
|
102
|
-
searchable: {
|
|
103
|
-
type: 'boolean',
|
|
104
|
-
description: 'Whether this page is included in platformOS search indexes.',
|
|
105
|
-
},
|
|
106
|
-
format: {
|
|
107
|
-
type: 'string',
|
|
108
|
-
description: 'Response format (html, json, xml, csv, …). Often encoded in the filename.',
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
allowAdditionalFields: true,
|
|
112
|
-
},
|
|
113
|
-
|
|
114
|
-
// ── Layout ───────────────────────────────────────────────────────────────────
|
|
115
|
-
[PlatformOSFileType.Layout]: {
|
|
116
|
-
name: 'Layout',
|
|
117
|
-
fields: {
|
|
118
|
-
name: {
|
|
119
|
-
type: 'string',
|
|
120
|
-
description: 'Identifier used to reference this layout from pages.',
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
allowAdditionalFields: true,
|
|
124
|
-
},
|
|
125
|
-
|
|
126
|
-
// ── Partial ──────────────────────────────────────────────────────────────────
|
|
127
|
-
[PlatformOSFileType.Partial]: {
|
|
128
|
-
name: 'Partial',
|
|
129
|
-
fields: {
|
|
130
|
-
metadata: {
|
|
131
|
-
type: 'object',
|
|
132
|
-
description:
|
|
133
|
-
'Partial metadata. `metadata.params` declares accepted parameters; `metadata.name` is a human-readable label for the style guide.',
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
allowAdditionalFields: true,
|
|
137
|
-
},
|
|
138
|
-
|
|
139
|
-
// ── AuthorizationPolicy ──────────────────────────────────────────────────────
|
|
140
|
-
[PlatformOSFileType.Authorization]: {
|
|
141
|
-
name: 'AuthorizationPolicy',
|
|
142
|
-
fields: {
|
|
143
|
-
name: {
|
|
144
|
-
type: 'string',
|
|
145
|
-
required: true,
|
|
146
|
-
description: 'Unique identifier for this authorization policy.',
|
|
147
|
-
},
|
|
148
|
-
redirect_to: {
|
|
149
|
-
type: 'string',
|
|
150
|
-
description: 'URL to redirect the user to when the policy fails.',
|
|
151
|
-
},
|
|
152
|
-
flash_alert: {
|
|
153
|
-
type: 'string',
|
|
154
|
-
description: 'Flash alert message shown after a failed authorization redirect.',
|
|
155
|
-
},
|
|
156
|
-
flash_notice: {
|
|
157
|
-
type: 'string',
|
|
158
|
-
description: 'Flash notice message shown after a failed authorization redirect.',
|
|
159
|
-
},
|
|
160
|
-
},
|
|
161
|
-
allowAdditionalFields: true,
|
|
162
|
-
},
|
|
163
|
-
|
|
164
|
-
// ── Email ────────────────────────────────────────────────────────────────────
|
|
165
|
-
[PlatformOSFileType.Email]: {
|
|
166
|
-
name: 'Email',
|
|
167
|
-
fields: {
|
|
168
|
-
to: {
|
|
169
|
-
type: 'string',
|
|
170
|
-
required: true,
|
|
171
|
-
description: 'Recipient email address (may use Liquid).',
|
|
172
|
-
},
|
|
173
|
-
from: {
|
|
174
|
-
type: 'string',
|
|
175
|
-
description: 'Sender email address.',
|
|
176
|
-
},
|
|
177
|
-
reply_to: {
|
|
178
|
-
type: 'string',
|
|
179
|
-
description: 'Reply-to email address.',
|
|
180
|
-
},
|
|
181
|
-
cc: {
|
|
182
|
-
type: 'string',
|
|
183
|
-
description: 'Carbon-copy recipients.',
|
|
184
|
-
},
|
|
185
|
-
bcc: {
|
|
186
|
-
type: 'string',
|
|
187
|
-
description: 'Blind carbon-copy recipients.',
|
|
188
|
-
},
|
|
189
|
-
subject: {
|
|
190
|
-
type: 'string',
|
|
191
|
-
required: true,
|
|
192
|
-
description: 'Email subject line (may use Liquid).',
|
|
193
|
-
},
|
|
194
|
-
layout_path: {
|
|
195
|
-
type: 'string',
|
|
196
|
-
description: 'Layout partial to wrap the email body.',
|
|
197
|
-
},
|
|
198
|
-
delay: {
|
|
199
|
-
type: 'integer',
|
|
200
|
-
description: 'Seconds to delay delivery after being triggered.',
|
|
201
|
-
},
|
|
202
|
-
enabled: {
|
|
203
|
-
type: 'boolean',
|
|
204
|
-
description: 'When false, this email is never sent. Defaults to true.',
|
|
205
|
-
},
|
|
206
|
-
trigger_condition: {
|
|
207
|
-
type: ['boolean', 'string'],
|
|
208
|
-
description:
|
|
209
|
-
'Liquid expression or boolean; email is only sent when this evaluates to true.',
|
|
210
|
-
},
|
|
211
|
-
},
|
|
212
|
-
allowAdditionalFields: true,
|
|
213
|
-
},
|
|
214
|
-
|
|
215
|
-
// ── ApiCall ──────────────────────────────────────────────────────────────────
|
|
216
|
-
[PlatformOSFileType.ApiCall]: {
|
|
217
|
-
name: 'ApiCall',
|
|
218
|
-
fields: {
|
|
219
|
-
to: {
|
|
220
|
-
type: 'string',
|
|
221
|
-
required: true,
|
|
222
|
-
description: 'Target URL for the HTTP request (may use Liquid).',
|
|
223
|
-
},
|
|
224
|
-
request_type: {
|
|
225
|
-
type: 'string',
|
|
226
|
-
required: true,
|
|
227
|
-
description: 'HTTP method: GET, POST, PUT, PATCH, or DELETE.',
|
|
228
|
-
},
|
|
229
|
-
request_headers: {
|
|
230
|
-
type: 'string',
|
|
231
|
-
description: 'Liquid template rendering a JSON object of request headers.',
|
|
232
|
-
},
|
|
233
|
-
headers: {
|
|
234
|
-
type: 'string',
|
|
235
|
-
description: 'Alias for request_headers.',
|
|
236
|
-
deprecated: true,
|
|
237
|
-
deprecatedMessage: 'Use `request_headers` instead of `headers`.',
|
|
238
|
-
},
|
|
239
|
-
callback: {
|
|
240
|
-
type: 'string',
|
|
241
|
-
description: 'Liquid template executed after the HTTP response is received.',
|
|
242
|
-
},
|
|
243
|
-
delay: {
|
|
244
|
-
type: 'integer',
|
|
245
|
-
description: 'Seconds to delay the request after being triggered.',
|
|
246
|
-
},
|
|
247
|
-
enabled: {
|
|
248
|
-
type: 'boolean',
|
|
249
|
-
description: 'When false, this API call is never executed. Defaults to true.',
|
|
250
|
-
},
|
|
251
|
-
trigger_condition: {
|
|
252
|
-
type: ['boolean', 'string'],
|
|
253
|
-
description: 'Liquid expression or boolean; call is only made when this evaluates to true.',
|
|
254
|
-
},
|
|
255
|
-
format: {
|
|
256
|
-
type: 'string',
|
|
257
|
-
description: 'Request body encoding format (http, json, …).',
|
|
258
|
-
},
|
|
259
|
-
},
|
|
260
|
-
allowAdditionalFields: true,
|
|
261
|
-
},
|
|
262
|
-
|
|
263
|
-
// ── Sms ──────────────────────────────────────────────────────────────────────
|
|
264
|
-
[PlatformOSFileType.Sms]: {
|
|
265
|
-
name: 'SMS',
|
|
266
|
-
fields: {
|
|
267
|
-
to: {
|
|
268
|
-
type: 'string',
|
|
269
|
-
required: true,
|
|
270
|
-
description: 'Recipient phone number in E.164 format (may use Liquid).',
|
|
271
|
-
},
|
|
272
|
-
delay: {
|
|
273
|
-
type: 'integer',
|
|
274
|
-
description: 'Seconds to delay sending after being triggered.',
|
|
275
|
-
},
|
|
276
|
-
enabled: {
|
|
277
|
-
type: 'boolean',
|
|
278
|
-
description: 'When false, this SMS is never sent. Defaults to true.',
|
|
279
|
-
},
|
|
280
|
-
trigger_condition: {
|
|
281
|
-
type: ['boolean', 'string'],
|
|
282
|
-
description: 'Liquid expression or boolean; SMS is only sent when this evaluates to true.',
|
|
283
|
-
},
|
|
284
|
-
},
|
|
285
|
-
allowAdditionalFields: true,
|
|
286
|
-
},
|
|
287
|
-
|
|
288
|
-
// ── Migration ────────────────────────────────────────────────────────────────
|
|
289
|
-
[PlatformOSFileType.Migration]: {
|
|
290
|
-
name: 'Migration',
|
|
291
|
-
fields: {},
|
|
292
|
-
allowAdditionalFields: true,
|
|
293
|
-
},
|
|
294
|
-
|
|
295
|
-
// ── FormConfiguration ────────────────────────────────────────────────────────
|
|
296
|
-
[PlatformOSFileType.FormConfiguration]: {
|
|
297
|
-
name: 'FormConfiguration',
|
|
298
|
-
fields: {
|
|
299
|
-
name: {
|
|
300
|
-
type: 'string',
|
|
301
|
-
required: true,
|
|
302
|
-
description: 'Unique identifier for this form, used in include_form / function calls.',
|
|
303
|
-
},
|
|
304
|
-
resource: {
|
|
305
|
-
type: ['string', 'object'],
|
|
306
|
-
description: 'Model or resource type this form operates on.',
|
|
307
|
-
},
|
|
308
|
-
resource_owner: {
|
|
309
|
-
type: 'string',
|
|
310
|
-
description: 'Who owns the resource being created/updated.',
|
|
311
|
-
},
|
|
312
|
-
fields: {
|
|
313
|
-
type: 'object',
|
|
314
|
-
description: 'Field definitions — what data this form accepts and validates.',
|
|
315
|
-
},
|
|
316
|
-
redirect_to: {
|
|
317
|
-
type: 'string',
|
|
318
|
-
description: 'URL to redirect to after a successful form submission.',
|
|
319
|
-
},
|
|
320
|
-
flash_notice: {
|
|
321
|
-
type: 'string',
|
|
322
|
-
description: 'Flash notice message shown after a successful submission.',
|
|
323
|
-
},
|
|
324
|
-
flash_alert: {
|
|
325
|
-
type: 'string',
|
|
326
|
-
description: 'Flash alert message shown after a failed submission.',
|
|
327
|
-
},
|
|
328
|
-
},
|
|
329
|
-
allowAdditionalFields: true,
|
|
330
|
-
},
|
|
331
|
-
};
|
|
332
|
-
|
|
333
|
-
// ─── Lookup helper ────────────────────────────────────────────────────────────
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* Returns the frontmatter schema for a given file type, or undefined if no
|
|
337
|
-
* schema is defined for that type (e.g. GraphQL, YAML, Asset types).
|
|
338
|
-
*/
|
|
339
|
-
export function getFrontmatterSchema(
|
|
340
|
-
fileType: PlatformOSFileType | undefined,
|
|
341
|
-
): FrontmatterSchema | undefined {
|
|
342
|
-
if (fileType === undefined) return undefined;
|
|
343
|
-
return FRONTMATTER_SCHEMAS[fileType];
|
|
344
|
-
}
|
|
1
|
+
// Frontmatter schemas and types live in platformos-common so they can be used
|
|
2
|
+
// by other packages without depending on the full linting engine.
|
|
3
|
+
export {
|
|
4
|
+
type FrontmatterFieldType,
|
|
5
|
+
type FrontmatterFieldSchema,
|
|
6
|
+
type FrontmatterSchema,
|
|
7
|
+
FRONTMATTER_SCHEMAS,
|
|
8
|
+
getFrontmatterSchema,
|
|
9
|
+
} from '@platformos/platformos-common';
|