@websolutespa/payload-plugin-bowl 1.1.0 → 1.3.0
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/CHANGELOG.md +20 -0
- package/dist/index.d.ts +8 -7
- package/dist/index.js +30 -45
- package/package.json +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @websolutespa/payload-plugin-bowl
|
|
2
2
|
|
|
3
|
+
## 1.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- c7a99a2b: Added tests
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- dad63747: Added defaultMarket, defaultLocale
|
|
12
|
+
- 11b63e3b: Fixed test config
|
|
13
|
+
- c7a99a2b: Fixed collection bulk patch handler
|
|
14
|
+
- Updated dependencies [dad63747]
|
|
15
|
+
- @websolutespa/bom-core@0.6.1
|
|
16
|
+
|
|
17
|
+
## 1.2.0
|
|
18
|
+
|
|
19
|
+
### Minor Changes
|
|
20
|
+
|
|
21
|
+
- Added: MenuItem extra.
|
|
22
|
+
|
|
3
23
|
## 1.1.0
|
|
4
24
|
|
|
5
25
|
### Minor Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -130,6 +130,7 @@ type IUndecoratedMenuBase = {
|
|
|
130
130
|
items: IUndecoratedMenuItem[];
|
|
131
131
|
markets?: string[];
|
|
132
132
|
abstract?: string;
|
|
133
|
+
extra?: string;
|
|
133
134
|
media?: IMedia;
|
|
134
135
|
};
|
|
135
136
|
type IUndecoratedMenuCategory = Omit<IUndecoratedMenuBase, 'type'> & {
|
|
@@ -178,8 +179,8 @@ declare const menuIndexGet: ((options: BowlOptions) => Endpoint);
|
|
|
178
179
|
declare const menuDetailGet: ((options: BowlOptions) => Endpoint);
|
|
179
180
|
declare function getLocales(req: PayloadRequest<any>): Promise<string[]>;
|
|
180
181
|
declare function getMarkets(req: PayloadRequest<any>): Promise<string[]>;
|
|
181
|
-
declare function decorateMenus(req: PayloadRequest<any>, items: IUndecoratedMenu[], market
|
|
182
|
-
declare function decorateMenu(req: PayloadRequest<any>, item: IUndecoratedMenu, market
|
|
182
|
+
declare function decorateMenus(req: PayloadRequest<any>, items: IUndecoratedMenu[], market: string, locale: string): Promise<IMenu[]>;
|
|
183
|
+
declare function decorateMenu(req: PayloadRequest<any>, item: IUndecoratedMenu, market: string, locale: string): Promise<IMenu>;
|
|
183
184
|
declare function decorateMenuCategory(item: IUndecoratedMenuCategory, categories: ICategory[], routes: IRoute[], market: string, depth?: number): IMenuItem;
|
|
184
185
|
declare function decorateMenuGroup(item: IUndecoratedMenuGroup, categories: ICategory[], routes: IRoute[], market: string): IMenuItem;
|
|
185
186
|
declare function decorateMenuLink(item: IUndecoratedMenuLink, categories: ICategory[], routes: IRoute[], market: string): IMenuItem;
|
|
@@ -188,10 +189,10 @@ declare function decorateMenuRoute(item: IRoute): IMenuItem;
|
|
|
188
189
|
declare function decorateMenuItem(item: IUndecoratedMenuItem, categories: ICategory[], routes: IRoute[], market: string, depth?: number): IMenuItem;
|
|
189
190
|
declare function hasMarket(item: IUndecoratedMenuItem, market: string): boolean;
|
|
190
191
|
|
|
191
|
-
declare function decorateHref<T extends ISchema = ISchema>(req: PayloadRequest<any>, item: T, slug: string, market
|
|
192
|
+
declare function decorateHref<T extends ISchema = ISchema>(req: PayloadRequest<any>, item: T, slug: string, market: string, locale: string): Promise<T & {
|
|
192
193
|
href: string | null;
|
|
193
194
|
}>;
|
|
194
|
-
declare function decorateHrefs<T extends ISchema = ISchema>(req: PayloadRequest<any>, items: T[], slug: string, market
|
|
195
|
+
declare function decorateHrefs<T extends ISchema = ISchema>(req: PayloadRequest<any>, items: T[], slug: string, market: string, locale: string): Promise<(T & {
|
|
195
196
|
href: string | null;
|
|
196
197
|
})[]>;
|
|
197
198
|
/**
|
|
@@ -344,7 +345,7 @@ type StaticCollectionConfig = {
|
|
|
344
345
|
declare function whereCollection<T = IEntity>(items: T[], where?: {
|
|
345
346
|
[key: string]: any;
|
|
346
347
|
}): Promise<T[]>;
|
|
347
|
-
declare function populateStaticFields<T = IEntity>(item: T, fields: Field[], locale
|
|
348
|
+
declare function populateStaticFields<T = IEntity>(item: T, fields: Field[], locale: string): Promise<T>;
|
|
348
349
|
declare function localizeCollection<T = IEntity>(items: T[], localizedFields: string[], locale?: string): Promise<T[]>;
|
|
349
350
|
declare function sortCollection<T = IEntity>(items: T[], sort?: string): Promise<T[]>;
|
|
350
351
|
declare function getStaticLoader(slug: string): any;
|
|
@@ -612,9 +613,9 @@ declare function log(...rest: unknown[]): void;
|
|
|
612
613
|
|
|
613
614
|
declare const defaultSlug: BowlSlug;
|
|
614
615
|
declare const defaultGroup: BowlGroup;
|
|
615
|
-
declare const defaultLocale = "en";
|
|
616
616
|
declare const defaultLocales: string[];
|
|
617
|
-
declare const
|
|
617
|
+
declare const defaultLocale: string;
|
|
618
|
+
declare const defaultMarket: string;
|
|
618
619
|
declare const options: BowlOptions;
|
|
619
620
|
declare const internalSlugs: string[];
|
|
620
621
|
|
package/dist/index.js
CHANGED
|
@@ -768,6 +768,7 @@ var translations = {
|
|
|
768
768
|
description: "Description",
|
|
769
769
|
details: "Details",
|
|
770
770
|
englishName: "English Name",
|
|
771
|
+
extra: "Extra",
|
|
771
772
|
from: "From",
|
|
772
773
|
hasCompatibleCollections: "Has Compatible Collections",
|
|
773
774
|
href: "Href",
|
|
@@ -941,6 +942,7 @@ var translations = {
|
|
|
941
942
|
description: "Descrizione",
|
|
942
943
|
details: "Dettagli",
|
|
943
944
|
englishName: "Nome Inglese",
|
|
945
|
+
extra: "Extra",
|
|
944
946
|
from: "Da",
|
|
945
947
|
hasCompatibleCollections: "Ha Collezioni Compatibili",
|
|
946
948
|
href: "Href",
|
|
@@ -1037,9 +1039,9 @@ var defaultGroup = {
|
|
|
1037
1039
|
i18n: "i18n",
|
|
1038
1040
|
admin: "admin"
|
|
1039
1041
|
};
|
|
1040
|
-
var defaultLocale = "en";
|
|
1041
1042
|
var defaultLocales = ["en", "it"];
|
|
1042
|
-
var
|
|
1043
|
+
var defaultLocale = process.env.DEFAULT_LOCALE || "en";
|
|
1044
|
+
var defaultMarket = process.env.DEFAULT_MARKET || "ww";
|
|
1043
1045
|
var options = {
|
|
1044
1046
|
collections: [],
|
|
1045
1047
|
defaultLocale,
|
|
@@ -1299,34 +1301,6 @@ var collectionBulkPatch = /* @__PURE__ */ __name((slug) => ({
|
|
|
1299
1301
|
console.log("collectionGet.error", error);
|
|
1300
1302
|
res.status(500).send(error);
|
|
1301
1303
|
}
|
|
1302
|
-
try {
|
|
1303
|
-
const payloadItems = req.body;
|
|
1304
|
-
const { modifiedCount } = await Model.bulkWrite(
|
|
1305
|
-
payloadItems.map((x) => ({
|
|
1306
|
-
updateOne: {
|
|
1307
|
-
filter: { _id: x.id },
|
|
1308
|
-
update: {
|
|
1309
|
-
category: x.category,
|
|
1310
|
-
order: x.order
|
|
1311
|
-
}
|
|
1312
|
-
/*
|
|
1313
|
-
update: {
|
|
1314
|
-
$set: {
|
|
1315
|
-
category: x.category,
|
|
1316
|
-
order: x.order
|
|
1317
|
-
}
|
|
1318
|
-
},
|
|
1319
|
-
*/
|
|
1320
|
-
}
|
|
1321
|
-
}))
|
|
1322
|
-
);
|
|
1323
|
-
console.log("modifiedCount", modifiedCount);
|
|
1324
|
-
const items = await getCollectionItems(req, slug);
|
|
1325
|
-
res.status(200).send(items);
|
|
1326
|
-
} catch (error) {
|
|
1327
|
-
console.log("collectionGet.error", error);
|
|
1328
|
-
res.status(500).send(error);
|
|
1329
|
-
}
|
|
1330
1304
|
}
|
|
1331
1305
|
}), "collectionBulkPatch");
|
|
1332
1306
|
var collectionUpdatePatch = /* @__PURE__ */ __name((slug) => ({
|
|
@@ -2453,7 +2427,7 @@ async function whereCollection(items, where) {
|
|
|
2453
2427
|
return items;
|
|
2454
2428
|
}
|
|
2455
2429
|
__name(whereCollection, "whereCollection");
|
|
2456
|
-
async function populateStaticFields(item, fields, locale
|
|
2430
|
+
async function populateStaticFields(item, fields, locale) {
|
|
2457
2431
|
const x = { ...item };
|
|
2458
2432
|
for (const field of fields) {
|
|
2459
2433
|
if (field.type === "relationship" && typeof field.relationTo === "string") {
|
|
@@ -2474,7 +2448,7 @@ async function populateStaticFields(item, fields, locale = "en") {
|
|
|
2474
2448
|
return x;
|
|
2475
2449
|
}
|
|
2476
2450
|
__name(populateStaticFields, "populateStaticFields");
|
|
2477
|
-
function localizeItem(item, localizedFields, locale
|
|
2451
|
+
function localizeItem(item, localizedFields, locale) {
|
|
2478
2452
|
let localizedItem = item;
|
|
2479
2453
|
if (localizedFields.length > 0) {
|
|
2480
2454
|
localizedItem = { ...item };
|
|
@@ -2579,7 +2553,7 @@ var withStaticCollection = /* @__PURE__ */ __name(({ src, map, duration, ...conf
|
|
|
2579
2553
|
let item = collection.find((x) => x.id === id);
|
|
2580
2554
|
if (item) {
|
|
2581
2555
|
if (depth !== 0 && Array.isArray(collectionConfig.fields)) {
|
|
2582
|
-
item = await populateStaticFields(item, collectionConfig.fields);
|
|
2556
|
+
item = await populateStaticFields(item, collectionConfig.fields, locale);
|
|
2583
2557
|
}
|
|
2584
2558
|
item = localizeItem(item, localizedFields, getStringParam(locale));
|
|
2585
2559
|
res.status(200).send(item);
|
|
@@ -2625,7 +2599,7 @@ var withCollection = /* @__PURE__ */ __name((config) => {
|
|
|
2625
2599
|
findMany
|
|
2626
2600
|
// boolean to denote if this hook is running against finding one, or finding many
|
|
2627
2601
|
}) => {
|
|
2628
|
-
if (doc && !findMany) {
|
|
2602
|
+
if (doc && !findMany && query) {
|
|
2629
2603
|
const { query: query2 } = req;
|
|
2630
2604
|
if (query2) {
|
|
2631
2605
|
const { locale } = query2;
|
|
@@ -2863,12 +2837,12 @@ async function getMarkets(req) {
|
|
|
2863
2837
|
return markets.filter((x) => x.isActive).map((x) => x.id);
|
|
2864
2838
|
}
|
|
2865
2839
|
__name(getMarkets, "getMarkets");
|
|
2866
|
-
async function decorateMenus(req, items, market
|
|
2840
|
+
async function decorateMenus(req, items, market, locale) {
|
|
2867
2841
|
const promises = items.map((x) => decorateMenu(req, x, market, locale));
|
|
2868
2842
|
return await Promise.all(promises);
|
|
2869
2843
|
}
|
|
2870
2844
|
__name(decorateMenus, "decorateMenus");
|
|
2871
|
-
async function decorateMenu(req, item, market
|
|
2845
|
+
async function decorateMenu(req, item, market, locale) {
|
|
2872
2846
|
const decoratedItem = {
|
|
2873
2847
|
id: item.id,
|
|
2874
2848
|
items: []
|
|
@@ -2894,7 +2868,8 @@ function decorateMenuCategory(item, categories, routes, market, depth = 0) {
|
|
|
2894
2868
|
title: "",
|
|
2895
2869
|
href: "",
|
|
2896
2870
|
category: "",
|
|
2897
|
-
items: []
|
|
2871
|
+
items: [],
|
|
2872
|
+
extra: item.extra
|
|
2898
2873
|
};
|
|
2899
2874
|
const category = typeof item.category === "string" ? categories.find((x) => x.id === item.category) : item.category;
|
|
2900
2875
|
if (category) {
|
|
@@ -2941,7 +2916,8 @@ function decorateMenuGroup(item, categories, routes, market) {
|
|
|
2941
2916
|
id: item.id,
|
|
2942
2917
|
type: item.type,
|
|
2943
2918
|
title: item.title,
|
|
2944
|
-
items: item.items.filter((x) => hasMarket(x, market)).map((x) => decorateMenuItem(x, categories, routes, market))
|
|
2919
|
+
items: item.items.filter((x) => hasMarket(x, market)).map((x) => decorateMenuItem(x, categories, routes, market)),
|
|
2920
|
+
extra: item.extra
|
|
2945
2921
|
};
|
|
2946
2922
|
return decoratedItem;
|
|
2947
2923
|
}
|
|
@@ -2953,13 +2929,16 @@ function decorateMenuLink(item, categories, routes, market) {
|
|
|
2953
2929
|
title: item.title,
|
|
2954
2930
|
href: item.href,
|
|
2955
2931
|
target: item.target,
|
|
2956
|
-
items: item.items.filter((x) => hasMarket(x, market)).map((x) => decorateMenuItem(x, categories, routes, market))
|
|
2932
|
+
items: item.items.filter((x) => hasMarket(x, market)).map((x) => decorateMenuItem(x, categories, routes, market)),
|
|
2933
|
+
extra: item.extra
|
|
2957
2934
|
};
|
|
2958
2935
|
return decoratedItem;
|
|
2959
2936
|
}
|
|
2960
2937
|
__name(decorateMenuLink, "decorateMenuLink");
|
|
2961
2938
|
function decorateMenuPage(item, categories, routes, market) {
|
|
2962
|
-
const route = routes.find(
|
|
2939
|
+
const route = routes.find(
|
|
2940
|
+
(x) => x.schema === item.page.relationTo && x.page === item.page.value.id
|
|
2941
|
+
);
|
|
2963
2942
|
const decoratedItem = {
|
|
2964
2943
|
id: item.id,
|
|
2965
2944
|
type: item.type,
|
|
@@ -2968,7 +2947,8 @@ function decorateMenuPage(item, categories, routes, market) {
|
|
|
2968
2947
|
media: item.page.value.media,
|
|
2969
2948
|
page: item.page.value.id,
|
|
2970
2949
|
schema: item.page.relationTo,
|
|
2971
|
-
items: item.items.filter((x) => hasMarket(x, market)).map((x) => decorateMenuItem(x, categories, routes, market))
|
|
2950
|
+
items: item.items.filter((x) => hasMarket(x, market)).map((x) => decorateMenuItem(x, categories, routes, market)),
|
|
2951
|
+
extra: item.extra
|
|
2972
2952
|
};
|
|
2973
2953
|
return decoratedItem;
|
|
2974
2954
|
}
|
|
@@ -3515,7 +3495,7 @@ __name(withLocalizedDescription, "withLocalizedDescription");
|
|
|
3515
3495
|
|
|
3516
3496
|
// src/core/api/page.service.ts
|
|
3517
3497
|
var USE_PAGE_COLLECTION = false;
|
|
3518
|
-
async function decorateHref(req, item, slug, market
|
|
3498
|
+
async function decorateHref(req, item, slug, market, locale) {
|
|
3519
3499
|
const route = (await getRoutes(req)).find(
|
|
3520
3500
|
(x) => x.schema === slug && x.page === item.id && x.market === market && x.locale === locale
|
|
3521
3501
|
);
|
|
@@ -3523,7 +3503,7 @@ async function decorateHref(req, item, slug, market = "ww", locale = "en") {
|
|
|
3523
3503
|
return { ...item, href };
|
|
3524
3504
|
}
|
|
3525
3505
|
__name(decorateHref, "decorateHref");
|
|
3526
|
-
async function decorateHrefs(req, items, slug, market
|
|
3506
|
+
async function decorateHrefs(req, items, slug, market, locale) {
|
|
3527
3507
|
const routes = (await getRoutes(req)).filter(
|
|
3528
3508
|
(x) => x.schema === slug && x.market === market && x.locale === locale
|
|
3529
3509
|
);
|
|
@@ -5185,7 +5165,6 @@ var MenuItem = /* @__PURE__ */ __name((options2, depth = 0, maxDepth = 10) => {
|
|
|
5185
5165
|
{
|
|
5186
5166
|
type: "withText",
|
|
5187
5167
|
name: "customTitle",
|
|
5188
|
-
label: "title",
|
|
5189
5168
|
localized: true,
|
|
5190
5169
|
admin: {
|
|
5191
5170
|
condition: (_, siblingData) => siblingData?.type === "category" || siblingData?.type === "page"
|
|
@@ -5202,7 +5181,13 @@ var MenuItem = /* @__PURE__ */ __name((options2, depth = 0, maxDepth = 10) => {
|
|
|
5202
5181
|
// custom class
|
|
5203
5182
|
{
|
|
5204
5183
|
type: "withText",
|
|
5205
|
-
|
|
5184
|
+
name: "customClass"
|
|
5185
|
+
},
|
|
5186
|
+
// extra
|
|
5187
|
+
{
|
|
5188
|
+
type: "withText",
|
|
5189
|
+
name: "extra",
|
|
5190
|
+
localized: true
|
|
5206
5191
|
}
|
|
5207
5192
|
]
|
|
5208
5193
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@websolutespa/payload-plugin-bowl",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Bowl PayloadCms plugin of the BOM Repository",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"payload",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
17
|
"lint": "eslint *.ts*",
|
|
18
|
-
"test": "jest",
|
|
18
|
+
"test": "jest --forceExit --runInBand --workerIdleMemoryLimit='1000MB'",
|
|
19
19
|
"test-watch": "npm test -- --watch",
|
|
20
20
|
"coverage:integration": "npm run test -- --coverage",
|
|
21
21
|
"coverage": "run-s -c --silent coverage:*",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/escape-html": "^1.0.2",
|
|
41
41
|
"@types/express": "^4.17.15",
|
|
42
|
+
"@types/uuid": "^9.0.2",
|
|
42
43
|
"@types/papaparse": "^5.3.7",
|
|
43
44
|
"@websolutespa/bom-cli": "*",
|
|
44
45
|
"@websolutespa/test": "*",
|
|
@@ -48,6 +49,7 @@
|
|
|
48
49
|
"eslint": "^8.46.0",
|
|
49
50
|
"eslint-config-websolute": "*",
|
|
50
51
|
"i18next": "^22.4.9",
|
|
52
|
+
"mongodb-memory-server": "^8.13.0",
|
|
51
53
|
"react": "^18.2.0",
|
|
52
54
|
"ts-node": "^10.9.1",
|
|
53
55
|
"tsup": "^6.7.0",
|