@ikonintegration/ikapi 2.5.6 → 2.6.0-beta2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikonintegration/ikapi",
3
- "version": "2.5.6",
3
+ "version": "2.6.0-beta2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "module": "main.js",
@@ -10,20 +10,21 @@
10
10
  "author": "",
11
11
  "license": "ISC",
12
12
  "dependencies": {
13
- "@aws/dynamodb-auto-marshaller": "0.7.1",
14
- "abind": "1.0.5",
15
- "aws-sdk": "^2.951.0",
16
- "bluebird": "3.7.2",
17
- "email-templates": "^8.0.7",
18
- "esm": "3.2.25",
19
- "is-email": "^1.0.1",
20
- "is-uuid": "1.0.2",
21
- "json-stringify-safe": "5.0.1",
22
- "ksuid": "2.0.0",
23
- "libphonenumber-js": "^1.9.22",
24
- "nodemailer": "^6.6.3",
25
- "path-to-regexp": "6.2.0",
26
- "pg": "^8.6.0",
13
+ "@aws/dynamodb-auto-marshaller": "^0.7.1",
14
+ "abind": "^1.0.5",
15
+ "aws-sdk": "^2.1034.0",
16
+ "bluebird": "^3.7.2",
17
+ "email-templates": "^8.0.8",
18
+ "esm": "^3.2.25",
19
+ "is-email": "^1.0.2",
20
+ "is-uuid": "^1.0.2",
21
+ "json-stringify-safe": "^5.0.1",
22
+ "ksuid": "^3.0.0",
23
+ "libphonenumber-js": "^1.9.43",
24
+ "nodemailer": "^6.7.1",
25
+ "path-to-regexp": "^6.2.0",
26
+ "pg": "^8.7.1",
27
+ "sha1": "^1.1.1",
27
28
  "stack-trace": "0.0.10",
28
29
  "superstruct": "0.8.4"
29
30
  }
@@ -62,12 +62,12 @@ export default class IKResponse {
62
62
  //
63
63
  function CustomError(body) {
64
64
  this.name = body && body.error ? body.error : 'UnknownError';
65
- this.message = body;
65
+ this.message = body && body.message ? body.message : 'Unknown error!';
66
66
  }
67
67
  CustomError.prototype = new Error();
68
68
  //
69
69
  if (!this._throwOnErrors) context.fail(new CustomError(this._body));
70
- else throw new CustomError(this._body);
70
+ else throw (new CustomError(this._body));
71
71
  }
72
72
  }
73
73
  }
@@ -1,9 +1,13 @@
1
1
  import AWS from "aws-sdk";
2
2
  import HTTPS from "https";
3
3
  import Utils from "./../../API/IKUtils";
4
+ import sha1 from 'sha1';
4
5
  //
5
6
  import IKGlobals from './../../IKGlobals';
6
7
  import IKDB from './../Prototype/IKDB';
8
+ //reusable connection
9
+ var DDB_CONN = null;
10
+ var DDB_CONN_HASH = null;
7
11
  //
8
12
  export default class IKDB_DDB extends IKDB {
9
13
  constructor(config, transaction) {
@@ -15,6 +19,10 @@ export default class IKDB_DDB extends IKDB {
15
19
  if (config && this.tableName) { localConsole.debug(`Using table: ${this.tableName} on region: ${this.region}`); }
16
20
  }
17
21
 
22
+ async _getConnection() {
23
+ if ((!DDB_CONN && !DDB_CONN_HASH) || DDB_CONN_HASH != sha1(this.region)) DDB_CONN = await this._newConnection(this.config);
24
+ return DDB_CONN;
25
+ }
18
26
  async connect() {
19
27
  const localConsole = (this.transaction ? this.transaction.logger : console);
20
28
  //setup db
@@ -29,6 +37,9 @@ export default class IKDB_DDB extends IKDB {
29
37
  //initialize connection
30
38
  AWS.config.update({httpOptions: sslAgent, region: this.region});
31
39
  this.connection = new AWS.DynamoDB();
40
+ //Reusable logic
41
+ DDB_CONN = this.connection;
42
+ DDB_CONN_HASH = sha1(this.region);
32
43
  }
33
44
  }
34
45
  }
@@ -1,6 +1,10 @@
1
1
  import AWS from "aws-sdk";
2
+ import sha1 from 'sha1';
2
3
  //
3
4
  import Utils from "./../API/IKUtils";
5
+ //reusable client
6
+ var PUBLISHER_CONN = null;
7
+ var PUBLISHER_CONN_HASH = null;
4
8
  //
5
9
  export default class IKPublisher {
6
10
  constructor(config) {
@@ -9,25 +13,33 @@ export default class IKPublisher {
9
13
  console.debug(`Using region: ${this.region}`);
10
14
  }
11
15
  }
12
-
16
+ /* Public */
13
17
  async publishOnTopic(messageObject, topic, additionalProps) {
14
18
  let resp = null;
15
19
  try {
16
- //Configure when sending!
17
- let configObj = { region: this.region };
18
- if (Utils.isOffline()) configObj = { ...configObj, accessKeyId: process.env.AWS_ACCESS_KEY_ID, secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY };
19
- AWS.config.update(configObj);
20
+ this._connect();
20
21
  //Send to SNS
21
22
  const params = {
22
23
  Message: JSON.stringify(messageObject),
23
24
  TopicArn: topic,
24
25
  ...(additionalProps ? additionalProps : {}),
25
26
  };
26
- resp = await (new AWS.SNS({ apiVersion: '2010-03-31' })).publish(params).promise();
27
+ resp = await PUBLISHER_CONN.publish(params).promise();
27
28
  } catch (e) {
28
29
  console.error(`Error while publishing into topic ${topic} with error: ${e}`);
29
30
  }
30
31
  console.debug('Publisher resp', resp);
31
32
  return resp;
32
33
  }
34
+ /* Private */
35
+ _connect() {
36
+ if ((!PUBLISHER_CONN && !PUBLISHER_CONN_HASH) || PUBLISHER_CONN_HASH != sha1(this.region)) {
37
+ //Configure when sending!
38
+ let configObj = { region: this.region };
39
+ if (Utils.isOffline()) configObj = { ...configObj, accessKeyId: process.env.AWS_ACCESS_KEY_ID, secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY };
40
+ AWS.config.update(configObj);
41
+ PUBLISHER_CONN = (new AWS.SNS({ apiVersion: '2010-03-31' }));
42
+ PUBLISHER_CONN_HASH = sha1(this.region);
43
+ }
44
+ }
33
45
  }