@crombolo/server 0.45.0 → 0.46.1
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 +13 -13
- package/src/adapters/media.ts +37 -43
- package/src/config.ts +1 -1
- package/src/core.ts +11 -0
- package/src/index.ts +1 -0
- package/src/marketplace.ts +82 -14
- package/src/no-nodes.ts +1 -1
- package/src/node-operations.ts +3 -0
- package/src/owner-jobs.ts +6 -0
- package/src/provenance.ts +43 -15
- package/src/seed/compile.ts +16 -287
- package/src/seed/export.ts +9 -150
- package/src/seed/index.ts +1 -0
- package/src/seed/values.ts +509 -0
- package/src/server.ts +45 -25
- package/src/webhook-edit.ts +70 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Changes to a webhook kept in the site's files (story 251): its address,
|
|
3
|
+
* events, content types, headers and whether it is on. Pure; the rules every
|
|
4
|
+
* webhook is held to are `webhookProblems`'s, which the caller runs.
|
|
5
|
+
*/
|
|
6
|
+
import { envReference, type WebhookDefinition } from './webhook-files.ts'
|
|
7
|
+
|
|
8
|
+
export type WebhookEditResult =
|
|
9
|
+
| { ok: true; webhook: WebhookDefinition }
|
|
10
|
+
| { ok: false; reason: string }
|
|
11
|
+
|
|
12
|
+
export interface WebhookChanges {
|
|
13
|
+
name?: string
|
|
14
|
+
description?: string
|
|
15
|
+
url?: string
|
|
16
|
+
enabled?: boolean
|
|
17
|
+
addEvents?: readonly string[]
|
|
18
|
+
removeEvents?: readonly string[]
|
|
19
|
+
/** Content types by alias, as a file names them. */
|
|
20
|
+
addContentTypes?: readonly string[]
|
|
21
|
+
removeContentTypes?: readonly string[]
|
|
22
|
+
/** Header name to its value; in a file, only `env:NAME`. */
|
|
23
|
+
setHeaders?: Readonly<Record<string, string>>
|
|
24
|
+
removeHeaders?: readonly string[]
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const added = (list: readonly string[], more: readonly string[] = []) => [
|
|
28
|
+
...list,
|
|
29
|
+
...more.filter((item) => !list.includes(item)),
|
|
30
|
+
]
|
|
31
|
+
const without = (list: readonly string[], less: readonly string[] = []) =>
|
|
32
|
+
list.filter((item) => !less.includes(item))
|
|
33
|
+
|
|
34
|
+
export function updateWebhook(
|
|
35
|
+
webhook: WebhookDefinition,
|
|
36
|
+
changes: WebhookChanges,
|
|
37
|
+
): WebhookEditResult {
|
|
38
|
+
for (const event of changes.removeEvents ?? [])
|
|
39
|
+
if (!webhook.events.includes(event))
|
|
40
|
+
return { ok: false, reason: `it is not sent on "${event}"` }
|
|
41
|
+
for (const type of changes.removeContentTypes ?? [])
|
|
42
|
+
if (!webhook.contentTypeKeys.includes(type))
|
|
43
|
+
return { ok: false, reason: `it is not limited to the content type "${type}"` }
|
|
44
|
+
for (const name of changes.removeHeaders ?? [])
|
|
45
|
+
if (!(name in webhook.headers)) return { ok: false, reason: `it sends no header "${name}"` }
|
|
46
|
+
for (const [name, value] of Object.entries(changes.setHeaders ?? {}))
|
|
47
|
+
if (!envReference(value))
|
|
48
|
+
return {
|
|
49
|
+
ok: false,
|
|
50
|
+
reason: `the header "${name}" would put its value in the site's files: give it as env:NAME and set NAME on the server`,
|
|
51
|
+
}
|
|
52
|
+
const headers = { ...webhook.headers, ...changes.setHeaders }
|
|
53
|
+
for (const name of changes.removeHeaders ?? []) delete headers[name]
|
|
54
|
+
return {
|
|
55
|
+
ok: true,
|
|
56
|
+
webhook: {
|
|
57
|
+
...webhook,
|
|
58
|
+
...(changes.name !== undefined ? { name: changes.name || null } : {}),
|
|
59
|
+
...(changes.description !== undefined ? { description: changes.description || null } : {}),
|
|
60
|
+
...(changes.url !== undefined ? { url: changes.url } : {}),
|
|
61
|
+
...(changes.enabled !== undefined ? { enabled: changes.enabled } : {}),
|
|
62
|
+
events: without(added(webhook.events, changes.addEvents), changes.removeEvents),
|
|
63
|
+
contentTypeKeys: without(
|
|
64
|
+
added(webhook.contentTypeKeys, changes.addContentTypes),
|
|
65
|
+
changes.removeContentTypes,
|
|
66
|
+
),
|
|
67
|
+
headers,
|
|
68
|
+
},
|
|
69
|
+
}
|
|
70
|
+
}
|