@valbuild/core 0.136.8 → 0.137.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 CHANGED
@@ -1,5 +1,41 @@
1
1
  # @valbuild/core
2
2
 
3
+ ## 0.137.0
4
+
5
+ ### Patch Changes
6
+
7
+ - [#676](https://github.com/valbuild/val/pull/676) [`43b58f2`](https://github.com/valbuild/val/commit/43b58f2962840883badf91950da2c51b89d1c7cb) Thanks [@freekh](https://github.com/freekh)! - External page keys are now validated, and `mailto:` and `tel:` are allowed.
8
+
9
+ `externalPageRouter` documented a rule — a key must start with `https://` or
10
+ `http://` — and never enforced it: the validator collected the errors and then
11
+ returned an empty list, so a key like `discord.gg/val` or `/about` was accepted
12
+ in silence and behaved as a relative link on the site.
13
+
14
+ Fixing that made the rule itself worth looking at, because it was a rule about
15
+ the protocol standing in for a rule about links. A contact page's email address
16
+ and phone number are external pages to whoever maintains the list, and they
17
+ were refused. So the rule that is now enforced is a deny list rather than an
18
+ allow list: a key must have a scheme, and the scheme must not be one of
19
+ `javascript:`, `data:`, `vbscript:`, `file:` or `blob:` — which are not links
20
+ at all. An external page key ends up in an `href` in your site's own markup, so
21
+ those stay refused however the router is configured.
22
+
23
+ A project that wants to be stricter says so:
24
+
25
+ ```ts
26
+ s.record(item).router(externalPageRouter({ schemes: ["https", "mailto"] }));
27
+ ```
28
+
29
+ `initVal()` from `@valbuild/next` and `@valbuild/tanstack` hands you the
30
+ callable form, so the narrowed version typechecks in an app.
31
+
32
+ Val Studio applies the same rule while you type — it calls the same function —
33
+ and shows a narrowed project's own list in the message.
34
+
35
+ If your project has a key with no scheme at all, it will start showing a
36
+ validation error on that entry. Give it one, or move it out of the external
37
+ router.
38
+
3
39
  ## 0.136.8
4
40
 
5
41
  ### Patch Changes
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Which URL schemes an external page key may use.
3
+ *
4
+ * External pages are the URLs a site links OUT to, and a link is not only a web
5
+ * page: `mailto:` on a contact page and `tel:` on a phone number are the same
6
+ * kind of thing to whoever maintains the list, and were refused outright.
7
+ *
8
+ * So the default is a deny list rather than an allow list — anything with a
9
+ * scheme, except the handful that are not links at all. Listing every scheme
10
+ * worth linking to is a list that is wrong the moment someone wants
11
+ * `whatsapp:` or `msteams:`, and being wrong that way means an editor cannot
12
+ * store a URL their site genuinely uses.
13
+ *
14
+ * A project that wants to be stricter says so:
15
+ *
16
+ * ```ts
17
+ * s.router(externalPageRouter({ schemes: ["https", "mailto"] }), item)
18
+ * ```
19
+ */
20
+ /**
21
+ * The schemes that are refused however wide the policy is.
22
+ *
23
+ * Not a style preference. An external page key ends up in an `href` in the
24
+ * consuming site's own markup, so `javascript:` there is stored XSS on that
25
+ * site, and `data:` is the same trick wearing a document. `vbscript:` is the
26
+ * historical spelling of the first. `file:` and `blob:` address the visitor's
27
+ * own machine rather than anywhere on the internet.
28
+ *
29
+ * These stay refused even when a project lists them in `schemes`: a config
30
+ * option is not a good enough reason to let content inject script into the
31
+ * page that renders it.
32
+ */
33
+ export declare const UNSAFE_URL_SCHEMES: readonly ["javascript", "data", "vbscript", "file", "blob"];
34
+ export type ExternalUrlSchemePolicy = {
35
+ /**
36
+ * The only schemes allowed, without the colon: `["https", "mailto"]`.
37
+ *
38
+ * Absent means the wide default — anything but {@link UNSAFE_URL_SCHEMES}.
39
+ */
40
+ schemes?: readonly string[];
41
+ };
42
+ /** The scheme of a URL, lowercased and without the colon, or null. */
43
+ export declare function schemeOf(url: string): string | null;
44
+ export type SchemeRejection = {
45
+ reason: "no-scheme";
46
+ } | {
47
+ reason: "unsafe";
48
+ scheme: string;
49
+ } | {
50
+ reason: "not-allowed";
51
+ scheme: string;
52
+ allowed: readonly string[];
53
+ };
54
+ /** `null` when the URL's scheme is acceptable under `policy`. */
55
+ export declare function rejectScheme(url: string, policy?: ExternalUrlSchemePolicy): SchemeRejection | null;
56
+ /** What to tell whoever wrote the key. */
57
+ export declare function describeSchemeRejection(rejection: SchemeRejection): string;
58
+ /**
59
+ * Whether a link check can open this URL.
60
+ *
61
+ * Separate from whether it is ALLOWED, and the two are not the same question:
62
+ * `mailto:` is a perfectly good external page and there is no request to make
63
+ * of it. A URL that cannot be opened is reported as not checked, never as
64
+ * broken.
65
+ */
66
+ export declare function isCheckableScheme(url: string): boolean;
@@ -79,9 +79,19 @@ export { type SerializedLiteralSchema, LiteralSchema } from "./schema/literal.js
79
79
  export { deserializeSchema } from "./schema/deserialize.js";
80
80
  export { type PreviewItem, type ItemPreviewInput, type RecordPreview, type ArrayPreview, type ReifiedPreview, type PreviewScope, previewScope, } from "./preview.js";
81
81
  export { type InlineRender, type FieldRender, isInlineRender } from "./render.js";
82
- export type { ValRouter, RouteValidationError } from "./router.js";
82
+ export type { ValRouter, ExternalPageRouter, RouteValidationError, } from "./router.js";
83
83
  export { parseNextJsRoutePattern, parseTanStackRoutePattern, tanStackSegmentsOfRoutePath, validateUrlAgainstPattern, } from "./router.js";
84
84
  export { getSourcePathFromRoute, isPageRouter } from "./getSourcePathFromRoute.js";
85
+ /**
86
+ * Which URL schemes an external page key may carry.
87
+ *
88
+ * Exported from the package root rather than only through `Internal` because
89
+ * the Studio has to apply the same rule the router does, while the key is
90
+ * being typed - one implementation, two callers, no second copy to drift.
91
+ */
92
+ export { describeSchemeRejection, isCheckableScheme, rejectScheme, schemeOf, UNSAFE_URL_SCHEMES, } from "./externalUrlSchemes.js";
93
+ export type { ExternalUrlSchemePolicy, SchemeRejection, } from "./externalUrlSchemes.js";
94
+ import { describeSchemeRejection, isCheckableScheme, rejectScheme, schemeOf } from "./externalUrlSchemes.js";
85
95
  export declare const FATAL_ERROR_TYPES: readonly ["no-schema", "no-source", "invalid-id", "no-module", "invalid-patch"];
86
96
  export type FatalErrorType = (typeof FATAL_ERROR_TYPES)[number];
87
97
  export declare const DEFAULT_CONTENT_HOST = "https://content.val.build";
@@ -138,7 +148,12 @@ declare const Internal: {
138
148
  joinModuleFilePathAndModulePath: typeof joinModuleFilePathAndModulePath;
139
149
  nextAppRouter: import("./router.js").ValRouter;
140
150
  tanstackRouter: import("./router.js").ValRouter;
141
- externalPageRouter: import("./router.js").ValRouter;
151
+ externalPageRouter: import("./router.js").ExternalPageRouter;
152
+ describeSchemeRejection: typeof describeSchemeRejection;
153
+ isCheckableScheme: typeof isCheckableScheme;
154
+ rejectScheme: typeof rejectScheme;
155
+ schemeOf: typeof schemeOf;
156
+ UNSAFE_URL_SCHEMES: readonly ["javascript", "data", "vbscript", "file", "blob"];
142
157
  color: {
143
158
  parseColor: typeof parseColor;
144
159
  formatColor: typeof formatColor;
@@ -1,5 +1,31 @@
1
1
  import { ModuleFilePath } from "./val/index.js";
2
- export declare const externalPageRouter: ValRouter;
2
+ import { ExternalUrlSchemePolicy } from "./externalUrlSchemes.js";
3
+ /**
4
+ * The router whose keys are URLs to somewhere else.
5
+ *
6
+ * Used directly for the wide default, or called to narrow it:
7
+ *
8
+ * ```ts
9
+ * s.router(externalPageRouter, item) // anything safe
10
+ * s.router(externalPageRouter({ schemes: ["https"] }), item) // https only
11
+ * ```
12
+ *
13
+ * Its one rule is that a key has a scheme, and that the scheme is not one of
14
+ * the handful that are not links at all - see `externalUrlSchemes.ts`. That
15
+ * rule was WRITTEN here from the start and never enforced: the errors were
16
+ * collected into a list and then `return []` threw them away, so every key was
17
+ * accepted however it was spelled.
18
+ *
19
+ * `expectedPath` is null because there is nothing to suggest: a key that is
20
+ * not a URL could have been meant as any URL, and guessing `https://` in front
21
+ * of it would propose a different site as often as the right one.
22
+ */
23
+ export declare const externalPageRouter: ExternalPageRouter;
24
+ /**
25
+ * Callable AND a router, so `externalPageRouter` keeps working unchanged
26
+ * where nobody needs to configure it - which is almost everywhere.
27
+ */
28
+ export type ExternalPageRouter = ValRouter & ((policy: ExternalUrlSchemePolicy) => ValRouter);
3
29
  export type RouteValidationError = {
4
30
  error: {
5
31
  message: string;
@@ -70,5 +96,14 @@ export declare function tanStackSegmentsOfRoutePath(routePath: string): string[]
70
96
  export declare const tanstackRouter: ValRouter;
71
97
  export interface ValRouter {
72
98
  getRouterId(): string;
99
+ /**
100
+ * Which URL schemes this router's keys may use, where it restricts them.
101
+ *
102
+ * Serialized alongside the router id so the Studio can apply the SAME rule
103
+ * while someone types, rather than accepting a key and reporting it as a
104
+ * validation error afterwards. Absent on routers whose keys are paths rather
105
+ * than URLs, which is every other one.
106
+ */
107
+ getUrlSchemePolicy?(): ExternalUrlSchemePolicy;
73
108
  validate(moduleFilePath: ModuleFilePath, urlPaths: string[]): RouteValidationError[];
74
109
  }
@@ -31,6 +31,15 @@ export type SerializedRecordSchema = {
31
31
  /** Static layout config, carried whole in the serialized schema — see `render.ts`. */
32
32
  render?: FieldRender;
33
33
  router?: string;
34
+ /**
35
+ * The URL schemes this router's keys may use, where it restricts them.
36
+ *
37
+ * Carried so the Studio can apply the router's OWN rule while someone types
38
+ * rather than accepting a key and reporting it afterwards. Absent both when
39
+ * the router has no scheme rule (every path router) and when it allows the
40
+ * wide default, which the Studio knows on its own.
41
+ */
42
+ routerSchemes?: string[];
34
43
  customValidate?: boolean;
35
44
  mediaType?: "files" | "images";
36
45
  accept?: string;
@@ -5630,6 +5630,21 @@ function missingDeclaredKeys(declared, present) {
5630
5630
  });
5631
5631
  }
5632
5632
 
5633
+ /**
5634
+ * A router's scheme restriction, as a spreadable fragment.
5635
+ *
5636
+ * Spread rather than assigned so an unrestricted router adds no key at all:
5637
+ * `routerSchemes: undefined` would serialize as an explicit `undefined` and
5638
+ * show up in every schema diff for no reason.
5639
+ */
5640
+ function routerSchemes(router) {
5641
+ var _router$getUrlSchemeP;
5642
+ var schemes = router === null || router === void 0 || (_router$getUrlSchemeP = router.getUrlSchemePolicy) === null || _router$getUrlSchemeP === void 0 ? void 0 : _router$getUrlSchemeP.call(router).schemes;
5643
+ return schemes === undefined ? {} : {
5644
+ routerSchemes: _toConsumableArray(schemes)
5645
+ };
5646
+ }
5647
+
5633
5648
  /**
5634
5649
  * The source type of a `.jsonValues()` record: every entry value is EITHER a
5635
5650
  * lazily loaded {@link JsonSource} whose resolved content is the (loosened, see
@@ -6446,21 +6461,22 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
6446
6461
  key: "executeSerialize",
6447
6462
  value: function executeSerialize() {
6448
6463
  var _this$renderInput, _this$keySchema, _this$currentRouter, _this$customValidateF, _this$externalLabel;
6449
- var result = {
6464
+ var result = _objectSpread2(_objectSpread2({
6450
6465
  type: "record",
6451
6466
  render: (_this$renderInput = this.renderInput) !== null && _this$renderInput !== void 0 ? _this$renderInput : undefined,
6452
6467
  item: this.item["executeSerialize"](),
6453
6468
  key: (_this$keySchema = this.keySchema) === null || _this$keySchema === void 0 ? void 0 : _this$keySchema["executeSerialize"](),
6454
6469
  opt: this.opt,
6455
6470
  preview: this.previewInput ? true : undefined,
6456
- router: (_this$currentRouter = this.currentRouter) === null || _this$currentRouter === void 0 ? void 0 : _this$currentRouter.getRouterId(),
6471
+ router: (_this$currentRouter = this.currentRouter) === null || _this$currentRouter === void 0 ? void 0 : _this$currentRouter.getRouterId()
6472
+ }, routerSchemes(this.currentRouter)), {}, {
6457
6473
  customValidate: this.customValidateFunctions && ((_this$customValidateF = this.customValidateFunctions) === null || _this$customValidateF === void 0 ? void 0 : _this$customValidateF.length) > 0,
6458
6474
  jsonValues: this.isJsonValues ? true : undefined,
6459
6475
  external: (_this$externalLabel = this.externalLabel) !== null && _this$externalLabel !== void 0 ? _this$externalLabel : undefined,
6460
6476
  readonly: this.isReadonly,
6461
6477
  hidden: this.isHidden,
6462
6478
  description: this.description
6463
- };
6479
+ });
6464
6480
  if (this.mediaOptions) {
6465
6481
  result.mediaType = this.mediaOptions.type;
6466
6482
  result.accept = this.mediaOptions.accept;
@@ -13765,35 +13781,165 @@ function isInlineRender(schema) {
13765
13781
  return false;
13766
13782
  }
13767
13783
 
13768
- var externalPageRouter = {
13769
- getRouterId: function getRouterId() {
13770
- return "external-url-router";
13771
- },
13772
- validate: function validate(_moduleFilePath, urlPaths) {
13773
- var errors = [];
13774
- var _iterator = _createForOfIteratorHelper(urlPaths),
13775
- _step;
13776
- try {
13777
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
13778
- var urlPath = _step.value;
13779
- if (!(urlPath.startsWith("https://") || urlPath.startsWith("http://"))) {
13780
- errors.push({
13781
- error: {
13782
- message: "URL path \"".concat(urlPath, "\" does not start with \"https://\" or \"http://\""),
13783
- expectedPath: null,
13784
- urlPath: urlPath
13785
- }
13786
- });
13784
+ /**
13785
+ * Which URL schemes an external page key may use.
13786
+ *
13787
+ * External pages are the URLs a site links OUT to, and a link is not only a web
13788
+ * page: `mailto:` on a contact page and `tel:` on a phone number are the same
13789
+ * kind of thing to whoever maintains the list, and were refused outright.
13790
+ *
13791
+ * So the default is a deny list rather than an allow list — anything with a
13792
+ * scheme, except the handful that are not links at all. Listing every scheme
13793
+ * worth linking to is a list that is wrong the moment someone wants
13794
+ * `whatsapp:` or `msteams:`, and being wrong that way means an editor cannot
13795
+ * store a URL their site genuinely uses.
13796
+ *
13797
+ * A project that wants to be stricter says so:
13798
+ *
13799
+ * ```ts
13800
+ * s.router(externalPageRouter({ schemes: ["https", "mailto"] }), item)
13801
+ * ```
13802
+ */
13803
+
13804
+ /**
13805
+ * The schemes that are refused however wide the policy is.
13806
+ *
13807
+ * Not a style preference. An external page key ends up in an `href` in the
13808
+ * consuming site's own markup, so `javascript:` there is stored XSS on that
13809
+ * site, and `data:` is the same trick wearing a document. `vbscript:` is the
13810
+ * historical spelling of the first. `file:` and `blob:` address the visitor's
13811
+ * own machine rather than anywhere on the internet.
13812
+ *
13813
+ * These stay refused even when a project lists them in `schemes`: a config
13814
+ * option is not a good enough reason to let content inject script into the
13815
+ * page that renders it.
13816
+ */
13817
+ var UNSAFE_URL_SCHEMES = ["javascript", "data", "vbscript", "file", "blob"];
13818
+ /** The scheme of a URL, lowercased and without the colon, or null. */
13819
+ function schemeOf(url) {
13820
+ var match = /^([a-zA-Z][a-zA-Z0-9+.-]*):/.exec(url.trim());
13821
+ return match === null ? null : match[1].toLowerCase();
13822
+ }
13823
+ /** `null` when the URL's scheme is acceptable under `policy`. */
13824
+ function rejectScheme(url) {
13825
+ var policy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
13826
+ var scheme = schemeOf(url);
13827
+ if (scheme === null) {
13828
+ return {
13829
+ reason: "no-scheme"
13830
+ };
13831
+ }
13832
+ if (UNSAFE_URL_SCHEMES.includes(scheme)) {
13833
+ return {
13834
+ reason: "unsafe",
13835
+ scheme: scheme
13836
+ };
13837
+ }
13838
+ if (policy.schemes !== undefined) {
13839
+ var allowed = policy.schemes.map(function (s) {
13840
+ return s.toLowerCase();
13841
+ });
13842
+ if (!allowed.includes(scheme)) {
13843
+ return {
13844
+ reason: "not-allowed",
13845
+ scheme: scheme,
13846
+ allowed: policy.schemes
13847
+ };
13848
+ }
13849
+ }
13850
+ return null;
13851
+ }
13852
+
13853
+ /** What to tell whoever wrote the key. */
13854
+ function describeSchemeRejection(rejection) {
13855
+ switch (rejection.reason) {
13856
+ case "no-scheme":
13857
+ return "Must start with a scheme, like https:// or mailto:.";
13858
+ case "unsafe":
13859
+ return "\"".concat(rejection.scheme, ":\" cannot be used in a link: it runs code or reads the visitor's own machine rather than pointing at somewhere on the internet.");
13860
+ case "not-allowed":
13861
+ return "\"".concat(rejection.scheme, ":\" is not one of the schemes this router allows (").concat(rejection.allowed.join(", "), ").");
13862
+ }
13863
+ }
13864
+
13865
+ /**
13866
+ * Whether a link check can open this URL.
13867
+ *
13868
+ * Separate from whether it is ALLOWED, and the two are not the same question:
13869
+ * `mailto:` is a perfectly good external page and there is no request to make
13870
+ * of it. A URL that cannot be opened is reported as not checked, never as
13871
+ * broken.
13872
+ */
13873
+ function isCheckableScheme(url) {
13874
+ var scheme = schemeOf(url);
13875
+ return scheme === "http" || scheme === "https";
13876
+ }
13877
+
13878
+ /**
13879
+ * The router whose keys are URLs to somewhere else.
13880
+ *
13881
+ * Used directly for the wide default, or called to narrow it:
13882
+ *
13883
+ * ```ts
13884
+ * s.router(externalPageRouter, item) // anything safe
13885
+ * s.router(externalPageRouter({ schemes: ["https"] }), item) // https only
13886
+ * ```
13887
+ *
13888
+ * Its one rule is that a key has a scheme, and that the scheme is not one of
13889
+ * the handful that are not links at all - see `externalUrlSchemes.ts`. That
13890
+ * rule was WRITTEN here from the start and never enforced: the errors were
13891
+ * collected into a list and then `return []` threw them away, so every key was
13892
+ * accepted however it was spelled.
13893
+ *
13894
+ * `expectedPath` is null because there is nothing to suggest: a key that is
13895
+ * not a URL could have been meant as any URL, and guessing `https://` in front
13896
+ * of it would propose a different site as often as the right one.
13897
+ */
13898
+ var externalPageRouter = Object.assign(function (policy) {
13899
+ return createExternalPageRouter(policy);
13900
+ }, createExternalPageRouter());
13901
+
13902
+ /**
13903
+ * Callable AND a router, so `externalPageRouter` keeps working unchanged
13904
+ * where nobody needs to configure it - which is almost everywhere.
13905
+ */
13906
+
13907
+ function createExternalPageRouter() {
13908
+ var policy = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
13909
+ return {
13910
+ getRouterId: function getRouterId() {
13911
+ return "external-url-router";
13912
+ },
13913
+ getUrlSchemePolicy: function getUrlSchemePolicy() {
13914
+ return policy;
13915
+ },
13916
+ validate: function validate(_moduleFilePath, urlPaths) {
13917
+ var errors = [];
13918
+ var _iterator = _createForOfIteratorHelper(urlPaths),
13919
+ _step;
13920
+ try {
13921
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
13922
+ var urlPath = _step.value;
13923
+ var rejection = rejectScheme(urlPath, policy);
13924
+ if (rejection !== null) {
13925
+ errors.push({
13926
+ error: {
13927
+ message: "URL \"".concat(urlPath, "\" cannot be used here. ").concat(describeSchemeRejection(rejection)),
13928
+ expectedPath: null,
13929
+ urlPath: urlPath
13930
+ }
13931
+ });
13932
+ }
13787
13933
  }
13934
+ } catch (err) {
13935
+ _iterator.e(err);
13936
+ } finally {
13937
+ _iterator.f();
13788
13938
  }
13789
- } catch (err) {
13790
- _iterator.e(err);
13791
- } finally {
13792
- _iterator.f();
13939
+ return errors;
13793
13940
  }
13794
- return [];
13795
- }
13796
- };
13941
+ };
13942
+ }
13797
13943
  // Helper function to validate a URL path against a route pattern
13798
13944
  function validateUrlAgainstPattern(urlPath, routePattern) {
13799
13945
  // Remove leading slash and split URL path
@@ -14193,7 +14339,7 @@ function isPageRouter(routerId) {
14193
14339
 
14194
14340
  var corePackageJson = {
14195
14341
  name: "@valbuild/core",
14196
- version: "0.136.8",
14342
+ version: "0.137.0",
14197
14343
  "private": false,
14198
14344
  description: "Val - supercharged hard-coded content",
14199
14345
  repository: {
@@ -14307,6 +14453,11 @@ var Internal = {
14307
14453
  nextAppRouter: nextAppRouter,
14308
14454
  tanstackRouter: tanstackRouter,
14309
14455
  externalPageRouter: externalPageRouter,
14456
+ describeSchemeRejection: describeSchemeRejection,
14457
+ isCheckableScheme: isCheckableScheme,
14458
+ rejectScheme: rejectScheme,
14459
+ schemeOf: schemeOf,
14460
+ UNSAFE_URL_SCHEMES: UNSAFE_URL_SCHEMES,
14310
14461
  color: {
14311
14462
  parseColor: parseColor,
14312
14463
  formatColor: formatColor,
@@ -14399,4 +14550,4 @@ function tryJsonParse(str) {
14399
14550
  }
14400
14551
  }
14401
14552
 
14402
- export { DEFAULT_COLOR_FORMAT as $, ArraySchema as A, BooleanSchema as B, isRootModuleFilePath as C, DEFAULT_CONTENT_HOST as D, resolveSettingsModule as E, FATAL_ERROR_TYPES as F, GenericSelector as G, localeTagError as H, Internal as I, localeOfValue as J, declaredKeySetOf as K, LocaleSchema as L, ModuleFilePathSep as M, NumberSchema as N, ObjectSchema as O, PatchError as P, missingDeclaredKeys as Q, RecordSchema as R, Schema as S, THEME_LOGO_DIRECTORY as T, discriminatedUnionBranchOf as U, VAL_EXTENSION as V, ColorSchema as W, CodeSchema as X, CODE_LANGUAGES as Y, COLOR_FORMATS as Z, _typeof as _, _slicedToArray as a, DateTimeSchema as a0, KeyOfSchema as a1, ValViewSchema as a2, isValViewSource as a3, RouteSchema as a4, RichTextSchema as a5, DiscriminatedUnionSchema as a6, EnumSchema as a7, LiteralSchema as a8, deserializeSchema as a9, previewScope as aa, isInlineRender as ab, parseNextJsRoutePattern as ac, parseTanStackRoutePattern as ad, tanStackSegmentsOfRoutePath as ae, validateUrlAgainstPattern as af, getSourcePathFromRoute as ag, isPageRouter as ah, _createClass as b, _classCallCheck as c, _toConsumableArray as d, DEFAULT_APP_HOST as e, DEFAULT_STATIC_HOST as f, extractValModules as g, computeValModuleShas as h, initVal as i, computeSourcesSha as j, hasRemoteFileSchema as k, hasMediaSchema as l, modules as m, DEFAULT_VAL_REMOTE_HOST as n, derefPatch as o, StringSchema as p, ImageSchema as q, FileSchema as r, splitModuleFilePathAndModulePath as s, DateSchema as t, SettingsSchema as u, ASSISTANT_SETTINGS_MAX_LENGTH as v, THEME_RADIUS_STEPS as w, THEME_RADIUS_LENGTHS as x, assistantAvailability as y, SETTINGS_MODULE_CONVENTION as z };
14553
+ export { DEFAULT_COLOR_FORMAT as $, ArraySchema as A, BooleanSchema as B, isRootModuleFilePath as C, DEFAULT_CONTENT_HOST as D, resolveSettingsModule as E, FATAL_ERROR_TYPES as F, GenericSelector as G, localeTagError as H, Internal as I, localeOfValue as J, declaredKeySetOf as K, LocaleSchema as L, ModuleFilePathSep as M, NumberSchema as N, ObjectSchema as O, PatchError as P, missingDeclaredKeys as Q, RecordSchema as R, Schema as S, THEME_LOGO_DIRECTORY as T, discriminatedUnionBranchOf as U, VAL_EXTENSION as V, ColorSchema as W, CodeSchema as X, CODE_LANGUAGES as Y, COLOR_FORMATS as Z, _typeof as _, _slicedToArray as a, DateTimeSchema as a0, KeyOfSchema as a1, ValViewSchema as a2, isValViewSource as a3, RouteSchema as a4, RichTextSchema as a5, DiscriminatedUnionSchema as a6, EnumSchema as a7, LiteralSchema as a8, deserializeSchema as a9, previewScope as aa, isInlineRender as ab, parseNextJsRoutePattern as ac, parseTanStackRoutePattern as ad, tanStackSegmentsOfRoutePath as ae, validateUrlAgainstPattern as af, getSourcePathFromRoute as ag, isPageRouter as ah, describeSchemeRejection as ai, isCheckableScheme as aj, rejectScheme as ak, schemeOf as al, UNSAFE_URL_SCHEMES as am, _createClass as b, _classCallCheck as c, _toConsumableArray as d, DEFAULT_APP_HOST as e, DEFAULT_STATIC_HOST as f, extractValModules as g, computeValModuleShas as h, initVal as i, computeSourcesSha as j, hasRemoteFileSchema as k, hasMediaSchema as l, modules as m, DEFAULT_VAL_REMOTE_HOST as n, derefPatch as o, StringSchema as p, ImageSchema as q, FileSchema as r, splitModuleFilePathAndModulePath as s, DateSchema as t, SettingsSchema as u, ASSISTANT_SETTINGS_MAX_LENGTH as v, THEME_RADIUS_STEPS as w, THEME_RADIUS_LENGTHS as x, assistantAvailability as y, SETTINGS_MODULE_CONVENTION as z };
@@ -5632,6 +5632,21 @@ function missingDeclaredKeys(declared, present) {
5632
5632
  });
5633
5633
  }
5634
5634
 
5635
+ /**
5636
+ * A router's scheme restriction, as a spreadable fragment.
5637
+ *
5638
+ * Spread rather than assigned so an unrestricted router adds no key at all:
5639
+ * `routerSchemes: undefined` would serialize as an explicit `undefined` and
5640
+ * show up in every schema diff for no reason.
5641
+ */
5642
+ function routerSchemes(router) {
5643
+ var _router$getUrlSchemeP;
5644
+ var schemes = router === null || router === void 0 || (_router$getUrlSchemeP = router.getUrlSchemePolicy) === null || _router$getUrlSchemeP === void 0 ? void 0 : _router$getUrlSchemeP.call(router).schemes;
5645
+ return schemes === undefined ? {} : {
5646
+ routerSchemes: _toConsumableArray(schemes)
5647
+ };
5648
+ }
5649
+
5635
5650
  /**
5636
5651
  * The source type of a `.jsonValues()` record: every entry value is EITHER a
5637
5652
  * lazily loaded {@link JsonSource} whose resolved content is the (loosened, see
@@ -6448,21 +6463,22 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
6448
6463
  key: "executeSerialize",
6449
6464
  value: function executeSerialize() {
6450
6465
  var _this$renderInput, _this$keySchema, _this$currentRouter, _this$customValidateF, _this$externalLabel;
6451
- var result = {
6466
+ var result = _objectSpread2(_objectSpread2({
6452
6467
  type: "record",
6453
6468
  render: (_this$renderInput = this.renderInput) !== null && _this$renderInput !== void 0 ? _this$renderInput : undefined,
6454
6469
  item: this.item["executeSerialize"](),
6455
6470
  key: (_this$keySchema = this.keySchema) === null || _this$keySchema === void 0 ? void 0 : _this$keySchema["executeSerialize"](),
6456
6471
  opt: this.opt,
6457
6472
  preview: this.previewInput ? true : undefined,
6458
- router: (_this$currentRouter = this.currentRouter) === null || _this$currentRouter === void 0 ? void 0 : _this$currentRouter.getRouterId(),
6473
+ router: (_this$currentRouter = this.currentRouter) === null || _this$currentRouter === void 0 ? void 0 : _this$currentRouter.getRouterId()
6474
+ }, routerSchemes(this.currentRouter)), {}, {
6459
6475
  customValidate: this.customValidateFunctions && ((_this$customValidateF = this.customValidateFunctions) === null || _this$customValidateF === void 0 ? void 0 : _this$customValidateF.length) > 0,
6460
6476
  jsonValues: this.isJsonValues ? true : undefined,
6461
6477
  external: (_this$externalLabel = this.externalLabel) !== null && _this$externalLabel !== void 0 ? _this$externalLabel : undefined,
6462
6478
  readonly: this.isReadonly,
6463
6479
  hidden: this.isHidden,
6464
6480
  description: this.description
6465
- };
6481
+ });
6466
6482
  if (this.mediaOptions) {
6467
6483
  result.mediaType = this.mediaOptions.type;
6468
6484
  result.accept = this.mediaOptions.accept;
@@ -13767,35 +13783,165 @@ function isInlineRender(schema) {
13767
13783
  return false;
13768
13784
  }
13769
13785
 
13770
- var externalPageRouter = {
13771
- getRouterId: function getRouterId() {
13772
- return "external-url-router";
13773
- },
13774
- validate: function validate(_moduleFilePath, urlPaths) {
13775
- var errors = [];
13776
- var _iterator = result._createForOfIteratorHelper(urlPaths),
13777
- _step;
13778
- try {
13779
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
13780
- var urlPath = _step.value;
13781
- if (!(urlPath.startsWith("https://") || urlPath.startsWith("http://"))) {
13782
- errors.push({
13783
- error: {
13784
- message: "URL path \"".concat(urlPath, "\" does not start with \"https://\" or \"http://\""),
13785
- expectedPath: null,
13786
- urlPath: urlPath
13787
- }
13788
- });
13786
+ /**
13787
+ * Which URL schemes an external page key may use.
13788
+ *
13789
+ * External pages are the URLs a site links OUT to, and a link is not only a web
13790
+ * page: `mailto:` on a contact page and `tel:` on a phone number are the same
13791
+ * kind of thing to whoever maintains the list, and were refused outright.
13792
+ *
13793
+ * So the default is a deny list rather than an allow list — anything with a
13794
+ * scheme, except the handful that are not links at all. Listing every scheme
13795
+ * worth linking to is a list that is wrong the moment someone wants
13796
+ * `whatsapp:` or `msteams:`, and being wrong that way means an editor cannot
13797
+ * store a URL their site genuinely uses.
13798
+ *
13799
+ * A project that wants to be stricter says so:
13800
+ *
13801
+ * ```ts
13802
+ * s.router(externalPageRouter({ schemes: ["https", "mailto"] }), item)
13803
+ * ```
13804
+ */
13805
+
13806
+ /**
13807
+ * The schemes that are refused however wide the policy is.
13808
+ *
13809
+ * Not a style preference. An external page key ends up in an `href` in the
13810
+ * consuming site's own markup, so `javascript:` there is stored XSS on that
13811
+ * site, and `data:` is the same trick wearing a document. `vbscript:` is the
13812
+ * historical spelling of the first. `file:` and `blob:` address the visitor's
13813
+ * own machine rather than anywhere on the internet.
13814
+ *
13815
+ * These stay refused even when a project lists them in `schemes`: a config
13816
+ * option is not a good enough reason to let content inject script into the
13817
+ * page that renders it.
13818
+ */
13819
+ var UNSAFE_URL_SCHEMES = ["javascript", "data", "vbscript", "file", "blob"];
13820
+ /** The scheme of a URL, lowercased and without the colon, or null. */
13821
+ function schemeOf(url) {
13822
+ var match = /^([a-zA-Z][a-zA-Z0-9+.-]*):/.exec(url.trim());
13823
+ return match === null ? null : match[1].toLowerCase();
13824
+ }
13825
+ /** `null` when the URL's scheme is acceptable under `policy`. */
13826
+ function rejectScheme(url) {
13827
+ var policy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
13828
+ var scheme = schemeOf(url);
13829
+ if (scheme === null) {
13830
+ return {
13831
+ reason: "no-scheme"
13832
+ };
13833
+ }
13834
+ if (UNSAFE_URL_SCHEMES.includes(scheme)) {
13835
+ return {
13836
+ reason: "unsafe",
13837
+ scheme: scheme
13838
+ };
13839
+ }
13840
+ if (policy.schemes !== undefined) {
13841
+ var allowed = policy.schemes.map(function (s) {
13842
+ return s.toLowerCase();
13843
+ });
13844
+ if (!allowed.includes(scheme)) {
13845
+ return {
13846
+ reason: "not-allowed",
13847
+ scheme: scheme,
13848
+ allowed: policy.schemes
13849
+ };
13850
+ }
13851
+ }
13852
+ return null;
13853
+ }
13854
+
13855
+ /** What to tell whoever wrote the key. */
13856
+ function describeSchemeRejection(rejection) {
13857
+ switch (rejection.reason) {
13858
+ case "no-scheme":
13859
+ return "Must start with a scheme, like https:// or mailto:.";
13860
+ case "unsafe":
13861
+ return "\"".concat(rejection.scheme, ":\" cannot be used in a link: it runs code or reads the visitor's own machine rather than pointing at somewhere on the internet.");
13862
+ case "not-allowed":
13863
+ return "\"".concat(rejection.scheme, ":\" is not one of the schemes this router allows (").concat(rejection.allowed.join(", "), ").");
13864
+ }
13865
+ }
13866
+
13867
+ /**
13868
+ * Whether a link check can open this URL.
13869
+ *
13870
+ * Separate from whether it is ALLOWED, and the two are not the same question:
13871
+ * `mailto:` is a perfectly good external page and there is no request to make
13872
+ * of it. A URL that cannot be opened is reported as not checked, never as
13873
+ * broken.
13874
+ */
13875
+ function isCheckableScheme(url) {
13876
+ var scheme = schemeOf(url);
13877
+ return scheme === "http" || scheme === "https";
13878
+ }
13879
+
13880
+ /**
13881
+ * The router whose keys are URLs to somewhere else.
13882
+ *
13883
+ * Used directly for the wide default, or called to narrow it:
13884
+ *
13885
+ * ```ts
13886
+ * s.router(externalPageRouter, item) // anything safe
13887
+ * s.router(externalPageRouter({ schemes: ["https"] }), item) // https only
13888
+ * ```
13889
+ *
13890
+ * Its one rule is that a key has a scheme, and that the scheme is not one of
13891
+ * the handful that are not links at all - see `externalUrlSchemes.ts`. That
13892
+ * rule was WRITTEN here from the start and never enforced: the errors were
13893
+ * collected into a list and then `return []` threw them away, so every key was
13894
+ * accepted however it was spelled.
13895
+ *
13896
+ * `expectedPath` is null because there is nothing to suggest: a key that is
13897
+ * not a URL could have been meant as any URL, and guessing `https://` in front
13898
+ * of it would propose a different site as often as the right one.
13899
+ */
13900
+ var externalPageRouter = Object.assign(function (policy) {
13901
+ return createExternalPageRouter(policy);
13902
+ }, createExternalPageRouter());
13903
+
13904
+ /**
13905
+ * Callable AND a router, so `externalPageRouter` keeps working unchanged
13906
+ * where nobody needs to configure it - which is almost everywhere.
13907
+ */
13908
+
13909
+ function createExternalPageRouter() {
13910
+ var policy = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
13911
+ return {
13912
+ getRouterId: function getRouterId() {
13913
+ return "external-url-router";
13914
+ },
13915
+ getUrlSchemePolicy: function getUrlSchemePolicy() {
13916
+ return policy;
13917
+ },
13918
+ validate: function validate(_moduleFilePath, urlPaths) {
13919
+ var errors = [];
13920
+ var _iterator = result._createForOfIteratorHelper(urlPaths),
13921
+ _step;
13922
+ try {
13923
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
13924
+ var urlPath = _step.value;
13925
+ var rejection = rejectScheme(urlPath, policy);
13926
+ if (rejection !== null) {
13927
+ errors.push({
13928
+ error: {
13929
+ message: "URL \"".concat(urlPath, "\" cannot be used here. ").concat(describeSchemeRejection(rejection)),
13930
+ expectedPath: null,
13931
+ urlPath: urlPath
13932
+ }
13933
+ });
13934
+ }
13789
13935
  }
13936
+ } catch (err) {
13937
+ _iterator.e(err);
13938
+ } finally {
13939
+ _iterator.f();
13790
13940
  }
13791
- } catch (err) {
13792
- _iterator.e(err);
13793
- } finally {
13794
- _iterator.f();
13941
+ return errors;
13795
13942
  }
13796
- return [];
13797
- }
13798
- };
13943
+ };
13944
+ }
13799
13945
  // Helper function to validate a URL path against a route pattern
13800
13946
  function validateUrlAgainstPattern(urlPath, routePattern) {
13801
13947
  // Remove leading slash and split URL path
@@ -14195,7 +14341,7 @@ function isPageRouter(routerId) {
14195
14341
 
14196
14342
  var corePackageJson = {
14197
14343
  name: "@valbuild/core",
14198
- version: "0.136.8",
14344
+ version: "0.137.0",
14199
14345
  "private": false,
14200
14346
  description: "Val - supercharged hard-coded content",
14201
14347
  repository: {
@@ -14309,6 +14455,11 @@ var Internal = {
14309
14455
  nextAppRouter: nextAppRouter,
14310
14456
  tanstackRouter: tanstackRouter,
14311
14457
  externalPageRouter: externalPageRouter,
14458
+ describeSchemeRejection: describeSchemeRejection,
14459
+ isCheckableScheme: isCheckableScheme,
14460
+ rejectScheme: rejectScheme,
14461
+ schemeOf: schemeOf,
14462
+ UNSAFE_URL_SCHEMES: UNSAFE_URL_SCHEMES,
14312
14463
  color: {
14313
14464
  parseColor: parseColor,
14314
14465
  formatColor: formatColor,
@@ -14439,6 +14590,7 @@ exports.StringSchema = StringSchema;
14439
14590
  exports.THEME_LOGO_DIRECTORY = THEME_LOGO_DIRECTORY;
14440
14591
  exports.THEME_RADIUS_LENGTHS = THEME_RADIUS_LENGTHS;
14441
14592
  exports.THEME_RADIUS_STEPS = THEME_RADIUS_STEPS;
14593
+ exports.UNSAFE_URL_SCHEMES = UNSAFE_URL_SCHEMES;
14442
14594
  exports.VAL_EXTENSION = VAL_EXTENSION;
14443
14595
  exports.ValViewSchema = ValViewSchema;
14444
14596
  exports._classCallCheck = _classCallCheck;
@@ -14451,6 +14603,7 @@ exports.computeSourcesSha = computeSourcesSha;
14451
14603
  exports.computeValModuleShas = computeValModuleShas;
14452
14604
  exports.declaredKeySetOf = declaredKeySetOf;
14453
14605
  exports.derefPatch = derefPatch;
14606
+ exports.describeSchemeRejection = describeSchemeRejection;
14454
14607
  exports.deserializeSchema = deserializeSchema;
14455
14608
  exports.discriminatedUnionBranchOf = discriminatedUnionBranchOf;
14456
14609
  exports.extractValModules = extractValModules;
@@ -14458,6 +14611,7 @@ exports.getSourcePathFromRoute = getSourcePathFromRoute;
14458
14611
  exports.hasMediaSchema = hasMediaSchema;
14459
14612
  exports.hasRemoteFileSchema = hasRemoteFileSchema;
14460
14613
  exports.initVal = initVal;
14614
+ exports.isCheckableScheme = isCheckableScheme;
14461
14615
  exports.isInlineRender = isInlineRender;
14462
14616
  exports.isPageRouter = isPageRouter;
14463
14617
  exports.isRootModuleFilePath = isRootModuleFilePath;
@@ -14469,7 +14623,9 @@ exports.modules = modules;
14469
14623
  exports.parseNextJsRoutePattern = parseNextJsRoutePattern;
14470
14624
  exports.parseTanStackRoutePattern = parseTanStackRoutePattern;
14471
14625
  exports.previewScope = previewScope;
14626
+ exports.rejectScheme = rejectScheme;
14472
14627
  exports.resolveSettingsModule = resolveSettingsModule;
14628
+ exports.schemeOf = schemeOf;
14473
14629
  exports.splitModuleFilePathAndModulePath = splitModuleFilePathAndModulePath;
14474
14630
  exports.tanStackSegmentsOfRoutePath = tanStackSegmentsOfRoutePath;
14475
14631
  exports.validateUrlAgainstPattern = validateUrlAgainstPattern;
@@ -5632,6 +5632,21 @@ function missingDeclaredKeys(declared, present) {
5632
5632
  });
5633
5633
  }
5634
5634
 
5635
+ /**
5636
+ * A router's scheme restriction, as a spreadable fragment.
5637
+ *
5638
+ * Spread rather than assigned so an unrestricted router adds no key at all:
5639
+ * `routerSchemes: undefined` would serialize as an explicit `undefined` and
5640
+ * show up in every schema diff for no reason.
5641
+ */
5642
+ function routerSchemes(router) {
5643
+ var _router$getUrlSchemeP;
5644
+ var schemes = router === null || router === void 0 || (_router$getUrlSchemeP = router.getUrlSchemePolicy) === null || _router$getUrlSchemeP === void 0 ? void 0 : _router$getUrlSchemeP.call(router).schemes;
5645
+ return schemes === undefined ? {} : {
5646
+ routerSchemes: _toConsumableArray(schemes)
5647
+ };
5648
+ }
5649
+
5635
5650
  /**
5636
5651
  * The source type of a `.jsonValues()` record: every entry value is EITHER a
5637
5652
  * lazily loaded {@link JsonSource} whose resolved content is the (loosened, see
@@ -6448,21 +6463,22 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
6448
6463
  key: "executeSerialize",
6449
6464
  value: function executeSerialize() {
6450
6465
  var _this$renderInput, _this$keySchema, _this$currentRouter, _this$customValidateF, _this$externalLabel;
6451
- var result = {
6466
+ var result = _objectSpread2(_objectSpread2({
6452
6467
  type: "record",
6453
6468
  render: (_this$renderInput = this.renderInput) !== null && _this$renderInput !== void 0 ? _this$renderInput : undefined,
6454
6469
  item: this.item["executeSerialize"](),
6455
6470
  key: (_this$keySchema = this.keySchema) === null || _this$keySchema === void 0 ? void 0 : _this$keySchema["executeSerialize"](),
6456
6471
  opt: this.opt,
6457
6472
  preview: this.previewInput ? true : undefined,
6458
- router: (_this$currentRouter = this.currentRouter) === null || _this$currentRouter === void 0 ? void 0 : _this$currentRouter.getRouterId(),
6473
+ router: (_this$currentRouter = this.currentRouter) === null || _this$currentRouter === void 0 ? void 0 : _this$currentRouter.getRouterId()
6474
+ }, routerSchemes(this.currentRouter)), {}, {
6459
6475
  customValidate: this.customValidateFunctions && ((_this$customValidateF = this.customValidateFunctions) === null || _this$customValidateF === void 0 ? void 0 : _this$customValidateF.length) > 0,
6460
6476
  jsonValues: this.isJsonValues ? true : undefined,
6461
6477
  external: (_this$externalLabel = this.externalLabel) !== null && _this$externalLabel !== void 0 ? _this$externalLabel : undefined,
6462
6478
  readonly: this.isReadonly,
6463
6479
  hidden: this.isHidden,
6464
6480
  description: this.description
6465
- };
6481
+ });
6466
6482
  if (this.mediaOptions) {
6467
6483
  result.mediaType = this.mediaOptions.type;
6468
6484
  result.accept = this.mediaOptions.accept;
@@ -13767,35 +13783,165 @@ function isInlineRender(schema) {
13767
13783
  return false;
13768
13784
  }
13769
13785
 
13770
- var externalPageRouter = {
13771
- getRouterId: function getRouterId() {
13772
- return "external-url-router";
13773
- },
13774
- validate: function validate(_moduleFilePath, urlPaths) {
13775
- var errors = [];
13776
- var _iterator = result._createForOfIteratorHelper(urlPaths),
13777
- _step;
13778
- try {
13779
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
13780
- var urlPath = _step.value;
13781
- if (!(urlPath.startsWith("https://") || urlPath.startsWith("http://"))) {
13782
- errors.push({
13783
- error: {
13784
- message: "URL path \"".concat(urlPath, "\" does not start with \"https://\" or \"http://\""),
13785
- expectedPath: null,
13786
- urlPath: urlPath
13787
- }
13788
- });
13786
+ /**
13787
+ * Which URL schemes an external page key may use.
13788
+ *
13789
+ * External pages are the URLs a site links OUT to, and a link is not only a web
13790
+ * page: `mailto:` on a contact page and `tel:` on a phone number are the same
13791
+ * kind of thing to whoever maintains the list, and were refused outright.
13792
+ *
13793
+ * So the default is a deny list rather than an allow list — anything with a
13794
+ * scheme, except the handful that are not links at all. Listing every scheme
13795
+ * worth linking to is a list that is wrong the moment someone wants
13796
+ * `whatsapp:` or `msteams:`, and being wrong that way means an editor cannot
13797
+ * store a URL their site genuinely uses.
13798
+ *
13799
+ * A project that wants to be stricter says so:
13800
+ *
13801
+ * ```ts
13802
+ * s.router(externalPageRouter({ schemes: ["https", "mailto"] }), item)
13803
+ * ```
13804
+ */
13805
+
13806
+ /**
13807
+ * The schemes that are refused however wide the policy is.
13808
+ *
13809
+ * Not a style preference. An external page key ends up in an `href` in the
13810
+ * consuming site's own markup, so `javascript:` there is stored XSS on that
13811
+ * site, and `data:` is the same trick wearing a document. `vbscript:` is the
13812
+ * historical spelling of the first. `file:` and `blob:` address the visitor's
13813
+ * own machine rather than anywhere on the internet.
13814
+ *
13815
+ * These stay refused even when a project lists them in `schemes`: a config
13816
+ * option is not a good enough reason to let content inject script into the
13817
+ * page that renders it.
13818
+ */
13819
+ var UNSAFE_URL_SCHEMES = ["javascript", "data", "vbscript", "file", "blob"];
13820
+ /** The scheme of a URL, lowercased and without the colon, or null. */
13821
+ function schemeOf(url) {
13822
+ var match = /^([a-zA-Z][a-zA-Z0-9+.-]*):/.exec(url.trim());
13823
+ return match === null ? null : match[1].toLowerCase();
13824
+ }
13825
+ /** `null` when the URL's scheme is acceptable under `policy`. */
13826
+ function rejectScheme(url) {
13827
+ var policy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
13828
+ var scheme = schemeOf(url);
13829
+ if (scheme === null) {
13830
+ return {
13831
+ reason: "no-scheme"
13832
+ };
13833
+ }
13834
+ if (UNSAFE_URL_SCHEMES.includes(scheme)) {
13835
+ return {
13836
+ reason: "unsafe",
13837
+ scheme: scheme
13838
+ };
13839
+ }
13840
+ if (policy.schemes !== undefined) {
13841
+ var allowed = policy.schemes.map(function (s) {
13842
+ return s.toLowerCase();
13843
+ });
13844
+ if (!allowed.includes(scheme)) {
13845
+ return {
13846
+ reason: "not-allowed",
13847
+ scheme: scheme,
13848
+ allowed: policy.schemes
13849
+ };
13850
+ }
13851
+ }
13852
+ return null;
13853
+ }
13854
+
13855
+ /** What to tell whoever wrote the key. */
13856
+ function describeSchemeRejection(rejection) {
13857
+ switch (rejection.reason) {
13858
+ case "no-scheme":
13859
+ return "Must start with a scheme, like https:// or mailto:.";
13860
+ case "unsafe":
13861
+ return "\"".concat(rejection.scheme, ":\" cannot be used in a link: it runs code or reads the visitor's own machine rather than pointing at somewhere on the internet.");
13862
+ case "not-allowed":
13863
+ return "\"".concat(rejection.scheme, ":\" is not one of the schemes this router allows (").concat(rejection.allowed.join(", "), ").");
13864
+ }
13865
+ }
13866
+
13867
+ /**
13868
+ * Whether a link check can open this URL.
13869
+ *
13870
+ * Separate from whether it is ALLOWED, and the two are not the same question:
13871
+ * `mailto:` is a perfectly good external page and there is no request to make
13872
+ * of it. A URL that cannot be opened is reported as not checked, never as
13873
+ * broken.
13874
+ */
13875
+ function isCheckableScheme(url) {
13876
+ var scheme = schemeOf(url);
13877
+ return scheme === "http" || scheme === "https";
13878
+ }
13879
+
13880
+ /**
13881
+ * The router whose keys are URLs to somewhere else.
13882
+ *
13883
+ * Used directly for the wide default, or called to narrow it:
13884
+ *
13885
+ * ```ts
13886
+ * s.router(externalPageRouter, item) // anything safe
13887
+ * s.router(externalPageRouter({ schemes: ["https"] }), item) // https only
13888
+ * ```
13889
+ *
13890
+ * Its one rule is that a key has a scheme, and that the scheme is not one of
13891
+ * the handful that are not links at all - see `externalUrlSchemes.ts`. That
13892
+ * rule was WRITTEN here from the start and never enforced: the errors were
13893
+ * collected into a list and then `return []` threw them away, so every key was
13894
+ * accepted however it was spelled.
13895
+ *
13896
+ * `expectedPath` is null because there is nothing to suggest: a key that is
13897
+ * not a URL could have been meant as any URL, and guessing `https://` in front
13898
+ * of it would propose a different site as often as the right one.
13899
+ */
13900
+ var externalPageRouter = Object.assign(function (policy) {
13901
+ return createExternalPageRouter(policy);
13902
+ }, createExternalPageRouter());
13903
+
13904
+ /**
13905
+ * Callable AND a router, so `externalPageRouter` keeps working unchanged
13906
+ * where nobody needs to configure it - which is almost everywhere.
13907
+ */
13908
+
13909
+ function createExternalPageRouter() {
13910
+ var policy = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
13911
+ return {
13912
+ getRouterId: function getRouterId() {
13913
+ return "external-url-router";
13914
+ },
13915
+ getUrlSchemePolicy: function getUrlSchemePolicy() {
13916
+ return policy;
13917
+ },
13918
+ validate: function validate(_moduleFilePath, urlPaths) {
13919
+ var errors = [];
13920
+ var _iterator = result._createForOfIteratorHelper(urlPaths),
13921
+ _step;
13922
+ try {
13923
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
13924
+ var urlPath = _step.value;
13925
+ var rejection = rejectScheme(urlPath, policy);
13926
+ if (rejection !== null) {
13927
+ errors.push({
13928
+ error: {
13929
+ message: "URL \"".concat(urlPath, "\" cannot be used here. ").concat(describeSchemeRejection(rejection)),
13930
+ expectedPath: null,
13931
+ urlPath: urlPath
13932
+ }
13933
+ });
13934
+ }
13789
13935
  }
13936
+ } catch (err) {
13937
+ _iterator.e(err);
13938
+ } finally {
13939
+ _iterator.f();
13790
13940
  }
13791
- } catch (err) {
13792
- _iterator.e(err);
13793
- } finally {
13794
- _iterator.f();
13941
+ return errors;
13795
13942
  }
13796
- return [];
13797
- }
13798
- };
13943
+ };
13944
+ }
13799
13945
  // Helper function to validate a URL path against a route pattern
13800
13946
  function validateUrlAgainstPattern(urlPath, routePattern) {
13801
13947
  // Remove leading slash and split URL path
@@ -14195,7 +14341,7 @@ function isPageRouter(routerId) {
14195
14341
 
14196
14342
  var corePackageJson = {
14197
14343
  name: "@valbuild/core",
14198
- version: "0.136.8",
14344
+ version: "0.137.0",
14199
14345
  "private": false,
14200
14346
  description: "Val - supercharged hard-coded content",
14201
14347
  repository: {
@@ -14309,6 +14455,11 @@ var Internal = {
14309
14455
  nextAppRouter: nextAppRouter,
14310
14456
  tanstackRouter: tanstackRouter,
14311
14457
  externalPageRouter: externalPageRouter,
14458
+ describeSchemeRejection: describeSchemeRejection,
14459
+ isCheckableScheme: isCheckableScheme,
14460
+ rejectScheme: rejectScheme,
14461
+ schemeOf: schemeOf,
14462
+ UNSAFE_URL_SCHEMES: UNSAFE_URL_SCHEMES,
14312
14463
  color: {
14313
14464
  parseColor: parseColor,
14314
14465
  formatColor: formatColor,
@@ -14439,6 +14590,7 @@ exports.StringSchema = StringSchema;
14439
14590
  exports.THEME_LOGO_DIRECTORY = THEME_LOGO_DIRECTORY;
14440
14591
  exports.THEME_RADIUS_LENGTHS = THEME_RADIUS_LENGTHS;
14441
14592
  exports.THEME_RADIUS_STEPS = THEME_RADIUS_STEPS;
14593
+ exports.UNSAFE_URL_SCHEMES = UNSAFE_URL_SCHEMES;
14442
14594
  exports.VAL_EXTENSION = VAL_EXTENSION;
14443
14595
  exports.ValViewSchema = ValViewSchema;
14444
14596
  exports._classCallCheck = _classCallCheck;
@@ -14451,6 +14603,7 @@ exports.computeSourcesSha = computeSourcesSha;
14451
14603
  exports.computeValModuleShas = computeValModuleShas;
14452
14604
  exports.declaredKeySetOf = declaredKeySetOf;
14453
14605
  exports.derefPatch = derefPatch;
14606
+ exports.describeSchemeRejection = describeSchemeRejection;
14454
14607
  exports.deserializeSchema = deserializeSchema;
14455
14608
  exports.discriminatedUnionBranchOf = discriminatedUnionBranchOf;
14456
14609
  exports.extractValModules = extractValModules;
@@ -14458,6 +14611,7 @@ exports.getSourcePathFromRoute = getSourcePathFromRoute;
14458
14611
  exports.hasMediaSchema = hasMediaSchema;
14459
14612
  exports.hasRemoteFileSchema = hasRemoteFileSchema;
14460
14613
  exports.initVal = initVal;
14614
+ exports.isCheckableScheme = isCheckableScheme;
14461
14615
  exports.isInlineRender = isInlineRender;
14462
14616
  exports.isPageRouter = isPageRouter;
14463
14617
  exports.isRootModuleFilePath = isRootModuleFilePath;
@@ -14469,7 +14623,9 @@ exports.modules = modules;
14469
14623
  exports.parseNextJsRoutePattern = parseNextJsRoutePattern;
14470
14624
  exports.parseTanStackRoutePattern = parseTanStackRoutePattern;
14471
14625
  exports.previewScope = previewScope;
14626
+ exports.rejectScheme = rejectScheme;
14472
14627
  exports.resolveSettingsModule = resolveSettingsModule;
14628
+ exports.schemeOf = schemeOf;
14473
14629
  exports.splitModuleFilePathAndModulePath = splitModuleFilePathAndModulePath;
14474
14630
  exports.tanStackSegmentsOfRoutePath = tanStackSegmentsOfRoutePath;
14475
14631
  exports.validateUrlAgainstPattern = validateUrlAgainstPattern;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var dist_valbuildCore = require('./index-afbcf0ca.cjs.dev.js');
5
+ var dist_valbuildCore = require('./index-fed897a2.cjs.dev.js');
6
6
  require('./result-bb1f436e.cjs.dev.js');
7
7
 
8
8
 
@@ -44,6 +44,7 @@ exports.StringSchema = dist_valbuildCore.StringSchema;
44
44
  exports.THEME_LOGO_DIRECTORY = dist_valbuildCore.THEME_LOGO_DIRECTORY;
45
45
  exports.THEME_RADIUS_LENGTHS = dist_valbuildCore.THEME_RADIUS_LENGTHS;
46
46
  exports.THEME_RADIUS_STEPS = dist_valbuildCore.THEME_RADIUS_STEPS;
47
+ exports.UNSAFE_URL_SCHEMES = dist_valbuildCore.UNSAFE_URL_SCHEMES;
47
48
  exports.VAL_EXTENSION = dist_valbuildCore.VAL_EXTENSION;
48
49
  exports.ValViewSchema = dist_valbuildCore.ValViewSchema;
49
50
  exports.assistantAvailability = dist_valbuildCore.assistantAvailability;
@@ -51,6 +52,7 @@ exports.computeSourcesSha = dist_valbuildCore.computeSourcesSha;
51
52
  exports.computeValModuleShas = dist_valbuildCore.computeValModuleShas;
52
53
  exports.declaredKeySetOf = dist_valbuildCore.declaredKeySetOf;
53
54
  exports.derefPatch = dist_valbuildCore.derefPatch;
55
+ exports.describeSchemeRejection = dist_valbuildCore.describeSchemeRejection;
54
56
  exports.deserializeSchema = dist_valbuildCore.deserializeSchema;
55
57
  exports.discriminatedUnionBranchOf = dist_valbuildCore.discriminatedUnionBranchOf;
56
58
  exports.extractValModules = dist_valbuildCore.extractValModules;
@@ -58,6 +60,7 @@ exports.getSourcePathFromRoute = dist_valbuildCore.getSourcePathFromRoute;
58
60
  exports.hasMediaSchema = dist_valbuildCore.hasMediaSchema;
59
61
  exports.hasRemoteFileSchema = dist_valbuildCore.hasRemoteFileSchema;
60
62
  exports.initVal = dist_valbuildCore.initVal;
63
+ exports.isCheckableScheme = dist_valbuildCore.isCheckableScheme;
61
64
  exports.isInlineRender = dist_valbuildCore.isInlineRender;
62
65
  exports.isPageRouter = dist_valbuildCore.isPageRouter;
63
66
  exports.isRootModuleFilePath = dist_valbuildCore.isRootModuleFilePath;
@@ -69,6 +72,8 @@ exports.modules = dist_valbuildCore.modules;
69
72
  exports.parseNextJsRoutePattern = dist_valbuildCore.parseNextJsRoutePattern;
70
73
  exports.parseTanStackRoutePattern = dist_valbuildCore.parseTanStackRoutePattern;
71
74
  exports.previewScope = dist_valbuildCore.previewScope;
75
+ exports.rejectScheme = dist_valbuildCore.rejectScheme;
72
76
  exports.resolveSettingsModule = dist_valbuildCore.resolveSettingsModule;
77
+ exports.schemeOf = dist_valbuildCore.schemeOf;
73
78
  exports.tanStackSegmentsOfRoutePath = dist_valbuildCore.tanStackSegmentsOfRoutePath;
74
79
  exports.validateUrlAgainstPattern = dist_valbuildCore.validateUrlAgainstPattern;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var dist_valbuildCore = require('./index-2545d3b4.cjs.prod.js');
5
+ var dist_valbuildCore = require('./index-481a7dcd.cjs.prod.js');
6
6
  require('./result-787e35f6.cjs.prod.js');
7
7
 
8
8
 
@@ -44,6 +44,7 @@ exports.StringSchema = dist_valbuildCore.StringSchema;
44
44
  exports.THEME_LOGO_DIRECTORY = dist_valbuildCore.THEME_LOGO_DIRECTORY;
45
45
  exports.THEME_RADIUS_LENGTHS = dist_valbuildCore.THEME_RADIUS_LENGTHS;
46
46
  exports.THEME_RADIUS_STEPS = dist_valbuildCore.THEME_RADIUS_STEPS;
47
+ exports.UNSAFE_URL_SCHEMES = dist_valbuildCore.UNSAFE_URL_SCHEMES;
47
48
  exports.VAL_EXTENSION = dist_valbuildCore.VAL_EXTENSION;
48
49
  exports.ValViewSchema = dist_valbuildCore.ValViewSchema;
49
50
  exports.assistantAvailability = dist_valbuildCore.assistantAvailability;
@@ -51,6 +52,7 @@ exports.computeSourcesSha = dist_valbuildCore.computeSourcesSha;
51
52
  exports.computeValModuleShas = dist_valbuildCore.computeValModuleShas;
52
53
  exports.declaredKeySetOf = dist_valbuildCore.declaredKeySetOf;
53
54
  exports.derefPatch = dist_valbuildCore.derefPatch;
55
+ exports.describeSchemeRejection = dist_valbuildCore.describeSchemeRejection;
54
56
  exports.deserializeSchema = dist_valbuildCore.deserializeSchema;
55
57
  exports.discriminatedUnionBranchOf = dist_valbuildCore.discriminatedUnionBranchOf;
56
58
  exports.extractValModules = dist_valbuildCore.extractValModules;
@@ -58,6 +60,7 @@ exports.getSourcePathFromRoute = dist_valbuildCore.getSourcePathFromRoute;
58
60
  exports.hasMediaSchema = dist_valbuildCore.hasMediaSchema;
59
61
  exports.hasRemoteFileSchema = dist_valbuildCore.hasRemoteFileSchema;
60
62
  exports.initVal = dist_valbuildCore.initVal;
63
+ exports.isCheckableScheme = dist_valbuildCore.isCheckableScheme;
61
64
  exports.isInlineRender = dist_valbuildCore.isInlineRender;
62
65
  exports.isPageRouter = dist_valbuildCore.isPageRouter;
63
66
  exports.isRootModuleFilePath = dist_valbuildCore.isRootModuleFilePath;
@@ -69,6 +72,8 @@ exports.modules = dist_valbuildCore.modules;
69
72
  exports.parseNextJsRoutePattern = dist_valbuildCore.parseNextJsRoutePattern;
70
73
  exports.parseTanStackRoutePattern = dist_valbuildCore.parseTanStackRoutePattern;
71
74
  exports.previewScope = dist_valbuildCore.previewScope;
75
+ exports.rejectScheme = dist_valbuildCore.rejectScheme;
72
76
  exports.resolveSettingsModule = dist_valbuildCore.resolveSettingsModule;
77
+ exports.schemeOf = dist_valbuildCore.schemeOf;
73
78
  exports.tanStackSegmentsOfRoutePath = dist_valbuildCore.tanStackSegmentsOfRoutePath;
74
79
  exports.validateUrlAgainstPattern = dist_valbuildCore.validateUrlAgainstPattern;
@@ -1,2 +1,2 @@
1
- export { v as ASSISTANT_SETTINGS_MAX_LENGTH, A as ArraySchema, B as BooleanSchema, Y as CODE_LANGUAGES, Z as COLOR_FORMATS, X as CodeSchema, W as ColorSchema, e as DEFAULT_APP_HOST, $ as DEFAULT_COLOR_FORMAT, D as DEFAULT_CONTENT_HOST, f as DEFAULT_STATIC_HOST, n as DEFAULT_VAL_REMOTE_HOST, t as DateSchema, a0 as DateTimeSchema, a6 as DiscriminatedUnionSchema, a7 as EnumSchema, F as FATAL_ERROR_TYPES, r as FileSchema, G as GenericSelector, q as ImageSchema, I as Internal, a1 as KeyOfSchema, a8 as LiteralSchema, L as LocaleSchema, M as ModuleFilePathSep, N as NumberSchema, O as ObjectSchema, R as RecordSchema, a5 as RichTextSchema, a4 as RouteSchema, z as SETTINGS_MODULE_CONVENTION, S as Schema, u as SettingsSchema, p as StringSchema, T as THEME_LOGO_DIRECTORY, x as THEME_RADIUS_LENGTHS, w as THEME_RADIUS_STEPS, V as VAL_EXTENSION, a2 as ValViewSchema, y as assistantAvailability, j as computeSourcesSha, h as computeValModuleShas, K as declaredKeySetOf, o as derefPatch, a9 as deserializeSchema, U as discriminatedUnionBranchOf, g as extractValModules, ag as getSourcePathFromRoute, l as hasMediaSchema, k as hasRemoteFileSchema, i as initVal, ab as isInlineRender, ah as isPageRouter, C as isRootModuleFilePath, a3 as isValViewSource, J as localeOfValue, H as localeTagError, Q as missingDeclaredKeys, m as modules, ac as parseNextJsRoutePattern, ad as parseTanStackRoutePattern, aa as previewScope, E as resolveSettingsModule, ae as tanStackSegmentsOfRoutePath, af as validateUrlAgainstPattern } from './index-962a8ac3.esm.js';
1
+ export { v as ASSISTANT_SETTINGS_MAX_LENGTH, A as ArraySchema, B as BooleanSchema, Y as CODE_LANGUAGES, Z as COLOR_FORMATS, X as CodeSchema, W as ColorSchema, e as DEFAULT_APP_HOST, $ as DEFAULT_COLOR_FORMAT, D as DEFAULT_CONTENT_HOST, f as DEFAULT_STATIC_HOST, n as DEFAULT_VAL_REMOTE_HOST, t as DateSchema, a0 as DateTimeSchema, a6 as DiscriminatedUnionSchema, a7 as EnumSchema, F as FATAL_ERROR_TYPES, r as FileSchema, G as GenericSelector, q as ImageSchema, I as Internal, a1 as KeyOfSchema, a8 as LiteralSchema, L as LocaleSchema, M as ModuleFilePathSep, N as NumberSchema, O as ObjectSchema, R as RecordSchema, a5 as RichTextSchema, a4 as RouteSchema, z as SETTINGS_MODULE_CONVENTION, S as Schema, u as SettingsSchema, p as StringSchema, T as THEME_LOGO_DIRECTORY, x as THEME_RADIUS_LENGTHS, w as THEME_RADIUS_STEPS, am as UNSAFE_URL_SCHEMES, V as VAL_EXTENSION, a2 as ValViewSchema, y as assistantAvailability, j as computeSourcesSha, h as computeValModuleShas, K as declaredKeySetOf, o as derefPatch, ai as describeSchemeRejection, a9 as deserializeSchema, U as discriminatedUnionBranchOf, g as extractValModules, ag as getSourcePathFromRoute, l as hasMediaSchema, k as hasRemoteFileSchema, i as initVal, aj as isCheckableScheme, ab as isInlineRender, ah as isPageRouter, C as isRootModuleFilePath, a3 as isValViewSource, J as localeOfValue, H as localeTagError, Q as missingDeclaredKeys, m as modules, ac as parseNextJsRoutePattern, ad as parseTanStackRoutePattern, aa as previewScope, ak as rejectScheme, E as resolveSettingsModule, al as schemeOf, ae as tanStackSegmentsOfRoutePath, af as validateUrlAgainstPattern } from './index-42ab6700.esm.js';
2
2
  import './result-daff1cae.esm.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valbuild/core",
3
- "version": "0.136.8",
3
+ "version": "0.137.0",
4
4
  "private": false,
5
5
  "description": "Val - supercharged hard-coded content",
6
6
  "repository": {
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var dist_valbuildCore = require('../../dist/index-afbcf0ca.cjs.dev.js');
5
+ var dist_valbuildCore = require('../../dist/index-fed897a2.cjs.dev.js');
6
6
  var result = require('../../dist/result-bb1f436e.cjs.dev.js');
7
7
  var util = require('../../dist/util-b213092b.cjs.dev.js');
8
8
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var dist_valbuildCore = require('../../dist/index-2545d3b4.cjs.prod.js');
5
+ var dist_valbuildCore = require('../../dist/index-481a7dcd.cjs.prod.js');
6
6
  var result = require('../../dist/result-787e35f6.cjs.prod.js');
7
7
  var util = require('../../dist/util-030d8a1f.cjs.prod.js');
8
8
 
@@ -1,5 +1,5 @@
1
- import { _ as _typeof, a as _slicedToArray, P as PatchError, s as splitModuleFilePathAndModulePath, b as _createClass, c as _classCallCheck, d as _toConsumableArray } from '../../dist/index-962a8ac3.esm.js';
2
- export { P as PatchError } from '../../dist/index-962a8ac3.esm.js';
1
+ import { _ as _typeof, a as _slicedToArray, P as PatchError, s as splitModuleFilePathAndModulePath, b as _createClass, c as _classCallCheck, d as _toConsumableArray } from '../../dist/index-42ab6700.esm.js';
2
+ export { P as PatchError } from '../../dist/index-42ab6700.esm.js';
3
3
  import { f as isNonEmpty, e as err, o as ok, m as map, g as flatMap, i as isErr, h as flatMapReduce, j as filterOrElse, k as mapErr, l as map$1, n as all, p as flatten, q as allT } from '../../dist/result-daff1cae.esm.js';
4
4
  import { p as pipe } from '../../dist/util-18613e99.esm.js';
5
5