@flowerforce/flowerbase 1.0.3-beta.0 โ 1.0.3-beta.2
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/local-userpass/controller.d.ts.map +1 -1
- package/dist/auth/providers/local-userpass/controller.js +35 -27
- package/dist/features/functions/controller.d.ts.map +1 -1
- package/dist/features/functions/controller.js +3 -2
- package/dist/features/functions/dtos.d.ts +1 -0
- package/dist/features/functions/dtos.d.ts.map +1 -1
- 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 +2 -1
- package/dist/features/functions/utils.d.ts.map +1 -1
- package/dist/features/functions/utils.js +5 -3
- package/dist/features/triggers/utils.d.ts.map +1 -1
- package/dist/features/triggers/utils.js +7 -4
- 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 +6 -4
- package/dist/utils/context/interface.d.ts +1 -0
- package/dist/utils/context/interface.d.ts.map +1 -1
- package/dist/utils/rules.d.ts.map +1 -1
- package/dist/utils/rules.js +5 -1
- package/package.json +1 -1
- package/src/auth/providers/local-userpass/controller.ts +37 -26
- package/src/features/functions/controller.ts +3 -2
- package/src/features/functions/dtos.ts +8 -7
- package/src/features/functions/interface.ts +1 -0
- package/src/features/functions/utils.ts +8 -2
- package/src/features/triggers/utils.ts +11 -5
- package/src/utils/context/index.ts +7 -4
- package/src/utils/context/interface.ts +1 -0
- package/src/utils/rules.ts +6 -1
|
@@ -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,iBA4PjE"}
|
|
@@ -56,6 +56,7 @@ function localUserPassController(app) {
|
|
|
56
56
|
const result = yield db.collection(authCollection).insertOne({
|
|
57
57
|
email: email,
|
|
58
58
|
password: hashedPassword,
|
|
59
|
+
status: 'pending',
|
|
59
60
|
custom_data: {
|
|
60
61
|
// TODO da aggiungere in fase di registrazione utente, funzionalitร utile che realm non permetteva
|
|
61
62
|
}
|
|
@@ -74,33 +75,6 @@ function localUserPassController(app) {
|
|
|
74
75
|
]
|
|
75
76
|
}
|
|
76
77
|
}));
|
|
77
|
-
if (result && on_user_creation_function_name && functionsList[on_user_creation_function_name]) {
|
|
78
|
-
const user = yield db.collection(authCollection).findOne({ _id: result === null || result === void 0 ? void 0 : result.insertedId });
|
|
79
|
-
user === null || user === void 0 ? true : delete user.password;
|
|
80
|
-
try {
|
|
81
|
-
const response = yield (0, context_1.GenerateContext)({
|
|
82
|
-
args: [{
|
|
83
|
-
operationType: 'CREATE',
|
|
84
|
-
providers: 'local-userpass',
|
|
85
|
-
user,
|
|
86
|
-
time: new Date().getTime()
|
|
87
|
-
}],
|
|
88
|
-
app,
|
|
89
|
-
rules: {},
|
|
90
|
-
user: undefined,
|
|
91
|
-
currentFunction: functionsList[on_user_creation_function_name],
|
|
92
|
-
functionsList,
|
|
93
|
-
services: services_1.services
|
|
94
|
-
});
|
|
95
|
-
console.log("๐ ~ response:", response);
|
|
96
|
-
}
|
|
97
|
-
catch (error) {
|
|
98
|
-
console.log("๐ ~ error:", error);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
console.error('Error function on_user_creation_function_name: ', on_user_creation_function_name);
|
|
103
|
-
}
|
|
104
78
|
res.status(201);
|
|
105
79
|
return {
|
|
106
80
|
userId: result === null || result === void 0 ? void 0 : result.insertedId
|
|
@@ -132,6 +106,40 @@ function localUserPassController(app) {
|
|
|
132
106
|
? (yield db.collection(userCollection).findOne({ [user_id_field]: storedUser._id.toString() }))
|
|
133
107
|
: {};
|
|
134
108
|
const userWithCustomData = Object.assign(Object.assign({}, storedUser), { user_data: user });
|
|
109
|
+
if (storedUser && storedUser.status === 'pending') {
|
|
110
|
+
try {
|
|
111
|
+
yield (db === null || db === void 0 ? void 0 : db.collection(authCollection).updateOne({ _id: storedUser._id }, {
|
|
112
|
+
$set: {
|
|
113
|
+
status: 'confirmed'
|
|
114
|
+
}
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
console.log(">>> ๐ ~ localUserPassController ~ error:", error);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (storedUser && storedUser.status === 'pending' && on_user_creation_function_name && functionsList[on_user_creation_function_name]) {
|
|
122
|
+
storedUser === null || storedUser === void 0 ? true : delete storedUser.password;
|
|
123
|
+
try {
|
|
124
|
+
yield (0, context_1.GenerateContext)({
|
|
125
|
+
args: [{
|
|
126
|
+
operationType: 'CREATE',
|
|
127
|
+
providers: 'local-userpass',
|
|
128
|
+
user,
|
|
129
|
+
time: new Date().getTime()
|
|
130
|
+
}],
|
|
131
|
+
app,
|
|
132
|
+
rules: {},
|
|
133
|
+
user: undefined,
|
|
134
|
+
currentFunction: functionsList[on_user_creation_function_name],
|
|
135
|
+
functionsList,
|
|
136
|
+
services: services_1.services
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
console.log("๐ ~ error:", error);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
135
143
|
return {
|
|
136
144
|
access_token: this.createAccessToken(userWithCustomData),
|
|
137
145
|
refresh_token: this.createRefreshToken(userWithCustomData),
|
|
@@ -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,kBAwFjC,CAAA"}
|
|
@@ -31,7 +31,7 @@ const functionsController = (app_1, _a) => __awaiter(void 0, [app_1, _a], void 0
|
|
|
31
31
|
if (!serviceFn) {
|
|
32
32
|
throw new Error(`Service "${req.body.service}" does not exist`);
|
|
33
33
|
}
|
|
34
|
-
const [{ database, collection, query, update, document, documents }] = args;
|
|
34
|
+
const [{ database, collection, query, update, document, documents, pipeline = [] }] = args;
|
|
35
35
|
const currentMethod = serviceFn(app, { rules, user })
|
|
36
36
|
.db(database)
|
|
37
37
|
.collection(collection)[method];
|
|
@@ -40,7 +40,8 @@ const functionsController = (app_1, _a) => __awaiter(void 0, [app_1, _a], void 0
|
|
|
40
40
|
query,
|
|
41
41
|
update,
|
|
42
42
|
document,
|
|
43
|
-
documents
|
|
43
|
+
documents,
|
|
44
|
+
pipeline
|
|
44
45
|
});
|
|
45
46
|
return operatorsByType[method]();
|
|
46
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dtos.d.ts","sourceRoot":"","sources":["../../../src/features/functions/dtos.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAA;AAEzE,KAAK,UAAU,GAAG,OAAO,CAAC,MAAM,UAAU,CAAC,oBAAoB,CAAC,EAAE,OAAO,CAAC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B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../src/features/functions/interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAA;AACzE,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAE1C,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B;AAED,MAAM,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAA;AAEtE,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;AAEhD,MAAM,MAAM,uBAAuB,GAAG;IACpC,GAAG,EAAE,eAAe,CAAA;IACpB,aAAa,EAAE,SAAS,CAAA;IACxB,SAAS,EAAE,KAAK,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,aAAa,EAAE,UAAU,CAAC,oBAAoB,CAAC,CAAC,MAAM,UAAU,CAAC,oBAAoB,CAAC,CAAC,CAAA;IACvF,KAAK,EAAE,UAAU,CAAC,oBAAoB,CAAC,CAAA;IACvC,MAAM,EAAE,QAAQ,CAAA;IAChB,QAAQ,EAAE,QAAQ,CAAA;IAClB,SAAS,EAAE,QAAQ,EAAE,CAAA;
|
|
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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 +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 }: ExecuteQueryParams) => Promise<{
|
|
13
|
+
export declare const executeQuery: ({ currentMethod, query, update, document, documents, pipeline }: ExecuteQueryParams) => Promise<{
|
|
14
14
|
find: () => Promise<any[]>;
|
|
15
15
|
findOne: () => Promise<unknown>;
|
|
16
16
|
deleteOne: () => Promise<unknown>;
|
|
@@ -19,5 +19,6 @@ export declare const executeQuery: ({ currentMethod, query, update, document, do
|
|
|
19
19
|
aggregate: () => Promise<import("bson").Document[]>;
|
|
20
20
|
insertMany: () => Promise<import("mongodb/mongodb").InsertManyResult<import("bson").Document>>;
|
|
21
21
|
updateMany: () => Promise<import("mongodb/mongodb").UpdateResult<import("bson").Document>>;
|
|
22
|
+
deleteMany: () => Promise<import("mongodb/mongodb").DeleteResult>;
|
|
22
23
|
}>;
|
|
23
24
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -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,iEAOhC,kBAAkB;;;;;;;;;;EAqCpB,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 }) {
|
|
61
|
+
const executeQuery = (_a) => __awaiter(void 0, [_a], void 0, function* ({ currentMethod, query, update, document, documents, pipeline }) {
|
|
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,10 +68,12 @@ 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(
|
|
71
|
+
return (yield currentMethod(bson_1.EJSON.deserialize(pipeline) // TODO -> ADD OPTIONS
|
|
72
|
+
)).toArray();
|
|
72
73
|
}),
|
|
73
74
|
insertMany: () => currentMethod(bson_1.EJSON.deserialize(documents)),
|
|
74
|
-
updateMany: () => currentMethod(bson_1.EJSON.deserialize(query), bson_1.EJSON.deserialize(update))
|
|
75
|
+
updateMany: () => currentMethod(bson_1.EJSON.deserialize(query), bson_1.EJSON.deserialize(update)),
|
|
76
|
+
deleteMany: () => currentMethod(bson_1.EJSON.deserialize(query))
|
|
75
77
|
};
|
|
76
78
|
});
|
|
77
79
|
exports.executeQuery = executeQuery;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/features/triggers/utils.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,aAAa,EAAW,QAAQ,EAAE,MAAM,aAAa,CAAA;AAE9D;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,GAAU,gBAAuB,KAAG,OAAO,CAAC,QAAQ,CAkB5E,CAAA;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/features/triggers/utils.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,aAAa,EAAW,QAAQ,EAAE,MAAM,aAAa,CAAA;AAE9D;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,GAAU,gBAAuB,KAAG,OAAO,CAAC,QAAQ,CAkB5E,CAAA;AAwJD,eAAO,MAAM,gBAAgB;0EApI1B,aAAa;yEAyFb,aAAa;+EArEb,aAAa;CAoHf,CAAA"}
|
|
@@ -75,12 +75,12 @@ const handleAuthenticationTrigger = (_a) => __awaiter(void 0, [_a], void 0, func
|
|
|
75
75
|
const pipeline = [
|
|
76
76
|
{
|
|
77
77
|
$match: {
|
|
78
|
-
operationType: { $in: ['
|
|
78
|
+
operationType: { $in: ['insert'] }
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
];
|
|
82
82
|
const changeStream = app.mongo.client
|
|
83
|
-
.db(database)
|
|
83
|
+
.db(database || constants_1.DB_NAME)
|
|
84
84
|
.collection(constants_1.AUTH_CONFIG.authCollection)
|
|
85
85
|
.watch(pipeline, {
|
|
86
86
|
fullDocument: 'whenAvailable'
|
|
@@ -93,13 +93,16 @@ const handleAuthenticationTrigger = (_a) => __awaiter(void 0, [_a], void 0, func
|
|
|
93
93
|
const currentUser = Object.assign({}, document);
|
|
94
94
|
delete currentUser.password;
|
|
95
95
|
yield (0, context_1.GenerateContext)({
|
|
96
|
-
args: [{
|
|
96
|
+
args: [{
|
|
97
|
+
user: Object.assign(Object.assign({}, currentUser), { id: currentUser._id.toString() })
|
|
98
|
+
}],
|
|
97
99
|
app,
|
|
98
100
|
rules: {},
|
|
99
101
|
user: {},
|
|
100
102
|
currentFunction: triggerHandler,
|
|
101
103
|
functionsList,
|
|
102
|
-
services
|
|
104
|
+
services,
|
|
105
|
+
runAsSystem: true
|
|
103
106
|
});
|
|
104
107
|
}
|
|
105
108
|
});
|
|
@@ -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 }: GenerateContextParams): Promise<any>;
|
|
13
|
+
export declare function GenerateContext({ args, app, rules, user, currentFunction, functionsList, services, runAsSystem }: 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":"AAIA,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,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/context/index.ts"],"names":[],"mappings":"AAIA,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,EACZ,EAAE,qBAAqB,gBA8BvB"}
|
|
@@ -29,21 +29,23 @@ const helpers_1 = require("./helpers");
|
|
|
29
29
|
* @param services -> the list of all services
|
|
30
30
|
*/
|
|
31
31
|
function GenerateContext(_a) {
|
|
32
|
-
return __awaiter(this, arguments, void 0, function* ({ args, app, rules, user, currentFunction, functionsList, services }) {
|
|
32
|
+
return __awaiter(this, arguments, void 0, function* ({ args, app, rules, user, currentFunction, functionsList, services, runAsSystem }) {
|
|
33
33
|
var _b, _c;
|
|
34
|
+
const contextFunction = Object.assign({ run_as_system: runAsSystem }, currentFunction);
|
|
34
35
|
const contextData = (0, helpers_1.generateContextData)({
|
|
35
36
|
user,
|
|
36
37
|
services,
|
|
37
38
|
app,
|
|
38
39
|
rules,
|
|
39
|
-
currentFunction,
|
|
40
|
+
currentFunction: contextFunction,
|
|
40
41
|
functionsList,
|
|
41
|
-
GenerateContext
|
|
42
|
+
GenerateContext,
|
|
43
|
+
runAsSystem
|
|
42
44
|
});
|
|
43
45
|
try {
|
|
44
46
|
const entryFile = (_c = (_b = require.main) === null || _b === void 0 ? void 0 : _b.filename) !== null && _c !== void 0 ? _c : process.cwd();
|
|
45
47
|
const customRequire = (0, node_module_1.createRequire)(entryFile);
|
|
46
|
-
vm_1.default.runInContext(
|
|
48
|
+
vm_1.default.runInContext(contextFunction.code, vm_1.default.createContext(Object.assign(Object.assign({}, contextData), { require: customRequire, exports,
|
|
47
49
|
module, __filename: __filename, __dirname: __dirname })));
|
|
48
50
|
}
|
|
49
51
|
catch (e) {
|
|
@@ -11,6 +11,7 @@ export interface GenerateContextParams {
|
|
|
11
11
|
user: User;
|
|
12
12
|
services: Services;
|
|
13
13
|
args: Arguments;
|
|
14
|
+
runAsSystem?: boolean;
|
|
14
15
|
}
|
|
15
16
|
export interface GenerateContextDataParams extends Omit<GenerateContextParams, 'args'> {
|
|
16
17
|
GenerateContext: (params: GenerateContextParams) => Promise<void>;
|
|
@@ -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;AACzC,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACjD,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|
-
{"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../src/utils/rules.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../src/utils/rules.ts"],"names":[],"mappings":"AAOA,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,OAqB9B"}
|
package/dist/utils/rules.js
CHANGED
|
@@ -5,6 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.expandQuery = expandQuery;
|
|
7
7
|
const get_1 = __importDefault(require("lodash/get"));
|
|
8
|
+
const removeExtraColons = (val) => {
|
|
9
|
+
return val === null || val === void 0 ? void 0 : val.toString().replace(/:+/g, ":");
|
|
10
|
+
};
|
|
8
11
|
// Funzione che espande dinamicamente i placeholder con supporto per percorsi annidati
|
|
9
12
|
function expandQuery(template, objs) {
|
|
10
13
|
let expandedQuery = JSON.stringify(template); // Converti l'oggetto in una stringa per sostituire i placeholder
|
|
@@ -15,7 +18,8 @@ function expandQuery(template, objs) {
|
|
|
15
18
|
const value = (0, get_1.default)(objs, `%%${path}`); // Recupera il valore annidato da values
|
|
16
19
|
const finalValue = typeof value === 'string' ? `"${value}"` : value && JSON.stringify(value);
|
|
17
20
|
// TODO tolto i primi : creava questo tipo di oggetto {"userId"::"%%user.id"}
|
|
18
|
-
|
|
21
|
+
const val = `:${value !== undefined ? finalValue : match}`; // Sostituisci se esiste, altrimenti lascia il placeholder
|
|
22
|
+
return removeExtraColons(val);
|
|
19
23
|
};
|
|
20
24
|
expandedQuery = expandedQuery.replace(regex, callback);
|
|
21
25
|
});
|
package/package.json
CHANGED
|
@@ -65,6 +65,7 @@ export async function localUserPassController(app: FastifyInstance) {
|
|
|
65
65
|
const result = await db.collection(authCollection!).insertOne({
|
|
66
66
|
email: email,
|
|
67
67
|
password: hashedPassword,
|
|
68
|
+
status: 'pending',
|
|
68
69
|
custom_data: {
|
|
69
70
|
// TODO da aggiungere in fase di registrazione utente, funzionalitร utile che realm non permetteva
|
|
70
71
|
}
|
|
@@ -88,32 +89,6 @@ export async function localUserPassController(app: FastifyInstance) {
|
|
|
88
89
|
}
|
|
89
90
|
)
|
|
90
91
|
|
|
91
|
-
if (result && on_user_creation_function_name && functionsList[on_user_creation_function_name]) {
|
|
92
|
-
const user = await db.collection(authCollection!).findOne({ _id: result?.insertedId })
|
|
93
|
-
delete user?.password
|
|
94
|
-
try {
|
|
95
|
-
const response = await GenerateContext({
|
|
96
|
-
args: [{
|
|
97
|
-
operationType: 'CREATE',
|
|
98
|
-
providers: 'local-userpass',
|
|
99
|
-
user,
|
|
100
|
-
time: new Date().getTime()
|
|
101
|
-
}],
|
|
102
|
-
app,
|
|
103
|
-
rules: {},
|
|
104
|
-
user: undefined,
|
|
105
|
-
currentFunction: functionsList[on_user_creation_function_name],
|
|
106
|
-
functionsList,
|
|
107
|
-
services
|
|
108
|
-
})
|
|
109
|
-
console.log("๐ ~ response:", response)
|
|
110
|
-
} catch (error) {
|
|
111
|
-
console.log("๐ ~ error:", error)
|
|
112
|
-
}
|
|
113
|
-
} else {
|
|
114
|
-
console.error('Error function on_user_creation_function_name: ', on_user_creation_function_name)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
92
|
res.status(201)
|
|
118
93
|
|
|
119
94
|
return {
|
|
@@ -158,6 +133,42 @@ export async function localUserPassController(app: FastifyInstance) {
|
|
|
158
133
|
|
|
159
134
|
const userWithCustomData = { ...storedUser, user_data: user }
|
|
160
135
|
|
|
136
|
+
if (storedUser && storedUser.status === 'pending') {
|
|
137
|
+
try {
|
|
138
|
+
await db?.collection(authCollection!).updateOne({ _id: storedUser._id },
|
|
139
|
+
{
|
|
140
|
+
$set: {
|
|
141
|
+
status: 'confirmed'
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
)
|
|
145
|
+
} catch (error) {
|
|
146
|
+
console.log(">>> ๐ ~ localUserPassController ~ error:", error)
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (storedUser && storedUser.status === 'pending' && on_user_creation_function_name && functionsList[on_user_creation_function_name]) {
|
|
151
|
+
delete storedUser?.password
|
|
152
|
+
try {
|
|
153
|
+
await GenerateContext({
|
|
154
|
+
args: [{
|
|
155
|
+
operationType: 'CREATE',
|
|
156
|
+
providers: 'local-userpass',
|
|
157
|
+
user,
|
|
158
|
+
time: new Date().getTime()
|
|
159
|
+
}],
|
|
160
|
+
app,
|
|
161
|
+
rules: {},
|
|
162
|
+
user: undefined,
|
|
163
|
+
currentFunction: functionsList[on_user_creation_function_name],
|
|
164
|
+
functionsList,
|
|
165
|
+
services
|
|
166
|
+
})
|
|
167
|
+
} catch (error) {
|
|
168
|
+
console.log("๐ ~ error:", error)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
161
172
|
return {
|
|
162
173
|
access_token: this.createAccessToken(userWithCustomData),
|
|
163
174
|
refresh_token: this.createRefreshToken(userWithCustomData),
|
|
@@ -28,7 +28,7 @@ export const functionsController: FunctionController = async (
|
|
|
28
28
|
if (!serviceFn) {
|
|
29
29
|
throw new Error(`Service "${req.body.service}" does not exist`)
|
|
30
30
|
}
|
|
31
|
-
const [{ database, collection, query, update, document, documents }] = args
|
|
31
|
+
const [{ database, collection, query, update, document, documents, pipeline = [] }] = args
|
|
32
32
|
|
|
33
33
|
const currentMethod = serviceFn(app, { rules, user })
|
|
34
34
|
.db(database)
|
|
@@ -39,7 +39,8 @@ export const functionsController: FunctionController = async (
|
|
|
39
39
|
query,
|
|
40
40
|
update,
|
|
41
41
|
document,
|
|
42
|
-
documents
|
|
42
|
+
documents,
|
|
43
|
+
pipeline
|
|
43
44
|
})
|
|
44
45
|
return operatorsByType[method as keyof typeof operatorsByType]()
|
|
45
46
|
}
|
|
@@ -6,14 +6,14 @@ type MethodName = Exclude<keyof ReturnType<GetOperatorsFunction>, 'match'>
|
|
|
6
6
|
|
|
7
7
|
export type FunctionCallDto =
|
|
8
8
|
| {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
name: MethodName
|
|
10
|
+
arguments: ArgumentsData
|
|
11
|
+
}
|
|
12
12
|
| {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
arguments: ArgumentsData
|
|
14
|
+
name: MethodName
|
|
15
|
+
service: 'mongodb-atlas'
|
|
16
|
+
}
|
|
17
17
|
|
|
18
18
|
export type FunctionCallBase64Dto = {
|
|
19
19
|
baas_request?: string
|
|
@@ -27,6 +27,7 @@ type ArgumentsData = Arguments<{
|
|
|
27
27
|
update: Document
|
|
28
28
|
document: Document
|
|
29
29
|
documents: Document[]
|
|
30
|
+
pipeline?: Document[]
|
|
30
31
|
}>
|
|
31
32
|
|
|
32
33
|
export type Base64Function = {
|
|
@@ -45,7 +45,8 @@ export const executeQuery = async ({
|
|
|
45
45
|
query,
|
|
46
46
|
update,
|
|
47
47
|
document,
|
|
48
|
-
documents
|
|
48
|
+
documents,
|
|
49
|
+
pipeline
|
|
49
50
|
}: ExecuteQueryParams) => {
|
|
50
51
|
return {
|
|
51
52
|
find: async () =>
|
|
@@ -67,7 +68,7 @@ export const executeQuery = async ({
|
|
|
67
68
|
updateOne: () => currentMethod(EJSON.deserialize(query), EJSON.deserialize(update)),
|
|
68
69
|
aggregate: async () =>
|
|
69
70
|
(await (currentMethod as ReturnType<GetOperatorsFunction>['aggregate'])(
|
|
70
|
-
EJSON.deserialize(
|
|
71
|
+
EJSON.deserialize(pipeline) // TODO -> ADD OPTIONS
|
|
71
72
|
)).toArray(),
|
|
72
73
|
insertMany: () =>
|
|
73
74
|
(currentMethod as ReturnType<GetOperatorsFunction>['insertMany'])(
|
|
@@ -77,6 +78,11 @@ export const executeQuery = async ({
|
|
|
77
78
|
(currentMethod as ReturnType<GetOperatorsFunction>['updateMany'])(
|
|
78
79
|
EJSON.deserialize(query),
|
|
79
80
|
EJSON.deserialize(update)
|
|
81
|
+
),
|
|
82
|
+
deleteMany: () =>
|
|
83
|
+
(currentMethod as ReturnType<GetOperatorsFunction>['deleteMany'])(
|
|
84
|
+
EJSON.deserialize(query)
|
|
80
85
|
)
|
|
81
86
|
}
|
|
82
87
|
}
|
|
88
|
+
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from 'fs'
|
|
2
2
|
import path from 'node:path'
|
|
3
3
|
import cron from 'node-cron'
|
|
4
|
-
import { AUTH_CONFIG } from '../../constants'
|
|
4
|
+
import { AUTH_CONFIG, DB_NAME } from '../../constants'
|
|
5
5
|
import { readJsonContent } from '../../utils'
|
|
6
6
|
import { GenerateContext } from '../../utils/context'
|
|
7
7
|
import { HandlerParams, Trigger, Triggers } from './interface'
|
|
@@ -77,12 +77,12 @@ const handleAuthenticationTrigger = async ({
|
|
|
77
77
|
const pipeline = [
|
|
78
78
|
{
|
|
79
79
|
$match: {
|
|
80
|
-
operationType: { $in: ['
|
|
80
|
+
operationType: { $in: ['insert'] }
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
]
|
|
84
84
|
const changeStream = app.mongo.client
|
|
85
|
-
.db(database)
|
|
85
|
+
.db(database || DB_NAME)
|
|
86
86
|
.collection(AUTH_CONFIG.authCollection)
|
|
87
87
|
.watch(pipeline, {
|
|
88
88
|
fullDocument: 'whenAvailable'
|
|
@@ -99,13 +99,19 @@ const handleAuthenticationTrigger = async ({
|
|
|
99
99
|
const currentUser = { ...document }
|
|
100
100
|
delete currentUser.password
|
|
101
101
|
await GenerateContext({
|
|
102
|
-
args: [{
|
|
102
|
+
args: [{
|
|
103
|
+
user: {
|
|
104
|
+
...currentUser,
|
|
105
|
+
id: currentUser._id.toString()
|
|
106
|
+
}
|
|
107
|
+
}],
|
|
103
108
|
app,
|
|
104
109
|
rules: {},
|
|
105
110
|
user: {},
|
|
106
111
|
currentFunction: triggerHandler,
|
|
107
112
|
functionsList,
|
|
108
|
-
services
|
|
113
|
+
services,
|
|
114
|
+
runAsSystem: true
|
|
109
115
|
})
|
|
110
116
|
}
|
|
111
117
|
})
|
|
@@ -22,23 +22,26 @@ export async function GenerateContext({
|
|
|
22
22
|
user,
|
|
23
23
|
currentFunction,
|
|
24
24
|
functionsList,
|
|
25
|
-
services
|
|
25
|
+
services,
|
|
26
|
+
runAsSystem
|
|
26
27
|
}: GenerateContextParams) {
|
|
28
|
+
const contextFunction = { run_as_system: runAsSystem, ...currentFunction }
|
|
27
29
|
const contextData = generateContextData({
|
|
28
30
|
user,
|
|
29
31
|
services,
|
|
30
32
|
app,
|
|
31
33
|
rules,
|
|
32
|
-
currentFunction,
|
|
34
|
+
currentFunction: contextFunction,
|
|
33
35
|
functionsList,
|
|
34
|
-
GenerateContext
|
|
36
|
+
GenerateContext,
|
|
37
|
+
runAsSystem
|
|
35
38
|
})
|
|
36
39
|
|
|
37
40
|
try {
|
|
38
41
|
const entryFile = require.main?.filename ?? process.cwd();
|
|
39
42
|
const customRequire = createRequire(entryFile);
|
|
40
43
|
|
|
41
|
-
vm.runInContext(
|
|
44
|
+
vm.runInContext(contextFunction.code, vm.createContext({
|
|
42
45
|
...contextData, require: customRequire,
|
|
43
46
|
exports,
|
|
44
47
|
module,
|
package/src/utils/rules.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import get from 'lodash/get'
|
|
2
2
|
|
|
3
|
+
const removeExtraColons = (val: unknown) => {
|
|
4
|
+
return val?.toString().replace(/:+/g, ":")
|
|
5
|
+
}
|
|
6
|
+
|
|
3
7
|
// Funzione che espande dinamicamente i placeholder con supporto per percorsi annidati
|
|
4
8
|
export function expandQuery(
|
|
5
9
|
template: Record<string, unknown>,
|
|
@@ -14,7 +18,8 @@ export function expandQuery(
|
|
|
14
18
|
const value = get(objs, `%%${path}`) // Recupera il valore annidato da values
|
|
15
19
|
const finalValue = typeof value === 'string' ? `"${value}"` : value && JSON.stringify(value)
|
|
16
20
|
// TODO tolto i primi : creava questo tipo di oggetto {"userId"::"%%user.id"}
|
|
17
|
-
|
|
21
|
+
const val = `:${value !== undefined ? finalValue : match}`; // Sostituisci se esiste, altrimenti lascia il placeholder
|
|
22
|
+
return removeExtraColons(val)
|
|
18
23
|
}
|
|
19
24
|
|
|
20
25
|
expandedQuery = expandedQuery.replace(
|