@kardalum/plugin-sdk 0.16.0 → 0.17.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/CHANGELOG.md +38 -0
- package/dist/admin-section-registry.d.ts +14 -5
- package/dist/admin-section-registry.js +14 -4
- package/dist/capabilities.js +0 -3
- package/dist/host-entry.d.ts +1 -1
- package/dist/host-entry.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +8 -8
- package/dist/license-verdict-keys.d.ts +4 -3
- package/dist/license-verdict-keys.js +4 -7
- package/dist/manifest-entry.d.ts +2 -2
- package/dist/manifest-entry.js +1 -1
- package/dist/manifest-schema.d.ts +51 -62
- package/dist/manifest-schema.js +97 -249
- package/dist/manifest.d.ts +41 -73
- package/dist/manifest.js +13 -36
- package/dist/plugin-screen-context.d.ts +11 -1
- package/dist/richtext/block-panel.js +2 -2
- package/dist/richtext/insert-menu.js +1 -1
- package/dist/richtext/style-listbox.js +4 -4
- package/dist/tokens/tokens.css +1 -0
- package/dist/tokens/tokens.json +2 -1
- package/dist/type-equality.d.ts +2 -0
- package/dist/type-equality.js +1 -0
- package/dist/views/html-view.js +1 -1
- package/dist/views/rich-text-view.js +1 -1
- package/node_modules/@kardalum/api-schemas/dist/asset-api.schema.d.ts +90 -0
- package/node_modules/@kardalum/api-schemas/dist/asset-api.schema.js +32 -1
- package/node_modules/@kardalum/api-schemas/dist/asset.schema.d.ts +22 -1
- package/node_modules/@kardalum/api-schemas/dist/asset.schema.js +50 -15
- package/node_modules/@kardalum/api-schemas/dist/audit-api.schema.d.ts +204 -0
- package/node_modules/@kardalum/api-schemas/dist/audit-api.schema.js +134 -0
- package/node_modules/@kardalum/api-schemas/dist/content-api.schema.js +6 -5
- package/node_modules/@kardalum/api-schemas/dist/content-list.schema.d.ts +2 -2
- package/node_modules/@kardalum/api-schemas/dist/content-trash-api.schema.d.ts +4 -0
- package/node_modules/@kardalum/api-schemas/dist/content-trash-api.schema.js +3 -0
- package/node_modules/@kardalum/api-schemas/dist/content-trash.schema.js +2 -1
- package/node_modules/@kardalum/api-schemas/dist/core-actions.d.ts +41 -5
- package/node_modules/@kardalum/api-schemas/dist/core-actions.js +23 -9
- package/node_modules/@kardalum/api-schemas/dist/index.d.ts +36 -20
- package/node_modules/@kardalum/api-schemas/dist/index.js +21 -11
- package/node_modules/@kardalum/api-schemas/dist/install-warnings.schema.d.ts +4 -0
- package/node_modules/@kardalum/api-schemas/dist/install-warnings.schema.js +8 -0
- package/node_modules/@kardalum/api-schemas/dist/issue-list.d.ts +6 -0
- package/node_modules/@kardalum/api-schemas/dist/issue-list.js +6 -0
- package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.d.ts +101 -62
- package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.js +15 -4
- package/node_modules/@kardalum/api-schemas/dist/plugin-actions.schema.d.ts +6 -2
- package/node_modules/@kardalum/api-schemas/dist/plugin-actions.schema.js +8 -6
- package/node_modules/@kardalum/api-schemas/dist/plugin-docs-api.schema.d.ts +1 -16
- package/node_modules/@kardalum/api-schemas/dist/plugin-docs.d.ts +3 -19
- package/node_modules/@kardalum/api-schemas/dist/plugin-docs.js +13 -15
- package/node_modules/@kardalum/api-schemas/dist/plugin-id-rules.d.ts +17 -7
- package/node_modules/@kardalum/api-schemas/dist/plugin-id-rules.js +18 -8
- package/node_modules/@kardalum/api-schemas/dist/plugin-install-record.schema.d.ts +1 -1
- package/node_modules/@kardalum/api-schemas/dist/plugin-install.d.ts +97 -85
- package/node_modules/@kardalum/api-schemas/dist/plugin-install.js +35 -68
- package/node_modules/@kardalum/api-schemas/dist/plugin-labels.d.ts +60 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-labels.js +116 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-locales.d.ts +9 -2
- package/node_modules/@kardalum/api-schemas/dist/plugin-locales.js +22 -7
- package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.d.ts +13 -6
- package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.js +7 -1
- package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-actions.d.ts +4 -3
- package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-actions.js +1 -1
- package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-api-routes.d.ts +14 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-api-routes.js +37 -1
- package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-fields.d.ts +64 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-fields.js +134 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-registry-api.schema.d.ts +2 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-registry-api.schema.js +4 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-template-payload.d.ts +74 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-template-payload.js +132 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-vocabulary.d.ts +13 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-vocabulary.js +15 -0
- package/node_modules/@kardalum/api-schemas/dist/public-api.schema.js +12 -3
- package/node_modules/@kardalum/api-schemas/dist/role.schema.d.ts +11 -0
- package/node_modules/@kardalum/api-schemas/dist/role.schema.js +7 -0
- package/node_modules/@kardalum/api-schemas/dist/sample-content.schema.d.ts +11 -2
- package/node_modules/@kardalum/api-schemas/dist/sample-content.schema.js +21 -3
- package/node_modules/@kardalum/api-schemas/dist/sandbox-attach.schema.d.ts +126 -0
- package/node_modules/@kardalum/api-schemas/dist/sandbox-attach.schema.js +70 -0
- package/node_modules/@kardalum/api-schemas/dist/setup-api.schema.d.ts +6 -6
- package/node_modules/@kardalum/api-schemas/dist/sites.schema.d.ts +44 -25
- package/node_modules/@kardalum/api-schemas/dist/sites.schema.js +187 -48
- package/node_modules/@kardalum/api-schemas/dist/snapshot-api.schema.d.ts +15 -3
- package/node_modules/@kardalum/api-schemas/dist/snapshot-api.schema.js +14 -0
- package/node_modules/@kardalum/api-schemas/dist/snapshot.schema.d.ts +1 -1
- package/node_modules/@kardalum/api-schemas/dist/strict-url.d.ts +12 -0
- package/node_modules/@kardalum/api-schemas/dist/strict-url.js +31 -0
- package/node_modules/@kardalum/api-schemas/dist/template-api.schema.d.ts +105 -1
- package/node_modules/@kardalum/api-schemas/dist/template-api.schema.js +43 -3
- package/node_modules/@kardalum/api-schemas/dist/template.schema.d.ts +30 -2
- package/node_modules/@kardalum/api-schemas/dist/template.schema.js +19 -5
- package/node_modules/@kardalum/api-schemas/dist/trash-cursor.schema.d.ts +4 -0
- package/node_modules/@kardalum/api-schemas/dist/trash-cursor.schema.js +29 -0
- package/node_modules/@kardalum/api-schemas/dist/user-api.schema.d.ts +4 -0
- package/node_modules/@kardalum/api-schemas/dist/user-api.schema.js +3 -0
- package/node_modules/@kardalum/api-schemas/dist/whoami-api.schema.d.ts +19 -0
- package/node_modules/@kardalum/api-schemas/dist/whoami-api.schema.js +22 -0
- package/node_modules/@kardalum/api-schemas/package.json +2 -2
- package/node_modules/@kardalum/design-tokens/dist/tailwind-theme.d.ts +1 -0
- package/node_modules/@kardalum/design-tokens/dist/tailwind-theme.js +2 -0
- package/node_modules/@kardalum/design-tokens/dist/tokens.css +1 -0
- package/node_modules/@kardalum/design-tokens/dist/tokens.js +3 -0
- package/node_modules/@kardalum/design-tokens/dist/tokens.json +2 -1
- package/node_modules/@kardalum/design-tokens/dist/types.d.ts +1 -0
- package/node_modules/@kardalum/plugin-package/README.md +4 -1
- package/node_modules/@kardalum/plugin-package/dist/build-reference.d.ts +6 -21
- package/node_modules/@kardalum/plugin-package/dist/build-reference.js +13 -8
- package/node_modules/@kardalum/plugin-package/dist/capabilities.d.ts +4 -4
- package/node_modules/@kardalum/plugin-package/dist/capabilities.js +9 -14
- package/node_modules/@kardalum/plugin-package/dist/client-bundle.d.ts +4 -0
- package/node_modules/@kardalum/plugin-package/dist/client-bundle.js +25 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/archive-names.d.ts +25 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/archive-names.js +203 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/bundle.d.ts +3 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/bundle.js +73 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/contributions.d.ts +5 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/contributions.js +60 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/icon-names.generated.d.ts +1 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/icon-names.generated.js +2052 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/icons.d.ts +2 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/icons.js +51 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/index.d.ts +8 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/index.js +7 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/label-languages.d.ts +17 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/label-languages.js +119 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/limits.d.ts +14 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/limits.js +21 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/locales.d.ts +5 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/locales.js +148 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/package-files.d.ts +5 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/package-files.js +76 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/registry.d.ts +22 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/registry.js +133 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/sample-content.d.ts +3 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/sample-content.js +90 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/support.d.ts +24 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/support.js +55 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/templates.d.ts +6 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/templates.js +158 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/types.d.ts +53 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/types.js +1 -0
- package/node_modules/@kardalum/plugin-package/dist/docs-contract.d.ts +3 -2
- package/node_modules/@kardalum/plugin-package/dist/docs-contract.js +4 -2
- package/node_modules/@kardalum/plugin-package/dist/extract.d.ts +92 -3
- package/node_modules/@kardalum/plugin-package/dist/extract.js +251 -41
- package/node_modules/@kardalum/plugin-package/dist/index.d.ts +9 -2
- package/node_modules/@kardalum/plugin-package/dist/index.js +7 -2
- package/node_modules/@kardalum/plugin-package/dist/manifest-entry.d.ts +5 -0
- package/node_modules/@kardalum/plugin-package/dist/manifest-entry.js +20 -0
- package/node_modules/@kardalum/plugin-package/dist/reference-entry.d.ts +1 -0
- package/node_modules/@kardalum/plugin-package/dist/reference-entry.js +1 -0
- package/node_modules/@kardalum/plugin-package/dist/sample-content.d.ts +21 -3
- package/node_modules/@kardalum/plugin-package/dist/sample-content.js +37 -9
- package/node_modules/@kardalum/plugin-package/dist/shipped-files.d.ts +39 -0
- package/node_modules/@kardalum/plugin-package/dist/shipped-files.js +133 -0
- package/node_modules/@kardalum/plugin-package/dist/shipped-locales.d.ts +7 -0
- package/node_modules/@kardalum/plugin-package/dist/shipped-locales.js +27 -0
- package/node_modules/@kardalum/plugin-package/package.json +4 -2
- package/node_modules/@kardalum/ui/dist/components/dropdown-menu.js +2 -2
- package/node_modules/@kardalum/ui/package.json +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const SANDBOX_ATTACH_OUTCOMES: readonly ["installed", "activated", "already-active", "updated", "ready"];
|
|
3
|
+
export declare const SandboxAttachRequestSchema: z.ZodObject<{
|
|
4
|
+
pluginDir: z.ZodString;
|
|
5
|
+
bundleDir: z.ZodString;
|
|
6
|
+
remoteUrl: z.ZodPipe<z.ZodString, z.ZodURL>;
|
|
7
|
+
answersPath: z.ZodOptional<z.ZodString>;
|
|
8
|
+
}, z.core.$strict>;
|
|
9
|
+
export declare const SandboxAttachResponseSchema: z.ZodObject<{
|
|
10
|
+
pluginId: z.ZodString;
|
|
11
|
+
version: z.ZodString;
|
|
12
|
+
outcome: z.ZodEnum<{
|
|
13
|
+
updated: "updated";
|
|
14
|
+
installed: "installed";
|
|
15
|
+
activated: "activated";
|
|
16
|
+
"already-active": "already-active";
|
|
17
|
+
ready: "ready";
|
|
18
|
+
}>;
|
|
19
|
+
packagePath: z.ZodString;
|
|
20
|
+
}, z.core.$strip>;
|
|
21
|
+
export type SandboxAttachRequest = z.infer<typeof SandboxAttachRequestSchema>;
|
|
22
|
+
export type SandboxAttachResponse = z.infer<typeof SandboxAttachResponseSchema>;
|
|
23
|
+
export declare const SandboxLocalPluginSchema: z.ZodObject<{
|
|
24
|
+
pluginId: z.ZodString;
|
|
25
|
+
name: z.ZodString;
|
|
26
|
+
version: z.ZodString;
|
|
27
|
+
attachId: z.ZodNumber;
|
|
28
|
+
installed: z.ZodBoolean;
|
|
29
|
+
installInterface: z.ZodObject<{
|
|
30
|
+
consent: z.ZodArray<z.ZodObject<{
|
|
31
|
+
id: z.ZodString;
|
|
32
|
+
details: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodPreprocess<z.ZodObject<{
|
|
33
|
+
en: z.ZodString;
|
|
34
|
+
}, z.core.$catchall<z.ZodString>>, unknown>]>>;
|
|
35
|
+
}, z.core.$strict>>;
|
|
36
|
+
sampleContent: z.ZodNullable<z.ZodObject<{
|
|
37
|
+
default: z.ZodLiteral<true>;
|
|
38
|
+
description: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
39
|
+
en: z.ZodString;
|
|
40
|
+
}, z.core.$catchall<z.ZodString>>, unknown>>;
|
|
41
|
+
}, z.core.$strict>>;
|
|
42
|
+
roles: z.ZodArray<z.ZodObject<{
|
|
43
|
+
id: z.ZodString;
|
|
44
|
+
label: z.ZodUnion<readonly [z.ZodString, z.ZodPreprocess<z.ZodObject<{
|
|
45
|
+
en: z.ZodString;
|
|
46
|
+
}, z.core.$catchall<z.ZodString>>, unknown>]>;
|
|
47
|
+
actions: z.ZodArray<z.ZodString>;
|
|
48
|
+
default: z.ZodLiteral<false>;
|
|
49
|
+
}, z.core.$strict>>;
|
|
50
|
+
steps: z.ZodArray<z.ZodObject<{
|
|
51
|
+
id: z.ZodString;
|
|
52
|
+
label: z.ZodPreprocess<z.ZodObject<{
|
|
53
|
+
en: z.ZodString;
|
|
54
|
+
}, z.core.$catchall<z.ZodString>>, unknown>;
|
|
55
|
+
description: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
56
|
+
en: z.ZodString;
|
|
57
|
+
}, z.core.$catchall<z.ZodString>>, unknown>>;
|
|
58
|
+
options: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
59
|
+
kind: z.ZodLiteral<"boolean">;
|
|
60
|
+
default: z.ZodBoolean;
|
|
61
|
+
id: z.ZodString;
|
|
62
|
+
label: z.ZodPreprocess<z.ZodObject<{
|
|
63
|
+
en: z.ZodString;
|
|
64
|
+
}, z.core.$catchall<z.ZodString>>, unknown>;
|
|
65
|
+
description: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
66
|
+
en: z.ZodString;
|
|
67
|
+
}, z.core.$catchall<z.ZodString>>, unknown>>;
|
|
68
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
69
|
+
kind: z.ZodLiteral<"select">;
|
|
70
|
+
choices: z.ZodArray<z.ZodObject<{
|
|
71
|
+
id: z.ZodString;
|
|
72
|
+
label: z.ZodPreprocess<z.ZodObject<{
|
|
73
|
+
en: z.ZodString;
|
|
74
|
+
}, z.core.$catchall<z.ZodString>>, unknown>;
|
|
75
|
+
description: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
76
|
+
en: z.ZodString;
|
|
77
|
+
}, z.core.$catchall<z.ZodString>>, unknown>>;
|
|
78
|
+
}, z.core.$strict>>;
|
|
79
|
+
default: z.ZodOptional<z.ZodString>;
|
|
80
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
81
|
+
id: z.ZodString;
|
|
82
|
+
label: z.ZodPreprocess<z.ZodObject<{
|
|
83
|
+
en: z.ZodString;
|
|
84
|
+
}, z.core.$catchall<z.ZodString>>, unknown>;
|
|
85
|
+
description: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
86
|
+
en: z.ZodString;
|
|
87
|
+
}, z.core.$catchall<z.ZodString>>, unknown>>;
|
|
88
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
89
|
+
kind: z.ZodLiteral<"multiSelect">;
|
|
90
|
+
choices: z.ZodArray<z.ZodObject<{
|
|
91
|
+
id: z.ZodString;
|
|
92
|
+
label: z.ZodPreprocess<z.ZodObject<{
|
|
93
|
+
en: z.ZodString;
|
|
94
|
+
}, z.core.$catchall<z.ZodString>>, unknown>;
|
|
95
|
+
description: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
96
|
+
en: z.ZodString;
|
|
97
|
+
}, z.core.$catchall<z.ZodString>>, unknown>>;
|
|
98
|
+
}, z.core.$strict>>;
|
|
99
|
+
default: z.ZodArray<z.ZodString>;
|
|
100
|
+
id: z.ZodString;
|
|
101
|
+
label: z.ZodPreprocess<z.ZodObject<{
|
|
102
|
+
en: z.ZodString;
|
|
103
|
+
}, z.core.$catchall<z.ZodString>>, unknown>;
|
|
104
|
+
description: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
105
|
+
en: z.ZodString;
|
|
106
|
+
}, z.core.$catchall<z.ZodString>>, unknown>>;
|
|
107
|
+
}, z.core.$strict>], "kind">>;
|
|
108
|
+
}, z.core.$strict>>;
|
|
109
|
+
}, z.core.$strict>;
|
|
110
|
+
actions: z.ZodArray<z.ZodObject<{
|
|
111
|
+
id: z.ZodString;
|
|
112
|
+
label: z.ZodUnion<readonly [z.ZodString, z.ZodPreprocess<z.ZodObject<{
|
|
113
|
+
en: z.ZodString;
|
|
114
|
+
}, z.core.$catchall<z.ZodString>>, unknown>]>;
|
|
115
|
+
}, z.core.$strip>>;
|
|
116
|
+
}, z.core.$strict>;
|
|
117
|
+
export declare const SandboxLocalPluginInstallRequestSchema: z.ZodObject<{
|
|
118
|
+
attachId: z.ZodNumber;
|
|
119
|
+
answers: z.ZodObject<{
|
|
120
|
+
sampleContent: z.ZodOptional<z.ZodBoolean>;
|
|
121
|
+
roles: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
122
|
+
options: z.ZodOptional<z.ZodPreprocess<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodBoolean, z.ZodString, z.ZodArray<z.ZodString>]>>, unknown>>;
|
|
123
|
+
}, z.core.$strict>;
|
|
124
|
+
}, z.core.$strict>;
|
|
125
|
+
export type SandboxLocalPlugin = z.infer<typeof SandboxLocalPluginSchema>;
|
|
126
|
+
export type SandboxLocalPluginInstallRequest = z.infer<typeof SandboxLocalPluginInstallRequestSchema>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { PluginActionDeclarationSchema } from "./plugin-actions.schema.js";
|
|
3
|
+
import { InstallAnswersSchema, InstallInterfaceSchema } from "./plugin-install.js";
|
|
4
|
+
import { hasNoControlCharacter, strictUrl } from "./strict-url.js";
|
|
5
|
+
// S313: the body and the answer of POST /api/manage/v1/sandbox/local-plugin,
|
|
6
|
+
// the route a server started by `kardalum dev` registers
|
|
7
|
+
// (KARDALUM_SANDBOX_ATTACH, never under NODE_ENV=production). Every path names
|
|
8
|
+
// a directory on the server's own disk: the sandbox and the server it starts
|
|
9
|
+
// share one machine.
|
|
10
|
+
// A control character has no place in a path or a URL the server opens.
|
|
11
|
+
const LocalPath = z.string().min(1).max(4096).refine(hasNoControlCharacter, "A path must not contain control characters");
|
|
12
|
+
// The row stores remoteUrl and the admin loads it as a federation remote, so
|
|
13
|
+
// it is an http or https URL and nothing else. The URL parser drops a tab or a
|
|
14
|
+
// line break silently, and zod's own URL check strips one as well (zod 4.6),
|
|
15
|
+
// so the strict URL helper refuses every control character on the raw string,
|
|
16
|
+
// ahead of the URL check (S314e, spec C6): a URL with a trailing newline or tab
|
|
17
|
+
// was accepted before and is refused now.
|
|
18
|
+
// Fastify prefixes the field ("body/remoteUrl"), so the message does not name it.
|
|
19
|
+
const REMOTE_URL_MESSAGE = "must be an http or https URL";
|
|
20
|
+
const RemoteUrl = strictUrl({ protocol: /^https?$/, error: REMOTE_URL_MESSAGE, max: 2048 });
|
|
21
|
+
// S313b (W1): "ready" is the attach that installed nothing: no registry row for
|
|
22
|
+
// the plugin and no answers file, so the sandbox admin's install screen asks.
|
|
23
|
+
export const SANDBOX_ATTACH_OUTCOMES = ["installed", "activated", "already-active", "updated", "ready"];
|
|
24
|
+
export const SandboxAttachRequestSchema = z
|
|
25
|
+
.object({
|
|
26
|
+
pluginDir: LocalPath.describe("The plugin project's root, as an absolute path. Its install facts, templates, public files and sample content are read from here."),
|
|
27
|
+
bundleDir: LocalPath.describe("An absolute path to a directory holding server/plugin.js and the docs files beside it, as `kardalum plugin bundle-server` writes them. Use a new directory for every bundle: a module already imported from a path is answered from memory."),
|
|
28
|
+
remoteUrl: RemoteUrl.describe("The http or https URL the plugin's federation remote (remoteEntry.js) is served from."),
|
|
29
|
+
answersPath: LocalPath.optional().describe("An absolute path to the project's install-answers.json, read on a fresh install and, at a version bump, for the options the install record does not cover."),
|
|
30
|
+
})
|
|
31
|
+
.strict();
|
|
32
|
+
export const SandboxAttachResponseSchema = z.object({
|
|
33
|
+
pluginId: z.string(),
|
|
34
|
+
version: z.string(),
|
|
35
|
+
outcome: z.enum(SANDBOX_ATTACH_OUTCOMES),
|
|
36
|
+
/** The bundle directory the registry row now names. */
|
|
37
|
+
packagePath: z.string(),
|
|
38
|
+
});
|
|
39
|
+
// S313b (W2): what GET /api/manage/v1/sandbox/local-plugin answers: the bundle
|
|
40
|
+
// the last attach since the server started handed over, the install interface
|
|
41
|
+
// installInterfaceFor computes for it (the one a marketplace listing carries),
|
|
42
|
+
// the actions it declares (so the install screen names the rights an offered
|
|
43
|
+
// role grants by their labels), and whether a registry row exists for it.
|
|
44
|
+
// S313b fix wave C (C1): attachId numbers the attach the description comes
|
|
45
|
+
// from (one more for each attach, and above every number an earlier server
|
|
46
|
+
// process handed out, fix wave E, E1: a restart must not give an install
|
|
47
|
+
// screen opened before it the number of the next process's first attach); the
|
|
48
|
+
// install screen sends it back, and the install route refuses a screen built
|
|
49
|
+
// from an older attach.
|
|
50
|
+
const AttachId = z.number().int().positive();
|
|
51
|
+
export const SandboxLocalPluginSchema = z
|
|
52
|
+
.object({
|
|
53
|
+
pluginId: z.string(),
|
|
54
|
+
name: z.string(),
|
|
55
|
+
version: z.string(),
|
|
56
|
+
attachId: AttachId.describe("Numbers the attach this description comes from: send it back with the install screen's answers."),
|
|
57
|
+
installed: z.boolean(),
|
|
58
|
+
installInterface: InstallInterfaceSchema,
|
|
59
|
+
actions: z.array(PluginActionDeclarationSchema),
|
|
60
|
+
})
|
|
61
|
+
.strict();
|
|
62
|
+
// S313b (W2): the body of POST /api/manage/v1/sandbox/local-plugin/install: the
|
|
63
|
+
// install screen's answers, the same object every install route takes, and
|
|
64
|
+
// (fix wave C, C1) the attach id of the description the screen was built from.
|
|
65
|
+
export const SandboxLocalPluginInstallRequestSchema = z
|
|
66
|
+
.object({
|
|
67
|
+
attachId: AttachId.describe("The attachId of the GET answer the install screen was built from."),
|
|
68
|
+
answers: InstallAnswersSchema,
|
|
69
|
+
})
|
|
70
|
+
.strict();
|
|
@@ -7,7 +7,7 @@ export declare const BundledTemplateSchema: z.ZodObject<{
|
|
|
7
7
|
sampleContent: z.ZodBoolean;
|
|
8
8
|
sampleContentDescription: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
9
9
|
en: z.ZodString;
|
|
10
|
-
}, z.core.$catchall<z.ZodString
|
|
10
|
+
}, z.core.$catchall<z.ZodString>>, unknown>>;
|
|
11
11
|
}, z.core.$strip>;
|
|
12
12
|
export type BundledTemplate = z.infer<typeof BundledTemplateSchema>;
|
|
13
13
|
export declare const SetupStatusResponseSchema: z.ZodObject<{
|
|
@@ -20,7 +20,7 @@ export declare const SetupStatusResponseSchema: z.ZodObject<{
|
|
|
20
20
|
sampleContent: z.ZodBoolean;
|
|
21
21
|
sampleContentDescription: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
22
22
|
en: z.ZodString;
|
|
23
|
-
}, z.core.$catchall<z.ZodString
|
|
23
|
+
}, z.core.$catchall<z.ZodString>>, unknown>>;
|
|
24
24
|
}, z.core.$strip>>;
|
|
25
25
|
databaseConfigured: z.ZodBoolean;
|
|
26
26
|
}, z.core.$strip>;
|
|
@@ -30,7 +30,7 @@ export declare const SetupStarterSelectionSchema: z.ZodObject<{
|
|
|
30
30
|
answers: z.ZodOptional<z.ZodObject<{
|
|
31
31
|
sampleContent: z.ZodOptional<z.ZodBoolean>;
|
|
32
32
|
roles: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
33
|
-
options: z.ZodOptional<z.ZodPreprocess<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodBoolean, z.ZodString, z.ZodArray<z.ZodString>]
|
|
33
|
+
options: z.ZodOptional<z.ZodPreprocess<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodBoolean, z.ZodString, z.ZodArray<z.ZodString>]>>, unknown>>;
|
|
34
34
|
}, z.core.$strict>>;
|
|
35
35
|
}, z.core.$strict>;
|
|
36
36
|
export type SetupStarterSelection = z.infer<typeof SetupStarterSelectionSchema>;
|
|
@@ -63,7 +63,7 @@ export declare const SetupCompleteRequestSchema: z.ZodObject<{
|
|
|
63
63
|
answers: z.ZodOptional<z.ZodObject<{
|
|
64
64
|
sampleContent: z.ZodOptional<z.ZodBoolean>;
|
|
65
65
|
roles: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
66
|
-
options: z.ZodOptional<z.ZodPreprocess<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodBoolean, z.ZodString, z.ZodArray<z.ZodString>]
|
|
66
|
+
options: z.ZodOptional<z.ZodPreprocess<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodBoolean, z.ZodString, z.ZodArray<z.ZodString>]>>, unknown>>;
|
|
67
67
|
}, z.core.$strict>>;
|
|
68
68
|
}, z.core.$strict>>;
|
|
69
69
|
}, z.core.$strip>;
|
|
@@ -93,9 +93,9 @@ export declare const SetupStarterResultSchema: z.ZodObject<{
|
|
|
93
93
|
roles: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
94
94
|
id: z.ZodString;
|
|
95
95
|
outcome: z.ZodEnum<{
|
|
96
|
+
failed: "failed";
|
|
96
97
|
created: "created";
|
|
97
98
|
"already-exists": "already-exists";
|
|
98
|
-
failed: "failed";
|
|
99
99
|
}>;
|
|
100
100
|
}, z.core.$strip>>>;
|
|
101
101
|
}, z.core.$strip>;
|
|
@@ -127,9 +127,9 @@ export declare const SetupCompleteResponseSchema: z.ZodObject<{
|
|
|
127
127
|
roles: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
128
128
|
id: z.ZodString;
|
|
129
129
|
outcome: z.ZodEnum<{
|
|
130
|
+
failed: "failed";
|
|
130
131
|
created: "created";
|
|
131
132
|
"already-exists": "already-exists";
|
|
132
|
-
failed: "failed";
|
|
133
133
|
}>;
|
|
134
134
|
}, z.core.$strip>>>;
|
|
135
135
|
}, z.core.$strip>>;
|
|
@@ -1,37 +1,56 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
/** A site's domain in parts: what `parseSiteDomain` reads and `formatSiteDomain` writes. */
|
|
3
|
+
export interface SiteDomain {
|
|
4
|
+
/** Present only when it was typed. It is never matched, only printed (D4). */
|
|
5
|
+
scheme?: "http" | "https";
|
|
6
|
+
/** A host name or an IPv4 address, lower case, no trailing dot. */
|
|
7
|
+
host: string;
|
|
8
|
+
/** Present only when it was typed, and never the scheme's own port (nor 80 or 443 without a scheme). */
|
|
9
|
+
port?: number;
|
|
10
|
+
}
|
|
2
11
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
12
|
+
* Reads what a person pastes into a site's domain field (S314i D1):
|
|
13
|
+
* `example.com`, `www.example.com`, `http://example.com`,
|
|
14
|
+
* `https://www.example.com:2136`, `localhost`, `localhost:3000`,
|
|
15
|
+
* `127.0.0.1:3100`, a one-word host, with or without a trailing slash.
|
|
16
|
+
* Trims, takes an `http://` or `https://` in any letter case, drops one
|
|
17
|
+
* trailing slash, then reads `host[:port]`. Returns null for anything else:
|
|
18
|
+
* a path, a query, a fragment, a user, a wildcard, an IPv6 address, another
|
|
19
|
+
* scheme, a port outside 1 to 65535 or written with a leading zero.
|
|
10
20
|
*
|
|
11
|
-
*
|
|
12
|
-
* (
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* An IP address is refused: a site's domain is a name, and the server's IP
|
|
19
|
-
* is an unclaimed address, which shows the default site. A name whose last
|
|
20
|
-
* label is a number is how an IPv4 address reads to a browser and to some
|
|
21
|
-
* resolvers (the WHATWG URL rule), and a number there is all digits or
|
|
22
|
-
* begins with "0x". So a name is refused when its last label is all digits
|
|
23
|
-
* or begins with "0x" or "0X", whatever follows: "0x7f000001" is
|
|
24
|
-
* 127.0.0.1 to a browser. No registered top-level domain begins that way.
|
|
21
|
+
* `www.` is kept as typed: a domain is matched as written. A port equal to
|
|
22
|
+
* the scheme's own (80 for http, 443 for https) is dropped, because a
|
|
23
|
+
* browser never sends it and the domain would otherwise match nothing.
|
|
24
|
+
* Without a scheme, 80 and 443 are both dropped for the same reason, so
|
|
25
|
+
* "example.com:443" is "example.com" and cannot sit beside
|
|
26
|
+
* "https://example.com" on another site. A port that is not the given
|
|
27
|
+
* scheme's own ("http://example.com:443") is kept: a browser sends it.
|
|
25
28
|
*
|
|
26
29
|
* Written with string functions only, behind a length cap, because the
|
|
27
30
|
* input is whatever somebody typed or sent: no pattern is ever run over it.
|
|
28
31
|
*/
|
|
29
|
-
export declare function
|
|
32
|
+
export declare function parseSiteDomain(input: string): SiteDomain | null;
|
|
33
|
+
/** The stored string of a domain: `[scheme://]host[:port]`. */
|
|
34
|
+
export declare function formatSiteDomain(domain: SiteDomain): string;
|
|
35
|
+
/**
|
|
36
|
+
* A stored domain without its scheme: `host[:port]`. This is what a domain
|
|
37
|
+
* is matched by and counted by (S314i D2, D3): `http://a.test` and
|
|
38
|
+
* `https://a.test` are one domain. A value with no scheme (the host of
|
|
39
|
+
* KARDALUM_PUBLIC_URL) comes back as it is.
|
|
40
|
+
*/
|
|
41
|
+
export declare function siteDomainAuthority(domain: string): string;
|
|
42
|
+
/**
|
|
43
|
+
* The origin a link or a redirect to a stored domain is written with
|
|
44
|
+
* (S314i D4): the domain as stored when it carries a scheme, otherwise
|
|
45
|
+
* `scheme` (the request's, or KARDALUM_PUBLIC_URL's) in front of it. The
|
|
46
|
+
* port is the stored one, or none.
|
|
47
|
+
*/
|
|
48
|
+
export declare function siteDomainOrigin(domain: string, scheme: "http" | "https"): string;
|
|
30
49
|
/**
|
|
31
|
-
* One domain of a site. Parses through `
|
|
32
|
-
*
|
|
50
|
+
* One domain of a site. Parses through `parseSiteDomain`, so the output is
|
|
51
|
+
* the stored form, and a stored domain parses to itself.
|
|
33
52
|
*/
|
|
34
|
-
export declare const
|
|
53
|
+
export declare const SiteDomainSchema: z.ZodType<string, string>;
|
|
35
54
|
export declare const MAX_HOSTNAMES_PER_SITE = 20;
|
|
36
55
|
/**
|
|
37
56
|
* The domains of one site, in order: the first is the site's address, and
|
|
@@ -1,18 +1,31 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { firstSegment, publicPath } from "./content-path.js";
|
|
3
3
|
// S277d: a site (a top-level node) can have its own domains. Everything
|
|
4
|
-
// here is the shape of that record and the rule for one
|
|
5
|
-
|
|
4
|
+
// here is the shape of that record and the rule for one domain.
|
|
5
|
+
//
|
|
6
|
+
// S314i: a domain is a host with an optional port and an optional scheme,
|
|
7
|
+
// stored as one string `[scheme://]host[:port]`. The admin's field, the
|
|
8
|
+
// route that writes the record, the server's match and the public lookup
|
|
9
|
+
// by address all read it through `parseSiteDomain`, so one rule decides.
|
|
10
|
+
/** The longest a host name may be (RFC 1035), without a trailing dot. */
|
|
6
11
|
const MAX_HOSTNAME_LENGTH = 253;
|
|
7
|
-
/** The longest one label of a
|
|
12
|
+
/** The longest one label of a host name may be. */
|
|
8
13
|
const MAX_LABEL_LENGTH = 63;
|
|
9
14
|
/**
|
|
10
|
-
* The longest input that is looked at at all. Twice the longest
|
|
11
|
-
* leaves room for surrounding whitespace
|
|
12
|
-
*
|
|
13
|
-
* costs the same whatever its length.
|
|
15
|
+
* The longest input that is looked at at all. Twice the longest host name
|
|
16
|
+
* leaves room for a scheme, a port, surrounding whitespace, a trailing dot
|
|
17
|
+
* and a trailing slash; anything longer is refused before a single
|
|
18
|
+
* character is read, so a hostile input costs the same whatever its length.
|
|
14
19
|
*/
|
|
15
|
-
const
|
|
20
|
+
const MAX_SITE_DOMAIN_INPUT_LENGTH = MAX_HOSTNAME_LENGTH * 2;
|
|
21
|
+
/** The highest port there is. */
|
|
22
|
+
const MAX_PORT = 65535;
|
|
23
|
+
/** "65535" has five digits. */
|
|
24
|
+
const MAX_PORT_DIGITS = 5;
|
|
25
|
+
/** The highest value of one part of an IPv4 address. */
|
|
26
|
+
const MAX_OCTET = 255;
|
|
27
|
+
/** The port a browser leaves out of the Host for each scheme. */
|
|
28
|
+
const DEFAULT_PORT = { http: 80, https: 443 };
|
|
16
29
|
const CODE_0 = 48;
|
|
17
30
|
const CODE_9 = 57;
|
|
18
31
|
const CODE_UPPER_A = 65;
|
|
@@ -22,6 +35,8 @@ const CODE_LOWER_Z = 122;
|
|
|
22
35
|
const CODE_DASH = 45;
|
|
23
36
|
const CODE_UPPER_X = 88;
|
|
24
37
|
const CODE_LOWER_X = 120;
|
|
38
|
+
/** Upper case to lower case, for A-Z. */
|
|
39
|
+
const ASCII_CASE_OFFSET = 32;
|
|
25
40
|
function isDigit(code) {
|
|
26
41
|
return code >= CODE_0 && code <= CODE_9;
|
|
27
42
|
}
|
|
@@ -31,39 +46,71 @@ function isLabelCharacter(code) {
|
|
|
31
46
|
isDigit(code) ||
|
|
32
47
|
code === CODE_DASH);
|
|
33
48
|
}
|
|
49
|
+
function isAllDigits(text) {
|
|
50
|
+
if (text.length === 0)
|
|
51
|
+
return false;
|
|
52
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
53
|
+
if (!isDigit(text.charCodeAt(i)))
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
34
58
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
|
|
59
|
+
* Whether `text` begins with `prefix` (lower case ASCII) in any letter
|
|
60
|
+
* case. Character by character, so no character outside A-Z is ever
|
|
61
|
+
* folded into one of the prefix's.
|
|
62
|
+
*/
|
|
63
|
+
function startsWithIgnoringAsciiCase(text, prefix) {
|
|
64
|
+
if (text.length < prefix.length)
|
|
65
|
+
return false;
|
|
66
|
+
for (let i = 0; i < prefix.length; i += 1) {
|
|
67
|
+
let code = text.charCodeAt(i);
|
|
68
|
+
if (code >= CODE_UPPER_A && code <= CODE_UPPER_Z)
|
|
69
|
+
code += ASCII_CASE_OFFSET;
|
|
70
|
+
if (code !== prefix.charCodeAt(i))
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
/** Four decimal parts, each 0 to 255, none written with a leading zero. */
|
|
76
|
+
function isIpv4(labels) {
|
|
77
|
+
if (labels.length !== 4)
|
|
78
|
+
return false;
|
|
79
|
+
for (const label of labels) {
|
|
80
|
+
if (!isAllDigits(label) || label.length > 3)
|
|
81
|
+
return false;
|
|
82
|
+
if (label.length > 1 && label.charCodeAt(0) === CODE_0)
|
|
83
|
+
return false;
|
|
84
|
+
if (Number(label) > MAX_OCTET)
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Drops one trailing dot and lower-cases. Returns null when the result is
|
|
91
|
+
* neither a host name nor an IPv4 address.
|
|
39
92
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
93
|
+
* A host name is one or more labels of a-z, 0-9 and "-" joined by dots, no
|
|
94
|
+
* label empty, longer than 63, or starting or ending with a dash, the
|
|
95
|
+
* whole name no longer than 253. So no scheme, port, path, wildcard, user
|
|
96
|
+
* or space gets through: each needs a character a label cannot hold.
|
|
42
97
|
*
|
|
43
98
|
* An internationalised domain is entered in its ASCII form
|
|
44
99
|
* ("xn--bcher-kva.example"); a name with a non-ASCII character is refused.
|
|
45
100
|
* The characters are tested BEFORE lower-casing, because lower-casing can
|
|
46
|
-
* turn a character that is not a letter of a
|
|
101
|
+
* turn a character that is not a letter of a host name into one (U+212A,
|
|
47
102
|
* the Kelvin sign, becomes "k"), and two entries would then mean one host.
|
|
48
103
|
*
|
|
49
104
|
* A single label such as "localhost" is accepted: a local setup needs it.
|
|
50
|
-
* An
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* resolvers (the WHATWG URL rule), and a number there is all digits
|
|
54
|
-
* begins with "0x". So
|
|
55
|
-
*
|
|
56
|
-
* 127.0.0.1 to a browser. No registered top-level domain begins that way.
|
|
57
|
-
*
|
|
58
|
-
* Written with string functions only, behind a length cap, because the
|
|
59
|
-
* input is whatever somebody typed or sent: no pattern is ever run over it.
|
|
105
|
+
* An IPv4 address (four parts, each 0 to 255, no leading zero) is accepted
|
|
106
|
+
* (S314i D1). Any other name whose last label is a number is refused: that
|
|
107
|
+
* is how an IPv4 address in another spelling reads to a browser and to
|
|
108
|
+
* some resolvers (the WHATWG URL rule), and a number there is all digits
|
|
109
|
+
* or begins with "0x". So "10.1" and "0x7f000001" are refused, and no
|
|
110
|
+
* registered top-level domain begins that way.
|
|
60
111
|
*/
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return null;
|
|
64
|
-
if (input.length > MAX_HOSTNAME_INPUT_LENGTH)
|
|
65
|
-
return null;
|
|
66
|
-
let name = input.trim();
|
|
112
|
+
function normalizeHost(input) {
|
|
113
|
+
let name = input;
|
|
67
114
|
if (name.endsWith("."))
|
|
68
115
|
name = name.slice(0, -1);
|
|
69
116
|
if (name.length === 0 || name.length > MAX_HOSTNAME_LENGTH)
|
|
@@ -79,15 +126,11 @@ export function normalizeHostname(input) {
|
|
|
79
126
|
return null;
|
|
80
127
|
}
|
|
81
128
|
}
|
|
129
|
+
// Digits and dots only: nothing to lower-case.
|
|
130
|
+
if (isIpv4(labels))
|
|
131
|
+
return name;
|
|
82
132
|
const last = labels[labels.length - 1];
|
|
83
|
-
|
|
84
|
-
for (let i = 0; i < last.length; i += 1) {
|
|
85
|
-
if (!isDigit(last.charCodeAt(i))) {
|
|
86
|
-
allDigits = false;
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
if (allDigits)
|
|
133
|
+
if (isAllDigits(last))
|
|
91
134
|
return null;
|
|
92
135
|
// "0x" or "0X" first: a hexadecimal number to the same readers.
|
|
93
136
|
if (last.charCodeAt(0) === CODE_0 && (last.charCodeAt(1) === CODE_LOWER_X || last.charCodeAt(1) === CODE_UPPER_X)) {
|
|
@@ -96,20 +139,116 @@ export function normalizeHostname(input) {
|
|
|
96
139
|
// Every character is ASCII by now, so this changes A-Z and nothing else.
|
|
97
140
|
return name.toLowerCase();
|
|
98
141
|
}
|
|
142
|
+
/** 1 to 65535, written in digits without a leading zero; null otherwise. */
|
|
143
|
+
function parsePort(text) {
|
|
144
|
+
if (text.length === 0 || text.length > MAX_PORT_DIGITS)
|
|
145
|
+
return null;
|
|
146
|
+
if (!isAllDigits(text) || text.charCodeAt(0) === CODE_0)
|
|
147
|
+
return null;
|
|
148
|
+
const port = Number(text);
|
|
149
|
+
return port >= 1 && port <= MAX_PORT ? port : null;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Reads what a person pastes into a site's domain field (S314i D1):
|
|
153
|
+
* `example.com`, `www.example.com`, `http://example.com`,
|
|
154
|
+
* `https://www.example.com:2136`, `localhost`, `localhost:3000`,
|
|
155
|
+
* `127.0.0.1:3100`, a one-word host, with or without a trailing slash.
|
|
156
|
+
* Trims, takes an `http://` or `https://` in any letter case, drops one
|
|
157
|
+
* trailing slash, then reads `host[:port]`. Returns null for anything else:
|
|
158
|
+
* a path, a query, a fragment, a user, a wildcard, an IPv6 address, another
|
|
159
|
+
* scheme, a port outside 1 to 65535 or written with a leading zero.
|
|
160
|
+
*
|
|
161
|
+
* `www.` is kept as typed: a domain is matched as written. A port equal to
|
|
162
|
+
* the scheme's own (80 for http, 443 for https) is dropped, because a
|
|
163
|
+
* browser never sends it and the domain would otherwise match nothing.
|
|
164
|
+
* Without a scheme, 80 and 443 are both dropped for the same reason, so
|
|
165
|
+
* "example.com:443" is "example.com" and cannot sit beside
|
|
166
|
+
* "https://example.com" on another site. A port that is not the given
|
|
167
|
+
* scheme's own ("http://example.com:443") is kept: a browser sends it.
|
|
168
|
+
*
|
|
169
|
+
* Written with string functions only, behind a length cap, because the
|
|
170
|
+
* input is whatever somebody typed or sent: no pattern is ever run over it.
|
|
171
|
+
*/
|
|
172
|
+
export function parseSiteDomain(input) {
|
|
173
|
+
if (typeof input !== "string")
|
|
174
|
+
return null;
|
|
175
|
+
if (input.length > MAX_SITE_DOMAIN_INPUT_LENGTH)
|
|
176
|
+
return null;
|
|
177
|
+
let rest = input.trim();
|
|
178
|
+
let scheme;
|
|
179
|
+
if (startsWithIgnoringAsciiCase(rest, "https://")) {
|
|
180
|
+
scheme = "https";
|
|
181
|
+
rest = rest.slice("https://".length);
|
|
182
|
+
}
|
|
183
|
+
else if (startsWithIgnoringAsciiCase(rest, "http://")) {
|
|
184
|
+
scheme = "http";
|
|
185
|
+
rest = rest.slice("http://".length);
|
|
186
|
+
}
|
|
187
|
+
if (rest.endsWith("/"))
|
|
188
|
+
rest = rest.slice(0, -1);
|
|
189
|
+
let hostText = rest;
|
|
190
|
+
let port;
|
|
191
|
+
const colon = rest.indexOf(":");
|
|
192
|
+
if (colon !== -1) {
|
|
193
|
+
hostText = rest.slice(0, colon);
|
|
194
|
+
const parsed = parsePort(rest.slice(colon + 1));
|
|
195
|
+
if (parsed === null)
|
|
196
|
+
return null;
|
|
197
|
+
port = parsed;
|
|
198
|
+
}
|
|
199
|
+
const host = normalizeHost(hostText);
|
|
200
|
+
if (host === null)
|
|
201
|
+
return null;
|
|
202
|
+
// With a scheme, its own port goes; without one, either goes (S314i C3).
|
|
203
|
+
const isDefaultPort = scheme === undefined ? port === DEFAULT_PORT.http || port === DEFAULT_PORT.https : port === DEFAULT_PORT[scheme];
|
|
204
|
+
if (isDefaultPort)
|
|
205
|
+
port = undefined;
|
|
206
|
+
return { ...(scheme !== undefined ? { scheme } : {}), host, ...(port !== undefined ? { port } : {}) };
|
|
207
|
+
}
|
|
208
|
+
/** The stored string of a domain: `[scheme://]host[:port]`. */
|
|
209
|
+
export function formatSiteDomain(domain) {
|
|
210
|
+
const scheme = domain.scheme === undefined ? "" : `${domain.scheme}://`;
|
|
211
|
+
const port = domain.port === undefined ? "" : `:${domain.port}`;
|
|
212
|
+
return `${scheme}${domain.host}${port}`;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* A stored domain without its scheme: `host[:port]`. This is what a domain
|
|
216
|
+
* is matched by and counted by (S314i D2, D3): `http://a.test` and
|
|
217
|
+
* `https://a.test` are one domain. A value with no scheme (the host of
|
|
218
|
+
* KARDALUM_PUBLIC_URL) comes back as it is.
|
|
219
|
+
*/
|
|
220
|
+
export function siteDomainAuthority(domain) {
|
|
221
|
+
if (domain.startsWith("https://"))
|
|
222
|
+
return domain.slice("https://".length);
|
|
223
|
+
if (domain.startsWith("http://"))
|
|
224
|
+
return domain.slice("http://".length);
|
|
225
|
+
return domain;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* The origin a link or a redirect to a stored domain is written with
|
|
229
|
+
* (S314i D4): the domain as stored when it carries a scheme, otherwise
|
|
230
|
+
* `scheme` (the request's, or KARDALUM_PUBLIC_URL's) in front of it. The
|
|
231
|
+
* port is the stored one, or none.
|
|
232
|
+
*/
|
|
233
|
+
export function siteDomainOrigin(domain, scheme) {
|
|
234
|
+
if (domain.startsWith("https://") || domain.startsWith("http://"))
|
|
235
|
+
return domain;
|
|
236
|
+
return `${scheme}://${domain}`;
|
|
237
|
+
}
|
|
99
238
|
/**
|
|
100
|
-
* One domain of a site. Parses through `
|
|
101
|
-
*
|
|
239
|
+
* One domain of a site. Parses through `parseSiteDomain`, so the output is
|
|
240
|
+
* the stored form, and a stored domain parses to itself.
|
|
102
241
|
*/
|
|
103
|
-
export const
|
|
104
|
-
const
|
|
105
|
-
if (
|
|
242
|
+
export const SiteDomainSchema = z.string().transform((value, ctx) => {
|
|
243
|
+
const domain = parseSiteDomain(value);
|
|
244
|
+
if (domain === null) {
|
|
106
245
|
ctx.addIssue({
|
|
107
246
|
code: "custom",
|
|
108
|
-
message: 'A domain is a
|
|
247
|
+
message: 'A domain is a host name or an IPv4 address, with an optional port and an optional http:// or https:// in front, such as "example.com", "localhost:3000", "127.0.0.1:3100" or "https://www.example.com:2136". A path, a query, a wildcard and an IPv6 address are refused.',
|
|
109
248
|
});
|
|
110
249
|
return z.NEVER;
|
|
111
250
|
}
|
|
112
|
-
return
|
|
251
|
+
return formatSiteDomain(domain);
|
|
113
252
|
});
|
|
114
253
|
export const MAX_HOSTNAMES_PER_SITE = 20;
|
|
115
254
|
/**
|
|
@@ -118,7 +257,7 @@ export const MAX_HOSTNAMES_PER_SITE = 20;
|
|
|
118
257
|
*/
|
|
119
258
|
export const SiteHostnamesSchema = z.object({
|
|
120
259
|
siteId: z.string().min(1),
|
|
121
|
-
hostnames: z.array(
|
|
260
|
+
hostnames: z.array(SiteDomainSchema).max(MAX_HOSTNAMES_PER_SITE),
|
|
122
261
|
});
|
|
123
262
|
/**
|
|
124
263
|
* The install's sites setting (the `sites` settings row): which top-level
|
|
@@ -142,7 +281,7 @@ export const SetDefaultSiteRequestSchema = z.object({ defaultSiteId: z.string().
|
|
|
142
281
|
* list, in order. An empty list takes every domain off the site.
|
|
143
282
|
*/
|
|
144
283
|
export const SetSiteHostnamesRequestSchema = z.object({
|
|
145
|
-
hostnames: z.array(
|
|
284
|
+
hostnames: z.array(SiteDomainSchema).max(MAX_HOSTNAMES_PER_SITE),
|
|
146
285
|
});
|
|
147
286
|
/**
|
|
148
287
|
* The default site as a visitor meets it: the top-level node whose own
|