@websolutespa/bom-mixer-store 1.8.13 → 1.10.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/CHANGELOG.md CHANGED
@@ -1,10 +1,24 @@
1
1
  # @websolutespa/bom-mixer-store
2
2
 
3
+ ## 1.10.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Added: IApp global
8
+ - Updated dependencies
9
+ - @websolutespa/bom-core@1.8.24
10
+
11
+ ## 1.10.0
12
+
13
+ ### Patch Changes
14
+
15
+ - Modified: remote.service, Added: preview.handler
16
+
3
17
  ## 1.8.13
4
18
 
5
19
  ### Patch Changes
6
20
 
7
- - Fixing: decorators collectRelations_ depth 0
21
+ - Fixing: decorators collectRelations\_ depth 0
8
22
 
9
23
  ## 1.8.12
10
24
 
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { FetchRequestOptions, IEquatable, ICategory, IStore, QueryParams, ICategorized, IRoute, ISchema, IUndecoratedMenu, IMenu, IEntity, JsonService, IMemoryStore, IQuerable, IPagedResult } from '@websolutespa/bom-core';
1
+ import { FetchRequestOptions, IEquatable, ICategory, IStore, QueryParams, ICategorized, IRoute, ISchema, IUndecoratedMenu, IMenu, IEntity, JsonService, IMemoryStore, IQuerable, GlobalQueryParams, IPagedResult } from '@websolutespa/bom-core';
2
2
  import { NextApiRequest, NextApiResponse } from 'next';
3
3
  import { NextRequest } from 'next/server';
4
4
 
@@ -132,9 +132,8 @@ declare function mockHandler(): IHandler<any>;
132
132
  declare function getMockStoreFromData_<T extends IStore>(data?: IMemoryStore): T;
133
133
  declare function getMockStore<T extends IStore = IStore>(): Promise<T>;
134
134
 
135
- declare const RemoteServiceStrategy: {
136
- draft: boolean;
137
- };
135
+ declare function previewHandler(): IHandler<any>;
136
+
138
137
  /**
139
138
  * This service handle call to remote api (bowl or over)
140
139
  */
@@ -142,6 +141,7 @@ declare class RemoteService<T extends IEntity = IEntity> implements IQuerable<T>
142
141
  key: string;
143
142
  store: IStore;
144
143
  constructor(key: string, store: IStore);
144
+ findGlobal<B extends T = T>(params?: GlobalQueryParams, token?: string): Promise<B | undefined>;
145
145
  findOne<B extends T = T>(id: IEquatable, params?: Omit<QueryParams, 'where'>, token?: string): Promise<B | undefined>;
146
146
  findMany<B extends T = T>(params?: QueryParams, token?: string): Promise<B[]>;
147
147
  findPaged<B extends T = T>(params?: QueryParams, token?: string): Promise<IPagedResult<B>>;
@@ -252,4 +252,4 @@ declare function getStore<T extends IStore>(): Promise<T>;
252
252
 
253
253
  declare function varsHandler(): IHandler<any>;
254
254
 
255
- export { ApiRequestOptions, BuildStrategy, COLLECTIONS, DEFAULT_DEPTH, IApiHandler, ICrudMethod, IField, IHandler, IPageResolvedRelation, KNOWN_COLLECTIONS, MAX_INT, MOCK_COLLECTIONS, MapTo, MockMenuService, MockPageService, MockService, NextPhase, RemoteMenuService, RemotePageService, RemoteService, RemoteServiceStrategy, STATIC_COLLECTIONS, StaticService, StaticServiceConfig, StaticServiceSrc, StoreStrategy, apiHandler, buildStrategy, collectCategory_, collectionDelete, collectionGet, collectionPatch, collectionPost, decorateCategories_, decorateCategory_, decorateHref_, decorateHrefs_, decorateLocalizable_, decorateLocalizables_, decorateMenu_, decorateMenus_, decorateNav_, decorateNavs_, decorateRelation_, decorateRelations_, decorateSchema_, decorateSchemas_, decorateStaticRelation_, decorateStaticRelations_, errorHandler, findRoute, fromCache, getLocalApiRequestOptions, getLocalApiUrl, getMockStore, getMockStoreFromData_, getRemoteApiRequestOptions, getRemoteApiUrl, getRemoteStore, getStore, isApiRequest, isNextRequest, isStaticRequest, localApiDelete, localApiFetch, localApiGet, localApiPatch, localApiPost, localApiPut, mockApiDelete, mockApiFetch, mockApiGet, mockApiPatch, mockApiPost, mockApiPut, mockHandler, nextPhase, optimizeMany_, optimizeOne_, remoteApiDelete, remoteApiFetch, remoteApiGet, remoteApiPatch, remoteApiPost, remoteApiPut, routePost, staticCollections, storeApiDelete, storeApiGet, storeApiPatch, storeApiPost, storeApiPut, storeCacheDuration, storeHandler, storeIndexHandler, storeStrategy, varsHandler };
255
+ export { ApiRequestOptions, BuildStrategy, COLLECTIONS, DEFAULT_DEPTH, IApiHandler, ICrudMethod, IField, IHandler, IPageResolvedRelation, KNOWN_COLLECTIONS, MAX_INT, MOCK_COLLECTIONS, MapTo, MockMenuService, MockPageService, MockService, NextPhase, RemoteMenuService, RemotePageService, RemoteService, STATIC_COLLECTIONS, StaticService, StaticServiceConfig, StaticServiceSrc, StoreStrategy, apiHandler, buildStrategy, collectCategory_, collectionDelete, collectionGet, collectionPatch, collectionPost, decorateCategories_, decorateCategory_, decorateHref_, decorateHrefs_, decorateLocalizable_, decorateLocalizables_, decorateMenu_, decorateMenus_, decorateNav_, decorateNavs_, decorateRelation_, decorateRelations_, decorateSchema_, decorateSchemas_, decorateStaticRelation_, decorateStaticRelations_, errorHandler, findRoute, fromCache, getLocalApiRequestOptions, getLocalApiUrl, getMockStore, getMockStoreFromData_, getRemoteApiRequestOptions, getRemoteApiUrl, getRemoteStore, getStore, isApiRequest, isNextRequest, isStaticRequest, localApiDelete, localApiFetch, localApiGet, localApiPatch, localApiPost, localApiPut, mockApiDelete, mockApiFetch, mockApiGet, mockApiPatch, mockApiPost, mockApiPut, mockHandler, nextPhase, optimizeMany_, optimizeOne_, previewHandler, remoteApiDelete, remoteApiFetch, remoteApiGet, remoteApiPatch, remoteApiPost, remoteApiPut, routePost, staticCollections, storeApiDelete, storeApiGet, storeApiPatch, storeApiPost, storeApiPut, storeCacheDuration, storeHandler, storeIndexHandler, storeStrategy, varsHandler };
package/dist/index.js CHANGED
@@ -43,7 +43,6 @@ __export(src_exports, {
43
43
  RemoteMenuService: () => RemoteMenuService,
44
44
  RemotePageService: () => RemotePageService,
45
45
  RemoteService: () => RemoteService,
46
- RemoteServiceStrategy: () => RemoteServiceStrategy,
47
46
  STATIC_COLLECTIONS: () => STATIC_COLLECTIONS,
48
47
  StaticService: () => StaticService,
49
48
  StoreStrategy: () => StoreStrategy,
@@ -100,6 +99,7 @@ __export(src_exports, {
100
99
  nextPhase: () => nextPhase,
101
100
  optimizeMany_: () => optimizeMany_,
102
101
  optimizeOne_: () => optimizeOne_,
102
+ previewHandler: () => previewHandler,
103
103
  remoteApiDelete: () => remoteApiDelete,
104
104
  remoteApiFetch: () => remoteApiFetch,
105
105
  remoteApiGet: () => remoteApiGet,
@@ -1178,6 +1178,7 @@ var ENV_COLLECTIONS = process.env.COLLECTIONS ? process.env.COLLECTIONS.split(",
1178
1178
  var MOCK_COLLECTIONS = process.env.MOCKS ? process.env.MOCKS.split(",") : [];
1179
1179
  var STATIC_COLLECTIONS = staticCollections.map((x) => x.slug);
1180
1180
  var KNOWN_COLLECTIONS = [
1181
+ "app",
1181
1182
  "category",
1182
1183
  "label",
1183
1184
  "locale",
@@ -1428,6 +1429,13 @@ var CachedService = class extends import_bom_core12.JsonService {
1428
1429
  data
1429
1430
  });
1430
1431
  }
1432
+ async findGlobal(params = {}) {
1433
+ const serializedParams = (0, import_bom_core12.qsSerialize)(params);
1434
+ const key = `findGlobal?${serializedParams}`;
1435
+ return await this.fromCache_(async () => {
1436
+ return await this.service_.findGlobal(params);
1437
+ }, key);
1438
+ }
1431
1439
  async findOne(id, params = {}) {
1432
1440
  const serializedParams = (0, import_bom_core12.qsSerialize)(params);
1433
1441
  const key = `findOne[${id}]?${serializedParams}`;
@@ -1528,9 +1536,6 @@ async function remoteApiDelete(url, options = {}) {
1528
1536
  }
1529
1537
 
1530
1538
  // src/remote/remote.service.ts
1531
- var RemoteServiceStrategy = {
1532
- draft: false
1533
- };
1534
1539
  var RemoteService = class {
1535
1540
  constructor(key, store) {
1536
1541
  if (!key) {
@@ -1542,9 +1547,23 @@ var RemoteService = class {
1542
1547
  this.key = key;
1543
1548
  this.store = store;
1544
1549
  }
1550
+ async findGlobal(params = {}, token) {
1551
+ params.richText = String(params.richText) === "true" ? true : false;
1552
+ const query = (0, import_bom_core14.qsSerialize)(params);
1553
+ const search = query ? `?${query}` : "";
1554
+ const url = `/globals/${this.key}${search}`;
1555
+ try {
1556
+ const item = await remoteApiGet(url, getRemoteApiRequestOptions(token));
1557
+ if (item) {
1558
+ return await this.decorateOne_(item, params);
1559
+ }
1560
+ } catch (error) {
1561
+ console.log("RemoteService", this.key, "findGlobal.error");
1562
+ }
1563
+ return;
1564
+ }
1545
1565
  async findOne(id, params = {}, token) {
1546
1566
  params.richText = String(params.richText) === "true" ? true : false;
1547
- params.draft = RemoteServiceStrategy.draft;
1548
1567
  const query = (0, import_bom_core14.qsSerialize)(params);
1549
1568
  const search = query ? `?${query}` : "";
1550
1569
  const url = `/${this.key}/${encodeURIComponent(id)}${search}`;
@@ -1560,7 +1579,6 @@ var RemoteService = class {
1560
1579
  }
1561
1580
  async findMany(params = {}, token) {
1562
1581
  params.richText = String(params.richText) === "true" ? true : false;
1563
- params.draft = RemoteServiceStrategy.draft;
1564
1582
  params.pagination = false;
1565
1583
  const query = (0, import_bom_core14.qsSerialize)(params);
1566
1584
  const search = query ? `?${query}` : "";
@@ -1571,7 +1589,6 @@ var RemoteService = class {
1571
1589
  }
1572
1590
  async findPaged(params = {}, token) {
1573
1591
  params.richText = String(params.richText) === "true" ? true : false;
1574
- params.draft = RemoteServiceStrategy.draft;
1575
1592
  params.pagination = true;
1576
1593
  const query = (0, import_bom_core14.qsSerialize)(params);
1577
1594
  const search = query ? `?${query}` : "";
@@ -1583,7 +1600,6 @@ var RemoteService = class {
1583
1600
  }
1584
1601
  async create(payload, params = {}, token) {
1585
1602
  params.richText = String(params.richText) === "true" ? true : false;
1586
- params.draft = RemoteServiceStrategy.draft;
1587
1603
  const query = (0, import_bom_core14.qsSerialize)(params);
1588
1604
  const search = query ? `?${query}` : "";
1589
1605
  const url = `/${this.key}${search}`;
@@ -1601,7 +1617,6 @@ var RemoteService = class {
1601
1617
  }
1602
1618
  async updateMany(payload, params = {}, token) {
1603
1619
  params.richText = String(params.richText) === "true" ? true : false;
1604
- params.draft = RemoteServiceStrategy.draft;
1605
1620
  params.pagination = false;
1606
1621
  const query = (0, import_bom_core14.qsSerialize)(params);
1607
1622
  const search = query ? `?${query}` : "";
@@ -1619,7 +1634,6 @@ var RemoteService = class {
1619
1634
  }
1620
1635
  async deleteMany(params = {}, token) {
1621
1636
  params.richText = String(params.richText) === "true" ? true : false;
1622
- params.draft = RemoteServiceStrategy.draft;
1623
1637
  params.pagination = false;
1624
1638
  const query = (0, import_bom_core14.qsSerialize)(params);
1625
1639
  const search = query ? `?${query}` : "";
@@ -2242,6 +2256,23 @@ function mockHandler() {
2242
2256
  return storeHandler(async () => await getMockStore());
2243
2257
  }
2244
2258
 
2259
+ // src/preview/preview.handler.ts
2260
+ function previewHandler() {
2261
+ return apiHandler({
2262
+ options: async (request, response) => {
2263
+ response.status(200).end();
2264
+ },
2265
+ get: async (request, response) => {
2266
+ const query = request.query;
2267
+ const { marketId, localeId, templateId, documentId, _status } = query;
2268
+ const destination = `/${marketId}/${localeId}/${templateId}/${documentId}${query._live ? "?_live=true" : ""}`;
2269
+ response.setPreviewData({ _status });
2270
+ response.setDraftMode({ enable: true });
2271
+ response.redirect(307, destination);
2272
+ }
2273
+ });
2274
+ }
2275
+
2245
2276
  // src/store/store.api.ts
2246
2277
  var storeApiFetch = storeStrategy === "mock" /* Mock */ ? localApiFetch : remoteApiFetch;
2247
2278
  async function storeApiGet(url, options = {}) {
@@ -2270,6 +2301,13 @@ async function getLabels(params = {}) {
2270
2301
  return items;
2271
2302
  }
2272
2303
 
2304
+ // ../models/src/app/app.service.ts
2305
+ async function getApp(params = {}) {
2306
+ const store = await getStore();
2307
+ const item = await store.app.findGlobal(params);
2308
+ return item;
2309
+ }
2310
+
2273
2311
  // ../models/src/locale/locale.service.ts
2274
2312
  async function getLocales(params = {}) {
2275
2313
  const store = await getStore();
@@ -2308,23 +2346,29 @@ async function getRouteLinkTree(market, locale) {
2308
2346
  const categories = await store.category.findMany({ market, locale });
2309
2347
  const rootCategory = (0, import_bom_core16.getRootCategory)(categories);
2310
2348
  if (rootCategory) {
2311
- const root = categoryToRouteLink(routes, categories, rootCategory, locale);
2349
+ const root = getRouteLinkCategory(locale, routes, categories, rootCategory, rootCategory);
2312
2350
  return root;
2313
2351
  }
2314
2352
  return void 0;
2315
2353
  }
2316
- function categoryToRouteLink(routes, categories, category, locale) {
2354
+ function getRouteLinkCategory(locale, routes, categories, rootCategory, category) {
2317
2355
  const route = (0, import_bom_core16.findRouteOfCategory)(routes, category.id);
2318
- if (!route) {
2319
- return void 0;
2320
- }
2321
- const rootCategory = (0, import_bom_core16.getRootCategory)(categories);
2322
- const childCategories = categories.filter((x) => {
2323
- const parentId = (0, import_bom_core16.asCategoryId)(x.category);
2324
- return rootCategory && rootCategory.id === category.id ? x.id !== rootCategory.id && (parentId === category.id || !parentId) : parentId === category.id;
2325
- });
2356
+ const otherCategories = categories.filter((x) => x.id !== category.id);
2357
+ const childCategories = otherCategories.filter((x) => (0, import_bom_core16.asCategoryId)(x.category) === category.id);
2326
2358
  const routeLink = newRouteLink(category, route, locale);
2327
- routeLink.items = childCategories.map((x) => categoryToRouteLink(routes, categories, x, locale)).filter((x) => x !== void 0);
2359
+ const items = [];
2360
+ for (const childCategory of childCategories) {
2361
+ const itemOrItems = getRouteLinkCategory(locale, routes, otherCategories, rootCategory, childCategory);
2362
+ if (Array.isArray(itemOrItems)) {
2363
+ items.push(...itemOrItems);
2364
+ } else if (itemOrItems) {
2365
+ items.push(itemOrItems);
2366
+ }
2367
+ }
2368
+ if (!route || category.isHidden && category.id !== rootCategory.id) {
2369
+ return items;
2370
+ }
2371
+ routeLink.items = items;
2328
2372
  return routeLink;
2329
2373
  }
2330
2374
  function newRouteLink(category, route, locale) {
@@ -2350,6 +2394,7 @@ async function getLayout(market, locale) {
2350
2394
  const markets = await getMarkets({ locale });
2351
2395
  const locales = await getLocales({ locale });
2352
2396
  const labels = await getLabels({ locale });
2397
+ const app = await getApp({ locale }) || {};
2353
2398
  const tree = await getRouteLinkTree(market, locale);
2354
2399
  const firstLevelRoutes = tree?.items || [];
2355
2400
  const flatTopLevelRoutes = tree ? [tree, ...firstLevelRoutes] : [];
@@ -2376,6 +2421,7 @@ async function getLayout(market, locale) {
2376
2421
  locales,
2377
2422
  market,
2378
2423
  markets,
2424
+ app,
2379
2425
  menu,
2380
2426
  topLevelHrefs,
2381
2427
  topLevelRoutes,
@@ -2539,7 +2585,6 @@ function varsHandler() {
2539
2585
  RemoteMenuService,
2540
2586
  RemotePageService,
2541
2587
  RemoteService,
2542
- RemoteServiceStrategy,
2543
2588
  STATIC_COLLECTIONS,
2544
2589
  StaticService,
2545
2590
  StoreStrategy,
@@ -2596,6 +2641,7 @@ function varsHandler() {
2596
2641
  nextPhase,
2597
2642
  optimizeMany_,
2598
2643
  optimizeOne_,
2644
+ previewHandler,
2599
2645
  remoteApiDelete,
2600
2646
  remoteApiFetch,
2601
2647
  remoteApiGet,
package/dist/index.mjs CHANGED
@@ -1073,6 +1073,7 @@ var ENV_COLLECTIONS = process.env.COLLECTIONS ? process.env.COLLECTIONS.split(",
1073
1073
  var MOCK_COLLECTIONS = process.env.MOCKS ? process.env.MOCKS.split(",") : [];
1074
1074
  var STATIC_COLLECTIONS = staticCollections.map((x) => x.slug);
1075
1075
  var KNOWN_COLLECTIONS = [
1076
+ "app",
1076
1077
  "category",
1077
1078
  "label",
1078
1079
  "locale",
@@ -1323,6 +1324,13 @@ var CachedService = class extends JsonService3 {
1323
1324
  data
1324
1325
  });
1325
1326
  }
1327
+ async findGlobal(params = {}) {
1328
+ const serializedParams = qsSerialize(params);
1329
+ const key = `findGlobal?${serializedParams}`;
1330
+ return await this.fromCache_(async () => {
1331
+ return await this.service_.findGlobal(params);
1332
+ }, key);
1333
+ }
1326
1334
  async findOne(id, params = {}) {
1327
1335
  const serializedParams = qsSerialize(params);
1328
1336
  const key = `findOne[${id}]?${serializedParams}`;
@@ -1423,9 +1431,6 @@ async function remoteApiDelete(url, options = {}) {
1423
1431
  }
1424
1432
 
1425
1433
  // src/remote/remote.service.ts
1426
- var RemoteServiceStrategy = {
1427
- draft: false
1428
- };
1429
1434
  var RemoteService = class {
1430
1435
  constructor(key, store) {
1431
1436
  if (!key) {
@@ -1437,9 +1442,23 @@ var RemoteService = class {
1437
1442
  this.key = key;
1438
1443
  this.store = store;
1439
1444
  }
1445
+ async findGlobal(params = {}, token) {
1446
+ params.richText = String(params.richText) === "true" ? true : false;
1447
+ const query = qsSerialize2(params);
1448
+ const search = query ? `?${query}` : "";
1449
+ const url = `/globals/${this.key}${search}`;
1450
+ try {
1451
+ const item = await remoteApiGet(url, getRemoteApiRequestOptions(token));
1452
+ if (item) {
1453
+ return await this.decorateOne_(item, params);
1454
+ }
1455
+ } catch (error) {
1456
+ console.log("RemoteService", this.key, "findGlobal.error");
1457
+ }
1458
+ return;
1459
+ }
1440
1460
  async findOne(id, params = {}, token) {
1441
1461
  params.richText = String(params.richText) === "true" ? true : false;
1442
- params.draft = RemoteServiceStrategy.draft;
1443
1462
  const query = qsSerialize2(params);
1444
1463
  const search = query ? `?${query}` : "";
1445
1464
  const url = `/${this.key}/${encodeURIComponent(id)}${search}`;
@@ -1455,7 +1474,6 @@ var RemoteService = class {
1455
1474
  }
1456
1475
  async findMany(params = {}, token) {
1457
1476
  params.richText = String(params.richText) === "true" ? true : false;
1458
- params.draft = RemoteServiceStrategy.draft;
1459
1477
  params.pagination = false;
1460
1478
  const query = qsSerialize2(params);
1461
1479
  const search = query ? `?${query}` : "";
@@ -1466,7 +1484,6 @@ var RemoteService = class {
1466
1484
  }
1467
1485
  async findPaged(params = {}, token) {
1468
1486
  params.richText = String(params.richText) === "true" ? true : false;
1469
- params.draft = RemoteServiceStrategy.draft;
1470
1487
  params.pagination = true;
1471
1488
  const query = qsSerialize2(params);
1472
1489
  const search = query ? `?${query}` : "";
@@ -1478,7 +1495,6 @@ var RemoteService = class {
1478
1495
  }
1479
1496
  async create(payload, params = {}, token) {
1480
1497
  params.richText = String(params.richText) === "true" ? true : false;
1481
- params.draft = RemoteServiceStrategy.draft;
1482
1498
  const query = qsSerialize2(params);
1483
1499
  const search = query ? `?${query}` : "";
1484
1500
  const url = `/${this.key}${search}`;
@@ -1496,7 +1512,6 @@ var RemoteService = class {
1496
1512
  }
1497
1513
  async updateMany(payload, params = {}, token) {
1498
1514
  params.richText = String(params.richText) === "true" ? true : false;
1499
- params.draft = RemoteServiceStrategy.draft;
1500
1515
  params.pagination = false;
1501
1516
  const query = qsSerialize2(params);
1502
1517
  const search = query ? `?${query}` : "";
@@ -1514,7 +1529,6 @@ var RemoteService = class {
1514
1529
  }
1515
1530
  async deleteMany(params = {}, token) {
1516
1531
  params.richText = String(params.richText) === "true" ? true : false;
1517
- params.draft = RemoteServiceStrategy.draft;
1518
1532
  params.pagination = false;
1519
1533
  const query = qsSerialize2(params);
1520
1534
  const search = query ? `?${query}` : "";
@@ -2137,6 +2151,23 @@ function mockHandler() {
2137
2151
  return storeHandler(async () => await getMockStore());
2138
2152
  }
2139
2153
 
2154
+ // src/preview/preview.handler.ts
2155
+ function previewHandler() {
2156
+ return apiHandler({
2157
+ options: async (request, response) => {
2158
+ response.status(200).end();
2159
+ },
2160
+ get: async (request, response) => {
2161
+ const query = request.query;
2162
+ const { marketId, localeId, templateId, documentId, _status } = query;
2163
+ const destination = `/${marketId}/${localeId}/${templateId}/${documentId}${query._live ? "?_live=true" : ""}`;
2164
+ response.setPreviewData({ _status });
2165
+ response.setDraftMode({ enable: true });
2166
+ response.redirect(307, destination);
2167
+ }
2168
+ });
2169
+ }
2170
+
2140
2171
  // src/store/store.api.ts
2141
2172
  var storeApiFetch = storeStrategy === "mock" /* Mock */ ? localApiFetch : remoteApiFetch;
2142
2173
  async function storeApiGet(url, options = {}) {
@@ -2165,6 +2196,13 @@ async function getLabels(params = {}) {
2165
2196
  return items;
2166
2197
  }
2167
2198
 
2199
+ // ../models/src/app/app.service.ts
2200
+ async function getApp(params = {}) {
2201
+ const store = await getStore();
2202
+ const item = await store.app.findGlobal(params);
2203
+ return item;
2204
+ }
2205
+
2168
2206
  // ../models/src/locale/locale.service.ts
2169
2207
  async function getLocales(params = {}) {
2170
2208
  const store = await getStore();
@@ -2203,23 +2241,29 @@ async function getRouteLinkTree(market, locale) {
2203
2241
  const categories = await store.category.findMany({ market, locale });
2204
2242
  const rootCategory = getRootCategory(categories);
2205
2243
  if (rootCategory) {
2206
- const root = categoryToRouteLink(routes, categories, rootCategory, locale);
2244
+ const root = getRouteLinkCategory(locale, routes, categories, rootCategory, rootCategory);
2207
2245
  return root;
2208
2246
  }
2209
2247
  return void 0;
2210
2248
  }
2211
- function categoryToRouteLink(routes, categories, category, locale) {
2249
+ function getRouteLinkCategory(locale, routes, categories, rootCategory, category) {
2212
2250
  const route = findRouteOfCategory3(routes, category.id);
2213
- if (!route) {
2214
- return void 0;
2215
- }
2216
- const rootCategory = getRootCategory(categories);
2217
- const childCategories = categories.filter((x) => {
2218
- const parentId = asCategoryId2(x.category);
2219
- return rootCategory && rootCategory.id === category.id ? x.id !== rootCategory.id && (parentId === category.id || !parentId) : parentId === category.id;
2220
- });
2251
+ const otherCategories = categories.filter((x) => x.id !== category.id);
2252
+ const childCategories = otherCategories.filter((x) => asCategoryId2(x.category) === category.id);
2221
2253
  const routeLink = newRouteLink(category, route, locale);
2222
- routeLink.items = childCategories.map((x) => categoryToRouteLink(routes, categories, x, locale)).filter((x) => x !== void 0);
2254
+ const items = [];
2255
+ for (const childCategory of childCategories) {
2256
+ const itemOrItems = getRouteLinkCategory(locale, routes, otherCategories, rootCategory, childCategory);
2257
+ if (Array.isArray(itemOrItems)) {
2258
+ items.push(...itemOrItems);
2259
+ } else if (itemOrItems) {
2260
+ items.push(itemOrItems);
2261
+ }
2262
+ }
2263
+ if (!route || category.isHidden && category.id !== rootCategory.id) {
2264
+ return items;
2265
+ }
2266
+ routeLink.items = items;
2223
2267
  return routeLink;
2224
2268
  }
2225
2269
  function newRouteLink(category, route, locale) {
@@ -2245,6 +2289,7 @@ async function getLayout(market, locale) {
2245
2289
  const markets = await getMarkets({ locale });
2246
2290
  const locales = await getLocales({ locale });
2247
2291
  const labels = await getLabels({ locale });
2292
+ const app = await getApp({ locale }) || {};
2248
2293
  const tree = await getRouteLinkTree(market, locale);
2249
2294
  const firstLevelRoutes = tree?.items || [];
2250
2295
  const flatTopLevelRoutes = tree ? [tree, ...firstLevelRoutes] : [];
@@ -2271,6 +2316,7 @@ async function getLayout(market, locale) {
2271
2316
  locales,
2272
2317
  market,
2273
2318
  markets,
2319
+ app,
2274
2320
  menu,
2275
2321
  topLevelHrefs,
2276
2322
  topLevelRoutes,
@@ -2433,7 +2479,6 @@ export {
2433
2479
  RemoteMenuService,
2434
2480
  RemotePageService,
2435
2481
  RemoteService,
2436
- RemoteServiceStrategy,
2437
2482
  STATIC_COLLECTIONS,
2438
2483
  StaticService,
2439
2484
  StoreStrategy,
@@ -2490,6 +2535,7 @@ export {
2490
2535
  nextPhase,
2491
2536
  optimizeMany_,
2492
2537
  optimizeOne_,
2538
+ previewHandler,
2493
2539
  remoteApiDelete,
2494
2540
  remoteApiFetch,
2495
2541
  remoteApiGet,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/bom-mixer-store",
3
- "version": "1.8.13",
3
+ "version": "1.10.1",
4
4
  "description": "Mixer Store module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",
@@ -1,4 +1,4 @@
1
- import { IEntity, IEquatable, IPagedResult, IQuerable, JsonService, QueryParams, qsSerialize } from '@websolutespa/bom-core';
1
+ import { GlobalQueryParams, IEntity, IEquatable, IPagedResult, IQuerable, JsonService, QueryParams, qsSerialize } from '@websolutespa/bom-core';
2
2
  import { StoreStrategy, storeCacheDuration, storeStrategy } from '../store/store';
3
3
 
4
4
  export type ICacheResult<T extends IEntity = IEntity> = T | T[] | IPagedResult<T> | undefined;
@@ -60,6 +60,14 @@ export class CachedService<T extends IEntity = IEntity> extends JsonService<T> {
60
60
  });
61
61
  }
62
62
 
63
+ async findGlobal<B extends T = T>(params: GlobalQueryParams = {}): Promise<B | undefined> {
64
+ const serializedParams = qsSerialize(params);
65
+ const key = `findGlobal?${serializedParams}`;
66
+ return await this.fromCache_(async () => {
67
+ return await this.service_.findGlobal(params);
68
+ }, key) as B | undefined;
69
+ }
70
+
63
71
  async findOne<B extends T = T>(id: IEquatable, params: QueryParams = {}): Promise<B | undefined> {
64
72
  const serializedParams = qsSerialize(params);
65
73
  const key = `findOne[${id}]?${serializedParams}`;
package/src/index.ts CHANGED
@@ -10,6 +10,7 @@ export * from './mock/mock.api';
10
10
  export * from './mock/mock.handler';
11
11
  export * from './mock/mock.service';
12
12
  export * from './mock/mock.store';
13
+ export * from './preview/preview.handler';
13
14
  export * from './remote/remote-menu.service';
14
15
  export * from './remote/remote-page.service';
15
16
  export * from './remote/remote.api';
@@ -0,0 +1,26 @@
1
+ import { NextApiRequest, NextApiResponse } from 'next';
2
+ import { apiHandler } from '../api/api.handler';
3
+
4
+ export function previewHandler() {
5
+ return apiHandler({
6
+ options: async (request: NextApiRequest, response: NextApiResponse) => {
7
+ response.status(200).end();
8
+ },
9
+ get: async (request: NextApiRequest, response: NextApiResponse) => {
10
+ const query = request.query as {
11
+ marketId: string;
12
+ localeId: string;
13
+ templateId: string;
14
+ documentId: string;
15
+ _status: 'published' | 'draft';
16
+ _live: string;
17
+ _token: string;
18
+ };
19
+ const { marketId, localeId, templateId, documentId, _status } = query;
20
+ const destination = `/${marketId}/${localeId}/${templateId}/${documentId}${query._live ? '?_live=true' : ''}`;
21
+ response.setPreviewData({ _status });
22
+ response.setDraftMode({ enable: true });
23
+ response.redirect(307, destination);
24
+ },
25
+ });
26
+ }
@@ -1,12 +1,8 @@
1
- import { IEntity, IEquatable, IPagedResult, IQuerable, IStore, qsSerialize, QueryParams } from '@websolutespa/bom-core';
1
+ import { GlobalQueryParams, IEntity, IEquatable, IPagedResult, IQuerable, IStore, qsSerialize, QueryParams } from '@websolutespa/bom-core';
2
2
  import { getRemoteApiRequestOptions } from '../api/api';
3
3
  import { decorateSchema_, decorateSchemas_ } from '../decorators';
4
4
  import { remoteApiDelete, remoteApiGet, remoteApiPatch, remoteApiPost } from './remote.api';
5
5
 
6
- export const RemoteServiceStrategy = {
7
- draft: false,
8
- };
9
-
10
6
  /**
11
7
  * This service handle call to remote api (bowl or over)
12
8
  */
@@ -26,9 +22,25 @@ export class RemoteService<T extends IEntity = IEntity> implements IQuerable<T>
26
22
  this.store = store;
27
23
  }
28
24
 
25
+ async findGlobal<B extends T = T>(params: GlobalQueryParams = {}, token?: string): Promise<B | undefined> {
26
+ params.richText = String(params.richText) === 'true' ? true : false;
27
+ const query = qsSerialize(params);
28
+ const search = query ? `?${query}` : '';
29
+ const url = `/globals/${this.key}${search}`;
30
+ // console.log('RemoteService', this.key, 'findGlobal', url);
31
+ try {
32
+ const item = await remoteApiGet<B>(url, getRemoteApiRequestOptions(token));
33
+ if (item) {
34
+ return await this.decorateOne_(item, params);
35
+ }
36
+ } catch (error) {
37
+ console.log('RemoteService', this.key, 'findGlobal.error');
38
+ }
39
+ return;
40
+ }
41
+
29
42
  async findOne<B extends T = T>(id: IEquatable, params: Omit<QueryParams, 'where'> = {}, token?: string): Promise<B | undefined> {
30
43
  params.richText = String(params.richText) === 'true' ? true : false;
31
- params.draft = RemoteServiceStrategy.draft;
32
44
  const query = qsSerialize(params);
33
45
  const search = query ? `?${query}` : '';
34
46
  const url = `/${this.key}/${encodeURIComponent(id)}${search}`;
@@ -46,7 +58,6 @@ export class RemoteService<T extends IEntity = IEntity> implements IQuerable<T>
46
58
 
47
59
  async findMany<B extends T = T>(params: QueryParams = {}, token?: string): Promise<B[]> {
48
60
  params.richText = String(params.richText) === 'true' ? true : false;
49
- params.draft = RemoteServiceStrategy.draft;
50
61
  params.pagination = false;
51
62
  const query = qsSerialize(params);
52
63
  const search = query ? `?${query}` : '';
@@ -59,7 +70,6 @@ export class RemoteService<T extends IEntity = IEntity> implements IQuerable<T>
59
70
 
60
71
  async findPaged<B extends T = T>(params: QueryParams = {}, token?: string): Promise<IPagedResult<B>> {
61
72
  params.richText = String(params.richText) === 'true' ? true : false;
62
- params.draft = RemoteServiceStrategy.draft;
63
73
  params.pagination = true;
64
74
  const query = qsSerialize(params);
65
75
  const search = query ? `?${query}` : '';
@@ -73,7 +83,6 @@ export class RemoteService<T extends IEntity = IEntity> implements IQuerable<T>
73
83
 
74
84
  async create<B extends T = T>(payload: Omit<B, 'id'>, params: QueryParams = {}, token?: string): Promise<B> {
75
85
  params.richText = String(params.richText) === 'true' ? true : false;
76
- params.draft = RemoteServiceStrategy.draft;
77
86
  const query = qsSerialize(params);
78
87
  const search = query ? `?${query}` : '';
79
88
  const url = `/${this.key}${search}`;
@@ -95,7 +104,6 @@ export class RemoteService<T extends IEntity = IEntity> implements IQuerable<T>
95
104
 
96
105
  async updateMany<B extends T = T>(payload: Partial<B>, params: QueryParams = {}, token?: string): Promise<B[]> {
97
106
  params.richText = String(params.richText) === 'true' ? true : false;
98
- params.draft = RemoteServiceStrategy.draft;
99
107
  params.pagination = false;
100
108
  const query = qsSerialize(params);
101
109
  const search = query ? `?${query}` : '';
@@ -117,7 +125,6 @@ export class RemoteService<T extends IEntity = IEntity> implements IQuerable<T>
117
125
 
118
126
  async deleteMany<B extends T = T>(params: QueryParams = {}, token?: string): Promise<B[]> {
119
127
  params.richText = String(params.richText) === 'true' ? true : false;
120
- params.draft = RemoteServiceStrategy.draft;
121
128
  params.pagination = false;
122
129
  const query = qsSerialize(params);
123
130
  const search = query ? `?${query}` : '';
@@ -69,6 +69,7 @@ const ENV_COLLECTIONS: string[] = process.env.COLLECTIONS ? process.env.COLLECTI
69
69
  export const MOCK_COLLECTIONS: string[] = process.env.MOCKS ? process.env.MOCKS.split(',') : [];
70
70
  export const STATIC_COLLECTIONS: string[] = staticCollections.map(x => x.slug);
71
71
  export const KNOWN_COLLECTIONS: string[] = [
72
+ 'app',
72
73
  'category',
73
74
  'label',
74
75
  'locale',