@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.
Files changed (118) hide show
  1. package/README.md +15 -2
  2. package/build/internal/connector/server/on-connect/make-oauth.mjs +27 -6
  3. package/build/internal/fetcher/fetcher.d.mts +14 -1
  4. package/build/internal/fetcher/fetcher.mjs +52 -11
  5. package/build/internal/fetcher/oauth-fetcher.d.mts +15 -2
  6. package/build/internal/fetcher/oauth-fetcher.mjs +72 -27
  7. package/build/internal/util/index.d.mts +8 -0
  8. package/build/internal/util/index.mjs +13 -1
  9. package/build/internal/util/jwe/index.mjs +3 -1
  10. package/package.json +8 -3
  11. package/.prettierrc.cjs +0 -8
  12. package/FINDINGS-PLAT-47.md +0 -253
  13. package/MULTI_RESOURCE_GUIDE.md +0 -220
  14. package/OPENAPI_TO_CONNECTOR.md +0 -349
  15. package/examples/hello-world/package.json +0 -25
  16. package/examples/hello-world/src/controller/index.mts +0 -12
  17. package/examples/hello-world/src/index.mts +0 -6
  18. package/examples/hello-world/tsconfig.json +0 -27
  19. package/examples/sample-api.json +0 -325
  20. package/examples/sample-api.yaml +0 -222
  21. package/examples/simple-api.json +0 -39
  22. package/index.js +0 -4
  23. package/src/builder/index.mts +0 -274
  24. package/src/builder/runtime-context.mts +0 -129
  25. package/src/cli.mts +0 -533
  26. package/src/controller/index.mts +0 -278
  27. package/src/index.mts +0 -2
  28. package/src/internal/connector/config.mts +0 -59
  29. package/src/internal/connector/index.mts +0 -53
  30. package/src/internal/connector/metrics.mts +0 -34
  31. package/src/internal/connector/server/index.mts +0 -51
  32. package/src/internal/connector/server/on-connect/decrypt-config.mts +0 -27
  33. package/src/internal/connector/server/on-connect/finish-oauth.mts +0 -109
  34. package/src/internal/connector/server/on-connect/index.mts +0 -162
  35. package/src/internal/connector/server/on-connect/make-oauth.mts +0 -97
  36. package/src/internal/connector/server/on-connect/start-oauth.mts +0 -24
  37. package/src/internal/connector/server/on-message.mts +0 -13
  38. package/src/internal/dispatcher/index.mts +0 -231
  39. package/src/internal/fetcher/fetcher.mts +0 -215
  40. package/src/internal/fetcher/oauth-fetcher.mts +0 -153
  41. package/src/internal/index.mts +0 -3
  42. package/src/internal/util/index.mts +0 -52
  43. package/src/internal/util/jwe/cli.mts +0 -12
  44. package/src/internal/util/jwe/index.mts +0 -72
  45. package/src/internal/websocket/config.mjs +0 -109
  46. package/src/internal/websocket/connection/constants.mjs +0 -25
  47. package/src/internal/websocket/connection/index.mjs +0 -71
  48. package/src/internal/websocket/connection/registration.mjs +0 -42
  49. package/src/internal/websocket/index.mjs +0 -46
  50. package/src/internal/websocket/transport/durable.mjs +0 -71
  51. package/src/internal/websocket/transport/index.mjs +0 -194
  52. package/src/internal/websocket/transport/packet.mjs +0 -54
  53. package/src/internal/websocket/transport/processor.mjs +0 -66
  54. package/src/openapi-to-connector.mts +0 -1648
  55. package/src/testing/fake-aloma.mts +0 -306
  56. package/src/testing/harness.mts +0 -172
  57. package/src/testing/index.mts +0 -15
  58. package/src/testing/keys.mts +0 -19
  59. package/src/testing/network-guard.mts +0 -57
  60. package/src/testing/runtime-connector.mts +0 -50
  61. package/src/testing/vendor-mock.mts +0 -166
  62. package/src/transform/index.mts +0 -544
  63. package/test/MUTATION-entry.md +0 -21
  64. package/test/MUTATION.md +0 -43
  65. package/test/dispatcher-ctx-forwarding.test.mjs +0 -161
  66. package/test/fetcher-query-params.test.mjs +0 -294
  67. package/test/fixtures/transform/basic/expected.json +0 -9
  68. package/test/fixtures/transform/basic/src/controller/abstract.mts +0 -5
  69. package/test/fixtures/transform/basic/src/controller/index.mts +0 -30
  70. package/test/fixtures/transform/basic/tsconfig.json +0 -1
  71. package/test/fixtures/transform/interface-param/src/controller/abstract.mts +0 -5
  72. package/test/fixtures/transform/interface-param/src/controller/index.mts +0 -12
  73. package/test/fixtures/transform/interface-param/tsconfig.json +0 -1
  74. package/test/fixtures/transform/overloads/expected.json +0 -6
  75. package/test/fixtures/transform/overloads/src/controller/abstract.mts +0 -5
  76. package/test/fixtures/transform/overloads/src/controller/index.mts +0 -11
  77. package/test/fixtures/transform/overloads/tsconfig.json +0 -1
  78. package/test/fixtures/transform/tdd-stub/expected.json +0 -8
  79. package/test/fixtures/transform/tdd-stub/src/controller/abstract.mts +0 -6
  80. package/test/fixtures/transform/tdd-stub/src/controller/index.mts +0 -204
  81. package/test/fixtures/transform/tdd-stub/tsconfig.json +0 -1
  82. package/test/fixtures/transform/two-exports/src/controller/abstract.mts +0 -5
  83. package/test/fixtures/transform/two-exports/src/controller/index.mts +0 -9
  84. package/test/fixtures/transform/two-exports/tsconfig.json +0 -1
  85. package/test/fixtures/transform/type-error/src/controller/abstract.mts +0 -5
  86. package/test/fixtures/transform/type-error/src/controller/index.mts +0 -7
  87. package/test/fixtures/transform/type-error/tsconfig.json +0 -1
  88. package/test/fixtures/transform/typed/expected.json +0 -8
  89. package/test/fixtures/transform/typed/src/controller/abstract.mts +0 -5
  90. package/test/fixtures/transform/typed/src/controller/index.mts +0 -13
  91. package/test/fixtures/transform/typed/tsconfig.json +0 -1
  92. package/test/fixtures/transform/visibility/expected.json +0 -9
  93. package/test/fixtures/transform/visibility/src/controller/abstract.mts +0 -5
  94. package/test/fixtures/transform/visibility/src/controller/index.mts +0 -19
  95. package/test/fixtures/transform/visibility/tsconfig.json +0 -1
  96. package/test/harness-connector-smoke.test.mjs +0 -72
  97. package/test/harness.test.mjs +0 -375
  98. package/test/nested-resolver.test.mjs +0 -184
  99. package/test/openapi-generator-bugs.test.mjs +0 -248
  100. package/test/openapi-identifier-sanitise.test.mjs +0 -69
  101. package/test/openapi-nested-paths.test.mjs +0 -100
  102. package/test/openapi-to-connector.test.mts +0 -232
  103. package/test/openapi-ts-compilation.test.mjs +0 -178
  104. package/test/scenarios/README.md +0 -148
  105. package/test/scenarios/complex/expected/controller.mts +0 -271
  106. package/test/scenarios/complex/expected/orders-resource.mts +0 -262
  107. package/test/scenarios/complex/expected/products-resource.mts +0 -237
  108. package/test/scenarios/complex/specs/orders.json +0 -362
  109. package/test/scenarios/complex/specs/products.json +0 -308
  110. package/test/scenarios/simple/expected-controller.mts +0 -60
  111. package/test/scenarios/simple/simple-api.json +0 -39
  112. package/test/scenarios.test.mts +0 -294
  113. package/test/transform.test.mjs +0 -68
  114. package/test/verify-scenarios.mjs +0 -298
  115. package/tools/mutation-run-entry.mjs +0 -52
  116. package/tools/mutation-run.mjs +0 -138
  117. package/tools/run-tests.mjs +0 -64
  118. package/tsconfig.json +0 -27
@@ -1,274 +0,0 @@
1
- import 'dotenv/config';
2
- import fs from 'node:fs';
3
- import path from 'node:path';
4
- import {fileURLToPath} from 'node:url';
5
- import {notEmpty} from '../internal/util/index.mjs';
6
- import RuntimeContext from './runtime-context.mjs';
7
-
8
- const DIR_OFFSET = '/../../../../../';
9
-
10
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
11
-
12
- export const TARGET_DIR = `${__dirname}${DIR_OFFSET}`;
13
-
14
- /**
15
- * a configuration field
16
- */
17
- export type ConfigField =
18
- | {
19
- /**
20
- * the name of the field
21
- */
22
- name: string;
23
- /**
24
- * a description about the field
25
- *
26
- * supports markdown
27
- */
28
- description?: string;
29
- /**
30
- * a placeholder for the field
31
- */
32
- placeholder?: string;
33
- /**
34
- * minimum height of the field
35
- */
36
- height?: number;
37
- /**
38
- * the type of the field
39
- */
40
- type: /**
41
- * a multiline text field
42
- */
43
- | 'multiline'
44
- /**
45
- * a single line text field
46
- */
47
- | 'line'
48
- /**
49
- * a number field
50
- */
51
- | 'number'
52
- /**
53
- * a boolean text field
54
- */
55
- | 'boolean';
56
- /**
57
- * if true, the field is optional, otherwise a value is required
58
- */
59
- optional?: boolean;
60
- /**
61
- * if true, the field will NOT be encrypted
62
- */
63
- plain?: boolean;
64
- }
65
- | undefined;
66
-
67
- /**
68
- * connector configuration
69
- */
70
- declare type Config = {
71
- /**
72
- * a short summary about the connector
73
- */
74
- summary?: string;
75
- /**
76
- * a longer description about the connector, including further reference or setup instructions
77
- *
78
- * supports markdown
79
- */
80
- description?: string;
81
-
82
- /**
83
- * fields that can be configured by the user in the ui
84
- */
85
- fields?: {
86
- authorizationURL?: ConfigField;
87
- tokenURL?: ConfigField;
88
- scope?: ConfigField;
89
- clientId?: ConfigField;
90
- clientSecret?: ConfigField;
91
- [key: string]: ConfigField;
92
- };
93
- };
94
-
95
- /**
96
- * connector options
97
- */
98
- declare type Options = {
99
- /**
100
- * if an endpoint is enabled for sending data to the connector
101
- */
102
- endpoint?: {
103
- /**
104
- * if the endpoint is enabled
105
- */
106
- enabled: boolean;
107
- /**
108
- * if true, the endpoint is required to operate the connector and not visible in the ui
109
- */
110
- required?: boolean;
111
- };
112
- };
113
-
114
- /**
115
- * OAuth configuration
116
- *
117
- * @see https://oauth.net/2/
118
- */
119
- declare type OAuth = {
120
- /**
121
- * oauth2 client id
122
- *
123
- * NOTE: preferred via process.env.OAUTH_CLIENT_ID
124
- */
125
- clientId?: string;
126
-
127
- /**
128
- * oauth2 client secret
129
- *
130
- * NOTE: preferred via process.env.OAUTH_CLIENT_SECRET
131
- */
132
- clientSecret?: string;
133
-
134
- /**
135
- * @example https://example.com/oauth2/v2/auth?client_id={{clientId}}&redirect_uri={{redirectURI}}&scope={{scope}}&response_type=code
136
- */
137
- authorizationURL?: string;
138
-
139
- /**
140
- * oauth2 token url
141
- * @example https://example.com/oauth2/v2/token
142
- */
143
- tokenURL?: string;
144
- /**
145
- * oauth2 scope
146
- * @example openid offline_access
147
- */
148
- scope?: string;
149
-
150
- /**
151
- * milliseconds to automatically refresh the token, if a refresh_token is available
152
- *
153
- * @default 4 * 60 * 60 * 1000 // 4 hours
154
- */
155
- tokenRefreshPeriod?: number;
156
-
157
- /**
158
- * if true, the clientId and clientSecret are sent to the tokenURL as basic auth header
159
- */
160
- useAuthHeader?: boolean;
161
-
162
- /**
163
- * whether to enable pkce code verification
164
- *
165
- * the oauth authorization url then must contain `code_challenge_method=S256&code_challenge={{codeChallenge}}` in order to work
166
- */
167
- useCodeChallenge?: boolean;
168
-
169
- /**
170
- * if true, the client can be configured by the user
171
- */
172
- configurableClient?: boolean;
173
-
174
- /**
175
- * if true, the configurable client is optional
176
- */
177
- configurableClientOptional?: boolean;
178
-
179
- /**
180
- * if true, the connection is optional
181
- */
182
- connectionOptional?: boolean;
183
-
184
- /**
185
- * oauth2 configurable client scope
186
- */
187
- configurableClientScope?: string;
188
-
189
- /**
190
- * additional token arguments
191
- */
192
- additionalTokenArgs?: {
193
- /**
194
- * oauth2 grant type
195
- */
196
- grant_type?: string;
197
- };
198
- };
199
-
200
- /**
201
- * a builder for creating a connector
202
- */
203
- export class Builder {
204
- private data: any = {
205
- controller: './build/.controller.json',
206
- };
207
-
208
- /**
209
- * configure properties of the connector
210
- * @param arg
211
- * @returns
212
- */
213
- config(arg: Config): Builder {
214
- this.data.config = arg;
215
-
216
- return this;
217
- }
218
-
219
- /**
220
- * configure additional options of the connector
221
- * @param arg
222
- * @returns
223
- */
224
- options(arg: Options): Builder {
225
- this.data.options = arg;
226
-
227
- return this;
228
- }
229
-
230
- /**
231
- * configure the authentication of the connector
232
- * @param arg
233
- * @returns
234
- */
235
- auth(arg: {oauth?: OAuth}): Builder {
236
- this.data.auth = arg;
237
- return this;
238
- }
239
-
240
- /**
241
- * build the connector
242
- * @returns
243
- */
244
- async build(): Promise<RuntimeContext> {
245
- await this.loadDescriptor();
246
- await this.checkIcon();
247
-
248
- // @ts-ignore
249
- const Controller = (await import(TARGET_DIR + 'build/controller/index.mjs')).default;
250
-
251
- return new RuntimeContext(new Controller(), this.data);
252
- }
253
-
254
- private async checkIcon() {
255
- const data = this.data;
256
-
257
- data.icon = TARGET_DIR + 'build/logo.png';
258
- }
259
-
260
- private async loadDescriptor() {
261
- notEmpty(this.data.controller, 'controller');
262
-
263
- const content = fs.readFileSync(this.data.controller, {
264
- encoding: 'utf-8',
265
- });
266
- const {text, methods, connectorId, version} = JSON.parse(content);
267
-
268
- this.data.types = text;
269
- this.data.methods = methods;
270
-
271
- notEmpty((this.data.id = connectorId), 'id');
272
- notEmpty((this.data.version = version), 'version');
273
- }
274
- }
@@ -1,129 +0,0 @@
1
- import fs from 'node:fs';
2
- import {AbstractController} from '../controller/index.mjs';
3
- import {Connector} from '../internal/index.mjs';
4
-
5
- /**
6
- * Build a resolvers object from a list of method names and a controller.
7
- *
8
- * If a method name contains dots (e.g. 'crm.contacts.create'), it is registered
9
- * as a nested object tree so that resolveMethod(['crm', 'contacts', 'create'])
10
- * finds the handler.
11
- *
12
- * If a method name has no dots (e.g. 'contactsCreate'), it is registered flat
13
- * as before: resolvers.contactsCreate = handler.
14
- */
15
- export function buildResolvers(methods: string[], controller: any): any {
16
- const resolvers: any = {};
17
-
18
- methods.forEach((method) => {
19
- const handler = async (args: any, ctx?: any) => {
20
- if (!methods.includes(method)) throw new Error(`${method} not found`);
21
- return controller[method](args, ctx);
22
- };
23
-
24
- if (method.includes('.')) {
25
- // Register nested tree for array-based resolution: ["crm", "contacts", "getPage"]
26
- const parts = method.split('.');
27
- let node = resolvers;
28
- for (let i = 0; i < parts.length - 1; i++) {
29
- if (!node[parts[i]] || typeof node[parts[i]] !== 'object') {
30
- node[parts[i]] = {};
31
- }
32
- node = node[parts[i]];
33
- }
34
- node[parts[parts.length - 1]] = handler;
35
- // Also register flat dotted key for string-based resolution: ["crm.contacts.getPage"]
36
- resolvers[method] = handler;
37
- } else {
38
- resolvers[method] = handler;
39
- }
40
- });
41
-
42
- return resolvers;
43
- }
44
-
45
- /**
46
- * Runtime context to manage the lifecycle of the connector
47
- */
48
- export default class RuntimeContext {
49
- constructor(
50
- private controller: AbstractController,
51
- private data: any
52
- ) {}
53
-
54
- /**
55
- * start the connector
56
- */
57
- async start(): Promise<void> {
58
- const controller = this.controller;
59
-
60
- if (!(controller instanceof AbstractController)) {
61
- throw new Error('the controller needs to extend AbstractController');
62
- }
63
-
64
- const data: any = this.data;
65
-
66
- let icon;
67
-
68
- try {
69
- if (data.icon) {
70
- icon = fs.readFileSync(data.icon).toString('base64');
71
- }
72
- } catch (e) {
73
- // blank
74
- }
75
-
76
- const connector = new Connector({
77
- id: data.id,
78
- version: data.version,
79
- name: `${data.id}/${data.version}`,
80
- icon,
81
- });
82
-
83
- const configuration = connector.configure().config(data.config || {});
84
-
85
- const methods: string[] = [...data.methods, '__autocomplete', '__endpoint', '__default'];
86
- const resolvers = buildResolvers(methods, controller);
87
-
88
- configuration.types(data.types).resolvers(resolvers);
89
-
90
- if (data.options?.endpoint?.enabled) {
91
- configuration.endpoint((arg) => controller.__endpoint(arg), data.options?.endpoint?.required);
92
- }
93
-
94
- if (data.auth?.oauth) {
95
- configuration.oauth(data.auth?.oauth);
96
- }
97
-
98
- let healthInterval;
99
-
100
- configuration.main(
101
- async ({newTask, updateTask, config, oauth, getClient, getBlob, getBlobContent, createBlob, healthCheck}) => {
102
- try {
103
- clearInterval(healthInterval);
104
-
105
- await controller._doStop();
106
- await controller._doStart(config, oauth, newTask, updateTask, getClient, getBlob, getBlobContent, createBlob);
107
-
108
- healthInterval = setInterval(() => healthCheck(controller), 30000).unref();
109
-
110
- await healthCheck(controller);
111
- } catch (e) {
112
- console.log(e);
113
- }
114
- }
115
- );
116
-
117
- connector.run();
118
-
119
- const term = async () => {
120
- clearInterval(healthInterval);
121
- await controller._doStop(true);
122
-
123
- process.exit(0);
124
- };
125
-
126
- process.on('SIGTERM', term);
127
- process.on('SIGINT', term);
128
- }
129
- }