@sdflc/backend-helpers 1.0.78 → 1.0.79

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 (109) hide show
  1. package/build/BaseCore.js +0 -3
  2. package/build/BaseGateway.js +0 -2
  3. package/build/RedisDataLoader.js +7 -12
  4. package/build/commonValidators.js +3 -9
  5. package/build/esm/BaseCore.d.ts +88 -0
  6. package/build/esm/BaseCore.js +810 -0
  7. package/build/esm/BaseGateway.d.ts +49 -0
  8. package/build/esm/BaseGateway.js +476 -0
  9. package/build/esm/DataCache.d.ts +14 -0
  10. package/build/esm/DataCache.js +98 -0
  11. package/build/esm/Database.d.ts +32 -0
  12. package/build/esm/Database.js +192 -0
  13. package/build/esm/DbMigratorAndSeeder.d.ts +49 -0
  14. package/build/esm/DbMigratorAndSeeder.js +199 -0
  15. package/build/esm/RedisDataLoader.d.ts +41 -0
  16. package/build/esm/RedisDataLoader.js +237 -0
  17. package/build/esm/apiContext.d.ts +11 -0
  18. package/build/esm/apiContext.js +135 -0
  19. package/build/esm/baseController.d.ts +17 -0
  20. package/build/esm/baseController.js +60 -0
  21. package/build/esm/checkItHelpers.d.ts +3 -0
  22. package/build/esm/checkItHelpers.js +23 -0
  23. package/build/esm/commonValidators.d.ts +17 -0
  24. package/build/esm/commonValidators.js +273 -0
  25. package/build/esm/configBulder.d.ts +2 -0
  26. package/build/esm/configBulder.js +28 -0
  27. package/build/esm/constants.d.ts +30 -0
  28. package/build/esm/constants.js +69 -0
  29. package/build/esm/dbHelpers.d.ts +43 -0
  30. package/build/esm/dbHelpers.js +154 -0
  31. package/build/esm/dbSeeder.d.ts +2 -0
  32. package/build/esm/dbSeeder.js +53 -0
  33. package/build/esm/dbTableHelpers.d.ts +11 -0
  34. package/build/esm/dbTableHelpers.js +99 -0
  35. package/build/esm/downloadHelpers.d.ts +2 -0
  36. package/build/esm/downloadHelpers.js +76 -0
  37. package/build/esm/index.d.ts +21 -0
  38. package/build/esm/index.js +21 -0
  39. package/build/esm/interfaces/ApiContext.d.ts +24 -0
  40. package/build/esm/interfaces/ApiContext.js +1 -0
  41. package/build/esm/interfaces/ApiContextInterface.d.ts +12 -0
  42. package/build/esm/interfaces/ApiContextInterface.js +1 -0
  43. package/build/esm/interfaces/BaseCoreActionsInterface.d.ts +38 -0
  44. package/build/esm/interfaces/BaseCoreActionsInterface.js +1 -0
  45. package/build/esm/interfaces/BaseCoreDoAuthOnActionInterface.d.ts +12 -0
  46. package/build/esm/interfaces/BaseCoreDoAuthOnActionInterface.js +1 -0
  47. package/build/esm/interfaces/BaseCoreDoingWhatInterface.d.ts +13 -0
  48. package/build/esm/interfaces/BaseCoreDoingWhatInterface.js +1 -0
  49. package/build/esm/interfaces/BaseCorePropsInterface.d.ts +36 -0
  50. package/build/esm/interfaces/BaseCorePropsInterface.js +1 -0
  51. package/build/esm/interfaces/BaseCoreValidatorsInterface.d.ts +13 -0
  52. package/build/esm/interfaces/BaseCoreValidatorsInterface.js +1 -0
  53. package/build/esm/interfaces/BaseGatewayPropsInterface.d.ts +39 -0
  54. package/build/esm/interfaces/BaseGatewayPropsInterface.js +1 -0
  55. package/build/esm/interfaces/BuildConfigOptions.d.ts +6 -0
  56. package/build/esm/interfaces/BuildConfigOptions.js +1 -0
  57. package/build/esm/interfaces/BuildDefaultResolversOptions.d.ts +17 -0
  58. package/build/esm/interfaces/BuildDefaultResolversOptions.js +1 -0
  59. package/build/esm/interfaces/BuildListQueryArgsInterface.d.ts +6 -0
  60. package/build/esm/interfaces/BuildListQueryArgsInterface.js +1 -0
  61. package/build/esm/interfaces/CacheInterface.d.ts +15 -0
  62. package/build/esm/interfaces/CacheInterface.js +1 -0
  63. package/build/esm/interfaces/CommonValidatorArgs.d.ts +3 -0
  64. package/build/esm/interfaces/CommonValidatorArgs.js +1 -0
  65. package/build/esm/interfaces/CoreActionInterface.d.ts +14 -0
  66. package/build/esm/interfaces/CoreActionInterface.js +1 -0
  67. package/build/esm/interfaces/CreateUserTokenArgs.d.ts +11 -0
  68. package/build/esm/interfaces/CreateUserTokenArgs.js +1 -0
  69. package/build/esm/interfaces/CreateUserTokenResult.d.ts +4 -0
  70. package/build/esm/interfaces/CreateUserTokenResult.js +1 -0
  71. package/build/esm/interfaces/DatabaseOptions.d.ts +22 -0
  72. package/build/esm/interfaces/DatabaseOptions.js +1 -0
  73. package/build/esm/interfaces/DatabaseReadInterface.d.ts +14 -0
  74. package/build/esm/interfaces/DatabaseReadInterface.js +1 -0
  75. package/build/esm/interfaces/DbFieldAddDefaultInterface.d.ts +9 -0
  76. package/build/esm/interfaces/DbFieldAddDefaultInterface.js +1 -0
  77. package/build/esm/interfaces/DownloadFileArgs.d.ts +6 -0
  78. package/build/esm/interfaces/DownloadFileArgs.js +1 -0
  79. package/build/esm/interfaces/ExtractCredentialsArgs.d.ts +19 -0
  80. package/build/esm/interfaces/ExtractCredentialsArgs.js +1 -0
  81. package/build/esm/interfaces/JwtTokenSecretAndSettings.d.ts +5 -0
  82. package/build/esm/interfaces/JwtTokenSecretAndSettings.js +1 -0
  83. package/build/esm/interfaces/ListArgsInterface.d.ts +5 -0
  84. package/build/esm/interfaces/ListArgsInterface.js +1 -0
  85. package/build/esm/interfaces/LoaderInterface.d.ts +4 -0
  86. package/build/esm/interfaces/LoaderInterface.js +1 -0
  87. package/build/esm/interfaces/PaginationInterface.d.ts +7 -0
  88. package/build/esm/interfaces/PaginationInterface.js +1 -0
  89. package/build/esm/interfaces/SortItemInterface.d.ts +4 -0
  90. package/build/esm/interfaces/SortItemInterface.js +1 -0
  91. package/build/esm/interfaces/UserTokenParams.d.ts +8 -0
  92. package/build/esm/interfaces/UserTokenParams.js +1 -0
  93. package/build/esm/interfaces/VerifyUserTokenArgs.d.ts +13 -0
  94. package/build/esm/interfaces/VerifyUserTokenArgs.js +1 -0
  95. package/build/esm/interfaces/index.d.ts +28 -0
  96. package/build/esm/interfaces/index.js +27 -0
  97. package/build/esm/knexConfigBuilder.d.ts +1 -0
  98. package/build/esm/knexConfigBuilder.js +73 -0
  99. package/build/esm/passwordHelpers.d.ts +5 -0
  100. package/build/esm/passwordHelpers.js +22 -0
  101. package/build/esm/redisClient.d.ts +17 -0
  102. package/build/esm/redisClient.js +94 -0
  103. package/build/esm/resolversHelpers.d.ts +3 -0
  104. package/build/esm/resolversHelpers.js +59 -0
  105. package/build/esm/userToken.d.ts +8 -0
  106. package/build/esm/userToken.js +74 -0
  107. package/build/esm/utils.d.ts +2 -0
  108. package/build/esm/utils.js +13 -0
  109. package/package.json +13 -5
@@ -0,0 +1,810 @@
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
+ import { OpResult, OP_RESULT_CODES } from '@sdflc/api-helpers';
11
+ import { Logger, ACCESS_RIGHTS, MeasureTool, StrOrderHelpers, LoggerLevels } from '@sdflc/utils';
12
+ import check from 'check-types';
13
+ import { castArray } from 'lodash';
14
+ import { validateGet, validateGetMany, validateRemove, validateRemoveMany } from './commonValidators';
15
+ import { ACTIONS, DEFAULT_ORDER_NO, DEFAULT_ORDER_NO_STEP, FIELDS, ID_TYPES, ORDER_BYS } from './constants';
16
+ import { getDefaultJwtAlgorithm, getDefaultJwtIssuer, verifyUserToken } from './userToken';
17
+ const defaultValidate = ( /*args: any, opt?: BaseCoreActionsInterface*/) => {
18
+ return [true, {}];
19
+ };
20
+ const defaultMutationValidate = ( /*args: any, opt?: BaseCoreActionsInterface*/) => {
21
+ return [true, {}];
22
+ };
23
+ const defaultValidators = {
24
+ list: defaultValidate,
25
+ get: validateGet,
26
+ getMany: validateGetMany,
27
+ create: defaultValidate,
28
+ createMany: defaultValidate,
29
+ update: defaultValidate,
30
+ updateMany: defaultValidate,
31
+ set: defaultValidate,
32
+ remove: validateRemove,
33
+ removeMany: validateRemoveMany,
34
+ };
35
+ class BaseCore {
36
+ constructor(props) {
37
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
38
+ this.measureTool = new MeasureTool();
39
+ this.config = props || {};
40
+ this.logger = this.config.logger instanceof Logger ? this.config.logger : new Logger({ level: LoggerLevels.ERROR });
41
+ this.config.doAuthOnAction = {
42
+ list: ((_a = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _a === void 0 ? void 0 : _a.list) != null ? (_b = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _b === void 0 ? void 0 : _b.list : props === null || props === void 0 ? void 0 : props.doAuth,
43
+ get: ((_c = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _c === void 0 ? void 0 : _c.get) != null ? (_d = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _d === void 0 ? void 0 : _d.get : props === null || props === void 0 ? void 0 : props.doAuth,
44
+ getMany: ((_e = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _e === void 0 ? void 0 : _e.getMany) != null ? (_f = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _f === void 0 ? void 0 : _f.getMany : props === null || props === void 0 ? void 0 : props.doAuth,
45
+ create: ((_g = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _g === void 0 ? void 0 : _g.create) != null ? (_h = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _h === void 0 ? void 0 : _h.create : props === null || props === void 0 ? void 0 : props.doAuth,
46
+ createMany: ((_j = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _j === void 0 ? void 0 : _j.createMany) != null ? (_k = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _k === void 0 ? void 0 : _k.createMany : props === null || props === void 0 ? void 0 : props.doAuth,
47
+ update: ((_l = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _l === void 0 ? void 0 : _l.update) != null ? (_m = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _m === void 0 ? void 0 : _m.update : props === null || props === void 0 ? void 0 : props.doAuth,
48
+ updateMany: ((_o = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _o === void 0 ? void 0 : _o.updateMany) != null ? (_p = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _p === void 0 ? void 0 : _p.updateMany : props === null || props === void 0 ? void 0 : props.doAuth,
49
+ set: ((_q = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _q === void 0 ? void 0 : _q.set) != null ? (_r = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _r === void 0 ? void 0 : _r.set : props === null || props === void 0 ? void 0 : props.doAuth,
50
+ remove: ((_s = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _s === void 0 ? void 0 : _s.remove) != null ? (_t = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _t === void 0 ? void 0 : _t.remove : props === null || props === void 0 ? void 0 : props.doAuth,
51
+ removeMany: ((_u = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _u === void 0 ? void 0 : _u.removeMany) != null ? (_v = props === null || props === void 0 ? void 0 : props.doAuthOnAction) === null || _v === void 0 ? void 0 : _v.removeMany : props === null || props === void 0 ? void 0 : props.doAuth,
52
+ };
53
+ }
54
+ getIdType() {
55
+ var _a;
56
+ return (_a = this.config.idType) !== null && _a !== void 0 ? _a : ID_TYPES.UNKNOWN;
57
+ }
58
+ getDb() {
59
+ return this.config.db;
60
+ }
61
+ getRequestId() {
62
+ return this.config.context.requestId;
63
+ }
64
+ getContext() {
65
+ return this.config.context;
66
+ }
67
+ getGateways() {
68
+ return this.config.context.gateways || {};
69
+ }
70
+ getGateway(name) {
71
+ var _a;
72
+ return (_a = this.getGateways()) === null || _a === void 0 ? void 0 : _a[name || this.config.gatewayName];
73
+ }
74
+ getValidators() {
75
+ return defaultValidators;
76
+ }
77
+ success(data, code) {
78
+ const code2use = code != null ? code : OP_RESULT_CODES.OK;
79
+ let data2use = data;
80
+ if (!Array.isArray(data2use)) {
81
+ if (data) {
82
+ data2use = [data];
83
+ }
84
+ else {
85
+ data2use = [];
86
+ }
87
+ }
88
+ return new OpResult({
89
+ code: code2use,
90
+ data: data2use,
91
+ errors: [],
92
+ }).toJS();
93
+ }
94
+ failure(code, errorMsg, data) {
95
+ const result = new OpResult({ data });
96
+ result.addError('', errorMsg, code);
97
+ return result.toJS();
98
+ }
99
+ validationFailure(ex) {
100
+ const result = new OpResult({ code: OP_RESULT_CODES.VALIDATION_FAILED });
101
+ if (ex instanceof OpResult) {
102
+ return result.toJS();
103
+ }
104
+ Object.keys((ex === null || ex === void 0 ? void 0 : ex.errors) || {}).forEach((key) => {
105
+ const obj = ex.errors[key];
106
+ if (Array.isArray(obj.errors)) {
107
+ // if we have multiple rules failures the add them all
108
+ obj.errors.forEach((item) => {
109
+ result.addError(key, item.message);
110
+ });
111
+ }
112
+ else {
113
+ result.addError(key, obj.message);
114
+ }
115
+ });
116
+ return result.toJS();
117
+ }
118
+ exceptionFailure(ex, doingWhat, data) {
119
+ const [isDbError, dbErrorMsg] = this.getDb().isDbError(ex);
120
+ const isOpResult = typeof ex.getErrorSummary === 'function';
121
+ const message = isOpResult ? ex.getErrorSummary() : ex.message;
122
+ const sysMsg = `An exception has occurred on ${doingWhat} with message ${message}:`;
123
+ let msg = '';
124
+ if (isDbError) {
125
+ msg = dbErrorMsg;
126
+ }
127
+ else {
128
+ msg = isOpResult ? ex.getErrorSummary() : `Sorry, something went wrong on ${doingWhat}`;
129
+ this.logger.error(sysMsg, ex);
130
+ }
131
+ const result = new OpResult({ data });
132
+ result.addError('', msg, OP_RESULT_CODES.EXCEPTION);
133
+ return result.toJS();
134
+ }
135
+ checkResult(args) {
136
+ return __awaiter(this, void 0, void 0, function* () {
137
+ const { hasTransaction, result, sameRequest, doingWhat } = args;
138
+ if (sameRequest) {
139
+ return;
140
+ }
141
+ if (hasTransaction && result) {
142
+ if (result.code >= OP_RESULT_CODES.OK) {
143
+ this.logger.debug(`Commit DB transaction on ${doingWhat}`);
144
+ yield this.getDb().commitTransaction();
145
+ }
146
+ else {
147
+ this.logger.debug(`Rollback DB transaction on ${doingWhat} as action result code is '${result.code}'`);
148
+ yield this.getDb().rollbackTransaction();
149
+ }
150
+ }
151
+ });
152
+ }
153
+ runAction(opt) {
154
+ return __awaiter(this, void 0, void 0, function* () {
155
+ const { args, validate, doAuth, action, hasTransaction, doingWhat, onException, shouldLogArgs, requireSpace } = opt || {};
156
+ // If we process action with the same requestId as requestId passed to the constructor it means
157
+ // we are processing the same request from FE and can skip some of the operations like transactions and etc
158
+ const sameRequest = !!this.config.context.requestId && (args === null || args === void 0 ? void 0 : args.requestId) === this.config.context.requestId;
159
+ // TODO: Calculate total thread block time between async calls withing the request
160
+ // this.measureTool.threadBlockTime(doingWhat, ({ name, durationMs }: any) => {
161
+ // this.logger.debug(`The ${name} blocked thread for the time of ${durationMs} ms`);
162
+ // });
163
+ if (shouldLogArgs == null || shouldLogArgs === true) {
164
+ this.logger.debug(`The ${doingWhat} started:`, args);
165
+ }
166
+ else {
167
+ this.logger.debug(`The ${doingWhat} started`);
168
+ }
169
+ this.measureTool.start();
170
+ let step = doingWhat || '';
171
+ const setStep = (stepName) => {
172
+ step = stepName || step;
173
+ const time = this.measureTool.addCheckpoint(stepName);
174
+ if (stepName) {
175
+ this.logger.debug(`${time.name}. Since last step: ${time.durationMs} ms`);
176
+ }
177
+ };
178
+ const actionOpt = {
179
+ core: this,
180
+ setStep,
181
+ sameRequest,
182
+ hasTransaction,
183
+ };
184
+ try {
185
+ if (!sameRequest) {
186
+ if (hasTransaction) {
187
+ this.logger.debug(`Start DB transaction on ${step}`);
188
+ yield this.getDb().startTransaction();
189
+ }
190
+ if (doAuth === true || (doAuth == null && this.config.doAuth)) {
191
+ this.measureTool.addCheckpoint('Authenticate request: start');
192
+ const [authResult, errMsg] = yield this.authenticate(opt, actionOpt);
193
+ this.measureTool.addCheckpoint('Authenticate request: end');
194
+ if (!authResult) {
195
+ const result = new OpResult({ code: OP_RESULT_CODES.UNAUTHORIZED }).addError('', errMsg);
196
+ this.logger.error(`The ${step} requires authentication and it has failed:`, errMsg);
197
+ yield this.checkResult({ hasTransaction, result, sameRequest, doingWhat });
198
+ return result;
199
+ }
200
+ }
201
+ else if (requireSpace == null || requireSpace === true) {
202
+ this.measureTool.addCheckpoint('Find space: start');
203
+ const [spaceResult, errMsg] = yield this.findSpace();
204
+ this.measureTool.addCheckpoint('Find space: end');
205
+ if (spaceResult !== true) {
206
+ const result = new OpResult({ code: OP_RESULT_CODES.UNAUTHORIZED }).addError('', errMsg);
207
+ this.logger.error(`The ${step} requires a space and it has failed:`, errMsg);
208
+ yield this.checkResult({ hasTransaction, result, sameRequest, doingWhat });
209
+ return result;
210
+ }
211
+ }
212
+ }
213
+ let validatedItems = {};
214
+ if (typeof validate === 'function') {
215
+ this.measureTool.addCheckpoint('Validate parameters: start');
216
+ // If we have validator provided, use it to validate data before running action
217
+ // validator is expected to return an array:
218
+ // [0] - true or validation error object,
219
+ // [1] - an object with some fetched data to pass ot the action handler
220
+ const valideResult = yield validate(args, actionOpt);
221
+ let result = valideResult;
222
+ if (Array.isArray(valideResult)) {
223
+ result = valideResult[0];
224
+ validatedItems = valideResult[1] || {};
225
+ }
226
+ // If validator returned null then consider the validation passed
227
+ result = result != null ? result : true;
228
+ this.measureTool.addCheckpoint('Validate parameters: end');
229
+ if (result !== true) {
230
+ // if there was an error then `result` is expected to be an object with the same structure as the checkit library does
231
+ yield this.checkResult({ hasTransaction, result, sameRequest });
232
+ return result.code != null ? result : new OpResult({ code: OP_RESULT_CODES.VALIDATION_FAILED });
233
+ }
234
+ }
235
+ let time = this.measureTool.stop();
236
+ this.logger.debug(`Authorization and validation time for the ${doingWhat} took ${time.durationMs} ms`);
237
+ const result = yield action(args, Object.assign(Object.assign({}, actionOpt), { validatedItems, args }));
238
+ yield this.checkResult({ hasTransaction, result, sameRequest, doingWhat });
239
+ time = this.measureTool.stop(doingWhat);
240
+ this.logger.debug(`The ${time.name} process time is ${time.durationMs} ms`);
241
+ return result;
242
+ }
243
+ catch (ex) {
244
+ this.logger.error(`An exception has occurred on ${step}:`, ex);
245
+ if (!sameRequest && hasTransaction) {
246
+ this.logger.debug(`Rolling back DB transaction on ${step} due to an excaption`);
247
+ yield this.getDb().rollbackTransaction();
248
+ }
249
+ let errMessage = '';
250
+ try {
251
+ errMessage = yield this.onException(args, Object.assign(Object.assign({}, actionOpt), { doingWhat, exception: ex }));
252
+ if (check.function(onException)) {
253
+ errMessage = yield onException(args, Object.assign(Object.assign({}, actionOpt), { doingWhat, exception: ex }));
254
+ }
255
+ }
256
+ catch (ex2) {
257
+ this.logger.error(`An exception has occured when handling exception:`, ex2);
258
+ }
259
+ if (!errMessage) {
260
+ errMessage = doingWhat;
261
+ }
262
+ if (doingWhat !== step) {
263
+ errMessage = `${step} failed on ${doingWhat}`;
264
+ }
265
+ const time = this.measureTool.stop(doingWhat);
266
+ this.logger.debug(`The ${time.name} process time is ${time.durationMs} ms`);
267
+ return this.exceptionFailure(ex, errMessage);
268
+ }
269
+ });
270
+ }
271
+ list(args) {
272
+ return __awaiter(this, void 0, void 0, function* () {
273
+ var _a, _b, _c, _d;
274
+ return this.runAction({
275
+ args,
276
+ doAuth: (_a = this.config.doAuthOnAction) === null || _a === void 0 ? void 0 : _a.list,
277
+ actionName: ACTIONS.LIST,
278
+ validate: this.getValidators().list,
279
+ accessRights: [ACCESS_RIGHTS.LIST],
280
+ action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
281
+ var _a;
282
+ const object = yield this.beforeList(args, opt);
283
+ if (object instanceof OpResult) {
284
+ return object;
285
+ }
286
+ const items = yield ((_a = this.getContext().gateways[this.config.gatewayName]) === null || _a === void 0 ? void 0 : _a.list(object));
287
+ const result = yield this.afterList(items, opt);
288
+ // ON NO DATA RETURN EMPTY CODE
289
+ return this.success(result);
290
+ }),
291
+ hasTransaction: false,
292
+ doingWhat: (_d = (_c = (_b = this.config.doingWhat) === null || _b === void 0 ? void 0 : _b.list) !== null && _c !== void 0 ? _c : this.config.name) !== null && _d !== void 0 ? _d : 'listing',
293
+ });
294
+ });
295
+ }
296
+ get(args) {
297
+ return __awaiter(this, void 0, void 0, function* () {
298
+ var _a, _b, _c, _d;
299
+ return this.runAction({
300
+ args,
301
+ doAuth: (_a = this.config.doAuthOnAction) === null || _a === void 0 ? void 0 : _a.get,
302
+ actionName: ACTIONS.GET,
303
+ validate: this.getValidators().get,
304
+ accessRights: [ACCESS_RIGHTS.GET],
305
+ action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
306
+ var _a;
307
+ const args2use = yield this.beforeGet(args, opt);
308
+ if (args2use instanceof OpResult) {
309
+ return args2use;
310
+ }
311
+ if ((args2use === null || args2use === void 0 ? void 0 : args2use.id) == null) {
312
+ return this.failure(OP_RESULT_CODES.NOT_FOUND, '', []);
313
+ }
314
+ const item = yield ((_a = this.getContext().gateways[this.config.gatewayName]) === null || _a === void 0 ? void 0 : _a.get(args2use === null || args2use === void 0 ? void 0 : args2use.id));
315
+ const result = yield this.afterGet(item, opt);
316
+ if (!result) {
317
+ return this.failure(OP_RESULT_CODES.NOT_FOUND, '', []);
318
+ }
319
+ return this.success([result]);
320
+ }),
321
+ hasTransaction: false,
322
+ doingWhat: (_d = (_c = (_b = this.config.doingWhat) === null || _b === void 0 ? void 0 : _b.get) !== null && _c !== void 0 ? _c : this.config.name) !== null && _d !== void 0 ? _d : 'getting an item',
323
+ });
324
+ });
325
+ }
326
+ getMany(args) {
327
+ return __awaiter(this, void 0, void 0, function* () {
328
+ var _a, _b, _c, _d;
329
+ return this.runAction({
330
+ args,
331
+ doAuth: (_a = this.config.doAuthOnAction) === null || _a === void 0 ? void 0 : _a.getMany,
332
+ actionName: ACTIONS.GET_MANY,
333
+ validate: this.getValidators().getMany,
334
+ accessRights: [ACCESS_RIGHTS.GET],
335
+ action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
336
+ var _a;
337
+ const args2use = yield this.beforeGetMany(args, opt);
338
+ if (args2use instanceof OpResult) {
339
+ return args2use;
340
+ }
341
+ if (!Array.isArray(args2use === null || args2use === void 0 ? void 0 : args2use.ids)) {
342
+ return this.failure(OP_RESULT_CODES.NOT_FOUND, '', []);
343
+ }
344
+ const items = yield ((_a = this.getContext().gateways[this.config.gatewayName]) === null || _a === void 0 ? void 0 : _a.getMany(args2use.ids));
345
+ const result = yield this.afterGetMany(items, opt);
346
+ return this.success(result);
347
+ }),
348
+ hasTransaction: false,
349
+ doingWhat: (_d = (_c = (_b = this.config.doingWhat) === null || _b === void 0 ? void 0 : _b.getMany) !== null && _c !== void 0 ? _c : this.config.name) !== null && _d !== void 0 ? _d : 'geting multiple items',
350
+ });
351
+ });
352
+ }
353
+ getGatewayToSetOrerNo() {
354
+ return this.getContext().gateways[this.config.gatewayName];
355
+ }
356
+ getFilterToSetOrderNo(args) {
357
+ return {};
358
+ }
359
+ create(args) {
360
+ return __awaiter(this, void 0, void 0, function* () {
361
+ var _a, _b, _c, _d;
362
+ return this.runAction({
363
+ args,
364
+ doAuth: (_a = this.config.doAuthOnAction) === null || _a === void 0 ? void 0 : _a.create,
365
+ actionName: ACTIONS.CREATE,
366
+ validate: this.getValidators().create,
367
+ accessRights: [ACCESS_RIGHTS.CREATE],
368
+ action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
369
+ var _a;
370
+ const { params } = args || {};
371
+ if (this.config.hasOrderNo === true) {
372
+ this.setOrderNo({
373
+ params,
374
+ filter: this.getFilterToSetOrderNo({ params, opt }),
375
+ gateway: this.getGatewayToSetOrerNo(),
376
+ });
377
+ }
378
+ const object = yield this.beforeCreate(params, opt);
379
+ if (object instanceof OpResult) {
380
+ return object;
381
+ }
382
+ const items = yield ((_a = this.getContext().gateways[this.config.gatewayName]) === null || _a === void 0 ? void 0 : _a.create(object));
383
+ const result = yield this.afterCreate(items, opt);
384
+ return this.success(result);
385
+ }),
386
+ hasTransaction: true,
387
+ doingWhat: (_d = (_c = (_b = this.config.doingWhat) === null || _b === void 0 ? void 0 : _b.create) !== null && _c !== void 0 ? _c : this.config.name) !== null && _d !== void 0 ? _d : 'creating an item',
388
+ });
389
+ });
390
+ }
391
+ createMany(args) {
392
+ return __awaiter(this, void 0, void 0, function* () {
393
+ var _a, _b, _c, _d;
394
+ return this.runAction({
395
+ args,
396
+ doAuth: (_a = this.config.doAuthOnAction) === null || _a === void 0 ? void 0 : _a.createMany,
397
+ actionName: ACTIONS.CREATE_MANY,
398
+ validate: this.getValidators().createMany,
399
+ accessRights: [ACCESS_RIGHTS.CREATE],
400
+ action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
401
+ var _a;
402
+ const { params } = args || {};
403
+ const objects = yield this.beforeCreateMany(params, opt);
404
+ if (objects instanceof OpResult) {
405
+ return objects;
406
+ }
407
+ const items = yield ((_a = this.getContext().gateways[this.config.gatewayName]) === null || _a === void 0 ? void 0 : _a.create(objects));
408
+ const result = yield this.afterCreateMany(items, opt);
409
+ return this.success(result);
410
+ }),
411
+ hasTransaction: true,
412
+ doingWhat: (_d = (_c = (_b = this.config.doingWhat) === null || _b === void 0 ? void 0 : _b.createMany) !== null && _c !== void 0 ? _c : this.config.name) !== null && _d !== void 0 ? _d : 'creating multiple items',
413
+ });
414
+ });
415
+ }
416
+ update(args) {
417
+ return __awaiter(this, void 0, void 0, function* () {
418
+ var _a, _b, _c, _d;
419
+ return this.runAction({
420
+ args,
421
+ doAuth: (_a = this.config.doAuthOnAction) === null || _a === void 0 ? void 0 : _a.update,
422
+ actionName: ACTIONS.UPDATE,
423
+ validate: this.getValidators().update,
424
+ accessRights: [ACCESS_RIGHTS.UPDATE],
425
+ action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
426
+ var _a;
427
+ const { where, params } = args || {};
428
+ const object = yield this.beforeUpdate(params, opt);
429
+ if (object instanceof OpResult) {
430
+ return object;
431
+ }
432
+ const items = yield ((_a = this.getContext().gateways[this.config.gatewayName]) === null || _a === void 0 ? void 0 : _a.update(where, object));
433
+ const result = yield this.afterUpdate(items, opt);
434
+ return this.success(result, result.length > 0 ? OP_RESULT_CODES.OK : OP_RESULT_CODES.NOT_FOUND);
435
+ }),
436
+ hasTransaction: true,
437
+ doingWhat: (_d = (_c = (_b = this.config.doingWhat) === null || _b === void 0 ? void 0 : _b.update) !== null && _c !== void 0 ? _c : this.config.name) !== null && _d !== void 0 ? _d : 'updating an item',
438
+ });
439
+ });
440
+ }
441
+ updateMany(args) {
442
+ return __awaiter(this, void 0, void 0, function* () {
443
+ var _a, _b, _c, _d;
444
+ return this.runAction({
445
+ args,
446
+ doAuth: (_a = this.config.doAuthOnAction) === null || _a === void 0 ? void 0 : _a.updateMany,
447
+ actionName: ACTIONS.UPDATE_MANY,
448
+ validate: this.getValidators().updateMany,
449
+ accessRights: [ACCESS_RIGHTS.UPDATE],
450
+ action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
451
+ var _a;
452
+ const { params } = args || {};
453
+ const object = yield this.beforeUpdateMany(params, opt);
454
+ if (object instanceof OpResult) {
455
+ return object;
456
+ }
457
+ const items = yield ((_a = this.getContext().gateways[this.config.gatewayName]) === null || _a === void 0 ? void 0 : _a.updateMany(object));
458
+ const result = yield this.afterUpdateMany(items, opt);
459
+ return this.success(result);
460
+ }),
461
+ hasTransaction: true,
462
+ doingWhat: (_d = (_c = (_b = this.config.doingWhat) === null || _b === void 0 ? void 0 : _b.updateMany) !== null && _c !== void 0 ? _c : this.config.name) !== null && _d !== void 0 ? _d : 'updating multiple items',
463
+ });
464
+ });
465
+ }
466
+ set(args) {
467
+ return __awaiter(this, void 0, void 0, function* () {
468
+ var _a, _b, _c, _d;
469
+ return this.runAction({
470
+ args,
471
+ doAuth: (_a = this.config.doAuthOnAction) === null || _a === void 0 ? void 0 : _a.set,
472
+ actionName: ACTIONS.SET,
473
+ validate: this.getValidators().set,
474
+ accessRights: [ACCESS_RIGHTS.CREATE, ACCESS_RIGHTS.UPDATE],
475
+ action: (args, opt /* { setStep, validatedItems, sameRequest } */) => __awaiter(this, void 0, void 0, function* () {
476
+ var _a;
477
+ const { params } = args || {};
478
+ const object = yield this.beforeSet(params, opt);
479
+ if (object instanceof OpResult) {
480
+ return object;
481
+ }
482
+ const items = yield ((_a = this.getContext().gateways[this.config.gatewayName]) === null || _a === void 0 ? void 0 : _a.set(object));
483
+ const result = yield this.afterSet(items, opt);
484
+ return this.success(result);
485
+ }),
486
+ hasTransaction: true,
487
+ doingWhat: (_d = (_c = (_b = this.config.doingWhat) === null || _b === void 0 ? void 0 : _b.updateMany) !== null && _c !== void 0 ? _c : this.config.name) !== null && _d !== void 0 ? _d : 'updating multiple items',
488
+ });
489
+ });
490
+ }
491
+ remove(args) {
492
+ return __awaiter(this, void 0, void 0, function* () {
493
+ var _a, _b, _c, _d;
494
+ return this.runAction({
495
+ args,
496
+ doAuth: (_a = this.config.doAuthOnAction) === null || _a === void 0 ? void 0 : _a.remove,
497
+ actionName: ACTIONS.REMOVE,
498
+ validate: this.getValidators().remove,
499
+ accessRights: [ACCESS_RIGHTS.REMOVE],
500
+ action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
501
+ var _a;
502
+ const { where } = args || {};
503
+ const object = yield this.beforeRemove(where, opt);
504
+ if (object instanceof OpResult) {
505
+ return object;
506
+ }
507
+ const items = yield ((_a = this.getContext().gateways[this.config.gatewayName]) === null || _a === void 0 ? void 0 : _a.remove(object));
508
+ const result = yield this.afterRemove(items, opt);
509
+ return this.success(result, result.length > 0 ? OP_RESULT_CODES.OK : OP_RESULT_CODES.NOT_FOUND);
510
+ }),
511
+ hasTransaction: false,
512
+ doingWhat: (_d = (_c = (_b = this.config.doingWhat) === null || _b === void 0 ? void 0 : _b.remove) !== null && _c !== void 0 ? _c : this.config.name) !== null && _d !== void 0 ? _d : 'removing an item',
513
+ });
514
+ });
515
+ }
516
+ removeMany(args) {
517
+ return __awaiter(this, void 0, void 0, function* () {
518
+ var _a, _b, _c, _d;
519
+ return this.runAction({
520
+ args,
521
+ doAuth: (_a = this.config.doAuthOnAction) === null || _a === void 0 ? void 0 : _a.removeMany,
522
+ actionName: ACTIONS.REMOVE_MANY,
523
+ validate: this.getValidators().removeMany,
524
+ accessRights: [ACCESS_RIGHTS.REMOVE],
525
+ action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
526
+ var _a;
527
+ const { where } = args || {};
528
+ const object = yield this.beforeRemoveMany(where, opt);
529
+ if (object instanceof OpResult) {
530
+ return object;
531
+ }
532
+ const items = yield ((_a = this.getContext().gateways[this.config.gatewayName]) === null || _a === void 0 ? void 0 : _a.remove(object));
533
+ const result = yield this.afterRemoveMany(items, opt);
534
+ return this.success(result, result.length > 0 ? OP_RESULT_CODES.OK : OP_RESULT_CODES.NOT_FOUND);
535
+ }),
536
+ hasTransaction: false,
537
+ doingWhat: (_d = (_c = (_b = this.config.doingWhat) === null || _b === void 0 ? void 0 : _b.removeMany) !== null && _c !== void 0 ? _c : this.config.name) !== null && _d !== void 0 ? _d : 'removing multiple items',
538
+ });
539
+ });
540
+ }
541
+ defaultAfterAndBefore(params, opt) {
542
+ return __awaiter(this, void 0, void 0, function* () {
543
+ return params;
544
+ });
545
+ }
546
+ /**
547
+ * Used to transform an object before sending it in the response
548
+ * @param {any} item An object coming from the database
549
+ * @param {BaseCoreActionsInterface} opt Options
550
+ * @returns {any} transformed object
551
+ */
552
+ processItemOnOut(item, opt) {
553
+ return this.defaultAfterAndBefore(item, opt);
554
+ }
555
+ /**
556
+ * Used to transform an object before processing it on the request
557
+ * @param {any} item An object coming from the outside
558
+ * @param {BaseCoreActionsInterface} opt Options
559
+ * @returns {any} transformed object
560
+ */
561
+ processItemOnIn(item, opt) {
562
+ return this.defaultAfterAndBefore(item, opt);
563
+ }
564
+ beforeGet(item, opt) {
565
+ return __awaiter(this, void 0, void 0, function* () {
566
+ return this.defaultAfterAndBefore(item, opt);
567
+ });
568
+ }
569
+ beforeGetMany(items, opt) {
570
+ return __awaiter(this, void 0, void 0, function* () {
571
+ return this.defaultAfterAndBefore(items, opt);
572
+ });
573
+ }
574
+ beforeList(filter, opt) {
575
+ return __awaiter(this, void 0, void 0, function* () {
576
+ return this.defaultAfterAndBefore(filter, opt);
577
+ });
578
+ }
579
+ afterGet(item, opt) {
580
+ return __awaiter(this, void 0, void 0, function* () {
581
+ return this.processItemOnOut(item, opt);
582
+ });
583
+ }
584
+ afterGetMany(items, opt) {
585
+ return __awaiter(this, void 0, void 0, function* () {
586
+ return items.map((item) => this.processItemOnOut(item, opt));
587
+ });
588
+ }
589
+ afterList(items, opt) {
590
+ return __awaiter(this, void 0, void 0, function* () {
591
+ return items.map((item) => this.processItemOnOut(item, opt));
592
+ });
593
+ }
594
+ beforeCreate(params, opt) {
595
+ return __awaiter(this, void 0, void 0, function* () {
596
+ return this.processItemOnIn(params, opt);
597
+ });
598
+ }
599
+ afterCreate(items, opt) {
600
+ return __awaiter(this, void 0, void 0, function* () {
601
+ return items.map((item) => this.processItemOnOut(item, opt));
602
+ });
603
+ }
604
+ beforeCreateMany(items, opt) {
605
+ return __awaiter(this, void 0, void 0, function* () {
606
+ return items.map((item) => this.processItemOnIn(item, opt));
607
+ });
608
+ }
609
+ afterCreateMany(items, opt) {
610
+ return __awaiter(this, void 0, void 0, function* () {
611
+ return items.map((item) => this.processItemOnOut(item, opt));
612
+ });
613
+ }
614
+ beforeUpdate(params, opt) {
615
+ return __awaiter(this, void 0, void 0, function* () {
616
+ return this.processItemOnIn(params, opt);
617
+ });
618
+ }
619
+ afterUpdate(items, opt) {
620
+ return __awaiter(this, void 0, void 0, function* () {
621
+ return items.map((item) => this.processItemOnOut(item, opt));
622
+ });
623
+ }
624
+ beforeUpdateMany(items, opt) {
625
+ return __awaiter(this, void 0, void 0, function* () {
626
+ return items.map((item) => {
627
+ return {
628
+ params: this.processItemOnIn(item.params, opt),
629
+ where: item.where,
630
+ };
631
+ });
632
+ });
633
+ }
634
+ afterUpdateMany(items, opt) {
635
+ return __awaiter(this, void 0, void 0, function* () {
636
+ return items.map((item) => this.processItemOnOut(item, opt));
637
+ });
638
+ }
639
+ beforeSet(params, opt) {
640
+ return __awaiter(this, void 0, void 0, function* () {
641
+ return castArray(params).map((item) => this.processItemOnIn(item, opt));
642
+ });
643
+ }
644
+ afterSet(items, opt) {
645
+ return __awaiter(this, void 0, void 0, function* () {
646
+ return items.map((item) => this.processItemOnOut(item, opt));
647
+ });
648
+ }
649
+ beforeRemove(params, opt) {
650
+ return __awaiter(this, void 0, void 0, function* () {
651
+ return this.defaultAfterAndBefore(params, opt);
652
+ });
653
+ }
654
+ afterRemove(items, opt) {
655
+ return __awaiter(this, void 0, void 0, function* () {
656
+ return items.map((item) => this.processItemOnOut(item, opt));
657
+ });
658
+ }
659
+ beforeRemoveMany(params, opt) {
660
+ return __awaiter(this, void 0, void 0, function* () {
661
+ return this.defaultAfterAndBefore(params, opt);
662
+ });
663
+ }
664
+ afterRemoveMany(items, opt) {
665
+ return __awaiter(this, void 0, void 0, function* () {
666
+ return items.map((item) => this.processItemOnOut(item, opt));
667
+ });
668
+ }
669
+ onException(params, opt) {
670
+ return __awaiter(this, void 0, void 0, function* () {
671
+ return '';
672
+ });
673
+ }
674
+ /**
675
+ * Returns JWT secret and its settings to verify received JWT token
676
+ * @param params Object of parameters passed to the authenticate method
677
+ * @returns Object with the jwtSecret and verifyTokenArgs
678
+ */
679
+ getJwtTokenSecretAndSettings(params) {
680
+ return __awaiter(this, void 0, void 0, function* () {
681
+ const { space } = this.getContext();
682
+ return {
683
+ jwtSecret: (space === null || space === void 0 ? void 0 : space.tokenSecret) || this.config.jwtSecret || '',
684
+ verifyTokenArgs: this.config.verifyTokenArgs,
685
+ };
686
+ });
687
+ }
688
+ findSpace() {
689
+ return __awaiter(this, void 0, void 0, function* () {
690
+ const { context } = this.config;
691
+ if (context.space) {
692
+ return [true, context.space];
693
+ }
694
+ let space = null;
695
+ if (context.spaceGw) {
696
+ if (!context.spaceId) {
697
+ return [false, 'Space not specified'];
698
+ }
699
+ // Lookup space in case we have gateway
700
+ space = yield context.spaceGw.get(context.spaceId || '');
701
+ if (!space) {
702
+ return [false, 'Space not found'];
703
+ }
704
+ context.space = space;
705
+ }
706
+ return [true, space];
707
+ });
708
+ }
709
+ extractCredentials(args) {
710
+ return __awaiter(this, void 0, void 0, function* () {
711
+ var _a, _b;
712
+ const { req, space, authorization } = args;
713
+ const token = ((_a = req.cookies) === null || _a === void 0 ? void 0 : _a[space.cookieName]) || authorization;
714
+ const fingerprint = ((_b = req.cookies) === null || _b === void 0 ? void 0 : _b[space.fingerprintCookieName]) || args.fingerprint || '';
715
+ return {
716
+ token,
717
+ fingerprint,
718
+ };
719
+ });
720
+ }
721
+ authenticate(params, opt) {
722
+ return __awaiter(this, void 0, void 0, function* () {
723
+ //const { accessRights } = params || {};
724
+ const context = this.getContext();
725
+ const { req, authorization } = context;
726
+ let authByToken = false;
727
+ const [spaceResult, space] = yield this.findSpace();
728
+ if (spaceResult !== true) {
729
+ return [spaceResult, space];
730
+ }
731
+ const { token, fingerprint } = yield this.extractCredentials({
732
+ req,
733
+ authorization,
734
+ fingerprint: context.fingerprint,
735
+ space,
736
+ params,
737
+ });
738
+ const { jwtSecret, verifyTokenArgs } = yield this.getJwtTokenSecretAndSettings(params);
739
+ if (token && jwtSecret) {
740
+ const verifyResult = verifyUserToken(token, jwtSecret, Object.assign(Object.assign({}, verifyTokenArgs), { algorithms: (verifyTokenArgs === null || verifyTokenArgs === void 0 ? void 0 : verifyTokenArgs.algorithms) || [getDefaultJwtAlgorithm()], audience: (verifyTokenArgs === null || verifyTokenArgs === void 0 ? void 0 : verifyTokenArgs.audience) || space.id, issuer: (verifyTokenArgs === null || verifyTokenArgs === void 0 ? void 0 : verifyTokenArgs.issuer) || getDefaultJwtIssuer(), fingerprint }));
741
+ if (verifyResult.didFail()) {
742
+ return [false, verifyResult.getErrorSummary('')];
743
+ }
744
+ const tokenData = verifyResult.getDataFirst();
745
+ context.accountId = tokenData.accountId;
746
+ context.roleId = tokenData.roleId;
747
+ context.userId = tokenData.userId;
748
+ context.isSuperAdmin = context.roleId === 'superadmin';
749
+ context.spaceId = context.spaceId || tokenData.spaceId;
750
+ context.lang = context.requestedLang || tokenData.lang;
751
+ authByToken = true;
752
+ }
753
+ if (!authByToken) {
754
+ if (this.config.interserviceApiKey && context.apiKey === this.config.interserviceApiKey) {
755
+ return [true, ''];
756
+ }
757
+ else if ((space === null || space === void 0 ? void 0 : space.apiKey) && (space === null || space === void 0 ? void 0 : space.apiKey) !== context.apiKey) {
758
+ return [false, 'API Key is invalid'];
759
+ }
760
+ }
761
+ return [true, ''];
762
+ });
763
+ }
764
+ processRemovedRecord(record) {
765
+ if (record && typeof record.id === 'string') {
766
+ record.id = record.id.split('~')[0];
767
+ }
768
+ return record;
769
+ }
770
+ addRemovedModifierToFields(fields) {
771
+ const obj = {};
772
+ if (!fields) {
773
+ this.logger.log(`The 'addRemovedModifierToFields' method expected its fields parameter to be a field name or an array of table field names but got:`, fields);
774
+ return obj;
775
+ }
776
+ castArray(fields).forEach((field) => {
777
+ obj[field] = this.getDb().raw(`${field} || '~removed~' || uuid_generate_v4()`);
778
+ });
779
+ return obj;
780
+ }
781
+ setOrderNo(args) {
782
+ return __awaiter(this, void 0, void 0, function* () {
783
+ var _a;
784
+ const { params, filter, gateway } = args || {};
785
+ if (typeof params !== 'object') {
786
+ throw new Error(`The 'setOrderNo' expected the parameter to have 'params' object but got: ${JSON.stringify(params)} `);
787
+ }
788
+ if (typeof gateway !== 'object') {
789
+ throw new Error(`The 'setOrderNo' expected the parameter to have 'gateway' object but got: ${JSON.stringify(gateway)} `);
790
+ }
791
+ if (typeof gateway.list !== 'function') {
792
+ throw new Error(`The 'setOrderNo' expected the 'gateway' object to have 'list' method but got: ${JSON.stringify(gateway.list)} `);
793
+ }
794
+ if (!params.orderNo) {
795
+ const lastRecord = yield gateway.list({
796
+ params: filter,
797
+ pagination: { pageSize: 1, sortBy: [{ name: FIELDS.ORDER_NO, order: ORDER_BYS.DESC }] },
798
+ });
799
+ if (lastRecord.length > 0) {
800
+ const order = new StrOrderHelpers({
801
+ start: ((_a = lastRecord[0]) === null || _a === void 0 ? void 0 : _a.orderNo) || DEFAULT_ORDER_NO,
802
+ step: DEFAULT_ORDER_NO_STEP,
803
+ });
804
+ params.orderNo = order.increase();
805
+ }
806
+ }
807
+ });
808
+ }
809
+ }
810
+ export { BaseCore };