adminforth 1.3.54-next.22 → 1.3.54-next.24

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.
Files changed (125) hide show
  1. package/dist/auth.js +41 -56
  2. package/dist/auth.js.map +1 -1
  3. package/dist/dataConnectors/baseConnector.js +107 -128
  4. package/dist/dataConnectors/baseConnector.js.map +1 -1
  5. package/dist/dataConnectors/clickhouse.js +125 -148
  6. package/dist/dataConnectors/clickhouse.js.map +1 -1
  7. package/dist/dataConnectors/mongo.js +74 -101
  8. package/dist/dataConnectors/mongo.js.map +1 -1
  9. package/dist/dataConnectors/postgres.js +117 -142
  10. package/dist/dataConnectors/postgres.js.map +1 -1
  11. package/dist/dataConnectors/sqlite.js +106 -129
  12. package/dist/dataConnectors/sqlite.js.map +1 -1
  13. package/dist/index.js +196 -217
  14. package/dist/index.js.map +1 -1
  15. package/dist/modules/codeInjector.js +470 -495
  16. package/dist/modules/codeInjector.js.map +1 -1
  17. package/dist/modules/configValidator.js +13 -22
  18. package/dist/modules/configValidator.js.map +1 -1
  19. package/dist/modules/operationalResource.js +49 -70
  20. package/dist/modules/operationalResource.js.map +1 -1
  21. package/dist/modules/restApi.js +103 -116
  22. package/dist/modules/restApi.js.map +1 -1
  23. package/dist/plugins/audit-log/types.js +2 -0
  24. package/dist/plugins/audit-log/types.js.map +1 -0
  25. package/dist/plugins/chat-gpt/types.js +2 -0
  26. package/dist/plugins/chat-gpt/types.js.map +1 -0
  27. package/dist/plugins/email-password-reset/types.js +2 -0
  28. package/dist/plugins/email-password-reset/types.js.map +1 -0
  29. package/dist/plugins/foreign-inline-list/types.js +2 -0
  30. package/dist/plugins/foreign-inline-list/types.js.map +1 -0
  31. package/dist/plugins/import-export/types.js +2 -0
  32. package/dist/plugins/import-export/types.js.map +1 -0
  33. package/dist/plugins/rich-editor/custom/async-queue.js +29 -0
  34. package/dist/plugins/rich-editor/custom/async-queue.js.map +1 -0
  35. package/dist/plugins/rich-editor/dist/async-queue.js +41 -0
  36. package/dist/plugins/rich-editor/dist/custom/async-queue.js +29 -0
  37. package/dist/plugins/rich-editor/dist/custom/async-queue.js.map +1 -0
  38. package/dist/plugins/rich-editor/types.js +16 -0
  39. package/dist/plugins/rich-editor/types.js.map +1 -0
  40. package/dist/plugins/two-factors-auth/types.js +2 -0
  41. package/dist/plugins/two-factors-auth/types.js.map +1 -0
  42. package/dist/plugins/upload/types.js +2 -0
  43. package/dist/plugins/upload/types.js.map +1 -0
  44. package/dist/servers/express.js +29 -42
  45. package/dist/servers/express.js.map +1 -1
  46. package/package.json +4 -1
  47. package/auth.ts +0 -140
  48. package/basePlugin.ts +0 -70
  49. package/dataConnectors/baseConnector.ts +0 -222
  50. package/dataConnectors/clickhouse.ts +0 -343
  51. package/dataConnectors/mongo.ts +0 -202
  52. package/dataConnectors/postgres.ts +0 -310
  53. package/dataConnectors/sqlite.ts +0 -258
  54. package/index.ts +0 -428
  55. package/modules/codeInjector.ts +0 -747
  56. package/modules/configValidator.ts +0 -588
  57. package/modules/operationalResource.ts +0 -98
  58. package/modules/restApi.ts +0 -718
  59. package/modules/styleGenerator.ts +0 -55
  60. package/modules/styles.ts +0 -126
  61. package/modules/utils.ts +0 -472
  62. package/servers/express.ts +0 -259
  63. package/spa/.eslintrc.cjs +0 -14
  64. package/spa/README.md +0 -39
  65. package/spa/env.d.ts +0 -1
  66. package/spa/index.html +0 -23
  67. package/spa/package-lock.json +0 -4659
  68. package/spa/package.json +0 -52
  69. package/spa/postcss.config.js +0 -6
  70. package/spa/public/assets/favicon.png +0 -0
  71. package/spa/src/App.vue +0 -418
  72. package/spa/src/assets/base.css +0 -2
  73. package/spa/src/assets/logo.svg +0 -19
  74. package/spa/src/components/AcceptModal.vue +0 -45
  75. package/spa/src/components/Breadcrumbs.vue +0 -41
  76. package/spa/src/components/BreadcrumbsWithButtons.vue +0 -26
  77. package/spa/src/components/CustomDatePicker.vue +0 -176
  78. package/spa/src/components/CustomDateRangePicker.vue +0 -218
  79. package/spa/src/components/CustomRangePicker.vue +0 -156
  80. package/spa/src/components/Dropdown.vue +0 -168
  81. package/spa/src/components/Filters.vue +0 -222
  82. package/spa/src/components/HelloWorld.vue +0 -17
  83. package/spa/src/components/MenuLink.vue +0 -27
  84. package/spa/src/components/ResourceForm.vue +0 -325
  85. package/spa/src/components/ResourceListTable.vue +0 -466
  86. package/spa/src/components/SingleSkeletLoader.vue +0 -13
  87. package/spa/src/components/SkeleteLoader.vue +0 -23
  88. package/spa/src/components/ThreeDotsMenu.vue +0 -43
  89. package/spa/src/components/Toast.vue +0 -78
  90. package/spa/src/components/ValueRenderer.vue +0 -141
  91. package/spa/src/components/icons/IconCalendar.vue +0 -5
  92. package/spa/src/components/icons/IconCommunity.vue +0 -7
  93. package/spa/src/components/icons/IconDocumentation.vue +0 -7
  94. package/spa/src/components/icons/IconEcosystem.vue +0 -7
  95. package/spa/src/components/icons/IconSupport.vue +0 -7
  96. package/spa/src/components/icons/IconTime.vue +0 -5
  97. package/spa/src/components/icons/IconTooling.vue +0 -19
  98. package/spa/src/composables/useFrontendApi.ts +0 -26
  99. package/spa/src/composables/useStores.ts +0 -131
  100. package/spa/src/index.scss +0 -31
  101. package/spa/src/main.ts +0 -18
  102. package/spa/src/renderers/CompactUUID.vue +0 -48
  103. package/spa/src/renderers/CountryFlag.vue +0 -69
  104. package/spa/src/router/index.ts +0 -59
  105. package/spa/src/spa_types/core.ts +0 -53
  106. package/spa/src/stores/core.ts +0 -148
  107. package/spa/src/stores/filters.ts +0 -27
  108. package/spa/src/stores/modal.ts +0 -48
  109. package/spa/src/stores/toast.ts +0 -31
  110. package/spa/src/stores/user.ts +0 -72
  111. package/spa/src/utils.ts +0 -160
  112. package/spa/src/views/CreateView.vue +0 -167
  113. package/spa/src/views/EditView.vue +0 -170
  114. package/spa/src/views/ListView.vue +0 -352
  115. package/spa/src/views/LoginView.vue +0 -192
  116. package/spa/src/views/ResourceParent.vue +0 -17
  117. package/spa/src/views/ShowView.vue +0 -194
  118. package/spa/tailwind.config.js +0 -17
  119. package/spa/tsconfig.app.json +0 -14
  120. package/spa/tsconfig.json +0 -11
  121. package/spa/tsconfig.node.json +0 -19
  122. package/spa/vite.config.ts +0 -56
  123. package/tsconfig.json +0 -112
  124. package/types/AdminForthConfig.ts +0 -1762
  125. package/types/FrontendAPI.ts +0 -143
@@ -1,36 +1,25 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { AdminForthFilterOperators, AdminForthDataTypes, AllowedActionsEnum, ActionCheckSource, AdminForthResourcePages } from "../types/AdminForthConfig.js";
11
2
  import { ADMINFORTH_VERSION, listify } from './utils.js';
12
3
  import AdminForthAuth from "../auth.js";
13
- export function interpretResource(adminUser, resource, meta, source) {
14
- return __awaiter(this, void 0, void 0, function* () {
15
- var _a;
16
- // if (process.env.HEAVY_DEBUG) {
17
- // console.log('🪲Interpreting resource', resource.resourceId, source, 'adminUser', adminUser);
18
- // }
19
- const allowedActions = {};
20
- yield Promise.all(Object.entries(((_a = resource.options) === null || _a === void 0 ? void 0 : _a.allowedActions) || {}).map((_b) => __awaiter(this, [_b], void 0, function* ([key, value]) {
21
- if (process.env.HEAVY_DEBUG) {
22
- console.log(`🪲🚥check allowed ${key}, ${value}`);
23
- }
24
- // if callable then call
25
- if (typeof value === 'function') {
26
- allowedActions[key] = yield value({ adminUser, resource, meta, source });
27
- }
28
- else {
29
- allowedActions[key] = value;
30
- }
31
- })));
32
- return { allowedActions };
33
- });
4
+ export async function interpretResource(adminUser, resource, meta, source) {
5
+ var _a;
6
+ // if (process.env.HEAVY_DEBUG) {
7
+ // console.log('🪲Interpreting resource', resource.resourceId, source, 'adminUser', adminUser);
8
+ // }
9
+ const allowedActions = {};
10
+ await Promise.all(Object.entries(((_a = resource.options) === null || _a === void 0 ? void 0 : _a.allowedActions) || {}).map(async ([key, value]) => {
11
+ if (process.env.HEAVY_DEBUG) {
12
+ console.log(`🪲🚥check allowed ${key}, ${value}`);
13
+ }
14
+ // if callable then call
15
+ if (typeof value === 'function') {
16
+ allowedActions[key] = await value({ adminUser, resource, meta, source });
17
+ }
18
+ else {
19
+ allowedActions[key] = value;
20
+ }
21
+ }));
22
+ return { allowedActions };
34
23
  }
35
24
  export default class AdminForthRestAPI {
36
25
  constructor(adminforth) {
@@ -41,8 +30,8 @@ export default class AdminForthRestAPI {
41
30
  noAuth: true,
42
31
  method: 'POST',
43
32
  path: '/login',
44
- handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, response }) {
45
- var _b, _c, _d, _e;
33
+ handler: async ({ body, response }) => {
34
+ var _a, _b, _c, _d;
46
35
  const INVALID_MESSAGE = 'Invalid Username or Password';
47
36
  const { username, password, rememberMe } = body;
48
37
  let adminUser;
@@ -62,7 +51,7 @@ export default class AdminForthRestAPI {
62
51
  });
63
52
  console.log('Adding passwordHashField to userResource', userResource);
64
53
  }
65
- const userRecord = (_b = (yield this.adminforth.connectors[userResource.dataSource].getData({
54
+ const userRecord = (_a = (await this.adminforth.connectors[userResource.dataSource].getData({
66
55
  resource: userResource,
67
56
  filters: [
68
57
  { field: this.adminforth.config.auth.usernameField, operator: AdminForthFilterOperators.EQ, value: username },
@@ -70,12 +59,12 @@ export default class AdminForthRestAPI {
70
59
  limit: 1,
71
60
  offset: 0,
72
61
  sort: [],
73
- })).data) === null || _b === void 0 ? void 0 : _b[0];
62
+ })).data) === null || _a === void 0 ? void 0 : _a[0];
74
63
  if (!userRecord) {
75
64
  return { error: INVALID_MESSAGE };
76
65
  }
77
66
  const passwordHash = userRecord[this.adminforth.config.auth.passwordHashField];
78
- const valid = yield AdminForthAuth.verifyPassword(password, passwordHash);
67
+ const valid = await AdminForthAuth.verifyPassword(password, passwordHash);
79
68
  if (valid) {
80
69
  adminUser = {
81
70
  dbUser: userRecord,
@@ -85,9 +74,9 @@ export default class AdminForthRestAPI {
85
74
  const beforeLoginConfirmation = this.adminforth.config.auth.beforeLoginConfirmation;
86
75
  if (beforeLoginConfirmation === null || beforeLoginConfirmation === void 0 ? void 0 : beforeLoginConfirmation.length) {
87
76
  for (const hook of beforeLoginConfirmation) {
88
- const resp = yield hook({ adminUser, response });
89
- if ((_c = resp === null || resp === void 0 ? void 0 : resp.body) === null || _c === void 0 ? void 0 : _c.redirectTo) {
90
- toReturn = { ok: resp.ok, redirectTo: (_d = resp === null || resp === void 0 ? void 0 : resp.body) === null || _d === void 0 ? void 0 : _d.redirectTo, allowedLogin: (_e = resp === null || resp === void 0 ? void 0 : resp.body) === null || _e === void 0 ? void 0 : _e.allowedLogin };
77
+ const resp = await hook({ adminUser, response });
78
+ if ((_b = resp === null || resp === void 0 ? void 0 : resp.body) === null || _b === void 0 ? void 0 : _b.redirectTo) {
79
+ toReturn = { ok: resp.ok, redirectTo: (_c = resp === null || resp === void 0 ? void 0 : resp.body) === null || _c === void 0 ? void 0 : _c.redirectTo, allowedLogin: (_d = resp === null || resp === void 0 ? void 0 : resp.body) === null || _d === void 0 ? void 0 : _d.allowedLogin };
91
80
  break;
92
81
  }
93
82
  }
@@ -106,30 +95,30 @@ export default class AdminForthRestAPI {
106
95
  return { error: INVALID_MESSAGE };
107
96
  }
108
97
  return toReturn;
109
- })
98
+ }
110
99
  });
111
100
  server.endpoint({
112
101
  method: 'POST',
113
102
  path: '/check_auth',
114
- handler: (_f) => __awaiter(this, [_f], void 0, function* ({ adminUser }) {
103
+ handler: async ({ adminUser }) => {
115
104
  return { ok: true };
116
- }),
105
+ },
117
106
  });
118
107
  server.endpoint({
119
108
  noAuth: true,
120
109
  method: 'POST',
121
110
  path: '/logout',
122
- handler: (_g) => __awaiter(this, [_g], void 0, function* ({ response }) {
111
+ handler: async ({ response }) => {
123
112
  this.adminforth.auth.removeAuthCookie(response);
124
113
  return { ok: true };
125
- }),
114
+ },
126
115
  });
127
116
  server.endpoint({
128
117
  noAuth: true,
129
118
  method: 'GET',
130
119
  path: '/get_public_config',
131
- handler: (_h) => __awaiter(this, [_h], void 0, function* ({ body }) {
132
- var _j;
120
+ handler: async ({ body }) => {
121
+ var _a;
133
122
  // find resource
134
123
  if (!this.adminforth.config.auth) {
135
124
  throw new Error('No config.auth defined');
@@ -142,19 +131,19 @@ export default class AdminForthRestAPI {
142
131
  usernameFieldName: usernameColumn.label,
143
132
  loginBackgroundImage: this.adminforth.config.auth.loginBackgroundImage,
144
133
  loginBackgroundPosition: this.adminforth.config.auth.loginBackgroundPosition,
145
- title: (_j = this.adminforth.config.customization) === null || _j === void 0 ? void 0 : _j.title,
134
+ title: (_a = this.adminforth.config.customization) === null || _a === void 0 ? void 0 : _a.title,
146
135
  demoCredentials: this.adminforth.config.auth.demoCredentials,
147
136
  loginPromptHTML: this.adminforth.config.auth.loginPromptHTML,
148
137
  loginPageInjections: this.adminforth.config.customization.loginPageInjections,
149
138
  rememberMeDays: this.adminforth.config.auth.rememberMeDays,
150
139
  };
151
- }),
140
+ },
152
141
  });
153
142
  server.endpoint({
154
143
  method: 'GET',
155
144
  path: '/get_base_config',
156
- handler: (_k) => __awaiter(this, [_k], void 0, function* ({ input, adminUser, cookies }) {
157
- var _l, _m, _o, _p, _q;
145
+ handler: async ({ input, adminUser, cookies }) => {
146
+ var _a, _b, _c, _d, _e;
158
147
  let username = '';
159
148
  let userFullName = '';
160
149
  const dbUser = adminUser.dbUser;
@@ -176,14 +165,12 @@ export default class AdminForthRestAPI {
176
165
  return toReturn;
177
166
  }
178
167
  };
179
- function processMenuItem(menuItem) {
180
- return __awaiter(this, void 0, void 0, function* () {
181
- if (menuItem.badge) {
182
- if (typeof menuItem.badge === 'function') {
183
- menuItem.badge = yield menuItem.badge(adminUser);
184
- }
168
+ async function processMenuItem(menuItem) {
169
+ if (menuItem.badge) {
170
+ if (typeof menuItem.badge === 'function') {
171
+ menuItem.badge = await menuItem.badge(adminUser);
185
172
  }
186
- });
173
+ }
187
174
  }
188
175
  let newMenu = [];
189
176
  for (let menuItem of this.adminforth.config.menu) {
@@ -202,15 +189,15 @@ export default class AdminForthRestAPI {
202
189
  continue;
203
190
  }
204
191
  }
205
- yield processMenuItem(newChild);
192
+ await processMenuItem(newChild);
206
193
  newChildren.push(newChild);
207
194
  }
208
195
  newMenuItem = Object.assign(Object.assign({}, newMenuItem), { children: newChildren });
209
196
  }
210
- yield processMenuItem(newMenuItem);
197
+ await processMenuItem(newMenuItem);
211
198
  newMenu.push(newMenuItem);
212
199
  }
213
- const announcementBadge = (_m = (_l = this.adminforth.config.customization).announcementBadge) === null || _m === void 0 ? void 0 : _m.call(_l, adminUser);
200
+ const announcementBadge = (_b = (_a = this.adminforth.config.customization).announcementBadge) === null || _b === void 0 ? void 0 : _b.call(_a, adminUser);
214
201
  return {
215
202
  user: userData,
216
203
  resources: this.adminforth.config.resources.map((res) => ({
@@ -227,15 +214,15 @@ export default class AdminForthRestAPI {
227
214
  deleteConfirmation: this.adminforth.config.deleteConfirmation,
228
215
  auth: this.adminforth.config.auth,
229
216
  usernameField: this.adminforth.config.auth.usernameField,
230
- title: (_o = this.adminforth.config.customization) === null || _o === void 0 ? void 0 : _o.title,
231
- emptyFieldPlaceholder: (_p = this.adminforth.config.customization) === null || _p === void 0 ? void 0 : _p.emptyFieldPlaceholder,
217
+ title: (_c = this.adminforth.config.customization) === null || _c === void 0 ? void 0 : _c.title,
218
+ emptyFieldPlaceholder: (_d = this.adminforth.config.customization) === null || _d === void 0 ? void 0 : _d.emptyFieldPlaceholder,
232
219
  announcementBadge,
233
- globalInjections: (_q = this.adminforth.config.customization) === null || _q === void 0 ? void 0 : _q.globalInjections,
220
+ globalInjections: (_e = this.adminforth.config.customization) === null || _e === void 0 ? void 0 : _e.globalInjections,
234
221
  },
235
222
  adminUser,
236
223
  version: ADMINFORTH_VERSION,
237
224
  };
238
- }),
225
+ },
239
226
  });
240
227
  function checkAccess(action, allowedActions) {
241
228
  const allowed = allowedActions[action];
@@ -247,7 +234,7 @@ export default class AdminForthRestAPI {
247
234
  server.endpoint({
248
235
  method: 'POST',
249
236
  path: '/get_resource',
250
- handler: (_r) => __awaiter(this, [_r], void 0, function* ({ body, adminUser }) {
237
+ handler: async ({ body, adminUser }) => {
251
238
  const { resourceId } = body;
252
239
  if (!this.adminforth.statuses.dbDiscover) {
253
240
  return { error: 'Database discovery not started' };
@@ -259,11 +246,11 @@ export default class AdminForthRestAPI {
259
246
  if (!resource) {
260
247
  return { error: `Resource ${resourceId} not found` };
261
248
  }
262
- const { allowedActions } = yield interpretResource(adminUser, resource, {}, ActionCheckSource.DisplayButtons);
249
+ const { allowedActions } = await interpretResource(adminUser, resource, {}, ActionCheckSource.DisplayButtons);
263
250
  const allowedBulkActions = [];
264
- yield Promise.all(resource.options.bulkActions.map((action) => __awaiter(this, void 0, void 0, function* () {
251
+ await Promise.all(resource.options.bulkActions.map(async (action) => {
265
252
  if (action.allowed) {
266
- const res = yield action.allowed({ adminUser, resource, allowedActions });
253
+ const res = await action.allowed({ adminUser, resource, allowedActions });
267
254
  if (res) {
268
255
  allowedBulkActions.push(action);
269
256
  }
@@ -271,18 +258,18 @@ export default class AdminForthRestAPI {
271
258
  else {
272
259
  allowedBulkActions.push(action);
273
260
  }
274
- })));
261
+ }));
275
262
  // exclude "plugins" key
276
263
  return {
277
264
  resource: Object.assign(Object.assign({}, resource), { plugins: undefined, options: Object.assign(Object.assign({}, resource.options), { bulkActions: allowedBulkActions, allowedActions }) })
278
265
  };
279
- }),
266
+ },
280
267
  });
281
268
  server.endpoint({
282
269
  method: 'POST',
283
270
  path: '/get_resource_data',
284
- handler: (_s) => __awaiter(this, [_s], void 0, function* ({ body, adminUser }) {
285
- var _t, _u, _v, _w;
271
+ handler: async ({ body, adminUser }) => {
272
+ var _a, _b, _c, _d;
286
273
  const { resourceId, source } = body;
287
274
  if (['show', 'list'].includes(source) === false) {
288
275
  return { error: 'Invalid source, should be list or show' };
@@ -297,13 +284,13 @@ export default class AdminForthRestAPI {
297
284
  if (!resource) {
298
285
  return { error: `Resource ${resourceId} not found` };
299
286
  }
300
- const { allowedActions } = yield interpretResource(adminUser, resource, { requestBody: body }, ActionCheckSource.DisplayButtons);
287
+ const { allowedActions } = await interpretResource(adminUser, resource, { requestBody: body }, ActionCheckSource.DisplayButtons);
301
288
  const { allowed, error } = checkAccess(source, allowedActions);
302
289
  if (!allowed) {
303
290
  return { error };
304
291
  }
305
- for (const hook of listify((_u = (_t = resource.hooks) === null || _t === void 0 ? void 0 : _t[source]) === null || _u === void 0 ? void 0 : _u.beforeDatasourceRequest)) {
306
- const resp = yield hook({ resource, query: body, adminUser });
292
+ for (const hook of listify((_b = (_a = resource.hooks) === null || _a === void 0 ? void 0 : _a[source]) === null || _b === void 0 ? void 0 : _b.beforeDatasourceRequest)) {
293
+ const resp = await hook({ resource, query: body, adminUser });
307
294
  if (!resp || (!resp.ok && !resp.error)) {
308
295
  throw new Error(`Hook must return object with {ok: true} or { error: 'Error' } `);
309
296
  }
@@ -329,7 +316,7 @@ export default class AdminForthRestAPI {
329
316
  return { data: [], total: 0 };
330
317
  }
331
318
  }
332
- const data = yield this.adminforth.connectors[resource.dataSource].getData({
319
+ const data = await this.adminforth.connectors[resource.dataSource].getData({
333
320
  resource,
334
321
  limit,
335
322
  offset,
@@ -338,7 +325,7 @@ export default class AdminForthRestAPI {
338
325
  getTotals: true,
339
326
  });
340
327
  // for foreign keys, add references
341
- yield Promise.all(resource.columns.filter((col) => col.foreignResource).map((col) => __awaiter(this, void 0, void 0, function* () {
328
+ await Promise.all(resource.columns.filter((col) => col.foreignResource).map(async (col) => {
342
329
  const targetResource = this.adminforth.config.resources.find((res) => res.resourceId == col.foreignResource.resourceId);
343
330
  const targetConnector = this.adminforth.connectors[targetResource.dataSource];
344
331
  const targetResourcePkField = targetResource.columns.find((col) => col.primaryKey).name;
@@ -346,7 +333,7 @@ export default class AdminForthRestAPI {
346
333
  if (pksUnique.length === 0) {
347
334
  return;
348
335
  }
349
- const targetData = yield targetConnector.getData({
336
+ const targetData = await targetConnector.getData({
350
337
  resource: targetResource,
351
338
  limit: limit,
352
339
  offset: 0,
@@ -369,7 +356,7 @@ export default class AdminForthRestAPI {
369
356
  data.data.forEach((item) => {
370
357
  item[col.name] = targetDataMap[item[col.name]];
371
358
  });
372
- })));
359
+ }));
373
360
  // remove all columns which are not defined in resources, or defined but backendOnly
374
361
  data.data.forEach((item) => {
375
362
  Object.keys(item).forEach((key) => {
@@ -380,13 +367,13 @@ export default class AdminForthRestAPI {
380
367
  item._label = resource.recordLabel(item);
381
368
  });
382
369
  if (resource.options.listTableClickUrl) {
383
- yield Promise.all(data.data.map((item) => __awaiter(this, void 0, void 0, function* () {
384
- item._clickUrl = yield resource.options.listTableClickUrl(item, adminUser);
385
- })));
370
+ await Promise.all(data.data.map(async (item) => {
371
+ item._clickUrl = await resource.options.listTableClickUrl(item, adminUser);
372
+ }));
386
373
  }
387
374
  // only after adminforth made all post processing, give user ability to edit it
388
- for (const hook of listify((_w = (_v = resource.hooks) === null || _v === void 0 ? void 0 : _v[source]) === null || _w === void 0 ? void 0 : _w.afterDatasourceResponse)) {
389
- const resp = yield hook({ resource, response: data.data, adminUser });
375
+ for (const hook of listify((_d = (_c = resource.hooks) === null || _c === void 0 ? void 0 : _c[source]) === null || _d === void 0 ? void 0 : _d.afterDatasourceResponse)) {
376
+ const resp = await hook({ resource, response: data.data, adminUser });
390
377
  if (!resp || (!resp.ok && !resp.error)) {
391
378
  throw new Error(`Hook must return object with {ok: true} or { error: 'Error' } `);
392
379
  }
@@ -395,13 +382,13 @@ export default class AdminForthRestAPI {
395
382
  }
396
383
  }
397
384
  return Object.assign(Object.assign({}, data), { options: resource === null || resource === void 0 ? void 0 : resource.options });
398
- }),
385
+ },
399
386
  });
400
387
  server.endpoint({
401
388
  method: 'POST',
402
389
  path: '/get_resource_foreign_data',
403
- handler: (_x) => __awaiter(this, [_x], void 0, function* ({ body, adminUser }) {
404
- var _y, _z, _0, _1;
390
+ handler: async ({ body, adminUser }) => {
391
+ var _a, _b, _c, _d;
405
392
  const { resourceId, column } = body;
406
393
  if (!this.adminforth.statuses.dbDiscover) {
407
394
  return { error: 'Database discovery not started' };
@@ -422,8 +409,8 @@ export default class AdminForthRestAPI {
422
409
  }
423
410
  const targetResourceId = columnConfig.foreignResource.resourceId;
424
411
  const targetResource = this.adminforth.config.resources.find((res) => res.resourceId == targetResourceId);
425
- for (const hook of listify((_z = (_y = columnConfig.foreignResource.hooks) === null || _y === void 0 ? void 0 : _y.dropdownList) === null || _z === void 0 ? void 0 : _z.beforeDatasourceRequest)) {
426
- const resp = yield hook({ query: body, adminUser, resource: targetResource });
412
+ for (const hook of listify((_b = (_a = columnConfig.foreignResource.hooks) === null || _a === void 0 ? void 0 : _a.dropdownList) === null || _b === void 0 ? void 0 : _b.beforeDatasourceRequest)) {
413
+ const resp = await hook({ query: body, adminUser, resource: targetResource });
427
414
  if (!resp || (!resp.ok && !resp.error)) {
428
415
  throw new Error(`Hook must return object with {ok: true} or { error: 'Error' } `);
429
416
  }
@@ -432,7 +419,7 @@ export default class AdminForthRestAPI {
432
419
  }
433
420
  }
434
421
  const { limit, offset, filters, sort } = body;
435
- const dbDataItems = yield this.adminforth.connectors[targetResource.dataSource].getData({
422
+ const dbDataItems = await this.adminforth.connectors[targetResource.dataSource].getData({
436
423
  resource: targetResource,
437
424
  limit,
438
425
  offset,
@@ -451,8 +438,8 @@ export default class AdminForthRestAPI {
451
438
  const response = {
452
439
  items
453
440
  };
454
- for (const hook of listify((_1 = (_0 = columnConfig.foreignResource.hooks) === null || _0 === void 0 ? void 0 : _0.dropdownList) === null || _1 === void 0 ? void 0 : _1.afterDatasourceResponse)) {
455
- const resp = yield hook({ response, adminUser, resource: targetResource });
441
+ for (const hook of listify((_d = (_c = columnConfig.foreignResource.hooks) === null || _c === void 0 ? void 0 : _c.dropdownList) === null || _d === void 0 ? void 0 : _d.afterDatasourceResponse)) {
442
+ const resp = await hook({ response, adminUser, resource: targetResource });
456
443
  if (!resp || (!resp.ok && !resp.error)) {
457
444
  throw new Error(`Hook must return object with {ok: true} or { error: 'Error' } `);
458
445
  }
@@ -461,12 +448,12 @@ export default class AdminForthRestAPI {
461
448
  }
462
449
  }
463
450
  return response;
464
- }),
451
+ },
465
452
  });
466
453
  server.endpoint({
467
454
  method: 'POST',
468
455
  path: '/get_min_max_for_columns',
469
- handler: (_2) => __awaiter(this, [_2], void 0, function* ({ body }) {
456
+ handler: async ({ body }) => {
470
457
  const { resourceId } = body;
471
458
  if (!this.adminforth.statuses.dbDiscover) {
472
459
  return { error: 'Database discovery not started' };
@@ -478,7 +465,7 @@ export default class AdminForthRestAPI {
478
465
  if (!resource) {
479
466
  return { error: `Resource '${resourceId}' not found` };
480
467
  }
481
- const item = yield this.adminforth.connectors[resource.dataSource].getMinMaxForColumns({
468
+ const item = await this.adminforth.connectors[resource.dataSource].getMinMaxForColumns({
482
469
  resource,
483
470
  columns: resource.columns.filter((col) => [
484
471
  AdminForthDataTypes.INTEGER,
@@ -490,31 +477,31 @@ export default class AdminForthRestAPI {
490
477
  ].includes(col.type) && col.allowMinMaxQuery === true),
491
478
  });
492
479
  return item;
493
- }),
480
+ },
494
481
  });
495
482
  server.endpoint({
496
483
  method: 'POST',
497
484
  path: '/create_record',
498
- handler: (_3) => __awaiter(this, [_3], void 0, function* ({ body, adminUser }) {
499
- var _4;
485
+ handler: async ({ body, adminUser }) => {
486
+ var _a;
500
487
  const resource = this.adminforth.config.resources.find((res) => res.resourceId == body['resourceId']);
501
488
  if (!resource) {
502
489
  return { error: `Resource '${body['resourceId']}' not found` };
503
490
  }
504
- const { allowedActions } = yield interpretResource(adminUser, resource, { requestBody: body }, ActionCheckSource.CreateRequest);
491
+ const { allowedActions } = await interpretResource(adminUser, resource, { requestBody: body }, ActionCheckSource.CreateRequest);
505
492
  const { allowed, error } = checkAccess(AllowedActionsEnum.create, allowedActions);
506
493
  if (!allowed) {
507
494
  return { error };
508
495
  }
509
496
  const { record } = body;
510
497
  for (const column of resource.columns) {
511
- if (((_4 = column.required) === null || _4 === void 0 ? void 0 : _4.create) &&
498
+ if (((_a = column.required) === null || _a === void 0 ? void 0 : _a.create) &&
512
499
  record[column.name] === undefined &&
513
500
  column.showIn.includes(AdminForthResourcePages.create)) {
514
501
  return { error: `Column '${column.name}' is required`, ok: false };
515
502
  }
516
503
  }
517
- const response = yield this.adminforth.createResourceRecord({ resource, record, adminUser });
504
+ const response = await this.adminforth.createResourceRecord({ resource, record, adminUser });
518
505
  if (response.error) {
519
506
  return { error: response.error, ok: false };
520
507
  }
@@ -523,44 +510,44 @@ export default class AdminForthRestAPI {
523
510
  newRecordId: response.createdRecord[connector.getPrimaryKey(resource)],
524
511
  ok: true
525
512
  };
526
- })
513
+ }
527
514
  });
528
515
  server.endpoint({
529
516
  method: 'POST',
530
517
  path: '/update_record',
531
- handler: (_5) => __awaiter(this, [_5], void 0, function* ({ body, adminUser }) {
518
+ handler: async ({ body, adminUser }) => {
532
519
  const resource = this.adminforth.config.resources.find((res) => res.resourceId == body['resourceId']);
533
520
  if (!resource) {
534
521
  return { error: `Resource '${body['resourceId']}' not found` };
535
522
  }
536
523
  const recordId = body['recordId'];
537
524
  const connector = this.adminforth.connectors[resource.dataSource];
538
- const oldRecord = yield connector.getRecordByPrimaryKey(resource, recordId);
525
+ const oldRecord = await connector.getRecordByPrimaryKey(resource, recordId);
539
526
  if (!oldRecord) {
540
527
  const primaryKeyColumn = resource.columns.find((col) => col.primaryKey);
541
528
  return { error: `Record with ${primaryKeyColumn.name} ${recordId} not found` };
542
529
  }
543
530
  const record = body['record'];
544
- const { allowedActions } = yield interpretResource(adminUser, resource, { requestBody: body, newRecord: record, oldRecord }, ActionCheckSource.EditRequest);
531
+ const { allowedActions } = await interpretResource(adminUser, resource, { requestBody: body, newRecord: record, oldRecord }, ActionCheckSource.EditRequest);
545
532
  const { allowed, error: allowedError } = checkAccess(AllowedActionsEnum.edit, allowedActions);
546
533
  if (!allowed) {
547
534
  return { allowedError };
548
535
  }
549
- const { error } = yield this.adminforth.updateResourceRecord({ resource, record, adminUser, oldRecord, recordId });
536
+ const { error } = await this.adminforth.updateResourceRecord({ resource, record, adminUser, oldRecord, recordId });
550
537
  if (error) {
551
538
  return { error };
552
539
  }
553
540
  return {
554
541
  ok: true
555
542
  };
556
- })
543
+ }
557
544
  });
558
545
  server.endpoint({
559
546
  method: 'POST',
560
547
  path: '/delete_record',
561
- handler: (_6) => __awaiter(this, [_6], void 0, function* ({ body, adminUser }) {
548
+ handler: async ({ body, adminUser }) => {
562
549
  const resource = this.adminforth.config.resources.find((res) => res.resourceId == body['resourceId']);
563
- const record = yield this.adminforth.connectors[resource.dataSource].getRecordByPrimaryKey(resource, body['primaryKey']);
550
+ const record = await this.adminforth.connectors[resource.dataSource].getRecordByPrimaryKey(resource, body['primaryKey']);
564
551
  if (!resource) {
565
552
  return { error: `Resource '${body['resourceId']}' not found` };
566
553
  }
@@ -570,12 +557,12 @@ export default class AdminForthRestAPI {
570
557
  if (resource.options.allowedActions.delete === false) {
571
558
  return { error: `Resource '${resource.resourceId}' does not allow delete action` };
572
559
  }
573
- const { allowedActions } = yield interpretResource(adminUser, resource, { requestBody: body }, ActionCheckSource.DeleteRequest);
560
+ const { allowedActions } = await interpretResource(adminUser, resource, { requestBody: body }, ActionCheckSource.DeleteRequest);
574
561
  const { allowed, error } = checkAccess(AllowedActionsEnum.delete, allowedActions);
575
562
  if (!allowed) {
576
563
  return { error };
577
564
  }
578
- const { error: deleteError } = yield this.adminforth.deleteResourceRecord({ resource, record, adminUser, recordId: body['primaryKey'] });
565
+ const { error: deleteError } = await this.adminforth.deleteResourceRecord({ resource, record, adminUser, recordId: body['primaryKey'] });
579
566
  if (deleteError) {
580
567
  return { error: deleteError };
581
568
  }
@@ -583,33 +570,33 @@ export default class AdminForthRestAPI {
583
570
  ok: true,
584
571
  recordId: body['primaryKey']
585
572
  };
586
- })
573
+ }
587
574
  });
588
575
  server.endpoint({
589
576
  method: 'POST',
590
577
  path: '/start_bulk_action',
591
- handler: (_7) => __awaiter(this, [_7], void 0, function* ({ body, adminUser }) {
578
+ handler: async ({ body, adminUser }) => {
592
579
  const { resourceId, actionId, recordIds } = body;
593
580
  const resource = this.adminforth.config.resources.find((res) => res.resourceId == resourceId);
594
581
  if (!resource) {
595
582
  return { error: `Resource '${resourceId}' not found` };
596
583
  }
597
- const { allowedActions } = yield interpretResource(adminUser, resource, { requestBody: body }, ActionCheckSource.BulkActionRequest);
584
+ const { allowedActions } = await interpretResource(adminUser, resource, { requestBody: body }, ActionCheckSource.BulkActionRequest);
598
585
  const action = resource.options.bulkActions.find((act) => act.id == actionId);
599
586
  if (!action) {
600
587
  return { error: `Action '${actionId}' not found` };
601
588
  }
602
589
  if (action.allowed) {
603
- const execAllowed = yield action.allowed({ adminUser, resource, selectedIds: recordIds, allowedActions });
590
+ const execAllowed = await action.allowed({ adminUser, resource, selectedIds: recordIds, allowedActions });
604
591
  if (!execAllowed) {
605
592
  return { error: `Action '${actionId}' is not allowed` };
606
593
  }
607
594
  }
608
- const response = yield action.action({ selectedIds: recordIds, adminUser, resource });
595
+ const response = await action.action({ selectedIds: recordIds, adminUser, resource });
609
596
  return Object.assign({ actionId,
610
597
  recordIds,
611
598
  resourceId }, response);
612
- })
599
+ }
613
600
  });
614
601
  // setup endpoints for all plugins
615
602
  this.adminforth.activatedPlugins.forEach((plugin) => {