@flowerforce/flowerbase 1.0.3-beta.3 → 1.0.3-beta.5
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/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/utils.d.ts +9 -0
- package/dist/auth/utils.d.ts.map +1 -1
- package/dist/constants.d.ts +5 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +8 -3
- package/dist/features/functions/controller.d.ts.map +1 -1
- package/dist/features/functions/controller.js +6 -4
- package/dist/features/functions/interface.d.ts +1 -0
- package/dist/features/functions/interface.d.ts.map +1 -1
- package/dist/features/functions/utils.d.ts +1 -1
- package/dist/features/functions/utils.d.ts.map +1 -1
- package/dist/features/functions/utils.js +2 -2
- package/dist/services/mongodb-atlas/index.d.ts.map +1 -1
- package/dist/services/mongodb-atlas/index.js +4 -1
- package/dist/services/mongodb-atlas/model.d.ts +1 -1
- package/dist/services/mongodb-atlas/model.d.ts.map +1 -1
- package/dist/utils/context/helpers.d.ts +11 -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 +3 -2
- package/dist/utils/context/interface.d.ts +4 -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/package.json +1 -1
- 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/utils.ts +10 -0
- package/src/constants.ts +7 -2
- package/src/features/functions/controller.ts +6 -4
- package/src/features/functions/interface.ts +1 -0
- package/src/features/functions/utils.ts +3 -1
- package/src/services/mongodb-atlas/index.ts +4 -1
- package/src/services/mongodb-atlas/model.ts +1 -0
- package/src/utils/context/helpers.ts +6 -1
- package/src/utils/context/index.ts +4 -2
- package/src/utils/context/interface.ts +3 -1
- package/src/utils/initializer/registerPlugins.ts +9 -1
|
@@ -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
|
+
};
|
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,M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
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
|
+
};
|
|
20
25
|
};
|
|
21
26
|
export declare const S3_CONFIG: {
|
|
22
27
|
ACCESS_KEY_ID: string | undefined;
|
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
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,13 +28,17 @@ 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
|
+
}
|
|
37
42
|
};
|
|
38
43
|
exports.S3_CONFIG = {
|
|
39
44
|
ACCESS_KEY_ID: process.env.S3_ACCESS_KEY_ID,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../src/features/functions/controller.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAGhD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,EAAE,
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../src/features/functions/controller.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAGhD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,EAAE,kBA0FjC,CAAA"}
|
|
@@ -28,9 +28,10 @@ const functionsController = (app_1, _a) => __awaiter(void 0, [app_1, _a], void 0
|
|
|
28
28
|
const { name: method, arguments: args } = req.body;
|
|
29
29
|
if ('service' in req.body) {
|
|
30
30
|
const serviceFn = services_1.services[req.body.service];
|
|
31
|
-
if (
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
if (req.body.service)
|
|
32
|
+
if (!serviceFn) {
|
|
33
|
+
throw new Error(`Service "${req.body.service}" does not exist`);
|
|
34
|
+
}
|
|
34
35
|
const [{ database, collection, query, update, document, documents, pipeline = [] }] = args;
|
|
35
36
|
const currentMethod = serviceFn(app, { rules, user })
|
|
36
37
|
.db(database)
|
|
@@ -41,7 +42,8 @@ const functionsController = (app_1, _a) => __awaiter(void 0, [app_1, _a], void 0
|
|
|
41
42
|
update,
|
|
42
43
|
document,
|
|
43
44
|
documents,
|
|
44
|
-
pipeline
|
|
45
|
+
pipeline,
|
|
46
|
+
isClient: true
|
|
45
47
|
});
|
|
46
48
|
return operatorsByType[method]();
|
|
47
49
|
}
|
|
@@ -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,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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,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,7 +10,7 @@ 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 }: ExecuteQueryParams) => Promise<{
|
|
13
|
+
export declare const executeQuery: ({ currentMethod, query, update, document, documents, pipeline, isClient }: ExecuteQueryParams) => Promise<{
|
|
14
14
|
find: () => Promise<any[]>;
|
|
15
15
|
findOne: () => Promise<unknown>;
|
|
16
16
|
deleteOne: () => Promise<unknown>;
|
|
@@ -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,2EAQhC,kBAAkB;;;;;;;;;;EAsCpB,CAAA"}
|
|
@@ -58,7 +58,7 @@ 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 }) {
|
|
61
|
+
const executeQuery = (_a) => __awaiter(void 0, [_a], void 0, function* ({ currentMethod, query, update, document, documents, pipeline, isClient = false }) {
|
|
62
62
|
return {
|
|
63
63
|
find: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
64
|
return yield currentMethod(bson_1.EJSON.deserialize(query)).toArray();
|
|
@@ -68,7 +68,7 @@ const executeQuery = (_a) => __awaiter(void 0, [_a], void 0, function* ({ curren
|
|
|
68
68
|
insertOne: () => currentMethod(bson_1.EJSON.deserialize(document)),
|
|
69
69
|
updateOne: () => currentMethod(bson_1.EJSON.deserialize(query), bson_1.EJSON.deserialize(update)),
|
|
70
70
|
aggregate: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
|
-
return (yield currentMethod(bson_1.EJSON.deserialize(pipeline) // TODO -> ADD OPTIONS
|
|
71
|
+
return (yield currentMethod(isClient, bson_1.EJSON.deserialize(pipeline) // TODO -> ADD OPTIONS
|
|
72
72
|
)).toArray();
|
|
73
73
|
}),
|
|
74
74
|
insertMany: () => currentMethod(bson_1.EJSON.deserialize(documents)),
|
|
@@ -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;AAoqBrF,QAAA,MAAM,YAAY,EAAE,oBAmBlB,CAAA;AAEF,eAAe,YAAY,CAAA"}
|
|
@@ -358,7 +358,10 @@ const getOperators = (collection, { rules = {}, collName, user, run_as_system })
|
|
|
358
358
|
return collection.watch(pipeline, options);
|
|
359
359
|
},
|
|
360
360
|
//TODO -> add filter & rules in aggregate
|
|
361
|
-
aggregate: (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (pipeline = [], options) {
|
|
361
|
+
aggregate: (isClient_1, ...args_1) => __awaiter(void 0, [isClient_1, ...args_1], void 0, function* (isClient, pipeline = [], options) {
|
|
362
|
+
if (isClient) {
|
|
363
|
+
throw new Error("Aggregate operator from cliente is not implemented! Move it to a function");
|
|
364
|
+
}
|
|
362
365
|
if (run_as_system) {
|
|
363
366
|
return collection.aggregate(pipeline, options);
|
|
364
367
|
}
|
|
@@ -30,7 +30,7 @@ export type GetOperatorsFunction = (collection: Collection<Document>, { rules, c
|
|
|
30
30
|
updateOne: (...params: Parameters<Method<'updateOne'>>) => ReturnType<Method<'updateOne'>>;
|
|
31
31
|
find: (...params: Parameters<Method<'find'>>) => FindCursor;
|
|
32
32
|
watch: (...params: Parameters<Method<'watch'>>) => ReturnType<Method<'watch'>>;
|
|
33
|
-
aggregate: (...params: Parameters<Method<'aggregate'>>) => Promise<ReturnType<Method<'aggregate'>>>;
|
|
33
|
+
aggregate: (isClient: boolean, ...params: Parameters<Method<'aggregate'>>) => Promise<ReturnType<Method<'aggregate'>>>;
|
|
34
34
|
insertMany: (...params: Parameters<Method<'insertMany'>>) => ReturnType<Method<'insertMany'>>;
|
|
35
35
|
updateMany: (...params: Parameters<Method<'updateMany'>>) => ReturnType<Method<'updateMany'>>;
|
|
36
36
|
deleteMany: (...params: Parameters<Method<'deleteMany'>>) => ReturnType<Method<'deleteMany'>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/services/mongodb-atlas/model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AACzC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAClE,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACtC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAA;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAA;AAElD,MAAM,MAAM,oBAAoB,GAAG,CACjC,GAAG,EAAE,eAAe,EACpB,EACE,KAAK,EACL,IAAI,EACJ,aAAa,EACd,EAAE;IACD,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB,KACE;IACH,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK;QACtB,UAAU,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,UAAU,CAA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AA;CACtC,CAAA;AAGD,oBAAY,eAAe;IACzB,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,MAAM,WAAW;IACjB,MAAM,WAAW;CAElB"}
|
|
@@ -11,12 +11,22 @@ import { GenerateContextDataParams } from './interface';
|
|
|
11
11
|
* @param currentFunction -> the function's name that should be called
|
|
12
12
|
* @param functionsList -> the list of all functions
|
|
13
13
|
*/
|
|
14
|
-
export declare const generateContextData: ({ user, services, app, rules, currentFunction, functionsList, GenerateContext }: GenerateContextDataParams) => {
|
|
14
|
+
export declare const generateContextData: ({ user, services, app, rules, currentFunction, functionsList, GenerateContext, request }: GenerateContextDataParams) => {
|
|
15
15
|
BSON: typeof mongodb.BSON;
|
|
16
16
|
console: {
|
|
17
17
|
log: (...args: Arguments) => void;
|
|
18
18
|
};
|
|
19
19
|
context: {
|
|
20
|
+
request: {
|
|
21
|
+
remoteIPAddress: string | undefined;
|
|
22
|
+
id?: string | undefined;
|
|
23
|
+
method?: string | undefined;
|
|
24
|
+
url?: string | undefined;
|
|
25
|
+
host?: string | undefined;
|
|
26
|
+
ips?: string[];
|
|
27
|
+
hostname?: string | undefined;
|
|
28
|
+
ip?: string | undefined;
|
|
29
|
+
};
|
|
20
30
|
user: unknown;
|
|
21
31
|
environment: {
|
|
22
32
|
tag: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/utils/context/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AAEvD;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,GAAI,
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/utils/context/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AAEvD;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,GAAI,0FASjC,yBAAyB;;;uBAGT,SAAS;;;;;;;;;;;;;;;;;;uBAcX,MAAM;;;+BAGE,MAAM,OAAO,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BA/BG,GAE3C;;;;;;;;;;;4BA8CgB,MAAM,OAAO,aAAa,WAAW,SAAS;;;CAclE,CAAA"}
|
|
@@ -12,7 +12,7 @@ const mongodb_1 = require("@fastify/mongodb");
|
|
|
12
12
|
* @param currentFunction -> the function's name that should be called
|
|
13
13
|
* @param functionsList -> the list of all functions
|
|
14
14
|
*/
|
|
15
|
-
const generateContextData = ({ user, services, app, rules, currentFunction, functionsList, GenerateContext }) => ({
|
|
15
|
+
const generateContextData = ({ user, services, app, rules, currentFunction, functionsList, GenerateContext, request }) => ({
|
|
16
16
|
BSON: mongodb_1.mongodb.BSON,
|
|
17
17
|
console: {
|
|
18
18
|
log: (...args) => {
|
|
@@ -20,6 +20,7 @@ const generateContextData = ({ user, services, app, rules, currentFunction, func
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
context: {
|
|
23
|
+
request: Object.assign(Object.assign({}, request), { remoteIPAddress: request === null || request === void 0 ? void 0 : request.ip }),
|
|
23
24
|
user,
|
|
24
25
|
environment: {
|
|
25
26
|
tag: process.env.NODE_ENV
|
|
@@ -10,5 +10,5 @@ import { GenerateContextParams } from './interface';
|
|
|
10
10
|
* @param functionsList -> the list of all functions
|
|
11
11
|
* @param services -> the list of all services
|
|
12
12
|
*/
|
|
13
|
-
export declare function GenerateContext({ args, app, rules, user, currentFunction, functionsList, services, runAsSystem, deserializeArgs, enqueue }: GenerateContextParams): Promise<any>;
|
|
13
|
+
export declare function GenerateContext({ args, app, rules, user, currentFunction, functionsList, services, runAsSystem, deserializeArgs, enqueue, request }: GenerateContextParams): Promise<any>;
|
|
14
14
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/context/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAEnD;;;;;;;;;;GAUG;AACH,wBAAsB,eAAe,CAAC,EACpC,IAAI,EACJ,GAAG,EACH,KAAK,EACL,IAAI,EACJ,eAAe,EACf,aAAa,EACb,QAAQ,EACR,WAAW,EACX,eAAsB,EACtB,OAAO,EACR,EAAE,qBAAqB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/context/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAEnD;;;;;;;;;;GAUG;AACH,wBAAsB,eAAe,CAAC,EACpC,IAAI,EACJ,GAAG,EACH,KAAK,EACL,IAAI,EACJ,eAAe,EACf,aAAa,EACb,QAAQ,EACR,WAAW,EACX,eAAsB,EACtB,OAAO,EACP,OAAO,EACR,EAAE,qBAAqB,gBA2CvB"}
|
|
@@ -30,7 +30,7 @@ const helpers_1 = require("./helpers");
|
|
|
30
30
|
* @param services -> the list of all services
|
|
31
31
|
*/
|
|
32
32
|
function GenerateContext(_a) {
|
|
33
|
-
return __awaiter(this, arguments, void 0, function* ({ args, app, rules, user, currentFunction, functionsList, services, runAsSystem, deserializeArgs = true, enqueue }) {
|
|
33
|
+
return __awaiter(this, arguments, void 0, function* ({ args, app, rules, user, currentFunction, functionsList, services, runAsSystem, deserializeArgs = true, enqueue, request }) {
|
|
34
34
|
const functionsQueue = state_1.StateManager.select("functionsQueue");
|
|
35
35
|
const functionToRun = Object.assign({ run_as_system: runAsSystem }, currentFunction);
|
|
36
36
|
const run = () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -42,7 +42,8 @@ function GenerateContext(_a) {
|
|
|
42
42
|
rules,
|
|
43
43
|
currentFunction: functionToRun,
|
|
44
44
|
functionsList,
|
|
45
|
-
GenerateContext
|
|
45
|
+
GenerateContext,
|
|
46
|
+
request
|
|
46
47
|
});
|
|
47
48
|
try {
|
|
48
49
|
const entryFile = (_b = (_a = require.main) === null || _a === void 0 ? void 0 : _a.filename) !== null && _b !== void 0 ? _b : process.cwd();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FastifyInstance } from 'fastify';
|
|
1
|
+
import { FastifyInstance, FastifyRequest } from 'fastify';
|
|
2
2
|
import { Arguments, User } from '../../auth/dtos';
|
|
3
3
|
import { Function, Functions } from '../../features/functions/interface';
|
|
4
4
|
import { Rules } from '../../features/rules/interface';
|
|
@@ -14,8 +14,11 @@ export interface GenerateContextParams {
|
|
|
14
14
|
runAsSystem?: boolean;
|
|
15
15
|
deserializeArgs?: boolean;
|
|
16
16
|
enqueue?: boolean;
|
|
17
|
+
request?: ContextRequest;
|
|
17
18
|
}
|
|
19
|
+
type ContextRequest = Pick<FastifyRequest, "ips" | "host" | "hostname" | "url" | "method" | "ip" | "id">;
|
|
18
20
|
export interface GenerateContextDataParams extends Omit<GenerateContextParams, 'args'> {
|
|
19
21
|
GenerateContext: (params: GenerateContextParams) => Promise<void>;
|
|
20
22
|
}
|
|
23
|
+
export {};
|
|
21
24
|
//# sourceMappingURL=interface.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../src/utils/context/interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../src/utils/context/interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AACzD,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAA;AACxE,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAA;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAEnD,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,eAAe,CAAA;IACpB,eAAe,EAAE,QAAQ,CAAA;IACzB,aAAa,EAAE,SAAS,CAAA;IACxB,KAAK,EAAE,KAAK,CAAA;IACZ,IAAI,EAAE,IAAI,CAAA;IACV,QAAQ,EAAE,QAAQ,CAAA;IAClB,IAAI,EAAE,SAAS,CAAA;IACf,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,OAAO,CAAC,EAAE,cAAc,CAAA;CACzB;AAED,KAAK,cAAc,GAAG,IAAI,CAAC,cAAc,EAAE,KAAK,GAAG,MAAM,GAAG,UAAU,GAAG,KAAK,GAAG,QAAQ,GAAG,IAAI,GAAG,IAAI,CAAC,CAAA;AACxG,MAAM,WAAW,yBAA0B,SAAQ,IAAI,CAAC,qBAAqB,EAAE,MAAM,CAAC;IACpF,eAAe,EAAE,CAAC,MAAM,EAAE,qBAAqB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAClE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerPlugins.d.ts","sourceRoot":"","sources":["../../../src/utils/initializer/registerPlugins.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"registerPlugins.d.ts","sourceRoot":"","sources":["../../../src/utils/initializer/registerPlugins.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAMzC,OAAO,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAA;AAE9D,KAAK,gBAAgB,GAAG,eAAe,CAAC,UAAU,CAAC,CAAA;AAGnD,KAAK,qBAAqB,GAAG;IAC3B,QAAQ,EAAE,gBAAgB,CAAA;IAC1B,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,aAAa,EAAE,SAAS,CAAA;CACzB,CAAA;AAQD;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAAU,oDAKnC,qBAAqB,kBAoBvB,CAAA"}
|
|
@@ -17,7 +17,8 @@ const cors_1 = __importDefault(require("@fastify/cors"));
|
|
|
17
17
|
const mongodb_1 = __importDefault(require("@fastify/mongodb"));
|
|
18
18
|
const controller_1 = require("../../auth/controller");
|
|
19
19
|
const jwt_1 = __importDefault(require("../../auth/plugins/jwt"));
|
|
20
|
-
const controller_2 = require("../../auth/providers/
|
|
20
|
+
const controller_2 = require("../../auth/providers/custom-function/controller");
|
|
21
|
+
const controller_3 = require("../../auth/providers/local-userpass/controller");
|
|
21
22
|
const constants_1 = require("../../constants");
|
|
22
23
|
/**
|
|
23
24
|
* > Used to register all plugins
|
|
@@ -50,7 +51,7 @@ const registerPlugins = (_a) => __awaiter(void 0, [_a], void 0, function* ({ reg
|
|
|
50
51
|
});
|
|
51
52
|
exports.registerPlugins = registerPlugins;
|
|
52
53
|
/**
|
|
53
|
-
* > Used to generate the register
|
|
54
|
+
* > Used to generate the register config
|
|
54
55
|
* @param mongodbUrl -> the database connection string
|
|
55
56
|
* @param jwtSecret -> connection jwt
|
|
56
57
|
* @testable
|
|
@@ -87,10 +88,17 @@ const getRegisterConfig = (_a) => __awaiter(void 0, [_a], void 0, function* ({ m
|
|
|
87
88
|
},
|
|
88
89
|
{
|
|
89
90
|
pluginName: 'localUserPassController',
|
|
90
|
-
plugin:
|
|
91
|
+
plugin: controller_3.localUserPassController,
|
|
91
92
|
options: {
|
|
92
93
|
prefix: `${constants_1.API_VERSION}/app/:appId/auth/providers/local-userpass`
|
|
93
94
|
}
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
pluginName: 'customFunctionController',
|
|
98
|
+
plugin: controller_2.customFunctionController,
|
|
99
|
+
options: {
|
|
100
|
+
prefix: `${constants_1.API_VERSION}/app/:appId/auth/providers/custom-function`
|
|
101
|
+
}
|
|
94
102
|
}
|
|
95
103
|
];
|
|
96
104
|
});
|
package/package.json
CHANGED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { ObjectId } from 'bson'
|
|
2
|
+
import { FastifyInstance } from 'fastify'
|
|
3
|
+
import { AUTH_CONFIG } from '../../../constants'
|
|
4
|
+
import { StateManager } from '../../../state'
|
|
5
|
+
import { GenerateContext } from '../../../utils/context'
|
|
6
|
+
import {
|
|
7
|
+
AUTH_ENDPOINTS,
|
|
8
|
+
} from '../../utils'
|
|
9
|
+
import {
|
|
10
|
+
LoginDto
|
|
11
|
+
} from './dtos'
|
|
12
|
+
import { LOGIN_SCHEMA } from './schema'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Controller for handling custom function login.
|
|
16
|
+
* @testable
|
|
17
|
+
* @param {FastifyInstance} app - The Fastify instance.
|
|
18
|
+
*/
|
|
19
|
+
export async function customFunctionController(app: FastifyInstance) {
|
|
20
|
+
|
|
21
|
+
const functionsList = StateManager.select('functions')
|
|
22
|
+
const services = StateManager.select('services')
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Endpoint for user login.
|
|
26
|
+
*
|
|
27
|
+
* @route {POST} /login
|
|
28
|
+
* @param {LoginDto} req - The request object with login data.
|
|
29
|
+
* @returns {Promise<Object>} A promise resolving with access and refresh tokens.
|
|
30
|
+
*/
|
|
31
|
+
app.post<LoginDto>(
|
|
32
|
+
AUTH_ENDPOINTS.LOGIN,
|
|
33
|
+
{
|
|
34
|
+
schema: LOGIN_SCHEMA
|
|
35
|
+
},
|
|
36
|
+
async function (req) {
|
|
37
|
+
const { providers } = AUTH_CONFIG
|
|
38
|
+
const authFunctionName = providers["custom-function"].authFunctionName
|
|
39
|
+
|
|
40
|
+
if (!authFunctionName || !functionsList[authFunctionName]) {
|
|
41
|
+
throw new Error("Missing Auth Function")
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const {
|
|
45
|
+
ips,
|
|
46
|
+
host,
|
|
47
|
+
hostname,
|
|
48
|
+
url,
|
|
49
|
+
method,
|
|
50
|
+
ip,
|
|
51
|
+
id
|
|
52
|
+
} = req
|
|
53
|
+
|
|
54
|
+
const res = await GenerateContext({
|
|
55
|
+
args: [
|
|
56
|
+
req.body
|
|
57
|
+
],
|
|
58
|
+
app,
|
|
59
|
+
rules: {},
|
|
60
|
+
user: {},
|
|
61
|
+
currentFunction: functionsList[authFunctionName],
|
|
62
|
+
functionsList,
|
|
63
|
+
services,
|
|
64
|
+
request: {
|
|
65
|
+
ips,
|
|
66
|
+
host,
|
|
67
|
+
hostname,
|
|
68
|
+
url,
|
|
69
|
+
method,
|
|
70
|
+
ip,
|
|
71
|
+
id
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
const currentUserData = {
|
|
76
|
+
_id: new ObjectId(res.id),
|
|
77
|
+
user_data: {
|
|
78
|
+
_id: new ObjectId(res.id),
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (res.id) {
|
|
82
|
+
return {
|
|
83
|
+
access_token: this.createAccessToken(currentUserData),
|
|
84
|
+
refresh_token: this.createRefreshToken(currentUserData),
|
|
85
|
+
device_id: '',
|
|
86
|
+
user_id: res.id
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
throw new Error("Authentication Failed")
|
|
91
|
+
}
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type LoginUserDto = {
|
|
2
|
+
username: string
|
|
3
|
+
password: string
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export type LoginSuccessDto = {
|
|
7
|
+
access_token: string
|
|
8
|
+
device_id: string
|
|
9
|
+
refresh_token: string
|
|
10
|
+
user_id: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface LoginDto {
|
|
14
|
+
Body: LoginUserDto
|
|
15
|
+
Reply: LoginSuccessDto
|
|
16
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export const LOGIN_SCHEMA = {
|
|
2
|
+
body: {
|
|
3
|
+
type: 'object',
|
|
4
|
+
properties:
|
|
5
|
+
{
|
|
6
|
+
apiKey: { type: 'string' },
|
|
7
|
+
options: {
|
|
8
|
+
type: "object",
|
|
9
|
+
properties: {
|
|
10
|
+
device: {
|
|
11
|
+
type: "object",
|
|
12
|
+
properties: {
|
|
13
|
+
sdkVersion: { type: 'string' },
|
|
14
|
+
platform: { type: 'string' },
|
|
15
|
+
platformVersion: { type: 'string' }
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
},
|
|
23
|
+
required: ['apiKey', 'options']
|
|
24
|
+
}
|
|
25
|
+
}
|
package/src/auth/utils.ts
CHANGED
|
@@ -66,6 +66,7 @@ export interface AuthConfig {
|
|
|
66
66
|
auth_collection?: string
|
|
67
67
|
'api-key': ApiKey
|
|
68
68
|
'local-userpass': LocalUserpass
|
|
69
|
+
'custom-function': CustomFunction
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
interface ApiKey {
|
|
@@ -80,6 +81,15 @@ interface LocalUserpass {
|
|
|
80
81
|
config: Config
|
|
81
82
|
}
|
|
82
83
|
|
|
84
|
+
interface CustomFunction {
|
|
85
|
+
name: "custom-function",
|
|
86
|
+
type: "custom-function",
|
|
87
|
+
disabled: boolean,
|
|
88
|
+
config: {
|
|
89
|
+
"authFunctionName": string
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
83
93
|
export interface Config {
|
|
84
94
|
autoConfirm: boolean
|
|
85
95
|
resetFunctionName: string
|
package/src/constants.ts
CHANGED
|
@@ -20,13 +20,18 @@ export const DEFAULT_CONFIG = {
|
|
|
20
20
|
export const API_VERSION = `/api/client/${DEFAULT_CONFIG.API_VERSION}`
|
|
21
21
|
export const HTTPS_SCHEMA = DEFAULT_CONFIG.HTTPS_SCHEMA
|
|
22
22
|
export const DB_NAME = database_name
|
|
23
|
+
|
|
24
|
+
// TODO spostare nell'oggetto providers anche le altre configurazioni
|
|
23
25
|
export const AUTH_CONFIG = {
|
|
24
26
|
authCollection: auth_collection,
|
|
25
27
|
userCollection: collection_name,
|
|
26
28
|
resetPasswordCollection: 'reset-password-requests',
|
|
27
|
-
resetPasswordConfig: configuration['local-userpass']
|
|
29
|
+
resetPasswordConfig: configuration['local-userpass']?.config,
|
|
28
30
|
user_id_field,
|
|
29
|
-
on_user_creation_function_name
|
|
31
|
+
on_user_creation_function_name,
|
|
32
|
+
providers: {
|
|
33
|
+
"custom-function": configuration['custom-function']?.config
|
|
34
|
+
}
|
|
30
35
|
}
|
|
31
36
|
|
|
32
37
|
|
|
@@ -25,9 +25,10 @@ export const functionsController: FunctionController = async (
|
|
|
25
25
|
|
|
26
26
|
if ('service' in req.body) {
|
|
27
27
|
const serviceFn = services[req.body.service]
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
if (req.body.service)
|
|
29
|
+
if (!serviceFn) {
|
|
30
|
+
throw new Error(`Service "${req.body.service}" does not exist`)
|
|
31
|
+
}
|
|
31
32
|
const [{ database, collection, query, update, document, documents, pipeline = [] }] = args
|
|
32
33
|
|
|
33
34
|
const currentMethod = serviceFn(app, { rules, user })
|
|
@@ -40,7 +41,8 @@ export const functionsController: FunctionController = async (
|
|
|
40
41
|
update,
|
|
41
42
|
document,
|
|
42
43
|
documents,
|
|
43
|
-
pipeline
|
|
44
|
+
pipeline,
|
|
45
|
+
isClient: true
|
|
44
46
|
})
|
|
45
47
|
return operatorsByType[method as keyof typeof operatorsByType]()
|
|
46
48
|
}
|
|
@@ -46,7 +46,8 @@ export const executeQuery = async ({
|
|
|
46
46
|
update,
|
|
47
47
|
document,
|
|
48
48
|
documents,
|
|
49
|
-
pipeline
|
|
49
|
+
pipeline,
|
|
50
|
+
isClient = false
|
|
50
51
|
}: ExecuteQueryParams) => {
|
|
51
52
|
return {
|
|
52
53
|
find: async () =>
|
|
@@ -68,6 +69,7 @@ export const executeQuery = async ({
|
|
|
68
69
|
updateOne: () => currentMethod(EJSON.deserialize(query), EJSON.deserialize(update)),
|
|
69
70
|
aggregate: async () =>
|
|
70
71
|
(await (currentMethod as ReturnType<GetOperatorsFunction>['aggregate'])(
|
|
72
|
+
isClient,
|
|
71
73
|
EJSON.deserialize(pipeline) // TODO -> ADD OPTIONS
|
|
72
74
|
)).toArray(),
|
|
73
75
|
insertMany: () =>
|
|
@@ -439,7 +439,10 @@ const getOperators: GetOperatorsFunction = (
|
|
|
439
439
|
return collection.watch(pipeline, options)
|
|
440
440
|
},
|
|
441
441
|
//TODO -> add filter & rules in aggregate
|
|
442
|
-
aggregate: async (pipeline = [], options) => {
|
|
442
|
+
aggregate: async (isClient, pipeline = [], options) => {
|
|
443
|
+
if (isClient) {
|
|
444
|
+
throw new Error("Aggregate operator from cliente is not implemented! Move it to a function")
|
|
445
|
+
}
|
|
443
446
|
if (run_as_system) {
|
|
444
447
|
return collection.aggregate(pipeline, options)
|
|
445
448
|
}
|
|
@@ -53,6 +53,7 @@ export type GetOperatorsFunction = (
|
|
|
53
53
|
find: (...params: Parameters<Method<'find'>>) => FindCursor
|
|
54
54
|
watch: (...params: Parameters<Method<'watch'>>) => ReturnType<Method<'watch'>>
|
|
55
55
|
aggregate: (
|
|
56
|
+
isClient: boolean,
|
|
56
57
|
...params: Parameters<Method<'aggregate'>>
|
|
57
58
|
) => Promise<ReturnType<Method<'aggregate'>>>
|
|
58
59
|
insertMany: (
|
|
@@ -20,7 +20,8 @@ export const generateContextData = ({
|
|
|
20
20
|
rules,
|
|
21
21
|
currentFunction,
|
|
22
22
|
functionsList,
|
|
23
|
-
GenerateContext
|
|
23
|
+
GenerateContext,
|
|
24
|
+
request
|
|
24
25
|
}: GenerateContextDataParams) => ({
|
|
25
26
|
BSON: mongodb.BSON,
|
|
26
27
|
console: {
|
|
@@ -29,6 +30,10 @@ export const generateContextData = ({
|
|
|
29
30
|
}
|
|
30
31
|
},
|
|
31
32
|
context: {
|
|
33
|
+
request: {
|
|
34
|
+
...request,
|
|
35
|
+
remoteIPAddress: request?.ip
|
|
36
|
+
},
|
|
32
37
|
user,
|
|
33
38
|
environment: {
|
|
34
39
|
tag: process.env.NODE_ENV
|
|
@@ -26,7 +26,8 @@ export async function GenerateContext({
|
|
|
26
26
|
services,
|
|
27
27
|
runAsSystem,
|
|
28
28
|
deserializeArgs = true,
|
|
29
|
-
enqueue
|
|
29
|
+
enqueue,
|
|
30
|
+
request
|
|
30
31
|
}: GenerateContextParams) {
|
|
31
32
|
|
|
32
33
|
const functionsQueue = StateManager.select("functionsQueue")
|
|
@@ -42,7 +43,8 @@ export async function GenerateContext({
|
|
|
42
43
|
rules,
|
|
43
44
|
currentFunction: functionToRun,
|
|
44
45
|
functionsList,
|
|
45
|
-
GenerateContext
|
|
46
|
+
GenerateContext,
|
|
47
|
+
request
|
|
46
48
|
})
|
|
47
49
|
|
|
48
50
|
try {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FastifyInstance } from 'fastify'
|
|
1
|
+
import { FastifyInstance, FastifyRequest } from 'fastify'
|
|
2
2
|
import { Arguments, User } from '../../auth/dtos'
|
|
3
3
|
import { Function, Functions } from '../../features/functions/interface'
|
|
4
4
|
import { Rules } from '../../features/rules/interface'
|
|
@@ -15,8 +15,10 @@ export interface GenerateContextParams {
|
|
|
15
15
|
runAsSystem?: boolean
|
|
16
16
|
deserializeArgs?: boolean
|
|
17
17
|
enqueue?: boolean
|
|
18
|
+
request?: ContextRequest
|
|
18
19
|
}
|
|
19
20
|
|
|
21
|
+
type ContextRequest = Pick<FastifyRequest, "ips" | "host" | "hostname" | "url" | "method" | "ip" | "id">
|
|
20
22
|
export interface GenerateContextDataParams extends Omit<GenerateContextParams, 'args'> {
|
|
21
23
|
GenerateContext: (params: GenerateContextParams) => Promise<void>
|
|
22
24
|
}
|
|
@@ -3,6 +3,7 @@ import fastifyMongodb from '@fastify/mongodb'
|
|
|
3
3
|
import { FastifyInstance } from 'fastify'
|
|
4
4
|
import { authController } from '../../auth/controller'
|
|
5
5
|
import jwtAuthPlugin from '../../auth/plugins/jwt'
|
|
6
|
+
import { customFunctionController } from '../../auth/providers/custom-function/controller'
|
|
6
7
|
import { localUserPassController } from '../../auth/providers/local-userpass/controller'
|
|
7
8
|
import { API_VERSION } from '../../constants'
|
|
8
9
|
import { Functions } from '../../features/functions/interface'
|
|
@@ -58,7 +59,7 @@ export const registerPlugins = async ({
|
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
/**
|
|
61
|
-
* > Used to generate the register
|
|
62
|
+
* > Used to generate the register config
|
|
62
63
|
* @param mongodbUrl -> the database connection string
|
|
63
64
|
* @param jwtSecret -> connection jwt
|
|
64
65
|
* @testable
|
|
@@ -104,6 +105,13 @@ const getRegisterConfig = async ({
|
|
|
104
105
|
options: {
|
|
105
106
|
prefix: `${API_VERSION}/app/:appId/auth/providers/local-userpass`
|
|
106
107
|
}
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
pluginName: 'customFunctionController',
|
|
111
|
+
plugin: customFunctionController,
|
|
112
|
+
options: {
|
|
113
|
+
prefix: `${API_VERSION}/app/:appId/auth/providers/custom-function`
|
|
114
|
+
}
|
|
107
115
|
}
|
|
108
116
|
] as RegisterConfig[]
|
|
109
117
|
}
|