@aloma.io/integration-sdk 3.8.70 → 3.8.71
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 +15 -2
- package/build/internal/connector/server/on-connect/make-oauth.mjs +27 -6
- package/build/internal/fetcher/fetcher.d.mts +14 -1
- package/build/internal/fetcher/fetcher.mjs +52 -11
- package/build/internal/fetcher/oauth-fetcher.d.mts +15 -2
- package/build/internal/fetcher/oauth-fetcher.mjs +72 -27
- package/build/internal/util/index.d.mts +8 -0
- package/build/internal/util/index.mjs +13 -1
- package/build/internal/util/jwe/index.mjs +3 -1
- package/package.json +8 -3
- package/.prettierrc.cjs +0 -8
- package/FINDINGS-PLAT-47.md +0 -253
- package/MULTI_RESOURCE_GUIDE.md +0 -220
- package/OPENAPI_TO_CONNECTOR.md +0 -349
- package/examples/hello-world/package.json +0 -25
- package/examples/hello-world/src/controller/index.mts +0 -12
- package/examples/hello-world/src/index.mts +0 -6
- package/examples/hello-world/tsconfig.json +0 -27
- package/examples/sample-api.json +0 -325
- package/examples/sample-api.yaml +0 -222
- package/examples/simple-api.json +0 -39
- package/index.js +0 -4
- package/src/builder/index.mts +0 -274
- package/src/builder/runtime-context.mts +0 -129
- package/src/cli.mts +0 -533
- package/src/controller/index.mts +0 -278
- package/src/index.mts +0 -2
- package/src/internal/connector/config.mts +0 -59
- package/src/internal/connector/index.mts +0 -53
- package/src/internal/connector/metrics.mts +0 -34
- package/src/internal/connector/server/index.mts +0 -51
- package/src/internal/connector/server/on-connect/decrypt-config.mts +0 -27
- package/src/internal/connector/server/on-connect/finish-oauth.mts +0 -109
- package/src/internal/connector/server/on-connect/index.mts +0 -162
- package/src/internal/connector/server/on-connect/make-oauth.mts +0 -97
- package/src/internal/connector/server/on-connect/start-oauth.mts +0 -24
- package/src/internal/connector/server/on-message.mts +0 -13
- package/src/internal/dispatcher/index.mts +0 -231
- package/src/internal/fetcher/fetcher.mts +0 -215
- package/src/internal/fetcher/oauth-fetcher.mts +0 -153
- package/src/internal/index.mts +0 -3
- package/src/internal/util/index.mts +0 -52
- package/src/internal/util/jwe/cli.mts +0 -12
- package/src/internal/util/jwe/index.mts +0 -72
- package/src/internal/websocket/config.mjs +0 -109
- package/src/internal/websocket/connection/constants.mjs +0 -25
- package/src/internal/websocket/connection/index.mjs +0 -71
- package/src/internal/websocket/connection/registration.mjs +0 -42
- package/src/internal/websocket/index.mjs +0 -46
- package/src/internal/websocket/transport/durable.mjs +0 -71
- package/src/internal/websocket/transport/index.mjs +0 -194
- package/src/internal/websocket/transport/packet.mjs +0 -54
- package/src/internal/websocket/transport/processor.mjs +0 -66
- package/src/openapi-to-connector.mts +0 -1648
- package/src/testing/fake-aloma.mts +0 -306
- package/src/testing/harness.mts +0 -172
- package/src/testing/index.mts +0 -15
- package/src/testing/keys.mts +0 -19
- package/src/testing/network-guard.mts +0 -57
- package/src/testing/runtime-connector.mts +0 -50
- package/src/testing/vendor-mock.mts +0 -166
- package/src/transform/index.mts +0 -544
- package/test/MUTATION-entry.md +0 -21
- package/test/MUTATION.md +0 -43
- package/test/dispatcher-ctx-forwarding.test.mjs +0 -161
- package/test/fetcher-query-params.test.mjs +0 -294
- package/test/fixtures/transform/basic/expected.json +0 -9
- package/test/fixtures/transform/basic/src/controller/abstract.mts +0 -5
- package/test/fixtures/transform/basic/src/controller/index.mts +0 -30
- package/test/fixtures/transform/basic/tsconfig.json +0 -1
- package/test/fixtures/transform/interface-param/src/controller/abstract.mts +0 -5
- package/test/fixtures/transform/interface-param/src/controller/index.mts +0 -12
- package/test/fixtures/transform/interface-param/tsconfig.json +0 -1
- package/test/fixtures/transform/overloads/expected.json +0 -6
- package/test/fixtures/transform/overloads/src/controller/abstract.mts +0 -5
- package/test/fixtures/transform/overloads/src/controller/index.mts +0 -11
- package/test/fixtures/transform/overloads/tsconfig.json +0 -1
- package/test/fixtures/transform/tdd-stub/expected.json +0 -8
- package/test/fixtures/transform/tdd-stub/src/controller/abstract.mts +0 -6
- package/test/fixtures/transform/tdd-stub/src/controller/index.mts +0 -204
- package/test/fixtures/transform/tdd-stub/tsconfig.json +0 -1
- package/test/fixtures/transform/two-exports/src/controller/abstract.mts +0 -5
- package/test/fixtures/transform/two-exports/src/controller/index.mts +0 -9
- package/test/fixtures/transform/two-exports/tsconfig.json +0 -1
- package/test/fixtures/transform/type-error/src/controller/abstract.mts +0 -5
- package/test/fixtures/transform/type-error/src/controller/index.mts +0 -7
- package/test/fixtures/transform/type-error/tsconfig.json +0 -1
- package/test/fixtures/transform/typed/expected.json +0 -8
- package/test/fixtures/transform/typed/src/controller/abstract.mts +0 -5
- package/test/fixtures/transform/typed/src/controller/index.mts +0 -13
- package/test/fixtures/transform/typed/tsconfig.json +0 -1
- package/test/fixtures/transform/visibility/expected.json +0 -9
- package/test/fixtures/transform/visibility/src/controller/abstract.mts +0 -5
- package/test/fixtures/transform/visibility/src/controller/index.mts +0 -19
- package/test/fixtures/transform/visibility/tsconfig.json +0 -1
- package/test/harness-connector-smoke.test.mjs +0 -72
- package/test/harness.test.mjs +0 -375
- package/test/nested-resolver.test.mjs +0 -184
- package/test/openapi-generator-bugs.test.mjs +0 -248
- package/test/openapi-identifier-sanitise.test.mjs +0 -69
- package/test/openapi-nested-paths.test.mjs +0 -100
- package/test/openapi-to-connector.test.mts +0 -232
- package/test/openapi-ts-compilation.test.mjs +0 -178
- package/test/scenarios/README.md +0 -148
- package/test/scenarios/complex/expected/controller.mts +0 -271
- package/test/scenarios/complex/expected/orders-resource.mts +0 -262
- package/test/scenarios/complex/expected/products-resource.mts +0 -237
- package/test/scenarios/complex/specs/orders.json +0 -362
- package/test/scenarios/complex/specs/products.json +0 -308
- package/test/scenarios/simple/expected-controller.mts +0 -60
- package/test/scenarios/simple/simple-api.json +0 -39
- package/test/scenarios.test.mts +0 -294
- package/test/transform.test.mjs +0 -68
- package/test/verify-scenarios.mjs +0 -298
- package/tools/mutation-run-entry.mjs +0 -52
- package/tools/mutation-run.mjs +0 -138
- package/tools/run-tests.mjs +0 -64
- package/tsconfig.json +0 -27
package/src/controller/index.mts
DELETED
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
import {ConfigField} from '../index.mjs';
|
|
2
|
-
import Fetcher from '../internal/fetcher/fetcher.mjs';
|
|
3
|
-
import {OAuth} from '../internal/fetcher/oauth-fetcher.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Abstract controller class
|
|
7
|
-
* this needs to be used in a connector
|
|
8
|
-
*/
|
|
9
|
-
export abstract class AbstractController {
|
|
10
|
-
/**
|
|
11
|
-
* connector configuration
|
|
12
|
-
*/
|
|
13
|
-
protected config: {[key: string]: any} = {};
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @deprecated
|
|
17
|
-
*/
|
|
18
|
-
protected client: any;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* oauth data, if the connector is using oauth
|
|
22
|
-
*/
|
|
23
|
-
protected oauth?: OAuth;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* invoked, when the controller is started
|
|
27
|
-
*/
|
|
28
|
-
protected async start(): Promise<void> {}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* invoked, when the controller is stopped
|
|
32
|
-
* @param isShutdown true if the controller is stopped due to shutdown
|
|
33
|
-
*/
|
|
34
|
-
protected async stop(isShutdown: boolean = false): Promise<void> {}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* autocomplete configuration options
|
|
38
|
-
*
|
|
39
|
-
* e.g. if this connector is connected to a system which has multiple entities with dynamic attributes, like deals, ...
|
|
40
|
-
* then this method should return the possible attributes of the entity when invoked like
|
|
41
|
-
* ```javascript
|
|
42
|
-
* autocomplete({entity: 'deal'})
|
|
43
|
-
* ```
|
|
44
|
-
* @param arg
|
|
45
|
-
* @returns
|
|
46
|
-
*/
|
|
47
|
-
protected async autocomplete(arg: any): Promise<any> {
|
|
48
|
-
return Promise.resolve({});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* called, when the remote public method is not found on the controller
|
|
53
|
-
* @param arg
|
|
54
|
-
* @param ctx optional invocation context (taskId, namespace, sticky)
|
|
55
|
-
*/
|
|
56
|
-
protected fallback(arg: any, ctx?: any): Promise<any> {
|
|
57
|
-
throw new Error('method not found');
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* will be invoked, when the connector has an endpoint enabled
|
|
62
|
-
* will receive the data and can e.g. create a new task from it
|
|
63
|
-
* @param arg
|
|
64
|
-
*/
|
|
65
|
-
protected async endpoint(arg: any): Promise<any> {
|
|
66
|
-
throw new Error('method not found');
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* create a new task
|
|
71
|
-
* @param name name of the task
|
|
72
|
-
* @param data data of the task
|
|
73
|
-
*/
|
|
74
|
-
protected async newTask(name: string, data: any): Promise<string> {
|
|
75
|
-
throw new Error('not implemented');
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* get a client to make requests
|
|
80
|
-
* @param baseUrl base url of the client
|
|
81
|
-
* @param onResponse callback to be invoked on response
|
|
82
|
-
* @param customize callback to customize the request
|
|
83
|
-
*/
|
|
84
|
-
protected getClient({
|
|
85
|
-
baseUrl,
|
|
86
|
-
onResponse,
|
|
87
|
-
customize,
|
|
88
|
-
}: {
|
|
89
|
-
baseUrl?: string;
|
|
90
|
-
onResponse?: (response: any) => void;
|
|
91
|
-
customize?: (request: any) => void;
|
|
92
|
-
}): Fetcher {
|
|
93
|
-
throw new Error('not implemented');
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* update a task
|
|
98
|
-
* @param name name of the task
|
|
99
|
-
* @param data partial data of the task to update
|
|
100
|
-
* @returns taskId
|
|
101
|
-
*/
|
|
102
|
-
protected async updateTask(name: string, data: any): Promise<string> {
|
|
103
|
-
throw new Error('not implemented');
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* create a blob
|
|
108
|
-
* @param content content of the blob in base64
|
|
109
|
-
* @param name name of the blob
|
|
110
|
-
* @param size size of the blob
|
|
111
|
-
* @param mimetype mimetype of the blob
|
|
112
|
-
* @param meta meta data of the blob
|
|
113
|
-
* @param taskId id of the task
|
|
114
|
-
*/
|
|
115
|
-
protected async createBlob({
|
|
116
|
-
content,
|
|
117
|
-
name,
|
|
118
|
-
size,
|
|
119
|
-
mimetype,
|
|
120
|
-
meta,
|
|
121
|
-
taskId,
|
|
122
|
-
}: {
|
|
123
|
-
content: string;
|
|
124
|
-
name?: string;
|
|
125
|
-
size?: number;
|
|
126
|
-
mimetype?: string;
|
|
127
|
-
meta?: any;
|
|
128
|
-
taskId?: string;
|
|
129
|
-
}): Promise<string> {
|
|
130
|
-
throw new Error('not implemented');
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* get the metadata of a blob by id
|
|
135
|
-
* @param id blob id
|
|
136
|
-
*/
|
|
137
|
-
protected async getBlob(id: string): Promise<{
|
|
138
|
-
name?: string;
|
|
139
|
-
id;
|
|
140
|
-
size?: number;
|
|
141
|
-
mimetype?: string;
|
|
142
|
-
meta?: any;
|
|
143
|
-
}> {
|
|
144
|
-
throw new Error('not implemented');
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* get the content of a blob by id as base64
|
|
149
|
-
* @param id blob id
|
|
150
|
-
*/
|
|
151
|
-
protected async getBlobContent(id: string): Promise<string> {
|
|
152
|
-
throw new Error('not implemented');
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* health check, will be called periodically
|
|
157
|
-
* throw an error if unhealthy with a message describing what needs to be fixed
|
|
158
|
-
*/
|
|
159
|
-
protected async healthCheck(): Promise<any> {
|
|
160
|
-
// blank, throw an error if unhealthy
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* config check, will be called periodically
|
|
165
|
-
* throw an error if the config is not valid
|
|
166
|
-
*
|
|
167
|
-
* @param configSchema the schema of the config
|
|
168
|
-
*/
|
|
169
|
-
protected async configCheck(configSchema: {[key: string]: ConfigField}): Promise<void> {
|
|
170
|
-
// blank, throw an error if the config is not valid
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* @ignore
|
|
175
|
-
**/
|
|
176
|
-
async __endpoint(arg: any): Promise<any | null> {
|
|
177
|
-
return this.endpoint(arg);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* @ignore
|
|
182
|
-
**/
|
|
183
|
-
async __autocomplete(arg: any): Promise<any | null> {
|
|
184
|
-
return this.autocomplete(arg);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* @ignore
|
|
189
|
-
**/
|
|
190
|
-
async __default(arg: any, ctx?: any): Promise<any | null> {
|
|
191
|
-
return this.fallback(arg, ctx);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* @ignore
|
|
196
|
-
**/
|
|
197
|
-
async __healthCheck(configSchema: () => {[key: string]: ConfigField}): Promise<void> {
|
|
198
|
-
const errors: string[] = [];
|
|
199
|
-
const schema = configSchema();
|
|
200
|
-
const fields: any = schema.fields;
|
|
201
|
-
|
|
202
|
-
try {
|
|
203
|
-
await this.healthCheck();
|
|
204
|
-
} catch (e: any) {
|
|
205
|
-
errors.push(e.message);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
try {
|
|
209
|
-
await this.defaultConfigCheck(fields);
|
|
210
|
-
} catch (e: any) {
|
|
211
|
-
errors.push(e.message);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
try {
|
|
215
|
-
await this.configCheck(fields);
|
|
216
|
-
} catch (e: any) {
|
|
217
|
-
errors.push(e.message);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
if (errors.length) {
|
|
221
|
-
throw new Error(errors.join('\n'));
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* @ignore
|
|
227
|
-
**/
|
|
228
|
-
private async defaultConfigCheck(configSchema: {[key: string]: ConfigField}): Promise<void> {
|
|
229
|
-
const config = this.config;
|
|
230
|
-
|
|
231
|
-
const missing = Object.entries(configSchema)
|
|
232
|
-
.map(([key, field]) => {
|
|
233
|
-
if (!field) return;
|
|
234
|
-
|
|
235
|
-
if (!field.optional && config[key] == null) {
|
|
236
|
-
return `Configuration: ${field.name || key} is required`;
|
|
237
|
-
}
|
|
238
|
-
})
|
|
239
|
-
.filter((what) => !!what);
|
|
240
|
-
|
|
241
|
-
if (missing.length) {
|
|
242
|
-
throw new Error(missing.join('\n'));
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* @ignore
|
|
248
|
-
**/
|
|
249
|
-
async _doStart(
|
|
250
|
-
config: any,
|
|
251
|
-
oauth: any,
|
|
252
|
-
newTask: any,
|
|
253
|
-
updateTask: any,
|
|
254
|
-
getClient: any,
|
|
255
|
-
getBlob: any,
|
|
256
|
-
getBlobContent: any,
|
|
257
|
-
createBlob: any
|
|
258
|
-
): Promise<void> {
|
|
259
|
-
this.config = config;
|
|
260
|
-
this.client = oauth;
|
|
261
|
-
this.oauth = oauth;
|
|
262
|
-
this.newTask = newTask;
|
|
263
|
-
this.updateTask = updateTask;
|
|
264
|
-
this.getClient = getClient;
|
|
265
|
-
this.createBlob = createBlob;
|
|
266
|
-
this.getBlob = getBlob;
|
|
267
|
-
this.getBlobContent = getBlobContent;
|
|
268
|
-
|
|
269
|
-
await this.start();
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* @ignore
|
|
274
|
-
**/
|
|
275
|
-
async _doStop(isShutdown: boolean = false): Promise<void> {
|
|
276
|
-
await this.stop(isShutdown);
|
|
277
|
-
}
|
|
278
|
-
}
|
package/src/index.mts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import JWE from '../util/jwe/index.mjs';
|
|
2
|
-
import {Config} from '../websocket/config.mjs';
|
|
3
|
-
|
|
4
|
-
export const makeConfig = async ({id, version, name, introspect, configSchema, icon}): Promise<Config> => {
|
|
5
|
-
const config = new Config({
|
|
6
|
-
id: id,
|
|
7
|
-
version: version,
|
|
8
|
-
name: process.env.HOSTNAME || name,
|
|
9
|
-
registrationToken: process.env.REGISTRATION_TOKEN,
|
|
10
|
-
endpoint: process.env.DEVICE_ENDPOINT || 'https://connect.aloma.io/',
|
|
11
|
-
wsEndpoint: process.env.WEBSOCKET_ENDPOINT || 'wss://connect.aloma.io/transport/',
|
|
12
|
-
privateKey: process.env.PRIVATE_KEY,
|
|
13
|
-
publicKey: process.env.PUBLIC_KEY,
|
|
14
|
-
introspect,
|
|
15
|
-
configSchema,
|
|
16
|
-
icon: icon,
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
if (Object.keys(configSchema().fields).length) {
|
|
20
|
-
try {
|
|
21
|
-
await config.validateKeys();
|
|
22
|
-
} catch (e) {
|
|
23
|
-
const haveKey = !!process.env.PRIVATE_KEY;
|
|
24
|
-
const jwe = new JWE({});
|
|
25
|
-
var text = 'Please double check the env variables';
|
|
26
|
-
|
|
27
|
-
if (!haveKey) {
|
|
28
|
-
await jwe.newPair();
|
|
29
|
-
text =
|
|
30
|
-
'fresh keys generated, set environment variables: \n\nPRIVATE_KEY: ' +
|
|
31
|
-
(await jwe.exportPrivateAsBase64()) +
|
|
32
|
-
'\n\nPUBLIC_KEY: ' +
|
|
33
|
-
(await jwe.exportPublicAsBase64()) +
|
|
34
|
-
'\n';
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
console.log(`
|
|
38
|
-
Error:
|
|
39
|
-
|
|
40
|
-
public (env.PUBLIC_KEY) and private key (env.PRIVATE_KEY) could not be loaded.
|
|
41
|
-
|
|
42
|
-
${text}
|
|
43
|
-
`);
|
|
44
|
-
|
|
45
|
-
await new Promise((resolve) => {
|
|
46
|
-
setTimeout(
|
|
47
|
-
() => {
|
|
48
|
-
resolve(null);
|
|
49
|
-
},
|
|
50
|
-
2 * 60 * 1000
|
|
51
|
-
);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
throw new Error('could not start');
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return config;
|
|
59
|
-
};
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import {Dispatcher} from '../dispatcher/index.mjs';
|
|
2
|
-
import {makeConfig} from './config.mjs';
|
|
3
|
-
import {makeMetrics} from './metrics.mjs';
|
|
4
|
-
import {makeServer} from './server/index.mjs';
|
|
5
|
-
|
|
6
|
-
export class Connector {
|
|
7
|
-
id: any;
|
|
8
|
-
version: any;
|
|
9
|
-
name: any;
|
|
10
|
-
icon: any;
|
|
11
|
-
dispatcher!: Dispatcher;
|
|
12
|
-
constructor({version, id, name, icon}) {
|
|
13
|
-
this.id = id;
|
|
14
|
-
this.version = version;
|
|
15
|
-
this.name = name;
|
|
16
|
-
this.icon = icon;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
configure() {
|
|
20
|
-
return (this.dispatcher = new Dispatcher());
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async run() {
|
|
24
|
-
console.log(`Running ${this.name}`);
|
|
25
|
-
|
|
26
|
-
const {processPacket, start, introspect, configSchema} = this.dispatcher.build();
|
|
27
|
-
|
|
28
|
-
const config = await makeConfig({
|
|
29
|
-
id: this.id,
|
|
30
|
-
version: this.version,
|
|
31
|
-
name: this.name,
|
|
32
|
-
introspect,
|
|
33
|
-
configSchema,
|
|
34
|
-
icon: this.icon,
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
await makeMetrics({
|
|
38
|
-
id: this.id,
|
|
39
|
-
name: this.name,
|
|
40
|
-
version: this.version,
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
const server = await makeServer({
|
|
44
|
-
config,
|
|
45
|
-
configSchema,
|
|
46
|
-
start,
|
|
47
|
-
processPacket,
|
|
48
|
-
dispatcher: this.dispatcher,
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
await server.start();
|
|
52
|
-
}
|
|
53
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import express from 'express';
|
|
2
|
-
import PromClient from 'prom-client';
|
|
3
|
-
|
|
4
|
-
export const makeMetrics = async ({id, name, version}): Promise<void> => {
|
|
5
|
-
const newMetrics = () => {
|
|
6
|
-
const metrics = PromClient;
|
|
7
|
-
|
|
8
|
-
const defaultLabels = {
|
|
9
|
-
service: name,
|
|
10
|
-
connectorId: id,
|
|
11
|
-
connectorVersion: version,
|
|
12
|
-
node: process.env.HOSTNAME || 'test',
|
|
13
|
-
};
|
|
14
|
-
metrics.register.setDefaultLabels(defaultLabels);
|
|
15
|
-
metrics.collectDefaultMetrics();
|
|
16
|
-
|
|
17
|
-
return metrics;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const makeMetricsServer = (metrics) => {
|
|
21
|
-
const app = express();
|
|
22
|
-
|
|
23
|
-
app.get('/metrics', async (request, response, next) => {
|
|
24
|
-
response.status(200);
|
|
25
|
-
response.set('Content-type', metrics.contentType);
|
|
26
|
-
response.send(await metrics.register.metrics());
|
|
27
|
-
response.end();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
return app;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
makeMetricsServer(newMetrics()).listen(4050, '0.0.0.0');
|
|
34
|
-
};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import Dispatcher from '../../dispatcher/index.mjs';
|
|
2
|
-
import {Config} from '../../websocket/config.mjs';
|
|
3
|
-
import {WebsocketConnector} from '../../websocket/index.mjs';
|
|
4
|
-
import {onConnect} from './on-connect/index.mjs';
|
|
5
|
-
import {onMessage} from './on-message.mjs';
|
|
6
|
-
|
|
7
|
-
export const makeServer = async ({
|
|
8
|
-
config,
|
|
9
|
-
configSchema,
|
|
10
|
-
start,
|
|
11
|
-
processPacket,
|
|
12
|
-
dispatcher,
|
|
13
|
-
}: {
|
|
14
|
-
config: Config;
|
|
15
|
-
configSchema: any;
|
|
16
|
-
start: any;
|
|
17
|
-
processPacket: any;
|
|
18
|
-
dispatcher: Dispatcher;
|
|
19
|
-
}): Promise<WebsocketConnector> => {
|
|
20
|
-
const server = new WebsocketConnector({
|
|
21
|
-
config,
|
|
22
|
-
onConnect: onConnect({config, configSchema, dispatcher, start}),
|
|
23
|
-
onMessage: onMessage(processPacket),
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
const term = async () => {
|
|
27
|
-
await server.leaving();
|
|
28
|
-
|
|
29
|
-
await new Promise((resolve) => {
|
|
30
|
-
setTimeout(async () => {
|
|
31
|
-
await server.close();
|
|
32
|
-
resolve(null);
|
|
33
|
-
}, 10000);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
process.exit(0);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
process.on('uncaughtException', (e) => {
|
|
40
|
-
console.log(e);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
process.on('unhandledRejection', (e) => {
|
|
44
|
-
console.log(e);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
process.on('SIGTERM', term);
|
|
48
|
-
process.on('SIGINT', term);
|
|
49
|
-
|
|
50
|
-
return server;
|
|
51
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export const decryptConfig = async ({configSchema, config, secrets}) => {
|
|
2
|
-
const decrypted: any = {};
|
|
3
|
-
|
|
4
|
-
const fields = configSchema().fields;
|
|
5
|
-
|
|
6
|
-
const keys = Object.keys(secrets);
|
|
7
|
-
const jwe = await config.validateKeys('RSA-OAEP-256');
|
|
8
|
-
|
|
9
|
-
for (var i = 0; i < keys.length; ++i) {
|
|
10
|
-
const key = keys[i];
|
|
11
|
-
const value = secrets[key];
|
|
12
|
-
if (!value) continue;
|
|
13
|
-
|
|
14
|
-
if (fields[key]?.plain || ['endpointUrl'].includes(key)) {
|
|
15
|
-
decrypted[key] = value;
|
|
16
|
-
} else {
|
|
17
|
-
try {
|
|
18
|
-
decrypted[key] = await jwe.decrypt(value, config.id());
|
|
19
|
-
} catch (e) {
|
|
20
|
-
const errorMsg = String(e).replaceAll(value, '***');
|
|
21
|
-
console.log('failed to decrypt key', key, config.id(), errorMsg);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return decrypted;
|
|
27
|
-
};
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import Dispatcher from '../../../dispatcher/index.mjs';
|
|
2
|
-
import {Config} from '../../../websocket/config.mjs';
|
|
3
|
-
import {WebsocketConnector} from '../../../websocket/index.mjs';
|
|
4
|
-
|
|
5
|
-
export const patchFinishOAuth = async ({
|
|
6
|
-
dispatcher,
|
|
7
|
-
decrypted,
|
|
8
|
-
config,
|
|
9
|
-
transport,
|
|
10
|
-
}: {
|
|
11
|
-
dispatcher: Dispatcher;
|
|
12
|
-
decrypted: any;
|
|
13
|
-
config: Config;
|
|
14
|
-
transport: WebsocketConnector;
|
|
15
|
-
}) => {
|
|
16
|
-
dispatcher.finishOAuth = async function (arg: {
|
|
17
|
-
code: string;
|
|
18
|
-
redirectURI: string;
|
|
19
|
-
codeVerifier?: string;
|
|
20
|
-
}): Promise<{value: string}> {
|
|
21
|
-
const tokenURL = process.env.OAUTH_TOKEN_URL || decrypted.tokenURL || dispatcher._oauth.tokenURL;
|
|
22
|
-
|
|
23
|
-
if (!dispatcher._oauth) throw new Error('oauth not configured');
|
|
24
|
-
if (!tokenURL && !dispatcher._oauth.finishOAuth) throw new Error('need tokenURL or finishOAuth(arg)');
|
|
25
|
-
|
|
26
|
-
var data = null;
|
|
27
|
-
|
|
28
|
-
const doFinish = async () => {
|
|
29
|
-
if (!arg.code || !arg.redirectURI) throw new Error('need code and redirectUri');
|
|
30
|
-
|
|
31
|
-
const clientId = decrypted.clientId || process.env.OAUTH_CLIENT_ID || dispatcher._oauth.clientId;
|
|
32
|
-
|
|
33
|
-
if (!clientId) throw new Error('clientId not configured');
|
|
34
|
-
|
|
35
|
-
const clientSecret = decrypted.clientSecret || process.env.OAUTH_CLIENT_SECRET || dispatcher._oauth.clientSecret;
|
|
36
|
-
if (!clientSecret) throw new Error('clientSecret not configured');
|
|
37
|
-
|
|
38
|
-
const additionalTokenArgs = dispatcher._oauth.additionalTokenArgs || {};
|
|
39
|
-
const useAuthHeader = !!dispatcher._oauth.useAuthHeader;
|
|
40
|
-
const useCodeChallenge = !!dispatcher._oauth.useCodeChallenge;
|
|
41
|
-
|
|
42
|
-
let body = {
|
|
43
|
-
grant_type: 'authorization_code',
|
|
44
|
-
...additionalTokenArgs,
|
|
45
|
-
code: arg.code,
|
|
46
|
-
redirect_uri: arg.redirectURI,
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
if (useCodeChallenge) {
|
|
50
|
-
body.code_verifier = arg.codeVerifier;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
let headers: any = {
|
|
54
|
-
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
|
|
55
|
-
Accept: 'application/json',
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
if (useAuthHeader) {
|
|
59
|
-
headers = {
|
|
60
|
-
...headers,
|
|
61
|
-
Authorization: `Basic ${btoa(`${clientId}:${clientSecret}`)}`,
|
|
62
|
-
};
|
|
63
|
-
} else {
|
|
64
|
-
body = {
|
|
65
|
-
...body,
|
|
66
|
-
client_id: clientId,
|
|
67
|
-
client_secret: clientSecret,
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const response = await fetch(tokenURL, {
|
|
72
|
-
method: 'POST',
|
|
73
|
-
body: new URLSearchParams(body),
|
|
74
|
-
headers,
|
|
75
|
-
signal: AbortSignal.timeout(60 * 1000),
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
const status = await response.status;
|
|
79
|
-
const text = await response.text();
|
|
80
|
-
|
|
81
|
-
if (status === 200) {
|
|
82
|
-
const ret = JSON.parse(text);
|
|
83
|
-
if (ret.error) {
|
|
84
|
-
throw new Error(`${status} ${ret.error} ${ret.error_description || ''}`);
|
|
85
|
-
} else if (ret.access_token) {
|
|
86
|
-
return {...ret};
|
|
87
|
-
} else {
|
|
88
|
-
throw new Error(status + ' response has no access_token - ' + text);
|
|
89
|
-
}
|
|
90
|
-
} else {
|
|
91
|
-
throw new Error(status + ' ' + text);
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
if (dispatcher._oauth.finishOAuth) {
|
|
96
|
-
data = await dispatcher._oauth.finishOAuth({
|
|
97
|
-
arg,
|
|
98
|
-
doFinish,
|
|
99
|
-
transport,
|
|
100
|
-
});
|
|
101
|
-
} else {
|
|
102
|
-
data = await doFinish();
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const jwe = await config.validateKeys('RSA-OAEP-256');
|
|
106
|
-
|
|
107
|
-
return {value: await jwe.encrypt(data, 'none', config.id())};
|
|
108
|
-
};
|
|
109
|
-
};
|