@ikonintegration/ikapi 2.6.10 → 3.0.0-alpha3
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 +8 -5
- package/src/API/IKRequest.js +0 -1
- package/src/API/IKUtils.js +5 -7
- package/src/Database/DDB/IKDB.js +12 -9
- package/src/Database/DDB/IKDBQueryPut.js +0 -16
- package/src/Database/DDB/_IKDBQueryTransactionalRead.js +4 -3
- package/src/IKGlobals.js +0 -2
- package/src/Logger/IKLogger.js +0 -1
- package/src/Mailer/IKMailer.js +2 -3
- package/src/Publisher/IKPublisher.js +2 -3
- package/src/Validation/IKValidation.js +0 -6
package/package.json
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ikonintegration/ikapi",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha3",
|
|
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
|
|
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",
|
package/src/API/IKRequest.js
CHANGED
package/src/API/IKUtils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
2
|
import KSUID from 'ksuid';
|
|
3
|
-
import {
|
|
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
|
-
|
|
36
|
-
|
|
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
|
-
|
|
45
|
-
return marshaller.unmarshallItem(item);
|
|
43
|
+
return unmarshall(item, { removeUndefinedValues: true });
|
|
46
44
|
} return item;
|
|
47
45
|
}
|
|
48
46
|
//Threads
|
package/src/Database/DDB/IKDB.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
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
|
//
|
|
6
6
|
import IKGlobals from './../../IKGlobals';
|
|
7
7
|
import IKDB from './../Prototype/IKDB';
|
|
8
|
+
//
|
|
9
|
+
const { Agent } = require("https");
|
|
8
10
|
//reusable connection
|
|
9
11
|
var DDB_CONN = null;
|
|
10
12
|
var DDB_CONN_HASH = null;
|
|
@@ -15,7 +17,7 @@ export default class IKDB_DDB extends IKDB {
|
|
|
15
17
|
this.tableName = config.tableName;
|
|
16
18
|
this.region = config.region;
|
|
17
19
|
//
|
|
18
|
-
const localConsole = (transaction ? transaction.logger : console);
|
|
20
|
+
// const localConsole = (transaction ? transaction.logger : console);
|
|
19
21
|
// if (config && this.tableName) { localConsole.debug(`Using table: ${this.tableName} on region: ${this.region}`); }
|
|
20
22
|
}
|
|
21
23
|
|
|
@@ -28,15 +30,16 @@ export default class IKDB_DDB extends IKDB {
|
|
|
28
30
|
//setup db
|
|
29
31
|
if (Utils.isOffline()) {
|
|
30
32
|
localConsole.debug("Starting offline database connection");
|
|
31
|
-
this.connection = new
|
|
33
|
+
this.connection = new DynamoDB(IKGlobals.DynamoDBLocalConfig);
|
|
32
34
|
} else {
|
|
33
35
|
// 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
36
|
//initialize connection
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
this.connection = new DynamoDB({
|
|
38
|
+
region: this.region,
|
|
39
|
+
requestHandler: new NodeHttpHandler({
|
|
40
|
+
httpsAgent: new Agent({ keepAlive: false, maxSockets: 50, rejectUnauthorized: true }),
|
|
41
|
+
})
|
|
42
|
+
});
|
|
40
43
|
//Reusable logic
|
|
41
44
|
DDB_CONN = this.connection;
|
|
42
45
|
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":
|
|
21
|
-
else val =
|
|
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(
|
|
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
|
|
package/src/Logger/IKLogger.js
CHANGED
package/src/Mailer/IKMailer.js
CHANGED
|
@@ -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
|
|
16
|
+
SES: new SESClient({ apiVersion: "2010-12-01", ...configObj })
|
|
18
17
|
});
|
|
19
18
|
}
|
|
20
19
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
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
|
-
|
|
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;
|