@valbuild/core 0.136.1 → 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.
@@ -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;
@@ -12611,9 +12627,41 @@ function collectObjectRecursive(item, collector) {
12611
12627
  * exactly. That is the property the promotion relies on: only the modules whose
12612
12628
  * source actually moved change anything.
12613
12629
  */
12630
+ /**
12631
+ * The `sourcesSha` fold on its own: path and source, in `val.modules` order.
12632
+ *
12633
+ * Separate from {@link computeValModuleShas} because the Studio needs it and
12634
+ * has nothing else that fold takes. It is how a client tells whether the base
12635
+ * it is showing is the base a server's `/stat` answer is relative to: the chain
12636
+ * a server announces is the patches ITS build does not contain, so applying it
12637
+ * to another build's source loses edits or applies them twice. Both sides call
12638
+ * this one implementation, so the comparison is only ever between two runs of
12639
+ * the same code.
12640
+ */
12641
+ function computeSourcesSha(entries) {
12642
+ var sourcesSha = "";
12643
+ var _iterator = result._createForOfIteratorHelper(entries),
12644
+ _step;
12645
+ try {
12646
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
12647
+ var _step$value = _step.value,
12648
+ path = _step$value.path,
12649
+ source = _step$value.source;
12650
+ sourcesSha = hash(sourcesSha + JSON.stringify({
12651
+ path: path,
12652
+ source: source
12653
+ }));
12654
+ }
12655
+ } catch (err) {
12656
+ _iterator.e(err);
12657
+ } finally {
12658
+ _iterator.f();
12659
+ }
12660
+ return sourcesSha;
12661
+ }
12614
12662
  function computeValModuleShas(config, entries, moduleErrors) {
12615
12663
  var configSha = hash(JSON.stringify(config));
12616
- var sourcesSha = "";
12664
+ var sourcesSha = computeSourcesSha(entries);
12617
12665
  var baseSha = configSha;
12618
12666
  // NOTE: schemaSha is deliberately NOT seeded with configSha. It is compared
12619
12667
  // across bundles (the server extracts from the Node bundle, the editor SPA
@@ -12624,18 +12672,14 @@ function computeValModuleShas(config, entries, moduleErrors) {
12624
12672
  // server-only env vars and therefore `undefined` in the browser. Seeding with
12625
12673
  // them made the two sides disagree on every production load.
12626
12674
  var schemaSha = "";
12627
- var _iterator = result._createForOfIteratorHelper(entries),
12628
- _step;
12675
+ var _iterator2 = result._createForOfIteratorHelper(entries),
12676
+ _step2;
12629
12677
  try {
12630
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
12631
- var entry = _step.value;
12678
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
12679
+ var entry = _step2.value;
12632
12680
  var path = entry.path,
12633
12681
  source = entry.source,
12634
12682
  serializedSchema = entry.serializedSchema;
12635
- sourcesSha = hash(sourcesSha + JSON.stringify({
12636
- path: path,
12637
- source: source
12638
- }));
12639
12683
  baseSha = hash(baseSha + JSON.stringify({
12640
12684
  path: path,
12641
12685
  schema: serializedSchema,
@@ -12653,9 +12697,9 @@ function computeValModuleShas(config, entries, moduleErrors) {
12653
12697
  }));
12654
12698
  }
12655
12699
  } catch (err) {
12656
- _iterator.e(err);
12700
+ _iterator2.e(err);
12657
12701
  } finally {
12658
- _iterator.f();
12702
+ _iterator2.f();
12659
12703
  }
12660
12704
  return {
12661
12705
  baseSha: baseSha,
@@ -12677,7 +12721,7 @@ function extractValModules(_x) {
12677
12721
  }
12678
12722
  function _extractValModules() {
12679
12723
  _extractValModules = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(valModules) {
12680
- var moduleErrors, addModuleError, sources, schemas, serializedSchemas, shaEntries, moduleIdx, module, at, value, path, schema, source, serializedSchema, pathM, _iterator2, _step2, error, _iterator3, _step3, _error, _t, _t2;
12724
+ var moduleErrors, addModuleError, sources, schemas, serializedSchemas, shaEntries, moduleIdx, module, at, value, path, schema, source, serializedSchema, pathM, _iterator3, _step3, error, _iterator4, _step4, _error, _t, _t2;
12681
12725
  return _regenerator().w(function (_context) {
12682
12726
  while (1) switch (_context.p = _context.n) {
12683
12727
  case 0:
@@ -12824,10 +12868,10 @@ function _extractValModules() {
12824
12868
  // Appended AFTER the loop on purpose: each entry's `moduleErrorsAt` is the
12825
12869
  // error count at the time it was folded in, so the SHAs stay a function of
12826
12870
  // the modules themselves.
12827
- _iterator2 = result._createForOfIteratorHelper(resolveSettingsModule(serializedSchemas).errors);
12871
+ _iterator3 = result._createForOfIteratorHelper(resolveSettingsModule(serializedSchemas).errors);
12828
12872
  try {
12829
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
12830
- error = _step2.value;
12873
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
12874
+ error = _step3.value;
12831
12875
  moduleErrors.push(error);
12832
12876
  }
12833
12877
  // Same kind of rule, same reason it is here: a view cycle is a property of the
@@ -12835,20 +12879,20 @@ function _extractValModules() {
12835
12879
  // catches it either — a view stores a pointer, not content, so there is no
12836
12880
  // data cycle for a source walk to trip over.
12837
12881
  } catch (err) {
12838
- _iterator2.e(err);
12882
+ _iterator3.e(err);
12839
12883
  } finally {
12840
- _iterator2.f();
12884
+ _iterator3.f();
12841
12885
  }
12842
- _iterator3 = result._createForOfIteratorHelper(viewCycleErrors(serializedSchemas));
12886
+ _iterator4 = result._createForOfIteratorHelper(viewCycleErrors(serializedSchemas));
12843
12887
  try {
12844
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
12845
- _error = _step3.value;
12888
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
12889
+ _error = _step4.value;
12846
12890
  moduleErrors.push(_error);
12847
12891
  }
12848
12892
  } catch (err) {
12849
- _iterator3.e(err);
12893
+ _iterator4.e(err);
12850
12894
  } finally {
12851
- _iterator3.f();
12895
+ _iterator4.f();
12852
12896
  }
12853
12897
  return _context.a(2, _objectSpread2(_objectSpread2({
12854
12898
  sources: sources,
@@ -13739,35 +13783,165 @@ function isInlineRender(schema) {
13739
13783
  return false;
13740
13784
  }
13741
13785
 
13742
- var externalPageRouter = {
13743
- getRouterId: function getRouterId() {
13744
- return "external-url-router";
13745
- },
13746
- validate: function validate(_moduleFilePath, urlPaths) {
13747
- var errors = [];
13748
- var _iterator = result._createForOfIteratorHelper(urlPaths),
13749
- _step;
13750
- try {
13751
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
13752
- var urlPath = _step.value;
13753
- if (!(urlPath.startsWith("https://") || urlPath.startsWith("http://"))) {
13754
- errors.push({
13755
- error: {
13756
- message: "URL path \"".concat(urlPath, "\" does not start with \"https://\" or \"http://\""),
13757
- expectedPath: null,
13758
- urlPath: urlPath
13759
- }
13760
- });
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
+ }
13761
13935
  }
13936
+ } catch (err) {
13937
+ _iterator.e(err);
13938
+ } finally {
13939
+ _iterator.f();
13762
13940
  }
13763
- } catch (err) {
13764
- _iterator.e(err);
13765
- } finally {
13766
- _iterator.f();
13941
+ return errors;
13767
13942
  }
13768
- return [];
13769
- }
13770
- };
13943
+ };
13944
+ }
13771
13945
  // Helper function to validate a URL path against a route pattern
13772
13946
  function validateUrlAgainstPattern(urlPath, routePattern) {
13773
13947
  // Remove leading slash and split URL path
@@ -14167,7 +14341,7 @@ function isPageRouter(routerId) {
14167
14341
 
14168
14342
  var corePackageJson = {
14169
14343
  name: "@valbuild/core",
14170
- version: "0.136.1",
14344
+ version: "0.137.0",
14171
14345
  "private": false,
14172
14346
  description: "Val - supercharged hard-coded content",
14173
14347
  repository: {
@@ -14281,6 +14455,11 @@ var Internal = {
14281
14455
  nextAppRouter: nextAppRouter,
14282
14456
  tanstackRouter: tanstackRouter,
14283
14457
  externalPageRouter: externalPageRouter,
14458
+ describeSchemeRejection: describeSchemeRejection,
14459
+ isCheckableScheme: isCheckableScheme,
14460
+ rejectScheme: rejectScheme,
14461
+ schemeOf: schemeOf,
14462
+ UNSAFE_URL_SCHEMES: UNSAFE_URL_SCHEMES,
14284
14463
  color: {
14285
14464
  parseColor: parseColor,
14286
14465
  formatColor: formatColor,
@@ -14411,6 +14590,7 @@ exports.StringSchema = StringSchema;
14411
14590
  exports.THEME_LOGO_DIRECTORY = THEME_LOGO_DIRECTORY;
14412
14591
  exports.THEME_RADIUS_LENGTHS = THEME_RADIUS_LENGTHS;
14413
14592
  exports.THEME_RADIUS_STEPS = THEME_RADIUS_STEPS;
14593
+ exports.UNSAFE_URL_SCHEMES = UNSAFE_URL_SCHEMES;
14414
14594
  exports.VAL_EXTENSION = VAL_EXTENSION;
14415
14595
  exports.ValViewSchema = ValViewSchema;
14416
14596
  exports._classCallCheck = _classCallCheck;
@@ -14419,9 +14599,11 @@ exports._slicedToArray = _slicedToArray;
14419
14599
  exports._toConsumableArray = _toConsumableArray;
14420
14600
  exports._typeof = _typeof;
14421
14601
  exports.assistantAvailability = assistantAvailability;
14602
+ exports.computeSourcesSha = computeSourcesSha;
14422
14603
  exports.computeValModuleShas = computeValModuleShas;
14423
14604
  exports.declaredKeySetOf = declaredKeySetOf;
14424
14605
  exports.derefPatch = derefPatch;
14606
+ exports.describeSchemeRejection = describeSchemeRejection;
14425
14607
  exports.deserializeSchema = deserializeSchema;
14426
14608
  exports.discriminatedUnionBranchOf = discriminatedUnionBranchOf;
14427
14609
  exports.extractValModules = extractValModules;
@@ -14429,6 +14611,7 @@ exports.getSourcePathFromRoute = getSourcePathFromRoute;
14429
14611
  exports.hasMediaSchema = hasMediaSchema;
14430
14612
  exports.hasRemoteFileSchema = hasRemoteFileSchema;
14431
14613
  exports.initVal = initVal;
14614
+ exports.isCheckableScheme = isCheckableScheme;
14432
14615
  exports.isInlineRender = isInlineRender;
14433
14616
  exports.isPageRouter = isPageRouter;
14434
14617
  exports.isRootModuleFilePath = isRootModuleFilePath;
@@ -14440,7 +14623,9 @@ exports.modules = modules;
14440
14623
  exports.parseNextJsRoutePattern = parseNextJsRoutePattern;
14441
14624
  exports.parseTanStackRoutePattern = parseTanStackRoutePattern;
14442
14625
  exports.previewScope = previewScope;
14626
+ exports.rejectScheme = rejectScheme;
14443
14627
  exports.resolveSettingsModule = resolveSettingsModule;
14628
+ exports.schemeOf = schemeOf;
14444
14629
  exports.splitModuleFilePathAndModulePath = splitModuleFilePathAndModulePath;
14445
14630
  exports.tanStackSegmentsOfRoutePath = tanStackSegmentsOfRoutePath;
14446
14631
  exports.validateUrlAgainstPattern = validateUrlAgainstPattern;