@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,166 +0,0 @@
1
- import {installNetworkGuard, uninstallNetworkGuard} from './network-guard.mjs';
2
-
3
- export type VendorRequest = {
4
- method: string;
5
- url: string;
6
- /** the url exactly as the connector passed it to fetch */
7
- rawUrl: string;
8
- headers: Record<string, string>;
9
- body?: string;
10
- };
11
-
12
- export type VendorResponse = {
13
- status?: number;
14
- headers?: Record<string, string>;
15
- /** sent as JSON with a json content-type */
16
- json?: unknown;
17
- /** sent as is */
18
- text?: string;
19
- };
20
-
21
- export type VendorResponder = VendorResponse | ((request: VendorRequest) => VendorResponse | Promise<VendorResponse>);
22
- export type UrlMatcher = string | RegExp | ((url: string) => boolean);
23
-
24
- type Route = {
25
- method: string;
26
- matcher: UrlMatcher;
27
- respond: VendorResponder;
28
- times: number;
29
- used: number;
30
- };
31
-
32
- // "https:/host/x" (one slash, which the SDK Fetcher produces) and "https://host/x" are the same URL to fetch
33
- const canonical = (url: string): string => {
34
- try {
35
- return new URL(url).href;
36
- } catch (e) {
37
- return url;
38
- }
39
- };
40
-
41
- const matches = (matcher: UrlMatcher, url: string): boolean => {
42
- if (typeof matcher === 'string') return canonical(matcher) === url;
43
- if (matcher instanceof RegExp) return matcher.test(url);
44
- return matcher(url);
45
- };
46
-
47
- /**
48
- * Mock for the HTTP calls a connector makes to its vendor API.
49
- *
50
- * - intercepts global fetch (what the SDK Fetcher and OAuth code use)
51
- * - answers from routes you register with on()/get()/post()...
52
- * - any request without a route is recorded in `unmocked` and rejected,
53
- * verify() then fails the test even if the connector swallowed the error
54
- * - also installs the network guard, so nothing can reach a non-loopback host
55
- */
56
- export class VendorMock {
57
- readonly requests: VendorRequest[] = [];
58
- readonly unmocked: VendorRequest[] = [];
59
- private routes: Route[] = [];
60
- private originalFetch?: typeof fetch;
61
- private passthrough: (url: URL) => boolean = () => false;
62
-
63
- /** urls for which the real fetch is used (the fake ALOMA endpoint); everything else is mocked */
64
- allowPassthrough(fn: (url: URL) => boolean) {
65
- this.passthrough = fn;
66
- return this;
67
- }
68
-
69
- on(method: string, matcher: UrlMatcher, respond: VendorResponder, options: {times?: number} = {}) {
70
- this.routes.push({method: method.toUpperCase(), matcher, respond, times: options.times ?? Infinity, used: 0});
71
- return this;
72
- }
73
-
74
- get(matcher: UrlMatcher, respond: VendorResponder, options?: {times?: number}) {
75
- return this.on('GET', matcher, respond, options);
76
- }
77
- post(matcher: UrlMatcher, respond: VendorResponder, options?: {times?: number}) {
78
- return this.on('POST', matcher, respond, options);
79
- }
80
- put(matcher: UrlMatcher, respond: VendorResponder, options?: {times?: number}) {
81
- return this.on('PUT', matcher, respond, options);
82
- }
83
- delete(matcher: UrlMatcher, respond: VendorResponder, options?: {times?: number}) {
84
- return this.on('DELETE', matcher, respond, options);
85
- }
86
-
87
- install() {
88
- if (this.originalFetch) return this;
89
-
90
- installNetworkGuard();
91
- this.originalFetch = globalThis.fetch;
92
- globalThis.fetch = ((input: any, init?: any) => this.handle(input, init)) as typeof fetch;
93
-
94
- return this;
95
- }
96
-
97
- uninstall() {
98
- if (!this.originalFetch) return;
99
-
100
- globalThis.fetch = this.originalFetch;
101
- this.originalFetch = undefined;
102
- uninstallNetworkGuard();
103
- }
104
-
105
- /** throws if the connector made a request that had no mock, even if it caught the error */
106
- verify() {
107
- if (this.unmocked.length) {
108
- const list = this.unmocked.map((r) => `${r.method} ${r.url}`).join('\n ');
109
- throw new Error(`UNMOCKED vendor requests were made (no network is allowed in tests):\n ${list}`);
110
- }
111
- }
112
-
113
- /** throws if a registered route was never used */
114
- verifyAllRoutesUsed() {
115
- const unused = this.routes.filter((r) => r.used === 0);
116
- if (unused.length) {
117
- throw new Error(`mocked routes never called: ${unused.map((r) => `${r.method} ${String(r.matcher)}`).join(', ')}`);
118
- }
119
- }
120
-
121
- private async handle(input: any, init: any = {}): Promise<Response> {
122
- const rawUrl: string = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url;
123
- const url = canonical(rawUrl);
124
- const method = String(init.method || (typeof input === 'object' && input.method) || 'GET').toUpperCase();
125
-
126
- const headers: Record<string, string> = {};
127
- new Headers(init.headers || (typeof input === 'object' && (input as any).headers) || {}).forEach((value, key) => {
128
- headers[key] = value;
129
- });
130
-
131
- const request: VendorRequest = {method, url, rawUrl, headers};
132
- if (init.body != null) request.body = typeof init.body === 'string' ? init.body : String(init.body);
133
-
134
- const route = this.routes.find((r) => r.method === method && r.used < r.times && matches(r.matcher, url));
135
-
136
- if (route) {
137
- route.used++;
138
- this.requests.push(request);
139
- const spec = typeof route.respond === 'function' ? await route.respond(request) : route.respond;
140
-
141
- const responseHeaders = {...spec.headers};
142
- let body: string | null = null;
143
- if (spec.json !== undefined) {
144
- body = JSON.stringify(spec.json);
145
- responseHeaders['content-type'] ||= 'application/json';
146
- } else if (spec.text !== undefined) {
147
- body = spec.text;
148
- }
149
-
150
- const status = spec.status ?? 200;
151
- return new Response([204, 205, 304].includes(status) ? null : body, {status, headers: responseHeaders});
152
- }
153
-
154
- if (this.originalFetch && this.passthrough(new URL(url))) {
155
- return this.originalFetch(input, init);
156
- }
157
-
158
- this.unmocked.push(request);
159
-
160
- // status 400 makes the SDK Fetcher give up at once instead of retrying for seconds
161
- const error: any = new Error(`UNMOCKED vendor request: ${method} ${url} (add a route with vendor.on(...))`);
162
- error.status = 400;
163
- error.alomaHarnessUnmocked = true;
164
- throw error;
165
- }
166
- }