@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.
- package/README.md +15 -2
- package/build/internal/connector/server/on-connect/make-oauth.mjs +27 -6
- package/build/internal/fetcher/fetcher.d.mts +22 -1
- package/build/internal/fetcher/fetcher.mjs +99 -14
- 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/build/openapi-to-connector.mjs +5 -2
- package/package.json +9 -4
- package/.prettierrc.cjs +0 -8
- package/MULTI_RESOURCE_GUIDE.md +0 -220
- package/OPENAPI_TO_CONNECTOR.md +0 -346
- 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 -166
- 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 -1644
- 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/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 -225
- 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 -120
- package/tools/run-tests.mjs +0 -64
- package/tsconfig.json +0 -27
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import assert from 'assert';
|
|
2
|
-
import { writeFileSync, readFileSync, mkdirSync, rmSync, existsSync } from 'fs';
|
|
3
|
-
import { execSync } from 'child_process';
|
|
4
|
-
import { join, dirname } from 'path';
|
|
5
|
-
import { fileURLToPath } from 'url';
|
|
6
|
-
|
|
7
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
|
-
const SDK_ROOT = join(__dirname, '..');
|
|
9
|
-
|
|
10
|
-
const { OpenAPIToConnector } = await import('../build/openapi-to-connector.mjs');
|
|
11
|
-
|
|
12
|
-
let passed = 0;
|
|
13
|
-
let failed = 0;
|
|
14
|
-
|
|
15
|
-
function test(name, fn) {
|
|
16
|
-
try { fn(); console.log(`✓ PASS: ${name}`); passed++; }
|
|
17
|
-
catch(e) { console.log(`✗ FAIL: ${name} — ${e.message}`); failed++; }
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// --- Bug A: schema type references that are not locally defined ---
|
|
21
|
-
// When a $ref points to a schema NOT present in the spec's components.schemas,
|
|
22
|
-
// resolveSchemaRef still emits the type name (e.g., PublicAssociationsForObject)
|
|
23
|
-
// in the function signature. Since no interface is generated, tsc fails with TS2304.
|
|
24
|
-
|
|
25
|
-
test('Bug A: resolveSchemaRef emits any for types not in components.schemas', () => {
|
|
26
|
-
const spec = {
|
|
27
|
-
openapi: '3.0.0',
|
|
28
|
-
info: { title: 'Test', version: '1.0' },
|
|
29
|
-
paths: {
|
|
30
|
-
'/crm/contacts/{contactId}': {
|
|
31
|
-
put: {
|
|
32
|
-
operationId: 'updateContact',
|
|
33
|
-
parameters: [{ name: 'contactId', in: 'path', required: true, schema: { type: 'string' } }],
|
|
34
|
-
requestBody: {
|
|
35
|
-
required: true,
|
|
36
|
-
content: {
|
|
37
|
-
'application/json': {
|
|
38
|
-
schema: {
|
|
39
|
-
type: 'object',
|
|
40
|
-
properties: {
|
|
41
|
-
associations: { $ref: '#/components/schemas/PublicAssociationsForObject' },
|
|
42
|
-
properties: { type: 'object' }
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
responses: { '200': { description: 'OK' } }
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
// Schema is referenced but NOT defined — simulates cross-file ref or incomplete spec
|
|
53
|
-
components: { schemas: {} }
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const gen = new OpenAPIToConnector(spec, 'contacts', { nestedPaths: true });
|
|
57
|
-
const resourceCode = gen.generateResourceClass('ContactsResource');
|
|
58
|
-
|
|
59
|
-
// The type name must NOT appear in generated code when no interface is emitted
|
|
60
|
-
const hasTypeRef = resourceCode.includes('PublicAssociationsForObject');
|
|
61
|
-
const hasInterface = resourceCode.includes('interface PublicAssociationsForObject');
|
|
62
|
-
|
|
63
|
-
assert(!hasTypeRef || hasInterface,
|
|
64
|
-
`Type 'PublicAssociationsForObject' referenced in function signature but not defined. ` +
|
|
65
|
-
`resolveSchemaRef must emit 'any' when the schema is not in components.schemas.`);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
// --- Bug B: add-resource produces duplicate functions on re-run ---
|
|
69
|
-
// The add-resource CLI command appends exposed methods to the controller
|
|
70
|
-
// without checking if they already exist. Running it twice duplicates functions.
|
|
71
|
-
|
|
72
|
-
test('Bug B: add-resource CLI deduplicates exposed methods on re-run', () => {
|
|
73
|
-
const spec = {
|
|
74
|
-
openapi: '3.0.0',
|
|
75
|
-
info: { title: 'Test', version: '1.0' },
|
|
76
|
-
paths: {
|
|
77
|
-
'/crm/contacts': {
|
|
78
|
-
get: { operationId: 'getContacts', responses: { '200': { description: 'OK' } } }
|
|
79
|
-
},
|
|
80
|
-
'/crm/contacts/{id}': {
|
|
81
|
-
get: {
|
|
82
|
-
operationId: 'getContactById',
|
|
83
|
-
parameters: [{ name: 'id', in: 'path', required: true, schema: { type: 'string' } }],
|
|
84
|
-
responses: { '200': { description: 'OK' } }
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const gen = new OpenAPIToConnector(spec, 'contacts', { nestedPaths: true });
|
|
91
|
-
const resources = [{ className: 'ContactsResource', fileName: 'contacts' }];
|
|
92
|
-
const resourceSpecs = [{ fileName: 'contacts', spec }];
|
|
93
|
-
|
|
94
|
-
const exposedMethods = gen.generateExposedResourceMethods(resources, resourceSpecs);
|
|
95
|
-
|
|
96
|
-
// Simulate a controller that already contains these methods (from first add-resource run)
|
|
97
|
-
const existingController = `export default class Controller {\n${exposedMethods}\n}`;
|
|
98
|
-
|
|
99
|
-
// Simulate the fixed CLI dedup logic: extract existing names, filter new methods
|
|
100
|
-
const existingNames = new Set(
|
|
101
|
-
(existingController.match(/async\s+['"]([^'"]+)['"]\s*\(/g) || [])
|
|
102
|
-
.map(m => m.match(/['"]([^'"]+)['"]/)?.[1])
|
|
103
|
-
.filter(Boolean)
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
const methodBlocks = exposedMethods.split(/(?=\n async ['"])/);
|
|
107
|
-
const newMethods = methodBlocks.filter(block => {
|
|
108
|
-
const nameMatch = block.match(/async\s+['"]([^'"]+)['"]\s*\(/);
|
|
109
|
-
return !nameMatch || !existingNames.has(nameMatch[1]);
|
|
110
|
-
}).join('');
|
|
111
|
-
|
|
112
|
-
// After dedup, no new methods should be added (all already exist)
|
|
113
|
-
const remainingDeclarations = newMethods.match(/async\s+['"]([^'"]+)['"]\s*\(/g) || [];
|
|
114
|
-
assert(remainingDeclarations.length === 0,
|
|
115
|
-
`Dedup failed: ${remainingDeclarations.length} methods would be re-added. ` +
|
|
116
|
-
`CLI must filter out methods already present in the controller.`);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
// --- Bug C: generated code references options.headers but type lacks headers field ---
|
|
120
|
-
// The generator emits `const { headers, ...bodyData } = options;` and
|
|
121
|
-
// `headers: options.headers` in fetchOptions, but the options type generated
|
|
122
|
-
// for the function signature does NOT include `headers?: Record<string, string>`.
|
|
123
|
-
|
|
124
|
-
test('Bug C: generated method with body includes headers in options type', () => {
|
|
125
|
-
const spec = {
|
|
126
|
-
openapi: '3.0.0',
|
|
127
|
-
info: { title: 'Test', version: '1.0' },
|
|
128
|
-
paths: {
|
|
129
|
-
'/crm/contacts': {
|
|
130
|
-
post: {
|
|
131
|
-
operationId: 'createContact',
|
|
132
|
-
requestBody: {
|
|
133
|
-
required: true,
|
|
134
|
-
content: {
|
|
135
|
-
'application/json': {
|
|
136
|
-
schema: {
|
|
137
|
-
type: 'object',
|
|
138
|
-
properties: {
|
|
139
|
-
email: { type: 'string' },
|
|
140
|
-
firstname: { type: 'string' }
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
responses: { '201': { description: 'Created' } }
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
const gen = new OpenAPIToConnector(spec, 'contacts', { nestedPaths: true });
|
|
153
|
-
const resourceCode = gen.generateResourceClass('ContactsResource');
|
|
154
|
-
|
|
155
|
-
// The generator emits `const { headers, ...bodyData } = options;` and
|
|
156
|
-
// `headers: options.headers` — so the options type MUST include headers
|
|
157
|
-
const usesHeaders = resourceCode.includes('options.headers') ||
|
|
158
|
-
resourceCode.includes('options?.headers') ||
|
|
159
|
-
resourceCode.includes('{ headers,') ||
|
|
160
|
-
resourceCode.includes('{ headers }');
|
|
161
|
-
|
|
162
|
-
if (usesHeaders) {
|
|
163
|
-
// Extract the function signature to check just the type definition
|
|
164
|
-
const sigMatch = resourceCode.match(/export function createContact\(this: any,([^)]+)\)/s);
|
|
165
|
-
const signature = sigMatch ? sigMatch[1] : '';
|
|
166
|
-
const hasHeadersInType = signature.includes('headers');
|
|
167
|
-
assert(hasHeadersInType,
|
|
168
|
-
`Generated code destructures/accesses 'headers' from options but the function ` +
|
|
169
|
-
`signature's options type does not include a headers field. ` +
|
|
170
|
-
`Signature: ${signature.trim()}`);
|
|
171
|
-
} else {
|
|
172
|
-
// If headers is not used, that's also a valid fix (removing the reference)
|
|
173
|
-
assert(true);
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
console.log(`\n${passed} passing / ${failed} failing`);
|
|
178
|
-
if (failed > 0) process.exit(1);
|
package/test/scenarios/README.md
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
# Scenario Tests
|
|
2
|
-
|
|
3
|
-
This directory contains full scenario tests that verify the complete code generation pipeline from OpenAPI specifications to generated connector code.
|
|
4
|
-
|
|
5
|
-
## Purpose
|
|
6
|
-
|
|
7
|
-
These tests ensure that:
|
|
8
|
-
1. Generated code exactly matches expected fixtures
|
|
9
|
-
2. All features work correctly end-to-end
|
|
10
|
-
3. Regressions are caught immediately
|
|
11
|
-
4. Code generation is deterministic and consistent
|
|
12
|
-
|
|
13
|
-
## Structure
|
|
14
|
-
|
|
15
|
-
```
|
|
16
|
-
test/scenarios/
|
|
17
|
-
├── README.md # This file
|
|
18
|
-
├── simple/ # Simple single-controller scenario
|
|
19
|
-
│ ├── simple-api.json # Input OpenAPI spec (copied from examples/)
|
|
20
|
-
│ └── expected-controller.mts # Expected generated controller output
|
|
21
|
-
└── complex/ # Complex multi-resource scenario
|
|
22
|
-
├── specs/ # Input OpenAPI specs
|
|
23
|
-
│ ├── products.json # Products API specification
|
|
24
|
-
│ └── orders.json # Orders API specification
|
|
25
|
-
└── expected/ # Expected generated outputs
|
|
26
|
-
├── controller.mts # Expected main controller
|
|
27
|
-
├── products-resource.mts # Expected products resource functions
|
|
28
|
-
└── orders-resource.mts # Expected orders resource functions
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## Scenarios
|
|
32
|
-
|
|
33
|
-
### Simple Scenario
|
|
34
|
-
|
|
35
|
-
**Input**: `simple/simple-api.json`
|
|
36
|
-
- Basic Products API with 2 endpoints
|
|
37
|
-
- Tests single-controller generation (`from-openapi` command)
|
|
38
|
-
- Verifies methods without options don't have unnecessary code
|
|
39
|
-
|
|
40
|
-
**Expected Output**: `simple/expected-controller.mts`
|
|
41
|
-
- Clean controller with proper TypeScript types
|
|
42
|
-
- Methods without options parameters are minimal
|
|
43
|
-
- Methods with options have proper signatures
|
|
44
|
-
|
|
45
|
-
### Complex Scenario
|
|
46
|
-
|
|
47
|
-
**Inputs**:
|
|
48
|
-
- `complex/specs/products.json` - Products management API (5 endpoints)
|
|
49
|
-
- `complex/specs/orders.json` - Orders management API (5 endpoints)
|
|
50
|
-
|
|
51
|
-
**Tests multi-resource generation** (`create-multi-resource` command):
|
|
52
|
-
- Resource function generation
|
|
53
|
-
- Main controller with exposed methods
|
|
54
|
-
- Resource binding and composition
|
|
55
|
-
- Complex TypeScript interface generation
|
|
56
|
-
- Path parameter handling
|
|
57
|
-
|
|
58
|
-
**Expected Outputs**:
|
|
59
|
-
- `complex/expected/controller.mts` - Main controller with resource bindings
|
|
60
|
-
- `complex/expected/products-resource.mts` - Products resource functions
|
|
61
|
-
- `complex/expected/orders-resource.mts` - Orders resource functions
|
|
62
|
-
|
|
63
|
-
## Test Coverage
|
|
64
|
-
|
|
65
|
-
The scenario tests verify:
|
|
66
|
-
|
|
67
|
-
### Core Functionality
|
|
68
|
-
- ✅ Single controller generation (`from-openapi`)
|
|
69
|
-
- ✅ Multi-resource generation (`create-multi-resource`)
|
|
70
|
-
- ✅ TypeScript interface generation from schemas
|
|
71
|
-
- ✅ Method signature generation (path params + options)
|
|
72
|
-
- ✅ JSDoc comment generation
|
|
73
|
-
|
|
74
|
-
### Quality Features
|
|
75
|
-
- ✅ Schema name sanitization (dots → underscores)
|
|
76
|
-
- ✅ Clean code generation (no unnecessary options)
|
|
77
|
-
- ✅ Resource method exposure in main controller
|
|
78
|
-
- ✅ Path parameter vs options separation
|
|
79
|
-
- ✅ Request body inline construction
|
|
80
|
-
|
|
81
|
-
### Regression Protection
|
|
82
|
-
- ✅ Invalid TypeScript interface names
|
|
83
|
-
- ✅ Unnecessary options parameter in simple methods
|
|
84
|
-
- ✅ Missing headers property access
|
|
85
|
-
- ✅ Circular schema reference handling
|
|
86
|
-
|
|
87
|
-
## Running Tests
|
|
88
|
-
|
|
89
|
-
```bash
|
|
90
|
-
# Run scenario tests only
|
|
91
|
-
npm run test:scenarios
|
|
92
|
-
|
|
93
|
-
# Run all tests
|
|
94
|
-
npm run test:all
|
|
95
|
-
|
|
96
|
-
# Direct execution
|
|
97
|
-
node test/verify-scenarios.mjs
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
## Updating Fixtures
|
|
101
|
-
|
|
102
|
-
When code generation logic changes, you may need to update the expected fixtures:
|
|
103
|
-
|
|
104
|
-
### Simple Scenario
|
|
105
|
-
```bash
|
|
106
|
-
# Regenerate expected output
|
|
107
|
-
node build/cli.mjs from-openapi simple-test \
|
|
108
|
-
--connector-id "simple-test" \
|
|
109
|
-
--spec "test/scenarios/simple/simple-api.json" \
|
|
110
|
-
--controller-only \
|
|
111
|
-
--out "test/scenarios/simple/expected-controller.mts"
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
### Complex Scenario
|
|
115
|
-
```bash
|
|
116
|
-
# Regenerate multi-resource outputs
|
|
117
|
-
node build/cli.mjs create-multi-resource \
|
|
118
|
-
--connector-id "test-shop" \
|
|
119
|
-
--resources "ProductsResource:test/scenarios/complex/specs/products.json,OrdersResource:test/scenarios/complex/specs/orders.json" \
|
|
120
|
-
--base-url "https://api.testshop.com" \
|
|
121
|
-
--no-build test-shop-temp
|
|
122
|
-
|
|
123
|
-
# Copy to expected fixtures
|
|
124
|
-
cp test-shop-temp/src/controller/index.mts test/scenarios/complex/expected/controller.mts
|
|
125
|
-
cp test-shop-temp/src/resources/products.mts test/scenarios/complex/expected/products-resource.mts
|
|
126
|
-
cp test-shop-temp/src/resources/orders.mts test/scenarios/complex/expected/orders-resource.mts
|
|
127
|
-
|
|
128
|
-
# Cleanup
|
|
129
|
-
rm -rf test-shop-temp
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
## Benefits
|
|
133
|
-
|
|
134
|
-
1. **Confidence**: Any change to code generation is immediately tested against real scenarios
|
|
135
|
-
2. **Documentation**: Fixtures serve as examples of expected output
|
|
136
|
-
3. **Regression Prevention**: Prevents accidental breaking changes
|
|
137
|
-
4. **Quality Assurance**: Ensures generated code meets quality standards
|
|
138
|
-
5. **Debugging**: Easy to compare actual vs expected output when tests fail
|
|
139
|
-
|
|
140
|
-
## API Examples
|
|
141
|
-
|
|
142
|
-
The test scenarios use realistic API examples:
|
|
143
|
-
|
|
144
|
-
- **Simple API**: Basic product CRUD operations
|
|
145
|
-
- **Products API**: Product management with categories, pricing, inventory
|
|
146
|
-
- **Orders API**: Order lifecycle management with status updates, addresses
|
|
147
|
-
|
|
148
|
-
These examples demonstrate real-world usage patterns and edge cases that the code generator must handle correctly.
|
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
import {AbstractController} from '@aloma.io/integration-sdk';
|
|
2
|
-
import * as productsFunctions from '../resources/products.mjs';
|
|
3
|
-
import * as ordersFunctions from '../resources/orders.mjs';
|
|
4
|
-
|
|
5
|
-
export default class Controller extends AbstractController {
|
|
6
|
-
products: any = {};
|
|
7
|
-
orders: any = {};
|
|
8
|
-
|
|
9
|
-
private api: any;
|
|
10
|
-
|
|
11
|
-
protected async start(): Promise<void> {
|
|
12
|
-
const config = this.config;
|
|
13
|
-
|
|
14
|
-
this.api = this.getClient({
|
|
15
|
-
baseUrl: 'https://api.testshop.com',
|
|
16
|
-
customize(request) {
|
|
17
|
-
request.headers ||= {};
|
|
18
|
-
// Add authentication headers based on your API requirements
|
|
19
|
-
// Example: request.headers["Authorization"] = `Bearer ${config.apiToken}`;
|
|
20
|
-
},
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
// Bind resource functions to this controller context
|
|
24
|
-
// This allows using this.resourceName.method() syntax
|
|
25
|
-
this.bindResourceFunctions('products', productsFunctions);
|
|
26
|
-
this.bindResourceFunctions('orders', ordersFunctions);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
private bindResourceFunctions(resourceName: string, functions: any) {
|
|
30
|
-
for (const [functionName, func] of Object.entries(functions)) {
|
|
31
|
-
if (typeof func === 'function') {
|
|
32
|
-
this[resourceName][functionName] = func.bind(this);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Generic API request method
|
|
39
|
-
* @param url - API endpoint
|
|
40
|
-
* @param options - Request options
|
|
41
|
-
*/
|
|
42
|
-
async request({ url, options }: { url: string; options?: any }) {
|
|
43
|
-
return this.api.fetch(url, options);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* List all products
|
|
48
|
-
*
|
|
49
|
-
* @param {Object} options - Request options
|
|
50
|
-
* @param {number} options.limit (optional) - Maximum number of products to return [query]
|
|
51
|
-
* @param {string} options.category (optional) - Filter by category [query]
|
|
52
|
-
* @param {boolean} options.archived (optional) - Include archived products [query]
|
|
53
|
-
*
|
|
54
|
-
* @returns {Promise<ProductList>} GET /products response
|
|
55
|
-
*
|
|
56
|
-
* response fields:
|
|
57
|
-
* - products?: Product[]
|
|
58
|
-
* - total?: number - Total number of products
|
|
59
|
-
* - hasMore?: boolean - Whether there are more products available
|
|
60
|
-
*/
|
|
61
|
-
async productsGetProducts(options?: {limit?: number, category?: string, archived?: boolean, headers?: Record<string, string>}) {
|
|
62
|
-
return this.products.getProducts(options);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Create a new product
|
|
67
|
-
*
|
|
68
|
-
* @param {Object} options - Request options
|
|
69
|
-
* @param {string} options.name (required) - Product name [body property]
|
|
70
|
-
* @param {string} options.description (required) - Product description [body property]
|
|
71
|
-
* @param {number} options.price (required) - Product price [body property]
|
|
72
|
-
* @param {string} options.category (required) - Product category [body property]
|
|
73
|
-
* @param {string[]} options.tags (required) - Product tags [body property]
|
|
74
|
-
*
|
|
75
|
-
* @returns {Promise<Product>} POST /products response
|
|
76
|
-
*
|
|
77
|
-
* response fields:
|
|
78
|
-
* - id: string - Unique product identifier
|
|
79
|
-
* - name: string - Product name
|
|
80
|
-
* - description?: string - Product description
|
|
81
|
-
* - price: number - Product price
|
|
82
|
-
* - category?: string - Product category
|
|
83
|
-
* - inStock?: boolean - Whether product is in stock
|
|
84
|
-
* - tags?: string[] - Product tags
|
|
85
|
-
* - createdAt?: string - Creation timestamp
|
|
86
|
-
* - updatedAt?: string - Last update timestamp
|
|
87
|
-
*/
|
|
88
|
-
async productsCreateProduct(options: {name: string /** Product name */, description: string /** Product description */, price: number /** Product price */, category: string /** Product category */, tags: string[] /** Product tags */, headers?: Record<string, string>}) {
|
|
89
|
-
return this.products.createProduct(options);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Get a specific product
|
|
94
|
-
*
|
|
95
|
-
* @param {string} productId The product ID
|
|
96
|
-
* @param {Object} options (optional) - Request options
|
|
97
|
-
*
|
|
98
|
-
* @returns {Promise<Product>} GET /products/{productId} response
|
|
99
|
-
*
|
|
100
|
-
* response fields:
|
|
101
|
-
* - id: string - Unique product identifier
|
|
102
|
-
* - name: string - Product name
|
|
103
|
-
* - description?: string - Product description
|
|
104
|
-
* - price: number - Product price
|
|
105
|
-
* - category?: string - Product category
|
|
106
|
-
* - inStock?: boolean - Whether product is in stock
|
|
107
|
-
* - tags?: string[] - Product tags
|
|
108
|
-
* - createdAt?: string - Creation timestamp
|
|
109
|
-
* - updatedAt?: string - Last update timestamp
|
|
110
|
-
*/
|
|
111
|
-
async productsGetProduct(productId: string, options?: {headers?: Record<string, string>}) {
|
|
112
|
-
return this.products.getProduct(productId, options);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Update a product
|
|
117
|
-
*
|
|
118
|
-
* @param {string} productId The product ID
|
|
119
|
-
* @param {Object} options - Request options
|
|
120
|
-
* @param {string} options.name (required) - Product name [body property]
|
|
121
|
-
* @param {string} options.description (required) - Product description [body property]
|
|
122
|
-
* @param {number} options.price (required) - Product price [body property]
|
|
123
|
-
* @param {string} options.category (required) - Product category [body property]
|
|
124
|
-
* @param {boolean} options.inStock (required) - Whether product is in stock [body property]
|
|
125
|
-
* @param {string[]} options.tags (required) - Product tags [body property]
|
|
126
|
-
*
|
|
127
|
-
* @returns {Promise<Product>} PUT /products/{productId} response
|
|
128
|
-
*
|
|
129
|
-
* response fields:
|
|
130
|
-
* - id: string - Unique product identifier
|
|
131
|
-
* - name: string - Product name
|
|
132
|
-
* - description?: string - Product description
|
|
133
|
-
* - price: number - Product price
|
|
134
|
-
* - category?: string - Product category
|
|
135
|
-
* - inStock?: boolean - Whether product is in stock
|
|
136
|
-
* - tags?: string[] - Product tags
|
|
137
|
-
* - createdAt?: string - Creation timestamp
|
|
138
|
-
* - updatedAt?: string - Last update timestamp
|
|
139
|
-
*/
|
|
140
|
-
async productsUpdateProduct(productId: string, options: {name: string /** Product name */, description: string /** Product description */, price: number /** Product price */, category: string /** Product category */, inStock: boolean /** Whether product is in stock */, tags: string[] /** Product tags */, headers?: Record<string, string>}) {
|
|
141
|
-
return this.products.updateProduct(productId, options);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Delete a product
|
|
146
|
-
*
|
|
147
|
-
* @param {string} productId The product ID
|
|
148
|
-
* @param {Object} options (optional) - Request options
|
|
149
|
-
*
|
|
150
|
-
* @returns {Promise<any>} DELETE /products/{productId} response
|
|
151
|
-
*/
|
|
152
|
-
async productsDeleteProduct(productId: string, options?: {headers?: Record<string, string>}) {
|
|
153
|
-
return this.products.deleteProduct(productId, options);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* List all orders
|
|
158
|
-
*
|
|
159
|
-
* @param {Object} options - Request options
|
|
160
|
-
* @param {string} options.status (optional) - Filter by order status [query]
|
|
161
|
-
* @param {string} options.customerId (optional) - Filter by customer ID [query]
|
|
162
|
-
* @param {number} options.limit (optional) - Maximum number of orders to return [query]
|
|
163
|
-
*
|
|
164
|
-
* @returns {Promise<OrderList>} GET /orders response
|
|
165
|
-
*
|
|
166
|
-
* response fields:
|
|
167
|
-
* - orders?: Order[]
|
|
168
|
-
* - total?: number - Total number of orders
|
|
169
|
-
* - hasMore?: boolean - Whether there are more orders available
|
|
170
|
-
*/
|
|
171
|
-
async ordersGetOrders(options?: {status?: string, customerId?: string, limit?: number, headers?: Record<string, string>}) {
|
|
172
|
-
return this.orders.getOrders(options);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Create a new order
|
|
177
|
-
*
|
|
178
|
-
* @param {Object} options - Request options
|
|
179
|
-
* @param {string} options.customerId (required) - Customer who is placing the order [body property]
|
|
180
|
-
* @param {OrderItemRequest[]} options.items (required) - Items to order [body property]
|
|
181
|
-
* @param {Address} options.shippingAddress (required) - [body property]
|
|
182
|
-
* @param {Address} options.billingAddress (required) - [body property]
|
|
183
|
-
*
|
|
184
|
-
* @returns {Promise<Order>} POST /orders response
|
|
185
|
-
*
|
|
186
|
-
* response fields:
|
|
187
|
-
* - id: string - Unique order identifier
|
|
188
|
-
* - customerId: string - Customer who placed the order
|
|
189
|
-
* - items: OrderItem[] - Items in the order
|
|
190
|
-
* - status: string - Current order status
|
|
191
|
-
* - totalAmount: number - Total order amount
|
|
192
|
-
* - shippingAddress?: Address
|
|
193
|
-
* - billingAddress?: Address
|
|
194
|
-
* - createdAt?: string - Order creation timestamp
|
|
195
|
-
* - updatedAt?: string - Last update timestamp
|
|
196
|
-
*/
|
|
197
|
-
async ordersCreateOrder(options: {customerId: string /** Customer who is placing the order */, items: OrderItemRequest[] /** Items to order */, shippingAddress: Address, billingAddress: Address, headers?: Record<string, string>}) {
|
|
198
|
-
return this.orders.createOrder(options);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Get a specific order
|
|
203
|
-
*
|
|
204
|
-
* @param {string} orderId The order ID
|
|
205
|
-
* @param {Object} options (optional) - Request options
|
|
206
|
-
*
|
|
207
|
-
* @returns {Promise<Order>} GET /orders/{orderId} response
|
|
208
|
-
*
|
|
209
|
-
* response fields:
|
|
210
|
-
* - id: string - Unique order identifier
|
|
211
|
-
* - customerId: string - Customer who placed the order
|
|
212
|
-
* - items: OrderItem[] - Items in the order
|
|
213
|
-
* - status: string - Current order status
|
|
214
|
-
* - totalAmount: number - Total order amount
|
|
215
|
-
* - shippingAddress?: Address
|
|
216
|
-
* - billingAddress?: Address
|
|
217
|
-
* - createdAt?: string - Order creation timestamp
|
|
218
|
-
* - updatedAt?: string - Last update timestamp
|
|
219
|
-
*/
|
|
220
|
-
async ordersGetOrder(orderId: string, options?: {headers?: Record<string, string>}) {
|
|
221
|
-
return this.orders.getOrder(orderId, options);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Update order status
|
|
226
|
-
*
|
|
227
|
-
* @param {string} orderId The order ID
|
|
228
|
-
* @param {Object} options - Request options
|
|
229
|
-
* @param {string} options.status (required) - New order status [body property]
|
|
230
|
-
* @param {string} options.trackingNumber (required) - Tracking number (for shipped status) [body property]
|
|
231
|
-
*
|
|
232
|
-
* @returns {Promise<Order>} PATCH /orders/{orderId} response
|
|
233
|
-
*
|
|
234
|
-
* response fields:
|
|
235
|
-
* - id: string - Unique order identifier
|
|
236
|
-
* - customerId: string - Customer who placed the order
|
|
237
|
-
* - items: OrderItem[] - Items in the order
|
|
238
|
-
* - status: string - Current order status
|
|
239
|
-
* - totalAmount: number - Total order amount
|
|
240
|
-
* - shippingAddress?: Address
|
|
241
|
-
* - billingAddress?: Address
|
|
242
|
-
* - createdAt?: string - Order creation timestamp
|
|
243
|
-
* - updatedAt?: string - Last update timestamp
|
|
244
|
-
*/
|
|
245
|
-
async ordersUpdateOrderStatus(orderId: string, options: {status: string /** New order status */, trackingNumber: string /** Tracking number (for shipped status) */, headers?: Record<string, string>}) {
|
|
246
|
-
return this.orders.updateOrderStatus(orderId, options);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Cancel an order
|
|
251
|
-
*
|
|
252
|
-
* @param {string} orderId The order ID
|
|
253
|
-
* @param {Object} options (optional) - Request options
|
|
254
|
-
*
|
|
255
|
-
* @returns {Promise<Order>} POST /orders/{orderId}/cancel response
|
|
256
|
-
*
|
|
257
|
-
* response fields:
|
|
258
|
-
* - id: string - Unique order identifier
|
|
259
|
-
* - customerId: string - Customer who placed the order
|
|
260
|
-
* - items: OrderItem[] - Items in the order
|
|
261
|
-
* - status: string - Current order status
|
|
262
|
-
* - totalAmount: number - Total order amount
|
|
263
|
-
* - shippingAddress?: Address
|
|
264
|
-
* - billingAddress?: Address
|
|
265
|
-
* - createdAt?: string - Order creation timestamp
|
|
266
|
-
* - updatedAt?: string - Last update timestamp
|
|
267
|
-
*/
|
|
268
|
-
async ordersCancelOrder(orderId: string, options?: {headers?: Record<string, string>}) {
|
|
269
|
-
return this.orders.cancelOrder(orderId, options);
|
|
270
|
-
}
|
|
271
|
-
}
|