@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,42 +0,0 @@
1
- import C from './constants.mjs';
2
-
3
- class Registration {
4
- constructor(config) {
5
- this.config = config;
6
- }
7
-
8
- async run() {
9
- var local = this;
10
- const config = this.config;
11
- const configSchema = config.configSchema();
12
- const intro = await config.introspect();
13
- const icon = config.icon();
14
-
15
- const response = await fetch(
16
- config.url() + 'register',
17
- C.augmentRegistration(
18
- {
19
- method: 'POST',
20
- body: JSON.stringify({
21
- deployment: process.env.DEPLOYMENT || '',
22
- name: config.name(),
23
- version: config.version(),
24
- id: config.id(),
25
- publicKey: config.publicKey(),
26
- schema: {configSchema, introspect: intro},
27
- icon,
28
- }),
29
- headers: {'Content-Type': 'application/json'},
30
- signal: AbortSignal.timeout(60 * 1000),
31
- },
32
- config
33
- )
34
- );
35
-
36
- if (response.status === 200) return (await response.json()).key;
37
-
38
- throw new Error('authentication failed');
39
- }
40
- }
41
-
42
- export {Registration};
@@ -1,46 +0,0 @@
1
- import WebSocket from 'ws';
2
- import {Connection} from './connection/index.mjs';
3
- import {Transport} from './transport/index.mjs';
4
-
5
- class WebsocketConnector {
6
- constructor({config, onMessage, onConnect}) {
7
- var local = this;
8
- this.config = config;
9
- this.transport = new Transport({config, onMessage, onConnect});
10
- }
11
-
12
- async start() {
13
- var local = this;
14
- const config = this.config;
15
-
16
- local.connection = new Connection({
17
- config,
18
- onStart: () => {
19
- local.transport.start(() => setTimeout(() => local.start(), 1000));
20
- },
21
- });
22
-
23
- await local.connection.start();
24
- }
25
-
26
- send(message) {
27
- if (!message) return;
28
-
29
- this.transport.send(this.transport.newPacket(message));
30
- }
31
-
32
- async close() {
33
- var local = this;
34
-
35
- if (local.transport) await local.transport.close();
36
- }
37
-
38
- async leaving() {
39
- var local = this;
40
-
41
- if (local.transport) await local.transport.leaving();
42
- if (local.connection) await local.connection.close();
43
- }
44
- }
45
-
46
- export {WebsocketConnector};
@@ -1,71 +0,0 @@
1
- import WebSocket from 'ws';
2
-
3
- class DurableWebsocket {
4
- constructor({endpoint, secret, onConnect, onMessage}) {
5
- this.endpoint = endpoint;
6
- this.secret = secret;
7
- this.onConnect = onConnect;
8
- this.onMessage = onMessage;
9
- this.failed = [];
10
- this.fails = 0;
11
- this.start();
12
- }
13
-
14
- async send(what) {
15
- try {
16
- return await this.ws.send(JSON.stringify(what));
17
- } catch (e) {
18
- this.failed.push(what);
19
- }
20
- }
21
-
22
- start() {
23
- var local = this;
24
-
25
- if (local.connecting || local.closed) return;
26
- local.connecting = true;
27
-
28
- const ws = (local.ws = new WebSocket(local.endpoint, [], {
29
- rejectUnauthorized: false,
30
- headers: {Authorization: `Bearer ${local.secret}`},
31
- }));
32
-
33
- ws.on('open', () => {
34
- local.connecting = false;
35
- local.fails = 0;
36
-
37
- var item;
38
-
39
- while ((item = local.failed.shift())) {
40
- local.send(item);
41
- }
42
-
43
- local.onConnect(local);
44
- });
45
-
46
- ws.on('message', (message) => {
47
- setImmediate(() => local.onMessage(JSON.parse(message)));
48
- });
49
-
50
- ws.on('error', (message) => {
51
- if (local.fails > 50) console.log('error:', message.message);
52
-
53
- ++local.fails;
54
- });
55
-
56
- ws.on('close', (message) => {
57
- local.connecting = false;
58
-
59
- if (!local.closed) setTimeout(() => local.start(), 5000);
60
- });
61
- }
62
-
63
- async close() {
64
- if (this.closed) return;
65
- this.closed = true;
66
-
67
- await this.ws?.close();
68
- }
69
- }
70
-
71
- export {DurableWebsocket};
@@ -1,194 +0,0 @@
1
- import {init} from '@paralleldrive/cuid2';
2
- import C from '../connection/constants.mjs';
3
- const cuid = init({length: 32});
4
-
5
- import WebSocket from 'ws';
6
- import {DurableWebsocket} from './durable.mjs';
7
- import {Callback, Packet} from './packet.mjs';
8
-
9
- const cleanInterval = 45 * 1000;
10
- const pingInterval = 30 * 1000;
11
-
12
- class Transport {
13
- constructor({config, onMessage, onConnect}) {
14
- var local = this;
15
-
16
- this.config = config;
17
- this.callbacks = {};
18
- this.running = true;
19
- this.pinger = null;
20
- this.cleaner = setInterval(() => local.clean(), cleanInterval);
21
-
22
- this.acks = [];
23
- this.packets = [];
24
- this.onConnect = onConnect;
25
- this._onMessage = onMessage;
26
- }
27
-
28
- schedule() {
29
- var local = this;
30
-
31
- setTimeout(() => local.schedule0(), 0);
32
- }
33
-
34
- schedule0() {
35
- var local = this,
36
- packets = [],
37
- packet;
38
-
39
- if (!local.packets.length || !local.connected) return;
40
-
41
- while ((packet = local.packets.shift())) {
42
- packets.push(packet.data);
43
- }
44
-
45
- if (!packets.length) return;
46
-
47
- try {
48
- local.ws.send(JSON.stringify({p: packets}));
49
- } catch (e) {
50
- console.log('could not send packets ', e);
51
- packets.forEach((packet) => local.packets.unshift(packet));
52
- }
53
- }
54
-
55
- async start(ondisconnect) {
56
- var local = this,
57
- config = local.config;
58
-
59
- if (local._leaving) return;
60
-
61
- local.close();
62
-
63
- this.running = true;
64
-
65
- const ws = (local.ws = new WebSocket(config.wsUrl(), ['connector'], C.augmentRequest({headers: {}}, config)));
66
-
67
- ws.onPing = function () {
68
- clearTimeout(this.pingTimeout);
69
- this.pingTimeout = setTimeout(() => {
70
- if (local.running) ws.terminate();
71
- }, 30000 + 15000);
72
- };
73
-
74
- ws.on('open', () => {
75
- console.log('transport connected');
76
- local.connected = true;
77
- ws.onPing();
78
- local.pinger = setInterval(() => ws.ping(() => null), pingInterval);
79
-
80
- local.onConnect(local);
81
- });
82
-
83
- ws.on('message', (message) => {
84
- setTimeout(() => local.onMessages(JSON.parse(message)), 0);
85
- });
86
-
87
- ws.on('ping', () => ws.onPing());
88
-
89
- ws.on('error', (message) => {
90
- console.log('error:', message);
91
- });
92
-
93
- ws.on('close', (message) => {
94
- local.connected = false;
95
- clearInterval(local.pinger);
96
-
97
- if (local.running) ondisconnect();
98
- });
99
- }
100
-
101
- newDurableWebsocket({endpoint, secret, onConnect, onMessage}) {
102
- return new DurableWebsocket({endpoint, secret, onConnect, onMessage});
103
- }
104
-
105
- send(packet) {
106
- if (!packet) return;
107
-
108
- this.packets.push(packet);
109
- this.schedule();
110
- }
111
-
112
- onMessages(msgs) {
113
- var local = this;
114
-
115
- msgs.p?.forEach((item) => {
116
- local.onMessage(item);
117
- });
118
- }
119
-
120
- onMessage(data) {
121
- if (!data) return;
122
-
123
- const packet = new Packet(data);
124
-
125
- if (packet.cb() && this.callbacks[packet.cb()]) {
126
- try {
127
- this.callbacks[packet.cb()].cb(packet.args());
128
- } catch (e) {
129
- console.log('error processing packet', e, packet);
130
- } finally {
131
- delete this.callbacks[packet.cb()];
132
- }
133
-
134
- return;
135
- }
136
-
137
- return this._onMessage(packet, this);
138
- }
139
-
140
- newPacket(data, cb, cbKey) {
141
- const packet = new Packet({...data});
142
-
143
- if (cb) {
144
- this.callbacks[cbKey || packet.id()] = new Callback({cb});
145
- packet.cb(cbKey || packet.id());
146
- }
147
-
148
- return packet;
149
- }
150
-
151
- clean() {
152
- var local = this;
153
- const cbs = {...this.callbacks},
154
- then = Date.now() - 5 * 60 * 1000;
155
-
156
- Object.keys(cbs).forEach((key) => {
157
- const cb = cbs[key];
158
- if (!cb) return;
159
-
160
- if (cb.created < then) {
161
- console.log('callback timeout', key);
162
-
163
- try {
164
- cb.cb({error: 'timeout'});
165
- } catch (e) {
166
- console.log('error while callback', key, cb, e);
167
- }
168
-
169
- delete local.callbacks[key];
170
- }
171
- });
172
- }
173
-
174
- leaving() {
175
- this._leaving = true;
176
- this.running = false;
177
- }
178
-
179
- close() {
180
- clearInterval(this.pinger);
181
- clearInterval(this.cleaner);
182
-
183
- this.running = false;
184
- this.connected = false;
185
-
186
- try {
187
- local.ws.terminate();
188
- } catch (e) {
189
- // blank
190
- }
191
- }
192
- }
193
-
194
- export {Transport};
@@ -1,54 +0,0 @@
1
- import {init} from '@paralleldrive/cuid2';
2
- const cuid = init({length: 32});
3
-
4
- class Packet {
5
- constructor(data = {}) {
6
- this.data = data;
7
- this.data.id ||= cuid();
8
- }
9
-
10
- id() {
11
- return this.data.id;
12
- }
13
-
14
- cb(what) {
15
- if (what) {
16
- this.data.c = what;
17
- }
18
-
19
- return this.data.c;
20
- }
21
-
22
- method(what) {
23
- if (what) {
24
- this.data.m = what;
25
- }
26
-
27
- return this.data.m;
28
- }
29
-
30
- event(what) {
31
- if (what) {
32
- this.data.e = what;
33
- }
34
-
35
- return this.data.e;
36
- }
37
-
38
- args(what) {
39
- if (what) {
40
- this.data.a = what;
41
- }
42
-
43
- return this.data.a;
44
- }
45
- }
46
-
47
- class Callback {
48
- constructor({cb}) {
49
- this.cb = cb;
50
- this.created = Date.now();
51
- }
52
- }
53
-
54
- export {Callback, Packet};
@@ -1,66 +0,0 @@
1
- import {Packet, Callback} from './packet.mjs';
2
-
3
- class Processor {
4
- constructor({transport, processPacket}) {
5
- var local = this;
6
-
7
- this.transport = transport;
8
- this._processPacket = processPacket;
9
- }
10
-
11
- async onMessages(what) {
12
- var local = this;
13
- const messages = what.p;
14
-
15
- const packets = messages.map((message) => {
16
- const packet = new Packet(message);
17
- local.transport.acks.push(packet.id());
18
-
19
- return local.processPacket(packet);
20
- });
21
-
22
- await Promise.all(packets);
23
- }
24
-
25
- async processPacket(packet) {
26
- var local = this;
27
-
28
- if (packet.args().packet) {
29
- await local.processPacket0(local.transport.newPacket(packet.args().packet), packet);
30
- } else {
31
- await local.processPacket0(packet, packet);
32
- }
33
- }
34
-
35
- async processPacket0(packet, original) {
36
- var local = this,
37
- callbacks = local.transport.callbacks;
38
-
39
- if (packet.cb() && callbacks[packet.cb()]) {
40
- try {
41
- callbacks[packet.cb()](packet.args());
42
- } catch (e) {
43
- console.log('error in callback', callbacks[packet.cb()], packet);
44
- }
45
-
46
- delete local.transport.callbacks[packet.cb()];
47
- } else if (packet.event()) {
48
- console.log('handle event packet', packet);
49
- } else {
50
- try {
51
- const result = await local._processPacket(packet);
52
- const reply = local.transport.newPacket({});
53
-
54
- reply.method('connector.reply');
55
- reply.cb(original.cb());
56
- reply.args({...result});
57
-
58
- local.transport.send(reply);
59
- } catch (e) {
60
- console.log('error processing packet', e, packet);
61
- }
62
- }
63
- }
64
- }
65
-
66
- export {Processor};