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

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.
package/dist/index.js CHANGED
@@ -418,7 +418,7 @@ var baseServerRequest = async (endpoint, query) => {
418
418
  url: endpoint,
419
419
  method: "GET",
420
420
  params: (0, import_requests.withGlobalRestriction)(query),
421
- skipCookieTokenLookup: requestContext?.skipCookieTokenLookup,
421
+ skipUserSession: requestContext?.skipUserSession,
422
422
  authToken: requestContext?.authToken
423
423
  });
424
424
  return response;
@@ -1672,7 +1672,7 @@ var getOrganizationProfileById = async (id, query) => {
1672
1672
  };
1673
1673
  var getOrganizationProfileByIdCached = (0, import_cache.unstable_cache)(
1674
1674
  async (id, query, context) => withServerRequestContext(
1675
- { skipCookieTokenLookup: true },
1675
+ { skipUserSession: true },
1676
1676
  () => fetchOrganizationProfileById(id, query, context)
1677
1677
  ),
1678
1678
  ["read-model", "organization-profile-v2"],
@@ -1961,11 +1961,15 @@ var resolveLocalizedLabel = (labels, uiLanguage) => {
1961
1961
  language: (item.language || "").trim().toLowerCase(),
1962
1962
  value: (item.value || "").trim()
1963
1963
  })).filter((item) => item.value.length > 0);
1964
- const exact = normalized.find((item) => item.language === normalizedUiLanguage)?.value;
1964
+ const exact = normalized.find(
1965
+ (item) => item.language === normalizedUiLanguage
1966
+ )?.value;
1965
1967
  if (exact) return exact;
1966
1968
  const base = normalized.find((item) => item.language === baseLanguage)?.value;
1967
1969
  if (base) return base;
1968
- const english = normalized.find((item) => item.language === "en" || item.language === "en-us")?.value;
1970
+ const english = normalized.find(
1971
+ (item) => item.language === "en" || item.language === "en-us"
1972
+ )?.value;
1969
1973
  if (english) return english;
1970
1974
  return normalized[0]?.value;
1971
1975
  };
@@ -2024,24 +2028,39 @@ var isNotFoundError = (error) => {
2024
2028
  return error.message.includes("HTTP error! status: 404");
2025
2029
  };
2026
2030
  var resolveMissingClassLabels = async (items, uiLanguage) => {
2027
- const classIds = Array.from(new Set(
2028
- 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))
2029
- ));
2031
+ const classIds = Array.from(
2032
+ new Set(
2033
+ items.map((item) => item.class?.id?.trim()).filter((id) => Boolean(id)).filter(
2034
+ (id) => !resolveLocalizedLabel(
2035
+ items.find((item) => item.class?.id?.trim() === id)?.class?.labels || [],
2036
+ uiLanguage
2037
+ )
2038
+ )
2039
+ )
2040
+ );
2030
2041
  const result = {};
2031
- await Promise.all(classIds.map(async (classId) => {
2032
- try {
2033
- const entity = await withServerRequestContext(
2034
- { skipCookieTokenLookup: true },
2035
- () => domainEntitiesGetByIdServer({ id: classId }, { Fields: ["labels"] })
2036
- );
2037
- result[classId] = resolveLocalizedLabel(entity.labels || [], uiLanguage);
2038
- } catch (error) {
2039
- if (!isNotFoundError(error)) {
2040
- throw error;
2042
+ await Promise.all(
2043
+ classIds.map(async (classId) => {
2044
+ try {
2045
+ const entity = await withServerRequestContext(
2046
+ { skipUserSession: true },
2047
+ () => domainEntitiesGetByIdServer(
2048
+ { id: classId },
2049
+ { Fields: ["labels"] }
2050
+ )
2051
+ );
2052
+ result[classId] = resolveLocalizedLabel(
2053
+ entity.labels || [],
2054
+ uiLanguage
2055
+ );
2056
+ } catch (error) {
2057
+ if (!isNotFoundError(error)) {
2058
+ throw error;
2059
+ }
2060
+ result[classId] = void 0;
2041
2061
  }
2042
- result[classId] = void 0;
2043
- }
2044
- }));
2062
+ })
2063
+ );
2045
2064
  return result;
2046
2065
  };
2047
2066
  var deriveParentIds = (entity) => {
@@ -2060,14 +2079,23 @@ var buildTaxonomyTree = (items, options) => {
2060
2079
  if (!entityRef) continue;
2061
2080
  nodesById[entityRef.id] = {
2062
2081
  ...entityRef,
2063
- classRef: toClassRef(item.class, options.uiLanguage, options.classLabelsById),
2082
+ classRef: toClassRef(
2083
+ item.class,
2084
+ options.uiLanguage,
2085
+ options.classLabelsById
2086
+ ),
2064
2087
  parentIds: deriveParentIds(item)
2065
2088
  };
2066
2089
  }
2067
2090
  Object.values(nodesById).forEach((node) => {
2068
- parentLinks.set(node.id, node.parentIds.filter((id) => Boolean(nodesById[id])));
2091
+ parentLinks.set(
2092
+ node.id,
2093
+ node.parentIds.filter((id) => Boolean(nodesById[id]))
2094
+ );
2069
2095
  });
2070
- const roots = Object.values(nodesById).filter((node) => (parentLinks.get(node.id) || []).length === 0);
2096
+ const roots = Object.values(nodesById).filter(
2097
+ (node) => (parentLinks.get(node.id) || []).length === 0
2098
+ );
2071
2099
  if (!options.groupRootsByClass) {
2072
2100
  return {
2073
2101
  roots: roots.sort((a, b) => a.label.localeCompare(b.label)),
@@ -2112,10 +2140,13 @@ var createTaxonomyResolver = (options) => {
2112
2140
  const cached = (0, import_cache2.unstable_cache)(
2113
2141
  async (_queryKey, query, uiLanguage) => {
2114
2142
  const items = await withServerRequestContext(
2115
- { skipCookieTokenLookup: true },
2143
+ { skipUserSession: true },
2116
2144
  () => fetchAllPages(options.fetch, query)
2117
2145
  );
2118
- const classLabelsById = await resolveMissingClassLabels(items, uiLanguage);
2146
+ const classLabelsById = await resolveMissingClassLabels(
2147
+ items,
2148
+ uiLanguage
2149
+ );
2119
2150
  const result = buildTaxonomyTree(items, {
2120
2151
  ...defaultTreeOptions(uiLanguage),
2121
2152
  classLabelsById
@@ -2123,8 +2154,16 @@ var createTaxonomyResolver = (options) => {
2123
2154
  const bytes = measureSerializedBytes(result);
2124
2155
  const limitBytes = resolveMetadataCacheMaxBytes();
2125
2156
  if (bytes > limitBytes) {
2126
- suppressMetadataCacheFamilyRuntime(options.cacheFamily, { bytes, limitBytes });
2127
- await logCacheOverflow(options.cacheFamily, bytes, limitBytes, options.cacheKey);
2157
+ suppressMetadataCacheFamilyRuntime(options.cacheFamily, {
2158
+ bytes,
2159
+ limitBytes
2160
+ });
2161
+ await logCacheOverflow(
2162
+ options.cacheFamily,
2163
+ bytes,
2164
+ limitBytes,
2165
+ options.cacheKey
2166
+ );
2128
2167
  return {
2129
2168
  roots: [],
2130
2169
  nodesById: {},
@@ -2147,7 +2186,10 @@ var createTaxonomyResolver = (options) => {
2147
2186
  );
2148
2187
  return async (query) => {
2149
2188
  const uiLanguage = await resolveUiLanguage();
2150
- const normalizedQuery = { ...options.defaultQuery, ...query || {} };
2189
+ const normalizedQuery = {
2190
+ ...options.defaultQuery,
2191
+ ...query || {}
2192
+ };
2151
2193
  const cacheKey = stableSerialize({ normalizedQuery, uiLanguage });
2152
2194
  return cached(cacheKey, normalizedQuery, uiLanguage);
2153
2195
  };
@@ -2282,8 +2324,11 @@ var mergeRoleRef = (current, candidate) => {
2282
2324
  var getPartiesCached = (0, import_cache2.unstable_cache)(
2283
2325
  async (_queryKey, query, uiLanguage) => {
2284
2326
  const items = await withServerRequestContext(
2285
- { skipCookieTokenLookup: true },
2286
- () => fetchAllPages(partiesGetAllServer, query)
2327
+ { skipUserSession: true },
2328
+ () => fetchAllPages(
2329
+ partiesGetAllServer,
2330
+ query
2331
+ )
2287
2332
  );
2288
2333
  const groups = /* @__PURE__ */ new Map();
2289
2334
  items.forEach((party) => {
@@ -2321,7 +2366,12 @@ var getPartiesCached = (0, import_cache2.unstable_cache)(
2321
2366
  ["read-model", "parties"],
2322
2367
  {
2323
2368
  revalidate: READMODEL_CACHE_POLICY.metadataRevalidateSeconds,
2324
- tags: [import_requests3.CREX_API_CACHE_TAG, import_requests3.CREX_READMODEL_CACHE_TAG, import_requests3.CREX_READMODEL_CACHE_METADATA_TAG, import_requests3.CREX_READMODEL_CACHE_PARTIES_TAG]
2369
+ tags: [
2370
+ import_requests3.CREX_API_CACHE_TAG,
2371
+ import_requests3.CREX_READMODEL_CACHE_TAG,
2372
+ import_requests3.CREX_READMODEL_CACHE_METADATA_TAG,
2373
+ import_requests3.CREX_READMODEL_CACHE_PARTIES_TAG
2374
+ ]
2325
2375
  }
2326
2376
  );
2327
2377
  var getInformationSubjects = async () => {
@@ -2334,7 +2384,10 @@ var getInformationSubjects = async () => {
2334
2384
  return categories;
2335
2385
  }
2336
2386
  } catch (error) {
2337
- console.warn("[MetadataReadModels] Categories endpoint unavailable, falling back to InformationSubjects.", error);
2387
+ console.warn(
2388
+ "[MetadataReadModels] Categories endpoint unavailable, falling back to InformationSubjects.",
2389
+ error
2390
+ );
2338
2391
  }
2339
2392
  return getInformationSubjectsLegacyCached();
2340
2393
  };
@@ -2352,7 +2405,11 @@ var getParties = async () => {
2352
2405
  Fields: ["labels", "partyRole", "vcard", "class"],
2353
2406
  Sort: ["shortId"]
2354
2407
  };
2355
- return getPartiesCached(stableSerialize({ query, uiLanguage }), query, uiLanguage);
2408
+ return getPartiesCached(
2409
+ stableSerialize({ query, uiLanguage }),
2410
+ query,
2411
+ uiLanguage
2412
+ );
2356
2413
  };
2357
2414
  var getTopicTypes = async (query) => {
2358
2415
  return getTopicTypesCached(query);
@@ -2700,11 +2757,15 @@ var resolveLocalizedLabel2 = (labels, uiLanguage) => {
2700
2757
  language: (item.language || "").toLowerCase(),
2701
2758
  value: item.value || ""
2702
2759
  })).filter((item) => item.value.length > 0);
2703
- const exact = normalized.find((item) => item.language === normalizedLanguage)?.value;
2760
+ const exact = normalized.find(
2761
+ (item) => item.language === normalizedLanguage
2762
+ )?.value;
2704
2763
  if (exact) return exact;
2705
2764
  const base = normalized.find((item) => item.language === baseLanguage)?.value;
2706
2765
  if (base) return base;
2707
- const english = normalized.find((item) => item.language === "en" || item.language === "en-us")?.value;
2766
+ const english = normalized.find(
2767
+ (item) => item.language === "en" || item.language === "en-us"
2768
+ )?.value;
2708
2769
  if (english) return english;
2709
2770
  return normalized[0]?.value;
2710
2771
  };
@@ -2720,7 +2781,7 @@ var getDomainEntitySectionLabelUncached = async (id, uiLanguage) => {
2720
2781
  };
2721
2782
  try {
2722
2783
  const entity = await withServerRequestContext(
2723
- { skipCookieTokenLookup: true },
2784
+ { skipUserSession: true },
2724
2785
  () => domainEntitiesGetByIdServer({ id }, query)
2725
2786
  );
2726
2787
  return resolveLocalizedLabel2(entity.labels || [], uiLanguage);
@@ -2736,7 +2797,11 @@ var getDomainEntitySectionLabelCached = (0, import_cache3.unstable_cache)(
2736
2797
  ["metadata-presentation-domain-entity-label"],
2737
2798
  {
2738
2799
  revalidate: READMODEL_CACHE_POLICY.metadataRevalidateSeconds,
2739
- tags: [import_requests4.CREX_API_CACHE_TAG, import_requests4.CREX_READMODEL_CACHE_TAG, import_requests4.CREX_READMODEL_CACHE_METADATA_TAG]
2800
+ tags: [
2801
+ import_requests4.CREX_API_CACHE_TAG,
2802
+ import_requests4.CREX_READMODEL_CACHE_TAG,
2803
+ import_requests4.CREX_READMODEL_CACHE_METADATA_TAG
2804
+ ]
2740
2805
  }
2741
2806
  );
2742
2807
  var inFlightDomainEntityLabelRequests = /* @__PURE__ */ new Map();
@@ -2744,15 +2809,23 @@ var getDomainEntitySectionLabel = async (id, uiLanguage) => {
2744
2809
  const inFlightKey = `${id}::${uiLanguage.toLowerCase()}`;
2745
2810
  const existing = inFlightDomainEntityLabelRequests.get(inFlightKey);
2746
2811
  if (existing) return existing;
2747
- const promise = getDomainEntitySectionLabelCached(id, uiLanguage).finally(() => {
2748
- inFlightDomainEntityLabelRequests.delete(inFlightKey);
2749
- });
2812
+ const promise = getDomainEntitySectionLabelCached(id, uiLanguage).finally(
2813
+ () => {
2814
+ inFlightDomainEntityLabelRequests.delete(inFlightKey);
2815
+ }
2816
+ );
2750
2817
  inFlightDomainEntityLabelRequests.set(inFlightKey, promise);
2751
2818
  return promise;
2752
2819
  };
2753
2820
  var getMetadataFacetPresentation = async (properties, uiLanguage = "en-US", options) => {
2754
- const defaultProperties = Object.keys(INFORMATION_UNIT_PROPERTY_PRESENTATION).filter((property) => INFORMATION_UNIT_PROPERTY_PRESENTATION[property].facet.supported);
2755
- const propertySet = new Set(properties && properties.length > 0 ? properties : defaultProperties);
2821
+ const defaultProperties = Object.keys(
2822
+ INFORMATION_UNIT_PROPERTY_PRESENTATION
2823
+ ).filter(
2824
+ (property) => INFORMATION_UNIT_PROPERTY_PRESENTATION[property].facet.supported
2825
+ );
2826
+ const propertySet = new Set(
2827
+ properties && properties.length > 0 ? properties : defaultProperties
2828
+ );
2756
2829
  const result = {};
2757
2830
  const classResolvers = {
2758
2831
  components: getComponents,
@@ -2786,7 +2859,9 @@ var getMetadataFacetPresentation = async (properties, uiLanguage = "en-US", opti
2786
2859
  const parties = await getParties();
2787
2860
  const partyPresentation = {};
2788
2861
  parties.groups.forEach((group) => {
2789
- const hidden = isMetadataGroupDenied("parties", { partyRoleId: group.role.id });
2862
+ const hidden = isMetadataGroupDenied("parties", {
2863
+ partyRoleId: group.role.id
2864
+ });
2790
2865
  const sectionLabel = group.role.label;
2791
2866
  group.parties.forEach((party) => {
2792
2867
  if (!party.shortId) return;
@@ -2820,15 +2895,27 @@ var getMetadataFacetPresentation = async (properties, uiLanguage = "en-US", opti
2820
2895
  if (property === "topicTypes" || property === "contentLifeCycleStatus") {
2821
2896
  const domainEntityId = property === "topicTypes" ? TOPIC_TYPE_DOMAIN_ENTITY_ID : CONTENT_LIFECYCLE_STATUS_DOMAIN_ENTITY_ID;
2822
2897
  const sectionLabel = await getDomainEntitySectionLabel(domainEntityId, uiLanguage) || resolveUnknownSectionLabel(property, uiLanguage);
2823
- const presentation = createClassSectionPresentation(property, taxonomy.nodesById, uiLanguage);
2898
+ const presentation = createClassSectionPresentation(
2899
+ property,
2900
+ taxonomy.nodesById,
2901
+ uiLanguage
2902
+ );
2824
2903
  Object.values(presentation).forEach((entry) => {
2825
2904
  entry.sectionLabel = sectionLabel;
2826
2905
  });
2827
2906
  result[property] = presentation;
2828
2907
  return;
2829
2908
  }
2830
- const classLabelsById = await resolveMissingClassLabels2(taxonomy.nodesById, uiLanguage);
2831
- result[property] = createClassSectionPresentation(property, taxonomy.nodesById, uiLanguage, { classLabelsById });
2909
+ const classLabelsById = await resolveMissingClassLabels2(
2910
+ taxonomy.nodesById,
2911
+ uiLanguage
2912
+ );
2913
+ result[property] = createClassSectionPresentation(
2914
+ property,
2915
+ taxonomy.nodesById,
2916
+ uiLanguage,
2917
+ { classLabelsById }
2918
+ );
2832
2919
  })()
2833
2920
  );
2834
2921
  }
@@ -3102,7 +3189,7 @@ var normalizeVersionItems = (items, uiLanguage) => {
3102
3189
  var getAvailableLanguagesByVersionOfCached = (0, import_cache4.unstable_cache)(
3103
3190
  async (_cacheKey, query, uiLanguage) => {
3104
3191
  const result = await withServerRequestContext(
3105
- { skipCookieTokenLookup: true },
3192
+ { skipUserSession: true },
3106
3193
  () => informationUnitsGetAllServer(query)
3107
3194
  );
3108
3195
  return normalizeVersionItems(result.items || [], uiLanguage);
@@ -3110,12 +3197,16 @@ var getAvailableLanguagesByVersionOfCached = (0, import_cache4.unstable_cache)(
3110
3197
  ["read-model", "version-availability"],
3111
3198
  {
3112
3199
  revalidate: READMODEL_CACHE_POLICY.metadataRevalidateSeconds,
3113
- tags: [import_requests5.CREX_API_CACHE_TAG, import_requests5.CREX_READMODEL_CACHE_TAG, import_requests5.CREX_READMODEL_CACHE_METADATA_TAG]
3200
+ tags: [
3201
+ import_requests5.CREX_API_CACHE_TAG,
3202
+ import_requests5.CREX_READMODEL_CACHE_TAG,
3203
+ import_requests5.CREX_READMODEL_CACHE_METADATA_TAG
3204
+ ]
3114
3205
  }
3115
3206
  );
3116
3207
  var fetchAvailableLanguagesByVersionOfDirect = async (query, uiLanguage) => {
3117
3208
  const result = await withServerRequestContext(
3118
- { skipCookieTokenLookup: true },
3209
+ { skipUserSession: true },
3119
3210
  () => informationUnitsGetAllServer(query)
3120
3211
  );
3121
3212
  return normalizeVersionItems(result.items || [], uiLanguage);
@@ -3224,7 +3315,7 @@ var import_cache5 = require("next/cache");
3224
3315
  var import_requests6 = require("@c-rex/core/requests");
3225
3316
  var import_logger2 = require("@c-rex/core/logger");
3226
3317
  var import_constants2 = require("@c-rex/constants");
3227
- var import_headers2 = require("next/headers");
3318
+ var import_server = require("@c-rex/core/auth/server");
3228
3319
  var import_sdk2 = require("@c-rex/core/sdk");
3229
3320
  var DEFAULT_SORT = ["-informationSubjects.id"];
3230
3321
  var DEFAULT_PAGE_SIZE = 100;
@@ -3258,7 +3349,7 @@ var findStaticPageBySlug = (pages, slug) => pages.find(
3258
3349
  var resolveStaticPageResourceHref = async (shortId) => {
3259
3350
  try {
3260
3351
  const topic = await withServerRequestContext(
3261
- { skipCookieTokenLookup: true },
3352
+ { skipUserSession: true },
3262
3353
  () => topicsGetByIdServer({ id: shortId }, { Fields: ["renditions"] })
3263
3354
  );
3264
3355
  return resolveViewHref(topic);
@@ -3349,7 +3440,7 @@ var fetchStaticPages = async (query) => {
3349
3440
  };
3350
3441
  var getStaticPagesCached = (0, import_cache5.unstable_cache)(
3351
3442
  async (query) => withServerRequestContext(
3352
- { skipCookieTokenLookup: true },
3443
+ { skipUserSession: true },
3353
3444
  () => fetchStaticPages(query)
3354
3445
  ),
3355
3446
  ["read-model", "static-pages-v1"],
@@ -3367,8 +3458,7 @@ var getCurrentUserAuthToken = async () => {
3367
3458
  try {
3368
3459
  const config = new import_sdk2.CrexSDK().getServerConfig();
3369
3460
  if (config.OIDC.tokenSource !== import_constants2.TOKEN_SOURCES.USER_LOGIN) return void 0;
3370
- const token = (await (0, import_headers2.cookies)()).get(import_constants2.CREX_TOKEN_HEADER_KEY)?.value.trim();
3371
- return token || void 0;
3461
+ return (await (0, import_server.getAccessToken)())?.token || void 0;
3372
3462
  } catch {
3373
3463
  return void 0;
3374
3464
  }
@@ -3377,7 +3467,7 @@ var getStaticPages = async (query) => {
3377
3467
  try {
3378
3468
  const authToken = await getCurrentUserAuthToken();
3379
3469
  const pages = authToken ? await withServerRequestContext(
3380
- { skipCookieTokenLookup: true, authToken },
3470
+ { skipUserSession: true, authToken },
3381
3471
  () => fetchStaticPages(query)
3382
3472
  ) : await getStaticPagesCached(query);
3383
3473
  return { status: "ok", pages };