@ikonintegration/ikapi 4.0.0-alpha9 → 4.0.1

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": "4.0.0-alpha9",
3
+ "version": "4.0.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "module": "main.js",
@@ -28,10 +28,10 @@
28
28
  "json-stringify-safe": "^5.0.1",
29
29
  "ksuid": "^3.0.0",
30
30
  "nodemailer": "^6.9.3",
31
- "path-to-regexp": "^6.2.0",
31
+ "path-to-regexp": "^6.3.0",
32
32
  "pg": "^8.11.1",
33
33
  "sha1": "^1.1.1",
34
34
  "stack-trace": "0.0.10",
35
- "superstruct": "0.8.4"
35
+ "superstruct": "1.0.3"
36
36
  }
37
37
  }
@@ -1,5 +1,5 @@
1
- import IKDBBaseQuery from './IKDBBaseQuery.js';
2
1
  import Utils from './../../API/IKUtils.js';
2
+ import IKDBBaseQuery from './IKDBBaseQuery.js';
3
3
  //
4
4
  export default class IKDBQueryScan extends IKDBBaseQuery {
5
5
  constructor(optIndexName) {
@@ -12,7 +12,7 @@ export default class IKDBQueryScan extends IKDBBaseQuery {
12
12
  const resp = await this.rawRun(dbManager, appendingItems);
13
13
  if (resp.Items) {
14
14
  let unmarshalled = Utils.decapsulateForDB(resp.Items);
15
- localConsole.debug('Parsed result: ', unmarshalled);
15
+ localConsole.debug('Parsed result: ', JSON.stringify(unmarshalled).substring(0,4000));
16
16
  //Check for appending items from previous query
17
17
  if (appendingItems && appendingItems.length > 0) {
18
18
  unmarshalled = unmarshalled.concat(appendingItems);
@@ -154,16 +154,18 @@ export default class IKDBQueryUpdate extends IKDBBaseQuery {
154
154
  if (!expression.ExpressionAttributeNames) expression.ExpressionAttributeNames = {};
155
155
  //build update expression
156
156
  for (let dbKey of Object.keys(this.incrementValues)) {
157
+ let initialKey = ':initial';
157
158
  let appendingKey = (':' + dbKey);
158
159
  let appendingValueKey = ('#' + dbKey);
159
160
  let val = this.incrementValues[dbKey];
160
161
  if (val != undefined) {
161
162
  let last = Object.keys(this.incrementValues).indexOf(dbKey) == (Object.keys(this.incrementValues).length - 1);
162
163
  //last
163
- if (last) expression.UpdateExpression += appendingValueKey + ' =' + appendingValueKey + '+' + appendingKey;
164
- else expression.UpdateExpression += appendingValueKey + ' =' + appendingValueKey + '+' + appendingKey + ', ';
164
+ if (last) expression.UpdateExpression += appendingValueKey + ` = if_not_exists(${appendingValueKey}, :initial) + ${appendingKey}`;
165
+ else expression.UpdateExpression += appendingValueKey + ` = if_not_exists(${appendingValueKey}, :initial) + ${appendingKey}` + ', ';
165
166
  //
166
167
  expression.ExpressionAttributeValues[appendingKey] = Utils.encapsulateForDB(val);
168
+ expression.ExpressionAttributeValues[initialKey] = Utils.encapsulateForDB(0);
167
169
  expression.ExpressionAttributeNames[appendingValueKey] = dbKey;
168
170
  }
169
171
  }
@@ -1,6 +1,6 @@
1
1
  import nodemailer from "nodemailer";
2
2
  import Email from 'email-templates';
3
- import { SES } from "@aws-sdk/client-ses";
3
+ import AWSSES from "@aws-sdk/client-ses";
4
4
  //
5
5
  import { defaultProvider } from '@aws-sdk/credential-provider-node';
6
6
  import Utils from "./../API/IKUtils.js";
@@ -15,18 +15,19 @@ export default class IKMailer {
15
15
  //
16
16
  this.transporter = nodemailer.createTransport({
17
17
  SES: {
18
- ses: new SES.SESClient({ apiVersion: "2010-12-01", ...configObj, defaultProvider }),
19
- aws: SES
18
+ ses: new AWSSES.SESClient({ apiVersion: "2010-12-01", ...configObj, defaultProvider }),
19
+ aws: AWSSES
20
20
  }
21
21
  });
22
22
  }
23
23
 
24
- //to can be an array or just one address
25
- async sendTemplatedEmail(_to, _templates, _data, _optionalCC, _optionalAttachments) {
24
+ //to and cc can be an array, just one address or a comma separated string containing multiple addresses
25
+ async sendTemplatedEmail(_to, _templates, _data, _optionalCC, _optionalAttachments, _optionalHeaders, _optionalFrom) {
26
26
  //Generate emails
27
27
  const email = new Email({
28
28
  message: {
29
- from: this.from,
29
+ ...(_optionalHeaders ? {headers: _optionalHeaders} : {}),
30
+ from: _optionalFrom ? _optionalFrom : this.from,
30
31
  to: _to,
31
32
  ...(_optionalAttachments ? {attachments: _optionalAttachments} : {}),
32
33
  ...(_optionalCC ? {cc: _optionalCC} : {})
@@ -2,29 +2,31 @@ import IKGlobals from './../IKGlobals.js';
2
2
  import Utils from './../API/IKUtils.js';
3
3
  import IKResponse, { IKBadRequestResponse } from './../API/IKResponse.js';
4
4
  //https://www.npmjs.com/package/superstruct
5
- import { struct, superstruct } from 'superstruct';
5
+ import * as struct from 'superstruct';
6
6
  //validation libs
7
7
  import isUuid from 'is-uuid';
8
8
  import isEmail from 'is-email';
9
9
  //
10
10
  export default class IKValidation {
11
11
  constructor(config) {
12
+ this.customStruct = {};
12
13
  this._buildInternalTypes((config && config.additionalTypes ? config.additionalTypes : {}));
13
14
  }
14
15
  _buildInternalTypes(additionalTypes) {
15
- this.structor = superstruct({
16
- types: {
17
- ...IKValidation.internalTypes(),
18
- ...additionalTypes
19
- }
20
- });
16
+ for (const key in IKValidation.internalTypes()) {
17
+ this.customStruct[key] = struct.define(key, IKValidation.internalTypes()[key]);
18
+ }
19
+ for (const key in additionalTypes) {
20
+ this.customStruct[key] = struct.define(key, additionalTypes[key]);
21
+ }
21
22
  }
22
23
  async validate(spec, obj, request) {
23
- let parsedObj = null;
24
+ let assertion = null;
24
25
  let err = null;
25
26
  try {
26
27
  let parsedRawObj = obj;
27
- parsedObj = this.structor(spec)(parsedRawObj);
28
+ if (typeof spec == 'function') spec = spec(this)
29
+ assertion = struct.assert(parsedRawObj, spec);
28
30
  } catch (e) {
29
31
  console.debug(e);
30
32
  const { path, value, type } = e;
@@ -38,17 +40,14 @@ export default class IKValidation {
38
40
  err = IKBadRequestResponse(IKGlobals.ErrorResponseValidationFail + errorMessage, IKGlobals.ErrorCode_InvalidInput);
39
41
  }
40
42
  //Catch error as response
41
- if (!parsedObj && err) return err;
43
+ if (err) return err;
42
44
  //run normal code out of this try/catch scope
43
- return await request(parsedObj);
45
+ return await request(obj);
44
46
  }
45
47
  }
46
48
  //
47
49
  IKValidation.internalTypes = function() {
48
50
  return {
49
- optionalNumber: value => (value == undefined || !isNaN(parseInt(value))),
50
- optionalValidString: value => { return (!value || Utils.isValidString(value) == true); },
51
- validString: value => { return (Utils.isValidString(value) == true); },
52
51
  email: value => { return (isEmail(value) && value.length < 256); },
53
52
  fullAddress: value => {
54
53
  if (!value) return false;