@c-rex/services 0.3.0-build.89 → 0.3.0-build.90

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.
@@ -96,7 +96,7 @@ var baseServerRequest = async (endpoint, query) => {
96
96
  url: endpoint,
97
97
  method: "GET",
98
98
  params: (0, import_requests.withGlobalRestriction)(query),
99
- skipCookieTokenLookup: requestContext?.skipCookieTokenLookup,
99
+ skipUserSession: requestContext?.skipUserSession,
100
100
  authToken: requestContext?.authToken
101
101
  });
102
102
  return response;
@@ -313,11 +313,15 @@ var resolveLocalizedLabel = (labels, uiLanguage) => {
313
313
  language: (item.language || "").trim().toLowerCase(),
314
314
  value: (item.value || "").trim()
315
315
  })).filter((item) => item.value.length > 0);
316
- const exact = normalized.find((item) => item.language === normalizedUiLanguage)?.value;
316
+ const exact = normalized.find(
317
+ (item) => item.language === normalizedUiLanguage
318
+ )?.value;
317
319
  if (exact) return exact;
318
320
  const base = normalized.find((item) => item.language === baseLanguage)?.value;
319
321
  if (base) return base;
320
- const english = normalized.find((item) => item.language === "en" || item.language === "en-us")?.value;
322
+ const english = normalized.find(
323
+ (item) => item.language === "en" || item.language === "en-us"
324
+ )?.value;
321
325
  if (english) return english;
322
326
  return normalized[0]?.value;
323
327
  };
@@ -376,24 +380,39 @@ var isNotFoundError = (error) => {
376
380
  return error.message.includes("HTTP error! status: 404");
377
381
  };
378
382
  var resolveMissingClassLabels = async (items, uiLanguage) => {
379
- const classIds = Array.from(new Set(
380
- items.map((item) => item.class?.id?.trim()).filter((id) => Boolean(id)).filter((id) => !resolveLocalizedLabel(items.find((item) => item.class?.id?.trim() === id)?.class?.labels || [], uiLanguage))
381
- ));
383
+ const classIds = Array.from(
384
+ new Set(
385
+ items.map((item) => item.class?.id?.trim()).filter((id) => Boolean(id)).filter(
386
+ (id) => !resolveLocalizedLabel(
387
+ items.find((item) => item.class?.id?.trim() === id)?.class?.labels || [],
388
+ uiLanguage
389
+ )
390
+ )
391
+ )
392
+ );
382
393
  const result = {};
383
- await Promise.all(classIds.map(async (classId) => {
384
- try {
385
- const entity = await withServerRequestContext(
386
- { skipCookieTokenLookup: true },
387
- () => domainEntitiesGetByIdServer({ id: classId }, { Fields: ["labels"] })
388
- );
389
- result[classId] = resolveLocalizedLabel(entity.labels || [], uiLanguage);
390
- } catch (error) {
391
- if (!isNotFoundError(error)) {
392
- throw error;
394
+ await Promise.all(
395
+ classIds.map(async (classId) => {
396
+ try {
397
+ const entity = await withServerRequestContext(
398
+ { skipUserSession: true },
399
+ () => domainEntitiesGetByIdServer(
400
+ { id: classId },
401
+ { Fields: ["labels"] }
402
+ )
403
+ );
404
+ result[classId] = resolveLocalizedLabel(
405
+ entity.labels || [],
406
+ uiLanguage
407
+ );
408
+ } catch (error) {
409
+ if (!isNotFoundError(error)) {
410
+ throw error;
411
+ }
412
+ result[classId] = void 0;
393
413
  }
394
- result[classId] = void 0;
395
- }
396
- }));
414
+ })
415
+ );
397
416
  return result;
398
417
  };
399
418
  var deriveParentIds = (entity) => {
@@ -412,14 +431,23 @@ var buildTaxonomyTree = (items, options) => {
412
431
  if (!entityRef) continue;
413
432
  nodesById[entityRef.id] = {
414
433
  ...entityRef,
415
- classRef: toClassRef(item.class, options.uiLanguage, options.classLabelsById),
434
+ classRef: toClassRef(
435
+ item.class,
436
+ options.uiLanguage,
437
+ options.classLabelsById
438
+ ),
416
439
  parentIds: deriveParentIds(item)
417
440
  };
418
441
  }
419
442
  Object.values(nodesById).forEach((node) => {
420
- parentLinks.set(node.id, node.parentIds.filter((id) => Boolean(nodesById[id])));
443
+ parentLinks.set(
444
+ node.id,
445
+ node.parentIds.filter((id) => Boolean(nodesById[id]))
446
+ );
421
447
  });
422
- const roots = Object.values(nodesById).filter((node) => (parentLinks.get(node.id) || []).length === 0);
448
+ const roots = Object.values(nodesById).filter(
449
+ (node) => (parentLinks.get(node.id) || []).length === 0
450
+ );
423
451
  if (!options.groupRootsByClass) {
424
452
  return {
425
453
  roots: roots.sort((a, b) => a.label.localeCompare(b.label)),
@@ -464,10 +492,13 @@ var createTaxonomyResolver = (options) => {
464
492
  const cached = (0, import_cache.unstable_cache)(
465
493
  async (_queryKey, query, uiLanguage) => {
466
494
  const items = await withServerRequestContext(
467
- { skipCookieTokenLookup: true },
495
+ { skipUserSession: true },
468
496
  () => fetchAllPages(options.fetch, query)
469
497
  );
470
- const classLabelsById = await resolveMissingClassLabels(items, uiLanguage);
498
+ const classLabelsById = await resolveMissingClassLabels(
499
+ items,
500
+ uiLanguage
501
+ );
471
502
  const result = buildTaxonomyTree(items, {
472
503
  ...defaultTreeOptions(uiLanguage),
473
504
  classLabelsById
@@ -475,8 +506,16 @@ var createTaxonomyResolver = (options) => {
475
506
  const bytes = measureSerializedBytes(result);
476
507
  const limitBytes = resolveMetadataCacheMaxBytes();
477
508
  if (bytes > limitBytes) {
478
- suppressMetadataCacheFamilyRuntime(options.cacheFamily, { bytes, limitBytes });
479
- await logCacheOverflow(options.cacheFamily, bytes, limitBytes, options.cacheKey);
509
+ suppressMetadataCacheFamilyRuntime(options.cacheFamily, {
510
+ bytes,
511
+ limitBytes
512
+ });
513
+ await logCacheOverflow(
514
+ options.cacheFamily,
515
+ bytes,
516
+ limitBytes,
517
+ options.cacheKey
518
+ );
480
519
  return {
481
520
  roots: [],
482
521
  nodesById: {},
@@ -499,7 +538,10 @@ var createTaxonomyResolver = (options) => {
499
538
  );
500
539
  return async (query) => {
501
540
  const uiLanguage = await resolveUiLanguage();
502
- const normalizedQuery = { ...options.defaultQuery, ...query || {} };
541
+ const normalizedQuery = {
542
+ ...options.defaultQuery,
543
+ ...query || {}
544
+ };
503
545
  const cacheKey = stableSerialize({ normalizedQuery, uiLanguage });
504
546
  return cached(cacheKey, normalizedQuery, uiLanguage);
505
547
  };
@@ -634,8 +676,11 @@ var mergeRoleRef = (current, candidate) => {
634
676
  var getPartiesCached = (0, import_cache.unstable_cache)(
635
677
  async (_queryKey, query, uiLanguage) => {
636
678
  const items = await withServerRequestContext(
637
- { skipCookieTokenLookup: true },
638
- () => fetchAllPages(partiesGetAllServer, query)
679
+ { skipUserSession: true },
680
+ () => fetchAllPages(
681
+ partiesGetAllServer,
682
+ query
683
+ )
639
684
  );
640
685
  const groups = /* @__PURE__ */ new Map();
641
686
  items.forEach((party) => {
@@ -673,7 +718,12 @@ var getPartiesCached = (0, import_cache.unstable_cache)(
673
718
  ["read-model", "parties"],
674
719
  {
675
720
  revalidate: READMODEL_CACHE_POLICY.metadataRevalidateSeconds,
676
- tags: [import_requests2.CREX_API_CACHE_TAG, import_requests2.CREX_READMODEL_CACHE_TAG, import_requests2.CREX_READMODEL_CACHE_METADATA_TAG, import_requests2.CREX_READMODEL_CACHE_PARTIES_TAG]
721
+ tags: [
722
+ import_requests2.CREX_API_CACHE_TAG,
723
+ import_requests2.CREX_READMODEL_CACHE_TAG,
724
+ import_requests2.CREX_READMODEL_CACHE_METADATA_TAG,
725
+ import_requests2.CREX_READMODEL_CACHE_PARTIES_TAG
726
+ ]
677
727
  }
678
728
  );
679
729
  var getInformationSubjects = async () => {
@@ -686,7 +736,10 @@ var getInformationSubjects = async () => {
686
736
  return categories;
687
737
  }
688
738
  } catch (error) {
689
- console.warn("[MetadataReadModels] Categories endpoint unavailable, falling back to InformationSubjects.", error);
739
+ console.warn(
740
+ "[MetadataReadModels] Categories endpoint unavailable, falling back to InformationSubjects.",
741
+ error
742
+ );
690
743
  }
691
744
  return getInformationSubjectsLegacyCached();
692
745
  };
@@ -704,7 +757,11 @@ var getParties = async () => {
704
757
  Fields: ["labels", "partyRole", "vcard", "class"],
705
758
  Sort: ["shortId"]
706
759
  };
707
- return getPartiesCached(stableSerialize({ query, uiLanguage }), query, uiLanguage);
760
+ return getPartiesCached(
761
+ stableSerialize({ query, uiLanguage }),
762
+ query,
763
+ uiLanguage
764
+ );
708
765
  };
709
766
  var getTopicTypes = async (query) => {
710
767
  return getTopicTypesCached(query);
@@ -1052,11 +1109,15 @@ var resolveLocalizedLabel2 = (labels, uiLanguage) => {
1052
1109
  language: (item.language || "").toLowerCase(),
1053
1110
  value: item.value || ""
1054
1111
  })).filter((item) => item.value.length > 0);
1055
- const exact = normalized.find((item) => item.language === normalizedLanguage)?.value;
1112
+ const exact = normalized.find(
1113
+ (item) => item.language === normalizedLanguage
1114
+ )?.value;
1056
1115
  if (exact) return exact;
1057
1116
  const base = normalized.find((item) => item.language === baseLanguage)?.value;
1058
1117
  if (base) return base;
1059
- const english = normalized.find((item) => item.language === "en" || item.language === "en-us")?.value;
1118
+ const english = normalized.find(
1119
+ (item) => item.language === "en" || item.language === "en-us"
1120
+ )?.value;
1060
1121
  if (english) return english;
1061
1122
  return normalized[0]?.value;
1062
1123
  };
@@ -1072,7 +1133,7 @@ var getDomainEntitySectionLabelUncached = async (id, uiLanguage) => {
1072
1133
  };
1073
1134
  try {
1074
1135
  const entity = await withServerRequestContext(
1075
- { skipCookieTokenLookup: true },
1136
+ { skipUserSession: true },
1076
1137
  () => domainEntitiesGetByIdServer({ id }, query)
1077
1138
  );
1078
1139
  return resolveLocalizedLabel2(entity.labels || [], uiLanguage);
@@ -1088,7 +1149,11 @@ var getDomainEntitySectionLabelCached = (0, import_cache2.unstable_cache)(
1088
1149
  ["metadata-presentation-domain-entity-label"],
1089
1150
  {
1090
1151
  revalidate: READMODEL_CACHE_POLICY.metadataRevalidateSeconds,
1091
- tags: [import_requests3.CREX_API_CACHE_TAG, import_requests3.CREX_READMODEL_CACHE_TAG, import_requests3.CREX_READMODEL_CACHE_METADATA_TAG]
1152
+ tags: [
1153
+ import_requests3.CREX_API_CACHE_TAG,
1154
+ import_requests3.CREX_READMODEL_CACHE_TAG,
1155
+ import_requests3.CREX_READMODEL_CACHE_METADATA_TAG
1156
+ ]
1092
1157
  }
1093
1158
  );
1094
1159
  var inFlightDomainEntityLabelRequests = /* @__PURE__ */ new Map();
@@ -1096,15 +1161,23 @@ var getDomainEntitySectionLabel = async (id, uiLanguage) => {
1096
1161
  const inFlightKey = `${id}::${uiLanguage.toLowerCase()}`;
1097
1162
  const existing = inFlightDomainEntityLabelRequests.get(inFlightKey);
1098
1163
  if (existing) return existing;
1099
- const promise = getDomainEntitySectionLabelCached(id, uiLanguage).finally(() => {
1100
- inFlightDomainEntityLabelRequests.delete(inFlightKey);
1101
- });
1164
+ const promise = getDomainEntitySectionLabelCached(id, uiLanguage).finally(
1165
+ () => {
1166
+ inFlightDomainEntityLabelRequests.delete(inFlightKey);
1167
+ }
1168
+ );
1102
1169
  inFlightDomainEntityLabelRequests.set(inFlightKey, promise);
1103
1170
  return promise;
1104
1171
  };
1105
1172
  var getMetadataFacetPresentation = async (properties, uiLanguage = "en-US", options) => {
1106
- const defaultProperties = Object.keys(INFORMATION_UNIT_PROPERTY_PRESENTATION).filter((property) => INFORMATION_UNIT_PROPERTY_PRESENTATION[property].facet.supported);
1107
- const propertySet = new Set(properties && properties.length > 0 ? properties : defaultProperties);
1173
+ const defaultProperties = Object.keys(
1174
+ INFORMATION_UNIT_PROPERTY_PRESENTATION
1175
+ ).filter(
1176
+ (property) => INFORMATION_UNIT_PROPERTY_PRESENTATION[property].facet.supported
1177
+ );
1178
+ const propertySet = new Set(
1179
+ properties && properties.length > 0 ? properties : defaultProperties
1180
+ );
1108
1181
  const result = {};
1109
1182
  const classResolvers = {
1110
1183
  components: getComponents,
@@ -1138,7 +1211,9 @@ var getMetadataFacetPresentation = async (properties, uiLanguage = "en-US", opti
1138
1211
  const parties = await getParties();
1139
1212
  const partyPresentation = {};
1140
1213
  parties.groups.forEach((group) => {
1141
- const hidden = isMetadataGroupDenied("parties", { partyRoleId: group.role.id });
1214
+ const hidden = isMetadataGroupDenied("parties", {
1215
+ partyRoleId: group.role.id
1216
+ });
1142
1217
  const sectionLabel = group.role.label;
1143
1218
  group.parties.forEach((party) => {
1144
1219
  if (!party.shortId) return;
@@ -1172,15 +1247,27 @@ var getMetadataFacetPresentation = async (properties, uiLanguage = "en-US", opti
1172
1247
  if (property === "topicTypes" || property === "contentLifeCycleStatus") {
1173
1248
  const domainEntityId = property === "topicTypes" ? TOPIC_TYPE_DOMAIN_ENTITY_ID : CONTENT_LIFECYCLE_STATUS_DOMAIN_ENTITY_ID;
1174
1249
  const sectionLabel = await getDomainEntitySectionLabel(domainEntityId, uiLanguage) || resolveUnknownSectionLabel(property, uiLanguage);
1175
- const presentation = createClassSectionPresentation(property, taxonomy.nodesById, uiLanguage);
1250
+ const presentation = createClassSectionPresentation(
1251
+ property,
1252
+ taxonomy.nodesById,
1253
+ uiLanguage
1254
+ );
1176
1255
  Object.values(presentation).forEach((entry) => {
1177
1256
  entry.sectionLabel = sectionLabel;
1178
1257
  });
1179
1258
  result[property] = presentation;
1180
1259
  return;
1181
1260
  }
1182
- const classLabelsById = await resolveMissingClassLabels2(taxonomy.nodesById, uiLanguage);
1183
- result[property] = createClassSectionPresentation(property, taxonomy.nodesById, uiLanguage, { classLabelsById });
1261
+ const classLabelsById = await resolveMissingClassLabels2(
1262
+ taxonomy.nodesById,
1263
+ uiLanguage
1264
+ );
1265
+ result[property] = createClassSectionPresentation(
1266
+ property,
1267
+ taxonomy.nodesById,
1268
+ uiLanguage,
1269
+ { classLabelsById }
1270
+ );
1184
1271
  })()
1185
1272
  );
1186
1273
  }
@@ -1454,7 +1541,7 @@ var normalizeVersionItems = (items, uiLanguage) => {
1454
1541
  var getAvailableLanguagesByVersionOfCached = (0, import_cache3.unstable_cache)(
1455
1542
  async (_cacheKey, query, uiLanguage) => {
1456
1543
  const result = await withServerRequestContext(
1457
- { skipCookieTokenLookup: true },
1544
+ { skipUserSession: true },
1458
1545
  () => informationUnitsGetAllServer(query)
1459
1546
  );
1460
1547
  return normalizeVersionItems(result.items || [], uiLanguage);
@@ -1462,12 +1549,16 @@ var getAvailableLanguagesByVersionOfCached = (0, import_cache3.unstable_cache)(
1462
1549
  ["read-model", "version-availability"],
1463
1550
  {
1464
1551
  revalidate: READMODEL_CACHE_POLICY.metadataRevalidateSeconds,
1465
- tags: [import_requests4.CREX_API_CACHE_TAG, import_requests4.CREX_READMODEL_CACHE_TAG, import_requests4.CREX_READMODEL_CACHE_METADATA_TAG]
1552
+ tags: [
1553
+ import_requests4.CREX_API_CACHE_TAG,
1554
+ import_requests4.CREX_READMODEL_CACHE_TAG,
1555
+ import_requests4.CREX_READMODEL_CACHE_METADATA_TAG
1556
+ ]
1466
1557
  }
1467
1558
  );
1468
1559
  var fetchAvailableLanguagesByVersionOfDirect = async (query, uiLanguage) => {
1469
1560
  const result = await withServerRequestContext(
1470
- { skipCookieTokenLookup: true },
1561
+ { skipUserSession: true },
1471
1562
  () => informationUnitsGetAllServer(query)
1472
1563
  );
1473
1564
  return normalizeVersionItems(result.items || [], uiLanguage);
@@ -1576,7 +1667,7 @@ var import_cache4 = require("next/cache");
1576
1667
  var import_requests5 = require("@c-rex/core/requests");
1577
1668
  var import_logger2 = require("@c-rex/core/logger");
1578
1669
  var import_constants2 = require("@c-rex/constants");
1579
- var import_headers2 = require("next/headers");
1670
+ var import_server = require("@c-rex/core/auth/server");
1580
1671
  var import_sdk2 = require("@c-rex/core/sdk");
1581
1672
  var DEFAULT_SORT = ["-informationSubjects.id"];
1582
1673
  var DEFAULT_PAGE_SIZE = 100;
@@ -1610,7 +1701,7 @@ var findStaticPageBySlug = (pages, slug) => pages.find(
1610
1701
  var resolveStaticPageResourceHref = async (shortId) => {
1611
1702
  try {
1612
1703
  const topic = await withServerRequestContext(
1613
- { skipCookieTokenLookup: true },
1704
+ { skipUserSession: true },
1614
1705
  () => topicsGetByIdServer({ id: shortId }, { Fields: ["renditions"] })
1615
1706
  );
1616
1707
  return resolveViewHref(topic);
@@ -1701,7 +1792,7 @@ var fetchStaticPages = async (query) => {
1701
1792
  };
1702
1793
  var getStaticPagesCached = (0, import_cache4.unstable_cache)(
1703
1794
  async (query) => withServerRequestContext(
1704
- { skipCookieTokenLookup: true },
1795
+ { skipUserSession: true },
1705
1796
  () => fetchStaticPages(query)
1706
1797
  ),
1707
1798
  ["read-model", "static-pages-v1"],
@@ -1719,8 +1810,7 @@ var getCurrentUserAuthToken = async () => {
1719
1810
  try {
1720
1811
  const config = new import_sdk2.CrexSDK().getServerConfig();
1721
1812
  if (config.OIDC.tokenSource !== import_constants2.TOKEN_SOURCES.USER_LOGIN) return void 0;
1722
- const token = (await (0, import_headers2.cookies)()).get(import_constants2.CREX_TOKEN_HEADER_KEY)?.value.trim();
1723
- return token || void 0;
1813
+ return (await (0, import_server.getAccessToken)())?.token || void 0;
1724
1814
  } catch {
1725
1815
  return void 0;
1726
1816
  }
@@ -1729,7 +1819,7 @@ var getStaticPages = async (query) => {
1729
1819
  try {
1730
1820
  const authToken = await getCurrentUserAuthToken();
1731
1821
  const pages = authToken ? await withServerRequestContext(
1732
- { skipCookieTokenLookup: true, authToken },
1822
+ { skipUserSession: true, authToken },
1733
1823
  () => fetchStaticPages(query)
1734
1824
  ) : await getStaticPagesCached(query);
1735
1825
  return { status: "ok", pages };