@websolutespa/bom-mixer-store 3.0.2 → 3.1.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 +22 -0
- package/dist/exports/proxy.d.ts +0 -2
- package/dist/exports/proxy.d.ts.map +1 -1
- package/dist/exports/proxy.js +5 -9
- package/dist/exports/proxy.js.map +1 -1
- package/dist/exports/server.d.ts +2 -54
- package/dist/exports/server.d.ts.map +1 -1
- package/dist/exports/server.js +146 -775
- package/dist/exports/server.js.map +1 -1
- package/dist/index.d.ts +4 -22
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +162 -2
- package/dist/index.js.map +1 -0
- package/dist/{static-C4UBVe92.d.ts → static-DbuZMdAg.d.ts} +2 -4
- package/dist/static-DbuZMdAg.d.ts.map +1 -0
- package/dist/{src-bMn1KJCJ.js → store-DiGwhQUO.js} +45 -242
- package/dist/store-DiGwhQUO.js.map +1 -0
- package/package.json +18 -13
- package/src/__tests/session.test.ts +60 -0
- package/src/cached/cached.service.ts +0 -1
- package/src/exports/server.ts +1 -1
- package/src/proxy/proxy.service.ts +22 -22
- package/src/store/store.service.ts +5 -3
- package/src/store/store.ts +1 -1
- package/dist/src-bMn1KJCJ.js.map +0 -1
- package/dist/static-C4UBVe92.d.ts.map +0 -1
package/dist/exports/server.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as decorateLocalizables_, C as decorateRelations_, D as decorateMenu_, F as decorateCategory_, L as fromCache, M as decorateHrefs_, O as decorateMenus_, P as decorateCategories_, S as decorateRelation_, _ as remoteApiPatch, a as NextPhase, b as decorateSchema_, c as buildStrategy, d as storeStrategy, f as staticCollections, g as remoteApiGet, i as MOCK_COLLECTIONS, j as decorateHref_, k as decorateLocalizable_, l as nextPhase, m as remoteApiDelete, n as COLLECTIONS, r as KNOWN_COLLECTIONS, s as StoreStrategy, u as storeCacheDuration, v as remoteApiPost, w as decorateNav_, x as decorateSchemas_, z as getRemoteApiRequestOptions } from "../store-DiGwhQUO.js";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
|
-
import { JsonService,
|
|
4
|
-
import { createPayloadRequest, getPayload } from "payload";
|
|
3
|
+
import { JsonService, asEquatable, defaultLocale, defaultMarket, getHost, getOrigin, httpGet, isDevelopment, isProduction, qsDeserialize, qsSerialize } from "@websolutespa/bom-core";
|
|
5
4
|
import { getIronSession } from "iron-session";
|
|
6
5
|
import * as fs from "fs";
|
|
7
|
-
|
|
8
|
-
//#region
|
|
6
|
+
import { getLayout } from "@websolutespa/bom-mixer-models/server";
|
|
7
|
+
//#region \0rolldown/runtime.js
|
|
9
8
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
10
|
-
|
|
11
9
|
//#endregion
|
|
12
10
|
//#region src/api/api.handler.ts
|
|
13
11
|
function apiHandler(handler) {
|
|
@@ -26,8 +24,7 @@ function apiHandler(handler) {
|
|
|
26
24
|
}
|
|
27
25
|
function errorHandler(error, response) {
|
|
28
26
|
if (typeof error === "string") {
|
|
29
|
-
const
|
|
30
|
-
const statusCode = is404 ? 404 : 400;
|
|
27
|
+
const statusCode = error.toLowerCase().endsWith("not found") ? 404 : 400;
|
|
31
28
|
response.status(statusCode).json({ message: error });
|
|
32
29
|
return;
|
|
33
30
|
}
|
|
@@ -38,337 +35,6 @@ function errorHandler(error, response) {
|
|
|
38
35
|
console.error(error);
|
|
39
36
|
response.status(500).json({ message: error.message });
|
|
40
37
|
}
|
|
41
|
-
|
|
42
|
-
//#endregion
|
|
43
|
-
//#region src/local_/local.api.ts
|
|
44
|
-
/**
|
|
45
|
-
|
|
46
|
-
* This methods handle api requests / responses to local api (bowl or over)
|
|
47
|
-
|
|
48
|
-
*/
|
|
49
|
-
const API_URL = process.env.STORE_URL;
|
|
50
|
-
const API_BASE = process.env.STORE_API || "/api";
|
|
51
|
-
function getLocalApiUrl(pathname) {
|
|
52
|
-
const url = `${API_URL}${API_BASE}${pathname}`;
|
|
53
|
-
return url;
|
|
54
|
-
}
|
|
55
|
-
async function localApiFetch(pathname, options = {}) {
|
|
56
|
-
if (isBrowser) throw "Unauthorized: local api cannot be fetched client side";
|
|
57
|
-
const url = getLocalApiUrl(pathname);
|
|
58
|
-
const apiOptions = merge({ ...getLocalApiRequestOptions() }, options);
|
|
59
|
-
const apiResponse = await httpFetch(url, apiOptions);
|
|
60
|
-
return apiResponse;
|
|
61
|
-
}
|
|
62
|
-
async function localApiGet(url, options = {}) {
|
|
63
|
-
return await localApiFetch(url, {
|
|
64
|
-
...options,
|
|
65
|
-
method: "GET"
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
async function localApiPost(url, payload, options = {}) {
|
|
69
|
-
return await localApiFetch(url, {
|
|
70
|
-
...options,
|
|
71
|
-
method: "POST",
|
|
72
|
-
body: JSON.stringify(payload)
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
async function localApiPatch(url, payload, options = {}) {
|
|
76
|
-
return await localApiFetch(url, {
|
|
77
|
-
...options,
|
|
78
|
-
method: "PATCH",
|
|
79
|
-
body: JSON.stringify(payload)
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
async function localApiDelete(url, options = {}) {
|
|
83
|
-
return await localApiFetch(url, {
|
|
84
|
-
...options,
|
|
85
|
-
method: "DELETE"
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
//#endregion
|
|
90
|
-
//#region src/local_/local.service.ts
|
|
91
|
-
const getSingletonProvider = () => {
|
|
92
|
-
let provider = globalThis.LocalProvider;
|
|
93
|
-
if (!provider) {
|
|
94
|
-
provider = {
|
|
95
|
-
config: void 0,
|
|
96
|
-
sanitizedConfig: void 0,
|
|
97
|
-
payload: void 0
|
|
98
|
-
};
|
|
99
|
-
globalThis.LocalProvider = provider;
|
|
100
|
-
}
|
|
101
|
-
return provider;
|
|
102
|
-
};
|
|
103
|
-
async function setPayloadConfig(config) {
|
|
104
|
-
const provider = getSingletonProvider();
|
|
105
|
-
provider.config = config;
|
|
106
|
-
const sanitizedConfig = await config;
|
|
107
|
-
provider.sanitizedConfig = sanitizedConfig;
|
|
108
|
-
return sanitizedConfig;
|
|
109
|
-
}
|
|
110
|
-
async function getPayloadSingleton() {
|
|
111
|
-
const provider = getSingletonProvider();
|
|
112
|
-
let payload = provider.payload;
|
|
113
|
-
if (!payload) {
|
|
114
|
-
const sanitizedConfig = provider.sanitizedConfig;
|
|
115
|
-
if (!sanitizedConfig) console.warn("LocalService.setPayloadConfig must be initialized", provider);
|
|
116
|
-
payload = await getPayload({ config: sanitizedConfig });
|
|
117
|
-
provider.payload = payload;
|
|
118
|
-
}
|
|
119
|
-
return payload;
|
|
120
|
-
}
|
|
121
|
-
function getAuthHeaders(token) {
|
|
122
|
-
if (token) return new Headers({ Authorization: `JWT ${token}` });
|
|
123
|
-
else return new Headers({ Authorization: `users API-Key ${process.env.STORE_API_KEY}` });
|
|
124
|
-
}
|
|
125
|
-
async function getPayloadUser(payload, token) {
|
|
126
|
-
const { user } = await payload.auth({ headers: getAuthHeaders(token) });
|
|
127
|
-
return user;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
|
|
131
|
-
* This service handle call to local api
|
|
132
|
-
|
|
133
|
-
*/
|
|
134
|
-
var LocalService = class {
|
|
135
|
-
key;
|
|
136
|
-
store;
|
|
137
|
-
constructor(key, store) {
|
|
138
|
-
if (!key) throw new Error("LocalService: key is required");
|
|
139
|
-
if (!store) throw new Error("LocalService: store is required");
|
|
140
|
-
this.key = key;
|
|
141
|
-
this.store = store;
|
|
142
|
-
}
|
|
143
|
-
async findGlobal(params = {}, token) {
|
|
144
|
-
if (["locale", "route"].includes(this.key)) {
|
|
145
|
-
params.richText = String(params.richText) === "true" ? true : false;
|
|
146
|
-
const query$1 = qsSerialize(params);
|
|
147
|
-
const search$1 = query$1 ? `?${query$1}` : "";
|
|
148
|
-
const url$1 = `/globals/${this.key}${search$1}`;
|
|
149
|
-
try {
|
|
150
|
-
const item = await remoteApiGet(url$1, getRemoteApiRequestOptions(token));
|
|
151
|
-
if (item) return await this.decorateOne_(item, params);
|
|
152
|
-
} catch (error) {
|
|
153
|
-
console.log("LocalService", this.key, "findGlobal.error", error);
|
|
154
|
-
}
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
const payload = await getPayloadSingleton();
|
|
158
|
-
const user = await getPayloadUser(payload, token);
|
|
159
|
-
const query = qsSerialize(params);
|
|
160
|
-
const search = query ? `?${query}` : "";
|
|
161
|
-
const url = `http://mixer/globals/${this.key}${search}`;
|
|
162
|
-
const req = await createPayloadRequest({
|
|
163
|
-
config: payload.config,
|
|
164
|
-
request: new Request(url)
|
|
165
|
-
});
|
|
166
|
-
String(params.richText) === "true" ? true : false;
|
|
167
|
-
try {
|
|
168
|
-
const item = await payload.findGlobal({
|
|
169
|
-
slug: this.key,
|
|
170
|
-
depth: params.depth,
|
|
171
|
-
locale: params.locale,
|
|
172
|
-
fallbackLocale: false,
|
|
173
|
-
req,
|
|
174
|
-
overrideAccess: false,
|
|
175
|
-
user
|
|
176
|
-
});
|
|
177
|
-
if (item) return await this.decorateOne_(item, params);
|
|
178
|
-
} catch (error) {
|
|
179
|
-
console.log("LocalService", this.key, "findOne.error", error);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
async findOne(id, params = {}, token) {
|
|
183
|
-
if (["locale", "route"].includes(this.key)) {
|
|
184
|
-
params.richText = String(params.richText) === "true" ? true : false;
|
|
185
|
-
const query$1 = qsSerialize(params);
|
|
186
|
-
const search$1 = query$1 ? `?${query$1}` : "";
|
|
187
|
-
const url$1 = `/${this.key}/${encodeURIComponent(id)}${search$1}`;
|
|
188
|
-
try {
|
|
189
|
-
console.log("remoteApiGet", url$1);
|
|
190
|
-
const item = await remoteApiGet(url$1, getRemoteApiRequestOptions(token));
|
|
191
|
-
if (item) return await this.decorateOne_(item, params);
|
|
192
|
-
} catch (error) {
|
|
193
|
-
console.log("LocalService", this.key, "findOne.error", error);
|
|
194
|
-
}
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
const payload = await getPayloadSingleton();
|
|
198
|
-
const user = await getPayloadUser(payload, token);
|
|
199
|
-
const query = qsSerialize(params);
|
|
200
|
-
const search = query ? `?${query}` : "";
|
|
201
|
-
const url = `http://mixer/${this.key}/${encodeURIComponent(id)}${search}`;
|
|
202
|
-
const req = await createPayloadRequest({
|
|
203
|
-
config: payload.config,
|
|
204
|
-
request: new Request(url)
|
|
205
|
-
});
|
|
206
|
-
String(params.richText) === "true" ? true : false;
|
|
207
|
-
try {
|
|
208
|
-
const item = await payload.findByID({
|
|
209
|
-
collection: this.key,
|
|
210
|
-
id,
|
|
211
|
-
depth: params.depth,
|
|
212
|
-
locale: params.locale,
|
|
213
|
-
fallbackLocale: false,
|
|
214
|
-
req,
|
|
215
|
-
overrideAccess: false,
|
|
216
|
-
user,
|
|
217
|
-
disableErrors: true
|
|
218
|
-
});
|
|
219
|
-
if (item) return await this.decorateOne_(item, params);
|
|
220
|
-
} catch (error) {
|
|
221
|
-
console.log("LocalService", this.key, "findOne.error", error);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
async findMany(params = {}, token) {
|
|
225
|
-
if (["locale", "route"].includes(this.key)) {
|
|
226
|
-
params.richText = String(params.richText) === "true" ? true : false;
|
|
227
|
-
params.pagination = false;
|
|
228
|
-
const query$1 = qsSerialize(params);
|
|
229
|
-
const search$1 = query$1 ? `?${query$1}` : "";
|
|
230
|
-
const url$1 = `/${this.key}${search$1}`;
|
|
231
|
-
const response$1 = await remoteApiGet(url$1, getRemoteApiRequestOptions(token));
|
|
232
|
-
const items$1 = Array.isArray(response$1) ? response$1 : response$1.docs;
|
|
233
|
-
return await this.decorateMany_(items$1, params);
|
|
234
|
-
}
|
|
235
|
-
params.richText = String(params.richText) === "true" ? true : false;
|
|
236
|
-
params.pagination = false;
|
|
237
|
-
const payload = await getPayloadSingleton();
|
|
238
|
-
const user = await getPayloadUser(payload, token);
|
|
239
|
-
const query = qsSerialize(params);
|
|
240
|
-
const search = query ? `?${query}` : "";
|
|
241
|
-
const url = `http://mixer/${this.key}${search}`;
|
|
242
|
-
const req = await createPayloadRequest({
|
|
243
|
-
config: payload.config,
|
|
244
|
-
request: new Request(url)
|
|
245
|
-
});
|
|
246
|
-
const response = await payload.find({
|
|
247
|
-
collection: this.key,
|
|
248
|
-
depth: params.depth,
|
|
249
|
-
locale: params.locale,
|
|
250
|
-
fallbackLocale: false,
|
|
251
|
-
req,
|
|
252
|
-
overrideAccess: false,
|
|
253
|
-
user,
|
|
254
|
-
disableErrors: true
|
|
255
|
-
});
|
|
256
|
-
const items = Array.isArray(response) ? response : response.docs;
|
|
257
|
-
return await this.decorateMany_(items, params);
|
|
258
|
-
}
|
|
259
|
-
async findPaged(params = {}, token) {
|
|
260
|
-
if (["locale", "route"].includes(this.key)) {
|
|
261
|
-
params.richText = String(params.richText) === "true" ? true : false;
|
|
262
|
-
params.pagination = true;
|
|
263
|
-
const query$1 = qsSerialize(params);
|
|
264
|
-
const search$1 = query$1 ? `?${query$1}` : "";
|
|
265
|
-
const url$1 = `/${this.key}${search$1}`;
|
|
266
|
-
const response$1 = await remoteApiGet(url$1, getRemoteApiRequestOptions(token));
|
|
267
|
-
let items$1 = response$1.docs;
|
|
268
|
-
items$1 = await this.decorateMany_(items$1, params);
|
|
269
|
-
return {
|
|
270
|
-
...response$1,
|
|
271
|
-
docs: items$1
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
params.richText = String(params.richText) === "true" ? true : false;
|
|
275
|
-
params.pagination = true;
|
|
276
|
-
const payload = await getPayloadSingleton();
|
|
277
|
-
const user = await getPayloadUser(payload, token);
|
|
278
|
-
const query = qsSerialize(params);
|
|
279
|
-
const search = query ? `?${query}` : "";
|
|
280
|
-
const url = `http://mixer/${this.key}${search}`;
|
|
281
|
-
const req = await createPayloadRequest({
|
|
282
|
-
config: payload.config,
|
|
283
|
-
request: new Request(url)
|
|
284
|
-
});
|
|
285
|
-
const response = await payload.find({
|
|
286
|
-
collection: this.key,
|
|
287
|
-
depth: params.depth,
|
|
288
|
-
locale: params.locale,
|
|
289
|
-
fallbackLocale: false,
|
|
290
|
-
req,
|
|
291
|
-
overrideAccess: false,
|
|
292
|
-
user,
|
|
293
|
-
disableErrors: true
|
|
294
|
-
});
|
|
295
|
-
let items = response.docs;
|
|
296
|
-
items = await this.decorateMany_(items, params);
|
|
297
|
-
return {
|
|
298
|
-
...response,
|
|
299
|
-
docs: items
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
async create(payload, params = {}, token) {
|
|
303
|
-
params.richText = String(params.richText) === "true" ? true : false;
|
|
304
|
-
const query = qsSerialize(params);
|
|
305
|
-
const search = query ? `?${query}` : "";
|
|
306
|
-
const url = `/${this.key}${search}`;
|
|
307
|
-
const result = await localApiPost(url, payload, getRemoteApiRequestOptions(token));
|
|
308
|
-
const item = result.doc ? result.doc : result;
|
|
309
|
-
return await this.decorateOne_(item, {});
|
|
310
|
-
}
|
|
311
|
-
async updateOne(id, payload, params = {}, token) {
|
|
312
|
-
const query = qsSerialize(params);
|
|
313
|
-
const search = query ? `?${query}` : "";
|
|
314
|
-
const url = `/${this.key}/${encodeURIComponent(id)}${search}`;
|
|
315
|
-
const result = await localApiPatch(url, payload, getRemoteApiRequestOptions(token));
|
|
316
|
-
const item = result.doc ? result.doc : result;
|
|
317
|
-
return await this.decorateOne_(item, {});
|
|
318
|
-
}
|
|
319
|
-
async updateMany(payload, params = {}, token) {
|
|
320
|
-
params.richText = String(params.richText) === "true" ? true : false;
|
|
321
|
-
params.pagination = false;
|
|
322
|
-
const query = qsSerialize(params);
|
|
323
|
-
const search = query ? `?${query}` : "";
|
|
324
|
-
const url = `/${this.key}${search}`;
|
|
325
|
-
const response = await localApiPatch(url, payload, getRemoteApiRequestOptions(token));
|
|
326
|
-
const items = Array.isArray(response) ? response : response.docs;
|
|
327
|
-
return await this.decorateMany_(items, params);
|
|
328
|
-
}
|
|
329
|
-
async deleteOne(id, params = {}, token) {
|
|
330
|
-
const query = qsSerialize(params);
|
|
331
|
-
const search = query ? `?${query}` : "";
|
|
332
|
-
const url = `/${this.key}/${encodeURIComponent(id)}${search}`;
|
|
333
|
-
const item = await localApiDelete(url, getRemoteApiRequestOptions(token));
|
|
334
|
-
return await this.decorateOne_(item, {});
|
|
335
|
-
}
|
|
336
|
-
async deleteMany(params = {}, token) {
|
|
337
|
-
params.richText = String(params.richText) === "true" ? true : false;
|
|
338
|
-
params.pagination = false;
|
|
339
|
-
const query = qsSerialize(params);
|
|
340
|
-
const search = query ? `?${query}` : "";
|
|
341
|
-
const url = `/${this.key}${search}`;
|
|
342
|
-
const response = await localApiDelete(url, getRemoteApiRequestOptions(token));
|
|
343
|
-
const items = Array.isArray(response) ? response : response.docs;
|
|
344
|
-
return await this.decorateMany_(items, params);
|
|
345
|
-
}
|
|
346
|
-
async update(payload, params = {}, token) {
|
|
347
|
-
const url = `/${this.key}`;
|
|
348
|
-
const result = await localApiPatch(url, payload, getRemoteApiRequestOptions(token));
|
|
349
|
-
const item = result.doc ? result.doc : result;
|
|
350
|
-
return await this.decorateOne_(item, {});
|
|
351
|
-
}
|
|
352
|
-
async delete(id, token) {
|
|
353
|
-
const params = { where: { id: { equals: id } } };
|
|
354
|
-
const query = qsSerialize(params);
|
|
355
|
-
const search = query ? `?${query}` : "";
|
|
356
|
-
const url = `/${this.key}${search}`;
|
|
357
|
-
const item = await localApiDelete(url, getRemoteApiRequestOptions(token));
|
|
358
|
-
return await this.decorateOne_(item, {});
|
|
359
|
-
}
|
|
360
|
-
async decorateOne_(item, params = {}) {
|
|
361
|
-
let decoratedItem = item;
|
|
362
|
-
decoratedItem = await decorateSchema_(this.store, decoratedItem, this.key);
|
|
363
|
-
return decoratedItem;
|
|
364
|
-
}
|
|
365
|
-
async decorateMany_(items, params = {}) {
|
|
366
|
-
let decoratedItems = items;
|
|
367
|
-
decoratedItems = await decorateSchemas_(this.store, decoratedItems, this.key);
|
|
368
|
-
return decoratedItems;
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
|
|
372
38
|
//#endregion
|
|
373
39
|
//#region src/mock/mock.service.ts
|
|
374
40
|
var MockService = class extends JsonService {
|
|
@@ -384,7 +50,7 @@ var MockService = class extends JsonService {
|
|
|
384
50
|
decoratedItem = await decorateRelation_(store, decoratedItem, {
|
|
385
51
|
market: params.market,
|
|
386
52
|
locale: params.locale,
|
|
387
|
-
depth: params.depth != null ? params.depth :
|
|
53
|
+
depth: params.depth != null ? params.depth : 3
|
|
388
54
|
});
|
|
389
55
|
return decoratedItem;
|
|
390
56
|
}
|
|
@@ -395,12 +61,11 @@ var MockService = class extends JsonService {
|
|
|
395
61
|
decoratedItems = await decorateRelations_(store, decoratedItems, {
|
|
396
62
|
market: params.market,
|
|
397
63
|
locale: params.locale,
|
|
398
|
-
depth: params.depth != null ? params.depth :
|
|
64
|
+
depth: params.depth != null ? params.depth : 3
|
|
399
65
|
});
|
|
400
66
|
return decoratedItems;
|
|
401
67
|
}
|
|
402
68
|
};
|
|
403
|
-
|
|
404
69
|
//#endregion
|
|
405
70
|
//#region src/mock/mock-menu.service.ts
|
|
406
71
|
var MockMenuService = class extends MockService {
|
|
@@ -425,7 +90,6 @@ var MockMenuService = class extends MockService {
|
|
|
425
90
|
return decoratedItems;
|
|
426
91
|
}
|
|
427
92
|
};
|
|
428
|
-
|
|
429
93
|
//#endregion
|
|
430
94
|
//#region src/mock/mock-page.service.ts
|
|
431
95
|
var MockPageService = class extends MockService {
|
|
@@ -467,19 +131,16 @@ var MockPageService = class extends MockService {
|
|
|
467
131
|
return decoratedItems;
|
|
468
132
|
}
|
|
469
133
|
};
|
|
470
|
-
|
|
471
134
|
//#endregion
|
|
472
135
|
//#region src/session/session.service.ts
|
|
473
136
|
async function getSession(request, response) {
|
|
474
137
|
const COOKIE_NAME = "websolutespa-next-js";
|
|
475
138
|
const COOKIE_PASSWORD = process.env.MIXER_SECRET || "MIXER_SECRET_32_CHARS_LONG_12345";
|
|
476
|
-
|
|
139
|
+
return await getIronSession(request, response, {
|
|
477
140
|
cookieName: COOKIE_NAME,
|
|
478
141
|
cookieOptions: { secure: !isDevelopment },
|
|
479
142
|
password: COOKIE_PASSWORD
|
|
480
|
-
};
|
|
481
|
-
const session = await getIronSession(request, response, sessionOptions);
|
|
482
|
-
return session;
|
|
143
|
+
});
|
|
483
144
|
}
|
|
484
145
|
async function getSessionToken(request, response) {
|
|
485
146
|
const session = await getSession(request, response);
|
|
@@ -492,118 +153,11 @@ async function getSessionToken(request, response) {
|
|
|
492
153
|
return;
|
|
493
154
|
}
|
|
494
155
|
}
|
|
495
|
-
|
|
496
|
-
//#endregion
|
|
497
|
-
//#region src/cached/cached.service.ts
|
|
498
|
-
var CachedService = class extends JsonService {
|
|
499
|
-
service_;
|
|
500
|
-
cache_ = /* @__PURE__ */ new Map();
|
|
501
|
-
duration_ = storeCacheDuration;
|
|
502
|
-
constructor(service, options = {}) {
|
|
503
|
-
super([]);
|
|
504
|
-
if (!service) throw new Error("CachedService: service is required");
|
|
505
|
-
this.service_ = service;
|
|
506
|
-
this.duration_ = typeof options.duration !== "undefined" ? options.duration : this.duration_;
|
|
507
|
-
}
|
|
508
|
-
async fromCache_(callback, key) {
|
|
509
|
-
if (key && this.hasKey_(key)) return this.getKey_(key);
|
|
510
|
-
else {
|
|
511
|
-
const t = await callback();
|
|
512
|
-
if (key && t) this.setKey_(key, t);
|
|
513
|
-
return t;
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
isExpired_(item) {
|
|
517
|
-
return this.duration_ === false ? true : item.timestamp < (/* @__PURE__ */ new Date()).getTime() - this.duration_;
|
|
518
|
-
}
|
|
519
|
-
hasKey_(key) {
|
|
520
|
-
const item = this.cache_.get(key);
|
|
521
|
-
return item ? !this.isExpired_(item) : false;
|
|
522
|
-
}
|
|
523
|
-
getKey_(key) {
|
|
524
|
-
return this.cache_.get(key).data;
|
|
525
|
-
}
|
|
526
|
-
setKey_(key, data) {
|
|
527
|
-
this.cache_.set(key, {
|
|
528
|
-
timestamp: (/* @__PURE__ */ new Date()).getTime(),
|
|
529
|
-
data
|
|
530
|
-
});
|
|
531
|
-
}
|
|
532
|
-
async findGlobal(params = {}) {
|
|
533
|
-
const serializedParams = qsSerialize(params);
|
|
534
|
-
const key = `findGlobal?${serializedParams}`;
|
|
535
|
-
return await this.fromCache_(async () => {
|
|
536
|
-
return await this.service_.findGlobal(params);
|
|
537
|
-
}, key);
|
|
538
|
-
}
|
|
539
|
-
async findOne(id, params = {}) {
|
|
540
|
-
const serializedParams = qsSerialize(params);
|
|
541
|
-
const key = `findOne[${id}]?${serializedParams}`;
|
|
542
|
-
return await this.fromCache_(async () => {
|
|
543
|
-
return await this.service_.findOne(id, params);
|
|
544
|
-
}, key);
|
|
545
|
-
}
|
|
546
|
-
async findMany(params = {}) {
|
|
547
|
-
if (storeStrategy === StoreStrategy.DecoratedApi) {
|
|
548
|
-
const { market, locale,...otherParams } = params;
|
|
549
|
-
const serializedParams = qsSerialize({
|
|
550
|
-
market,
|
|
551
|
-
locale
|
|
552
|
-
});
|
|
553
|
-
const key = `findMany?${serializedParams}`;
|
|
554
|
-
let items = await this.fromCache_(async () => {
|
|
555
|
-
return await this.service_.findMany({
|
|
556
|
-
market,
|
|
557
|
-
locale
|
|
558
|
-
});
|
|
559
|
-
}, key);
|
|
560
|
-
if (otherParams.where) items = this.whereItems_(items, otherParams.where);
|
|
561
|
-
if (otherParams.sort) items = this.sortCollection_(items, otherParams.sort);
|
|
562
|
-
return items;
|
|
563
|
-
} else {
|
|
564
|
-
const serializedParams = qsSerialize(params);
|
|
565
|
-
const key = `findMany?${serializedParams}`;
|
|
566
|
-
return await this.fromCache_(async () => {
|
|
567
|
-
return await this.service_.findMany(params);
|
|
568
|
-
}, key);
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
async findPaged(params = {}) {
|
|
572
|
-
const serializedParams = qsSerialize(params);
|
|
573
|
-
const key = `findPaged?${serializedParams}`;
|
|
574
|
-
return await this.fromCache_(async () => {
|
|
575
|
-
return await this.service_.findPaged(params);
|
|
576
|
-
}, key);
|
|
577
|
-
}
|
|
578
|
-
async create(payload) {
|
|
579
|
-
return await this.service_.create(payload);
|
|
580
|
-
}
|
|
581
|
-
async updateOne(id, payload, params = {}) {
|
|
582
|
-
return await this.service_.updateOne(id, payload, params);
|
|
583
|
-
}
|
|
584
|
-
async updateMany(payload, params = {}) {
|
|
585
|
-
return await this.service_.updateMany(payload, params);
|
|
586
|
-
}
|
|
587
|
-
async deleteOne(id, params = {}) {
|
|
588
|
-
return await this.service_.deleteOne(id, params);
|
|
589
|
-
}
|
|
590
|
-
async deleteMany(params = {}) {
|
|
591
|
-
return await this.service_.deleteMany(params);
|
|
592
|
-
}
|
|
593
|
-
async update(payload) {
|
|
594
|
-
return await this.service_.update(payload);
|
|
595
|
-
}
|
|
596
|
-
async delete(id) {
|
|
597
|
-
return await this.service_.delete(id);
|
|
598
|
-
}
|
|
599
|
-
};
|
|
600
|
-
|
|
601
156
|
//#endregion
|
|
602
157
|
//#region src/fs/fs.service.ts
|
|
603
158
|
async function fsRead(pathname, option) {
|
|
604
159
|
try {
|
|
605
|
-
|
|
606
|
-
return data || void 0;
|
|
160
|
+
return await fs.promises.readFile(pathname, option?.encoding || "utf8") || void 0;
|
|
607
161
|
} catch (error) {
|
|
608
162
|
console.log("fsRead.error", error, pathname);
|
|
609
163
|
return;
|
|
@@ -619,7 +173,6 @@ async function fsReadJson(pathname) {
|
|
|
619
173
|
return;
|
|
620
174
|
}
|
|
621
175
|
}
|
|
622
|
-
|
|
623
176
|
//#endregion
|
|
624
177
|
//#region src/static/static.service.ts
|
|
625
178
|
var StaticService = class extends JsonService {
|
|
@@ -648,10 +201,8 @@ var StaticService = class extends JsonService {
|
|
|
648
201
|
else {
|
|
649
202
|
const config = this.config;
|
|
650
203
|
const src = config.src;
|
|
651
|
-
if (typeof src === "string") {
|
|
652
|
-
|
|
653
|
-
items = response.items;
|
|
654
|
-
} else if (typeof src === "function") if (src instanceof Promise) items = await src(config);
|
|
204
|
+
if (typeof src === "string") items = (await httpGet(src, {})).items;
|
|
205
|
+
else if (typeof src === "function") if (src instanceof Promise) items = await src(config);
|
|
655
206
|
else items = src(config);
|
|
656
207
|
else items = src;
|
|
657
208
|
items = this.mapItems_(items, config.map);
|
|
@@ -684,7 +235,7 @@ var StaticService = class extends JsonService {
|
|
|
684
235
|
}
|
|
685
236
|
};
|
|
686
237
|
async function decorateStaticRelation_(store, fields, item, params = {}) {
|
|
687
|
-
const depth = params.depth != null ? params.depth :
|
|
238
|
+
const depth = params.depth != null ? params.depth : 3;
|
|
688
239
|
if (depth === 0) return item;
|
|
689
240
|
const decoratedItem = { ...item };
|
|
690
241
|
for (const field of fields) if (field.type === "relationship" && typeof field.relationTo === "string") {
|
|
@@ -709,17 +260,13 @@ async function decorateStaticRelations_(store, fields, items, params = {}) {
|
|
|
709
260
|
}
|
|
710
261
|
return decoratedItems;
|
|
711
262
|
}
|
|
712
|
-
|
|
713
263
|
//#endregion
|
|
714
264
|
//#region src/mock/mock.store.ts
|
|
715
|
-
const PAGES$
|
|
265
|
+
const PAGES$1 = process.env.PAGES ? process.env.PAGES.split(",") : [];
|
|
716
266
|
function getMockStoreFromData_(data) {
|
|
717
267
|
const store = {};
|
|
718
268
|
if (data) {
|
|
719
|
-
for (const key in data) if (!PAGES$
|
|
720
|
-
const service = new MockService(data[key], store);
|
|
721
|
-
store[key] = service;
|
|
722
|
-
}
|
|
269
|
+
for (const key in data) if (!PAGES$1.includes(key)) store[key] = new MockService(data[key], store);
|
|
723
270
|
const category = store.category;
|
|
724
271
|
if (!category) console.warn("mock category not found");
|
|
725
272
|
const route = store.route;
|
|
@@ -727,10 +274,7 @@ function getMockStoreFromData_(data) {
|
|
|
727
274
|
if (category && route) {
|
|
728
275
|
const menu = data.menu;
|
|
729
276
|
if (menu) store.menu = new MockMenuService(menu, store);
|
|
730
|
-
for (const key in data) if (PAGES$
|
|
731
|
-
const service = new MockPageService(data[key], store);
|
|
732
|
-
store[key] = service;
|
|
733
|
-
}
|
|
277
|
+
for (const key in data) if (PAGES$1.includes(key)) store[key] = new MockPageService(data[key], store);
|
|
734
278
|
}
|
|
735
279
|
} else console.warn("mock store not found");
|
|
736
280
|
staticCollections.forEach((config) => {
|
|
@@ -742,127 +286,124 @@ async function getStoreData_() {
|
|
|
742
286
|
if (isDevelopment) {
|
|
743
287
|
const path = __require("path");
|
|
744
288
|
const directory = "cwd" in process && typeof process.cwd === "function" ? process.cwd() : process.env.CWD;
|
|
745
|
-
|
|
746
|
-
return await fsReadJson(pathname) || {};
|
|
289
|
+
return await fsReadJson(path.join(directory, ".mixer", "store.json")) || {};
|
|
747
290
|
} else {
|
|
748
291
|
const store = process.env.STORE_ || {};
|
|
749
292
|
return typeof store === "string" ? JSON.parse(store) : store;
|
|
750
293
|
}
|
|
751
294
|
}
|
|
752
295
|
async function getMockStore_() {
|
|
753
|
-
|
|
754
|
-
const store = getMockStoreFromData_(data);
|
|
755
|
-
return store;
|
|
296
|
+
return getMockStoreFromData_(await getStoreData_());
|
|
756
297
|
}
|
|
757
298
|
async function getMockStore() {
|
|
758
299
|
return fromCache(async () => {
|
|
759
300
|
if (!isDevelopment) console.warn("getMockStore");
|
|
760
|
-
|
|
761
|
-
return store;
|
|
301
|
+
return await getMockStore_();
|
|
762
302
|
}, isDevelopment ? void 0 : "STORE_MOCK_");
|
|
763
303
|
}
|
|
764
|
-
|
|
765
304
|
//#endregion
|
|
766
|
-
//#region src/
|
|
767
|
-
var
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
if (
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
});
|
|
777
|
-
return decoratedItem;
|
|
305
|
+
//#region src/cached/cached.service.ts
|
|
306
|
+
var CachedService = class extends JsonService {
|
|
307
|
+
service_;
|
|
308
|
+
cache_ = /* @__PURE__ */ new Map();
|
|
309
|
+
duration_ = storeCacheDuration;
|
|
310
|
+
constructor(service, options = {}) {
|
|
311
|
+
super([]);
|
|
312
|
+
if (!service) throw new Error("CachedService: service is required");
|
|
313
|
+
this.service_ = service;
|
|
314
|
+
this.duration_ = typeof options.duration !== "undefined" ? options.duration : this.duration_;
|
|
778
315
|
}
|
|
779
|
-
async
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
locale: params.locale
|
|
787
|
-
});
|
|
788
|
-
return decoratedItems;
|
|
316
|
+
async fromCache_(callback, key) {
|
|
317
|
+
if (key && this.hasKey_(key)) return this.getKey_(key);
|
|
318
|
+
else {
|
|
319
|
+
const t = await callback();
|
|
320
|
+
if (key && t) this.setKey_(key, t);
|
|
321
|
+
return t;
|
|
322
|
+
}
|
|
789
323
|
}
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
//#endregion
|
|
793
|
-
//#region src/local_/local-page.service.ts
|
|
794
|
-
var LocalPageService = class extends LocalService {
|
|
795
|
-
async decorateOne_(item, params = {}) {
|
|
796
|
-
const store = this.store;
|
|
797
|
-
let decoratedItem = item;
|
|
798
|
-
decoratedItem = await decorateSchema_(store, decoratedItem, this.key);
|
|
799
|
-
decoratedItem = await decorateCategory_(store, decoratedItem, params);
|
|
800
|
-
decoratedItem = await decorateHref_(store, decoratedItem, params);
|
|
801
|
-
decoratedItem = await decorateNav_(store, decoratedItem, params);
|
|
802
|
-
decoratedItem = await decorateRelation_(store, decoratedItem, {
|
|
803
|
-
market: params.market,
|
|
804
|
-
locale: params.locale,
|
|
805
|
-
depth: params.depth
|
|
806
|
-
});
|
|
807
|
-
return decoratedItem;
|
|
324
|
+
isExpired_(item) {
|
|
325
|
+
return this.duration_ === false ? true : item.timestamp < (/* @__PURE__ */ new Date()).getTime() - this.duration_;
|
|
808
326
|
}
|
|
809
|
-
|
|
810
|
-
const
|
|
811
|
-
|
|
812
|
-
decoratedItems = await decorateSchemas_(store, decoratedItems, this.key);
|
|
813
|
-
decoratedItems = await decorateCategories_(store, decoratedItems, params);
|
|
814
|
-
decoratedItems = await decorateHrefs_(store, decoratedItems, params);
|
|
815
|
-
return decoratedItems;
|
|
327
|
+
hasKey_(key) {
|
|
328
|
+
const item = this.cache_.get(key);
|
|
329
|
+
return item ? !this.isExpired_(item) : false;
|
|
816
330
|
}
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
if (COLLECTIONS.length === 0) {
|
|
825
|
-
console.error("LocalStore.getLocalStore_ no collections");
|
|
826
|
-
throw "LocalStore.getLocalStore_ no collections";
|
|
827
|
-
}
|
|
828
|
-
let mockStore = {};
|
|
829
|
-
if (MOCK_COLLECTIONS.length > 0) mockStore = await getMockStore();
|
|
830
|
-
const store = {};
|
|
831
|
-
COLLECTIONS.sort();
|
|
832
|
-
COLLECTIONS.forEach((key) => {
|
|
833
|
-
if (MOCK_COLLECTIONS.includes(key)) store[key] = mockStore[key];
|
|
834
|
-
else if (PAGES$1.includes(key) && storeStrategy === StoreStrategy.DecoratedApi) store[key] = new LocalPageService(key, store);
|
|
835
|
-
else if (key === "menu" && storeStrategy === StoreStrategy.DecoratedApi) store[key] = new CachedService(new LocalMenuService(key, store));
|
|
836
|
-
else if (KNOWN_COLLECTIONS.includes(key)) store[key] = new CachedService(new LocalService(key, store));
|
|
837
|
-
else store[key] = new LocalService(key, store);
|
|
331
|
+
getKey_(key) {
|
|
332
|
+
return this.cache_.get(key).data;
|
|
333
|
+
}
|
|
334
|
+
setKey_(key, data) {
|
|
335
|
+
this.cache_.set(key, {
|
|
336
|
+
timestamp: (/* @__PURE__ */ new Date()).getTime(),
|
|
337
|
+
data
|
|
838
338
|
});
|
|
839
|
-
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
const
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
339
|
+
}
|
|
340
|
+
async findGlobal(params = {}) {
|
|
341
|
+
const key = `findGlobal?${qsSerialize(params)}`;
|
|
342
|
+
return await this.fromCache_(async () => {
|
|
343
|
+
return await this.service_.findGlobal(params);
|
|
344
|
+
}, key);
|
|
345
|
+
}
|
|
346
|
+
async findOne(id, params = {}) {
|
|
347
|
+
const key = `findOne[${id}]?${qsSerialize(params)}`;
|
|
348
|
+
return await this.fromCache_(async () => {
|
|
349
|
+
return await this.service_.findOne(id, params);
|
|
350
|
+
}, key);
|
|
351
|
+
}
|
|
352
|
+
async findMany(params = {}) {
|
|
353
|
+
if (storeStrategy === StoreStrategy.DecoratedApi) {
|
|
354
|
+
const { market, locale, ...otherParams } = params;
|
|
355
|
+
const key = `findMany?${qsSerialize({
|
|
356
|
+
market,
|
|
357
|
+
locale
|
|
358
|
+
})}`;
|
|
359
|
+
let items = await this.fromCache_(async () => {
|
|
360
|
+
return await this.service_.findMany({
|
|
361
|
+
market,
|
|
362
|
+
locale
|
|
363
|
+
});
|
|
364
|
+
}, key);
|
|
365
|
+
if (otherParams.where) items = this.whereItems_(items, otherParams.where);
|
|
366
|
+
if (otherParams.sort) items = this.sortCollection_(items, otherParams.sort);
|
|
367
|
+
return items;
|
|
368
|
+
} else {
|
|
369
|
+
const key = `findMany?${qsSerialize(params)}`;
|
|
370
|
+
return await this.fromCache_(async () => {
|
|
371
|
+
return await this.service_.findMany(params);
|
|
372
|
+
}, key);
|
|
851
373
|
}
|
|
852
|
-
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
}
|
|
859
|
-
|
|
374
|
+
}
|
|
375
|
+
async findPaged(params = {}) {
|
|
376
|
+
const key = `findPaged?${qsSerialize(params)}`;
|
|
377
|
+
return await this.fromCache_(async () => {
|
|
378
|
+
return await this.service_.findPaged(params);
|
|
379
|
+
}, key);
|
|
380
|
+
}
|
|
381
|
+
async create(payload) {
|
|
382
|
+
return await this.service_.create(payload);
|
|
383
|
+
}
|
|
384
|
+
async updateOne(id, payload, params = {}) {
|
|
385
|
+
return await this.service_.updateOne(id, payload, params);
|
|
386
|
+
}
|
|
387
|
+
async updateMany(payload, params = {}) {
|
|
388
|
+
return await this.service_.updateMany(payload, params);
|
|
389
|
+
}
|
|
390
|
+
async deleteOne(id, params = {}) {
|
|
391
|
+
return await this.service_.deleteOne(id, params);
|
|
392
|
+
}
|
|
393
|
+
async deleteMany(params = {}) {
|
|
394
|
+
return await this.service_.deleteMany(params);
|
|
395
|
+
}
|
|
396
|
+
async update(payload) {
|
|
397
|
+
return await this.service_.update(payload);
|
|
398
|
+
}
|
|
399
|
+
async delete(id) {
|
|
400
|
+
return await this.service_.delete(id);
|
|
401
|
+
}
|
|
402
|
+
};
|
|
860
403
|
//#endregion
|
|
861
404
|
//#region src/remote/remote.service.ts
|
|
862
405
|
/**
|
|
863
|
-
|
|
864
406
|
* This service handle call to remote api (bowl or over)
|
|
865
|
-
|
|
866
407
|
*/
|
|
867
408
|
var RemoteService = class {
|
|
868
409
|
key;
|
|
@@ -903,8 +444,7 @@ var RemoteService = class {
|
|
|
903
444
|
params.pagination = false;
|
|
904
445
|
const query = qsSerialize(params);
|
|
905
446
|
const search = query ? `?${query}` : "";
|
|
906
|
-
const
|
|
907
|
-
const response = await remoteApiGet(url, getRemoteApiRequestOptions(token));
|
|
447
|
+
const response = await remoteApiGet(`/${this.key}${search}`, getRemoteApiRequestOptions(token));
|
|
908
448
|
const items = Array.isArray(response) ? response : response.docs;
|
|
909
449
|
return await this.decorateMany_(items, params);
|
|
910
450
|
}
|
|
@@ -913,8 +453,7 @@ var RemoteService = class {
|
|
|
913
453
|
params.pagination = true;
|
|
914
454
|
const query = qsSerialize(params);
|
|
915
455
|
const search = query ? `?${query}` : "";
|
|
916
|
-
const
|
|
917
|
-
const response = await remoteApiGet(url, getRemoteApiRequestOptions(token));
|
|
456
|
+
const response = await remoteApiGet(`/${this.key}${search}`, getRemoteApiRequestOptions(token));
|
|
918
457
|
let items = response.docs;
|
|
919
458
|
items = await this.decorateMany_(items, params);
|
|
920
459
|
return {
|
|
@@ -926,16 +465,14 @@ var RemoteService = class {
|
|
|
926
465
|
params.richText = String(params.richText) === "true" ? true : false;
|
|
927
466
|
const query = qsSerialize(params);
|
|
928
467
|
const search = query ? `?${query}` : "";
|
|
929
|
-
const
|
|
930
|
-
const result = await remoteApiPost(url, payload, getRemoteApiRequestOptions(token));
|
|
468
|
+
const result = await remoteApiPost(`/${this.key}${search}`, payload, getRemoteApiRequestOptions(token));
|
|
931
469
|
const item = result.doc ? result.doc : result;
|
|
932
470
|
return await this.decorateOne_(item, {});
|
|
933
471
|
}
|
|
934
472
|
async updateOne(id, payload, params = {}, token) {
|
|
935
473
|
const query = qsSerialize(params);
|
|
936
474
|
const search = query ? `?${query}` : "";
|
|
937
|
-
const
|
|
938
|
-
const result = await remoteApiPatch(url, payload, getRemoteApiRequestOptions(token));
|
|
475
|
+
const result = await remoteApiPatch(`/${this.key}/${encodeURIComponent(id)}${search}`, payload, getRemoteApiRequestOptions(token));
|
|
939
476
|
const item = result.doc ? result.doc : result;
|
|
940
477
|
return await this.decorateOne_(item, {});
|
|
941
478
|
}
|
|
@@ -944,16 +481,14 @@ var RemoteService = class {
|
|
|
944
481
|
params.pagination = false;
|
|
945
482
|
const query = qsSerialize(params);
|
|
946
483
|
const search = query ? `?${query}` : "";
|
|
947
|
-
const
|
|
948
|
-
const response = await remoteApiPatch(url, payload, getRemoteApiRequestOptions(token));
|
|
484
|
+
const response = await remoteApiPatch(`/${this.key}${search}`, payload, getRemoteApiRequestOptions(token));
|
|
949
485
|
const items = Array.isArray(response) ? response : response.docs;
|
|
950
486
|
return await this.decorateMany_(items, params);
|
|
951
487
|
}
|
|
952
488
|
async deleteOne(id, params = {}, token) {
|
|
953
489
|
const query = qsSerialize(params);
|
|
954
490
|
const search = query ? `?${query}` : "";
|
|
955
|
-
const
|
|
956
|
-
const item = await remoteApiDelete(url, getRemoteApiRequestOptions(token));
|
|
491
|
+
const item = await remoteApiDelete(`/${this.key}/${encodeURIComponent(id)}${search}`, getRemoteApiRequestOptions(token));
|
|
957
492
|
return await this.decorateOne_(item, {});
|
|
958
493
|
}
|
|
959
494
|
async deleteMany(params = {}, token) {
|
|
@@ -961,23 +496,19 @@ var RemoteService = class {
|
|
|
961
496
|
params.pagination = false;
|
|
962
497
|
const query = qsSerialize(params);
|
|
963
498
|
const search = query ? `?${query}` : "";
|
|
964
|
-
const
|
|
965
|
-
const response = await remoteApiDelete(url, getRemoteApiRequestOptions(token));
|
|
499
|
+
const response = await remoteApiDelete(`/${this.key}${search}`, getRemoteApiRequestOptions(token));
|
|
966
500
|
const items = Array.isArray(response) ? response : response.docs;
|
|
967
501
|
return await this.decorateMany_(items, params);
|
|
968
502
|
}
|
|
969
503
|
async update(payload, params = {}, token) {
|
|
970
|
-
const
|
|
971
|
-
const result = await remoteApiPatch(url, payload, getRemoteApiRequestOptions(token));
|
|
504
|
+
const result = await remoteApiPatch(`/${this.key}`, payload, getRemoteApiRequestOptions(token));
|
|
972
505
|
const item = result.doc ? result.doc : result;
|
|
973
506
|
return await this.decorateOne_(item, {});
|
|
974
507
|
}
|
|
975
508
|
async delete(id, token) {
|
|
976
|
-
const
|
|
977
|
-
const query = qsSerialize(params);
|
|
509
|
+
const query = qsSerialize({ where: { id: { equals: id } } });
|
|
978
510
|
const search = query ? `?${query}` : "";
|
|
979
|
-
const
|
|
980
|
-
const item = await remoteApiDelete(url, getRemoteApiRequestOptions(token));
|
|
511
|
+
const item = await remoteApiDelete(`/${this.key}${search}`, getRemoteApiRequestOptions(token));
|
|
981
512
|
return await this.decorateOne_(item, {});
|
|
982
513
|
}
|
|
983
514
|
async decorateOne_(item, params = {}) {
|
|
@@ -991,7 +522,6 @@ var RemoteService = class {
|
|
|
991
522
|
return decoratedItems;
|
|
992
523
|
}
|
|
993
524
|
};
|
|
994
|
-
|
|
995
525
|
//#endregion
|
|
996
526
|
//#region src/remote/remote-menu.service.ts
|
|
997
527
|
var RemoteMenuService = class extends RemoteService {
|
|
@@ -1018,7 +548,6 @@ var RemoteMenuService = class extends RemoteService {
|
|
|
1018
548
|
return decoratedItems;
|
|
1019
549
|
}
|
|
1020
550
|
};
|
|
1021
|
-
|
|
1022
551
|
//#endregion
|
|
1023
552
|
//#region src/remote/remote-page.service.ts
|
|
1024
553
|
var RemotePageService = class extends RemoteService {
|
|
@@ -1045,7 +574,6 @@ var RemotePageService = class extends RemoteService {
|
|
|
1045
574
|
return decoratedItems;
|
|
1046
575
|
}
|
|
1047
576
|
};
|
|
1048
|
-
|
|
1049
577
|
//#endregion
|
|
1050
578
|
//#region src/remote/remote.store.ts
|
|
1051
579
|
const PAGES = process.env.PAGES ? process.env.PAGES.split(",") : [];
|
|
@@ -1073,12 +601,8 @@ async function getRemoteStoreStaticBuild_() {
|
|
|
1073
601
|
return fromCache(async () => {
|
|
1074
602
|
console.log("getRemoteStoreStaticBuild_");
|
|
1075
603
|
let store = {};
|
|
1076
|
-
const
|
|
1077
|
-
|
|
1078
|
-
if (json != null) {
|
|
1079
|
-
const data = Object.fromEntries(COLLECTIONS.map((key) => [key, json[key] || []]));
|
|
1080
|
-
store = getMockStoreFromData_(data);
|
|
1081
|
-
}
|
|
604
|
+
const json = await remoteApiGet(`/store?strategy=${buildStrategy}`);
|
|
605
|
+
if (json != null) store = getMockStoreFromData_(Object.fromEntries(COLLECTIONS.map((key) => [key, json[key] || []])));
|
|
1082
606
|
return store;
|
|
1083
607
|
}, "STORE_BUILD_");
|
|
1084
608
|
}
|
|
@@ -1086,17 +610,14 @@ async function getRemoteStore() {
|
|
|
1086
610
|
if (nextPhase === NextPhase.ProductionBuild) return await getRemoteStoreStaticBuild_();
|
|
1087
611
|
else return await getRemoteStore_();
|
|
1088
612
|
}
|
|
1089
|
-
|
|
1090
613
|
//#endregion
|
|
1091
614
|
//#region src/store/store.service.ts
|
|
1092
615
|
async function getStore() {
|
|
1093
616
|
switch (storeStrategy) {
|
|
1094
617
|
case StoreStrategy.Mock: return await getMockStore();
|
|
1095
|
-
case StoreStrategy.Local: return await getLocalStore();
|
|
1096
618
|
default: return await getRemoteStore();
|
|
1097
619
|
}
|
|
1098
620
|
}
|
|
1099
|
-
|
|
1100
621
|
//#endregion
|
|
1101
622
|
//#region src/store/store.handler.ts
|
|
1102
623
|
function storeHandler(storePromise = async () => await getStore()) {
|
|
@@ -1110,21 +631,19 @@ function storeHandler(storePromise = async () => await getStore()) {
|
|
|
1110
631
|
function collectionGet(storePromise) {
|
|
1111
632
|
return async (request, response) => {
|
|
1112
633
|
try {
|
|
1113
|
-
const { collections
|
|
634
|
+
const { collections, ...query } = request.query;
|
|
1114
635
|
if (!Array.isArray(collections) || collections?.length === 0) {
|
|
1115
636
|
console.error("storeHandler.collectionGet", "method not allowed", collections);
|
|
1116
637
|
return response.status(405).send("method not allowed");
|
|
1117
638
|
}
|
|
1118
639
|
const collection = collections[0];
|
|
1119
640
|
const id = collections[1];
|
|
1120
|
-
const
|
|
1121
|
-
const params = qsDeserialize(qs);
|
|
641
|
+
const params = qsDeserialize(Object.entries(query).map((kv) => kv.join("=")).join("&"));
|
|
1122
642
|
if (!COLLECTIONS.includes(collection)) {
|
|
1123
643
|
console.error("storeHandler.collectionGet", "method not allowed", collection);
|
|
1124
644
|
return response.status(405).send("method not allowed");
|
|
1125
645
|
}
|
|
1126
|
-
const
|
|
1127
|
-
const service = store[collection];
|
|
646
|
+
const service = (await storePromise())[collection];
|
|
1128
647
|
if (!service) {
|
|
1129
648
|
console.error("storeHandler.collectionGet", "method not allowed", collection);
|
|
1130
649
|
return response.status(405).send("method not allowed");
|
|
@@ -1150,19 +669,17 @@ function collectionGet(storePromise) {
|
|
|
1150
669
|
function collectionPost(storePromise) {
|
|
1151
670
|
return async (request, response) => {
|
|
1152
671
|
try {
|
|
1153
|
-
const { collections
|
|
672
|
+
const { collections, ...query } = request.query;
|
|
1154
673
|
if (!Array.isArray(collections) || collections.length !== 1) {
|
|
1155
674
|
console.error("method not allowed", collections);
|
|
1156
675
|
return response.status(405).send("method not allowed");
|
|
1157
676
|
}
|
|
1158
677
|
const collection = collections[0];
|
|
1159
|
-
|
|
1160
|
-
if (id) {
|
|
678
|
+
if (collections[1]) {
|
|
1161
679
|
console.error("method not allowed", collection);
|
|
1162
680
|
return response.status(405).send("method not allowed");
|
|
1163
681
|
}
|
|
1164
|
-
const
|
|
1165
|
-
const params = qsDeserialize(qs);
|
|
682
|
+
const params = qsDeserialize(Object.entries(query).map((kv) => kv.join("=")).join("&"));
|
|
1166
683
|
const store = await storePromise();
|
|
1167
684
|
const service = store[collection];
|
|
1168
685
|
if (!service) {
|
|
@@ -1183,7 +700,7 @@ function collectionPost(storePromise) {
|
|
|
1183
700
|
function collectionPatch(storePromise) {
|
|
1184
701
|
return async (request, response) => {
|
|
1185
702
|
try {
|
|
1186
|
-
const { collections
|
|
703
|
+
const { collections, ...query } = request.query;
|
|
1187
704
|
if (!Array.isArray(collections) || collections?.length === 0) {
|
|
1188
705
|
console.error("storeHandler.collectionUpdate", "method not allowed", collections);
|
|
1189
706
|
return response.status(405).send("method not allowed");
|
|
@@ -1194,14 +711,12 @@ function collectionPatch(storePromise) {
|
|
|
1194
711
|
}
|
|
1195
712
|
const collection = collections[0];
|
|
1196
713
|
const id = collections[1];
|
|
1197
|
-
const
|
|
1198
|
-
const params = qsDeserialize(qs);
|
|
714
|
+
const params = qsDeserialize(Object.entries(query).map((kv) => kv.join("=")).join("&"));
|
|
1199
715
|
if (!COLLECTIONS.includes(collection)) {
|
|
1200
716
|
console.error("storeHandler.collectionUpdate", "method not allowed", collection);
|
|
1201
717
|
return response.status(405).send("method not allowed");
|
|
1202
718
|
}
|
|
1203
|
-
const
|
|
1204
|
-
const service = store[collection];
|
|
719
|
+
const service = (await storePromise())[collection];
|
|
1205
720
|
if (!service) {
|
|
1206
721
|
console.error("storeHandler.collectionUpdate", "method not allowed", collection);
|
|
1207
722
|
return response.status(405).send("method not allowed");
|
|
@@ -1225,7 +740,7 @@ function collectionPatch(storePromise) {
|
|
|
1225
740
|
function collectionDelete(storePromise) {
|
|
1226
741
|
return async (request, response) => {
|
|
1227
742
|
try {
|
|
1228
|
-
const { collections
|
|
743
|
+
const { collections, ...query } = request.query;
|
|
1229
744
|
if (!Array.isArray(collections) || collections?.length === 0) {
|
|
1230
745
|
console.error("storeHandler.collectionDelete", "method not allowed", collections);
|
|
1231
746
|
return response.status(405).send("method not allowed");
|
|
@@ -1236,14 +751,12 @@ function collectionDelete(storePromise) {
|
|
|
1236
751
|
}
|
|
1237
752
|
const collection = collections[0];
|
|
1238
753
|
const id = collections[1];
|
|
1239
|
-
const
|
|
1240
|
-
const params = qsDeserialize(qs);
|
|
754
|
+
const params = qsDeserialize(Object.entries(query).map((kv) => kv.join("=")).join("&"));
|
|
1241
755
|
if (!COLLECTIONS.includes(collection)) {
|
|
1242
756
|
console.error("storeHandler.collectionDelete", "method not allowed", collection);
|
|
1243
757
|
return response.status(405).send("method not allowed");
|
|
1244
758
|
}
|
|
1245
|
-
const
|
|
1246
|
-
const service = store[collection];
|
|
759
|
+
const service = (await storePromise())[collection];
|
|
1247
760
|
if (!service) {
|
|
1248
761
|
console.error("storeHandler.collectionDelete", "method not allowed", collection);
|
|
1249
762
|
return response.status(405).send("method not allowed");
|
|
@@ -1440,10 +953,8 @@ async function findRoute(store, pathname, href, hrefBeforeRedirect) {
|
|
|
1440
953
|
const routes = await store.route.findMany({ where: { id: { equals: pathname } } });
|
|
1441
954
|
if (routes.length > 0) return routes[0];
|
|
1442
955
|
else {
|
|
1443
|
-
const
|
|
1444
|
-
|
|
1445
|
-
const match = pathname.indexOf(c.id) === 0;
|
|
1446
|
-
if (match && (!p || p.id.length < c.id.length)) return {
|
|
956
|
+
const splatRoute = (await store.route.findMany({ where: { useSplat: { equals: true } } })).reduce((p, c) => {
|
|
957
|
+
if (pathname.indexOf(c.id) === 0 && (!p || p.id.length < c.id.length)) return {
|
|
1447
958
|
...c,
|
|
1448
959
|
splat: pathname.substring(c.id.length, pathname.length)
|
|
1449
960
|
};
|
|
@@ -1461,13 +972,11 @@ async function findRoute(store, pathname, href, hrefBeforeRedirect) {
|
|
|
1461
972
|
}));
|
|
1462
973
|
const exactMatchResolver = (redirect) => {
|
|
1463
974
|
const status = parseInt(redirect.status) || 307;
|
|
1464
|
-
if (status < 400) {
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
};
|
|
1470
|
-
} else throw { status };
|
|
975
|
+
if (status < 400) throw {
|
|
976
|
+
status,
|
|
977
|
+
redirectUrl: sanitizeRedirectUrl(redirect.to, url)
|
|
978
|
+
};
|
|
979
|
+
else throw { status };
|
|
1471
980
|
};
|
|
1472
981
|
const exactMatchRedirect = redirects.find((x) => x.from === sanitizedHref);
|
|
1473
982
|
if (exactMatchRedirect !== void 0) return exactMatchResolver(exactMatchRedirect);
|
|
@@ -1498,13 +1007,11 @@ async function findRoute(store, pathname, href, hrefBeforeRedirect) {
|
|
|
1498
1007
|
throw { status: 404 };
|
|
1499
1008
|
}
|
|
1500
1009
|
}
|
|
1501
|
-
|
|
1502
1010
|
//#endregion
|
|
1503
1011
|
//#region src/mock/mock.handler.ts
|
|
1504
1012
|
function mockHandler() {
|
|
1505
1013
|
return storeHandler(async () => await getMockStore());
|
|
1506
1014
|
}
|
|
1507
|
-
|
|
1508
1015
|
//#endregion
|
|
1509
1016
|
//#region src/preview/preview.handler.ts
|
|
1510
1017
|
function previewHandler() {
|
|
@@ -1522,142 +1029,6 @@ function previewHandler() {
|
|
|
1522
1029
|
}
|
|
1523
1030
|
});
|
|
1524
1031
|
}
|
|
1525
|
-
|
|
1526
|
-
//#endregion
|
|
1527
|
-
//#region ../models/src/app/app.service.ts
|
|
1528
|
-
async function getApp(params = {}) {
|
|
1529
|
-
const store = await getStore();
|
|
1530
|
-
const item = await store.app.findGlobal(params);
|
|
1531
|
-
return item;
|
|
1532
|
-
}
|
|
1533
|
-
|
|
1534
|
-
//#endregion
|
|
1535
|
-
//#region ../models/src/label/label.service.ts
|
|
1536
|
-
async function getLabels(params = {}) {
|
|
1537
|
-
const store = await getStore();
|
|
1538
|
-
const items = await store.label.findMany(params);
|
|
1539
|
-
return items;
|
|
1540
|
-
}
|
|
1541
|
-
|
|
1542
|
-
//#endregion
|
|
1543
|
-
//#region ../models/src/locale/locale.service.ts
|
|
1544
|
-
async function getLocales(params = {}) {
|
|
1545
|
-
const store = await getStore();
|
|
1546
|
-
const items = await store.locale.findMany(params);
|
|
1547
|
-
return items;
|
|
1548
|
-
}
|
|
1549
|
-
|
|
1550
|
-
//#endregion
|
|
1551
|
-
//#region ../models/src/market/market.service.ts
|
|
1552
|
-
async function getMarkets(params = {}) {
|
|
1553
|
-
const store = await getStore();
|
|
1554
|
-
const items = await store.market.findMany(params);
|
|
1555
|
-
return items;
|
|
1556
|
-
}
|
|
1557
|
-
|
|
1558
|
-
//#endregion
|
|
1559
|
-
//#region ../models/src/menu/menu.service.ts
|
|
1560
|
-
async function getMenus(params = {}) {
|
|
1561
|
-
const store = await getStore();
|
|
1562
|
-
const items = await store.menu.findMany(params);
|
|
1563
|
-
return items;
|
|
1564
|
-
}
|
|
1565
|
-
|
|
1566
|
-
//#endregion
|
|
1567
|
-
//#region ../models/src/route/route.ts
|
|
1568
|
-
function newRouteLink(category, route, locale) {
|
|
1569
|
-
const href = route && route.id ? route.id.toString() : "/";
|
|
1570
|
-
const id = route?.page || category.id;
|
|
1571
|
-
const media = category.media || route?.media;
|
|
1572
|
-
const schema = route?.template || route?.schema || category?.schema || "unknown";
|
|
1573
|
-
const title = localize(category.title || route?.title || "untitled", locale);
|
|
1574
|
-
const routeLink = {
|
|
1575
|
-
category: category.id,
|
|
1576
|
-
href,
|
|
1577
|
-
id,
|
|
1578
|
-
items: [],
|
|
1579
|
-
media,
|
|
1580
|
-
schema,
|
|
1581
|
-
title
|
|
1582
|
-
};
|
|
1583
|
-
return routeLink;
|
|
1584
|
-
}
|
|
1585
|
-
|
|
1586
|
-
//#endregion
|
|
1587
|
-
//#region ../models/src/route/route.service.ts
|
|
1588
|
-
async function getRouteLinkTree(market, locale) {
|
|
1589
|
-
const store = await getStore();
|
|
1590
|
-
const routes = await store.route.findMany({ where: {
|
|
1591
|
-
market: { equals: market },
|
|
1592
|
-
locale: { equals: locale }
|
|
1593
|
-
} });
|
|
1594
|
-
const categories = await store.category.findMany({
|
|
1595
|
-
market,
|
|
1596
|
-
locale
|
|
1597
|
-
});
|
|
1598
|
-
const rootCategory = getRootCategory(categories);
|
|
1599
|
-
if (rootCategory) {
|
|
1600
|
-
const root = getRouteLinkCategory(locale, routes, categories, rootCategory, rootCategory);
|
|
1601
|
-
return root;
|
|
1602
|
-
}
|
|
1603
|
-
return void 0;
|
|
1604
|
-
}
|
|
1605
|
-
function getRouteLinkCategory(locale, routes, categories, rootCategory, category) {
|
|
1606
|
-
const route = findRouteOfCategory(routes, category.id);
|
|
1607
|
-
const otherCategories = categories.filter((x) => x.id !== category.id);
|
|
1608
|
-
const childCategories = otherCategories.filter((x) => asCategoryId(x.category) === category.id);
|
|
1609
|
-
const routeLink = newRouteLink(category, route, locale);
|
|
1610
|
-
const items = [];
|
|
1611
|
-
for (const childCategory of childCategories) {
|
|
1612
|
-
const itemOrItems = getRouteLinkCategory(locale, routes, otherCategories, rootCategory, childCategory);
|
|
1613
|
-
if (Array.isArray(itemOrItems)) items.push(...itemOrItems);
|
|
1614
|
-
else if (itemOrItems) items.push(itemOrItems);
|
|
1615
|
-
}
|
|
1616
|
-
if (!route || category.isHidden && category.id !== rootCategory.id) return items;
|
|
1617
|
-
routeLink.items = items;
|
|
1618
|
-
return routeLink;
|
|
1619
|
-
}
|
|
1620
|
-
|
|
1621
|
-
//#endregion
|
|
1622
|
-
//#region ../models/src/layout/layout.service.ts
|
|
1623
|
-
async function getLayout(market, locale) {
|
|
1624
|
-
const markets = await getMarkets({ locale });
|
|
1625
|
-
const locales = await getLocales({ locale });
|
|
1626
|
-
const labels = await getLabels({ locale });
|
|
1627
|
-
const app = await getApp({ locale }) || {};
|
|
1628
|
-
const tree = await getRouteLinkTree(market, locale);
|
|
1629
|
-
const firstLevelRoutes = tree?.items || [];
|
|
1630
|
-
const flatTopLevelRoutes = tree ? [tree, ...firstLevelRoutes] : [];
|
|
1631
|
-
const topLevelRoutes = flatTopLevelRoutes.reduce((object, routeLink) => {
|
|
1632
|
-
if (!object[routeLink.schema] || routeLink.schema === routeLink.category) object[routeLink.schema] = routeLink;
|
|
1633
|
-
return object;
|
|
1634
|
-
}, {});
|
|
1635
|
-
const topLevelHrefs = flatTopLevelRoutes.reduce((object, routeLink) => {
|
|
1636
|
-
if (routeLink.href && (!object[routeLink.schema] || routeLink.schema === routeLink.category)) object[routeLink.schema] = routeLink.href;
|
|
1637
|
-
return object;
|
|
1638
|
-
}, {});
|
|
1639
|
-
const menu = {};
|
|
1640
|
-
const menus = await getMenus({
|
|
1641
|
-
market,
|
|
1642
|
-
locale
|
|
1643
|
-
});
|
|
1644
|
-
menus.forEach((x) => {
|
|
1645
|
-
menu[x.id] = x;
|
|
1646
|
-
});
|
|
1647
|
-
return {
|
|
1648
|
-
labels,
|
|
1649
|
-
locale,
|
|
1650
|
-
locales,
|
|
1651
|
-
market,
|
|
1652
|
-
markets,
|
|
1653
|
-
app,
|
|
1654
|
-
menu,
|
|
1655
|
-
topLevelHrefs,
|
|
1656
|
-
topLevelRoutes,
|
|
1657
|
-
tree
|
|
1658
|
-
};
|
|
1659
|
-
}
|
|
1660
|
-
|
|
1661
1032
|
//#endregion
|
|
1662
1033
|
//#region src/vars/vars.handler.ts
|
|
1663
1034
|
const DISALLOWED_KEYS = ["__NEXT_PRIVATE_STANDALONE_CONFIG"];
|
|
@@ -1678,9 +1049,9 @@ function varsHandler() {
|
|
|
1678
1049
|
},
|
|
1679
1050
|
get: async (request, response) => {
|
|
1680
1051
|
try {
|
|
1681
|
-
const defaultLocale
|
|
1052
|
+
const defaultLocale = process.env.DEFAULT_LOCALE || "it";
|
|
1682
1053
|
const defaultMaket = process.env.DEFAULT_MARKET || "ww";
|
|
1683
|
-
const { locale = defaultLocale
|
|
1054
|
+
const { locale = defaultLocale, market = defaultMaket } = request.query || {};
|
|
1684
1055
|
const layout = typeof locale === "string" && typeof market === "string" ? await getLayout(market, locale) : void 0;
|
|
1685
1056
|
const info = {
|
|
1686
1057
|
production: isProduction,
|
|
@@ -1796,7 +1167,7 @@ function varsHandler() {
|
|
|
1796
1167
|
}
|
|
1797
1168
|
});
|
|
1798
1169
|
}
|
|
1799
|
-
|
|
1800
1170
|
//#endregion
|
|
1801
|
-
export {
|
|
1171
|
+
export { MockMenuService, MockPageService, MockService, RemoteMenuService, RemotePageService, RemoteService, StaticService, apiHandler, collectionDelete, collectionGet, collectionPatch, collectionPost, decorateStaticRelation_, decorateStaticRelations_, errorHandler, findRoute, getMockStore, getMockStoreFromData_, getRemoteStore, getStore, mockHandler, previewHandler, routePost, storeHandler, storeIndexHandler, varsHandler };
|
|
1172
|
+
|
|
1802
1173
|
//# sourceMappingURL=server.js.map
|