@transai/connector-runtime-sdk 0.1.0
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/.eslintrc.json +30 -0
- package/CHANGELOG.md +25 -0
- package/README.md +11 -0
- package/jest.config.ts +10 -0
- package/package.json +16 -0
- package/project.json +37 -0
- package/src/index.ts +3 -0
- package/src/lib/connector-runtime.interface.ts +7 -0
- package/src/lib/connector-runtime.spec.ts +115 -0
- package/src/lib/connector-runtime.ts +119 -0
- package/src/lib/sdk/files.sdk.interface.ts +29 -0
- package/src/lib/sdk/http-client.interface.ts +110 -0
- package/src/lib/sdk/index.ts +10 -0
- package/src/lib/sdk/logger.sdk.interface.ts +11 -0
- package/src/lib/sdk/offset-store.sdk.interface.ts +14 -0
- package/src/lib/sdk/processing.sdk.interface.ts +20 -0
- package/src/lib/sdk/receiver.sdk.interface.ts +29 -0
- package/src/lib/sdk/sdk.interface.ts +42 -0
- package/src/lib/sdk/sender.sdk.interface.ts +34 -0
- package/src/lib/sdk/telemetry.sdk.interface.ts +12 -0
- package/src/lib/sdk/templating.sdk.interface.ts +16 -0
- package/tsconfig.json +16 -0
- package/tsconfig.lib.json +11 -0
- package/tsconfig.spec.json +14 -0
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": ["../../.eslintrc.json"],
|
|
3
|
+
"ignorePatterns": ["!**/*"],
|
|
4
|
+
"overrides": [
|
|
5
|
+
{
|
|
6
|
+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
|
|
7
|
+
"rules": {}
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"files": ["*.ts", "*.tsx"],
|
|
11
|
+
"rules": {}
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"files": ["*.js", "*.jsx"],
|
|
15
|
+
"rules": {}
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"files": ["*.json"],
|
|
19
|
+
"parser": "jsonc-eslint-parser",
|
|
20
|
+
"rules": {
|
|
21
|
+
"@nx/dependency-checks": [
|
|
22
|
+
"error",
|
|
23
|
+
{
|
|
24
|
+
"ignoredFiles": ["{projectRoot}/eslint.config.{js,cjs,mjs}"]
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
}
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
## 0.1.0 (2025-11-19)
|
|
2
|
+
|
|
3
|
+
### 🚀 Features
|
|
4
|
+
|
|
5
|
+
- fix connector packages publish ([517d2fd2](https://github.com/xip-online-applications/xod-core/commit/517d2fd2))
|
|
6
|
+
- **XODO-1133:** added file connector that uses the SDK ([#875](https://github.com/xip-online-applications/xod-core/pull/875))
|
|
7
|
+
- **XODO-1134:** added generic API connector ([#883](https://github.com/xip-online-applications/xod-core/pull/883))
|
|
8
|
+
- **XODO-1108:** added actions for MKG tables ([#877](https://github.com/xip-online-applications/xod-core/pull/877))
|
|
9
|
+
- **XODO-1134:** added full http-client wrapper ([#878](https://github.com/xip-online-applications/xod-core/pull/878))
|
|
10
|
+
- **XODO-1125:** use delta link in Office365 connector ([#865](https://github.com/xip-online-applications/xod-core/pull/865))
|
|
11
|
+
- enhance callback handling with action configuration and job mes… ([#814](https://github.com/xip-online-applications/xod-core/pull/814))
|
|
12
|
+
- **XODO-1029 XODO-1074:** added office365 mail client connector ([#805](https://github.com/xip-online-applications/xod-core/pull/805))
|
|
13
|
+
- enhance callback handling with action configuration and job message validation ([225b8cef](https://github.com/xip-online-applications/xod-core/commit/225b8cef))
|
|
14
|
+
- refactor output parser generation and streamline ConnectorRuntimeSDK initialization ([a72e7d83](https://github.com/xip-online-applications/xod-core/commit/a72e7d83))
|
|
15
|
+
|
|
16
|
+
### 🩹 Fixes
|
|
17
|
+
|
|
18
|
+
- handle failure more gracefully from OPC UA ([#856](https://github.com/xip-online-applications/xod-core/pull/856))
|
|
19
|
+
|
|
20
|
+
### ❤️ Thank You
|
|
21
|
+
|
|
22
|
+
- Copilot @Copilot
|
|
23
|
+
- frankdikker
|
|
24
|
+
- Rene Heijdens @H31nz3l
|
|
25
|
+
- Youri Lefers @yourilefers
|
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# connector-runtime-sdk
|
|
2
|
+
|
|
3
|
+
This library was generated with [Nx](https://nx.dev).
|
|
4
|
+
|
|
5
|
+
## Building
|
|
6
|
+
|
|
7
|
+
Run `nx build connector-runtime-sdk` to build the library.
|
|
8
|
+
|
|
9
|
+
## Running unit tests
|
|
10
|
+
|
|
11
|
+
Run `nx test connector-runtime-sdk` to execute the unit tests via [Jest](https://jestjs.io).
|
package/jest.config.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
displayName: 'connector-runtime-sdk',
|
|
3
|
+
preset: '../../jest.preset.js',
|
|
4
|
+
testEnvironment: 'node',
|
|
5
|
+
transform: {
|
|
6
|
+
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
|
|
7
|
+
},
|
|
8
|
+
moduleFileExtensions: ['ts', 'js', 'html'],
|
|
9
|
+
coverageDirectory: '../../coverage/libs/connector-runtime-sdk',
|
|
10
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@transai/connector-runtime-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"license": "LGPL-3.0-or-later",
|
|
8
|
+
"author": {
|
|
9
|
+
"name": "transAI",
|
|
10
|
+
"email": "samen@transai.com",
|
|
11
|
+
"url": "https://transai.com"
|
|
12
|
+
},
|
|
13
|
+
"type": "commonjs",
|
|
14
|
+
"main": "./index.cjs",
|
|
15
|
+
"typings": "./index.d.ts"
|
|
16
|
+
}
|
package/project.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@transai/connector-runtime-sdk",
|
|
3
|
+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
+
"sourceRoot": "libs/connector-runtime-sdk/src",
|
|
5
|
+
"projectType": "library",
|
|
6
|
+
"tags": ["connector:runtime", "connector:runtime-sdk-ready"],
|
|
7
|
+
"targets": {
|
|
8
|
+
"build": {
|
|
9
|
+
"executor": "@nx/esbuild:esbuild",
|
|
10
|
+
"outputs": ["{options.outputPath}"],
|
|
11
|
+
"options": {
|
|
12
|
+
"platform": "node",
|
|
13
|
+
"outputPath": "dist/libs/connector-runtime-sdk",
|
|
14
|
+
"format": ["cjs", "esm"],
|
|
15
|
+
"main": "libs/connector-runtime-sdk/src/index.ts",
|
|
16
|
+
"tsConfig": "libs/connector-runtime-sdk/tsconfig.lib.json",
|
|
17
|
+
"bundle": true,
|
|
18
|
+
"deleteOutputPath": true,
|
|
19
|
+
"generatePackageJson": true,
|
|
20
|
+
"sourcemap": true,
|
|
21
|
+
"minify": true,
|
|
22
|
+
"metafile": true,
|
|
23
|
+
"thirdParty": true
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"lint": {
|
|
27
|
+
"executor": "@nx/eslint:lint"
|
|
28
|
+
},
|
|
29
|
+
"test": {
|
|
30
|
+
"executor": "@nx/jest:jest",
|
|
31
|
+
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
|
32
|
+
"options": {
|
|
33
|
+
"jestConfig": "libs/connector-runtime-sdk/jest.config.ts"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ConfiguredConnectorTypes,
|
|
3
|
+
ConnectorInterface,
|
|
4
|
+
KafkaCallbackResponse,
|
|
5
|
+
XodJobType,
|
|
6
|
+
} from '@xip-online-data/types';
|
|
7
|
+
|
|
8
|
+
import { ConnectorRuntimeSDK } from './connector-runtime';
|
|
9
|
+
import {
|
|
10
|
+
CompileDelegate,
|
|
11
|
+
ConnectorSDKInterface,
|
|
12
|
+
LoggerSDKInterface,
|
|
13
|
+
} from './sdk';
|
|
14
|
+
|
|
15
|
+
class Implementation extends ConnectorRuntimeSDK {
|
|
16
|
+
override init = async (): Promise<void> => {
|
|
17
|
+
this.callbackFunction = (
|
|
18
|
+
message: XodJobType,
|
|
19
|
+
): Promise<KafkaCallbackResponse> => {
|
|
20
|
+
throw new Error(`Method not implemented, called with ${message.type}`);
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe('ConnectorRuntimeSDK', () => {
|
|
26
|
+
let implementation: Implementation;
|
|
27
|
+
let connector: ConnectorInterface;
|
|
28
|
+
let connectorSDK: ConnectorSDKInterface;
|
|
29
|
+
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
connector = {
|
|
32
|
+
identifier: 'test-connector',
|
|
33
|
+
connectorType: ConfiguredConnectorTypes.DUMMY_NODE,
|
|
34
|
+
tenantIdentifier: 'test-tenant',
|
|
35
|
+
name: 'Test Connector',
|
|
36
|
+
location: 'us-east-1',
|
|
37
|
+
enabled: true,
|
|
38
|
+
config: {},
|
|
39
|
+
createdAt: new Date(),
|
|
40
|
+
updatedAt: new Date(),
|
|
41
|
+
actions: [
|
|
42
|
+
{
|
|
43
|
+
identifier: 'test-action',
|
|
44
|
+
version: '1.0.0',
|
|
45
|
+
tenantIdentifier: 'test-tenant',
|
|
46
|
+
connectorIdentifier: 'test-connector',
|
|
47
|
+
name: 'Test Action',
|
|
48
|
+
config: {
|
|
49
|
+
templates: {
|
|
50
|
+
testTemplate: 'Hello, {{name}',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
inputParameters: [],
|
|
54
|
+
outputParameters: {},
|
|
55
|
+
createdAt: new Date(),
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
};
|
|
59
|
+
connectorSDK = {
|
|
60
|
+
logger: {
|
|
61
|
+
info: jest.fn(),
|
|
62
|
+
warn: jest.fn(),
|
|
63
|
+
error: jest.fn(),
|
|
64
|
+
debug: jest.fn(),
|
|
65
|
+
verbose: jest.fn(),
|
|
66
|
+
} as LoggerSDKInterface,
|
|
67
|
+
templating: { compile: jest.fn().mockReturnValue({} as CompileDelegate) },
|
|
68
|
+
receiver: {
|
|
69
|
+
registerCallback: jest.fn(),
|
|
70
|
+
},
|
|
71
|
+
} as unknown as ConnectorSDKInterface;
|
|
72
|
+
|
|
73
|
+
implementation = new Implementation(connector, connectorSDK);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
afterEach(() => {
|
|
77
|
+
jest.clearAllMocks();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('should be defined', () => {
|
|
81
|
+
expect(implementation).toBeDefined();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe('actions compilation', () => {
|
|
85
|
+
it('should have compiled templates for actions', () => {
|
|
86
|
+
expect(connectorSDK.templating.compile).toHaveBeenCalledWith(
|
|
87
|
+
'Hello, {{name}',
|
|
88
|
+
);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('should have parsed templates in action config', () => {
|
|
92
|
+
expect(
|
|
93
|
+
connector.actions?.[0].config['parsedTemplates']?.['testTemplate'],
|
|
94
|
+
).toBeDefined();
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('callback registration', () => {
|
|
99
|
+
it('should have registered the callback function on init', async () => {
|
|
100
|
+
await implementation.init();
|
|
101
|
+
|
|
102
|
+
expect(connectorSDK.receiver.registerCallback).toHaveBeenCalled();
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe('lifecycle', () => {
|
|
107
|
+
it('should start without error', async () => {
|
|
108
|
+
await expect(implementation.start()).resolves.toBeUndefined();
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('should stop without error', async () => {
|
|
112
|
+
await expect(implementation.stop()).resolves.toBeUndefined();
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
});
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import * as process from 'node:process';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
KafkaCallbackResponse,
|
|
5
|
+
BaseConnectorConfig,
|
|
6
|
+
ActionInterface,
|
|
7
|
+
ConnectorInterface,
|
|
8
|
+
XodJobType,
|
|
9
|
+
} from '@xip-online-data/types';
|
|
10
|
+
|
|
11
|
+
import { ConnectorRuntimeInterface } from './connector-runtime.interface';
|
|
12
|
+
import { CompileDelegate, ConnectorSDKInterface } from './sdk';
|
|
13
|
+
|
|
14
|
+
export interface IpcMessage {
|
|
15
|
+
cmd: string;
|
|
16
|
+
message: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export abstract class ConnectorRuntimeSDK<
|
|
20
|
+
T extends BaseConnectorConfig = BaseConnectorConfig,
|
|
21
|
+
> implements ConnectorRuntimeInterface
|
|
22
|
+
{
|
|
23
|
+
readonly #IPC_CHANNEL = 'connector-runtime';
|
|
24
|
+
|
|
25
|
+
readonly #connectorSDK: ConnectorSDKInterface<T>;
|
|
26
|
+
|
|
27
|
+
constructor(
|
|
28
|
+
connector: ConnectorInterface,
|
|
29
|
+
connectorSDK: ConnectorSDKInterface,
|
|
30
|
+
) {
|
|
31
|
+
this.#connectorSDK = connectorSDK as ConnectorSDKInterface<T>;
|
|
32
|
+
|
|
33
|
+
if (process.on) {
|
|
34
|
+
process.on('message', (message: IpcMessage) => {
|
|
35
|
+
if (message.cmd === this.#IPC_CHANNEL) {
|
|
36
|
+
connectorSDK.logger.verbose(
|
|
37
|
+
`${process.pid} Received message from parent process:`,
|
|
38
|
+
message,
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
} else {
|
|
43
|
+
connectorSDK.logger.warn(
|
|
44
|
+
'IPC channel is not available. process.on is undefined.',
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (!process.send) {
|
|
49
|
+
// Check if process.send is available
|
|
50
|
+
connectorSDK.logger.warn(
|
|
51
|
+
'IPC channel is not available. process.send is undefined.',
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
56
|
+
connector.actions?.forEach((action: ActionInterface) => {
|
|
57
|
+
if (action.config['templates'] === undefined) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const containers: {
|
|
62
|
+
[key: string]: CompileDelegate;
|
|
63
|
+
} = {};
|
|
64
|
+
|
|
65
|
+
Object.entries(action.config['templates']).forEach(([key, value]) => {
|
|
66
|
+
try {
|
|
67
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
68
|
+
containers[key] = connectorSDK.templating.compile(value);
|
|
69
|
+
} catch (error: unknown) {
|
|
70
|
+
connectorSDK.logger.error(
|
|
71
|
+
`Error compiling template ${key} for action ${action.identifier}`,
|
|
72
|
+
error,
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// eslint-disable-next-line no-param-reassign
|
|
78
|
+
action.config['parsedTemplates'] = containers;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public init: () => Promise<void> = () => Promise.resolve();
|
|
83
|
+
|
|
84
|
+
public start: () => Promise<void> = () => Promise.resolve();
|
|
85
|
+
|
|
86
|
+
public stop: () => Promise<void> = () => Promise.resolve();
|
|
87
|
+
|
|
88
|
+
set callbackFunction(
|
|
89
|
+
callback: (
|
|
90
|
+
message: XodJobType,
|
|
91
|
+
action: ActionInterface,
|
|
92
|
+
) => Promise<KafkaCallbackResponse>,
|
|
93
|
+
) {
|
|
94
|
+
this.connectorSDK.receiver.registerCallback(
|
|
95
|
+
this.#enrichWithActionConfig(callback),
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
protected get connectorSDK(): ConnectorSDKInterface<T> {
|
|
100
|
+
return this.#connectorSDK;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
#enrichWithActionConfig(
|
|
104
|
+
callbackFunction: (
|
|
105
|
+
message: XodJobType,
|
|
106
|
+
action: ActionInterface,
|
|
107
|
+
) => Promise<KafkaCallbackResponse>,
|
|
108
|
+
): (message: XodJobType) => Promise<KafkaCallbackResponse> {
|
|
109
|
+
return async (message: XodJobType) => {
|
|
110
|
+
const action = this.#connectorSDK.receiver.getActionConfig(message);
|
|
111
|
+
if (!action) {
|
|
112
|
+
return this.#connectorSDK.receiver.responses.badRequest(
|
|
113
|
+
'Action not found',
|
|
114
|
+
)(message);
|
|
115
|
+
}
|
|
116
|
+
return callbackFunction(message, action);
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface FileInfo {
|
|
2
|
+
type: 'DIRECTORY' | 'FILE';
|
|
3
|
+
name: string;
|
|
4
|
+
size: number;
|
|
5
|
+
modifyTime: Date;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface FileHandleInterface {
|
|
9
|
+
get(): Buffer;
|
|
10
|
+
|
|
11
|
+
close(): boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface FilesSDKInterface {
|
|
15
|
+
list(path: string): Promise<Array<FileInfo>>;
|
|
16
|
+
|
|
17
|
+
read(filePath: string): Promise<FileHandleInterface>;
|
|
18
|
+
|
|
19
|
+
write(
|
|
20
|
+
filePath: string,
|
|
21
|
+
data: FileHandleInterface | Buffer | string,
|
|
22
|
+
): Promise<boolean>;
|
|
23
|
+
|
|
24
|
+
delete(path: string): Promise<boolean>;
|
|
25
|
+
|
|
26
|
+
exists(path: string): Promise<boolean>;
|
|
27
|
+
|
|
28
|
+
pathAsDsn(path: string): string;
|
|
29
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
export interface HttpConfig {
|
|
2
|
+
baseUrl?: string;
|
|
3
|
+
contentType?: string;
|
|
4
|
+
timeout?: number;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export type HttpRequestOptions<D = string | object> = {
|
|
8
|
+
headers?: Record<string, string>;
|
|
9
|
+
params?: Record<string, string | number | boolean>;
|
|
10
|
+
data?: D;
|
|
11
|
+
withCredentials?: boolean;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type HttpRequestOptionsFormatter<D = string | object> = (
|
|
15
|
+
requestOptions: HttpRequestOptions<D>,
|
|
16
|
+
method: HttpMethod,
|
|
17
|
+
url: string,
|
|
18
|
+
) => Promise<HttpRequestOptions<D>> | HttpRequestOptions<D>;
|
|
19
|
+
|
|
20
|
+
export type HttpMethod =
|
|
21
|
+
| 'GET'
|
|
22
|
+
| 'POST'
|
|
23
|
+
| 'PUT'
|
|
24
|
+
| 'DELETE'
|
|
25
|
+
| 'PATCH'
|
|
26
|
+
| 'HEAD'
|
|
27
|
+
| 'OPTIONS';
|
|
28
|
+
|
|
29
|
+
export type HttpResponseHeader =
|
|
30
|
+
| string
|
|
31
|
+
| Array<string>
|
|
32
|
+
| number
|
|
33
|
+
| boolean
|
|
34
|
+
| null;
|
|
35
|
+
|
|
36
|
+
export type HttpResponse<D = unknown> = {
|
|
37
|
+
status: number;
|
|
38
|
+
data: D;
|
|
39
|
+
headers?: Record<string, HttpResponseHeader>;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type HttpError = {
|
|
43
|
+
status: number;
|
|
44
|
+
error?: string;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
interface PromiseWithReason<T = unknown, R = unknown> extends Promise<T> {
|
|
48
|
+
then<TResult1 = T, TResult2 = never>(
|
|
49
|
+
onfulfilled?:
|
|
50
|
+
| ((value: T) => TResult1 | PromiseLike<TResult1>)
|
|
51
|
+
| undefined
|
|
52
|
+
| null,
|
|
53
|
+
onrejected?:
|
|
54
|
+
| ((reason: R) => TResult2 | PromiseLike<TResult2>)
|
|
55
|
+
| undefined
|
|
56
|
+
| null,
|
|
57
|
+
): Promise<TResult1 | TResult2>;
|
|
58
|
+
|
|
59
|
+
catch<TResult = never>(
|
|
60
|
+
onrejected?:
|
|
61
|
+
| ((reason: R) => TResult | PromiseLike<TResult>)
|
|
62
|
+
| undefined
|
|
63
|
+
| null,
|
|
64
|
+
): Promise<T | TResult>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export type HttpClientPromise<T> = PromiseWithReason<
|
|
68
|
+
HttpResponse<T>,
|
|
69
|
+
HttpError
|
|
70
|
+
>;
|
|
71
|
+
|
|
72
|
+
export interface HttpClientSDKInterface {
|
|
73
|
+
get<R = unknown>(
|
|
74
|
+
destination: string,
|
|
75
|
+
options?: HttpRequestOptions,
|
|
76
|
+
): HttpClientPromise<R>;
|
|
77
|
+
|
|
78
|
+
post<R = unknown, D = string | object>(
|
|
79
|
+
destination: string,
|
|
80
|
+
data: D,
|
|
81
|
+
options?: HttpRequestOptions<D>,
|
|
82
|
+
): HttpClientPromise<R>;
|
|
83
|
+
|
|
84
|
+
put<R = unknown, D = string | object>(
|
|
85
|
+
destination: string,
|
|
86
|
+
data: D,
|
|
87
|
+
options?: HttpRequestOptions<D>,
|
|
88
|
+
): HttpClientPromise<R>;
|
|
89
|
+
|
|
90
|
+
patch<R = unknown, D = string | object>(
|
|
91
|
+
destination: string,
|
|
92
|
+
data: D,
|
|
93
|
+
options?: HttpRequestOptions<D>,
|
|
94
|
+
): HttpClientPromise<R>;
|
|
95
|
+
|
|
96
|
+
delete<R = unknown>(
|
|
97
|
+
destination: string,
|
|
98
|
+
options?: HttpRequestOptions,
|
|
99
|
+
): HttpClientPromise<R>;
|
|
100
|
+
|
|
101
|
+
request<R = unknown, D = string | object>(
|
|
102
|
+
method: HttpMethod,
|
|
103
|
+
url: string,
|
|
104
|
+
options?: HttpRequestOptions<D>,
|
|
105
|
+
): HttpClientPromise<R>;
|
|
106
|
+
|
|
107
|
+
setRequestOptionsFormatter<D = string | object>(
|
|
108
|
+
formatter: HttpRequestOptionsFormatter<D>,
|
|
109
|
+
): HttpClientSDKInterface;
|
|
110
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './sdk.interface';
|
|
2
|
+
export * from './http-client.interface';
|
|
3
|
+
export * from './logger.sdk.interface';
|
|
4
|
+
export * from './offset-store.sdk.interface';
|
|
5
|
+
export * from './processing.sdk.interface';
|
|
6
|
+
export * from './receiver.sdk.interface';
|
|
7
|
+
export * from './sender.sdk.interface';
|
|
8
|
+
export * from './telemetry.sdk.interface';
|
|
9
|
+
export * from './templating.sdk.interface';
|
|
10
|
+
export * from './files.sdk.interface';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface StoredOffset {
|
|
2
|
+
timestamp: number;
|
|
3
|
+
id: number | string;
|
|
4
|
+
isoDate?: string;
|
|
5
|
+
date?: string;
|
|
6
|
+
rawTimestamp?: number | string;
|
|
7
|
+
[key: string]: string | number | undefined;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface OffsetStoreSDKInterface {
|
|
11
|
+
getOffset(identifier: string): Promise<StoredOffset>;
|
|
12
|
+
|
|
13
|
+
setOffset(offset: StoredOffset, identifier: string): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface IntervalHandler {
|
|
2
|
+
name?: string;
|
|
3
|
+
onInit?: () => Promise<void> | void;
|
|
4
|
+
onRun: () => Promise<void> | void;
|
|
5
|
+
onStop?: () => Promise<void> | void;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type RegisterIntervalOptions = {
|
|
9
|
+
immediate?: boolean;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export interface ProcessingSDKInterface {
|
|
13
|
+
registerInterval(
|
|
14
|
+
intervalSeconds: number,
|
|
15
|
+
handler: IntervalHandler,
|
|
16
|
+
options?: RegisterIntervalOptions,
|
|
17
|
+
): Promise<string>;
|
|
18
|
+
|
|
19
|
+
stopInterval(name: string): Promise<void>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ActionInterface,
|
|
3
|
+
KafkaCallbackResponse,
|
|
4
|
+
KafkaCallbackResponseType,
|
|
5
|
+
XodJobType,
|
|
6
|
+
} from '@xip-online-data/types';
|
|
7
|
+
|
|
8
|
+
export interface ReceiverSDKInterface {
|
|
9
|
+
readonly responses: {
|
|
10
|
+
readonly ok: KafkaCallbackResponseType;
|
|
11
|
+
readonly created: KafkaCallbackResponseType;
|
|
12
|
+
readonly badRequest: KafkaCallbackResponseType;
|
|
13
|
+
readonly unprocessableEntity: KafkaCallbackResponseType;
|
|
14
|
+
readonly notFound: KafkaCallbackResponseType;
|
|
15
|
+
readonly internalServerError: KafkaCallbackResponseType;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
registerCallback<T extends XodJobType = XodJobType>(
|
|
19
|
+
callbackFunction: (message: T) => Promise<KafkaCallbackResponse>,
|
|
20
|
+
eventType?: string,
|
|
21
|
+
identifier?: string,
|
|
22
|
+
): void;
|
|
23
|
+
|
|
24
|
+
getActionConfig(message: XodJobType): ActionInterface | null;
|
|
25
|
+
|
|
26
|
+
emitEventType<T extends XodJobType = XodJobType>(
|
|
27
|
+
callbackFunction: (message: T) => Promise<KafkaCallbackResponse>,
|
|
28
|
+
): (message: T) => Promise<KafkaCallbackResponse>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { BaseConnectorConfig } from '@xip-online-data/types';
|
|
2
|
+
|
|
3
|
+
import { FilesSDKInterface } from './files.sdk.interface';
|
|
4
|
+
import { HttpClientSDKInterface, HttpConfig } from './http-client.interface';
|
|
5
|
+
import { LoggerSDKInterface } from './logger.sdk.interface';
|
|
6
|
+
import { OffsetStoreSDKInterface } from './offset-store.sdk.interface';
|
|
7
|
+
import { ProcessingSDKInterface } from './processing.sdk.interface';
|
|
8
|
+
import { ReceiverSDKInterface } from './receiver.sdk.interface';
|
|
9
|
+
import { SenderSDKInterface } from './sender.sdk.interface';
|
|
10
|
+
import { TelemetrySDKInterface } from './telemetry.sdk.interface';
|
|
11
|
+
import { TemplatingSDKInterface } from './templating.sdk.interface';
|
|
12
|
+
|
|
13
|
+
export interface ConnectorSDKInterface<T = BaseConnectorConfig> {
|
|
14
|
+
get config(): T;
|
|
15
|
+
|
|
16
|
+
get logger(): LoggerSDKInterface;
|
|
17
|
+
|
|
18
|
+
get sender(): SenderSDKInterface;
|
|
19
|
+
|
|
20
|
+
get receiver(): ReceiverSDKInterface;
|
|
21
|
+
|
|
22
|
+
get templating(): TemplatingSDKInterface;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Service to schedule and manage processing tasks that need monitoring and retries.
|
|
26
|
+
*/
|
|
27
|
+
get processing(): ProcessingSDKInterface;
|
|
28
|
+
|
|
29
|
+
get offsetStore(): OffsetStoreSDKInterface;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Ability to send telemetry data such as gauges and increments on how the connector is performing.
|
|
33
|
+
*/
|
|
34
|
+
get telemetry(): TelemetrySDKInterface;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Get file service instance to access files using a specified DSN. If no DSN is provided, defaults to local file system tmp dir.
|
|
38
|
+
*/
|
|
39
|
+
files(dsn?: string): FilesSDKInterface;
|
|
40
|
+
|
|
41
|
+
httpClient(httpConfig?: HttpConfig): HttpClientSDKInterface;
|
|
42
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface Metric {
|
|
2
|
+
key: string;
|
|
3
|
+
value: number;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export type Metadata = { [key: string]: string };
|
|
7
|
+
|
|
8
|
+
export interface Context {
|
|
9
|
+
timestamp?: Date;
|
|
10
|
+
ttl?: number;
|
|
11
|
+
extraPayload?: { [key: string]: string };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type Result = boolean | { [index: number]: boolean };
|
|
15
|
+
|
|
16
|
+
export interface SenderSDKInterface {
|
|
17
|
+
metrics(
|
|
18
|
+
metrics: Array<Metric>,
|
|
19
|
+
metadata?: Metadata,
|
|
20
|
+
context?: Context,
|
|
21
|
+
): Promise<Result>;
|
|
22
|
+
|
|
23
|
+
metricsLegacy(
|
|
24
|
+
metrics: Array<never>,
|
|
25
|
+
metadata?: Metadata,
|
|
26
|
+
context?: Context,
|
|
27
|
+
): Promise<Result>;
|
|
28
|
+
|
|
29
|
+
documents(
|
|
30
|
+
metrics: Array<object>,
|
|
31
|
+
metadata?: Metadata,
|
|
32
|
+
context?: Context,
|
|
33
|
+
): Promise<Result>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface TelemetrySDKInterface {
|
|
2
|
+
/**
|
|
3
|
+
* Increment a telemetry counter by 1.
|
|
4
|
+
*/
|
|
5
|
+
increment(key: string): void;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Increment a telemetry counter by a specified value. 0 doesn't send any telemetry.
|
|
9
|
+
* A negative value will decrement the counter.
|
|
10
|
+
*/
|
|
11
|
+
increment(key: string, value: number): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type RuntimeOptions = {
|
|
2
|
+
partial?: boolean;
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
export type CompileDelegate<T = unknown> = {
|
|
6
|
+
(context: T, options?: RuntimeOptions): string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type CompileOptions = { strict?: boolean };
|
|
10
|
+
|
|
11
|
+
export interface TemplatingSDKInterface {
|
|
12
|
+
compile<T = unknown>(
|
|
13
|
+
input: string,
|
|
14
|
+
options?: CompileOptions,
|
|
15
|
+
): CompileDelegate<T>;
|
|
16
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"outDir": "../../dist/out-tsc",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"types": ["node"]
|
|
8
|
+
},
|
|
9
|
+
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"],
|
|
10
|
+
"include": ["src/**/*.ts"]
|
|
11
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "../../dist/out-tsc",
|
|
5
|
+
"module": "commonjs",
|
|
6
|
+
"types": ["jest", "node"]
|
|
7
|
+
},
|
|
8
|
+
"include": [
|
|
9
|
+
"jest.config.ts",
|
|
10
|
+
"src/**/*.test.ts",
|
|
11
|
+
"src/**/*.spec.ts",
|
|
12
|
+
"src/**/*.d.ts"
|
|
13
|
+
]
|
|
14
|
+
}
|