@flowerforce/flowerbase 1.0.1-beta.3 → 1.0.1-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.
@@ -4,6 +4,8 @@ export declare const DEFAULT_CONFIG: {
4
4
  JWT_SECRET: string;
5
5
  API_VERSION: string;
6
6
  HTTPS_SCHEMA: string;
7
+ HOST: string;
8
+ ENABLE_LOGGER: string | undefined;
7
9
  };
8
10
  export declare const API_VERSION: string;
9
11
  export declare const HTTPS_SCHEMA: string;
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,cAAc;;;;;;CAM1B,CAAA;AACD,eAAO,MAAM,WAAW,QAA8C,CAAA;AACtE,eAAO,MAAM,YAAY,QAA8B,CAAA;AACvD,eAAO,MAAM,OAAO,QAAgB,CAAA;AACpC,eAAO,MAAM,WAAW;;;;;;CAMvB,CAAA"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,cAAc;;;;;;;;CAQ1B,CAAA;AACD,eAAO,MAAM,WAAW,QAA8C,CAAA;AACtE,eAAO,MAAM,YAAY,QAA8B,CAAA;AACvD,eAAO,MAAM,OAAO,QAAgB,CAAA;AACpC,eAAO,MAAM,WAAW;;;;;;CAMvB,CAAA"}
package/dist/constants.js CHANGED
@@ -20,7 +20,9 @@ exports.DEFAULT_CONFIG = {
20
20
  MONGODB_URL: process.env.MONGODB_URL || '',
21
21
  JWT_SECRET: process.env.JWT_SECRET || '',
22
22
  API_VERSION: process.env.API_VERSION || "v2.0",
23
- HTTPS_SCHEMA: process.env.HTTPS_SCHEMA || 'https'
23
+ HTTPS_SCHEMA: process.env.HTTPS_SCHEMA || 'https',
24
+ HOST: process.env.HOST || '0.0.0.0',
25
+ ENABLE_LOGGER: process.env.ENABLE_LOGGER
24
26
  };
25
27
  exports.API_VERSION = `/api/client/${exports.DEFAULT_CONFIG.API_VERSION}`;
26
28
  exports.HTTPS_SCHEMA = exports.DEFAULT_CONFIG.HTTPS_SCHEMA;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/features/triggers/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,QAAQ,CAAA;AAG/C;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAAU,0CAIpC,sBAAsB,kBAexB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/features/triggers/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,QAAQ,CAAA;AAG/C;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAAU,0CAIpC,sBAAsB,kBAiBxB,CAAA"}
@@ -29,6 +29,7 @@ const utils_1 = require("./utils");
29
29
  const activateTriggers = (_a) => __awaiter(void 0, [_a], void 0, function* ({ fastify, triggersList, functionsList }) {
30
30
  var _b, triggersList_1, triggersList_1_1;
31
31
  var _c, e_1, _d, _e;
32
+ console.log("START ACTIVATION TRIGGERS");
32
33
  try {
33
34
  try {
34
35
  for (_b = true, triggersList_1 = __asyncValues(triggersList); triggersList_1_1 = yield triggersList_1.next(), _c = triggersList_1_1.done, !_c; _b = true) {
@@ -49,6 +50,7 @@ const activateTriggers = (_a) => __awaiter(void 0, [_a], void 0, function* ({ fa
49
50
  }
50
51
  finally { if (e_1) throw e_1.error; }
51
52
  }
53
+ console.log("TRIGGERS ACTIVATION COMPLETED");
52
54
  }
53
55
  catch (e) {
54
56
  console.error('Error while activating triggers', e.message);
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAA;AActB,cAAc,SAAS,CAAC;AAExB,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,CAAA;AAED;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAAC,EAC/B,SAAS,EACT,IAAI,EACJ,SAAqC,EACrC,IAA0B,EAC1B,UAAuC,EACxC,EAAE,gBAAgB,iBAoClB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAA;AActB,cAAc,SAAS,CAAC;AAExB,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,CAAA;AAED;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAAC,EAC/B,SAAS,EACT,IAAI,EACJ,SAAqC,EACrC,IAA0B,EAC1B,UAAuC,EACxC,EAAE,gBAAgB,iBAgDlB"}
package/dist/index.js CHANGED
@@ -53,12 +53,18 @@ __exportStar(require("./model"), exports);
53
53
  function initialize(_a) {
54
54
  return __awaiter(this, arguments, void 0, function* ({ projectId, host, jwtSecret = constants_1.DEFAULT_CONFIG.JWT_SECRET, port = constants_1.DEFAULT_CONFIG.PORT, mongodbUrl = constants_1.DEFAULT_CONFIG.MONGODB_URL }) {
55
55
  const fastify = (0, fastify_1.default)({
56
- logger: false
56
+ logger: !!constants_1.DEFAULT_CONFIG.ENABLE_LOGGER
57
57
  });
58
+ console.log("CURRENT PORT", port);
59
+ console.log("CURRENT HOST", host);
58
60
  const functionsList = yield (0, utils_2.loadFunctions)();
61
+ console.log("Functions LOADED");
59
62
  const triggersList = yield (0, utils_4.loadTriggers)();
63
+ console.log("Triggers LOADED");
60
64
  const endpointsList = yield (0, utils_1.loadEndpoints)();
65
+ console.log("Endpoints LOADED");
61
66
  const rulesList = yield (0, utils_3.loadRules)();
67
+ console.log("Rules LOADED");
62
68
  const stateConfig = {
63
69
  functions: functionsList,
64
70
  triggers: triggersList,
@@ -74,10 +80,17 @@ function initialize(_a) {
74
80
  jwtSecret,
75
81
  functionsList
76
82
  });
83
+ console.log("Plugins registration COMPLETED");
77
84
  yield (0, exposeRoutes_1.exposeRoutes)(fastify);
85
+ console.log("APP Routes registration COMPLETED");
78
86
  yield (0, functions_1.registerFunctions)({ app: fastify, functionsList, rulesList });
87
+ console.log("Functions registration COMPLETED");
79
88
  yield (0, endpoints_1.generateEndpoints)({ app: fastify, functionsList, endpointsList });
80
- fastify.ready(() => (0, triggers_1.activateTriggers)({ fastify, triggersList, functionsList }));
89
+ console.log("HTTP Endpoints registration COMPLETED");
90
+ fastify.ready(() => {
91
+ console.log("FASTIFY IS READY");
92
+ (triggersList === null || triggersList === void 0 ? void 0 : triggersList.length) > 0 && (0, triggers_1.activateTriggers)({ fastify, triggersList, functionsList });
93
+ });
81
94
  yield fastify.listen({ port, host });
82
95
  fastify.log.info(`[${projectId}] Server listening on port ${port}`);
83
96
  });
@@ -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;AAKzC,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;AAOD;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAAU,oDAKnC,qBAAqB,kBAcvB,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;AAKzC,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,kBAsBvB,CAAA"}
@@ -33,8 +33,15 @@ const registerPlugins = (_a) => __awaiter(void 0, [_a], void 0, function* ({ reg
33
33
  jwtSecret,
34
34
  functionsList
35
35
  });
36
- registersConfig.forEach(({ plugin, options }) => {
37
- register(plugin, options);
36
+ registersConfig.forEach(({ plugin, options, pluginName }) => {
37
+ try {
38
+ register(plugin, options);
39
+ console.log("registration COMPLETED --->", pluginName);
40
+ }
41
+ catch (e) {
42
+ console.log("Registration FAILED --->", pluginName);
43
+ console.log("Error --->", e);
44
+ }
38
45
  });
39
46
  }
40
47
  catch (e) {
@@ -51,6 +58,7 @@ exports.registerPlugins = registerPlugins;
51
58
  const getRegisterConfig = (_a) => __awaiter(void 0, [_a], void 0, function* ({ mongodbUrl, jwtSecret }) {
52
59
  return [
53
60
  {
61
+ pluginName: "cors",
54
62
  plugin: cors_1.default,
55
63
  options: {
56
64
  origin: '*',
@@ -58,6 +66,7 @@ const getRegisterConfig = (_a) => __awaiter(void 0, [_a], void 0, function* ({ m
58
66
  }
59
67
  },
60
68
  {
69
+ pluginName: "fastifyMongodb",
61
70
  plugin: mongodb_1.default,
62
71
  options: {
63
72
  forceClose: true,
@@ -65,16 +74,19 @@ const getRegisterConfig = (_a) => __awaiter(void 0, [_a], void 0, function* ({ m
65
74
  }
66
75
  },
67
76
  {
77
+ pluginName: "jwtAuthPlugin",
68
78
  plugin: jwt_1.default,
69
79
  options: {
70
80
  secret: jwtSecret
71
81
  }
72
82
  },
73
83
  {
84
+ pluginName: "authController",
74
85
  plugin: controller_1.authController,
75
86
  options: { prefix: `${constants_1.API_VERSION}/auth` }
76
87
  },
77
88
  {
89
+ pluginName: "localUserPassController",
78
90
  plugin: controller_2.localUserPassController,
79
91
  options: {
80
92
  prefix: `${constants_1.API_VERSION}/app/:appId/auth/providers/local-userpass`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowerforce/flowerbase",
3
- "version": "1.0.1-beta.3",
3
+ "version": "1.0.1-beta.5",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -10,7 +10,7 @@
10
10
  "scripts": {
11
11
  "test": "npx jest",
12
12
  "build": "rm -rf dist/ && tsc",
13
- "start": "node src/index.ts"
13
+ "start": "node dist/src/index.ts"
14
14
  },
15
15
  "keywords": [],
16
16
  "author": "",
@@ -19,6 +19,7 @@
19
19
  "@fastify/cors": "^10.0.1",
20
20
  "@fastify/jwt": "^9.0.1",
21
21
  "@fastify/mongodb": "^9.0.1",
22
+ "@sendgrid/mail": "^8.1.4",
22
23
  "aws-sdk": "^2.1692.0",
23
24
  "bson": "^6.8.0",
24
25
  "dotenv": "^16.4.7",
@@ -27,7 +28,6 @@
27
28
  "fastify-plugin": "^5.0.1",
28
29
  "lodash": "^4.17.21",
29
30
  "node-cron": "^3.0.3",
30
- "@sendgrid/mail": "^8.1.4",
31
31
  "nodemon": "^3.1.7",
32
32
  "undici": "^7.1.0"
33
33
  },
@@ -58,6 +58,5 @@
58
58
  "ts-node": "^10.9.2",
59
59
  "typescript": "^5.6.2",
60
60
  "typescript-eslint": "^8.8.1"
61
- },
62
- "peerDependencies": {}
61
+ }
63
62
  }
package/src/constants.ts CHANGED
@@ -8,7 +8,9 @@ export const DEFAULT_CONFIG = {
8
8
  MONGODB_URL: process.env.MONGODB_URL || '',
9
9
  JWT_SECRET: process.env.JWT_SECRET || '',
10
10
  API_VERSION: process.env.API_VERSION || "v2.0",
11
- HTTPS_SCHEMA: process.env.HTTPS_SCHEMA || 'https'
11
+ HTTPS_SCHEMA: process.env.HTTPS_SCHEMA || 'https',
12
+ HOST: process.env.HOST || '0.0.0.0',
13
+ ENABLE_LOGGER: process.env.ENABLE_LOGGER
12
14
  }
13
15
  export const API_VERSION = `/api/client/${DEFAULT_CONFIG.API_VERSION}`
14
16
  export const HTTPS_SCHEMA = DEFAULT_CONFIG.HTTPS_SCHEMA
@@ -15,6 +15,7 @@ export const activateTriggers = async ({
15
15
  triggersList,
16
16
  functionsList
17
17
  }: ActivateTriggersParams) => {
18
+ console.log("START ACTIVATION TRIGGERS")
18
19
  try {
19
20
  for await (const trigger of triggersList) {
20
21
  const { content } = trigger
@@ -26,6 +27,7 @@ export const activateTriggers = async ({
26
27
  await TRIGGER_HANDLERS[type]({ config, triggerHandler, app: fastify, services, functionsList })
27
28
 
28
29
  }
30
+ console.log("TRIGGERS ACTIVATION COMPLETED")
29
31
  } catch (e) {
30
32
  console.error('Error while activating triggers', (e as Error).message)
31
33
  }
package/src/index.ts CHANGED
@@ -38,14 +38,20 @@ export async function initialize({
38
38
  mongodbUrl = DEFAULT_CONFIG.MONGODB_URL
39
39
  }: InitializeConfig) {
40
40
  const fastify = Fastify({
41
- logger: false
41
+ logger: !!DEFAULT_CONFIG.ENABLE_LOGGER
42
42
  })
43
43
 
44
+ console.log("CURRENT PORT", port)
45
+ console.log("CURRENT HOST", host)
44
46
 
45
47
  const functionsList = await loadFunctions()
48
+ console.log("Functions LOADED")
46
49
  const triggersList = await loadTriggers()
50
+ console.log("Triggers LOADED")
47
51
  const endpointsList = await loadEndpoints()
52
+ console.log("Endpoints LOADED")
48
53
  const rulesList = await loadRules()
54
+ console.log("Rules LOADED")
49
55
  const stateConfig = {
50
56
  functions: functionsList,
51
57
  triggers: triggersList,
@@ -63,12 +69,18 @@ export async function initialize({
63
69
  jwtSecret,
64
70
  functionsList
65
71
  })
72
+
73
+ console.log("Plugins registration COMPLETED")
66
74
  await exposeRoutes(fastify)
75
+ console.log("APP Routes registration COMPLETED")
67
76
  await registerFunctions({ app: fastify, functionsList, rulesList })
68
-
77
+ console.log("Functions registration COMPLETED")
69
78
  await generateEndpoints({ app: fastify, functionsList, endpointsList })
70
-
71
- fastify.ready(() => activateTriggers({ fastify, triggersList, functionsList }))
79
+ console.log("HTTP Endpoints registration COMPLETED")
80
+ fastify.ready(() => {
81
+ console.log("FASTIFY IS READY")
82
+ triggersList?.length > 0 && activateTriggers({ fastify, triggersList, functionsList })
83
+ })
72
84
  await fastify.listen({ port, host })
73
85
 
74
86
  fastify.log.info(`[${projectId}] Server listening on port ${port}`)
@@ -18,6 +18,7 @@ type RegisterPluginsParams = {
18
18
  }
19
19
 
20
20
  type RegisterConfig = {
21
+ pluginName: string
21
22
  plugin: RegisterParameters[0]
22
23
  options: RegisterParameters[1]
23
24
  }
@@ -42,8 +43,16 @@ export const registerPlugins = async ({
42
43
  functionsList
43
44
  })
44
45
 
45
- registersConfig.forEach(({ plugin, options }) => {
46
- register(plugin, options)
46
+ registersConfig.forEach(({ plugin, options, pluginName }) => {
47
+ try {
48
+ register(plugin, options)
49
+ console.log("registration COMPLETED --->", pluginName)
50
+ }
51
+ catch (e) {
52
+ console.log("Registration FAILED --->", pluginName)
53
+ console.log("Error --->", e)
54
+ }
55
+
47
56
  })
48
57
  } catch (e) {
49
58
  console.error('Error while registering plugins', (e as Error).message)
@@ -64,6 +73,7 @@ const getRegisterConfig = async ({
64
73
  > => {
65
74
  return [
66
75
  {
76
+ pluginName: "cors",
67
77
  plugin: cors,
68
78
  options: {
69
79
  origin: '*',
@@ -71,6 +81,7 @@ const getRegisterConfig = async ({
71
81
  }
72
82
  },
73
83
  {
84
+ pluginName: "fastifyMongodb",
74
85
  plugin: fastifyMongodb,
75
86
  options: {
76
87
  forceClose: true,
@@ -78,16 +89,19 @@ const getRegisterConfig = async ({
78
89
  }
79
90
  },
80
91
  {
92
+ pluginName: "jwtAuthPlugin",
81
93
  plugin: jwtAuthPlugin,
82
94
  options: {
83
95
  secret: jwtSecret
84
96
  }
85
97
  },
86
98
  {
99
+ pluginName: "authController",
87
100
  plugin: authController,
88
101
  options: { prefix: `${API_VERSION}/auth` }
89
102
  },
90
103
  {
104
+ pluginName: "localUserPassController",
91
105
  plugin: localUserPassController,
92
106
  options: {
93
107
  prefix: `${API_VERSION}/app/:appId/auth/providers/local-userpass`