@prezly/theme-kit-core 10.15.1 → 10.16.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.
Files changed (37) 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 +2 -1
  18. package/build/metadata/getAlternateLanguageLinks.cjs +1 -1
  19. package/build/metadata/getAlternateLanguageLinks.mjs +1 -1
  20. package/build/routing/Route.cjs +27 -8
  21. package/build/routing/Route.mjs +27 -8
  22. package/build/routing/Route.test.cjs +46 -0
  23. package/build/routing/Route.test.mjs +46 -0
  24. package/build/routing/index.cjs +2 -1
  25. package/build/routing/types.d.ts +2 -0
  26. package/build/routing/utils/generateUrlFromPattern.cjs +19 -10
  27. package/build/routing/utils/generateUrlFromPattern.mjs +19 -10
  28. package/build/routing/utils/generateUrlFromPattern.test.cjs +15 -0
  29. package/build/routing/utils/generateUrlFromPattern.test.mjs +15 -0
  30. package/build/routing/utils/wildcard.cjs +76 -0
  31. package/build/routing/utils/wildcard.d.ts +25 -0
  32. package/build/routing/utils/wildcard.mjs +66 -0
  33. package/build/sitemap/build.cjs +1 -1
  34. package/build/sitemap/build.mjs +1 -1
  35. package/build/sitemap/generate.cjs +5 -1
  36. package/build/sitemap/generate.mjs +5 -1
  37. package/package.json +2 -2
@@ -4,8 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.allStories = exports.DEFAULT_NEGATIVE_TTL = void 0;
7
+ exports.categoryPath = categoryPath;
7
8
  exports.createClient = createClient;
8
- exports.story = exports.stories = exports.galleries = void 0;
9
+ exports.galleries = void 0;
10
+ exports.previousCategoryPaths = previousCategoryPaths;
11
+ exports.story = exports.stories = void 0;
9
12
  var _sdk = require("@prezly/sdk");
10
13
  var _RequestCoalescer = require("./RequestCoalescer.cjs");
11
14
  var _telemetry = require("./telemetry.cjs");
@@ -13,7 +16,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
13
16
  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; }
14
17
  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; }
15
18
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
16
- 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); }
19
+ 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); }
17
20
  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); }
18
21
  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); }); }; }
19
22
  /**
@@ -34,13 +37,34 @@ var CHRONOLOGICALLY = _sdk.SortOrder.combine(_sdk.SortOrder.desc('is_pinned'), _
34
37
  /**
35
38
  * Do not cache these methods, as they are derivatives of other cached methods.
36
39
  */
37
- var UNCACHED_METHODS = ['themeSettings', 'language', 'usedLanguages', 'locales', 'defaultLanguage', 'defaultLocale', 'languageOrDefault', 'companyInformation', 'notifications', 'category', 'translatedCategory', 'translatedCategories'];
40
+ var UNCACHED_METHODS = ['themeSettings', 'language', 'usedLanguages', 'locales', 'defaultLanguage', 'defaultLocale', 'languageOrDefault', 'companyInformation', 'notifications', 'category', 'translatedCategory', 'translatedCategoryByPath', 'translatedCategoryBySlug', 'translatedCategories', 'movedCategory'];
41
+
42
+ /**
43
+ * The address of a category page: `cars/models/eqs`.
44
+ *
45
+ * Read like this, because `path` is only known to newer versions of `@prezly/sdk`. Without it
46
+ * (an older SDK or API response, or a category from before paths existed) the path is the slug.
47
+ */
48
+ function categoryPath(translation) {
49
+ var _ref = translation,
50
+ path = _ref.path;
51
+ return path || translation.slug;
52
+ }
53
+
54
+ /**
55
+ * The paths a category had before in a locale, the most recently replaced first.
56
+ */
57
+ function previousCategoryPaths(category, locale) {
58
+ var _translation$previous;
59
+ var translation = category.i18n[locale];
60
+ return (_translation$previous = translation === null || translation === void 0 ? void 0 : translation.previous_paths) !== null && _translation$previous !== void 0 ? _translation$previous : [];
61
+ }
38
62
  function createClient(prezly, newsroomUuid, newsroomThemeUuid) {
39
- var _ref = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
40
- _ref$formats = _ref.formats,
41
- formats = _ref$formats === void 0 ? [_sdk.Story.FormatVersion.SLATEJS_V4] : _ref$formats,
42
- cache = _ref.cache,
43
- telemetry = _ref.telemetry;
63
+ var _ref2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
64
+ _ref2$formats = _ref2.formats,
65
+ formats = _ref2$formats === void 0 ? [_sdk.Story.FormatVersion.SLATEJS_V4] : _ref2$formats,
66
+ cache = _ref2.cache,
67
+ telemetry = _ref2.telemetry;
44
68
  var client = {
45
69
  newsroom() {
46
70
  return prezly.newsrooms.get(newsroomUuid);
@@ -114,13 +138,19 @@ function createClient(prezly, newsroomUuid, newsroomThemeUuid) {
114
138
  sortOrder: '+order'
115
139
  });
116
140
  },
141
+ /**
142
+ * Finds a category by its ID, or by its address in any locale: its path
143
+ * (`cars/models/eqs`), or else its slug.
144
+ */
117
145
  category(arg) {
118
146
  return _asyncToGenerator(function* () {
147
+ var _has;
119
148
  var categories = yield client.categories();
120
149
  if (typeof arg === 'number') {
121
150
  return categories.find(category => category.id === arg);
122
151
  }
123
- return categories.find(category => _sdk.Category.translations(category).some(translation => translation.slug === arg));
152
+ var has = matches => categories.find(category => Object.values(category.i18n).some(matches));
153
+ return (_has = has(translation => categoryPath(translation) === arg)) !== null && _has !== void 0 ? _has : has(translation => translation.slug === arg);
124
154
  })();
125
155
  },
126
156
  translatedCategories(locale, categories) {
@@ -128,10 +158,66 @@ function createClient(prezly, newsroomUuid, newsroomThemeUuid) {
128
158
  return _sdk.Category.translations(categories !== null && categories !== void 0 ? categories : yield client.categories(), locale);
129
159
  })();
130
160
  },
131
- translatedCategory(locale, slug) {
161
+ /**
162
+ * Finds a category by its address in a locale, for themes whose category URLs have one
163
+ * segment (`/category/:slug`).
164
+ *
165
+ * It returns the category with that path, which for a top-level category is its slug.
166
+ * When no category has that path, it returns the first category with that slug, as it
167
+ * always did. So the result can be a category that lives at another address: a theme
168
+ * with nested category URLs should use `translatedCategoryByPath()`, which never guesses.
169
+ */
170
+ translatedCategory(locale, pathOrSlug) {
171
+ return _asyncToGenerator(function* () {
172
+ var _yield$client$transla;
173
+ return (_yield$client$transla = yield client.translatedCategoryByPath(locale, pathOrSlug !== null && pathOrSlug !== void 0 ? pathOrSlug : '')) !== null && _yield$client$transla !== void 0 ? _yield$client$transla : yield client.translatedCategoryBySlug(locale, pathOrSlug !== null && pathOrSlug !== void 0 ? pathOrSlug : '');
174
+ })();
175
+ },
176
+ /**
177
+ * Finds the category that is at this path in a locale: `cars/models/eqs`. Only an exact
178
+ * match counts.
179
+ *
180
+ * For themes with nested category URLs (`/category/*path`). When it finds nothing, ask
181
+ * `movedCategory()` whether a category used to be there, and only then fall back to
182
+ * `translatedCategoryBySlug()` for old one-segment links. Redirect in both cases, so
183
+ * every category is served at one URL.
184
+ */
185
+ translatedCategoryByPath(locale, path) {
132
186
  return _asyncToGenerator(function* () {
133
- var translations = yield client.translatedCategories(locale);
134
- return translations.find(category => category.slug === slug);
187
+ var categories = yield client.categories();
188
+ var found = categories.find(category => {
189
+ var translation = category.i18n[locale];
190
+ return translation && categoryPath(translation) === path;
191
+ });
192
+ return found ? _sdk.Category.translation(found, locale) : undefined;
193
+ })();
194
+ },
195
+ /**
196
+ * Finds the first category with this slug in a locale. Slugs repeat across parent
197
+ * categories (`cars/events`, `vans/events`), so this is a guess, for old links only.
198
+ */
199
+ translatedCategoryBySlug(locale, slug) {
200
+ return _asyncToGenerator(function* () {
201
+ var categories = yield client.categories();
202
+ var found = categories.find(category => {
203
+ var _category$i18n$locale;
204
+ return ((_category$i18n$locale = category.i18n[locale]) === null || _category$i18n$locale === void 0 ? void 0 : _category$i18n$locale.slug) === slug;
205
+ });
206
+ return found ? _sdk.Category.translation(found, locale) : undefined;
207
+ })();
208
+ },
209
+ /**
210
+ * Finds the category that used to have this path in a locale, to redirect a request for
211
+ * its old address to the current one. Use it only when `translatedCategoryByPath()`
212
+ * found nothing: a category that has the path now always wins over one that had it
213
+ * before. Ask it before falling back to a slug: what the path used to lead to is known,
214
+ * a slug is a guess.
215
+ */
216
+ movedCategory(locale, path) {
217
+ return _asyncToGenerator(function* () {
218
+ var categories = yield client.categories();
219
+ var moved = categories.find(category => previousCategoryPaths(category, locale).includes(path));
220
+ return moved ? _sdk.Category.translation(moved, locale) : undefined;
135
221
  })();
136
222
  },
137
223
  featuredContacts() {
@@ -191,8 +277,8 @@ function createClient(prezly, newsroomUuid, newsroomThemeUuid) {
191
277
  search,
192
278
  query: mergeQueries(query, {
193
279
  'category.id': categories !== null && categories !== void 0 && categories.length ? {
194
- $all: categories.map(_ref2 => {
195
- var id = _ref2.id;
280
+ $all: categories.map(_ref3 => {
281
+ var id = _ref3.id;
196
282
  return id;
197
283
  })
198
284
  } : undefined,
@@ -69,6 +69,19 @@ export declare namespace galleries {
69
69
  }
70
70
  }
71
71
  export type Client = ReturnType<typeof createClient>;
72
+ /**
73
+ * The address of a category page: `cars/models/eqs`.
74
+ *
75
+ * Read like this, because `path` is only known to newer versions of `@prezly/sdk`. Without it
76
+ * (an older SDK or API response, or a category from before paths existed) the path is the slug.
77
+ */
78
+ export declare function categoryPath<T extends {
79
+ slug: string | null;
80
+ }>(translation: T): T['slug'];
81
+ /**
82
+ * The paths a category had before in a locale, the most recently replaced first.
83
+ */
84
+ export declare function previousCategoryPaths(category: Category, locale: Culture['code']): string[];
72
85
  export declare function createClient(prezly: PrezlyClient, newsroomUuid: Newsroom['uuid'], newsroomThemeUuid: NewsroomTheme['id'] | undefined, { formats, cache, telemetry }?: Options): {
73
86
  newsroom(): Promise<Newsroom>;
74
87
  theme(): Promise<import("@prezly/sdk").NewsroomThemePreset> | undefined;
@@ -83,9 +96,45 @@ export declare function createClient(prezly: PrezlyClient, newsroomUuid: Newsroo
83
96
  language(code: Culture["code"]): Promise<import("@prezly/sdk").NewsroomLanguageSettings | undefined>;
84
97
  languageOrDefault(code: Culture["code"]): Promise<import("@prezly/sdk").NewsroomLanguageSettings>;
85
98
  categories(): Promise<Category[]>;
99
+ /**
100
+ * Finds a category by its ID, or by its address in any locale: its path
101
+ * (`cars/models/eqs`), or else its slug.
102
+ */
86
103
  category(arg: Category["id"] | Category.Translation["slug"]): Promise<Category | undefined>;
87
104
  translatedCategories(locale: Culture["code"], categories?: Category[]): Promise<TranslatedCategory[]>;
88
- translatedCategory(locale: Culture["code"], slug: Category.Translation["slug"]): Promise<TranslatedCategory | undefined>;
105
+ /**
106
+ * Finds a category by its address in a locale, for themes whose category URLs have one
107
+ * segment (`/category/:slug`).
108
+ *
109
+ * It returns the category with that path, which for a top-level category is its slug.
110
+ * When no category has that path, it returns the first category with that slug, as it
111
+ * always did. So the result can be a category that lives at another address: a theme
112
+ * with nested category URLs should use `translatedCategoryByPath()`, which never guesses.
113
+ */
114
+ translatedCategory(locale: Culture["code"], pathOrSlug: Category.Translation["slug"]): Promise<TranslatedCategory | undefined>;
115
+ /**
116
+ * Finds the category that is at this path in a locale: `cars/models/eqs`. Only an exact
117
+ * match counts.
118
+ *
119
+ * For themes with nested category URLs (`/category/*path`). When it finds nothing, ask
120
+ * `movedCategory()` whether a category used to be there, and only then fall back to
121
+ * `translatedCategoryBySlug()` for old one-segment links. Redirect in both cases, so
122
+ * every category is served at one URL.
123
+ */
124
+ translatedCategoryByPath(locale: Culture["code"], path: string): Promise<TranslatedCategory | undefined>;
125
+ /**
126
+ * Finds the first category with this slug in a locale. Slugs repeat across parent
127
+ * categories (`cars/events`, `vans/events`), so this is a guess, for old links only.
128
+ */
129
+ translatedCategoryBySlug(locale: Culture["code"], slug: string): Promise<TranslatedCategory | undefined>;
130
+ /**
131
+ * Finds the category that used to have this path in a locale, to redirect a request for
132
+ * its old address to the current one. Use it only when `translatedCategoryByPath()`
133
+ * found nothing: a category that has the path now always wins over one that had it
134
+ * before. Ask it before falling back to a slug: what the path used to lead to is known,
135
+ * a slug is a guess.
136
+ */
137
+ movedCategory(locale: Culture["code"], path: string): Promise<TranslatedCategory | undefined>;
89
138
  featuredContacts(): Promise<import("@prezly/sdk").NewsroomContact[]>;
90
139
  galleries(params?: galleries.SearchParams): Promise<import("@prezly/sdk/dist/endpoints/NewsroomGalleries").ListResponse>;
91
140
  gallery(uuid: NewsroomGallery["uuid"]): Promise<NewsroomGallery | null>;
@@ -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
  import { ApiError, Category, NewsroomGallery, SortOrder, Stories, Story } from '@prezly/sdk';
@@ -26,13 +26,34 @@ var CHRONOLOGICALLY = SortOrder.combine(SortOrder.desc('is_pinned'), SortOrder.d
26
26
  /**
27
27
  * Do not cache these methods, as they are derivatives of other cached methods.
28
28
  */
29
- var UNCACHED_METHODS = ['themeSettings', 'language', 'usedLanguages', 'locales', 'defaultLanguage', 'defaultLocale', 'languageOrDefault', 'companyInformation', 'notifications', 'category', 'translatedCategory', 'translatedCategories'];
29
+ var UNCACHED_METHODS = ['themeSettings', 'language', 'usedLanguages', 'locales', 'defaultLanguage', 'defaultLocale', 'languageOrDefault', 'companyInformation', 'notifications', 'category', 'translatedCategory', 'translatedCategoryByPath', 'translatedCategoryBySlug', 'translatedCategories', 'movedCategory'];
30
+
31
+ /**
32
+ * The address of a category page: `cars/models/eqs`.
33
+ *
34
+ * Read like this, because `path` is only known to newer versions of `@prezly/sdk`. Without it
35
+ * (an older SDK or API response, or a category from before paths existed) the path is the slug.
36
+ */
37
+ export function categoryPath(translation) {
38
+ var _ref = translation,
39
+ path = _ref.path;
40
+ return path || translation.slug;
41
+ }
42
+
43
+ /**
44
+ * The paths a category had before in a locale, the most recently replaced first.
45
+ */
46
+ export function previousCategoryPaths(category, locale) {
47
+ var _translation$previous;
48
+ var translation = category.i18n[locale];
49
+ return (_translation$previous = translation === null || translation === void 0 ? void 0 : translation.previous_paths) !== null && _translation$previous !== void 0 ? _translation$previous : [];
50
+ }
30
51
  export function createClient(prezly, newsroomUuid, newsroomThemeUuid) {
31
- var _ref = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
32
- _ref$formats = _ref.formats,
33
- formats = _ref$formats === void 0 ? [Story.FormatVersion.SLATEJS_V4] : _ref$formats,
34
- cache = _ref.cache,
35
- telemetry = _ref.telemetry;
52
+ var _ref2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
53
+ _ref2$formats = _ref2.formats,
54
+ formats = _ref2$formats === void 0 ? [Story.FormatVersion.SLATEJS_V4] : _ref2$formats,
55
+ cache = _ref2.cache,
56
+ telemetry = _ref2.telemetry;
36
57
  var client = {
37
58
  newsroom() {
38
59
  return prezly.newsrooms.get(newsroomUuid);
@@ -106,13 +127,19 @@ export function createClient(prezly, newsroomUuid, newsroomThemeUuid) {
106
127
  sortOrder: '+order'
107
128
  });
108
129
  },
130
+ /**
131
+ * Finds a category by its ID, or by its address in any locale: its path
132
+ * (`cars/models/eqs`), or else its slug.
133
+ */
109
134
  category(arg) {
110
135
  return _asyncToGenerator(function* () {
136
+ var _has;
111
137
  var categories = yield client.categories();
112
138
  if (typeof arg === 'number') {
113
139
  return categories.find(category => category.id === arg);
114
140
  }
115
- return categories.find(category => Category.translations(category).some(translation => translation.slug === arg));
141
+ var has = matches => categories.find(category => Object.values(category.i18n).some(matches));
142
+ return (_has = has(translation => categoryPath(translation) === arg)) !== null && _has !== void 0 ? _has : has(translation => translation.slug === arg);
116
143
  })();
117
144
  },
118
145
  translatedCategories(locale, categories) {
@@ -120,10 +147,66 @@ export function createClient(prezly, newsroomUuid, newsroomThemeUuid) {
120
147
  return Category.translations(categories !== null && categories !== void 0 ? categories : yield client.categories(), locale);
121
148
  })();
122
149
  },
123
- translatedCategory(locale, slug) {
150
+ /**
151
+ * Finds a category by its address in a locale, for themes whose category URLs have one
152
+ * segment (`/category/:slug`).
153
+ *
154
+ * It returns the category with that path, which for a top-level category is its slug.
155
+ * When no category has that path, it returns the first category with that slug, as it
156
+ * always did. So the result can be a category that lives at another address: a theme
157
+ * with nested category URLs should use `translatedCategoryByPath()`, which never guesses.
158
+ */
159
+ translatedCategory(locale, pathOrSlug) {
160
+ return _asyncToGenerator(function* () {
161
+ var _yield$client$transla;
162
+ return (_yield$client$transla = yield client.translatedCategoryByPath(locale, pathOrSlug !== null && pathOrSlug !== void 0 ? pathOrSlug : '')) !== null && _yield$client$transla !== void 0 ? _yield$client$transla : yield client.translatedCategoryBySlug(locale, pathOrSlug !== null && pathOrSlug !== void 0 ? pathOrSlug : '');
163
+ })();
164
+ },
165
+ /**
166
+ * Finds the category that is at this path in a locale: `cars/models/eqs`. Only an exact
167
+ * match counts.
168
+ *
169
+ * For themes with nested category URLs (`/category/*path`). When it finds nothing, ask
170
+ * `movedCategory()` whether a category used to be there, and only then fall back to
171
+ * `translatedCategoryBySlug()` for old one-segment links. Redirect in both cases, so
172
+ * every category is served at one URL.
173
+ */
174
+ translatedCategoryByPath(locale, path) {
124
175
  return _asyncToGenerator(function* () {
125
- var translations = yield client.translatedCategories(locale);
126
- return translations.find(category => category.slug === slug);
176
+ var categories = yield client.categories();
177
+ var found = categories.find(category => {
178
+ var translation = category.i18n[locale];
179
+ return translation && categoryPath(translation) === path;
180
+ });
181
+ return found ? Category.translation(found, locale) : undefined;
182
+ })();
183
+ },
184
+ /**
185
+ * Finds the first category with this slug in a locale. Slugs repeat across parent
186
+ * categories (`cars/events`, `vans/events`), so this is a guess, for old links only.
187
+ */
188
+ translatedCategoryBySlug(locale, slug) {
189
+ return _asyncToGenerator(function* () {
190
+ var categories = yield client.categories();
191
+ var found = categories.find(category => {
192
+ var _category$i18n$locale;
193
+ return ((_category$i18n$locale = category.i18n[locale]) === null || _category$i18n$locale === void 0 ? void 0 : _category$i18n$locale.slug) === slug;
194
+ });
195
+ return found ? Category.translation(found, locale) : undefined;
196
+ })();
197
+ },
198
+ /**
199
+ * Finds the category that used to have this path in a locale, to redirect a request for
200
+ * its old address to the current one. Use it only when `translatedCategoryByPath()`
201
+ * found nothing: a category that has the path now always wins over one that had it
202
+ * before. Ask it before falling back to a slug: what the path used to lead to is known,
203
+ * a slug is a guess.
204
+ */
205
+ movedCategory(locale, path) {
206
+ return _asyncToGenerator(function* () {
207
+ var categories = yield client.categories();
208
+ var moved = categories.find(category => previousCategoryPaths(category, locale).includes(path));
209
+ return moved ? Category.translation(moved, locale) : undefined;
127
210
  })();
128
211
  },
129
212
  featuredContacts() {
@@ -183,8 +266,8 @@ export function createClient(prezly, newsroomUuid, newsroomThemeUuid) {
183
266
  search,
184
267
  query: mergeQueries(query, {
185
268
  'category.id': categories !== null && categories !== void 0 && categories.length ? {
186
- $all: categories.map(_ref2 => {
187
- var id = _ref2.id;
269
+ $all: categories.map(_ref3 => {
270
+ var id = _ref3.id;
188
271
  return id;
189
272
  })
190
273
  } : undefined,
@@ -12,7 +12,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
12
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
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
14
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
15
- 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); }
15
+ 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); }
16
16
  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); }
17
17
  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); }); }; }
18
18
  function memory() {
@@ -645,4 +645,88 @@ describe('ContentDelivery negative caching', () => {
645
645
  cache
646
646
  })).toThrow(RangeError);
647
647
  });
648
+ });
649
+ describe('ContentDelivery categories', () => {
650
+ function translation(slug, path) {
651
+ var previous_paths = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
652
+ return {
653
+ locale: {
654
+ code: 'en'
655
+ },
656
+ name: slug,
657
+ description: null,
658
+ slug,
659
+ path,
660
+ previous_paths,
661
+ public_stories_number: 1
662
+ };
663
+ }
664
+ var categories = [{
665
+ id: 1,
666
+ i18n: {
667
+ en: translation('cars', 'cars')
668
+ }
669
+ }, {
670
+ id: 2,
671
+ i18n: {
672
+ en: translation('events', 'cars/events', ['cars-events'])
673
+ }
674
+ }, {
675
+ id: 3,
676
+ i18n: {
677
+ en: translation('events', 'events', ['happenings'])
678
+ }
679
+ },
680
+ // From an API that does not know paths yet.
681
+ {
682
+ id: 4,
683
+ i18n: {
684
+ en: translation('vans', undefined)
685
+ }
686
+ }, {
687
+ id: 5,
688
+ i18n: {
689
+ en: translation('launches', 'vans/launches')
690
+ }
691
+ }];
692
+ function client() {
693
+ var list = jest.fn(/*#__PURE__*/_asyncToGenerator(function* () {
694
+ return categories;
695
+ }));
696
+ return (0, _ContentDelivery.createClient)({
697
+ newsroomCategories: {
698
+ list
699
+ }
700
+ }, 'room', undefined);
701
+ }
702
+ it('finds a category by its path', /*#__PURE__*/_asyncToGenerator(function* () {
703
+ var _yield$client$transla, _yield$client$transla2, _yield$client$categor;
704
+ expect((_yield$client$transla = yield client().translatedCategory('en', 'cars/events')) === null || _yield$client$transla === void 0 ? void 0 : _yield$client$transla.id).toBe(2);
705
+ expect((_yield$client$transla2 = yield client().translatedCategory('en', 'events')) === null || _yield$client$transla2 === void 0 ? void 0 : _yield$client$transla2.id).toBe(3);
706
+ expect((_yield$client$categor = yield client().category('cars/events')) === null || _yield$client$categor === void 0 ? void 0 : _yield$client$categor.id).toBe(2);
707
+ expect(yield client().translatedCategory('en', 'cars/nothing')).toBeUndefined();
708
+ }));
709
+ it('falls back to the slug, for themes with one-segment category URLs', /*#__PURE__*/_asyncToGenerator(function* () {
710
+ var _yield$client$transla3, _yield$client$transla4, _yield$client$categor2;
711
+ expect((_yield$client$transla3 = yield client().translatedCategory('en', 'vans')) === null || _yield$client$transla3 === void 0 ? void 0 : _yield$client$transla3.id).toBe(4);
712
+ expect((_yield$client$transla4 = yield client().translatedCategory('en', 'launches')) === null || _yield$client$transla4 === void 0 ? void 0 : _yield$client$transla4.id).toBe(5);
713
+ expect((_yield$client$categor2 = yield client().category('launches')) === null || _yield$client$categor2 === void 0 ? void 0 : _yield$client$categor2.id).toBe(5);
714
+ }));
715
+ it('finds a category by its exact path only, for themes with nested URLs', /*#__PURE__*/_asyncToGenerator(function* () {
716
+ var _yield$client$transla5, _yield$client$transla6, _yield$client$transla7;
717
+ expect((_yield$client$transla5 = yield client().translatedCategoryByPath('en', 'vans/launches')) === null || _yield$client$transla5 === void 0 ? void 0 : _yield$client$transla5.id).toBe(5);
718
+ // `launches` is the slug of a category that lives at `vans/launches`. Not a match:
719
+ // the theme decides whether to redirect, after asking movedCategory().
720
+ expect(yield client().translatedCategoryByPath('en', 'launches')).toBeUndefined();
721
+ expect((_yield$client$transla6 = yield client().translatedCategoryBySlug('en', 'launches')) === null || _yield$client$transla6 === void 0 ? void 0 : _yield$client$transla6.id).toBe(5);
722
+ // Without a path, the slug is the path.
723
+ expect((_yield$client$transla7 = yield client().translatedCategoryByPath('en', 'vans')) === null || _yield$client$transla7 === void 0 ? void 0 : _yield$client$transla7.id).toBe(4);
724
+ }));
725
+ it('finds the category that used to have a path', /*#__PURE__*/_asyncToGenerator(function* () {
726
+ var _yield$client$movedCa, _yield$client$movedCa2;
727
+ expect((_yield$client$movedCa = yield client().movedCategory('en', 'cars-events')) === null || _yield$client$movedCa === void 0 ? void 0 : _yield$client$movedCa.id).toBe(2);
728
+ expect((_yield$client$movedCa2 = yield client().movedCategory('en', 'happenings')) === null || _yield$client$movedCa2 === void 0 ? void 0 : _yield$client$movedCa2.id).toBe(3);
729
+ expect(yield client().movedCategory('en', 'nothing')).toBeUndefined();
730
+ expect(yield client().movedCategory('fr', 'cars-events')).toBeUndefined();
731
+ }));
648
732
  });
@@ -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
  import { ApiError, Story } from '@prezly/sdk';
@@ -643,4 +643,88 @@ describe('ContentDelivery negative caching', () => {
643
643
  cache
644
644
  })).toThrow(RangeError);
645
645
  });
646
+ });
647
+ describe('ContentDelivery categories', () => {
648
+ function translation(slug, path) {
649
+ var previous_paths = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
650
+ return {
651
+ locale: {
652
+ code: 'en'
653
+ },
654
+ name: slug,
655
+ description: null,
656
+ slug,
657
+ path,
658
+ previous_paths,
659
+ public_stories_number: 1
660
+ };
661
+ }
662
+ var categories = [{
663
+ id: 1,
664
+ i18n: {
665
+ en: translation('cars', 'cars')
666
+ }
667
+ }, {
668
+ id: 2,
669
+ i18n: {
670
+ en: translation('events', 'cars/events', ['cars-events'])
671
+ }
672
+ }, {
673
+ id: 3,
674
+ i18n: {
675
+ en: translation('events', 'events', ['happenings'])
676
+ }
677
+ },
678
+ // From an API that does not know paths yet.
679
+ {
680
+ id: 4,
681
+ i18n: {
682
+ en: translation('vans', undefined)
683
+ }
684
+ }, {
685
+ id: 5,
686
+ i18n: {
687
+ en: translation('launches', 'vans/launches')
688
+ }
689
+ }];
690
+ function client() {
691
+ var list = jest.fn(/*#__PURE__*/_asyncToGenerator(function* () {
692
+ return categories;
693
+ }));
694
+ return createClient({
695
+ newsroomCategories: {
696
+ list
697
+ }
698
+ }, 'room', undefined);
699
+ }
700
+ it('finds a category by its path', /*#__PURE__*/_asyncToGenerator(function* () {
701
+ var _yield$client$transla, _yield$client$transla2, _yield$client$categor;
702
+ expect((_yield$client$transla = yield client().translatedCategory('en', 'cars/events')) === null || _yield$client$transla === void 0 ? void 0 : _yield$client$transla.id).toBe(2);
703
+ expect((_yield$client$transla2 = yield client().translatedCategory('en', 'events')) === null || _yield$client$transla2 === void 0 ? void 0 : _yield$client$transla2.id).toBe(3);
704
+ expect((_yield$client$categor = yield client().category('cars/events')) === null || _yield$client$categor === void 0 ? void 0 : _yield$client$categor.id).toBe(2);
705
+ expect(yield client().translatedCategory('en', 'cars/nothing')).toBeUndefined();
706
+ }));
707
+ it('falls back to the slug, for themes with one-segment category URLs', /*#__PURE__*/_asyncToGenerator(function* () {
708
+ var _yield$client$transla3, _yield$client$transla4, _yield$client$categor2;
709
+ expect((_yield$client$transla3 = yield client().translatedCategory('en', 'vans')) === null || _yield$client$transla3 === void 0 ? void 0 : _yield$client$transla3.id).toBe(4);
710
+ expect((_yield$client$transla4 = yield client().translatedCategory('en', 'launches')) === null || _yield$client$transla4 === void 0 ? void 0 : _yield$client$transla4.id).toBe(5);
711
+ expect((_yield$client$categor2 = yield client().category('launches')) === null || _yield$client$categor2 === void 0 ? void 0 : _yield$client$categor2.id).toBe(5);
712
+ }));
713
+ it('finds a category by its exact path only, for themes with nested URLs', /*#__PURE__*/_asyncToGenerator(function* () {
714
+ var _yield$client$transla5, _yield$client$transla6, _yield$client$transla7;
715
+ expect((_yield$client$transla5 = yield client().translatedCategoryByPath('en', 'vans/launches')) === null || _yield$client$transla5 === void 0 ? void 0 : _yield$client$transla5.id).toBe(5);
716
+ // `launches` is the slug of a category that lives at `vans/launches`. Not a match:
717
+ // the theme decides whether to redirect, after asking movedCategory().
718
+ expect(yield client().translatedCategoryByPath('en', 'launches')).toBeUndefined();
719
+ expect((_yield$client$transla6 = yield client().translatedCategoryBySlug('en', 'launches')) === null || _yield$client$transla6 === void 0 ? void 0 : _yield$client$transla6.id).toBe(5);
720
+ // Without a path, the slug is the path.
721
+ expect((_yield$client$transla7 = yield client().translatedCategoryByPath('en', 'vans')) === null || _yield$client$transla7 === void 0 ? void 0 : _yield$client$transla7.id).toBe(4);
722
+ }));
723
+ it('finds the category that used to have a path', /*#__PURE__*/_asyncToGenerator(function* () {
724
+ var _yield$client$movedCa, _yield$client$movedCa2;
725
+ expect((_yield$client$movedCa = yield client().movedCategory('en', 'cars-events')) === null || _yield$client$movedCa === void 0 ? void 0 : _yield$client$movedCa.id).toBe(2);
726
+ expect((_yield$client$movedCa2 = yield client().movedCategory('en', 'happenings')) === null || _yield$client$movedCa2 === void 0 ? void 0 : _yield$client$movedCa2.id).toBe(3);
727
+ expect(yield client().movedCategory('en', 'nothing')).toBeUndefined();
728
+ expect(yield client().movedCategory('fr', 'cars-events')).toBeUndefined();
729
+ }));
646
730
  });
@@ -10,7 +10,7 @@ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.
10
10
  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); }); }; }
11
11
  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; }
12
12
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
13
- 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); }
13
+ 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); }
14
14
  var CACHE_WRITE_RETENTION_MS = 1000;
15
15
 
16
16
  /** Shares running work, then retains its result for a bounded cache-write window. */
@@ -3,7 +3,7 @@ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.
3
3
  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); }); }; }
4
4
  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; }
5
5
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
6
- 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); }
6
+ 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); }
7
7
  var CACHE_WRITE_RETENTION_MS = 1000;
8
8
 
9
9
  /** Shares running work, then retains its result for a bounded cache-write window. */
@@ -16,7 +16,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
16
16
  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; }
17
17
  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; }
18
18
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
19
- 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); }
19
+ 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); }
20
20
  var BUCKETS = [0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 30, Number.POSITIVE_INFINITY];
21
21
  function choice(value, values, fallback) {
22
22
  return typeof value === 'string' && values.includes(value) ? value : fallback;
@@ -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
  import { CONTENT_OPERATIONS, UPSTREAM_ROUTES } from "./telemetry.mjs";
13
13
  var BUCKETS = [0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 30, Number.POSITIVE_INFINITY];
14
14
  function choice(value, values, fallback) {