@aloma.io/integration-sdk 3.8.69 → 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 (117) 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 +22 -1
  4. package/build/internal/fetcher/fetcher.mjs +99 -14
  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/build/openapi-to-connector.mjs +5 -2
  11. package/package.json +9 -4
  12. package/.prettierrc.cjs +0 -8
  13. package/MULTI_RESOURCE_GUIDE.md +0 -220
  14. package/OPENAPI_TO_CONNECTOR.md +0 -346
  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 -166
  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 -1644
  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/fixtures/transform/basic/expected.json +0 -9
  67. package/test/fixtures/transform/basic/src/controller/abstract.mts +0 -5
  68. package/test/fixtures/transform/basic/src/controller/index.mts +0 -30
  69. package/test/fixtures/transform/basic/tsconfig.json +0 -1
  70. package/test/fixtures/transform/interface-param/src/controller/abstract.mts +0 -5
  71. package/test/fixtures/transform/interface-param/src/controller/index.mts +0 -12
  72. package/test/fixtures/transform/interface-param/tsconfig.json +0 -1
  73. package/test/fixtures/transform/overloads/expected.json +0 -6
  74. package/test/fixtures/transform/overloads/src/controller/abstract.mts +0 -5
  75. package/test/fixtures/transform/overloads/src/controller/index.mts +0 -11
  76. package/test/fixtures/transform/overloads/tsconfig.json +0 -1
  77. package/test/fixtures/transform/tdd-stub/expected.json +0 -8
  78. package/test/fixtures/transform/tdd-stub/src/controller/abstract.mts +0 -6
  79. package/test/fixtures/transform/tdd-stub/src/controller/index.mts +0 -204
  80. package/test/fixtures/transform/tdd-stub/tsconfig.json +0 -1
  81. package/test/fixtures/transform/two-exports/src/controller/abstract.mts +0 -5
  82. package/test/fixtures/transform/two-exports/src/controller/index.mts +0 -9
  83. package/test/fixtures/transform/two-exports/tsconfig.json +0 -1
  84. package/test/fixtures/transform/type-error/src/controller/abstract.mts +0 -5
  85. package/test/fixtures/transform/type-error/src/controller/index.mts +0 -7
  86. package/test/fixtures/transform/type-error/tsconfig.json +0 -1
  87. package/test/fixtures/transform/typed/expected.json +0 -8
  88. package/test/fixtures/transform/typed/src/controller/abstract.mts +0 -5
  89. package/test/fixtures/transform/typed/src/controller/index.mts +0 -13
  90. package/test/fixtures/transform/typed/tsconfig.json +0 -1
  91. package/test/fixtures/transform/visibility/expected.json +0 -9
  92. package/test/fixtures/transform/visibility/src/controller/abstract.mts +0 -5
  93. package/test/fixtures/transform/visibility/src/controller/index.mts +0 -19
  94. package/test/fixtures/transform/visibility/tsconfig.json +0 -1
  95. package/test/harness-connector-smoke.test.mjs +0 -72
  96. package/test/harness.test.mjs +0 -375
  97. package/test/nested-resolver.test.mjs +0 -184
  98. package/test/openapi-generator-bugs.test.mjs +0 -248
  99. package/test/openapi-identifier-sanitise.test.mjs +0 -69
  100. package/test/openapi-nested-paths.test.mjs +0 -100
  101. package/test/openapi-to-connector.test.mts +0 -225
  102. package/test/openapi-ts-compilation.test.mjs +0 -178
  103. package/test/scenarios/README.md +0 -148
  104. package/test/scenarios/complex/expected/controller.mts +0 -271
  105. package/test/scenarios/complex/expected/orders-resource.mts +0 -262
  106. package/test/scenarios/complex/expected/products-resource.mts +0 -237
  107. package/test/scenarios/complex/specs/orders.json +0 -362
  108. package/test/scenarios/complex/specs/products.json +0 -308
  109. package/test/scenarios/simple/expected-controller.mts +0 -60
  110. package/test/scenarios/simple/simple-api.json +0 -39
  111. package/test/scenarios.test.mts +0 -294
  112. package/test/transform.test.mjs +0 -68
  113. package/test/verify-scenarios.mjs +0 -298
  114. package/tools/mutation-run-entry.mjs +0 -52
  115. package/tools/mutation-run.mjs +0 -120
  116. package/tools/run-tests.mjs +0 -64
  117. package/tsconfig.json +0 -27
@@ -1,248 +0,0 @@
1
- import { OpenAPIToConnector } from '../build/openapi-to-connector.mjs';
2
-
3
- // Simple test framework matching project convention
4
- const colors = {
5
- green: '\x1b[32m',
6
- red: '\x1b[31m',
7
- yellow: '\x1b[33m',
8
- reset: '\x1b[0m',
9
- cyan: '\x1b[36m'
10
- };
11
-
12
- let passed = 0;
13
- let failed = 0;
14
-
15
- async function test(name, fn) {
16
- try {
17
- console.log(`${colors.cyan}Running: ${name}${colors.reset}`);
18
- await fn();
19
- console.log(`${colors.green}✓ PASS: ${name}${colors.reset}\n`);
20
- passed++;
21
- } catch (error) {
22
- console.log(`${colors.red}✗ FAIL: ${name}${colors.reset}`);
23
- console.log(`${colors.red} Error: ${error.message}${colors.reset}\n`);
24
- failed++;
25
- }
26
- }
27
-
28
- function assert(condition, message) {
29
- if (!condition) throw new Error(message || 'Assertion failed');
30
- }
31
-
32
- function assertEqual(actual, expected, message) {
33
- if (actual !== expected) {
34
- throw new Error(message || `Expected "${expected}", got "${actual}"`);
35
- }
36
- }
37
-
38
- // Minimal OpenAPI spec for testing
39
- const minimalSpec = {
40
- openapi: '3.0.0',
41
- info: { title: 'Test API', version: '1.0.0' },
42
- paths: {}
43
- };
44
-
45
- // === BUG 1: Duplicate function names within a resource ===
46
-
47
- await test('Bug1: Two ops producing same method name are deduplicated in resource output', async () => {
48
- // Spec with two operations that both derive "archive" as method name:
49
- // POST /batch/archive -> operationId batch_archive (suffix: archive)
50
- // DELETE /contacts/{id} -> operationId contacts_archive (suffix: archive)
51
- const spec = {
52
- openapi: '3.0.0',
53
- info: { title: 'Test', version: '1.0.0' },
54
- paths: {
55
- '/contacts/batch/archive': {
56
- post: {
57
- operationId: 'batch_archive',
58
- summary: 'Batch archive contacts',
59
- responses: { '200': { description: 'OK' } }
60
- }
61
- },
62
- '/contacts/{contactId}': {
63
- delete: {
64
- operationId: 'contacts_archive',
65
- summary: 'Archive single contact',
66
- parameters: [{ name: 'contactId', in: 'path', required: true, schema: { type: 'string' } }],
67
- responses: { '204': { description: 'Deleted' } }
68
- }
69
- }
70
- }
71
- };
72
-
73
- const generator = new OpenAPIToConnector(spec, 'test', { nestedPaths: false });
74
- const output = generator.generateResourceClass('ContactsResource');
75
-
76
- // Count how many times "export function archive(" appears
77
- const matches = output.match(/export function archive\(/g);
78
- assert(
79
- !matches || matches.length <= 1,
80
- `Expected at most 1 "export function archive(" but found ${matches ? matches.length : 0}. Duplicate function names!`
81
- );
82
-
83
- // There should be two distinct function declarations (disambiguated)
84
- const funcDecls = output.match(/export function \w+\(/g);
85
- assert(funcDecls && funcDecls.length >= 2, `Expected at least 2 distinct function declarations, got ${funcDecls ? funcDecls.length : 0}`);
86
- });
87
-
88
- await test('Bug1: generateController with colliding method names produces distinct methods', async () => {
89
- const spec = {
90
- openapi: '3.0.0',
91
- info: { title: 'Test', version: '1.0.0' },
92
- paths: {
93
- '/items/batch/read': {
94
- post: {
95
- operationId: 'batch_read',
96
- summary: 'Batch read items',
97
- responses: { '200': { description: 'OK' } }
98
- }
99
- },
100
- '/items/{itemId}': {
101
- get: {
102
- operationId: 'items_read',
103
- summary: 'Read single item',
104
- parameters: [{ name: 'itemId', in: 'path', required: true, schema: { type: 'string' } }],
105
- responses: { '200': { description: 'OK' } }
106
- }
107
- }
108
- }
109
- };
110
-
111
- const generator = new OpenAPIToConnector(spec, 'test', { nestedPaths: false });
112
- const output = generator.generateController();
113
-
114
- // Count occurrences of "async read(" — should be at most 1
115
- const matches = output.match(/async read\(/g);
116
- assert(
117
- !matches || matches.length <= 1,
118
- `Expected at most 1 "async read(" but found ${matches ? matches.length : 0}. Duplicate method names in controller!`
119
- );
120
- });
121
-
122
- // === BUG 2: Dead code after return ===
123
-
124
- await test('Bug2: Resource function for simple path+params has no statements after return', async () => {
125
- // A simple GET with path param and no query/body triggers the "isSimple" branch
126
- // which already emits a return, but then the code unconditionally appends another return
127
- const spec = {
128
- openapi: '3.0.0',
129
- info: { title: 'Test', version: '1.0.0' },
130
- paths: {
131
- '/contacts/{contactId}': {
132
- get: {
133
- operationId: 'getContact',
134
- summary: 'Get a contact',
135
- parameters: [{ name: 'contactId', in: 'path', required: true, schema: { type: 'string' } }],
136
- responses: { '200': { description: 'OK' } }
137
- }
138
- }
139
- }
140
- };
141
-
142
- const generator = new OpenAPIToConnector(spec, 'test', { nestedPaths: false });
143
- const output = generator.generateResourceClass('ContactsResource');
144
-
145
- // Extract the function body for getContact
146
- const funcMatch = output.match(/export function getContact[\s\S]*?\n\}/);
147
- assert(funcMatch, 'Could not find getContact function in output');
148
- const funcBody = funcMatch[0];
149
-
150
- // Find all return statements
151
- const returnStatements = funcBody.match(/return this\.api\.fetch/g);
152
- assert(
153
- returnStatements && returnStatements.length === 1,
154
- `Expected exactly 1 return statement but found ${returnStatements ? returnStatements.length : 0}. Dead code after return!`
155
- );
156
- });
157
-
158
- await test('Bug2: Controller function for simple path+params has no dead code after return', async () => {
159
- const spec = {
160
- openapi: '3.0.0',
161
- info: { title: 'Test', version: '1.0.0' },
162
- paths: {
163
- '/items/{itemId}': {
164
- get: {
165
- operationId: 'getItem',
166
- summary: 'Get an item',
167
- parameters: [{ name: 'itemId', in: 'path', required: true, schema: { type: 'string' } }],
168
- responses: { '200': { description: 'OK' } }
169
- }
170
- }
171
- }
172
- };
173
-
174
- const generator = new OpenAPIToConnector(spec, 'test', { nestedPaths: false });
175
- const output = generator.generateController();
176
-
177
- // Extract the method body for getItem
178
- const methodMatch = output.match(/async getItem[\s\S]*?\n \}/);
179
- assert(methodMatch, 'Could not find getItem method in output');
180
- const methodBody = methodMatch[0];
181
-
182
- // Find all return statements
183
- const returnStatements = methodBody.match(/return this\.api\.fetch/g);
184
- assert(
185
- returnStatements && returnStatements.length === 1,
186
- `Expected exactly 1 return statement but found ${returnStatements ? returnStatements.length : 0}. Dead code after return in controller!`
187
- );
188
- });
189
-
190
- // === BUG 3: Raw URL path segments in method names ===
191
-
192
- await test('Bug3: deriveMethodPath handles operationId with raw URL paths (lists style)', async () => {
193
- const generator = new OpenAPIToConnector(minimalSpec, 'hubspot', { nestedPaths: true });
194
-
195
- // HubSpot lists-style operationId: "get-/crm/v3/lists_/crm/v3/lists"
196
- const result = generator.deriveMethodPath('GET', '/crm/v3/lists', 'get-/crm/v3/lists_/crm/v3/lists');
197
-
198
- // Should NOT contain slashes or version numbers
199
- assert(!result.includes('/'), `Method path should not contain slashes, got: "${result}"`);
200
- assert(!result.includes('v3'), `Method path should not contain version numbers, got: "${result}"`);
201
- });
202
-
203
- await test('Bug3: deriveMethodPath handles operationId suffix that IS a raw URL path', async () => {
204
- const generator = new OpenAPIToConnector(minimalSpec, 'hubspot', { nestedPaths: true });
205
-
206
- // operationId: "post-/crm/v3/lists/search_/crm/v3/lists/search"
207
- const result = generator.deriveMethodPath('POST', '/crm/v3/lists/search', 'post-/crm/v3/lists/search_/crm/v3/lists/search');
208
-
209
- assert(!result.includes('/'), `Method path should not contain slashes, got: "${result}"`);
210
- assert(!result.includes('v3'), `Method path should not contain version numbers, got: "${result}"`);
211
- // Should contain "lists" and "search" in some form
212
- assert(result.includes('lists'), `Method path should contain "lists", got: "${result}"`);
213
- assert(result.includes('search'), `Method path should contain "search", got: "${result}"`);
214
- });
215
-
216
- await test('Bug3: deriveMethodPath does not produce doubled segments from URL-style operationId', async () => {
217
- const generator = new OpenAPIToConnector(minimalSpec, 'hubspot', { nestedPaths: true });
218
-
219
- // operationId: "put-/crm/v3/lists/{listId}/restore_/crm/v3/lists/{listId}/restore"
220
- const result = generator.deriveMethodPath('PUT', '/crm/v3/lists/{listId}/restore', 'put-/crm/v3/lists/{listId}/restore_/crm/v3/lists/{listId}/restore');
221
-
222
- assert(!result.includes('/'), `Method path should not contain slashes, got: "${result}"`);
223
- // Should not have doubled path segments like "lists.lists" or "restore.restore"
224
- const parts = result.split('.');
225
- for (let i = 0; i < parts.length - 1; i++) {
226
- assert(parts[i] !== parts[i + 1], `Doubled segment "${parts[i]}" in method path: "${result}"`);
227
- }
228
- });
229
-
230
- await test('Bug3: generateMethodName (flat mode) cleans operationId with raw URL paths', async () => {
231
- const generator = new OpenAPIToConnector(minimalSpec, 'hubspot', { nestedPaths: false });
232
-
233
- // When nestedPaths is false, deriveMethodPath calls generateMethodName
234
- // This should still produce a clean identifier without slashes
235
- const result = generator.deriveMethodPath('GET', '/crm/v3/lists', 'get-/crm/v3/lists_/crm/v3/lists');
236
-
237
- assert(!result.includes('/'), `Flat method name should not contain slashes, got: "${result}"`);
238
- assert(/^[a-zA-Z_]/.test(result), `Method name should start with letter or underscore, got: "${result}"`);
239
- });
240
-
241
- // --- Report ---
242
- console.log(`\n${colors.yellow}===== Results =====${colors.reset}`);
243
- console.log(`${colors.green}Passed: ${passed}${colors.reset}`);
244
- console.log(`${colors.red}Failed: ${failed}${colors.reset}`);
245
-
246
- if (failed > 0) {
247
- process.exit(1);
248
- }
@@ -1,69 +0,0 @@
1
- import assert from 'assert';
2
-
3
- const { OpenAPIToConnector } = await import('../build/openapi-to-connector.mjs');
4
-
5
- let passed = 0;
6
- let failed = 0;
7
-
8
- function test(name, fn) {
9
- try { fn(); console.log(`✓ PASS: ${name}`); passed++; }
10
- catch(e) { console.log(`✗ FAIL: ${name} — ${e.message}`); failed++; }
11
- }
12
-
13
- const minimalSpec = { openapi: '3.0.0', info: { title: 'Test', version: '1.0' }, paths: {} };
14
- const gen = new OpenAPIToConnector(minimalSpec, 'test', { nestedPaths: true });
15
-
16
- // Bug 4: hyphenated path segment must not appear in dotted method path
17
- test('hyphenated path segment sanitised in nested method path', () => {
18
- const path = gen.deriveMethodPath('PUT',
19
- '/crm/lists/2025-09/{listId}/memberships/add-and-remove',
20
- 'put-/crm/lists/2025-09/{listId}/memberships/add-and-remove_addAndRemove');
21
- const segments = path.split('.');
22
- segments.forEach(seg => {
23
- assert(!seg.includes('-'), `Method path segment contains hyphen: "${seg}" in "${path}"`);
24
- });
25
- });
26
-
27
- // Bug 4: path with object-type-id (hyphenated) must produce clean segments
28
- test('object-type-id hyphenated path sanitised to camelCase', () => {
29
- const path = gen.deriveMethodPath('GET',
30
- '/crm/lists/2025-09/object-type-id/{objectTypeId}/name/{listName}',
31
- 'get-/crm/lists/2025-09/object-type-id/{objectTypeId}/name/{listName}_getByName');
32
- const segments = path.split('.');
33
- segments.forEach(seg => {
34
- assert(!seg.includes('-'), `Method path segment contains hyphen: "${seg}" in "${path}"`);
35
- });
36
- });
37
-
38
- // Bug 5: operationId suffix that IS a raw URL path must not duplicate the full path
39
- test('raw URL suffix does not produce duplicated path in method name', () => {
40
- const path = gen.deriveMethodPath('GET',
41
- '/crm/lists/2025-09',
42
- 'get-/crm/lists/2025-09_/crm/lists/2025-09');
43
- // Should be short and clean, not a duplicated path
44
- assert(path.length < 40, `Path too long (duplication): "${path}" (${path.length} chars)`);
45
- assert(!path.includes('_'), `Path contains underscores (non-nested fallback used): "${path}"`);
46
- });
47
-
48
- // Bug 5: same duplication test for the batch/read endpoint
49
- test('batch/read raw URL suffix does not produce duplicated path', () => {
50
- const path = gen.deriveMethodPath('POST',
51
- '/crm/lists/2025-09/records/memberships/batch/read',
52
- 'post-/crm/lists/2025-09/records/memberships/batch/read_/crm/lists/2025-09/records/memberships/batch/read');
53
- assert(path.length < 60, `Path too long (duplication): "${path}" (${path.length} chars)`);
54
- assert(!path.includes('_'), `Path contains underscores (non-nested fallback used): "${path}"`);
55
- });
56
-
57
- // Bug 4: generateMethodName fallback (no operationId) must sanitise hyphens
58
- test('generateMethodName fallback sanitises hyphens to camelCase', () => {
59
- const name = gen.generateMethodName({
60
- method: 'PUT',
61
- path: '/crm/lists/2025-09/folders/move-list',
62
- operationId: undefined
63
- });
64
- assert(!name.includes('-'), `Fallback name contains hyphen: "${name}"`);
65
- assert(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name), `Not a valid identifier: "${name}"`);
66
- });
67
-
68
- console.log(`\n${passed} passing / ${failed} failing`);
69
- if (failed > 0) process.exit(1);
@@ -1,100 +0,0 @@
1
- import { OpenAPIToConnector } from '../build/openapi-to-connector.mjs';
2
-
3
- // Simple test framework matching project convention
4
- const colors = {
5
- green: '\x1b[32m',
6
- red: '\x1b[31m',
7
- yellow: '\x1b[33m',
8
- reset: '\x1b[0m',
9
- cyan: '\x1b[36m'
10
- };
11
-
12
- let passed = 0;
13
- let failed = 0;
14
-
15
- async function test(name, fn) {
16
- try {
17
- console.log(`${colors.cyan}Running: ${name}${colors.reset}`);
18
- await fn();
19
- console.log(`${colors.green}✓ PASS: ${name}${colors.reset}\n`);
20
- passed++;
21
- } catch (error) {
22
- console.log(`${colors.red}✗ FAIL: ${name}${colors.reset}`);
23
- console.log(`${colors.red} Error: ${error.message}${colors.reset}\n`);
24
- failed++;
25
- }
26
- }
27
-
28
- function assert(condition, message) {
29
- if (!condition) throw new Error(message || 'Assertion failed');
30
- }
31
-
32
- function assertEqual(actual, expected, message) {
33
- if (actual !== expected) {
34
- throw new Error(message || `Expected "${expected}", got "${actual}"`);
35
- }
36
- }
37
-
38
- // Minimal OpenAPI spec for testing
39
- const minimalSpec = {
40
- openapi: '3.0.0',
41
- info: { title: 'Test API', version: '1.0.0' },
42
- paths: {}
43
- };
44
-
45
- // --- TESTS ---
46
-
47
- // Test 1: GET /crm/v3/objects/contacts with opId -> crm.contacts.getPage
48
- await test('nestedPaths: GET /crm/v3/objects/contacts -> crm.contacts.getPage', async () => {
49
- const generator = new OpenAPIToConnector(minimalSpec, 'hubspot', { nestedPaths: true });
50
- assert(typeof generator.deriveMethodPath === 'function', 'deriveMethodPath should be a method on the generator');
51
- const result = generator.deriveMethodPath('GET', '/crm/v3/objects/contacts', 'get-/crm/v3/objects/contacts_getPage');
52
- assertEqual(result, 'crm.contacts.getPage');
53
- });
54
-
55
- // Test 2: POST /crm/v3/objects/contacts with opId -> crm.contacts.create
56
- await test('nestedPaths: POST /crm/v3/objects/contacts -> crm.contacts.create', async () => {
57
- const generator = new OpenAPIToConnector(minimalSpec, 'hubspot', { nestedPaths: true });
58
- const result = generator.deriveMethodPath('POST', '/crm/v3/objects/contacts', 'post-/crm/v3/objects/contacts_create');
59
- assertEqual(result, 'crm.contacts.create');
60
- });
61
-
62
- // Test 3: Dedup - POST /crm/v3/objects/contacts/merge with opId _merge -> crm.contacts.merge (NOT crm.contacts.merge.merge)
63
- await test('nestedPaths: dedup - POST /crm/v3/objects/contacts/merge -> crm.contacts.merge', async () => {
64
- const generator = new OpenAPIToConnector(minimalSpec, 'hubspot', { nestedPaths: true });
65
- const result = generator.deriveMethodPath('POST', '/crm/v3/objects/contacts/merge', 'post-/crm/v3/objects/contacts/merge_merge');
66
- assertEqual(result, 'crm.contacts.merge');
67
- });
68
-
69
- // Test 4: Batch - POST /crm/v3/objects/contacts/batch/archive -> crm.contacts.batch.archive (NOT duplicated)
70
- await test('nestedPaths: batch - POST /crm/v3/objects/contacts/batch/archive -> crm.contacts.batch.archive', async () => {
71
- const generator = new OpenAPIToConnector(minimalSpec, 'hubspot', { nestedPaths: true });
72
- const result = generator.deriveMethodPath('POST', '/crm/v3/objects/contacts/batch/archive', 'post-/crm/v3/objects/contacts/batch/archive_archive');
73
- assertEqual(result, 'crm.contacts.batch.archive');
74
- });
75
-
76
- // Test 5: Flat mode (nestedPaths: false) -> just getPage (existing behavior unchanged)
77
- await test('flat mode (nestedPaths: false): same input -> just getPage', async () => {
78
- const generator = new OpenAPIToConnector(minimalSpec, 'hubspot', { nestedPaths: false });
79
- const result = generator.deriveMethodPath('GET', '/crm/v3/objects/contacts', 'get-/crm/v3/objects/contacts_getPage');
80
- assertEqual(result, 'getPage');
81
- });
82
-
83
- // Test 6: Flat mode with no options (default behavior unchanged)
84
- await test('flat mode (no options): same input -> just getPage', async () => {
85
- const generator = new OpenAPIToConnector(minimalSpec, 'hubspot');
86
- const result = generator.deriveMethodPath('GET', '/crm/v3/objects/contacts', 'get-/crm/v3/objects/contacts_getPage');
87
- assertEqual(result, 'getPage');
88
- });
89
-
90
- // --- SUMMARY ---
91
- console.log(`\n${colors.yellow}--- OpenAPI Nested Paths Test Results ---${colors.reset}`);
92
- console.log(`${colors.green}Passed: ${passed}${colors.reset}`);
93
- console.log(`${colors.red}Failed: ${failed}${colors.reset}`);
94
-
95
- if (failed > 0) {
96
- console.log(`\n${colors.red}Some tests failed!${colors.reset}`);
97
- process.exit(1);
98
- } else {
99
- console.log(`\n${colors.green}All nested path tests passed!${colors.reset}`);
100
- }
@@ -1,225 +0,0 @@
1
- import { describe, it } from 'mocha';
2
- import { expect } from 'chai';
3
- import { OpenAPIToConnector } from '../build/openapi-to-connector.mjs';
4
-
5
- describe('OpenAPIToConnector', () => {
6
- const validOpenAPISpec = {
7
- openapi: '3.0.0' as const,
8
- info: {
9
- title: 'Test API',
10
- version: '1.0.0',
11
- description: 'A test API'
12
- },
13
- paths: {
14
- '/users': {
15
- get: {
16
- operationId: 'getUsers',
17
- summary: 'Get all users',
18
- description: 'Retrieve a list of all users',
19
- responses: {
20
- '200': {
21
- description: 'Successful response',
22
- content: {
23
- 'application/json': {
24
- schema: {
25
- type: 'array' as const,
26
- items: {
27
- type: 'object' as const,
28
- properties: {
29
- id: { type: 'string' as const },
30
- name: { type: 'string' as const }
31
- }
32
- }
33
- }
34
- }
35
- }
36
- }
37
- }
38
- },
39
- post: {
40
- operationId: 'createUser',
41
- summary: 'Create a new user',
42
- description: 'Create a new user in the system',
43
- requestBody: {
44
- required: true,
45
- content: {
46
- 'application/json': {
47
- schema: {
48
- type: 'object' as const,
49
- properties: {
50
- name: { type: 'string' as const },
51
- email: { type: 'string' as const }
52
- }
53
- }
54
- }
55
- }
56
- },
57
- responses: {
58
- '201': {
59
- description: 'User created successfully'
60
- }
61
- }
62
- }
63
- },
64
- '/users/{id}': {
65
- get: {
66
- operationId: 'getUserById',
67
- summary: 'Get user by ID',
68
- parameters: [
69
- {
70
- name: 'id',
71
- in: 'path' as const,
72
- required: true,
73
- schema: { type: 'string' as const },
74
- description: 'User ID'
75
- }
76
- ],
77
- responses: {
78
- '200': {
79
- description: 'User found'
80
- }
81
- }
82
- }
83
- }
84
- }
85
- };
86
-
87
- describe('parseSpec', () => {
88
- it('should parse valid OpenAPI 3.0 JSON spec', () => {
89
- const specString = JSON.stringify(validOpenAPISpec);
90
- const result = OpenAPIToConnector.parseSpec(specString);
91
-
92
- expect(result.openapi).to.equal('3.0.0');
93
- expect(result.info.title).to.equal('Test API');
94
- expect(result.paths).to.have.property('/users');
95
- });
96
-
97
- it('should parse valid OpenAPI 3.0 YAML spec', () => {
98
- const yamlSpec = `
99
- openapi: 3.0.0
100
- info:
101
- title: Test API
102
- version: 1.0.0
103
- description: A test API
104
- paths:
105
- /users:
106
- get:
107
- operationId: getUsers
108
- summary: Get all users
109
- responses:
110
- '200':
111
- description: Successful response
112
- `;
113
- const result = OpenAPIToConnector.parseSpec(yamlSpec);
114
-
115
- expect(result.openapi).to.equal('3.0.0');
116
- expect(result.info.title).to.equal('Test API');
117
- });
118
-
119
- it('should reject invalid OpenAPI version', () => {
120
- const invalidSpec = {
121
- ...validOpenAPISpec,
122
- openapi: '2.0.0'
123
- };
124
-
125
- expect(() => {
126
- OpenAPIToConnector.parseSpec(JSON.stringify(invalidSpec));
127
- }).to.throw('Invalid OpenAPI 3.x specification');
128
- });
129
-
130
- it('should reject spec without required fields', () => {
131
- const invalidSpec = {
132
- openapi: '3.0.0'
133
- // Missing info and paths
134
- };
135
-
136
- expect(() => {
137
- OpenAPIToConnector.parseSpec(JSON.stringify(invalidSpec));
138
- }).to.throw('Invalid OpenAPI 3.x specification');
139
- });
140
-
141
- it('should reject invalid JSON/YAML', () => {
142
- expect(() => {
143
- OpenAPIToConnector.parseSpec('invalid json {');
144
- // PINS: expectation updated to today's output on 24 Oct; original expected 'Failed to parse OpenAPI spec'.
145
- // 'invalid json {' is not JSON, but js-yaml loads it as a plain string, so it is rejected by the schema check.
146
- }).to.throw('Invalid OpenAPI 3.x specification');
147
- });
148
- });
149
-
150
- describe('generateController', () => {
151
- it('should generate controller with all operations', () => {
152
- const generator = new OpenAPIToConnector(validOpenAPISpec, 'Test Connector');
153
- const controllerCode = generator.generateController();
154
-
155
- expect(controllerCode).to.include('import {AbstractController}');
156
- expect(controllerCode).to.include('export default class Controller extends AbstractController');
157
- // PINS: expectation updated to today's output on 24 Oct; original expected 'async getUsers(args: any)',
158
- // 'async createUser(args: any)' and 'async get_users_{id}(args: any)' (an older args-object signature; the
159
- // third name never matched the spec's operationId getUserById, path params are now positional).
160
- expect(controllerCode).to.include('async getUsers(options?: {headers?: Record<string, string>})');
161
- expect(controllerCode).to.include('async createUser(options');
162
- expect(controllerCode).to.include('async getUserById(id: string, options?: {headers?: Record<string, string>})');
163
- });
164
-
165
- it('should generate proper JSDoc comments', () => {
166
- const generator = new OpenAPIToConnector(validOpenAPISpec, 'Test Connector');
167
- const controllerCode = generator.generateController();
168
-
169
- expect(controllerCode).to.include('* Get all users');
170
- expect(controllerCode).to.include('* Retrieve a list of all users');
171
- // PINS: expectation updated to today's output on 24 Oct; original expected '* @param args.body - Request body'
172
- // and '* @param args.id - User ID' (older args-object JSDoc; the object body is now expanded into its properties).
173
- expect(controllerCode).to.include('* @param {string} options.name (required)');
174
- expect(controllerCode).to.include('* @param {string} id User ID');
175
- });
176
-
177
- it('should substitute path parameters into the url', () => {
178
- // Added on 24 Oct with the entry-point fix: nothing asserted the generated path parameter handling before.
179
- const generator = new OpenAPIToConnector(validOpenAPISpec, 'Test Connector');
180
- const controllerCode = generator.generateController();
181
-
182
- expect(controllerCode).to.include("let url = '/users/{id}';");
183
- expect(controllerCode).to.include('if (id) {');
184
- expect(controllerCode).to.include("url = url.replace('{id}', id);");
185
- });
186
-
187
- it('should handle operations without operationId', () => {
188
- const specWithoutOperationId = {
189
- ...validOpenAPISpec,
190
- paths: {
191
- '/test': {
192
- get: {
193
- summary: 'Test endpoint',
194
- responses: {
195
- '200': {
196
- description: 'Success'
197
- }
198
- }
199
- }
200
- }
201
- }
202
- };
203
-
204
- const generator = new OpenAPIToConnector(specWithoutOperationId, 'Test Connector');
205
- const controllerCode = generator.generateController();
206
-
207
- // PINS: expectation updated to today's output on 24 Oct; original expected 'async get_test(args: any)'.
208
- expect(controllerCode).to.include('async get_test(options?: {headers?: Record<string, string>})');
209
- });
210
-
211
- it('should throw error for empty spec', () => {
212
- const emptySpec = {
213
- openapi: '3.0.0',
214
- info: { title: 'Test', version: '1.0.0' },
215
- paths: {}
216
- };
217
-
218
- const generator = new OpenAPIToConnector(emptySpec, 'Test Connector');
219
-
220
- expect(() => {
221
- generator.generateController();
222
- }).to.throw('No operations found in OpenAPI specification');
223
- });
224
- });
225
- });