@flowerforce/flowerbase 1.2.0 → 1.2.1-beta.11
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/README.md +28 -3
- package/dist/auth/controller.d.ts.map +1 -1
- package/dist/auth/controller.js +57 -3
- package/dist/auth/plugins/jwt.d.ts.map +1 -1
- package/dist/auth/plugins/jwt.js +49 -3
- package/dist/auth/providers/custom-function/controller.d.ts.map +1 -1
- package/dist/auth/providers/custom-function/controller.js +19 -3
- package/dist/auth/providers/local-userpass/controller.d.ts.map +1 -1
- package/dist/auth/providers/local-userpass/controller.js +125 -71
- package/dist/auth/providers/local-userpass/dtos.d.ts +11 -2
- package/dist/auth/providers/local-userpass/dtos.d.ts.map +1 -1
- package/dist/auth/utils.d.ts +53 -14
- package/dist/auth/utils.d.ts.map +1 -1
- package/dist/auth/utils.js +46 -63
- package/dist/constants.d.ts +14 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +18 -5
- package/dist/features/functions/controller.d.ts.map +1 -1
- package/dist/features/functions/controller.js +32 -3
- package/dist/features/functions/dtos.d.ts +3 -0
- package/dist/features/functions/dtos.d.ts.map +1 -1
- package/dist/features/functions/interface.d.ts +3 -0
- package/dist/features/functions/interface.d.ts.map +1 -1
- package/dist/features/functions/utils.d.ts +2 -1
- package/dist/features/functions/utils.d.ts.map +1 -1
- package/dist/features/functions/utils.js +19 -7
- package/dist/features/rules/utils.d.ts.map +1 -1
- package/dist/features/rules/utils.js +11 -2
- package/dist/features/triggers/index.d.ts.map +1 -1
- package/dist/features/triggers/index.js +48 -7
- package/dist/features/triggers/utils.d.ts.map +1 -1
- package/dist/features/triggers/utils.js +118 -27
- package/dist/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +57 -21
- package/dist/services/mongodb-atlas/index.d.ts.map +1 -1
- package/dist/services/mongodb-atlas/index.js +605 -478
- package/dist/services/mongodb-atlas/model.d.ts +2 -1
- package/dist/services/mongodb-atlas/model.d.ts.map +1 -1
- package/dist/services/mongodb-atlas/utils.d.ts +9 -2
- package/dist/services/mongodb-atlas/utils.d.ts.map +1 -1
- package/dist/services/mongodb-atlas/utils.js +113 -23
- package/dist/shared/handleUserRegistration.d.ts.map +1 -1
- package/dist/shared/handleUserRegistration.js +4 -1
- package/dist/shared/models/handleUserRegistration.model.d.ts +6 -2
- package/dist/shared/models/handleUserRegistration.model.d.ts.map +1 -1
- package/dist/utils/context/helpers.d.ts +7 -6
- package/dist/utils/context/helpers.d.ts.map +1 -1
- package/dist/utils/context/helpers.js +3 -0
- package/dist/utils/context/index.d.ts +1 -1
- package/dist/utils/context/index.d.ts.map +1 -1
- package/dist/utils/context/index.js +176 -5
- package/dist/utils/context/interface.d.ts +1 -1
- package/dist/utils/context/interface.d.ts.map +1 -1
- package/dist/utils/crypto/index.d.ts +1 -0
- package/dist/utils/crypto/index.d.ts.map +1 -1
- package/dist/utils/crypto/index.js +6 -2
- package/dist/utils/initializer/exposeRoutes.d.ts.map +1 -1
- package/dist/utils/initializer/exposeRoutes.js +11 -4
- package/dist/utils/initializer/registerPlugins.d.ts +3 -1
- package/dist/utils/initializer/registerPlugins.d.ts.map +1 -1
- package/dist/utils/initializer/registerPlugins.js +9 -6
- package/dist/utils/roles/helpers.js +11 -3
- package/dist/utils/roles/machines/commonValidators.d.ts.map +1 -1
- package/dist/utils/roles/machines/commonValidators.js +10 -6
- package/dist/utils/roles/machines/read/B/validators.d.ts +4 -0
- package/dist/utils/roles/machines/read/B/validators.d.ts.map +1 -0
- package/dist/utils/roles/machines/read/B/validators.js +8 -0
- package/dist/utils/roles/machines/read/C/index.d.ts.map +1 -1
- package/dist/utils/roles/machines/read/C/index.js +10 -7
- package/dist/utils/roles/machines/read/C/validators.d.ts +5 -0
- package/dist/utils/roles/machines/read/C/validators.d.ts.map +1 -0
- package/dist/utils/roles/machines/read/C/validators.js +29 -0
- package/dist/utils/roles/machines/read/D/index.d.ts.map +1 -1
- package/dist/utils/roles/machines/read/D/index.js +13 -11
- package/dist/utils/rules.d.ts +1 -1
- package/dist/utils/rules.d.ts.map +1 -1
- package/dist/utils/rules.js +26 -17
- package/jest.config.ts +2 -12
- package/jest.setup.ts +28 -0
- package/package.json +1 -2
- package/src/auth/controller.ts +70 -4
- package/src/auth/plugins/jwt.test.ts +93 -0
- package/src/auth/plugins/jwt.ts +62 -3
- package/src/auth/providers/custom-function/controller.ts +22 -5
- package/src/auth/providers/local-userpass/controller.ts +168 -96
- package/src/auth/providers/local-userpass/dtos.ts +13 -2
- package/src/auth/utils.ts +51 -86
- package/src/constants.ts +17 -3
- package/src/fastify.d.ts +32 -15
- package/src/features/functions/controller.ts +51 -3
- package/src/features/functions/dtos.ts +3 -0
- package/src/features/functions/interface.ts +3 -0
- package/src/features/functions/utils.ts +29 -8
- package/src/features/rules/utils.ts +11 -2
- package/src/features/triggers/index.ts +43 -1
- package/src/features/triggers/utils.ts +146 -38
- package/src/index.ts +69 -20
- package/src/services/mongodb-atlas/__tests__/findOneAndUpdate.test.ts +95 -0
- package/src/services/mongodb-atlas/__tests__/utils.test.ts +141 -0
- package/src/services/mongodb-atlas/index.ts +241 -90
- package/src/services/mongodb-atlas/model.ts +15 -2
- package/src/services/mongodb-atlas/utils.ts +158 -22
- package/src/shared/handleUserRegistration.ts +5 -4
- package/src/shared/models/handleUserRegistration.model.ts +8 -3
- package/src/types/fastify-raw-body.d.ts +22 -0
- package/src/utils/__tests__/STEP_B_STATES.test.ts +1 -1
- package/src/utils/__tests__/STEP_C_STATES.test.ts +1 -1
- package/src/utils/__tests__/STEP_D_STATES.test.ts +2 -2
- package/src/utils/__tests__/checkIsValidFieldNameFn.test.ts +9 -4
- package/src/utils/__tests__/registerPlugins.test.ts +16 -1
- package/src/utils/context/helpers.ts +3 -0
- package/src/utils/context/index.ts +238 -13
- package/src/utils/context/interface.ts +1 -1
- package/src/utils/crypto/index.ts +5 -1
- package/src/utils/initializer/exposeRoutes.ts +15 -8
- package/src/utils/initializer/registerPlugins.ts +15 -7
- package/src/utils/roles/helpers.ts +23 -5
- package/src/utils/roles/machines/commonValidators.ts +10 -5
- package/src/utils/roles/machines/read/B/validators.ts +8 -0
- package/src/utils/roles/machines/read/C/index.ts +11 -7
- package/src/utils/roles/machines/read/C/validators.ts +21 -0
- package/src/utils/roles/machines/read/D/index.ts +22 -12
- package/src/utils/rules.ts +31 -22
- package/tsconfig.spec.json +7 -0
package/dist/auth/utils.d.ts
CHANGED
|
@@ -4,23 +4,50 @@ export declare const LOGIN_SCHEMA: {
|
|
|
4
4
|
properties: {
|
|
5
5
|
username: {
|
|
6
6
|
type: string;
|
|
7
|
+
pattern: string;
|
|
8
|
+
minLength: number;
|
|
9
|
+
maxLength: number;
|
|
7
10
|
};
|
|
8
11
|
password: {
|
|
9
12
|
type: string;
|
|
13
|
+
minLength: number;
|
|
14
|
+
maxLength: number;
|
|
10
15
|
};
|
|
11
16
|
};
|
|
12
17
|
required: string[];
|
|
13
18
|
};
|
|
14
19
|
};
|
|
15
|
-
export declare const
|
|
20
|
+
export declare const RESET_SEND_SCHEMA: {
|
|
16
21
|
body: {
|
|
17
22
|
type: string;
|
|
18
23
|
properties: {
|
|
19
24
|
email: {
|
|
20
25
|
type: string;
|
|
26
|
+
pattern: string;
|
|
27
|
+
minLength: number;
|
|
28
|
+
maxLength: number;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
required: string[];
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export declare const RESET_CALL_SCHEMA: {
|
|
35
|
+
body: {
|
|
36
|
+
type: string;
|
|
37
|
+
properties: {
|
|
38
|
+
email: {
|
|
39
|
+
type: string;
|
|
40
|
+
pattern: string;
|
|
41
|
+
minLength: number;
|
|
42
|
+
maxLength: number;
|
|
21
43
|
};
|
|
22
44
|
password: {
|
|
23
45
|
type: string;
|
|
46
|
+
minLength: number;
|
|
47
|
+
maxLength: number;
|
|
48
|
+
};
|
|
49
|
+
arguments: {
|
|
50
|
+
type: string;
|
|
24
51
|
};
|
|
25
52
|
};
|
|
26
53
|
required: string[];
|
|
@@ -32,6 +59,8 @@ export declare const CONFIRM_RESET_SCHEMA: {
|
|
|
32
59
|
properties: {
|
|
33
60
|
password: {
|
|
34
61
|
type: string;
|
|
62
|
+
minLength: number;
|
|
63
|
+
maxLength: number;
|
|
35
64
|
};
|
|
36
65
|
token: {
|
|
37
66
|
type: string;
|
|
@@ -43,15 +72,34 @@ export declare const CONFIRM_RESET_SCHEMA: {
|
|
|
43
72
|
required: string[];
|
|
44
73
|
};
|
|
45
74
|
};
|
|
75
|
+
export declare const RESET_SCHEMA: {
|
|
76
|
+
body: {
|
|
77
|
+
type: string;
|
|
78
|
+
properties: {
|
|
79
|
+
email: {
|
|
80
|
+
type: string;
|
|
81
|
+
pattern: string;
|
|
82
|
+
minLength: number;
|
|
83
|
+
maxLength: number;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
required: string[];
|
|
87
|
+
};
|
|
88
|
+
};
|
|
46
89
|
export declare const REGISTRATION_SCHEMA: {
|
|
47
90
|
body: {
|
|
48
91
|
type: string;
|
|
49
92
|
properties: {
|
|
50
93
|
email: {
|
|
51
94
|
type: string;
|
|
95
|
+
pattern: string;
|
|
96
|
+
minLength: number;
|
|
97
|
+
maxLength: number;
|
|
52
98
|
};
|
|
53
99
|
password: {
|
|
54
100
|
type: string;
|
|
101
|
+
minLength: number;
|
|
102
|
+
maxLength: number;
|
|
55
103
|
};
|
|
56
104
|
};
|
|
57
105
|
required: string[];
|
|
@@ -62,14 +110,16 @@ export declare enum AUTH_ENDPOINTS {
|
|
|
62
110
|
REGISTRATION = "/register",
|
|
63
111
|
PROFILE = "/profile",
|
|
64
112
|
SESSION = "/session",
|
|
65
|
-
RESET = "/reset/
|
|
113
|
+
RESET = "/reset/send",
|
|
114
|
+
RESET_CALL = "/reset/call",
|
|
66
115
|
CONFIRM_RESET = "/reset",
|
|
67
116
|
FIRST_USER = "/setup/first-user"
|
|
68
117
|
}
|
|
69
118
|
export declare enum AUTH_ERRORS {
|
|
70
119
|
INVALID_CREDENTIALS = "Invalid credentials",
|
|
71
120
|
INVALID_TOKEN = "Invalid refresh token provided",
|
|
72
|
-
INVALID_RESET_PARAMS = "Invalid token or tokenId provided"
|
|
121
|
+
INVALID_RESET_PARAMS = "Invalid token or tokenId provided",
|
|
122
|
+
MISSING_RESET_FUNCTION = "Missing reset function"
|
|
73
123
|
}
|
|
74
124
|
export interface AuthConfig {
|
|
75
125
|
auth_collection?: string;
|
|
@@ -102,11 +152,6 @@ export interface Config {
|
|
|
102
152
|
resetPasswordUrl: string;
|
|
103
153
|
runConfirmationFunction: boolean;
|
|
104
154
|
runResetFunction: boolean;
|
|
105
|
-
mailConfig: {
|
|
106
|
-
from: string;
|
|
107
|
-
subject: string;
|
|
108
|
-
mailToken: string;
|
|
109
|
-
};
|
|
110
155
|
}
|
|
111
156
|
export interface CustomUserDataConfig {
|
|
112
157
|
enabled: boolean;
|
|
@@ -126,12 +171,6 @@ export declare const loadAuthConfig: () => AuthConfig;
|
|
|
126
171
|
* @testable
|
|
127
172
|
*/
|
|
128
173
|
export declare const loadCustomUserData: () => CustomUserDataConfig;
|
|
129
|
-
export declare const getMailConfig: (resetPasswordConfig: Config, token: string, tokenId: string) => {
|
|
130
|
-
from: string;
|
|
131
|
-
subject: string;
|
|
132
|
-
mailToken: string;
|
|
133
|
-
body: string;
|
|
134
|
-
};
|
|
135
174
|
export declare const generatePassword: (length?: number) => string;
|
|
136
175
|
export {};
|
|
137
176
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/auth/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/auth/utils.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,YAAY
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/auth/utils.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,YAAY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AM;IACrB,WAAW,EAAE,OAAO,CAAA;IACpB,iBAAiB,EAAE,MAAM,CAAA;IACzB,gBAAgB,EAAE,MAAM,CAAA;IACxB,uBAAuB,EAAE,OAAO,CAAA;IAChC,gBAAgB,EAAE,OAAO,CAAA;CAC1B;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,OAAO,CAAA;IAChB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,aAAa,EAAE,MAAM,CAAA;IACrB,eAAe,EAAE,MAAM,CAAA;IACvB,aAAa,EAAE,MAAM,CAAA;IACrB,8BAA8B,EAAE,MAAM,CAAA;CACvC;AAMD;;;GAGG;AACH,eAAO,MAAM,cAAc,QAAO,UAGjC,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,kBAAkB,QAAO,oBAGrC,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,eAAW,WAG3C,CAAA"}
|
package/dist/auth/utils.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.generatePassword = exports.
|
|
6
|
+
exports.generatePassword = exports.loadCustomUserData = exports.loadAuthConfig = exports.AUTH_ERRORS = exports.AUTH_ENDPOINTS = exports.REGISTRATION_SCHEMA = exports.RESET_SCHEMA = exports.CONFIRM_RESET_SCHEMA = exports.RESET_CALL_SCHEMA = exports.RESET_SEND_SCHEMA = exports.LOGIN_SCHEMA = void 0;
|
|
7
7
|
const crypto_1 = __importDefault(require("crypto"));
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
@@ -12,18 +12,43 @@ exports.LOGIN_SCHEMA = {
|
|
|
12
12
|
body: {
|
|
13
13
|
type: 'object',
|
|
14
14
|
properties: {
|
|
15
|
-
username: {
|
|
16
|
-
|
|
15
|
+
username: {
|
|
16
|
+
type: 'string',
|
|
17
|
+
pattern: '^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$',
|
|
18
|
+
minLength: 3,
|
|
19
|
+
maxLength: 254
|
|
20
|
+
},
|
|
21
|
+
password: { type: 'string', minLength: 8, maxLength: 128 }
|
|
17
22
|
},
|
|
18
23
|
required: ['username', 'password']
|
|
19
24
|
}
|
|
20
25
|
};
|
|
21
|
-
exports.
|
|
26
|
+
exports.RESET_SEND_SCHEMA = {
|
|
22
27
|
body: {
|
|
23
28
|
type: 'object',
|
|
24
29
|
properties: {
|
|
25
|
-
email: {
|
|
26
|
-
|
|
30
|
+
email: {
|
|
31
|
+
type: 'string',
|
|
32
|
+
pattern: '^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$',
|
|
33
|
+
minLength: 3,
|
|
34
|
+
maxLength: 254
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
required: ['email']
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
exports.RESET_CALL_SCHEMA = {
|
|
41
|
+
body: {
|
|
42
|
+
type: 'object',
|
|
43
|
+
properties: {
|
|
44
|
+
email: {
|
|
45
|
+
type: 'string',
|
|
46
|
+
pattern: '^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$',
|
|
47
|
+
minLength: 3,
|
|
48
|
+
maxLength: 254
|
|
49
|
+
},
|
|
50
|
+
password: { type: 'string', minLength: 8, maxLength: 128 },
|
|
51
|
+
arguments: { type: 'array' }
|
|
27
52
|
},
|
|
28
53
|
required: ['email', 'password']
|
|
29
54
|
}
|
|
@@ -32,19 +57,25 @@ exports.CONFIRM_RESET_SCHEMA = {
|
|
|
32
57
|
body: {
|
|
33
58
|
type: 'object',
|
|
34
59
|
properties: {
|
|
35
|
-
password: { type: 'string' },
|
|
60
|
+
password: { type: 'string', minLength: 8, maxLength: 128 },
|
|
36
61
|
token: { type: 'string' },
|
|
37
62
|
tokenId: { type: 'string' }
|
|
38
63
|
},
|
|
39
64
|
required: ['password', 'token', 'tokenId']
|
|
40
65
|
}
|
|
41
66
|
};
|
|
67
|
+
exports.RESET_SCHEMA = exports.RESET_SEND_SCHEMA;
|
|
42
68
|
exports.REGISTRATION_SCHEMA = {
|
|
43
69
|
body: {
|
|
44
70
|
type: 'object',
|
|
45
71
|
properties: {
|
|
46
|
-
email: {
|
|
47
|
-
|
|
72
|
+
email: {
|
|
73
|
+
type: 'string',
|
|
74
|
+
pattern: '^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$',
|
|
75
|
+
minLength: 3,
|
|
76
|
+
maxLength: 254
|
|
77
|
+
},
|
|
78
|
+
password: { type: 'string', minLength: 8, maxLength: 128 }
|
|
48
79
|
},
|
|
49
80
|
required: ['email', 'password']
|
|
50
81
|
}
|
|
@@ -55,7 +86,8 @@ var AUTH_ENDPOINTS;
|
|
|
55
86
|
AUTH_ENDPOINTS["REGISTRATION"] = "/register";
|
|
56
87
|
AUTH_ENDPOINTS["PROFILE"] = "/profile";
|
|
57
88
|
AUTH_ENDPOINTS["SESSION"] = "/session";
|
|
58
|
-
AUTH_ENDPOINTS["RESET"] = "/reset/
|
|
89
|
+
AUTH_ENDPOINTS["RESET"] = "/reset/send";
|
|
90
|
+
AUTH_ENDPOINTS["RESET_CALL"] = "/reset/call";
|
|
59
91
|
AUTH_ENDPOINTS["CONFIRM_RESET"] = "/reset";
|
|
60
92
|
AUTH_ENDPOINTS["FIRST_USER"] = "/setup/first-user";
|
|
61
93
|
})(AUTH_ENDPOINTS || (exports.AUTH_ENDPOINTS = AUTH_ENDPOINTS = {}));
|
|
@@ -64,13 +96,15 @@ var AUTH_ERRORS;
|
|
|
64
96
|
AUTH_ERRORS["INVALID_CREDENTIALS"] = "Invalid credentials";
|
|
65
97
|
AUTH_ERRORS["INVALID_TOKEN"] = "Invalid refresh token provided";
|
|
66
98
|
AUTH_ERRORS["INVALID_RESET_PARAMS"] = "Invalid token or tokenId provided";
|
|
99
|
+
AUTH_ERRORS["MISSING_RESET_FUNCTION"] = "Missing reset function";
|
|
67
100
|
})(AUTH_ERRORS || (exports.AUTH_ERRORS = AUTH_ERRORS = {}));
|
|
101
|
+
const resolveAppPath = () => { var _a, _b, _c; return (_c = (_a = process.env.FLOWERBASE_APP_PATH) !== null && _a !== void 0 ? _a : (_b = require.main) === null || _b === void 0 ? void 0 : _b.path) !== null && _c !== void 0 ? _c : process.cwd(); };
|
|
68
102
|
/**
|
|
69
103
|
* > Loads the auth config json file
|
|
70
104
|
* @testable
|
|
71
105
|
*/
|
|
72
106
|
const loadAuthConfig = () => {
|
|
73
|
-
const authPath = path_1.default.join(
|
|
107
|
+
const authPath = path_1.default.join(resolveAppPath(), 'auth/providers.json');
|
|
74
108
|
return JSON.parse(fs_1.default.readFileSync(authPath, 'utf-8'));
|
|
75
109
|
};
|
|
76
110
|
exports.loadAuthConfig = loadAuthConfig;
|
|
@@ -79,61 +113,10 @@ exports.loadAuthConfig = loadAuthConfig;
|
|
|
79
113
|
* @testable
|
|
80
114
|
*/
|
|
81
115
|
const loadCustomUserData = () => {
|
|
82
|
-
const userDataPath = path_1.default.join(
|
|
116
|
+
const userDataPath = path_1.default.join(resolveAppPath(), 'auth/custom_user_data.json');
|
|
83
117
|
return JSON.parse(fs_1.default.readFileSync(userDataPath, 'utf-8'));
|
|
84
118
|
};
|
|
85
119
|
exports.loadCustomUserData = loadCustomUserData;
|
|
86
|
-
const getMailConfig = (resetPasswordConfig, token, tokenId) => {
|
|
87
|
-
var _a, _b, _c;
|
|
88
|
-
const { mailConfig, resetPasswordUrl } = resetPasswordConfig;
|
|
89
|
-
const ENV_PREFIX = 'ENV';
|
|
90
|
-
const { from, subject, mailToken } = mailConfig;
|
|
91
|
-
const [fromPrefix, fromPath] = from.split('.');
|
|
92
|
-
if (!fromPath) {
|
|
93
|
-
throw new Error(`Invalid fromPath: ${fromPath}`);
|
|
94
|
-
}
|
|
95
|
-
const currentSender = (_a = (fromPrefix === ENV_PREFIX ? process.env[fromPath] : from)) !== null && _a !== void 0 ? _a : '';
|
|
96
|
-
const [subjectPrefix, subjectPath] = subject.split('.');
|
|
97
|
-
if (!subjectPath) {
|
|
98
|
-
throw new Error(`Invalid subjectPath: ${subjectPath}`);
|
|
99
|
-
}
|
|
100
|
-
const currentSubject = (_b = (subjectPrefix === ENV_PREFIX ? process.env[subjectPath] : subject)) !== null && _b !== void 0 ? _b : '';
|
|
101
|
-
const [mailTokenPrefix, mailTokenPath] = mailToken.split('.');
|
|
102
|
-
if (!mailTokenPath) {
|
|
103
|
-
throw new Error(`Invalid mailTokenPath: ${mailTokenPath}`);
|
|
104
|
-
}
|
|
105
|
-
const currentMailToken = (_c = (mailTokenPrefix === 'ENV' ? process.env[mailTokenPath] : mailToken)) !== null && _c !== void 0 ? _c : '';
|
|
106
|
-
const link = `${resetPasswordUrl}/${token}/${tokenId}`;
|
|
107
|
-
const body = `<body style="font-family: Arial, sans-serif; background-color: #f4f4f4; text-align: center; padding: 20px;">
|
|
108
|
-
<table width="100%" cellspacing="0" cellpadding="0">
|
|
109
|
-
<tr>
|
|
110
|
-
<td align="center">
|
|
111
|
-
<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);">
|
|
112
|
-
<tr>
|
|
113
|
-
<td align="center">
|
|
114
|
-
<h2>Password Reset Request</h2>
|
|
115
|
-
<p>If you requested a password reset, click the button below to reset your password.</p>
|
|
116
|
-
<p>If you did not request this, please ignore this email.</p>
|
|
117
|
-
<p>
|
|
118
|
-
<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>
|
|
119
|
-
</p>
|
|
120
|
-
<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>
|
|
121
|
-
<p style="font-size: 12px; color: #777;">${link}</p>
|
|
122
|
-
</td>
|
|
123
|
-
</tr>
|
|
124
|
-
</table>
|
|
125
|
-
</td>
|
|
126
|
-
</tr>
|
|
127
|
-
</table>
|
|
128
|
-
</body>`;
|
|
129
|
-
return {
|
|
130
|
-
from: currentSender !== null && currentSender !== void 0 ? currentSender : '',
|
|
131
|
-
subject: currentSubject,
|
|
132
|
-
mailToken: currentMailToken,
|
|
133
|
-
body
|
|
134
|
-
};
|
|
135
|
-
};
|
|
136
|
-
exports.getMailConfig = getMailConfig;
|
|
137
120
|
const generatePassword = (length = 20) => {
|
|
138
121
|
const bytes = crypto_1.default.randomBytes(length);
|
|
139
122
|
return Array.from(bytes, (b) => CHARSET[b % CHARSET.length]).join("");
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ALLOWED_METHODS } from './';
|
|
1
2
|
export declare const DEFAULT_CONFIG: {
|
|
2
3
|
PORT: number;
|
|
3
4
|
MONGODB_URL: string;
|
|
@@ -6,6 +7,17 @@ export declare const DEFAULT_CONFIG: {
|
|
|
6
7
|
HTTPS_SCHEMA: string;
|
|
7
8
|
HOST: string;
|
|
8
9
|
ENABLE_LOGGER: string | undefined;
|
|
10
|
+
RESET_PASSWORD_TTL_SECONDS: number;
|
|
11
|
+
AUTH_RATE_LIMIT_WINDOW_MS: number;
|
|
12
|
+
AUTH_LOGIN_MAX_ATTEMPTS: number;
|
|
13
|
+
AUTH_RESET_MAX_ATTEMPTS: number;
|
|
14
|
+
REFRESH_TOKEN_TTL_DAYS: number;
|
|
15
|
+
SWAGGER_UI_USER: string;
|
|
16
|
+
SWAGGER_UI_PASSWORD: string;
|
|
17
|
+
CORS_OPTIONS: {
|
|
18
|
+
origin: string;
|
|
19
|
+
methods: ALLOWED_METHODS[];
|
|
20
|
+
};
|
|
9
21
|
};
|
|
10
22
|
export declare const API_VERSION: string;
|
|
11
23
|
export declare const HTTPS_SCHEMA: string;
|
|
@@ -14,7 +26,9 @@ export declare const AUTH_CONFIG: {
|
|
|
14
26
|
authCollection: string;
|
|
15
27
|
userCollection: string;
|
|
16
28
|
resetPasswordCollection: string;
|
|
29
|
+
refreshTokensCollection: string;
|
|
17
30
|
resetPasswordConfig: import("./auth/utils").Config;
|
|
31
|
+
localUserpassConfig: import("./auth/utils").Config;
|
|
18
32
|
user_id_field: string;
|
|
19
33
|
on_user_creation_function_name: string;
|
|
20
34
|
providers: {
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,IAAI,CAAA;AAUpC,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;iBAiBsB,eAAe,EAAE;;CAEjE,CAAA;AACD,eAAO,MAAM,WAAW,QAA8C,CAAA;AACtE,eAAO,MAAM,YAAY,QAA8B,CAAA;AACvD,eAAO,MAAM,OAAO,QAAgB,CAAA;AAGpC,eAAO,MAAM,WAAW;;;;;;;;;;;;;;CAYvB,CAAA;AAID,eAAO,MAAM,SAAS;;;CAGrB,CAAA"}
|
package/dist/constants.js
CHANGED
|
@@ -10,12 +10,12 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
}
|
|
11
11
|
return t;
|
|
12
12
|
};
|
|
13
|
-
var _a, _b;
|
|
13
|
+
var _a, _b, _c;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.S3_CONFIG = exports.AUTH_CONFIG = exports.DB_NAME = exports.HTTPS_SCHEMA = exports.API_VERSION = exports.DEFAULT_CONFIG = void 0;
|
|
16
16
|
const utils_1 = require("./auth/utils");
|
|
17
17
|
const { database_name, collection_name = 'users', user_id_field = 'id', on_user_creation_function_name } = (0, utils_1.loadCustomUserData)();
|
|
18
|
-
const
|
|
18
|
+
const _d = (0, utils_1.loadAuthConfig)(), { auth_collection = 'auth_users' } = _d, configuration = __rest(_d, ["auth_collection"]);
|
|
19
19
|
exports.DEFAULT_CONFIG = {
|
|
20
20
|
PORT: Number(process.env.PORT) || 3000,
|
|
21
21
|
MONGODB_URL: process.env.MONGODB_URL || '',
|
|
@@ -23,7 +23,18 @@ exports.DEFAULT_CONFIG = {
|
|
|
23
23
|
API_VERSION: process.env.API_VERSION || 'v2.0',
|
|
24
24
|
HTTPS_SCHEMA: process.env.HTTPS_SCHEMA || 'https',
|
|
25
25
|
HOST: process.env.HOST || '0.0.0.0',
|
|
26
|
-
ENABLE_LOGGER: process.env.ENABLE_LOGGER
|
|
26
|
+
ENABLE_LOGGER: process.env.ENABLE_LOGGER,
|
|
27
|
+
RESET_PASSWORD_TTL_SECONDS: Number(process.env.RESET_PASSWORD_TTL_SECONDS) || 3600,
|
|
28
|
+
AUTH_RATE_LIMIT_WINDOW_MS: Number(process.env.AUTH_RATE_LIMIT_WINDOW_MS) || 15 * 60 * 1000,
|
|
29
|
+
AUTH_LOGIN_MAX_ATTEMPTS: Number(process.env.AUTH_LOGIN_MAX_ATTEMPTS) || 10,
|
|
30
|
+
AUTH_RESET_MAX_ATTEMPTS: Number(process.env.AUTH_RESET_MAX_ATTEMPTS) || 5,
|
|
31
|
+
REFRESH_TOKEN_TTL_DAYS: Number(process.env.REFRESH_TOKEN_TTL_DAYS) || 60,
|
|
32
|
+
SWAGGER_UI_USER: process.env.SWAGGER_UI_USER || '',
|
|
33
|
+
SWAGGER_UI_PASSWORD: process.env.SWAGGER_UI_PASSWORD || '',
|
|
34
|
+
CORS_OPTIONS: {
|
|
35
|
+
origin: "*",
|
|
36
|
+
methods: ["GET", "POST", "PUT", "DELETE"]
|
|
37
|
+
}
|
|
27
38
|
};
|
|
28
39
|
exports.API_VERSION = `/api/client/${exports.DEFAULT_CONFIG.API_VERSION}`;
|
|
29
40
|
exports.HTTPS_SCHEMA = exports.DEFAULT_CONFIG.HTTPS_SCHEMA;
|
|
@@ -32,12 +43,14 @@ exports.DB_NAME = database_name;
|
|
|
32
43
|
exports.AUTH_CONFIG = {
|
|
33
44
|
authCollection: auth_collection,
|
|
34
45
|
userCollection: collection_name,
|
|
35
|
-
resetPasswordCollection: '
|
|
46
|
+
resetPasswordCollection: 'reset_password_requests',
|
|
47
|
+
refreshTokensCollection: 'auth_refresh_tokens',
|
|
36
48
|
resetPasswordConfig: (_a = configuration['local-userpass']) === null || _a === void 0 ? void 0 : _a.config,
|
|
49
|
+
localUserpassConfig: (_b = configuration['local-userpass']) === null || _b === void 0 ? void 0 : _b.config,
|
|
37
50
|
user_id_field,
|
|
38
51
|
on_user_creation_function_name,
|
|
39
52
|
providers: {
|
|
40
|
-
"custom-function": (
|
|
53
|
+
"custom-function": (_c = configuration['custom-function']) === null || _c === void 0 ? void 0 : _c.config
|
|
41
54
|
}
|
|
42
55
|
};
|
|
43
56
|
exports.S3_CONFIG = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../src/features/functions/controller.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../src/features/functions/controller.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AA6BhD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,EAAE,kBA2IjC,CAAA"}
|
|
@@ -15,6 +15,23 @@ const services_1 = require("../../services");
|
|
|
15
15
|
const state_1 = require("../../state");
|
|
16
16
|
const context_1 = require("../../utils/context");
|
|
17
17
|
const utils_1 = require("./utils");
|
|
18
|
+
const normalizeUser = (payload) => {
|
|
19
|
+
var _a, _b, _c, _d, _e, _f;
|
|
20
|
+
if (!payload)
|
|
21
|
+
return undefined;
|
|
22
|
+
const nestedUser = (_c = (_b = (_a = payload.data) !== null && _a !== void 0 ? _a : payload.user_data) !== null && _b !== void 0 ? _b : payload.custom_data) !== null && _c !== void 0 ? _c : payload;
|
|
23
|
+
const flattened = typeof nestedUser === 'object' && nestedUser !== null ? nestedUser : {};
|
|
24
|
+
return Object.assign(Object.assign(Object.assign({}, payload), flattened), { custom_data: (_d = payload.custom_data) !== null && _d !== void 0 ? _d : flattened, user_data: (_e = payload.user_data) !== null && _e !== void 0 ? _e : flattened, data: (_f = payload.data) !== null && _f !== void 0 ? _f : flattened });
|
|
25
|
+
};
|
|
26
|
+
const getRequestUser = (req) => {
|
|
27
|
+
const candidate = req.user;
|
|
28
|
+
return normalizeUser(candidate);
|
|
29
|
+
};
|
|
30
|
+
const logFunctionCall = (method, user, args) => {
|
|
31
|
+
if (process.env.DEBUG_FUNCTIONS !== 'true')
|
|
32
|
+
return;
|
|
33
|
+
console.log('[functions-debug]', method, user ? { id: user.id, role: user.role, email: user.email } : 'no-user', args);
|
|
34
|
+
};
|
|
18
35
|
/**
|
|
19
36
|
* > Creates a pre handler for every query
|
|
20
37
|
* @param app -> the fastify instance
|
|
@@ -25,7 +42,10 @@ const functionsController = (app_1, _a) => __awaiter(void 0, [app_1, _a], void 0
|
|
|
25
42
|
app.addHook('preHandler', app.jwtAuthentication);
|
|
26
43
|
const streams = {};
|
|
27
44
|
app.post('/call', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
-
const
|
|
45
|
+
const user = getRequestUser(req);
|
|
46
|
+
if (!user || user.typ !== 'access') {
|
|
47
|
+
throw new Error('Access token required');
|
|
48
|
+
}
|
|
29
49
|
const { name: method, arguments: args } = req.body;
|
|
30
50
|
if ('service' in req.body) {
|
|
31
51
|
const serviceFn = services_1.services[req.body.service];
|
|
@@ -33,14 +53,18 @@ const functionsController = (app_1, _a) => __awaiter(void 0, [app_1, _a], void 0
|
|
|
33
53
|
if (!serviceFn) {
|
|
34
54
|
throw new Error(`Service "${req.body.service}" does not exist`);
|
|
35
55
|
}
|
|
36
|
-
const [{ database, collection, query, update, document, documents, pipeline = [] }] = args;
|
|
56
|
+
const [{ database, collection, query, filter, update, options, returnNewDocument, document, documents, pipeline = [] }] = args;
|
|
37
57
|
const currentMethod = serviceFn(app, { rules, user })
|
|
38
58
|
.db(database)
|
|
39
59
|
.collection(collection)[method];
|
|
60
|
+
logFunctionCall(`service:${req.body.service}:${method}`, user, args);
|
|
40
61
|
const operatorsByType = yield (0, utils_1.executeQuery)({
|
|
41
62
|
currentMethod,
|
|
42
63
|
query,
|
|
64
|
+
filter,
|
|
43
65
|
update,
|
|
66
|
+
options,
|
|
67
|
+
returnNewDocument,
|
|
44
68
|
document,
|
|
45
69
|
documents,
|
|
46
70
|
pipeline,
|
|
@@ -55,6 +79,7 @@ const functionsController = (app_1, _a) => __awaiter(void 0, [app_1, _a], void 0
|
|
|
55
79
|
if (currentFunction.private) {
|
|
56
80
|
throw new Error(`Function "${req.body.name}" is private`);
|
|
57
81
|
}
|
|
82
|
+
logFunctionCall(`function:${method}`, user, args);
|
|
58
83
|
const result = yield (0, context_1.GenerateContext)({
|
|
59
84
|
args: req.body.arguments,
|
|
60
85
|
app,
|
|
@@ -68,7 +93,11 @@ const functionsController = (app_1, _a) => __awaiter(void 0, [app_1, _a], void 0
|
|
|
68
93
|
return JSON.stringify(result);
|
|
69
94
|
}));
|
|
70
95
|
app.get('/call', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
|
-
const { query
|
|
96
|
+
const { query } = req;
|
|
97
|
+
const user = getRequestUser(req);
|
|
98
|
+
if (!user || user.typ !== 'access') {
|
|
99
|
+
throw new Error('Access token required');
|
|
100
|
+
}
|
|
72
101
|
const { baas_request, stitch_request } = query;
|
|
73
102
|
const config = JSON.parse(Buffer.from(baas_request || stitch_request || '', 'base64').toString('utf8'));
|
|
74
103
|
const [{ database, collection }] = config.arguments;
|
|
@@ -17,8 +17,11 @@ export type FunctionCallBase64Dto = {
|
|
|
17
17
|
type ArgumentsData = Arguments<{
|
|
18
18
|
database: string;
|
|
19
19
|
collection: string;
|
|
20
|
+
filter?: Document;
|
|
20
21
|
query: Parameters<GetOperatorsFunction>;
|
|
21
22
|
update: Document;
|
|
23
|
+
options?: Document;
|
|
24
|
+
returnNewDocument?: boolean;
|
|
22
25
|
document: Document;
|
|
23
26
|
documents: Document[];
|
|
24
27
|
pipeline?: Document[];
|
|
@@ -1 +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;IAClB,SAAS,EAAE,QAAQ,EAAE,CAAA;IACrB,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAA;CACtB,CAAC,CAAA;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,QAAQ,EAAE,CAAA;IACrB,OAAO,EAAE,M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C3B,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"}
|
|
@@ -21,6 +21,9 @@ export type ExecuteQueryParams = {
|
|
|
21
21
|
currentMethod: ReturnType<GetOperatorsFunction>[keyof ReturnType<GetOperatorsFunction>];
|
|
22
22
|
query: Parameters<GetOperatorsFunction>;
|
|
23
23
|
update: Document;
|
|
24
|
+
filter?: Document;
|
|
25
|
+
options?: Document;
|
|
26
|
+
returnNewDocument?: boolean;
|
|
24
27
|
document: Document;
|
|
25
28
|
documents: Document[];
|
|
26
29
|
pipeline: Document[];
|
|
@@ -1 +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,e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I,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,MAAM,CAAC,EAAE,QAAQ,CAAA;IACjB,OAAO,CAAC,EAAE,QAAQ,CAAA;IAClB,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,QAAQ,EAAE,QAAQ,CAAA;IAClB,SAAS,EAAE,QAAQ,EAAE,CAAA;IACrB,QAAQ,EAAE,QAAQ,EAAE,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,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"}
|
|
@@ -10,12 +10,13 @@ export declare const loadFunctions: (rootDir?: string) => Promise<Functions>;
|
|
|
10
10
|
* @param query -> the query data
|
|
11
11
|
* @param update -> the update Document that should be deserialized
|
|
12
12
|
*/
|
|
13
|
-
export declare const executeQuery: ({ currentMethod, query, update, document, documents, pipeline, isClient }: ExecuteQueryParams) => Promise<{
|
|
13
|
+
export declare const executeQuery: ({ currentMethod, query, update, filter, options, returnNewDocument, document, documents, pipeline, isClient }: ExecuteQueryParams) => Promise<{
|
|
14
14
|
find: () => Promise<any[]>;
|
|
15
15
|
findOne: () => Promise<unknown>;
|
|
16
16
|
deleteOne: () => Promise<unknown>;
|
|
17
17
|
insertOne: () => Promise<import("mongodb/mongodb").InsertOneResult<import("bson").Document>>;
|
|
18
18
|
updateOne: () => Promise<unknown> | import("mongodb/mongodb").FindCursor<any> | import("mongodb/mongodb").ChangeStream<import("bson").Document, import("bson").Document>;
|
|
19
|
+
findOneAndUpdate: () => Promise<import("bson").Document | null>;
|
|
19
20
|
aggregate: () => Promise<import("bson").Document[]>;
|
|
20
21
|
insertMany: () => Promise<import("mongodb/mongodb").InsertManyResult<import("bson").Document>>;
|
|
21
22
|
updateMany: () => Promise<import("mongodb/mongodb").UpdateResult<import("bson").Document>>;
|
|
@@ -1 +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,
|
|
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,+GAWhC,kBAAkB;;;;;;;;;;;EA0DpB,CAAA"}
|
|
@@ -58,22 +58,34 @@ exports.loadFunctions = loadFunctions;
|
|
|
58
58
|
* @param query -> the query data
|
|
59
59
|
* @param update -> the update Document that should be deserialized
|
|
60
60
|
*/
|
|
61
|
-
const executeQuery = (_a) => __awaiter(void 0, [_a], void 0, function* ({ currentMethod, query, update, document, documents, pipeline, isClient = false }) {
|
|
61
|
+
const executeQuery = (_a) => __awaiter(void 0, [_a], void 0, function* ({ currentMethod, query, update, filter, options, returnNewDocument, document, documents, pipeline, isClient = false }) {
|
|
62
|
+
const resolvedQuery = typeof query !== 'undefined'
|
|
63
|
+
? query
|
|
64
|
+
: typeof filter !== 'undefined'
|
|
65
|
+
? filter
|
|
66
|
+
: {};
|
|
67
|
+
const resolvedUpdate = typeof update !== 'undefined' ? update : {};
|
|
68
|
+
const resolvedOptions = typeof options !== 'undefined'
|
|
69
|
+
? options
|
|
70
|
+
: typeof returnNewDocument === 'boolean'
|
|
71
|
+
? { returnDocument: returnNewDocument ? 'after' : 'before' }
|
|
72
|
+
: undefined;
|
|
62
73
|
return {
|
|
63
74
|
find: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
|
-
return yield currentMethod(bson_1.EJSON.deserialize(
|
|
75
|
+
return yield currentMethod(bson_1.EJSON.deserialize(resolvedQuery)).toArray();
|
|
65
76
|
}),
|
|
66
|
-
findOne: () => currentMethod(bson_1.EJSON.deserialize(
|
|
67
|
-
deleteOne: () => currentMethod(bson_1.EJSON.deserialize(
|
|
77
|
+
findOne: () => currentMethod(bson_1.EJSON.deserialize(resolvedQuery)),
|
|
78
|
+
deleteOne: () => currentMethod(bson_1.EJSON.deserialize(resolvedQuery)),
|
|
68
79
|
insertOne: () => currentMethod(bson_1.EJSON.deserialize(document)),
|
|
69
|
-
updateOne: () => currentMethod(bson_1.EJSON.deserialize(
|
|
80
|
+
updateOne: () => currentMethod(bson_1.EJSON.deserialize(resolvedQuery), bson_1.EJSON.deserialize(resolvedUpdate)),
|
|
81
|
+
findOneAndUpdate: () => currentMethod(bson_1.EJSON.deserialize(resolvedQuery), bson_1.EJSON.deserialize(resolvedUpdate), resolvedOptions ? bson_1.EJSON.deserialize(resolvedOptions) : undefined),
|
|
70
82
|
aggregate: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
83
|
return (yield currentMethod(bson_1.EJSON.deserialize(pipeline), {}, // TODO -> ADD OPTIONS
|
|
72
84
|
isClient)).toArray();
|
|
73
85
|
}),
|
|
74
86
|
insertMany: () => currentMethod(bson_1.EJSON.deserialize(documents)),
|
|
75
|
-
updateMany: () => currentMethod(bson_1.EJSON.deserialize(
|
|
76
|
-
deleteMany: () => currentMethod(bson_1.EJSON.deserialize(
|
|
87
|
+
updateMany: () => currentMethod(bson_1.EJSON.deserialize(resolvedQuery), bson_1.EJSON.deserialize(resolvedUpdate)),
|
|
88
|
+
deleteMany: () => currentMethod(bson_1.EJSON.deserialize(resolvedQuery))
|
|
77
89
|
};
|
|
78
90
|
});
|
|
79
91
|
exports.executeQuery = executeQuery;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/features/rules/utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAe,MAAM,aAAa,CAAA;AAEhD,eAAO,MAAM,SAAS,GAAU,gBAAuB,KAAG,OAAO,CAAC,KAAK,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/features/rules/utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAe,MAAM,aAAa,CAAA;AAEhD,eAAO,MAAM,SAAS,GAAU,gBAAuB,KAAG,OAAO,CAAC,KAAK,CAuBtE,CAAA"}
|
|
@@ -18,10 +18,19 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
|
18
18
|
const utils_1 = require("../../utils");
|
|
19
19
|
const loadRules = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (rootDir = process.cwd()) {
|
|
20
20
|
const rulesRoot = node_path_1.default.join(rootDir, 'data_sources', 'mongodb-atlas');
|
|
21
|
-
const
|
|
21
|
+
const recursivelyCollectFiles = (dir) => {
|
|
22
|
+
return fs_1.default.readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
|
|
23
|
+
const fullPath = node_path_1.default.join(dir, entry.name);
|
|
24
|
+
if (entry.isDirectory()) {
|
|
25
|
+
return recursivelyCollectFiles(fullPath);
|
|
26
|
+
}
|
|
27
|
+
return entry.isFile() ? [fullPath] : [];
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
const files = recursivelyCollectFiles(rulesRoot);
|
|
22
31
|
const rulesFiles = files.filter((x) => x.endsWith('rules.json'));
|
|
23
32
|
const rulesByCollection = rulesFiles.reduce((acc, rulesFile) => {
|
|
24
|
-
const filePath =
|
|
33
|
+
const filePath = rulesFile;
|
|
25
34
|
const collectionRules = (0, utils_1.readJsonContent)(filePath);
|
|
26
35
|
acc[collectionRules.collection] = collectionRules;
|
|
27
36
|
return acc;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/features/triggers/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/features/triggers/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,sBAAsB,EAAE,MAAM,QAAQ,CAAA;AAG/C;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAAU,0CAIpC,sBAAsB,kBA+DxB,CAAA"}
|