creo-flow-extensions-base 1.0.0 → 1.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/lib/api/index.js +3 -2
- package/lib/config/dev/index.d.ts +3 -0
- package/lib/config/dev/index.js +6 -0
- package/lib/config/index.d.ts +3 -0
- package/lib/config/index.js +6 -0
- package/lib/config/prod/index.d.ts +3 -0
- package/lib/config/prod/index.js +6 -0
- package/lib/config/qa/index.d.ts +3 -0
- package/lib/config/qa/index.js +6 -0
- package/lib/context/index.d.ts +6 -5
- package/lib/context/index.js +43 -13
- package/lib/context/interfaces/index.d.ts +1 -0
- package/lib/context/utils/index.js +17 -7
- package/lib/createExtension/index.d.ts +1 -32
- package/lib/createExtension/index.js +49 -26
- package/lib/enum/index.d.ts +5 -0
- package/lib/enum/index.js +7 -1
- package/lib/error/ErrorLevels.d.ts +4 -0
- package/lib/error/ErrorLevels.js +8 -0
- package/lib/error/index.d.ts +5 -2
- package/lib/error/index.js +13 -5
- package/lib/error/interface.d.ts +6 -0
- package/lib/error/interface.js +2 -0
- package/lib/executionContext/index.d.ts +4 -0
- package/lib/executionContext/index.js +10 -0
- package/lib/interfaces/index.d.ts +30 -0
- package/lib/interfaces/index.js +2 -0
- package/lib/logger/index.js +6 -2
- package/lib/nodes/index.d.ts +8 -2
- package/package.json +2 -7
package/lib/api/index.js
CHANGED
|
@@ -5,10 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ownApi = void 0;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const
|
|
8
|
+
const config_1 = require("../config");
|
|
9
|
+
const baseApiUrl = config_1.config.baseApiUrl;
|
|
9
10
|
exports.ownApi = axios_1.default.create({
|
|
10
11
|
baseURL: baseApiUrl,
|
|
11
|
-
timeout: 60000 * 2,
|
|
12
|
+
timeout: 60000 * 2, // 120sec
|
|
12
13
|
maxContentLength: 200 * 1000 * 1024 * 1024, // 2 000 MB
|
|
13
14
|
});
|
|
14
15
|
const retryRequest = (error) => {
|
package/lib/context/index.d.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { IDeleteContextToRedis, IGetContextFromRedis, IGetContextFromS3, IWriteContext, IWriteContextToRedis, IWriteContextToS3 } from './interfaces';
|
|
2
|
-
|
|
2
|
+
import { NodeContext } from "../executionContext";
|
|
3
|
+
export declare class ContextService {
|
|
4
|
+
private context;
|
|
5
|
+
constructor(context: NodeContext);
|
|
3
6
|
getContext({ methodProps, token, urls }: {
|
|
4
7
|
methodProps: any;
|
|
5
8
|
token: string;
|
|
6
9
|
urls?: Record<string, string>;
|
|
7
|
-
}): Promise<Record<string, any
|
|
10
|
+
}): Promise<Record<string, any>>;
|
|
8
11
|
writeContext({ contextKey, data, token, url }: IWriteContext): Promise<void>;
|
|
9
12
|
private getContextByKeys;
|
|
10
13
|
private receiveContext;
|
|
11
14
|
getContextFromRedis({ contextKey, token }: IGetContextFromRedis): Promise<import("axios").AxiosResponse<any, any>>;
|
|
12
|
-
getContextFromS3({ url }: IGetContextFromS3): Promise<any>;
|
|
15
|
+
getContextFromS3({ url, contextKey }: IGetContextFromS3): Promise<any>;
|
|
13
16
|
sendContextToRedis({ contextKey, data, token }: IWriteContextToRedis): Promise<void>;
|
|
14
17
|
sendContextToS3({ data, url }: IWriteContextToS3): Promise<void>;
|
|
15
18
|
deleteContextFromRedis({ contextKey, token }: IDeleteContextToRedis): Promise<void>;
|
|
16
19
|
}
|
|
17
|
-
export declare const contextService: ContextService;
|
|
18
|
-
export {};
|
package/lib/context/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.ContextService = void 0;
|
|
7
7
|
const api_1 = require("../api");
|
|
8
8
|
const utils_1 = require("./utils");
|
|
9
9
|
const axios_1 = __importDefault(require("axios"));
|
|
@@ -11,8 +11,13 @@ const error_1 = require("../error");
|
|
|
11
11
|
const v8_1 = require("v8");
|
|
12
12
|
const zlib_1 = __importDefault(require("zlib"));
|
|
13
13
|
const logger_1 = require("../logger");
|
|
14
|
+
const ErrorLevels_1 = require("../error/ErrorLevels");
|
|
14
15
|
const redisSizeLimit = 1024 * 100; // 0.1mb
|
|
15
16
|
class ContextService {
|
|
17
|
+
context;
|
|
18
|
+
constructor(context) {
|
|
19
|
+
this.context = context;
|
|
20
|
+
}
|
|
16
21
|
async getContext({ methodProps, token, urls }) {
|
|
17
22
|
try {
|
|
18
23
|
const contextReadKeys = (0, utils_1.getContextKeys)(methodProps);
|
|
@@ -24,7 +29,7 @@ class ContextService {
|
|
|
24
29
|
contextReadKeys,
|
|
25
30
|
}
|
|
26
31
|
});
|
|
27
|
-
return;
|
|
32
|
+
return {};
|
|
28
33
|
}
|
|
29
34
|
logger_1.logger.info({
|
|
30
35
|
message: 'Get context',
|
|
@@ -43,15 +48,23 @@ class ContextService {
|
|
|
43
48
|
});
|
|
44
49
|
return context;
|
|
45
50
|
}
|
|
46
|
-
catch (
|
|
51
|
+
catch (error) {
|
|
47
52
|
logger_1.logger.error({
|
|
48
53
|
message: 'Error while getting context',
|
|
49
54
|
location: this.constructor.name,
|
|
50
55
|
payload: {
|
|
51
|
-
errorMessage:
|
|
56
|
+
errorMessage: error.message,
|
|
52
57
|
}
|
|
53
58
|
});
|
|
54
|
-
|
|
59
|
+
const isCaughtError = error instanceof error_1.ExecutionError;
|
|
60
|
+
if (isCaughtError) {
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
throw new error_1.ExecutionError({
|
|
64
|
+
errorLevel: ErrorLevels_1.ErrorLevels.BASE_LIB_LEVEL,
|
|
65
|
+
message: `Something went wrong while getting context`,
|
|
66
|
+
nodeName: this.context.nodeTitle
|
|
67
|
+
});
|
|
55
68
|
}
|
|
56
69
|
}
|
|
57
70
|
async writeContext({ contextKey, data, token, url }) {
|
|
@@ -94,7 +107,11 @@ class ContextService {
|
|
|
94
107
|
errorMessage: e.message,
|
|
95
108
|
}
|
|
96
109
|
});
|
|
97
|
-
throw new error_1.
|
|
110
|
+
throw new error_1.ExecutionError({
|
|
111
|
+
errorLevel: ErrorLevels_1.ErrorLevels.BASE_LIB_LEVEL,
|
|
112
|
+
message: `Error while writing context by key ${contextKey}`,
|
|
113
|
+
nodeName: this.context.nodeTitle
|
|
114
|
+
});
|
|
98
115
|
}
|
|
99
116
|
}
|
|
100
117
|
async getContextByKeys({ contextKeys, token, urls }) {
|
|
@@ -136,7 +153,7 @@ class ContextService {
|
|
|
136
153
|
contextKey,
|
|
137
154
|
}
|
|
138
155
|
});
|
|
139
|
-
const result = await this.getContextFromS3({ url });
|
|
156
|
+
const result = await this.getContextFromS3({ url, contextKey });
|
|
140
157
|
logger_1.logger.info({
|
|
141
158
|
message: 'Context by key from S3 received',
|
|
142
159
|
location: this.constructor.name,
|
|
@@ -146,7 +163,11 @@ class ContextService {
|
|
|
146
163
|
});
|
|
147
164
|
return result;
|
|
148
165
|
}
|
|
149
|
-
throw
|
|
166
|
+
throw new error_1.ExecutionError({
|
|
167
|
+
errorLevel: ErrorLevels_1.ErrorLevels.BASE_LIB_LEVEL,
|
|
168
|
+
message: `Error while getting context by key ${contextKey}`,
|
|
169
|
+
nodeName: this.context.nodeTitle
|
|
170
|
+
});
|
|
150
171
|
}
|
|
151
172
|
}
|
|
152
173
|
async getContextFromRedis({ contextKey, token }) {
|
|
@@ -156,10 +177,19 @@ class ContextService {
|
|
|
156
177
|
headers: { 'context-token': token }
|
|
157
178
|
});
|
|
158
179
|
}
|
|
159
|
-
async getContextFromS3({ url }) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
180
|
+
async getContextFromS3({ url, contextKey }) {
|
|
181
|
+
try {
|
|
182
|
+
const { data: response } = await axios_1.default.get(url, { responseType: 'arraybuffer' });
|
|
183
|
+
const uncompressed = zlib_1.default.unzipSync(response);
|
|
184
|
+
return (0, v8_1.deserialize)(uncompressed);
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
throw new error_1.ExecutionError({
|
|
188
|
+
errorLevel: ErrorLevels_1.ErrorLevels.BASE_LIB_LEVEL,
|
|
189
|
+
message: `Error while getting context by key ${contextKey}`,
|
|
190
|
+
nodeName: this.context.nodeTitle
|
|
191
|
+
});
|
|
192
|
+
}
|
|
163
193
|
}
|
|
164
194
|
async sendContextToRedis({ contextKey, data, token }) {
|
|
165
195
|
const { flowContextId, flowId } = (0, utils_1.parseToken)(token);
|
|
@@ -175,4 +205,4 @@ class ContextService {
|
|
|
175
205
|
await api_1.ownApi.delete(`flows/${flowId}/contexts/${flowContextId}/${contextKey}`, { headers: { 'context-token': token } });
|
|
176
206
|
}
|
|
177
207
|
}
|
|
178
|
-
exports.
|
|
208
|
+
exports.ContextService = ContextService;
|
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.checkIsJSON = exports.calculateBiteSize = exports.parseToken = exports.getContextKeys = void 0;
|
|
27
37
|
const jwt = __importStar(require("jsonwebtoken"));
|
|
@@ -1,36 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { INodeDescriptor } from '../nodes';
|
|
3
|
-
import { ExtensionTypes } from '../enum';
|
|
4
|
-
export interface ICreateExtensionParams {
|
|
5
|
-
nodes: INodeDescriptor[];
|
|
6
|
-
connections?: IConnectionSchema[];
|
|
7
|
-
title: string;
|
|
8
|
-
icon: string;
|
|
9
|
-
type: ExtensionTypes;
|
|
10
|
-
}
|
|
11
|
-
declare enum EventTypes {
|
|
12
|
-
EXECUTE = "execute",
|
|
13
|
-
GET_EXTENSION_INFO = "getExtensionInfo",
|
|
14
|
-
GET_FULL_NODE = "getFullNode"
|
|
15
|
-
}
|
|
16
|
-
interface IEvent {
|
|
17
|
-
method?: {
|
|
18
|
-
name: string;
|
|
19
|
-
uri: string;
|
|
20
|
-
databaseName: string;
|
|
21
|
-
collectionName: string;
|
|
22
|
-
query?: string;
|
|
23
|
-
};
|
|
24
|
-
writeContextUrl: string;
|
|
25
|
-
readContextUrls: {
|
|
26
|
-
[contextKey: string]: string;
|
|
27
|
-
};
|
|
28
|
-
type: EventTypes;
|
|
29
|
-
contextKey: string;
|
|
30
|
-
flowContextToken: string;
|
|
31
|
-
}
|
|
1
|
+
import { ICreateExtensionParams, IEvent } from "../interfaces";
|
|
32
2
|
export declare const createExtension: (extension: ICreateExtensionParams) => (event: IEvent) => Promise<{
|
|
33
3
|
statusCode: number;
|
|
34
4
|
body: string;
|
|
35
5
|
}>;
|
|
36
|
-
export {};
|
|
@@ -1,24 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createExtension = void 0;
|
|
4
|
-
const enum_1 = require("../
|
|
5
|
-
const
|
|
4
|
+
const enum_1 = require("../enum");
|
|
5
|
+
const enum_2 = require("../fields/enum");
|
|
6
6
|
const error_1 = require("../error");
|
|
7
7
|
const logger_1 = require("../logger");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
EventTypes["GET_EXTENSION_INFO"] = "getExtensionInfo";
|
|
12
|
-
EventTypes["GET_FULL_NODE"] = "getFullNode";
|
|
13
|
-
})(EventTypes || (EventTypes = {}));
|
|
8
|
+
const ErrorLevels_1 = require("../error/ErrorLevels");
|
|
9
|
+
const context_1 = require("../context");
|
|
10
|
+
const executionContext_1 = require("../executionContext");
|
|
14
11
|
// @TODO: add dependencies between fields for smart rendering. Now on each field change we need to get node info;
|
|
15
12
|
// Disable node select fields without options.
|
|
16
13
|
const createExtension = (extension) => async (event) => {
|
|
17
14
|
try {
|
|
18
15
|
const EventCallbacks = {
|
|
19
|
-
[EventTypes.EXECUTE]: execute,
|
|
20
|
-
[EventTypes.GET_EXTENSION_INFO]: getExtensionInfo,
|
|
21
|
-
[EventTypes.GET_FULL_NODE]: getFullNode,
|
|
16
|
+
[enum_1.EventTypes.EXECUTE]: (event) => execute(event, extension, { nodeTitle: event.nodeTitle }),
|
|
17
|
+
[enum_1.EventTypes.GET_EXTENSION_INFO]: getExtensionInfo,
|
|
18
|
+
[enum_1.EventTypes.GET_FULL_NODE]: getFullNode,
|
|
22
19
|
};
|
|
23
20
|
const eventCallback = EventCallbacks[event.type];
|
|
24
21
|
const result = await eventCallback(event, extension);
|
|
@@ -27,12 +24,14 @@ const createExtension = (extension) => async (event) => {
|
|
|
27
24
|
catch (e) {
|
|
28
25
|
return {
|
|
29
26
|
statusCode: 500,
|
|
30
|
-
body: JSON.stringify({ message: `An error occurred ${e.message}` })
|
|
27
|
+
body: JSON.stringify({ errorDetails: { message: `An error occurred ${e.message}` } })
|
|
31
28
|
};
|
|
32
29
|
}
|
|
33
30
|
};
|
|
34
31
|
exports.createExtension = createExtension;
|
|
35
|
-
const execute = async (event, extension) => {
|
|
32
|
+
const execute = async (event, extension, nodeInfo) => {
|
|
33
|
+
const nodeContext = new executionContext_1.NodeContext(nodeInfo.nodeTitle);
|
|
34
|
+
const contextService = new context_1.ContextService(nodeContext);
|
|
36
35
|
try {
|
|
37
36
|
const methodProps = event?.method;
|
|
38
37
|
const method = methodProps?.name ? extension.nodes.find(({ name }) => name === methodProps.name) : undefined;
|
|
@@ -46,21 +45,29 @@ const execute = async (event, extension) => {
|
|
|
46
45
|
}
|
|
47
46
|
});
|
|
48
47
|
if (!method) {
|
|
49
|
-
throw new
|
|
48
|
+
throw new error_1.ExecutionError({
|
|
49
|
+
message: 'Unknown extension method',
|
|
50
|
+
errorLevel: ErrorLevels_1.ErrorLevels.BASE_LIB_LEVEL,
|
|
51
|
+
nodeName: event.nodeTitle
|
|
52
|
+
});
|
|
50
53
|
}
|
|
51
54
|
;
|
|
52
55
|
const contextWriteKey = event?.contextKey;
|
|
53
56
|
if (!contextWriteKey) {
|
|
54
|
-
throw new
|
|
57
|
+
throw new error_1.ExecutionError({
|
|
58
|
+
message: 'Context key is not provided',
|
|
59
|
+
errorLevel: ErrorLevels_1.ErrorLevels.BASE_LIB_LEVEL,
|
|
60
|
+
nodeName: event.nodeTitle
|
|
61
|
+
});
|
|
55
62
|
}
|
|
56
63
|
const contextToken = event?.flowContextToken;
|
|
57
64
|
if (!contextToken) {
|
|
58
65
|
throw new Error('Context token is not provided');
|
|
59
66
|
}
|
|
60
|
-
const context = await
|
|
61
|
-
const response = await method.func(methodProps, context);
|
|
67
|
+
const context = await contextService.getContext({ methodProps, token: event.flowContextToken, urls: readContextUrls });
|
|
68
|
+
const response = await method.func({ args: methodProps, context, nodeContext });
|
|
62
69
|
if (writeContextUrl && event.flowContextToken) {
|
|
63
|
-
await
|
|
70
|
+
await contextService.writeContext({ contextKey: contextWriteKey, data: response, token: event.flowContextToken, url: writeContextUrl });
|
|
64
71
|
}
|
|
65
72
|
logger_1.logger.info({
|
|
66
73
|
message: `Extension successfully executed, extension: ${extension.title}`,
|
|
@@ -82,14 +89,20 @@ const execute = async (event, extension) => {
|
|
|
82
89
|
}
|
|
83
90
|
});
|
|
84
91
|
// TODO: Use for better error handling.
|
|
85
|
-
const isCaughtError = error instanceof error_1.
|
|
92
|
+
const isCaughtError = error instanceof error_1.ExecutionError;
|
|
86
93
|
const statusCode = isCaughtError ? 400 : 500;
|
|
87
|
-
const
|
|
94
|
+
const errorDetails = isCaughtError
|
|
95
|
+
? error.getErrorDetails()
|
|
96
|
+
: {
|
|
97
|
+
message: `An execution error occurred`,
|
|
98
|
+
errorLevel: ErrorLevels_1.ErrorLevels.BASE_LIB_LEVEL,
|
|
99
|
+
nodeName: event.nodeTitle
|
|
100
|
+
};
|
|
88
101
|
const logs = [...logger_1.logger.getLogs()];
|
|
89
102
|
logger_1.logger.clearLogs();
|
|
90
103
|
return {
|
|
91
104
|
statusCode,
|
|
92
|
-
body: JSON.stringify({
|
|
105
|
+
body: JSON.stringify({ errorDetails, logs }),
|
|
93
106
|
};
|
|
94
107
|
}
|
|
95
108
|
};
|
|
@@ -104,10 +117,14 @@ const getFullNode = async (event, extension) => {
|
|
|
104
117
|
const methodProps = event?.method;
|
|
105
118
|
const method = methodProps?.name ? extension.nodes.find(({ name }) => name === methodProps.name) : undefined;
|
|
106
119
|
if (!method) {
|
|
107
|
-
throw new error_1.
|
|
120
|
+
throw new error_1.ExecutionError({
|
|
121
|
+
message: 'Unknown extension method',
|
|
122
|
+
errorLevel: ErrorLevels_1.ErrorLevels.BASE_LIB_LEVEL,
|
|
123
|
+
nodeName: event.nodeTitle
|
|
124
|
+
});
|
|
108
125
|
}
|
|
109
126
|
const fullFields = await Promise.all(method.fields.map(async (field) => {
|
|
110
|
-
const isSelect = field.type ===
|
|
127
|
+
const isSelect = field.type === enum_2.FieldTypes.SELECT;
|
|
111
128
|
if (!isSelect)
|
|
112
129
|
return field;
|
|
113
130
|
const options = field?.getOptions ? await field.getOptions(methodProps) : [];
|
|
@@ -119,12 +136,18 @@ const getFullNode = async (event, extension) => {
|
|
|
119
136
|
};
|
|
120
137
|
}
|
|
121
138
|
catch (error) {
|
|
122
|
-
const isCaughtError = error instanceof error_1.
|
|
139
|
+
const isCaughtError = error instanceof error_1.ExecutionError;
|
|
123
140
|
const statusCode = isCaughtError ? 400 : 500;
|
|
124
|
-
const
|
|
141
|
+
const errorDetails = isCaughtError
|
|
142
|
+
? error.getErrorDetails()
|
|
143
|
+
: {
|
|
144
|
+
message: 'An receiving node info error occurred',
|
|
145
|
+
errorLevel: ErrorLevels_1.ErrorLevels.BASE_LIB_LEVEL,
|
|
146
|
+
nodeName: event.nodeTitle
|
|
147
|
+
};
|
|
125
148
|
return {
|
|
126
149
|
statusCode,
|
|
127
|
-
body: JSON.stringify({
|
|
150
|
+
body: JSON.stringify({ errorDetails }),
|
|
128
151
|
};
|
|
129
152
|
}
|
|
130
153
|
};
|
package/lib/enum/index.d.ts
CHANGED
package/lib/enum/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ExtensionTypes = void 0;
|
|
3
|
+
exports.EventTypes = exports.ExtensionTypes = void 0;
|
|
4
4
|
var ExtensionTypes;
|
|
5
5
|
(function (ExtensionTypes) {
|
|
6
6
|
ExtensionTypes["DB_CONNECTION"] = "db_connection";
|
|
@@ -9,3 +9,9 @@ var ExtensionTypes;
|
|
|
9
9
|
ExtensionTypes["PARALLEL"] = "parallel";
|
|
10
10
|
ExtensionTypes["CODE"] = "code";
|
|
11
11
|
})(ExtensionTypes || (exports.ExtensionTypes = ExtensionTypes = {}));
|
|
12
|
+
var EventTypes;
|
|
13
|
+
(function (EventTypes) {
|
|
14
|
+
EventTypes["EXECUTE"] = "execute";
|
|
15
|
+
EventTypes["GET_EXTENSION_INFO"] = "getExtensionInfo";
|
|
16
|
+
EventTypes["GET_FULL_NODE"] = "getFullNode";
|
|
17
|
+
})(EventTypes || (exports.EventTypes = EventTypes = {}));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ErrorLevels = void 0;
|
|
4
|
+
var ErrorLevels;
|
|
5
|
+
(function (ErrorLevels) {
|
|
6
|
+
ErrorLevels["BASE_LIB_LEVEL"] = "baseLibLevel";
|
|
7
|
+
ErrorLevels["EXTENSION_LEVEL"] = "extensionLevel";
|
|
8
|
+
})(ErrorLevels || (exports.ErrorLevels = ErrorLevels = {}));
|
package/lib/error/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { IExecutionError } from "./interface";
|
|
2
|
+
export declare class ExecutionError extends Error {
|
|
3
|
+
errorInfo: IExecutionError;
|
|
4
|
+
constructor(props: IExecutionError);
|
|
5
|
+
getErrorDetails(): IExecutionError;
|
|
3
6
|
}
|
package/lib/error/index.js
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
class
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
exports.ExecutionError = void 0;
|
|
4
|
+
class ExecutionError extends Error {
|
|
5
|
+
errorInfo;
|
|
6
|
+
constructor(props) {
|
|
7
|
+
super(props.message);
|
|
7
8
|
this.name = this.constructor.name;
|
|
9
|
+
this.errorInfo = props;
|
|
10
|
+
if (Error.captureStackTrace) {
|
|
11
|
+
Error.captureStackTrace(this, this.constructor);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
getErrorDetails() {
|
|
15
|
+
return this.errorInfo;
|
|
8
16
|
}
|
|
9
17
|
}
|
|
10
|
-
exports.
|
|
18
|
+
exports.ExecutionError = ExecutionError;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { INodeDescriptor } from "../nodes";
|
|
2
|
+
import { IConnectionSchema } from "../connection";
|
|
3
|
+
import { EventTypes, ExtensionTypes } from "../enum";
|
|
4
|
+
export interface INodeInfo {
|
|
5
|
+
nodeTitle: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ICreateExtensionParams {
|
|
8
|
+
nodes: INodeDescriptor[];
|
|
9
|
+
connections?: IConnectionSchema[];
|
|
10
|
+
title: string;
|
|
11
|
+
icon: string;
|
|
12
|
+
type: ExtensionTypes;
|
|
13
|
+
}
|
|
14
|
+
export interface IEvent {
|
|
15
|
+
method?: {
|
|
16
|
+
name: string;
|
|
17
|
+
uri: string;
|
|
18
|
+
databaseName: string;
|
|
19
|
+
collectionName: string;
|
|
20
|
+
query?: string;
|
|
21
|
+
};
|
|
22
|
+
writeContextUrl: string;
|
|
23
|
+
readContextUrls: {
|
|
24
|
+
[contextKey: string]: string;
|
|
25
|
+
};
|
|
26
|
+
type: EventTypes;
|
|
27
|
+
contextKey: string;
|
|
28
|
+
flowContextToken: string;
|
|
29
|
+
nodeTitle: string;
|
|
30
|
+
}
|
package/lib/logger/index.js
CHANGED
|
@@ -13,10 +13,14 @@ class Logger {
|
|
|
13
13
|
this.logs = [];
|
|
14
14
|
}
|
|
15
15
|
info({ location, message, payload }) {
|
|
16
|
-
|
|
16
|
+
const logData = { level: LogLevels.INFO, location, message, payload, timestamp: this.getCurrentTimestamp() };
|
|
17
|
+
console.log(logData);
|
|
18
|
+
this.logs.push(logData);
|
|
17
19
|
}
|
|
18
20
|
error({ location, message, payload }) {
|
|
19
|
-
|
|
21
|
+
const logData = { level: LogLevels.ERROR, location, message, payload, timestamp: this.getCurrentTimestamp() };
|
|
22
|
+
console.error(logData);
|
|
23
|
+
this.logs.push(logData);
|
|
20
24
|
}
|
|
21
25
|
getLogs() {
|
|
22
26
|
return this.logs;
|
package/lib/nodes/index.d.ts
CHANGED
|
@@ -2,18 +2,24 @@ import { ICheckboxField } from '../fields/checkbox';
|
|
|
2
2
|
import { IInputField } from '../fields/input';
|
|
3
3
|
import { ISelectField } from '../fields/select';
|
|
4
4
|
import { ICodeField } from '../fields/code';
|
|
5
|
+
import { NodeContext } from "../executionContext";
|
|
5
6
|
type Field = IInputField | ISelectField | ICheckboxField | ICodeField;
|
|
7
|
+
export interface IFuncProps {
|
|
8
|
+
args: any;
|
|
9
|
+
context: object;
|
|
10
|
+
nodeContext: NodeContext;
|
|
11
|
+
}
|
|
6
12
|
export interface INodeDescriptor {
|
|
7
13
|
name: string;
|
|
8
14
|
title: string;
|
|
9
15
|
fields: Field[];
|
|
10
|
-
func: (args
|
|
16
|
+
func: ({ args, context, nodeContext }: IFuncProps) => any;
|
|
11
17
|
}
|
|
12
18
|
interface IProps {
|
|
13
19
|
name: string;
|
|
14
20
|
title: string;
|
|
15
21
|
fields: Field[];
|
|
16
|
-
func: (args
|
|
22
|
+
func: ({ args, context, nodeContext }: IFuncProps) => any;
|
|
17
23
|
}
|
|
18
24
|
export declare const createNodeDescriptor: (params: IProps) => INodeDescriptor;
|
|
19
25
|
export {};
|
package/package.json
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "creo-flow-extensions-base",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": "git@github.com:CloudDataHub/cdh-flow-extension-base.git",
|
|
6
6
|
"author": "Ilia Kobaliia",
|
|
7
7
|
"license": "ISC",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"clean": "rm -rf ./lib",
|
|
10
|
-
"build": "npm run clean && tsc"
|
|
11
|
-
"publishPackage": "npm run build && npm publish",
|
|
12
|
-
"publishPackageDev": "npm run build && npm publish --tag dev",
|
|
13
|
-
"publishPackageQa": "npm run build && npm publish --tag qa"
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
"build": "npm run clean && tsc"
|
|
16
11
|
},
|
|
17
12
|
"devDependencies": {
|
|
18
13
|
"@types/jsonwebtoken": "^9.0.5",
|