@ikonintegration/ikapi 4.0.0-alpha → 4.0.0-alpha11
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/README.md +2 -1
- package/index.js +77 -50
- package/package.json +2 -2
- package/src/BaseEvent/IKTransaction.js +1 -1
- package/src/Cache/Redis/IKRedis.js +10 -7
- package/src/Validation/IKValidation.js +12 -11
package/README.md
CHANGED
|
@@ -14,9 +14,10 @@ Ikon nodejs API foundation
|
|
|
14
14
|
- Router
|
|
15
15
|
|
|
16
16
|
````
|
|
17
|
+
import * as Config from './routes/tenant/config.js';
|
|
17
18
|
|
|
18
19
|
const routes = [
|
|
19
|
-
{ route: '/tenant/config', method: 'GET', handler:
|
|
20
|
+
{ route: '/tenant/config', method: 'GET', handler: Config.get },
|
|
20
21
|
];
|
|
21
22
|
//Main handler
|
|
22
23
|
export const handler = async (event, context) => {
|
package/index.js
CHANGED
|
@@ -1,61 +1,88 @@
|
|
|
1
1
|
//Set defaults
|
|
2
|
-
|
|
2
|
+
import Bluebird from "bluebird";
|
|
3
|
+
global.Promise = Bluebird;
|
|
4
|
+
//Base Events
|
|
5
|
+
import IKTransaction from "./src/BaseEvent/IKTransaction.js";
|
|
6
|
+
import IKProcess from "./src/BaseEvent/IKProcess.js";
|
|
7
|
+
//Extra Events
|
|
8
|
+
import IKRouter from "./src/IKRouter.js";
|
|
9
|
+
import IKEventProcessor from "./src/IKEventProcessor.js";
|
|
10
|
+
import IKDynamoStream from "./src/IKDynamoStream.js";
|
|
11
|
+
import IKStepTransaction from "./src/IKStepTransaction.js";
|
|
12
|
+
//Extra components
|
|
13
|
+
import IKMailer from "./src/Mailer/IKMailer.js";
|
|
14
|
+
import IKValidation from "./src/Validation/IKValidation.js";
|
|
15
|
+
//Responses
|
|
16
|
+
import * as IKResponse from "./src/API/IKResponse.js";
|
|
17
|
+
//Helpers
|
|
18
|
+
import Utils from "./src/API/IKUtils.js";
|
|
19
|
+
//Cache
|
|
20
|
+
//Redis
|
|
21
|
+
import IKRedis from "./src/Cache/Redis/IKRedis.js";
|
|
22
|
+
//Database
|
|
23
|
+
//PSQL
|
|
24
|
+
import IKDBPSQLQuery from "./src/Database/PSQL/IKDBBaseQuery.js";
|
|
25
|
+
//DDB
|
|
26
|
+
import IKDBQueryScan from "./src/Database/DDB/IKDBQueryScan.js";
|
|
27
|
+
import IKDBQueryGet from "./src/Database/DDB/IKDBQueryGet.js";
|
|
28
|
+
import IKDBQueryPut from "./src/Database/DDB/IKDBQueryPut.js";
|
|
29
|
+
import IKDBQueryUpdate from "./src/Database/DDB/IKDBQueryUpdate.js";
|
|
30
|
+
import IKDBQueryDelete from "./src/Database/DDB/IKDBQueryDelete.js";
|
|
31
|
+
import IKDBQueryBatchWrite from "./src/Database/DDB/IKDBQueryBatchWrite.js";
|
|
32
|
+
import IKDBQueryBatchGet from "./src/Database/DDB/IKDBQueryBatchGet.js";
|
|
33
|
+
import IKDBQueryTransactionalWrite from "./src/Database/DDB/IKDBQueryTransactionalWrite.js";
|
|
34
|
+
import { IKDBExpressionOperator } from "./src/Database/DDB/IKDBBaseExpression.js";
|
|
3
35
|
//
|
|
4
36
|
export default {
|
|
5
37
|
//Base Events
|
|
6
|
-
IKTransaction
|
|
7
|
-
IKProcess
|
|
38
|
+
IKTransaction,
|
|
39
|
+
IKProcess,
|
|
8
40
|
//Extra Events
|
|
9
|
-
IKRouter
|
|
10
|
-
IKEventProcessor
|
|
11
|
-
IKDynamoStream
|
|
12
|
-
IKStepTransaction
|
|
13
|
-
|
|
41
|
+
IKRouter,
|
|
42
|
+
IKEventProcessor,
|
|
43
|
+
IKDynamoStream,
|
|
44
|
+
IKStepTransaction,
|
|
14
45
|
//Extra components
|
|
15
|
-
IKMailer
|
|
16
|
-
IKValidation
|
|
17
|
-
|
|
46
|
+
IKMailer,
|
|
47
|
+
IKValidation,
|
|
18
48
|
//Responses
|
|
19
|
-
IKResponse:
|
|
20
|
-
IKBadRequestResponse:
|
|
21
|
-
IKUnauthorizedResponse:
|
|
22
|
-
IKMissingParamResponse:
|
|
23
|
-
IKMissingQueryResponse:
|
|
24
|
-
IKSuccessResponse:
|
|
25
|
-
IKSuccessStreamResponse:
|
|
26
|
-
IKSuccessNoContentResponse:
|
|
27
|
-
IKBadRequestResponseWithRollback:
|
|
28
|
-
IKStepFunctionResponse:
|
|
29
|
-
IKSimpleResponse:
|
|
30
|
-
|
|
49
|
+
IKResponse: IKResponse.default,
|
|
50
|
+
IKBadRequestResponse: IKResponse.IKBadRequestResponse,
|
|
51
|
+
IKUnauthorizedResponse: IKResponse.IKUnauthorizedResponse,
|
|
52
|
+
IKMissingParamResponse: IKResponse.IKMissingParamResponse,
|
|
53
|
+
IKMissingQueryResponse: IKResponse.IKMissingQueryResponse,
|
|
54
|
+
IKSuccessResponse: IKResponse.IKSuccessResponse,
|
|
55
|
+
IKSuccessStreamResponse: IKResponse.IKSuccessStreamResponse,
|
|
56
|
+
IKSuccessNoContentResponse: IKResponse.IKSuccessNoContentResponse,
|
|
57
|
+
IKBadRequestResponseWithRollback: IKResponse.IKBadRequestResponseWithRollback,
|
|
58
|
+
IKStepFunctionResponse: IKResponse.IKStepFunctionResponse,
|
|
59
|
+
IKSimpleResponse: IKResponse.IKSimpleResponse,
|
|
31
60
|
//Helpers
|
|
32
|
-
Utils
|
|
33
|
-
|
|
61
|
+
Utils,
|
|
34
62
|
//Cache
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
63
|
+
//Redis
|
|
64
|
+
IKRedis,
|
|
38
65
|
//Database
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
66
|
+
//PSQL
|
|
67
|
+
IKDBPSQLQuery,
|
|
68
|
+
//DDB
|
|
69
|
+
IKDBDDBQueryScan: IKDBQueryScan,
|
|
70
|
+
IKDBDDBQueryGet: IKDBQueryGet,
|
|
71
|
+
IKDBDDBQueryPut: IKDBQueryPut,
|
|
72
|
+
IKDBDDBQueryUpdate: IKDBQueryUpdate,
|
|
73
|
+
IKDBDDBQueryDelete: IKDBQueryDelete,
|
|
74
|
+
IKDBDDBQueryBatchWrite: IKDBQueryBatchWrite,
|
|
75
|
+
IKDBDDBQueryBatchGet: IKDBQueryBatchGet,
|
|
76
|
+
IKDBDDBQueryTransactionalWrite: IKDBQueryTransactionalWrite,
|
|
77
|
+
IKDBDDBExpressionOperator: IKDBExpressionOperator,
|
|
78
|
+
//Legacy
|
|
79
|
+
IKDBQueryScan,
|
|
80
|
+
IKDBQueryGet,
|
|
81
|
+
IKDBQueryPut,
|
|
82
|
+
IKDBQueryUpdate,
|
|
83
|
+
IKDBQueryDelete,
|
|
84
|
+
IKDBQueryBatchWrite,
|
|
85
|
+
IKDBQueryBatchGet,
|
|
86
|
+
IKDBQueryTransactionalWrite,
|
|
87
|
+
IKDBExpressionOperator,
|
|
61
88
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ikonintegration/ikapi",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-alpha11",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "main.js",
|
|
@@ -32,6 +32,6 @@
|
|
|
32
32
|
"pg": "^8.11.1",
|
|
33
33
|
"sha1": "^1.1.1",
|
|
34
34
|
"stack-trace": "0.0.10",
|
|
35
|
-
"superstruct": "0.
|
|
35
|
+
"superstruct": "1.0.3"
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -99,7 +99,7 @@ export default class IKTransaction {
|
|
|
99
99
|
if (this.db) await this.db.cleanup();
|
|
100
100
|
} catch (e) {
|
|
101
101
|
this.logger.error('Exception when executing DB transactions.');
|
|
102
|
-
this.logger.log(e);
|
|
102
|
+
this.logger.log(e.stack);
|
|
103
103
|
//retrow?
|
|
104
104
|
if (this._retrowErrors) throw e;
|
|
105
105
|
}
|
|
@@ -73,15 +73,18 @@ export default class IKCache_Redis extends IKCache {
|
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
/* Private */
|
|
76
|
-
_isRedisClientAvailable() {
|
|
76
|
+
async _isRedisClientAvailable() {
|
|
77
77
|
let response = true;
|
|
78
|
-
try { const test =
|
|
78
|
+
try { const test = await import('redis'); }
|
|
79
79
|
catch (e) { response = false; }
|
|
80
80
|
return response;
|
|
81
81
|
}
|
|
82
|
-
_isRedisClientV4() {
|
|
82
|
+
async _isRedisClientV4() {
|
|
83
83
|
let isV4 = false;
|
|
84
|
-
try {
|
|
84
|
+
try {
|
|
85
|
+
const test = await import('redis');
|
|
86
|
+
isV4 = !!test.createCluster;
|
|
87
|
+
}
|
|
85
88
|
catch (e) { }
|
|
86
89
|
return isV4;
|
|
87
90
|
}
|
|
@@ -93,7 +96,7 @@ export default class IKCache_Redis extends IKCache {
|
|
|
93
96
|
} else if (this.connection) return this.connection; //already connected
|
|
94
97
|
|
|
95
98
|
//Check if redis client is available
|
|
96
|
-
if (!this._isRedisClientAvailable()) throw new Error('Redis client is not available! Please, run "npm i -S redis".');
|
|
99
|
+
if (!(await this._isRedisClientAvailable())) throw new Error('Redis client is not available! Please, run "npm i -S redis".');
|
|
97
100
|
|
|
98
101
|
//Prepare
|
|
99
102
|
const localConsole = (this.transaction ? this.transaction.logger : console);
|
|
@@ -102,8 +105,8 @@ export default class IKCache_Redis extends IKCache {
|
|
|
102
105
|
|
|
103
106
|
//Instantiate client and initiate connection
|
|
104
107
|
return new Promise(async (resolve, reject) => {
|
|
105
|
-
const redis =
|
|
106
|
-
const isV4 = this._isRedisClientV4();
|
|
108
|
+
const redis = await import("redis");
|
|
109
|
+
const isV4 = await this._isRedisClientV4();
|
|
107
110
|
//
|
|
108
111
|
const connection = redis.createClient({
|
|
109
112
|
...(isV4 ? {
|
|
@@ -2,29 +2,30 @@ 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
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
|
24
|
+
let assertion = null;
|
|
24
25
|
let err = null;
|
|
25
26
|
try {
|
|
26
27
|
let parsedRawObj = obj;
|
|
27
|
-
|
|
28
|
+
assertion = struct.assert(parsedRawObj, spec);
|
|
28
29
|
} catch (e) {
|
|
29
30
|
console.debug(e);
|
|
30
31
|
const { path, value, type } = e;
|
|
@@ -38,9 +39,9 @@ export default class IKValidation {
|
|
|
38
39
|
err = IKBadRequestResponse(IKGlobals.ErrorResponseValidationFail + errorMessage, IKGlobals.ErrorCode_InvalidInput);
|
|
39
40
|
}
|
|
40
41
|
//Catch error as response
|
|
41
|
-
if (
|
|
42
|
+
if (err) return err;
|
|
42
43
|
//run normal code out of this try/catch scope
|
|
43
|
-
return await request(
|
|
44
|
+
return await request(obj);
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
47
|
//
|