@flowerforce/flowerbase 1.0.3-beta.2 → 1.0.3-beta.4
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/custom-function/controller.d.ts +8 -0
- package/dist/auth/providers/custom-function/controller.d.ts.map +1 -0
- package/dist/auth/providers/custom-function/controller.js +83 -0
- package/dist/auth/providers/custom-function/dtos.d.ts +15 -0
- package/dist/auth/providers/custom-function/dtos.d.ts.map +1 -0
- package/dist/auth/providers/custom-function/dtos.js +2 -0
- package/dist/auth/providers/custom-function/schema.d.ts +31 -0
- package/dist/auth/providers/custom-function/schema.d.ts.map +1 -0
- package/dist/auth/providers/custom-function/schema.js +25 -0
- package/dist/auth/providers/local-userpass/controller.d.ts.map +1 -1
- package/dist/auth/providers/local-userpass/controller.js +31 -59
- package/dist/auth/utils.d.ts +9 -0
- package/dist/auth/utils.d.ts.map +1 -1
- package/dist/constants.d.ts +9 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +13 -4
- 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 +15 -1
- package/dist/utils/context/helpers.d.ts.map +1 -1
- package/dist/utils/context/helpers.js +2 -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 +31 -22
- package/dist/utils/context/interface.d.ts +6 -1
- package/dist/utils/context/interface.d.ts.map +1 -1
- package/dist/utils/initializer/registerPlugins.d.ts.map +1 -1
- package/dist/utils/initializer/registerPlugins.js +11 -3
- 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/custom-function/controller.ts +94 -0
- package/src/auth/providers/custom-function/dtos.ts +16 -0
- package/src/auth/providers/custom-function/schema.ts +25 -0
- package/src/auth/providers/local-userpass/controller.ts +45 -71
- package/src/auth/utils.ts +10 -0
- package/src/constants.ts +14 -2
- 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/helpers.ts +6 -1
- package/src/utils/context/index.ts +46 -29
- package/src/utils/context/interface.ts +5 -1
- package/src/utils/initializer/registerPlugins.ts +9 -1
- 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,
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FastifyInstance } from 'fastify';
|
|
2
|
+
/**
|
|
3
|
+
* Controller for handling custom function login.
|
|
4
|
+
* @testable
|
|
5
|
+
* @param {FastifyInstance} app - The Fastify instance.
|
|
6
|
+
*/
|
|
7
|
+
export declare function customFunctionController(app: FastifyInstance): Promise<void>;
|
|
8
|
+
//# sourceMappingURL=controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../../src/auth/providers/custom-function/controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAYzC;;;;GAIG;AACH,wBAAsB,wBAAwB,CAAC,GAAG,EAAE,eAAe,iBA2ElE"}
|
|
@@ -0,0 +1,83 @@
|
|
|
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.customFunctionController = customFunctionController;
|
|
13
|
+
const bson_1 = require("bson");
|
|
14
|
+
const constants_1 = require("../../../constants");
|
|
15
|
+
const state_1 = require("../../../state");
|
|
16
|
+
const context_1 = require("../../../utils/context");
|
|
17
|
+
const utils_1 = require("../../utils");
|
|
18
|
+
const schema_1 = require("./schema");
|
|
19
|
+
/**
|
|
20
|
+
* Controller for handling custom function login.
|
|
21
|
+
* @testable
|
|
22
|
+
* @param {FastifyInstance} app - The Fastify instance.
|
|
23
|
+
*/
|
|
24
|
+
function customFunctionController(app) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const functionsList = state_1.StateManager.select('functions');
|
|
27
|
+
const services = state_1.StateManager.select('services');
|
|
28
|
+
/**
|
|
29
|
+
* Endpoint for user login.
|
|
30
|
+
*
|
|
31
|
+
* @route {POST} /login
|
|
32
|
+
* @param {LoginDto} req - The request object with login data.
|
|
33
|
+
* @returns {Promise<Object>} A promise resolving with access and refresh tokens.
|
|
34
|
+
*/
|
|
35
|
+
app.post(utils_1.AUTH_ENDPOINTS.LOGIN, {
|
|
36
|
+
schema: schema_1.LOGIN_SCHEMA
|
|
37
|
+
}, function (req) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
const { providers } = constants_1.AUTH_CONFIG;
|
|
40
|
+
const authFunctionName = providers["custom-function"].authFunctionName;
|
|
41
|
+
if (!authFunctionName || !functionsList[authFunctionName]) {
|
|
42
|
+
throw new Error("Missing Auth Function");
|
|
43
|
+
}
|
|
44
|
+
const { ips, host, hostname, url, method, ip, id } = req;
|
|
45
|
+
const res = yield (0, context_1.GenerateContext)({
|
|
46
|
+
args: [
|
|
47
|
+
req.body
|
|
48
|
+
],
|
|
49
|
+
app,
|
|
50
|
+
rules: {},
|
|
51
|
+
user: {},
|
|
52
|
+
currentFunction: functionsList[authFunctionName],
|
|
53
|
+
functionsList,
|
|
54
|
+
services,
|
|
55
|
+
request: {
|
|
56
|
+
ips,
|
|
57
|
+
host,
|
|
58
|
+
hostname,
|
|
59
|
+
url,
|
|
60
|
+
method,
|
|
61
|
+
ip,
|
|
62
|
+
id
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
const currentUserData = {
|
|
66
|
+
_id: new bson_1.ObjectId(res.id),
|
|
67
|
+
user_data: {
|
|
68
|
+
_id: new bson_1.ObjectId(res.id),
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
if (res.id) {
|
|
72
|
+
return {
|
|
73
|
+
access_token: this.createAccessToken(currentUserData),
|
|
74
|
+
refresh_token: this.createRefreshToken(currentUserData),
|
|
75
|
+
device_id: '',
|
|
76
|
+
user_id: res.id
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
throw new Error("Authentication Failed");
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type LoginUserDto = {
|
|
2
|
+
username: string;
|
|
3
|
+
password: string;
|
|
4
|
+
};
|
|
5
|
+
export type LoginSuccessDto = {
|
|
6
|
+
access_token: string;
|
|
7
|
+
device_id: string;
|
|
8
|
+
refresh_token: string;
|
|
9
|
+
user_id: string;
|
|
10
|
+
};
|
|
11
|
+
export interface LoginDto {
|
|
12
|
+
Body: LoginUserDto;
|
|
13
|
+
Reply: LoginSuccessDto;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=dtos.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dtos.d.ts","sourceRoot":"","sources":["../../../../src/auth/providers/custom-function/dtos.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,aAAa,EAAE,MAAM,CAAA;IACrB,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,YAAY,CAAA;IAClB,KAAK,EAAE,eAAe,CAAA;CACvB"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare const LOGIN_SCHEMA: {
|
|
2
|
+
body: {
|
|
3
|
+
type: string;
|
|
4
|
+
properties: {
|
|
5
|
+
apiKey: {
|
|
6
|
+
type: string;
|
|
7
|
+
};
|
|
8
|
+
options: {
|
|
9
|
+
type: string;
|
|
10
|
+
properties: {
|
|
11
|
+
device: {
|
|
12
|
+
type: string;
|
|
13
|
+
properties: {
|
|
14
|
+
sdkVersion: {
|
|
15
|
+
type: string;
|
|
16
|
+
};
|
|
17
|
+
platform: {
|
|
18
|
+
type: string;
|
|
19
|
+
};
|
|
20
|
+
platformVersion: {
|
|
21
|
+
type: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
required: string[];
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/auth/providers/custom-function/schema.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwBxB,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LOGIN_SCHEMA = void 0;
|
|
4
|
+
exports.LOGIN_SCHEMA = {
|
|
5
|
+
body: {
|
|
6
|
+
type: 'object',
|
|
7
|
+
properties: {
|
|
8
|
+
apiKey: { type: 'string' },
|
|
9
|
+
options: {
|
|
10
|
+
type: "object",
|
|
11
|
+
properties: {
|
|
12
|
+
device: {
|
|
13
|
+
type: "object",
|
|
14
|
+
properties: {
|
|
15
|
+
sdkVersion: { type: 'string' },
|
|
16
|
+
platform: { type: 'string' },
|
|
17
|
+
platformVersion: { type: 'string' }
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
required: ['apiKey', 'options']
|
|
24
|
+
}
|
|
25
|
+
};
|
|
@@ -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/auth/utils.d.ts
CHANGED
|
@@ -75,6 +75,7 @@ export interface AuthConfig {
|
|
|
75
75
|
auth_collection?: string;
|
|
76
76
|
'api-key': ApiKey;
|
|
77
77
|
'local-userpass': LocalUserpass;
|
|
78
|
+
'custom-function': CustomFunction;
|
|
78
79
|
}
|
|
79
80
|
interface ApiKey {
|
|
80
81
|
name: string;
|
|
@@ -87,6 +88,14 @@ interface LocalUserpass {
|
|
|
87
88
|
disabled: boolean;
|
|
88
89
|
config: Config;
|
|
89
90
|
}
|
|
91
|
+
interface CustomFunction {
|
|
92
|
+
name: "custom-function";
|
|
93
|
+
type: "custom-function";
|
|
94
|
+
disabled: boolean;
|
|
95
|
+
config: {
|
|
96
|
+
"authFunctionName": string;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
90
99
|
export interface Config {
|
|
91
100
|
autoConfirm: boolean;
|
|
92
101
|
resetFunctionName: string;
|
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":"AAGA,eAAO,MAAM,YAAY;;;;;;;;;;;;;CASxB,CAAA;AAED,eAAO,MAAM,YAAY;;;;;;;;;;;;;CASxB,CAAA;AAED,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;CAUhC,CAAA;AAED,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;CAS/B,CAAA;AAED,oBAAY,cAAc;IACxB,KAAK,WAAW;IAChB,YAAY,cAAc;IAC1B,OAAO,aAAa;IACpB,OAAO,aAAa;IACpB,KAAK,gBAAgB;IACrB,aAAa,WAAW;IACxB,UAAU,sBAAsB;CACjC;AAED,oBAAY,WAAW;IACrB,mBAAmB,wBAAwB;IAC3C,aAAa,mCAAmC;IAChD,oBAAoB,sCAAsC;CAC3D;AAED,MAAM,WAAW,UAAU;IACzB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,EAAE,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/auth/utils.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY;;;;;;;;;;;;;CASxB,CAAA;AAED,eAAO,MAAM,YAAY;;;;;;;;;;;;;CASxB,CAAA;AAED,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;CAUhC,CAAA;AAED,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;CAS/B,CAAA;AAED,oBAAY,cAAc;IACxB,KAAK,WAAW;IAChB,YAAY,cAAc;IAC1B,OAAO,aAAa;IACpB,OAAO,aAAa;IACpB,KAAK,gBAAgB;IACrB,aAAa,WAAW;IACxB,UAAU,sBAAsB;CACjC;AAED,oBAAY,WAAW;IACrB,mBAAmB,wBAAwB;IAC3C,aAAa,mCAAmC;IAChD,oBAAoB,sCAAsC;CAC3D;AAED,MAAM,WAAW,UAAU;IACzB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,EAAE,aAAa,CAAA;IAC/B,iBAAiB,EAAE,cAAc,CAAA;CAClC;AAED,UAAU,MAAM;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,OAAO,CAAA;CAClB;AACD,UAAU,aAAa;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,OAAO,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;CACf;AAED,UAAU,cAAc;IACtB,IAAI,EAAE,iBAAiB,CAAC;IACxB,IAAI,EAAE,iBAAiB,CAAC;IACxB,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE;QACN,kBAAkB,EAAE,MAAM,CAAA;KAC3B,CAAA;CACF;AAED,MAAM,WAAW,MAAM;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;IACzB,UAAU,EAAE;QACV,IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,EAAE,MAAM,CAAA;QACf,SAAS,EAAE,MAAM,CAAA;KAClB,CAAA;CACF;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;AAED,eAAO,MAAM,aAAa,mBAAmB,CAAA;AAE7C;;;GAGG;AACH,eAAO,MAAM,cAAc,QAAO,UAGjC,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,kBAAkB,QAAO,oBAGrC,CAAA;AAED,eAAO,MAAM,aAAa,GACxB,qBAAqB,MAAM,EAC3B,OAAO,MAAM,EACb,SAAS,MAAM;;;;;CA4ChB,CAAA"}
|
package/dist/constants.d.ts
CHANGED
|
@@ -17,5 +17,14 @@ export declare const AUTH_CONFIG: {
|
|
|
17
17
|
resetPasswordConfig: import("./auth/utils").Config;
|
|
18
18
|
user_id_field: string;
|
|
19
19
|
on_user_creation_function_name: string;
|
|
20
|
+
providers: {
|
|
21
|
+
"custom-function": {
|
|
22
|
+
authFunctionName: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export declare const S3_CONFIG: {
|
|
27
|
+
ACCESS_KEY_ID: string | undefined;
|
|
28
|
+
SECRET_ACCESS_KEY: string | undefined;
|
|
20
29
|
};
|
|
21
30
|
//# 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;
|
|
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;AAGpC,eAAO,MAAM,WAAW;;;;;;;;;;;;CAUvB,CAAA;AAID,eAAO,MAAM,SAAS;;;CAGrB,CAAA"}
|
package/dist/constants.js
CHANGED
|
@@ -10,11 +10,12 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
}
|
|
11
11
|
return t;
|
|
12
12
|
};
|
|
13
|
+
var _a, _b;
|
|
13
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.AUTH_CONFIG = exports.DB_NAME = exports.HTTPS_SCHEMA = exports.API_VERSION = exports.DEFAULT_CONFIG = void 0;
|
|
15
|
+
exports.S3_CONFIG = exports.AUTH_CONFIG = exports.DB_NAME = exports.HTTPS_SCHEMA = exports.API_VERSION = exports.DEFAULT_CONFIG = void 0;
|
|
15
16
|
const utils_1 = require("./auth/utils");
|
|
16
17
|
const { database_name, collection_name = 'users', user_id_field = 'id', on_user_creation_function_name } = (0, utils_1.loadCustomUserData)();
|
|
17
|
-
const
|
|
18
|
+
const _c = (0, utils_1.loadAuthConfig)(), { auth_collection = 'auth_users' } = _c, configuration = __rest(_c, ["auth_collection"]);
|
|
18
19
|
exports.DEFAULT_CONFIG = {
|
|
19
20
|
PORT: Number(process.env.PORT) || 3000,
|
|
20
21
|
MONGODB_URL: process.env.MONGODB_URL || '',
|
|
@@ -27,11 +28,19 @@ exports.DEFAULT_CONFIG = {
|
|
|
27
28
|
exports.API_VERSION = `/api/client/${exports.DEFAULT_CONFIG.API_VERSION}`;
|
|
28
29
|
exports.HTTPS_SCHEMA = exports.DEFAULT_CONFIG.HTTPS_SCHEMA;
|
|
29
30
|
exports.DB_NAME = database_name;
|
|
31
|
+
// TODO spostare nell'oggetto providers anche le altre configurazioni
|
|
30
32
|
exports.AUTH_CONFIG = {
|
|
31
33
|
authCollection: auth_collection,
|
|
32
34
|
userCollection: collection_name,
|
|
33
35
|
resetPasswordCollection: 'reset-password-requests',
|
|
34
|
-
resetPasswordConfig: configuration['local-userpass'].config,
|
|
36
|
+
resetPasswordConfig: (_a = configuration['local-userpass']) === null || _a === void 0 ? void 0 : _a.config,
|
|
35
37
|
user_id_field,
|
|
36
|
-
on_user_creation_function_name
|
|
38
|
+
on_user_creation_function_name,
|
|
39
|
+
providers: {
|
|
40
|
+
"custom-function": (_b = configuration['custom-function']) === null || _b === void 0 ? void 0 : _b.config
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
exports.S3_CONFIG = {
|
|
44
|
+
ACCESS_KEY_ID: process.env.S3_ACCESS_KEY_ID,
|
|
45
|
+
SECRET_ACCESS_KEY: process.env.S3_SECRET_ACCESS_KEY
|
|
37
46
|
};
|
|
@@ -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"}
|