@sdflc/backend-helpers 1.0.21 → 1.0.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.
- package/build/apiContext.d.ts +2 -2
- package/build/apiContext.js +122 -65
- package/build/baseCore.d.ts +7 -2
- package/build/baseCore.js +83 -37
- package/build/baseGateway.d.ts +9 -8
- package/build/baseGateway.js +141 -62
- package/build/baseGatewayHelpers.js +7 -6
- package/build/checkItHelpers.js +1 -1
- package/build/configBulder.js +4 -4
- package/build/constants.d.ts +5 -2
- package/build/constants.js +22 -36
- package/build/dataCache.js +1 -1
- package/build/database.js +2 -2
- package/build/dbHelpers.js +3 -3
- package/build/dbMigratorAndSeeder.js +10 -10
- package/build/dbSeeder.js +6 -6
- package/build/dbTableHelpers.d.ts +1 -2
- package/build/dbTableHelpers.js +9 -7
- package/build/index.d.ts +2 -1
- package/build/index.js +9 -1
- package/build/interfaces/BaseCoreInterface.d.ts +5 -0
- package/build/interfaces/BaseGatewayInterface.d.ts +2 -2
- package/build/interfaces/CreateUserTokenArgs.d.ts +0 -3
- package/build/interfaces/VerifyUserTokenArgs.d.ts +0 -2
- package/build/knexConfigBuilder.js +5 -5
- package/build/passwordHelpers.d.ts +5 -0
- package/build/passwordHelpers.js +76 -0
- package/build/resolversHelpers.js +11 -12
- package/build/userToken.d.ts +3 -3
- package/build/userToken.js +24 -19
- package/package.json +21 -19
package/build/apiContext.d.ts
CHANGED
|
@@ -3,9 +3,9 @@ import { ApiContextInterface } from './interfaces';
|
|
|
3
3
|
* Creates a GraphQL context object with all available cores.
|
|
4
4
|
* @returns {object} A context object with all available cores
|
|
5
5
|
*/
|
|
6
|
-
export declare const createApiContext: (args: ApiContextInterface) => any
|
|
6
|
+
export declare const createApiContext: (args: ApiContextInterface) => Promise<any>;
|
|
7
7
|
/**
|
|
8
8
|
* Creates default a GraphQL context object with all avilable cores.
|
|
9
9
|
* @returns {object} A context object with all available cores
|
|
10
10
|
*/
|
|
11
|
-
export declare const createContextDefault: (args: any) => any
|
|
11
|
+
export declare const createContextDefault: (args: any) => Promise<any>;
|
package/build/apiContext.js
CHANGED
|
@@ -10,6 +10,42 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
13
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
50
|
exports.createContextDefault = exports.createApiContext = void 0;
|
|
15
51
|
var lodash_1 = require("lodash");
|
|
@@ -20,75 +56,96 @@ var database_1 = require("./database");
|
|
|
20
56
|
* Creates a GraphQL context object with all available cores.
|
|
21
57
|
* @returns {object} A context object with all available cores
|
|
22
58
|
*/
|
|
23
|
-
var createApiContext = function (args) {
|
|
24
|
-
var _a
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
};
|
|
59
|
+
var createApiContext = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
|
60
|
+
var _a, cores, req, getCoreContext, extendContext, inRequestId, keys, requestId, coreContext, _b, context;
|
|
61
|
+
return __generator(this, function (_c) {
|
|
62
|
+
switch (_c.label) {
|
|
63
|
+
case 0:
|
|
64
|
+
_a = args || {}, cores = _a.cores, req = _a.req, getCoreContext = _a.getCoreContext, extendContext = _a.extendContext, inRequestId = _a.requestId;
|
|
65
|
+
keys = Object.keys(cores || {});
|
|
66
|
+
requestId = inRequestId || (0, uuid_1.v4)();
|
|
67
|
+
if (!(typeof getCoreContext === 'function')) return [3 /*break*/, 2];
|
|
68
|
+
return [4 /*yield*/, getCoreContext({ req: req })];
|
|
69
|
+
case 1:
|
|
70
|
+
_b = _c.sent();
|
|
71
|
+
return [3 /*break*/, 3];
|
|
72
|
+
case 2:
|
|
73
|
+
_b = {};
|
|
74
|
+
_c.label = 3;
|
|
75
|
+
case 3:
|
|
76
|
+
coreContext = _b;
|
|
77
|
+
context = keys.reduce(function (acc, key) {
|
|
78
|
+
acc[(0, lodash_1.camelCase)(key)] = new cores[key](__assign(__assign({}, coreContext), { requestId: requestId }));
|
|
79
|
+
return acc;
|
|
80
|
+
}, {});
|
|
81
|
+
context.requestId = requestId;
|
|
82
|
+
if (!(typeof extendContext === 'function')) return [3 /*break*/, 5];
|
|
83
|
+
return [4 /*yield*/, extendContext({ context: context, req: req })];
|
|
84
|
+
case 4:
|
|
85
|
+
_c.sent();
|
|
86
|
+
_c.label = 5;
|
|
87
|
+
case 5: return [2 /*return*/, context];
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}); };
|
|
38
91
|
exports.createApiContext = createApiContext;
|
|
39
92
|
/**
|
|
40
93
|
* Creates default a GraphQL context object with all avilable cores.
|
|
41
94
|
* @returns {object} A context object with all available cores
|
|
42
95
|
*/
|
|
43
|
-
var createContextDefault = function (args) {
|
|
44
|
-
var _a
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
96
|
+
var createContextDefault = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
|
97
|
+
var _a, knexConfig, dbSchema, cores, req, extendContext, getCoreContext, authorization, spaceId, apiKey, managementApiKey, accountId, roleId, userId, userAgent, referer, ipAddress, acceptLanguage, languages, requestedLang, requestId, db;
|
|
98
|
+
return __generator(this, function (_b) {
|
|
99
|
+
switch (_b.label) {
|
|
100
|
+
case 0:
|
|
101
|
+
_a = args || {}, knexConfig = _a.knexConfig, dbSchema = _a.dbSchema, cores = _a.cores, req = _a.req, extendContext = _a.extendContext, getCoreContext = _a.getCoreContext;
|
|
102
|
+
authorization = req.headers['authorization'] ? req.headers['authorization'].replace('Bearer ', '') : undefined;
|
|
103
|
+
spaceId = req.headers['x-space-id'];
|
|
104
|
+
apiKey = req.headers['x-api-key'];
|
|
105
|
+
managementApiKey = req.headers['x-management-api-key'];
|
|
106
|
+
accountId = req.headers['x-account-id'];
|
|
107
|
+
roleId = req.headers['x-role-id'];
|
|
108
|
+
userId = req.headers['x-user-id'];
|
|
109
|
+
userAgent = req.headers['user-agent'];
|
|
110
|
+
referer = req.headers['referer'];
|
|
111
|
+
ipAddress = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
|
|
112
|
+
acceptLanguage = req.headers['accept-language'];
|
|
113
|
+
languages = (0, utils_1.extractLanguages)(acceptLanguage);
|
|
114
|
+
requestedLang = req.query['lang'];
|
|
115
|
+
requestId = (0, uuid_1.v4)();
|
|
116
|
+
db = new database_1.Database({
|
|
117
|
+
knexConfig: knexConfig,
|
|
118
|
+
dbSchema: dbSchema,
|
|
119
|
+
});
|
|
120
|
+
return [4 /*yield*/, (0, exports.createApiContext)({
|
|
121
|
+
cores: cores,
|
|
122
|
+
req: req,
|
|
123
|
+
requestId: requestId,
|
|
124
|
+
extendContext: function (_a) {
|
|
125
|
+
var context = _a.context, req = _a.req;
|
|
126
|
+
context.db = db;
|
|
127
|
+
if (typeof extendContext === 'function') {
|
|
128
|
+
extendContext({ context: context, req: req });
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
getCoreContext: function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
|
132
|
+
var extendCoreConext;
|
|
133
|
+
return __generator(this, function (_a) {
|
|
134
|
+
switch (_a.label) {
|
|
135
|
+
case 0:
|
|
136
|
+
extendCoreConext = {};
|
|
137
|
+
if (!(typeof getCoreContext === 'function')) return [3 /*break*/, 2];
|
|
138
|
+
return [4 /*yield*/, getCoreContext(args)];
|
|
139
|
+
case 1:
|
|
140
|
+
extendCoreConext = _a.sent();
|
|
141
|
+
_a.label = 2;
|
|
142
|
+
case 2: return [2 /*return*/, __assign(__assign({ db: db }, extendCoreConext), { context: __assign({ spaceId: spaceId, apiKey: apiKey, managementApiKey: managementApiKey, userAgent: userAgent, referer: referer, ipAddress: ipAddress, acceptLanguage: acceptLanguage, languages: languages, requestedLang: requestedLang, authorization: authorization, accountId: accountId, roleId: roleId, userId: userId }, (extendCoreConext.context || {})) })];
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
}); },
|
|
146
|
+
})];
|
|
147
|
+
case 1: return [2 /*return*/, _b.sent()];
|
|
148
|
+
}
|
|
92
149
|
});
|
|
93
|
-
};
|
|
150
|
+
}); };
|
|
94
151
|
exports.createContextDefault = createContextDefault;
|
package/build/baseCore.d.ts
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
import { Logger } from '@sdflc/utils';
|
|
2
2
|
import { BaseCoreInterface, BaseCoreDoingWhatInterface, BaseCoreActionsInterface, CoreActionInterface, BaseCoreValidatorsInterface } from './interfaces';
|
|
3
|
+
import { VerifyUserTokenArgs } from './interfaces/VerifyUserTokenArgs';
|
|
3
4
|
import { BaseGateway } from './baseGateway';
|
|
4
5
|
import { Database } from './database';
|
|
5
6
|
declare class BaseCore {
|
|
6
7
|
protected props: BaseCoreInterface;
|
|
7
8
|
protected db: Database;
|
|
8
9
|
protected context: any;
|
|
9
|
-
protected gateway?: BaseGateway;
|
|
10
10
|
protected doingWhat?: BaseCoreDoingWhatInterface;
|
|
11
11
|
protected logger: Logger;
|
|
12
12
|
protected name?: string;
|
|
13
|
+
protected gateway?: BaseGateway;
|
|
13
14
|
protected gateways?: any;
|
|
15
|
+
protected gwSpace?: BaseGateway;
|
|
16
|
+
protected interserviceApiKey?: string;
|
|
17
|
+
protected jwtSecret: string;
|
|
18
|
+
protected verifytokenArgs?: VerifyUserTokenArgs;
|
|
14
19
|
protected requestId: string;
|
|
15
20
|
protected validators: BaseCoreValidatorsInterface;
|
|
16
21
|
protected doAuth: boolean;
|
|
@@ -52,6 +57,6 @@ declare class BaseCore {
|
|
|
52
57
|
beforeRemoveMany(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
53
58
|
afterRemoveMany(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
54
59
|
onException(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
55
|
-
authenticate(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
60
|
+
authenticate(params: any, opt?: BaseCoreActionsInterface): Promise<any[]>;
|
|
56
61
|
}
|
|
57
62
|
export { BaseCore };
|
package/build/baseCore.js
CHANGED
|
@@ -46,16 +46,13 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
46
46
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
-
};
|
|
52
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
50
|
exports.BaseCore = void 0;
|
|
54
51
|
var api_helpers_1 = require("@sdflc/api-helpers");
|
|
55
52
|
var utils_1 = require("@sdflc/utils");
|
|
53
|
+
var userToken_1 = require("./userToken");
|
|
54
|
+
var baseGateway_1 = require("./baseGateway");
|
|
56
55
|
var utils_2 = require("./utils");
|
|
57
|
-
var constants_1 = __importDefault(require("./constants"));
|
|
58
|
-
var ACCESS_RIGHTS = constants_1.default.ACCESS_RIGHTS;
|
|
59
56
|
var defaultAfterAndBefore = function (params, opt) {
|
|
60
57
|
return params;
|
|
61
58
|
};
|
|
@@ -74,21 +71,32 @@ var defaultValidators = {
|
|
|
74
71
|
remove: defaultValidate,
|
|
75
72
|
removeMany: defaultValidate,
|
|
76
73
|
};
|
|
77
|
-
var defaultAuth = function (params) {
|
|
78
|
-
return [true, ''];
|
|
79
|
-
};
|
|
80
74
|
var BaseCore = /** @class */ (function () {
|
|
81
75
|
function BaseCore(props) {
|
|
76
|
+
var _this = this;
|
|
82
77
|
this.validators = defaultValidators;
|
|
83
78
|
this.props = props || {};
|
|
84
79
|
this.db = props.db;
|
|
85
80
|
this.name = props.name || '';
|
|
86
81
|
this.context = props.context || {};
|
|
87
|
-
this.gateway = props.gateway;
|
|
88
82
|
this.doingWhat = props.doingWhat;
|
|
89
83
|
this.logger = props.logger || new utils_1.Logger({ level: props.logLevel });
|
|
84
|
+
this.gateway = props.gateway;
|
|
90
85
|
this.gateways = __assign({ gateway: this.gateway }, (props.gateways || {}));
|
|
91
|
-
this.
|
|
86
|
+
if (this.gateway instanceof baseGateway_1.BaseGateway) {
|
|
87
|
+
this.gateway.setCore(this);
|
|
88
|
+
}
|
|
89
|
+
Object.keys(this.gateways).forEach(function (gatewayName) {
|
|
90
|
+
var gateway = _this.gateways[gatewayName];
|
|
91
|
+
if (gateway instanceof baseGateway_1.BaseGateway) {
|
|
92
|
+
gateway.setCore(_this);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
this.gwSpace = props.gwSpace;
|
|
96
|
+
this.interserviceApiKey = props.interserviceApiKey;
|
|
97
|
+
this.jwtSecret = props.jwtSecret || '';
|
|
98
|
+
this.verifytokenArgs = props.verifytokenArgs;
|
|
99
|
+
this.validators = (0, utils_2.setFunctions)((props === null || props === void 0 ? void 0 : props.validators) || {}, this.validators);
|
|
92
100
|
this.doAuth = props.doAuth === true;
|
|
93
101
|
this.requestId = props.requestId || '';
|
|
94
102
|
}
|
|
@@ -137,7 +145,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
137
145
|
var _a = this.getDb().isDbError(ex), isDbError = _a[0], dbErrorMsg = _a[1];
|
|
138
146
|
var isOpResult = typeof ex.getErrorSummary === 'function';
|
|
139
147
|
var message = isOpResult ? ex.getErrorSummary() : ex.message;
|
|
140
|
-
var sysMsg = "An exception has occurred on "
|
|
148
|
+
var sysMsg = "An exception has occurred on ".concat(doingWhat, " with message ").concat(message, ":");
|
|
141
149
|
var msg = '';
|
|
142
150
|
if (isDbError) {
|
|
143
151
|
msg = dbErrorMsg;
|
|
@@ -147,7 +155,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
147
155
|
msg = doingWhat['message'];
|
|
148
156
|
}
|
|
149
157
|
else {
|
|
150
|
-
msg = "Sorry, something went wrong on "
|
|
158
|
+
msg = isOpResult ? ex.getErrorSummary() : "Sorry, something went wrong on ".concat(doingWhat);
|
|
151
159
|
}
|
|
152
160
|
this.logger.error(sysMsg, ex);
|
|
153
161
|
}
|
|
@@ -256,7 +264,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
256
264
|
what = doingWhat;
|
|
257
265
|
if (doingWhat !== step) {
|
|
258
266
|
what = {
|
|
259
|
-
message: step
|
|
267
|
+
message: "".concat(step, " failed on ").concat(doingWhat),
|
|
260
268
|
};
|
|
261
269
|
}
|
|
262
270
|
return [2 /*return*/, this.exceptionFailure(ex_1, what)];
|
|
@@ -273,14 +281,14 @@ var BaseCore = /** @class */ (function () {
|
|
|
273
281
|
return [2 /*return*/, this.runAction({
|
|
274
282
|
args: args,
|
|
275
283
|
validate: this.validators.list,
|
|
276
|
-
accessRights: [ACCESS_RIGHTS.LIST],
|
|
284
|
+
accessRights: [utils_1.ACCESS_RIGHTS.LIST],
|
|
277
285
|
action: function (args, opt) { return __awaiter(_this, void 0, void 0, function () {
|
|
278
286
|
var object, items, result;
|
|
279
287
|
var _a;
|
|
280
288
|
return __generator(this, function (_b) {
|
|
281
289
|
switch (_b.label) {
|
|
282
290
|
case 0:
|
|
283
|
-
this.logger.log("Requesting a list for "
|
|
291
|
+
this.logger.log("Requesting a list for ".concat(this.name, ":"), args);
|
|
284
292
|
return [4 /*yield*/, this.beforeList(args, opt)];
|
|
285
293
|
case 1:
|
|
286
294
|
object = _b.sent();
|
|
@@ -309,7 +317,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
309
317
|
return [2 /*return*/, this.runAction({
|
|
310
318
|
args: args,
|
|
311
319
|
validate: this.validators.get,
|
|
312
|
-
accessRights: [ACCESS_RIGHTS.GET],
|
|
320
|
+
accessRights: [utils_1.ACCESS_RIGHTS.GET],
|
|
313
321
|
action: function (args) { return __awaiter(_this, void 0, void 0, function () {
|
|
314
322
|
var id, item;
|
|
315
323
|
var _a;
|
|
@@ -317,7 +325,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
317
325
|
switch (_b.label) {
|
|
318
326
|
case 0:
|
|
319
327
|
id = (args || {}).id;
|
|
320
|
-
this.logger.log("Requesting an item for "
|
|
328
|
+
this.logger.log("Requesting an item for ".concat(this.name, ":"), args);
|
|
321
329
|
return [4 /*yield*/, ((_a = this.gateway) === null || _a === void 0 ? void 0 : _a.get(id))];
|
|
322
330
|
case 1:
|
|
323
331
|
item = _b.sent();
|
|
@@ -339,7 +347,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
339
347
|
return [2 /*return*/, this.runAction({
|
|
340
348
|
args: args,
|
|
341
349
|
validate: this.validators.getMany,
|
|
342
|
-
accessRights: [ACCESS_RIGHTS.GET],
|
|
350
|
+
accessRights: [utils_1.ACCESS_RIGHTS.GET],
|
|
343
351
|
action: function (args) { return __awaiter(_this, void 0, void 0, function () {
|
|
344
352
|
var ids, items;
|
|
345
353
|
var _a;
|
|
@@ -347,7 +355,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
347
355
|
switch (_b.label) {
|
|
348
356
|
case 0:
|
|
349
357
|
ids = (args || {}).ids;
|
|
350
|
-
this.logger.log("Requesting multiple items for "
|
|
358
|
+
this.logger.log("Requesting multiple items for ".concat(this.name, ":"), args);
|
|
351
359
|
return [4 /*yield*/, ((_a = this.gateway) === null || _a === void 0 ? void 0 : _a.getMany(ids))];
|
|
352
360
|
case 1:
|
|
353
361
|
items = _b.sent();
|
|
@@ -369,7 +377,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
369
377
|
return [2 /*return*/, this.runAction({
|
|
370
378
|
args: args,
|
|
371
379
|
validate: this.validators.create,
|
|
372
|
-
accessRights: [ACCESS_RIGHTS.CREATE],
|
|
380
|
+
accessRights: [utils_1.ACCESS_RIGHTS.CREATE],
|
|
373
381
|
action: function (args, opt) { return __awaiter(_this, void 0, void 0, function () {
|
|
374
382
|
var params, object, item, result;
|
|
375
383
|
var _a;
|
|
@@ -377,7 +385,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
377
385
|
switch (_b.label) {
|
|
378
386
|
case 0:
|
|
379
387
|
params = (args || {}).params;
|
|
380
|
-
this.logger.log("Requesting creation of an item for "
|
|
388
|
+
this.logger.log("Requesting creation of an item for ".concat(this.name, ":"), args);
|
|
381
389
|
return [4 /*yield*/, this.beforeCreate(params, opt)];
|
|
382
390
|
case 1:
|
|
383
391
|
object = _b.sent();
|
|
@@ -405,7 +413,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
405
413
|
return [2 /*return*/, this.runAction({
|
|
406
414
|
args: args,
|
|
407
415
|
validate: this.validators.createMany,
|
|
408
|
-
accessRights: [ACCESS_RIGHTS.CREATE],
|
|
416
|
+
accessRights: [utils_1.ACCESS_RIGHTS.CREATE],
|
|
409
417
|
action: function (args, opt) { return __awaiter(_this, void 0, void 0, function () {
|
|
410
418
|
var params, objects, items, result;
|
|
411
419
|
var _a;
|
|
@@ -413,7 +421,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
413
421
|
switch (_b.label) {
|
|
414
422
|
case 0:
|
|
415
423
|
params = (args || {}).params;
|
|
416
|
-
this.logger.log("Requesting creation of multiple items for "
|
|
424
|
+
this.logger.log("Requesting creation of multiple items for ".concat(this.name, ":"), args);
|
|
417
425
|
return [4 /*yield*/, this.beforeCreateMany(params, opt)];
|
|
418
426
|
case 1:
|
|
419
427
|
objects = _b.sent();
|
|
@@ -441,7 +449,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
441
449
|
return [2 /*return*/, this.runAction({
|
|
442
450
|
args: args,
|
|
443
451
|
validate: this.validators.update,
|
|
444
|
-
accessRights: [ACCESS_RIGHTS.UPDATE],
|
|
452
|
+
accessRights: [utils_1.ACCESS_RIGHTS.UPDATE],
|
|
445
453
|
action: function (args, opt) { return __awaiter(_this, void 0, void 0, function () {
|
|
446
454
|
var _a, where, params, object, item, result;
|
|
447
455
|
var _b;
|
|
@@ -449,7 +457,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
449
457
|
switch (_c.label) {
|
|
450
458
|
case 0:
|
|
451
459
|
_a = args || {}, where = _a.where, params = _a.params;
|
|
452
|
-
this.logger.log("Requesting update of an item for "
|
|
460
|
+
this.logger.log("Requesting update of an item for ".concat(this.name, ":"), args);
|
|
453
461
|
return [4 /*yield*/, this.beforeUpdate(params, opt)];
|
|
454
462
|
case 1:
|
|
455
463
|
object = _c.sent();
|
|
@@ -477,7 +485,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
477
485
|
return [2 /*return*/, this.runAction({
|
|
478
486
|
args: args,
|
|
479
487
|
validate: this.validators.updateMany,
|
|
480
|
-
accessRights: [ACCESS_RIGHTS.UPDATE],
|
|
488
|
+
accessRights: [utils_1.ACCESS_RIGHTS.UPDATE],
|
|
481
489
|
action: function (args, opt) { return __awaiter(_this, void 0, void 0, function () {
|
|
482
490
|
var params, object, items, result;
|
|
483
491
|
var _a;
|
|
@@ -485,7 +493,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
485
493
|
switch (_b.label) {
|
|
486
494
|
case 0:
|
|
487
495
|
params = (args || {}).params;
|
|
488
|
-
this.logger.log("Requesting update of an item for "
|
|
496
|
+
this.logger.log("Requesting update of an item for ".concat(this.name, ":"), args);
|
|
489
497
|
return [4 /*yield*/, this.beforeUpdateMany(params, opt)];
|
|
490
498
|
case 1:
|
|
491
499
|
object = _b.sent();
|
|
@@ -513,7 +521,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
513
521
|
return [2 /*return*/, this.runAction({
|
|
514
522
|
args: args,
|
|
515
523
|
validate: this.validators.set,
|
|
516
|
-
accessRights: [ACCESS_RIGHTS.CREATE, ACCESS_RIGHTS.UPDATE],
|
|
524
|
+
accessRights: [utils_1.ACCESS_RIGHTS.CREATE, utils_1.ACCESS_RIGHTS.UPDATE],
|
|
517
525
|
action: function (args, opt /* { setStep, validatedItems, sameRequest } */) { return __awaiter(_this, void 0, void 0, function () {
|
|
518
526
|
var params, object, items, result;
|
|
519
527
|
var _a;
|
|
@@ -521,7 +529,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
521
529
|
switch (_b.label) {
|
|
522
530
|
case 0:
|
|
523
531
|
params = (args || {}).params;
|
|
524
|
-
this.logger.log("Requesting setting of item(s) for "
|
|
532
|
+
this.logger.log("Requesting setting of item(s) for ".concat(this.name, ":"), args);
|
|
525
533
|
return [4 /*yield*/, this.beforeSet(params, opt)];
|
|
526
534
|
case 1:
|
|
527
535
|
object = _b.sent();
|
|
@@ -549,7 +557,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
549
557
|
return [2 /*return*/, this.runAction({
|
|
550
558
|
args: args,
|
|
551
559
|
validate: this.validators.remove,
|
|
552
|
-
accessRights: [ACCESS_RIGHTS.REMOVE],
|
|
560
|
+
accessRights: [utils_1.ACCESS_RIGHTS.REMOVE],
|
|
553
561
|
action: function (args, opt) { return __awaiter(_this, void 0, void 0, function () {
|
|
554
562
|
var where, object, items, result;
|
|
555
563
|
var _a;
|
|
@@ -557,7 +565,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
557
565
|
switch (_b.label) {
|
|
558
566
|
case 0:
|
|
559
567
|
where = (args || {}).where;
|
|
560
|
-
this.logger.log("Requesting removal of an item for "
|
|
568
|
+
this.logger.log("Requesting removal of an item for ".concat(this.name, ":"), args);
|
|
561
569
|
return [4 /*yield*/, this.beforeRemove(where, opt)];
|
|
562
570
|
case 1:
|
|
563
571
|
object = _b.sent();
|
|
@@ -585,7 +593,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
585
593
|
return [2 /*return*/, this.runAction({
|
|
586
594
|
args: args,
|
|
587
595
|
validate: this.validators.removeMany,
|
|
588
|
-
accessRights: [ACCESS_RIGHTS.REMOVE],
|
|
596
|
+
accessRights: [utils_1.ACCESS_RIGHTS.REMOVE],
|
|
589
597
|
action: function (args, opt) { return __awaiter(_this, void 0, void 0, function () {
|
|
590
598
|
var where, object, items, result;
|
|
591
599
|
var _a;
|
|
@@ -593,7 +601,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
593
601
|
switch (_b.label) {
|
|
594
602
|
case 0:
|
|
595
603
|
where = (args || {}).where;
|
|
596
|
-
this.logger.log("Requesting removal of multiple items for "
|
|
604
|
+
this.logger.log("Requesting removal of multiple items for ".concat(this.name, ":"), args);
|
|
597
605
|
return [4 /*yield*/, this.beforeRemoveMany(where, opt)];
|
|
598
606
|
case 1:
|
|
599
607
|
object = _b.sent();
|
|
@@ -767,11 +775,49 @@ var BaseCore = /** @class */ (function () {
|
|
|
767
775
|
});
|
|
768
776
|
};
|
|
769
777
|
BaseCore.prototype.authenticate = function (params, opt) {
|
|
778
|
+
var _a;
|
|
770
779
|
return __awaiter(this, void 0, void 0, function () {
|
|
771
|
-
var
|
|
772
|
-
return __generator(this, function (
|
|
773
|
-
|
|
774
|
-
|
|
780
|
+
var context, authByToken, verifyResult, token, space;
|
|
781
|
+
return __generator(this, function (_b) {
|
|
782
|
+
switch (_b.label) {
|
|
783
|
+
case 0:
|
|
784
|
+
if (!(typeof this.props.authenticate === 'function')) return [3 /*break*/, 2];
|
|
785
|
+
return [4 /*yield*/, this.props.authenticate(params, opt)];
|
|
786
|
+
case 1:
|
|
787
|
+
// if we have an auth function passed to constructor then use it for the authentication
|
|
788
|
+
return [2 /*return*/, _b.sent()];
|
|
789
|
+
case 2:
|
|
790
|
+
context = this.context;
|
|
791
|
+
authByToken = false;
|
|
792
|
+
if (context.authorization && this.jwtSecret) {
|
|
793
|
+
verifyResult = (0, userToken_1.verifyUserToken)(context.authorization, this.jwtSecret, this.verifytokenArgs);
|
|
794
|
+
if (verifyResult.didFail()) {
|
|
795
|
+
return [2 /*return*/, [false, verifyResult.getErrorSummary('')]];
|
|
796
|
+
}
|
|
797
|
+
token = verifyResult.getDataFirst();
|
|
798
|
+
context.accountId = token.accountId;
|
|
799
|
+
context.roleId = token.roleId;
|
|
800
|
+
context.userId = token.userId;
|
|
801
|
+
context.spaceId = token.spaceId || context.spaceId;
|
|
802
|
+
authByToken = true;
|
|
803
|
+
}
|
|
804
|
+
return [4 /*yield*/, ((_a = this.gwSpace) === null || _a === void 0 ? void 0 : _a.get(context.spaceId || ''))];
|
|
805
|
+
case 3:
|
|
806
|
+
space = _b.sent();
|
|
807
|
+
if (!space) {
|
|
808
|
+
return [2 /*return*/, [false, 'Space Not Found']];
|
|
809
|
+
}
|
|
810
|
+
context.space = space;
|
|
811
|
+
if (!authByToken) {
|
|
812
|
+
if (this.interserviceApiKey && context.apiKey === this.interserviceApiKey) {
|
|
813
|
+
return [2 /*return*/, [true, '']];
|
|
814
|
+
}
|
|
815
|
+
else if (space.apiKey && space.apiKey !== context.apiKey) {
|
|
816
|
+
return [2 /*return*/, [false, 'API Key is invalid']];
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
return [2 /*return*/, [true, '']];
|
|
820
|
+
}
|
|
775
821
|
});
|
|
776
822
|
});
|
|
777
823
|
};
|
package/build/baseGateway.d.ts
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { BaseGatewayInterface, ListArgsInterface } from './interfaces';
|
|
2
|
-
import { BaseCore } from '
|
|
2
|
+
import { BaseCore } from './baseCore';
|
|
3
3
|
declare class BaseGateway {
|
|
4
4
|
protected config: BaseGatewayInterface;
|
|
5
5
|
protected loader: any;
|
|
6
|
-
protected idGenerator: any;
|
|
7
|
-
protected insertFormatter: any;
|
|
8
|
-
protected updateFormatter: any;
|
|
9
|
-
protected removeFormatter: any;
|
|
10
|
-
protected updateFilter: any;
|
|
11
|
-
protected removeFilter: any;
|
|
12
6
|
protected returnFields: any[];
|
|
13
7
|
constructor(props: BaseGatewayInterface);
|
|
8
|
+
generateId(args?: any): Promise<any>;
|
|
9
|
+
onListFilter(query: any, filterParams: any): Promise<void>;
|
|
10
|
+
onUpdateFilter(query: any, filterParams: any): Promise<void>;
|
|
11
|
+
onRemoveFilter(query: any, filterParams: any): Promise<void>;
|
|
12
|
+
transformOnCreate(args: any): Promise<any>;
|
|
13
|
+
transformOnUpdate(params: any, where?: any): Promise<any>;
|
|
14
|
+
transformOnRemove(args?: any): Promise<any>;
|
|
14
15
|
getDb(): import("./database").Database;
|
|
15
16
|
getBuilder(): any;
|
|
16
17
|
getIdField(): any;
|
|
17
|
-
getCore(): BaseCore;
|
|
18
|
+
getCore(): BaseCore | undefined;
|
|
18
19
|
setCore(core: BaseCore): void;
|
|
19
20
|
get(id: any): Promise<any>;
|
|
20
21
|
getMany(ids: any[]): Promise<any>;
|