@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
package/MULTI_RESOURCE_GUIDE.md
DELETED
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
# Multi-Resource Connector Guide
|
|
2
|
-
|
|
3
|
-
This guide explains how to create and manage multi-resource connectors using the Aloma Integration SDK.
|
|
4
|
-
|
|
5
|
-
## Overview
|
|
6
|
-
|
|
7
|
-
Multi-resource connectors allow you to organize large APIs into logical resource groups (e.g., `companies`, `contacts`, `deals`) while maintaining a clean, modular architecture. Each resource is generated from its own OpenAPI specification and composed in a main controller.
|
|
8
|
-
|
|
9
|
-
## Architecture
|
|
10
|
-
|
|
11
|
-
```
|
|
12
|
-
src/
|
|
13
|
-
├── controller/
|
|
14
|
-
│ └── index.mts # Main controller (extends AbstractController)
|
|
15
|
-
└── resources/
|
|
16
|
-
├── companies.mts # Companies resource functions
|
|
17
|
-
├── contacts.mts # Contacts resource functions
|
|
18
|
-
└── lists.mts # Lists resource functions
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
### Main Controller
|
|
22
|
-
- Extends `AbstractController`
|
|
23
|
-
- Has `private api: any` and `protected async start()`
|
|
24
|
-
- Binds resource functions to controller context with `function.bind(this)`
|
|
25
|
-
- Initializes API client once and provides context to bound functions
|
|
26
|
-
|
|
27
|
-
### Resource Functions (New Pattern!)
|
|
28
|
-
- Plain TypeScript exported functions (no classes)
|
|
29
|
-
- Bound to controller context using `function.bind(this)`
|
|
30
|
-
- Access `api` directly via `this.api` (bound context)
|
|
31
|
-
- Focus on their specific domain
|
|
32
|
-
- Enable proper API introspection by the framework
|
|
33
|
-
|
|
34
|
-
## Creating Multi-Resource Connectors
|
|
35
|
-
|
|
36
|
-
### 1. Generate Base Controller (Functions Pattern)
|
|
37
|
-
|
|
38
|
-
```bash
|
|
39
|
-
npx @aloma.io/integration-sdk@latest create-multi-resource "MyConnector" \
|
|
40
|
-
--connector-id "my-connector-123" \
|
|
41
|
-
--resources "CompaniesResource:companies.json,ContactsResource:contacts.json,ListsResource:lists.json" \
|
|
42
|
-
--base-url "https://api.example.com"
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
**Parameters:**
|
|
46
|
-
- `--resources`: Comma-separated list of `ResourceName:specFile` pairs
|
|
47
|
-
- `--base-url`: API base URL (optional, extracted from first spec if not provided)
|
|
48
|
-
- `--no-build`: Skip dependency installation and building
|
|
49
|
-
|
|
50
|
-
### 2. Resource Specification Format
|
|
51
|
-
|
|
52
|
-
The `--resources` parameter accepts a comma-separated list in this format:
|
|
53
|
-
```
|
|
54
|
-
"ClassName1:specFile1,ClassName2:specFile2,ClassName3:specFile3"
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
**Examples:**
|
|
58
|
-
```bash
|
|
59
|
-
# HubSpot connector
|
|
60
|
-
--resources "CompaniesResource:hubspot-companies.json,ContactsResource:hubspot-contacts.json,ListsResource:hubspot-lists.json"
|
|
61
|
-
|
|
62
|
-
# Salesforce connector
|
|
63
|
-
--resources "AccountsResource:sf-accounts.json,ContactsResource:sf-contacts.json,OpportunitiesResource:sf-opportunities.json"
|
|
64
|
-
|
|
65
|
-
# Stripe connector
|
|
66
|
-
--resources "CustomersResource:stripe-customers.json,PaymentsResource:stripe-payments.json,SubscriptionsResource:stripe-subscriptions.json"
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
## Adding Resources to Existing Projects
|
|
70
|
-
|
|
71
|
-
### 1. Add New Resource
|
|
72
|
-
|
|
73
|
-
```bash
|
|
74
|
-
npx @aloma.io/integration-sdk@latest add-resource ./existing-project \
|
|
75
|
-
--className "DealsResource" \
|
|
76
|
-
--spec "deals.json" \
|
|
77
|
-
--no-build
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
This will:
|
|
81
|
-
- Generate the new resource functions
|
|
82
|
-
- Save them to `src/resources/deals.mts`
|
|
83
|
-
- Provide instructions for updating the main controller
|
|
84
|
-
|
|
85
|
-
### 2. Update Main Controller Manually
|
|
86
|
-
|
|
87
|
-
After adding a resource, you need to update the main controller:
|
|
88
|
-
|
|
89
|
-
```typescript
|
|
90
|
-
// 1. Add import
|
|
91
|
-
import * as dealsResource from '../resources/deals.mjs';
|
|
92
|
-
|
|
93
|
-
// 2. Add property
|
|
94
|
-
deals!: typeof dealsResource;
|
|
95
|
-
|
|
96
|
-
// 3. Add initialization in start()
|
|
97
|
-
this.deals = this.bindResourceFunctions(dealsResource);
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
## Usage Examples
|
|
101
|
-
|
|
102
|
-
### Generated API Calls
|
|
103
|
-
|
|
104
|
-
```typescript
|
|
105
|
-
// Companies resource
|
|
106
|
-
await controller.companies.create({
|
|
107
|
-
body: { properties: { name: 'Acme Corp', domain: 'acme.com' } }
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
await controller.companies.getPage({
|
|
111
|
-
limit: 10,
|
|
112
|
-
properties: ['name', 'domain', 'industry']
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
await controller.companies.getById('12345', {
|
|
116
|
-
properties: ['name', 'email']
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
// Contacts resource
|
|
120
|
-
await controller.contacts.create({
|
|
121
|
-
body: { properties: { firstname: 'John', lastname: 'Doe', email: 'john@example.com' } }
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
await controller.contacts.getPage({
|
|
125
|
-
limit: 20,
|
|
126
|
-
properties: ['firstname', 'lastname', 'email']
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
// Lists resource
|
|
130
|
-
await controller.lists.getAll({ limit: 50 });
|
|
131
|
-
|
|
132
|
-
await controller.lists.create({
|
|
133
|
-
body: { name: 'My Contact List', processingType: 'MANUAL' }
|
|
134
|
-
});
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
### With Custom Headers
|
|
138
|
-
|
|
139
|
-
```typescript
|
|
140
|
-
await controller.companies.getPage({
|
|
141
|
-
limit: 10,
|
|
142
|
-
headers: {
|
|
143
|
-
'X-Request-ID': 'unique-id-123',
|
|
144
|
-
'X-Custom-Header': 'value'
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
## Best Practices
|
|
150
|
-
|
|
151
|
-
### 1. Resource Naming
|
|
152
|
-
- Use descriptive resource names: `CompaniesResource`, `ContactsResource`
|
|
153
|
-
- File names are auto-generated: `companies.mts`, `contacts.mts`
|
|
154
|
-
- Property names in controller (bound functions): `companies`, `contacts`
|
|
155
|
-
|
|
156
|
-
### 2. OpenAPI Specifications
|
|
157
|
-
- Each resource should have its own focused OpenAPI spec
|
|
158
|
-
- Ensure all specs use the same base URL or provide `--base-url`
|
|
159
|
-
- Use consistent parameter naming across specs
|
|
160
|
-
|
|
161
|
-
### 3. Error Handling
|
|
162
|
-
- All generated methods return promises
|
|
163
|
-
- API errors are handled by the underlying `api.fetch()` method
|
|
164
|
-
- Add custom error handling in your connector logic as needed
|
|
165
|
-
|
|
166
|
-
### 4. Type Safety
|
|
167
|
-
- Generated code uses `any` types for flexibility
|
|
168
|
-
- Consider adding TypeScript interfaces for better type safety
|
|
169
|
-
- Use JSDoc comments for parameter documentation
|
|
170
|
-
|
|
171
|
-
## Example: Complete HubSpot Connector
|
|
172
|
-
|
|
173
|
-
```bash
|
|
174
|
-
# Create the connector
|
|
175
|
-
npx @aloma.io/integration-sdk@latest create-multi-resource "HubSpot-v2" \
|
|
176
|
-
--connector-id "hubspot-123" \
|
|
177
|
-
--resources "CompaniesResource:examples/hubspot-companies.json,ContactsResource:examples/hubspot-contacts.json,ListsResource:examples/hubspot-lists.json" \
|
|
178
|
-
--base-url "https://api.hubapi.com"
|
|
179
|
-
|
|
180
|
-
# Install dependencies
|
|
181
|
-
cd HubSpot-v2
|
|
182
|
-
yarn --ignore-engines
|
|
183
|
-
|
|
184
|
-
# Build
|
|
185
|
-
yarn build
|
|
186
|
-
|
|
187
|
-
# Start
|
|
188
|
-
yarn start
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
## Troubleshooting
|
|
192
|
-
|
|
193
|
-
### Import Path Errors
|
|
194
|
-
If you see TypeScript errors about missing file extensions:
|
|
195
|
-
- Ensure you're using `.mjs` extensions in imports
|
|
196
|
-
- The generator handles this automatically in new projects
|
|
197
|
-
|
|
198
|
-
### Resource Functions Not Found
|
|
199
|
-
If a resource property is undefined:
|
|
200
|
-
- Check that the resource functions are properly bound in `start()`
|
|
201
|
-
- Ensure `bindResourceFunctions()` was called correctly
|
|
202
|
-
- Verify the import path in the main controller
|
|
203
|
-
- Ensure the resource file was generated correctly
|
|
204
|
-
|
|
205
|
-
### Build Errors
|
|
206
|
-
If the project fails to build:
|
|
207
|
-
- Try using `--no-build` flag during creation
|
|
208
|
-
- Install dependencies manually: `yarn --ignore-engines`
|
|
209
|
-
- Check for TypeScript errors in generated files
|
|
210
|
-
|
|
211
|
-
## Migration from Single-Resource
|
|
212
|
-
|
|
213
|
-
To convert an existing single-resource connector to multi-resource:
|
|
214
|
-
|
|
215
|
-
1. Extract the relevant endpoints into separate OpenAPI specs
|
|
216
|
-
2. Create new resource classes using `from-openapi --resource`
|
|
217
|
-
3. Update the main controller to compose the resources
|
|
218
|
-
4. Remove the old single controller methods
|
|
219
|
-
|
|
220
|
-
This approach maintains backward compatibility while providing better organization for large APIs.
|
package/OPENAPI_TO_CONNECTOR.md
DELETED
|
@@ -1,346 +0,0 @@
|
|
|
1
|
-
# OpenAPI to Connector Generator
|
|
2
|
-
|
|
3
|
-
A deterministic script that generates Aloma connector controllers from OpenAPI 3.x specifications.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
### Core Generation
|
|
8
|
-
- ✅ **Deterministic**: Same OpenAPI input always produces the same connector definition
|
|
9
|
-
- ✅ **No LLM involvement**: Pure parsing and code generation
|
|
10
|
-
- ✅ **OpenAPI 3.x support**: Validates against OpenAPI 3.x schema
|
|
11
|
-
- ✅ **JSON & YAML support**: Handles both JSON and YAML OpenAPI specifications
|
|
12
|
-
- ✅ **Comprehensive coverage**: Generates methods for all endpoints and operations
|
|
13
|
-
|
|
14
|
-
### TypeScript & Code Quality
|
|
15
|
-
- ✅ **TypeScript Interface Generation**: Automatically generates interfaces from OpenAPI schemas
|
|
16
|
-
- ✅ **Schema Name Sanitization**: Converts invalid names (e.g., `Complex.Name.With.Dots` → `Complex_Name_With_Dots`)
|
|
17
|
-
- ✅ **Clean Parameter Handling**: No unnecessary options parameters for simple methods
|
|
18
|
-
- ✅ **Path Parameter Separation**: Discrete path parameters with optional options object
|
|
19
|
-
- ✅ **Inline Body Construction**: Direct body building without helper methods
|
|
20
|
-
|
|
21
|
-
### Documentation & Usability
|
|
22
|
-
- ✅ **Rich JSDoc Generation**: Detailed documentation with parameter descriptions and examples
|
|
23
|
-
- ✅ **Schema Field Documentation**: Documents response object fields and properties
|
|
24
|
-
- ✅ **Parameter Type Documentation**: Includes TypeScript types in JSDoc comments
|
|
25
|
-
- ✅ **Controller-Only Mode**: Generate just the controller file for existing projects
|
|
26
|
-
|
|
27
|
-
### Architecture Support
|
|
28
|
-
- ✅ **Multi-Resource Architecture**: Support for complex APIs with multiple resource groups
|
|
29
|
-
- ✅ **Resource Function Pattern**: Functions bound to controller context for proper introspection
|
|
30
|
-
- ✅ **API Introspection**: Exposed methods for framework compatibility
|
|
31
|
-
- ✅ **Error handling**: Clear error messages for invalid specifications
|
|
32
|
-
|
|
33
|
-
## Installation
|
|
34
|
-
|
|
35
|
-
The script is included in the integration-sdk package. Install dependencies:
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
npm install
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
Build the project:
|
|
42
|
-
|
|
43
|
-
```bash
|
|
44
|
-
npm run build
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
## Usage
|
|
48
|
-
|
|
49
|
-
### CLI Usage (Recommended)
|
|
50
|
-
|
|
51
|
-
After deploying to npm, you can use the integrated CLI command:
|
|
52
|
-
|
|
53
|
-
```bash
|
|
54
|
-
# Create a complete connector project from OpenAPI spec
|
|
55
|
-
npx @aloma.io/integration-sdk@latest from-openapi "My Connector" --connector-id "my-connector-123" --spec api.yaml
|
|
56
|
-
|
|
57
|
-
# With custom output path
|
|
58
|
-
npx @aloma.io/integration-sdk@latest from-openapi "My Connector" --connector-id "my-connector-123" --spec api.yaml --out src/controller/index.mts
|
|
59
|
-
|
|
60
|
-
# Controller-only mode (NEW!) - Generate just the controller file
|
|
61
|
-
npx @aloma.io/integration-sdk@latest from-openapi "My Connector" \
|
|
62
|
-
--connector-id "my-connector-123" \
|
|
63
|
-
--spec api.yaml \
|
|
64
|
-
--controller-only \
|
|
65
|
-
--out "./src/controller/index.mts"
|
|
66
|
-
|
|
67
|
-
# Multi-resource connector
|
|
68
|
-
npx @aloma.io/integration-sdk@latest create-multi-resource "My Connector" \
|
|
69
|
-
--connector-id "my-connector-123" \
|
|
70
|
-
--resources "ProductsResource:products.json,OrdersResource:orders.json" \
|
|
71
|
-
--base-url "https://api.example.com"
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
#### Options
|
|
75
|
-
|
|
76
|
-
- `<name>` (required): Name of the connector project
|
|
77
|
-
- `--connector-id <id>` (required): ID of the connector
|
|
78
|
-
- `--spec <file>` (required): OpenAPI specification file (JSON or YAML)
|
|
79
|
-
- `--out <file>` (optional): Output file path for the controller (default: `src/controller/index.mts`)
|
|
80
|
-
- `--controller-only` (optional): Generate only the controller file, no project structure
|
|
81
|
-
- `--resource <className>` (optional): Generate as a resource class instead of controller
|
|
82
|
-
- `--no-build` (optional): Skip installing dependencies and building the project
|
|
83
|
-
|
|
84
|
-
### Standalone Script Usage
|
|
85
|
-
|
|
86
|
-
You can also use the standalone script directly:
|
|
87
|
-
|
|
88
|
-
```bash
|
|
89
|
-
node ./build/openapi-to-connector.mjs generate --name "My Connector" --spec api.yaml --out controller.mts
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
#### Options
|
|
93
|
-
|
|
94
|
-
- `--name <name>` (required): Human-readable connector name
|
|
95
|
-
- `--spec <file>` (required): OpenAPI specification file (JSON or YAML)
|
|
96
|
-
- `--out <file>` (optional): Output file path (default: `index.mts`)
|
|
97
|
-
|
|
98
|
-
### Programmatic Usage
|
|
99
|
-
|
|
100
|
-
```typescript
|
|
101
|
-
import { OpenAPIToConnector } from './build/openapi-to-connector.mjs';
|
|
102
|
-
|
|
103
|
-
// Parse OpenAPI spec
|
|
104
|
-
const spec = OpenAPIToConnector.parseSpec(specString);
|
|
105
|
-
|
|
106
|
-
// Generate controller
|
|
107
|
-
const generator = new OpenAPIToConnector(spec, 'My Connector');
|
|
108
|
-
const controllerCode = generator.generateController();
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
## Example
|
|
112
|
-
|
|
113
|
-
### Input: OpenAPI Specification
|
|
114
|
-
|
|
115
|
-
```yaml
|
|
116
|
-
openapi: 3.0.0
|
|
117
|
-
info:
|
|
118
|
-
title: User API
|
|
119
|
-
version: 1.0.0
|
|
120
|
-
paths:
|
|
121
|
-
/users:
|
|
122
|
-
get:
|
|
123
|
-
operationId: listUsers
|
|
124
|
-
summary: List all users
|
|
125
|
-
parameters:
|
|
126
|
-
- name: page
|
|
127
|
-
in: query
|
|
128
|
-
schema:
|
|
129
|
-
type: integer
|
|
130
|
-
responses:
|
|
131
|
-
'200':
|
|
132
|
-
description: Success
|
|
133
|
-
post:
|
|
134
|
-
operationId: createUser
|
|
135
|
-
summary: Create user
|
|
136
|
-
requestBody:
|
|
137
|
-
required: true
|
|
138
|
-
content:
|
|
139
|
-
application/json:
|
|
140
|
-
schema:
|
|
141
|
-
type: object
|
|
142
|
-
responses:
|
|
143
|
-
'201':
|
|
144
|
-
description: Created
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
### Output: Generated Controller
|
|
148
|
-
|
|
149
|
-
```typescript
|
|
150
|
-
import {AbstractController} from '@aloma.io/integration-sdk';
|
|
151
|
-
|
|
152
|
-
// Generated TypeScript interfaces from OpenAPI schemas
|
|
153
|
-
|
|
154
|
-
export interface User {
|
|
155
|
-
id: string;
|
|
156
|
-
name: string;
|
|
157
|
-
email?: string;
|
|
158
|
-
createdAt: string;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export interface UserList {
|
|
162
|
-
users: User[];
|
|
163
|
-
total: number;
|
|
164
|
-
hasMore: boolean;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
export default class Controller extends AbstractController {
|
|
168
|
-
|
|
169
|
-
private api: any;
|
|
170
|
-
|
|
171
|
-
protected async start(): Promise<void> {
|
|
172
|
-
const config = this.config;
|
|
173
|
-
|
|
174
|
-
this.api = this.getClient({
|
|
175
|
-
baseUrl: 'https://api.example.com',
|
|
176
|
-
customize(request) {
|
|
177
|
-
request.headers ||= {};
|
|
178
|
-
// Add authentication headers based on your API requirements
|
|
179
|
-
// Example: request.headers["Authorization"] = `Bearer ${config.apiToken}`;
|
|
180
|
-
},
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* List all users
|
|
186
|
-
*
|
|
187
|
-
* @param {Object} options - Request options
|
|
188
|
-
* @param {number} options.page (optional) - Page number for pagination [query]
|
|
189
|
-
*
|
|
190
|
-
* @returns {Promise<UserList>} GET /users response
|
|
191
|
-
*
|
|
192
|
-
* response fields:
|
|
193
|
-
* - users: User[] - Array of user objects
|
|
194
|
-
* - total: number - Total number of users
|
|
195
|
-
* - hasMore: boolean - Whether there are more users available
|
|
196
|
-
*/
|
|
197
|
-
async listUsers(options?: {page?: number}) {
|
|
198
|
-
options = options || {};
|
|
199
|
-
|
|
200
|
-
const url = '/users';
|
|
201
|
-
|
|
202
|
-
const fetchOptions: any = {
|
|
203
|
-
method: 'GET',
|
|
204
|
-
params: {},
|
|
205
|
-
headers: options.headers,
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
// Add query parameters
|
|
209
|
-
if (options.page !== undefined) {
|
|
210
|
-
fetchOptions.params.page = options.page;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
return this.api.fetch(url, fetchOptions);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Create user
|
|
218
|
-
*
|
|
219
|
-
* @param {Object} options - Request options
|
|
220
|
-
* @param {string} options.name (required) - User's full name [body property]
|
|
221
|
-
* @param {string} options.email (optional) - User's email address [body property]
|
|
222
|
-
*
|
|
223
|
-
* @returns {Promise<User>} POST /users response
|
|
224
|
-
*/
|
|
225
|
-
async createUser(options: {name: string, email?: string}) {
|
|
226
|
-
options = options || {};
|
|
227
|
-
|
|
228
|
-
const url = '/users';
|
|
229
|
-
|
|
230
|
-
const { headers, ...bodyData } = options;
|
|
231
|
-
const requestBody = Object.keys(bodyData).length > 0 ? bodyData : undefined;
|
|
232
|
-
|
|
233
|
-
const fetchOptions: any = {
|
|
234
|
-
method: 'POST',
|
|
235
|
-
body: requestBody,
|
|
236
|
-
headers: options.headers,
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
return this.api.fetch(url, fetchOptions);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
## Generated Method Names
|
|
245
|
-
|
|
246
|
-
The script generates method names using the following priority:
|
|
247
|
-
|
|
248
|
-
1. **Operation ID**: If `operationId` is present, use it directly
|
|
249
|
-
2. **Method + Path**: Combine HTTP method with path segments
|
|
250
|
-
- `GET /users` → `getUsers`
|
|
251
|
-
- `POST /users/{id}/posts` → `post_users_{id}_posts`
|
|
252
|
-
|
|
253
|
-
## Parameter Mapping
|
|
254
|
-
|
|
255
|
-
- **Path parameters**: Mapped to `args.paramName`
|
|
256
|
-
- **Query parameters**: Mapped to `args.paramName`
|
|
257
|
-
- **Request body**: Mapped to `args.body`
|
|
258
|
-
- **Headers**: Mapped to `args.headerName`
|
|
259
|
-
|
|
260
|
-
## JSDoc Generation
|
|
261
|
-
|
|
262
|
-
The script generates comprehensive JSDoc comments using:
|
|
263
|
-
|
|
264
|
-
- **Summary**: From `operation.summary`
|
|
265
|
-
- **Description**: From `operation.description`
|
|
266
|
-
- **Parameters**: From `operation.parameters` with descriptions
|
|
267
|
-
- **Request body**: When present
|
|
268
|
-
- **Return type**: Always includes `@returns Response data`
|
|
269
|
-
|
|
270
|
-
## Error Handling
|
|
271
|
-
|
|
272
|
-
The script provides clear error messages for:
|
|
273
|
-
|
|
274
|
-
- Invalid JSON/YAML syntax
|
|
275
|
-
- Non-OpenAPI 3.x specifications
|
|
276
|
-
- Missing required fields (`openapi`, `info`, `paths`)
|
|
277
|
-
- Empty specifications (no operations)
|
|
278
|
-
|
|
279
|
-
## Testing
|
|
280
|
-
|
|
281
|
-
### Comprehensive Scenario Tests
|
|
282
|
-
|
|
283
|
-
The SDK includes comprehensive scenario tests that verify the complete code generation pipeline:
|
|
284
|
-
|
|
285
|
-
```bash
|
|
286
|
-
# Run all scenario tests with fixtures
|
|
287
|
-
npm run test:scenarios
|
|
288
|
-
|
|
289
|
-
# Run all tests (including unit tests)
|
|
290
|
-
npm run test:all
|
|
291
|
-
```
|
|
292
|
-
|
|
293
|
-
### Test Coverage
|
|
294
|
-
|
|
295
|
-
The scenario tests verify:
|
|
296
|
-
- ✅ **Complete code generation** from OpenAPI specs to connector code
|
|
297
|
-
- ✅ **TypeScript interface generation** with proper schema sanitization
|
|
298
|
-
- ✅ **Clean parameter handling** (no unnecessary options for simple methods)
|
|
299
|
-
- ✅ **Multi-resource architecture** with resource binding and exposure
|
|
300
|
-
- ✅ **Schema name sanitization** (e.g., `Complex.Name.With.Dots` → `Complex_Name_With_Dots`)
|
|
301
|
-
- ✅ **Path parameter separation** from options object
|
|
302
|
-
- ✅ **JSDoc generation** with detailed parameter documentation
|
|
303
|
-
- ✅ **Regression protection** against common code generation issues
|
|
304
|
-
|
|
305
|
-
### Test Scenarios
|
|
306
|
-
- **Simple Scenario**: Basic single-controller generation using `examples/simple-api.json`
|
|
307
|
-
- **Complex Scenario**: Multi-resource generation with Products + Orders APIs
|
|
308
|
-
- **Regression Tests**: Edge cases, schema sanitization, and clean code generation
|
|
309
|
-
|
|
310
|
-
All tests compare generated output against fixtures to ensure deterministic, high-quality code generation.
|
|
311
|
-
|
|
312
|
-
### Manual Testing
|
|
313
|
-
|
|
314
|
-
```bash
|
|
315
|
-
# Test with sample API
|
|
316
|
-
node ./build/openapi-to-connector.mjs generate --name "Sample API" --spec ./examples/sample-api.yaml --out ./test-output.mts
|
|
317
|
-
|
|
318
|
-
# Test controller-only mode
|
|
319
|
-
node build/cli.mjs from-openapi test-connector \
|
|
320
|
-
--connector-id "test" \
|
|
321
|
-
--spec "examples/simple-api.json" \
|
|
322
|
-
--controller-only \
|
|
323
|
-
--out "./test-controller.mts"
|
|
324
|
-
```
|
|
325
|
-
|
|
326
|
-
## Requirements Met
|
|
327
|
-
|
|
328
|
-
✅ **Runnable script**: CLI with proper argument parsing
|
|
329
|
-
✅ **OpenAPI 3.x support**: Validates and parses OpenAPI 3.x specs
|
|
330
|
-
✅ **JSON/YAML support**: Handles both formats
|
|
331
|
-
✅ **Deterministic**: Same input always produces same output
|
|
332
|
-
✅ **No inference**: Fails fast on missing information
|
|
333
|
-
✅ **Full coverage**: Generates methods for all operations
|
|
334
|
-
✅ **Rich documentation**: Uses all available descriptions
|
|
335
|
-
✅ **Testing**: Includes unit tests for core functionality
|
|
336
|
-
|
|
337
|
-
## Integration with Aloma SDK
|
|
338
|
-
|
|
339
|
-
The generated controller extends `AbstractController` and follows the Aloma connector pattern:
|
|
340
|
-
|
|
341
|
-
- Each OpenAPI operation becomes a public async method
|
|
342
|
-
- Methods receive `args` parameter with all request data
|
|
343
|
-
- Methods should return response data or throw errors
|
|
344
|
-
- JSDoc comments provide rich documentation for the UI
|
|
345
|
-
|
|
346
|
-
The generated controller can be used directly in an Aloma connector project after implementing the actual API calls.
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "hello-world",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "",
|
|
5
|
-
"author": "aloma.io",
|
|
6
|
-
"connectorId": "TODO",
|
|
7
|
-
"license": "Apache-2.0",
|
|
8
|
-
"type": "module",
|
|
9
|
-
"scripts": {
|
|
10
|
-
"start": "node build/index.mjs",
|
|
11
|
-
"dev": "./node_modules/typescript/bin/tsc --watch",
|
|
12
|
-
"build": "./node_modules/@aloma.io/integration-sdk/build/cli.mjs build; ./node_modules/typescript/bin/tsc",
|
|
13
|
-
"test": "./node_modules/mocha/bin/_mocha --recursive",
|
|
14
|
-
"format": "yarn prettier --write src/"
|
|
15
|
-
},
|
|
16
|
-
"dependencies": {
|
|
17
|
-
"@aloma.io/integration-sdk": "^3"
|
|
18
|
-
},
|
|
19
|
-
"devDependencies": {
|
|
20
|
-
"@types/node": "^18",
|
|
21
|
-
"mocha": "^10",
|
|
22
|
-
"prettier": "^3",
|
|
23
|
-
"typescript": "^5"
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "es2022",
|
|
4
|
-
"skipLibCheck": true,
|
|
5
|
-
"module": "node16",
|
|
6
|
-
"moduleResolution": "node16",
|
|
7
|
-
"lib": ["es2015", "es6", "esnext"],
|
|
8
|
-
"declaration": true,
|
|
9
|
-
"allowJs": true,
|
|
10
|
-
"outDir": "build",
|
|
11
|
-
"rootDir": "src/",
|
|
12
|
-
"strict": true,
|
|
13
|
-
"noImplicitAny": false,
|
|
14
|
-
"esModuleInterop": true,
|
|
15
|
-
"resolveJsonModule": true,
|
|
16
|
-
"experimentalDecorators": true,
|
|
17
|
-
"emitDecoratorMetadata": true,
|
|
18
|
-
"allowSyntheticDefaultImports": true
|
|
19
|
-
},
|
|
20
|
-
"include": [
|
|
21
|
-
"src/**/*"
|
|
22
|
-
],
|
|
23
|
-
"exclude": [
|
|
24
|
-
"node_modules/**/*",
|
|
25
|
-
"dist/**/*"
|
|
26
|
-
]
|
|
27
|
-
}
|