@ikonintegration/ikapi 2.6.9 → 3.0.0-alpha2

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,18 +1,22 @@
1
1
  {
2
2
  "name": "@ikonintegration/ikapi",
3
- "version": "2.6.9",
3
+ "version": "3.0.0-alpha2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "module": "main.js",
7
7
  "scripts": {
8
- "test": "echo \"Error: no test specified\" && exit 1"
8
+ "test": "echo \"Error: no test specified\" && exit 1",
9
+ "pre-publish": "npm i -production && curl -sf https://gobinaries.com/tj/node-prune | sh && node-prune"
9
10
  },
10
11
  "author": "",
11
12
  "license": "ISC",
12
13
  "dependencies": {
13
- "@aws/dynamodb-auto-marshaller": "^0.7.1",
14
+ "@aws-sdk/client-dynamodb": "^3.72.0",
15
+ "@aws-sdk/client-ses": "^3.72.0",
16
+ "@aws-sdk/client-sns": "^3.72.0",
17
+ "@aws-sdk/node-http-handler": "^3.58.0",
18
+ "@aws-sdk/util-dynamodb": "^3.72.0",
14
19
  "abind": "^1.0.5",
15
- "aws-sdk": "^2.1034.0",
16
20
  "bluebird": "^3.7.2",
17
21
  "email-templates": "^8.0.8",
18
22
  "esm": "^3.2.25",
@@ -20,7 +24,6 @@
20
24
  "is-uuid": "^1.0.2",
21
25
  "json-stringify-safe": "^5.0.1",
22
26
  "ksuid": "^3.0.0",
23
- "libphonenumber-js": "^1.9.43",
24
27
  "nodemailer": "^6.7.1",
25
28
  "path-to-regexp": "^6.2.0",
26
29
  "pg": "^8.7.1",
@@ -1,5 +1,4 @@
1
1
  /** Ikon Integration DynamoDB wrapper**/
2
- import AWS from "aws-sdk";
3
2
  import Utils from "./IKUtils";
4
3
  //
5
4
  export default class IKRequest {
@@ -1,6 +1,6 @@
1
- import AWS from "aws-sdk";
1
+
2
2
  import KSUID from 'ksuid';
3
- import { Marshaller } from '@aws/dynamodb-auto-marshaller';
3
+ import { convertToAttr, marshall, unmarshall } from "@aws-sdk/util-dynamodb";
4
4
  //
5
5
  export default class IKUtils {}
6
6
  IKUtils.isOffline = function() { return process.env.IS_OFFLINE; }
@@ -32,17 +32,15 @@ IKUtils.caseInsensitiveSetObjectForKey = function(obj, key, value) {
32
32
  IKUtils.encapsulateForDB = function(item) {
33
33
  if (Array.isArray(item)) return {L: item.map(_i => IKUtils.encapsulateForDB(_i))};
34
34
  else if (typeof item === 'object' && isNaN(parseInt(item))) {
35
- const marshaller = new Marshaller({onEmpty: 'omit'});
36
- return {M: marshaller.marshallItem(item)};
37
- } else return AWS.DynamoDB.Converter.input(item);
35
+ return {M: marshall(item, {removeUndefinedValues: true})};
36
+ } else return convertToAttr(item);
38
37
  }
39
38
  IKUtils.decapsulateForDB = function(item) {
40
39
  if (!item && item !== false) return null;
41
40
  if (Array.isArray(item)) {
42
41
  return item.map(_item => IKUtils.decapsulateForDB(_item));
43
42
  } else if (typeof item === 'object') {
44
- const marshaller = new Marshaller({onEmpty: 'omit'});
45
- return marshaller.unmarshallItem(item);
43
+ return unmarshall(item, { removeUndefinedValues: true });
46
44
  } return item;
47
45
  }
48
46
  //Threads
@@ -81,10 +81,7 @@ export default class IKCache_Redis extends IKCache {
81
81
  }
82
82
  _isRedisClientV4() {
83
83
  let isV4 = false;
84
- try {
85
- const test = require('redis').createClient({});
86
- if (test.connect) isV4 = true;
87
- }
84
+ try { isV4 = !!require('redis').createCluster; }
88
85
  catch (e) { }
89
86
  return isV4;
90
87
  }
@@ -1,5 +1,5 @@
1
- import AWS from "aws-sdk";
2
- import HTTPS from "https";
1
+ import { DynamoDB } from "@aws-sdk/client-dynamodb";
2
+ import { NodeHttpHandler } from "@aws-sdk/node-http-handler";
3
3
  import Utils from "./../../API/IKUtils";
4
4
  import sha1 from 'sha1';
5
5
  //
@@ -15,7 +15,7 @@ export default class IKDB_DDB extends IKDB {
15
15
  this.tableName = config.tableName;
16
16
  this.region = config.region;
17
17
  //
18
- const localConsole = (transaction ? transaction.logger : console);
18
+ // const localConsole = (transaction ? transaction.logger : console);
19
19
  // if (config && this.tableName) { localConsole.debug(`Using table: ${this.tableName} on region: ${this.region}`); }
20
20
  }
21
21
 
@@ -28,15 +28,16 @@ export default class IKDB_DDB extends IKDB {
28
28
  //setup db
29
29
  if (Utils.isOffline()) {
30
30
  localConsole.debug("Starting offline database connection");
31
- this.connection = new AWS.DynamoDB(IKGlobals.DynamoDBLocalConfig);
31
+ this.connection = new DynamoDB(IKGlobals.DynamoDBLocalConfig);
32
32
  } else {
33
33
  // localConsole.debug("Starting remote database connection");
34
- //setup ssl
35
- const sslAgent = new HTTPS.Agent({ keepAlive: true, maxSockets: 50, rejectUnauthorized: true });
36
- sslAgent.setMaxListeners(50);
37
34
  //initialize connection
38
- AWS.config.update({httpOptions: sslAgent, region: this.region});
39
- this.connection = new AWS.DynamoDB();
35
+ this.connection = new DynamoDB({
36
+ region: this.region,
37
+ requestHandler: new NodeHttpHandler({
38
+ httpsAgent: new Agent({ keepAlive: false, maxSockets: 50, rejectUnauthorized: true }),
39
+ })
40
+ });
40
41
  //Reusable logic
41
42
  DDB_CONN = this.connection;
42
43
  DDB_CONN_HASH = sha1(this.region);
@@ -80,19 +80,3 @@ export default class IKDBQueryPut extends IKDBBaseQuery {
80
80
  } return expression;
81
81
  }
82
82
  }
83
-
84
-
85
- /*marshalling should be done
86
- let unMarshalled = dbResp.Items.map((item) => {
87
- let i = AWS.DynamoDB.Converter.unmarshall(item);
88
- const { gsi1sk, gsi3pk,...otherProps } = i;
89
- const activitydate = gsi1sk;
90
- const ctid = gsi3pk;
91
- const ret = { activitydate, ctid, ...otherProps };
92
- console.log("um:", ret);
93
- return ret;
94
- });
95
- unMarshalled.request_data = AWS.DynamoDB.Converter.unmarshall(unMarshalled.request_data);
96
- console.log(unMarshalled);
97
- return unMarshalled;
98
- */
@@ -1,4 +1,5 @@
1
1
  import IKDBQuery from './IKDBQuery';
2
+ import { convertToAttr, marshall, unmarshall } from "@aws-sdk/util-dynamodb";
2
3
  //
3
4
  export default class IKDBQueryPut extends IKDBQuery {
4
5
  constructor() {
@@ -17,8 +18,8 @@ export default class IKDBQueryPut extends IKDBQuery {
17
18
  (source[key].length > 0))) {
18
19
  //Check for object conversion
19
20
  let val;
20
- if (isObject) val = {"M": AWS.DynamoDB.Converter.marshall(source[key])};
21
- else val = AWS.DynamoDB.Converter.input(source[key]);
21
+ if (isObject) val = {"M": marshall(source[key])};
22
+ else val = convertToAttr(source[key]);
22
23
  //valid
23
24
  if (val != undefined) { this.putItems[key]= val; }
24
25
  // console.debug("Apppending key:", key, " val:", val);
@@ -32,7 +33,7 @@ export default class IKDBQueryPut extends IKDBQuery {
32
33
  localConsole.log('Putting item: ', query);
33
34
  const resp = await dbManager.connection.putItem(query).promise();
34
35
  // localConsole.log('Raw result: ', resp);
35
- const unmarshalled = resp.Items.map(AWS.DynamoDB.Converter.unmarshall);
36
+ const unmarshalled = resp.Items.map(unmarshall);
36
37
  localConsole.log('Parsed result: ', unmarshalled);
37
38
  return unmarshalled;
38
39
  }
package/src/IKGlobals.js CHANGED
@@ -11,8 +11,6 @@ IKGlobals.ErrorResponseValidationFail = 'Input validation failed: '; //400
11
11
  IKGlobals.ErrorResponseInvalidServerResponse = 'No valid response, this is a system error.'; //400
12
12
  IKGlobals.ErrorResponseUnhandledError = 'Unhandled error when processing request.'; //400
13
13
  IKGlobals.ErrorResponseNoRecords = 'No events to be processed.'; //400
14
- //Validation engine
15
- IKGlobals.ValidationEngine_PhoneNumberLocalization = 'CA';
16
14
  //Development Configs
17
15
  IKGlobals.DynamoDBLocalConfig = {region: "localhost", endpoint: "http://localhost:8000", accessKeyId: 'DEFAULT_ACCESS_KEY', secretAccessKey: 'DEFAULT_SECRET'};
18
16
 
@@ -1,4 +1,3 @@
1
- import AWS from "aws-sdk";
2
1
  const abind = require('abind');
3
2
  const stackTrace = require('stack-trace');
4
3
  const stringify = require('json-stringify-safe');
@@ -1,7 +1,7 @@
1
1
  const nodemailer = require("nodemailer");
2
- const AWS = require('aws-sdk');
3
2
  const Email = require('email-templates');
4
3
  //
4
+ import { SESClient } from "@aws-sdk/client-ses";
5
5
  import Utils from "./../API/IKUtils";
6
6
  //
7
7
  export default class IKMailer {
@@ -11,10 +11,9 @@ export default class IKMailer {
11
11
  //setup local stuff
12
12
  let configObj = {region: region};
13
13
  if (Utils.isOffline()) configObj = {region: region, accessKeyId: process.env.AWS_ACCESS_KEY_ID, secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY};
14
- AWS.config.update(configObj);
15
14
  //
16
15
  this.transporter = nodemailer.createTransport({
17
- SES: new AWS.SES({ apiVersion: "2010-12-01" })
16
+ SES: new SESClient({ apiVersion: "2010-12-01", ...configObj })
18
17
  });
19
18
  }
20
19
 
@@ -1,4 +1,4 @@
1
- import AWS from "aws-sdk";
1
+ import { SNSClient } from "@aws-sdk/client-sns";
2
2
  import sha1 from 'sha1';
3
3
  //
4
4
  import Utils from "./../API/IKUtils";
@@ -37,8 +37,7 @@ export default class IKPublisher {
37
37
  //Configure when sending!
38
38
  let configObj = { region: this.region };
39
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' }));
40
+ PUBLISHER_CONN = (new SNSClient({ apiVersion: '2010-03-31', ...config }));
42
41
  PUBLISHER_CONN_HASH = sha1(this.region);
43
42
  }
44
43
  }
@@ -4,7 +4,6 @@ import IKResponse, { IKBadRequestResponse } from './../API/IKResponse';
4
4
  //https://www.npmjs.com/package/superstruct
5
5
  import { struct, superstruct } from 'superstruct';
6
6
  //validation libs
7
- import { parsePhoneNumberFromString } from 'libphonenumber-js'; //phone number validation and parse
8
7
  import isUuid from 'is-uuid';
9
8
  import isEmail from 'is-email';
10
9
  //
@@ -66,11 +65,6 @@ IKValidation.internalTypes = function() {
66
65
  for (let id of value) if (id.length < 10) return false;
67
66
  return true;
68
67
  },
69
- phoneNumber: value => {
70
- if (!value) return false;
71
- const v = parsePhoneNumberFromString(value, IKGlobals.ValidationEngine_PhoneNumberLocalization);
72
- return ((v && v.isValid()) == true);
73
- },
74
68
  //TODO: this should be moved out to the project requiring this
75
69
  ACEArray: value => {
76
70
  if (!value || !value.length) return false;