@prezly/theme-kit-core 10.15.1 → 10.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/build/content-delivery/ContentDelivery.cjs +100 -14
  2. package/build/content-delivery/ContentDelivery.d.ts +50 -1
  3. package/build/content-delivery/ContentDelivery.mjs +96 -13
  4. package/build/content-delivery/ContentDelivery.test.cjs +85 -1
  5. package/build/content-delivery/ContentDelivery.test.mjs +85 -1
  6. package/build/content-delivery/RequestCoalescer.cjs +1 -1
  7. package/build/content-delivery/RequestCoalescer.mjs +1 -1
  8. package/build/content-delivery/metrics.cjs +1 -1
  9. package/build/content-delivery/metrics.mjs +1 -1
  10. package/build/content-delivery/telemetry.cjs +1 -1
  11. package/build/content-delivery/telemetry.mjs +1 -1
  12. package/build/environment.cjs +1 -1
  13. package/build/environment.mjs +1 -1
  14. package/build/http/HttpClient.cjs +1 -1
  15. package/build/http/HttpClient.mjs +1 -1
  16. package/build/http/index.cjs +2 -1
  17. package/build/index.cjs +6 -2
  18. package/build/index.d.ts +1 -0
  19. package/build/index.mjs +2 -0
  20. package/build/metadata/getAlternateLanguageLinks.cjs +1 -1
  21. package/build/metadata/getAlternateLanguageLinks.mjs +1 -1
  22. package/build/routing/Route.cjs +27 -8
  23. package/build/routing/Route.mjs +27 -8
  24. package/build/routing/Route.test.cjs +46 -0
  25. package/build/routing/Route.test.mjs +46 -0
  26. package/build/routing/index.cjs +2 -1
  27. package/build/routing/types.d.ts +2 -0
  28. package/build/routing/utils/generateUrlFromPattern.cjs +19 -10
  29. package/build/routing/utils/generateUrlFromPattern.mjs +19 -10
  30. package/build/routing/utils/generateUrlFromPattern.test.cjs +15 -0
  31. package/build/routing/utils/generateUrlFromPattern.test.mjs +15 -0
  32. package/build/routing/utils/wildcard.cjs +76 -0
  33. package/build/routing/utils/wildcard.d.ts +25 -0
  34. package/build/routing/utils/wildcard.mjs +66 -0
  35. package/build/sitemap/build.cjs +1 -1
  36. package/build/sitemap/build.mjs +1 -1
  37. package/build/sitemap/generate.cjs +5 -1
  38. package/build/sitemap/generate.mjs +5 -1
  39. package/build/stories.cjs +27 -0
  40. package/build/stories.d.ts +16 -0
  41. package/build/stories.mjs +20 -0
  42. package/build/stories.test.cjs +47 -0
  43. package/build/stories.test.mjs +45 -0
  44. package/package.json +2 -2
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.encodeWildcard = encodeWildcard;
7
+ exports.fromMatch = fromMatch;
8
+ exports.parseWildcard = parseWildcard;
9
+ exports.stringify = stringify;
10
+ exports.toStringifyParams = toStringifyParams;
11
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
12
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
13
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
14
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
15
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
16
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
17
+ function _toPrimitive(t, e) { if ("object" != typeof t || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
18
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
19
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
20
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
21
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
22
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
23
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
24
+ /**
25
+ * A route pattern can end in one named wildcard: `/category/*path`. Unlike a `:param`, which is
26
+ * one segment of the URL, a wildcard takes every segment that is left: `cars/models/eqs`.
27
+ *
28
+ * `url-pattern` only knows unnamed wildcards (`*`), which it reports as `_`. These helpers
29
+ * translate between the two, so routes and their params only ever see the name.
30
+ */
31
+ var NAMED_WILDCARD = /\*([A-Za-z][A-Za-z0-9]*)/;
32
+ var UNNAMED = '_';
33
+ function parseWildcard(pattern) {
34
+ var _pattern$match;
35
+ var _ref = (_pattern$match = pattern.match(NAMED_WILDCARD)) !== null && _pattern$match !== void 0 ? _pattern$match : [],
36
+ _ref2 = _slicedToArray(_ref, 2),
37
+ name = _ref2[1];
38
+ return {
39
+ pattern: name ? pattern.replace(NAMED_WILDCARD, '*') : pattern,
40
+ name
41
+ };
42
+ }
43
+
44
+ /**
45
+ * Params as a route sees them, from what `url-pattern` matched.
46
+ */
47
+ function fromMatch(matched, name) {
48
+ if (!name || !(UNNAMED in matched)) return matched;
49
+ var value = matched[UNNAMED],
50
+ params = _objectWithoutProperties(matched, [UNNAMED].map(_toPropertyKey));
51
+ return _objectSpread(_objectSpread({}, params), {}, {
52
+ [name]: value
53
+ });
54
+ }
55
+
56
+ /**
57
+ * Params as `url-pattern` wants them to build a URL.
58
+ */
59
+ function toStringifyParams(params, name) {
60
+ if (!name || !(name in params)) return params;
61
+ var value = params[name],
62
+ rest = _objectWithoutProperties(params, [name].map(_toPropertyKey));
63
+ return _objectSpread(_objectSpread({}, rest), {}, {
64
+ [UNNAMED]: value
65
+ });
66
+ }
67
+
68
+ /**
69
+ * Encodes a wildcard value for a URL, keeping the slashes between its segments.
70
+ */
71
+ function encodeWildcard(value) {
72
+ return value.split('/').map(encodeURIComponent).join('/');
73
+ }
74
+ function stringify(urlPattern, params, name) {
75
+ return urlPattern.stringify(toStringifyParams(params, name));
76
+ }
@@ -0,0 +1,25 @@
1
+ import type UrlPattern from 'url-pattern';
2
+ export interface Wildcard {
3
+ /**
4
+ * The pattern as `url-pattern` understands it.
5
+ */
6
+ pattern: string;
7
+ /**
8
+ * Name of the wildcard param, if the pattern has one.
9
+ */
10
+ name: string | undefined;
11
+ }
12
+ export declare function parseWildcard(pattern: string): Wildcard;
13
+ /**
14
+ * Params as a route sees them, from what `url-pattern` matched.
15
+ */
16
+ export declare function fromMatch<T extends Record<string, unknown>>(matched: T, name: Wildcard['name']): T;
17
+ /**
18
+ * Params as `url-pattern` wants them to build a URL.
19
+ */
20
+ export declare function toStringifyParams<T extends Record<string, unknown>>(params: T, name: Wildcard['name']): T;
21
+ /**
22
+ * Encodes a wildcard value for a URL, keeping the slashes between its segments.
23
+ */
24
+ export declare function encodeWildcard(value: string): string;
25
+ export declare function stringify(urlPattern: UrlPattern, params: Record<string, unknown>, name: Wildcard['name']): string;
@@ -0,0 +1,66 @@
1
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
3
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
4
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
5
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
6
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
7
+ function _toPrimitive(t, e) { if ("object" != typeof t || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
8
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
9
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
10
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
11
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
12
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
13
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
14
+ /**
15
+ * A route pattern can end in one named wildcard: `/category/*path`. Unlike a `:param`, which is
16
+ * one segment of the URL, a wildcard takes every segment that is left: `cars/models/eqs`.
17
+ *
18
+ * `url-pattern` only knows unnamed wildcards (`*`), which it reports as `_`. These helpers
19
+ * translate between the two, so routes and their params only ever see the name.
20
+ */
21
+ var NAMED_WILDCARD = /\*([A-Za-z][A-Za-z0-9]*)/;
22
+ var UNNAMED = '_';
23
+ export function parseWildcard(pattern) {
24
+ var _pattern$match;
25
+ var _ref = (_pattern$match = pattern.match(NAMED_WILDCARD)) !== null && _pattern$match !== void 0 ? _pattern$match : [],
26
+ _ref2 = _slicedToArray(_ref, 2),
27
+ name = _ref2[1];
28
+ return {
29
+ pattern: name ? pattern.replace(NAMED_WILDCARD, '*') : pattern,
30
+ name
31
+ };
32
+ }
33
+
34
+ /**
35
+ * Params as a route sees them, from what `url-pattern` matched.
36
+ */
37
+ export function fromMatch(matched, name) {
38
+ if (!name || !(UNNAMED in matched)) return matched;
39
+ var value = matched[UNNAMED],
40
+ params = _objectWithoutProperties(matched, [UNNAMED].map(_toPropertyKey));
41
+ return _objectSpread(_objectSpread({}, params), {}, {
42
+ [name]: value
43
+ });
44
+ }
45
+
46
+ /**
47
+ * Params as `url-pattern` wants them to build a URL.
48
+ */
49
+ export function toStringifyParams(params, name) {
50
+ if (!name || !(name in params)) return params;
51
+ var value = params[name],
52
+ rest = _objectWithoutProperties(params, [name].map(_toPropertyKey));
53
+ return _objectSpread(_objectSpread({}, rest), {}, {
54
+ [UNNAMED]: value
55
+ });
56
+ }
57
+
58
+ /**
59
+ * Encodes a wildcard value for a URL, keeping the slashes between its segments.
60
+ */
61
+ export function encodeWildcard(value) {
62
+ return value.split('/').map(encodeURIComponent).join('/');
63
+ }
64
+ export function stringify(urlPattern, params, name) {
65
+ return urlPattern.stringify(toStringifyParams(params, name));
66
+ }
@@ -8,7 +8,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
8
8
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
9
9
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
10
10
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
11
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
11
+ function _toPrimitive(t, e) { if ("object" != typeof t || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
12
12
  function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
13
13
  function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
14
14
  function build(_x, _x2) {
@@ -2,7 +2,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
2
2
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
3
3
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
4
4
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
5
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
5
+ function _toPrimitive(t, e) { if ("object" != typeof t || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
6
6
  function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
7
7
  function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
8
8
  export function build(_x, _x2) {
@@ -11,6 +11,7 @@ exports.isNonEmptyUrl = isNonEmptyUrl;
11
11
  exports.withAlternateLinks = withAlternateLinks;
12
12
  var _sdk = require("@prezly/sdk");
13
13
  var _themeKitIntl = require("@prezly/theme-kit-intl");
14
+ var _index = require("../content-delivery/index.cjs");
14
15
  var _resolvable = require("../resolvable.cjs");
15
16
  var _build = require("./build.cjs");
16
17
  var _excluded = ["locale"];
@@ -24,7 +25,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
24
25
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
25
26
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
26
27
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
27
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
28
+ function _toPrimitive(t, e) { if ("object" != typeof t || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
28
29
  function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
29
30
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
30
31
  function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
@@ -134,7 +135,10 @@ function _generateCategoriesEntries() {
134
135
  public_stories_number = _ref6.public_stories_number;
135
136
  return locales.includes(locale) && public_stories_number !== 0;
136
137
  }).map(translation => {
138
+ // `path` for routes with nested category URLs (`/category/*path`),
139
+ // `slug` for routes with one segment (`/category/:slug`).
137
140
  var params = _objectSpread(_objectSpread({}, translation), {}, {
141
+ path: (0, _index.categoryPath)(translation),
138
142
  localeCode: translation.locale
139
143
  });
140
144
  return {
@@ -9,13 +9,14 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
9
9
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
10
10
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
11
11
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
12
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
12
+ function _toPrimitive(t, e) { if ("object" != typeof t || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
13
13
  function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
14
14
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
15
15
  function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
16
16
  function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
17
17
  import { Category } from '@prezly/sdk';
18
18
  import { Locale } from '@prezly/theme-kit-intl';
19
+ import { categoryPath } from "../content-delivery/index.mjs";
19
20
  import { AsyncResolvable } from "../resolvable.mjs";
20
21
  import { build } from "./build.mjs";
21
22
  export function generate(_x, _x2) {
@@ -123,7 +124,10 @@ function _generateCategoriesEntries() {
123
124
  public_stories_number = _ref6.public_stories_number;
124
125
  return locales.includes(locale) && public_stories_number !== 0;
125
126
  }).map(translation => {
127
+ // `path` for routes with nested category URLs (`/category/*path`),
128
+ // `slug` for routes with one segment (`/category/:slug`).
126
129
  var params = _objectSpread(_objectSpread({}, translation), {}, {
130
+ path: categoryPath(translation),
127
131
  localeCode: translation.locale
128
132
  });
129
133
  return {
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getPublicTranslations = getPublicTranslations;
7
+ exports.isPubliclyPublished = isPubliclyPublished;
8
+ var _sdk = require("@prezly/sdk");
9
+ /**
10
+ * Tells whether anyone can open the story on the site right now.
11
+ *
12
+ * A published story is not necessarily public: private and confidential stories are published too,
13
+ * and only people who were given the link should reach them.
14
+ */
15
+ function isPubliclyPublished(story) {
16
+ return story.status === _sdk.Story.Status.PUBLISHED && story.visibility === _sdk.Story.Visibility.PUBLIC;
17
+ }
18
+
19
+ /**
20
+ * Lists the story translations a page can link to.
21
+ *
22
+ * The API returns every translation of a story, whatever its status and visibility. Linking to a
23
+ * draft, scheduled, embargoed, private or confidential translation would disclose it to visitors.
24
+ */
25
+ function getPublicTranslations(story) {
26
+ return story.translations.filter(isPubliclyPublished);
27
+ }
@@ -0,0 +1,16 @@
1
+ import { Story } from '@prezly/sdk';
2
+ import type { StoryRef } from '@prezly/sdk';
3
+ /**
4
+ * Tells whether anyone can open the story on the site right now.
5
+ *
6
+ * A published story is not necessarily public: private and confidential stories are published too,
7
+ * and only people who were given the link should reach them.
8
+ */
9
+ export declare function isPubliclyPublished(story: Pick<StoryRef, 'status' | 'visibility'>): boolean;
10
+ /**
11
+ * Lists the story translations a page can link to.
12
+ *
13
+ * The API returns every translation of a story, whatever its status and visibility. Linking to a
14
+ * draft, scheduled, embargoed, private or confidential translation would disclose it to visitors.
15
+ */
16
+ export declare function getPublicTranslations(story: Pick<Story, 'translations'>): StoryRef[];
@@ -0,0 +1,20 @@
1
+ import { Story } from '@prezly/sdk';
2
+ /**
3
+ * Tells whether anyone can open the story on the site right now.
4
+ *
5
+ * A published story is not necessarily public: private and confidential stories are published too,
6
+ * and only people who were given the link should reach them.
7
+ */
8
+ export function isPubliclyPublished(story) {
9
+ return story.status === Story.Status.PUBLISHED && story.visibility === Story.Visibility.PUBLIC;
10
+ }
11
+
12
+ /**
13
+ * Lists the story translations a page can link to.
14
+ *
15
+ * The API returns every translation of a story, whatever its status and visibility. Linking to a
16
+ * draft, scheduled, embargoed, private or confidential translation would disclose it to visitors.
17
+ */
18
+ export function getPublicTranslations(story) {
19
+ return story.translations.filter(isPubliclyPublished);
20
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ var _sdk = require("@prezly/sdk");
4
+ var _stories = require("./stories.cjs");
5
+ function translation(code, status) {
6
+ var visibility = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _sdk.Story.Visibility.PUBLIC;
7
+ return {
8
+ culture: {
9
+ code
10
+ },
11
+ status,
12
+ visibility
13
+ };
14
+ }
15
+ describe('isPubliclyPublished', () => {
16
+ it('accepts a published public story', () => {
17
+ expect((0, _stories.isPubliclyPublished)({
18
+ status: _sdk.Story.Status.PUBLISHED,
19
+ visibility: _sdk.Story.Visibility.PUBLIC
20
+ })).toBe(true);
21
+ });
22
+ it.each([_sdk.Story.Visibility.PRIVATE, _sdk.Story.Visibility.CONFIDENTIAL, _sdk.Story.Visibility.EMBARGO])('rejects a published %s story', visibility => {
23
+ expect((0, _stories.isPubliclyPublished)({
24
+ status: _sdk.Story.Status.PUBLISHED,
25
+ visibility
26
+ })).toBe(false);
27
+ });
28
+ it.each([_sdk.Story.Status.UNINITIALIZED, _sdk.Story.Status.DRAFT, _sdk.Story.Status.SCHEDULED, _sdk.Story.Status.EMBARGO])('rejects a public story with the %s status', status => {
29
+ expect((0, _stories.isPubliclyPublished)({
30
+ status,
31
+ visibility: _sdk.Story.Visibility.PUBLIC
32
+ })).toBe(false);
33
+ });
34
+ });
35
+ describe('getPublicTranslations', () => {
36
+ it('keeps only the published public translations', () => {
37
+ var translations = [translation('en', _sdk.Story.Status.PUBLISHED), translation('fr', _sdk.Story.Status.DRAFT), translation('de', _sdk.Story.Status.SCHEDULED), translation('es', _sdk.Story.Status.EMBARGO, _sdk.Story.Visibility.EMBARGO), translation('nl', _sdk.Story.Status.PUBLISHED, _sdk.Story.Visibility.PRIVATE), translation('it', _sdk.Story.Status.PUBLISHED, _sdk.Story.Visibility.CONFIDENTIAL), translation('pt', _sdk.Story.Status.PUBLISHED)];
38
+ expect((0, _stories.getPublicTranslations)({
39
+ translations
40
+ }).map(story => story.culture.code)).toEqual(['en', 'pt']);
41
+ });
42
+ it('returns an empty list when the story has no translations', () => {
43
+ expect((0, _stories.getPublicTranslations)({
44
+ translations: []
45
+ })).toEqual([]);
46
+ });
47
+ });
@@ -0,0 +1,45 @@
1
+ import { Story } from '@prezly/sdk';
2
+ import { getPublicTranslations, isPubliclyPublished } from "./stories.mjs";
3
+ function translation(code, status) {
4
+ var visibility = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Story.Visibility.PUBLIC;
5
+ return {
6
+ culture: {
7
+ code
8
+ },
9
+ status,
10
+ visibility
11
+ };
12
+ }
13
+ describe('isPubliclyPublished', () => {
14
+ it('accepts a published public story', () => {
15
+ expect(isPubliclyPublished({
16
+ status: Story.Status.PUBLISHED,
17
+ visibility: Story.Visibility.PUBLIC
18
+ })).toBe(true);
19
+ });
20
+ it.each([Story.Visibility.PRIVATE, Story.Visibility.CONFIDENTIAL, Story.Visibility.EMBARGO])('rejects a published %s story', visibility => {
21
+ expect(isPubliclyPublished({
22
+ status: Story.Status.PUBLISHED,
23
+ visibility
24
+ })).toBe(false);
25
+ });
26
+ it.each([Story.Status.UNINITIALIZED, Story.Status.DRAFT, Story.Status.SCHEDULED, Story.Status.EMBARGO])('rejects a public story with the %s status', status => {
27
+ expect(isPubliclyPublished({
28
+ status,
29
+ visibility: Story.Visibility.PUBLIC
30
+ })).toBe(false);
31
+ });
32
+ });
33
+ describe('getPublicTranslations', () => {
34
+ it('keeps only the published public translations', () => {
35
+ var translations = [translation('en', Story.Status.PUBLISHED), translation('fr', Story.Status.DRAFT), translation('de', Story.Status.SCHEDULED), translation('es', Story.Status.EMBARGO, Story.Visibility.EMBARGO), translation('nl', Story.Status.PUBLISHED, Story.Visibility.PRIVATE), translation('it', Story.Status.PUBLISHED, Story.Visibility.CONFIDENTIAL), translation('pt', Story.Status.PUBLISHED)];
36
+ expect(getPublicTranslations({
37
+ translations
38
+ }).map(story => story.culture.code)).toEqual(['en', 'pt']);
39
+ });
40
+ it('returns an empty list when the story has no translations', () => {
41
+ expect(getPublicTranslations({
42
+ translations: []
43
+ })).toEqual([]);
44
+ });
45
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prezly/theme-kit-core",
3
- "version": "10.15.1",
3
+ "version": "10.16.1",
4
4
  "description": "Data layer and utility library for developing Prezly themes with JavaScript",
5
5
  "main": "build/index.mjs",
6
6
  "type": "module",
@@ -25,7 +25,7 @@
25
25
  "@technically/omit-undefined": "^1.0.4",
26
26
  "parse-data-url": "^6.0.0",
27
27
  "url-pattern": "^1.0.3",
28
- "@prezly/theme-kit-intl": "^10.15.1"
28
+ "@prezly/theme-kit-intl": "^10.16.1"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/parse-data-url": "3.0.2"