soajs.controller 4.2.15 → 4.2.17

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/.travis.yml CHANGED
@@ -20,18 +20,18 @@ jobs:
20
20
  - if [ "$TRAVIS_BRANCH" != "master" ]; then grunt test; fi
21
21
  - if [ "$TRAVIS_BRANCH" = "master" ]; then grunt coverage; fi
22
22
 
23
- - stage: Publish to npm
24
- if: branch =~ /(release)/
25
- script:
26
- - echo "PUBLISH npm"
27
- deploy:
28
- skip_cleanup: true
29
- provider: npm
30
- email: $NPM_EMAIL
31
- api_key: $NPM_TOKEN
32
- on:
33
- all_branches: true
34
- condition: $TRAVIS_BRANCH =~ ^(release)*
23
+ # - stage: Publish to npm
24
+ # if: branch =~ /(release)/
25
+ # script:
26
+ # - echo "PUBLISH npm"
27
+ # deploy:
28
+ # skip_cleanup: true
29
+ # provider: npm
30
+ # email: $NPM_EMAIL
31
+ # api_key: $NPM_TOKEN
32
+ # on:
33
+ # all_branches: true
34
+ # condition: $TRAVIS_BRANCH =~ ^(release)*
35
35
 
36
36
  - stage: Publish to docker registry
37
37
  if: branch =~ /(release)/
@@ -0,0 +1,81 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * @license
5
+ * Copyright SOAJS All Rights Reserved.
6
+ *
7
+ * Use of this source code is governed by an Apache license that can be
8
+ * found in the LICENSE file at the root of this repository
9
+ */
10
+
11
+ const request = require("request");
12
+ const get = (p, o) => p.reduce((xs, x) => (xs && xs[x]) ? xs[x] : null, o);
13
+
14
+ /**
15
+ *
16
+ * @param configuration
17
+ * @returns {Function}
18
+ */
19
+ module.exports = () => {
20
+
21
+ return (req, res, next) => {
22
+ next();
23
+
24
+ let lastSeen = get(["soajs", "registry", "custom", "gateway", "value", "lastSeen"], req);
25
+ if (lastSeen && lastSeen.active) {
26
+
27
+ const item = {
28
+ "name": lastSeen.serviceName || "urac",
29
+ "version": lastSeen.serviceVersion || "3",
30
+ "api": lastSeen.api || "/user/last/seen"
31
+ };
32
+
33
+ let userId = null;
34
+ if (req.soajs.uracDriver) {
35
+ let uracObj = req.soajs.uracDriver.getProfile();
36
+ userId = uracObj._id;
37
+ }
38
+
39
+ if (userId) {
40
+ req.soajs.awareness.getHost(item.name, item.version, (host) => {
41
+ if (host) {
42
+ item.host = host;
43
+ item.port = req.soajs.registry.services[item.name].port;
44
+
45
+ let options = {
46
+ method: "post",
47
+ uri: "http://" + item.host + ":" + item.port + item.api,
48
+ json: true
49
+ };
50
+ if (req.headers && req.headers.soajsinjectobj) {
51
+ options.headers = { "soajsinjectobj": req.headers.soajsinjectobj };
52
+ }
53
+ request(options, (error, response, body) => {
54
+ if (error) {
55
+ req.soajs.log.debug("lastSeen failed for [" + item.name + "@" + item.version + " " + item.api + "]");
56
+ req.soajs.log.error("lastSeen " + error.message);
57
+ } else if (!body.result) {
58
+ let errorMsg = "";
59
+ if (body.errors && body.errors && body.errors.details && body.errors.details.length > 0) {
60
+ body.errors.details.forEach((detail) => {
61
+ if (errorMsg === "") {
62
+ errorMsg += detail.message;
63
+ }
64
+ else {
65
+ errorMsg += " - " + detail.message;
66
+ }
67
+ });
68
+ }
69
+ req.soajs.log.error("lastSeen", errorMsg);
70
+ }
71
+ });
72
+ } else {
73
+ req.soajs.log.debug("lastSeen failed with no host for [" + item.name + "@" + item.version + " " + item.api + "]");
74
+ }
75
+ });
76
+ } else {
77
+ req.soajs.log.debug("lastSeen failed with no userId for [" + item.name + "@" + item.version + " " + item.api + "]");
78
+ }
79
+ }
80
+ };
81
+ };
@@ -22,6 +22,9 @@ let model = {
22
22
  model.log = log;
23
23
  if (!model.mongo) {
24
24
  model.mongo = new Mongo(dbConfiguration);
25
+ model.mongo.createIndex(throttling_monitor, { 'l1': 1, 'l2': 1 }, {}, (err, index) => {
26
+ log.debug("Index: " + index + " created with error: " + err);
27
+ });
25
28
  }
26
29
  },
27
30
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "soajs.controller",
3
3
  "description": "soajs multi tenant API gateway",
4
- "version": "4.2.15",
4
+ "version": "4.2.17",
5
5
  "author": {
6
6
  "name": "soajs team",
7
7
  "email": "team@soajs.org"
@@ -18,7 +18,7 @@
18
18
  "test": "grunt test"
19
19
  },
20
20
  "dependencies": {
21
- "async": "3.2.5",
21
+ "async": "3.2.6",
22
22
  "connect": "3.7.0",
23
23
  "http-proxy": "1.18.1",
24
24
  "jsonwebtoken": "9.0.2",
@@ -30,15 +30,15 @@
30
30
  "path-to-regexp": "6.2.2",
31
31
  "request": "2.88.2",
32
32
  "soajs.core.libs": "1.2.0",
33
- "soajs.core.modules": "5.2.11",
34
- "soajs.urac.driver": "3.2.8",
33
+ "soajs.core.modules": "5.2.12",
34
+ "soajs.urac.driver": "3.2.9",
35
35
  "useragent": "2.3.0"
36
36
  },
37
37
  "devDependencies": {
38
- "@babel/core": "7.25.2",
39
- "@babel/plugin-transform-runtime": "7.24.7",
40
- "@babel/preset-env": "7.25.3",
41
- "express": "4.18.2",
38
+ "@babel/core": "7.26.0",
39
+ "@babel/plugin-transform-runtime": "7.25.9",
40
+ "@babel/preset-env": "7.26.0",
41
+ "express": "4.21.1",
42
42
  "grunt": "1.6.1",
43
43
  "grunt-babel": "8.0.0",
44
44
  "grunt-contrib-clean": "2.0.1",
@@ -50,6 +50,7 @@
50
50
  "grunt-jsdoc": "2.4.1",
51
51
  "grunt-mocha-test": "0.13.3",
52
52
  "mocha": "10.7.3",
53
- "sinon": "18.0.0"
53
+ "nock": "13.5.6",
54
+ "sinon": "19.0.2"
54
55
  }
55
56
  }
@@ -37,6 +37,7 @@ const keyACL_mw = require("../mw/keyACL/index");
37
37
  const gotoService_mw = require("../mw/gotoService/index");
38
38
  const mt_mw = require("../mw/mt/index");
39
39
  const traffic_mw = require("../mw/traffic/index");
40
+ const lastSeen_mw = require("../mw/lastSeen/index");
40
41
 
41
42
  const utils = require("../utilities/utils");
42
43
 
@@ -172,6 +173,8 @@ Controller.prototype.init = function (callback) {
172
173
  "gatewayDB": registry.coreDB.gateway || registry.coreDB.provision
173
174
  }));
174
175
 
176
+ app.use(lastSeen_mw());
177
+
175
178
  app.use((req, res, next) => {
176
179
  setImmediate(() => {
177
180
  req.soajs.controller.gotoservice(req, res, next);
@@ -34,6 +34,7 @@ describe("Starting Gateway Unit test", () => {
34
34
  require("./mw/response/index.js");
35
35
  require("./mw/soajs/index.js");
36
36
  require("./mw/traffic/index.js");
37
+ require("./mw/lastSeen/index.js");
37
38
 
38
39
  require("./utilities/utils.js");
39
40
 
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+
3
+ const helper = require("../../../helper.js");
4
+ const mw = helper.requireModule('./mw/lastSeen/index');
5
+ const assert = require('assert');
6
+ const nock = require('nock')
7
+
8
+ describe("Unit test for: mw - lastSeen", () => {
9
+
10
+ it("success - default from environment", (done) => {
11
+ let res = {};
12
+ let req = {
13
+ getClientIP: () => {
14
+ return "127.0.0.1"
15
+ },
16
+ soajs: {
17
+ log: {
18
+ debug: (a) => {
19
+ console.log(a);
20
+ },
21
+ error: (a) => {
22
+ console.log(a);
23
+ }
24
+ },
25
+ uracDriver: {
26
+ getProfile: (name, version, cb) => {
27
+ return { _id: "1111111111" };
28
+ }
29
+ },
30
+ awareness: {
31
+ getHost: (name, version, cb) => {
32
+ return cb("urac.fake");
33
+ }
34
+ },
35
+ registry: {
36
+ services: {
37
+ urac: {
38
+ port: 4001
39
+ }
40
+ },
41
+ custom: {
42
+ gateway: {
43
+ value: {
44
+ lastSeen: {
45
+ active: true
46
+ }
47
+ }
48
+ }
49
+ }
50
+ }
51
+ }
52
+ };
53
+ const scope = nock('http://urac.fake:4001')
54
+ .post('/user/last/seen')
55
+ .reply(200, {
56
+ result: true,
57
+ data: true
58
+ })
59
+ let functionMw = mw({});
60
+ functionMw(req, res, (error) => {
61
+ assert.ifError(error);
62
+ // nock.cleanAll()
63
+ done();
64
+ });
65
+ });
66
+
67
+ });