@websolutespa/bom-mixer-store 1.7.3 → 1.7.5

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,178 +1,194 @@
1
- # @websolutespa/bom-mixer-store
2
-
3
- ## 1.7.3
4
-
5
- ### Patch Changes
6
-
7
- - Updating: dependencies
8
- - Updated dependencies
9
- - @websolutespa/bom-core@1.7.3
10
-
11
- ## 1.7.2
12
-
13
- ### Patch Changes
14
-
15
- - 7898849: Modified: exporting getRemoteApiUrl
16
-
17
- ## 1.7.1
18
-
19
- ### Patch Changes
20
-
21
- - Fixing: findRoute redirects
22
-
23
- ## 1.7.0
24
-
25
- ### Minor Changes
26
-
27
- - 28e86bd: Modified: IPage, Store services & decorators
28
- - Updated dependencies [28e86bd]
29
- - @websolutespa/bom-core@1.7.0
30
-
31
- ## 1.6.0
32
-
33
- ### Patch Changes
34
-
35
- - f664993: Added: useLivePreview
36
- - Updated dependencies [6cbf4cb]
37
- - @websolutespa/bom-core@0.6.7
38
-
39
- ## 1.4.6
40
-
41
- ### Patch Changes
42
-
43
- - Fixing: CachedService findMany DecoratedApi
44
-
45
- ## 1.4.5
46
-
47
- ### Patch Changes
48
-
49
- - Fixing: decorateSchema
50
-
51
- ## 1.4.4
52
-
53
- ### Patch Changes
54
-
55
- - Added: Schema decorator
56
- - Modified: RemoteMenuService, RemotePageService, RemoteService
57
- - Updated dependencies
58
- - @websolutespa/bom-core@0.6.5
59
-
60
- ## 1.4.3
61
-
62
- ### Patch Changes
63
-
64
- - Modified: CachedService, Decorators, LocalApi, MockApi, MockStore, RemoteApi, RemoteStore, StoreHandler
65
-
66
- ## 1.4.2
67
-
68
- ### Patch Changes
69
-
70
- - Added: Decorators, CachedService, RemotePageService, RemoteMenuService, StoreStrategy.DecoratedApi, nextPhase, storeCacheDuration
71
- - Modified: RemoteStore
72
- - Updated dependencies
73
- - @websolutespa/bom-core@0.6.4
74
-
75
- ## 1.4.1
76
-
77
- ### Patch Changes
78
-
79
- - Modified: MockPageService
80
- - Updated dependencies
81
- - @websolutespa/bom-core@0.6.3
82
-
83
- ## 1.4.0
84
-
85
- ### Minor Changes
86
-
87
- - Added: BuildStrategy
88
-
89
- ## 1.3.0
90
-
91
- ### Minor Changes
92
-
93
- - Added: storeIndexHandler
94
- - Modified: Store, StoreHandler, RemoteService, MockService, MockPageService, MockMenuService, StaticService
95
-
96
- ## 1.2.2
97
-
98
- ### Patch Changes
99
-
100
- - Modified: MockMenuService IPageRelationResult
101
-
102
- ## 1.2.1
103
-
104
- ### Patch Changes
105
-
106
- - Fixing: MockMenuService collectPages
107
-
108
- ## 1.2.0
109
-
110
- ### Minor Changes
111
-
112
- - Updating: next 13
113
-
114
- ## 1.1.1
115
-
116
- ### Patch Changes
117
-
118
- - Fixing: check redirects by pattern
119
-
120
- ## 1.1.0
121
-
122
- ### Minor Changes
123
-
124
- - Modified: store refactor
125
-
126
- ## 1.0.1
127
-
128
- ### Patch Changes
129
-
130
- - Fixing: localhost url
131
-
132
- ## 1.0.0
133
-
134
- ### Minor Changes
135
-
136
- - Modified routes, added redirects
137
-
138
- ## 0.3.2
139
-
140
- ### Patch Changes
141
-
142
- - Modified: MockMenuService
143
-
144
- ## 0.3.1
145
-
146
- ### Patch Changes
147
-
148
- - Added: source files
149
-
150
- ## 0.3.0
151
-
152
- ### Minor Changes
153
-
154
- - Added: splat routes
155
-
156
- ## 0.2.0
157
-
158
- ### Minor Changes
159
-
160
- - Added: @websolutespa/bom-core
161
-
162
- ## 0.1.1
163
-
164
- ### Patch Changes
165
-
166
- - Modified: store service
167
-
168
- ## 0.1.0
169
-
170
- ### Minor Changes
171
-
172
- - mock refactor
173
-
174
- ## 0.0.2
175
-
176
- ### Patch Changes
177
-
178
- - Added: first release
1
+ # @websolutespa/bom-mixer-store
2
+
3
+ ## 1.7.5
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixing: downgrading eslint to v8.56.0
8
+ - Updated dependencies
9
+ - @websolutespa/bom-core@1.7.8
10
+
11
+ ## 1.7.4
12
+
13
+ ### Patch Changes
14
+
15
+ - Added: varsHandler
16
+ - Updated dependencies
17
+ - @websolutespa/bom-core@1.7.7
18
+
19
+ ## 1.7.3
20
+
21
+ ### Patch Changes
22
+
23
+ - Updating: dependencies
24
+ - Updated dependencies
25
+ - @websolutespa/bom-core@1.7.3
26
+
27
+ ## 1.7.2
28
+
29
+ ### Patch Changes
30
+
31
+ - 7898849: Modified: exporting getRemoteApiUrl
32
+
33
+ ## 1.7.1
34
+
35
+ ### Patch Changes
36
+
37
+ - Fixing: findRoute redirects
38
+
39
+ ## 1.7.0
40
+
41
+ ### Minor Changes
42
+
43
+ - 28e86bd: Modified: IPage, Store services & decorators
44
+ - Updated dependencies [28e86bd]
45
+ - @websolutespa/bom-core@1.7.0
46
+
47
+ ## 1.6.0
48
+
49
+ ### Patch Changes
50
+
51
+ - f664993: Added: useLivePreview
52
+ - Updated dependencies [6cbf4cb]
53
+ - @websolutespa/bom-core@0.6.7
54
+
55
+ ## 1.4.6
56
+
57
+ ### Patch Changes
58
+
59
+ - Fixing: CachedService findMany DecoratedApi
60
+
61
+ ## 1.4.5
62
+
63
+ ### Patch Changes
64
+
65
+ - Fixing: decorateSchema
66
+
67
+ ## 1.4.4
68
+
69
+ ### Patch Changes
70
+
71
+ - Added: Schema decorator
72
+ - Modified: RemoteMenuService, RemotePageService, RemoteService
73
+ - Updated dependencies
74
+ - @websolutespa/bom-core@0.6.5
75
+
76
+ ## 1.4.3
77
+
78
+ ### Patch Changes
79
+
80
+ - Modified: CachedService, Decorators, LocalApi, MockApi, MockStore, RemoteApi, RemoteStore, StoreHandler
81
+
82
+ ## 1.4.2
83
+
84
+ ### Patch Changes
85
+
86
+ - Added: Decorators, CachedService, RemotePageService, RemoteMenuService, StoreStrategy.DecoratedApi, nextPhase, storeCacheDuration
87
+ - Modified: RemoteStore
88
+ - Updated dependencies
89
+ - @websolutespa/bom-core@0.6.4
90
+
91
+ ## 1.4.1
92
+
93
+ ### Patch Changes
94
+
95
+ - Modified: MockPageService
96
+ - Updated dependencies
97
+ - @websolutespa/bom-core@0.6.3
98
+
99
+ ## 1.4.0
100
+
101
+ ### Minor Changes
102
+
103
+ - Added: BuildStrategy
104
+
105
+ ## 1.3.0
106
+
107
+ ### Minor Changes
108
+
109
+ - Added: storeIndexHandler
110
+ - Modified: Store, StoreHandler, RemoteService, MockService, MockPageService, MockMenuService, StaticService
111
+
112
+ ## 1.2.2
113
+
114
+ ### Patch Changes
115
+
116
+ - Modified: MockMenuService IPageRelationResult
117
+
118
+ ## 1.2.1
119
+
120
+ ### Patch Changes
121
+
122
+ - Fixing: MockMenuService collectPages
123
+
124
+ ## 1.2.0
125
+
126
+ ### Minor Changes
127
+
128
+ - Updating: next 13
129
+
130
+ ## 1.1.1
131
+
132
+ ### Patch Changes
133
+
134
+ - Fixing: check redirects by pattern
135
+
136
+ ## 1.1.0
137
+
138
+ ### Minor Changes
139
+
140
+ - Modified: store refactor
141
+
142
+ ## 1.0.1
143
+
144
+ ### Patch Changes
145
+
146
+ - Fixing: localhost url
147
+
148
+ ## 1.0.0
149
+
150
+ ### Minor Changes
151
+
152
+ - Modified routes, added redirects
153
+
154
+ ## 0.3.2
155
+
156
+ ### Patch Changes
157
+
158
+ - Modified: MockMenuService
159
+
160
+ ## 0.3.1
161
+
162
+ ### Patch Changes
163
+
164
+ - Added: source files
165
+
166
+ ## 0.3.0
167
+
168
+ ### Minor Changes
169
+
170
+ - Added: splat routes
171
+
172
+ ## 0.2.0
173
+
174
+ ### Minor Changes
175
+
176
+ - Added: @websolutespa/bom-core
177
+
178
+ ## 0.1.1
179
+
180
+ ### Patch Changes
181
+
182
+ - Modified: store service
183
+
184
+ ## 0.1.0
185
+
186
+ ### Minor Changes
187
+
188
+ - mock refactor
189
+
190
+ ## 0.0.2
191
+
192
+ ### Patch Changes
193
+
194
+ - Added: first release
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { FetchRequestOptions, ICategorized, IStore, QueryParams, ICategory, ISchema, IUndecoratedMenu, IMenu, IRoute, IEquatable, IEntity, JsonService, IMemoryStore, IQuerable, IPagedResult } from '@websolutespa/bom-core';
2
2
  import { NextApiRequest, NextApiResponse } from 'next';
3
3
  import { NextRequest } from 'next/server';
4
+ import * as _websolutespa_bom_mixer_store from '@websolutespa/bom-mixer-store';
4
5
 
5
6
  type ApiRequestOptions = FetchRequestOptions;
6
7
  declare const defaultApiRequestOptions: ApiRequestOptions;
@@ -236,4 +237,6 @@ declare function findRoute(store: IStore, pathname: string, href: string, hrefBe
236
237
 
237
238
  declare function getStore<T extends IStore>(): Promise<T>;
238
239
 
239
- export { ApiRequestOptions, BuildStrategy, COLLECTIONS, IApiHandler, ICrudMethod, IField, IHandler, IPageResolvedRelation, KNOWN_COLLECTIONS, MAX_INT, MOCK_COLLECTIONS, MapTo, MockMenuService, MockPageService, MockService, NextPhase, RemoteMenuService, RemotePageService, RemoteService, RemoteServiceStrategy, SERVICE_DEFAULT_DEPTH, STATIC_COLLECTIONS, StaticService, StaticServiceConfig, StaticServiceSrc, StoreStrategy, apiHandler, buildStrategy, collectionDelete, collectionGet, collectionPatch, collectionPost, decorateCategories_, decorateCategory_, decorateHref_, decorateHrefs_, decorateLocalizable_, decorateLocalizables_, decorateMenu_, decorateMenus_, decorateNav_, decorateNavs_, decorateRelation_, decorateRelations_, decorateSchema_, decorateSchemas_, decorateStaticRelation_, decorateStaticRelations_, defaultApiRequestOptions, errorHandler, findRoute, fromCache, getDefaultApiRequestOptions, getLocalApiUrl, getMockStore, getMockStoreFromData_, 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 };
240
+ declare function varsHandler(): _websolutespa_bom_mixer_store.IHandler<any>;
241
+
242
+ export { ApiRequestOptions, BuildStrategy, COLLECTIONS, IApiHandler, ICrudMethod, IField, IHandler, IPageResolvedRelation, KNOWN_COLLECTIONS, MAX_INT, MOCK_COLLECTIONS, MapTo, MockMenuService, MockPageService, MockService, NextPhase, RemoteMenuService, RemotePageService, RemoteService, RemoteServiceStrategy, SERVICE_DEFAULT_DEPTH, STATIC_COLLECTIONS, StaticService, StaticServiceConfig, StaticServiceSrc, StoreStrategy, apiHandler, buildStrategy, collectionDelete, collectionGet, collectionPatch, collectionPost, decorateCategories_, decorateCategory_, decorateHref_, decorateHrefs_, decorateLocalizable_, decorateLocalizables_, decorateMenu_, decorateMenus_, decorateNav_, decorateNavs_, decorateRelation_, decorateRelations_, decorateSchema_, decorateSchemas_, decorateStaticRelation_, decorateStaticRelations_, defaultApiRequestOptions, errorHandler, findRoute, fromCache, getDefaultApiRequestOptions, getLocalApiUrl, getMockStore, getMockStoreFromData_, 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 };
package/dist/index.js CHANGED
@@ -115,7 +115,8 @@ __export(src_exports, {
115
115
  storeCacheDuration: () => storeCacheDuration,
116
116
  storeHandler: () => storeHandler,
117
117
  storeIndexHandler: () => storeIndexHandler,
118
- storeStrategy: () => storeStrategy
118
+ storeStrategy: () => storeStrategy,
119
+ varsHandler: () => varsHandler
119
120
  });
120
121
  module.exports = __toCommonJS(src_exports);
121
122
 
@@ -2028,6 +2029,271 @@ async function storeApiPatch(url, payload, options = {}) {
2028
2029
  async function storeApiDelete(url, options = {}) {
2029
2030
  return await storeApiFetch(url, { ...options, method: "DELETE" });
2030
2031
  }
2032
+
2033
+ // src/vars/vars.handler.ts
2034
+ var import_bom_core16 = require("@websolutespa/bom-core");
2035
+
2036
+ // ../models/src/route/route.service.ts
2037
+ var import_bom_core15 = require("@websolutespa/bom-core");
2038
+ async function getRouteLinkTree(market, locale) {
2039
+ const store = await getStore();
2040
+ const routes = await store.route.findMany({
2041
+ where: {
2042
+ market: {
2043
+ equals: market
2044
+ },
2045
+ locale: {
2046
+ equals: locale
2047
+ }
2048
+ }
2049
+ });
2050
+ const categories = await store.category.findMany();
2051
+ const rootCategory = (0, import_bom_core15.getRootCategory)(categories);
2052
+ if (rootCategory) {
2053
+ const root = categoryToRouteLink(routes, categories, rootCategory, locale);
2054
+ return root;
2055
+ }
2056
+ return void 0;
2057
+ }
2058
+ function categoryToRouteLink(routes, categories, category, locale) {
2059
+ const route = routes.find(
2060
+ (r) => r.category === category.id && r.isDefault
2061
+ );
2062
+ if (!route) {
2063
+ return void 0;
2064
+ }
2065
+ const rootCategory = (0, import_bom_core15.getRootCategory)(categories);
2066
+ const childCategories = categories.filter((x) => {
2067
+ const parentId = x.category ? (0, import_bom_core15.asCategoryId)(x.category) : null;
2068
+ return rootCategory && rootCategory.id === category.id ? x.id !== rootCategory.id && (parentId === category.id || !parentId) : parentId === category.id;
2069
+ });
2070
+ const routeLink = newRouteLink(category, route, locale);
2071
+ routeLink.items = childCategories.map((x) => categoryToRouteLink(routes, categories, x, locale)).filter((x) => x !== void 0);
2072
+ return routeLink;
2073
+ }
2074
+ function newRouteLink(category, route, locale) {
2075
+ const href = route && route.id ? route.id.toString() : "/";
2076
+ const id = route?.page || category.id;
2077
+ const media = category.media || route?.media;
2078
+ const schema = route?.schema || category?.schema || "unknown";
2079
+ const title = (0, import_bom_core15.localize)(category.title || route?.title || "untitled", locale);
2080
+ const routeLink = {
2081
+ category: category.id,
2082
+ href,
2083
+ id,
2084
+ items: [],
2085
+ media,
2086
+ schema,
2087
+ title
2088
+ };
2089
+ return routeLink;
2090
+ }
2091
+
2092
+ // ../models/src/label/label.service.ts
2093
+ async function getLabels(params = {}) {
2094
+ const store = await getStore();
2095
+ const items = await store.label.findMany(params);
2096
+ return items;
2097
+ }
2098
+
2099
+ // ../models/src/locale/locale.service.ts
2100
+ async function getLocales(params = {}) {
2101
+ const store = await getStore();
2102
+ const items = await store.locale.findMany(params);
2103
+ return items;
2104
+ }
2105
+
2106
+ // ../models/src/market/market.service.ts
2107
+ async function getMarkets(params = {}) {
2108
+ const store = await getStore();
2109
+ const items = await store.market.findMany(params);
2110
+ return items;
2111
+ }
2112
+
2113
+ // ../models/src/menu/menu.service.ts
2114
+ async function getMenus(params = {}) {
2115
+ const store = await getStore();
2116
+ const items = await store.menu.findMany(params);
2117
+ return items;
2118
+ }
2119
+
2120
+ // ../models/src/layout/layout.service.ts
2121
+ async function getLayout(market, locale) {
2122
+ const markets = await getMarkets({ locale });
2123
+ const locales = await getLocales({ locale });
2124
+ const labels = await getLabels({ locale });
2125
+ const tree = await getRouteLinkTree(market, locale);
2126
+ const firstLevelRoutes = tree?.items || [];
2127
+ const flatTopLevelRoutes = tree ? [tree, ...firstLevelRoutes] : [];
2128
+ const topLevelRoutes = flatTopLevelRoutes.reduce((object, routeLink) => {
2129
+ object[routeLink.schema] = routeLink;
2130
+ return object;
2131
+ }, {});
2132
+ const topLevelHrefs = flatTopLevelRoutes.reduce((object, routeLink) => {
2133
+ if (routeLink.href) {
2134
+ object[routeLink.schema] = routeLink.href;
2135
+ }
2136
+ return object;
2137
+ }, {});
2138
+ const menu = {};
2139
+ const menus = await getMenus({ market, locale });
2140
+ menus.forEach((x) => {
2141
+ menu[x.id] = x;
2142
+ });
2143
+ return {
2144
+ labels,
2145
+ locale,
2146
+ locales,
2147
+ market,
2148
+ markets,
2149
+ menu,
2150
+ topLevelHrefs,
2151
+ topLevelRoutes,
2152
+ tree
2153
+ };
2154
+ }
2155
+
2156
+ // src/vars/vars.handler.ts
2157
+ var DISALLOWED_KEYS = [
2158
+ "__NEXT_PRIVATE_STANDALONE_CONFIG"
2159
+ ];
2160
+ var getFilteredEnv = (env) => {
2161
+ const entries = Object.entries(env).filter(([k, v]) => !DISALLOWED_KEYS.includes(k) && typeof v === "string");
2162
+ entries.sort();
2163
+ return Object.fromEntries(entries);
2164
+ };
2165
+ var sortKeys = (object) => {
2166
+ const entries = Object.entries(object || {});
2167
+ entries.sort();
2168
+ return Object.fromEntries(entries);
2169
+ };
2170
+ function varsHandler() {
2171
+ return apiHandler({
2172
+ options: async (request, response) => {
2173
+ response.status(200).end();
2174
+ },
2175
+ get: async (request, response) => {
2176
+ try {
2177
+ const defaultLocale3 = process.env.DEFAULT_LOCALE || "it";
2178
+ const defaultMaket = process.env.DEFAULT_MARKET || "ww";
2179
+ const { locale = defaultLocale3, market = defaultMaket } = request.query || {};
2180
+ const layout = typeof locale === "string" && typeof market === "string" ? await getLayout(market, locale) : void 0;
2181
+ const info = {
2182
+ production: import_bom_core16.isProduction,
2183
+ development: import_bom_core16.isDevelopment,
2184
+ origin: (0, import_bom_core16.getOrigin)(request.headers),
2185
+ host: (0, import_bom_core16.getHost)(request.headers),
2186
+ headers: { ...sortKeys(request.headers) },
2187
+ env: { ...getFilteredEnv(process.env) },
2188
+ layout: { ...sortKeys(layout) }
2189
+ };
2190
+ if (!request.headers.accept?.includes("text/html")) {
2191
+ return response.status(200).json(info);
2192
+ }
2193
+ response.status(200).send(`<!DOCTYPE html>
2194
+ <html>
2195
+ <head>
2196
+ <meta charSet="utf-8"/>
2197
+ <style>
2198
+ html, body {
2199
+ background: #282828;
2200
+ color: #7cacf8;
2201
+ }
2202
+ body {
2203
+ padding: 0;
2204
+ margin: 0;
2205
+ font-family: monospace;
2206
+ font-size: 14px;
2207
+ line-height: 1.16;
2208
+ font-weight: 100;
2209
+ }
2210
+ json-viewer {
2211
+ padding: 20px;
2212
+ min-height: 100vh;
2213
+ box-sizing: border-box;
2214
+ line-height: 1.2;
2215
+ --background-color: #282828;
2216
+ --color: #e3e3e3;
2217
+ --property-color: #7cacf8;
2218
+ --string-color: #53d5fb;
2219
+ --number-color: #7b80ff;
2220
+ --boolean-color: #9980ff;
2221
+ --null-color: #6f6f6f;
2222
+ --preview-color: #8f8f8f;
2223
+ --highlight-color: #7b0000;
2224
+ --font-family: monospace;
2225
+ --font-size: 14px;
2226
+ --indent-size: 1em;
2227
+ --indentguide-size: 1px;
2228
+ --indentguide-style: solid;
2229
+ --indentguide-color: #333;
2230
+ --indentguide-color-active: #666;
2231
+ --indentguide: var(--indentguide-size) var(--indentguide-style) var(--indentguide-color);
2232
+ --indentguide-active: var(--indentguide-size) var(--indentguide-style) var(--indentguide-color-active);
2233
+ }
2234
+
2235
+ :root {
2236
+ --scrollbar-size: 8px;
2237
+ --scrollbar-border-radius: 2px;
2238
+ --scrollbar-track-color: transparent;
2239
+ --scrollbar-track-hover-color: transparent;
2240
+ --scrollbar-thumb-color: #888888;
2241
+ --scrollbar-thumb-hover-color: #aaaaaa;
2242
+ }
2243
+
2244
+ ::-webkit-scrollbar {
2245
+ width: var(--scrollbar-size);
2246
+ height: var(--scrollbar-size);
2247
+ border-radius: 0;
2248
+ }
2249
+
2250
+ ::-webkit-scrollbar-button {
2251
+ display: none;
2252
+ }
2253
+
2254
+ ::-webkit-scrollbar-button:hover {
2255
+ display: none;
2256
+ }
2257
+
2258
+ ::-webkit-scrollbar-thumb {
2259
+ background-color: var(--scrollbar-thumb-color);
2260
+ box-shadow: none;
2261
+ border-radius: calc(var(--scrollbar-size) * 0.5);
2262
+ }
2263
+
2264
+ ::-webkit-scrollbar-thumb:hover {
2265
+ background-color: var(--scrollbar-thumb-hover-color);
2266
+ }
2267
+
2268
+ ::-webkit-scrollbar-track {
2269
+ background-color: var(--scrollbar-track-color);
2270
+ border-radius: 0;
2271
+ }
2272
+
2273
+ ::-webkit-scrollbar-track:hover {
2274
+ background-color: var(--scrollbar-track-hover-color);
2275
+ }
2276
+
2277
+ </style>
2278
+ <script src="https://unpkg.com/@alenaksu/json-viewer@2.0.0/dist/json-viewer.bundle.js"></script>
2279
+ <script>
2280
+ document.addEventListener('DOMContentLoaded', () => {
2281
+ const viewer = document.querySelector('#json-viewer');
2282
+ viewer.data = ${JSON.stringify(info)};
2283
+ viewer.expand(/headers|env/);
2284
+ });
2285
+ </script>
2286
+ </head>
2287
+ <body>
2288
+ <json-viewer id="json-viewer"></json-viewer>
2289
+ </body>
2290
+ </html>`);
2291
+ } catch (error) {
2292
+ response.status(400).json(error);
2293
+ }
2294
+ }
2295
+ });
2296
+ }
2031
2297
  // Annotate the CommonJS export names for ESM import in node:
2032
2298
  0 && (module.exports = {
2033
2299
  BuildStrategy,
@@ -2115,5 +2381,6 @@ async function storeApiDelete(url, options = {}) {
2115
2381
  storeCacheDuration,
2116
2382
  storeHandler,
2117
2383
  storeIndexHandler,
2118
- storeStrategy
2384
+ storeStrategy,
2385
+ varsHandler
2119
2386
  });
package/dist/index.mjs CHANGED
@@ -1919,6 +1919,271 @@ async function storeApiPatch(url, payload, options = {}) {
1919
1919
  async function storeApiDelete(url, options = {}) {
1920
1920
  return await storeApiFetch(url, { ...options, method: "DELETE" });
1921
1921
  }
1922
+
1923
+ // src/vars/vars.handler.ts
1924
+ import { getHost, getOrigin, isDevelopment as isDevelopment2, isProduction } from "@websolutespa/bom-core";
1925
+
1926
+ // ../models/src/route/route.service.ts
1927
+ import { asCategoryId, defaultLocale as defaultLocale2, defaultMarket as defaultMarket2, getRootCategory, localize } from "@websolutespa/bom-core";
1928
+ async function getRouteLinkTree(market, locale) {
1929
+ const store = await getStore();
1930
+ const routes = await store.route.findMany({
1931
+ where: {
1932
+ market: {
1933
+ equals: market
1934
+ },
1935
+ locale: {
1936
+ equals: locale
1937
+ }
1938
+ }
1939
+ });
1940
+ const categories = await store.category.findMany();
1941
+ const rootCategory = getRootCategory(categories);
1942
+ if (rootCategory) {
1943
+ const root = categoryToRouteLink(routes, categories, rootCategory, locale);
1944
+ return root;
1945
+ }
1946
+ return void 0;
1947
+ }
1948
+ function categoryToRouteLink(routes, categories, category, locale) {
1949
+ const route = routes.find(
1950
+ (r) => r.category === category.id && r.isDefault
1951
+ );
1952
+ if (!route) {
1953
+ return void 0;
1954
+ }
1955
+ const rootCategory = getRootCategory(categories);
1956
+ const childCategories = categories.filter((x) => {
1957
+ const parentId = x.category ? asCategoryId(x.category) : null;
1958
+ return rootCategory && rootCategory.id === category.id ? x.id !== rootCategory.id && (parentId === category.id || !parentId) : parentId === category.id;
1959
+ });
1960
+ const routeLink = newRouteLink(category, route, locale);
1961
+ routeLink.items = childCategories.map((x) => categoryToRouteLink(routes, categories, x, locale)).filter((x) => x !== void 0);
1962
+ return routeLink;
1963
+ }
1964
+ function newRouteLink(category, route, locale) {
1965
+ const href = route && route.id ? route.id.toString() : "/";
1966
+ const id = route?.page || category.id;
1967
+ const media = category.media || route?.media;
1968
+ const schema = route?.schema || category?.schema || "unknown";
1969
+ const title = localize(category.title || route?.title || "untitled", locale);
1970
+ const routeLink = {
1971
+ category: category.id,
1972
+ href,
1973
+ id,
1974
+ items: [],
1975
+ media,
1976
+ schema,
1977
+ title
1978
+ };
1979
+ return routeLink;
1980
+ }
1981
+
1982
+ // ../models/src/label/label.service.ts
1983
+ async function getLabels(params = {}) {
1984
+ const store = await getStore();
1985
+ const items = await store.label.findMany(params);
1986
+ return items;
1987
+ }
1988
+
1989
+ // ../models/src/locale/locale.service.ts
1990
+ async function getLocales(params = {}) {
1991
+ const store = await getStore();
1992
+ const items = await store.locale.findMany(params);
1993
+ return items;
1994
+ }
1995
+
1996
+ // ../models/src/market/market.service.ts
1997
+ async function getMarkets(params = {}) {
1998
+ const store = await getStore();
1999
+ const items = await store.market.findMany(params);
2000
+ return items;
2001
+ }
2002
+
2003
+ // ../models/src/menu/menu.service.ts
2004
+ async function getMenus(params = {}) {
2005
+ const store = await getStore();
2006
+ const items = await store.menu.findMany(params);
2007
+ return items;
2008
+ }
2009
+
2010
+ // ../models/src/layout/layout.service.ts
2011
+ async function getLayout(market, locale) {
2012
+ const markets = await getMarkets({ locale });
2013
+ const locales = await getLocales({ locale });
2014
+ const labels = await getLabels({ locale });
2015
+ const tree = await getRouteLinkTree(market, locale);
2016
+ const firstLevelRoutes = tree?.items || [];
2017
+ const flatTopLevelRoutes = tree ? [tree, ...firstLevelRoutes] : [];
2018
+ const topLevelRoutes = flatTopLevelRoutes.reduce((object, routeLink) => {
2019
+ object[routeLink.schema] = routeLink;
2020
+ return object;
2021
+ }, {});
2022
+ const topLevelHrefs = flatTopLevelRoutes.reduce((object, routeLink) => {
2023
+ if (routeLink.href) {
2024
+ object[routeLink.schema] = routeLink.href;
2025
+ }
2026
+ return object;
2027
+ }, {});
2028
+ const menu = {};
2029
+ const menus = await getMenus({ market, locale });
2030
+ menus.forEach((x) => {
2031
+ menu[x.id] = x;
2032
+ });
2033
+ return {
2034
+ labels,
2035
+ locale,
2036
+ locales,
2037
+ market,
2038
+ markets,
2039
+ menu,
2040
+ topLevelHrefs,
2041
+ topLevelRoutes,
2042
+ tree
2043
+ };
2044
+ }
2045
+
2046
+ // src/vars/vars.handler.ts
2047
+ var DISALLOWED_KEYS = [
2048
+ "__NEXT_PRIVATE_STANDALONE_CONFIG"
2049
+ ];
2050
+ var getFilteredEnv = (env) => {
2051
+ const entries = Object.entries(env).filter(([k, v]) => !DISALLOWED_KEYS.includes(k) && typeof v === "string");
2052
+ entries.sort();
2053
+ return Object.fromEntries(entries);
2054
+ };
2055
+ var sortKeys = (object) => {
2056
+ const entries = Object.entries(object || {});
2057
+ entries.sort();
2058
+ return Object.fromEntries(entries);
2059
+ };
2060
+ function varsHandler() {
2061
+ return apiHandler({
2062
+ options: async (request, response) => {
2063
+ response.status(200).end();
2064
+ },
2065
+ get: async (request, response) => {
2066
+ try {
2067
+ const defaultLocale3 = process.env.DEFAULT_LOCALE || "it";
2068
+ const defaultMaket = process.env.DEFAULT_MARKET || "ww";
2069
+ const { locale = defaultLocale3, market = defaultMaket } = request.query || {};
2070
+ const layout = typeof locale === "string" && typeof market === "string" ? await getLayout(market, locale) : void 0;
2071
+ const info = {
2072
+ production: isProduction,
2073
+ development: isDevelopment2,
2074
+ origin: getOrigin(request.headers),
2075
+ host: getHost(request.headers),
2076
+ headers: { ...sortKeys(request.headers) },
2077
+ env: { ...getFilteredEnv(process.env) },
2078
+ layout: { ...sortKeys(layout) }
2079
+ };
2080
+ if (!request.headers.accept?.includes("text/html")) {
2081
+ return response.status(200).json(info);
2082
+ }
2083
+ response.status(200).send(`<!DOCTYPE html>
2084
+ <html>
2085
+ <head>
2086
+ <meta charSet="utf-8"/>
2087
+ <style>
2088
+ html, body {
2089
+ background: #282828;
2090
+ color: #7cacf8;
2091
+ }
2092
+ body {
2093
+ padding: 0;
2094
+ margin: 0;
2095
+ font-family: monospace;
2096
+ font-size: 14px;
2097
+ line-height: 1.16;
2098
+ font-weight: 100;
2099
+ }
2100
+ json-viewer {
2101
+ padding: 20px;
2102
+ min-height: 100vh;
2103
+ box-sizing: border-box;
2104
+ line-height: 1.2;
2105
+ --background-color: #282828;
2106
+ --color: #e3e3e3;
2107
+ --property-color: #7cacf8;
2108
+ --string-color: #53d5fb;
2109
+ --number-color: #7b80ff;
2110
+ --boolean-color: #9980ff;
2111
+ --null-color: #6f6f6f;
2112
+ --preview-color: #8f8f8f;
2113
+ --highlight-color: #7b0000;
2114
+ --font-family: monospace;
2115
+ --font-size: 14px;
2116
+ --indent-size: 1em;
2117
+ --indentguide-size: 1px;
2118
+ --indentguide-style: solid;
2119
+ --indentguide-color: #333;
2120
+ --indentguide-color-active: #666;
2121
+ --indentguide: var(--indentguide-size) var(--indentguide-style) var(--indentguide-color);
2122
+ --indentguide-active: var(--indentguide-size) var(--indentguide-style) var(--indentguide-color-active);
2123
+ }
2124
+
2125
+ :root {
2126
+ --scrollbar-size: 8px;
2127
+ --scrollbar-border-radius: 2px;
2128
+ --scrollbar-track-color: transparent;
2129
+ --scrollbar-track-hover-color: transparent;
2130
+ --scrollbar-thumb-color: #888888;
2131
+ --scrollbar-thumb-hover-color: #aaaaaa;
2132
+ }
2133
+
2134
+ ::-webkit-scrollbar {
2135
+ width: var(--scrollbar-size);
2136
+ height: var(--scrollbar-size);
2137
+ border-radius: 0;
2138
+ }
2139
+
2140
+ ::-webkit-scrollbar-button {
2141
+ display: none;
2142
+ }
2143
+
2144
+ ::-webkit-scrollbar-button:hover {
2145
+ display: none;
2146
+ }
2147
+
2148
+ ::-webkit-scrollbar-thumb {
2149
+ background-color: var(--scrollbar-thumb-color);
2150
+ box-shadow: none;
2151
+ border-radius: calc(var(--scrollbar-size) * 0.5);
2152
+ }
2153
+
2154
+ ::-webkit-scrollbar-thumb:hover {
2155
+ background-color: var(--scrollbar-thumb-hover-color);
2156
+ }
2157
+
2158
+ ::-webkit-scrollbar-track {
2159
+ background-color: var(--scrollbar-track-color);
2160
+ border-radius: 0;
2161
+ }
2162
+
2163
+ ::-webkit-scrollbar-track:hover {
2164
+ background-color: var(--scrollbar-track-hover-color);
2165
+ }
2166
+
2167
+ </style>
2168
+ <script src="https://unpkg.com/@alenaksu/json-viewer@2.0.0/dist/json-viewer.bundle.js"></script>
2169
+ <script>
2170
+ document.addEventListener('DOMContentLoaded', () => {
2171
+ const viewer = document.querySelector('#json-viewer');
2172
+ viewer.data = ${JSON.stringify(info)};
2173
+ viewer.expand(/headers|env/);
2174
+ });
2175
+ </script>
2176
+ </head>
2177
+ <body>
2178
+ <json-viewer id="json-viewer"></json-viewer>
2179
+ </body>
2180
+ </html>`);
2181
+ } catch (error) {
2182
+ response.status(400).json(error);
2183
+ }
2184
+ }
2185
+ });
2186
+ }
1922
2187
  export {
1923
2188
  BuildStrategy,
1924
2189
  COLLECTIONS,
@@ -2005,5 +2270,6 @@ export {
2005
2270
  storeCacheDuration,
2006
2271
  storeHandler,
2007
2272
  storeIndexHandler,
2008
- storeStrategy
2273
+ storeStrategy,
2274
+ varsHandler
2009
2275
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/bom-mixer-store",
3
- "version": "1.7.3",
3
+ "version": "1.7.5",
4
4
  "description": "Mixer Store module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",
@@ -35,7 +35,7 @@
35
35
  "@websolutespa/bom-cli": "*",
36
36
  "@websolutespa/test": "*",
37
37
  "@websolutespa/tsconfig": "*",
38
- "eslint": "^9.0.0",
38
+ "eslint": "^8.56.0",
39
39
  "eslint-config-websolute": "*",
40
40
  "npm-run-all": "^4.1.5",
41
41
  "ts-node": "^10.9.2",
package/src/index.ts CHANGED
@@ -22,4 +22,5 @@ export * from './store/store';
22
22
  export * from './store/store.api';
23
23
  export * from './store/store.handler';
24
24
  export * from './store/store.service';
25
+ export * from './vars/vars.handler';
25
26
 
@@ -0,0 +1,153 @@
1
+ import { getHost, getOrigin, isDevelopment, isProduction } from '@websolutespa/bom-core';
2
+ import { getLayout } from '@websolutespa/bom-mixer-models';
3
+ import { apiHandler } from '@websolutespa/bom-mixer-store';
4
+ import { NextApiRequest, NextApiResponse } from 'next';
5
+
6
+ const DISALLOWED_KEYS = [
7
+ '__NEXT_PRIVATE_STANDALONE_CONFIG',
8
+ ];
9
+
10
+ const getFilteredEnv = (env: Record<string, unknown>): Record<string, unknown> => {
11
+ const entries = Object.entries(env).filter(([k, v]) => (
12
+ !DISALLOWED_KEYS.includes(k) && typeof v === 'string'
13
+ ));
14
+ entries.sort();
15
+ return Object.fromEntries(entries);
16
+ }
17
+
18
+ const sortKeys = (object?: Record<string, unknown>): Record<string, unknown> => {
19
+ const entries = Object.entries(object || {});
20
+ entries.sort();
21
+ return Object.fromEntries(entries);
22
+ }
23
+
24
+ export function varsHandler() {
25
+ return apiHandler({
26
+ options: async (request: NextApiRequest, response: NextApiResponse) => {
27
+ response.status(200).end();
28
+ },
29
+ get: async (request: NextApiRequest, response: NextApiResponse) => {
30
+ try {
31
+ const defaultLocale = process.env.DEFAULT_LOCALE || 'it';
32
+ const defaultMaket = process.env.DEFAULT_MARKET || 'ww';
33
+ const { locale = defaultLocale, market = defaultMaket } = (request.query || {});
34
+ const layout =
35
+ typeof locale === 'string' && typeof market === 'string' ?
36
+ await getLayout(market, locale) :
37
+ undefined;
38
+ const info = {
39
+ production: isProduction,
40
+ development: isDevelopment,
41
+ origin: getOrigin(request.headers),
42
+ host: getHost(request.headers),
43
+ headers: { ...sortKeys(request.headers) },
44
+ env: { ...getFilteredEnv(process.env) },
45
+ layout: { ...sortKeys(layout) },
46
+ }
47
+ if (!(request.headers.accept?.includes('text/html'))) {
48
+ return response.status(200).json(info);
49
+ }
50
+ response.status(200).send(`<!DOCTYPE html>
51
+ <html>
52
+ <head>
53
+ <meta charSet="utf-8"/>
54
+ <style>
55
+ html, body {
56
+ background: #282828;
57
+ color: #7cacf8;
58
+ }
59
+ body {
60
+ padding: 0;
61
+ margin: 0;
62
+ font-family: monospace;
63
+ font-size: 14px;
64
+ line-height: 1.16;
65
+ font-weight: 100;
66
+ }
67
+ json-viewer {
68
+ padding: 20px;
69
+ min-height: 100vh;
70
+ box-sizing: border-box;
71
+ line-height: 1.2;
72
+ --background-color: #282828;
73
+ --color: #e3e3e3;
74
+ --property-color: #7cacf8;
75
+ --string-color: #53d5fb;
76
+ --number-color: #7b80ff;
77
+ --boolean-color: #9980ff;
78
+ --null-color: #6f6f6f;
79
+ --preview-color: #8f8f8f;
80
+ --highlight-color: #7b0000;
81
+ --font-family: monospace;
82
+ --font-size: 14px;
83
+ --indent-size: 1em;
84
+ --indentguide-size: 1px;
85
+ --indentguide-style: solid;
86
+ --indentguide-color: #333;
87
+ --indentguide-color-active: #666;
88
+ --indentguide: var(--indentguide-size) var(--indentguide-style) var(--indentguide-color);
89
+ --indentguide-active: var(--indentguide-size) var(--indentguide-style) var(--indentguide-color-active);
90
+ }
91
+
92
+ :root {
93
+ --scrollbar-size: 8px;
94
+ --scrollbar-border-radius: 2px;
95
+ --scrollbar-track-color: transparent;
96
+ --scrollbar-track-hover-color: transparent;
97
+ --scrollbar-thumb-color: #888888;
98
+ --scrollbar-thumb-hover-color: #aaaaaa;
99
+ }
100
+
101
+ ::-webkit-scrollbar {
102
+ width: var(--scrollbar-size);
103
+ height: var(--scrollbar-size);
104
+ border-radius: 0;
105
+ }
106
+
107
+ ::-webkit-scrollbar-button {
108
+ display: none;
109
+ }
110
+
111
+ ::-webkit-scrollbar-button:hover {
112
+ display: none;
113
+ }
114
+
115
+ ::-webkit-scrollbar-thumb {
116
+ background-color: var(--scrollbar-thumb-color);
117
+ box-shadow: none;
118
+ border-radius: calc(var(--scrollbar-size) * 0.5);
119
+ }
120
+
121
+ ::-webkit-scrollbar-thumb:hover {
122
+ background-color: var(--scrollbar-thumb-hover-color);
123
+ }
124
+
125
+ ::-webkit-scrollbar-track {
126
+ background-color: var(--scrollbar-track-color);
127
+ border-radius: 0;
128
+ }
129
+
130
+ ::-webkit-scrollbar-track:hover {
131
+ background-color: var(--scrollbar-track-hover-color);
132
+ }
133
+
134
+ </style>
135
+ <script src="https://unpkg.com/@alenaksu/json-viewer@2.0.0/dist/json-viewer.bundle.js"></script>
136
+ <script>
137
+ document.addEventListener('DOMContentLoaded', () => {
138
+ const viewer = document.querySelector('#json-viewer');
139
+ viewer.data = ${JSON.stringify(info)};
140
+ viewer.expand(/headers|env/);
141
+ });
142
+ </script>
143
+ </head>
144
+ <body>
145
+ <json-viewer id="json-viewer"></json-viewer>
146
+ </body>
147
+ </html>`);
148
+ } catch (error) {
149
+ response.status(400).json(error);
150
+ }
151
+ },
152
+ });
153
+ }