@prezly/theme-kit-core 10.9.0 → 10.9.2

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 +87 -71
  2. package/build/content-delivery/ContentDelivery.d.ts +2 -0
  3. package/build/content-delivery/ContentDelivery.mjs +87 -71
  4. package/build/content-delivery/ContentDelivery.test.cjs +284 -0
  5. package/build/content-delivery/ContentDelivery.test.mjs +282 -0
  6. package/build/content-delivery/RequestCoalescer.cjs +70 -0
  7. package/build/content-delivery/RequestCoalescer.d.ts +13 -0
  8. package/build/content-delivery/RequestCoalescer.mjs +63 -0
  9. package/build/content-delivery/RequestCoalescer.test.cjs +151 -0
  10. package/build/content-delivery/RequestCoalescer.test.mjs +149 -0
  11. package/build/content-delivery/cache/memory.cjs +15 -8
  12. package/build/content-delivery/cache/memory.mjs +15 -8
  13. package/build/galleries.cjs +2 -4
  14. package/build/galleries.mjs +2 -4
  15. package/build/http/HttpClient.cjs +12 -3
  16. package/build/http/HttpClient.mjs +12 -3
  17. package/build/metadata/getAlternateLanguageLinks.cjs +16 -7
  18. package/build/metadata/getAlternateLanguageLinks.mjs +16 -7
  19. package/build/metadata/getAlternateLanguageLinks.test.cjs +4 -6
  20. package/build/metadata/getAlternateLanguageLinks.test.mjs +4 -6
  21. package/build/privacy-portal.cjs +6 -7
  22. package/build/privacy-portal.mjs +6 -7
  23. package/build/resolvable.cjs +1 -1
  24. package/build/resolvable.mjs +1 -1
  25. package/build/routing/Route.cjs +14 -7
  26. package/build/routing/Route.mjs +14 -7
  27. package/build/routing/Router.cjs +19 -13
  28. package/build/routing/Router.mjs +19 -13
  29. package/build/routing/utils/generateUrlFromPattern.cjs +3 -6
  30. package/build/routing/utils/generateUrlFromPattern.mjs +3 -6
  31. package/build/routing/utils/getShortestLocaleSlug.cjs +5 -6
  32. package/build/routing/utils/getShortestLocaleSlug.mjs +5 -6
  33. package/build/sitemap/build.cjs +1 -3
  34. package/build/sitemap/build.mjs +1 -3
  35. package/build/sitemap/generate.cjs +49 -46
  36. package/build/sitemap/generate.mjs +49 -46
  37. package/package.json +77 -77
@@ -7,6 +7,7 @@ exports.allStories = void 0;
7
7
  exports.createClient = createClient;
8
8
  exports.story = exports.stories = exports.galleries = void 0;
9
9
  var _sdk = require("@prezly/sdk");
10
+ var _RequestCoalescer = require("./RequestCoalescer.cjs");
10
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; }
11
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; }
12
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; }
@@ -28,10 +29,10 @@ var CHRONOLOGICALLY = _sdk.SortOrder.combine(_sdk.SortOrder.desc('is_pinned'), _
28
29
  */
29
30
  var UNCACHED_METHODS = ['themeSettings', 'language', 'usedLanguages', 'locales', 'defaultLanguage', 'defaultLocale', 'languageOrDefault', 'companyInformation', 'notifications', 'category', 'translatedCategory', 'translatedCategories'];
30
31
  function createClient(prezly, newsroomUuid, newsroomThemeUuid) {
31
- var {
32
- formats = [_sdk.Story.FormatVersion.SLATEJS_V4],
33
- cache
34
- } = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
32
+ var _ref = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
33
+ _ref$formats = _ref.formats,
34
+ formats = _ref$formats === void 0 ? [_sdk.Story.FormatVersion.SLATEJS_V4] : _ref$formats,
35
+ cache = _ref.cache;
35
36
  var client = {
36
37
  newsroom() {
37
38
  return prezly.newsrooms.get(newsroomUuid);
@@ -134,11 +135,9 @@ function createClient(prezly, newsroomUuid, newsroomThemeUuid) {
134
135
  },
135
136
  galleries() {
136
137
  var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
137
- var {
138
- offset,
139
- limit,
140
- type
141
- } = params;
138
+ var offset = params.offset,
139
+ limit = params.limit,
140
+ type = params.type;
142
141
  return prezly.newsroomGalleries.search(newsroomUuid, {
143
142
  limit,
144
143
  offset,
@@ -163,19 +162,18 @@ function createClient(prezly, newsroomUuid, newsroomThemeUuid) {
163
162
  },
164
163
  stories(params) {
165
164
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
166
- var {
167
- search,
168
- query,
169
- offset = 0,
170
- limit,
171
- categories,
172
- locale,
173
- highlighted = 0,
174
- tags
175
- } = params;
176
- var {
177
- include = []
178
- } = options;
165
+ var search = params.search,
166
+ query = params.query,
167
+ _params$offset = params.offset,
168
+ offset = _params$offset === void 0 ? 0 : _params$offset,
169
+ limit = params.limit,
170
+ categories = params.categories,
171
+ locale = params.locale,
172
+ _params$highlighted = params.highlighted,
173
+ highlighted = _params$highlighted === void 0 ? 0 : _params$highlighted,
174
+ tags = params.tags;
175
+ var _options$include = options.include,
176
+ include = _options$include === void 0 ? [] : _options$include;
179
177
  var localeCode = locale && typeof locale === 'object' ? locale.code : locale;
180
178
  return prezly.stories.search({
181
179
  sortOrder: CHRONOLOGICALLY,
@@ -185,10 +183,8 @@ function createClient(prezly, newsroomUuid, newsroomThemeUuid) {
185
183
  search,
186
184
  query: mergeQueries(query, {
187
185
  'category.id': categories !== null && categories !== void 0 && categories.length ? {
188
- $all: categories.map(_ref => {
189
- var {
190
- id
191
- } = _ref;
186
+ $all: categories.map(_ref2 => {
187
+ var id = _ref2.id;
192
188
  return id;
193
189
  })
194
190
  } : undefined,
@@ -216,9 +212,8 @@ function createClient(prezly, newsroomUuid, newsroomThemeUuid) {
216
212
  return _asyncToGenerator(function* () {
217
213
  var params = _arguments.length > 0 && _arguments[0] !== undefined ? _arguments[0] : {};
218
214
  var options = _arguments.length > 1 && _arguments[1] !== undefined ? _arguments[1] : {};
219
- var {
220
- include = []
221
- } = options;
215
+ var _options$include2 = options.include,
216
+ include = _options$include2 === void 0 ? [] : _options$include2;
222
217
  var newsroom = yield client.newsroom();
223
218
  var chunkSize = 200;
224
219
 
@@ -226,24 +221,34 @@ function createClient(prezly, newsroomUuid, newsroomThemeUuid) {
226
221
  // Depending on the specific newsroom data, the rate of overfetching may be significant.
227
222
  var maxStories = newsroom.stories_number;
228
223
  var pages = Math.ceil(maxStories / chunkSize);
229
- var promises = Array.from({
230
- length: pages
231
- }, (_, chunkIndex) => client.stories(_objectSpread(_objectSpread({}, params), {}, {
232
- limit: chunkSize,
233
- offset: chunkIndex * chunkSize
234
- }), {
235
- include
236
- }));
237
- return (yield Promise.all(promises)).flatMap(response => response.stories);
224
+
225
+ // Bound production as well as transport admission: a large newsroom
226
+ // must not enqueue every page and overflow the shared HTTP queue itself.
227
+ var pagesPerBatch = 8;
228
+ var responses = [];
229
+ var _loop = function* _loop(firstPage) {
230
+ var batch = yield Promise.all(Array.from({
231
+ length: Math.min(pagesPerBatch, pages - firstPage)
232
+ }, (_, index) => client.stories(_objectSpread(_objectSpread({}, params), {}, {
233
+ limit: chunkSize,
234
+ offset: (firstPage + index) * chunkSize
235
+ }), {
236
+ include
237
+ })));
238
+ responses.push(...batch);
239
+ };
240
+ for (var firstPage = 0; firstPage < pages; firstPage += pagesPerBatch) {
241
+ yield* _loop(firstPage);
242
+ }
243
+ return responses.flatMap(response => response.stories);
238
244
  })();
239
245
  },
240
246
  story(params) {
241
247
  var _arguments2 = arguments;
242
248
  return _asyncToGenerator(function* () {
243
249
  var options = _arguments2.length > 1 && _arguments2[1] !== undefined ? _arguments2[1] : {};
244
- var {
245
- include = []
246
- } = options;
250
+ var _options$include3 = options.include,
251
+ include = _options$include3 === void 0 ? [] : _options$include3;
247
252
  if (params.uuid) {
248
253
  try {
249
254
  return yield prezly.stories.get(params.uuid, {
@@ -283,47 +288,58 @@ function createClient(prezly, newsroomUuid, newsroomThemeUuid) {
283
288
  }
284
289
  };
285
290
  if (cache) {
286
- injectCache(client, cache.storage.namespace("".concat(newsroomUuid, ":").concat(newsroomThemeUuid, ":").concat(formats.join(','), ":")), cache.latestVersion, UNCACHED_METHODS);
291
+ if (cache.scope !== undefined && !cache.scope) {
292
+ throw new Error('Content cache scope must not be empty.');
293
+ }
294
+ var namespace = "".concat(newsroomUuid, ":").concat(newsroomThemeUuid, ":").concat(formats.join(','), ":");
295
+ // A single schema prefix keeps old readers away from scoped envelopes.
296
+ // Scope/version changes overwrite the same keys rather than adding namespaces.
297
+ var storage = cache.scope === undefined ? cache.storage : cache.storage.namespace('scoped-v1');
298
+ injectCache(client, storage.namespace(namespace), cache.latestVersion, cache.scope, namespace, UNCACHED_METHODS);
287
299
  }
288
300
  return client;
289
301
  }
290
- function injectCache(client, cache, latestVersion) {
291
- var uncachedMethods = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
292
- var methodCalls = new Map();
302
+ function injectCache(client, cache, latestVersion, scope, namespace) {
303
+ var uncachedMethods = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : [];
304
+ // An opaque SDK client does not expose its credentials/source. Callers without
305
+ // an explicit scope keep request-local sharing; the Next.js adapter supplies one.
306
+ var requests = scope === undefined ? new _RequestCoalescer.RequestCoalescer() : _RequestCoalescer.sharedContentRequests;
293
307
  var methodNames = Object.keys(client);
294
308
  methodNames.forEach(methodName => {
295
- if (uncachedMethods.includes(methodName)) {
296
- // Do not cache this method.
297
- return;
298
- }
309
+ if (uncachedMethods.includes(methodName)) return;
299
310
  var uncachedFn = client[methodName].bind(client);
300
311
  client[methodName] = /*#__PURE__*/_asyncToGenerator(function* () {
301
312
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
302
313
  args[_key] = arguments[_key];
303
314
  }
315
+ // Preserve existing argument serialization; query canonicalization is separate.
304
316
  var cacheKey = "".concat(methodName, ":").concat(JSON.stringify(args));
305
- var dedupeKey = "".concat(latestVersion, ":").concat(cacheKey);
306
-
307
- // Dedupe requests
308
- var pending = methodCalls.get(dedupeKey);
309
- if (pending) return pending;
310
- function invoke() {
311
- return _invoke.apply(this, arguments);
312
- }
313
- function _invoke() {
314
- _invoke = _asyncToGenerator(function* () {
315
- var cached = yield cache.get(cacheKey, latestVersion);
316
- if (cached) return cached;
317
- var value = yield uncachedFn(...args);
318
- cache.set(cacheKey, value, latestVersion);
319
- methodCalls.delete(dedupeKey);
320
- return value;
321
- });
322
- return _invoke.apply(this, arguments);
323
- }
324
- var invokation = invoke();
325
- methodCalls.set(dedupeKey, invokation);
326
- return invokation;
317
+ var dedupeKey = JSON.stringify([scope, namespace, latestVersion, cacheKey]);
318
+ return requests.run(dedupeKey, /*#__PURE__*/_asyncToGenerator(function* () {
319
+ try {
320
+ var _stored = yield cache.get(cacheKey, latestVersion);
321
+ var cached = scope === undefined ? _stored : (_stored === null || _stored === void 0 ? void 0 : _stored.scope) === scope ? _stored.value : undefined;
322
+ // Preserve existing negative-cache semantics until null results
323
+ // have a deliberately short TTL and correct error classification.
324
+ if (cached) return {
325
+ value: cached
326
+ };
327
+ } catch (_unused) {
328
+ // A cache failure must not prevent a bounded origin fallback.
329
+ }
330
+ var value = yield uncachedFn(...args);
331
+ var stored = scope === undefined ? value : {
332
+ scope,
333
+ value
334
+ };
335
+ // Observe synchronous and asynchronous write failures without holding
336
+ // up a successful response or leaving an unhandled rejection.
337
+ var cacheWrite = Promise.resolve().then(() => cache.set(cacheKey, stored, latestVersion)).catch(() => undefined);
338
+ return {
339
+ value,
340
+ cacheWrite
341
+ };
342
+ }));
327
343
  });
328
344
  });
329
345
  }
@@ -6,6 +6,8 @@ export interface Options {
6
6
  cache?: {
7
7
  storage: Cache;
8
8
  latestVersion: UnixTimestampInSeconds;
9
+ /** Stable source/authorization identity. Enables cross-client request sharing. */
10
+ scope?: string;
9
11
  };
10
12
  }
11
13
  export declare namespace stories {
@@ -6,6 +6,7 @@ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e =
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';
9
+ import { RequestCoalescer, sharedContentRequests } from "./RequestCoalescer.mjs";
9
10
  export var stories;
10
11
  export var allStories;
11
12
  export var story;
@@ -20,10 +21,10 @@ var CHRONOLOGICALLY = SortOrder.combine(SortOrder.desc('is_pinned'), SortOrder.d
20
21
  */
21
22
  var UNCACHED_METHODS = ['themeSettings', 'language', 'usedLanguages', 'locales', 'defaultLanguage', 'defaultLocale', 'languageOrDefault', 'companyInformation', 'notifications', 'category', 'translatedCategory', 'translatedCategories'];
22
23
  export function createClient(prezly, newsroomUuid, newsroomThemeUuid) {
23
- var {
24
- formats = [Story.FormatVersion.SLATEJS_V4],
25
- cache
26
- } = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
24
+ var _ref = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
25
+ _ref$formats = _ref.formats,
26
+ formats = _ref$formats === void 0 ? [Story.FormatVersion.SLATEJS_V4] : _ref$formats,
27
+ cache = _ref.cache;
27
28
  var client = {
28
29
  newsroom() {
29
30
  return prezly.newsrooms.get(newsroomUuid);
@@ -126,11 +127,9 @@ export function createClient(prezly, newsroomUuid, newsroomThemeUuid) {
126
127
  },
127
128
  galleries() {
128
129
  var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
129
- var {
130
- offset,
131
- limit,
132
- type
133
- } = params;
130
+ var offset = params.offset,
131
+ limit = params.limit,
132
+ type = params.type;
134
133
  return prezly.newsroomGalleries.search(newsroomUuid, {
135
134
  limit,
136
135
  offset,
@@ -155,19 +154,18 @@ export function createClient(prezly, newsroomUuid, newsroomThemeUuid) {
155
154
  },
156
155
  stories(params) {
157
156
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
158
- var {
159
- search,
160
- query,
161
- offset = 0,
162
- limit,
163
- categories,
164
- locale,
165
- highlighted = 0,
166
- tags
167
- } = params;
168
- var {
169
- include = []
170
- } = options;
157
+ var search = params.search,
158
+ query = params.query,
159
+ _params$offset = params.offset,
160
+ offset = _params$offset === void 0 ? 0 : _params$offset,
161
+ limit = params.limit,
162
+ categories = params.categories,
163
+ locale = params.locale,
164
+ _params$highlighted = params.highlighted,
165
+ highlighted = _params$highlighted === void 0 ? 0 : _params$highlighted,
166
+ tags = params.tags;
167
+ var _options$include = options.include,
168
+ include = _options$include === void 0 ? [] : _options$include;
171
169
  var localeCode = locale && typeof locale === 'object' ? locale.code : locale;
172
170
  return prezly.stories.search({
173
171
  sortOrder: CHRONOLOGICALLY,
@@ -177,10 +175,8 @@ export function createClient(prezly, newsroomUuid, newsroomThemeUuid) {
177
175
  search,
178
176
  query: mergeQueries(query, {
179
177
  'category.id': categories !== null && categories !== void 0 && categories.length ? {
180
- $all: categories.map(_ref => {
181
- var {
182
- id
183
- } = _ref;
178
+ $all: categories.map(_ref2 => {
179
+ var id = _ref2.id;
184
180
  return id;
185
181
  })
186
182
  } : undefined,
@@ -208,9 +204,8 @@ export function createClient(prezly, newsroomUuid, newsroomThemeUuid) {
208
204
  return _asyncToGenerator(function* () {
209
205
  var params = _arguments.length > 0 && _arguments[0] !== undefined ? _arguments[0] : {};
210
206
  var options = _arguments.length > 1 && _arguments[1] !== undefined ? _arguments[1] : {};
211
- var {
212
- include = []
213
- } = options;
207
+ var _options$include2 = options.include,
208
+ include = _options$include2 === void 0 ? [] : _options$include2;
214
209
  var newsroom = yield client.newsroom();
215
210
  var chunkSize = 200;
216
211
 
@@ -218,24 +213,34 @@ export function createClient(prezly, newsroomUuid, newsroomThemeUuid) {
218
213
  // Depending on the specific newsroom data, the rate of overfetching may be significant.
219
214
  var maxStories = newsroom.stories_number;
220
215
  var pages = Math.ceil(maxStories / chunkSize);
221
- var promises = Array.from({
222
- length: pages
223
- }, (_, chunkIndex) => client.stories(_objectSpread(_objectSpread({}, params), {}, {
224
- limit: chunkSize,
225
- offset: chunkIndex * chunkSize
226
- }), {
227
- include
228
- }));
229
- return (yield Promise.all(promises)).flatMap(response => response.stories);
216
+
217
+ // Bound production as well as transport admission: a large newsroom
218
+ // must not enqueue every page and overflow the shared HTTP queue itself.
219
+ var pagesPerBatch = 8;
220
+ var responses = [];
221
+ var _loop = function* _loop(firstPage) {
222
+ var batch = yield Promise.all(Array.from({
223
+ length: Math.min(pagesPerBatch, pages - firstPage)
224
+ }, (_, index) => client.stories(_objectSpread(_objectSpread({}, params), {}, {
225
+ limit: chunkSize,
226
+ offset: (firstPage + index) * chunkSize
227
+ }), {
228
+ include
229
+ })));
230
+ responses.push(...batch);
231
+ };
232
+ for (var firstPage = 0; firstPage < pages; firstPage += pagesPerBatch) {
233
+ yield* _loop(firstPage);
234
+ }
235
+ return responses.flatMap(response => response.stories);
230
236
  })();
231
237
  },
232
238
  story(params) {
233
239
  var _arguments2 = arguments;
234
240
  return _asyncToGenerator(function* () {
235
241
  var options = _arguments2.length > 1 && _arguments2[1] !== undefined ? _arguments2[1] : {};
236
- var {
237
- include = []
238
- } = options;
242
+ var _options$include3 = options.include,
243
+ include = _options$include3 === void 0 ? [] : _options$include3;
239
244
  if (params.uuid) {
240
245
  try {
241
246
  return yield prezly.stories.get(params.uuid, {
@@ -275,47 +280,58 @@ export function createClient(prezly, newsroomUuid, newsroomThemeUuid) {
275
280
  }
276
281
  };
277
282
  if (cache) {
278
- injectCache(client, cache.storage.namespace("".concat(newsroomUuid, ":").concat(newsroomThemeUuid, ":").concat(formats.join(','), ":")), cache.latestVersion, UNCACHED_METHODS);
283
+ if (cache.scope !== undefined && !cache.scope) {
284
+ throw new Error('Content cache scope must not be empty.');
285
+ }
286
+ var namespace = "".concat(newsroomUuid, ":").concat(newsroomThemeUuid, ":").concat(formats.join(','), ":");
287
+ // A single schema prefix keeps old readers away from scoped envelopes.
288
+ // Scope/version changes overwrite the same keys rather than adding namespaces.
289
+ var storage = cache.scope === undefined ? cache.storage : cache.storage.namespace('scoped-v1');
290
+ injectCache(client, storage.namespace(namespace), cache.latestVersion, cache.scope, namespace, UNCACHED_METHODS);
279
291
  }
280
292
  return client;
281
293
  }
282
- function injectCache(client, cache, latestVersion) {
283
- var uncachedMethods = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
284
- var methodCalls = new Map();
294
+ function injectCache(client, cache, latestVersion, scope, namespace) {
295
+ var uncachedMethods = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : [];
296
+ // An opaque SDK client does not expose its credentials/source. Callers without
297
+ // an explicit scope keep request-local sharing; the Next.js adapter supplies one.
298
+ var requests = scope === undefined ? new RequestCoalescer() : sharedContentRequests;
285
299
  var methodNames = Object.keys(client);
286
300
  methodNames.forEach(methodName => {
287
- if (uncachedMethods.includes(methodName)) {
288
- // Do not cache this method.
289
- return;
290
- }
301
+ if (uncachedMethods.includes(methodName)) return;
291
302
  var uncachedFn = client[methodName].bind(client);
292
303
  client[methodName] = /*#__PURE__*/_asyncToGenerator(function* () {
293
304
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
294
305
  args[_key] = arguments[_key];
295
306
  }
307
+ // Preserve existing argument serialization; query canonicalization is separate.
296
308
  var cacheKey = "".concat(methodName, ":").concat(JSON.stringify(args));
297
- var dedupeKey = "".concat(latestVersion, ":").concat(cacheKey);
298
-
299
- // Dedupe requests
300
- var pending = methodCalls.get(dedupeKey);
301
- if (pending) return pending;
302
- function invoke() {
303
- return _invoke.apply(this, arguments);
304
- }
305
- function _invoke() {
306
- _invoke = _asyncToGenerator(function* () {
307
- var cached = yield cache.get(cacheKey, latestVersion);
308
- if (cached) return cached;
309
- var value = yield uncachedFn(...args);
310
- cache.set(cacheKey, value, latestVersion);
311
- methodCalls.delete(dedupeKey);
312
- return value;
313
- });
314
- return _invoke.apply(this, arguments);
315
- }
316
- var invokation = invoke();
317
- methodCalls.set(dedupeKey, invokation);
318
- return invokation;
309
+ var dedupeKey = JSON.stringify([scope, namespace, latestVersion, cacheKey]);
310
+ return requests.run(dedupeKey, /*#__PURE__*/_asyncToGenerator(function* () {
311
+ try {
312
+ var _stored = yield cache.get(cacheKey, latestVersion);
313
+ var cached = scope === undefined ? _stored : (_stored === null || _stored === void 0 ? void 0 : _stored.scope) === scope ? _stored.value : undefined;
314
+ // Preserve existing negative-cache semantics until null results
315
+ // have a deliberately short TTL and correct error classification.
316
+ if (cached) return {
317
+ value: cached
318
+ };
319
+ } catch (_unused) {
320
+ // A cache failure must not prevent a bounded origin fallback.
321
+ }
322
+ var value = yield uncachedFn(...args);
323
+ var stored = scope === undefined ? value : {
324
+ scope,
325
+ value
326
+ };
327
+ // Observe synchronous and asynchronous write failures without holding
328
+ // up a successful response or leaving an unhandled rejection.
329
+ var cacheWrite = Promise.resolve().then(() => cache.set(cacheKey, stored, latestVersion)).catch(() => undefined);
330
+ return {
331
+ value,
332
+ cacheWrite
333
+ };
334
+ }));
319
335
  });
320
336
  });
321
337
  }