@c-rex/services 0.1.18 → 0.1.20
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/{client-requests.d.mts → generated/client-requests.d.mts} +11 -7
- package/dist/{client-requests.d.ts → generated/client-requests.d.ts} +11 -7
- package/dist/{client-requests.js → generated/client-requests.js} +90 -80
- package/dist/generated/client-requests.js.map +1 -0
- package/dist/{client-requests.mjs → generated/client-requests.mjs} +88 -80
- package/dist/generated/client-requests.mjs.map +1 -0
- package/dist/{server-requests.d.mts → generated/server-requests.d.mts} +11 -7
- package/dist/{server-requests.d.ts → generated/server-requests.d.ts} +11 -7
- package/dist/{server-requests.js → generated/server-requests.js} +103 -81
- package/dist/generated/server-requests.js.map +1 -0
- package/dist/{server-requests.mjs → generated/server-requests.mjs} +101 -81
- package/dist/generated/server-requests.mjs.map +1 -0
- package/dist/index.d.mts +44 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.js +3268 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2905 -0
- package/dist/index.mjs.map +1 -0
- package/dist/read-models/index.d.mts +244 -0
- package/dist/read-models/index.d.ts +244 -0
- package/dist/read-models/index.js +1268 -0
- package/dist/read-models/index.js.map +1 -0
- package/dist/read-models/index.mjs +1226 -0
- package/dist/read-models/index.mjs.map +1 -0
- package/dist/vcard/index.d.mts +102 -0
- package/dist/vcard/index.d.ts +102 -0
- package/dist/vcard/index.js +561 -0
- package/dist/vcard/index.js.map +1 -0
- package/dist/vcard/index.mjs +522 -0
- package/dist/vcard/index.mjs.map +1 -0
- package/package.json +69 -49
- package/dist/client-requests.js.map +0 -1
- package/dist/client-requests.mjs.map +0 -1
- package/dist/server-requests.js.map +0 -1
- package/dist/server-requests.mjs.map +0 -1
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { VCardInfoModel, ConfigInterface, VCardImageModel, OrganizationsGetByIdQueryParams, OrganizationsGetAllQueryParams, IndividualsGetByIdQueryParams, IndividualsGetAllQueryParams, VCardsGetByIdQueryParams, VCardsGetAllQueryParams } from '@c-rex/interfaces';
|
|
2
|
+
|
|
3
|
+
type ContactEntry = {
|
|
4
|
+
label: string;
|
|
5
|
+
value: string;
|
|
6
|
+
href?: string;
|
|
7
|
+
};
|
|
8
|
+
type BaseVCardProfile = {
|
|
9
|
+
id?: string;
|
|
10
|
+
displayName: string;
|
|
11
|
+
logoSrc: string;
|
|
12
|
+
addressLines: string[];
|
|
13
|
+
email?: string;
|
|
14
|
+
telephoneEntries: ContactEntry[];
|
|
15
|
+
website?: string;
|
|
16
|
+
};
|
|
17
|
+
type ResolvedSocialLink = {
|
|
18
|
+
label: string;
|
|
19
|
+
href: string;
|
|
20
|
+
provider: string;
|
|
21
|
+
};
|
|
22
|
+
type VCardEntityLike = {
|
|
23
|
+
id?: string | null;
|
|
24
|
+
fullName?: string | null;
|
|
25
|
+
organizationName?: string | null;
|
|
26
|
+
logos?: VCardImageModel[] | null;
|
|
27
|
+
photos?: VCardImageModel[] | null;
|
|
28
|
+
emails?: VCardInfoModel[] | null;
|
|
29
|
+
telephones?: VCardInfoModel[] | null;
|
|
30
|
+
addresses?: VCardInfoModel[] | null;
|
|
31
|
+
urls?: VCardInfoModel[] | null;
|
|
32
|
+
};
|
|
33
|
+
declare const DEFAULT_LOGO_SRC = "/img/logo.png";
|
|
34
|
+
declare const resolveLogoSource: (images?: VCardImageModel[]) => string | undefined;
|
|
35
|
+
declare const normalizeHref: (value?: string | null) => string | undefined;
|
|
36
|
+
declare const resolveSocialProviderLabel: (href: string) => string;
|
|
37
|
+
declare const resolveTypedSocialLinks: (urls?: VCardInfoModel[]) => ResolvedSocialLink[];
|
|
38
|
+
declare const normalizeEmail: (value?: string | null) => string | undefined;
|
|
39
|
+
declare const buildTelephoneEntries: (telephones: VCardInfoModel[] | undefined, uiLanguage: string) => ContactEntry[];
|
|
40
|
+
declare const resolveUiLanguage: () => string;
|
|
41
|
+
declare const mapVCardEntityToBaseProfile: (entity: VCardEntityLike, options: {
|
|
42
|
+
uiLanguage: string;
|
|
43
|
+
displayNameFallback: string;
|
|
44
|
+
logoFallbackSrc?: string;
|
|
45
|
+
}) => BaseVCardProfile;
|
|
46
|
+
declare const decodeEncodedVcardId: (encodedId: string) => string | undefined;
|
|
47
|
+
declare const getServerConfig: () => ConfigInterface;
|
|
48
|
+
|
|
49
|
+
type OrganizationProfile = {
|
|
50
|
+
id?: string;
|
|
51
|
+
displayName: string;
|
|
52
|
+
organizationName: string;
|
|
53
|
+
logoSrc: string;
|
|
54
|
+
addressLines: string[];
|
|
55
|
+
email?: string;
|
|
56
|
+
telephoneEntries: ContactEntry[];
|
|
57
|
+
website?: string;
|
|
58
|
+
socialLinks: Array<{
|
|
59
|
+
label: string;
|
|
60
|
+
href: string;
|
|
61
|
+
}>;
|
|
62
|
+
};
|
|
63
|
+
declare const getOrganizationProfileById: (id: string, query?: Partial<OrganizationsGetByIdQueryParams>) => Promise<OrganizationProfile>;
|
|
64
|
+
declare const getOrganizationsProfiles: (query?: Partial<OrganizationsGetAllQueryParams>) => Promise<OrganizationProfile[]>;
|
|
65
|
+
/**
|
|
66
|
+
* Resolves organization profile data (VCARD + configured fallbacks) for shared branding.
|
|
67
|
+
*/
|
|
68
|
+
declare const getOrganizationProfile: () => Promise<OrganizationProfile>;
|
|
69
|
+
/**
|
|
70
|
+
* Convenience projection for places that only need logo + organization title.
|
|
71
|
+
*/
|
|
72
|
+
declare const getOrganizationBranding: () => Promise<Pick<OrganizationProfile, "logoSrc" | "organizationName">>;
|
|
73
|
+
|
|
74
|
+
type IndividualProfile = {
|
|
75
|
+
id?: string;
|
|
76
|
+
displayName: string;
|
|
77
|
+
fullName: string;
|
|
78
|
+
logoSrc: string;
|
|
79
|
+
addressLines: string[];
|
|
80
|
+
email?: string;
|
|
81
|
+
telephoneEntries: ContactEntry[];
|
|
82
|
+
website?: string;
|
|
83
|
+
title?: string;
|
|
84
|
+
role?: string;
|
|
85
|
+
};
|
|
86
|
+
declare const getIndividualProfileById: (id: string, query?: Partial<IndividualsGetByIdQueryParams>) => Promise<IndividualProfile>;
|
|
87
|
+
declare const getIndividualsProfiles: (query?: Partial<IndividualsGetAllQueryParams>) => Promise<IndividualProfile[]>;
|
|
88
|
+
|
|
89
|
+
type VCardProfile = {
|
|
90
|
+
id?: string;
|
|
91
|
+
displayName: string;
|
|
92
|
+
fullName: string;
|
|
93
|
+
logoSrc: string;
|
|
94
|
+
addressLines: string[];
|
|
95
|
+
email?: string;
|
|
96
|
+
telephoneEntries: ContactEntry[];
|
|
97
|
+
website?: string;
|
|
98
|
+
};
|
|
99
|
+
declare const getVCardProfileById: (id: string, query?: Partial<VCardsGetByIdQueryParams>) => Promise<VCardProfile>;
|
|
100
|
+
declare const getVCardProfiles: (query?: Partial<VCardsGetAllQueryParams>) => Promise<VCardProfile[]>;
|
|
101
|
+
|
|
102
|
+
export { type BaseVCardProfile, type ContactEntry, DEFAULT_LOGO_SRC, type IndividualProfile, type OrganizationProfile, type ResolvedSocialLink, type VCardProfile, buildTelephoneEntries, decodeEncodedVcardId, getIndividualProfileById, getIndividualsProfiles, getOrganizationBranding, getOrganizationProfile, getOrganizationProfileById, getOrganizationsProfiles, getServerConfig, getVCardProfileById, getVCardProfiles, mapVCardEntityToBaseProfile, normalizeEmail, normalizeHref, resolveLogoSource, resolveSocialProviderLabel, resolveTypedSocialLinks, resolveUiLanguage };
|
|
@@ -0,0 +1,561 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/vcard/index.ts
|
|
21
|
+
var vcard_exports = {};
|
|
22
|
+
__export(vcard_exports, {
|
|
23
|
+
DEFAULT_LOGO_SRC: () => DEFAULT_LOGO_SRC,
|
|
24
|
+
buildTelephoneEntries: () => buildTelephoneEntries,
|
|
25
|
+
decodeEncodedVcardId: () => decodeEncodedVcardId,
|
|
26
|
+
getIndividualProfileById: () => getIndividualProfileById,
|
|
27
|
+
getIndividualsProfiles: () => getIndividualsProfiles,
|
|
28
|
+
getOrganizationBranding: () => getOrganizationBranding,
|
|
29
|
+
getOrganizationProfile: () => getOrganizationProfile,
|
|
30
|
+
getOrganizationProfileById: () => getOrganizationProfileById,
|
|
31
|
+
getOrganizationsProfiles: () => getOrganizationsProfiles,
|
|
32
|
+
getServerConfig: () => getServerConfig,
|
|
33
|
+
getVCardProfileById: () => getVCardProfileById,
|
|
34
|
+
getVCardProfiles: () => getVCardProfiles,
|
|
35
|
+
mapVCardEntityToBaseProfile: () => mapVCardEntityToBaseProfile,
|
|
36
|
+
normalizeEmail: () => normalizeEmail,
|
|
37
|
+
normalizeHref: () => normalizeHref,
|
|
38
|
+
resolveLogoSource: () => resolveLogoSource,
|
|
39
|
+
resolveSocialProviderLabel: () => resolveSocialProviderLabel,
|
|
40
|
+
resolveTypedSocialLinks: () => resolveTypedSocialLinks,
|
|
41
|
+
resolveUiLanguage: () => resolveUiLanguage
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(vcard_exports);
|
|
44
|
+
|
|
45
|
+
// src/vcard/profile-utils.ts
|
|
46
|
+
var import_sdk = require("@c-rex/core/sdk");
|
|
47
|
+
var import_constants = require("@c-rex/constants");
|
|
48
|
+
var import_headers = require("next/headers");
|
|
49
|
+
var DEFAULT_LOGO_SRC = "/img/logo.png";
|
|
50
|
+
var normalizePathLikeImageSource = (value) => {
|
|
51
|
+
if (!value) return void 0;
|
|
52
|
+
const trimmed = value.trim();
|
|
53
|
+
if (!trimmed) return void 0;
|
|
54
|
+
if (trimmed.startsWith("data:") || trimmed.startsWith("http://") || trimmed.startsWith("https://") || trimmed.startsWith("/")) {
|
|
55
|
+
return trimmed;
|
|
56
|
+
}
|
|
57
|
+
return `/${trimmed}`;
|
|
58
|
+
};
|
|
59
|
+
var resolveLogoSource = (images = []) => {
|
|
60
|
+
const sourceFirst = images.map((image) => normalizePathLikeImageSource(image.source)).find((value) => Boolean(value));
|
|
61
|
+
if (!sourceFirst) {
|
|
62
|
+
console.warn("[VCardProfile] No usable VCARD image source found. Ignoring 'value' until IDS provides absolute resource URLs.");
|
|
63
|
+
}
|
|
64
|
+
return sourceFirst;
|
|
65
|
+
};
|
|
66
|
+
var normalizeHref = (value) => {
|
|
67
|
+
if (!value) return void 0;
|
|
68
|
+
const trimmed = value.trim();
|
|
69
|
+
if (!trimmed) return void 0;
|
|
70
|
+
if (trimmed.startsWith("http://") || trimmed.startsWith("https://") || trimmed.startsWith("mailto:") || trimmed.startsWith("tel:")) {
|
|
71
|
+
return trimmed;
|
|
72
|
+
}
|
|
73
|
+
return `https://${trimmed}`;
|
|
74
|
+
};
|
|
75
|
+
var SOCIAL_MEDIA_TYPE_URI = "https://www.c-rex.net/ns/iirds/vcard#SocialMedia";
|
|
76
|
+
var SOCIAL_MEDIA_TYPE_URI_NORMALIZED = SOCIAL_MEDIA_TYPE_URI.toLowerCase();
|
|
77
|
+
var isSocialMediaType = (value) => {
|
|
78
|
+
if (!value) return false;
|
|
79
|
+
const normalized = value.trim().toLowerCase();
|
|
80
|
+
return normalized === SOCIAL_MEDIA_TYPE_URI_NORMALIZED || normalized.endsWith("#socialmedia");
|
|
81
|
+
};
|
|
82
|
+
var isSocialMediaUrlEntry = (url) => {
|
|
83
|
+
const hasTypedMarker = Array.isArray(url.types) && url.types.some((type) => isSocialMediaType(type));
|
|
84
|
+
if (hasTypedMarker) return true;
|
|
85
|
+
const hasClassMarker = Array.isArray(url.classes) && url.classes.some((cls) => isSocialMediaType(cls?.id));
|
|
86
|
+
if (hasClassMarker) return true;
|
|
87
|
+
const hasClassLabelMarker = Array.isArray(url.classes) && url.classes.some(
|
|
88
|
+
(cls) => (cls?.labels || []).some((label) => (label.value || "").trim().toLowerCase() === "social media")
|
|
89
|
+
);
|
|
90
|
+
return hasClassLabelMarker;
|
|
91
|
+
};
|
|
92
|
+
var SOCIAL_PROVIDER_BY_HOST = [
|
|
93
|
+
{ hostPattern: /(^|\.)x\.com$/i, label: "X" },
|
|
94
|
+
{ hostPattern: /(^|\.)twitter\.com$/i, label: "Twitter" },
|
|
95
|
+
{ hostPattern: /(^|\.)facebook\.com$/i, label: "Facebook" },
|
|
96
|
+
{ hostPattern: /(^|\.)instagram\.com$/i, label: "Instagram" },
|
|
97
|
+
{ hostPattern: /(^|\.)youtube\.com$/i, label: "YouTube" },
|
|
98
|
+
{ hostPattern: /(^|\.)youtu\.be$/i, label: "YouTube" },
|
|
99
|
+
{ hostPattern: /(^|\.)linkedin\.com$/i, label: "LinkedIn" },
|
|
100
|
+
{ hostPattern: /(^|\.)xing\.com$/i, label: "Xing" }
|
|
101
|
+
];
|
|
102
|
+
var resolveSocialProviderLabel = (href) => {
|
|
103
|
+
try {
|
|
104
|
+
const hostname = new URL(href).hostname.toLowerCase();
|
|
105
|
+
const provider = SOCIAL_PROVIDER_BY_HOST.find((entry) => entry.hostPattern.test(hostname));
|
|
106
|
+
return provider?.label || hostname.replace(/^www\./i, "");
|
|
107
|
+
} catch {
|
|
108
|
+
return "Social";
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
var isKnownSocialProviderHref = (href) => {
|
|
112
|
+
try {
|
|
113
|
+
const hostname = new URL(href).hostname.toLowerCase();
|
|
114
|
+
return SOCIAL_PROVIDER_BY_HOST.some((entry) => entry.hostPattern.test(hostname));
|
|
115
|
+
} catch {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
var resolveTypedSocialLinks = (urls = []) => {
|
|
120
|
+
const items = urls.filter((url) => {
|
|
121
|
+
if (isSocialMediaUrlEntry(url)) return true;
|
|
122
|
+
const href = normalizeHref(url.value);
|
|
123
|
+
return Boolean(href && isKnownSocialProviderHref(href));
|
|
124
|
+
}).map((url) => normalizeHref(url.value)).filter((value) => Boolean(value));
|
|
125
|
+
const byHref = /* @__PURE__ */ new Map();
|
|
126
|
+
items.forEach((href) => {
|
|
127
|
+
if (byHref.has(href)) return;
|
|
128
|
+
const label = resolveSocialProviderLabel(href);
|
|
129
|
+
byHref.set(href, {
|
|
130
|
+
href,
|
|
131
|
+
label,
|
|
132
|
+
provider: label
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
return Array.from(byHref.values());
|
|
136
|
+
};
|
|
137
|
+
var normalizePhone = (value) => {
|
|
138
|
+
if (!value) return void 0;
|
|
139
|
+
return value.replace(/^tel:/i, "").trim() || void 0;
|
|
140
|
+
};
|
|
141
|
+
var isDialablePhone = (value) => {
|
|
142
|
+
if (!value) return false;
|
|
143
|
+
const normalized = value.trim();
|
|
144
|
+
if (!normalized) return false;
|
|
145
|
+
if (!/\d/.test(normalized)) return false;
|
|
146
|
+
return /^[+\d()[\]\-./\s]+$/.test(normalized);
|
|
147
|
+
};
|
|
148
|
+
var normalizePhoneHref = (value) => {
|
|
149
|
+
if (!value) return void 0;
|
|
150
|
+
const normalizedPhone = normalizePhone(value);
|
|
151
|
+
if (!normalizedPhone || !isDialablePhone(normalizedPhone)) return void 0;
|
|
152
|
+
return `tel:${normalizedPhone}`;
|
|
153
|
+
};
|
|
154
|
+
var normalizeEmail = (value) => {
|
|
155
|
+
if (!value) return void 0;
|
|
156
|
+
return value.replace(/^mailto:/i, "").trim() || void 0;
|
|
157
|
+
};
|
|
158
|
+
var normalizeLanguage = (value) => {
|
|
159
|
+
return (value || "").trim().toLowerCase().replace("_", "-");
|
|
160
|
+
};
|
|
161
|
+
var getLiteralLanguage = (literal) => {
|
|
162
|
+
const language = literal.language || literal["xml:lang"] || "";
|
|
163
|
+
return normalizeLanguage(language);
|
|
164
|
+
};
|
|
165
|
+
var getLocalizedLiteral = (labels = [], uiLanguage) => {
|
|
166
|
+
const normalizedUiLanguage = normalizeLanguage(uiLanguage);
|
|
167
|
+
const normalizedUiBaseLanguage = normalizedUiLanguage.split("-")[0];
|
|
168
|
+
const exact = labels.find((item) => getLiteralLanguage(item) === normalizedUiLanguage)?.value?.trim();
|
|
169
|
+
if (exact) return exact;
|
|
170
|
+
const base = labels.find((item) => getLiteralLanguage(item).startsWith(`${normalizedUiBaseLanguage}`))?.value?.trim();
|
|
171
|
+
if (base) return base;
|
|
172
|
+
const fallback = labels.find((item) => (item.value || "").trim().length > 0)?.value?.trim();
|
|
173
|
+
return fallback || void 0;
|
|
174
|
+
};
|
|
175
|
+
var buildTelephoneEntries = (telephones = [], uiLanguage) => {
|
|
176
|
+
return telephones.reduce((entries, telephone) => {
|
|
177
|
+
const normalizedValue = normalizePhone(telephone.value);
|
|
178
|
+
if (!normalizedValue) return entries;
|
|
179
|
+
const classLabels = (telephone.classes || []).map((cls) => getLocalizedLiteral(cls.labels || [], uiLanguage)).filter((value) => Boolean(value));
|
|
180
|
+
const dedupedClassLabels = Array.from(
|
|
181
|
+
new Map(classLabels.map((value) => [value.toLowerCase(), value])).values()
|
|
182
|
+
);
|
|
183
|
+
entries.push({
|
|
184
|
+
label: dedupedClassLabels.length > 0 ? dedupedClassLabels.join(" ") : "",
|
|
185
|
+
value: normalizedValue,
|
|
186
|
+
href: normalizePhoneHref(telephone.value)
|
|
187
|
+
});
|
|
188
|
+
return entries;
|
|
189
|
+
}, []);
|
|
190
|
+
};
|
|
191
|
+
var resolveUiLanguage = () => {
|
|
192
|
+
const sdk = new import_sdk.CrexSDK();
|
|
193
|
+
const clientConfig = sdk.getClientConfig();
|
|
194
|
+
const defaultLanguage = normalizeLanguage(clientConfig.languageSwitcher.default || "en-us");
|
|
195
|
+
const uiLanguageFromCookie = (0, import_headers.cookies)().get(import_constants.UI_LANG_KEY)?.value;
|
|
196
|
+
return normalizeLanguage(uiLanguageFromCookie) || defaultLanguage;
|
|
197
|
+
};
|
|
198
|
+
var buildAddressLines = (address) => {
|
|
199
|
+
if (!address) return [];
|
|
200
|
+
const line1 = [address.streetAddress].filter(Boolean).join(" ").trim();
|
|
201
|
+
const line2 = [address.postalCode, address.locality].filter(Boolean).join(" ").trim();
|
|
202
|
+
const line3 = [address.countryName].filter(Boolean).join(" ").trim();
|
|
203
|
+
return [line1, line2, line3].filter((line) => line.length > 0);
|
|
204
|
+
};
|
|
205
|
+
var mapVCardEntityToBaseProfile = (entity, options) => {
|
|
206
|
+
const preferredAddress = entity.addresses?.[0];
|
|
207
|
+
const preferredEmail = entity.emails?.[0];
|
|
208
|
+
const preferredWebsite = entity.urls?.find((item) => normalizeHref(item.value));
|
|
209
|
+
const logoSrc = resolveLogoSource([...entity.logos || [], ...entity.photos || []]) || (options.logoFallbackSrc || DEFAULT_LOGO_SRC);
|
|
210
|
+
return {
|
|
211
|
+
id: entity.id || void 0,
|
|
212
|
+
displayName: entity.organizationName?.trim() || entity.fullName?.trim() || options.displayNameFallback,
|
|
213
|
+
logoSrc,
|
|
214
|
+
addressLines: buildAddressLines(preferredAddress),
|
|
215
|
+
email: normalizeEmail(preferredEmail?.value),
|
|
216
|
+
telephoneEntries: buildTelephoneEntries(entity.telephones || [], options.uiLanguage),
|
|
217
|
+
website: normalizeHref(preferredWebsite?.value)
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
var decodeEncodedVcardId = (encodedId) => {
|
|
221
|
+
try {
|
|
222
|
+
return decodeURIComponent(encodedId);
|
|
223
|
+
} catch (error) {
|
|
224
|
+
console.error(`[VCardProfile] Invalid encoded VCARD ID value: "${encodedId}".`, error);
|
|
225
|
+
return void 0;
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
var getServerConfig = () => {
|
|
229
|
+
const sdk = new import_sdk.CrexSDK();
|
|
230
|
+
return sdk.getServerConfig();
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
// src/vcard/organization-profile.ts
|
|
234
|
+
var import_requests2 = require("@c-rex/core/requests");
|
|
235
|
+
var import_cache = require("next/cache");
|
|
236
|
+
|
|
237
|
+
// src/base-server-request.ts
|
|
238
|
+
var import_requests = require("@c-rex/core/requests");
|
|
239
|
+
|
|
240
|
+
// src/server-request-context.ts
|
|
241
|
+
var import_node_async_hooks = require("async_hooks");
|
|
242
|
+
var requestContextStorage = new import_node_async_hooks.AsyncLocalStorage();
|
|
243
|
+
var withServerRequestContext = async (context, run) => {
|
|
244
|
+
return requestContextStorage.run(context, run);
|
|
245
|
+
};
|
|
246
|
+
var getServerRequestContext = () => {
|
|
247
|
+
return requestContextStorage.getStore();
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
// src/base-server-request.ts
|
|
251
|
+
var baseServerRequest = async (endpoint, query) => {
|
|
252
|
+
const api = new import_requests.CrexApi();
|
|
253
|
+
const requestContext = getServerRequestContext();
|
|
254
|
+
const response = await api.execute({
|
|
255
|
+
url: endpoint,
|
|
256
|
+
method: "GET",
|
|
257
|
+
params: query,
|
|
258
|
+
skipCookieTokenLookup: requestContext?.skipCookieTokenLookup,
|
|
259
|
+
authToken: requestContext?.authToken
|
|
260
|
+
});
|
|
261
|
+
return response;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
// src/generated/server-requests.ts
|
|
265
|
+
var individualsGetAllServer = async (query) => {
|
|
266
|
+
return baseServerRequest("vcard/v1/Individuals", query);
|
|
267
|
+
};
|
|
268
|
+
var individualsGetByIdServer = async (params, query) => {
|
|
269
|
+
return baseServerRequest(`vcard/v1/Individuals/${encodeURIComponent(String(params.id))}`, query);
|
|
270
|
+
};
|
|
271
|
+
var organizationsGetAllServer = async (query) => {
|
|
272
|
+
return baseServerRequest("vcard/v1/Organizations", query);
|
|
273
|
+
};
|
|
274
|
+
var organizationsGetByIdServer = async (params, query) => {
|
|
275
|
+
return baseServerRequest(`vcard/v1/Organizations/${encodeURIComponent(String(params.id))}`, query);
|
|
276
|
+
};
|
|
277
|
+
var vCardsGetAllServer = async (query) => {
|
|
278
|
+
return baseServerRequest("vcard/v1/VCards", query);
|
|
279
|
+
};
|
|
280
|
+
var vCardsGetByIdServer = async (params, query) => {
|
|
281
|
+
return baseServerRequest(`vcard/v1/VCards/${encodeURIComponent(String(params.id))}`, query);
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
// src/read-models/cache-policy.ts
|
|
285
|
+
var readPositiveInt = (rawValue, fallback) => {
|
|
286
|
+
const parsed = Number(rawValue);
|
|
287
|
+
if (!Number.isFinite(parsed) || parsed <= 0) return fallback;
|
|
288
|
+
return Math.floor(parsed);
|
|
289
|
+
};
|
|
290
|
+
var READMODEL_CACHE_POLICY = {
|
|
291
|
+
metadataRevalidateSeconds: readPositiveInt(
|
|
292
|
+
process.env.CREX_CACHE_REVALIDATE_METADATA_SECONDS,
|
|
293
|
+
2 * 60 * 60
|
|
294
|
+
),
|
|
295
|
+
vcardRevalidateSeconds: readPositiveInt(
|
|
296
|
+
process.env.CREX_CACHE_REVALIDATE_VCARD_SECONDS,
|
|
297
|
+
6 * 60 * 60
|
|
298
|
+
),
|
|
299
|
+
requestsRevalidateSeconds: readPositiveInt(
|
|
300
|
+
process.env.CREX_CACHE_REVALIDATE_REQUESTS_SECONDS,
|
|
301
|
+
15 * 60
|
|
302
|
+
)
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
// src/vcard/organization-profile.ts
|
|
306
|
+
var toOrganizationProfile = (organization, options) => {
|
|
307
|
+
const base = mapVCardEntityToBaseProfile(organization, {
|
|
308
|
+
uiLanguage: options.uiLanguage,
|
|
309
|
+
displayNameFallback: options.displayNameFallback,
|
|
310
|
+
logoFallbackSrc: options.logoFallbackSrc
|
|
311
|
+
});
|
|
312
|
+
return {
|
|
313
|
+
...base,
|
|
314
|
+
organizationName: base.displayName,
|
|
315
|
+
socialLinks: resolveTypedSocialLinks(organization.urls || []).map((item) => ({
|
|
316
|
+
label: item.label,
|
|
317
|
+
href: item.href
|
|
318
|
+
}))
|
|
319
|
+
};
|
|
320
|
+
};
|
|
321
|
+
var ORGANIZATION_PROFILE_REQUIRED_FIELDS = [
|
|
322
|
+
"organizationName",
|
|
323
|
+
"fullName",
|
|
324
|
+
"logos",
|
|
325
|
+
"photos",
|
|
326
|
+
"emails",
|
|
327
|
+
"telephones",
|
|
328
|
+
"addresses",
|
|
329
|
+
"urls"
|
|
330
|
+
];
|
|
331
|
+
var resolveOrganizationProfileQuery = (query) => {
|
|
332
|
+
if (!query) return void 0;
|
|
333
|
+
if (!Array.isArray(query.Fields) || query.Fields.length === 0) return query;
|
|
334
|
+
const mergedFields = Array.from(/* @__PURE__ */ new Set([...query.Fields, ...ORGANIZATION_PROFILE_REQUIRED_FIELDS]));
|
|
335
|
+
return {
|
|
336
|
+
...query,
|
|
337
|
+
Fields: mergedFields
|
|
338
|
+
};
|
|
339
|
+
};
|
|
340
|
+
var fetchOrganizationProfileById = async (id, query, context) => {
|
|
341
|
+
try {
|
|
342
|
+
const organization = await organizationsGetByIdServer({ id }, resolveOrganizationProfileQuery(query));
|
|
343
|
+
return toOrganizationProfile(organization, {
|
|
344
|
+
uiLanguage: context.uiLanguage,
|
|
345
|
+
displayNameFallback: context.fallbackName,
|
|
346
|
+
logoFallbackSrc: context.logoFallbackSrc
|
|
347
|
+
});
|
|
348
|
+
} catch (error) {
|
|
349
|
+
console.error(`[OrganizationProfile] Failed to load VCARD organization "${id}".`, error);
|
|
350
|
+
return {
|
|
351
|
+
id,
|
|
352
|
+
logoSrc: context.logoFallbackSrc,
|
|
353
|
+
displayName: context.fallbackName,
|
|
354
|
+
organizationName: context.fallbackName,
|
|
355
|
+
addressLines: [],
|
|
356
|
+
telephoneEntries: [],
|
|
357
|
+
socialLinks: []
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
var getOrganizationProfileById = async (id, query) => {
|
|
362
|
+
const serverConfig = getServerConfig();
|
|
363
|
+
const uiLanguage = resolveUiLanguage();
|
|
364
|
+
const fallbackName = serverConfig.projectName;
|
|
365
|
+
const logoFallbackSrc = serverConfig.organization?.logoFallbackSrc || DEFAULT_LOGO_SRC;
|
|
366
|
+
return fetchOrganizationProfileById(id, query, {
|
|
367
|
+
uiLanguage,
|
|
368
|
+
fallbackName,
|
|
369
|
+
logoFallbackSrc
|
|
370
|
+
});
|
|
371
|
+
};
|
|
372
|
+
var getOrganizationProfileByIdCached = (0, import_cache.unstable_cache)(
|
|
373
|
+
async (id, query, context) => withServerRequestContext(
|
|
374
|
+
{ skipCookieTokenLookup: true },
|
|
375
|
+
() => fetchOrganizationProfileById(id, query, context)
|
|
376
|
+
),
|
|
377
|
+
["read-model", "organization-profile-v2"],
|
|
378
|
+
{
|
|
379
|
+
revalidate: READMODEL_CACHE_POLICY.vcardRevalidateSeconds,
|
|
380
|
+
tags: [
|
|
381
|
+
import_requests2.CREX_API_CACHE_TAG,
|
|
382
|
+
import_requests2.CREX_API_CACHE_VCARD_TAG,
|
|
383
|
+
import_requests2.CREX_READMODEL_CACHE_TAG,
|
|
384
|
+
import_requests2.CREX_READMODEL_CACHE_VCARD_TAG,
|
|
385
|
+
import_requests2.CREX_READMODEL_CACHE_ORGANIZATION_TAG
|
|
386
|
+
]
|
|
387
|
+
}
|
|
388
|
+
);
|
|
389
|
+
var getOrganizationsProfiles = async (query) => {
|
|
390
|
+
const serverConfig = getServerConfig();
|
|
391
|
+
const uiLanguage = resolveUiLanguage();
|
|
392
|
+
const fallbackName = serverConfig.projectName;
|
|
393
|
+
const logoFallbackSrc = serverConfig.organization?.logoFallbackSrc || DEFAULT_LOGO_SRC;
|
|
394
|
+
const result = await organizationsGetAllServer(query);
|
|
395
|
+
return result.items.map(
|
|
396
|
+
(organization) => toOrganizationProfile(organization, {
|
|
397
|
+
uiLanguage,
|
|
398
|
+
displayNameFallback: fallbackName,
|
|
399
|
+
logoFallbackSrc
|
|
400
|
+
})
|
|
401
|
+
);
|
|
402
|
+
};
|
|
403
|
+
var getOrganizationProfile = async () => {
|
|
404
|
+
const serverConfig = getServerConfig();
|
|
405
|
+
const rawVcardId = process.env.CREX_ORGANIZATION_VCARD_ID?.trim();
|
|
406
|
+
const encodedVcardId = process.env.CREX_ORGANIZATION_VCARD_ID_ENCODED?.trim();
|
|
407
|
+
const decodedEncodedVcardId = encodedVcardId ? decodeEncodedVcardId(encodedVcardId) : void 0;
|
|
408
|
+
const configuredVcardId = rawVcardId || decodedEncodedVcardId || serverConfig.organization?.vcardId?.trim();
|
|
409
|
+
if (!configuredVcardId) {
|
|
410
|
+
console.info("[OrganizationProfile] No VCARD organization ID configured. Using fallback branding.");
|
|
411
|
+
const logoFallbackSrc2 = serverConfig.organization?.logoFallbackSrc || DEFAULT_LOGO_SRC;
|
|
412
|
+
const fallbackName2 = serverConfig.projectName;
|
|
413
|
+
return {
|
|
414
|
+
logoSrc: logoFallbackSrc2,
|
|
415
|
+
displayName: fallbackName2,
|
|
416
|
+
organizationName: fallbackName2,
|
|
417
|
+
addressLines: [],
|
|
418
|
+
telephoneEntries: [],
|
|
419
|
+
socialLinks: []
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
if (rawVcardId && rawVcardId.startsWith("http") && !rawVcardId.includes("#")) {
|
|
423
|
+
console.warn(
|
|
424
|
+
`[OrganizationProfile] VCARD ID does not contain "#": "${rawVcardId}". If this value comes from .env, wrap it in quotes or use CREX_ORGANIZATION_VCARD_ID_ENCODED.`
|
|
425
|
+
);
|
|
426
|
+
}
|
|
427
|
+
const uiLanguage = resolveUiLanguage();
|
|
428
|
+
const fallbackName = serverConfig.projectName;
|
|
429
|
+
const logoFallbackSrc = serverConfig.organization?.logoFallbackSrc || DEFAULT_LOGO_SRC;
|
|
430
|
+
const context = {
|
|
431
|
+
uiLanguage,
|
|
432
|
+
fallbackName,
|
|
433
|
+
logoFallbackSrc
|
|
434
|
+
};
|
|
435
|
+
if (process.env.NODE_ENV === "test") {
|
|
436
|
+
return fetchOrganizationProfileById(configuredVcardId, void 0, context);
|
|
437
|
+
}
|
|
438
|
+
return getOrganizationProfileByIdCached(configuredVcardId, void 0, context);
|
|
439
|
+
};
|
|
440
|
+
var getOrganizationBranding = async () => {
|
|
441
|
+
const profile = await getOrganizationProfile();
|
|
442
|
+
return {
|
|
443
|
+
logoSrc: profile.logoSrc,
|
|
444
|
+
organizationName: profile.organizationName
|
|
445
|
+
};
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
// src/vcard/individual-profile.ts
|
|
449
|
+
var toIndividualProfile = (individual, options) => {
|
|
450
|
+
const base = mapVCardEntityToBaseProfile(individual, {
|
|
451
|
+
uiLanguage: options.uiLanguage,
|
|
452
|
+
displayNameFallback: options.displayNameFallback,
|
|
453
|
+
logoFallbackSrc: options.logoFallbackSrc
|
|
454
|
+
});
|
|
455
|
+
return {
|
|
456
|
+
...base,
|
|
457
|
+
fullName: base.displayName,
|
|
458
|
+
title: individual.title?.trim() || void 0,
|
|
459
|
+
role: individual.role?.trim() || void 0
|
|
460
|
+
};
|
|
461
|
+
};
|
|
462
|
+
var getIndividualProfileById = async (id, query) => {
|
|
463
|
+
const uiLanguage = resolveUiLanguage();
|
|
464
|
+
try {
|
|
465
|
+
const individual = await individualsGetByIdServer({ id }, query);
|
|
466
|
+
return toIndividualProfile(individual, {
|
|
467
|
+
uiLanguage,
|
|
468
|
+
displayNameFallback: id,
|
|
469
|
+
logoFallbackSrc: DEFAULT_LOGO_SRC
|
|
470
|
+
});
|
|
471
|
+
} catch (error) {
|
|
472
|
+
console.error(`[IndividualProfile] Failed to load VCARD individual "${id}".`, error);
|
|
473
|
+
return {
|
|
474
|
+
id,
|
|
475
|
+
logoSrc: DEFAULT_LOGO_SRC,
|
|
476
|
+
displayName: id,
|
|
477
|
+
fullName: id,
|
|
478
|
+
addressLines: [],
|
|
479
|
+
telephoneEntries: []
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
var getIndividualsProfiles = async (query) => {
|
|
484
|
+
const uiLanguage = resolveUiLanguage();
|
|
485
|
+
const result = await individualsGetAllServer(query);
|
|
486
|
+
return result.items.map(
|
|
487
|
+
(individual) => toIndividualProfile(individual, {
|
|
488
|
+
uiLanguage,
|
|
489
|
+
displayNameFallback: individual.id || "Unknown individual",
|
|
490
|
+
logoFallbackSrc: DEFAULT_LOGO_SRC
|
|
491
|
+
})
|
|
492
|
+
);
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
// src/vcard/vcard-profile.ts
|
|
496
|
+
var toVCardProfile = (vcard, options) => {
|
|
497
|
+
const base = mapVCardEntityToBaseProfile(vcard, {
|
|
498
|
+
uiLanguage: options.uiLanguage,
|
|
499
|
+
displayNameFallback: options.displayNameFallback,
|
|
500
|
+
logoFallbackSrc: options.logoFallbackSrc
|
|
501
|
+
});
|
|
502
|
+
return {
|
|
503
|
+
...base,
|
|
504
|
+
fullName: base.displayName
|
|
505
|
+
};
|
|
506
|
+
};
|
|
507
|
+
var getVCardProfileById = async (id, query) => {
|
|
508
|
+
const uiLanguage = resolveUiLanguage();
|
|
509
|
+
try {
|
|
510
|
+
const vcard = await vCardsGetByIdServer({ id }, query);
|
|
511
|
+
return toVCardProfile(vcard, {
|
|
512
|
+
uiLanguage,
|
|
513
|
+
displayNameFallback: id,
|
|
514
|
+
logoFallbackSrc: DEFAULT_LOGO_SRC
|
|
515
|
+
});
|
|
516
|
+
} catch (error) {
|
|
517
|
+
console.error(`[VCardProfile] Failed to load VCARD "${id}".`, error);
|
|
518
|
+
return {
|
|
519
|
+
id,
|
|
520
|
+
logoSrc: DEFAULT_LOGO_SRC,
|
|
521
|
+
displayName: id,
|
|
522
|
+
fullName: id,
|
|
523
|
+
addressLines: [],
|
|
524
|
+
telephoneEntries: []
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
var getVCardProfiles = async (query) => {
|
|
529
|
+
const uiLanguage = resolveUiLanguage();
|
|
530
|
+
const result = await vCardsGetAllServer(query);
|
|
531
|
+
return result.items.map(
|
|
532
|
+
(vcard) => toVCardProfile(vcard, {
|
|
533
|
+
uiLanguage,
|
|
534
|
+
displayNameFallback: vcard.id || "Unknown vCard",
|
|
535
|
+
logoFallbackSrc: DEFAULT_LOGO_SRC
|
|
536
|
+
})
|
|
537
|
+
);
|
|
538
|
+
};
|
|
539
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
540
|
+
0 && (module.exports = {
|
|
541
|
+
DEFAULT_LOGO_SRC,
|
|
542
|
+
buildTelephoneEntries,
|
|
543
|
+
decodeEncodedVcardId,
|
|
544
|
+
getIndividualProfileById,
|
|
545
|
+
getIndividualsProfiles,
|
|
546
|
+
getOrganizationBranding,
|
|
547
|
+
getOrganizationProfile,
|
|
548
|
+
getOrganizationProfileById,
|
|
549
|
+
getOrganizationsProfiles,
|
|
550
|
+
getServerConfig,
|
|
551
|
+
getVCardProfileById,
|
|
552
|
+
getVCardProfiles,
|
|
553
|
+
mapVCardEntityToBaseProfile,
|
|
554
|
+
normalizeEmail,
|
|
555
|
+
normalizeHref,
|
|
556
|
+
resolveLogoSource,
|
|
557
|
+
resolveSocialProviderLabel,
|
|
558
|
+
resolveTypedSocialLinks,
|
|
559
|
+
resolveUiLanguage
|
|
560
|
+
});
|
|
561
|
+
//# sourceMappingURL=index.js.map
|