@adobe-commerce/aio-toolkit 1.0.13 → 1.0.15
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/CHANGELOG.md +116 -0
- package/README.md +122 -9
- package/dist/aio-toolkit-cursor-context/bin/cli.js +1089 -0
- package/dist/aio-toolkit-cursor-context/bin/cli.js.map +1 -0
- package/dist/index.d.mts +43 -16
- package/dist/index.d.ts +43 -16
- package/dist/index.js +1030 -166
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1034 -167
- package/dist/index.mjs.map +1 -1
- package/files/cursor-context/commands/aio-toolkit-create-event-consumer-action.md +562 -0
- package/files/cursor-context/commands/aio-toolkit-create-graphql-action.md +531 -0
- package/files/cursor-context/commands/aio-toolkit-create-runtime-action.md +293 -0
- package/files/cursor-context/commands/aio-toolkit-create-webhook-action.md +439 -0
- package/files/cursor-context/rules/aio-toolkit-create-adobe-commerce-client.mdc +1321 -0
- package/files/cursor-context/rules/aio-toolkit-oop-best-practices.mdc +331 -0
- package/files/cursor-context/rules/aio-toolkit-setup-new-relic-telemetry.mdc +354 -0
- package/package.json +6 -1
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
# AIO Toolkit: Create Runtime Action
|
|
2
|
+
|
|
3
|
+
**Command Name:** `aio-toolkit-create-runtime-action`
|
|
4
|
+
|
|
5
|
+
**Description:** Creates a runtime action using @adobe-commerce/aio-toolkit
|
|
6
|
+
|
|
7
|
+
## Workflow
|
|
8
|
+
|
|
9
|
+
This command creates a new runtime action with @adobe-commerce/aio-toolkit.
|
|
10
|
+
|
|
11
|
+
### Step 1: Verify Prerequisites
|
|
12
|
+
|
|
13
|
+
1. Check if `@adobe-commerce/aio-toolkit` is installed in `package.json`
|
|
14
|
+
- If NOT installed, ask user if they want to install it: `npm install @adobe-commerce/aio-toolkit`
|
|
15
|
+
2. Detect project language (TypeScript or JavaScript)
|
|
16
|
+
- Check for `typescript` in dependencies + `tsconfig.json`
|
|
17
|
+
- Check for `.ts` files in `actions/` or `lib/`
|
|
18
|
+
- Default to JavaScript if ambiguous
|
|
19
|
+
3. Detect project structure
|
|
20
|
+
- Check for `application:` in `app.config.yaml` (root actions)
|
|
21
|
+
- Check for `extensions:` in `app.config.yaml` (extension point actions)
|
|
22
|
+
|
|
23
|
+
### Step 2: Collect Action Configuration
|
|
24
|
+
|
|
25
|
+
Ask the user:
|
|
26
|
+
|
|
27
|
+
1. **Action Name** (required)
|
|
28
|
+
- Example: `order-processor`, `customer-sync`, `product-list`
|
|
29
|
+
|
|
30
|
+
2. **Action Location** (auto-detect or ask)
|
|
31
|
+
- Root application (`actions/`)
|
|
32
|
+
- Extension point (`[extension-path]/actions/`)
|
|
33
|
+
|
|
34
|
+
3. **Package Structure**
|
|
35
|
+
- Simple: `actions/[action-name]/index.[js/ts]`
|
|
36
|
+
- Packaged: `actions/[package]/[action-name]/index.[js/ts]`
|
|
37
|
+
- If packaged, ask for package name
|
|
38
|
+
|
|
39
|
+
4. **HTTP Methods** (comma-separated or empty for all)
|
|
40
|
+
- Options: GET, POST, PUT, DELETE, PATCH
|
|
41
|
+
- Example: `POST, GET`
|
|
42
|
+
|
|
43
|
+
5. **Required Parameters** (comma-separated or empty)
|
|
44
|
+
- Example: `orderId, customerId`
|
|
45
|
+
|
|
46
|
+
6. **Required Headers** (comma-separated or empty)
|
|
47
|
+
- Example: `Authorization, x-api-key`
|
|
48
|
+
- Note: If `Authorization` included, sets `require-adobe-auth: true`
|
|
49
|
+
|
|
50
|
+
7. **Business Logic Description**
|
|
51
|
+
- Brief description of what the action should do
|
|
52
|
+
|
|
53
|
+
8. **Success Response Data**
|
|
54
|
+
- What data should the action return on success?
|
|
55
|
+
- Example: `{ orderId, status }`, `{ products: [...] }`, `{ message: "Success" }`
|
|
56
|
+
- This will be passed to RuntimeActionResponse.success(result)
|
|
57
|
+
|
|
58
|
+
### Step 3: Confirm Configuration
|
|
59
|
+
|
|
60
|
+
Display summary:
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
📋 Runtime Action Configuration
|
|
64
|
+
|
|
65
|
+
Action Name: [name]
|
|
66
|
+
Language: [JavaScript/TypeScript] (auto-detected)
|
|
67
|
+
Location: [Root/Extension]
|
|
68
|
+
Package: [package-name or simple]
|
|
69
|
+
HTTP Methods: [methods or all]
|
|
70
|
+
Required Parameters: [params or none]
|
|
71
|
+
Required Headers: [headers or none]
|
|
72
|
+
Authentication: [Yes/No]
|
|
73
|
+
Business Logic: [description]
|
|
74
|
+
Success Response: [data structure]
|
|
75
|
+
|
|
76
|
+
✅ Files to Create:
|
|
77
|
+
- actions/[path]/index.[js/ts]
|
|
78
|
+
- Update app.config.yaml or ext.config.yaml
|
|
79
|
+
[- actions/[package]/actions.config.yaml if packaged]
|
|
80
|
+
|
|
81
|
+
Should I proceed?
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Step 4: Generate Runtime Action
|
|
85
|
+
|
|
86
|
+
Create action file with this template:
|
|
87
|
+
|
|
88
|
+
**JavaScript:**
|
|
89
|
+
```javascript
|
|
90
|
+
const {
|
|
91
|
+
RuntimeAction,
|
|
92
|
+
RuntimeActionResponse,
|
|
93
|
+
HttpMethod,
|
|
94
|
+
HttpStatus,
|
|
95
|
+
} = require('@adobe-commerce/aio-toolkit');
|
|
96
|
+
const name = '[action-name]';
|
|
97
|
+
|
|
98
|
+
exports.main = RuntimeAction.execute(
|
|
99
|
+
name,
|
|
100
|
+
[/* HttpMethod.GET, HttpMethod.POST */],
|
|
101
|
+
[/* 'param1', 'param2' */],
|
|
102
|
+
[/* 'Authorization', 'x-api-key' */],
|
|
103
|
+
async (params, ctx) => {
|
|
104
|
+
const { logger } = ctx;
|
|
105
|
+
logger.info({ message: `${name}-processing`, params: JSON.stringify(params) });
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
// TODO: Implement business logic
|
|
109
|
+
const result = {
|
|
110
|
+
/* your response data */
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
logger.info({ message: `${name}-success` });
|
|
114
|
+
return RuntimeActionResponse.success(result);
|
|
115
|
+
} catch (error) {
|
|
116
|
+
logger.error({ message: `${name}-error`, error: error.message, stack: error.stack });
|
|
117
|
+
return RuntimeActionResponse.error(
|
|
118
|
+
HttpStatus.INTERNAL_ERROR,
|
|
119
|
+
`Failed: ${error.message}`
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
);
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**TypeScript:** Same with type annotations and `import` syntax
|
|
127
|
+
|
|
128
|
+
### Step 5: Update Configuration Files
|
|
129
|
+
|
|
130
|
+
Add action to `app.config.yaml` or `ext.config.yaml`:
|
|
131
|
+
|
|
132
|
+
**Simple structure:**
|
|
133
|
+
```yaml
|
|
134
|
+
application:
|
|
135
|
+
runtimeManifest:
|
|
136
|
+
packages:
|
|
137
|
+
[package-name]:
|
|
138
|
+
license: Apache-2.0
|
|
139
|
+
actions:
|
|
140
|
+
[action-name]:
|
|
141
|
+
function: actions/[action-name]/index.[js/ts]
|
|
142
|
+
web: 'yes'
|
|
143
|
+
runtime: nodejs:22
|
|
144
|
+
inputs:
|
|
145
|
+
LOG_LEVEL: debug
|
|
146
|
+
annotations:
|
|
147
|
+
require-adobe-auth: [true/false]
|
|
148
|
+
final: true
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
**Packaged structure:**
|
|
152
|
+
Create `actions/[package]/actions.config.yaml` and reference in main config.
|
|
153
|
+
|
|
154
|
+
### Step 6: Completion
|
|
155
|
+
|
|
156
|
+
Display:
|
|
157
|
+
|
|
158
|
+
```
|
|
159
|
+
✅ Runtime Action Created Successfully!
|
|
160
|
+
|
|
161
|
+
📁 Files Created:
|
|
162
|
+
- actions/[path]/index.[js/ts]
|
|
163
|
+
|
|
164
|
+
📝 Configuration Updated:
|
|
165
|
+
- app.config.yaml or ext.config.yaml
|
|
166
|
+
[- actions/[package]/actions.config.yaml if packaged]
|
|
167
|
+
|
|
168
|
+
🚀 Next Steps:
|
|
169
|
+
1. Implement business logic in the action
|
|
170
|
+
2. Test locally: aio app dev
|
|
171
|
+
3. Deploy: aio app deploy
|
|
172
|
+
4. Test the action endpoint
|
|
173
|
+
|
|
174
|
+
📖 Documentation:
|
|
175
|
+
- RuntimeAction: @adobe-commerce/aio-toolkit
|
|
176
|
+
|
|
177
|
+
💡 Response Methods:
|
|
178
|
+
- success(result): Returns 200 with your data
|
|
179
|
+
- error(statusCode, message): Returns error with HTTP status code
|
|
180
|
+
- See RuntimeActionResponse Methods section for examples
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Key Features
|
|
184
|
+
|
|
185
|
+
- **Auto-detection**: Language (TS/JS) and project structure
|
|
186
|
+
- **Flexible**: Simple or packaged actions
|
|
187
|
+
- **HTTP Method Validation**: GET, POST, PUT, DELETE, PATCH
|
|
188
|
+
- **Parameter & Header Validation**: Automatic validation before execution
|
|
189
|
+
- **Response Methods**: success and error with proper HTTP status codes
|
|
190
|
+
- **Best Practices**: Structured logging, error handling, telemetry-ready
|
|
191
|
+
- **Configuration Management**: Automatic config file updates
|
|
192
|
+
|
|
193
|
+
### RuntimeActionResponse Methods
|
|
194
|
+
|
|
195
|
+
Runtime actions return responses using these methods:
|
|
196
|
+
|
|
197
|
+
#### **success(result)** - Return Successful Response
|
|
198
|
+
|
|
199
|
+
Returns a successful response with the provided result data and 200 status code.
|
|
200
|
+
|
|
201
|
+
**Parameters:**
|
|
202
|
+
- `result` (required): The data to return in the response body
|
|
203
|
+
|
|
204
|
+
```javascript
|
|
205
|
+
// Return success with data
|
|
206
|
+
return RuntimeActionResponse.success({
|
|
207
|
+
orderId: '12345',
|
|
208
|
+
status: 'completed',
|
|
209
|
+
message: 'Order processed successfully'
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
// Return success with array
|
|
213
|
+
return RuntimeActionResponse.success([
|
|
214
|
+
{ id: 1, name: 'Product A' },
|
|
215
|
+
{ id: 2, name: 'Product B' }
|
|
216
|
+
]);
|
|
217
|
+
|
|
218
|
+
// Return success with simple value
|
|
219
|
+
return RuntimeActionResponse.success({ message: 'Success' });
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Returns:
|
|
223
|
+
```json
|
|
224
|
+
{
|
|
225
|
+
"statusCode": 200,
|
|
226
|
+
"body": {
|
|
227
|
+
"orderId": "12345",
|
|
228
|
+
"status": "completed",
|
|
229
|
+
"message": "Order processed successfully"
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
#### **error(statusCode, message)** - Return Error Response
|
|
235
|
+
|
|
236
|
+
Returns an error response with the specified HTTP status code and error message.
|
|
237
|
+
|
|
238
|
+
**Parameters:**
|
|
239
|
+
- `statusCode` (required): HTTP status code from HttpStatus enum
|
|
240
|
+
- `message` (required): Error message string
|
|
241
|
+
|
|
242
|
+
**Available HttpStatus codes:**
|
|
243
|
+
- `HttpStatus.BAD_REQUEST` (400) - Invalid request
|
|
244
|
+
- `HttpStatus.UNAUTHORIZED` (401) - Authentication required
|
|
245
|
+
- `HttpStatus.FORBIDDEN` (403) - Access denied
|
|
246
|
+
- `HttpStatus.NOT_FOUND` (404) - Resource not found
|
|
247
|
+
- `HttpStatus.METHOD_NOT_ALLOWED` (405) - HTTP method not allowed
|
|
248
|
+
- `HttpStatus.INTERNAL_ERROR` (500) - Internal server error
|
|
249
|
+
|
|
250
|
+
```javascript
|
|
251
|
+
// Internal server error
|
|
252
|
+
return RuntimeActionResponse.error(
|
|
253
|
+
HttpStatus.INTERNAL_ERROR,
|
|
254
|
+
'Failed to process order'
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
// Bad request error
|
|
258
|
+
return RuntimeActionResponse.error(
|
|
259
|
+
HttpStatus.BAD_REQUEST,
|
|
260
|
+
'Invalid order ID provided'
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
// Not found error
|
|
264
|
+
return RuntimeActionResponse.error(
|
|
265
|
+
HttpStatus.NOT_FOUND,
|
|
266
|
+
'Customer not found'
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
// With error details from exception
|
|
270
|
+
catch (error) {
|
|
271
|
+
return RuntimeActionResponse.error(
|
|
272
|
+
HttpStatus.INTERNAL_ERROR,
|
|
273
|
+
`Failed: ${error.message}`
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
Returns:
|
|
279
|
+
```json
|
|
280
|
+
{
|
|
281
|
+
"error": {
|
|
282
|
+
"statusCode": 500,
|
|
283
|
+
"body": {
|
|
284
|
+
"error": "Failed to process order"
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
### Related Rules
|
|
291
|
+
|
|
292
|
+
- **Setting up New Relic Telemetry**: Add observability to your runtime action
|
|
293
|
+
|