@ikonintegration/ikapi 2.6.0-beta1 → 2.6.2-alpha

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.6.0-beta1",
3
+ "version": "2.6.2-alpha",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "module": "main.js",
@@ -21,40 +21,38 @@ export default class IKResponse {
21
21
  getBody() { return this._body; }
22
22
  appendIntoBody(key, value) { this._body[key] = value; }
23
23
  appendHeader(key, value) { this._headers[key] = value; }
24
- build(context, requestID, isBatch, transaction) {
24
+ async build(context, transaction, isBatch) {
25
25
  //Stream support
26
26
  if (this._streamingOut) return;
27
- if (this._isStream) return this._pipe(context, requestID);
28
- //Raw response support
29
- if (this._contextRawBody) return this.rawContext(context, requestID, transaction);
27
+ if (this._isStream) return this._pipe(context);
30
28
 
31
29
  //append default fields
32
- if (requestID && this._body) this.appendIntoBody('transactionID', requestID); //append transaction ID
30
+ if (this.request.getRequestID() && this._body) this.appendIntoBody('transactionID', this.request.getRequestID()); //append transaction ID
31
+ //Raw response support
32
+ if (this._contextRawBody) return this.rawContext(context, transaction);
33
+
33
34
  //build response
34
35
  let b = {
35
- statusCode: this._statusCode,
36
+ statusCode: this._statusCode, headers: this._headers,
36
37
  ...(this._body ? { body: JSON.stringify(this._body) } : {}),
37
- headers: this._headers
38
38
  };
39
39
  //log response and respond to context
40
40
  transaction.logger.debug(b)
41
+ //Check for transaction response proxy
42
+ if (transaction.responseProxy) await transaction.responseProxy(b);
43
+ //Batch does not succeed directly just on upper transaction (which will should be a batch)
41
44
  if (!isBatch) context.succeed(b);
42
45
  }
43
- _pipe(context, requestID) {
46
+ _pipe(context) {
44
47
  //Check if not streaming
45
48
  if (this._streamingOut) return;
46
49
  this._streamingOut = true;
47
50
  //build response
48
- let b = {
49
- statusCode: this._statusCode,
50
- body: this._body, headers: this._headers
51
- };
51
+ let b = { statusCode: this._statusCode, body: this._body, headers: this._headers };
52
52
  //log response and respond to context
53
53
  context.succeed(b);
54
54
  }
55
- rawContext(context, requestID, transaction) {
56
- //append default fields
57
- if(requestID && this._body) this.appendIntoBody('transactionID', requestID); //append transaction ID
55
+ rawContext(context, transaction) {
58
56
  //log response and respond to context
59
57
  transaction.logger.debug(this._body)
60
58
  if (this.getCode() <= 200 && this.getCode() <= 299) context.succeed(this._body);
@@ -23,8 +23,10 @@ export default class IKTransaction {
23
23
  //queue support
24
24
  this._isBatch = _isBatch;
25
25
  this._resp = null;
26
- //
27
- this._retrowErrors = _retrowErrors;
26
+ //Step function support
27
+ this._retrowErrors = _retrowErrors; /* retrow internal errors */
28
+ //When set, this will be called with the response context right before calling the context suceed/fail
29
+ this.responseProxy = null;
28
30
  //
29
31
  this.logger = new IKLogger({/*COFIG S3/SQS HERE*/}, Utils.logLevel(), (context.awsRequestId ? context.awsRequestId : (event.requestContext ? event.requestContext.requestId : 'unknown')));
30
32
  this.request = new IKRequest(this._event, this._context, this);
@@ -52,11 +54,11 @@ export default class IKTransaction {
52
54
  this._resp = await executionFunc(this);
53
55
  //Answer client
54
56
  if (this._resp && this._resp instanceof IKResponse) {
55
- this._resp.build(this._context, this.request.getRequestID(), this._isBatch, this);
57
+ await this._resp.build(this._context, this, this._isBatch);
56
58
  executionFailed = !!(this._resp.getBody() && this._resp.getBody().rollback);
57
59
  } else {
58
60
  this._resp = this._getErrorResponse(IKGlobals.ErrorResponseInvalidServerResponse, IKGlobals.ErrorCode_APIError)
59
- this._resp.build(this._context, this.request.getRequestID(), this._isBatch, this);
61
+ await this._resp.build(this._context, this, this._isBatch);
60
62
  this.logger.error("Invalid response object from main request code.");
61
63
  }
62
64
  } catch (e) { /*EXECUTION FAIL*/
@@ -67,7 +69,7 @@ export default class IKTransaction {
67
69
  //envelope exception?
68
70
  if (executionFailed) {
69
71
  this._resp = this._getErrorResponse(IKGlobals.ErrorResponseUnhandledError, IKGlobals.ErrorCode_APIError);
70
- this._resp.build(this._context, this.request.getRequestID(), this._isBatch, this);
72
+ await this._resp.build(this._context, this, this._isBatch);
71
73
  }
72
74
  } return executionFailed;
73
75
  }
@@ -1,6 +1,7 @@
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';
@@ -27,7 +27,10 @@ export default class IKDBQueryUpdate extends IKDBBaseQuery {
27
27
  this.setValues[key] = val;
28
28
  console.debug(`Append ${key}@${val}`);
29
29
  return true;
30
- } return false;
30
+ }
31
+ //remove
32
+ this.removeValues.push(key);
33
+ return false;
31
34
  }
32
35
  //return if the value was appended or not
33
36
  incrementValue(val, key, prefix) {
@@ -1,4 +1,5 @@
1
1
  import AWS from "aws-sdk";
2
+ import sha1 from 'sha1';
2
3
  //
3
4
  import Utils from "./../API/IKUtils";
4
5
  //reusable client
@@ -32,7 +33,7 @@ export default class IKPublisher {
32
33
  }
33
34
  /* Private */
34
35
  _connect() {
35
- if ((!PUBLISHER_CONN && !PUBLISHER_CONN_HASH) || PUBLISHER_CONN_HASH != sha1(this.regiond)) {
36
+ if ((!PUBLISHER_CONN && !PUBLISHER_CONN_HASH) || PUBLISHER_CONN_HASH != sha1(this.region)) {
36
37
  //Configure when sending!
37
38
  let configObj = { region: this.region };
38
39
  if (Utils.isOffline()) configObj = { ...configObj, accessKeyId: process.env.AWS_ACCESS_KEY_ID, secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY };