@c-rex/services 0.3.0-build.85 → 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.
@@ -32,7 +32,7 @@ var baseServerRequest = async (endpoint, query) => {
32
32
  url: endpoint,
33
33
  method: "GET",
34
34
  params: withGlobalRestriction(query),
35
- skipCookieTokenLookup: requestContext?.skipCookieTokenLookup,
35
+ skipUserSession: requestContext?.skipUserSession,
36
36
  authToken: requestContext?.authToken
37
37
  });
38
38
  return response;
@@ -249,11 +249,15 @@ var resolveLocalizedLabel = (labels, uiLanguage) => {
249
249
  language: (item.language || "").trim().toLowerCase(),
250
250
  value: (item.value || "").trim()
251
251
  })).filter((item) => item.value.length > 0);
252
- const exact = normalized.find((item) => item.language === normalizedUiLanguage)?.value;
252
+ const exact = normalized.find(
253
+ (item) => item.language === normalizedUiLanguage
254
+ )?.value;
253
255
  if (exact) return exact;
254
256
  const base = normalized.find((item) => item.language === baseLanguage)?.value;
255
257
  if (base) return base;
256
- const english = normalized.find((item) => item.language === "en" || item.language === "en-us")?.value;
258
+ const english = normalized.find(
259
+ (item) => item.language === "en" || item.language === "en-us"
260
+ )?.value;
257
261
  if (english) return english;
258
262
  return normalized[0]?.value;
259
263
  };
@@ -312,24 +316,39 @@ var isNotFoundError = (error) => {
312
316
  return error.message.includes("HTTP error! status: 404");
313
317
  };
314
318
  var resolveMissingClassLabels = async (items, uiLanguage) => {
315
- const classIds = Array.from(new Set(
316
- 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))
317
- ));
319
+ const classIds = Array.from(
320
+ new Set(
321
+ items.map((item) => item.class?.id?.trim()).filter((id) => Boolean(id)).filter(
322
+ (id) => !resolveLocalizedLabel(
323
+ items.find((item) => item.class?.id?.trim() === id)?.class?.labels || [],
324
+ uiLanguage
325
+ )
326
+ )
327
+ )
328
+ );
318
329
  const result = {};
319
- await Promise.all(classIds.map(async (classId) => {
320
- try {
321
- const entity = await withServerRequestContext(
322
- { skipCookieTokenLookup: true },
323
- () => domainEntitiesGetByIdServer({ id: classId }, { Fields: ["labels"] })
324
- );
325
- result[classId] = resolveLocalizedLabel(entity.labels || [], uiLanguage);
326
- } catch (error) {
327
- if (!isNotFoundError(error)) {
328
- throw error;
330
+ await Promise.all(
331
+ classIds.map(async (classId) => {
332
+ try {
333
+ const entity = await withServerRequestContext(
334
+ { skipUserSession: true },
335
+ () => domainEntitiesGetByIdServer(
336
+ { id: classId },
337
+ { Fields: ["labels"] }
338
+ )
339
+ );
340
+ result[classId] = resolveLocalizedLabel(
341
+ entity.labels || [],
342
+ uiLanguage
343
+ );
344
+ } catch (error) {
345
+ if (!isNotFoundError(error)) {
346
+ throw error;
347
+ }
348
+ result[classId] = void 0;
329
349
  }
330
- result[classId] = void 0;
331
- }
332
- }));
350
+ })
351
+ );
333
352
  return result;
334
353
  };
335
354
  var deriveParentIds = (entity) => {
@@ -348,14 +367,23 @@ var buildTaxonomyTree = (items, options) => {
348
367
  if (!entityRef) continue;
349
368
  nodesById[entityRef.id] = {
350
369
  ...entityRef,
351
- classRef: toClassRef(item.class, options.uiLanguage, options.classLabelsById),
370
+ classRef: toClassRef(
371
+ item.class,
372
+ options.uiLanguage,
373
+ options.classLabelsById
374
+ ),
352
375
  parentIds: deriveParentIds(item)
353
376
  };
354
377
  }
355
378
  Object.values(nodesById).forEach((node) => {
356
- parentLinks.set(node.id, node.parentIds.filter((id) => Boolean(nodesById[id])));
379
+ parentLinks.set(
380
+ node.id,
381
+ node.parentIds.filter((id) => Boolean(nodesById[id]))
382
+ );
357
383
  });
358
- const roots = Object.values(nodesById).filter((node) => (parentLinks.get(node.id) || []).length === 0);
384
+ const roots = Object.values(nodesById).filter(
385
+ (node) => (parentLinks.get(node.id) || []).length === 0
386
+ );
359
387
  if (!options.groupRootsByClass) {
360
388
  return {
361
389
  roots: roots.sort((a, b) => a.label.localeCompare(b.label)),
@@ -400,10 +428,13 @@ var createTaxonomyResolver = (options) => {
400
428
  const cached = unstable_cache(
401
429
  async (_queryKey, query, uiLanguage) => {
402
430
  const items = await withServerRequestContext(
403
- { skipCookieTokenLookup: true },
431
+ { skipUserSession: true },
404
432
  () => fetchAllPages(options.fetch, query)
405
433
  );
406
- const classLabelsById = await resolveMissingClassLabels(items, uiLanguage);
434
+ const classLabelsById = await resolveMissingClassLabels(
435
+ items,
436
+ uiLanguage
437
+ );
407
438
  const result = buildTaxonomyTree(items, {
408
439
  ...defaultTreeOptions(uiLanguage),
409
440
  classLabelsById
@@ -411,8 +442,16 @@ var createTaxonomyResolver = (options) => {
411
442
  const bytes = measureSerializedBytes(result);
412
443
  const limitBytes = resolveMetadataCacheMaxBytes();
413
444
  if (bytes > limitBytes) {
414
- suppressMetadataCacheFamilyRuntime(options.cacheFamily, { bytes, limitBytes });
415
- await logCacheOverflow(options.cacheFamily, bytes, limitBytes, options.cacheKey);
445
+ suppressMetadataCacheFamilyRuntime(options.cacheFamily, {
446
+ bytes,
447
+ limitBytes
448
+ });
449
+ await logCacheOverflow(
450
+ options.cacheFamily,
451
+ bytes,
452
+ limitBytes,
453
+ options.cacheKey
454
+ );
416
455
  return {
417
456
  roots: [],
418
457
  nodesById: {},
@@ -435,7 +474,10 @@ var createTaxonomyResolver = (options) => {
435
474
  );
436
475
  return async (query) => {
437
476
  const uiLanguage = await resolveUiLanguage();
438
- const normalizedQuery = { ...options.defaultQuery, ...query || {} };
477
+ const normalizedQuery = {
478
+ ...options.defaultQuery,
479
+ ...query || {}
480
+ };
439
481
  const cacheKey = stableSerialize({ normalizedQuery, uiLanguage });
440
482
  return cached(cacheKey, normalizedQuery, uiLanguage);
441
483
  };
@@ -570,8 +612,11 @@ var mergeRoleRef = (current, candidate) => {
570
612
  var getPartiesCached = unstable_cache(
571
613
  async (_queryKey, query, uiLanguage) => {
572
614
  const items = await withServerRequestContext(
573
- { skipCookieTokenLookup: true },
574
- () => fetchAllPages(partiesGetAllServer, query)
615
+ { skipUserSession: true },
616
+ () => fetchAllPages(
617
+ partiesGetAllServer,
618
+ query
619
+ )
575
620
  );
576
621
  const groups = /* @__PURE__ */ new Map();
577
622
  items.forEach((party) => {
@@ -609,7 +654,12 @@ var getPartiesCached = unstable_cache(
609
654
  ["read-model", "parties"],
610
655
  {
611
656
  revalidate: READMODEL_CACHE_POLICY.metadataRevalidateSeconds,
612
- tags: [CREX_API_CACHE_TAG, CREX_READMODEL_CACHE_TAG, CREX_READMODEL_CACHE_METADATA_TAG, CREX_READMODEL_CACHE_PARTIES_TAG]
657
+ tags: [
658
+ CREX_API_CACHE_TAG,
659
+ CREX_READMODEL_CACHE_TAG,
660
+ CREX_READMODEL_CACHE_METADATA_TAG,
661
+ CREX_READMODEL_CACHE_PARTIES_TAG
662
+ ]
613
663
  }
614
664
  );
615
665
  var getInformationSubjects = async () => {
@@ -622,7 +672,10 @@ var getInformationSubjects = async () => {
622
672
  return categories;
623
673
  }
624
674
  } catch (error) {
625
- console.warn("[MetadataReadModels] Categories endpoint unavailable, falling back to InformationSubjects.", error);
675
+ console.warn(
676
+ "[MetadataReadModels] Categories endpoint unavailable, falling back to InformationSubjects.",
677
+ error
678
+ );
626
679
  }
627
680
  return getInformationSubjectsLegacyCached();
628
681
  };
@@ -640,7 +693,11 @@ var getParties = async () => {
640
693
  Fields: ["labels", "partyRole", "vcard", "class"],
641
694
  Sort: ["shortId"]
642
695
  };
643
- return getPartiesCached(stableSerialize({ query, uiLanguage }), query, uiLanguage);
696
+ return getPartiesCached(
697
+ stableSerialize({ query, uiLanguage }),
698
+ query,
699
+ uiLanguage
700
+ );
644
701
  };
645
702
  var getTopicTypes = async (query) => {
646
703
  return getTopicTypesCached(query);
@@ -894,7 +951,11 @@ var INFORMATION_UNIT_PROPERTY_PRESENTATION = {
894
951
 
895
952
  // src/read-models/metadata-presentation.ts
896
953
  import { unstable_cache as unstable_cache2 } from "next/cache";
897
- import { CREX_API_CACHE_TAG as CREX_API_CACHE_TAG2, CREX_READMODEL_CACHE_METADATA_TAG as CREX_READMODEL_CACHE_METADATA_TAG2, CREX_READMODEL_CACHE_TAG as CREX_READMODEL_CACHE_TAG2 } from "@c-rex/core/requests";
954
+ import {
955
+ CREX_API_CACHE_TAG as CREX_API_CACHE_TAG2,
956
+ CREX_READMODEL_CACHE_METADATA_TAG as CREX_READMODEL_CACHE_METADATA_TAG2,
957
+ CREX_READMODEL_CACHE_TAG as CREX_READMODEL_CACHE_TAG2
958
+ } from "@c-rex/core/requests";
898
959
  var UNKNOWN_SECTION_LABELS = {
899
960
  en: {
900
961
  components: "Unknown component",
@@ -988,11 +1049,15 @@ var resolveLocalizedLabel2 = (labels, uiLanguage) => {
988
1049
  language: (item.language || "").toLowerCase(),
989
1050
  value: item.value || ""
990
1051
  })).filter((item) => item.value.length > 0);
991
- const exact = normalized.find((item) => item.language === normalizedLanguage)?.value;
1052
+ const exact = normalized.find(
1053
+ (item) => item.language === normalizedLanguage
1054
+ )?.value;
992
1055
  if (exact) return exact;
993
1056
  const base = normalized.find((item) => item.language === baseLanguage)?.value;
994
1057
  if (base) return base;
995
- const english = normalized.find((item) => item.language === "en" || item.language === "en-us")?.value;
1058
+ const english = normalized.find(
1059
+ (item) => item.language === "en" || item.language === "en-us"
1060
+ )?.value;
996
1061
  if (english) return english;
997
1062
  return normalized[0]?.value;
998
1063
  };
@@ -1008,7 +1073,7 @@ var getDomainEntitySectionLabelUncached = async (id, uiLanguage) => {
1008
1073
  };
1009
1074
  try {
1010
1075
  const entity = await withServerRequestContext(
1011
- { skipCookieTokenLookup: true },
1076
+ { skipUserSession: true },
1012
1077
  () => domainEntitiesGetByIdServer({ id }, query)
1013
1078
  );
1014
1079
  return resolveLocalizedLabel2(entity.labels || [], uiLanguage);
@@ -1024,7 +1089,11 @@ var getDomainEntitySectionLabelCached = unstable_cache2(
1024
1089
  ["metadata-presentation-domain-entity-label"],
1025
1090
  {
1026
1091
  revalidate: READMODEL_CACHE_POLICY.metadataRevalidateSeconds,
1027
- tags: [CREX_API_CACHE_TAG2, CREX_READMODEL_CACHE_TAG2, CREX_READMODEL_CACHE_METADATA_TAG2]
1092
+ tags: [
1093
+ CREX_API_CACHE_TAG2,
1094
+ CREX_READMODEL_CACHE_TAG2,
1095
+ CREX_READMODEL_CACHE_METADATA_TAG2
1096
+ ]
1028
1097
  }
1029
1098
  );
1030
1099
  var inFlightDomainEntityLabelRequests = /* @__PURE__ */ new Map();
@@ -1032,15 +1101,23 @@ var getDomainEntitySectionLabel = async (id, uiLanguage) => {
1032
1101
  const inFlightKey = `${id}::${uiLanguage.toLowerCase()}`;
1033
1102
  const existing = inFlightDomainEntityLabelRequests.get(inFlightKey);
1034
1103
  if (existing) return existing;
1035
- const promise = getDomainEntitySectionLabelCached(id, uiLanguage).finally(() => {
1036
- inFlightDomainEntityLabelRequests.delete(inFlightKey);
1037
- });
1104
+ const promise = getDomainEntitySectionLabelCached(id, uiLanguage).finally(
1105
+ () => {
1106
+ inFlightDomainEntityLabelRequests.delete(inFlightKey);
1107
+ }
1108
+ );
1038
1109
  inFlightDomainEntityLabelRequests.set(inFlightKey, promise);
1039
1110
  return promise;
1040
1111
  };
1041
1112
  var getMetadataFacetPresentation = async (properties, uiLanguage = "en-US", options) => {
1042
- const defaultProperties = Object.keys(INFORMATION_UNIT_PROPERTY_PRESENTATION).filter((property) => INFORMATION_UNIT_PROPERTY_PRESENTATION[property].facet.supported);
1043
- const propertySet = new Set(properties && properties.length > 0 ? properties : defaultProperties);
1113
+ const defaultProperties = Object.keys(
1114
+ INFORMATION_UNIT_PROPERTY_PRESENTATION
1115
+ ).filter(
1116
+ (property) => INFORMATION_UNIT_PROPERTY_PRESENTATION[property].facet.supported
1117
+ );
1118
+ const propertySet = new Set(
1119
+ properties && properties.length > 0 ? properties : defaultProperties
1120
+ );
1044
1121
  const result = {};
1045
1122
  const classResolvers = {
1046
1123
  components: getComponents,
@@ -1074,7 +1151,9 @@ var getMetadataFacetPresentation = async (properties, uiLanguage = "en-US", opti
1074
1151
  const parties = await getParties();
1075
1152
  const partyPresentation = {};
1076
1153
  parties.groups.forEach((group) => {
1077
- const hidden = isMetadataGroupDenied("parties", { partyRoleId: group.role.id });
1154
+ const hidden = isMetadataGroupDenied("parties", {
1155
+ partyRoleId: group.role.id
1156
+ });
1078
1157
  const sectionLabel = group.role.label;
1079
1158
  group.parties.forEach((party) => {
1080
1159
  if (!party.shortId) return;
@@ -1108,15 +1187,27 @@ var getMetadataFacetPresentation = async (properties, uiLanguage = "en-US", opti
1108
1187
  if (property === "topicTypes" || property === "contentLifeCycleStatus") {
1109
1188
  const domainEntityId = property === "topicTypes" ? TOPIC_TYPE_DOMAIN_ENTITY_ID : CONTENT_LIFECYCLE_STATUS_DOMAIN_ENTITY_ID;
1110
1189
  const sectionLabel = await getDomainEntitySectionLabel(domainEntityId, uiLanguage) || resolveUnknownSectionLabel(property, uiLanguage);
1111
- const presentation = createClassSectionPresentation(property, taxonomy.nodesById, uiLanguage);
1190
+ const presentation = createClassSectionPresentation(
1191
+ property,
1192
+ taxonomy.nodesById,
1193
+ uiLanguage
1194
+ );
1112
1195
  Object.values(presentation).forEach((entry) => {
1113
1196
  entry.sectionLabel = sectionLabel;
1114
1197
  });
1115
1198
  result[property] = presentation;
1116
1199
  return;
1117
1200
  }
1118
- const classLabelsById = await resolveMissingClassLabels2(taxonomy.nodesById, uiLanguage);
1119
- result[property] = createClassSectionPresentation(property, taxonomy.nodesById, uiLanguage, { classLabelsById });
1201
+ const classLabelsById = await resolveMissingClassLabels2(
1202
+ taxonomy.nodesById,
1203
+ uiLanguage
1204
+ );
1205
+ result[property] = createClassSectionPresentation(
1206
+ property,
1207
+ taxonomy.nodesById,
1208
+ uiLanguage,
1209
+ { classLabelsById }
1210
+ );
1120
1211
  })()
1121
1212
  );
1122
1213
  }
@@ -1352,7 +1443,11 @@ var getMetadataDisplayRows = async (data, options) => {
1352
1443
  };
1353
1444
 
1354
1445
  // src/read-models/version-availability.ts
1355
- import { CREX_API_CACHE_TAG as CREX_API_CACHE_TAG3, CREX_READMODEL_CACHE_METADATA_TAG as CREX_READMODEL_CACHE_METADATA_TAG3, CREX_READMODEL_CACHE_TAG as CREX_READMODEL_CACHE_TAG3 } from "@c-rex/core/requests";
1446
+ import {
1447
+ CREX_API_CACHE_TAG as CREX_API_CACHE_TAG3,
1448
+ CREX_READMODEL_CACHE_METADATA_TAG as CREX_READMODEL_CACHE_METADATA_TAG3,
1449
+ CREX_READMODEL_CACHE_TAG as CREX_READMODEL_CACHE_TAG3
1450
+ } from "@c-rex/core/requests";
1356
1451
  import { resolvePreferredLanguage as resolvePreferredLanguage2 } from "@c-rex/utils";
1357
1452
  import { unstable_cache as unstable_cache3 } from "next/cache";
1358
1453
  var stableSerialize2 = (value) => {
@@ -1390,7 +1485,7 @@ var normalizeVersionItems = (items, uiLanguage) => {
1390
1485
  var getAvailableLanguagesByVersionOfCached = unstable_cache3(
1391
1486
  async (_cacheKey, query, uiLanguage) => {
1392
1487
  const result = await withServerRequestContext(
1393
- { skipCookieTokenLookup: true },
1488
+ { skipUserSession: true },
1394
1489
  () => informationUnitsGetAllServer(query)
1395
1490
  );
1396
1491
  return normalizeVersionItems(result.items || [], uiLanguage);
@@ -1398,12 +1493,16 @@ var getAvailableLanguagesByVersionOfCached = unstable_cache3(
1398
1493
  ["read-model", "version-availability"],
1399
1494
  {
1400
1495
  revalidate: READMODEL_CACHE_POLICY.metadataRevalidateSeconds,
1401
- tags: [CREX_API_CACHE_TAG3, CREX_READMODEL_CACHE_TAG3, CREX_READMODEL_CACHE_METADATA_TAG3]
1496
+ tags: [
1497
+ CREX_API_CACHE_TAG3,
1498
+ CREX_READMODEL_CACHE_TAG3,
1499
+ CREX_READMODEL_CACHE_METADATA_TAG3
1500
+ ]
1402
1501
  }
1403
1502
  );
1404
1503
  var fetchAvailableLanguagesByVersionOfDirect = async (query, uiLanguage) => {
1405
1504
  const result = await withServerRequestContext(
1406
- { skipCookieTokenLookup: true },
1505
+ { skipUserSession: true },
1407
1506
  () => informationUnitsGetAllServer(query)
1408
1507
  );
1409
1508
  return normalizeVersionItems(result.items || [], uiLanguage);
@@ -1516,12 +1615,8 @@ import {
1516
1615
  CREX_READMODEL_CACHE_STATIC_PAGES_TAG
1517
1616
  } from "@c-rex/core/requests";
1518
1617
  import { CrexLogger as CrexLogger2 } from "@c-rex/core/logger";
1519
- import {
1520
- CREX_TOKEN_HEADER_KEY,
1521
- RENDITION_LINK_RELS,
1522
- TOKEN_SOURCES
1523
- } from "@c-rex/constants";
1524
- import { cookies as cookies2 } from "next/headers";
1618
+ import { RENDITION_LINK_RELS, TOKEN_SOURCES } from "@c-rex/constants";
1619
+ import { getAccessToken } from "@c-rex/core/auth/server";
1525
1620
  import { CrexSDK as CrexSDK2 } from "@c-rex/core/sdk";
1526
1621
  var DEFAULT_SORT = ["-informationSubjects.id"];
1527
1622
  var DEFAULT_PAGE_SIZE = 100;
@@ -1555,7 +1650,7 @@ var findStaticPageBySlug = (pages, slug) => pages.find(
1555
1650
  var resolveStaticPageResourceHref = async (shortId) => {
1556
1651
  try {
1557
1652
  const topic = await withServerRequestContext(
1558
- { skipCookieTokenLookup: true },
1653
+ { skipUserSession: true },
1559
1654
  () => topicsGetByIdServer({ id: shortId }, { Fields: ["renditions"] })
1560
1655
  );
1561
1656
  return resolveViewHref(topic);
@@ -1646,7 +1741,7 @@ var fetchStaticPages = async (query) => {
1646
1741
  };
1647
1742
  var getStaticPagesCached = unstable_cache4(
1648
1743
  async (query) => withServerRequestContext(
1649
- { skipCookieTokenLookup: true },
1744
+ { skipUserSession: true },
1650
1745
  () => fetchStaticPages(query)
1651
1746
  ),
1652
1747
  ["read-model", "static-pages-v1"],
@@ -1664,8 +1759,7 @@ var getCurrentUserAuthToken = async () => {
1664
1759
  try {
1665
1760
  const config = new CrexSDK2().getServerConfig();
1666
1761
  if (config.OIDC.tokenSource !== TOKEN_SOURCES.USER_LOGIN) return void 0;
1667
- const token = (await cookies2()).get(CREX_TOKEN_HEADER_KEY)?.value.trim();
1668
- return token || void 0;
1762
+ return (await getAccessToken())?.token || void 0;
1669
1763
  } catch {
1670
1764
  return void 0;
1671
1765
  }
@@ -1674,7 +1768,7 @@ var getStaticPages = async (query) => {
1674
1768
  try {
1675
1769
  const authToken = await getCurrentUserAuthToken();
1676
1770
  const pages = authToken ? await withServerRequestContext(
1677
- { skipCookieTokenLookup: true, authToken },
1771
+ { skipUserSession: true, authToken },
1678
1772
  () => fetchStaticPages(query)
1679
1773
  ) : await getStaticPagesCached(query);
1680
1774
  return { status: "ok", pages };