@websolutespa/bom-core 2.0.1-next.0 → 2.0.1

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.mjs ADDED
@@ -0,0 +1,1807 @@
1
+ // src/utils/arrayShuffle.ts
2
+ function arrayShuffle(items) {
3
+ return items.map((item) => ({ item, order: Math.random() })).sort((a, b) => a.order - b.order).map(({ item }) => item);
4
+ }
5
+
6
+ // src/utils/typeGuards.ts
7
+ function isNumber(item) {
8
+ return typeof item === "number";
9
+ }
10
+ function isString(item) {
11
+ return typeof item === "string";
12
+ }
13
+ function isValidString(item) {
14
+ return typeof item === "string" && item.length > 0;
15
+ }
16
+ function isArray(item) {
17
+ return Array.isArray(item);
18
+ }
19
+ function isNonEmptyArray(item) {
20
+ return Array.isArray(item) && item.length > 0;
21
+ }
22
+ function isObject(item) {
23
+ return item != null && typeof item === "object" && !isArray(item);
24
+ }
25
+ function isPromise(result) {
26
+ return isObject(result) && typeof result.then === "function";
27
+ }
28
+ function isNotNullString(item) {
29
+ return typeof item === "string" && Boolean(item);
30
+ }
31
+ function isEquatable(item) {
32
+ return typeof item === "number" || isNotNullString(item);
33
+ }
34
+ function isEntity(item) {
35
+ return isObject(item) && isEquatable(item.id);
36
+ }
37
+ function isComponent(item) {
38
+ return isObject(item) && (isValidString(item.blockType) || isValidString(item.schema));
39
+ }
40
+ function hasComponents(item) {
41
+ return isObject(item) && "components" in item && Array.isArray(item.components) && item.components.length > 0;
42
+ }
43
+ function isUnresolvedRelation(item) {
44
+ return isObject(item) && isNotNullString(item.relationTo) && (isEquatable(item.value) || isArray(item.value));
45
+ }
46
+ function isRelation(item) {
47
+ return isObject(item) && isNotNullString(item.relationTo) && isEntity(item.value);
48
+ }
49
+ function isUnresolvedCategory(category) {
50
+ return category ? typeof category === "string" : false;
51
+ }
52
+ function isUndecoratedCategory(category) {
53
+ return isObject(category) && !category.href;
54
+ }
55
+ function isUndecoratedMenuItem(item) {
56
+ return isObject(item) && (item.type === "category" && isEquatable(item.category) || item.type === "page" && isEquatable(item.page.value));
57
+ }
58
+ function isUndecoratedMenuCategory(item) {
59
+ return isObject(item) && item.type === "category" && isNotNullString(item.category) && item.id === void 0 && item.href === void 0;
60
+ }
61
+ function isUndecoratedMenuPage(item) {
62
+ return isObject(item) && item.type === "page" && isObject(item.page) && isNotNullString(item.page.relationTo) && isEquatable(item.page.value);
63
+ }
64
+ function isUndecoratedNav(item) {
65
+ return isUndecoratedMenuPage(item);
66
+ }
67
+
68
+ // src/utils/asEquatable.ts
69
+ function asEquatable(value) {
70
+ const id = isEntity(value) ? value.id : value;
71
+ if (typeof id === "string") {
72
+ if (String(parseInt(id)) === id) {
73
+ return Number(id);
74
+ }
75
+ }
76
+ return id;
77
+ }
78
+ function asEquatableString(value) {
79
+ const id = isEntity(value) ? value.id : value;
80
+ if (typeof id !== "undefined") {
81
+ return String(id);
82
+ }
83
+ return id;
84
+ }
85
+ function asEquatableNumber(value) {
86
+ const id = isEntity(value) ? value.id : value;
87
+ if (typeof id === "string") {
88
+ if (String(parseInt(id)) === id) {
89
+ return Number(id);
90
+ } else {
91
+ return void 0;
92
+ }
93
+ }
94
+ return id;
95
+ }
96
+
97
+ // src/utils/asSortedOptions.ts
98
+ function asSortedOptions(items) {
99
+ items.sort((a, b) => {
100
+ const nameA = a.name.toLowerCase();
101
+ const nameB = b.name.toLowerCase();
102
+ return nameA < nameB ? -1 : nameA > nameB ? 1 : 0;
103
+ });
104
+ return items;
105
+ }
106
+
107
+ // src/utils/babelCase.ts
108
+ function unknownCaseToPascalCase(unknownCase) {
109
+ const pascalCase = unknownCase.replace(
110
+ /(^[a-zA-Z])|(\W|_)+(\w?)([a-z0-9]*)?/g,
111
+ (m, g1, g2, g3, g4) => (g1 ? g1.toUpperCase() : "") + (g3 ? g3.toUpperCase() : "") + (g4 ? g4.toLowerCase() : "")
112
+ );
113
+ return pascalCase;
114
+ }
115
+ function pascalCaseToCamelCase(pascalCase) {
116
+ const camelCase = pascalCase.charAt(0).toLowerCase() + pascalCase.slice(1);
117
+ return camelCase;
118
+ }
119
+ function pascalCaseToCharCase(pascalCase, char = "-") {
120
+ const charCase = pascalCase.replace(
121
+ /([A-Z]+)/g,
122
+ (m, g1, index) => (index > 0 ? char : "") + m
123
+ ).toLowerCase();
124
+ return charCase;
125
+ }
126
+ function pascalCaseToKebabCase(pascalCase) {
127
+ const kebabCase = pascalCaseToCharCase(pascalCase, "-");
128
+ return kebabCase;
129
+ }
130
+ function pascalCaseToSnakeCase(pascalCase) {
131
+ const kebabCase = pascalCaseToCharCase(pascalCase, "_");
132
+ return kebabCase;
133
+ }
134
+ function toPascalCase(unknownCase) {
135
+ const pascalCase = unknownCaseToPascalCase(unknownCase);
136
+ return pascalCase;
137
+ }
138
+ function toCamelCase(unknownCase) {
139
+ const pascalCase = unknownCaseToPascalCase(unknownCase);
140
+ const camelCase = pascalCaseToCamelCase(pascalCase);
141
+ return camelCase;
142
+ }
143
+ function toCharCase(unknownCase, char = "-") {
144
+ const pascalCase = unknownCaseToPascalCase(unknownCase);
145
+ const charCase = pascalCaseToCharCase(pascalCase, char);
146
+ return charCase;
147
+ }
148
+ function toKebabCase(unknownCase) {
149
+ const kebabCase = toCharCase(unknownCase, "-");
150
+ return kebabCase;
151
+ }
152
+ function toSnakeCase(unknownCase) {
153
+ const snakeCase = toCharCase(unknownCase, "_");
154
+ return snakeCase;
155
+ }
156
+
157
+ // src/utils/cloneItem.ts
158
+ function cloneItem(item) {
159
+ if (isArray(item)) {
160
+ item = item.map((x) => cloneItem(x));
161
+ } else if (isObject(item)) {
162
+ item = { ...item };
163
+ const object = item;
164
+ Object.keys(object).forEach((key) => {
165
+ object[key] = cloneItem(object[key]);
166
+ });
167
+ }
168
+ return item;
169
+ }
170
+
171
+ // src/utils/collectFeatureTypes.ts
172
+ async function collectFeatureTypes(items, ...keys) {
173
+ const featureTypes = [];
174
+ if (keys.length > 0) {
175
+ items.forEach((item) => {
176
+ keys.forEach((key) => {
177
+ const value = item[key] || [];
178
+ const values = Array.isArray(value) ? value : [value];
179
+ values.forEach((value2) => {
180
+ let featureType = featureTypes.find((x) => x.id === key);
181
+ if (!featureType) {
182
+ featureType = {
183
+ id: key,
184
+ schema: "featureType",
185
+ title: key,
186
+ mode: "or",
187
+ features: []
188
+ };
189
+ featureTypes.push(featureType);
190
+ }
191
+ const features = featureType.features;
192
+ const option = isObject(value2) ? {
193
+ ...value2,
194
+ title: value2.title || value2.name || value2.label || "Untitled"
195
+ } : {
196
+ id: value2,
197
+ title: String(value2)
198
+ };
199
+ if (option.id && option.title && features && !features.find((x) => x.id === option.id)) {
200
+ features.push(option);
201
+ }
202
+ });
203
+ });
204
+ });
205
+ }
206
+ featureTypes.forEach((featureType) => {
207
+ featureType.features.sort((a, b) => {
208
+ const textA = a.title.toUpperCase();
209
+ const textB = b.title.toUpperCase();
210
+ return textA < textB ? -1 : textA > textB ? 1 : 0;
211
+ });
212
+ });
213
+ return featureTypes;
214
+ }
215
+ async function collectFeatureTypes__(items, ...keys) {
216
+ const featureTypes = [];
217
+ if (keys.length > 0) {
218
+ items.forEach((item) => {
219
+ keys.forEach((key) => {
220
+ const value = item[key];
221
+ if (value) {
222
+ let featureType = featureTypes.find((x) => x.id === key);
223
+ if (!featureType) {
224
+ featureType = {
225
+ id: key,
226
+ schema: "featureType",
227
+ title: key,
228
+ mode: "or",
229
+ features: []
230
+ };
231
+ featureTypes.push(featureType);
232
+ }
233
+ const features = featureType.features;
234
+ if (features && !features.find((x) => x.id === value)) {
235
+ features.push({
236
+ id: value,
237
+ title: String(value)
238
+ });
239
+ }
240
+ }
241
+ });
242
+ });
243
+ }
244
+ return featureTypes;
245
+ }
246
+
247
+ // src/utils/collectOptions.ts
248
+ async function collectOptions(items, ...keys) {
249
+ const optionsGroup = {};
250
+ if (keys.length > 0) {
251
+ items.forEach((item) => {
252
+ keys.forEach((key) => {
253
+ const value = item[key];
254
+ if (value) {
255
+ let options = optionsGroup[key];
256
+ if (!options) {
257
+ options = [];
258
+ optionsGroup[key] = options;
259
+ }
260
+ if (!options.find((x) => x.id === value)) {
261
+ options.push({
262
+ id: value,
263
+ name: String(value)
264
+ });
265
+ }
266
+ }
267
+ });
268
+ });
269
+ }
270
+ return optionsGroup;
271
+ }
272
+
273
+ // src/utils/uuid.ts
274
+ function uuidv4() {
275
+ return "10000000-1000-4000-8000-100000000000".replace(
276
+ /[018]/g,
277
+ (c) => (+c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> +c / 4).toString(16)
278
+ );
279
+ }
280
+
281
+ // src/utils/components.ts
282
+ function isComponentOfType(item, ...blockTypes) {
283
+ return isComponent(item) && blockTypes.includes(item.blockType || item.schema || "");
284
+ }
285
+ function pickComponent(items, ...blockTypes) {
286
+ return items?.filter((x) => isComponentOfType(x, ...blockTypes));
287
+ }
288
+ function excludeComponent(items, ...blockTypes) {
289
+ return items?.filter((x) => !isComponentOfType(x, ...blockTypes));
290
+ }
291
+ function pickHero(items, blockTypes = ["hero"]) {
292
+ const heroComponents = pickComponent(items, ...blockTypes);
293
+ const otherComponents = excludeComponent(items, ...blockTypes);
294
+ return [heroComponents, otherComponents];
295
+ }
296
+ function prependHero(items, hero, blockType = "hero") {
297
+ const components = items || [];
298
+ const heroIndex = components.findIndex((x) => isComponentOfType(x, blockType));
299
+ if (heroIndex === -1) {
300
+ const component = typeof hero === "string" ? {
301
+ id: uuidv4(),
302
+ blockType: hero
303
+ } : hero;
304
+ components.unshift(component);
305
+ }
306
+ return components;
307
+ }
308
+ function groupComponents(items, blockTypes, blockType) {
309
+ const components = [];
310
+ let previousGroup;
311
+ let previousItem;
312
+ (items || []).forEach((item) => {
313
+ if (blockTypes.includes(item.blockType || item.schema || "unkown_type")) {
314
+ if (previousItem) {
315
+ if (previousGroup) {
316
+ previousGroup.components.push(item);
317
+ } else {
318
+ previousGroup = {
319
+ id: uuidv4(),
320
+ blockType,
321
+ components: [previousItem, item]
322
+ };
323
+ }
324
+ }
325
+ previousItem = item;
326
+ } else {
327
+ if (previousGroup) {
328
+ components.push(previousGroup);
329
+ } else if (previousItem) {
330
+ components.push(previousItem);
331
+ }
332
+ previousGroup = void 0;
333
+ previousItem = void 0;
334
+ components.push(item);
335
+ }
336
+ });
337
+ return components;
338
+ }
339
+
340
+ // src/utils/deepMerge.ts
341
+ function deepMerge(target, source) {
342
+ const output = { ...target };
343
+ if (isObject(target) && isObject(source)) {
344
+ Object.entries(source).forEach(([k, v]) => {
345
+ if (isArray(v)) {
346
+ output[k] = v.map((x) => deepMerge(x, x));
347
+ } else if (isObject(v)) {
348
+ const targetValue = k in target ? target[k] : void 0;
349
+ output[k] = isObject(targetValue) ? deepMerge(targetValue, v) : deepMerge(v, v);
350
+ } else {
351
+ output[k] = v;
352
+ }
353
+ });
354
+ }
355
+ return output;
356
+ }
357
+
358
+ // src/types/image.ts
359
+ var ImageStrategy = /* @__PURE__ */ ((ImageStrategy2) => {
360
+ ImageStrategy2["None"] = "none";
361
+ ImageStrategy2["Next"] = "next";
362
+ ImageStrategy2["Mixer"] = "mixer";
363
+ ImageStrategy2["Oven"] = "oven";
364
+ ImageStrategy2["Token"] = "token";
365
+ ImageStrategy2["Custom"] = "custom";
366
+ return ImageStrategy2;
367
+ })(ImageStrategy || {});
368
+
369
+ // src/types/media.ts
370
+ function resolveMediaType(media) {
371
+ if (typeof media.type === "string" && media.type.length > 0) {
372
+ return media.type;
373
+ }
374
+ if (typeof media.mimeType === "string" && media.mimeType.length > 0) {
375
+ const mime = media.mimeType.split("/");
376
+ return mime[0] === "application" ? mime[1] : mime[0];
377
+ }
378
+ return "unknown";
379
+ }
380
+ function isMediaImage(media) {
381
+ const type = resolveMediaType(media);
382
+ if (type === "image") {
383
+ media.type = type;
384
+ return true;
385
+ }
386
+ return false;
387
+ }
388
+ function isMediaVideo(media) {
389
+ const type = resolveMediaType(media);
390
+ if (type === "video") {
391
+ media.type = type;
392
+ return true;
393
+ }
394
+ return false;
395
+ }
396
+ function isMediaJson(media) {
397
+ const type = resolveMediaType(media);
398
+ if (type === "json") {
399
+ media.type = type;
400
+ return true;
401
+ }
402
+ return false;
403
+ }
404
+ function isMediaPdf(media) {
405
+ const type = resolveMediaType(media);
406
+ if (type === "pdf") {
407
+ media.type = type;
408
+ return true;
409
+ }
410
+ return false;
411
+ }
412
+ function isMedia(item) {
413
+ return isObject(item) && ("mimeType" in item || "type" in item) && (isValidString(item.url) || isValidString(item.src));
414
+ }
415
+
416
+ // src/types/menu.ts
417
+ function isMenuHref(item) {
418
+ return ["category", "link", "page", "route"].includes(item.type);
419
+ }
420
+ function isMenuCategory(item) {
421
+ return item.type === "category";
422
+ }
423
+ function isMenuGroup(item) {
424
+ return item.type === "group";
425
+ }
426
+ function isMenuLink(item) {
427
+ return item.type === "link";
428
+ }
429
+ function isMenuPage(item) {
430
+ return item.type === "page";
431
+ }
432
+ function isMenuRoute(item) {
433
+ return item.type === "route";
434
+ }
435
+ var MenuCategoryStrategy = /* @__PURE__ */ ((MenuCategoryStrategy2) => {
436
+ MenuCategoryStrategy2["Default"] = "default";
437
+ MenuCategoryStrategy2["ExcludeHidden"] = "exclude-hidden";
438
+ return MenuCategoryStrategy2;
439
+ })(MenuCategoryStrategy || {});
440
+
441
+ // src/types/querable.ts
442
+ function toFindParams(idOrParams) {
443
+ if (typeof idOrParams === "number" || typeof idOrParams === "string") {
444
+ return { where: { id: idOrParams } };
445
+ } else {
446
+ return idOrParams;
447
+ }
448
+ }
449
+
450
+ // src/types/redirect.ts
451
+ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
452
+ RedirectReason2["MovedPermanently"] = "301";
453
+ RedirectReason2["Found"] = "302";
454
+ RedirectReason2["TemporaryRedirect"] = "307";
455
+ RedirectReason2["PermanentRedirect"] = "308";
456
+ RedirectReason2["Gone"] = "410";
457
+ return RedirectReason2;
458
+ })(RedirectReason || {});
459
+
460
+ // src/utils/eachValue.ts
461
+ function eachValue(item, callback) {
462
+ if (isArray(item)) {
463
+ item.forEach((value) => {
464
+ callback(value);
465
+ eachValue(value, callback);
466
+ });
467
+ } else if (isObject(item)) {
468
+ Object.values(item).forEach((value) => {
469
+ callback(value);
470
+ eachValue(value, callback);
471
+ });
472
+ } else {
473
+ callback(item);
474
+ }
475
+ }
476
+
477
+ // src/utils/eachMedia.ts
478
+ function eachMedia(item, callback) {
479
+ eachValue(item, (value) => {
480
+ if (isMedia(value)) {
481
+ callback(value);
482
+ }
483
+ });
484
+ }
485
+
486
+ // src/utils/enumToList.ts
487
+ function enumToList(enumeration, separatorRegex = /_/g) {
488
+ const array = Object.keys(enumeration);
489
+ return array.filter((key) => isNaN(Number(key))).filter((key) => typeof enumeration[key] === "number" || typeof enumeration[key] === "string").map((key) => ({
490
+ key: String(key).replace(separatorRegex, " "),
491
+ value: enumeration[key]
492
+ }));
493
+ }
494
+
495
+ // src/utils/index.ts
496
+ function getIsDevelopment() {
497
+ return process && (!process.env.NODE_ENV || process.env.NODE_ENV === "development");
498
+ }
499
+ function getIsProduction() {
500
+ return process && process.env && String(process.env.PRODUCTION) === "true";
501
+ }
502
+ var isDevelopment = getIsDevelopment();
503
+ var isProduction = getIsProduction();
504
+ var isStage = !isProduction && !isDevelopment;
505
+ var isBrowser = typeof window !== "undefined";
506
+ function getEnv() {
507
+ const env = {};
508
+ const keys = Object.keys(process.env).sort();
509
+ keys.forEach((key) => {
510
+ env[key] = process.env[key];
511
+ });
512
+ return env;
513
+ }
514
+ function withSchema(component, schema) {
515
+ return Object.assign(component, schema);
516
+ }
517
+ function asServerProps(props) {
518
+ return JSON.parse(JSON.stringify(props));
519
+ }
520
+ async function awaitAll(array, callback) {
521
+ const promises = array.map(callback);
522
+ return await Promise.all(promises);
523
+ }
524
+ function merge(target, source) {
525
+ if (source === null) {
526
+ return source;
527
+ }
528
+ if (!target) {
529
+ if (source && typeof source === "object") {
530
+ return Object.assign({}, source);
531
+ } else {
532
+ return source;
533
+ }
534
+ }
535
+ if (source && typeof source === "object") {
536
+ Object.keys(source).forEach((key) => {
537
+ const value = source[key];
538
+ if (typeof value === "object" && !Array.isArray(value)) {
539
+ target[key] = merge(target[key], value);
540
+ } else {
541
+ target[key] = value;
542
+ }
543
+ });
544
+ }
545
+ return target;
546
+ }
547
+
548
+ // src/base64/base64.ts
549
+ function base64ToString(text) {
550
+ return isBrowser ? window.atob(text) : Buffer.from(text, "base64").toString();
551
+ }
552
+ function stringToBase64(text) {
553
+ return isBrowser ? window.btoa(text) : Buffer.from(text).toString("base64");
554
+ }
555
+
556
+ // src/category/category.ts
557
+ var ROOT_CATEGORY = process.env.ROOT_CATEGORY || "";
558
+ function getRootCategory(categories) {
559
+ const rootCategory = ROOT_CATEGORY && categories.find((x) => x.id == ROOT_CATEGORY);
560
+ if (rootCategory) {
561
+ return rootCategory;
562
+ } else {
563
+ return categories.find((x) => x.category == null);
564
+ }
565
+ }
566
+ function getParentCategory(categories, item) {
567
+ const parentCategoryId = asCategoryId(item.category);
568
+ const parentCategory = parentCategoryId ? categories.find((x) => x.id === parentCategoryId) : void 0;
569
+ return parentCategory;
570
+ }
571
+ function getParentCategoriesById(categories, id) {
572
+ const routeCategories = [];
573
+ const segments = [];
574
+ let parentId = id;
575
+ while (parentId != null) {
576
+ const parentCategory = categories.find((c) => c.id === parentId);
577
+ if (parentCategory) {
578
+ const segment = { ...parentCategory };
579
+ segments.unshift(segment);
580
+ routeCategories.push(parentId);
581
+ parentId = asCategoryId(parentCategory.category);
582
+ if (parentId) {
583
+ if (routeCategories.includes(parentId)) {
584
+ console.log("ICategory.getParentCategoriesById", "circular reference found", parentId);
585
+ parentId = void 0;
586
+ }
587
+ }
588
+ } else {
589
+ parentId = void 0;
590
+ }
591
+ }
592
+ return segments;
593
+ }
594
+ function getCategorySegments(categories, item) {
595
+ const parentCategoryId = asCategoryId(item.category);
596
+ const segments = getParentCategoriesById(categories, parentCategoryId);
597
+ return segments;
598
+ }
599
+ function getCategorySegmentsByCategory(categories, item) {
600
+ const parentCategoryId = asCategoryId(item.category);
601
+ const segments = parentCategoryId ? getParentCategoriesById(categories, parentCategoryId) : [];
602
+ segments.push(item);
603
+ return segments;
604
+ }
605
+ function asCategoryId(value) {
606
+ return isEntity(value) ? String(value.id) : value ? String(value) : void 0;
607
+ }
608
+ function findCategoryInCategories(categories, item) {
609
+ const categoryId = asCategoryId(item);
610
+ return categoryId ? categories.find((x) => x.id === categoryId) : void 0;
611
+ }
612
+ function findChildCategories(categories, item) {
613
+ const categoryId = asCategoryId(item);
614
+ return categoryId ? categories.filter((x) => asCategoryId(x.category) === categoryId) : [];
615
+ }
616
+
617
+ // src/classNames/classNames.ts
618
+ function isClassNameCollection(value) {
619
+ return typeof value === "object" && !Array.isArray(value);
620
+ }
621
+ function classNameCollectionToString(className) {
622
+ const keys = Object.keys(className);
623
+ const total = keys.length;
624
+ let classNames = "";
625
+ for (let i = 0; i < total; i++) {
626
+ const key = keys[i];
627
+ const value = className[keys[i]];
628
+ if (!value) {
629
+ continue;
630
+ }
631
+ classNames = classNames ? `${classNames} ${String(key)}` : String(key);
632
+ }
633
+ return classNames;
634
+ }
635
+ function getClassNames(...props) {
636
+ const total = props.length;
637
+ let classNames = "";
638
+ if (total === 0) {
639
+ return classNames;
640
+ }
641
+ for (let i = 0; i < total; i++) {
642
+ const value = props[i];
643
+ if (!value) {
644
+ continue;
645
+ }
646
+ if (isClassNameCollection(value)) {
647
+ classNames += ` ${classNameCollectionToString(value)}`;
648
+ } else {
649
+ classNames += ` ${String(value).trim()}`;
650
+ }
651
+ }
652
+ return classNames.trim();
653
+ }
654
+
655
+ // src/collection/collection.ts
656
+ import pluralize from "pluralize";
657
+ function getCollectionDescription(text) {
658
+ text = toValidCollectionName(text);
659
+ const displayName = toDisplayName(text);
660
+ const pluralName = toPluralName(text);
661
+ const pluralDisplayName = toDisplayName(pluralName);
662
+ const singularName = text;
663
+ const title = toTitleCase(text);
664
+ return {
665
+ displayName,
666
+ pluralName,
667
+ pluralDisplayName,
668
+ singularName,
669
+ title
670
+ };
671
+ }
672
+ function camelToSnakeCase(text) {
673
+ return text.replace(/[A-Z]/g, (letter, index) => {
674
+ return index > 0 ? `_${letter.toLowerCase()}` : letter.toLowerCase();
675
+ });
676
+ }
677
+ function isValidCollectionDescription(description) {
678
+ return description.singularName !== description.pluralName;
679
+ }
680
+ function isReservedCollectionDescription(description) {
681
+ return [
682
+ "category",
683
+ "label",
684
+ "locale",
685
+ "market",
686
+ "menu",
687
+ "redirect",
688
+ "route",
689
+ "template"
690
+ ].includes(description.singularName);
691
+ }
692
+ function toDisplayName(text) {
693
+ return toTitleCase(text).replace(/\s/g, "");
694
+ }
695
+ function toPluralName(text) {
696
+ const plural = pluralize.plural(text);
697
+ return plural === text ? `${plural}es` : plural;
698
+ }
699
+ function toTitleCase(text) {
700
+ return text.replace(/^[-_]*(.)/, (_, c) => c.toUpperCase()).replace(/[-_]+(.)/g, (_, c) => " " + c.toUpperCase());
701
+ }
702
+ function toValidCollectionName(text) {
703
+ text = text.trim().replace(/\W/g, "_").replace(/^[_]*(.)/, (_, c) => c);
704
+ text = camelToSnakeCase(text);
705
+ text = text.replace(/__/g, "_");
706
+ return text.toLowerCase();
707
+ }
708
+
709
+ // src/consoleWarn/consoleWarn.ts
710
+ var warningStack = {};
711
+ function consoleWarn(message, component) {
712
+ if (typeof console === "undefined") {
713
+ return;
714
+ }
715
+ const tag = component ? ` [${component}]` : " ";
716
+ const log = `[DesignSystem]${tag}: ${message}`;
717
+ if (warningStack[log]) {
718
+ return;
719
+ }
720
+ warningStack[log] = true;
721
+ if (process.env.NODE_ENV !== "production") {
722
+ return console.error(log);
723
+ }
724
+ console.warn(log);
725
+ }
726
+
727
+ // src/entity/entity.ts
728
+ function asEntityId(value) {
729
+ return isEntity(value) ? value.id : value;
730
+ }
731
+
732
+ // src/http/http.service.ts
733
+ var defaultOptions = {
734
+ // method: 'POST', // *GET, POST, PUT, DELETE, etc.
735
+ // mode: 'cors', // no-cors, *cors, same-origin
736
+ // cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
737
+ // credentials: 'same-origin', // include, *same-origin, omit
738
+ headers: {
739
+ "Content-Type": "application/json"
740
+ // 'Content-Type': 'application/x-www-form-urlencoded',
741
+ }
742
+ // redirect: 'follow', // manual, *follow, error
743
+ // referrerPolicy: 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
744
+ // body: JSON.stringify(data) // body data type must match 'Content-Type' header
745
+ };
746
+ async function httpFetch(url, options = {}, serviceOptions) {
747
+ try {
748
+ const httpOptions = merge({ ...defaultOptions }, options);
749
+ const httpResponse = await fetch(url, httpOptions);
750
+ if (!httpResponse.ok) {
751
+ throw httpResponse;
752
+ }
753
+ const response = await httpResponse.json();
754
+ return response;
755
+ } catch (error) {
756
+ if (typeof error === "object" && error.status) {
757
+ console.log("httpFetch.error", options.method, url, error.status, error.statusText);
758
+ } else {
759
+ console.log("httpFetch.error", options.method, url, error);
760
+ }
761
+ throw error;
762
+ }
763
+ }
764
+ async function httpGet(url, options = {}) {
765
+ return await httpFetch(url, { ...options, method: "GET" });
766
+ }
767
+ async function httpPost(url, payload, options = {}) {
768
+ return await httpFetch(url, { ...options, method: "POST", body: JSON.stringify(payload) });
769
+ }
770
+ async function httpPut(url, payload, options = {}) {
771
+ return await httpFetch(url, { ...options, method: "PUT", body: JSON.stringify(payload) });
772
+ }
773
+ async function httpPatch(url, payload, options = {}) {
774
+ return await httpFetch(url, { ...options, method: "PATCH", body: JSON.stringify(payload) });
775
+ }
776
+ async function httpDelete(url, options = {}) {
777
+ return await httpFetch(url, { ...options, method: "DELETE" });
778
+ }
779
+
780
+ // src/image/image.ts
781
+ function getSecret() {
782
+ return process.env.IMAGE_SECRET || "IMAGE_SECRET";
783
+ }
784
+ function textToArrayBuffer_(text) {
785
+ const encoder = new TextEncoder();
786
+ const arrayBuffer = encoder.encode(text);
787
+ return arrayBuffer;
788
+ }
789
+ function arrayBufferToText_(arrayBuffer) {
790
+ const encoder = new TextDecoder("utf-8");
791
+ const text = encoder.decode(arrayBuffer);
792
+ return text;
793
+ }
794
+ function xor_(text, secret) {
795
+ const s = textToArrayBuffer_(secret);
796
+ const t = textToArrayBuffer_(text);
797
+ const m = t.map((a, i) => {
798
+ const b = s[i % s.length];
799
+ return a ^ b;
800
+ });
801
+ return arrayBufferToText_(m);
802
+ }
803
+ function encrypt_(text, secret) {
804
+ const encrypted = xor_(text, secret);
805
+ const base64 = stringToBase64(encrypted);
806
+ return base64;
807
+ }
808
+ function decrypt_(base64, secret) {
809
+ const text = base64ToString(base64);
810
+ const decrypted = xor_(text, secret);
811
+ return decrypted;
812
+ }
813
+ function encryptImageToken(imageResize) {
814
+ const text = JSON.stringify(imageResize);
815
+ const token = encrypt_(text, getSecret());
816
+ return token;
817
+ }
818
+ function decryptImageResize(token) {
819
+ const text = decrypt_(token, getSecret());
820
+ const data = JSON.parse(text);
821
+ return data;
822
+ }
823
+
824
+ // src/json/json.service.ts
825
+ var JsonService = class {
826
+ constructor(items) {
827
+ this.items = items;
828
+ }
829
+ async getItems() {
830
+ return this.items;
831
+ }
832
+ async findGlobal(params = {}) {
833
+ const items = await this.getItems();
834
+ if (items.length > 0) {
835
+ return await this.decorateOne_(items[0], params);
836
+ } else {
837
+ console.log("JsonService.findGlobal.notfound", params);
838
+ return void 0;
839
+ }
840
+ }
841
+ async findOne(id, params = {}) {
842
+ let items = await this.getItems();
843
+ params.where = params.where || {};
844
+ params.where.id = params.where.id || { equals: id };
845
+ items = this.whereItems_(items, params.where);
846
+ if (items.length > 0) {
847
+ return await this.decorateOne_(items[0], params);
848
+ } else {
849
+ console.log("JsonService.findOne.notfound", id, params);
850
+ return void 0;
851
+ }
852
+ }
853
+ async findMany(params = {}) {
854
+ params.pagination = false;
855
+ let items = await this.getItems();
856
+ if (params.where) {
857
+ items = this.whereItems_(items, params.where, params.limit);
858
+ }
859
+ if (params.sort) {
860
+ items = this.sortCollection_(items, params.sort);
861
+ }
862
+ if (params.limit && !params.where) {
863
+ items = this.limitCollection_(items, params.limit);
864
+ }
865
+ return await this.decorateMany_(items, params);
866
+ }
867
+ async findPaged(params = {}) {
868
+ params.pagination = true;
869
+ let items = await this.getItems();
870
+ if (params.where) {
871
+ items = this.whereItems_(items, params.where);
872
+ }
873
+ if (params.sort) {
874
+ items = this.sortCollection_(items, params.sort);
875
+ }
876
+ const pagination = this.paginatedItems_(items, params.page, params.limit);
877
+ pagination.docs = await this.decorateMany_(pagination.docs, params);
878
+ return pagination;
879
+ }
880
+ async create(payload) {
881
+ const items = await this.getItems();
882
+ const item = { ...payload, id: this.newUUID_() };
883
+ this.items = [...items, item];
884
+ return item;
885
+ }
886
+ async updateOne(id, payload, params = {}) {
887
+ let items = await this.getItems();
888
+ params.where = params.where || {};
889
+ params.where.id = params.where.id || { equals: id };
890
+ const whereItems = this.whereItems_(items, params.where);
891
+ if (whereItems.length > 0) {
892
+ const index = items.indexOf(whereItems[0]);
893
+ const item = { ...items[index], payload };
894
+ items = [...items];
895
+ items[index] = item;
896
+ this.items = items;
897
+ return await this.decorateOne_(item, params);
898
+ }
899
+ throw "not found";
900
+ }
901
+ async updateMany(payload, params = {}) {
902
+ params.pagination = false;
903
+ let items = await this.getItems();
904
+ let filteredItems = items;
905
+ if (params.where) {
906
+ filteredItems = this.whereItems_(filteredItems, params.where, params.limit);
907
+ }
908
+ if (params.sort) {
909
+ filteredItems = this.sortCollection_(filteredItems, params.sort);
910
+ }
911
+ if (params.limit && !params.where) {
912
+ filteredItems = this.limitCollection_(filteredItems, params.limit);
913
+ }
914
+ items = [...items];
915
+ filteredItems = filteredItems.map((x) => {
916
+ const index = items.indexOf(x);
917
+ const item = { ...items[index], payload };
918
+ items[index] = item;
919
+ return item;
920
+ });
921
+ this.items = items;
922
+ return await this.decorateMany_(filteredItems, params);
923
+ }
924
+ async deleteOne(id, params = {}) {
925
+ let items = await this.getItems();
926
+ params.where = params.where || {};
927
+ params.where.id = params.where.id || { equals: id };
928
+ const whereItems = this.whereItems_(items, params.where);
929
+ if (whereItems.length > 0) {
930
+ const index = items.indexOf(whereItems[0]);
931
+ if (index !== -1) {
932
+ const item = items[index];
933
+ items = [...items];
934
+ items.splice(index, 1);
935
+ this.items = items;
936
+ return await this.decorateOne_(item, params);
937
+ }
938
+ return void 0;
939
+ }
940
+ return void 0;
941
+ }
942
+ async deleteMany(params = {}) {
943
+ params.pagination = false;
944
+ let items = await this.getItems();
945
+ let filteredItems = items;
946
+ if (params.where) {
947
+ filteredItems = this.whereItems_(filteredItems, params.where, params.limit);
948
+ }
949
+ if (params.sort) {
950
+ filteredItems = this.sortCollection_(filteredItems, params.sort);
951
+ }
952
+ if (params.limit && !params.where) {
953
+ filteredItems = this.limitCollection_(filteredItems, params.limit);
954
+ }
955
+ items = [...items];
956
+ this.items = items.filter((x) => filteredItems.indexOf(x) === -1);
957
+ return await this.decorateMany_(filteredItems, params);
958
+ }
959
+ // !!! old
960
+ async update(payload) {
961
+ let items = await this.getItems();
962
+ const index = items.reduce((p, c, i) => {
963
+ return c.id === payload.id ? i : p;
964
+ }, -1);
965
+ if (index !== -1) {
966
+ const item = { ...items[index], payload };
967
+ items = [...items];
968
+ items[index] = item;
969
+ this.items = items;
970
+ return item;
971
+ }
972
+ throw "not found";
973
+ }
974
+ async delete(id) {
975
+ let items = await this.getItems();
976
+ const index = items.reduce((p, c, i) => {
977
+ return c.id === id ? i : p;
978
+ }, -1);
979
+ if (index !== -1) {
980
+ const item = items[index];
981
+ items = [...items];
982
+ items.splice(index, 1);
983
+ this.items = items;
984
+ return item;
985
+ }
986
+ return void 0;
987
+ }
988
+ async decorateOne_(item, params = {}) {
989
+ return item;
990
+ }
991
+ async decorateMany_(items, params = {}) {
992
+ return items;
993
+ }
994
+ newUUID_() {
995
+ return (/* @__PURE__ */ new Date()).getTime();
996
+ }
997
+ // where
998
+ equalsClause_(value, equals) {
999
+ if (typeof equals !== "undefined") {
1000
+ return value === equals;
1001
+ }
1002
+ return true;
1003
+ }
1004
+ notEqualsClause_(value, not_equals) {
1005
+ if (typeof not_equals !== "undefined") {
1006
+ return value != not_equals;
1007
+ }
1008
+ return true;
1009
+ }
1010
+ existsClause_(value, exists) {
1011
+ if (typeof exists === "boolean") {
1012
+ return value != null === exists;
1013
+ }
1014
+ return true;
1015
+ }
1016
+ greaterThanClause_(value, greater_than) {
1017
+ if (typeof greater_than === "number") {
1018
+ return typeof value === "number" && value > greater_than;
1019
+ }
1020
+ return true;
1021
+ }
1022
+ greaterThanEqualClause_(value, greater_than_equal) {
1023
+ if (typeof greater_than_equal === "number") {
1024
+ return typeof value === "number" && value >= greater_than_equal;
1025
+ }
1026
+ return true;
1027
+ }
1028
+ lessThanClause_(value, less_than) {
1029
+ if (typeof less_than === "number") {
1030
+ return typeof value === "number" && value < less_than;
1031
+ }
1032
+ return true;
1033
+ }
1034
+ lessThanEqualClause_(value, less_than_equal) {
1035
+ if (typeof less_than_equal === "number") {
1036
+ return typeof value === "number" && value <= less_than_equal;
1037
+ }
1038
+ return true;
1039
+ }
1040
+ likeClause_(value, query) {
1041
+ if (typeof query === "string") {
1042
+ return String(value).toLowerCase().indexOf(query.toLowerCase()) !== -1;
1043
+ }
1044
+ return true;
1045
+ }
1046
+ containsClause_(value, contains) {
1047
+ if (typeof contains !== "undefined") {
1048
+ contains = String(contains).toLowerCase();
1049
+ if (Array.isArray(value)) {
1050
+ return value.reduce((p, c) => p || String(c).toLowerCase() === contains, false);
1051
+ } else if (typeof value === "string") {
1052
+ return value.toLowerCase().includes(contains);
1053
+ } else {
1054
+ return false;
1055
+ }
1056
+ }
1057
+ return true;
1058
+ }
1059
+ inClause_(value, values) {
1060
+ if (Array.isArray(values) && values.length > 0) {
1061
+ return values.indexOf(value) !== -1;
1062
+ }
1063
+ return true;
1064
+ }
1065
+ notInClause_(value, values) {
1066
+ if (Array.isArray(values) && values.length > 0) {
1067
+ return values.indexOf(value) === -1;
1068
+ }
1069
+ return true;
1070
+ }
1071
+ allClause_(value, values) {
1072
+ if (Array.isArray(values) && values.length > 0) {
1073
+ return Array.isArray(value) ? values.reduce((p, c) => p && value.includes(c), true) : false;
1074
+ }
1075
+ return true;
1076
+ }
1077
+ nearClause_(value, near) {
1078
+ if (Array.isArray(near) && near.reduce((p, c) => p && typeof c === "number", true)) {
1079
+ if (!Array.isArray(value)) {
1080
+ return false;
1081
+ }
1082
+ const itemLongitude = value[0];
1083
+ if (typeof itemLongitude !== "number") {
1084
+ return false;
1085
+ }
1086
+ const itemLatitude = value[1];
1087
+ if (typeof itemLatitude !== "number") {
1088
+ return false;
1089
+ }
1090
+ const [longitude, latitude, maxDistance, minDistance] = near;
1091
+ const distance = calculateDistanceInMeters_(itemLongitude, itemLatitude, longitude, latitude);
1092
+ if (typeof maxDistance === "number" && typeof minDistance === "number") {
1093
+ return distance <= maxDistance && distance >= minDistance;
1094
+ } else if (typeof maxDistance === "number") {
1095
+ return distance <= maxDistance;
1096
+ } else if (typeof minDistance === "number") {
1097
+ return distance >= minDistance;
1098
+ }
1099
+ }
1100
+ return true;
1101
+ }
1102
+ whereItem_(item, where) {
1103
+ let has = true;
1104
+ if (typeof where === "object") {
1105
+ Object.entries(where).forEach(([k, v]) => {
1106
+ switch (k) {
1107
+ case "and":
1108
+ if (Array.isArray(v)) {
1109
+ has = v.reduce((p, c) => {
1110
+ return p && this.whereItem_(item, c);
1111
+ }, has);
1112
+ }
1113
+ break;
1114
+ case "or":
1115
+ if (Array.isArray(v)) {
1116
+ has = has && v.reduce((p, c) => {
1117
+ return p || this.whereItem_(item, c);
1118
+ }, false);
1119
+ }
1120
+ break;
1121
+ default:
1122
+ if (Array.isArray(v)) {
1123
+ } else if (typeof v === "object") {
1124
+ const value = getValue(item, k);
1125
+ has = has && this.equalsClause_(value, v.equals);
1126
+ has = has && this.notEqualsClause_(value, v.not_equals);
1127
+ has = has && this.existsClause_(value, v.exists);
1128
+ has = has && this.greaterThanClause_(value, v.greater_than);
1129
+ has = has && this.greaterThanEqualClause_(value, v.greater_than_equal);
1130
+ has = has && this.lessThanClause_(value, v.less_than);
1131
+ has = has && this.lessThanEqualClause_(value, v.less_than_equal);
1132
+ has = has && this.likeClause_(value, v.like);
1133
+ has = has && this.containsClause_(value, v.contains);
1134
+ has = has && this.inClause_(value, v.in);
1135
+ has = has && this.notInClause_(value, v.not_in);
1136
+ has = has && this.allClause_(value, v.all);
1137
+ has = has && this.nearClause_(value, v.near);
1138
+ }
1139
+ }
1140
+ });
1141
+ }
1142
+ return has;
1143
+ }
1144
+ /**
1145
+ equals The value must be exactly equal.
1146
+ not_equals The query will return all documents where the value is not equal.
1147
+ exists Only return documents where the value either exists (true) or does not exist (false).
1148
+ greater_than For numeric or date-based fields.
1149
+ greater_than_equal For numeric or date-based fields.
1150
+ less_than For numeric or date-based fields.
1151
+ less_than_equal For numeric or date-based fields.
1152
+ like Case-insensitive string must be present. If string of words, all words must be present, in any order.
1153
+ contains Must contain the value entered, case-insensitive.
1154
+ in The value must be found within the provided comma-delimited list of values.
1155
+ not_in The value must NOT be within the provided comma-delimited list of values.
1156
+ all The value must contain all values provided in the comma-delimited list.
1157
+ near For distance related to a point field comma separated as <longitude>, <latitude>, <maxDistance in meters (nullable)>, <minDistance in meters (nullable)>.
1158
+ */
1159
+ whereItems_(items, where, limit = -1) {
1160
+ if (typeof where === "object") {
1161
+ const whereItems = [];
1162
+ for (const item of items) {
1163
+ if (limit > -1 && whereItems.length >= limit) {
1164
+ return whereItems;
1165
+ }
1166
+ if (this.whereItem_(item, where)) {
1167
+ whereItems.push(item);
1168
+ }
1169
+ }
1170
+ return whereItems;
1171
+ }
1172
+ return items;
1173
+ }
1174
+ // ^ where
1175
+ // sort
1176
+ sortCollection_(items, sort) {
1177
+ if (sort) {
1178
+ const reverse = sort.indexOf("-") === 0 ? -1 : 1;
1179
+ const key = sort.replace(/^-/, "");
1180
+ items = [...items];
1181
+ items.sort((a, b) => {
1182
+ const aValue = a[key];
1183
+ const bValue = b[key];
1184
+ if (typeof aValue === "number" && typeof bValue === "number") {
1185
+ return (aValue - bValue) * reverse;
1186
+ }
1187
+ const aStringValue = String(aValue);
1188
+ const bStringValue = String(bValue);
1189
+ return aStringValue.localeCompare(bStringValue) * reverse;
1190
+ });
1191
+ }
1192
+ return items;
1193
+ }
1194
+ // ^ sort
1195
+ // limit
1196
+ limitCollection_(items, limit) {
1197
+ if (limit) {
1198
+ items = items.slice(0, Math.min(limit, items.length));
1199
+ }
1200
+ return items;
1201
+ }
1202
+ // ^ limit
1203
+ // pagination
1204
+ paginatedItems_(items, page = 1, limit = 10) {
1205
+ const totalDocs = items.length;
1206
+ const totalPages = Math.ceil(items.length / limit);
1207
+ const hasNextPage = page < totalPages;
1208
+ const hasPrevPage = page > 1;
1209
+ const index = page - 1;
1210
+ const from = index * limit;
1211
+ const to = Math.min(page * limit, totalDocs);
1212
+ const docs = items.slice(from, to);
1213
+ const pagination = {
1214
+ totalDocs,
1215
+ totalPages,
1216
+ page,
1217
+ limit,
1218
+ hasNextPage,
1219
+ hasPrevPage,
1220
+ nextPage: hasNextPage ? page + 1 : null,
1221
+ prevPage: hasPrevPage ? page - 1 : null,
1222
+ pagingCounter: from + 1
1223
+ };
1224
+ return {
1225
+ docs,
1226
+ ...pagination
1227
+ };
1228
+ }
1229
+ // ^ sort
1230
+ };
1231
+ function getValue(item, key) {
1232
+ const keys = key.split(".");
1233
+ const value = keys.reduce((p, c) => {
1234
+ if (isObject(p)) {
1235
+ const v = p[c];
1236
+ if (isUnresolvedRelation(v)) {
1237
+ return v.value;
1238
+ }
1239
+ return v;
1240
+ } else {
1241
+ return void 0;
1242
+ }
1243
+ }, item);
1244
+ return value;
1245
+ }
1246
+ function calculateDistanceInMeters_(lon1, lat1, lon2, lat2) {
1247
+ const R = 6371;
1248
+ const dLat = deg2rad_(lat2 - lat1);
1249
+ const dLon = deg2rad_(lon2 - lon1);
1250
+ const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(deg2rad_(lat1)) * Math.cos(deg2rad_(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
1251
+ const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
1252
+ const distance = R * c * 1e3;
1253
+ return distance;
1254
+ }
1255
+ function deg2rad_(deg) {
1256
+ return deg * (Math.PI / 180);
1257
+ }
1258
+
1259
+ // src/locale/locale.ts
1260
+ function getDefaultLocale() {
1261
+ let defaultLocale2 = "en";
1262
+ if (typeof process !== "undefined" && process.env.DEFAULT_LOCALE) {
1263
+ defaultLocale2 = process.env.DEFAULT_LOCALE;
1264
+ }
1265
+ return defaultLocale2;
1266
+ }
1267
+ var defaultLocale = getDefaultLocale();
1268
+
1269
+ // src/localized/localized.ts
1270
+ var DEFAULT_LOCALE = defaultLocale;
1271
+ function isLocalizedString(value) {
1272
+ let isLocalizedString2 = false;
1273
+ if (value && !Array.isArray(value) && typeof value === "object") {
1274
+ const matchKeys = Object.keys(value).reduce((p, c) => p && /^(\w{2})(-\w{2})?$/.test(c), true);
1275
+ const matchValues = Object.values(value).reduce((p, c) => p && (typeof c === "string" || !c), true);
1276
+ isLocalizedString2 = Boolean(matchKeys && matchValues);
1277
+ }
1278
+ return isLocalizedString2;
1279
+ }
1280
+ function localizedToString(json, locale, defaultLocale2 = DEFAULT_LOCALE) {
1281
+ const localizedString = json[locale] || json[defaultLocale2] || Object.values(json)[0];
1282
+ return localizedString;
1283
+ }
1284
+ function localize(value, locale, defaultLocale2 = DEFAULT_LOCALE) {
1285
+ return isLocalizedString(value) ? localizedToString(value, locale, defaultLocale2) : value;
1286
+ }
1287
+ function localizeValue(value, locale, defaultLocale2 = DEFAULT_LOCALE) {
1288
+ if (value) {
1289
+ if (isLocalizedString(value)) {
1290
+ return localizedToString(value, locale, defaultLocale2);
1291
+ } else {
1292
+ return localizeItem(value, locale, defaultLocale2);
1293
+ }
1294
+ }
1295
+ }
1296
+ function localizeItem(item, locale, defaultLocale2 = DEFAULT_LOCALE) {
1297
+ if (isArray(item)) {
1298
+ item = item.map((x) => localizeValue(x, locale, defaultLocale2));
1299
+ } else if (isObject(item)) {
1300
+ item = { ...item };
1301
+ const object = item;
1302
+ Object.keys(object).forEach((key) => {
1303
+ object[key] = localizeValue(object[key], locale, defaultLocale2);
1304
+ });
1305
+ }
1306
+ return item;
1307
+ }
1308
+
1309
+ // src/logger/logger.ts
1310
+ var LoggerLevel = /* @__PURE__ */ ((LoggerLevel2) => {
1311
+ LoggerLevel2[LoggerLevel2["NONE"] = 0] = "NONE";
1312
+ LoggerLevel2[LoggerLevel2["ERROR"] = 1] = "ERROR";
1313
+ LoggerLevel2[LoggerLevel2["WARN"] = 2] = "WARN";
1314
+ LoggerLevel2[LoggerLevel2["INFO"] = 3] = "INFO";
1315
+ LoggerLevel2[LoggerLevel2["LOG"] = 4] = "LOG";
1316
+ LoggerLevel2[LoggerLevel2["ALL"] = 5] = "ALL";
1317
+ return LoggerLevel2;
1318
+ })(LoggerLevel || {});
1319
+ var Logger = class {
1320
+ static setLevel(level) {
1321
+ this.level_ = level;
1322
+ }
1323
+ static getLevel() {
1324
+ if (isDevelopment) {
1325
+ return this.level_;
1326
+ } else {
1327
+ return 1 /* ERROR */;
1328
+ }
1329
+ }
1330
+ static error(...args) {
1331
+ if (this.getLevel() >= 1 /* ERROR */) {
1332
+ console.error(...args);
1333
+ }
1334
+ }
1335
+ static warn(...args) {
1336
+ if (this.getLevel() >= 2 /* WARN */) {
1337
+ console.warn(...args);
1338
+ }
1339
+ }
1340
+ static info(...args) {
1341
+ if (this.getLevel() >= 3 /* INFO */) {
1342
+ console.info(...args);
1343
+ }
1344
+ }
1345
+ static log(...args) {
1346
+ if (this.getLevel() >= 4 /* LOG */) {
1347
+ console.log(...args);
1348
+ }
1349
+ }
1350
+ };
1351
+ Logger.level_ = 5 /* ALL */;
1352
+
1353
+ // src/market/market.ts
1354
+ function getDefaultMarket() {
1355
+ let defaultMarket2 = "ww";
1356
+ if (typeof process !== "undefined" && process.env.DEFAULT_MARKET) {
1357
+ defaultMarket2 = process.env.DEFAULT_MARKET;
1358
+ }
1359
+ return defaultMarket2;
1360
+ }
1361
+ var defaultMarket = getDefaultMarket();
1362
+
1363
+ // src/password/password.ts
1364
+ function getPasswordStrategy() {
1365
+ const passwordStrategy2 = typeof process !== "undefined" && process.env.NEXT_PUBLIC_PASSWORD_STRATEGY ? process.env.NEXT_PUBLIC_PASSWORD_STRATEGY : "^(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])[a-zA-Z0-9._\\-\\W]{8,}$";
1366
+ return passwordStrategy2;
1367
+ }
1368
+ var passwordStrategy = getPasswordStrategy();
1369
+
1370
+ // src/qs/qs.ts
1371
+ function qsSerializeKey(key, parentKey = "") {
1372
+ return parentKey ? `${parentKey}[${key}]` : String(key);
1373
+ }
1374
+ function qsSerializeParam(key, value, serializedParams = [], parentKey = "") {
1375
+ if (value != null) {
1376
+ if (typeof value === "object") {
1377
+ serializedParams = qsSerializeParams(value, serializedParams, qsSerializeKey(key, parentKey));
1378
+ } else {
1379
+ serializedParams.push({
1380
+ key: qsSerializeKey(key, parentKey),
1381
+ value
1382
+ });
1383
+ }
1384
+ }
1385
+ return serializedParams;
1386
+ }
1387
+ function qsSerializeParams(params, serializedParams = [], parentKey = "") {
1388
+ if (Array.isArray(params)) {
1389
+ params.forEach((value, key) => {
1390
+ serializedParams = qsSerializeParam(key, value, serializedParams, parentKey);
1391
+ });
1392
+ } else {
1393
+ Object.entries(params).forEach(([key, value]) => {
1394
+ serializedParams = qsSerializeParam(key, value, serializedParams, parentKey);
1395
+ });
1396
+ }
1397
+ return serializedParams;
1398
+ }
1399
+ function qsSerialize(queryParams = {}) {
1400
+ const params = qsSerializeParams(queryParams);
1401
+ if (params.length) {
1402
+ return params.map((x) => `${x.key}=${x.value}`).join("&");
1403
+ }
1404
+ return "";
1405
+ }
1406
+ function qsSerializeRaw(queryParams = {}) {
1407
+ const params = qsSerializeParams(queryParams);
1408
+ if (params.length) {
1409
+ return params.map((x) => `${x.key}=${x.value}`).join("&");
1410
+ }
1411
+ return "";
1412
+ }
1413
+ function qsDeserializeValue(value) {
1414
+ if (String(parseInt(value)) === value) {
1415
+ return Number(value);
1416
+ } else if (String(value) === "true") {
1417
+ return true;
1418
+ } else if (String(value) === "false") {
1419
+ return false;
1420
+ }
1421
+ return value;
1422
+ }
1423
+ function qsDeserializeKey(value) {
1424
+ if (String(parseInt(value)) === value) {
1425
+ return Number(value);
1426
+ }
1427
+ return value;
1428
+ }
1429
+ function qsDeserializeKeys(key) {
1430
+ const keys = key.replace(/[\]]/g, "").split("[").map((x) => qsDeserializeKey(x));
1431
+ return keys;
1432
+ }
1433
+ function getNextKeyItem(key) {
1434
+ if (typeof key === "number") {
1435
+ return [];
1436
+ } else {
1437
+ return {};
1438
+ }
1439
+ }
1440
+ function qsDeserializeParam(key, value, deserializedParams = {}) {
1441
+ const keys = qsDeserializeKeys(key);
1442
+ let target = deserializedParams;
1443
+ while (keys.length) {
1444
+ const key2 = keys.shift();
1445
+ if (keys.length === 0) {
1446
+ target[key2] = qsDeserializeValue(value);
1447
+ } else {
1448
+ const next = target[key2] ? target[key2] : target[key2] = getNextKeyItem(keys[0]);
1449
+ target = next;
1450
+ }
1451
+ }
1452
+ return deserializedParams;
1453
+ }
1454
+ function qsDeserializeParams(params, deserializedParams = {}) {
1455
+ params.forEach((x) => qsDeserializeParam(x[0], x[1], deserializedParams));
1456
+ return deserializedParams;
1457
+ }
1458
+ function qsDeserialize(query = "", deserializedParams = {}) {
1459
+ if (query.indexOf("?") === 0) {
1460
+ query = query.substring(1);
1461
+ }
1462
+ if (query !== "") {
1463
+ const params = query.split("&").map((x) => x.split("="));
1464
+ if (params.length) {
1465
+ return qsDeserializeParams(params, deserializedParams);
1466
+ }
1467
+ }
1468
+ return deserializedParams;
1469
+ }
1470
+ function qsDeserializeRaw(query = "", deserializedParams = {}) {
1471
+ if (query.indexOf("?") === 0) {
1472
+ query = query.substring(1);
1473
+ }
1474
+ if (query !== "") {
1475
+ const params = query.split("&").map((x) => x.split("="));
1476
+ if (params.length) {
1477
+ return qsDeserializeParams(params, deserializedParams);
1478
+ }
1479
+ }
1480
+ return deserializedParams;
1481
+ }
1482
+
1483
+ // src/request/request.ts
1484
+ function isHeaders(headers) {
1485
+ return typeof headers === "object" && "get" in headers ? typeof headers.get === "function" : false;
1486
+ }
1487
+ function isIncomingHttpHeaders(headers) {
1488
+ return typeof headers === "object" && !("get" in headers);
1489
+ }
1490
+ function getHost(headers) {
1491
+ if (isIncomingHttpHeaders(headers)) {
1492
+ return headers["x-forwarded-host"] || headers.forwarded || headers.host || null;
1493
+ } else if (isHeaders(headers)) {
1494
+ return headers.get("X-Forwarded-Host") || headers.get("Forwarded") || headers.get("Host") || null;
1495
+ } else {
1496
+ return null;
1497
+ }
1498
+ }
1499
+ function getProto(headers) {
1500
+ if (isIncomingHttpHeaders(headers)) {
1501
+ return headers["x-forwarded-proto"] || "https";
1502
+ } else if (isHeaders(headers)) {
1503
+ return headers.get("X-Forwarded-Proto") || "https";
1504
+ } else {
1505
+ return "https";
1506
+ }
1507
+ }
1508
+ function getOrigin(headers) {
1509
+ if (process.env.NEXT_PUBLIC_URL) {
1510
+ return process.env.NEXT_PUBLIC_URL;
1511
+ } else {
1512
+ const host = getHost(headers);
1513
+ if (host) {
1514
+ return host.indexOf("localhost") !== -1 ? "http://" + host : getProto(headers) + "://" + host;
1515
+ } else {
1516
+ return "";
1517
+ }
1518
+ }
1519
+ }
1520
+
1521
+ // src/route/route.ts
1522
+ var RouteStrategy = /* @__PURE__ */ ((RouteStrategy2) => {
1523
+ RouteStrategy2["Auto"] = "auto";
1524
+ RouteStrategy2["Default"] = "default";
1525
+ RouteStrategy2["Manual"] = "manual";
1526
+ return RouteStrategy2;
1527
+ })(RouteStrategy || {});
1528
+ var ROUTE_STRATEGY = process.env.ROUTE_STRATEGY || "manual" /* Manual */;
1529
+ function collectRoutes(store, categories, markets, locales, medias) {
1530
+ const routes = [];
1531
+ if (locales.length > 0 && markets.length > 0) {
1532
+ const rootCategory = getRootCategory(categories);
1533
+ eachCategorized(store, (item, key) => {
1534
+ const segments = getCategorySegments(categories, item);
1535
+ const visibleSegments = segments.filter((x) => Boolean(x.isHidden) === false);
1536
+ const visibleCategory = visibleSegments.length > 0 ? visibleSegments[visibleSegments.length - 1] : rootCategory;
1537
+ if (visibleCategory) {
1538
+ const slugs = visibleSegments.map((x) => ({ slug: x.slug }));
1539
+ if (Boolean(item.isDefault) === false) {
1540
+ slugs.push({ slug: item.slug });
1541
+ }
1542
+ const isRootCategory = rootCategory && item.category === rootCategory.id && item.isDefault;
1543
+ eachMarketLocale(markets, locales, (market, locale, markets2, locales2) => {
1544
+ if (hasMarket(item, market)) {
1545
+ const title = localize(item.title, locale.id);
1546
+ const id = getRouteHref(slugs, market, locale, markets2, locales2);
1547
+ const {
1548
+ _status,
1549
+ category,
1550
+ isDefault,
1551
+ media,
1552
+ order,
1553
+ template,
1554
+ updatedAt,
1555
+ useSplat
1556
+ } = item;
1557
+ const route = {
1558
+ _status,
1559
+ category,
1560
+ // id: isDefaultRootCategory ? '/' : id,
1561
+ id,
1562
+ locale: locale.id,
1563
+ market: market.id,
1564
+ media,
1565
+ page: item.id,
1566
+ resolvedCategory: visibleCategory.id,
1567
+ schema: key,
1568
+ template,
1569
+ title,
1570
+ updatedAt
1571
+ };
1572
+ if (isDefault) {
1573
+ route.isDefault = true;
1574
+ }
1575
+ if (isRootCategory) {
1576
+ route.isRoot = true;
1577
+ }
1578
+ const noindex = (item.meta?.robots || "").includes("noindex");
1579
+ if (noindex) {
1580
+ route.noindex = true;
1581
+ }
1582
+ if (order != null) {
1583
+ route.order = order;
1584
+ }
1585
+ if (useSplat) {
1586
+ route.useSplat = true;
1587
+ }
1588
+ const mediaId = typeof item.media === "string" ? item.media : void 0;
1589
+ if (Array.isArray(medias) && mediaId) {
1590
+ const media2 = item.media && medias.find((x) => x.id === mediaId);
1591
+ if (media2) {
1592
+ route.media = media2;
1593
+ }
1594
+ }
1595
+ routes.push(route);
1596
+ }
1597
+ });
1598
+ }
1599
+ });
1600
+ }
1601
+ return routes;
1602
+ }
1603
+ function eachMarketLocale(markets, locales, callback) {
1604
+ locales = locales.filter((x) => x.isActive !== false);
1605
+ markets = markets.filter((x) => x.isActive !== false);
1606
+ markets.forEach((market) => {
1607
+ const marketLocales = market.languages && market.languages.length > 0 ? market.languages.map((idOrEntity) => locales.find((x) => x.id === asEntityId(idOrEntity))).filter((x) => x !== void 0) : locales;
1608
+ marketLocales.forEach((locale) => {
1609
+ callback(market, locale, markets, locales);
1610
+ });
1611
+ });
1612
+ }
1613
+ function eachCategorized(store, callback) {
1614
+ const keys = Object.keys(store);
1615
+ for (const key of keys) {
1616
+ const items = store[key];
1617
+ for (const item of items) {
1618
+ callback(item, key);
1619
+ }
1620
+ }
1621
+ }
1622
+ function findRouteOfCategory(routes, categoryId, market, locale) {
1623
+ const findRoute = market && locale ? (route2) => route2.isDefault && route2.resolvedCategory === categoryId && route2.market === market && route2.locale === locale : (route2) => route2.isDefault && route2.resolvedCategory === categoryId;
1624
+ const route = routes.find(findRoute);
1625
+ return route;
1626
+ }
1627
+ function findRoutesOfCategory(routes, categoryId, isDefault = true) {
1628
+ const filteredRoutes = routes.filter(
1629
+ (route) => route.resolvedCategory === categoryId && Boolean(route.isDefault) === isDefault
1630
+ );
1631
+ return filteredRoutes;
1632
+ }
1633
+ function getRouteHref(segments, market, locale, markets, locales) {
1634
+ const href = segments.reduce((p, c, i) => {
1635
+ let slug = localize(c.slug || "", locale.id);
1636
+ slug = `${p}/${slug}`;
1637
+ return slug === "/" ? "" : slug;
1638
+ }, "");
1639
+ const prefixes = [];
1640
+ switch (ROUTE_STRATEGY) {
1641
+ case "auto" /* Auto */:
1642
+ if (locales.length > 1 || markets.length > 1) {
1643
+ prefixes.push(locale.id);
1644
+ }
1645
+ if (markets.length > 1) {
1646
+ prefixes.push(market.id);
1647
+ }
1648
+ break;
1649
+ case "default" /* Default */:
1650
+ if (locale.isDefault !== true) {
1651
+ prefixes.push(locale.id);
1652
+ }
1653
+ if (market.isDefault !== true) {
1654
+ prefixes.push(market.id);
1655
+ }
1656
+ break;
1657
+ case "manual" /* Manual */:
1658
+ if (locale.isHidden !== true) {
1659
+ prefixes.push(locale.id);
1660
+ }
1661
+ if (market.isHidden !== true) {
1662
+ prefixes.push(market.id);
1663
+ }
1664
+ break;
1665
+ }
1666
+ const prefix = prefixes.length ? `/${prefixes.join("-")}` : "";
1667
+ return `${prefix}${href}`;
1668
+ }
1669
+ function hasMarket(item, market) {
1670
+ return !item.markets || item.markets.length === 0 || item.markets.includes(market.id);
1671
+ }
1672
+ export {
1673
+ ImageStrategy,
1674
+ JsonService,
1675
+ Logger,
1676
+ LoggerLevel,
1677
+ MenuCategoryStrategy,
1678
+ RedirectReason,
1679
+ RouteStrategy,
1680
+ arrayShuffle,
1681
+ asCategoryId,
1682
+ asEntityId,
1683
+ asEquatable,
1684
+ asEquatableNumber,
1685
+ asEquatableString,
1686
+ asServerProps,
1687
+ asSortedOptions,
1688
+ awaitAll,
1689
+ base64ToString,
1690
+ camelToSnakeCase,
1691
+ cloneItem,
1692
+ collectFeatureTypes,
1693
+ collectFeatureTypes__,
1694
+ collectOptions,
1695
+ collectRoutes,
1696
+ consoleWarn,
1697
+ decryptImageResize,
1698
+ deepMerge,
1699
+ defaultLocale,
1700
+ defaultMarket,
1701
+ eachCategorized,
1702
+ eachMarketLocale,
1703
+ eachMedia,
1704
+ eachValue,
1705
+ encryptImageToken,
1706
+ enumToList,
1707
+ excludeComponent,
1708
+ findCategoryInCategories,
1709
+ findChildCategories,
1710
+ findRouteOfCategory,
1711
+ findRoutesOfCategory,
1712
+ getCategorySegments,
1713
+ getCategorySegmentsByCategory,
1714
+ getClassNames,
1715
+ getCollectionDescription,
1716
+ getEnv,
1717
+ getHost,
1718
+ getIsDevelopment,
1719
+ getIsProduction,
1720
+ getOrigin,
1721
+ getParentCategoriesById,
1722
+ getParentCategory,
1723
+ getProto,
1724
+ getRootCategory,
1725
+ getRouteHref,
1726
+ groupComponents,
1727
+ hasComponents,
1728
+ hasMarket,
1729
+ httpDelete,
1730
+ httpFetch,
1731
+ httpGet,
1732
+ httpPatch,
1733
+ httpPost,
1734
+ httpPut,
1735
+ isArray,
1736
+ isBrowser,
1737
+ isComponent,
1738
+ isComponentOfType,
1739
+ isDevelopment,
1740
+ isEntity,
1741
+ isEquatable,
1742
+ isHeaders,
1743
+ isIncomingHttpHeaders,
1744
+ isLocalizedString,
1745
+ isMedia,
1746
+ isMediaImage,
1747
+ isMediaJson,
1748
+ isMediaPdf,
1749
+ isMediaVideo,
1750
+ isMenuCategory,
1751
+ isMenuGroup,
1752
+ isMenuHref,
1753
+ isMenuLink,
1754
+ isMenuPage,
1755
+ isMenuRoute,
1756
+ isNonEmptyArray,
1757
+ isNotNullString,
1758
+ isNumber,
1759
+ isObject,
1760
+ isProduction,
1761
+ isPromise,
1762
+ isRelation,
1763
+ isReservedCollectionDescription,
1764
+ isStage,
1765
+ isString,
1766
+ isUndecoratedCategory,
1767
+ isUndecoratedMenuCategory,
1768
+ isUndecoratedMenuItem,
1769
+ isUndecoratedMenuPage,
1770
+ isUndecoratedNav,
1771
+ isUnresolvedCategory,
1772
+ isUnresolvedRelation,
1773
+ isValidCollectionDescription,
1774
+ isValidString,
1775
+ localize,
1776
+ localizeItem,
1777
+ localizeValue,
1778
+ localizedToString,
1779
+ merge,
1780
+ pascalCaseToCamelCase,
1781
+ pascalCaseToCharCase,
1782
+ pascalCaseToKebabCase,
1783
+ pascalCaseToSnakeCase,
1784
+ passwordStrategy,
1785
+ pickComponent,
1786
+ pickHero,
1787
+ prependHero,
1788
+ qsDeserialize,
1789
+ qsDeserializeRaw,
1790
+ qsSerialize,
1791
+ qsSerializeRaw,
1792
+ resolveMediaType,
1793
+ stringToBase64,
1794
+ toCamelCase,
1795
+ toCharCase,
1796
+ toDisplayName,
1797
+ toFindParams,
1798
+ toKebabCase,
1799
+ toPascalCase,
1800
+ toPluralName,
1801
+ toSnakeCase,
1802
+ toTitleCase,
1803
+ toValidCollectionName,
1804
+ unknownCaseToPascalCase,
1805
+ uuidv4,
1806
+ withSchema
1807
+ };