akamai-edge-delivery-polyfill 1.0.0
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/LICENSE +21 -0
- package/README.md +320 -0
- package/dist/crypto.d.ts +69 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +161 -0
- package/dist/crypto.js.map +7 -0
- package/dist/global.d.ts +22 -0
- package/dist/global.d.ts.map +1 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +817 -0
- package/dist/index.js.map +7 -0
- package/dist/kv-namespace.d.ts +68 -0
- package/dist/kv-namespace.d.ts.map +1 -0
- package/dist/kv-namespace.js +132 -0
- package/dist/kv-namespace.js.map +7 -0
- package/dist/polyfill.global.js +846 -0
- package/dist/polyfill.global.js.map +7 -0
- package/dist/request.d.ts +48 -0
- package/dist/request.d.ts.map +1 -0
- package/dist/request.js +220 -0
- package/dist/request.js.map +7 -0
- package/dist/response.d.ts +37 -0
- package/dist/response.d.ts.map +1 -0
- package/dist/response.js +233 -0
- package/dist/response.js.map +7 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Istiak Mahmod
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
# Akamai Edge Delivery Polyfill
|
|
2
|
+
|
|
3
|
+
A comprehensive polyfill that makes Akamai EdgeWorkers compatible with Cloudflare Workers API, enabling the use of Optimizely Edge Delivery SDK and other Cloudflare-compatible libraries on Akamai's edge platform.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Request/Response API**: Full Fetch API compatibility for handling HTTP requests and responses
|
|
8
|
+
- **Headers API**: Complete Headers implementation matching Web standards
|
|
9
|
+
- **KVNamespace**: Maps Cloudflare KV operations to Akamai EdgeKV
|
|
10
|
+
- **Crypto API**: Web Crypto API polyfill for cryptographic operations
|
|
11
|
+
- **TextEncoder/TextDecoder**: Text encoding/decoding utilities
|
|
12
|
+
- **ReadableStream**: Basic stream implementation for body handling
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install akamai-edge-delivery-polyfill
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Building
|
|
21
|
+
|
|
22
|
+
### Build the Package
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
# Install dependencies
|
|
26
|
+
npm install
|
|
27
|
+
|
|
28
|
+
# Build all bundles
|
|
29
|
+
npm run build
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
This creates:
|
|
33
|
+
- `dist/index.js` - ESM bundle for module imports
|
|
34
|
+
- `dist/polyfill.global.js` - Global IIFE bundle that auto-installs polyfills
|
|
35
|
+
- `dist/request.js`, `dist/response.js`, etc. - Individual module bundles
|
|
36
|
+
- TypeScript declarations in `dist/*.d.ts`
|
|
37
|
+
|
|
38
|
+
### Build Output
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
dist/
|
|
42
|
+
├── index.js # ESM bundle (main)
|
|
43
|
+
├── polyfill.global.js # Global bundle (auto-installs APIs)
|
|
44
|
+
├── request.js # Individual modules
|
|
45
|
+
├── response.js
|
|
46
|
+
├── kv-namespace.js
|
|
47
|
+
├── crypto.js
|
|
48
|
+
└── *.d.ts # TypeScript declarations
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Usage
|
|
52
|
+
|
|
53
|
+
### Option 1: Global Bundle (Easiest - Recommended)
|
|
54
|
+
|
|
55
|
+
The global bundle automatically installs all polyfills when loaded, making them available globally.
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
// Import the global bundle first (auto-installs all APIs)
|
|
59
|
+
import './node_modules/akamai-edge-delivery-polyfill/dist/polyfill.global.js';
|
|
60
|
+
|
|
61
|
+
// Now Request, Response, Headers, crypto, etc. are global
|
|
62
|
+
export async function onClientRequest(request) {
|
|
63
|
+
const cfRequest = new Request(request);
|
|
64
|
+
|
|
65
|
+
const response = Response.json({
|
|
66
|
+
message: 'Hello from Akamai!',
|
|
67
|
+
url: cfRequest.url
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
status: response.status,
|
|
72
|
+
headers: Object.fromEntries(response.headers.entries()),
|
|
73
|
+
body: await response.text()
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Option 2: ES Modules
|
|
79
|
+
|
|
80
|
+
Use the ESM bundle for module imports:
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import { Request, Response, installGlobalPolyfills } from 'akamai-edge-delivery-polyfill';
|
|
84
|
+
|
|
85
|
+
// Use classes directly
|
|
86
|
+
export async function onClientRequest(request) {
|
|
87
|
+
const cfRequest = new Request(request);
|
|
88
|
+
|
|
89
|
+
const response = new Response(JSON.stringify({ message: 'Hello from Akamai!' }), {
|
|
90
|
+
status: 200,
|
|
91
|
+
headers: {
|
|
92
|
+
'Content-Type': 'application/json'
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
status: response.status,
|
|
98
|
+
headers: Object.fromEntries(response.headers.entries()),
|
|
99
|
+
body: await response.text()
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Option 2: Install global polyfills (useful for libraries expecting global APIs)
|
|
104
|
+
installGlobalPolyfills();
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Using with Optimizely Edge Delivery SDK
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
import { installGlobalPolyfills, KVNamespace } from 'akamai-edge-delivery-polyfill';
|
|
111
|
+
import { createInstance } from '@optimizely/edge-delivery-sdk';
|
|
112
|
+
|
|
113
|
+
// Install global polyfills for Optimizely SDK compatibility
|
|
114
|
+
installGlobalPolyfills();
|
|
115
|
+
|
|
116
|
+
// Create KV namespace for Optimizely data
|
|
117
|
+
const optimizelyKV = new KVNamespace('optimizely', 'config');
|
|
118
|
+
|
|
119
|
+
// Initialize Optimizely
|
|
120
|
+
const optimizely = createInstance({
|
|
121
|
+
sdkKey: 'your-sdk-key',
|
|
122
|
+
// ... other config
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
export async function onClientRequest(request) {
|
|
126
|
+
const cfRequest = new Request(request);
|
|
127
|
+
|
|
128
|
+
// Use Optimizely for decision making
|
|
129
|
+
const user = {
|
|
130
|
+
id: cfRequest.headers.get('user-id') || 'anonymous',
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const decision = optimizely.decide(user, 'feature-flag-key');
|
|
134
|
+
|
|
135
|
+
// Return personalized response
|
|
136
|
+
const response = new Response(JSON.stringify({
|
|
137
|
+
enabled: decision.enabled,
|
|
138
|
+
variables: decision.variables,
|
|
139
|
+
}), {
|
|
140
|
+
status: 200,
|
|
141
|
+
headers: { 'Content-Type': 'application/json' }
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
return {
|
|
145
|
+
status: response.status,
|
|
146
|
+
headers: Object.fromEntries(response.headers.entries()),
|
|
147
|
+
body: await response.text()
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### KVNamespace (EdgeKV Integration)
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
import { KVNamespace } from 'akamai-edge-delivery-polyfill';
|
|
156
|
+
|
|
157
|
+
// Create a KV namespace (maps to Akamai EdgeKV)
|
|
158
|
+
const myKV = new KVNamespace('my-namespace', 'production');
|
|
159
|
+
|
|
160
|
+
// Get a value
|
|
161
|
+
const value = await myKV.get('key');
|
|
162
|
+
const jsonValue = await myKV.get('key', 'json');
|
|
163
|
+
|
|
164
|
+
// Put a value
|
|
165
|
+
await myKV.put('key', 'value');
|
|
166
|
+
await myKV.put('key', JSON.stringify({ data: 'value' }));
|
|
167
|
+
|
|
168
|
+
// Delete a value
|
|
169
|
+
await myKV.delete('key');
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Crypto API
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
import { Crypto } from 'akamai-edge-delivery-polyfill';
|
|
176
|
+
|
|
177
|
+
const crypto = new Crypto();
|
|
178
|
+
|
|
179
|
+
// Generate random UUID
|
|
180
|
+
const uuid = crypto.randomUUID();
|
|
181
|
+
|
|
182
|
+
// Generate random values
|
|
183
|
+
const array = new Uint8Array(16);
|
|
184
|
+
crypto.getRandomValues(array);
|
|
185
|
+
|
|
186
|
+
// Use SubtleCrypto for hashing (if supported by runtime)
|
|
187
|
+
const data = new TextEncoder().encode('Hello World');
|
|
188
|
+
const hash = await crypto.subtle.digest('SHA-256', data);
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Helper Functions
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
import { toEdgeWorkerResponse } from 'akamai-edge-delivery-polyfill';
|
|
195
|
+
|
|
196
|
+
// Convert Cloudflare-style Response to Akamai EdgeWorker format
|
|
197
|
+
const cfResponse = new Response('Hello', { status: 200 });
|
|
198
|
+
const ewResponse = await toEdgeWorkerResponse(cfResponse);
|
|
199
|
+
|
|
200
|
+
// Returns: { status: 200, headers: {...}, body: 'Hello' }
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## API Reference
|
|
204
|
+
|
|
205
|
+
### Request
|
|
206
|
+
|
|
207
|
+
Wraps Akamai EdgeWorker requests to provide Cloudflare-compatible Request interface.
|
|
208
|
+
|
|
209
|
+
**Constructor:**
|
|
210
|
+
```typescript
|
|
211
|
+
new Request(input: string | Request | AkamaiRequest, init?: RequestInit)
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
**Properties:**
|
|
215
|
+
- `url: string` - The request URL
|
|
216
|
+
- `method: string` - HTTP method
|
|
217
|
+
- `headers: Headers` - Request headers
|
|
218
|
+
- `bodyUsed: boolean` - Whether body has been consumed
|
|
219
|
+
|
|
220
|
+
**Methods:**
|
|
221
|
+
- `text(): Promise<string>` - Read body as text
|
|
222
|
+
- `json(): Promise<any>` - Read body as JSON
|
|
223
|
+
- `arrayBuffer(): Promise<ArrayBuffer>` - Read body as ArrayBuffer
|
|
224
|
+
- `clone(): Request` - Clone the request
|
|
225
|
+
|
|
226
|
+
### Response
|
|
227
|
+
|
|
228
|
+
Creates Cloudflare-compatible Response objects.
|
|
229
|
+
|
|
230
|
+
**Constructor:**
|
|
231
|
+
```typescript
|
|
232
|
+
new Response(body?: BodyInit | null, init?: ResponseInit)
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
**Properties:**
|
|
236
|
+
- `status: number` - HTTP status code
|
|
237
|
+
- `statusText: string` - HTTP status text
|
|
238
|
+
- `ok: boolean` - True if status is 2xx
|
|
239
|
+
- `headers: Headers` - Response headers
|
|
240
|
+
- `body: ReadableStream | null` - Response body stream
|
|
241
|
+
- `bodyUsed: boolean` - Whether body has been consumed
|
|
242
|
+
|
|
243
|
+
**Methods:**
|
|
244
|
+
- `text(): Promise<string>` - Read body as text
|
|
245
|
+
- `json(): Promise<any>` - Read body as JSON
|
|
246
|
+
- `arrayBuffer(): Promise<ArrayBuffer>` - Read body as ArrayBuffer
|
|
247
|
+
- `clone(): Response` - Clone the response
|
|
248
|
+
|
|
249
|
+
**Static Methods:**
|
|
250
|
+
- `Response.json(data: any, init?: ResponseInit): Response` - Create JSON response
|
|
251
|
+
- `Response.redirect(url: string, status?: number): Response` - Create redirect response
|
|
252
|
+
|
|
253
|
+
### KVNamespace
|
|
254
|
+
|
|
255
|
+
Maps Cloudflare KV operations to Akamai EdgeKV.
|
|
256
|
+
|
|
257
|
+
**Constructor:**
|
|
258
|
+
```typescript
|
|
259
|
+
new KVNamespace(namespace: string, group?: string)
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
**Methods:**
|
|
263
|
+
- `get(key: string, type?: 'text' | 'json' | 'arrayBuffer' | 'stream'): Promise<any>` - Get value
|
|
264
|
+
- `getWithMetadata<T>(key: string, type?): Promise<{ value: any, metadata: T }>` - Get with metadata
|
|
265
|
+
- `put(key: string, value: string | ArrayBuffer | ReadableStream): Promise<void>` - Put value
|
|
266
|
+
- `delete(key: string): Promise<void>` - Delete value
|
|
267
|
+
- `list(options?: KVListOptions): Promise<KVListResult>` - List keys (limited support)
|
|
268
|
+
|
|
269
|
+
### Crypto
|
|
270
|
+
|
|
271
|
+
Web Crypto API polyfill.
|
|
272
|
+
|
|
273
|
+
**Methods:**
|
|
274
|
+
- `getRandomValues<T extends ArrayBufferView>(array: T): T` - Fill array with random values
|
|
275
|
+
- `randomUUID(): string` - Generate random UUID
|
|
276
|
+
- `subtle: SubtleCrypto` - Access SubtleCrypto API
|
|
277
|
+
|
|
278
|
+
## Important Notes
|
|
279
|
+
|
|
280
|
+
### EdgeKV Setup
|
|
281
|
+
|
|
282
|
+
To use `KVNamespace`, you need to have Akamai EdgeKV configured and the `edgekv.js` helper library available in your EdgeWorker bundle. The polyfill expects to require it as:
|
|
283
|
+
|
|
284
|
+
```javascript
|
|
285
|
+
const { EdgeKV } = require('./edgekv.js');
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### Limitations
|
|
289
|
+
|
|
290
|
+
1. **KVNamespace.list()**: EdgeKV doesn't natively support listing keys, so this method has limited functionality
|
|
291
|
+
2. **ReadableStream**: Basic implementation provided; may not support all stream features
|
|
292
|
+
3. **Crypto.subtle**: Some operations may not be available depending on Akamai runtime capabilities
|
|
293
|
+
|
|
294
|
+
### TypeScript Support
|
|
295
|
+
|
|
296
|
+
The polyfill includes full TypeScript definitions. No additional `@types` packages needed.
|
|
297
|
+
|
|
298
|
+
## Examples
|
|
299
|
+
|
|
300
|
+
See the `examples/` directory for complete working examples:
|
|
301
|
+
|
|
302
|
+
- `basic-usage.ts` - Basic request/response handling
|
|
303
|
+
- `optimizely-integration.ts` - Using with Optimizely Edge Delivery SDK
|
|
304
|
+
- `kv-storage.ts` - EdgeKV integration examples
|
|
305
|
+
|
|
306
|
+
## License
|
|
307
|
+
|
|
308
|
+
MIT
|
|
309
|
+
|
|
310
|
+
## Contributing
|
|
311
|
+
|
|
312
|
+
Contributions are welcome! Please open an issue or submit a pull request.
|
|
313
|
+
|
|
314
|
+
## Support
|
|
315
|
+
|
|
316
|
+
For issues specific to this polyfill, please open a GitHub issue.
|
|
317
|
+
|
|
318
|
+
For Akamai EdgeWorkers support, see [Akamai EdgeWorkers documentation](https://techdocs.akamai.com/edgeworkers/docs)
|
|
319
|
+
|
|
320
|
+
For Optimizely Edge Delivery SDK support, see [Optimizely documentation](https://docs.developers.optimizely.com/)
|
package/dist/crypto.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Crypto polyfill for Akamai EdgeWorkers to match Cloudflare Workers Web Crypto API
|
|
3
|
+
* Provides a subset of the Web Crypto API using Akamai's crypto module
|
|
4
|
+
*/
|
|
5
|
+
export declare class Crypto {
|
|
6
|
+
/**
|
|
7
|
+
* Generate cryptographically strong random values
|
|
8
|
+
*/
|
|
9
|
+
getRandomValues<T extends ArrayBufferView>(array: T): T;
|
|
10
|
+
/**
|
|
11
|
+
* Generate a random UUID
|
|
12
|
+
*/
|
|
13
|
+
randomUUID(): string;
|
|
14
|
+
/**
|
|
15
|
+
* SubtleCrypto API for cryptographic operations
|
|
16
|
+
*/
|
|
17
|
+
get subtle(): SubtleCrypto;
|
|
18
|
+
}
|
|
19
|
+
export declare class SubtleCrypto {
|
|
20
|
+
/**
|
|
21
|
+
* Generate a digest (hash) of the data
|
|
22
|
+
*/
|
|
23
|
+
digest(algorithm: AlgorithmIdentifier, data: BufferSource): Promise<ArrayBuffer>;
|
|
24
|
+
/**
|
|
25
|
+
* Sign data with a key
|
|
26
|
+
*/
|
|
27
|
+
sign(algorithm: AlgorithmIdentifier, key: CryptoKey, data: BufferSource): Promise<ArrayBuffer>;
|
|
28
|
+
/**
|
|
29
|
+
* Verify a signature
|
|
30
|
+
*/
|
|
31
|
+
verify(algorithm: AlgorithmIdentifier, key: CryptoKey, signature: BufferSource, data: BufferSource): Promise<boolean>;
|
|
32
|
+
/**
|
|
33
|
+
* Encrypt data
|
|
34
|
+
*/
|
|
35
|
+
encrypt(algorithm: AlgorithmIdentifier, key: CryptoKey, data: BufferSource): Promise<ArrayBuffer>;
|
|
36
|
+
/**
|
|
37
|
+
* Decrypt data
|
|
38
|
+
*/
|
|
39
|
+
decrypt(algorithm: AlgorithmIdentifier, key: CryptoKey, data: BufferSource): Promise<ArrayBuffer>;
|
|
40
|
+
/**
|
|
41
|
+
* Generate a key
|
|
42
|
+
*/
|
|
43
|
+
generateKey(algorithm: AlgorithmIdentifier, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKey | CryptoKeyPair>;
|
|
44
|
+
/**
|
|
45
|
+
* Derive bits from a key
|
|
46
|
+
*/
|
|
47
|
+
deriveBits(algorithm: AlgorithmIdentifier, baseKey: CryptoKey, length: number): Promise<ArrayBuffer>;
|
|
48
|
+
/**
|
|
49
|
+
* Derive a key from another key
|
|
50
|
+
*/
|
|
51
|
+
deriveKey(algorithm: AlgorithmIdentifier, baseKey: CryptoKey, derivedKeyAlgorithm: AlgorithmIdentifier, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKey>;
|
|
52
|
+
/**
|
|
53
|
+
* Import a key
|
|
54
|
+
*/
|
|
55
|
+
importKey(format: KeyFormat, keyData: BufferSource | JsonWebKey, algorithm: AlgorithmIdentifier, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKey>;
|
|
56
|
+
/**
|
|
57
|
+
* Export a key
|
|
58
|
+
*/
|
|
59
|
+
exportKey(format: KeyFormat, key: CryptoKey): Promise<ArrayBuffer | JsonWebKey>;
|
|
60
|
+
/**
|
|
61
|
+
* Wrap a key
|
|
62
|
+
*/
|
|
63
|
+
wrapKey(format: KeyFormat, key: CryptoKey, wrappingKey: CryptoKey, wrapAlgorithm: AlgorithmIdentifier): Promise<ArrayBuffer>;
|
|
64
|
+
/**
|
|
65
|
+
* Unwrap a key
|
|
66
|
+
*/
|
|
67
|
+
unwrapKey(format: KeyFormat, wrappedKey: BufferSource, unwrappingKey: CryptoKey, unwrapAlgorithm: AlgorithmIdentifier, unwrappedKeyAlgorithm: AlgorithmIdentifier, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKey>;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=crypto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,qBAA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xC,WAAW,EAAE,OAAO,EACpB,SAAS,EAAE,QAAQ,EAAE,GACpB,OAAO,CAAC,SAAS,CAAC;IAUrB;;OAEG;IACG,SAAS,CACb,MAAM,EAAE,SAAS,EACjB,OAAO,EAAE,YAAY,GAAG,UAAU,EAClC,SAAS,EAAE,mBAAmB,EAC9B,WAAW,EAAE,OAAO,EACpB,SAAS,EAAE,QAAQ,EAAE,GACpB,OAAO,CAAC,SAAS,CAAC;IAUrB;;OAEG;IACG,SAAS,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,GAAG,OAAO,CAAC,WAAW,GAAG,UAAU,CAAC;IAUrF;;OAEG;IACG,OAAO,CACX,MAAM,EAAE,SAAS,EACjB,GAAG,EAAE,SAAS,EACd,WAAW,EAAE,SAAS,EACtB,aAAa,EAAE,mBAAmB,GACjC,OAAO,CAAC,WAAW,CAAC;IAUvB;;OAEG;IACG,SAAS,CACb,MAAM,EAAE,SAAS,EACjB,UAAU,EAAE,YAAY,EACxB,aAAa,EAAE,SAAS,EACxB,eAAe,EAAE,mBAAmB,EACpC,qBAAqB,EAAE,mBAAmB,EAC1C,WAAW,EAAE,OAAO,EACpB,SAAS,EAAE,QAAQ,EAAE,GACpB,OAAO,CAAC,SAAS,CAAC;CAiBtB"}
|
package/dist/crypto.js
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// src/crypto.ts
|
|
2
|
+
var Crypto = class {
|
|
3
|
+
/**
|
|
4
|
+
* Generate cryptographically strong random values
|
|
5
|
+
*/
|
|
6
|
+
getRandomValues(array) {
|
|
7
|
+
if (typeof crypto !== "undefined" && crypto.getRandomValues) {
|
|
8
|
+
return crypto.getRandomValues(array);
|
|
9
|
+
}
|
|
10
|
+
console.warn("Using fallback random number generation - not cryptographically secure");
|
|
11
|
+
const bytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
|
|
12
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
13
|
+
bytes[i] = Math.floor(Math.random() * 256);
|
|
14
|
+
}
|
|
15
|
+
return array;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Generate a random UUID
|
|
19
|
+
*/
|
|
20
|
+
randomUUID() {
|
|
21
|
+
if (typeof crypto !== "undefined" && crypto.randomUUID) {
|
|
22
|
+
return crypto.randomUUID();
|
|
23
|
+
}
|
|
24
|
+
const bytes = new Uint8Array(16);
|
|
25
|
+
this.getRandomValues(bytes);
|
|
26
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
27
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
28
|
+
const hex = Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
29
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* SubtleCrypto API for cryptographic operations
|
|
33
|
+
*/
|
|
34
|
+
get subtle() {
|
|
35
|
+
return new SubtleCrypto();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var SubtleCrypto = class {
|
|
39
|
+
/**
|
|
40
|
+
* Generate a digest (hash) of the data
|
|
41
|
+
*/
|
|
42
|
+
async digest(algorithm, data) {
|
|
43
|
+
const algName = typeof algorithm === "string" ? algorithm : algorithm.name;
|
|
44
|
+
if (typeof crypto !== "undefined" && crypto.subtle && crypto.subtle.digest) {
|
|
45
|
+
return crypto.subtle.digest(algorithm, data);
|
|
46
|
+
}
|
|
47
|
+
throw new Error(`Digest algorithm ${algName} not supported in this environment`);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Sign data with a key
|
|
51
|
+
*/
|
|
52
|
+
async sign(algorithm, key, data) {
|
|
53
|
+
if (typeof crypto !== "undefined" && crypto.subtle && crypto.subtle.sign) {
|
|
54
|
+
return crypto.subtle.sign(algorithm, key, data);
|
|
55
|
+
}
|
|
56
|
+
throw new Error("Sign operation not supported in this environment");
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Verify a signature
|
|
60
|
+
*/
|
|
61
|
+
async verify(algorithm, key, signature, data) {
|
|
62
|
+
if (typeof crypto !== "undefined" && crypto.subtle && crypto.subtle.verify) {
|
|
63
|
+
return crypto.subtle.verify(algorithm, key, signature, data);
|
|
64
|
+
}
|
|
65
|
+
throw new Error("Verify operation not supported in this environment");
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Encrypt data
|
|
69
|
+
*/
|
|
70
|
+
async encrypt(algorithm, key, data) {
|
|
71
|
+
if (typeof crypto !== "undefined" && crypto.subtle && crypto.subtle.encrypt) {
|
|
72
|
+
return crypto.subtle.encrypt(algorithm, key, data);
|
|
73
|
+
}
|
|
74
|
+
throw new Error("Encrypt operation not supported in this environment");
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Decrypt data
|
|
78
|
+
*/
|
|
79
|
+
async decrypt(algorithm, key, data) {
|
|
80
|
+
if (typeof crypto !== "undefined" && crypto.subtle && crypto.subtle.decrypt) {
|
|
81
|
+
return crypto.subtle.decrypt(algorithm, key, data);
|
|
82
|
+
}
|
|
83
|
+
throw new Error("Decrypt operation not supported in this environment");
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Generate a key
|
|
87
|
+
*/
|
|
88
|
+
async generateKey(algorithm, extractable, keyUsages) {
|
|
89
|
+
if (typeof crypto !== "undefined" && crypto.subtle && crypto.subtle.generateKey) {
|
|
90
|
+
return crypto.subtle.generateKey(algorithm, extractable, keyUsages);
|
|
91
|
+
}
|
|
92
|
+
throw new Error("GenerateKey operation not supported in this environment");
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Derive bits from a key
|
|
96
|
+
*/
|
|
97
|
+
async deriveBits(algorithm, baseKey, length) {
|
|
98
|
+
if (typeof crypto !== "undefined" && crypto.subtle && crypto.subtle.deriveBits) {
|
|
99
|
+
return crypto.subtle.deriveBits(algorithm, baseKey, length);
|
|
100
|
+
}
|
|
101
|
+
throw new Error("DeriveBits operation not supported in this environment");
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Derive a key from another key
|
|
105
|
+
*/
|
|
106
|
+
async deriveKey(algorithm, baseKey, derivedKeyAlgorithm, extractable, keyUsages) {
|
|
107
|
+
if (typeof crypto !== "undefined" && crypto.subtle && crypto.subtle.deriveKey) {
|
|
108
|
+
return crypto.subtle.deriveKey(algorithm, baseKey, derivedKeyAlgorithm, extractable, keyUsages);
|
|
109
|
+
}
|
|
110
|
+
throw new Error("DeriveKey operation not supported in this environment");
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Import a key
|
|
114
|
+
*/
|
|
115
|
+
async importKey(format, keyData, algorithm, extractable, keyUsages) {
|
|
116
|
+
if (typeof crypto !== "undefined" && crypto.subtle && crypto.subtle.importKey) {
|
|
117
|
+
return crypto.subtle.importKey(format, keyData, algorithm, extractable, keyUsages);
|
|
118
|
+
}
|
|
119
|
+
throw new Error("ImportKey operation not supported in this environment");
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Export a key
|
|
123
|
+
*/
|
|
124
|
+
async exportKey(format, key) {
|
|
125
|
+
if (typeof crypto !== "undefined" && crypto.subtle && crypto.subtle.exportKey) {
|
|
126
|
+
return crypto.subtle.exportKey(format, key);
|
|
127
|
+
}
|
|
128
|
+
throw new Error("ExportKey operation not supported in this environment");
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Wrap a key
|
|
132
|
+
*/
|
|
133
|
+
async wrapKey(format, key, wrappingKey, wrapAlgorithm) {
|
|
134
|
+
if (typeof crypto !== "undefined" && crypto.subtle && crypto.subtle.wrapKey) {
|
|
135
|
+
return crypto.subtle.wrapKey(format, key, wrappingKey, wrapAlgorithm);
|
|
136
|
+
}
|
|
137
|
+
throw new Error("WrapKey operation not supported in this environment");
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Unwrap a key
|
|
141
|
+
*/
|
|
142
|
+
async unwrapKey(format, wrappedKey, unwrappingKey, unwrapAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages) {
|
|
143
|
+
if (typeof crypto !== "undefined" && crypto.subtle && crypto.subtle.unwrapKey) {
|
|
144
|
+
return crypto.subtle.unwrapKey(
|
|
145
|
+
format,
|
|
146
|
+
wrappedKey,
|
|
147
|
+
unwrappingKey,
|
|
148
|
+
unwrapAlgorithm,
|
|
149
|
+
unwrappedKeyAlgorithm,
|
|
150
|
+
extractable,
|
|
151
|
+
keyUsages
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
throw new Error("UnwrapKey operation not supported in this environment");
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
export {
|
|
158
|
+
Crypto,
|
|
159
|
+
SubtleCrypto
|
|
160
|
+
};
|
|
161
|
+
//# sourceMappingURL=crypto.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/crypto.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Crypto polyfill for Akamai EdgeWorkers to match Cloudflare Workers Web Crypto API\n * Provides a subset of the Web Crypto API using Akamai's crypto module\n */\n\nexport class Crypto {\n /**\n * Generate cryptographically strong random values\n */\n getRandomValues<T extends ArrayBufferView>(array: T): T {\n // In Akamai EdgeWorkers, we can use the crypto module\n // @ts-ignore - crypto is available in Akamai runtime\n if (typeof crypto !== 'undefined' && crypto.getRandomValues) {\n return crypto.getRandomValues(array);\n }\n\n // Fallback implementation (not cryptographically secure, for development only)\n console.warn('Using fallback random number generation - not cryptographically secure');\n const bytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);\n for (let i = 0; i < bytes.length; i++) {\n bytes[i] = Math.floor(Math.random() * 256);\n }\n return array;\n }\n\n /**\n * Generate a random UUID\n */\n randomUUID(): string {\n // @ts-ignore - crypto is available in Akamai runtime\n if (typeof crypto !== 'undefined' && crypto.randomUUID) {\n return crypto.randomUUID();\n }\n\n // Fallback UUID v4 generation\n const bytes = new Uint8Array(16);\n this.getRandomValues(bytes);\n\n // Set version (4) and variant bits\n bytes[6] = (bytes[6] & 0x0f) | 0x40;\n bytes[8] = (bytes[8] & 0x3f) | 0x80;\n\n const hex = Array.from(bytes)\n .map(b => b.toString(16).padStart(2, '0'))\n .join('');\n\n return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;\n }\n\n /**\n * SubtleCrypto API for cryptographic operations\n */\n get subtle(): SubtleCrypto {\n return new SubtleCrypto();\n }\n}\n\nexport class SubtleCrypto {\n /**\n * Generate a digest (hash) of the data\n */\n async digest(algorithm: AlgorithmIdentifier, data: BufferSource): Promise<ArrayBuffer> {\n const algName = typeof algorithm === 'string' ? algorithm : algorithm.name;\n\n // @ts-ignore - crypto is available in Akamai runtime\n if (typeof crypto !== 'undefined' && crypto.subtle && crypto.subtle.digest) {\n // @ts-ignore - type compatibility with native crypto\n return crypto.subtle.digest(algorithm, data);\n }\n\n // For Akamai EdgeWorkers without native crypto.subtle\n // You would need to use the crypto module's createHash or similar\n throw new Error(`Digest algorithm ${algName} not supported in this environment`);\n }\n\n /**\n * Sign data with a key\n */\n async sign(\n algorithm: AlgorithmIdentifier,\n key: CryptoKey,\n data: BufferSource\n ): Promise<ArrayBuffer> {\n // @ts-ignore\n if (typeof crypto !== 'undefined' && crypto.subtle && crypto.subtle.sign) {\n // @ts-ignore - type compatibility with native crypto\n return crypto.subtle.sign(algorithm, key, data);\n }\n\n throw new Error('Sign operation not supported in this environment');\n }\n\n /**\n * Verify a signature\n */\n async verify(\n algorithm: AlgorithmIdentifier,\n key: CryptoKey,\n signature: BufferSource,\n data: BufferSource\n ): Promise<boolean> {\n // @ts-ignore\n if (typeof crypto !== 'undefined' && crypto.subtle && crypto.subtle.verify) {\n // @ts-ignore - type compatibility with native crypto\n return crypto.subtle.verify(algorithm, key, signature, data);\n }\n\n throw new Error('Verify operation not supported in this environment');\n }\n\n /**\n * Encrypt data\n */\n async encrypt(\n algorithm: AlgorithmIdentifier,\n key: CryptoKey,\n data: BufferSource\n ): Promise<ArrayBuffer> {\n // @ts-ignore\n if (typeof crypto !== 'undefined' && crypto.subtle && crypto.subtle.encrypt) {\n // @ts-ignore - type compatibility with native crypto\n return crypto.subtle.encrypt(algorithm, key, data);\n }\n\n throw new Error('Encrypt operation not supported in this environment');\n }\n\n /**\n * Decrypt data\n */\n async decrypt(\n algorithm: AlgorithmIdentifier,\n key: CryptoKey,\n data: BufferSource\n ): Promise<ArrayBuffer> {\n // @ts-ignore\n if (typeof crypto !== 'undefined' && crypto.subtle && crypto.subtle.decrypt) {\n // @ts-ignore - type compatibility with native crypto\n return crypto.subtle.decrypt(algorithm, key, data);\n }\n\n throw new Error('Decrypt operation not supported in this environment');\n }\n\n /**\n * Generate a key\n */\n async generateKey(\n algorithm: AlgorithmIdentifier,\n extractable: boolean,\n keyUsages: KeyUsage[]\n ): Promise<CryptoKey | CryptoKeyPair> {\n // @ts-ignore\n if (typeof crypto !== 'undefined' && crypto.subtle && crypto.subtle.generateKey) {\n // @ts-ignore - type compatibility with native crypto\n return crypto.subtle.generateKey(algorithm, extractable, keyUsages);\n }\n\n throw new Error('GenerateKey operation not supported in this environment');\n }\n\n /**\n * Derive bits from a key\n */\n async deriveBits(\n algorithm: AlgorithmIdentifier,\n baseKey: CryptoKey,\n length: number\n ): Promise<ArrayBuffer> {\n // @ts-ignore\n if (typeof crypto !== 'undefined' && crypto.subtle && crypto.subtle.deriveBits) {\n // @ts-ignore - type compatibility with native crypto\n return crypto.subtle.deriveBits(algorithm, baseKey, length);\n }\n\n throw new Error('DeriveBits operation not supported in this environment');\n }\n\n /**\n * Derive a key from another key\n */\n async deriveKey(\n algorithm: AlgorithmIdentifier,\n baseKey: CryptoKey,\n derivedKeyAlgorithm: AlgorithmIdentifier,\n extractable: boolean,\n keyUsages: KeyUsage[]\n ): Promise<CryptoKey> {\n // @ts-ignore\n if (typeof crypto !== 'undefined' && crypto.subtle && crypto.subtle.deriveKey) {\n // @ts-ignore - type compatibility with native crypto\n return crypto.subtle.deriveKey(algorithm, baseKey, derivedKeyAlgorithm, extractable, keyUsages);\n }\n\n throw new Error('DeriveKey operation not supported in this environment');\n }\n\n /**\n * Import a key\n */\n async importKey(\n format: KeyFormat,\n keyData: BufferSource | JsonWebKey,\n algorithm: AlgorithmIdentifier,\n extractable: boolean,\n keyUsages: KeyUsage[]\n ): Promise<CryptoKey> {\n // @ts-ignore\n if (typeof crypto !== 'undefined' && crypto.subtle && crypto.subtle.importKey) {\n // @ts-ignore - type compatibility with native crypto\n return crypto.subtle.importKey(format, keyData, algorithm, extractable, keyUsages);\n }\n\n throw new Error('ImportKey operation not supported in this environment');\n }\n\n /**\n * Export a key\n */\n async exportKey(format: KeyFormat, key: CryptoKey): Promise<ArrayBuffer | JsonWebKey> {\n // @ts-ignore\n if (typeof crypto !== 'undefined' && crypto.subtle && crypto.subtle.exportKey) {\n // @ts-ignore - type compatibility with native crypto\n return crypto.subtle.exportKey(format, key);\n }\n\n throw new Error('ExportKey operation not supported in this environment');\n }\n\n /**\n * Wrap a key\n */\n async wrapKey(\n format: KeyFormat,\n key: CryptoKey,\n wrappingKey: CryptoKey,\n wrapAlgorithm: AlgorithmIdentifier\n ): Promise<ArrayBuffer> {\n // @ts-ignore\n if (typeof crypto !== 'undefined' && crypto.subtle && crypto.subtle.wrapKey) {\n // @ts-ignore - type compatibility with native crypto\n return crypto.subtle.wrapKey(format, key, wrappingKey, wrapAlgorithm);\n }\n\n throw new Error('WrapKey operation not supported in this environment');\n }\n\n /**\n * Unwrap a key\n */\n async unwrapKey(\n format: KeyFormat,\n wrappedKey: BufferSource,\n unwrappingKey: CryptoKey,\n unwrapAlgorithm: AlgorithmIdentifier,\n unwrappedKeyAlgorithm: AlgorithmIdentifier,\n extractable: boolean,\n keyUsages: KeyUsage[]\n ): Promise<CryptoKey> {\n // @ts-ignore\n if (typeof crypto !== 'undefined' && crypto.subtle && crypto.subtle.unwrapKey) {\n // @ts-ignore - type compatibility with native crypto\n return crypto.subtle.unwrapKey(\n format,\n wrappedKey,\n unwrappingKey,\n unwrapAlgorithm,\n unwrappedKeyAlgorithm,\n extractable,\n keyUsages\n );\n }\n\n throw new Error('UnwrapKey operation not supported in this environment');\n }\n}\n\n// Type definitions are provided by lib.dom.d.ts\n// We don't need to redefine them here since tsconfig includes \"DOM\" lib\n"],
|
|
5
|
+
"mappings": ";AAKO,IAAM,SAAN,MAAa;AAAA;AAAA;AAAA;AAAA,EAIlB,gBAA2C,OAAa;AAGtD,QAAI,OAAO,WAAW,eAAe,OAAO,iBAAiB;AAC3D,aAAO,OAAO,gBAAgB,KAAK;AAAA,IACrC;AAGA,YAAQ,KAAK,wEAAwE;AACrF,UAAM,QAAQ,IAAI,WAAW,MAAM,QAAQ,MAAM,YAAY,MAAM,UAAU;AAC7E,aAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACrC,YAAM,CAAC,IAAI,KAAK,MAAM,KAAK,OAAO,IAAI,GAAG;AAAA,IAC3C;AACA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,aAAqB;AAEnB,QAAI,OAAO,WAAW,eAAe,OAAO,YAAY;AACtD,aAAO,OAAO,WAAW;AAAA,IAC3B;AAGA,UAAM,QAAQ,IAAI,WAAW,EAAE;AAC/B,SAAK,gBAAgB,KAAK;AAG1B,UAAM,CAAC,IAAK,MAAM,CAAC,IAAI,KAAQ;AAC/B,UAAM,CAAC,IAAK,MAAM,CAAC,IAAI,KAAQ;AAE/B,UAAM,MAAM,MAAM,KAAK,KAAK,EACzB,IAAI,OAAK,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EACxC,KAAK,EAAE;AAEV,WAAO,GAAG,IAAI,MAAM,GAAG,CAAC,CAAC,IAAI,IAAI,MAAM,GAAG,EAAE,CAAC,IAAI,IAAI,MAAM,IAA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,WAAW;AAE7E,aAAO,OAAO,OAAO,UAAU,QAAQ,GAAG;AAAA,IAC5C;AAEA,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QACJ,QACA,KACA,aACA,eACsB;AAEtB,QAAI,OAAO,WAAW,eAAe,OAAO,UAAU,OAAO,OAAO,SAAS;AAE3E,aAAO,OAAO,OAAO,QAAQ,QAAQ,KAAK,aAAa,aAAa;AAAA,IACtE;AAEA,UAAM,IAAI,MAAM,qDAAqD;AAAA,EACvE;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,UACJ,QACA,YACA,eACA,iBACA,uBACA,aACA,WACoB;AAEpB,QAAI,OAAO,WAAW,eAAe,OAAO,UAAU,OAAO,OAAO,WAAW;AAE7E,aAAO,OAAO,OAAO;AAAA,QACnB;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/global.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global entry point - exposes all polyfills as global variables
|
|
3
|
+
* This file is used for the IIFE build that automatically installs polyfills
|
|
4
|
+
*/
|
|
5
|
+
import { Request, Headers } from './request';
|
|
6
|
+
import { Response } from './response';
|
|
7
|
+
import { KVNamespace } from './kv-namespace';
|
|
8
|
+
import { Crypto, SubtleCrypto } from './crypto';
|
|
9
|
+
import { installGlobalPolyfills, toEdgeWorkerResponse } from './index';
|
|
10
|
+
export { Request, Response, Headers, KVNamespace, Crypto, SubtleCrypto, installGlobalPolyfills, toEdgeWorkerResponse, };
|
|
11
|
+
declare const _default: {
|
|
12
|
+
Request: typeof Request;
|
|
13
|
+
Response: typeof Response;
|
|
14
|
+
Headers: typeof Headers;
|
|
15
|
+
KVNamespace: typeof KVNamespace;
|
|
16
|
+
Crypto: typeof Crypto;
|
|
17
|
+
SubtleCrypto: typeof SubtleCrypto;
|
|
18
|
+
installGlobalPolyfills: typeof installGlobalPolyfills;
|
|
19
|
+
toEdgeWorkerResponse: typeof toEdgeWorkerResponse;
|
|
20
|
+
};
|
|
21
|
+
export default _default;
|
|
22
|
+
//# sourceMappingURL=global.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global.d.ts","sourceRoot":"","sources":["../src/global.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAGvE,OAAO,EACL,OAAO,EACP,QAAQ,EACR,OAAO,EACP,WAAW,EACX,MAAM,EACN,YAAY,EACZ,sBAAsB,EACtB,oBAAoB,GACrB,CAAC;;;;;;;;;;;AAGF,wBASE"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Akamai EdgeWorkers to Cloudflare Workers API Polyfill
|
|
3
|
+
*
|
|
4
|
+
* This polyfill makes Akamai EdgeWorkers compatible with Cloudflare Workers API,
|
|
5
|
+
* enabling the use of Optimizely Edge Delivery SDK and other Cloudflare-compatible
|
|
6
|
+
* libraries on Akamai's edge platform.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { Request, Response, KVNamespace, Crypto } from 'akamai-edge-delivery-polyfill';
|
|
11
|
+
*
|
|
12
|
+
* // Use in your EdgeWorker
|
|
13
|
+
* export async function onClientRequest(request) {
|
|
14
|
+
* const cfRequest = new Request(request);
|
|
15
|
+
* const response = new Response('Hello World', { status: 200 });
|
|
16
|
+
* return response;
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
import { Request, Headers } from './request';
|
|
21
|
+
import { Response } from './response';
|
|
22
|
+
import { KVNamespace } from './kv-namespace';
|
|
23
|
+
import { Crypto, SubtleCrypto } from './crypto';
|
|
24
|
+
export { Request, Headers } from './request';
|
|
25
|
+
export { Response } from './response';
|
|
26
|
+
export { KVNamespace } from './kv-namespace';
|
|
27
|
+
export { Crypto, SubtleCrypto } from './crypto';
|
|
28
|
+
/**
|
|
29
|
+
* Helper function to convert Akamai EdgeWorker Response to a format
|
|
30
|
+
* that can be returned from EdgeWorker event handlers
|
|
31
|
+
*/
|
|
32
|
+
export declare function toEdgeWorkerResponse(response: any): Promise<any>;
|
|
33
|
+
/**
|
|
34
|
+
* Create a global polyfill that injects Cloudflare-compatible APIs into the global scope
|
|
35
|
+
* This is useful when using libraries that expect these APIs to be globally available
|
|
36
|
+
*/
|
|
37
|
+
export declare function installGlobalPolyfills(): void;
|
|
38
|
+
declare const _default: {
|
|
39
|
+
Request: typeof Request;
|
|
40
|
+
Response: typeof Response;
|
|
41
|
+
Headers: typeof Headers;
|
|
42
|
+
KVNamespace: typeof KVNamespace;
|
|
43
|
+
Crypto: typeof Crypto;
|
|
44
|
+
SubtleCrypto: typeof SubtleCrypto;
|
|
45
|
+
toEdgeWorkerResponse: typeof toEdgeWorkerResponse;
|
|
46
|
+
installGlobalPolyfills: typeof installGlobalPolyfills;
|
|
47
|
+
};
|
|
48
|
+
export default _default;
|
|
49
|
+
//# sourceMappingURL=index.d.ts.map
|