@crombolo/schema 0.61.0 → 0.62.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crombolo/schema",
3
- "version": "0.61.0",
3
+ "version": "0.62.0",
4
4
  "description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. Schema-as-code for crombolo: TOML document, media and member type definitions.",
5
5
  "license": "MIT",
6
6
  "author": "Crombolo",
@@ -28,7 +28,7 @@
28
28
  "access": "public"
29
29
  },
30
30
  "dependencies": {
31
- "@crombolo/core": "0.61.0",
32
- "@crombolo/data": "0.61.0"
31
+ "@crombolo/core": "0.62.0",
32
+ "@crombolo/data": "0.62.0"
33
33
  }
34
34
  }
@@ -20,6 +20,16 @@ import {
20
20
  } from '@crombolo/core'
21
21
  import type { SchemaProblem } from './model.ts'
22
22
 
23
+ /** An absolute http or https URL (story 304): no other scheme is sent to. */
24
+ const isWebAddress = (url: string): boolean => {
25
+ try {
26
+ const parsed = new URL(url)
27
+ return parsed.protocol === 'http:' || parsed.protocol === 'https:'
28
+ } catch {
29
+ return false
30
+ }
31
+ }
32
+
23
33
  const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
24
34
 
25
35
  const VERSION = /^\d+(\.\d+)*$/
@@ -373,8 +383,29 @@ function validateWorkflows(
373
383
 
374
384
  if (workflow.type === 'sendToUrl') {
375
385
  const url = workflow.settings.url
376
- if (typeof url === 'string' && !/^https?:\/\//.test(url))
386
+ if (typeof url === 'string' && !isWebAddress(url))
377
387
  add(file, `${path}.settings.url`, 'must be an http or https URL')
388
+ const headers = workflow.settings.headers
389
+ if (headers !== undefined) {
390
+ if (!headers || typeof headers !== 'object' || Array.isArray(headers))
391
+ add(file, `${path}.settings.headers`, 'expected a table of header names')
392
+ else
393
+ for (const [name, value] of Object.entries(headers))
394
+ if (
395
+ typeof value !== 'string' &&
396
+ !(
397
+ value &&
398
+ typeof value === 'object' &&
399
+ Object.keys(value).length === 1 &&
400
+ (value as { secret?: unknown }).secret === true
401
+ )
402
+ )
403
+ add(
404
+ file,
405
+ `${path}.settings.headers.${name}`,
406
+ 'expected the value as text, or { secret = true } for one kept sealed on the site',
407
+ )
408
+ }
378
409
  const method = workflow.settings.method
379
410
  if (method !== undefined && method !== 'POST' && method !== 'PUT')
380
411
  add(file, `${path}.settings.method`, "expected 'POST' or 'PUT'")
@@ -23,7 +23,9 @@ function scalar(value: unknown): string {
23
23
  if (typeof value === 'number' || typeof value === 'boolean') return String(value)
24
24
  if (Array.isArray(value)) return `[${value.map(scalar).join(', ')}]`
25
25
  if (value === null || value === undefined) return '""'
26
- return str(JSON.stringify(value))
26
+ // A table, such as a send-to-URL workflow's headers, as an inline table.
27
+ const entries = Object.entries(value as Record<string, unknown>)
28
+ return `{ ${entries.map(([key, inner]) => `${keyOf(key)} = ${scalar(inner)}`).join(', ')} }`
27
29
  }
28
30
 
29
31
  /** Workflow settings arrive from the API, so a key may need quoting. */