@things-factory/integration-lmd 3.7.7 → 3.8.26

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,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Etrax = void 0;
7
- const node_fetch_1 = __importDefault(require("node-fetch"));
8
7
  const crypto_1 = __importDefault(require("crypto"));
9
- const entities_1 = require("../../entities");
8
+ const node_fetch_1 = __importDefault(require("node-fetch"));
10
9
  const typeorm_1 = require("typeorm");
10
+ const entities_1 = require("../../entities");
11
11
  const ENDPOINT = 'http://ets.sntglobal.com';
12
12
  //const ENDPOINT = 'https://localhost:44344'
13
13
  const debug = require('debug')('things-factory:integration-lmd:etrax');
@@ -22,10 +22,10 @@ class Etrax {
22
22
  }
23
23
  async post(path, data) {
24
24
  const timestamp = this.getTimestamp();
25
- let apiKey = "CREATE_DELIVERY";
25
+ let apiKey = 'CREATE_DELIVERY';
26
26
  //Path to APIKEY
27
27
  if (path.includes('create-delivery')) {
28
- apiKey = "CREATE_DELIVERY";
28
+ apiKey = 'CREATE_DELIVERY';
29
29
  }
30
30
  await this.generateToken(timestamp, apiKey);
31
31
  let finalData = Object.assign(Object.assign({}, data), this._auth);
@@ -49,7 +49,7 @@ class Etrax {
49
49
  return result;
50
50
  }
51
51
  async validateToken(receivedToken, apiKey, timestamp) {
52
- if (receivedToken !== await this.generateToken(timestamp, apiKey)) {
52
+ if (receivedToken !== (await this.generateToken(timestamp, apiKey))) {
53
53
  return false;
54
54
  }
55
55
  else {
@@ -64,17 +64,17 @@ class Etrax {
64
64
  const md5 = this.generateMD5(temp);
65
65
  this._auth.TimeStamp = timestamp;
66
66
  this._auth.Token = md5;
67
- return md5;
67
+ return md5.toString().toUpperCase();
68
68
  }
69
69
  getTimestamp() {
70
- const pad = (n) => n < 10 ? '0' + n : n;
70
+ const pad = (n) => (n < 10 ? '0' + n : n);
71
71
  const date = new Date();
72
- const timestamp = date.getFullYear().toString()
73
- + pad(date.getMonth() + 1)
74
- + pad(date.getDate())
75
- + pad(date.getHours())
76
- + pad(date.getMinutes())
77
- + pad(date.getSeconds());
72
+ const timestamp = date.getFullYear().toString() +
73
+ pad(date.getMonth() + 1) +
74
+ pad(date.getDate()) +
75
+ pad(date.getHours()) +
76
+ pad(date.getMinutes()) +
77
+ pad(date.getSeconds());
78
78
  return timestamp;
79
79
  }
80
80
  generateMD5(input) {
@@ -1 +1 @@
1
- {"version":3,"file":"etrax.js","sourceRoot":"","sources":["../../../server/controllers/etrax/etrax.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA8B;AAC9B,oDAA2B;AAC3B,6CAAiD;AACjD,qCAAuC;AAGvC,MAAM,QAAQ,GAAG,0BAA0B,CAAA;AAC3C,4CAA4C;AAC5C,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,sCAAsC,CAAC,CAAA;AAQtE,MAAa,KAAK;IAIf,YAAY,YAAoB;QAC7B,IAAI,CAAC,KAAK,GAAG;YACV,QAAQ,EAAE,EAAE;YACZ,SAAS,EAAE,EAAE;YACb,KAAK,EAAE,EAAE;SACX,CAAC;QAEF,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,YAAY,CAAA;IACrC,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,IAAY,EAAE,IAAS;QAE/B,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QACtC,IAAI,MAAM,GAAG,iBAAiB,CAAA;QAE9B,gBAAgB;QAChB,IAAI,IAAI,CAAC,QAAQ,CAAC,iBAAiB,CAAC,EAAC;YAClC,MAAM,GAAG,iBAAiB,CAAA;SAC5B;QAED,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAE5C,IAAI,SAAS,mCACP,IAAI,GACJ,IAAI,CAAC,KAAK,CACf,CAAA;QACD,IAAI,QAAQ,G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AI,CAAC,UAAU,EAAE,CAAC;YACtB,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAA;QACxB,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,WAAW,CAAC,KAAa;QACvB,OAAO,gBAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAC7D,CAAC;CACF;AA1FD,sBA0FC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/integration-lmd",
3
- "version": "3.7.7",
3
+ "version": "3.8.26",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -24,19 +24,19 @@
24
24
  "migration:create": "node ../../node_modules/typeorm/cli.js migration:create -d ./server/migrations"
25
25
  },
26
26
  "dependencies": {
27
- "@things-factory/apptool-ui": "^3.7.5",
28
- "@things-factory/auth-ui": "^3.7.7",
29
- "@things-factory/biz-base": "^3.7.5",
30
- "@things-factory/code-ui": "^3.7.5",
31
- "@things-factory/context-ui": "^3.7.5",
27
+ "@things-factory/apptool-ui": "^3.8.0",
28
+ "@things-factory/auth-ui": "^3.8.0",
29
+ "@things-factory/biz-base": "^3.8.26",
30
+ "@things-factory/code-ui": "^3.8.0",
31
+ "@things-factory/context-ui": "^3.8.0",
32
32
  "@things-factory/grist-ui": "^3.7.5",
33
- "@things-factory/i18n-ui": "^3.7.5",
34
- "@things-factory/integration-ui": "^3.7.5",
35
- "@things-factory/more-ui": "^3.7.5",
36
- "@things-factory/resource-ui": "^3.7.7",
37
- "@things-factory/setting-ui": "^3.7.5",
38
- "@things-factory/shell": "^3.7.5",
39
- "@things-factory/system-ui": "^3.7.5",
33
+ "@things-factory/i18n-ui": "^3.8.0",
34
+ "@things-factory/integration-ui": "^3.8.0",
35
+ "@things-factory/more-ui": "^3.8.0",
36
+ "@things-factory/resource-ui": "^3.8.0",
37
+ "@things-factory/setting-ui": "^3.8.19",
38
+ "@things-factory/shell": "^3.8.0",
39
+ "@things-factory/system-ui": "^3.8.0",
40
40
  "debug": "^4.1.1",
41
41
  "node-fetch": "^2.6.0"
42
42
  },
@@ -51,5 +51,5 @@
51
51
  "nock": "^13.0.2",
52
52
  "should": "^13.2.3"
53
53
  },
54
- "gitHead": "7e1cfc771ca9e8970d90493d3049d4d589e96f08"
54
+ "gitHead": "6ca26d91b7dad8eec6bc7859391bbd50374c744b"
55
55
  }
@@ -1,107 +1,107 @@
1
- import fetch from 'node-fetch'
2
1
  import crypto from 'crypto'
3
- import { LastMileDelivery } from '../../entities'
2
+ import fetch from 'node-fetch'
4
3
  import { getRepository } from 'typeorm'
5
- import { LMD_STATUS } from '..'
4
+
5
+ import { LastMileDelivery } from '../../entities'
6
6
 
7
7
  const ENDPOINT = 'http://ets.sntglobal.com'
8
8
  //const ENDPOINT = 'https://localhost:44344'
9
9
  const debug = require('debug')('things-factory:integration-lmd:etrax')
10
10
 
11
11
  export type EtraxAuth = {
12
- SourceID: string,
13
- TimeStamp: string,
14
- Token: string
12
+ SourceID: string
13
+ TimeStamp: string
14
+ Token: string
15
15
  }
16
16
 
17
17
  export class Etrax {
18
- private _auth: EtraxAuth
19
- private _secretKey: string
20
-
21
- constructor(customerCode: string){
22
- this._auth = {
23
- SourceID: '',
24
- TimeStamp: '',
25
- Token: ''
26
- };
27
-
28
- this._auth.SourceID = customerCode
29
- }
30
-
31
- async post(path: string, data: any){
32
-
33
- const timestamp = this.getTimestamp();
34
- let apiKey = "CREATE_DELIVERY"
35
-
36
- //Path to APIKEY
37
- if (path.includes('create-delivery')){
38
- apiKey = "CREATE_DELIVERY"
39
- }
40
-
41
- await this.generateToken(timestamp, apiKey);
42
-
43
- let finalData = {
44
- ...data,
45
- ...this._auth
46
- }
47
- let jsonData = JSON.stringify(finalData)
48
-
49
- debug(ENDPOINT + path)
50
- debug(jsonData)
51
-
52
- const response = await fetch(ENDPOINT + path, {
53
- method: 'post',
54
- headers: {
55
- accept: 'application/json',
56
- 'Content-Type': 'application/json'
57
- },
58
- body: jsonData
59
- })
60
-
61
- if (!response.ok) {
62
- throw response
63
- }
64
- let result = await response.json()
65
- debug('response result', result)
66
- //result = this.convertStatusCode(result)
67
-
68
- return result
69
- }
70
-
71
- async validateToken(receivedToken: string, apiKey: string, timestamp: string) {
72
- if (receivedToken !== await this.generateToken(timestamp, apiKey)){
73
- return false
74
- } else {
75
- return true
76
- }
77
- }
78
-
79
- async generateToken(timestamp: string, apiKey: string) {
80
- const lmdRepo = getRepository(LastMileDelivery)
81
- const lmd = await lmdRepo.findOne({where: {clientName: this._auth.SourceID}})
82
- const secretKey = lmd.secretKey
83
-
84
- const temp = apiKey + timestamp + secretKey
85
- const md5 = this.generateMD5(temp)
86
- this._auth.TimeStamp = timestamp
87
- this._auth.Token = md5
88
-
89
- return md5
90
- }
91
-
92
- getTimestamp() {
93
- const pad = (n: Number) => n < 10 ? '0' + n : n
94
- const date = new Date()
95
- const timestamp = date.getFullYear().toString()
96
- + pad(date.getMonth() + 1)
97
- + pad( date.getDate())
98
- + pad( date.getHours() )
99
- + pad( date.getMinutes() )
100
- + pad( date.getSeconds() )
101
- return timestamp
102
- }
103
-
104
- generateMD5(input: string){
105
- return crypto.createHash('md5').update(input).digest('hex')
106
- }
107
- }
18
+ private _auth: EtraxAuth
19
+ private _secretKey: string
20
+
21
+ constructor(customerCode: string) {
22
+ this._auth = {
23
+ SourceID: '',
24
+ TimeStamp: '',
25
+ Token: ''
26
+ }
27
+
28
+ this._auth.SourceID = customerCode
29
+ }
30
+
31
+ async post(path: string, data: any) {
32
+ const timestamp = this.getTimestamp()
33
+ let apiKey = 'CREATE_DELIVERY'
34
+
35
+ //Path to APIKEY
36
+ if (path.includes('create-delivery')) {
37
+ apiKey = 'CREATE_DELIVERY'
38
+ }
39
+
40
+ await this.generateToken(timestamp, apiKey)
41
+
42
+ let finalData = {
43
+ ...data,
44
+ ...this._auth
45
+ }
46
+ let jsonData = JSON.stringify(finalData)
47
+
48
+ debug(ENDPOINT + path)
49
+ debug(jsonData)
50
+
51
+ const response = await fetch(ENDPOINT + path, {
52
+ method: 'post',
53
+ headers: {
54
+ accept: 'application/json',
55
+ 'Content-Type': 'application/json'
56
+ },
57
+ body: jsonData
58
+ })
59
+
60
+ if (!response.ok) {
61
+ throw response
62
+ }
63
+ let result = await response.json()
64
+ debug('response result', result)
65
+ //result = this.convertStatusCode(result)
66
+
67
+ return result
68
+ }
69
+
70
+ async validateToken(receivedToken: string, apiKey: string, timestamp: string) {
71
+ if (receivedToken !== (await this.generateToken(timestamp, apiKey))) {
72
+ return false
73
+ } else {
74
+ return true
75
+ }
76
+ }
77
+
78
+ async generateToken(timestamp: string, apiKey: string) {
79
+ const lmdRepo = getRepository(LastMileDelivery)
80
+ const lmd = await lmdRepo.findOne({ where: { clientName: this._auth.SourceID } })
81
+ const secretKey = lmd.secretKey
82
+
83
+ const temp = apiKey + timestamp + secretKey
84
+ const md5 = this.generateMD5(temp)
85
+ this._auth.TimeStamp = timestamp
86
+ this._auth.Token = md5
87
+
88
+ return md5.toString().toUpperCase()
89
+ }
90
+
91
+ getTimestamp() {
92
+ const pad = (n: Number) => (n < 10 ? '0' + n : n)
93
+ const date = new Date()
94
+ const timestamp =
95
+ date.getFullYear().toString() +
96
+ pad(date.getMonth() + 1) +
97
+ pad(date.getDate()) +
98
+ pad(date.getHours()) +
99
+ pad(date.getMinutes()) +
100
+ pad(date.getSeconds())
101
+ return timestamp
102
+ }
103
+
104
+ generateMD5(input: string) {
105
+ return crypto.createHash('md5').update(input).digest('hex')
106
+ }
107
+ }