@flowerforce/flowerbase 1.2.1-beta.2 → 1.2.1-beta.21
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 +37 -6
- package/dist/auth/controller.d.ts.map +1 -1
- package/dist/auth/controller.js +55 -4
- package/dist/auth/plugins/jwt.d.ts.map +1 -1
- package/dist/auth/plugins/jwt.js +52 -6
- package/dist/auth/providers/anon-user/controller.d.ts +8 -0
- package/dist/auth/providers/anon-user/controller.d.ts.map +1 -0
- package/dist/auth/providers/anon-user/controller.js +90 -0
- package/dist/auth/providers/anon-user/dtos.d.ts +10 -0
- package/dist/auth/providers/anon-user/dtos.d.ts.map +1 -0
- package/dist/auth/providers/anon-user/dtos.js +2 -0
- package/dist/auth/providers/custom-function/controller.d.ts.map +1 -1
- package/dist/auth/providers/custom-function/controller.js +35 -25
- package/dist/auth/providers/custom-function/dtos.d.ts +4 -1
- package/dist/auth/providers/custom-function/dtos.d.ts.map +1 -1
- package/dist/auth/providers/local-userpass/controller.d.ts.map +1 -1
- package/dist/auth/providers/local-userpass/controller.js +159 -73
- package/dist/auth/providers/local-userpass/dtos.d.ts +17 -2
- package/dist/auth/providers/local-userpass/dtos.d.ts.map +1 -1
- package/dist/auth/utils.d.ts +76 -14
- package/dist/auth/utils.d.ts.map +1 -1
- package/dist/auth/utils.js +55 -61
- package/dist/constants.d.ts +12 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +16 -4
- package/dist/features/functions/controller.d.ts.map +1 -1
- package/dist/features/functions/controller.js +31 -12
- 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 +3 -2
- package/dist/features/functions/utils.d.ts.map +1 -1
- package/dist/features/functions/utils.js +19 -7
- package/dist/features/triggers/index.d.ts.map +1 -1
- package/dist/features/triggers/index.js +49 -7
- package/dist/features/triggers/interface.d.ts +1 -0
- package/dist/features/triggers/interface.d.ts.map +1 -1
- package/dist/features/triggers/utils.d.ts.map +1 -1
- package/dist/features/triggers/utils.js +67 -26
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +48 -13
- package/dist/services/mongodb-atlas/index.d.ts.map +1 -1
- package/dist/services/mongodb-atlas/index.js +72 -2
- package/dist/services/mongodb-atlas/model.d.ts +3 -2
- package/dist/services/mongodb-atlas/model.d.ts.map +1 -1
- package/dist/services/mongodb-atlas/utils.d.ts.map +1 -1
- package/dist/services/mongodb-atlas/utils.js +3 -1
- package/dist/shared/handleUserRegistration.d.ts.map +1 -1
- package/dist/shared/handleUserRegistration.js +66 -1
- package/dist/shared/models/handleUserRegistration.model.d.ts +2 -1
- package/dist/shared/models/handleUserRegistration.model.d.ts.map +1 -1
- package/dist/shared/models/handleUserRegistration.model.js +1 -0
- package/dist/utils/context/helpers.d.ts +6 -6
- package/dist/utils/context/helpers.d.ts.map +1 -1
- 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 -9
- 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.js +1 -1
- package/dist/utils/initializer/registerPlugins.d.ts.map +1 -1
- package/dist/utils/initializer/registerPlugins.js +12 -4
- package/dist/utils/roles/helpers.js +2 -1
- package/dist/utils/rules-matcher/utils.d.ts.map +1 -1
- package/dist/utils/rules-matcher/utils.js +3 -0
- package/package.json +1 -2
- package/src/auth/controller.ts +71 -5
- package/src/auth/plugins/jwt.test.ts +93 -0
- package/src/auth/plugins/jwt.ts +67 -8
- package/src/auth/providers/anon-user/controller.ts +91 -0
- package/src/auth/providers/anon-user/dtos.ts +10 -0
- package/src/auth/providers/custom-function/controller.ts +40 -31
- package/src/auth/providers/custom-function/dtos.ts +5 -1
- package/src/auth/providers/local-userpass/controller.ts +211 -101
- package/src/auth/providers/local-userpass/dtos.ts +20 -2
- package/src/auth/utils.ts +66 -83
- package/src/constants.ts +14 -2
- package/src/features/functions/controller.ts +42 -12
- 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/triggers/index.ts +44 -1
- package/src/features/triggers/interface.ts +1 -0
- package/src/features/triggers/utils.ts +89 -37
- package/src/index.ts +49 -13
- package/src/services/mongodb-atlas/__tests__/findOneAndUpdate.test.ts +95 -0
- package/src/services/mongodb-atlas/index.ts +665 -567
- package/src/services/mongodb-atlas/model.ts +16 -3
- package/src/services/mongodb-atlas/utils.ts +3 -0
- package/src/shared/handleUserRegistration.ts +83 -2
- package/src/shared/models/handleUserRegistration.model.ts +2 -1
- package/src/utils/__tests__/registerPlugins.test.ts +5 -1
- package/src/utils/context/index.ts +238 -18
- package/src/utils/context/interface.ts +1 -1
- package/src/utils/crypto/index.ts +5 -1
- package/src/utils/initializer/exposeRoutes.ts +1 -1
- package/src/utils/initializer/registerPlugins.ts +8 -0
- package/src/utils/roles/helpers.ts +3 -2
- package/src/utils/rules-matcher/utils.ts +3 -0
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_USER_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,35 @@ 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.CONFIRM_USER_SCHEMA = {
|
|
68
|
+
body: {
|
|
69
|
+
type: 'object',
|
|
70
|
+
properties: {
|
|
71
|
+
token: { type: 'string' },
|
|
72
|
+
tokenId: { type: 'string' }
|
|
73
|
+
},
|
|
74
|
+
required: ['token', 'tokenId']
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
exports.RESET_SCHEMA = exports.RESET_SEND_SCHEMA;
|
|
42
78
|
exports.REGISTRATION_SCHEMA = {
|
|
43
79
|
body: {
|
|
44
80
|
type: 'object',
|
|
45
81
|
properties: {
|
|
46
|
-
email: {
|
|
47
|
-
|
|
82
|
+
email: {
|
|
83
|
+
type: 'string',
|
|
84
|
+
pattern: '^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$',
|
|
85
|
+
minLength: 3,
|
|
86
|
+
maxLength: 254
|
|
87
|
+
},
|
|
88
|
+
password: { type: 'string', minLength: 8, maxLength: 128 }
|
|
48
89
|
},
|
|
49
90
|
required: ['email', 'password']
|
|
50
91
|
}
|
|
@@ -53,9 +94,11 @@ var AUTH_ENDPOINTS;
|
|
|
53
94
|
(function (AUTH_ENDPOINTS) {
|
|
54
95
|
AUTH_ENDPOINTS["LOGIN"] = "/login";
|
|
55
96
|
AUTH_ENDPOINTS["REGISTRATION"] = "/register";
|
|
97
|
+
AUTH_ENDPOINTS["CONFIRM"] = "/confirm";
|
|
56
98
|
AUTH_ENDPOINTS["PROFILE"] = "/profile";
|
|
57
99
|
AUTH_ENDPOINTS["SESSION"] = "/session";
|
|
58
|
-
AUTH_ENDPOINTS["RESET"] = "/reset/
|
|
100
|
+
AUTH_ENDPOINTS["RESET"] = "/reset/send";
|
|
101
|
+
AUTH_ENDPOINTS["RESET_CALL"] = "/reset/call";
|
|
59
102
|
AUTH_ENDPOINTS["CONFIRM_RESET"] = "/reset";
|
|
60
103
|
AUTH_ENDPOINTS["FIRST_USER"] = "/setup/first-user";
|
|
61
104
|
})(AUTH_ENDPOINTS || (exports.AUTH_ENDPOINTS = AUTH_ENDPOINTS = {}));
|
|
@@ -64,6 +107,8 @@ var AUTH_ERRORS;
|
|
|
64
107
|
AUTH_ERRORS["INVALID_CREDENTIALS"] = "Invalid credentials";
|
|
65
108
|
AUTH_ERRORS["INVALID_TOKEN"] = "Invalid refresh token provided";
|
|
66
109
|
AUTH_ERRORS["INVALID_RESET_PARAMS"] = "Invalid token or tokenId provided";
|
|
110
|
+
AUTH_ERRORS["MISSING_RESET_FUNCTION"] = "Missing reset function";
|
|
111
|
+
AUTH_ERRORS["USER_NOT_CONFIRMED"] = "User not confirmed";
|
|
67
112
|
})(AUTH_ERRORS || (exports.AUTH_ERRORS = AUTH_ERRORS = {}));
|
|
68
113
|
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(); };
|
|
69
114
|
/**
|
|
@@ -84,57 +129,6 @@ const loadCustomUserData = () => {
|
|
|
84
129
|
return JSON.parse(fs_1.default.readFileSync(userDataPath, 'utf-8'));
|
|
85
130
|
};
|
|
86
131
|
exports.loadCustomUserData = loadCustomUserData;
|
|
87
|
-
const getMailConfig = (resetPasswordConfig, token, tokenId) => {
|
|
88
|
-
var _a, _b, _c;
|
|
89
|
-
const { mailConfig, resetPasswordUrl } = resetPasswordConfig;
|
|
90
|
-
const ENV_PREFIX = 'ENV';
|
|
91
|
-
const { from, subject, mailToken } = mailConfig;
|
|
92
|
-
const [fromPrefix, fromPath] = from.split('.');
|
|
93
|
-
if (!fromPath) {
|
|
94
|
-
throw new Error(`Invalid fromPath: ${fromPath}`);
|
|
95
|
-
}
|
|
96
|
-
const currentSender = (_a = (fromPrefix === ENV_PREFIX ? process.env[fromPath] : from)) !== null && _a !== void 0 ? _a : '';
|
|
97
|
-
const [subjectPrefix, subjectPath] = subject.split('.');
|
|
98
|
-
if (!subjectPath) {
|
|
99
|
-
throw new Error(`Invalid subjectPath: ${subjectPath}`);
|
|
100
|
-
}
|
|
101
|
-
const currentSubject = (_b = (subjectPrefix === ENV_PREFIX ? process.env[subjectPath] : subject)) !== null && _b !== void 0 ? _b : '';
|
|
102
|
-
const [mailTokenPrefix, mailTokenPath] = mailToken.split('.');
|
|
103
|
-
if (!mailTokenPath) {
|
|
104
|
-
throw new Error(`Invalid mailTokenPath: ${mailTokenPath}`);
|
|
105
|
-
}
|
|
106
|
-
const currentMailToken = (_c = (mailTokenPrefix === 'ENV' ? process.env[mailTokenPath] : mailToken)) !== null && _c !== void 0 ? _c : '';
|
|
107
|
-
const link = `${resetPasswordUrl}/${token}/${tokenId}`;
|
|
108
|
-
const body = `<body style="font-family: Arial, sans-serif; background-color: #f4f4f4; text-align: center; padding: 20px;">
|
|
109
|
-
<table width="100%" cellspacing="0" cellpadding="0">
|
|
110
|
-
<tr>
|
|
111
|
-
<td align="center">
|
|
112
|
-
<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);">
|
|
113
|
-
<tr>
|
|
114
|
-
<td align="center">
|
|
115
|
-
<h2>Password Reset Request</h2>
|
|
116
|
-
<p>If you requested a password reset, click the button below to reset your password.</p>
|
|
117
|
-
<p>If you did not request this, please ignore this email.</p>
|
|
118
|
-
<p>
|
|
119
|
-
<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>
|
|
120
|
-
</p>
|
|
121
|
-
<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>
|
|
122
|
-
<p style="font-size: 12px; color: #777;">${link}</p>
|
|
123
|
-
</td>
|
|
124
|
-
</tr>
|
|
125
|
-
</table>
|
|
126
|
-
</td>
|
|
127
|
-
</tr>
|
|
128
|
-
</table>
|
|
129
|
-
</body>`;
|
|
130
|
-
return {
|
|
131
|
-
from: currentSender !== null && currentSender !== void 0 ? currentSender : '',
|
|
132
|
-
subject: currentSubject,
|
|
133
|
-
mailToken: currentMailToken,
|
|
134
|
-
body
|
|
135
|
-
};
|
|
136
|
-
};
|
|
137
|
-
exports.getMailConfig = getMailConfig;
|
|
138
132
|
const generatePassword = (length = 20) => {
|
|
139
133
|
const bytes = crypto_1.default.randomBytes(length);
|
|
140
134
|
return Array.from(bytes, (b) => CHARSET[b % CHARSET.length]).join("");
|
package/dist/constants.d.ts
CHANGED
|
@@ -7,6 +7,15 @@ export declare const DEFAULT_CONFIG: {
|
|
|
7
7
|
HTTPS_SCHEMA: string;
|
|
8
8
|
HOST: string;
|
|
9
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_REGISTER_MAX_ATTEMPTS: number;
|
|
14
|
+
AUTH_RESET_MAX_ATTEMPTS: number;
|
|
15
|
+
REFRESH_TOKEN_TTL_DAYS: number;
|
|
16
|
+
ANON_USER_TTL_SECONDS: number;
|
|
17
|
+
SWAGGER_UI_USER: string;
|
|
18
|
+
SWAGGER_UI_PASSWORD: string;
|
|
10
19
|
CORS_OPTIONS: {
|
|
11
20
|
origin: string;
|
|
12
21
|
methods: ALLOWED_METHODS[];
|
|
@@ -19,13 +28,16 @@ export declare const AUTH_CONFIG: {
|
|
|
19
28
|
authCollection: string;
|
|
20
29
|
userCollection: string;
|
|
21
30
|
resetPasswordCollection: string;
|
|
31
|
+
refreshTokensCollection: string;
|
|
22
32
|
resetPasswordConfig: import("./auth/utils").Config;
|
|
33
|
+
localUserpassConfig: import("./auth/utils").Config;
|
|
23
34
|
user_id_field: string;
|
|
24
35
|
on_user_creation_function_name: string;
|
|
25
36
|
providers: {
|
|
26
37
|
"custom-function": {
|
|
27
38
|
authFunctionName: string;
|
|
28
39
|
};
|
|
40
|
+
"anon-user": import("./auth/utils").AnonUser | undefined;
|
|
29
41
|
};
|
|
30
42
|
};
|
|
31
43
|
export declare const S3_CONFIG: {
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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
|
|
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;;;;;;;;;;;;;;;;;;;iBAmBsB,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;;;;;;;;;;;;;;;CAavB,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 || '',
|
|
@@ -24,6 +24,15 @@ exports.DEFAULT_CONFIG = {
|
|
|
24
24
|
HTTPS_SCHEMA: process.env.HTTPS_SCHEMA || 'https',
|
|
25
25
|
HOST: process.env.HOST || '0.0.0.0',
|
|
26
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_REGISTER_MAX_ATTEMPTS: Number(process.env.AUTH_REGISTER_MAX_ATTEMPTS) || 5,
|
|
31
|
+
AUTH_RESET_MAX_ATTEMPTS: Number(process.env.AUTH_RESET_MAX_ATTEMPTS) || 5,
|
|
32
|
+
REFRESH_TOKEN_TTL_DAYS: Number(process.env.REFRESH_TOKEN_TTL_DAYS) || 60,
|
|
33
|
+
ANON_USER_TTL_SECONDS: Number(process.env.ANON_USER_TTL_SECONDS) || 3 * 60 * 60,
|
|
34
|
+
SWAGGER_UI_USER: process.env.SWAGGER_UI_USER || '',
|
|
35
|
+
SWAGGER_UI_PASSWORD: process.env.SWAGGER_UI_PASSWORD || '',
|
|
27
36
|
CORS_OPTIONS: {
|
|
28
37
|
origin: "*",
|
|
29
38
|
methods: ["GET", "POST", "PUT", "DELETE"]
|
|
@@ -36,12 +45,15 @@ exports.DB_NAME = database_name;
|
|
|
36
45
|
exports.AUTH_CONFIG = {
|
|
37
46
|
authCollection: auth_collection,
|
|
38
47
|
userCollection: collection_name,
|
|
39
|
-
resetPasswordCollection: '
|
|
48
|
+
resetPasswordCollection: 'reset_password_requests',
|
|
49
|
+
refreshTokensCollection: 'auth_refresh_tokens',
|
|
40
50
|
resetPasswordConfig: (_a = configuration['local-userpass']) === null || _a === void 0 ? void 0 : _a.config,
|
|
51
|
+
localUserpassConfig: (_b = configuration['local-userpass']) === null || _b === void 0 ? void 0 : _b.config,
|
|
41
52
|
user_id_field,
|
|
42
53
|
on_user_creation_function_name,
|
|
43
54
|
providers: {
|
|
44
|
-
"custom-function": (
|
|
55
|
+
"custom-function": (_c = configuration['custom-function']) === null || _c === void 0 ? void 0 : _c.config,
|
|
56
|
+
"anon-user": configuration['anon-user']
|
|
45
57
|
}
|
|
46
58
|
};
|
|
47
59
|
exports.S3_CONFIG = {
|
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../src/features/functions/controller.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAoChD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,EAAE,kBAoJjC,CAAA"}
|
|
@@ -32,6 +32,12 @@ const logFunctionCall = (method, user, args) => {
|
|
|
32
32
|
return;
|
|
33
33
|
console.log('[functions-debug]', method, user ? { id: user.id, role: user.role, email: user.email } : 'no-user', args);
|
|
34
34
|
};
|
|
35
|
+
const formatFunctionExecutionError = (error) => {
|
|
36
|
+
const err = error;
|
|
37
|
+
const message = typeof (err === null || err === void 0 ? void 0 : err.message) === 'string' ? err.message : String(error);
|
|
38
|
+
const name = typeof (err === null || err === void 0 ? void 0 : err.name) === 'string' ? err.name : 'Error';
|
|
39
|
+
return JSON.stringify({ message, name });
|
|
40
|
+
};
|
|
35
41
|
/**
|
|
36
42
|
* > Creates a pre handler for every query
|
|
37
43
|
* @param app -> the fastify instance
|
|
@@ -53,7 +59,7 @@ const functionsController = (app_1, _a) => __awaiter(void 0, [app_1, _a], void 0
|
|
|
53
59
|
if (!serviceFn) {
|
|
54
60
|
throw new Error(`Service "${req.body.service}" does not exist`);
|
|
55
61
|
}
|
|
56
|
-
const [{ database, collection, query, update, document, documents, pipeline = [] }] = args;
|
|
62
|
+
const [{ database, collection, query, filter, update, options, returnNewDocument, document, documents, pipeline = [] }] = args;
|
|
57
63
|
const currentMethod = serviceFn(app, { rules, user })
|
|
58
64
|
.db(database)
|
|
59
65
|
.collection(collection)[method];
|
|
@@ -61,7 +67,10 @@ const functionsController = (app_1, _a) => __awaiter(void 0, [app_1, _a], void 0
|
|
|
61
67
|
const operatorsByType = yield (0, utils_1.executeQuery)({
|
|
62
68
|
currentMethod,
|
|
63
69
|
query,
|
|
70
|
+
filter,
|
|
64
71
|
update,
|
|
72
|
+
options,
|
|
73
|
+
returnNewDocument,
|
|
65
74
|
document,
|
|
66
75
|
documents,
|
|
67
76
|
pipeline,
|
|
@@ -77,17 +86,27 @@ const functionsController = (app_1, _a) => __awaiter(void 0, [app_1, _a], void 0
|
|
|
77
86
|
throw new Error(`Function "${req.body.name}" is private`);
|
|
78
87
|
}
|
|
79
88
|
logFunctionCall(`function:${method}`, user, args);
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
try {
|
|
90
|
+
const result = yield (0, context_1.GenerateContext)({
|
|
91
|
+
args: req.body.arguments,
|
|
92
|
+
app,
|
|
93
|
+
rules,
|
|
94
|
+
user: Object.assign(Object.assign({}, user), { _id: new bson_1.ObjectId(user.id) }),
|
|
95
|
+
currentFunction,
|
|
96
|
+
functionsList,
|
|
97
|
+
services: services_1.services
|
|
98
|
+
});
|
|
99
|
+
res.type('application/json');
|
|
100
|
+
return JSON.stringify(result);
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
res.status(500);
|
|
104
|
+
res.type('application/json');
|
|
105
|
+
return JSON.stringify({
|
|
106
|
+
error: formatFunctionExecutionError(error),
|
|
107
|
+
error_code: 'FunctionExecutionError'
|
|
108
|
+
});
|
|
109
|
+
}
|
|
91
110
|
}));
|
|
92
111
|
app.get('/call', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
93
112
|
const { query } = req;
|
|
@@ -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,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G,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,MAAM,CAAC,EAAE,QAAQ,CAAA;IACjB,KAAK,EAAE,UAAU,CAAC,oBAAoB,CAAC,CAAA;IACvC,MAAM,EAAE,QAAQ,CAAA;IAChB,OAAO,CAAC,EAAE,QAAQ,CAAA;IAClB,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,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,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,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;IAClB,SAAS,EAAE,QAAQ,EAAE,CAAA;IACrB,QAAQ,EAAE,QA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AAE,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
|
-
updateOne: () => Promise<unknown> | import("mongodb/mongodb").FindCursor<any> | import("mongodb/mongodb").ChangeStream<import("bson").Document, 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
|
+
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":"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,kBAgExB,CAAA"}
|
|
@@ -17,6 +17,7 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
|
17
17
|
};
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.activateTriggers = void 0;
|
|
20
|
+
const constants_1 = require("../../constants");
|
|
20
21
|
const services_1 = require("../../services");
|
|
21
22
|
const utils_1 = require("./utils");
|
|
22
23
|
/**
|
|
@@ -27,15 +28,56 @@ const utils_1 = require("./utils");
|
|
|
27
28
|
* @param functionsList -> the list of all functions
|
|
28
29
|
*/
|
|
29
30
|
const activateTriggers = (_a) => __awaiter(void 0, [_a], void 0, function* ({ fastify, triggersList, functionsList }) {
|
|
30
|
-
var _b,
|
|
31
|
-
var
|
|
31
|
+
var _b, e_1, _c, _d;
|
|
32
|
+
var _e;
|
|
32
33
|
console.log('START ACTIVATION TRIGGERS');
|
|
33
34
|
try {
|
|
35
|
+
const triggersToActivate = [...triggersList];
|
|
36
|
+
if (constants_1.AUTH_CONFIG.on_user_creation_function_name) {
|
|
37
|
+
const alreadyDeclared = triggersToActivate.some((trigger) => {
|
|
38
|
+
var _a, _b, _c;
|
|
39
|
+
return trigger.content.type === 'AUTHENTICATION' &&
|
|
40
|
+
((_c = (_b = (_a = trigger.content.event_processors) === null || _a === void 0 ? void 0 : _a.FUNCTION) === null || _b === void 0 ? void 0 : _b.config) === null || _c === void 0 ? void 0 : _c.function_name) ===
|
|
41
|
+
constants_1.AUTH_CONFIG.on_user_creation_function_name;
|
|
42
|
+
});
|
|
43
|
+
if (!alreadyDeclared) {
|
|
44
|
+
triggersToActivate.push({
|
|
45
|
+
fileName: '__auto_on_user_creation_trigger__.json',
|
|
46
|
+
content: {
|
|
47
|
+
name: 'onUserCreation',
|
|
48
|
+
type: 'AUTHENTICATION',
|
|
49
|
+
disabled: false,
|
|
50
|
+
config: {
|
|
51
|
+
isAutoTrigger: true,
|
|
52
|
+
collection: (_e = constants_1.AUTH_CONFIG.authCollection) !== null && _e !== void 0 ? _e : 'auth_users',
|
|
53
|
+
database: constants_1.DB_NAME,
|
|
54
|
+
full_document: true,
|
|
55
|
+
full_document_before_change: false,
|
|
56
|
+
match: {},
|
|
57
|
+
operation_types: ['insert', 'update', 'replace'],
|
|
58
|
+
project: {},
|
|
59
|
+
service_name: 'mongodb-atlas',
|
|
60
|
+
skip_catchup_events: false,
|
|
61
|
+
tolerate_resume_errors: false,
|
|
62
|
+
unordered: false,
|
|
63
|
+
schedule: ''
|
|
64
|
+
},
|
|
65
|
+
event_processors: {
|
|
66
|
+
FUNCTION: {
|
|
67
|
+
config: {
|
|
68
|
+
function_name: constants_1.AUTH_CONFIG.on_user_creation_function_name
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
34
76
|
try {
|
|
35
|
-
for (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const trigger =
|
|
77
|
+
for (var _f = true, triggersToActivate_1 = __asyncValues(triggersToActivate), triggersToActivate_1_1; triggersToActivate_1_1 = yield triggersToActivate_1.next(), _b = triggersToActivate_1_1.done, !_b; _f = true) {
|
|
78
|
+
_d = triggersToActivate_1_1.value;
|
|
79
|
+
_f = false;
|
|
80
|
+
const trigger = _d;
|
|
39
81
|
const { content } = trigger;
|
|
40
82
|
const { type, config, event_processors } = content;
|
|
41
83
|
const functionName = event_processors.FUNCTION.config.function_name;
|
|
@@ -52,7 +94,7 @@ const activateTriggers = (_a) => __awaiter(void 0, [_a], void 0, function* ({ fa
|
|
|
52
94
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
53
95
|
finally {
|
|
54
96
|
try {
|
|
55
|
-
if (!
|
|
97
|
+
if (!_f && !_b && (_c = triggersToActivate_1.return)) yield _c.call(triggersToActivate_1);
|
|
56
98
|
}
|
|
57
99
|
finally { if (e_1) throw e_1.error; }
|
|
58
100
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../src/features/triggers/interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAE5D,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,WAAW,CAAA;IACjB,QAAQ,EAAE,OAAO,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,gBAAgB,EAAE;QAChB,QAAQ,EAAE;YACR,MAAM,EAAE;gBACN,aAAa,EAAE,MAAM,CAAA;aACtB,CAAA;SACF,CAAA;KACF,CAAA;CACF;AAED,KAAK,MAAM,GAAG;IACZ,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,aAAa,EAAE,OAAO,CAAA;IACtB,2BAA2B,EAAE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;CACF;AAED,KAAK,MAAM,GAAG;IACZ,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,aAAa,EAAE,OAAO,CAAA;IACtB,2BAA2B,EAAE,OAAO,CAAA;IACpC,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC9B,eAAe,EAAE,MAAM,EAAE,CAAA;IACzB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAChC,YAAY,EAAE,MAAM,CAAA;IACpB,mBAAmB,EAAE,OAAO,CAAA;IAC5B,sBAAsB,EAAE,OAAO,CAAA;IAC/B,SAAS,EAAE,OAAO,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,UAAU,GAAG,gBAAgB,CAAA;AACrE,MAAM,MAAM,QAAQ,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,EAAE,CAAA;AAE/D,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,QAAQ,CAAA;IACxB,GAAG,EAAE,eAAe,CAAA;IACpB,QAAQ,EAAE,QAAQ,CAAA;IAClB,aAAa,EAAE,SAAS,CAAA;CACzB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/features/triggers/utils.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,aAAa,EAAW,QAAQ,EAAE,MAAM,aAAa,CAAA;AAqC9D;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,GAAU,gBAAuB,KAAG,OAAO,CAAC,QAAQ,CAkB5E,CAAA;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/features/triggers/utils.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,aAAa,EAAW,QAAQ,EAAE,MAAM,aAAa,CAAA;AAqC9D;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,GAAU,gBAAuB,KAAG,OAAO,CAAC,QAAQ,CAkB5E,CAAA;AAsOD,eAAO,MAAM,gBAAgB;0EAlN1B,aAAa;yEA6Jb,aAAa;+EAxIb,aAAa;CAiMf,CAAA"}
|