@aloma.io/integration-sdk 3.8.54 → 3.8.56

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 (35) hide show
  1. package/MULTI_RESOURCE_GUIDE.md +24 -21
  2. package/OPENAPI_TO_CONNECTOR.md +146 -16
  3. package/README.md +62 -10
  4. package/build/cli.mjs +122 -33
  5. package/build/openapi-to-connector.d.mts +92 -11
  6. package/build/openapi-to-connector.mjs +968 -168
  7. package/package.json +3 -1
  8. package/src/cli.mts +140 -37
  9. package/src/openapi-to-connector.mts +1092 -176
  10. package/test/scenarios/README.md +148 -0
  11. package/test/scenarios/complex/expected/controller.mts +271 -0
  12. package/test/scenarios/complex/expected/orders-resource.mts +264 -0
  13. package/test/scenarios/complex/expected/products-resource.mts +239 -0
  14. package/test/scenarios/complex/specs/orders.json +362 -0
  15. package/test/scenarios/complex/specs/products.json +308 -0
  16. package/test/scenarios/simple/expected-controller.mts +60 -0
  17. package/test/scenarios/simple/simple-api.json +39 -0
  18. package/test/scenarios.test.mts +286 -0
  19. package/test/verify-scenarios.mjs +298 -0
  20. package/examples/api-without-servers.json +0 -32
  21. package/examples/companies-resource-class.mts +0 -310
  22. package/examples/companies-resource.mts +0 -310
  23. package/examples/complete-example.sh +0 -116
  24. package/examples/create-hubspot-connector.sh +0 -33
  25. package/examples/generate-connector.sh +0 -35
  26. package/examples/generated-controller.mts +0 -81
  27. package/examples/hubspot-companies.json +0 -1889
  28. package/examples/hubspot-contacts.json +0 -1919
  29. package/examples/hubspot-controller-individual-params.mts +0 -323
  30. package/examples/hubspot-controller-with-implementation.mts +0 -315
  31. package/examples/hubspot-controller.mts +0 -192
  32. package/examples/hubspot-lists.json +0 -5525
  33. package/examples/main-controller-with-resources.mts +0 -35
  34. package/examples/stripe.json +0 -182829
  35. package/examples/utility-click.json +0 -8992
@@ -0,0 +1,148 @@
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.
@@ -0,0 +1,271 @@
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}) {
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 */}) {
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) {
112
+ return this.products.getProduct(productId);
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 */}) {
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) {
153
+ return this.products.deleteProduct(productId);
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}) {
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}) {
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) {
221
+ return this.orders.getOrder(orderId);
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) */}) {
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) {
269
+ return this.orders.cancelOrder(orderId);
270
+ }
271
+ }
@@ -0,0 +1,264 @@
1
+ // OrdersResource resource functions
2
+ // These functions will be bound to the controller instance and accessible as orders.method()
3
+
4
+ // Generated TypeScript interfaces from OpenAPI schemas
5
+
6
+ export interface Order {
7
+ /** Unique order identifier */
8
+ id: string;
9
+ /** Customer who placed the order */
10
+ customerId: string;
11
+ /** Items in the order */
12
+ items: OrderItem[];
13
+ /** Current order status */
14
+ status: string;
15
+ /** Total order amount */
16
+ totalAmount: number;
17
+ shippingAddress?: Address;
18
+ billingAddress?: Address;
19
+ /** Order creation timestamp */
20
+ createdAt?: string;
21
+ /** Last update timestamp */
22
+ updatedAt?: string;
23
+ }
24
+
25
+ export interface OrderItem {
26
+ /** Product identifier */
27
+ productId: string;
28
+ /** Product name */
29
+ productName?: string;
30
+ /** Quantity ordered */
31
+ quantity: number;
32
+ /** Price per unit */
33
+ unitPrice: number;
34
+ /** Total price for this item */
35
+ totalPrice?: number;
36
+ }
37
+
38
+ export interface Address {
39
+ /** Street address */
40
+ street: string;
41
+ /** City */
42
+ city: string;
43
+ /** State or province */
44
+ state?: string;
45
+ /** ZIP or postal code */
46
+ zipCode: string;
47
+ /** Country */
48
+ country: string;
49
+ }
50
+
51
+ export interface OrderList {
52
+ orders?: Order[];
53
+ /** Total number of orders */
54
+ total?: number;
55
+ /** Whether there are more orders available */
56
+ hasMore?: boolean;
57
+ }
58
+
59
+ export interface CreateOrderRequest {
60
+ /** Customer who is placing the order */
61
+ customerId: string;
62
+ /** Items to order */
63
+ items: OrderItemRequest[];
64
+ shippingAddress?: Address;
65
+ billingAddress?: Address;
66
+ }
67
+
68
+ export interface OrderItemRequest {
69
+ /** Product to order */
70
+ productId: string;
71
+ /** Quantity to order */
72
+ quantity: number;
73
+ }
74
+
75
+ export interface UpdateOrderStatusRequest {
76
+ /** New order status */
77
+ status: string;
78
+ /** Tracking number (for shipped status) */
79
+ trackingNumber?: string;
80
+ }
81
+
82
+
83
+ /**
84
+ * List all orders
85
+ *
86
+ * @param {Object} options - Request options
87
+ * @param {string} options.status (optional) - Filter by order status [query]
88
+ * @param {string} options.customerId (optional) - Filter by customer ID [query]
89
+ * @param {number} options.limit (optional) - Maximum number of orders to return [query]
90
+ *
91
+ * @returns {Promise<OrderList>} GET /orders response
92
+ *
93
+ * response fields:
94
+ * - orders?: Order[]
95
+ * - total?: number - Total number of orders
96
+ * - hasMore?: boolean - Whether there are more orders available
97
+ */
98
+ export function getOrders(this: any, options?: {status?: string, customerId?: string, limit?: number}) {
99
+ options = options || {};
100
+
101
+ const url = '/orders';
102
+
103
+ const fetchOptions: any = {
104
+ method: 'GET',
105
+ params: {},
106
+ headers: options.headers,
107
+ };
108
+
109
+ // Add query parameters
110
+ if (options.status !== undefined) {
111
+ fetchOptions.params.status = options.status;
112
+ }
113
+ if (options.customerId !== undefined) {
114
+ fetchOptions.params.customerId = options.customerId;
115
+ }
116
+ if (options.limit !== undefined) {
117
+ fetchOptions.params.limit = options.limit;
118
+ }
119
+
120
+ return this.api.fetch(url, fetchOptions);
121
+ }
122
+
123
+ /**
124
+ * Create a new order
125
+ *
126
+ * @param {Object} options - Request options
127
+ * @param {string} options.customerId (required) - Customer who is placing the order [body property]
128
+ * @param {OrderItemRequest[]} options.items (required) - Items to order [body property]
129
+ * @param {Address} options.shippingAddress (required) - [body property]
130
+ * @param {Address} options.billingAddress (required) - [body property]
131
+ *
132
+ * @returns {Promise<Order>} POST /orders response
133
+ *
134
+ * response fields:
135
+ * - id: string - Unique order identifier
136
+ * - customerId: string - Customer who placed the order
137
+ * - items: OrderItem[] - Items in the order
138
+ * - status: string - Current order status
139
+ * - totalAmount: number - Total order amount
140
+ * - shippingAddress?: Address
141
+ * - billingAddress?: Address
142
+ * - createdAt?: string - Order creation timestamp
143
+ * - updatedAt?: string - Last update timestamp
144
+ */
145
+ export function createOrder(this: any, options: {customerId: string /** Customer who is placing the order */, items: OrderItemRequest[] /** Items to order */, shippingAddress: Address, billingAddress: Address}) {
146
+ options = options || {};
147
+
148
+ const url = '/orders';
149
+
150
+ const { headers, ...bodyData } = options;
151
+ const requestBody = Object.keys(bodyData).length > 0 ? bodyData : undefined;
152
+
153
+ const fetchOptions: any = {
154
+ method: 'POST',
155
+ body: requestBody,
156
+ headers: options.headers,
157
+ };
158
+
159
+ return this.api.fetch(url, fetchOptions);
160
+ }
161
+
162
+ /**
163
+ * Get a specific order
164
+ *
165
+ * @param {string} orderId The order ID
166
+ * @param {Object} options (optional) - Request options
167
+ *
168
+ * @returns {Promise<Order>} GET /orders/{orderId} response
169
+ *
170
+ * response fields:
171
+ * - id: string - Unique order identifier
172
+ * - customerId: string - Customer who placed the order
173
+ * - items: OrderItem[] - Items in the order
174
+ * - status: string - Current order status
175
+ * - totalAmount: number - Total order amount
176
+ * - shippingAddress?: Address
177
+ * - billingAddress?: Address
178
+ * - createdAt?: string - Order creation timestamp
179
+ * - updatedAt?: string - Last update timestamp
180
+ */
181
+ export function getOrder(this: any, orderId: string) {
182
+ let url = '/orders/{orderId}';
183
+ if (orderId) {
184
+ url = url.replace('{orderId}', orderId);
185
+ }
186
+
187
+ return this.api.fetch(url, {
188
+ method: 'GET',
189
+ });
190
+ return this.api.fetch(url, fetchOptions);
191
+ }
192
+
193
+ /**
194
+ * Update order status
195
+ *
196
+ * @param {string} orderId The order ID
197
+ * @param {Object} options - Request options
198
+ * @param {string} options.status (required) - New order status [body property]
199
+ * @param {string} options.trackingNumber (required) - Tracking number (for shipped status) [body property]
200
+ *
201
+ * @returns {Promise<Order>} PATCH /orders/{orderId} response
202
+ *
203
+ * response fields:
204
+ * - id: string - Unique order identifier
205
+ * - customerId: string - Customer who placed the order
206
+ * - items: OrderItem[] - Items in the order
207
+ * - status: string - Current order status
208
+ * - totalAmount: number - Total order amount
209
+ * - shippingAddress?: Address
210
+ * - billingAddress?: Address
211
+ * - createdAt?: string - Order creation timestamp
212
+ * - updatedAt?: string - Last update timestamp
213
+ */
214
+ export function updateOrderStatus(this: any, orderId: string, options: {status: string /** New order status */, trackingNumber: string /** Tracking number (for shipped status */})) {
215
+ options = options || {};
216
+
217
+ // Build URL with path parameters
218
+ let url = '/orders/{orderId}';
219
+ if (orderId) {
220
+ url = url.replace('{orderId}', orderId);
221
+ }
222
+
223
+ const { headers, ...bodyData } = options;
224
+ const requestBody = Object.keys(bodyData).length > 0 ? bodyData : undefined;
225
+
226
+ const fetchOptions: any = {
227
+ method: 'PATCH',
228
+ body: requestBody,
229
+ headers: options.headers,
230
+ };
231
+
232
+ return this.api.fetch(url, fetchOptions);
233
+ }
234
+
235
+ /**
236
+ * Cancel an order
237
+ *
238
+ * @param {string} orderId The order ID
239
+ * @param {Object} options (optional) - Request options
240
+ *
241
+ * @returns {Promise<Order>} POST /orders/{orderId}/cancel response
242
+ *
243
+ * response fields:
244
+ * - id: string - Unique order identifier
245
+ * - customerId: string - Customer who placed the order
246
+ * - items: OrderItem[] - Items in the order
247
+ * - status: string - Current order status
248
+ * - totalAmount: number - Total order amount
249
+ * - shippingAddress?: Address
250
+ * - billingAddress?: Address
251
+ * - createdAt?: string - Order creation timestamp
252
+ * - updatedAt?: string - Last update timestamp
253
+ */
254
+ export function cancelOrder(this: any, orderId: string) {
255
+ let url = '/orders/{orderId}/cancel';
256
+ if (orderId) {
257
+ url = url.replace('{orderId}', orderId);
258
+ }
259
+
260
+ return this.api.fetch(url, {
261
+ method: 'POST',
262
+ });
263
+ return this.api.fetch(url, fetchOptions);
264
+ }