@transai/connector-runner-microsoft-office365-email 0.1.0 → 0.2.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 +18 -0
- package/CHANGELOG.md +24 -1
- package/jest.config.ts +11 -0
- package/package.json +1 -1
- package/project.json +45 -0
- package/src/lib/actions-handler.spec.ts +171 -0
- package/src/lib/actions-handler.ts +171 -0
- package/src/lib/connector-runner-microsoft-office365-email.spec.ts +82 -0
- package/src/lib/connector-runner-microsoft-office365-email.ts +53 -0
- package/src/lib/mail-processor.spec.ts +195 -0
- package/src/lib/mail-processor.ts +277 -0
- package/src/lib/types.ts +19 -0
- package/tsconfig.json +16 -0
- package/tsconfig.lib.json +10 -0
- package/tsconfig.spec.json +14 -0
- package/index.cjs +0 -196
- package/index.cjs.map +0 -7
- package/index.js +0 -196
- package/index.js.map +0 -7
- package/libs/connector-runner-microsoft-office365-email/src/lib/actions-handler.d.ts +0 -8
- package/libs/connector-runner-microsoft-office365-email/src/lib/connector-runner-microsoft-office365-email.d.ts +0 -8
- package/libs/connector-runner-microsoft-office365-email/src/lib/mail-processor.d.ts +0 -11
- package/libs/connector-runner-microsoft-office365-email/src/lib/types.d.ts +0 -14
- package/libs/connector-runtime-sdk/src/index.d.ts +0 -3
- package/libs/connector-runtime-sdk/src/lib/connector-runtime.d.ts +0 -16
- package/libs/connector-runtime-sdk/src/lib/connector-runtime.interface.d.ts +0 -5
- package/libs/connector-runtime-sdk/src/lib/sdk/index.d.ts +0 -7
- package/libs/connector-runtime-sdk/src/lib/sdk/logger.sdk.interface.d.ts +0 -7
- package/libs/connector-runtime-sdk/src/lib/sdk/offset-store.sdk.interface.d.ts +0 -11
- package/libs/connector-runtime-sdk/src/lib/sdk/processing.sdk.interface.d.ts +0 -12
- package/libs/connector-runtime-sdk/src/lib/sdk/receiver.sdk.interface.d.ts +0 -14
- package/libs/connector-runtime-sdk/src/lib/sdk/sdk.interface.d.ts +0 -16
- package/libs/connector-runtime-sdk/src/lib/sdk/sender.sdk.interface.d.ts +0 -22
- package/libs/connector-runtime-sdk/src/lib/sdk/templating.sdk.interface.d.ts +0 -12
- package/libs/logger/src/index.d.ts +0 -1
- package/libs/logger/src/lib/logger.d.ts +0 -28
- package/libs/microsoft-office365-mail-client/src/index.d.ts +0 -3
- package/libs/microsoft-office365-mail-client/src/lib/mail-client.d.ts +0 -12
- package/libs/microsoft-office365-mail-client/src/lib/mail-client.interface.d.ts +0 -7
- package/libs/microsoft-office365-mail-client/src/lib/office365-client.d.ts +0 -16
- package/libs/microsoft-office365-mail-client/src/lib/office365-mail-parser.d.ts +0 -8
- package/libs/microsoft-office365-mail-client/src/lib/office365-types.d.ts +0 -73
- package/libs/microsoft-office365-mail-client/src/lib/types.d.ts +0 -46
- package/libs/types/src/index.d.ts +0 -7
- package/libs/types/src/lib/cube-query-config.types.d.ts +0 -20
- package/libs/types/src/lib/file-action.types.d.ts +0 -5
- package/libs/types/src/lib/http-status-codes.enum.d.ts +0 -63
- package/libs/types/src/lib/management-api/action-definition.interface.d.ts +0 -12
- package/libs/types/src/lib/management-api/chart.interface.d.ts +0 -9
- package/libs/types/src/lib/management-api/connector/connector.interface.d.ts +0 -140
- package/libs/types/src/lib/management-api/connector/connectors.interface.d.ts +0 -126
- package/libs/types/src/lib/management-api/connector-orchestrator-config.interface.d.ts +0 -14
- package/libs/types/src/lib/management-api/cube-dataset.interface.d.ts +0 -93
- package/libs/types/src/lib/management-api/dashboard.interface.d.ts +0 -35
- package/libs/types/src/lib/management-api/dataset/collection.interface.d.ts +0 -16
- package/libs/types/src/lib/management-api/dataset/dataset-record.interface.d.ts +0 -5
- package/libs/types/src/lib/management-api/dataset/dataset.interface.d.ts +0 -730
- package/libs/types/src/lib/management-api/dataset/datasets.interface.d.ts +0 -710
- package/libs/types/src/lib/management-api/dataset/dimension.interface.d.ts +0 -205
- package/libs/types/src/lib/management-api/dataset/dimensions.interface.d.ts +0 -186
- package/libs/types/src/lib/management-api/dataset/filter-group.interface.d.ts +0 -8
- package/libs/types/src/lib/management-api/dataset/filter.interface.d.ts +0 -34
- package/libs/types/src/lib/management-api/dataset/filters.interface.d.ts +0 -7
- package/libs/types/src/lib/management-api/dataset/measure.interface.d.ts +0 -65
- package/libs/types/src/lib/management-api/dataset/measures.interface.d.ts +0 -56
- package/libs/types/src/lib/management-api/dataset/meta.interface.d.ts +0 -9
- package/libs/types/src/lib/management-api/dataset/pre-aggregate.interface.d.ts +0 -69
- package/libs/types/src/lib/management-api/dataset/pre-aggregations.interface.d.ts +0 -54
- package/libs/types/src/lib/management-api/dataset/relation.interface.d.ts +0 -40
- package/libs/types/src/lib/management-api/dataset/relations.interface.d.ts +0 -36
- package/libs/types/src/lib/management-api/dataset/segment.interface.d.ts +0 -45
- package/libs/types/src/lib/management-api/dataset/segments.interface.d.ts +0 -43
- package/libs/types/src/lib/management-api/dataset/switch.interface.d.ts +0 -70
- package/libs/types/src/lib/management-api/dataset/when-item.interface.d.ts +0 -41
- package/libs/types/src/lib/management-api/dataset/when-items.interface.d.ts +0 -40
- package/libs/types/src/lib/management-api/event-origin.interface.d.ts +0 -22
- package/libs/types/src/lib/management-api/index.d.ts +0 -39
- package/libs/types/src/lib/management-api/pagination/index.d.ts +0 -1
- package/libs/types/src/lib/management-api/pagination/paginated-response.interface.d.ts +0 -17
- package/libs/types/src/lib/management-api/semantic-trigger/index.d.ts +0 -5
- package/libs/types/src/lib/management-api/semantic-trigger/semantic-trigger-filter.interface.d.ts +0 -20
- package/libs/types/src/lib/management-api/semantic-trigger/semantic-trigger-filters.interface.d.ts +0 -18
- package/libs/types/src/lib/management-api/semantic-trigger/semantic-trigger-record.interface.d.ts +0 -6
- package/libs/types/src/lib/management-api/semantic-trigger/semantic-trigger.interface.d.ts +0 -74
- package/libs/types/src/lib/management-api/semantic-trigger/semantic-triggers.interface.d.ts +0 -62
- package/libs/types/src/lib/management-api/template-implementation-overrides.interface.d.ts +0 -1152
- package/libs/types/src/lib/management-api/template-implementation.interface.d.ts +0 -2860
- package/libs/types/src/lib/management-api/template.interface.d.ts +0 -1191
- package/libs/types/src/lib/management-api/tenant.interface.d.ts +0 -8
- package/libs/types/src/lib/management-api/type-enums.d.ts +0 -85
- package/libs/types/src/lib/management-api/workflow/action.interface.d.ts +0 -85
- package/libs/types/src/lib/management-api/workflow/index.d.ts +0 -6
- package/libs/types/src/lib/management-api/workflow/offset.interface.d.ts +0 -16
- package/libs/types/src/lib/management-api/workflow/trigger-types.interface.d.ts +0 -5
- package/libs/types/src/lib/management-api/workflow/workflow-definition.interface.d.ts +0 -49
- package/libs/types/src/lib/management-api/workflow/workflow-run.d.ts +0 -65
- package/libs/types/src/lib/management-api/workflow/workflow.drawing.d.ts +0 -101
- package/libs/types/src/lib/message.types.d.ts +0 -59
- package/libs/types/src/lib/response.types.d.ts +0 -27
- package/libs/types/src/lib/types.d.ts +0 -115
- /package/{libs/connector-runner-microsoft-office365-email/src/index.d.ts → src/index.ts} +0 -0
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
}
|
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,31 @@
|
|
|
1
|
+
## 0.2.0 (2025-11-19)
|
|
2
|
+
|
|
3
|
+
### 🚀 Features
|
|
4
|
+
|
|
5
|
+
- **XODO-1133:** added file connector that uses the SDK ([#875](https://github.com/xip-online-applications/xod-core/pull/875))
|
|
6
|
+
- **XODO-1125:** use delta link in Office365 connector ([#865](https://github.com/xip-online-applications/xod-core/pull/865))
|
|
7
|
+
- ability to send statistics to logs for now ([#863](https://github.com/xip-online-applications/xod-core/pull/863))
|
|
8
|
+
- let mail processor save attachments ([#836](https://github.com/xip-online-applications/xod-core/pull/836))
|
|
9
|
+
- add method to fetch email attachments ([#833](https://github.com/xip-online-applications/xod-core/pull/833))
|
|
10
|
+
|
|
11
|
+
### 🩹 Fixes
|
|
12
|
+
|
|
13
|
+
- remove mailbox from collection ([64d58424](https://github.com/xip-online-applications/xod-core/commit/64d58424))
|
|
14
|
+
- mail processor not sending correct format ([ecb008f7](https://github.com/xip-online-applications/xod-core/commit/ecb008f7))
|
|
15
|
+
- interval starting ([f8e2ee14](https://github.com/xip-online-applications/xod-core/commit/f8e2ee14))
|
|
16
|
+
|
|
17
|
+
### ❤️ Thank You
|
|
18
|
+
|
|
19
|
+
- Copilot @Copilot
|
|
20
|
+
- frankdikker
|
|
21
|
+
- Rene Heijdens @H31nz3l
|
|
22
|
+
- Youri Lefers @yourilefers
|
|
23
|
+
|
|
1
24
|
# Changelog
|
|
2
25
|
|
|
3
26
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
27
|
|
|
5
|
-
# 0.1.0 (2025-10-
|
|
28
|
+
# 0.1.0 (2025-10-24)
|
|
6
29
|
|
|
7
30
|
|
|
8
31
|
### Features
|
package/jest.config.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
displayName: 'connector-runner-microsoft-office365-email',
|
|
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:
|
|
10
|
+
'../../coverage/libs/connector-runner-microsoft-office365-email',
|
|
11
|
+
};
|
package/package.json
CHANGED
package/project.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "connector-runner-microsoft-office365-email",
|
|
3
|
+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
+
"sourceRoot": "libs/connector-runner-microsoft-office365-email/src",
|
|
5
|
+
"projectType": "library",
|
|
6
|
+
"tags": [
|
|
7
|
+
"connector:runner",
|
|
8
|
+
"connector:runner-sdk",
|
|
9
|
+
"connector:email",
|
|
10
|
+
"connector:source",
|
|
11
|
+
"provider:@transai"
|
|
12
|
+
],
|
|
13
|
+
"targets": {
|
|
14
|
+
"build": {
|
|
15
|
+
"executor": "@transai/tools:connector",
|
|
16
|
+
"outputs": ["{options.outputPath}"],
|
|
17
|
+
"options": {
|
|
18
|
+
"external": ["cpu-features", "ssh2"]
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"lint": {
|
|
22
|
+
"executor": "@nx/eslint:lint"
|
|
23
|
+
},
|
|
24
|
+
"test": {
|
|
25
|
+
"executor": "@nx/jest:jest",
|
|
26
|
+
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
|
27
|
+
"options": {
|
|
28
|
+
"jestConfig": "libs/connector-runner-microsoft-office365-email/jest.config.ts"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"version": {
|
|
32
|
+
"executor": "@jscutlery/semver:version",
|
|
33
|
+
"options": {
|
|
34
|
+
"postTargets": ["build", "deploy"]
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"deploy": {
|
|
38
|
+
"executor": "ngx-deploy-npm:deploy",
|
|
39
|
+
"dependsOn": ["build"],
|
|
40
|
+
"options": {
|
|
41
|
+
"distFolderPath": "dist/connectors/connector-runner-microsoft-office365-email"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { ConnectorSDKInterface } from '@transai/connector-runtime-sdk';
|
|
2
|
+
import { MailClientInterface } from '@xip-online-data/microsoft-office365-mail-client';
|
|
3
|
+
import { ActionInterface, XodBaseMessageType } from '@xip-online-data/types';
|
|
4
|
+
|
|
5
|
+
import { ActionsHandler } from './actions-handler';
|
|
6
|
+
|
|
7
|
+
describe('ActionsHandler', () => {
|
|
8
|
+
let handler: ActionsHandler;
|
|
9
|
+
|
|
10
|
+
let sdkMock: ConnectorSDKInterface;
|
|
11
|
+
let mailClientMock: MailClientInterface;
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
sdkMock = {
|
|
15
|
+
logger: {
|
|
16
|
+
info: jest.fn(),
|
|
17
|
+
debug: jest.fn(),
|
|
18
|
+
error: jest.fn(),
|
|
19
|
+
},
|
|
20
|
+
receiver: {
|
|
21
|
+
emitEventType: jest.fn().mockReturnValue(
|
|
22
|
+
jest.fn().mockReturnValue({
|
|
23
|
+
statusCode: 201,
|
|
24
|
+
}),
|
|
25
|
+
),
|
|
26
|
+
responses: {
|
|
27
|
+
created: jest.fn().mockReturnValue(
|
|
28
|
+
jest.fn().mockReturnValue({
|
|
29
|
+
statusCode: 201,
|
|
30
|
+
}),
|
|
31
|
+
),
|
|
32
|
+
badRequest: jest.fn().mockReturnValue(
|
|
33
|
+
jest.fn().mockReturnValue({
|
|
34
|
+
statusCode: 400,
|
|
35
|
+
}),
|
|
36
|
+
),
|
|
37
|
+
internalServerError: jest.fn().mockReturnValue(
|
|
38
|
+
jest.fn().mockReturnValue({
|
|
39
|
+
statusCode: 500,
|
|
40
|
+
}),
|
|
41
|
+
),
|
|
42
|
+
},
|
|
43
|
+
getActionConfig: jest.fn(),
|
|
44
|
+
},
|
|
45
|
+
} as unknown as ConnectorSDKInterface;
|
|
46
|
+
|
|
47
|
+
mailClientMock = {
|
|
48
|
+
reply: jest.fn(),
|
|
49
|
+
addCategory: jest.fn(),
|
|
50
|
+
removeCategory: jest.fn(),
|
|
51
|
+
} as unknown as MailClientInterface;
|
|
52
|
+
|
|
53
|
+
handler = new ActionsHandler(sdkMock, mailClientMock);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should be defined', () => {
|
|
57
|
+
expect(handler).toBeDefined();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe('JOB actions', () => {
|
|
61
|
+
it('should handle JOB message without action config', async () => {
|
|
62
|
+
const jobMessage = {
|
|
63
|
+
type: 'JOB',
|
|
64
|
+
payload: {},
|
|
65
|
+
} as XodBaseMessageType;
|
|
66
|
+
|
|
67
|
+
(sdkMock.receiver.getActionConfig as jest.Mock).mockReturnValueOnce(
|
|
68
|
+
undefined,
|
|
69
|
+
);
|
|
70
|
+
const response = await handler.callbackFunctionChain(jobMessage);
|
|
71
|
+
|
|
72
|
+
expect(sdkMock.receiver.getActionConfig).toHaveBeenCalledWith(jobMessage);
|
|
73
|
+
expect(response.statusCode).toBe(400);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('should handle JOB message that sends a reply', async () => {
|
|
77
|
+
const jobMessage = {
|
|
78
|
+
type: 'JOB',
|
|
79
|
+
payload: {},
|
|
80
|
+
} as XodBaseMessageType;
|
|
81
|
+
const action = {
|
|
82
|
+
identifier: 'action-1',
|
|
83
|
+
config: {
|
|
84
|
+
parsedTemplates: {
|
|
85
|
+
action: jest.fn().mockReturnValue('REPLY'),
|
|
86
|
+
params: jest
|
|
87
|
+
.fn()
|
|
88
|
+
.mockReturnValue(
|
|
89
|
+
'{ "messageId": "123", "from": "foo@example.com", "mailBody": "Test reply" }',
|
|
90
|
+
),
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
} as unknown as ActionInterface;
|
|
94
|
+
|
|
95
|
+
(sdkMock.receiver.getActionConfig as jest.Mock).mockReturnValueOnce(
|
|
96
|
+
action,
|
|
97
|
+
);
|
|
98
|
+
const response = await handler.callbackFunctionChain(jobMessage);
|
|
99
|
+
|
|
100
|
+
expect(mailClientMock.reply).toHaveBeenCalledWith(
|
|
101
|
+
'123',
|
|
102
|
+
'foo@example.com',
|
|
103
|
+
'Test reply',
|
|
104
|
+
true,
|
|
105
|
+
);
|
|
106
|
+
expect(response.statusCode).toBe(201);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('should handle JOB message that add a category', async () => {
|
|
110
|
+
const jobMessage = {
|
|
111
|
+
type: 'JOB',
|
|
112
|
+
payload: {},
|
|
113
|
+
} as XodBaseMessageType;
|
|
114
|
+
const action = {
|
|
115
|
+
identifier: 'action-1',
|
|
116
|
+
config: {
|
|
117
|
+
parsedTemplates: {
|
|
118
|
+
action: jest.fn().mockReturnValue('CATEGORY_ADD'),
|
|
119
|
+
params: jest
|
|
120
|
+
.fn()
|
|
121
|
+
.mockReturnValue(
|
|
122
|
+
'{ "messageId": "123", "category": "some-category" }',
|
|
123
|
+
),
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
} as unknown as ActionInterface;
|
|
127
|
+
|
|
128
|
+
(sdkMock.receiver.getActionConfig as jest.Mock).mockReturnValueOnce(
|
|
129
|
+
action,
|
|
130
|
+
);
|
|
131
|
+
const response = await handler.callbackFunctionChain(jobMessage);
|
|
132
|
+
|
|
133
|
+
expect(mailClientMock.addCategory).toHaveBeenCalledWith(
|
|
134
|
+
'123',
|
|
135
|
+
'some-category',
|
|
136
|
+
);
|
|
137
|
+
expect(response.statusCode).toBe(201);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('should handle JOB message that removes a category', async () => {
|
|
141
|
+
const jobMessage = {
|
|
142
|
+
type: 'JOB',
|
|
143
|
+
payload: {},
|
|
144
|
+
} as XodBaseMessageType;
|
|
145
|
+
const action = {
|
|
146
|
+
identifier: 'action-1',
|
|
147
|
+
config: {
|
|
148
|
+
parsedTemplates: {
|
|
149
|
+
action: jest.fn().mockReturnValue('CATEGORY_REMOVE'),
|
|
150
|
+
params: jest
|
|
151
|
+
.fn()
|
|
152
|
+
.mockReturnValue(
|
|
153
|
+
'{ "messageId": "123", "category": "some-category" }',
|
|
154
|
+
),
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
} as unknown as ActionInterface;
|
|
158
|
+
|
|
159
|
+
(sdkMock.receiver.getActionConfig as jest.Mock).mockReturnValueOnce(
|
|
160
|
+
action,
|
|
161
|
+
);
|
|
162
|
+
const response = await handler.callbackFunctionChain(jobMessage);
|
|
163
|
+
|
|
164
|
+
expect(mailClientMock.removeCategory).toHaveBeenCalledWith(
|
|
165
|
+
'123',
|
|
166
|
+
'some-category',
|
|
167
|
+
);
|
|
168
|
+
expect(response.statusCode).toBe(201);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
});
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CompileDelegate,
|
|
3
|
+
ConnectorSDKInterface,
|
|
4
|
+
} from '@transai/connector-runtime-sdk';
|
|
5
|
+
import { MailClientInterface } from '@xip-online-data/microsoft-office365-mail-client';
|
|
6
|
+
import {
|
|
7
|
+
KafkaCallbackResponse,
|
|
8
|
+
XodActionType,
|
|
9
|
+
XodBaseMessageType,
|
|
10
|
+
XodJobType,
|
|
11
|
+
} from '@xip-online-data/types';
|
|
12
|
+
|
|
13
|
+
export class ActionsHandler {
|
|
14
|
+
readonly #connectorSDK: ConnectorSDKInterface;
|
|
15
|
+
|
|
16
|
+
readonly #mailClient: MailClientInterface;
|
|
17
|
+
|
|
18
|
+
constructor(
|
|
19
|
+
connectorSDK: ConnectorSDKInterface,
|
|
20
|
+
mailClient: MailClientInterface,
|
|
21
|
+
) {
|
|
22
|
+
this.#connectorSDK = connectorSDK;
|
|
23
|
+
this.#mailClient = mailClient;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get callbackFunctionChain(): (
|
|
27
|
+
m: XodBaseMessageType,
|
|
28
|
+
) => Promise<KafkaCallbackResponse> {
|
|
29
|
+
return this.#jobCallbackFunction(
|
|
30
|
+
this.#actionCallbackFunction(
|
|
31
|
+
this.#connectorSDK.receiver.emitEventType(
|
|
32
|
+
this.#connectorSDK.receiver.responses.created(),
|
|
33
|
+
),
|
|
34
|
+
),
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
#jobCallbackFunction(
|
|
39
|
+
callbackFunction: (
|
|
40
|
+
message: XodBaseMessageType,
|
|
41
|
+
) => Promise<KafkaCallbackResponse>,
|
|
42
|
+
) {
|
|
43
|
+
return async (m: XodBaseMessageType): Promise<KafkaCallbackResponse> => {
|
|
44
|
+
if (m.type !== 'JOB') {
|
|
45
|
+
return callbackFunction(m);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const message = m as XodJobType;
|
|
49
|
+
const action = this.#connectorSDK.receiver.getActionConfig(message);
|
|
50
|
+
if (!action) {
|
|
51
|
+
return this.#connectorSDK.receiver.responses.badRequest(
|
|
52
|
+
'Action configuration not found',
|
|
53
|
+
)(message);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
this.#connectorSDK.logger.debug(
|
|
58
|
+
`Apply templates on payload: ${JSON.stringify(message.payload)}, action: ${JSON.stringify(action)}`,
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const handleBars = action.config['parsedTemplates'] as {
|
|
62
|
+
action: CompileDelegate;
|
|
63
|
+
params: CompileDelegate;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const parsedAction = handleBars
|
|
67
|
+
.action({
|
|
68
|
+
inputs: message.payload,
|
|
69
|
+
})
|
|
70
|
+
.trim();
|
|
71
|
+
|
|
72
|
+
const parsedParams = handleBars
|
|
73
|
+
.params({
|
|
74
|
+
inputs: message.payload,
|
|
75
|
+
})
|
|
76
|
+
.trim();
|
|
77
|
+
|
|
78
|
+
if (message.testRun) {
|
|
79
|
+
this.#connectorSDK.logger.info(
|
|
80
|
+
`Test run for ${message.eventId} with payload ${parsedParams} to action ${parsedAction}`,
|
|
81
|
+
);
|
|
82
|
+
return callbackFunction(message);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
this.#connectorSDK.logger.debug(
|
|
86
|
+
`Parsed action: ${parsedAction}, parameters: ${parsedParams}`,
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const parsedParamsJson = JSON.parse(parsedParams);
|
|
90
|
+
this.#connectorSDK.logger.debug(
|
|
91
|
+
`Parsed params json: ${JSON.stringify(parsedParamsJson)}`,
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
switch (parsedAction) {
|
|
95
|
+
case 'REPLY':
|
|
96
|
+
await this.#mailClient.reply(
|
|
97
|
+
parsedParamsJson.messageId,
|
|
98
|
+
parsedParamsJson.from,
|
|
99
|
+
parsedParamsJson.mailBody,
|
|
100
|
+
true,
|
|
101
|
+
);
|
|
102
|
+
break;
|
|
103
|
+
case 'FORWARD':
|
|
104
|
+
// this.#mailClient.forward(parsedParams);
|
|
105
|
+
break;
|
|
106
|
+
case 'SEND':
|
|
107
|
+
// this.#mailClient.send(parsedParams);
|
|
108
|
+
break;
|
|
109
|
+
case 'CATEGORY_ADD':
|
|
110
|
+
await this.#mailClient.addCategory(
|
|
111
|
+
parsedParamsJson.messageId,
|
|
112
|
+
parsedParamsJson.category,
|
|
113
|
+
);
|
|
114
|
+
break;
|
|
115
|
+
case 'CATEGORY_REMOVE':
|
|
116
|
+
await this.#mailClient.removeCategory(
|
|
117
|
+
parsedParamsJson.messageId,
|
|
118
|
+
parsedParamsJson.category,
|
|
119
|
+
);
|
|
120
|
+
break;
|
|
121
|
+
default:
|
|
122
|
+
this.#connectorSDK.logger.error(
|
|
123
|
+
`Unknown action type: ${parsedAction} in message ${message.eventId}`,
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return callbackFunction(message);
|
|
128
|
+
} catch (error: unknown) {
|
|
129
|
+
return this.#connectorSDK.receiver.responses.internalServerError(
|
|
130
|
+
error instanceof Error ? error.message : 'Unknown error occurred',
|
|
131
|
+
)(message);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
#actionCallbackFunction(
|
|
137
|
+
callbackFunction: (
|
|
138
|
+
message: XodBaseMessageType,
|
|
139
|
+
) => Promise<KafkaCallbackResponse>,
|
|
140
|
+
) {
|
|
141
|
+
return async (m: XodBaseMessageType): Promise<KafkaCallbackResponse> => {
|
|
142
|
+
if (m.type !== 'ACTION') {
|
|
143
|
+
return callbackFunction(m);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const message = m as XodActionType;
|
|
147
|
+
try {
|
|
148
|
+
if (!message.payload.destination || !message.payload.content) {
|
|
149
|
+
return this.#connectorSDK.receiver.responses.badRequest(
|
|
150
|
+
'Destination or content not found',
|
|
151
|
+
)(message);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// her comes the action handling logic
|
|
155
|
+
const result = { success: true, data: 'Not implemented yet' };
|
|
156
|
+
|
|
157
|
+
if (result.success) {
|
|
158
|
+
return callbackFunction(message);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return this.#connectorSDK.receiver.responses.internalServerError(
|
|
162
|
+
result.data,
|
|
163
|
+
)(message);
|
|
164
|
+
} catch (error) {
|
|
165
|
+
return this.#connectorSDK.receiver.responses.internalServerError(
|
|
166
|
+
error instanceof Error ? error.message : 'Unknown error occurred',
|
|
167
|
+
)(message);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { ConnectorSDKInterface } from '@transai/connector-runtime-sdk';
|
|
2
|
+
import { ConnectorInterface } from '@xip-online-data/types';
|
|
3
|
+
|
|
4
|
+
import { ConnectorRunnerMicrosoftOffice365Email } from './connector-runner-microsoft-office365-email';
|
|
5
|
+
import { MailProcessor } from './mail-processor';
|
|
6
|
+
import { ConnectorConfig } from './types';
|
|
7
|
+
|
|
8
|
+
describe('ConnectorRunnerMicrosoftOffice365Email', () => {
|
|
9
|
+
let connector: ConnectorRunnerMicrosoftOffice365Email;
|
|
10
|
+
|
|
11
|
+
let sdkMock: ConnectorSDKInterface;
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
sdkMock = {
|
|
15
|
+
logger: {
|
|
16
|
+
warn: jest.fn(),
|
|
17
|
+
info: jest.fn(),
|
|
18
|
+
debug: jest.fn(),
|
|
19
|
+
error: jest.fn(),
|
|
20
|
+
},
|
|
21
|
+
config: {
|
|
22
|
+
mailConfig: {
|
|
23
|
+
username: 'some-tenant',
|
|
24
|
+
tenantId: 'some-id',
|
|
25
|
+
clientId: 'some-client-id',
|
|
26
|
+
clientSecret: 'some-client-secret',
|
|
27
|
+
},
|
|
28
|
+
mailboxes: [
|
|
29
|
+
{
|
|
30
|
+
mailboxIdentifier: 'inbox-1',
|
|
31
|
+
mailbox: 'mailbox',
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
} as ConnectorConfig,
|
|
35
|
+
receiver: {
|
|
36
|
+
emitEventType: jest.fn(),
|
|
37
|
+
responses: {
|
|
38
|
+
created: jest.fn(),
|
|
39
|
+
},
|
|
40
|
+
registerCallback: jest.fn(),
|
|
41
|
+
},
|
|
42
|
+
processing: {
|
|
43
|
+
registerInterval: jest.fn(),
|
|
44
|
+
},
|
|
45
|
+
} as unknown as ConnectorSDKInterface<ConnectorConfig>;
|
|
46
|
+
|
|
47
|
+
connector = new ConnectorRunnerMicrosoftOffice365Email(
|
|
48
|
+
{} as ConnectorInterface,
|
|
49
|
+
sdkMock,
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('should be defined', () => {
|
|
54
|
+
expect(connector).toBeDefined();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('start', () => {
|
|
58
|
+
it('should start the connector', async () => {
|
|
59
|
+
await expect(connector.start()).resolves.toBeUndefined();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('should register interval for each mailbox', async () => {
|
|
63
|
+
await connector.init();
|
|
64
|
+
|
|
65
|
+
expect(sdkMock.processing.registerInterval).toHaveBeenCalledWith(
|
|
66
|
+
expect.any(Number),
|
|
67
|
+
expect.any(Object),
|
|
68
|
+
{ immediate: true },
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('should build correct mail processor', async () => {
|
|
73
|
+
sdkMock.processing.registerInterval = jest
|
|
74
|
+
.fn()
|
|
75
|
+
.mockImplementation((interval, processor) => {
|
|
76
|
+
expect(processor).toBeInstanceOf(MailProcessor);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
await connector.start();
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ConnectorRuntimeSDK,
|
|
3
|
+
ConnectorSDKInterface,
|
|
4
|
+
} from '@transai/connector-runtime-sdk';
|
|
5
|
+
import { MailClient } from '@xip-online-data/microsoft-office365-mail-client';
|
|
6
|
+
import { ConnectorInterface } from '@xip-online-data/types';
|
|
7
|
+
|
|
8
|
+
import { ActionsHandler } from './actions-handler';
|
|
9
|
+
import { MailProcessor } from './mail-processor';
|
|
10
|
+
import { ConnectorConfig } from './types';
|
|
11
|
+
|
|
12
|
+
export class ConnectorRunnerMicrosoftOffice365Email extends ConnectorRuntimeSDK<ConnectorConfig> {
|
|
13
|
+
readonly #mailClient: MailClient;
|
|
14
|
+
|
|
15
|
+
readonly #actionsHandler: ActionsHandler;
|
|
16
|
+
|
|
17
|
+
constructor(
|
|
18
|
+
connector: ConnectorInterface,
|
|
19
|
+
connectorSDK: ConnectorSDKInterface,
|
|
20
|
+
) {
|
|
21
|
+
super(connector, connectorSDK);
|
|
22
|
+
|
|
23
|
+
const { config } = this.connectorSDK;
|
|
24
|
+
this.#mailClient = new MailClient(config.mailConfig);
|
|
25
|
+
|
|
26
|
+
this.#actionsHandler = new ActionsHandler(
|
|
27
|
+
this.connectorSDK,
|
|
28
|
+
this.#mailClient,
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
this.callbackFunction = this.#actionsHandler.callbackFunctionChain;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
override init = async (): Promise<void> => {
|
|
35
|
+
const { config } = this.connectorSDK;
|
|
36
|
+
|
|
37
|
+
await Promise.all(
|
|
38
|
+
config.mailboxes.map(async (mailSourceConfig) => {
|
|
39
|
+
const mailProcessor = new MailProcessor(
|
|
40
|
+
this.connectorSDK,
|
|
41
|
+
mailSourceConfig,
|
|
42
|
+
this.#mailClient,
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
await this.connectorSDK.processing.registerInterval(
|
|
46
|
+
mailSourceConfig.interval ?? mailProcessor.DEFAULT_INTERVAL_SECONDS,
|
|
47
|
+
mailProcessor,
|
|
48
|
+
{ immediate: true },
|
|
49
|
+
);
|
|
50
|
+
}),
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
}
|