@platformos/platformos-common 0.0.12 → 0.0.16
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 +27 -0
- package/dist/documents-locator/DocumentsLocator.d.ts +13 -2
- package/dist/documents-locator/DocumentsLocator.js +49 -13
- package/dist/documents-locator/DocumentsLocator.js.map +1 -1
- package/dist/frontmatter.d.ts +75 -0
- package/dist/frontmatter.js +487 -0
- package/dist/frontmatter.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/path-utils.d.ts +34 -0
- package/dist/path-utils.js +40 -0
- package/dist/path-utils.js.map +1 -1
- package/dist/route-table/RouteTable.d.ts +26 -0
- package/dist/route-table/RouteTable.js +18 -1
- package/dist/route-table/RouteTable.js.map +1 -1
- package/dist/route-table/index.d.ts +1 -1
- package/dist/route-table/index.js +2 -1
- package/dist/route-table/index.js.map +1 -1
- package/dist/translation-provider/TranslationProvider.d.ts +10 -1
- package/dist/translation-provider/TranslationProvider.js +32 -8
- package/dist/translation-provider/TranslationProvider.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/documents-locator/DocumentsLocator.spec.ts +68 -0
- package/src/documents-locator/DocumentsLocator.ts +62 -20
- package/src/frontmatter.ts +533 -0
- package/src/index.ts +1 -0
- package/src/path-utils.ts +55 -0
- package/src/route-table/RouteTable.ts +19 -2
- package/src/route-table/index.ts +1 -1
- package/src/translation-provider/TranslationProvider.ts +37 -15
|
@@ -0,0 +1,533 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Frontmatter schema definitions for platformOS Liquid file types.
|
|
3
|
+
*
|
|
4
|
+
* Each Liquid file type in platformOS has a YAML frontmatter section at the
|
|
5
|
+
* top of the file that configures server-side behaviour. The schema for each
|
|
6
|
+
* type is different — Pages have slug/layout, Emails have to/from/subject, etc.
|
|
7
|
+
*
|
|
8
|
+
* This module provides:
|
|
9
|
+
* - FrontmatterFieldSchema — type definition for a single field
|
|
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 { FILE_TYPE_DIRS, PlatformOSFileType } from './path-utils';
|
|
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
|
+
* Allowed values for this field. When set, a validator should warn if the
|
|
35
|
+
* field value is not one of these entries.
|
|
36
|
+
*/
|
|
37
|
+
enumValues?: (string | number)[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface FrontmatterSchema {
|
|
41
|
+
/** Human-readable name of the file type, used in diagnostics. */
|
|
42
|
+
name: string;
|
|
43
|
+
/**
|
|
44
|
+
* Known frontmatter fields.
|
|
45
|
+
* Checks can use this to surface unknown keys or missing required keys.
|
|
46
|
+
* Any key not listed here will produce an "unknown field" warning.
|
|
47
|
+
*/
|
|
48
|
+
fields: Record<string, FrontmatterFieldSchema>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// ─── Schemas ──────────────────────────────────────────────────────────────────
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Per-type frontmatter schemas.
|
|
55
|
+
*
|
|
56
|
+
* Only Liquid file types are present here — GraphQL, YAML, and Asset types
|
|
57
|
+
* do not use frontmatter.
|
|
58
|
+
*
|
|
59
|
+
* Field lists are derived from the server-side converter files in
|
|
60
|
+
* app/services/app_builder/converters/. Enum constraints mirror server validations.
|
|
61
|
+
* Unknown keys always produce a warning; file types with arbitrary frontmatter
|
|
62
|
+
* (e.g. Migration) are omitted so no validation runs for them.
|
|
63
|
+
*/
|
|
64
|
+
export const FRONTMATTER_SCHEMAS: Partial<Record<PlatformOSFileType, FrontmatterSchema>> = {
|
|
65
|
+
// ── Page ─────────────────────────────────────────────────────────────────────
|
|
66
|
+
[PlatformOSFileType.Page]: {
|
|
67
|
+
name: 'Page',
|
|
68
|
+
fields: {
|
|
69
|
+
slug: {
|
|
70
|
+
type: 'string',
|
|
71
|
+
description: 'URL slug for this page. Supports dynamic segments (e.g. users/:id).',
|
|
72
|
+
},
|
|
73
|
+
layout: {
|
|
74
|
+
type: 'string',
|
|
75
|
+
description: 'Layout template to wrap this page (path relative to app root, no extension).',
|
|
76
|
+
},
|
|
77
|
+
layout_name: {
|
|
78
|
+
type: 'string',
|
|
79
|
+
description: 'Alias for layout.',
|
|
80
|
+
deprecated: true,
|
|
81
|
+
deprecatedMessage: 'Use `layout` instead of `layout_name`.',
|
|
82
|
+
},
|
|
83
|
+
method: {
|
|
84
|
+
type: 'string',
|
|
85
|
+
description: 'HTTP method this page responds to.',
|
|
86
|
+
enumValues: ['delete', 'get', 'patch', 'post', 'put', 'options'],
|
|
87
|
+
},
|
|
88
|
+
redirect_to: {
|
|
89
|
+
type: 'string',
|
|
90
|
+
description: 'URL to redirect to.',
|
|
91
|
+
},
|
|
92
|
+
redirect_url: {
|
|
93
|
+
type: 'string',
|
|
94
|
+
description: 'Alias for redirect_to.',
|
|
95
|
+
deprecated: true,
|
|
96
|
+
deprecatedMessage: 'Use `redirect_to` instead of `redirect_url`.',
|
|
97
|
+
},
|
|
98
|
+
redirect_code: {
|
|
99
|
+
type: 'integer',
|
|
100
|
+
description: 'HTTP redirect status code.',
|
|
101
|
+
enumValues: [301, 302, 307],
|
|
102
|
+
},
|
|
103
|
+
authorization_policies: {
|
|
104
|
+
type: 'array',
|
|
105
|
+
description: 'List of authorization policy names that must pass before rendering.',
|
|
106
|
+
},
|
|
107
|
+
response_headers: {
|
|
108
|
+
type: 'string',
|
|
109
|
+
description: 'Liquid template that renders a JSON object of HTTP response headers.',
|
|
110
|
+
},
|
|
111
|
+
metadata: {
|
|
112
|
+
type: 'object',
|
|
113
|
+
description: 'Arbitrary metadata object (e.g. SEO title/description, robots directives).',
|
|
114
|
+
},
|
|
115
|
+
max_deep_level: {
|
|
116
|
+
type: 'integer',
|
|
117
|
+
description: 'Maximum number of dynamic URL segments to capture.',
|
|
118
|
+
},
|
|
119
|
+
searchable: {
|
|
120
|
+
type: 'boolean',
|
|
121
|
+
description: 'Whether this page is included in platformOS search indexes.',
|
|
122
|
+
},
|
|
123
|
+
format: {
|
|
124
|
+
type: 'string',
|
|
125
|
+
description: 'Response format (html, json, xml, csv, …). Often encoded in the filename.',
|
|
126
|
+
},
|
|
127
|
+
default_layout: {
|
|
128
|
+
type: 'boolean',
|
|
129
|
+
description: 'Use the instance default layout.',
|
|
130
|
+
},
|
|
131
|
+
handler: {
|
|
132
|
+
type: 'string',
|
|
133
|
+
description: 'Template handler type.',
|
|
134
|
+
},
|
|
135
|
+
converter: {
|
|
136
|
+
type: 'string',
|
|
137
|
+
description: 'Content converter, e.g. `markdown`.',
|
|
138
|
+
},
|
|
139
|
+
dynamic_cache: {
|
|
140
|
+
type: 'object',
|
|
141
|
+
description: 'Dynamic cache settings: { key, layout, expire }.',
|
|
142
|
+
},
|
|
143
|
+
static_cache: {
|
|
144
|
+
type: 'object',
|
|
145
|
+
description: 'Static cache settings: { expire }.',
|
|
146
|
+
},
|
|
147
|
+
cache_for: {
|
|
148
|
+
type: 'integer',
|
|
149
|
+
description: 'Static cache expiration in seconds.',
|
|
150
|
+
},
|
|
151
|
+
subdomain: {
|
|
152
|
+
type: 'string',
|
|
153
|
+
description: 'Subdomain routing.',
|
|
154
|
+
},
|
|
155
|
+
require_verified_user: {
|
|
156
|
+
type: 'boolean',
|
|
157
|
+
},
|
|
158
|
+
admin_page: {
|
|
159
|
+
type: 'boolean',
|
|
160
|
+
},
|
|
161
|
+
enable_profiler: {
|
|
162
|
+
type: 'boolean',
|
|
163
|
+
},
|
|
164
|
+
metadata_title: {
|
|
165
|
+
type: 'string',
|
|
166
|
+
description: 'SEO <title> shorthand (alias for metadata.title).',
|
|
167
|
+
},
|
|
168
|
+
metadata_meta_description: {
|
|
169
|
+
type: 'string',
|
|
170
|
+
description: 'SEO meta description shorthand (alias for metadata.meta_description).',
|
|
171
|
+
},
|
|
172
|
+
metadata_canonical_url: {
|
|
173
|
+
type: 'string',
|
|
174
|
+
description: 'Canonical URL shorthand (alias for metadata.canonical_url).',
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
// ── Layout ───────────────────────────────────────────────────────────────────
|
|
180
|
+
// liquid_view_converter.rb: primary_key derived from physical_file_path; no `name` property.
|
|
181
|
+
[PlatformOSFileType.Layout]: {
|
|
182
|
+
name: 'Layout',
|
|
183
|
+
fields: {
|
|
184
|
+
converter: {
|
|
185
|
+
type: 'string',
|
|
186
|
+
description: 'Content converter, e.g. `markdown`.',
|
|
187
|
+
},
|
|
188
|
+
metadata: {
|
|
189
|
+
type: 'object',
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
|
|
194
|
+
// ── Partial ──────────────────────────────────────────────────────────────────
|
|
195
|
+
[PlatformOSFileType.Partial]: {
|
|
196
|
+
name: 'Partial',
|
|
197
|
+
fields: {
|
|
198
|
+
metadata: {
|
|
199
|
+
type: 'object',
|
|
200
|
+
description:
|
|
201
|
+
'Partial metadata. `metadata.params` declares accepted parameters; `metadata.name` is a human-readable label for the style guide.',
|
|
202
|
+
},
|
|
203
|
+
converter: {
|
|
204
|
+
type: 'string',
|
|
205
|
+
description: 'Content converter, e.g. `markdown`.',
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
|
|
210
|
+
// ── AuthorizationPolicy ──────────────────────────────────────────────────────
|
|
211
|
+
// authorization_policy_converter.rb: name, content, flash_alert, redirect_to, http_status, metadata.
|
|
212
|
+
// Note: only flash_alert is supported — flash_notice is NOT a valid property here.
|
|
213
|
+
[PlatformOSFileType.Authorization]: {
|
|
214
|
+
name: 'AuthorizationPolicy',
|
|
215
|
+
fields: {
|
|
216
|
+
name: {
|
|
217
|
+
type: 'string',
|
|
218
|
+
description: 'Unique identifier for this authorization policy.',
|
|
219
|
+
},
|
|
220
|
+
redirect_to: {
|
|
221
|
+
type: 'string',
|
|
222
|
+
description: 'URL to redirect the user to when the policy fails.',
|
|
223
|
+
},
|
|
224
|
+
flash_alert: {
|
|
225
|
+
type: 'string',
|
|
226
|
+
description: 'Flash alert message shown after a failed authorization redirect.',
|
|
227
|
+
},
|
|
228
|
+
http_status: {
|
|
229
|
+
type: 'integer',
|
|
230
|
+
description: 'HTTP status code returned on policy failure.',
|
|
231
|
+
enumValues: [403, 404],
|
|
232
|
+
},
|
|
233
|
+
metadata: {
|
|
234
|
+
type: 'object',
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
|
|
239
|
+
// ── Email ────────────────────────────────────────────────────────────────────
|
|
240
|
+
[PlatformOSFileType.Email]: {
|
|
241
|
+
name: 'Email',
|
|
242
|
+
fields: {
|
|
243
|
+
name: {
|
|
244
|
+
type: 'string',
|
|
245
|
+
description: 'Unique identifier for this email notification.',
|
|
246
|
+
},
|
|
247
|
+
to: {
|
|
248
|
+
type: 'string',
|
|
249
|
+
description: 'Recipient email address (may use Liquid).',
|
|
250
|
+
},
|
|
251
|
+
from: {
|
|
252
|
+
type: 'string',
|
|
253
|
+
description: 'Sender email address.',
|
|
254
|
+
},
|
|
255
|
+
reply_to: {
|
|
256
|
+
type: 'string',
|
|
257
|
+
description: 'Reply-to email address.',
|
|
258
|
+
},
|
|
259
|
+
cc: {
|
|
260
|
+
type: 'string',
|
|
261
|
+
description: 'Carbon-copy recipients.',
|
|
262
|
+
},
|
|
263
|
+
bcc: {
|
|
264
|
+
type: 'string',
|
|
265
|
+
description: 'Blind carbon-copy recipients.',
|
|
266
|
+
},
|
|
267
|
+
subject: {
|
|
268
|
+
type: 'string',
|
|
269
|
+
description: 'Email subject line (may use Liquid).',
|
|
270
|
+
},
|
|
271
|
+
layout: {
|
|
272
|
+
type: 'string',
|
|
273
|
+
description: 'Layout partial to wrap the email body.',
|
|
274
|
+
},
|
|
275
|
+
layout_path: {
|
|
276
|
+
type: 'string',
|
|
277
|
+
description: 'Alias for layout.',
|
|
278
|
+
deprecated: true,
|
|
279
|
+
deprecatedMessage: 'Use `layout` instead of `layout_path`.',
|
|
280
|
+
},
|
|
281
|
+
delay: {
|
|
282
|
+
type: 'integer',
|
|
283
|
+
description: 'Seconds to delay delivery after being triggered.',
|
|
284
|
+
},
|
|
285
|
+
enabled: {
|
|
286
|
+
type: 'boolean',
|
|
287
|
+
description: 'When false, this email is never sent. Defaults to true.',
|
|
288
|
+
},
|
|
289
|
+
trigger_condition: {
|
|
290
|
+
type: ['boolean', 'string'],
|
|
291
|
+
description:
|
|
292
|
+
'Liquid expression or boolean; email is only sent when this evaluates to true.',
|
|
293
|
+
},
|
|
294
|
+
locale: {
|
|
295
|
+
type: 'string',
|
|
296
|
+
description: 'Locale for the email.',
|
|
297
|
+
},
|
|
298
|
+
forced: {
|
|
299
|
+
type: 'boolean',
|
|
300
|
+
},
|
|
301
|
+
attachments: {
|
|
302
|
+
type: 'string',
|
|
303
|
+
},
|
|
304
|
+
unique_args: {
|
|
305
|
+
type: 'object',
|
|
306
|
+
description: 'Extra key/value pairs passed to the email delivery provider.',
|
|
307
|
+
},
|
|
308
|
+
metadata: {
|
|
309
|
+
type: 'object',
|
|
310
|
+
},
|
|
311
|
+
},
|
|
312
|
+
},
|
|
313
|
+
|
|
314
|
+
// ── ApiCall ──────────────────────────────────────────────────────────────────
|
|
315
|
+
[PlatformOSFileType.ApiCall]: {
|
|
316
|
+
name: 'ApiCall',
|
|
317
|
+
fields: {
|
|
318
|
+
name: {
|
|
319
|
+
type: 'string',
|
|
320
|
+
description: 'Unique identifier for this API call notification.',
|
|
321
|
+
},
|
|
322
|
+
to: {
|
|
323
|
+
type: 'string',
|
|
324
|
+
description: 'Target URL for the HTTP request (may use Liquid).',
|
|
325
|
+
},
|
|
326
|
+
request_type: {
|
|
327
|
+
type: 'string',
|
|
328
|
+
description: 'HTTP method: GET, POST, PUT, PATCH, or DELETE.',
|
|
329
|
+
enumValues: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'],
|
|
330
|
+
},
|
|
331
|
+
request_headers: {
|
|
332
|
+
type: 'string',
|
|
333
|
+
description: 'Liquid template rendering a JSON object of request headers.',
|
|
334
|
+
},
|
|
335
|
+
headers: {
|
|
336
|
+
type: 'string',
|
|
337
|
+
description: 'Alias for request_headers.',
|
|
338
|
+
deprecated: true,
|
|
339
|
+
deprecatedMessage: 'Use `request_headers` instead of `headers`.',
|
|
340
|
+
},
|
|
341
|
+
callback: {
|
|
342
|
+
type: 'string',
|
|
343
|
+
description: 'Liquid template executed after the HTTP response is received.',
|
|
344
|
+
},
|
|
345
|
+
delay: {
|
|
346
|
+
type: 'integer',
|
|
347
|
+
description: 'Seconds to delay the request after being triggered.',
|
|
348
|
+
},
|
|
349
|
+
enabled: {
|
|
350
|
+
type: 'boolean',
|
|
351
|
+
description: 'When false, this API call is never executed. Defaults to true.',
|
|
352
|
+
},
|
|
353
|
+
trigger_condition: {
|
|
354
|
+
type: ['boolean', 'string'],
|
|
355
|
+
description: 'Liquid expression or boolean; call is only made when this evaluates to true.',
|
|
356
|
+
},
|
|
357
|
+
format: {
|
|
358
|
+
type: 'string',
|
|
359
|
+
description: 'Request body encoding format (http, json, …).',
|
|
360
|
+
},
|
|
361
|
+
locale: {
|
|
362
|
+
type: 'string',
|
|
363
|
+
},
|
|
364
|
+
metadata: {
|
|
365
|
+
type: 'object',
|
|
366
|
+
},
|
|
367
|
+
},
|
|
368
|
+
},
|
|
369
|
+
|
|
370
|
+
// ── Sms ──────────────────────────────────────────────────────────────────────
|
|
371
|
+
[PlatformOSFileType.Sms]: {
|
|
372
|
+
name: 'SMS',
|
|
373
|
+
fields: {
|
|
374
|
+
name: {
|
|
375
|
+
type: 'string',
|
|
376
|
+
description: 'Unique identifier for this SMS notification.',
|
|
377
|
+
},
|
|
378
|
+
to: {
|
|
379
|
+
type: 'string',
|
|
380
|
+
description: 'Recipient phone number in E.164 format (may use Liquid).',
|
|
381
|
+
},
|
|
382
|
+
content: {
|
|
383
|
+
type: 'string',
|
|
384
|
+
description: 'SMS body (may use Liquid).',
|
|
385
|
+
},
|
|
386
|
+
delay: {
|
|
387
|
+
type: 'integer',
|
|
388
|
+
description: 'Seconds to delay sending after being triggered.',
|
|
389
|
+
},
|
|
390
|
+
enabled: {
|
|
391
|
+
type: 'boolean',
|
|
392
|
+
description: 'When false, this SMS is never sent. Defaults to true.',
|
|
393
|
+
},
|
|
394
|
+
trigger_condition: {
|
|
395
|
+
type: ['boolean', 'string'],
|
|
396
|
+
description: 'Liquid expression or boolean; SMS is only sent when this evaluates to true.',
|
|
397
|
+
},
|
|
398
|
+
locale: {
|
|
399
|
+
type: 'string',
|
|
400
|
+
},
|
|
401
|
+
metadata: {
|
|
402
|
+
type: 'object',
|
|
403
|
+
},
|
|
404
|
+
},
|
|
405
|
+
},
|
|
406
|
+
|
|
407
|
+
// ── FormConfiguration ────────────────────────────────────────────────────────
|
|
408
|
+
[PlatformOSFileType.FormConfiguration]: {
|
|
409
|
+
name: 'FormConfiguration',
|
|
410
|
+
fields: {
|
|
411
|
+
name: {
|
|
412
|
+
type: 'string',
|
|
413
|
+
description: 'Unique identifier for this form, used in include_form / function calls.',
|
|
414
|
+
},
|
|
415
|
+
resource: {
|
|
416
|
+
type: ['string', 'object'],
|
|
417
|
+
description: 'Model or resource type this form operates on.',
|
|
418
|
+
},
|
|
419
|
+
resource_owner: {
|
|
420
|
+
type: 'string',
|
|
421
|
+
description: 'Who owns the resource being created/updated.',
|
|
422
|
+
},
|
|
423
|
+
fields: {
|
|
424
|
+
type: 'object',
|
|
425
|
+
description: 'Field definitions — what data this form accepts and validates.',
|
|
426
|
+
},
|
|
427
|
+
configuration: {
|
|
428
|
+
type: 'object',
|
|
429
|
+
description: 'Alias for fields.',
|
|
430
|
+
},
|
|
431
|
+
redirect_to: {
|
|
432
|
+
type: 'string',
|
|
433
|
+
description: 'URL to redirect to after a successful form submission.',
|
|
434
|
+
},
|
|
435
|
+
return_to: {
|
|
436
|
+
type: 'string',
|
|
437
|
+
description: 'Alias for redirect_to.',
|
|
438
|
+
deprecated: true,
|
|
439
|
+
deprecatedMessage: 'Use `redirect_to` instead of `return_to`.',
|
|
440
|
+
},
|
|
441
|
+
flash_notice: {
|
|
442
|
+
type: 'string',
|
|
443
|
+
description: 'Flash notice message shown after a successful submission.',
|
|
444
|
+
},
|
|
445
|
+
flash_alert: {
|
|
446
|
+
type: 'string',
|
|
447
|
+
description: 'Flash alert message shown after a failed submission.',
|
|
448
|
+
},
|
|
449
|
+
spam_protection: {
|
|
450
|
+
type: 'string',
|
|
451
|
+
description: 'Spam protection mechanism to use.',
|
|
452
|
+
enumValues: ['recaptcha', 'recaptcha_v2', 'recaptcha_v3', 'hcaptcha'],
|
|
453
|
+
},
|
|
454
|
+
request_allowed: {
|
|
455
|
+
type: 'boolean',
|
|
456
|
+
description: 'Whether the request is allowed. Default: true.',
|
|
457
|
+
},
|
|
458
|
+
live_reindex: {
|
|
459
|
+
type: 'boolean',
|
|
460
|
+
},
|
|
461
|
+
default_payload: {
|
|
462
|
+
type: ['string', 'object'],
|
|
463
|
+
},
|
|
464
|
+
callback_actions: {
|
|
465
|
+
type: 'string',
|
|
466
|
+
description: 'Liquid template with GraphQL mutations to run after submission.',
|
|
467
|
+
},
|
|
468
|
+
async_callback_actions: {
|
|
469
|
+
type: 'object',
|
|
470
|
+
description: 'Async callback settings: { content, delay, max_attempts, priority }.',
|
|
471
|
+
},
|
|
472
|
+
email_notifications: {
|
|
473
|
+
type: 'array',
|
|
474
|
+
description: 'Email notification names to trigger after successful form submission.',
|
|
475
|
+
},
|
|
476
|
+
sms_notifications: {
|
|
477
|
+
type: 'array',
|
|
478
|
+
description: 'SMS notification names to trigger after successful form submission.',
|
|
479
|
+
},
|
|
480
|
+
api_call_notifications: {
|
|
481
|
+
type: 'array',
|
|
482
|
+
description: 'API call notification names to trigger after successful form submission.',
|
|
483
|
+
},
|
|
484
|
+
response_headers: {
|
|
485
|
+
type: ['string', 'object'],
|
|
486
|
+
},
|
|
487
|
+
metadata: {
|
|
488
|
+
type: 'object',
|
|
489
|
+
},
|
|
490
|
+
},
|
|
491
|
+
},
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
// ─── Lookup helper ────────────────────────────────────────────────────────────
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Returns the frontmatter schema for a given file type, or undefined if no
|
|
498
|
+
* schema is defined for that type (e.g. GraphQL, YAML, Asset types).
|
|
499
|
+
*/
|
|
500
|
+
export function getFrontmatterSchema(
|
|
501
|
+
fileType: PlatformOSFileType | undefined,
|
|
502
|
+
): FrontmatterSchema | undefined {
|
|
503
|
+
if (fileType === undefined) return undefined;
|
|
504
|
+
return FRONTMATTER_SCHEMAS[fileType];
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
// ─── Frontmatter association directories ──────────────────────────────────────
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* Maps frontmatter list-field names to their canonical app-relative directory.
|
|
511
|
+
*
|
|
512
|
+
* Derived from FILE_TYPE_DIRS[type][0] so it always stays in sync with the
|
|
513
|
+
* single source of truth in path-utils.ts.
|
|
514
|
+
*
|
|
515
|
+
* Used by both the ValidFrontmatter check (file-existence validation) and the
|
|
516
|
+
* FrontmatterDefinitionProvider (go-to-definition) to resolve association paths.
|
|
517
|
+
*/
|
|
518
|
+
export const FRONTMATTER_ASSOCIATION_DIRS: Readonly<Record<string, string>> = {
|
|
519
|
+
authorization_policies: FILE_TYPE_DIRS[PlatformOSFileType.Authorization][0],
|
|
520
|
+
email_notifications: FILE_TYPE_DIRS[PlatformOSFileType.Email][0],
|
|
521
|
+
sms_notifications: FILE_TYPE_DIRS[PlatformOSFileType.Sms][0],
|
|
522
|
+
api_call_notifications: FILE_TYPE_DIRS[PlatformOSFileType.ApiCall][0],
|
|
523
|
+
};
|
|
524
|
+
|
|
525
|
+
// ─── Liquid expression detection ──────────────────────────────────────────────
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Returns true if the value contains a Liquid output tag (`{{`) or tag (`{%`).
|
|
529
|
+
* Used to skip static validation of dynamic frontmatter values.
|
|
530
|
+
*/
|
|
531
|
+
export function containsLiquid(value: string): boolean {
|
|
532
|
+
return value.includes('{{') || value.includes('{%');
|
|
533
|
+
}
|
package/src/index.ts
CHANGED
package/src/path-utils.ts
CHANGED
|
@@ -220,6 +220,19 @@ export function isKnownLiquidFile(uri: UriString): boolean {
|
|
|
220
220
|
return type !== undefined && LIQUID_FILE_TYPES.has(type);
|
|
221
221
|
}
|
|
222
222
|
|
|
223
|
+
/**
|
|
224
|
+
* Returns true if the URI has a `.liquid` extension but does not match any
|
|
225
|
+
* recognized platformOS directory. Useful for detecting misplaced files that
|
|
226
|
+
* the server will silently ignore.
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* isUnclassifiedLiquidFile('file:///project/scripts/helper.liquid') // → true
|
|
230
|
+
* isUnclassifiedLiquidFile('file:///project/app/views/pages/home.liquid') // → false (Page)
|
|
231
|
+
*/
|
|
232
|
+
export function isUnclassifiedLiquidFile(uri: UriString): boolean {
|
|
233
|
+
return uri.endsWith('.liquid') && getFileType(uri) === undefined;
|
|
234
|
+
}
|
|
235
|
+
|
|
223
236
|
/**
|
|
224
237
|
* Returns true if the URI belongs to a recognized platformOS GraphQL directory
|
|
225
238
|
* and should be linted. Files outside known directories (e.g. generator
|
|
@@ -264,3 +277,45 @@ export function isMigration(uri: UriString): boolean {
|
|
|
264
277
|
export function isFormConfiguration(uri: UriString): boolean {
|
|
265
278
|
return getFileType(uri) === PlatformOSFileType.FormConfiguration;
|
|
266
279
|
}
|
|
280
|
+
|
|
281
|
+
// ─── Module prefix utilities ──────────────────────────────────────────────────
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Result of parsing a `modules/{name}/...` prefix from a path or key.
|
|
285
|
+
* Used by DocumentsLocator and TranslationProvider to route lookups to the
|
|
286
|
+
* correct module directory.
|
|
287
|
+
*/
|
|
288
|
+
export type ModulePrefix =
|
|
289
|
+
| { isModule: false; key: string }
|
|
290
|
+
| { isModule: true; moduleName: string; key: string };
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Parse a `modules/{name}/{rest}` prefix from a path or translation key.
|
|
294
|
+
* Returns the module name and the remaining key, or marks it as non-module.
|
|
295
|
+
*
|
|
296
|
+
* @example
|
|
297
|
+
* parseModulePrefix('modules/community/components/card') // → { isModule: true, moduleName: 'community', key: 'components/card' }
|
|
298
|
+
* parseModulePrefix('modules/community/hello.world') // → { isModule: true, moduleName: 'community', key: 'hello.world' }
|
|
299
|
+
* parseModulePrefix('app/views/partials/card') // → { isModule: false, key: 'app/views/partials/card' }
|
|
300
|
+
* parseModulePrefix('modules/community') // → { isModule: false, key: 'modules/community' } (no key segment)
|
|
301
|
+
*/
|
|
302
|
+
export function parseModulePrefix(path: string): ModulePrefix {
|
|
303
|
+
if (!path.startsWith('modules/')) {
|
|
304
|
+
return { isModule: false, key: path };
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const withoutPrefix = path.slice('modules/'.length);
|
|
308
|
+
const slashIdx = withoutPrefix.indexOf('/');
|
|
309
|
+
|
|
310
|
+
if (slashIdx === -1) {
|
|
311
|
+
// Just "modules/name" with no key segment
|
|
312
|
+
return { isModule: false, key: path };
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const moduleName = withoutPrefix.slice(0, slashIdx);
|
|
316
|
+
const key = withoutPrefix.slice(slashIdx + 1);
|
|
317
|
+
|
|
318
|
+
// moduleName must be non-empty to be a valid module prefix.
|
|
319
|
+
// key may be empty (e.g. 'modules/users/') — that means "all files in the module".
|
|
320
|
+
return moduleName ? { isModule: true, moduleName, key } : { isModule: false, key: path };
|
|
321
|
+
}
|
|
@@ -16,7 +16,9 @@ function extractFrontmatter(source: string): PageFrontmatter | null {
|
|
|
16
16
|
const trimmed = source.trimStart();
|
|
17
17
|
if (!trimmed.startsWith('---')) return null;
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
// Search for the closing delimiter as `\n---` so we don't accidentally match
|
|
20
|
+
// a `---` sequence that appears inside a YAML value (e.g. `slug: my---slug`).
|
|
21
|
+
const end = trimmed.indexOf('\n---', 3);
|
|
20
22
|
if (end === -1) return null;
|
|
21
23
|
|
|
22
24
|
const yamlBlock = trimmed.slice(3, end).trim();
|
|
@@ -48,7 +50,7 @@ function extractFrontmatter(source: string): PageFrontmatter | null {
|
|
|
48
50
|
* file:///project/app/views/pages/about.html.liquid -> about.html.liquid
|
|
49
51
|
* file:///project/modules/admin/public/views/pages/dashboard.html.liquid -> dashboard.html.liquid
|
|
50
52
|
*/
|
|
51
|
-
function extractRelativePagePath(uri: string): string | null {
|
|
53
|
+
export function extractRelativePagePath(uri: string): string | null {
|
|
52
54
|
const patterns = [
|
|
53
55
|
// App-level pages: app/views/pages/ or marketplace_builder/pages/
|
|
54
56
|
/\/(app|marketplace_builder)\/(views\/pages|pages)\//,
|
|
@@ -187,6 +189,21 @@ export class RouteTable {
|
|
|
187
189
|
return this._built;
|
|
188
190
|
}
|
|
189
191
|
|
|
192
|
+
/**
|
|
193
|
+
* Populate the route table from an in-memory collection of URI → content
|
|
194
|
+
* pairs, bypassing the filesystem entirely. Useful for warming the table
|
|
195
|
+
* from a DocumentManager without a full disk scan on startup.
|
|
196
|
+
*
|
|
197
|
+
* Only page URIs are registered; non-page URIs are silently skipped.
|
|
198
|
+
*/
|
|
199
|
+
buildFromEntries(entries: Iterable<[uri: string, content: string]>): void {
|
|
200
|
+
this.routes.clear();
|
|
201
|
+
for (const [uri, content] of entries) {
|
|
202
|
+
this.addPageFromContent(uri, content);
|
|
203
|
+
}
|
|
204
|
+
this._built = true;
|
|
205
|
+
}
|
|
206
|
+
|
|
190
207
|
async build(rootUri: URI): Promise<void> {
|
|
191
208
|
this.routes.clear();
|
|
192
209
|
|
package/src/route-table/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { RouteTable } from './RouteTable';
|
|
1
|
+
export { RouteTable, extractRelativePagePath } from './RouteTable';
|
|
2
2
|
export { slugFromFilePath, formatFromFilePath, KNOWN_FORMATS } from './slugFromFilePath';
|
|
3
3
|
export { parseSlug, calculatePrecedence } from './parseSlug';
|
|
4
4
|
export type { RouteEntry, RouteSegment } from './types';
|