qcobjects 2.4.72 → 2.4.74

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/VERSION CHANGED
@@ -1 +1 @@
1
- 2.4.72
1
+ 2.4.74
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qcobjects",
3
- "version": "2.4.72",
3
+ "version": "2.4.74",
4
4
  "description": "QCObjects is an Open-source framework that empowers full-stack developers to make micro-services and micro-frontends into an N-Tier architecture.",
5
5
  "main": "src/index.cjs",
6
6
  "module": "src/index.mjs",
package/src/QCObjects.js CHANGED
@@ -67,6 +67,8 @@
67
67
  _.prototype.toString = function () {
68
68
  var _protected_symbols = [
69
69
  "__qcobjects__",
70
+ "__qcobjects_sdk__",
71
+ "__loaded__",
70
72
  "ComplexStorageCache",
71
73
  "css",
72
74
  "append",
@@ -1004,21 +1006,24 @@
1004
1006
  _methods_(self.__definition).map(function (m) {
1005
1007
  self[m.name] = m.bind(self);
1006
1008
  });
1007
-
1008
- if (typeof self.__definition === "undefined" || (!Object.hasOwnProperty.call(self.__definition, "body")) || typeof self.__definition.body === "undefined") {
1009
- try {
1010
- if (isBrowser) {
1011
- self["body"] = _DOMCreateElement(self.__definition.__classType);
1012
- } else {
1009
+
1010
+ if (!!self["body"]){
1011
+ if (typeof self.__definition === "undefined" || (!Object.hasOwnProperty.call(self.__definition, "body")) || typeof self.__definition.body === "undefined") {
1012
+ try {
1013
+ if (isBrowser) {
1014
+ self["body"] = _DOMCreateElement(self.__definition.__classType);
1015
+ } else {
1016
+ self["body"] = {};
1017
+ }
1018
+ } catch (e) {
1013
1019
  self["body"] = {};
1014
1020
  }
1015
- } catch (e) {
1016
- self["body"] = {};
1017
- }
1018
- } else if (Object.hasOwnProperty.call(self.__definition, "body")) {
1019
- self["body"] = self.__definition.body;
1021
+ } else if (Object.hasOwnProperty.call(self.__definition, "body")) {
1022
+ self["body"] = self.__definition.body;
1023
+ }
1020
1024
  }
1021
1025
 
1026
+
1022
1027
  try {
1023
1028
  if (typeof self.__new__ === "function") {
1024
1029
  self.__new__.call(self, _o_);
@@ -1434,7 +1439,6 @@
1434
1439
  "componentsBasePath": "",
1435
1440
  "delayForReady": 0,
1436
1441
  "preserveComponentBodyTag": false,
1437
- "overrideComponentTag": false,
1438
1442
  "useConfigService": false,
1439
1443
  "routingWay": "hash",
1440
1444
  "useSDK": true,
@@ -2192,7 +2196,7 @@
2192
2196
  if (typeof self.__new__ === "function") {
2193
2197
  self.__new__.call(self, self);
2194
2198
  }
2195
-
2199
+
2196
2200
  self._generateRoutingPaths(self.body)
2197
2201
  .then(function (){
2198
2202
  self._reroute_()
@@ -2471,10 +2475,6 @@
2471
2475
  } else if (effectClassName !== null && applyEffectTo === "load") {
2472
2476
  _component_.applyTransitionEffect(effectClassName);
2473
2477
  }
2474
- if (_top.CONFIG.get("overrideComponentTag")) {
2475
- _component_.body.outerHTML = this.body.innerHTML;
2476
- }
2477
-
2478
2478
  }
2479
2479
  resolve({component:_component_, effect:_component_.effect});
2480
2480
  });
@@ -3980,17 +3980,19 @@
3980
3980
  constructor ({
3981
3981
  domain= _domain_,
3982
3982
  basePath= _basePath_,
3983
- body= null,
3983
+ body = null,
3984
3984
  stream= null,
3985
3985
  request= null
3986
3986
  }){
3987
3987
  super(...arguments);
3988
-
3989
- var o = this;
3990
-
3991
- logger.debug("Executing BackendMicroservice ");
3988
+ logger.debug("Initializing BackendMicroservice...");
3992
3989
  let microservice = this;
3993
- microservice.body = null;
3990
+ if (typeof this.body === "undefined") {
3991
+ this.body = null;
3992
+ }
3993
+ if (typeof body !== "undefined"){
3994
+ this.body = body;
3995
+ }
3994
3996
  this.cors();
3995
3997
  microservice.stream = stream;
3996
3998
  stream.on("data", (data) => {
@@ -4025,6 +4027,7 @@
4025
4027
 
4026
4028
  cors() {
4027
4029
  if (this.route.cors) {
4030
+ logger.debug("Validating CORS...");
4028
4031
  let {
4029
4032
  allow_origins,
4030
4033
  allow_credentials,
@@ -4035,37 +4038,54 @@
4035
4038
  if (typeof microservice.headers !== "object") {
4036
4039
  microservice.headers = {};
4037
4040
  }
4041
+ if (typeof microservice.route.responseHeaders !== "object") {
4042
+ microservice.route.responseHeaders = {};
4043
+ }
4038
4044
  if (typeof allow_origins !== "undefined") {
4045
+ logger.debug("CORS: allow_origins available. Validating origins...");
4039
4046
  // an example of allow_origins is ['https://example.com','http://www.example.com']
4040
4047
  if (allow_origins === "*" || (typeof microservice.request.headers.origin === "undefined") || [...allow_origins].indexOf(microservice.request.headers.origin) !== -1) {
4041
4048
  // for compatibility with all browsers allways return a wildcard when the origin is allowed
4042
- microservice.headers["Access-Control-Allow-Origin"] = "*";
4049
+ logger.debug("CORS: Adding header Access-Control-Allow-Origin=*");
4050
+ microservice.route.responseHeaders["Access-Control-Allow-Origin"] = "*";
4043
4051
  } else {
4044
- logger.debug("Origin is not allowed: " + microservice.request.headers.origin);
4045
- logger.debug("Forcing to finish the response...");
4052
+ logger.debug("CORS: Origin is not allowed: " + microservice.request.headers.origin);
4053
+ logger.debug("CORS: Forcing to finish the response...");
4046
4054
  this.body = {};
4047
4055
  try {
4048
4056
  this.done();
4049
- } catch (e) {}
4057
+ } catch (e) {
4058
+ logger.debug(`It was not possible to finish the call to the microservice: ${e}`);
4059
+ }
4050
4060
  }
4051
4061
  } else {
4052
- microservice.headers["Access-Control-Allow-Origin"] = "*";
4062
+ logger.debug("CORS: no allow_origins available. Allowing all origins...");
4063
+ logger.debug("CORS: Adding header Access-Control-Allow-Origin=*");
4064
+ microservice.route.responseHeaders["Access-Control-Allow-Origin"] = "*";
4053
4065
  }
4054
4066
  if (typeof allow_credentials !== "undefined") {
4055
- microservice.headers["Access-Control-Allow-Credentials"] = allow_credentials.toString();
4067
+ logger.debug(`CORS: allow_credentials present. Allowing ${allow_credentials}...`);
4068
+ microservice.route.responseHeaders["Access-Control-Allow-Credentials"] = allow_credentials.toString();
4056
4069
  } else {
4057
- microservice.headers["Access-Control-Allow-Credentials"] = "true";
4070
+ logger.debug("CORS: No allow_credentials present. Allowing all credentials.");
4071
+ microservice.route.responseHeaders["Access-Control-Allow-Credentials"] = "true";
4058
4072
  }
4059
4073
  if (typeof allow_methods !== "undefined") {
4060
- microservice.headers["Access-Control-Allow-Methods"] = [...allow_methods].join(",");
4074
+ logger.debug(`CORS: allow_methods present. Allowing ${allow_methods}...`);
4075
+ microservice.route.responseHeaders["Access-Control-Allow-Methods"] = [...allow_methods].join(",");
4061
4076
  } else {
4062
- microservice.headers["Access-Control-Allow-Methods"] = "GET, OPTIONS, POST";
4077
+ logger.debug("CORS: No allow_methods present. Allowing only GET, OPTIONS and POST");
4078
+ microservice.route.responseHeaders["Access-Control-Allow-Methods"] = "GET, OPTIONS, POST";
4063
4079
  }
4064
4080
  if (typeof allow_headers !== "undefined") {
4065
- microservice.headers["Access-Control-Allow-Headers"] = [...allow_headers].join(",");
4081
+ logger.debug(`CORS: allow_headers present. Allowing ${allow_headers}...`);
4082
+ microservice.route.responseHeaders["Access-Control-Allow-Headers"] = [...allow_headers].join(",");
4066
4083
  } else {
4067
- microservice.headers["Access-Control-Allow-Headers"] = "*";
4084
+ logger.debug(`CORS: No allow_headers present. Allowing all headers...`);
4085
+ microservice.route.responseHeaders["Access-Control-Allow-Headers"] = "*";
4068
4086
  }
4087
+ } else {
4088
+ logger.debug("No CORS validation available. You can specify cors in CONFIG.backend.routes[].cors");
4069
4089
  }
4070
4090
  }
4071
4091
 
@@ -4075,6 +4095,7 @@
4075
4095
  }
4076
4096
 
4077
4097
  get(formData) {
4098
+ logger.debug(`[BackendMicroservice.get] Data received: ${_DataStringify(formData)}`);
4078
4099
  this.done();
4079
4100
  }
4080
4101
 
@@ -4108,27 +4129,45 @@
4108
4129
 
4109
4130
  finishWithBody(stream) {
4110
4131
  try {
4111
- stream.write(_DataStringify(this.body));
4132
+ logger.debug("[BackendMicroservice.finishWithBody] Ending the stream...");
4133
+ logger.debug(`[BackendMicroservice.finishWithBody] type of body is: ${typeof this.body}`);
4134
+ if (typeof this.body !== "string"){
4135
+ this.body = _DataStringify(this.body);
4136
+ }
4137
+ logger.debug(`[BackendMicroservice.finishWithBody] \n body: ${this.body} `);
4138
+ stream.write(this.body);
4112
4139
  stream.end();
4140
+ logger.debug(`[BackendMicroservice.finishWithBody] Stream ended.`);
4113
4141
  } catch (e) {
4114
- logger.debug("Something wrong writing the response for microservice" + e.toString());
4142
+ logger.debug(`[BackendMicroservice.finishWithBody] Something went wrong ending the stream: ${e}`);
4115
4143
  }
4116
4144
  }
4117
4145
 
4118
4146
  done() {
4147
+ logger.debug(`[BackendMicroservice.done] Finalizing the response...`);
4119
4148
  var microservice = this;
4120
4149
  var stream = microservice.stream;
4121
4150
  try {
4122
- stream.respond(microservice.headers);
4151
+ logger.debug(`[BackendMicroservice.done] Sending response headers...`);
4152
+ if (microservice.route.responseHeaders){
4153
+ logger.debug(`[BackendMicroservice.done] Response headers present: ${Object.keys(microservice.route.responseHeaders)}`);
4154
+ stream.respond(microservice.route.responseHeaders);
4155
+ } else {
4156
+ throw Error(`[BackendMicroservice.done] No headers present.`);
4157
+ }
4123
4158
  } catch (e) {
4124
- logger.debug(e.toString());
4159
+ logger.debug(`[BackendMicroservice.done] Something went wrong sending response headers: ${e}`);
4125
4160
  }
4126
4161
  if (microservice.body !== null) {
4127
4162
  try {
4163
+ logger.debug(`[BackendMicroservice.done] A body of message is present. Finalizing the response...`);
4128
4164
  microservice.finishWithBody.call(microservice, stream);
4129
4165
  } catch (e) {
4130
- logger.debug(e.toString());
4166
+ logger.debug(`[BackendMicroservice.done] Something went wrong finalizing the response: ${e}`);
4131
4167
  }
4168
+ } else {
4169
+ logger.debug("[BackendMicroservice.done] No body present. Ending stream...");
4170
+ stream.end();
4132
4171
  }
4133
4172
  }
4134
4173