@flowerforce/flowerbase 1.0.1-beta.3
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/CHANGELOG.md +0 -0
- package/LICENSE +3 -0
- package/README.md +18 -0
- package/dist/auth/controller.d.ts +8 -0
- package/dist/auth/controller.d.ts.map +1 -0
- package/dist/auth/controller.js +76 -0
- package/dist/auth/dtos.d.ts +6 -0
- package/dist/auth/dtos.d.ts.map +1 -0
- package/dist/auth/dtos.js +2 -0
- package/dist/auth/plugins/jwt.d.ts +14 -0
- package/dist/auth/plugins/jwt.d.ts.map +1 -0
- package/dist/auth/plugins/jwt.js +68 -0
- package/dist/auth/providers/local-userpass/controller.d.ts +8 -0
- package/dist/auth/providers/local-userpass/controller.d.ts.map +1 -0
- package/dist/auth/providers/local-userpass/controller.js +184 -0
- package/dist/auth/providers/local-userpass/dtos.d.ts +35 -0
- package/dist/auth/providers/local-userpass/dtos.d.ts.map +1 -0
- package/dist/auth/providers/local-userpass/dtos.js +2 -0
- package/dist/auth/utils.d.ts +126 -0
- package/dist/auth/utils.d.ts.map +1 -0
- package/dist/auth/utils.js +122 -0
- package/dist/constants.d.ts +18 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +34 -0
- package/dist/features/endpoints/index.d.ts +10 -0
- package/dist/features/endpoints/index.d.ts.map +1 -0
- package/dist/features/endpoints/index.js +31 -0
- package/dist/features/endpoints/interface.d.ts +27 -0
- package/dist/features/endpoints/interface.d.ts.map +1 -0
- package/dist/features/endpoints/interface.js +2 -0
- package/dist/features/endpoints/utils.d.ts +31 -0
- package/dist/features/endpoints/utils.d.ts.map +1 -0
- package/dist/features/endpoints/utils.js +85 -0
- package/dist/features/functions/controller.d.ts +9 -0
- package/dist/features/functions/controller.d.ts.map +1 -0
- package/dist/features/functions/controller.js +88 -0
- package/dist/features/functions/dtos.d.ts +34 -0
- package/dist/features/functions/dtos.d.ts.map +1 -0
- package/dist/features/functions/dtos.js +2 -0
- package/dist/features/functions/index.d.ts +9 -0
- package/dist/features/functions/index.d.ts.map +1 -0
- package/dist/features/functions/index.js +28 -0
- package/dist/features/functions/interface.d.ts +32 -0
- package/dist/features/functions/interface.d.ts.map +1 -0
- package/dist/features/functions/interface.js +2 -0
- package/dist/features/functions/utils.d.ts +23 -0
- package/dist/features/functions/utils.d.ts.map +1 -0
- package/dist/features/functions/utils.js +75 -0
- package/dist/features/rules/index.d.ts +1 -0
- package/dist/features/rules/index.d.ts.map +1 -0
- package/dist/features/rules/index.js +1 -0
- package/dist/features/rules/interface.d.ts +22 -0
- package/dist/features/rules/interface.d.ts.map +1 -0
- package/dist/features/rules/interface.js +2 -0
- package/dist/features/rules/utils.d.ts +3 -0
- package/dist/features/rules/utils.d.ts.map +1 -0
- package/dist/features/rules/utils.js +31 -0
- package/dist/features/triggers/dtos.d.ts +9 -0
- package/dist/features/triggers/dtos.d.ts.map +1 -0
- package/dist/features/triggers/dtos.js +2 -0
- package/dist/features/triggers/index.d.ts +10 -0
- package/dist/features/triggers/index.d.ts.map +1 -0
- package/dist/features/triggers/index.js +57 -0
- package/dist/features/triggers/interface.d.ts +44 -0
- package/dist/features/triggers/interface.d.ts.map +1 -0
- package/dist/features/triggers/interface.js +2 -0
- package/dist/features/triggers/utils.d.ts +16 -0
- package/dist/features/triggers/utils.d.ts.map +1 -0
- package/dist/features/triggers/utils.js +153 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +84 -0
- package/dist/model.d.ts +2 -0
- package/dist/model.d.ts.map +1 -0
- package/dist/model.js +2 -0
- package/dist/services/api/index.d.ts +36 -0
- package/dist/services/api/index.d.ts.map +1 -0
- package/dist/services/api/index.js +36 -0
- package/dist/services/api/model.d.ts +33 -0
- package/dist/services/api/model.d.ts.map +1 -0
- package/dist/services/api/model.js +2 -0
- package/dist/services/api/utils.d.ts +16 -0
- package/dist/services/api/utils.d.ts.map +1 -0
- package/dist/services/api/utils.js +45 -0
- package/dist/services/aws/index.d.ts +13 -0
- package/dist/services/aws/index.d.ts.map +1 -0
- package/dist/services/aws/index.js +50 -0
- package/dist/services/index.d.ts +41 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +14 -0
- package/dist/services/interface.d.ts +3 -0
- package/dist/services/interface.d.ts.map +1 -0
- package/dist/services/interface.js +2 -0
- package/dist/services/mongodb-atlas/index.d.ts +4 -0
- package/dist/services/mongodb-atlas/index.d.ts.map +1 -0
- package/dist/services/mongodb-atlas/index.js +483 -0
- package/dist/services/mongodb-atlas/model.d.ts +39 -0
- package/dist/services/mongodb-atlas/model.d.ts.map +1 -0
- package/dist/services/mongodb-atlas/model.js +2 -0
- package/dist/services/mongodb-atlas/utils.d.ts +8 -0
- package/dist/services/mongodb-atlas/utils.d.ts.map +1 -0
- package/dist/services/mongodb-atlas/utils.js +33 -0
- package/dist/state.d.ts +6 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +18 -0
- package/dist/utils/context/helpers.d.ts +74 -0
- package/dist/utils/context/helpers.d.ts.map +1 -0
- package/dist/utils/context/helpers.js +60 -0
- package/dist/utils/context/index.d.ts +14 -0
- package/dist/utils/context/index.d.ts.map +1 -0
- package/dist/utils/context/index.js +50 -0
- package/dist/utils/context/interface.d.ts +18 -0
- package/dist/utils/context/interface.d.ts.map +1 -0
- package/dist/utils/context/interface.js +2 -0
- package/dist/utils/crypto/index.d.ts +19 -0
- package/dist/utils/crypto/index.d.ts.map +1 -0
- package/dist/utils/crypto/index.js +50 -0
- package/dist/utils/helpers/someAsync.d.ts +12 -0
- package/dist/utils/helpers/someAsync.d.ts.map +1 -0
- package/dist/utils/helpers/someAsync.js +56 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +11 -0
- package/dist/utils/initializer/exposeRoutes.d.ts +8 -0
- package/dist/utils/initializer/exposeRoutes.d.ts.map +1 -0
- package/dist/utils/initializer/exposeRoutes.js +41 -0
- package/dist/utils/initializer/registerPlugins.d.ts +19 -0
- package/dist/utils/initializer/registerPlugins.d.ts.map +1 -0
- package/dist/utils/initializer/registerPlugins.js +84 -0
- package/dist/utils/roles/helpers.d.ts +4 -0
- package/dist/utils/roles/helpers.d.ts.map +1 -0
- package/dist/utils/roles/helpers.js +47 -0
- package/dist/utils/roles/interface.d.ts +33 -0
- package/dist/utils/roles/interface.d.ts.map +1 -0
- package/dist/utils/roles/interface.js +2 -0
- package/dist/utils/roles/machines/commonValidators.d.ts +6 -0
- package/dist/utils/roles/machines/commonValidators.d.ts.map +1 -0
- package/dist/utils/roles/machines/commonValidators.js +34 -0
- package/dist/utils/roles/machines/index.d.ts +14 -0
- package/dist/utils/roles/machines/index.d.ts.map +1 -0
- package/dist/utils/roles/machines/index.js +27 -0
- package/dist/utils/roles/machines/interface.d.ts +46 -0
- package/dist/utils/roles/machines/interface.d.ts.map +1 -0
- package/dist/utils/roles/machines/interface.js +2 -0
- package/dist/utils/roles/machines/machine.d.ts +15 -0
- package/dist/utils/roles/machines/machine.d.ts.map +1 -0
- package/dist/utils/roles/machines/machine.js +97 -0
- package/dist/utils/roles/machines/read/A/index.d.ts +3 -0
- package/dist/utils/roles/machines/read/A/index.d.ts.map +1 -0
- package/dist/utils/roles/machines/read/A/index.js +27 -0
- package/dist/utils/roles/machines/read/B/index.d.ts +3 -0
- package/dist/utils/roles/machines/read/B/index.d.ts.map +1 -0
- package/dist/utils/roles/machines/read/B/index.js +36 -0
- package/dist/utils/roles/machines/read/C/index.d.ts +3 -0
- package/dist/utils/roles/machines/read/C/index.d.ts.map +1 -0
- package/dist/utils/roles/machines/read/C/index.js +38 -0
- package/dist/utils/roles/machines/read/D/index.d.ts +3 -0
- package/dist/utils/roles/machines/read/D/index.d.ts.map +1 -0
- package/dist/utils/roles/machines/read/D/index.js +26 -0
- package/dist/utils/roles/machines/read/D/validators.d.ts +4 -0
- package/dist/utils/roles/machines/read/D/validators.d.ts.map +1 -0
- package/dist/utils/roles/machines/read/D/validators.js +24 -0
- package/dist/utils/roles/machines/read/index.d.ts +2 -0
- package/dist/utils/roles/machines/read/index.d.ts.map +1 -0
- package/dist/utils/roles/machines/read/index.js +8 -0
- package/dist/utils/roles/machines/utils.d.ts +37 -0
- package/dist/utils/roles/machines/utils.d.ts.map +1 -0
- package/dist/utils/roles/machines/utils.js +54 -0
- package/dist/utils/roles/machines/write/A/index.d.ts +3 -0
- package/dist/utils/roles/machines/write/A/index.d.ts.map +1 -0
- package/dist/utils/roles/machines/write/A/index.js +29 -0
- package/dist/utils/roles/machines/write/B/index.d.ts +3 -0
- package/dist/utils/roles/machines/write/B/index.d.ts.map +1 -0
- package/dist/utils/roles/machines/write/B/index.js +47 -0
- package/dist/utils/roles/machines/write/C/index.d.ts +3 -0
- package/dist/utils/roles/machines/write/C/index.d.ts.map +1 -0
- package/dist/utils/roles/machines/write/C/index.js +26 -0
- package/dist/utils/roles/machines/write/C/validators.d.ts +4 -0
- package/dist/utils/roles/machines/write/C/validators.d.ts.map +1 -0
- package/dist/utils/roles/machines/write/C/validators.js +24 -0
- package/dist/utils/roles/machines/write/index.d.ts +2 -0
- package/dist/utils/roles/machines/write/index.d.ts.map +1 -0
- package/dist/utils/roles/machines/write/index.js +7 -0
- package/dist/utils/rules-matcher/interface.d.ts +338 -0
- package/dist/utils/rules-matcher/interface.d.ts.map +1 -0
- package/dist/utils/rules-matcher/interface.js +26 -0
- package/dist/utils/rules-matcher/utils.d.ts +11 -0
- package/dist/utils/rules-matcher/utils.d.ts.map +1 -0
- package/dist/utils/rules-matcher/utils.js +214 -0
- package/dist/utils/rules.d.ts +2 -0
- package/dist/utils/rules.d.ts.map +1 -0
- package/dist/utils/rules.js +22 -0
- package/jest.config.ts +24 -0
- package/package.json +63 -0
- package/project.json +10 -0
- package/rollup.config.js +17 -0
- package/src/auth/controller.ts +78 -0
- package/src/auth/dtos.ts +6 -0
- package/src/auth/plugins/jwt.ts +68 -0
- package/src/auth/providers/local-userpass/controller.ts +226 -0
- package/src/auth/providers/local-userpass/dtos.ts +40 -0
- package/src/auth/utils.ts +165 -0
- package/src/babel.config.json +3 -0
- package/src/constants.ts +22 -0
- package/src/fastify.d.ts +28 -0
- package/src/features/endpoints/index.ts +27 -0
- package/src/features/endpoints/interface.ts +29 -0
- package/src/features/endpoints/utils.ts +72 -0
- package/src/features/functions/controller.ts +102 -0
- package/src/features/functions/dtos.ts +41 -0
- package/src/features/functions/index.ts +21 -0
- package/src/features/functions/interface.ts +38 -0
- package/src/features/functions/utils.ts +82 -0
- package/src/features/rules/index.tsx +0 -0
- package/src/features/rules/interface.ts +24 -0
- package/src/features/rules/utils.ts +20 -0
- package/src/features/triggers/dtos.ts +9 -0
- package/src/features/triggers/index.ts +34 -0
- package/src/features/triggers/interface.ts +44 -0
- package/src/features/triggers/utils.ts +157 -0
- package/src/global.d.ts +0 -0
- package/src/index.ts +75 -0
- package/src/model.ts +1 -0
- package/src/services/api/index.ts +50 -0
- package/src/services/api/model.ts +38 -0
- package/src/services/api/utils.ts +39 -0
- package/src/services/aws/index.ts +48 -0
- package/src/services/index.ts +9 -0
- package/src/services/interface.ts +3 -0
- package/src/services/mongodb-atlas/index.ts +569 -0
- package/src/services/mongodb-atlas/model.ts +67 -0
- package/src/services/mongodb-atlas/utils.ts +44 -0
- package/src/state.ts +24 -0
- package/src/utils/__tests__/STEP_A_STATES.test.ts +54 -0
- package/src/utils/__tests__/STEP_B_STATES.test.ts +113 -0
- package/src/utils/__tests__/STEP_C_STATES.test.ts +87 -0
- package/src/utils/__tests__/STEP_D_STATES.test.ts +93 -0
- package/src/utils/__tests__/checkAdditionalFieldsFn.test.ts +45 -0
- package/src/utils/__tests__/checkApplyWhen.test.ts +49 -0
- package/src/utils/__tests__/checkFieldsPropertyExists.test.ts +47 -0
- package/src/utils/__tests__/checkIsValidFieldNameFn.test.ts +190 -0
- package/src/utils/__tests__/comparePassword.test.ts +38 -0
- package/src/utils/__tests__/evaluateDocumentsFiltersReadFn.test.ts +57 -0
- package/src/utils/__tests__/evaluateDocumentsFiltersWriteFn.test.ts +57 -0
- package/src/utils/__tests__/evaluateTopLevelReadFn.test.ts +58 -0
- package/src/utils/__tests__/evaluateTopLevelWriteFn.test.ts +66 -0
- package/src/utils/__tests__/exposeRoutes.test.ts +65 -0
- package/src/utils/__tests__/generateContextData.test.ts +75 -0
- package/src/utils/__tests__/getDefaultRule.test.ts +29 -0
- package/src/utils/__tests__/getKey.test.ts +12 -0
- package/src/utils/__tests__/getKeys.test.ts +11 -0
- package/src/utils/__tests__/getWinningRole.test.ts +66 -0
- package/src/utils/__tests__/hashPassword.test.ts +28 -0
- package/src/utils/__tests__/isEmpty.test.ts +17 -0
- package/src/utils/__tests__/logMachineInfo.test.ts +15 -0
- package/src/utils/__tests__/operators.test.ts +99 -0
- package/src/utils/__tests__/readFileContent.test.ts +35 -0
- package/src/utils/__tests__/registerPlugins.test.ts +59 -0
- package/src/utils/__tests__/rule.test.ts +51 -0
- package/src/utils/__tests__/rulesMatcherInterfaces.test.ts +57 -0
- package/src/utils/__tests__/rulesMatcherUtils.test.ts +56 -0
- package/src/utils/__tests__/someAsync.test.ts +55 -0
- package/src/utils/context/helpers.ts +71 -0
- package/src/utils/context/index.ts +52 -0
- package/src/utils/context/interface.ts +19 -0
- package/src/utils/crypto/index.ts +36 -0
- package/src/utils/helpers/someAsync.ts +24 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/initializer/exposeRoutes.ts +26 -0
- package/src/utils/initializer/registerPlugins.ts +97 -0
- package/src/utils/roles/helpers.ts +47 -0
- package/src/utils/roles/interface.ts +42 -0
- package/src/utils/roles/machines/commonValidators.ts +24 -0
- package/src/utils/roles/machines/index.ts +20 -0
- package/src/utils/roles/machines/interface.ts +46 -0
- package/src/utils/roles/machines/machine.ts +85 -0
- package/src/utils/roles/machines/read/A/index.ts +19 -0
- package/src/utils/roles/machines/read/B/index.ts +31 -0
- package/src/utils/roles/machines/read/C/index.ts +30 -0
- package/src/utils/roles/machines/read/D/index.ts +20 -0
- package/src/utils/roles/machines/read/D/validators.ts +24 -0
- package/src/utils/roles/machines/read/index.ts +6 -0
- package/src/utils/roles/machines/utils.ts +54 -0
- package/src/utils/roles/machines/write/A/index.ts +25 -0
- package/src/utils/roles/machines/write/B/index.ts +43 -0
- package/src/utils/roles/machines/write/C/index.ts +20 -0
- package/src/utils/roles/machines/write/C/validators.ts +24 -0
- package/src/utils/roles/machines/write/index.ts +5 -0
- package/src/utils/rules-matcher/interface.ts +365 -0
- package/src/utils/rules-matcher/utils.ts +281 -0
- package/src/utils/rules.ts +19 -0
- package/tsconfig.json +28 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getMailConfig = exports.loadCustomUserData = exports.loadAuthConfig = exports.PROVIDER_TYPE = exports.AUTH_ERRORS = exports.AUTH_ENDPOINTS = exports.REGISTRATION_SCHEMA = exports.CONFIRM_RESET_SCHEMA = exports.RESET_SCHEMA = exports.LOGIN_SCHEMA = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
exports.LOGIN_SCHEMA = {
|
|
9
|
+
body: {
|
|
10
|
+
type: 'object',
|
|
11
|
+
properties: {
|
|
12
|
+
username: { type: 'string' },
|
|
13
|
+
password: { type: 'string' }
|
|
14
|
+
},
|
|
15
|
+
required: ['username', 'password']
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
exports.RESET_SCHEMA = {
|
|
19
|
+
body: {
|
|
20
|
+
type: 'object',
|
|
21
|
+
properties: {
|
|
22
|
+
email: { type: 'string' },
|
|
23
|
+
password: { type: 'string' }
|
|
24
|
+
},
|
|
25
|
+
required: ['email', 'password']
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
exports.CONFIRM_RESET_SCHEMA = {
|
|
29
|
+
body: {
|
|
30
|
+
type: 'object',
|
|
31
|
+
properties: {
|
|
32
|
+
password: { type: 'string' },
|
|
33
|
+
token: { type: 'string' },
|
|
34
|
+
tokenId: { type: 'string' }
|
|
35
|
+
},
|
|
36
|
+
required: ['password', 'token', 'tokenId']
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
exports.REGISTRATION_SCHEMA = {
|
|
40
|
+
body: {
|
|
41
|
+
type: 'object',
|
|
42
|
+
properties: {
|
|
43
|
+
email: { type: 'string' },
|
|
44
|
+
password: { type: 'string' }
|
|
45
|
+
},
|
|
46
|
+
required: ['email', 'password']
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var AUTH_ENDPOINTS;
|
|
50
|
+
(function (AUTH_ENDPOINTS) {
|
|
51
|
+
AUTH_ENDPOINTS["LOGIN"] = "/login";
|
|
52
|
+
AUTH_ENDPOINTS["REGISTRATION"] = "/register";
|
|
53
|
+
AUTH_ENDPOINTS["PROFILE"] = "/profile";
|
|
54
|
+
AUTH_ENDPOINTS["SESSION"] = "/session";
|
|
55
|
+
AUTH_ENDPOINTS["RESET"] = "/reset/call";
|
|
56
|
+
AUTH_ENDPOINTS["CONFIRM_RESET"] = "/reset";
|
|
57
|
+
})(AUTH_ENDPOINTS || (exports.AUTH_ENDPOINTS = AUTH_ENDPOINTS = {}));
|
|
58
|
+
var AUTH_ERRORS;
|
|
59
|
+
(function (AUTH_ERRORS) {
|
|
60
|
+
AUTH_ERRORS["INVALID_CREDENTIALS"] = "Invalid credentials";
|
|
61
|
+
AUTH_ERRORS["INVALID_TOKEN"] = "Invalid refresh token provided";
|
|
62
|
+
AUTH_ERRORS["INVALID_RESET_PARAMS"] = "Invalid token or tokenId provided";
|
|
63
|
+
})(AUTH_ERRORS || (exports.AUTH_ERRORS = AUTH_ERRORS = {}));
|
|
64
|
+
exports.PROVIDER_TYPE = 'local-userpass';
|
|
65
|
+
/**
|
|
66
|
+
* > Loads the auth config json file
|
|
67
|
+
* @testable
|
|
68
|
+
*/
|
|
69
|
+
const loadAuthConfig = () => {
|
|
70
|
+
return JSON.parse(fs_1.default.readFileSync('auth/providers.json', 'utf-8'));
|
|
71
|
+
};
|
|
72
|
+
exports.loadAuthConfig = loadAuthConfig;
|
|
73
|
+
/**
|
|
74
|
+
* > Loads the custom user data config json file
|
|
75
|
+
* @testable
|
|
76
|
+
*/
|
|
77
|
+
const loadCustomUserData = () => {
|
|
78
|
+
return JSON.parse(fs_1.default.readFileSync('auth/custom_user_data.json', 'utf-8'));
|
|
79
|
+
};
|
|
80
|
+
exports.loadCustomUserData = loadCustomUserData;
|
|
81
|
+
const getMailConfig = (resetPasswordConfig, token, tokenId) => {
|
|
82
|
+
var _a, _b, _c;
|
|
83
|
+
const { mailConfig, resetPasswordUrl } = resetPasswordConfig;
|
|
84
|
+
const ENV_PREFIX = "ENV";
|
|
85
|
+
const { from, subject, mailToken } = mailConfig;
|
|
86
|
+
const [fromPrefix, fromPath] = from.split(".");
|
|
87
|
+
const currentSender = (_a = (fromPrefix === ENV_PREFIX ? process.env[fromPath] : from)) !== null && _a !== void 0 ? _a : "";
|
|
88
|
+
const [subjectPrefix, subjectPath] = subject.split(".");
|
|
89
|
+
const currentSubject = (_b = (subjectPrefix === ENV_PREFIX ? process.env[subjectPath] : subject)) !== null && _b !== void 0 ? _b : "";
|
|
90
|
+
const [mailTokenPrefix, mailTokenPath] = mailToken.split(".");
|
|
91
|
+
const currentMailToken = (_c = (mailTokenPrefix === "ENV" ? process.env[mailTokenPath] : mailToken)) !== null && _c !== void 0 ? _c : "";
|
|
92
|
+
const link = `${resetPasswordUrl}/${token}/${tokenId}`;
|
|
93
|
+
const body = `<body style="font-family: Arial, sans-serif; background-color: #f4f4f4; text-align: center; padding: 20px;">
|
|
94
|
+
<table width="100%" cellspacing="0" cellpadding="0">
|
|
95
|
+
<tr>
|
|
96
|
+
<td align="center">
|
|
97
|
+
<table width="600" cellspacing="0" cellpadding="0" style="background: #ffffff; padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);">
|
|
98
|
+
<tr>
|
|
99
|
+
<td align="center">
|
|
100
|
+
<h2>Password Reset Request</h2>
|
|
101
|
+
<p>If you requested a password reset, click the button below to reset your password.</p>
|
|
102
|
+
<p>If you did not request this, please ignore this email.</p>
|
|
103
|
+
<p>
|
|
104
|
+
<a href="${link}" style="display: inline-block; padding: 12px 20px; font-size: 16px; color: #ffffff; background: #007bff; text-decoration: none; border-radius: 5px;">Reset Password</a>
|
|
105
|
+
</p>
|
|
106
|
+
<p style="margin-top: 20px; font-size: 12px; color: #777;">If the button does not work, copy and paste the following link into your browser:</p>
|
|
107
|
+
<p style="font-size: 12px; color: #777;">${link}</p>
|
|
108
|
+
</td>
|
|
109
|
+
</tr>
|
|
110
|
+
</table>
|
|
111
|
+
</td>
|
|
112
|
+
</tr>
|
|
113
|
+
</table>
|
|
114
|
+
</body>`;
|
|
115
|
+
return {
|
|
116
|
+
from: currentSender !== null && currentSender !== void 0 ? currentSender : "",
|
|
117
|
+
subject: currentSubject,
|
|
118
|
+
mailToken: currentMailToken,
|
|
119
|
+
body
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
exports.getMailConfig = getMailConfig;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const DEFAULT_CONFIG: {
|
|
2
|
+
PORT: number;
|
|
3
|
+
MONGODB_URL: string;
|
|
4
|
+
JWT_SECRET: string;
|
|
5
|
+
API_VERSION: string;
|
|
6
|
+
HTTPS_SCHEMA: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const API_VERSION: string;
|
|
9
|
+
export declare const HTTPS_SCHEMA: string;
|
|
10
|
+
export declare const DB_NAME: string;
|
|
11
|
+
export declare const AUTH_CONFIG: {
|
|
12
|
+
authCollection: string;
|
|
13
|
+
userCollection: string;
|
|
14
|
+
resetPasswordCollection: string;
|
|
15
|
+
resetPasswordConfig: import("./auth/utils").Config;
|
|
16
|
+
user_id_field: string;
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,cAAc;;;;;;CAM1B,CAAA;AACD,eAAO,MAAM,WAAW,QAA8C,CAAA;AACtE,eAAO,MAAM,YAAY,QAA8B,CAAA;AACvD,eAAO,MAAM,OAAO,QAAgB,CAAA;AACpC,eAAO,MAAM,WAAW;;;;;;CAMvB,CAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.AUTH_CONFIG = exports.DB_NAME = exports.HTTPS_SCHEMA = exports.API_VERSION = exports.DEFAULT_CONFIG = void 0;
|
|
15
|
+
const utils_1 = require("./auth/utils");
|
|
16
|
+
const { database_name, collection_name = 'users', user_id_field = "id" } = (0, utils_1.loadCustomUserData)();
|
|
17
|
+
const _a = (0, utils_1.loadAuthConfig)(), { auth_collection = 'auth_users' } = _a, configuration = __rest(_a, ["auth_collection"]);
|
|
18
|
+
exports.DEFAULT_CONFIG = {
|
|
19
|
+
PORT: Number(process.env.PORT) || 3000,
|
|
20
|
+
MONGODB_URL: process.env.MONGODB_URL || '',
|
|
21
|
+
JWT_SECRET: process.env.JWT_SECRET || '',
|
|
22
|
+
API_VERSION: process.env.API_VERSION || "v2.0",
|
|
23
|
+
HTTPS_SCHEMA: process.env.HTTPS_SCHEMA || 'https'
|
|
24
|
+
};
|
|
25
|
+
exports.API_VERSION = `/api/client/${exports.DEFAULT_CONFIG.API_VERSION}`;
|
|
26
|
+
exports.HTTPS_SCHEMA = exports.DEFAULT_CONFIG.HTTPS_SCHEMA;
|
|
27
|
+
exports.DB_NAME = database_name;
|
|
28
|
+
exports.AUTH_CONFIG = {
|
|
29
|
+
authCollection: auth_collection,
|
|
30
|
+
userCollection: collection_name,
|
|
31
|
+
resetPasswordCollection: "reset-password-requests",
|
|
32
|
+
resetPasswordConfig: configuration['local-userpass'].config,
|
|
33
|
+
user_id_field
|
|
34
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { GenerateEndpointsParams } from './interface';
|
|
2
|
+
/**
|
|
3
|
+
* > Generates all HTTP endpoints
|
|
4
|
+
* @testable
|
|
5
|
+
* @param app -> the fastify instance
|
|
6
|
+
* @param functionsList -> the list of all functions
|
|
7
|
+
* @param endpointsList -> the list of all endpoints
|
|
8
|
+
*/
|
|
9
|
+
export declare const generateEndpoints: ({ app, functionsList, endpointsList }: GenerateEndpointsParams) => Promise<void>;
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/features/endpoints/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAGrD;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAAU,uCAIrC,uBAAuB,kBAYzB,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.generateEndpoints = void 0;
|
|
13
|
+
const utils_1 = require("./utils");
|
|
14
|
+
/**
|
|
15
|
+
* > Generates all HTTP endpoints
|
|
16
|
+
* @testable
|
|
17
|
+
* @param app -> the fastify instance
|
|
18
|
+
* @param functionsList -> the list of all functions
|
|
19
|
+
* @param endpointsList -> the list of all endpoints
|
|
20
|
+
*/
|
|
21
|
+
const generateEndpoints = (_a) => __awaiter(void 0, [_a], void 0, function* ({ app, functionsList, endpointsList }) {
|
|
22
|
+
endpointsList.forEach(({ http_method, route, disabled, function_name }) => {
|
|
23
|
+
const currentFunction = functionsList[function_name];
|
|
24
|
+
if (disabled || !currentFunction)
|
|
25
|
+
return;
|
|
26
|
+
const handler = (0, utils_1.generateHandler)({ app, currentFunction, functionsList });
|
|
27
|
+
const currentMethod = (0, utils_1.getMethodsConfig)(app, handler, `/app/:appId/endpoint/${route}`)[http_method];
|
|
28
|
+
currentMethod();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
exports.generateEndpoints = generateEndpoints;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { FastifyInstance } from 'fastify';
|
|
2
|
+
import { Function, Functions } from '../functions/interface';
|
|
3
|
+
export type GenerateEndpointsParams = {
|
|
4
|
+
app: FastifyInstance;
|
|
5
|
+
functionsList: Functions;
|
|
6
|
+
endpointsList: Endpoints;
|
|
7
|
+
};
|
|
8
|
+
export type GenerateHandlerParams = {
|
|
9
|
+
app: FastifyInstance;
|
|
10
|
+
currentFunction: Function;
|
|
11
|
+
functionsList: Functions;
|
|
12
|
+
};
|
|
13
|
+
type HTTP_METHOD<T> = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | T;
|
|
14
|
+
export type Endpoint<T = 'ALL'> = {
|
|
15
|
+
http_method: HTTP_METHOD<T>;
|
|
16
|
+
route: string;
|
|
17
|
+
function_name: string;
|
|
18
|
+
secret_name: string;
|
|
19
|
+
validation_method: string;
|
|
20
|
+
respond_result: boolean;
|
|
21
|
+
fetch_custom_user_data: boolean;
|
|
22
|
+
create_user_on_auth: boolean;
|
|
23
|
+
disabled: boolean;
|
|
24
|
+
};
|
|
25
|
+
export type Endpoints<T = 'ALL'> = Endpoint<T>[];
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../src/features/endpoints/interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAE5D,MAAM,MAAM,uBAAuB,GAAG;IACpC,GAAG,EAAE,eAAe,CAAA;IACpB,aAAa,EAAE,SAAS,CAAA;IACxB,aAAa,EAAE,SAAS,CAAA;CACzB,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC,GAAG,EAAE,eAAe,CAAA;IACpB,eAAe,EAAE,QAAQ,CAAA;IACzB,aAAa,EAAE,SAAS,CAAA;CACzB,CAAA;AAED,KAAK,WAAW,CAAC,CAAC,IAAI,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,CAAC,CAAA;AAErE,MAAM,MAAM,QAAQ,CAAC,CAAC,GAAG,KAAK,IAAI;IAChC,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,CAAA;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,aAAa,EAAE,MAAM,CAAA;IACrB,WAAW,EAAE,MAAM,CAAA;IACnB,iBAAiB,EAAE,MAAM,CAAA;IACzB,cAAc,EAAE,OAAO,CAAA;IACvB,sBAAsB,EAAE,OAAO,CAAA;IAC/B,mBAAmB,EAAE,OAAO,CAAA;IAC5B,QAAQ,EAAE,OAAO,CAAA;CAClB,CAAA;AACD,MAAM,MAAM,SAAS,CAAC,CAAC,GAAG,KAAK,IAAI,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify';
|
|
2
|
+
import { Endpoints, GenerateHandlerParams } from './interface';
|
|
3
|
+
/**
|
|
4
|
+
* > Loads the endpoint config json file
|
|
5
|
+
* @testable
|
|
6
|
+
*/
|
|
7
|
+
export declare const loadEndpoints: () => Promise<Endpoints>;
|
|
8
|
+
/**
|
|
9
|
+
* > Creates an object with a config for all HTTP methods
|
|
10
|
+
* @testable
|
|
11
|
+
* @param app -> the fastify instance
|
|
12
|
+
* @param handler -> the handler function for that route
|
|
13
|
+
* @param endpoint -> the current endpoint
|
|
14
|
+
*/
|
|
15
|
+
export declare const getMethodsConfig: (app: FastifyInstance, handler: ReturnType<typeof generateHandler>, endpoint: string) => {
|
|
16
|
+
ALL: () => FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>;
|
|
17
|
+
GET: () => FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>;
|
|
18
|
+
POST: () => FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>;
|
|
19
|
+
PUT: () => FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>;
|
|
20
|
+
PATCH: () => FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>;
|
|
21
|
+
DELETE: () => FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* > Creates an handler function for a single endpoint
|
|
25
|
+
* @testable
|
|
26
|
+
* @param app -> the fastify instance
|
|
27
|
+
* @param currentFunction -> the name of the function that should be called for that endpoint
|
|
28
|
+
* @param functionsList -> the list of all functions
|
|
29
|
+
*/
|
|
30
|
+
export declare const generateHandler: ({ app, currentFunction, functionsList }: GenerateHandlerParams) => (req: FastifyRequest, res: FastifyReply) => Promise<{}>;
|
|
31
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/features/endpoints/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAKvE,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAE9D;;;GAGG;AACH,eAAO,MAAM,aAAa,QAAa,OAAO,CAAC,SAAS,CAQvD,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAC3B,KAAK,eAAe,EACpB,SAAS,UAAU,CAAC,OAAO,eAAe,CAAC,EAC3C,UAAU,MAAM;;;;;;;CAQhB,CAAA;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAAI,yCAI7B,qBAAqB,MACR,KAAK,cAAc,EAAE,KAAK,YAAY,gBAiBrD,CAAA"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.generateHandler = exports.getMethodsConfig = exports.loadEndpoints = void 0;
|
|
27
|
+
const fs_1 = __importDefault(require("fs"));
|
|
28
|
+
const services_1 = require("../../services");
|
|
29
|
+
const context_1 = require("../../utils/context");
|
|
30
|
+
/**
|
|
31
|
+
* > Loads the endpoint config json file
|
|
32
|
+
* @testable
|
|
33
|
+
*/
|
|
34
|
+
const loadEndpoints = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
+
const config = JSON.parse(fs_1.default.readFileSync('http_endpoints/config.json', 'utf-8'));
|
|
36
|
+
return config.map((_a) => {
|
|
37
|
+
var { http_method } = _a, endpoint = __rest(_a, ["http_method"]);
|
|
38
|
+
return (Object.assign({ http_method: http_method === '*' ? 'ALL' : http_method }, endpoint));
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
exports.loadEndpoints = loadEndpoints;
|
|
42
|
+
/**
|
|
43
|
+
* > Creates an object with a config for all HTTP methods
|
|
44
|
+
* @testable
|
|
45
|
+
* @param app -> the fastify instance
|
|
46
|
+
* @param handler -> the handler function for that route
|
|
47
|
+
* @param endpoint -> the current endpoint
|
|
48
|
+
*/
|
|
49
|
+
const getMethodsConfig = (app, handler, endpoint) => ({
|
|
50
|
+
ALL: () => app.all(endpoint, handler),
|
|
51
|
+
GET: () => app.get(endpoint, handler),
|
|
52
|
+
POST: () => app.post(endpoint, handler),
|
|
53
|
+
PUT: () => app.put(endpoint, handler),
|
|
54
|
+
PATCH: () => app.patch(endpoint, handler),
|
|
55
|
+
DELETE: () => app.delete(endpoint, handler)
|
|
56
|
+
});
|
|
57
|
+
exports.getMethodsConfig = getMethodsConfig;
|
|
58
|
+
/**
|
|
59
|
+
* > Creates an handler function for a single endpoint
|
|
60
|
+
* @testable
|
|
61
|
+
* @param app -> the fastify instance
|
|
62
|
+
* @param currentFunction -> the name of the function that should be called for that endpoint
|
|
63
|
+
* @param functionsList -> the list of all functions
|
|
64
|
+
*/
|
|
65
|
+
const generateHandler = ({ app, currentFunction, functionsList }) => {
|
|
66
|
+
return (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
|
+
try {
|
|
68
|
+
const response = yield (0, context_1.GenerateContext)({
|
|
69
|
+
args: [req],
|
|
70
|
+
app,
|
|
71
|
+
rules: {}, //TODO -> check rules
|
|
72
|
+
user: req.user,
|
|
73
|
+
currentFunction,
|
|
74
|
+
functionsList,
|
|
75
|
+
services: services_1.services
|
|
76
|
+
});
|
|
77
|
+
res.send(response);
|
|
78
|
+
}
|
|
79
|
+
catch (e) {
|
|
80
|
+
console.log(e);
|
|
81
|
+
}
|
|
82
|
+
return {};
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
exports.generateHandler = generateHandler;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FunctionController } from './interface';
|
|
2
|
+
/**
|
|
3
|
+
* > Creates a pre handler for every query
|
|
4
|
+
* @param app -> the fastify instance
|
|
5
|
+
* @param functionsList -> the list of all functions
|
|
6
|
+
* @param rules -> all the rules
|
|
7
|
+
*/
|
|
8
|
+
export declare const functionsController: FunctionController;
|
|
9
|
+
//# sourceMappingURL=controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../src/features/functions/controller.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAGhD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,EAAE,kBAqFjC,CAAA"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.functionsController = void 0;
|
|
13
|
+
const bson_1 = require("bson");
|
|
14
|
+
const services_1 = require("../../services");
|
|
15
|
+
const state_1 = require("../../state");
|
|
16
|
+
const context_1 = require("../../utils/context");
|
|
17
|
+
const utils_1 = require("./utils");
|
|
18
|
+
/**
|
|
19
|
+
* > Creates a pre handler for every query
|
|
20
|
+
* @param app -> the fastify instance
|
|
21
|
+
* @param functionsList -> the list of all functions
|
|
22
|
+
* @param rules -> all the rules
|
|
23
|
+
*/
|
|
24
|
+
const functionsController = (app_1, _a) => __awaiter(void 0, [app_1, _a], void 0, function* (app, { functionsList, rules }) {
|
|
25
|
+
app.addHook('preHandler', app.jwtAuthentication);
|
|
26
|
+
app.post('/call', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
const { user } = req;
|
|
28
|
+
const { name: method, arguments: args } = req.body;
|
|
29
|
+
if ('service' in req.body) {
|
|
30
|
+
const serviceFn = services_1.services[req.body.service];
|
|
31
|
+
if (!serviceFn) {
|
|
32
|
+
throw new Error(`Service "${req.body.service}" does not exist`);
|
|
33
|
+
}
|
|
34
|
+
const [{ database, collection, query, update, document }] = args;
|
|
35
|
+
const currentMethod = serviceFn(app, { rules, user })
|
|
36
|
+
.db(database)
|
|
37
|
+
.collection(collection)[method];
|
|
38
|
+
const operatorsByType = yield (0, utils_1.executeQuery)({
|
|
39
|
+
currentMethod,
|
|
40
|
+
query,
|
|
41
|
+
update,
|
|
42
|
+
document
|
|
43
|
+
});
|
|
44
|
+
return operatorsByType[method]();
|
|
45
|
+
}
|
|
46
|
+
const currentFunction = functionsList[method];
|
|
47
|
+
if (!currentFunction) {
|
|
48
|
+
throw new Error(`Function "${req.body.name}" does not exist`);
|
|
49
|
+
}
|
|
50
|
+
if (currentFunction.private) {
|
|
51
|
+
throw new Error(`Function "${req.body.name}" is private`);
|
|
52
|
+
}
|
|
53
|
+
const result = yield (0, context_1.GenerateContext)({
|
|
54
|
+
args: req.body.arguments,
|
|
55
|
+
app,
|
|
56
|
+
rules,
|
|
57
|
+
user: Object.assign(Object.assign({}, user), { _id: new bson_1.ObjectId(user.id) }),
|
|
58
|
+
currentFunction,
|
|
59
|
+
functionsList,
|
|
60
|
+
services: services_1.services
|
|
61
|
+
});
|
|
62
|
+
res.type("application/json");
|
|
63
|
+
return JSON.stringify(result);
|
|
64
|
+
}));
|
|
65
|
+
app.get('/call', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
+
const { query, user } = req;
|
|
67
|
+
const { baas_request, stitch_request } = query;
|
|
68
|
+
const config = JSON.parse(Buffer.from(baas_request || stitch_request || "", "base64").toString("utf8"));
|
|
69
|
+
const [{ database, collection }] = config.arguments;
|
|
70
|
+
const app = state_1.StateManager.select("app");
|
|
71
|
+
const services = state_1.StateManager.select("services");
|
|
72
|
+
const changeStream = yield services["mongodb-atlas"](app, {
|
|
73
|
+
user,
|
|
74
|
+
rules
|
|
75
|
+
}).db(database).collection(collection).watch([], { fullDocument: "whenAvailable" });
|
|
76
|
+
res.header('Content-Type', 'text/event-stream');
|
|
77
|
+
res.header('Cache-Control', 'no-cache');
|
|
78
|
+
res.header('Connection', 'keep-alive');
|
|
79
|
+
res.raw.flushHeaders();
|
|
80
|
+
changeStream.on('change', (change) => {
|
|
81
|
+
res.raw.write(`data: ${JSON.stringify(change)}\n\n`);
|
|
82
|
+
});
|
|
83
|
+
req.raw.on('close', () => {
|
|
84
|
+
changeStream.close();
|
|
85
|
+
});
|
|
86
|
+
}));
|
|
87
|
+
});
|
|
88
|
+
exports.functionsController = functionsController;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Document } from "mongodb";
|
|
2
|
+
import { Arguments } from '../../auth/dtos';
|
|
3
|
+
import { GetOperatorsFunction } from '../../services/mongodb-atlas/model';
|
|
4
|
+
type MethodName = Exclude<keyof ReturnType<GetOperatorsFunction>, 'match'>;
|
|
5
|
+
export type FunctionCallDto = {
|
|
6
|
+
name: MethodName;
|
|
7
|
+
arguments: ArgumentsData;
|
|
8
|
+
} | {
|
|
9
|
+
arguments: ArgumentsData;
|
|
10
|
+
name: MethodName;
|
|
11
|
+
service: 'mongodb-atlas';
|
|
12
|
+
};
|
|
13
|
+
export type FunctionCallBase64Dto = {
|
|
14
|
+
baas_request?: string;
|
|
15
|
+
stitch_request?: string;
|
|
16
|
+
};
|
|
17
|
+
type ArgumentsData = Arguments<{
|
|
18
|
+
database: string;
|
|
19
|
+
collection: string;
|
|
20
|
+
query: Parameters<GetOperatorsFunction>;
|
|
21
|
+
update: Document;
|
|
22
|
+
document: Document;
|
|
23
|
+
}>;
|
|
24
|
+
export type Base64Function = {
|
|
25
|
+
name: string;
|
|
26
|
+
arguments: Argument[];
|
|
27
|
+
service: string;
|
|
28
|
+
};
|
|
29
|
+
type Argument = {
|
|
30
|
+
database: string;
|
|
31
|
+
collection: string;
|
|
32
|
+
};
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=dtos.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dtos.d.ts","sourceRoot":"","sources":["../../../src/features/functions/dtos.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAA;AAEzE,KAAK,UAAU,GAAG,OAAO,CAAC,MAAM,UAAU,CAAC,oBAAoB,CAAC,EAAE,OAAO,CAAC,CAAA;AAE1E,MAAM,MAAM,eAAe,GACvB;IACA,IAAI,EAAE,UAAU,CAAA;IAChB,SAAS,EAAE,aAAa,CAAA;CACzB,GACC;IACA,SAAS,EAAE,aAAa,CAAA;IACxB,IAAI,EAAE,UAAU,CAAA;IAChB,OAAO,EAAE,eAAe,CAAA;CACzB,CAAA;AAEH,MAAM,MAAM,qBAAqB,GAAG;IAClC,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB,CAAA;AAED,KAAK,aAAa,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,UAAU,CAAC,oBAAoB,CAAC,CAAA;IACvC,MAAM,EAAE,QAAQ,CAAA;IAChB,QAAQ,EAAE,QAAQ,CAAA;CACnB,CAAC,CAAA;AAGF,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,QAAQ,EAAE,CAAA;IACrB,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,KAAK,QAAQ,GAAG;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RegisterFunctionsParams } from './interface';
|
|
2
|
+
/**
|
|
3
|
+
* > Registers the functions controller
|
|
4
|
+
* @param app -> the fastify instance
|
|
5
|
+
* @param functionsList -> the list of all functions
|
|
6
|
+
* @param rulesList -> the list of all rules
|
|
7
|
+
*/
|
|
8
|
+
export declare const registerFunctions: ({ app, rulesList, functionsList }: RegisterFunctionsParams) => Promise<void>;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/features/functions/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAErD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAU,mCAIrC,uBAAuB,kBAMzB,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.registerFunctions = void 0;
|
|
13
|
+
const constants_1 = require("../../constants");
|
|
14
|
+
const controller_1 = require("./controller");
|
|
15
|
+
/**
|
|
16
|
+
* > Registers the functions controller
|
|
17
|
+
* @param app -> the fastify instance
|
|
18
|
+
* @param functionsList -> the list of all functions
|
|
19
|
+
* @param rulesList -> the list of all rules
|
|
20
|
+
*/
|
|
21
|
+
const registerFunctions = (_a) => __awaiter(void 0, [_a], void 0, function* ({ app, rulesList, functionsList }) {
|
|
22
|
+
yield app.register(controller_1.functionsController, {
|
|
23
|
+
functionsList,
|
|
24
|
+
rules: rulesList,
|
|
25
|
+
prefix: `${constants_1.API_VERSION}/app/:appId/functions`
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
exports.registerFunctions = registerFunctions;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { FastifyInstance } from 'fastify';
|
|
2
|
+
import { Document } from "mongodb";
|
|
3
|
+
import { GetOperatorsFunction } from '../../services/mongodb-atlas/model';
|
|
4
|
+
import { Rules } from '../rules/interface';
|
|
5
|
+
export interface FunctionConfig {
|
|
6
|
+
name: string;
|
|
7
|
+
private?: boolean;
|
|
8
|
+
run_as_system?: boolean;
|
|
9
|
+
disable_arg_logs?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export type Function = Omit<FunctionConfig, 'name'> & {
|
|
12
|
+
code: string;
|
|
13
|
+
};
|
|
14
|
+
export type Functions = Record<string, Function>;
|
|
15
|
+
export type RegisterFunctionsParams = {
|
|
16
|
+
app: FastifyInstance;
|
|
17
|
+
functionsList: Functions;
|
|
18
|
+
rulesList: Rules;
|
|
19
|
+
};
|
|
20
|
+
export type ExecuteQueryParams = {
|
|
21
|
+
currentMethod: ReturnType<GetOperatorsFunction>[keyof ReturnType<GetOperatorsFunction>];
|
|
22
|
+
query: Parameters<GetOperatorsFunction>;
|
|
23
|
+
update: Document;
|
|
24
|
+
document: Document;
|
|
25
|
+
};
|
|
26
|
+
type FunctionsControllerOptions = {
|
|
27
|
+
functionsList: Functions;
|
|
28
|
+
rules: Rules;
|
|
29
|
+
};
|
|
30
|
+
export type FunctionController = (app: FastifyInstance, { functionsList, rules }: FunctionsControllerOptions) => Promise<void>;
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../src/features/functions/interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAA;AACzE,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAE1C,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B;AAED,MAAM,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAA;AAEtE,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;AAEhD,MAAM,MAAM,uBAAuB,GAAG;IACpC,GAAG,EAAE,eAAe,CAAA;IACpB,aAAa,EAAE,SAAS,CAAA;IACxB,SAAS,EAAE,KAAK,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,aAAa,EAAE,UAAU,CAAC,oBAAoB,CAAC,CAAC,MAAM,UAAU,CAAC,oBAAoB,CAAC,CAAC,CAAA;IACvF,KAAK,EAAE,UAAU,CAAC,oBAAoB,CAAC,CAAA;IACvC,MAAM,EAAE,QAAQ,CAAA;IAChB,QAAQ,EAAE,QAAQ,CAAA;CACnB,CAAA;AAED,KAAK,0BAA0B,GAAG;IAChC,aAAa,EAAE,SAAS,CAAA;IACxB,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG,CAC/B,GAAG,EAAE,eAAe,EACpB,EAAE,aAAa,EAAE,KAAK,EAAE,EAAE,0BAA0B,KACjD,OAAO,CAAC,IAAI,CAAC,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ExecuteQueryParams, Functions } from './interface';
|
|
2
|
+
/**
|
|
3
|
+
* > Loads the functions config json file
|
|
4
|
+
* @testable
|
|
5
|
+
*/
|
|
6
|
+
export declare const loadFunctions: (rootDir?: string) => Promise<Functions>;
|
|
7
|
+
/**
|
|
8
|
+
* > Executes a single query
|
|
9
|
+
* @param currentMethod -> the method that should be called
|
|
10
|
+
* @param query -> the query data
|
|
11
|
+
* @param update -> the update Document that should be deserialized
|
|
12
|
+
*/
|
|
13
|
+
export declare const executeQuery: ({ currentMethod, query, update, document }: ExecuteQueryParams) => Promise<{
|
|
14
|
+
find: () => Promise<any[]>;
|
|
15
|
+
findOne: () => Promise<unknown>;
|
|
16
|
+
deleteOne: () => Promise<unknown>;
|
|
17
|
+
insertOne: () => Promise<import("mongodb/mongodb").InsertOneResult<import("bson").Document>>;
|
|
18
|
+
updateOne: () => Promise<unknown> | import("mongodb/mongodb").FindCursor<any> | import("mongodb/mongodb").ChangeStream<import("bson").Document, import("bson").Document> | import("mongodb/mongodb").AggregationCursor<import("bson").Document>;
|
|
19
|
+
aggregate: () => import("mongodb/mongodb").AggregationCursor<import("bson").Document>;
|
|
20
|
+
insertMany: () => Promise<import("mongodb/mongodb").InsertManyResult<import("bson").Document>>;
|
|
21
|
+
updateMany: () => Promise<import("mongodb/mongodb").UpdateResult<import("bson").Document>>;
|
|
22
|
+
}>;
|
|
23
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/features/functions/utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE3D;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAU,gBAAuB,KAAG,OAAO,CAAC,SAAS,CAwB9E,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAU,4CAKhC,kBAAkB;;;;;;;;;EAkCpB,CAAA"}
|