@adobe-commerce/aio-toolkit 1.0.0 โ 1.0.1
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 +90 -16
- package/README.md +146 -97
- package/dist/index.d.mts +15 -12
- package/dist/index.d.ts +15 -12
- package/dist/index.js +134 -36
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +134 -36
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -12
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,80 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.0.1] - 2025-09-22
|
|
9
|
+
|
|
10
|
+
### ๐ Enhanced Developer Experience & API Improvements
|
|
11
|
+
|
|
12
|
+
This patch release focuses on improving developer experience, enhancing API consistency, and streamlining documentation. All changes maintain backward compatibility while introducing new features and improvements.
|
|
13
|
+
|
|
14
|
+
#### ๐ง API Enhancements
|
|
15
|
+
|
|
16
|
+
- **RestClient** `[Enhanced]` - Added granular HTTP request control
|
|
17
|
+
- `makeRequest()` method for raw HTTP requests returning Response objects
|
|
18
|
+
- `parseResponse()` method for flexible response parsing
|
|
19
|
+
- `parsed` flag on CRUD methods (get, post, put, delete) to control response parsing
|
|
20
|
+
- Deprecated `apiCall()` method (maintains backward compatibility)
|
|
21
|
+
- Enhanced flexibility for handling different response formats
|
|
22
|
+
|
|
23
|
+
- **HttpMethod Enum** `[Updated]` - Standardized HTTP method values
|
|
24
|
+
- Updated enum values from lowercase to uppercase (GET, POST, PUT, DELETE, etc.)
|
|
25
|
+
- Enhanced compliance with HTTP standards
|
|
26
|
+
- Automatic conversion of incoming method names for backward compatibility
|
|
27
|
+
- Updated all related tests and validation logic
|
|
28
|
+
|
|
29
|
+
- **BearerToken** `[Enhanced]` - Improved token extraction and portability
|
|
30
|
+
- Enhanced `extract()` method to prioritize standard HTTP headers
|
|
31
|
+
- Fallback support for OpenWhisk-specific `__ow_headers` format
|
|
32
|
+
- Improved portability across different runtime environments
|
|
33
|
+
- Enhanced documentation with comprehensive usage examples
|
|
34
|
+
- Better header parsing for standard HTTP authorization patterns
|
|
35
|
+
|
|
36
|
+
#### ๐ Documentation Improvements
|
|
37
|
+
|
|
38
|
+
- **Installation Guide** `[Updated]` - Simplified installation process
|
|
39
|
+
- Updated root README.md with correct npm installation steps
|
|
40
|
+
- Removed complex GitHub Packages setup instructions
|
|
41
|
+
- Streamlined onboarding for new developers
|
|
42
|
+
|
|
43
|
+
- **FileRepository Documentation** `[Fixed]` - Corrected method signatures
|
|
44
|
+
- Fixed inaccurate `save()` method documentation showing two parameters
|
|
45
|
+
- Updated to correct single-parameter `save(payload)` usage
|
|
46
|
+
- Added comprehensive examples with custom repository classes
|
|
47
|
+
- Included realistic CRUD operation patterns with proper parameter validation
|
|
48
|
+
- Updated require paths to use `@lib/EntityRepository` alias
|
|
49
|
+
|
|
50
|
+
- **Documentation Consolidation** `[Improved]` - Single source of truth
|
|
51
|
+
- Moved comprehensive package documentation to root README.md
|
|
52
|
+
- Removed duplicate `docs/` directory structure
|
|
53
|
+
- Updated package.json scripts to remove docs references
|
|
54
|
+
- Fixed broken links in CHANGELOG.md
|
|
55
|
+
- Simplified maintenance with unified documentation approach
|
|
56
|
+
|
|
57
|
+
#### ๐ ๏ธ Package & Repository Enhancements
|
|
58
|
+
|
|
59
|
+
- **Package Metadata** `[Cleaned]` - Streamlined package configuration
|
|
60
|
+
- Removed redundant repository URLs from package.json
|
|
61
|
+
- Cleaned up external links and badges
|
|
62
|
+
- Simplified License section to reference local LICENSE file
|
|
63
|
+
- Removed unnecessary "Support" section
|
|
64
|
+
|
|
65
|
+
- **Pull Request Template** `[Revised]` - Enhanced contributor workflow
|
|
66
|
+
- Streamlined PR template for better contributor experience
|
|
67
|
+
- Added clear sections for changes, motivation, testing, and impact assessment
|
|
68
|
+
- Improved checklist items for essential quality gates
|
|
69
|
+
- Reduced complexity while maintaining quality standards
|
|
70
|
+
- Better guidance for component testing and documentation updates
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
### ๐งช **Quality Assurance**
|
|
75
|
+
|
|
76
|
+
- **100% Test Coverage Maintained**: All new features and changes fully tested
|
|
77
|
+
- **Zero Breaking Changes**: Complete backward compatibility preserved
|
|
78
|
+
- **Enhanced Error Handling**: Improved error messages and validation
|
|
79
|
+
- **TypeScript Support**: All new APIs fully typed with comprehensive interfaces
|
|
80
|
+
- **Linting & Formatting**: All code meets strict quality standards
|
|
81
|
+
|
|
8
82
|
## [1.0.0] - 2025-09-14
|
|
9
83
|
|
|
10
84
|
### ๐ Initial Release
|
|
@@ -26,13 +100,13 @@ This is the first stable release of the **@adobe-commerce/aio-toolkit** - a comp
|
|
|
26
100
|
- Removed duplicate content and improved navigation
|
|
27
101
|
|
|
28
102
|
#### ๐๏ธ Commerce Components
|
|
29
|
-
- **
|
|
103
|
+
- **AdobeAuth** `[Added]` - Adobe IMS authentication and token management
|
|
30
104
|
- Static token retrieval with configurable IMS context
|
|
31
105
|
- Support for custom scopes and client credentials
|
|
32
106
|
- Comprehensive error handling for authentication failures
|
|
33
107
|
- TypeScript interfaces for IMS configuration
|
|
34
108
|
|
|
35
|
-
- **
|
|
109
|
+
- **AdobeCommerceClient** `[Added]` - HTTP client for Adobe Commerce API integration
|
|
36
110
|
- Multiple authentication strategies (Basic Auth, OAuth 1.0a, IMS Bearer Token)
|
|
37
111
|
- Built-in request/response logging and error handling
|
|
38
112
|
- Configurable HTTP client with Got.js integration
|
|
@@ -40,38 +114,38 @@ This is the first stable release of the **@adobe-commerce/aio-toolkit** - a comp
|
|
|
40
114
|
- Connection pattern for extensible authentication
|
|
41
115
|
|
|
42
116
|
#### ๐ง Framework Components
|
|
43
|
-
- **
|
|
117
|
+
- **EventConsumerAction** `[Added]` - Event-driven processing for Adobe I/O Events
|
|
44
118
|
- Automatic event validation and processing
|
|
45
119
|
- Configurable retry mechanisms and error handling
|
|
46
120
|
- Support for custom event handlers and middleware
|
|
47
121
|
- Built-in logging and monitoring capabilities
|
|
48
122
|
|
|
49
|
-
- **
|
|
123
|
+
- **FileRepository** `[Added]` - File-based storage with CRUD operations
|
|
50
124
|
- Complete CRUD operations for JSON file management
|
|
51
125
|
- Integration with Adobe I/O Runtime file system
|
|
52
126
|
- Automatic timestamp-based ID generation
|
|
53
127
|
- Error handling with graceful degradation
|
|
54
128
|
- TypeScript interfaces for file records
|
|
55
129
|
|
|
56
|
-
- **
|
|
130
|
+
- **GraphQlAction** `[Added]` - GraphQL server implementation
|
|
57
131
|
- Schema validation and type safety
|
|
58
132
|
- Custom resolver support with context injection
|
|
59
133
|
- Error handling and response formatting
|
|
60
134
|
- Integration with Adobe I/O Runtime
|
|
61
135
|
|
|
62
|
-
- **
|
|
136
|
+
- **OpenWhisk** `[Added]` - OpenWhisk client for serverless action invocation
|
|
63
137
|
- Direct OpenWhisk action invocation
|
|
64
138
|
- Parameter passing and response handling
|
|
65
139
|
- Error management and timeout handling
|
|
66
140
|
- TypeScript support for action parameters
|
|
67
141
|
|
|
68
|
-
- **
|
|
142
|
+
- **OpenWhiskAction** `[Added]` - OpenWhisk action wrapper
|
|
69
143
|
- Standardized action structure with logging
|
|
70
144
|
- Request parameter validation
|
|
71
145
|
- Error handling with proper HTTP status codes
|
|
72
146
|
- Extensible base class for custom actions
|
|
73
147
|
|
|
74
|
-
- **
|
|
148
|
+
- **RuntimeAction** `[Added]` - HTTP request handling and business logic execution
|
|
75
149
|
- Complete HTTP request/response handling
|
|
76
150
|
- Parameter validation and error management
|
|
77
151
|
- Built-in logging and debugging support
|
|
@@ -79,20 +153,20 @@ This is the first stable release of the **@adobe-commerce/aio-toolkit** - a comp
|
|
|
79
153
|
- TypeScript interfaces for all HTTP methods and status codes
|
|
80
154
|
|
|
81
155
|
#### ๐ Integration Components
|
|
82
|
-
- **
|
|
156
|
+
- **BearerToken** `[Added]` - Bearer token extraction utility for OpenWhisk actions
|
|
83
157
|
- Extract and validate Bearer tokens from OpenWhisk headers
|
|
84
158
|
- JWT token parsing with expiration validation
|
|
85
159
|
- Support for custom token formats
|
|
86
160
|
- Token information extraction with expiry details
|
|
87
161
|
|
|
88
|
-
- **
|
|
162
|
+
- **InfiniteLoopBreaker** `[Added]` - Detect and prevent infinite loops in event-driven applications
|
|
89
163
|
- SHA256-based fingerprinting for event deduplication
|
|
90
164
|
- Configurable TTL for stored fingerprints
|
|
91
165
|
- State-based persistence using Adobe I/O State
|
|
92
166
|
- Support for custom key and fingerprint functions
|
|
93
167
|
- Comprehensive error handling and logging
|
|
94
168
|
|
|
95
|
-
- **
|
|
169
|
+
- **OnboardEvents** `[Added]` - Complete onboarding orchestration for Adobe I/O Events
|
|
96
170
|
- **Comprehensive Event Onboarding**: End-to-end orchestration of providers, event metadata, and registrations
|
|
97
171
|
- **Provider Management**: Create and manage Adobe I/O Events providers with commerce-specific metadata
|
|
98
172
|
- **Event Metadata Creation**: Automated event metadata creation with sample templates
|
|
@@ -102,7 +176,7 @@ This is the first stable release of the **@adobe-commerce/aio-toolkit** - a comp
|
|
|
102
176
|
- **Input Validation**: Comprehensive input parsing and validation
|
|
103
177
|
- **TypeScript Support**: Full type definitions for all interfaces and responses
|
|
104
178
|
|
|
105
|
-
- **
|
|
179
|
+
- **RestClient** `[Added]` - HTTP client for external API integration
|
|
106
180
|
- Support for all HTTP methods (GET, POST, PUT, DELETE)
|
|
107
181
|
- Configurable headers and request/response handling
|
|
108
182
|
- Error handling with status code management
|
|
@@ -110,21 +184,21 @@ This is the first stable release of the **@adobe-commerce/aio-toolkit** - a comp
|
|
|
110
184
|
- TypeScript interfaces for headers and responses
|
|
111
185
|
|
|
112
186
|
#### ๐ก I/O Events Components
|
|
113
|
-
- **
|
|
187
|
+
- **EventMetadataManager** `[Added]` - Manage event metadata for Adobe I/O Events providers
|
|
114
188
|
- Complete CRUD operations for event metadata
|
|
115
189
|
- Sample event template management
|
|
116
190
|
- URL encoding support for event codes
|
|
117
191
|
- Comprehensive error handling and validation
|
|
118
192
|
- TypeScript interfaces for all operations
|
|
119
193
|
|
|
120
|
-
- **
|
|
194
|
+
- **ProviderManager** `[Added]` - Manage event providers for Adobe I/O Events
|
|
121
195
|
- Provider creation, retrieval, updating, and deletion
|
|
122
196
|
- Support for provider metadata and documentation URLs
|
|
123
197
|
- Query parameter support for filtering
|
|
124
198
|
- Commerce-specific provider enhancements
|
|
125
199
|
- Complete HAL+JSON response handling
|
|
126
200
|
|
|
127
|
-
- **
|
|
201
|
+
- **RegistrationManager** `[Added]` - Manage event registrations and subscriptions
|
|
128
202
|
- Registration lifecycle management
|
|
129
203
|
- Support for webhook, journal, and EventBridge delivery types
|
|
130
204
|
- Event filtering and subscription management
|
|
@@ -153,7 +227,7 @@ This is the first stable release of the **@adobe-commerce/aio-toolkit** - a comp
|
|
|
153
227
|
## ๐ฆ **Package Information**
|
|
154
228
|
|
|
155
229
|
- **Package Name**: `@adobe-commerce/aio-toolkit`
|
|
156
|
-
- **Version**: 1.0.
|
|
230
|
+
- **Version**: 1.0.1
|
|
157
231
|
- **Node.js Support**: >=18.0.0
|
|
158
232
|
- **TypeScript Support**: >=4.9.0
|
|
159
233
|
- **License**: Proprietary (Adobe Commerce)
|
package/README.md
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
# @adobe-commerce/aio-toolkit
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/@adobe-commerce/aio-toolkit)
|
|
4
|
-
[](LICENSE)
|
|
5
|
-
|
|
6
3
|
## Overview
|
|
7
4
|
|
|
8
5
|
A comprehensive TypeScript toolkit for Adobe App Builder applications providing standardized Adobe Commerce integrations, I/O Events orchestration, file storage utilities, authentication helpers, and robust backend development tools with 100% test coverage.
|
|
@@ -182,99 +179,128 @@ exports.main = helloWorldAction;
|
|
|
182
179
|
#### `FileRepository`
|
|
183
180
|
File-based storage with CRUD operations for Adobe I/O Runtime applications.
|
|
184
181
|
|
|
185
|
-
|
|
186
|
-
|
|
182
|
+
**Key Methods:**
|
|
183
|
+
- `save(payload)`: Saves data as a single object parameter. Include `id` in the payload for explicit ID, or omit it for auto-generated timestamp ID.
|
|
184
|
+
- `load(id)`: Loads data by ID
|
|
185
|
+
- `list()`: Lists all stored records
|
|
186
|
+
- `delete(ids)`: Deletes records by ID array
|
|
187
187
|
|
|
188
|
-
|
|
189
|
-
const orderRepository = new FileRepository('orders');
|
|
190
|
-
const customerRepository = new FileRepository('customers');
|
|
188
|
+
**Best Practice:** Create custom repository classes that extend FileRepository for specific entities.
|
|
191
189
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const orderId = orderData.orderId;
|
|
195
|
-
|
|
196
|
-
const success = await orderRepository.save(orderId, {
|
|
197
|
-
...orderData,
|
|
198
|
-
createdAt: new Date().toISOString(),
|
|
199
|
-
status: 'pending'
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
if (success) {
|
|
203
|
-
console.log(`Order ${orderId} saved successfully`);
|
|
204
|
-
} else {
|
|
205
|
-
throw new Error(`Failed to save order ${orderId}`);
|
|
206
|
-
}
|
|
207
|
-
};
|
|
190
|
+
##### **1. Define Entity Repository**
|
|
191
|
+
Create a custom repository class extending FileRepository:
|
|
208
192
|
|
|
209
|
-
|
|
210
|
-
const
|
|
211
|
-
const orderData = await orderRepository.load(orderId);
|
|
212
|
-
|
|
213
|
-
if (Object.keys(orderData).length === 0) {
|
|
214
|
-
throw new Error(`Order ${orderId} not found`);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
return orderData;
|
|
218
|
-
};
|
|
193
|
+
```javascript
|
|
194
|
+
const { FileRepository } = require("@adobe-commerce/aio-toolkit");
|
|
219
195
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
orders.push({ id: orderId, ...orderData });
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
return orders;
|
|
232
|
-
};
|
|
196
|
+
class EntityRepository extends FileRepository {
|
|
197
|
+
/**
|
|
198
|
+
* @constructor
|
|
199
|
+
*/
|
|
200
|
+
constructor() {
|
|
201
|
+
super("/toolkit-demo/entity");
|
|
202
|
+
}
|
|
203
|
+
}
|
|
233
204
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
await
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
);
|
|
205
|
+
module.exports = EntityRepository;
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
##### **2. List Action**
|
|
209
|
+
Retrieve all entities from the repository:
|
|
210
|
+
|
|
211
|
+
```javascript
|
|
212
|
+
const { HttpMethod, RuntimeAction, RuntimeActionResponse } = require("@adobe-commerce/aio-toolkit");
|
|
213
|
+
const EntityRepository = require("@lib/EntityRepository");
|
|
214
|
+
|
|
215
|
+
exports.main = RuntimeAction.execute(
|
|
216
|
+
"entity-list",
|
|
217
|
+
[HttpMethod.POST],
|
|
218
|
+
[],
|
|
219
|
+
['Authorization'],
|
|
220
|
+
async (params) => {
|
|
221
|
+
const entityRepository = new EntityRepository();
|
|
222
|
+
return RuntimeActionResponse.success(await entityRepository.list());
|
|
223
|
+
}
|
|
224
|
+
);
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
##### **3. Load Action**
|
|
228
|
+
Load a specific entity by ID:
|
|
229
|
+
|
|
230
|
+
```javascript
|
|
231
|
+
const { HttpMethod, RuntimeAction, RuntimeActionResponse } = require("@adobe-commerce/aio-toolkit");
|
|
232
|
+
const EntityRepository = require("@lib/EntityRepository");
|
|
233
|
+
|
|
234
|
+
exports.main = RuntimeAction.execute(
|
|
235
|
+
"entity-load",
|
|
236
|
+
[HttpMethod.POST],
|
|
237
|
+
['id'],
|
|
238
|
+
['Authorization'],
|
|
239
|
+
async (params) => {
|
|
240
|
+
const entityRepository = new EntityRepository();
|
|
241
|
+
return RuntimeActionResponse.success(await entityRepository.load(params.id));
|
|
271
242
|
}
|
|
272
|
-
}
|
|
273
243
|
);
|
|
244
|
+
```
|
|
274
245
|
|
|
275
|
-
|
|
246
|
+
##### **4. Save Action**
|
|
247
|
+
Save entity data with proper parameter handling:
|
|
248
|
+
|
|
249
|
+
```javascript
|
|
250
|
+
const { HttpMethod, RuntimeAction, RuntimeActionResponse } = require("@adobe-commerce/aio-toolkit");
|
|
251
|
+
const EntityRepository = require("@lib/EntityRepository");
|
|
252
|
+
|
|
253
|
+
const requiredParams = [
|
|
254
|
+
"name",
|
|
255
|
+
"status"
|
|
256
|
+
];
|
|
257
|
+
|
|
258
|
+
exports.main = RuntimeAction.execute(
|
|
259
|
+
"entity-save",
|
|
260
|
+
[HttpMethod.POST],
|
|
261
|
+
requiredParams,
|
|
262
|
+
['Authorization'],
|
|
263
|
+
async (params) => {
|
|
264
|
+
const entityRepository = new EntityRepository();
|
|
265
|
+
|
|
266
|
+
let payload = {};
|
|
267
|
+
for (const fieldName in requiredParams) {
|
|
268
|
+
payload[requiredParams[fieldName]] = params[requiredParams[fieldName]];
|
|
269
|
+
}
|
|
270
|
+
if (Object.prototype.hasOwnProperty.call(params, 'id')) {
|
|
271
|
+
payload['id'] = params['id'];
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return RuntimeActionResponse.success((await entityRepository.save(payload)).toString());
|
|
275
|
+
}
|
|
276
|
+
);
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
##### **5. Delete Action**
|
|
280
|
+
Delete entities by providing an array of IDs:
|
|
281
|
+
|
|
282
|
+
```javascript
|
|
283
|
+
const { HttpMethod, RuntimeAction, RuntimeActionResponse } = require("@adobe-commerce/aio-toolkit");
|
|
284
|
+
const EntityRepository = require("@lib/EntityRepository");
|
|
285
|
+
|
|
286
|
+
exports.main = RuntimeAction.execute(
|
|
287
|
+
"entity-delete",
|
|
288
|
+
[HttpMethod.POST],
|
|
289
|
+
['ids'],
|
|
290
|
+
['Authorization'],
|
|
291
|
+
async (params) => {
|
|
292
|
+
const entityRepository = new EntityRepository();
|
|
293
|
+
return RuntimeActionResponse.success(await entityRepository.delete(params.ids));
|
|
294
|
+
}
|
|
295
|
+
);
|
|
276
296
|
```
|
|
277
297
|
|
|
298
|
+
This approach provides:
|
|
299
|
+
- **Separation of concerns**: Each CRUD operation has its own action file
|
|
300
|
+
- **Reusable repository**: Custom repository can be shared across actions
|
|
301
|
+
- **Proper validation**: Required parameters and headers are enforced
|
|
302
|
+
- **Consistent responses**: All actions use RuntimeActionResponse for standardized output
|
|
303
|
+
|
|
278
304
|
### ๐ช Commerce Components
|
|
279
305
|
|
|
280
306
|
**Adobe Commerce API integration and authentication**
|
|
@@ -339,18 +365,46 @@ const response = await client.get('https://api.example.com/data', {
|
|
|
339
365
|
```
|
|
340
366
|
|
|
341
367
|
#### `BearerToken`
|
|
342
|
-
Bearer token extraction and JWT analysis utility.
|
|
368
|
+
Bearer token extraction and JWT analysis utility. Supports both standard HTTP headers and OpenWhisk format for maximum portability.
|
|
343
369
|
|
|
370
|
+
**Extract from Standard HTTP Headers**
|
|
344
371
|
```typescript
|
|
345
372
|
const { BearerToken } = require('@adobe-commerce/aio-toolkit');
|
|
346
373
|
|
|
347
|
-
const
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
374
|
+
const headers = { authorization: 'Bearer abc123token' };
|
|
375
|
+
const tokenInfo = BearerToken.extract(headers);
|
|
376
|
+
console.log(tokenInfo);
|
|
377
|
+
// Output: {
|
|
378
|
+
// token: 'abc123token',
|
|
379
|
+
// tokenLength: 11,
|
|
380
|
+
// isValid: true,
|
|
381
|
+
// expiry: '2024-01-02T12:00:00.000Z',
|
|
382
|
+
// timeUntilExpiry: 86400000
|
|
383
|
+
// }
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
**Extract from OpenWhisk Params (Backward Compatibility)**
|
|
387
|
+
```typescript
|
|
388
|
+
const params = { __ow_headers: { authorization: 'Bearer abc123token' } };
|
|
389
|
+
const owTokenInfo = BearerToken.extract(params);
|
|
390
|
+
console.log(owTokenInfo); // Same output format as above
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
**Direct Token Analysis**
|
|
394
|
+
```typescript
|
|
395
|
+
const directInfo = BearerToken.info('jwt-token-string');
|
|
396
|
+
if (directInfo.isValid) {
|
|
397
|
+
console.log(`Token expires at: ${directInfo.expiry}`);
|
|
398
|
+
console.log(`Time until expiry: ${directInfo.timeUntilExpiry}ms`);
|
|
399
|
+
} else {
|
|
400
|
+
console.log('Token is invalid or expired');
|
|
351
401
|
}
|
|
352
402
|
```
|
|
353
403
|
|
|
404
|
+
**Methods:**
|
|
405
|
+
- `extract(headersOrParams)` - Extracts Bearer token from headers or OpenWhisk params
|
|
406
|
+
- `info(token)` - Analyzes token string and returns validation/expiry details
|
|
407
|
+
|
|
354
408
|
#### `InfiniteLoopBreaker`
|
|
355
409
|
Detect and prevent infinite loops in event-driven applications.
|
|
356
410
|
|
|
@@ -650,9 +704,4 @@ IO_WORKSPACE_ID=workspace-id
|
|
|
650
704
|
|
|
651
705
|
## License
|
|
652
706
|
|
|
653
|
-
See the
|
|
654
|
-
|
|
655
|
-
## Support
|
|
656
|
-
|
|
657
|
-
- **Documentation**: Full API documentation available in TypeScript definitions
|
|
658
|
-
- **Package**: [npm package page](https://www.npmjs.com/package/@adobe-commerce/aio-toolkit)
|
|
707
|
+
See the LICENSE file (in package) for license rights and limitations.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import openwhisk, { Dict, Activation } from 'openwhisk';
|
|
2
|
+
import { Response } from 'node-fetch';
|
|
2
3
|
import { Logger } from '@adobe/aio-sdk';
|
|
3
4
|
import { Got, RequestError } from 'got';
|
|
4
5
|
|
|
@@ -11,13 +12,13 @@ declare enum HttpStatus {
|
|
|
11
12
|
INTERNAL_ERROR = 500
|
|
12
13
|
}
|
|
13
14
|
declare enum HttpMethod {
|
|
14
|
-
GET = "
|
|
15
|
-
POST = "
|
|
16
|
-
PUT = "
|
|
17
|
-
DELETE = "
|
|
18
|
-
PATCH = "
|
|
19
|
-
HEAD = "
|
|
20
|
-
OPTIONS = "
|
|
15
|
+
GET = "GET",
|
|
16
|
+
POST = "POST",
|
|
17
|
+
PUT = "PUT",
|
|
18
|
+
DELETE = "DELETE",
|
|
19
|
+
PATCH = "PATCH",
|
|
20
|
+
HEAD = "HEAD",
|
|
21
|
+
OPTIONS = "OPTIONS"
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
interface SuccessResponse {
|
|
@@ -146,7 +147,7 @@ interface BearerTokenInfo {
|
|
|
146
147
|
}
|
|
147
148
|
|
|
148
149
|
declare class BearerToken {
|
|
149
|
-
static extract(
|
|
150
|
+
static extract(headersOrParams: {
|
|
150
151
|
[key: string]: any;
|
|
151
152
|
}): BearerTokenInfo;
|
|
152
153
|
static info(token: string | null): BearerTokenInfo;
|
|
@@ -159,10 +160,12 @@ interface Headers {
|
|
|
159
160
|
}
|
|
160
161
|
|
|
161
162
|
declare class RestClient {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
163
|
+
makeRequest(endpoint: string, method?: string, headers?: Headers, payload?: any): Promise<Response>;
|
|
164
|
+
parseResponse(response: Response): Promise<any>;
|
|
165
|
+
get(endpoint: string, headers?: Headers, parsed?: boolean): Promise<Response | any>;
|
|
166
|
+
post(endpoint: string, headers?: Headers, payload?: any, parsed?: boolean): Promise<Response | any>;
|
|
167
|
+
put(endpoint: string, headers?: Headers, payload?: any, parsed?: boolean): Promise<Response | any>;
|
|
168
|
+
delete(endpoint: string, headers?: Headers, parsed?: boolean): Promise<Response | any>;
|
|
166
169
|
apiCall(endpoint: string, method?: string, headers?: Headers, payload?: any): Promise<any>;
|
|
167
170
|
}
|
|
168
171
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import openwhisk, { Dict, Activation } from 'openwhisk';
|
|
2
|
+
import { Response } from 'node-fetch';
|
|
2
3
|
import { Logger } from '@adobe/aio-sdk';
|
|
3
4
|
import { Got, RequestError } from 'got';
|
|
4
5
|
|
|
@@ -11,13 +12,13 @@ declare enum HttpStatus {
|
|
|
11
12
|
INTERNAL_ERROR = 500
|
|
12
13
|
}
|
|
13
14
|
declare enum HttpMethod {
|
|
14
|
-
GET = "
|
|
15
|
-
POST = "
|
|
16
|
-
PUT = "
|
|
17
|
-
DELETE = "
|
|
18
|
-
PATCH = "
|
|
19
|
-
HEAD = "
|
|
20
|
-
OPTIONS = "
|
|
15
|
+
GET = "GET",
|
|
16
|
+
POST = "POST",
|
|
17
|
+
PUT = "PUT",
|
|
18
|
+
DELETE = "DELETE",
|
|
19
|
+
PATCH = "PATCH",
|
|
20
|
+
HEAD = "HEAD",
|
|
21
|
+
OPTIONS = "OPTIONS"
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
interface SuccessResponse {
|
|
@@ -146,7 +147,7 @@ interface BearerTokenInfo {
|
|
|
146
147
|
}
|
|
147
148
|
|
|
148
149
|
declare class BearerToken {
|
|
149
|
-
static extract(
|
|
150
|
+
static extract(headersOrParams: {
|
|
150
151
|
[key: string]: any;
|
|
151
152
|
}): BearerTokenInfo;
|
|
152
153
|
static info(token: string | null): BearerTokenInfo;
|
|
@@ -159,10 +160,12 @@ interface Headers {
|
|
|
159
160
|
}
|
|
160
161
|
|
|
161
162
|
declare class RestClient {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
163
|
+
makeRequest(endpoint: string, method?: string, headers?: Headers, payload?: any): Promise<Response>;
|
|
164
|
+
parseResponse(response: Response): Promise<any>;
|
|
165
|
+
get(endpoint: string, headers?: Headers, parsed?: boolean): Promise<Response | any>;
|
|
166
|
+
post(endpoint: string, headers?: Headers, payload?: any, parsed?: boolean): Promise<Response | any>;
|
|
167
|
+
put(endpoint: string, headers?: Headers, payload?: any, parsed?: boolean): Promise<Response | any>;
|
|
168
|
+
delete(endpoint: string, headers?: Headers, parsed?: boolean): Promise<Response | any>;
|
|
166
169
|
apiCall(endpoint: string, method?: string, headers?: Headers, payload?: any): Promise<any>;
|
|
167
170
|
}
|
|
168
171
|
|