@balena/pinejs 19.7.2-build-renovate-postgres-17-x-38c77839796930404f59a924e2e4573ffdc6405d-1 → 19.7.2-build-esm-ce2a147ed7533c40f456b27f17ac4e559a0f9da8-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/.versionbot/CHANGELOG.yml +5 -6
  2. package/CHANGELOG.md +1 -1
  3. package/{Gruntfile.ts → Gruntfile.cts} +9 -22
  4. package/bin/abstract-sql-compiler.js +1 -1
  5. package/bin/odata-compiler.js +1 -1
  6. package/bin/sbvr-compiler.js +1 -1
  7. package/build/{browser.ts → browser.cts} +1 -1
  8. package/build/{config.ts → config.cts} +5 -1
  9. package/build/{module.ts → module.cts} +1 -1
  10. package/build/{server.ts → server.cts} +1 -1
  11. package/docker-compose.npm-test.yml +1 -1
  12. package/out/bin/abstract-sql-compiler.js +17 -19
  13. package/out/bin/abstract-sql-compiler.js.map +1 -1
  14. package/out/bin/odata-compiler.js +19 -21
  15. package/out/bin/odata-compiler.js.map +1 -1
  16. package/out/bin/sbvr-compiler.js +19 -54
  17. package/out/bin/sbvr-compiler.js.map +1 -1
  18. package/out/bin/utils.d.ts +3 -3
  19. package/out/bin/utils.js +16 -53
  20. package/out/bin/utils.js.map +1 -1
  21. package/out/config-loader/config-loader.d.ts +6 -6
  22. package/out/config-loader/config-loader.js +23 -63
  23. package/out/config-loader/config-loader.js.map +1 -1
  24. package/out/config-loader/env.d.ts +1 -1
  25. package/out/config-loader/env.js +24 -66
  26. package/out/config-loader/env.js.map +1 -1
  27. package/out/data-server/sbvr-server.d.ts +3 -3
  28. package/out/data-server/sbvr-server.js +5 -42
  29. package/out/data-server/sbvr-server.js.map +1 -1
  30. package/out/database-layer/db.d.ts +3 -3
  31. package/out/database-layer/db.js +37 -83
  32. package/out/database-layer/db.js.map +1 -1
  33. package/out/express-emulator/express.js.map +1 -1
  34. package/out/extended-sbvr-parser/extended-sbvr-parser.js +8 -11
  35. package/out/extended-sbvr-parser/extended-sbvr-parser.js.map +1 -1
  36. package/out/http-transactions/transactions.d.ts +2 -2
  37. package/out/http-transactions/transactions.js +4 -4
  38. package/out/http-transactions/transactions.js.map +1 -1
  39. package/out/migrator/async.d.ts +2 -2
  40. package/out/migrator/async.js +20 -60
  41. package/out/migrator/async.js.map +1 -1
  42. package/out/migrator/migrations.js +1 -2
  43. package/out/migrator/sync.d.ts +6 -6
  44. package/out/migrator/sync.js +20 -61
  45. package/out/migrator/sync.js.map +1 -1
  46. package/out/migrator/utils.d.ts +4 -4
  47. package/out/migrator/utils.js +42 -97
  48. package/out/migrator/utils.js.map +1 -1
  49. package/out/odata-metadata/odata-metadata-generator.js +7 -14
  50. package/out/odata-metadata/odata-metadata-generator.js.map +1 -1
  51. package/out/passport-pinejs/mount-login-router.d.ts +1 -1
  52. package/out/passport-pinejs/mount-login-router.js +4 -41
  53. package/out/passport-pinejs/mount-login-router.js.map +1 -1
  54. package/out/passport-pinejs/passport-pinejs.d.ts +1 -1
  55. package/out/passport-pinejs/passport-pinejs.js +11 -46
  56. package/out/passport-pinejs/passport-pinejs.js.map +1 -1
  57. package/out/pinejs-session-store/pinejs-session-store.d.ts +1 -1
  58. package/out/pinejs-session-store/pinejs-session-store.js +11 -48
  59. package/out/pinejs-session-store/pinejs-session-store.js.map +1 -1
  60. package/out/sbvr-api/abstract-sql.d.ts +2 -2
  61. package/out/sbvr-api/abstract-sql.js +22 -65
  62. package/out/sbvr-api/abstract-sql.js.map +1 -1
  63. package/out/sbvr-api/cached-compile.js +8 -15
  64. package/out/sbvr-api/cached-compile.js.map +1 -1
  65. package/out/sbvr-api/common-types.js +1 -2
  66. package/out/sbvr-api/control-flow.d.ts +1 -1
  67. package/out/sbvr-api/control-flow.js +12 -25
  68. package/out/sbvr-api/control-flow.js.map +1 -1
  69. package/out/sbvr-api/dev.js +1 -2
  70. package/out/sbvr-api/errors.d.ts +1 -1
  71. package/out/sbvr-api/errors.js +47 -95
  72. package/out/sbvr-api/errors.js.map +1 -1
  73. package/out/sbvr-api/express-extension.d.ts +2 -2
  74. package/out/sbvr-api/express-extension.js +1 -2
  75. package/out/sbvr-api/hooks.d.ts +4 -4
  76. package/out/sbvr-api/hooks.js +23 -35
  77. package/out/sbvr-api/hooks.js.map +1 -1
  78. package/out/sbvr-api/odata-response.d.ts +2 -2
  79. package/out/sbvr-api/odata-response.js +19 -29
  80. package/out/sbvr-api/odata-response.js.map +1 -1
  81. package/out/sbvr-api/permissions.d.ts +8 -8
  82. package/out/sbvr-api/permissions.js +106 -159
  83. package/out/sbvr-api/permissions.js.map +1 -1
  84. package/out/sbvr-api/sbvr-utils.d.ts +38 -16
  85. package/out/sbvr-api/sbvr-utils.js +222 -285
  86. package/out/sbvr-api/sbvr-utils.js.map +1 -1
  87. package/out/sbvr-api/translations.d.ts +1 -1
  88. package/out/sbvr-api/translations.js +10 -17
  89. package/out/sbvr-api/translations.js.map +1 -1
  90. package/out/sbvr-api/uri-parser.d.ts +6 -6
  91. package/out/sbvr-api/uri-parser.js +39 -84
  92. package/out/sbvr-api/uri-parser.js.map +1 -1
  93. package/out/sbvr-api/user.js +1 -2
  94. package/out/server-glue/global-ext.d.ts +0 -3
  95. package/out/server-glue/module.d.ts +15 -15
  96. package/out/server-glue/module.js +20 -59
  97. package/out/server-glue/module.js.map +1 -1
  98. package/out/server-glue/sbvr-loader.d.ts +2 -1
  99. package/out/server-glue/sbvr-loader.js +4 -11
  100. package/out/server-glue/sbvr-loader.js.map +1 -1
  101. package/out/server-glue/server.d.ts +2 -2
  102. package/out/server-glue/server.js +17 -59
  103. package/out/server-glue/server.js.map +1 -1
  104. package/out/tasks/common.d.ts +1 -1
  105. package/out/tasks/common.js +3 -9
  106. package/out/tasks/common.js.map +1 -1
  107. package/out/tasks/index.d.ts +8 -8
  108. package/out/tasks/index.js +25 -63
  109. package/out/tasks/index.js.map +1 -1
  110. package/out/tasks/tasks.js +1 -2
  111. package/out/tasks/worker.d.ts +3 -3
  112. package/out/tasks/worker.js +14 -51
  113. package/out/tasks/worker.js.map +1 -1
  114. package/out/webresource-handler/handlers/NoopHandler.d.ts +1 -1
  115. package/out/webresource-handler/handlers/NoopHandler.js +1 -5
  116. package/out/webresource-handler/handlers/NoopHandler.js.map +1 -1
  117. package/out/webresource-handler/handlers/S3Handler.d.ts +1 -1
  118. package/out/webresource-handler/handlers/S3Handler.js +17 -24
  119. package/out/webresource-handler/handlers/S3Handler.js.map +1 -1
  120. package/out/webresource-handler/handlers/index.d.ts +2 -2
  121. package/out/webresource-handler/handlers/index.js +2 -18
  122. package/out/webresource-handler/handlers/index.js.map +1 -1
  123. package/out/webresource-handler/index.d.ts +1 -1
  124. package/out/webresource-handler/index.js +35 -85
  125. package/out/webresource-handler/index.js.map +1 -1
  126. package/package.json +10 -10
  127. package/src/bin/abstract-sql-compiler.ts +3 -3
  128. package/src/bin/odata-compiler.ts +3 -3
  129. package/src/bin/sbvr-compiler.ts +2 -2
  130. package/src/bin/utils.ts +20 -15
  131. package/src/config-loader/config-loader.ts +11 -11
  132. package/src/config-loader/env.ts +3 -3
  133. package/src/data-server/sbvr-server.ts +4 -4
  134. package/src/database-layer/db.ts +18 -11
  135. package/src/extended-sbvr-parser/extended-sbvr-parser.ts +5 -5
  136. package/src/http-transactions/transactions.js +4 -4
  137. package/src/migrator/async.ts +5 -5
  138. package/src/migrator/sync.ts +8 -8
  139. package/src/migrator/utils.ts +7 -7
  140. package/src/odata-metadata/odata-metadata-generator.ts +3 -2
  141. package/src/passport-pinejs/mount-login-router.ts +3 -3
  142. package/src/passport-pinejs/passport-pinejs.ts +3 -3
  143. package/src/pinejs-session-store/pinejs-session-store.ts +4 -4
  144. package/src/sbvr-api/abstract-sql.ts +5 -5
  145. package/src/sbvr-api/cached-compile.ts +1 -1
  146. package/src/sbvr-api/control-flow.ts +1 -1
  147. package/src/sbvr-api/errors.ts +1 -1
  148. package/src/sbvr-api/express-extension.ts +2 -2
  149. package/src/sbvr-api/hooks.ts +5 -5
  150. package/src/sbvr-api/odata-response.ts +8 -4
  151. package/src/sbvr-api/permissions.ts +17 -17
  152. package/src/sbvr-api/sbvr-utils.ts +37 -31
  153. package/src/sbvr-api/translations.ts +1 -1
  154. package/src/sbvr-api/uri-parser.ts +9 -9
  155. package/src/server-glue/global-ext.d.ts +0 -3
  156. package/src/server-glue/module.ts +19 -19
  157. package/src/server-glue/sbvr-loader.ts +15 -27
  158. package/src/server-glue/server.ts +13 -24
  159. package/src/tasks/common.ts +1 -1
  160. package/src/tasks/index.ts +14 -14
  161. package/src/tasks/worker.ts +8 -8
  162. package/src/webresource-handler/handlers/NoopHandler.ts +5 -1
  163. package/src/webresource-handler/handlers/S3Handler.ts +1 -1
  164. package/src/webresource-handler/handlers/index.ts +2 -2
  165. package/src/webresource-handler/index.ts +8 -8
  166. package/tsconfig.dev.json +4 -2
  167. package/tsconfig.json +1 -1
  168. package/typings/lf-to-abstract-sql.d.ts +2 -2
  169. package/typings/memoizee.d.ts +1 -1
@@ -1,70 +1,28 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.config = exports.addPermissions = exports.checkPermissionsMiddleware = exports.checkPermissions = exports.apiKeyMiddleware = exports.customApiKeyMiddleware = exports.resolveApiKey = exports.authorizationMiddleware = exports.customAuthorizationMiddleware = exports.canAccess = exports.resolveAuthHeader = exports.checkApiKey = exports.getApiKeyPermissions = exports.getUserPermissions = exports.checkPassword = exports.rootRead = exports.root = exports.PermissionParsingError = exports.PermissionError = void 0;
40
- exports.nestedCheck = nestedCheck;
41
- exports.setup = setup;
42
- require("./express-extension");
43
- const odata_to_abstract_sql_1 = require("@balena/odata-to-abstract-sql");
44
- const ODataParser = __importStar(require("@balena/odata-parser"));
45
- const lodash_1 = __importDefault(require("lodash"));
46
- const memoizee_1 = __importDefault(require("memoizee"));
47
- const randomstring = __importStar(require("randomstring"));
48
- const env = __importStar(require("../config-loader/env"));
49
- const sbvrUtils = __importStar(require("../sbvr-api/sbvr-utils"));
50
- const hooks_1 = require("./hooks");
51
- const errors_1 = require("./errors");
52
- Object.defineProperty(exports, "PermissionError", { enumerable: true, get: function () { return errors_1.PermissionError; } });
53
- Object.defineProperty(exports, "PermissionParsingError", { enumerable: true, get: function () { return errors_1.PermissionParsingError; } });
54
- const uri_parser_1 = require("./uri-parser");
55
- const weak_1 = __importDefault(require("memoizee/weak"));
56
- const sbvr_loader_1 = require("../server-glue/sbvr-loader");
57
- const userModel = (0, sbvr_loader_1.requireSBVR)('./user.sbvr', require);
1
+ import './express-extension.js';
2
+ import { isBindReference, odataNameToSqlName, sqlNameToODataName, } from '@balena/odata-to-abstract-sql';
3
+ import * as ODataParser from '@balena/odata-parser';
4
+ import _ from 'lodash';
5
+ import memoize from 'memoizee';
6
+ import randomstring from 'randomstring';
7
+ import * as env from '../config-loader/env.js';
8
+ import * as sbvrUtils from '../sbvr-api/sbvr-utils.js';
9
+ import { addPureHook, addHook } from './hooks.js';
10
+ import { BadRequestError, PermissionError, PermissionParsingError, } from './errors.js';
11
+ import { memoizedGetOData2AbstractSQL, memoizedParseOdata, metadataEndpoints, } from './uri-parser.js';
12
+ import memoizeWeak from 'memoizee/weak.js';
13
+ import { importSBVR } from '../server-glue/sbvr-loader.js';
14
+ const userModel = await importSBVR('./user.sbvr', import.meta);
58
15
  const DEFAULT_ACTOR_BIND = '@__ACTOR_ID';
59
- const DEFAULT_ACTOR_BIND_REGEX = new RegExp(lodash_1.default.escapeRegExp(DEFAULT_ACTOR_BIND), 'g');
60
- exports.root = {
16
+ const DEFAULT_ACTOR_BIND_REGEX = new RegExp(_.escapeRegExp(DEFAULT_ACTOR_BIND), 'g');
17
+ export { PermissionError, PermissionParsingError };
18
+ export const root = {
61
19
  user: {
62
20
  id: 0,
63
21
  actor: 0,
64
22
  permissions: ['resource.all'],
65
23
  },
66
24
  };
67
- exports.rootRead = {
25
+ export const rootRead = {
68
26
  user: {
69
27
  id: 0,
70
28
  actor: 0,
@@ -99,7 +57,7 @@ const $parsePermissions = env.createCache('parsePermissions', (filter) => {
99
57
  const rewriteODataBinds = ({ tree, extraBinds }, odataBinds) => {
100
58
  const bindsLength = odataBinds.length;
101
59
  odataBinds.push(...extraBinds);
102
- return lodash_1.default.cloneDeepWith(tree, (value) => {
60
+ return _.cloneDeepWith(tree, (value) => {
103
61
  if (value != null) {
104
62
  const bind = value.bind;
105
63
  if (Number.isInteger(bind)) {
@@ -114,7 +72,7 @@ const parsePermissions = (filter, odataBinds) => {
114
72
  };
115
73
  const isAnd = (x) => typeof x === 'object' && 'and' in x;
116
74
  const isOr = (x) => typeof x === 'object' && 'or' in x;
117
- function nestedCheck(check, stringCallback) {
75
+ export function nestedCheck(check, stringCallback) {
118
76
  if (typeof check === 'string') {
119
77
  return stringCallback(check);
120
78
  }
@@ -142,7 +100,7 @@ function nestedCheck(check, stringCallback) {
142
100
  }
143
101
  if (results.length > 1) {
144
102
  return {
145
- and: lodash_1.default.uniq(results),
103
+ and: _.uniq(results),
146
104
  };
147
105
  }
148
106
  return true;
@@ -180,7 +138,7 @@ function nestedCheck(check, stringCallback) {
180
138
  }
181
139
  if (results.length > 1) {
182
140
  return {
183
- or: lodash_1.default.uniq(results),
141
+ or: _.uniq(results),
184
142
  };
185
143
  }
186
144
  return false;
@@ -210,13 +168,13 @@ const collapsePermissionFilters = (v) => {
210
168
  return v;
211
169
  };
212
170
  const namespaceRelationships = (relationships, alias) => {
213
- lodash_1.default.forEach(relationships, (relationship, key) => {
171
+ _.forEach(relationships, (relationship, key) => {
214
172
  if (key === '$') {
215
173
  return;
216
174
  }
217
175
  let mapping = relationship.$;
218
176
  if (mapping != null && mapping.length === 2) {
219
- mapping = lodash_1.default.cloneDeep(mapping);
177
+ mapping = _.cloneDeep(mapping);
220
178
  mapping[1][0] = `${mapping[1][0]}$${alias}`;
221
179
  relationships[`${key}$${alias}`] = {
222
180
  $: mapping,
@@ -243,7 +201,7 @@ const getPermissionsLookup = env.createCache('permissionsLookup', (permissions,
243
201
  for (const target of Object.keys(permissionsLookup)) {
244
202
  const conditions = permissionsLookup[target];
245
203
  if (conditions !== true) {
246
- permissionsLookup[target] = lodash_1.default.uniq(conditions);
204
+ permissionsLookup[target] = _.uniq(conditions);
247
205
  }
248
206
  }
249
207
  return permissionsLookup;
@@ -275,7 +233,7 @@ const $checkPermissions = (permissionsLookup, actionList, vocabulary, resourceNa
275
233
  vocabularyResourcePermission = maybeVocabularyResourcePermission;
276
234
  }
277
235
  }
278
- const conditionalPermissions = lodash_1.default.union(resourcePermission, vocabularyPermission, vocabularyResourcePermission);
236
+ const conditionalPermissions = _.union(resourcePermission, vocabularyPermission, vocabularyResourcePermission);
279
237
  if (conditionalPermissions.length === 1) {
280
238
  return conditionalPermissions[0];
281
239
  }
@@ -314,7 +272,7 @@ const rewriteSubPermissionBindings = (filter, counter) => {
314
272
  object.bind = counter + object.bind;
315
273
  }
316
274
  if (Array.isArray(object) || typeof object === 'object') {
317
- lodash_1.default.forEach(object, (v) => {
275
+ _.forEach(object, (v) => {
318
276
  rewrite(v);
319
277
  });
320
278
  }
@@ -337,28 +295,28 @@ const buildODataPermission = (permissionsLookup, actionList, vocabulary, resourc
337
295
  }
338
296
  catch (e) {
339
297
  console.warn('Failed to parse conditional permissions: ', permissionCheck);
340
- throw new errors_1.PermissionParsingError(e);
298
+ throw new PermissionParsingError(e);
341
299
  }
342
300
  });
343
301
  const collapsedPermissionFilters = collapsePermissionFilters(permissionFilters);
344
302
  return collapsedPermissionFilters;
345
303
  };
346
- const constrainedPermissionError = new errors_1.PermissionError();
304
+ const constrainedPermissionError = new PermissionError();
347
305
  const generateConstrainedAbstractSql = (permissionsLookup, actionList, vocabulary, resourceName) => {
348
306
  const abstractSQLModel = sbvrUtils.getAbstractSqlModel({
349
307
  vocabulary,
350
308
  });
351
- const odata = (0, uri_parser_1.memoizedParseOdata)(`/${resourceName}`);
309
+ const odata = memoizedParseOdata(`/${resourceName}`);
352
310
  const collapsedPermissionFilters = buildODataPermission(permissionsLookup, actionList, vocabulary, resourceName, odata);
353
311
  if (collapsePermissionFilters == null) {
354
312
  return;
355
313
  }
356
- lodash_1.default.set(odata, ['tree', 'options', '$filter'], collapsedPermissionFilters);
314
+ _.set(odata, ['tree', 'options', '$filter'], collapsedPermissionFilters);
357
315
  const lambdaAlias = randomstring.generate(20);
358
316
  let inc = 0;
359
317
  const canAccessTrace = [resourceName];
360
318
  const resolveBind = (maybeBind, extraBinds) => {
361
- if ((0, odata_to_abstract_sql_1.isBindReference)(maybeBind)) {
319
+ if (isBindReference(maybeBind)) {
362
320
  const { bind } = maybeBind;
363
321
  if (typeof bind === 'string' || bind < odata.binds.length) {
364
322
  return odata.binds[bind];
@@ -375,7 +333,7 @@ const generateConstrainedAbstractSql = (permissionsLookup, actionList, vocabular
375
333
  const targetResource = this.NavigateResources(this.defaultResource, resolvedProperty.name);
376
334
  const lambdaId = `${lambdaAlias}+${inc}`;
377
335
  inc = inc + 1;
378
- const targetResourceName = (0, odata_to_abstract_sql_1.sqlNameToODataName)(targetResource.resource.name);
336
+ const targetResourceName = sqlNameToODataName(targetResource.resource.name);
379
337
  const traceIndex = canAccessTrace.findIndex((rName) => rName === targetResourceName);
380
338
  if (traceIndex !== -1) {
381
339
  if (canAccessTrace[canAccessTrace.length - 1] !== targetResourceName) {
@@ -400,7 +358,7 @@ const generateConstrainedAbstractSql = (permissionsLookup, actionList, vocabular
400
358
  return this.Property(resolvedProperty);
401
359
  }
402
360
  }
403
- const parentOdata = (0, uri_parser_1.memoizedParseOdata)(`/${targetResourceName}`);
361
+ const parentOdata = memoizedParseOdata(`/${targetResourceName}`);
404
362
  const collapsedParentPermissionFilters = buildODataPermission(permissionsLookup, actionList, vocabulary, targetResourceName, parentOdata);
405
363
  if (collapsedParentPermissionFilters == null) {
406
364
  return ['Equals', ['Boolean', true], ['Boolean', true]];
@@ -421,7 +379,7 @@ const generateConstrainedAbstractSql = (permissionsLookup, actionList, vocabular
421
379
  canAccessTrace.pop();
422
380
  }
423
381
  };
424
- const { tree, extraBindVars } = (0, uri_parser_1.memoizedGetOData2AbstractSQL)(abstractSQLModel).match(odata.tree, 'GET', [], odata.binds.length, {
382
+ const { tree, extraBindVars } = memoizedGetOData2AbstractSQL(abstractSQLModel).match(odata.tree, 'GET', [], odata.binds.length, {
425
383
  canAccess: canAccessFunction,
426
384
  });
427
385
  odata.binds.push(...extraBindVars);
@@ -430,7 +388,7 @@ const generateConstrainedAbstractSql = (permissionsLookup, actionList, vocabular
430
388
  const select = abstractSqlQuery.find((v) => v[0] === 'Select');
431
389
  select[1] = select[1].map((selectField) => {
432
390
  if (selectField[0] === 'Alias') {
433
- const sqlName = (0, odata_to_abstract_sql_1.odataNameToSqlName)(selectField[2]);
391
+ const sqlName = odataNameToSqlName(selectField[2]);
434
392
  const maybeField = selectField[1];
435
393
  if ((maybeField[0] === 'ReferencedField' && maybeField[2] === sqlName) ||
436
394
  (maybeField[0] === 'Field' && maybeField[1] === sqlName)) {
@@ -478,7 +436,7 @@ const deepFreezeExceptDefinition = (obj) => {
478
436
  }
479
437
  }
480
438
  };
481
- const createBypassDefinition = (definition) => lodash_1.default.cloneDeepWith(definition, (abstractSql) => {
439
+ const createBypassDefinition = (definition) => _.cloneDeepWith(definition, (abstractSql) => {
482
440
  if (Array.isArray(abstractSql) &&
483
441
  abstractSql[0] === 'Resource' &&
484
442
  !abstractSql[1].endsWith('$bypass')) {
@@ -487,13 +445,13 @@ const createBypassDefinition = (definition) => lodash_1.default.cloneDeepWith(de
487
445
  });
488
446
  const createVersionSpecificPermissionDefinition = ({ abstractSql, ...restDefinition }, permissionsJSON) => {
489
447
  return {
490
- ...lodash_1.default.cloneDeep(restDefinition),
491
- abstractSql: lodash_1.default.cloneDeepWith(abstractSql, (abstractSqlNode) => {
448
+ ..._.cloneDeep(restDefinition),
449
+ abstractSql: _.cloneDeepWith(abstractSql, (abstractSqlNode) => {
492
450
  if (!Array.isArray(abstractSqlNode)) {
493
451
  return;
494
452
  }
495
453
  if (abstractSqlNode[0] === 'Select' || abstractSqlNode[0] === 'Where') {
496
- return lodash_1.default.cloneDeep(abstractSqlNode);
454
+ return _.cloneDeep(abstractSqlNode);
497
455
  }
498
456
  if (abstractSqlNode[0] === 'Resource' &&
499
457
  typeof abstractSqlNode[1] === 'string' &&
@@ -515,10 +473,10 @@ const getAlias = (name) => {
515
473
  }
516
474
  return `permissions${permissionsJSON}`;
517
475
  };
518
- const rewriteRelationship = (0, weak_1.default)((value, name, abstractSqlModel, permissionsLookup, vocabulary, odata2AbstractSQL) => {
519
- let escapedName = (0, odata_to_abstract_sql_1.sqlNameToODataName)(name);
476
+ const rewriteRelationship = memoizeWeak((value, name, abstractSqlModel, permissionsLookup, vocabulary, odata2AbstractSQL) => {
477
+ let escapedName = sqlNameToODataName(name);
520
478
  if (abstractSqlModel.tables[name]) {
521
- escapedName = (0, odata_to_abstract_sql_1.sqlNameToODataName)(abstractSqlModel.tables[name].name);
479
+ escapedName = sqlNameToODataName(abstractSqlModel.tables[name].name);
522
480
  }
523
481
  const rewrite = (object) => {
524
482
  if ('$' in object && Array.isArray(object.$)) {
@@ -531,27 +489,27 @@ const rewriteRelationship = (0, weak_1.default)((value, name, abstractSqlModel,
531
489
  if (possibleTargetResourceName.endsWith('$bypass')) {
532
490
  return;
533
491
  }
534
- const targetResourceEscaped = (0, odata_to_abstract_sql_1.sqlNameToODataName)(abstractSqlModel.tables[possibleTargetResourceName]?.name ??
492
+ const targetResourceEscaped = sqlNameToODataName(abstractSqlModel.tables[possibleTargetResourceName]?.name ??
535
493
  possibleTargetResourceName);
536
494
  if (targetResourceEscaped.includes('$')) {
537
495
  return;
538
496
  }
539
497
  let foundCanAccessLink = false;
540
498
  try {
541
- const odata = (0, uri_parser_1.memoizedParseOdata)(`/${targetResourceEscaped}`);
499
+ const odata = memoizedParseOdata(`/${targetResourceEscaped}`);
542
500
  const collapsedPermissionFilters = buildODataPermission(permissionsLookup, methodPermissions.GET, vocabulary, targetResourceEscaped, odata);
543
501
  if (collapsedPermissionFilters == null) {
544
502
  return;
545
503
  }
546
- lodash_1.default.set(odata, ['tree', 'options', '$filter'], collapsedPermissionFilters);
504
+ _.set(odata, ['tree', 'options', '$filter'], collapsedPermissionFilters);
547
505
  const canAccessFunction = function (property) {
548
506
  delete property.method;
549
507
  if (!this.defaultResource) {
550
508
  throw new Error(`No resource selected in AST.`);
551
509
  }
552
510
  const targetResourceAST = this.NavigateResources(this.defaultResource, property.name);
553
- const targetResourceName = (0, odata_to_abstract_sql_1.sqlNameToODataName)(targetResourceAST.resource.name);
554
- const currentResourceName = (0, odata_to_abstract_sql_1.sqlNameToODataName)(this.defaultResource.name);
511
+ const targetResourceName = sqlNameToODataName(targetResourceAST.resource.name);
512
+ const currentResourceName = sqlNameToODataName(this.defaultResource.name);
555
513
  if (currentResourceName === targetResourceEscaped &&
556
514
  targetResourceName === escapedName) {
557
515
  foundCanAccessLink = true;
@@ -582,7 +540,7 @@ const rewriteRelationship = (0, weak_1.default)((value, name, abstractSqlModel,
582
540
  }
583
541
  }
584
542
  if (Array.isArray(object) || typeof object === 'object') {
585
- lodash_1.default.forEach(object, (v) => {
543
+ _.forEach(object, (v) => {
586
544
  if (typeof v !== 'string') {
587
545
  rewrite(v);
588
546
  }
@@ -595,15 +553,15 @@ const rewriteRelationships = (abstractSqlModel, relationships, permissionsLookup
595
553
  const originalAbstractSQLModel = sbvrUtils.getAbstractSqlModel({
596
554
  vocabulary,
597
555
  });
598
- const odata2AbstractSQL = (0, uri_parser_1.memoizedGetOData2AbstractSQL)(originalAbstractSQLModel);
599
- const newRelationships = lodash_1.default.cloneDeep(relationships);
600
- lodash_1.default.forOwn(newRelationships, (value, name) => {
556
+ const odata2AbstractSQL = memoizedGetOData2AbstractSQL(originalAbstractSQLModel);
557
+ const newRelationships = _.cloneDeep(relationships);
558
+ _.forOwn(newRelationships, (value, name) => {
601
559
  rewriteRelationship(value, name, abstractSqlModel, permissionsLookup, vocabulary, odata2AbstractSQL);
602
560
  });
603
561
  return newRelationships;
604
562
  };
605
- const getBoundConstrainedMemoizer = (0, weak_1.default)((abstractSqlModel) => (0, weak_1.default)((permissionsLookup, vocabulary) => {
606
- const constrainedAbstractSqlModel = lodash_1.default.cloneDeep(abstractSqlModel);
563
+ const getBoundConstrainedMemoizer = memoizeWeak((abstractSqlModel) => memoizeWeak((permissionsLookup, vocabulary) => {
564
+ const constrainedAbstractSqlModel = _.cloneDeep(abstractSqlModel);
607
565
  const origSynonyms = Object.entries(constrainedAbstractSqlModel.synonyms);
608
566
  constrainedAbstractSqlModel.synonyms = new Proxy(constrainedAbstractSqlModel.synonyms, {
609
567
  get(synonyms, permissionSynonym, receiver) {
@@ -624,7 +582,7 @@ const getBoundConstrainedMemoizer = (0, weak_1.default)((abstractSqlModel) => (0
624
582
  },
625
583
  });
626
584
  const origRelationships = Object.keys(constrainedAbstractSqlModel.relationships);
627
- lodash_1.default.forEach(constrainedAbstractSqlModel.tables, (table, resourceName) => {
585
+ _.forEach(constrainedAbstractSqlModel.tables, (table, resourceName) => {
628
586
  const bypassResourceName = `${resourceName}$bypass`;
629
587
  constrainedAbstractSqlModel.tables[bypassResourceName] = {
630
588
  ...table,
@@ -635,7 +593,7 @@ const getBoundConstrainedMemoizer = (0, weak_1.default)((abstractSqlModel) => (0
635
593
  constrainedAbstractSqlModel.tables[bypassResourceName].definition =
636
594
  createBypassDefinition(table.definition);
637
595
  const tableDefinition = table.definition;
638
- for (const stringifiedPermission of lodash_1.default.uniq(Object.values(stringifiedMethodPermissions))) {
596
+ for (const stringifiedPermission of _.uniq(Object.values(stringifiedMethodPermissions))) {
639
597
  if (stringifiedPermission === stringifiedMethodPermissions.GET) {
640
598
  continue;
641
599
  }
@@ -672,7 +630,7 @@ const getBoundConstrainedMemoizer = (0, weak_1.default)((abstractSqlModel) => (0
672
630
  ...table,
673
631
  });
674
632
  permissionsTable.resourceName = permissionResourceName;
675
- onceGetter(permissionsTable, 'definition', () => generateConstrainedAbstractSql(permissionsLookup, permissions, vocabulary, (0, odata_to_abstract_sql_1.sqlNameToODataName)(permissionsTable.modifyName ?? permissionsTable.name)));
633
+ onceGetter(permissionsTable, 'definition', () => generateConstrainedAbstractSql(permissionsLookup, permissions, vocabulary, sqlNameToODataName(permissionsTable.modifyName ?? permissionsTable.name)));
676
634
  return permissionsTable;
677
635
  },
678
636
  });
@@ -703,10 +661,10 @@ const getBoundConstrainedMemoizer = (0, weak_1.default)((abstractSqlModel) => (0
703
661
  primitive: true,
704
662
  }));
705
663
  const memoizedGetConstrainedModel = (abstractSqlModel, permissionsLookup, vocabulary) => getBoundConstrainedMemoizer(abstractSqlModel)(permissionsLookup, vocabulary);
706
- const getCheckPasswordQuery = lodash_1.default.once(() => sbvrUtils.api.Auth.prepare({
664
+ const getCheckPasswordQuery = _.once(() => sbvrUtils.api.Auth.prepare({
707
665
  resource: 'user',
708
666
  passthrough: {
709
- req: exports.rootRead,
667
+ req: rootRead,
710
668
  },
711
669
  id: {
712
670
  username: { '@': 'username' },
@@ -715,7 +673,7 @@ const getCheckPasswordQuery = lodash_1.default.once(() => sbvrUtils.api.Auth.pre
715
673
  $select: ['id', 'actor', 'password'],
716
674
  },
717
675
  }, { username: ['string'] }));
718
- const checkPassword = async (username, password) => {
676
+ export const checkPassword = async (username, password) => {
719
677
  const user = await getCheckPasswordQuery()({
720
678
  username,
721
679
  });
@@ -727,7 +685,7 @@ const checkPassword = async (username, password) => {
727
685
  throw new Error('Passwords do not match');
728
686
  }
729
687
  const userId = user.id;
730
- const permissions = await (0, exports.getUserPermissions)(userId);
688
+ const permissions = await getUserPermissions(userId);
731
689
  return {
732
690
  id: userId,
733
691
  actor: user.actor.__id,
@@ -735,12 +693,11 @@ const checkPassword = async (username, password) => {
735
693
  permissions,
736
694
  };
737
695
  };
738
- exports.checkPassword = checkPassword;
739
696
  const $getUserPermissions = (() => {
740
- const getUserPermissionsQuery = lodash_1.default.once(() => sbvrUtils.api.Auth.prepare({
697
+ const getUserPermissionsQuery = _.once(() => sbvrUtils.api.Auth.prepare({
741
698
  resource: 'permission',
742
699
  passthrough: {
743
- req: exports.rootRead,
700
+ req: rootRead,
744
701
  },
745
702
  options: {
746
703
  $select: 'name',
@@ -818,7 +775,7 @@ const $getUserPermissions = (() => {
818
775
  normalizer: ([userId]) => `${userId}`,
819
776
  });
820
777
  })();
821
- const getUserPermissions = async (userId, tx) => {
778
+ export const getUserPermissions = async (userId, tx) => {
822
779
  if (typeof userId === 'string') {
823
780
  userId = parseInt(userId, 10);
824
781
  }
@@ -833,12 +790,11 @@ const getUserPermissions = async (userId, tx) => {
833
790
  throw err;
834
791
  }
835
792
  };
836
- exports.getUserPermissions = getUserPermissions;
837
793
  const $getApiKeyPermissions = (() => {
838
- const getApiKeyPermissionsQuery = lodash_1.default.once(() => sbvrUtils.api.Auth.prepare({
794
+ const getApiKeyPermissionsQuery = _.once(() => sbvrUtils.api.Auth.prepare({
839
795
  resource: 'permission',
840
796
  passthrough: {
841
- req: exports.rootRead,
797
+ req: rootRead,
842
798
  },
843
799
  options: {
844
800
  $select: 'name',
@@ -936,7 +892,7 @@ const $getApiKeyPermissions = (() => {
936
892
  normalizer: ([apiKey]) => apiKey,
937
893
  });
938
894
  })();
939
- const getApiKeyPermissions = async (apiKey, tx) => {
895
+ export const getApiKeyPermissions = async (apiKey, tx) => {
940
896
  if (typeof apiKey !== 'string') {
941
897
  throw new Error('API key has to be a string, got: ' + typeof apiKey);
942
898
  }
@@ -948,12 +904,11 @@ const getApiKeyPermissions = async (apiKey, tx) => {
948
904
  throw err;
949
905
  }
950
906
  };
951
- exports.getApiKeyPermissions = getApiKeyPermissions;
952
907
  const getApiKeyActorId = (() => {
953
- const getApiKeyActorIdQuery = lodash_1.default.once(() => sbvrUtils.api.Auth.prepare({
908
+ const getApiKeyActorIdQuery = _.once(() => sbvrUtils.api.Auth.prepare({
954
909
  resource: 'api_key',
955
910
  passthrough: {
956
- req: exports.rootRead,
911
+ req: rootRead,
957
912
  },
958
913
  id: {
959
914
  key: { '@': 'apiKey' },
@@ -968,7 +923,7 @@ const getApiKeyActorId = (() => {
968
923
  },
969
924
  },
970
925
  }, { apiKey: ['string'] }));
971
- const apiActorPermissionError = new errors_1.PermissionError();
926
+ const apiActorPermissionError = new PermissionError();
972
927
  return env.createCache('apiKeyActorId', async (apiKey, tx) => {
973
928
  const apiKeyResult = await getApiKeyActorIdQuery()({
974
929
  apiKey,
@@ -987,8 +942,8 @@ const getApiKeyActorId = (() => {
987
942
  normalizer: ([apiKey]) => apiKey,
988
943
  });
989
944
  })();
990
- const checkApiKey = async (apiKey, tx) => {
991
- const permissions = await (0, exports.getApiKeyPermissions)(apiKey, tx);
945
+ export const checkApiKey = async (apiKey, tx) => {
946
+ const permissions = await getApiKeyPermissions(apiKey, tx);
992
947
  const actor = await getApiKeyActorId(apiKey, tx);
993
948
  return {
994
949
  key: apiKey,
@@ -996,8 +951,7 @@ const checkApiKey = async (apiKey, tx) => {
996
951
  actor,
997
952
  };
998
953
  };
999
- exports.checkApiKey = checkApiKey;
1000
- const resolveAuthHeader = async (req, expectedScheme = 'Bearer', tx) => {
954
+ export const resolveAuthHeader = async (req, expectedScheme = 'Bearer', tx) => {
1001
955
  const auth = req.header('Authorization');
1002
956
  if (!auth) {
1003
957
  return;
@@ -1010,20 +964,19 @@ const resolveAuthHeader = async (req, expectedScheme = 'Bearer', tx) => {
1010
964
  if (scheme.toLowerCase() !== expectedScheme.toLowerCase()) {
1011
965
  return;
1012
966
  }
1013
- return await (0, exports.checkApiKey)(apiKey, tx);
967
+ return await checkApiKey(apiKey, tx);
1014
968
  };
1015
- exports.resolveAuthHeader = resolveAuthHeader;
1016
- exports.canAccess = {
969
+ export const canAccess = {
1017
970
  $fn: {
1018
971
  $scope: 'Auth',
1019
972
  $method: 'canAccess',
1020
973
  },
1021
974
  };
1022
- const customAuthorizationMiddleware = (expectedScheme = 'Bearer') => {
975
+ export const customAuthorizationMiddleware = (expectedScheme = 'Bearer') => {
1023
976
  expectedScheme = expectedScheme.toLowerCase();
1024
977
  return async (req, _res, next) => {
1025
978
  try {
1026
- const apiKey = await (0, exports.resolveAuthHeader)(req, expectedScheme);
979
+ const apiKey = await resolveAuthHeader(req, expectedScheme);
1027
980
  if (apiKey) {
1028
981
  req.apiKey = apiKey;
1029
982
  }
@@ -1033,20 +986,18 @@ const customAuthorizationMiddleware = (expectedScheme = 'Bearer') => {
1033
986
  }
1034
987
  };
1035
988
  };
1036
- exports.customAuthorizationMiddleware = customAuthorizationMiddleware;
1037
- exports.authorizationMiddleware = (0, exports.customAuthorizationMiddleware)();
1038
- const resolveApiKey = async (req, paramName = 'apikey', tx) => {
989
+ export const authorizationMiddleware = customAuthorizationMiddleware();
990
+ export const resolveApiKey = async (req, paramName = 'apikey', tx) => {
1039
991
  const apiKey = req.params[paramName] ?? req.body[paramName] ?? req.query[paramName];
1040
992
  if (apiKey == null) {
1041
993
  return;
1042
994
  }
1043
- return await (0, exports.checkApiKey)(apiKey, tx);
995
+ return await checkApiKey(apiKey, tx);
1044
996
  };
1045
- exports.resolveApiKey = resolveApiKey;
1046
- const customApiKeyMiddleware = (paramName = 'apikey') => {
997
+ export const customApiKeyMiddleware = (paramName = 'apikey') => {
1047
998
  return async (req, _res, next) => {
1048
999
  try {
1049
- const apiKey = await (0, exports.resolveApiKey)(req, paramName);
1000
+ const apiKey = await resolveApiKey(req, paramName);
1050
1001
  if (apiKey) {
1051
1002
  req.apiKey = apiKey;
1052
1003
  }
@@ -1056,16 +1007,14 @@ const customApiKeyMiddleware = (paramName = 'apikey') => {
1056
1007
  }
1057
1008
  };
1058
1009
  };
1059
- exports.customApiKeyMiddleware = customApiKeyMiddleware;
1060
- exports.apiKeyMiddleware = (0, exports.customApiKeyMiddleware)();
1061
- const checkPermissions = async (req, actionList, resourceName, vocabulary) => {
1010
+ export const apiKeyMiddleware = customApiKeyMiddleware();
1011
+ export const checkPermissions = async (req, actionList, resourceName, vocabulary) => {
1062
1012
  const permissionsLookup = await getReqPermissions(req);
1063
1013
  return $checkPermissions(permissionsLookup, actionList, vocabulary, resourceName);
1064
1014
  };
1065
- exports.checkPermissions = checkPermissions;
1066
- const checkPermissionsMiddleware = (action) => async (req, res, next) => {
1015
+ export const checkPermissionsMiddleware = (action) => async (req, res, next) => {
1067
1016
  try {
1068
- const allowed = await (0, exports.checkPermissions)(req, action);
1017
+ const allowed = await checkPermissions(req, action);
1069
1018
  switch (allowed) {
1070
1019
  case false:
1071
1020
  res.status(401).end();
@@ -1082,13 +1031,12 @@ const checkPermissionsMiddleware = (action) => async (req, res, next) => {
1082
1031
  res.status(503).end();
1083
1032
  }
1084
1033
  };
1085
- exports.checkPermissionsMiddleware = checkPermissionsMiddleware;
1086
1034
  let guestPermissionsInitialized = false;
1087
- const getGuestPermissions = (0, memoizee_1.default)(async () => {
1035
+ const getGuestPermissions = memoize(async () => {
1088
1036
  const result = await sbvrUtils.api.Auth.get({
1089
1037
  resource: 'user',
1090
1038
  passthrough: {
1091
- req: exports.rootRead,
1039
+ req: rootRead,
1092
1040
  },
1093
1041
  id: {
1094
1042
  username: 'guest',
@@ -1100,7 +1048,7 @@ const getGuestPermissions = (0, memoizee_1.default)(async () => {
1100
1048
  if (result == null) {
1101
1049
  throw new Error('No guest user');
1102
1050
  }
1103
- const guestPermissions = lodash_1.default.uniq(await (0, exports.getUserPermissions)(result.id));
1051
+ const guestPermissions = _.uniq(await getUserPermissions(result.id));
1104
1052
  if (guestPermissions.some((p) => DEFAULT_ACTOR_BIND_REGEX.test(p))) {
1105
1053
  throw new Error('Guest permissions cannot reference actors');
1106
1054
  }
@@ -1110,7 +1058,7 @@ const getGuestPermissions = (0, memoizee_1.default)(async () => {
1110
1058
  const getReqPermissions = async (req, odataBinds = []) => {
1111
1059
  const guestPermissions = await (async () => {
1112
1060
  if (guestPermissionsInitialized === false &&
1113
- (req.user === exports.root.user || req.user === exports.rootRead.user)) {
1061
+ (req.user === root.user || req.user === rootRead.user)) {
1114
1062
  return [];
1115
1063
  }
1116
1064
  return await getGuestPermissions();
@@ -1128,14 +1076,14 @@ const getReqPermissions = async (req, odataBinds = []) => {
1128
1076
  }
1129
1077
  return getPermissionsLookup(actorPermissions, guestPermissions);
1130
1078
  };
1131
- const addPermissions = async (req, request) => {
1079
+ export const addPermissions = async (req, request) => {
1132
1080
  const { resourceName, odataQuery, odataBinds } = request;
1133
- const vocabulary = lodash_1.default.last(request.translateVersions);
1081
+ const vocabulary = _.last(request.translateVersions);
1134
1082
  let abstractSqlModel = sbvrUtils.getAbstractSqlModel(request);
1135
1083
  let { permissionType } = request;
1136
1084
  if (permissionType == null) {
1137
1085
  const method = request.method.toUpperCase();
1138
- const isMetadataEndpoint = method === 'OPTIONS' || uri_parser_1.metadataEndpoints.includes(resourceName);
1086
+ const isMetadataEndpoint = method === 'OPTIONS' || metadataEndpoints.includes(resourceName);
1139
1087
  if (isMetadataEndpoint) {
1140
1088
  permissionType = 'model';
1141
1089
  }
@@ -1152,12 +1100,11 @@ const addPermissions = async (req, request) => {
1152
1100
  }
1153
1101
  const permissionsLookup = await getReqPermissions(req, odataBinds);
1154
1102
  request.abstractSqlModel = abstractSqlModel = memoizedGetConstrainedModel(abstractSqlModel, permissionsLookup, vocabulary);
1155
- if (!lodash_1.default.isEqual(permissionType, methodPermissions.GET)) {
1103
+ if (!_.isEqual(permissionType, methodPermissions.GET)) {
1156
1104
  const sqlName = sbvrUtils.resolveSynonym(request);
1157
1105
  odataQuery.resource = `${sqlName}$permissions${JSON.stringify(permissionType)}`;
1158
1106
  }
1159
1107
  };
1160
- exports.addPermissions = addPermissions;
1161
1108
  const authModelConfig = {
1162
1109
  apiRoot: 'Auth',
1163
1110
  modelText: userModel,
@@ -1197,14 +1144,14 @@ const authModelConfig = {
1197
1144
  `,
1198
1145
  },
1199
1146
  };
1200
- exports.config = {
1147
+ export const config = {
1201
1148
  models: [authModelConfig],
1202
1149
  };
1203
- function setup() {
1204
- (0, hooks_1.addHook)('all', 'all', 'all', {
1150
+ export function setup() {
1151
+ addHook('all', 'all', 'all', {
1205
1152
  sideEffects: false,
1206
1153
  readOnlyTx: true,
1207
- PREPARSE: ({ req }) => (0, exports.apiKeyMiddleware)(req),
1154
+ PREPARSE: ({ req }) => apiKeyMiddleware(req),
1208
1155
  POSTPARSE: async ({ req, request, }) => {
1209
1156
  if (request.abstractSqlQuery != null) {
1210
1157
  return;
@@ -1212,16 +1159,16 @@ function setup() {
1212
1159
  if (request.method === 'POST' &&
1213
1160
  request.odataQuery.property?.resource === 'canAccess') {
1214
1161
  if (request.odataQuery.key == null) {
1215
- throw new errors_1.BadRequestError();
1162
+ throw new BadRequestError();
1216
1163
  }
1217
1164
  const { action, method } = request.values;
1218
1165
  if ((method == null) === (action == null)) {
1219
- throw new errors_1.BadRequestError();
1166
+ throw new BadRequestError();
1220
1167
  }
1221
1168
  if (method != null) {
1222
1169
  const permissions = methodPermissions[method];
1223
1170
  if (permissions == null) {
1224
- throw new errors_1.BadRequestError();
1171
+ throw new BadRequestError();
1225
1172
  }
1226
1173
  request.permissionType = permissions;
1227
1174
  }
@@ -1246,18 +1193,18 @@ function setup() {
1246
1193
  request.method = 'GET';
1247
1194
  request.custom.isAction = 'canAccess';
1248
1195
  }
1249
- await (0, exports.addPermissions)(req, request);
1196
+ await addPermissions(req, request);
1250
1197
  },
1251
1198
  PRERESPOND: ({ request, response }) => {
1252
1199
  if (request.custom.isAction === 'canAccess' &&
1253
1200
  (response.body == null ||
1254
1201
  typeof response.body === 'string' ||
1255
- lodash_1.default.isEmpty(response.body?.d))) {
1256
- throw new errors_1.PermissionError();
1202
+ _.isEmpty(response.body?.d))) {
1203
+ throw new PermissionError();
1257
1204
  }
1258
1205
  },
1259
1206
  });
1260
- (0, hooks_1.addPureHook)('POST', 'Auth', 'user', {
1207
+ addPureHook('POST', 'Auth', 'user', {
1261
1208
  POSTPARSE: async ({ request, api }) => {
1262
1209
  const result = await api.post({
1263
1210
  resource: 'actor',
@@ -1266,7 +1213,7 @@ function setup() {
1266
1213
  request.values.actor = result.id;
1267
1214
  },
1268
1215
  });
1269
- (0, hooks_1.addPureHook)('DELETE', 'Auth', 'user', {
1216
+ addPureHook('DELETE', 'Auth', 'user', {
1270
1217
  POSTRUN: ({ request, api }) => api.delete({
1271
1218
  resource: 'actor',
1272
1219
  id: request.values.actor,