@flowerforce/flowerbase 1.0.3-beta.4 → 1.0.3-beta.6

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.
@@ -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,wBAqDE"}
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,wBAwDE"}
@@ -43,10 +43,11 @@ exports.default = (0, fastify_plugin_1.default)(function (fastify, opts) {
43
43
  fastify.decorate('createAccessToken', function (user) {
44
44
  const id = user._id.toString();
45
45
  const userDataId = user.user_data._id.toString();
46
- const user_data = Object.assign({ _id: userDataId, id: userDataId }, user.user_data);
46
+ const user_data = Object.assign({ _id: userDataId, id: userDataId, email: user.email }, user.user_data);
47
47
  return this.jwt.sign({
48
48
  typ: 'access',
49
49
  id,
50
+ data: user_data,
50
51
  user_data: user_data,
51
52
  custom_data: user_data
52
53
  }, {
@@ -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,a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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;;;;;CA2DhB,CAAA"}
@@ -88,10 +88,19 @@ const getMailConfig = (resetPasswordConfig, token, tokenId) => {
88
88
  const ENV_PREFIX = 'ENV';
89
89
  const { from, subject, mailToken } = mailConfig;
90
90
  const [fromPrefix, fromPath] = from.split('.');
91
+ if (!fromPath) {
92
+ throw new Error(`Invalid fromPath: ${fromPath}`);
93
+ }
91
94
  const currentSender = (_a = (fromPrefix === ENV_PREFIX ? process.env[fromPath] : from)) !== null && _a !== void 0 ? _a : '';
92
95
  const [subjectPrefix, subjectPath] = subject.split('.');
96
+ if (!subjectPath) {
97
+ throw new Error(`Invalid subjectPath: ${subjectPath}`);
98
+ }
93
99
  const currentSubject = (_b = (subjectPrefix === ENV_PREFIX ? process.env[subjectPath] : subject)) !== null && _b !== void 0 ? _b : '';
94
100
  const [mailTokenPrefix, mailTokenPath] = mailToken.split('.');
101
+ if (!mailTokenPath) {
102
+ throw new Error(`Invalid mailTokenPath: ${mailTokenPath}`);
103
+ }
95
104
  const currentMailToken = (_c = (mailTokenPrefix === 'ENV' ? process.env[mailTokenPath] : mailToken)) !== null && _c !== void 0 ? _c : '';
96
105
  const link = `${resetPasswordUrl}/${token}/${tokenId}`;
97
106
  const body = `<body style="font-family: Arial, sans-serif; background-color: #f4f4f4; text-align: center; padding: 20px;">
@@ -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,kBAwFjC,CAAA"}
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 (!serviceFn) {
32
- throw new Error(`Service "${req.body.service}" does not exist`);
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
  }
@@ -24,6 +24,7 @@ export type ExecuteQueryParams = {
24
24
  document: Document;
25
25
  documents: Document[];
26
26
  pipeline: Document[];
27
+ isClient?: boolean;
27
28
  };
28
29
  type FunctionsControllerOptions = {
29
30
  functionsList: Functions;
@@ -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,E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pB,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,iEAOhC,kBAAkB;;;;;;;;;;EAqCpB,CAAA"}
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;AAiqBrF,QAAA,MAAM,YAAY,EAAE,oBAmBlB,CAAA;AAEF,eAAe,YAAY,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,CAAC,oBAAoB,CAAC,CAAA;KACnE,CAAA;CACF,CAAA;AAED,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,IAAI,GAAG,MAAM,IAAI;IACxD,OAAO,EAAE,CAAC,EAAE,CAAA;IACZ,IAAI,EAAE,IAAI,CAAA;IACV,MAAM,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,GAAG,QAAQ,GAAG,IAAI,CAAA;CAC5C,CAAA;AACD,KAAK,MAAM,CAAC,CAAC,SAAS,MAAM,UAAU,CAAC,QAAQ,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAA;AAE3E,MAAM,MAAM,oBAAoB,GAAG,CACjC,UAAU,EAAE,UAAU,CAAC,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,MAAM,CAAC,CAAC,KAAK,UAAU,CAAA;IAC3D,KAAK,EAAE,CAAC,GAAG,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAA;IAC9E,SAAS,EAAE,CACT,QAAQ,EAAE,OAAO,EACjB,GAAG,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,KACvC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAA;IAC7C,UAAU,EAAE,CACV,GAAG,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,KACxC,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAA;IACrC,UAAU,EAAE,CACV,GAAG,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,KACxC,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAA;IACrC,UAAU,EAAE,CACV,GAAG,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,KACxC,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAA;CACtC,CAAA;AAGD,oBAAY,eAAe;IACzB,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,MAAM,WAAW;IACjB,MAAM,WAAW;CAElB"}
@@ -1 +1 @@
1
- {"version":3,"file":"handleUserRegistration.d.ts","sourceRoot":"","sources":["../../src/shared/handleUserRegistration.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAA;AAE9E;;;;;;GAMG;AACH,QAAA,MAAM,sBAAsB,EAAE,sBAiD7B,CAAA;AAED,eAAe,sBAAsB,CAAA"}
1
+ {"version":3,"file":"handleUserRegistration.d.ts","sourceRoot":"","sources":["../../src/shared/handleUserRegistration.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAA;AAE9E;;;;;;GAMG;AACH,QAAA,MAAM,sBAAsB,EAAE,sBAkD7B,CAAA;AAED,eAAe,sBAAsB,CAAA"}
@@ -25,7 +25,8 @@ const handleUserRegistration = (app, opt) => (_a) => __awaiter(void 0, [_a], voi
25
25
  throw new Error('only run_as_system');
26
26
  }
27
27
  const { authCollection } = constants_1.AUTH_CONFIG;
28
- const db = app === null || app === void 0 ? void 0 : app.mongo.client.db(constants_1.DB_NAME);
28
+ const mongo = app === null || app === void 0 ? void 0 : app.mongo;
29
+ const db = mongo.client.db(constants_1.DB_NAME);
29
30
  const hashedPassword = yield (0, crypto_1.hashPassword)(password);
30
31
  const existingUser = yield (db === null || db === void 0 ? void 0 : db.collection(authCollection).findOne({ email }));
31
32
  if (existingUser) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/crypto/index.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,eAAO,MAAM,YAAY,GAAU,WAAW,MAAM,oBAInD,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAAU,WAAW,MAAM,EAAE,gBAAgB,MAAM,qBAK9E,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAI,eAAW,WAExC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/crypto/index.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,eAAO,MAAM,YAAY,GAAU,WAAW,MAAM,oBAInD,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAAU,WAAW,MAAM,EAAE,gBAAgB,MAAM,qBAU9E,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAI,eAAW,WAExC,CAAA"}
@@ -35,6 +35,9 @@ exports.hashPassword = hashPassword;
35
35
  */
36
36
  const comparePassword = (plaintext, storedPassword) => __awaiter(void 0, void 0, void 0, function* () {
37
37
  const [storedHash, storedSalt] = storedPassword.split('.');
38
+ if (!storedHash || !storedSalt) {
39
+ throw new Error(`Invalid stored password: ${storedPassword}`);
40
+ }
38
41
  const storedBuffer = Buffer.from(storedHash, 'hex');
39
42
  const buffer = (yield scrypt(plaintext, storedSalt, 64));
40
43
  return node_crypto_1.default.timingSafeEqual(buffer, storedBuffer);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowerforce/flowerbase",
3
- "version": "1.0.3-beta.4",
3
+ "version": "1.0.3-beta.6",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -37,12 +37,15 @@ export default fp(async function (fastify, opts: Options) {
37
37
  const user_data = {
38
38
  _id: userDataId,
39
39
  id: userDataId,
40
+ email: user.email,
40
41
  ...user.user_data
41
42
  }
43
+
42
44
  return this.jwt.sign(
43
45
  {
44
46
  typ: 'access',
45
47
  id,
48
+ data: user_data,
46
49
  user_data: user_data,
47
50
  custom_data: user_data
48
51
  },
package/src/auth/utils.ts CHANGED
@@ -142,11 +142,26 @@ export const getMailConfig = (
142
142
  const { from, subject, mailToken } = mailConfig
143
143
 
144
144
  const [fromPrefix, fromPath] = from.split('.')
145
+
146
+ if (!fromPath) {
147
+ throw new Error(`Invalid fromPath: ${fromPath}`)
148
+ }
149
+
145
150
  const currentSender = (fromPrefix === ENV_PREFIX ? process.env[fromPath] : from) ?? ''
146
151
  const [subjectPrefix, subjectPath] = subject.split('.')
152
+
153
+ if (!subjectPath) {
154
+ throw new Error(`Invalid subjectPath: ${subjectPath}`)
155
+ }
156
+
147
157
  const currentSubject =
148
158
  (subjectPrefix === ENV_PREFIX ? process.env[subjectPath] : subject) ?? ''
149
159
  const [mailTokenPrefix, mailTokenPath] = mailToken.split('.')
160
+
161
+ if (!mailTokenPath) {
162
+ throw new Error(`Invalid mailTokenPath: ${mailTokenPath}`)
163
+ }
164
+
150
165
  const currentMailToken =
151
166
  (mailTokenPrefix === 'ENV' ? process.env[mailTokenPath] : mailToken) ?? ''
152
167
 
@@ -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 (!serviceFn) {
29
- throw new Error(`Service "${req.body.service}" does not exist`)
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
  }
@@ -27,6 +27,7 @@ export type ExecuteQueryParams = {
27
27
  document: Document
28
28
  documents: Document[]
29
29
  pipeline: Document[]
30
+ isClient?: boolean
30
31
  }
31
32
 
32
33
  type FunctionsControllerOptions = {
@@ -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: (
@@ -1,3 +1,4 @@
1
+ import { FastifyMongoObject } from "@fastify/mongodb/types"
1
2
  import { PROVIDER_TYPE } from "../auth/utils"
2
3
  import { AUTH_CONFIG, DB_NAME } from "../constants"
3
4
  import { hashPassword } from "../utils/crypto"
@@ -18,7 +19,8 @@ const handleUserRegistration: HandleUserRegistration = (app, opt) => async ({ em
18
19
  }
19
20
 
20
21
  const { authCollection } = AUTH_CONFIG
21
- const db = app?.mongo.client.db(DB_NAME)
22
+ const mongo: FastifyMongoObject = app?.mongo
23
+ const db = mongo.client.db(DB_NAME)
22
24
  const hashedPassword = await hashPassword(password)
23
25
 
24
26
  const existingUser = await db?.collection(authCollection!).findOne({ email })
@@ -22,6 +22,11 @@ export const hashPassword = async (plaintext: string) => {
22
22
  */
23
23
  export const comparePassword = async (plaintext: string, storedPassword: string) => {
24
24
  const [storedHash, storedSalt] = storedPassword.split('.')
25
+
26
+ if (!storedHash || !storedSalt) {
27
+ throw new Error(`Invalid stored password: ${storedPassword}`);
28
+ }
29
+
25
30
  const storedBuffer = Buffer.from(storedHash, 'hex')
26
31
  const buffer = (await scrypt(plaintext, storedSalt, 64)) as Buffer
27
32
  return crypto.timingSafeEqual(buffer, storedBuffer)