@flowerforce/flowerbase 1.0.3-beta.2 → 1.0.3-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/dist/auth/plugins/jwt.d.ts.map +1 -1
- package/dist/auth/plugins/jwt.js +2 -1
- package/dist/auth/providers/local-userpass/controller.d.ts.map +1 -1
- package/dist/auth/providers/local-userpass/controller.js +31 -59
- package/dist/constants.d.ts +4 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +5 -1
- package/dist/features/endpoints/utils.d.ts.map +1 -1
- package/dist/features/endpoints/utils.js +23 -4
- package/dist/features/functions/queue.d.ts +7 -0
- package/dist/features/functions/queue.d.ts.map +1 -0
- package/dist/features/functions/queue.js +69 -0
- package/dist/features/triggers/utils.d.ts.map +1 -1
- package/dist/features/triggers/utils.js +22 -6
- package/dist/services/auth/index.d.ts +4 -0
- package/dist/services/auth/index.d.ts.map +1 -0
- package/dist/services/auth/index.js +14 -0
- package/dist/services/auth/model.d.ts +12 -0
- package/dist/services/auth/model.d.ts.map +1 -0
- package/dist/services/auth/model.js +2 -0
- package/dist/services/aws/index.d.ts.map +1 -1
- package/dist/services/aws/index.js +7 -10
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/index.js +2 -0
- package/dist/services/mongodb-atlas/index.d.ts.map +1 -1
- package/dist/services/mongodb-atlas/index.js +28 -5
- package/dist/services/mongodb-atlas/utils.d.ts +17 -1
- package/dist/services/mongodb-atlas/utils.d.ts.map +1 -1
- package/dist/services/mongodb-atlas/utils.js +24 -11
- package/dist/shared/handleUserRegistration.d.ts +11 -0
- package/dist/shared/handleUserRegistration.d.ts.map +1 -0
- package/dist/shared/handleUserRegistration.js +62 -0
- package/dist/shared/models/handleUserRegistration.model.d.ts +16 -0
- package/dist/shared/models/handleUserRegistration.model.d.ts.map +1 -0
- package/dist/shared/models/handleUserRegistration.model.js +2 -0
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +3 -1
- package/dist/utils/context/helpers.d.ts +4 -0
- 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 +30 -22
- package/dist/utils/context/interface.d.ts +2 -0
- package/dist/utils/context/interface.d.ts.map +1 -1
- package/dist/utils/roles/helpers.js +1 -1
- package/package.json +1 -1
- package/src/auth/plugins/jwt.ts +4 -2
- package/src/auth/providers/local-userpass/controller.ts +45 -71
- package/src/constants.ts +7 -0
- package/src/features/endpoints/utils.ts +26 -6
- package/src/features/functions/queue.ts +48 -0
- package/src/features/triggers/utils.ts +11 -6
- package/src/services/auth/index.ts +12 -0
- package/src/services/auth/model.ts +13 -0
- package/src/services/aws/index.ts +10 -11
- package/src/services/index.ts +2 -0
- package/src/services/mongodb-atlas/index.ts +61 -26
- package/src/services/mongodb-atlas/utils.ts +98 -59
- package/src/shared/handleUserRegistration.ts +64 -0
- package/src/shared/models/handleUserRegistration.model.ts +20 -0
- package/src/state.ts +4 -1
- package/src/utils/context/index.ts +44 -29
- package/src/utils/context/interface.ts +2 -0
- package/src/utils/roles/helpers.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../../src/auth/plugins/jwt.ts"],"names":[],"mappings":"AAIA,KAAK,OAAO,GAAG;IACb,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED;;;;;;;GAOG;iUAC8C,OAAO;AAAxD,
|
|
1
|
+
{"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../../src/auth/plugins/jwt.ts"],"names":[],"mappings":"AAIA,KAAK,OAAO,GAAG;IACb,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED;;;;;;;GAOG;iUAC8C,OAAO;AAAxD,wBAqDE"}
|
package/dist/auth/plugins/jwt.js
CHANGED
|
@@ -42,7 +42,8 @@ exports.default = (0, fastify_plugin_1.default)(function (fastify, opts) {
|
|
|
42
42
|
});
|
|
43
43
|
fastify.decorate('createAccessToken', function (user) {
|
|
44
44
|
const id = user._id.toString();
|
|
45
|
-
const
|
|
45
|
+
const userDataId = user.user_data._id.toString();
|
|
46
|
+
const user_data = Object.assign({ _id: userDataId, id: userDataId }, user.user_data);
|
|
46
47
|
return this.jwt.sign({
|
|
47
48
|
typ: 'access',
|
|
48
49
|
id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../../src/auth/providers/local-userpass/controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAuBzC;;;;GAIG;AACH,wBAAsB,uBAAuB,CAAC,GAAG,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../../src/auth/providers/local-userpass/controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAuBzC;;;;GAIG;AACH,wBAAsB,uBAAuB,CAAC,GAAG,EAAE,eAAe,iBAkOjE"}
|
|
@@ -16,6 +16,7 @@ exports.localUserPassController = localUserPassController;
|
|
|
16
16
|
const mail_1 = __importDefault(require("@sendgrid/mail"));
|
|
17
17
|
const constants_1 = require("../../../constants");
|
|
18
18
|
const services_1 = require("../../../services");
|
|
19
|
+
const handleUserRegistration_1 = __importDefault(require("../../../shared/handleUserRegistration"));
|
|
19
20
|
const state_1 = require("../../../state");
|
|
20
21
|
const context_1 = require("../../../utils/context");
|
|
21
22
|
const crypto_1 = require("../../../utils/crypto");
|
|
@@ -40,47 +41,11 @@ function localUserPassController(app) {
|
|
|
40
41
|
*/
|
|
41
42
|
app.post(utils_1.AUTH_ENDPOINTS.REGISTRATION, {
|
|
42
43
|
schema: utils_1.REGISTRATION_SCHEMA
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
email
|
|
49
|
-
});
|
|
50
|
-
if (existingUser) {
|
|
51
|
-
res.status(409);
|
|
52
|
-
return {
|
|
53
|
-
error: 'This email address is already used'
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
const result = yield db.collection(authCollection).insertOne({
|
|
57
|
-
email: email,
|
|
58
|
-
password: hashedPassword,
|
|
59
|
-
status: 'pending',
|
|
60
|
-
custom_data: {
|
|
61
|
-
// TODO da aggiungere in fase di registrazione utente, funzionalità utile che realm non permetteva
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
yield (db === null || db === void 0 ? void 0 : db.collection(authCollection).updateOne({
|
|
65
|
-
email: email
|
|
66
|
-
}, {
|
|
67
|
-
$set: {
|
|
68
|
-
identities: [
|
|
69
|
-
{
|
|
70
|
-
id: result === null || result === void 0 ? void 0 : result.insertedId.toString(),
|
|
71
|
-
provider_id: result === null || result === void 0 ? void 0 : result.insertedId.toString(),
|
|
72
|
-
provider_type: utils_1.PROVIDER_TYPE,
|
|
73
|
-
provider_data: { email }
|
|
74
|
-
}
|
|
75
|
-
]
|
|
76
|
-
}
|
|
77
|
-
}));
|
|
78
|
-
res.status(201);
|
|
79
|
-
return {
|
|
80
|
-
userId: result === null || result === void 0 ? void 0 : result.insertedId
|
|
81
|
-
};
|
|
82
|
-
});
|
|
83
|
-
});
|
|
44
|
+
}, (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const result = yield (0, handleUserRegistration_1.default)(app, { run_as_system: true })({ email: req.body.email.toLowerCase(), password: req.body.password });
|
|
46
|
+
res === null || res === void 0 ? void 0 : res.status(201);
|
|
47
|
+
return { userId: result === null || result === void 0 ? void 0 : result.insertedId.toString() };
|
|
48
|
+
}));
|
|
84
49
|
/**
|
|
85
50
|
* Endpoint for user login.
|
|
86
51
|
*
|
|
@@ -92,59 +57,66 @@ function localUserPassController(app) {
|
|
|
92
57
|
schema: utils_1.LOGIN_SCHEMA
|
|
93
58
|
}, function (req) {
|
|
94
59
|
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
-
const
|
|
60
|
+
const authUser = yield db.collection(authCollection).findOne({
|
|
96
61
|
email: req.body.username
|
|
97
62
|
});
|
|
98
|
-
if (!
|
|
63
|
+
if (!authUser) {
|
|
99
64
|
throw new Error(utils_1.AUTH_ERRORS.INVALID_CREDENTIALS);
|
|
100
65
|
}
|
|
101
|
-
const passwordMatches = yield (0, crypto_1.comparePassword)(req.body.password,
|
|
66
|
+
const passwordMatches = yield (0, crypto_1.comparePassword)(req.body.password, authUser.password);
|
|
102
67
|
if (!passwordMatches) {
|
|
103
68
|
throw new Error(utils_1.AUTH_ERRORS.INVALID_CREDENTIALS);
|
|
104
69
|
}
|
|
105
70
|
const user = user_id_field && userCollection
|
|
106
|
-
?
|
|
71
|
+
? yield db
|
|
72
|
+
.collection(userCollection)
|
|
73
|
+
.findOne({ [user_id_field]: authUser._id.toString() })
|
|
107
74
|
: {};
|
|
108
|
-
|
|
109
|
-
|
|
75
|
+
authUser === null || authUser === void 0 ? true : delete authUser.password;
|
|
76
|
+
const userWithCustomData = Object.assign(Object.assign({}, authUser), { user_data: user, id: authUser._id.toString() });
|
|
77
|
+
if (authUser && authUser.status === 'pending') {
|
|
110
78
|
try {
|
|
111
|
-
yield (db === null || db === void 0 ? void 0 : db.collection(authCollection).updateOne({ _id:
|
|
79
|
+
yield (db === null || db === void 0 ? void 0 : db.collection(authCollection).updateOne({ _id: authUser._id }, {
|
|
112
80
|
$set: {
|
|
113
81
|
status: 'confirmed'
|
|
114
82
|
}
|
|
115
83
|
}));
|
|
116
84
|
}
|
|
117
85
|
catch (error) {
|
|
118
|
-
console.log(
|
|
86
|
+
console.log('>>> 🚀 ~ localUserPassController ~ error:', error);
|
|
119
87
|
}
|
|
120
88
|
}
|
|
121
|
-
if (
|
|
122
|
-
|
|
89
|
+
if (authUser &&
|
|
90
|
+
authUser.status === 'pending' &&
|
|
91
|
+
on_user_creation_function_name &&
|
|
92
|
+
functionsList[on_user_creation_function_name]) {
|
|
123
93
|
try {
|
|
124
94
|
yield (0, context_1.GenerateContext)({
|
|
125
|
-
args: [
|
|
95
|
+
args: [
|
|
96
|
+
{
|
|
126
97
|
operationType: 'CREATE',
|
|
127
98
|
providers: 'local-userpass',
|
|
128
|
-
user,
|
|
99
|
+
user: userWithCustomData,
|
|
129
100
|
time: new Date().getTime()
|
|
130
|
-
}
|
|
101
|
+
}
|
|
102
|
+
],
|
|
131
103
|
app,
|
|
132
104
|
rules: {},
|
|
133
|
-
user:
|
|
105
|
+
user: userWithCustomData,
|
|
134
106
|
currentFunction: functionsList[on_user_creation_function_name],
|
|
135
107
|
functionsList,
|
|
136
108
|
services: services_1.services
|
|
137
109
|
});
|
|
138
110
|
}
|
|
139
111
|
catch (error) {
|
|
140
|
-
console.log(
|
|
112
|
+
console.log('localUserPassController - /login - GenerateContext - CATCH:', error);
|
|
141
113
|
}
|
|
142
114
|
}
|
|
143
115
|
return {
|
|
144
116
|
access_token: this.createAccessToken(userWithCustomData),
|
|
145
117
|
refresh_token: this.createRefreshToken(userWithCustomData),
|
|
146
118
|
device_id: '',
|
|
147
|
-
user_id:
|
|
119
|
+
user_id: authUser._id.toString()
|
|
148
120
|
};
|
|
149
121
|
});
|
|
150
122
|
});
|
|
@@ -161,10 +133,10 @@ function localUserPassController(app) {
|
|
|
161
133
|
return __awaiter(this, void 0, void 0, function* () {
|
|
162
134
|
const { resetPasswordCollection, resetPasswordConfig } = constants_1.AUTH_CONFIG;
|
|
163
135
|
const email = req.body.email;
|
|
164
|
-
const
|
|
136
|
+
const authUser = yield db.collection(authCollection).findOne({
|
|
165
137
|
email
|
|
166
138
|
});
|
|
167
|
-
if (!
|
|
139
|
+
if (!authUser) {
|
|
168
140
|
throw new Error(utils_1.AUTH_ERRORS.INVALID_CREDENTIALS);
|
|
169
141
|
}
|
|
170
142
|
const token = (0, crypto_1.generateToken)();
|
package/dist/constants.d.ts
CHANGED
|
@@ -18,4 +18,8 @@ export declare const AUTH_CONFIG: {
|
|
|
18
18
|
user_id_field: string;
|
|
19
19
|
on_user_creation_function_name: string;
|
|
20
20
|
};
|
|
21
|
+
export declare const S3_CONFIG: {
|
|
22
|
+
ACCESS_KEY_ID: string | undefined;
|
|
23
|
+
SECRET_ACCESS_KEY: string | undefined;
|
|
24
|
+
};
|
|
21
25
|
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,cAAc;;;;;;;;CAQ1B,CAAA;AACD,eAAO,MAAM,WAAW,QAA8C,CAAA;AACtE,eAAO,MAAM,YAAY,QAA8B,CAAA;AACvD,eAAO,MAAM,OAAO,QAAgB,CAAA;AACpC,eAAO,MAAM,WAAW;;;;;;;CAOvB,CAAA"}
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,cAAc;;;;;;;;CAQ1B,CAAA;AACD,eAAO,MAAM,WAAW,QAA8C,CAAA;AACtE,eAAO,MAAM,YAAY,QAA8B,CAAA;AACvD,eAAO,MAAM,OAAO,QAAgB,CAAA;AACpC,eAAO,MAAM,WAAW;;;;;;;CAOvB,CAAA;AAID,eAAO,MAAM,SAAS;;;CAGrB,CAAA"}
|
package/dist/constants.js
CHANGED
|
@@ -11,7 +11,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
return t;
|
|
12
12
|
};
|
|
13
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;
|
|
14
|
+
exports.S3_CONFIG = exports.AUTH_CONFIG = exports.DB_NAME = exports.HTTPS_SCHEMA = exports.API_VERSION = exports.DEFAULT_CONFIG = void 0;
|
|
15
15
|
const utils_1 = require("./auth/utils");
|
|
16
16
|
const { database_name, collection_name = 'users', user_id_field = 'id', on_user_creation_function_name } = (0, utils_1.loadCustomUserData)();
|
|
17
17
|
const _a = (0, utils_1.loadAuthConfig)(), { auth_collection = 'auth_users' } = _a, configuration = __rest(_a, ["auth_collection"]);
|
|
@@ -35,3 +35,7 @@ exports.AUTH_CONFIG = {
|
|
|
35
35
|
user_id_field,
|
|
36
36
|
on_user_creation_function_name
|
|
37
37
|
};
|
|
38
|
+
exports.S3_CONFIG = {
|
|
39
|
+
ACCESS_KEY_ID: process.env.S3_ACCESS_KEY_ID,
|
|
40
|
+
SECRET_ACCESS_KEY: process.env.S3_SECRET_ACCESS_KEY
|
|
41
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/features/endpoints/utils.ts"],"names":[],"mappings":"AAEA,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,GAAU,gBAAuB,KAAG,OAAO,CAAC,SAAS,CAmB9E,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,oDAK7B,qBAAqB,MACR,KAAK,cAAc,EAAE,KAAK,YAAY,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/features/endpoints/utils.ts"],"names":[],"mappings":"AAEA,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,GAAU,gBAAuB,KAAG,OAAO,CAAC,SAAS,CAmB9E,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,oDAK7B,qBAAqB,MACR,KAAK,cAAc,EAAE,KAAK,YAAY,gBA2CrD,CAAA"}
|
|
@@ -74,18 +74,37 @@ exports.getMethodsConfig = getMethodsConfig;
|
|
|
74
74
|
*/
|
|
75
75
|
const generateHandler = ({ app, currentFunction, functionsList, rulesList }) => {
|
|
76
76
|
return (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
77
|
+
var _a;
|
|
78
|
+
const { body: originalBody, headers, query } = req;
|
|
79
|
+
const customBody = {
|
|
80
|
+
text: () => JSON.stringify(originalBody)
|
|
81
|
+
};
|
|
82
|
+
const customResponseBody = {
|
|
83
|
+
data: null
|
|
84
|
+
};
|
|
77
85
|
try {
|
|
78
|
-
|
|
86
|
+
const customResponse = {
|
|
87
|
+
setStatusCode: (code) => {
|
|
88
|
+
res.status(code);
|
|
89
|
+
},
|
|
90
|
+
setBody: (body) => {
|
|
91
|
+
customResponseBody.data = body;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
79
94
|
const response = yield (0, context_1.GenerateContext)({
|
|
80
|
-
args: [
|
|
95
|
+
args: [
|
|
96
|
+
{ body: customBody, headers, query: JSON.parse(JSON.stringify(query)) },
|
|
97
|
+
customResponse
|
|
98
|
+
],
|
|
81
99
|
app,
|
|
82
100
|
rules: rulesList,
|
|
83
101
|
user: req.user,
|
|
84
102
|
currentFunction,
|
|
85
103
|
functionsList,
|
|
86
|
-
services: services_1.services
|
|
104
|
+
services: services_1.services,
|
|
105
|
+
deserializeArgs: false
|
|
87
106
|
});
|
|
88
|
-
return res.send(response);
|
|
107
|
+
return res.send((_a = customResponseBody.data) !== null && _a !== void 0 ? _a : response);
|
|
89
108
|
}
|
|
90
109
|
catch (e) {
|
|
91
110
|
console.log(e);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../../../src/features/functions/queue.ts"],"names":[],"mappings":"AAEA,qBAAa,cAAc;IACvB,OAAO,CAAC,CAAC,CAAkC;IAC3C,OAAO,CAAC,OAAO,CAAS;IAExB,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,GAAE,OAAe,GAAG,OAAO,CAAC,CAAC,CAAC;YA2BtD,GAAG;CAcpB"}
|
|
@@ -0,0 +1,69 @@
|
|
|
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.FunctionsQueue = void 0;
|
|
13
|
+
// TODO gestire session di esecuzione in base all'utente
|
|
14
|
+
class FunctionsQueue {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.q = [];
|
|
17
|
+
this.running = false;
|
|
18
|
+
}
|
|
19
|
+
add(task, enqueue = false) {
|
|
20
|
+
if (!enqueue) {
|
|
21
|
+
return (() => __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
return yield task();
|
|
23
|
+
// try {
|
|
24
|
+
// this.running = true;
|
|
25
|
+
// const res = await task();
|
|
26
|
+
// this.running = false;
|
|
27
|
+
// return res
|
|
28
|
+
// }
|
|
29
|
+
// catch (e) {
|
|
30
|
+
// this.running = false
|
|
31
|
+
// throw e;
|
|
32
|
+
// }
|
|
33
|
+
}))();
|
|
34
|
+
}
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
this.q.push(() => __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
try {
|
|
38
|
+
resolve(yield task());
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
reject(e);
|
|
42
|
+
}
|
|
43
|
+
}));
|
|
44
|
+
void this.run();
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
run() {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
if (this.running)
|
|
50
|
+
return;
|
|
51
|
+
this.running = true;
|
|
52
|
+
try {
|
|
53
|
+
while (this.q.length) {
|
|
54
|
+
const t = this.q.shift();
|
|
55
|
+
try {
|
|
56
|
+
yield t();
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
console.log(e);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
this.running = false;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.FunctionsQueue = FunctionsQueue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/features/triggers/utils.ts"],"names":[],"mappings":"
|
|
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;AAE9D;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,GAAU,gBAAuB,KAAG,OAAO,CAAC,QAAQ,CAkB5E,CAAA;AA4JD,eAAO,MAAM,gBAAgB;0EAxI1B,aAAa;yEA6Fb,aAAa;+EAzEb,aAAa;CAwHf,CAAA"}
|
|
@@ -8,6 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
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
|
+
};
|
|
11
22
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
24
|
};
|
|
@@ -17,6 +28,7 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
17
28
|
const node_path_1 = __importDefault(require("node:path"));
|
|
18
29
|
const node_cron_1 = __importDefault(require("node-cron"));
|
|
19
30
|
const constants_1 = require("../../constants");
|
|
31
|
+
const state_1 = require("../../state");
|
|
20
32
|
const utils_1 = require("../../utils");
|
|
21
33
|
const context_1 = require("../../utils/context");
|
|
22
34
|
/**
|
|
@@ -94,11 +106,14 @@ const handleAuthenticationTrigger = (_a) => __awaiter(void 0, [_a], void 0, func
|
|
|
94
106
|
delete currentUser.password;
|
|
95
107
|
yield (0, context_1.GenerateContext)({
|
|
96
108
|
args: [{
|
|
97
|
-
user: Object.assign(Object.assign({}, currentUser), { id: currentUser._id.toString()
|
|
109
|
+
user: Object.assign(Object.assign({}, currentUser), { id: currentUser._id.toString(), data: {
|
|
110
|
+
_id: currentUser._id.toString(),
|
|
111
|
+
email: currentUser.email
|
|
112
|
+
} })
|
|
98
113
|
}],
|
|
99
114
|
app,
|
|
100
|
-
rules:
|
|
101
|
-
user: {},
|
|
115
|
+
rules: state_1.StateManager.select("rules"),
|
|
116
|
+
user: {}, // TODO from currentUser ??
|
|
102
117
|
currentFunction: triggerHandler,
|
|
103
118
|
functionsList,
|
|
104
119
|
services,
|
|
@@ -145,13 +160,14 @@ const handleDataBaseTrigger = (_a) => __awaiter(void 0, [_a], void 0, function*
|
|
|
145
160
|
? 'whenAvailable'
|
|
146
161
|
: undefined
|
|
147
162
|
});
|
|
148
|
-
changeStream.on('change', function (
|
|
163
|
+
changeStream.on('change', function (_a) {
|
|
149
164
|
return __awaiter(this, void 0, void 0, function* () {
|
|
165
|
+
var { clusterTime } = _a, change = __rest(_a, ["clusterTime"]);
|
|
150
166
|
yield (0, context_1.GenerateContext)({
|
|
151
167
|
args: [change],
|
|
152
168
|
app,
|
|
153
|
-
rules:
|
|
154
|
-
user: {},
|
|
169
|
+
rules: state_1.StateManager.select("rules"),
|
|
170
|
+
user: {}, // TODO add from?
|
|
155
171
|
currentFunction: triggerHandler,
|
|
156
172
|
functionsList,
|
|
157
173
|
services
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/auth/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAEzC,QAAA,MAAM,IAAI,EAAE,eAMX,CAAA;AAED,eAAe,IAAI,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
const handleUserRegistration_1 = __importDefault(require("../../shared/handleUserRegistration"));
|
|
7
|
+
const Auth = (app, opt) => {
|
|
8
|
+
return {
|
|
9
|
+
emailPasswordAuth: {
|
|
10
|
+
registerUser: (0, handleUserRegistration_1.default)(app, opt)
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
exports.default = Auth;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FastifyInstance } from "fastify/types/instance";
|
|
2
|
+
import handleUserRegistration from "../../../src/shared/handleUserRegistration";
|
|
3
|
+
import { Options } from "../../shared/models/handleUserRegistration.model";
|
|
4
|
+
type EmailPasswordAuth = {
|
|
5
|
+
registerUser: ReturnType<typeof handleUserRegistration>;
|
|
6
|
+
};
|
|
7
|
+
type AuthMethods = {
|
|
8
|
+
emailPasswordAuth: EmailPasswordAuth;
|
|
9
|
+
};
|
|
10
|
+
export type AuthServiceType = (app: FastifyInstance, options: Options) => AuthMethods;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/services/auth/model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,sBAAsB,MAAM,4CAA4C,CAAA;AAC/E,OAAO,EAAE,OAAO,EAAE,MAAM,kDAAkD,CAAA;AAE1E,KAAK,iBAAiB,GAAG;IACrB,YAAY,EAAE,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAA;CAC1D,CAAA;AAED,KAAK,WAAW,GAAG;IACf,iBAAiB,EAAE,iBAAiB,CAAA;CACvC,CAAA;AAED,MAAM,MAAM,eAAe,GAAG,CAAC,GAAG,EAAE,eAAe,EAAE,OAAO,EAAE,OAAO,KAAK,WAAW,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/aws/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/aws/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAe,MAAM,SAAS,CAAA;AAC/C,OAAO,MAAM,MAAM,wBAAwB,CAAA;AAC3C,OAAO,EAAE,MAAM,oBAAoB,CAAA;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAInD,QAAA,MAAM,GAAG;qBAQY,MAAM;gBAKX,CACN,GAAG,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,KAClC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAC;qBACnD,MAAM,CAAC,aAAa,CAAC;;iBAczB,MAAM;CAStB,CAAA;AAED,eAAe,GAAG,CAAA"}
|
|
@@ -14,17 +14,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const lambda_1 = __importDefault(require("aws-sdk/clients/lambda"));
|
|
16
16
|
const s3_1 = __importDefault(require("aws-sdk/clients/s3"));
|
|
17
|
-
const
|
|
18
|
-
const secretAccessKey = 'GET_THIS_FROM_CONFIG';
|
|
17
|
+
const constants_1 = require("../../constants");
|
|
19
18
|
const Aws = () => {
|
|
19
|
+
const credentials = {
|
|
20
|
+
accessKeyId: constants_1.S3_CONFIG.ACCESS_KEY_ID,
|
|
21
|
+
secretAccessKey: constants_1.S3_CONFIG.SECRET_ACCESS_KEY,
|
|
22
|
+
};
|
|
20
23
|
return {
|
|
21
24
|
lambda: (region) => {
|
|
22
25
|
const lambda = new lambda_1.default({
|
|
23
26
|
region: region,
|
|
24
|
-
credentials
|
|
25
|
-
accessKeyId,
|
|
26
|
-
secretAccessKey
|
|
27
|
-
}
|
|
27
|
+
credentials
|
|
28
28
|
});
|
|
29
29
|
lambda.Invoke = (...args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
30
|
const res = yield lambda.invoke(...args).promise();
|
|
@@ -38,10 +38,7 @@ const Aws = () => {
|
|
|
38
38
|
s3: (region) => new s3_1.default({
|
|
39
39
|
region,
|
|
40
40
|
apiVersion: '2006-03-01',
|
|
41
|
-
credentials
|
|
42
|
-
accessKeyId,
|
|
43
|
-
secretAccessKey
|
|
44
|
-
},
|
|
41
|
+
credentials,
|
|
45
42
|
s3ForcePathStyle: true,
|
|
46
43
|
signatureVersion: 'v4'
|
|
47
44
|
})
|
package/dist/services/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAMqT,GAAc;;;;;;;CADvV,CAAA"}
|
package/dist/services/index.js
CHANGED
|
@@ -5,10 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.services = void 0;
|
|
7
7
|
const api_1 = __importDefault(require("./api"));
|
|
8
|
+
const auth_1 = __importDefault(require("./auth"));
|
|
8
9
|
const aws_1 = __importDefault(require("./aws"));
|
|
9
10
|
const mongodb_atlas_1 = __importDefault(require("./mongodb-atlas"));
|
|
10
11
|
exports.services = {
|
|
11
12
|
api: api_1.default,
|
|
12
13
|
aws: aws_1.default,
|
|
14
|
+
auth: auth_1.default,
|
|
13
15
|
'mongodb-atlas': mongodb_atlas_1.default
|
|
14
16
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/mongodb-atlas/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAyC,oBAAoB,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/mongodb-atlas/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAyC,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAiqBrF,QAAA,MAAM,YAAY,EAAE,oBAmBlB,CAAA;AAEF,eAAe,YAAY,CAAA"}
|
|
@@ -161,24 +161,39 @@ const getOperators = (collection, { rules = {}, collName, user, run_as_system })
|
|
|
161
161
|
* - If validation fails, throws an error; otherwise, updates the document.
|
|
162
162
|
*/
|
|
163
163
|
updateOne: (query, data, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
164
|
+
console.log('Step1 - query', query);
|
|
165
|
+
console.log('Step1 - data', data);
|
|
166
|
+
console.log('Step1 - options', options);
|
|
164
167
|
if (!run_as_system) {
|
|
168
|
+
console.log('Step1 - runs_as_system');
|
|
165
169
|
(0, utils_2.checkDenyOperation)(rules, collection.collectionName, model_1.CRUD_OPERATIONS.UPDATE);
|
|
166
170
|
const { filters, roles } = rules[collName] || {};
|
|
167
171
|
// Apply access control filters
|
|
172
|
+
// Normalize _id
|
|
168
173
|
const formattedQuery = (0, utils_2.getFormattedQuery)(filters, query, user);
|
|
174
|
+
const safeQuery = Array.isArray(formattedQuery)
|
|
175
|
+
? (0, utils_2.normalizeQuery)(formattedQuery)
|
|
176
|
+
: formattedQuery;
|
|
177
|
+
const result = yield collection.findOne({ $and: safeQuery });
|
|
178
|
+
/* const formattedQuery = getFormattedQuery(filters, query, user) */
|
|
179
|
+
console.log('Step2 - formattedQuery', formattedQuery);
|
|
169
180
|
// Retrieve the document to check permissions before updating
|
|
170
|
-
|
|
181
|
+
console.log('Step2 after fq - collection ', collection);
|
|
182
|
+
/* const result = await collection.findOne({ $and: formattedQuery }) */
|
|
183
|
+
console.log('result ', result);
|
|
171
184
|
if (!result) {
|
|
185
|
+
console.log('check step error in !result');
|
|
172
186
|
throw new Error('Update not permitted');
|
|
173
187
|
}
|
|
174
188
|
const winningRole = (0, utils_1.getWinningRole)(result, user, roles);
|
|
189
|
+
console.log('Step3 - winningRole', winningRole);
|
|
175
190
|
// Check if the update data contains MongoDB update operators (e.g., $set, $inc)
|
|
176
191
|
const hasOperators = Object.keys(data).some((key) => key.startsWith('$'));
|
|
177
192
|
// Flatten the update object to extract the actual fields being modified
|
|
178
193
|
// const docToCheck = hasOperators
|
|
179
194
|
// ? Object.values(data).reduce((acc, operation) => ({ ...acc, ...operation }), {})
|
|
180
195
|
// : data
|
|
181
|
-
const [matchQuery] = formattedQuery;
|
|
196
|
+
const [matchQuery] = formattedQuery; // TODO da chiedere/capire perchè è solo uno. tutti gli altri { $match: { $and: formattedQuery } }
|
|
182
197
|
const pipeline = [
|
|
183
198
|
{
|
|
184
199
|
$match: matchQuery
|
|
@@ -188,6 +203,7 @@ const getOperators = (collection, { rules = {}, collName, user, run_as_system })
|
|
|
188
203
|
},
|
|
189
204
|
...Object.entries(data).map(([key, value]) => ({ [key]: value }))
|
|
190
205
|
];
|
|
206
|
+
console.log('Step5 - pipeline', pipeline);
|
|
191
207
|
const [docToCheck] = hasOperators
|
|
192
208
|
? yield collection.aggregate(pipeline).toArray()
|
|
193
209
|
: [data];
|
|
@@ -200,9 +216,11 @@ const getOperators = (collection, { rules = {}, collName, user, run_as_system })
|
|
|
200
216
|
expansions: {}
|
|
201
217
|
}, user)
|
|
202
218
|
: { status: true, document: docToCheck };
|
|
219
|
+
console.log('Step6 - status', status);
|
|
203
220
|
// Ensure no unauthorized changes are made
|
|
204
221
|
const areDocumentsEqual = (0, isEqual_1.default)(document, docToCheck);
|
|
205
222
|
if (!status || !areDocumentsEqual) {
|
|
223
|
+
console.log('check step error in status or documentsEqual');
|
|
206
224
|
throw new Error('Update not permitted');
|
|
207
225
|
}
|
|
208
226
|
return collection.updateOne({ $and: formattedQuery }, data, options);
|
|
@@ -423,6 +441,7 @@ const getOperators = (collection, { rules = {}, collName, user, run_as_system })
|
|
|
423
441
|
// Retrieve the document to check permissions before updating
|
|
424
442
|
const result = yield collection.find({ $and: formattedQuery }).toArray();
|
|
425
443
|
if (!result) {
|
|
444
|
+
console.log('check1 In updateMany --> (!result)');
|
|
426
445
|
throw new Error('Update not permitted');
|
|
427
446
|
}
|
|
428
447
|
// Check if the update data contains MongoDB update operators (e.g., $set, $inc)
|
|
@@ -433,7 +452,7 @@ const getOperators = (collection, { rules = {}, collName, user, run_as_system })
|
|
|
433
452
|
// : data
|
|
434
453
|
const pipeline = [
|
|
435
454
|
{
|
|
436
|
-
$match: formattedQuery
|
|
455
|
+
$match: { $and: formattedQuery }
|
|
437
456
|
},
|
|
438
457
|
...Object.entries(data).map(([key, value]) => ({ [key]: value }))
|
|
439
458
|
];
|
|
@@ -455,9 +474,10 @@ const getOperators = (collection, { rules = {}, collName, user, run_as_system })
|
|
|
455
474
|
// Ensure no unauthorized changes are made
|
|
456
475
|
const areDocumentsEqual = (0, isEqual_1.default)(docsToCheck, filteredItems);
|
|
457
476
|
if (!areDocumentsEqual) {
|
|
477
|
+
console.log('check1 In updateMany --> (!areDocumentsEqual)');
|
|
458
478
|
throw new Error('Update not permitted');
|
|
459
479
|
}
|
|
460
|
-
return collection.updateMany(formattedQuery, data, options);
|
|
480
|
+
return collection.updateMany({ $and: formattedQuery }, data, options);
|
|
461
481
|
}
|
|
462
482
|
return collection.updateMany(query, data, options);
|
|
463
483
|
}),
|
|
@@ -522,7 +542,10 @@ const MongodbAtlas = (app, { rules, user, run_as_system } = {}) => ({
|
|
|
522
542
|
.db(dbName)
|
|
523
543
|
.collection(collName);
|
|
524
544
|
return getOperators(collection, {
|
|
525
|
-
rules,
|
|
545
|
+
rules,
|
|
546
|
+
collName,
|
|
547
|
+
user,
|
|
548
|
+
run_as_system
|
|
526
549
|
});
|
|
527
550
|
}
|
|
528
551
|
};
|