@datawheel/bespoke 0.3.13 → 0.3.15-noauth.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/dist/index.js +132 -1130
- package/dist/server.js +95 -668
- package/package.json +1 -3
package/dist/server.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { initAuth0 } from '@auth0/nextjs-auth0';
|
|
2
|
-
import auth0 from 'auth0';
|
|
3
1
|
import * as pg from 'pg';
|
|
4
2
|
import { Sequelize, Error as Error$1, fn, col, Op, DataTypes, QueryTypes, Model } from 'sequelize';
|
|
5
3
|
import yn2 from 'yn';
|
|
@@ -43,316 +41,6 @@ var __export = (target, all) => {
|
|
|
43
41
|
for (var name in all)
|
|
44
42
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
45
43
|
};
|
|
46
|
-
var getAuth_default = initAuth0({
|
|
47
|
-
secret: process.env.AUTH0_SECRET,
|
|
48
|
-
issuerBaseURL: process.env.AUTH0_ISSUER_BASE_URL,
|
|
49
|
-
baseURL: process.env.REPORTS_BASE_URL || process.env.AUTH0_BASE_URL,
|
|
50
|
-
clientID: process.env.AUTH0_CLIENT_ID,
|
|
51
|
-
clientSecret: process.env.AUTH0_CLIENT_SECRET
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
// api/auth/getSession.ts
|
|
55
|
-
var getSession_default = getAuth_default.getSession;
|
|
56
|
-
|
|
57
|
-
// api/auth/handleAuth.ts
|
|
58
|
-
var afterRefetch = async (req, res, session) => {
|
|
59
|
-
return session;
|
|
60
|
-
};
|
|
61
|
-
var fetchMe = async (req, res, refetch) => {
|
|
62
|
-
return await getAuth_default.handleProfile(req, res, { afterRefetch, refetch });
|
|
63
|
-
};
|
|
64
|
-
var handleAuth_default = getAuth_default.handleAuth({
|
|
65
|
-
// Override "/me" url which is grabbed by useUser
|
|
66
|
-
profile: async (req, res) => {
|
|
67
|
-
try {
|
|
68
|
-
await fetchMe(req, res, false);
|
|
69
|
-
} catch (error) {
|
|
70
|
-
console.error(error);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
// api/lib.ts
|
|
76
|
-
var BackendError = class extends Error {
|
|
77
|
-
constructor(code, message) {
|
|
78
|
-
super(message);
|
|
79
|
-
this.code = code;
|
|
80
|
-
}
|
|
81
|
-
toJSON() {
|
|
82
|
-
return failureResult(this);
|
|
83
|
-
}
|
|
84
|
-
static is(obj) {
|
|
85
|
-
return Object.prototype.hasOwnProperty.call(obj, "code") && typeof obj.code === "number";
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
function successResult(result) {
|
|
89
|
-
return { ok: true, status: 200, data: result };
|
|
90
|
-
}
|
|
91
|
-
function failureResult(err) {
|
|
92
|
-
return { ok: false, status: BackendError.is(err) ? err.code : 500, error: err.message };
|
|
93
|
-
}
|
|
94
|
-
function resultWrapper(method) {
|
|
95
|
-
return (param) => method(param).then(successResult, failureResult);
|
|
96
|
-
}
|
|
97
|
-
function pickMethod(api, operation, entity) {
|
|
98
|
-
const name = `${operation}${capitalize(entity)}`;
|
|
99
|
-
return api[name];
|
|
100
|
-
}
|
|
101
|
-
function capitalize(str) {
|
|
102
|
-
return str[0].toUpperCase() + str.slice(1);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// types/auth.ts
|
|
106
|
-
var CMS_ROLES = {
|
|
107
|
-
ADMIN: "Admin",
|
|
108
|
-
EDITOR: "Editor",
|
|
109
|
-
WRITER: "Writer"
|
|
110
|
-
};
|
|
111
|
-
var CMS_ROLES_TYPES = {
|
|
112
|
-
APP: "App",
|
|
113
|
-
USER: "User"
|
|
114
|
-
};
|
|
115
|
-
var addRoleTypes = (roles) => {
|
|
116
|
-
const systemRoles = Object.values(CMS_ROLES);
|
|
117
|
-
return roles ? roles.map((r) => {
|
|
118
|
-
return {
|
|
119
|
-
...r,
|
|
120
|
-
type: systemRoles.includes(r.name) ? CMS_ROLES_TYPES.APP : CMS_ROLES_TYPES.USER
|
|
121
|
-
};
|
|
122
|
-
}) : [];
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
// api/db/users/auth0.ts
|
|
126
|
-
var auth0ConfigObject = {
|
|
127
|
-
domain: new URL(process.env.AUTH0_ISSUER_BASE_URL || "").host,
|
|
128
|
-
clientId: process.env.AUTH0_CLIENT_ID,
|
|
129
|
-
clientSecret: process.env.AUTH0_CLIENT_SECRET
|
|
130
|
-
};
|
|
131
|
-
var managementClient = new auth0.ManagementClient(auth0ConfigObject);
|
|
132
|
-
function dbSearchRole() {
|
|
133
|
-
return async () => {
|
|
134
|
-
try {
|
|
135
|
-
const roles = await managementClient.roles.getAll({
|
|
136
|
-
include_totals: true,
|
|
137
|
-
per_page: 100
|
|
138
|
-
});
|
|
139
|
-
return {
|
|
140
|
-
roles: addRoleTypes(roles.roles)
|
|
141
|
-
};
|
|
142
|
-
} catch (err) {
|
|
143
|
-
console.error("AuthZeroError", err);
|
|
144
|
-
throw new BackendError(err.response?.status || 500, err.message);
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
function dbSearchUser() {
|
|
149
|
-
return async (filters) => {
|
|
150
|
-
try {
|
|
151
|
-
let users;
|
|
152
|
-
if (filters) {
|
|
153
|
-
const pagination = {
|
|
154
|
-
include_totals: true,
|
|
155
|
-
per_page: 10,
|
|
156
|
-
page: filters.page || 0
|
|
157
|
-
};
|
|
158
|
-
if (filters.role_id && filters.role_id !== "") {
|
|
159
|
-
const paramsByRole = {
|
|
160
|
-
...pagination,
|
|
161
|
-
id: filters.role_id
|
|
162
|
-
};
|
|
163
|
-
users = await managementClient.roles.getUsers(paramsByRole);
|
|
164
|
-
} else {
|
|
165
|
-
const paramsSearch = {
|
|
166
|
-
...pagination,
|
|
167
|
-
q: filters.query
|
|
168
|
-
};
|
|
169
|
-
users = await managementClient.users.getAll(paramsSearch);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return users;
|
|
173
|
-
} catch (err) {
|
|
174
|
-
console.error("AuthZeroError", err);
|
|
175
|
-
throw new BackendError(err.response?.status || 500, err.message);
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
function dbReadUser() {
|
|
180
|
-
return async (userId) => {
|
|
181
|
-
try {
|
|
182
|
-
if (userId) {
|
|
183
|
-
const userData = await Promise.all([
|
|
184
|
-
managementClient.users.get({ id: userId }),
|
|
185
|
-
managementClient.users.getRoles({ id: userId })
|
|
186
|
-
]);
|
|
187
|
-
return {
|
|
188
|
-
...userData[0],
|
|
189
|
-
roles: userData[1]
|
|
190
|
-
};
|
|
191
|
-
} else {
|
|
192
|
-
throw new BackendError(404, "User ID required");
|
|
193
|
-
}
|
|
194
|
-
} catch (err) {
|
|
195
|
-
console.error("AuthZeroError", err);
|
|
196
|
-
throw new BackendError(err.response?.status || 500, err.message);
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
function dbUpdateUser() {
|
|
201
|
-
return async (user) => {
|
|
202
|
-
try {
|
|
203
|
-
if (user.user_id) {
|
|
204
|
-
if (user.app_metadata) {
|
|
205
|
-
await updateUserMetadata(user.user_id, user.app_metadata);
|
|
206
|
-
}
|
|
207
|
-
if (user.roles) {
|
|
208
|
-
const currentRoles = await managementClient.users.getRoles({ id: user.user_id });
|
|
209
|
-
const oldRoles = currentRoles.map((r) => r.id);
|
|
210
|
-
const newRoles = user.roles.map((r) => r.id);
|
|
211
|
-
const rolesToAssign = newRoles.filter((role) => !oldRoles.includes(role));
|
|
212
|
-
const rolesToDelete = oldRoles.filter((role) => !newRoles.includes(role));
|
|
213
|
-
if (rolesToAssign.length > 0) {
|
|
214
|
-
await managementClient.users.assignRoles({ id: user.user_id }, { roles: rolesToAssign });
|
|
215
|
-
}
|
|
216
|
-
if (rolesToDelete.length > 0) {
|
|
217
|
-
await managementClient.users.removeRoles({ id: user.user_id }, { roles: rolesToDelete });
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
return "User updated!";
|
|
221
|
-
} else {
|
|
222
|
-
throw new BackendError(404, "user_id is required");
|
|
223
|
-
}
|
|
224
|
-
} catch (err) {
|
|
225
|
-
console.error("AuthZeroError", err);
|
|
226
|
-
throw new BackendError(err.response?.status || 500, err.message);
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
function dbAddNewReportToCurrentUser() {
|
|
231
|
-
return async (params) => {
|
|
232
|
-
try {
|
|
233
|
-
return "NOT USED SERVICE";
|
|
234
|
-
} catch (err) {
|
|
235
|
-
console.error("AuthZeroError", err);
|
|
236
|
-
throw new BackendError(err.response?.status || 500, err.message);
|
|
237
|
-
}
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
async function updateUserMetadata(userId, newMetadata) {
|
|
241
|
-
return await managementClient.users.updateAppMetadata({ id: userId }, newMetadata);
|
|
242
|
-
}
|
|
243
|
-
async function searchUsersByMetadata(key, value) {
|
|
244
|
-
try {
|
|
245
|
-
const users = await managementClient.getUsers({
|
|
246
|
-
search_engine: "v3",
|
|
247
|
-
q: `app_metadata.${key}:"${value}"`
|
|
248
|
-
});
|
|
249
|
-
for (let index = 0; index < users.length; index++) {
|
|
250
|
-
const u = users[index];
|
|
251
|
-
u.bespoke_app_metadata = u.app_metadata || {};
|
|
252
|
-
delete u.app_metadata;
|
|
253
|
-
u.bespoke_roles = (await managementClient.users.getRoles({ id: u.user_id })).map((r) => r.name);
|
|
254
|
-
}
|
|
255
|
-
return users;
|
|
256
|
-
} catch (error) {
|
|
257
|
-
console.error(error);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
// api/auth/updateCurrentUserMetadata.tsx
|
|
262
|
-
var updateCurrentUserMetadata = (req, res, newMetadata) => {
|
|
263
|
-
return new Promise((resolve, reject) => {
|
|
264
|
-
const updateMetadata = async () => {
|
|
265
|
-
try {
|
|
266
|
-
const session = await getAuth_default.getSession(req, res);
|
|
267
|
-
if (!session || !session.user) {
|
|
268
|
-
throw new Error("not_authenticated");
|
|
269
|
-
} else {
|
|
270
|
-
const { user } = session;
|
|
271
|
-
const oldMetadata = session.user.bespoke_app_metadata || {};
|
|
272
|
-
const latestMetadata = {
|
|
273
|
-
...oldMetadata,
|
|
274
|
-
...newMetadata
|
|
275
|
-
};
|
|
276
|
-
await updateUserMetadata(session.user.sub, latestMetadata);
|
|
277
|
-
await getAuth_default.updateSession(req, res, {
|
|
278
|
-
...session,
|
|
279
|
-
user: {
|
|
280
|
-
...user,
|
|
281
|
-
bespoke_app_metadata: latestMetadata
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
resolve({
|
|
285
|
-
error: "",
|
|
286
|
-
description: `Settings updated for user ${session.user.email}`
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
} catch (error) {
|
|
290
|
-
reject({
|
|
291
|
-
error: error.message,
|
|
292
|
-
description: "The user does not have an active session or is not authenticated"
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
};
|
|
296
|
-
updateMetadata();
|
|
297
|
-
});
|
|
298
|
-
};
|
|
299
|
-
var updateCurrentUserMetadata_default = updateCurrentUserMetadata;
|
|
300
|
-
|
|
301
|
-
// libs/js/arrayUtils.ts
|
|
302
|
-
var keyDiver = (obj, str) => !str ? obj : typeof str === "string" ? str.split(".").reduce((o, i) => o[i], obj) : obj;
|
|
303
|
-
function arrContainsAnyItem(arr1, arr2) {
|
|
304
|
-
return arr1.some((item) => arr2.includes(item));
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
// api/auth/withApiRoleAuthRequired.tsx
|
|
308
|
-
var withApiRoleAuthRequired = (apiRoute, allowedRoles) => {
|
|
309
|
-
return async function(req, res) {
|
|
310
|
-
const session = await getAuth_default.getSession(req, res);
|
|
311
|
-
if (!session || !session.user) {
|
|
312
|
-
res.status(401).json({
|
|
313
|
-
error: "not_authenticated",
|
|
314
|
-
description: "The user does not have an active session or is not authenticated"
|
|
315
|
-
});
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
const usersRoles = session.user.bespoke_roles;
|
|
319
|
-
if (allowedRoles.length > 0 && !arrContainsAnyItem(usersRoles, allowedRoles)) {
|
|
320
|
-
res.status(402).json({
|
|
321
|
-
error: "unauthorize",
|
|
322
|
-
description: "The user requires some specific roles"
|
|
323
|
-
});
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
await apiRoute(req, res);
|
|
327
|
-
};
|
|
328
|
-
};
|
|
329
|
-
var withApiRoleAuthRequired_default = withApiRoleAuthRequired;
|
|
330
|
-
|
|
331
|
-
// api/auth/searchUsersByMetadata.tsx
|
|
332
|
-
var searchUsersByMetadata2 = (key, value) => {
|
|
333
|
-
return new Promise((resolve, reject) => {
|
|
334
|
-
const searchUsers = async () => {
|
|
335
|
-
try {
|
|
336
|
-
if (key && value && key !== "" && value !== "") {
|
|
337
|
-
const users = await searchUsersByMetadata(key, value);
|
|
338
|
-
resolve(users);
|
|
339
|
-
} else {
|
|
340
|
-
reject({
|
|
341
|
-
error: "empty_params",
|
|
342
|
-
description: "key or value params are empty"
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
} catch (error) {
|
|
346
|
-
reject({
|
|
347
|
-
error: error.message,
|
|
348
|
-
description: "Error "
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
};
|
|
352
|
-
searchUsers();
|
|
353
|
-
});
|
|
354
|
-
};
|
|
355
|
-
var searchUsersByMetadata_default = searchUsersByMetadata2;
|
|
356
44
|
var getLogging_default = (env = process.env) => yn2(env.REPORTS_LOGGING);
|
|
357
45
|
var BlockModel = class extends Model {
|
|
358
46
|
getContent(locale) {
|
|
@@ -1334,15 +1022,48 @@ var getDB = () => {
|
|
|
1334
1022
|
return global.sequelize;
|
|
1335
1023
|
};
|
|
1336
1024
|
|
|
1025
|
+
// api/lib.ts
|
|
1026
|
+
var BackendError = class extends Error {
|
|
1027
|
+
constructor(code, message) {
|
|
1028
|
+
super(message);
|
|
1029
|
+
this.code = code;
|
|
1030
|
+
}
|
|
1031
|
+
toJSON() {
|
|
1032
|
+
return failureResult(this);
|
|
1033
|
+
}
|
|
1034
|
+
static is(obj) {
|
|
1035
|
+
return Object.prototype.hasOwnProperty.call(obj, "code") && typeof obj.code === "number";
|
|
1036
|
+
}
|
|
1037
|
+
};
|
|
1038
|
+
function successResult(result) {
|
|
1039
|
+
return { ok: true, status: 200, data: result };
|
|
1040
|
+
}
|
|
1041
|
+
function failureResult(err) {
|
|
1042
|
+
return { ok: false, status: BackendError.is(err) ? err.code : 500, error: err.message };
|
|
1043
|
+
}
|
|
1044
|
+
function resultWrapper(method) {
|
|
1045
|
+
return (param) => method(param).then(successResult, failureResult);
|
|
1046
|
+
}
|
|
1047
|
+
function pickMethod(api, operation, entity) {
|
|
1048
|
+
const name = `${operation}${capitalize(entity)}`;
|
|
1049
|
+
return api[name];
|
|
1050
|
+
}
|
|
1051
|
+
function capitalize(str) {
|
|
1052
|
+
return str[0].toUpperCase() + str.slice(1);
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1337
1055
|
// libs/configs/getLocales.ts
|
|
1338
1056
|
var getLocales_default = () => {
|
|
1339
|
-
const
|
|
1340
|
-
const locales9 = process.env.NEXT_PUBLIC_REPORTS_LOCALES?.split(",") || [
|
|
1341
|
-
if (!locales9.includes(
|
|
1342
|
-
locales9.push(
|
|
1343
|
-
return { localeDefault:
|
|
1057
|
+
const localeDefault10 = process.env.NEXT_PUBLIC_REPORTS_LOCALE_DEFAULT || "en";
|
|
1058
|
+
const locales9 = process.env.NEXT_PUBLIC_REPORTS_LOCALES?.split(",") || [localeDefault10];
|
|
1059
|
+
if (!locales9.includes(localeDefault10))
|
|
1060
|
+
locales9.push(localeDefault10);
|
|
1061
|
+
return { localeDefault: localeDefault10, locales: locales9 };
|
|
1344
1062
|
};
|
|
1345
1063
|
|
|
1064
|
+
// libs/js/arrayUtils.ts
|
|
1065
|
+
var keyDiver = (obj, str) => !str ? obj : typeof str === "string" ? str.split(".").reduce((o, i) => o[i], obj) : obj;
|
|
1066
|
+
|
|
1346
1067
|
// libs/js/stripHTML.ts
|
|
1347
1068
|
function stripHTML(n) {
|
|
1348
1069
|
const entities = {
|
|
@@ -2727,7 +2448,7 @@ function endpointMemberFactory(operations) {
|
|
|
2727
2448
|
endpoint("POST", "update/member", (req) => {
|
|
2728
2449
|
const { body } = req;
|
|
2729
2450
|
return updateMember(body);
|
|
2730
|
-
}, [
|
|
2451
|
+
}, []),
|
|
2731
2452
|
/*
|
|
2732
2453
|
* Get image file itself
|
|
2733
2454
|
* Example queries:
|
|
@@ -3250,96 +2971,6 @@ function dbRevalidateUrlFactory() {
|
|
|
3250
2971
|
}
|
|
3251
2972
|
};
|
|
3252
2973
|
}
|
|
3253
|
-
|
|
3254
|
-
// libs/blocks/crawlDown.ts
|
|
3255
|
-
function crawlDown(rootBlockIds, blockList) {
|
|
3256
|
-
let consumersBlocksIds = [];
|
|
3257
|
-
const crawlDownIndividual = (privateBlockId) => {
|
|
3258
|
-
const downIds = Object.values(blockList).reduce((acc, block) => {
|
|
3259
|
-
if ("inputs" in block && block.inputs.includes(privateBlockId)) {
|
|
3260
|
-
acc.push(block.id);
|
|
3261
|
-
acc = acc.concat(crawlDownIndividual(block.id));
|
|
3262
|
-
}
|
|
3263
|
-
return acc;
|
|
3264
|
-
}, []);
|
|
3265
|
-
return downIds;
|
|
3266
|
-
};
|
|
3267
|
-
rootBlockIds.forEach((rootBlockId) => {
|
|
3268
|
-
consumersBlocksIds = consumersBlocksIds.concat(crawlDownIndividual(rootBlockId));
|
|
3269
|
-
});
|
|
3270
|
-
const uniqueConsumerBlocksIds = [];
|
|
3271
|
-
consumersBlocksIds.forEach((id) => {
|
|
3272
|
-
if (!uniqueConsumerBlocksIds.includes(id)) {
|
|
3273
|
-
uniqueConsumerBlocksIds.push(id);
|
|
3274
|
-
}
|
|
3275
|
-
});
|
|
3276
|
-
return uniqueConsumerBlocksIds;
|
|
3277
|
-
}
|
|
3278
|
-
|
|
3279
|
-
// api/db/readPrivateBlocks.ts
|
|
3280
|
-
function accessContainsRole(arr1, arr2) {
|
|
3281
|
-
return arr1.some((item) => arr2.includes(`role.${item}`));
|
|
3282
|
-
}
|
|
3283
|
-
function dbReadPrivateBlocksFactory(db) {
|
|
3284
|
-
const { report: Report } = db;
|
|
3285
|
-
return dbReadPrivateBlocks;
|
|
3286
|
-
async function dbReadPrivateBlocks(params) {
|
|
3287
|
-
const allBlocks = await Report.findByPk(
|
|
3288
|
-
params.report_id,
|
|
3289
|
-
{
|
|
3290
|
-
include: {
|
|
3291
|
-
association: "sections",
|
|
3292
|
-
separate: true,
|
|
3293
|
-
include: [
|
|
3294
|
-
{
|
|
3295
|
-
association: "blocks",
|
|
3296
|
-
separate: true,
|
|
3297
|
-
include: [
|
|
3298
|
-
{
|
|
3299
|
-
association: "contentByLocale",
|
|
3300
|
-
separate: true,
|
|
3301
|
-
where: {
|
|
3302
|
-
locale: params.locale
|
|
3303
|
-
}
|
|
3304
|
-
},
|
|
3305
|
-
{
|
|
3306
|
-
association: "inputs"
|
|
3307
|
-
},
|
|
3308
|
-
{
|
|
3309
|
-
association: "consumers"
|
|
3310
|
-
}
|
|
3311
|
-
]
|
|
3312
|
-
}
|
|
3313
|
-
]
|
|
3314
|
-
}
|
|
3315
|
-
}
|
|
3316
|
-
).then((report) => {
|
|
3317
|
-
if (report && report.sections && Array.isArray(report.sections)) {
|
|
3318
|
-
return report.sections.reduce((acc, section) => {
|
|
3319
|
-
const nestedBlocks = section.blocks.map((entity) => {
|
|
3320
|
-
const normalized = entity.toJSON();
|
|
3321
|
-
normalized.inputs = normalized.inputs.map((b) => b.id);
|
|
3322
|
-
normalized.consumers = normalized.consumers.map((b) => b.id);
|
|
3323
|
-
return normalized;
|
|
3324
|
-
});
|
|
3325
|
-
return acc.concat(nestedBlocks);
|
|
3326
|
-
}, []);
|
|
3327
|
-
} else {
|
|
3328
|
-
return [];
|
|
3329
|
-
}
|
|
3330
|
-
});
|
|
3331
|
-
let privateBlockIds = allBlocks.filter((block) => {
|
|
3332
|
-
return block.settings && block.settings.access && Array.isArray(block.settings.access) && Array.isArray(params.roles) && (block.settings.access.includes("private") || accessContainsRole(params.roles, block.settings.access));
|
|
3333
|
-
}).map((block) => block.id);
|
|
3334
|
-
privateBlockIds = privateBlockIds.concat(crawlDown(privateBlockIds, allBlocks));
|
|
3335
|
-
return {
|
|
3336
|
-
params: {
|
|
3337
|
-
...params
|
|
3338
|
-
},
|
|
3339
|
-
data: allBlocks.filter((block) => privateBlockIds.includes(block.id))
|
|
3340
|
-
};
|
|
3341
|
-
}
|
|
3342
|
-
}
|
|
3343
2974
|
var iconsList = Object.keys(allIcons).filter((iconName) => iconName.indexOf("Icon") === 0);
|
|
3344
2975
|
async function listTablerProvider() {
|
|
3345
2976
|
return {
|
|
@@ -3400,14 +3031,8 @@ function apiFactory(dbModels) {
|
|
|
3400
3031
|
imageUnsplashSave: dbImageSaveFactory(dbModels, "unsplash"),
|
|
3401
3032
|
imageUploadSave: dbImageSaveFactory(dbModels, "upload"),
|
|
3402
3033
|
urlProxy: dbUrlProxyFactory(),
|
|
3403
|
-
searchRole: resultWrapper(dbSearchRole()),
|
|
3404
|
-
searchUser: resultWrapper(dbSearchUser()),
|
|
3405
|
-
readUser: resultWrapper(dbReadUser()),
|
|
3406
|
-
updateUser: resultWrapper(dbUpdateUser()),
|
|
3407
|
-
addNewReportToCurrentUser: resultWrapper(dbAddNewReportToCurrentUser()),
|
|
3408
3034
|
revalidateReport: resultWrapper(dbRevalidateReportFactory(dbModels)),
|
|
3409
3035
|
revalidateUrl: resultWrapper(dbRevalidateUrlFactory()),
|
|
3410
|
-
readPrivateBlocks: resultWrapper(dbReadPrivateBlocksFactory(dbModels)),
|
|
3411
3036
|
listTablerIcons: dbListIconsFactory("tabler"),
|
|
3412
3037
|
readTablerIcon: dbReadIconFactory("tabler")
|
|
3413
3038
|
};
|
|
@@ -3444,7 +3069,7 @@ function endpointCRUDFactory(api, entity) {
|
|
|
3444
3069
|
endpoint("POST", `create/${entity}`, (req) => {
|
|
3445
3070
|
const { body } = req;
|
|
3446
3071
|
return crudCreate(body);
|
|
3447
|
-
}, [
|
|
3072
|
+
}, []),
|
|
3448
3073
|
endpoint("GET", `read/${entity}`, (req) => {
|
|
3449
3074
|
const params = req.query;
|
|
3450
3075
|
const id = normalizeList(params.id).map(parseFiniteNumber);
|
|
@@ -3453,11 +3078,11 @@ function endpointCRUDFactory(api, entity) {
|
|
|
3453
3078
|
endpoint("POST", `update/${entity}`, (req) => {
|
|
3454
3079
|
const { body } = req;
|
|
3455
3080
|
return crudUpdate(body);
|
|
3456
|
-
}, [
|
|
3081
|
+
}, []),
|
|
3457
3082
|
endpoint("DELETE", `delete/${entity}`, (req) => {
|
|
3458
3083
|
const id = parseFiniteNumber(req.query.id);
|
|
3459
3084
|
return crudDelete(id);
|
|
3460
|
-
}, [
|
|
3085
|
+
}, [])
|
|
3461
3086
|
];
|
|
3462
3087
|
}
|
|
3463
3088
|
function endpointVariantCRUDFactory(api) {
|
|
@@ -3468,7 +3093,7 @@ function endpointVariantCRUDFactory(api) {
|
|
|
3468
3093
|
const params = req.query;
|
|
3469
3094
|
const dimension = parseFiniteNumber(params.dimension);
|
|
3470
3095
|
return validateVariantSlug({ dimension, slug: slugify_default(params.slug) });
|
|
3471
|
-
}, [
|
|
3096
|
+
}, [])
|
|
3472
3097
|
];
|
|
3473
3098
|
}
|
|
3474
3099
|
|
|
@@ -3485,7 +3110,7 @@ function endpointImageSaveFactory(operations, provider) {
|
|
|
3485
3110
|
throw new BackendError(400, "Missing 'image_id' parameter.");
|
|
3486
3111
|
}
|
|
3487
3112
|
return saveMethod(params);
|
|
3488
|
-
}, [
|
|
3113
|
+
}, []);
|
|
3489
3114
|
}
|
|
3490
3115
|
|
|
3491
3116
|
// api/endpoints/image/imageSearch.ts
|
|
@@ -3498,7 +3123,7 @@ function endpointImageSearchFactory(operations, provider) {
|
|
|
3498
3123
|
throw new BackendError(400, "Empty 'prompt' param.");
|
|
3499
3124
|
}
|
|
3500
3125
|
return searchMethod({ prompt });
|
|
3501
|
-
}, [
|
|
3126
|
+
}, []);
|
|
3502
3127
|
}
|
|
3503
3128
|
|
|
3504
3129
|
// api/endpoints/readMetadata.ts
|
|
@@ -3510,7 +3135,7 @@ function endpointReadMetadataFactory(operations) {
|
|
|
3510
3135
|
// api/endpoints/regenerateSearch.ts
|
|
3511
3136
|
function endpointRegenerateSearchFactory(operations) {
|
|
3512
3137
|
const { regenerateSearch } = operations;
|
|
3513
|
-
return endpoint("POST", "search/regenerate", () => regenerateSearch(void 0), [
|
|
3138
|
+
return endpoint("POST", "search/regenerate", () => regenerateSearch(void 0), []);
|
|
3514
3139
|
}
|
|
3515
3140
|
|
|
3516
3141
|
// api/endpoints/searchReport.ts
|
|
@@ -3603,7 +3228,7 @@ function endpointRevalidateReportFactory(operations) {
|
|
|
3603
3228
|
console.log(err);
|
|
3604
3229
|
throw new BackendError(500, "Error revalidating");
|
|
3605
3230
|
}
|
|
3606
|
-
}, [
|
|
3231
|
+
}, []);
|
|
3607
3232
|
}
|
|
3608
3233
|
|
|
3609
3234
|
// api/endpoints/revalidateUrl.ts
|
|
@@ -3627,122 +3252,16 @@ function endpointRevalidateUrlFactory() {
|
|
|
3627
3252
|
throw new BackendError(500, "Error revalidating");
|
|
3628
3253
|
}
|
|
3629
3254
|
}
|
|
3630
|
-
}, [CMS_ROLES.ADMIN, CMS_ROLES.EDITOR, CMS_ROLES.WRITER]);
|
|
3631
|
-
}
|
|
3632
|
-
|
|
3633
|
-
// api/endpoints/readPrivateBlocks.ts
|
|
3634
|
-
var { localeDefault: localeDefault5 } = getLocales_default();
|
|
3635
|
-
function endpointReadPrivateBlocksFactory(operations) {
|
|
3636
|
-
const { readPrivateBlocks: readPrivateBlocks2 } = operations;
|
|
3637
|
-
return endpoint("POST", "read/blocks/private", (req, res, session) => {
|
|
3638
|
-
const params = {
|
|
3639
|
-
report_id: parseInt(req.body.report_id, 10),
|
|
3640
|
-
locale: req.body.locale || localeDefault5,
|
|
3641
|
-
roles: session && session.user ? session.user.bespoke_roles : []
|
|
3642
|
-
};
|
|
3643
|
-
return readPrivateBlocks2(params);
|
|
3644
3255
|
}, []);
|
|
3645
3256
|
}
|
|
3646
3257
|
|
|
3647
|
-
// api/endpoints/users/auth0.ts
|
|
3648
|
-
function endpointGetRolesFactory(operations) {
|
|
3649
|
-
const { searchRole: searchRole2 } = operations;
|
|
3650
|
-
return endpoint("GET", "auth/search/roles", () => {
|
|
3651
|
-
return searchRole2("");
|
|
3652
|
-
}, [CMS_ROLES.EDITOR]);
|
|
3653
|
-
}
|
|
3654
|
-
function endpointGetUsersFactory(operations) {
|
|
3655
|
-
const { searchUser: searchUser2 } = operations;
|
|
3656
|
-
return endpoint("GET", "auth/search/users", (req) => {
|
|
3657
|
-
return searchUser2({
|
|
3658
|
-
query: req.query.query,
|
|
3659
|
-
role_id: req.query.role_id,
|
|
3660
|
-
page: req.query.page || 0
|
|
3661
|
-
});
|
|
3662
|
-
}, [CMS_ROLES.ADMIN]);
|
|
3663
|
-
}
|
|
3664
|
-
function endpointGetUserDataFactory(operations) {
|
|
3665
|
-
const { readUser: readUser2 } = operations;
|
|
3666
|
-
return endpoint("GET", "auth/read/user", (req) => {
|
|
3667
|
-
return readUser2(req.query.user_id);
|
|
3668
|
-
}, [CMS_ROLES.ADMIN]);
|
|
3669
|
-
}
|
|
3670
|
-
function endpointUpdateUserDataFactory(operations) {
|
|
3671
|
-
const { updateUser: updateUser2, readUser: readUser2 } = operations;
|
|
3672
|
-
return endpoint("POST", "auth/update/user", async (req, res, session) => {
|
|
3673
|
-
const userData = req.body;
|
|
3674
|
-
const response = await updateUser2(userData);
|
|
3675
|
-
if (session && session.user && userData.user_id === session.user.sub) {
|
|
3676
|
-
const latestUserData = await readUser2(session.user.sub);
|
|
3677
|
-
if (latestUserData.ok) {
|
|
3678
|
-
await getAuth_default.updateSession(req, res, {
|
|
3679
|
-
...session,
|
|
3680
|
-
user: {
|
|
3681
|
-
...session.user,
|
|
3682
|
-
bespoke_app_metadata: latestUserData.data.app_metadata,
|
|
3683
|
-
bespoke_roles: latestUserData.data.roles.map((r) => r.name)
|
|
3684
|
-
}
|
|
3685
|
-
});
|
|
3686
|
-
}
|
|
3687
|
-
}
|
|
3688
|
-
return response;
|
|
3689
|
-
}, [CMS_ROLES.ADMIN]);
|
|
3690
|
-
}
|
|
3691
|
-
function endpointAddNewReportToCurrentUserFactory(operations) {
|
|
3692
|
-
const { updateUser: updateUser2, readUser: readUser2 } = operations;
|
|
3693
|
-
return endpoint("POST", "auth/update/me", async (req, res, session) => {
|
|
3694
|
-
const reportId = req.body.report_id;
|
|
3695
|
-
try {
|
|
3696
|
-
if (session && session.user && reportId) {
|
|
3697
|
-
const updateObject = {
|
|
3698
|
-
user_id: session.user.sub,
|
|
3699
|
-
app_metadata: {}
|
|
3700
|
-
};
|
|
3701
|
-
const { user } = session;
|
|
3702
|
-
if (user.bespoke_app_metadata && user.bespoke_app_metadata.reports && Array.isArray(user.bespoke_app_metadata.reports)) {
|
|
3703
|
-
updateObject.app_metadata = {
|
|
3704
|
-
...user.bespoke_app_metadata
|
|
3705
|
-
};
|
|
3706
|
-
} else {
|
|
3707
|
-
updateObject.app_metadata = { reports: [] };
|
|
3708
|
-
}
|
|
3709
|
-
updateObject.app_metadata.reports.push({
|
|
3710
|
-
reportId
|
|
3711
|
-
});
|
|
3712
|
-
await updateUser2(updateObject);
|
|
3713
|
-
const latestUserData = await readUser2(updateObject.user_id);
|
|
3714
|
-
if (latestUserData.ok) {
|
|
3715
|
-
await getAuth_default.updateSession(req, res, {
|
|
3716
|
-
...session,
|
|
3717
|
-
user: {
|
|
3718
|
-
...user,
|
|
3719
|
-
bespoke_app_metadata: latestUserData.data.app_metadata
|
|
3720
|
-
}
|
|
3721
|
-
});
|
|
3722
|
-
}
|
|
3723
|
-
}
|
|
3724
|
-
return {
|
|
3725
|
-
ok: true,
|
|
3726
|
-
status: 200,
|
|
3727
|
-
data: "User & session updated"
|
|
3728
|
-
};
|
|
3729
|
-
} catch (error) {
|
|
3730
|
-
return {
|
|
3731
|
-
ok: false,
|
|
3732
|
-
status: 500,
|
|
3733
|
-
error: error.message
|
|
3734
|
-
};
|
|
3735
|
-
}
|
|
3736
|
-
}, [CMS_ROLES.EDITOR]);
|
|
3737
|
-
}
|
|
3738
|
-
|
|
3739
3258
|
// api/endpoints/icon/listIcons.ts
|
|
3740
3259
|
function endpointListIconsFactory(operations, provider) {
|
|
3741
3260
|
const listMethodKey = `list${capitalize(provider)}Icons`;
|
|
3742
3261
|
const listMethod = operations[listMethodKey];
|
|
3743
3262
|
return endpoint("GET", `list/icons/${provider}`, async () => {
|
|
3744
3263
|
return listMethod({});
|
|
3745
|
-
}, [
|
|
3264
|
+
}, []);
|
|
3746
3265
|
}
|
|
3747
3266
|
|
|
3748
3267
|
// api/endpoints/icon/readIcon.ts
|
|
@@ -3816,14 +3335,8 @@ function getEndpointMap(db) {
|
|
|
3816
3335
|
endpointImageSearchFactory(api, "local"),
|
|
3817
3336
|
endpointImageSearchFactory(api, "unsplash"),
|
|
3818
3337
|
endpointUrlProxyFactory(api),
|
|
3819
|
-
endpointGetRolesFactory(api),
|
|
3820
|
-
endpointGetUsersFactory(api),
|
|
3821
|
-
endpointGetUserDataFactory(api),
|
|
3822
|
-
endpointUpdateUserDataFactory(api),
|
|
3823
|
-
endpointAddNewReportToCurrentUserFactory(api),
|
|
3824
3338
|
endpointRevalidateReportFactory(api),
|
|
3825
3339
|
endpointRevalidateUrlFactory(),
|
|
3826
|
-
endpointReadPrivateBlocksFactory(api),
|
|
3827
3340
|
endpointListIconsFactory(api, "tabler"),
|
|
3828
3341
|
endpointReadIconFactory(api, "tabler"),
|
|
3829
3342
|
endpointReportVariables()
|
|
@@ -3844,21 +3357,11 @@ async function endpointNextJsHandlerFactory(req, res) {
|
|
|
3844
3357
|
return map[key];
|
|
3845
3358
|
});
|
|
3846
3359
|
if (handlerObj) {
|
|
3847
|
-
const session = await getAuth_default.getSession(req, res);
|
|
3848
|
-
if (handlerObj.roleRequired) {
|
|
3849
|
-
if (!session) {
|
|
3850
|
-
return res.status(401).json({ error: "Unauthorized. Must be logged in." });
|
|
3851
|
-
}
|
|
3852
|
-
const userRoles = session && session.user && session.user.bespoke_roles && Array.isArray(session.user.bespoke_roles) ? session.user.bespoke_roles : [];
|
|
3853
|
-
if (Array.isArray(handlerObj.roleRequired) && handlerObj.roleRequired.length > 0 && !arrContainsAnyItem(userRoles, handlerObj.roleRequired)) {
|
|
3854
|
-
return res.status(402).json({ error: "Forbidden. Not enough roles." });
|
|
3855
|
-
}
|
|
3856
|
-
}
|
|
3857
3360
|
if (handlerObj.handler) {
|
|
3858
3361
|
if (["POST", "DELETE"].includes(method)) {
|
|
3859
3362
|
req.body = await parseBody(req);
|
|
3860
3363
|
}
|
|
3861
|
-
return Promise.resolve(req).then((req2) => handlerObj.handler(req2, res,
|
|
3364
|
+
return Promise.resolve(req).then((req2) => handlerObj.handler(req2, res, void 0)).then((result) => {
|
|
3862
3365
|
if (result && "error" in result) {
|
|
3863
3366
|
throw new BackendError(result.status, result.error);
|
|
3864
3367
|
}
|
|
@@ -3900,15 +3403,12 @@ var crosswalk_default = reportsCrosswalkEntrypointFn;
|
|
|
3900
3403
|
var actions_exports = {};
|
|
3901
3404
|
__export(actions_exports, {
|
|
3902
3405
|
addBlockToState: () => addBlockToState,
|
|
3903
|
-
addNewReportToCurrentUser: () => addNewReportToCurrentUser,
|
|
3904
3406
|
createEntity: () => createEntity,
|
|
3905
3407
|
deleteEntity: () => deleteEntity,
|
|
3906
3408
|
deleteQueryParam: () => deleteQueryParam,
|
|
3907
3409
|
readEntity: () => readEntity,
|
|
3908
3410
|
readMember: () => readMember,
|
|
3909
3411
|
readMetadata: () => readMetadata,
|
|
3910
|
-
readPrivateBlocks: () => readPrivateBlocks,
|
|
3911
|
-
readUser: () => readUser,
|
|
3912
3412
|
recalculateVariables: () => recalculateVariables,
|
|
3913
3413
|
removeBlocksFromState: () => removeBlocksFromState,
|
|
3914
3414
|
reportSearch: () => reportSearch,
|
|
@@ -3917,15 +3417,12 @@ __export(actions_exports, {
|
|
|
3917
3417
|
revalidateUrl: () => revalidateUrl,
|
|
3918
3418
|
searchMember: () => searchMember,
|
|
3919
3419
|
searchRegenerate: () => searchRegenerate,
|
|
3920
|
-
searchRole: () => searchRole,
|
|
3921
|
-
searchUser: () => searchUser,
|
|
3922
3420
|
setCurrentLocale: () => setCurrentLocale,
|
|
3923
3421
|
setPreviews: () => setPreviews,
|
|
3924
3422
|
setQueryParam: () => setQueryParam,
|
|
3925
3423
|
setSectionState: () => setSectionState,
|
|
3926
3424
|
setStatus: () => setStatus,
|
|
3927
3425
|
updateEntity: () => updateEntity,
|
|
3928
|
-
updateUser: () => updateUser,
|
|
3929
3426
|
urlProxy: () => urlProxy2,
|
|
3930
3427
|
variantValidateSlug: () => variantValidateSlug
|
|
3931
3428
|
});
|
|
@@ -4068,26 +3565,20 @@ function apiFactory2(baseURL) {
|
|
|
4068
3565
|
readMetadata: httpGET(axios6, "read/metadata"),
|
|
4069
3566
|
regenerateSearch: httpPOST(axios6, "search/regenerate"),
|
|
4070
3567
|
urlProxy: httpGET(axios6, "url/proxy"),
|
|
4071
|
-
searchRole: httpGET(axios6, "auth/search/roles"),
|
|
4072
|
-
searchUser: httpGET(axios6, "auth/search/users"),
|
|
4073
|
-
readUser: httpGET(axios6, "auth/read/user"),
|
|
4074
|
-
updateUser: httpPOST(axios6, "auth/update/user"),
|
|
4075
|
-
addNewReportToCurrentUser: httpPOST(axios6, "auth/update/me"),
|
|
4076
3568
|
revalidateReport: httpGET(axios6, "revalidate/report"),
|
|
4077
3569
|
revalidateUrl: httpGET(axios6, "revalidate/url"),
|
|
4078
|
-
readPrivateBlocks: httpPOST(axios6, "read/blocks/private"),
|
|
4079
3570
|
listTablerIcons: httpListIconsFactory(axios6, "tabler"),
|
|
4080
3571
|
readTablerIcon: httpReadIconFactory(axios6, "tabler")
|
|
4081
3572
|
};
|
|
4082
3573
|
}
|
|
4083
3574
|
|
|
4084
3575
|
// models/block.ts
|
|
4085
|
-
var { localeDefault:
|
|
3576
|
+
var { localeDefault: localeDefault5 } = getLocales_default();
|
|
4086
3577
|
function parseBlockContext(context) {
|
|
4087
3578
|
return {
|
|
4088
3579
|
variables: context.variables || {},
|
|
4089
3580
|
query: context.query || {},
|
|
4090
|
-
locale: context.locale ||
|
|
3581
|
+
locale: context.locale || localeDefault5
|
|
4091
3582
|
};
|
|
4092
3583
|
}
|
|
4093
3584
|
var verbose4 = yn2(process.env.REPORTS_LOGGING);
|
|
@@ -4291,10 +3782,10 @@ var selectorQueryToVariable = (id, query, config) => {
|
|
|
4291
3782
|
var selectorQueryToVariable_default = selectorQueryToVariable;
|
|
4292
3783
|
|
|
4293
3784
|
// libs/blocks/getBlockContent.ts
|
|
4294
|
-
var { localeDefault:
|
|
3785
|
+
var { localeDefault: localeDefault6, locales: locales6 } = getLocales_default();
|
|
4295
3786
|
var logicTypes = Object.values(BLOCK_LOGIC_TYPES);
|
|
4296
|
-
var getLocaleDerived = (block, locale =
|
|
4297
|
-
var getBlockContent = (block, _locale =
|
|
3787
|
+
var getLocaleDerived = (block, locale = localeDefault6) => block && logicTypes.includes(block.type) ? { locale: BLOCK_LOGIC_LOCALE, locales: [BLOCK_LOGIC_LOCALE] } : { locale, locales: locales6 };
|
|
3788
|
+
var getBlockContent = (block, _locale = localeDefault6) => {
|
|
4298
3789
|
if (!block)
|
|
4299
3790
|
return {};
|
|
4300
3791
|
const { locale } = getLocaleDerived(block, _locale);
|
|
@@ -4641,7 +4132,7 @@ async function runSingleBlock(block, formatterFunctions, blockContext, readMembe
|
|
|
4641
4132
|
}
|
|
4642
4133
|
};
|
|
4643
4134
|
}
|
|
4644
|
-
var getDependencies = (bid, blocks, acc = [], crawlUp = true,
|
|
4135
|
+
var getDependencies = (bid, blocks, acc = [], crawlUp = true, crawlDown = true, withinSection = true, visited = []) => {
|
|
4645
4136
|
if (visited.includes(bid))
|
|
4646
4137
|
return [];
|
|
4647
4138
|
visited.push(bid);
|
|
@@ -4655,13 +4146,13 @@ var getDependencies = (bid, blocks, acc = [], crawlUp = true, crawlDown2 = true,
|
|
|
4655
4146
|
rootBlock.inputs.forEach((iid2) => getDependencies(iid2, blocks, acc, crawlUp, false, withinSection, visited));
|
|
4656
4147
|
});
|
|
4657
4148
|
}
|
|
4658
|
-
if (rootBlock.consumers.length &&
|
|
4149
|
+
if (rootBlock.consumers.length && crawlDown) {
|
|
4659
4150
|
rootBlock.consumers.forEach((cid) => {
|
|
4660
4151
|
const rel = `${bid}-${cid}`;
|
|
4661
4152
|
if (!acc.includes(rel) && (blocks[cid].section_id === blocks[bid].section_id || !withinSection)) {
|
|
4662
4153
|
acc.push(rel);
|
|
4663
4154
|
}
|
|
4664
|
-
rootBlock.consumers.filter((cid2) => blocks[cid2].section_id === blocks[bid].section_id || !withinSection).forEach((cid2) => getDependencies(cid2, blocks, acc, false,
|
|
4155
|
+
rootBlock.consumers.filter((cid2) => blocks[cid2].section_id === blocks[bid].section_id || !withinSection).forEach((cid2) => getDependencies(cid2, blocks, acc, false, crawlDown, withinSection, visited));
|
|
4665
4156
|
});
|
|
4666
4157
|
}
|
|
4667
4158
|
return acc;
|
|
@@ -4882,7 +4373,7 @@ var parse = (config, formatters = {}, locale = "en", actions = {}, extraGlobals
|
|
|
4882
4373
|
};
|
|
4883
4374
|
|
|
4884
4375
|
// store/lib.ts
|
|
4885
|
-
var { localeDefault:
|
|
4376
|
+
var { localeDefault: localeDefault7 } = getLocales_default();
|
|
4886
4377
|
var blockSchema = new schema.Entity("block" /* BLOCKS */, {}, {
|
|
4887
4378
|
mergeStrategy(a, b) {
|
|
4888
4379
|
if (b.block_input)
|
|
@@ -4981,23 +4472,23 @@ var parseVariableUpdateParams = (status, params = void 0) => {
|
|
|
4981
4472
|
statusPayload
|
|
4982
4473
|
};
|
|
4983
4474
|
};
|
|
4984
|
-
var funcifyFormattersByLocale = (formatters = [], locale =
|
|
4475
|
+
var funcifyFormattersByLocale = (formatters = [], locale = localeDefault7) => formatters.reduce((acc, f) => {
|
|
4985
4476
|
const formatterFn = parse({ vars: ["n"], logic: f.content.logic }, {}, locale, {});
|
|
4986
4477
|
acc[f.name] = formatterFn;
|
|
4987
4478
|
return acc;
|
|
4988
4479
|
}, {});
|
|
4989
4480
|
|
|
4990
4481
|
// store/envvars.ts
|
|
4991
|
-
var
|
|
4992
|
-
var locales7 = process.env.NEXT_PUBLIC_REPORTS_LOCALES?.split(",") || [
|
|
4993
|
-
if (!locales7.includes(
|
|
4994
|
-
locales7.push(
|
|
4482
|
+
var localeDefault8 = process.env.NEXT_PUBLIC_REPORTS_LOCALE_DEFAULT || "en";
|
|
4483
|
+
var locales7 = process.env.NEXT_PUBLIC_REPORTS_LOCALES?.split(",") || [localeDefault8];
|
|
4484
|
+
if (!locales7.includes(localeDefault8))
|
|
4485
|
+
locales7.push(localeDefault8);
|
|
4995
4486
|
|
|
4996
4487
|
// store/statusSlice.ts
|
|
4997
4488
|
var initialState = {
|
|
4998
|
-
localeDefault:
|
|
4489
|
+
localeDefault: localeDefault8,
|
|
4999
4490
|
locales: locales7,
|
|
5000
|
-
currentLocale:
|
|
4491
|
+
currentLocale: localeDefault8,
|
|
5001
4492
|
showToolbar: false,
|
|
5002
4493
|
activeSection: null,
|
|
5003
4494
|
previews: [],
|
|
@@ -5640,51 +5131,6 @@ function urlProxy2(url) {
|
|
|
5640
5131
|
return result.data;
|
|
5641
5132
|
};
|
|
5642
5133
|
}
|
|
5643
|
-
function searchRole() {
|
|
5644
|
-
return async (_, __, api) => {
|
|
5645
|
-
const result = await api.searchRole("");
|
|
5646
|
-
if ("error" in result) {
|
|
5647
|
-
throw new Error(result.error);
|
|
5648
|
-
}
|
|
5649
|
-
return result.data;
|
|
5650
|
-
};
|
|
5651
|
-
}
|
|
5652
|
-
function searchUser(filters) {
|
|
5653
|
-
return async (_, __, api) => {
|
|
5654
|
-
const result = await api.searchUser(filters);
|
|
5655
|
-
if ("error" in result) {
|
|
5656
|
-
throw new Error(result.error);
|
|
5657
|
-
}
|
|
5658
|
-
return result.data;
|
|
5659
|
-
};
|
|
5660
|
-
}
|
|
5661
|
-
function readUser(userId) {
|
|
5662
|
-
return async (_, __, api) => {
|
|
5663
|
-
const result = await api.readUser({ user_id: userId });
|
|
5664
|
-
if ("error" in result) {
|
|
5665
|
-
throw new Error(result.error);
|
|
5666
|
-
}
|
|
5667
|
-
return result.data;
|
|
5668
|
-
};
|
|
5669
|
-
}
|
|
5670
|
-
function updateUser({ user }) {
|
|
5671
|
-
return async (_, __, api) => {
|
|
5672
|
-
const result = await api.updateUser(user);
|
|
5673
|
-
if ("error" in result) {
|
|
5674
|
-
throw new Error(result.error);
|
|
5675
|
-
}
|
|
5676
|
-
return result.data;
|
|
5677
|
-
};
|
|
5678
|
-
}
|
|
5679
|
-
function addNewReportToCurrentUser(params) {
|
|
5680
|
-
return async (_, __, api) => {
|
|
5681
|
-
const result = await api.addNewReportToCurrentUser(params);
|
|
5682
|
-
if ("error" in result) {
|
|
5683
|
-
throw new Error(result.error);
|
|
5684
|
-
}
|
|
5685
|
-
return result.data;
|
|
5686
|
-
};
|
|
5687
|
-
}
|
|
5688
5134
|
function removeBlocksFromState(privateBlockIds) {
|
|
5689
5135
|
const { removeBlocks } = recordsSlice.actions;
|
|
5690
5136
|
return async (dispatch) => {
|
|
@@ -5697,15 +5143,6 @@ function addBlockToState(newBlocks) {
|
|
|
5697
5143
|
await dispatch(addBlocks(newBlocks));
|
|
5698
5144
|
};
|
|
5699
5145
|
}
|
|
5700
|
-
function readPrivateBlocks(params) {
|
|
5701
|
-
return async (_, __, api) => {
|
|
5702
|
-
const result = await api.readPrivateBlocks({ ...params, roles: [] });
|
|
5703
|
-
if ("error" in result) {
|
|
5704
|
-
throw new Error(result.error);
|
|
5705
|
-
}
|
|
5706
|
-
return result.data;
|
|
5707
|
-
};
|
|
5708
|
-
}
|
|
5709
5146
|
function revalidateUrl(params) {
|
|
5710
5147
|
return async (_, __, api) => {
|
|
5711
5148
|
const result = await api.revalidateUrl({ target: params.target });
|
|
@@ -5751,32 +5188,30 @@ function BespokeManagerServerSideProps(options) {
|
|
|
5751
5188
|
preResolve = noop,
|
|
5752
5189
|
postResolve = noop
|
|
5753
5190
|
} = options || {};
|
|
5754
|
-
return
|
|
5755
|
-
|
|
5756
|
-
|
|
5757
|
-
|
|
5758
|
-
|
|
5759
|
-
|
|
5760
|
-
|
|
5761
|
-
|
|
5762
|
-
|
|
5763
|
-
|
|
5764
|
-
|
|
5765
|
-
|
|
5766
|
-
|
|
5767
|
-
|
|
5768
|
-
|
|
5769
|
-
|
|
5770
|
-
|
|
5771
|
-
|
|
5772
|
-
|
|
5773
|
-
|
|
5774
|
-
|
|
5775
|
-
|
|
5776
|
-
}
|
|
5777
|
-
};
|
|
5191
|
+
return storeWrapper.getServerSideProps((store) => {
|
|
5192
|
+
const { dispatch } = store;
|
|
5193
|
+
return async (ctx) => {
|
|
5194
|
+
await dispatch(useDatabaseApi);
|
|
5195
|
+
const preResult = await preResolve(store, ctx);
|
|
5196
|
+
if ("redirect" in preResult)
|
|
5197
|
+
return { props: preResult };
|
|
5198
|
+
await Promise.all([
|
|
5199
|
+
dispatch(readEntity("formatter", {})),
|
|
5200
|
+
dispatch(readEntity("report", {
|
|
5201
|
+
id: parseReportId(ctx.query[pathSegmentsKey]),
|
|
5202
|
+
include: true
|
|
5203
|
+
})),
|
|
5204
|
+
// Mark the status as CMS environment
|
|
5205
|
+
dispatch(statusActions.setStatus({ isCMS: true }))
|
|
5206
|
+
]);
|
|
5207
|
+
const postResult = await postResolve(store, ctx);
|
|
5208
|
+
return {
|
|
5209
|
+
props: {
|
|
5210
|
+
...preResult,
|
|
5211
|
+
...postResult
|
|
5212
|
+
}
|
|
5778
5213
|
};
|
|
5779
|
-
}
|
|
5214
|
+
};
|
|
5780
5215
|
});
|
|
5781
5216
|
}
|
|
5782
5217
|
function parseReportId(value) {
|
|
@@ -5812,7 +5247,7 @@ function BespokeRendererStaticPaths(options) {
|
|
|
5812
5247
|
} = options || {};
|
|
5813
5248
|
return async (context) => {
|
|
5814
5249
|
const {
|
|
5815
|
-
defaultLocale =
|
|
5250
|
+
defaultLocale = localeDefault8,
|
|
5816
5251
|
locales: locales9 = []
|
|
5817
5252
|
} = context;
|
|
5818
5253
|
let paths = [];
|
|
@@ -5824,7 +5259,7 @@ function BespokeRendererStaticPaths(options) {
|
|
|
5824
5259
|
// gets top {limit} ranked per profile type.
|
|
5825
5260
|
limit,
|
|
5826
5261
|
format: "plain",
|
|
5827
|
-
locale: locale ||
|
|
5262
|
+
locale: locale || localeDefault8,
|
|
5828
5263
|
noImage: false,
|
|
5829
5264
|
visible: true,
|
|
5830
5265
|
report: [],
|
|
@@ -5856,10 +5291,11 @@ function BespokeRendererStaticProps(options) {
|
|
|
5856
5291
|
return storeWrapper.getStaticProps((store) => {
|
|
5857
5292
|
const { dispatch } = store;
|
|
5858
5293
|
return async (context) => {
|
|
5294
|
+
console.log("loading store");
|
|
5859
5295
|
await dispatch(useDatabaseApi);
|
|
5860
5296
|
const buildTime = (/* @__PURE__ */ new Date()).toISOString();
|
|
5861
5297
|
const {
|
|
5862
|
-
locale =
|
|
5298
|
+
locale = localeDefault8,
|
|
5863
5299
|
// TODO: detect or use app default
|
|
5864
5300
|
params = {}
|
|
5865
5301
|
} = context;
|
|
@@ -5893,23 +5329,13 @@ function BespokeRendererStaticProps(options) {
|
|
|
5893
5329
|
const sectionList = selectSectionList(state);
|
|
5894
5330
|
const blockRecords = selectBlockRecords(state);
|
|
5895
5331
|
const publicBlockRecords = { ...blockRecords };
|
|
5896
|
-
let privateBlockIds = Object.values(blockRecords).reduce((acc, block) => {
|
|
5897
|
-
if ("access" in block.settings && !["public", "guest"].some((grant) => !block.settings.access || block.settings.access.includes(grant))) {
|
|
5898
|
-
acc.push(block.id);
|
|
5899
|
-
}
|
|
5900
|
-
return acc;
|
|
5901
|
-
}, []);
|
|
5902
|
-
privateBlockIds = privateBlockIds.concat(crawlDown(privateBlockIds, Object.values(publicBlockRecords)));
|
|
5903
|
-
privateBlockIds.forEach((privateBlockId) => {
|
|
5904
|
-
delete publicBlockRecords[privateBlockId];
|
|
5905
|
-
});
|
|
5906
|
-
await dispatch(removeBlocksFromState(privateBlockIds));
|
|
5907
5332
|
const attributes = {
|
|
5908
5333
|
...previewsToAttributes_default(members.results),
|
|
5909
5334
|
locale,
|
|
5910
5335
|
...publicEnvVarsToAttributes_default()
|
|
5911
5336
|
};
|
|
5912
5337
|
const readMemberFn = async (innerParams) => await dispatch(readMember(innerParams));
|
|
5338
|
+
console.log("runConsumers");
|
|
5913
5339
|
await runConsumersV2(
|
|
5914
5340
|
publicBlockRecords,
|
|
5915
5341
|
sectionList,
|
|
@@ -5924,6 +5350,7 @@ function BespokeRendererStaticProps(options) {
|
|
|
5924
5350
|
readMemberFn,
|
|
5925
5351
|
"report"
|
|
5926
5352
|
).then((data) => {
|
|
5353
|
+
console.log("Done run consumers");
|
|
5927
5354
|
dispatch(variablesActions.setVariableChange({ ...data, attributes }));
|
|
5928
5355
|
});
|
|
5929
5356
|
return {
|
|
@@ -5951,4 +5378,4 @@ function getSlugSegments(slugs = []) {
|
|
|
5951
5378
|
};
|
|
5952
5379
|
}
|
|
5953
5380
|
|
|
5954
|
-
export {
|
|
5381
|
+
export { BespokeManagerServerSideProps, BespokeRendererStaticPaths, BespokeRendererStaticProps, crosswalk_default as ReportCrosswalkHandler, apiFactory as dbApiFactory, endpointKey, endpointNextJsHandlerFactory, getDB, useDatabaseApi };
|