npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

akamai-edge-delivery-polyfill

v1.0.8

Published

Polyfill to make Akamai EdgeWorkers compatible with Cloudflare Workers API for Optimizely Edge Delivery SDK

Downloads

62

Readme

Akamai Edge Delivery Polyfill

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.

Features

  • Request/Response API: Full Fetch API compatibility for handling HTTP requests and responses
  • Headers API: Complete Headers implementation matching Web standards
  • KVNamespace: Maps Cloudflare KV operations to Akamai EdgeKV
  • Crypto API: Web Crypto API polyfill for cryptographic operations
  • TextEncoder/TextDecoder: Text encoding/decoding utilities
  • ReadableStream: Basic stream implementation for body handling

Installation

npm install akamai-edge-delivery-polyfill

Building

Build the Package

# Install dependencies
npm install

# Build all bundles
npm run build

This creates:

  • dist/index.js - ESM bundle for module imports
  • dist/polyfill.global.js - Global IIFE bundle that auto-installs polyfills
  • dist/request.js, dist/response.js, etc. - Individual module bundles
  • TypeScript declarations in dist/*.d.ts

Build Output

dist/
├── index.js              # ESM bundle (main)
├── polyfill.global.js    # Global bundle (auto-installs APIs)
├── request.js            # Individual modules
├── response.js
├── kv-namespace.js
├── crypto.js
└── *.d.ts                # TypeScript declarations

Usage

Option 1: Global Bundle (Easiest - Recommended)

The global bundle automatically installs all polyfills when loaded, making them available globally.

// Import the global bundle first (auto-installs all APIs)
import './node_modules/akamai-edge-delivery-polyfill/dist/polyfill.global.js';

// Now Request, Response, Headers, crypto, etc. are global
export async function onClientRequest(request) {
  const cfRequest = new Request(request);

  const response = Response.json({
    message: 'Hello from Akamai!',
    url: cfRequest.url
  });

  return {
    status: response.status,
    headers: Object.fromEntries(response.headers.entries()),
    body: await response.text()
  };
}

Option 2: ES Modules

Use the ESM bundle for module imports:

import { Request, Response, installGlobalPolyfills } from 'akamai-edge-delivery-polyfill';

// Use classes directly
export async function onClientRequest(request) {
  const cfRequest = new Request(request);

  const response = new Response(JSON.stringify({ message: 'Hello from Akamai!' }), {
    status: 200,
    headers: {
      'Content-Type': 'application/json'
    }
  });

  return {
    status: response.status,
    headers: Object.fromEntries(response.headers.entries()),
    body: await response.text()
  };
}

// Option 2: Install global polyfills (useful for libraries expecting global APIs)
installGlobalPolyfills();

Using with Optimizely Edge Delivery SDK

import { installGlobalPolyfills, KVNamespace } from 'akamai-edge-delivery-polyfill';
import { createInstance } from '@optimizely/edge-delivery-sdk';

// Install global polyfills for Optimizely SDK compatibility
installGlobalPolyfills();

// Create KV namespace for Optimizely data
const optimizelyKV = new KVNamespace('optimizely', 'config');

// Initialize Optimizely
const optimizely = createInstance({
  sdkKey: 'your-sdk-key',
  // ... other config
});

export async function onClientRequest(request) {
  const cfRequest = new Request(request);

  // Use Optimizely for decision making
  const user = {
    id: cfRequest.headers.get('user-id') || 'anonymous',
  };

  const decision = optimizely.decide(user, 'feature-flag-key');

  // Return personalized response
  const response = new Response(JSON.stringify({
    enabled: decision.enabled,
    variables: decision.variables,
  }), {
    status: 200,
    headers: { 'Content-Type': 'application/json' }
  });

  return {
    status: response.status,
    headers: Object.fromEntries(response.headers.entries()),
    body: await response.text()
  };
}

KVNamespace (EdgeKV Integration)

import { KVNamespace } from 'akamai-edge-delivery-polyfill';

// Create a KV namespace (maps to Akamai EdgeKV)
const myKV = new KVNamespace('my-namespace', 'production');

// Get a value
const value = await myKV.get('key');
const jsonValue = await myKV.get('key', 'json');

// Put a value
await myKV.put('key', 'value');
await myKV.put('key', JSON.stringify({ data: 'value' }));

// Delete a value
await myKV.delete('key');

Crypto API

import { Crypto } from 'akamai-edge-delivery-polyfill';

const crypto = new Crypto();

// Generate random UUID
const uuid = crypto.randomUUID();

// Generate random values
const array = new Uint8Array(16);
crypto.getRandomValues(array);

// Use SubtleCrypto for hashing (if supported by runtime)
const data = new TextEncoder().encode('Hello World');
const hash = await crypto.subtle.digest('SHA-256', data);

Helper Functions

import { toEdgeWorkerResponse } from 'akamai-edge-delivery-polyfill';

// Convert Cloudflare-style Response to Akamai EdgeWorker format
const cfResponse = new Response('Hello', { status: 200 });
const ewResponse = await toEdgeWorkerResponse(cfResponse);

// Returns: { status: 200, headers: {...}, body: 'Hello' }

API Reference

Request

Wraps Akamai EdgeWorker requests to provide Cloudflare-compatible Request interface.

Constructor:

new Request(input: string | Request | AkamaiRequest, init?: RequestInit)

Properties:

  • url: string - The request URL
  • method: string - HTTP method
  • headers: Headers - Request headers
  • bodyUsed: boolean - Whether body has been consumed

Methods:

  • text(): Promise<string> - Read body as text
  • json(): Promise<any> - Read body as JSON
  • arrayBuffer(): Promise<ArrayBuffer> - Read body as ArrayBuffer
  • clone(): Request - Clone the request

Response

Creates Cloudflare-compatible Response objects.

Constructor:

new Response(body?: BodyInit | null, init?: ResponseInit)

Properties:

  • status: number - HTTP status code
  • statusText: string - HTTP status text
  • ok: boolean - True if status is 2xx
  • headers: Headers - Response headers
  • body: ReadableStream | null - Response body stream
  • bodyUsed: boolean - Whether body has been consumed

Methods:

  • text(): Promise<string> - Read body as text
  • json(): Promise<any> - Read body as JSON
  • arrayBuffer(): Promise<ArrayBuffer> - Read body as ArrayBuffer
  • clone(): Response - Clone the response

Static Methods:

  • Response.json(data: any, init?: ResponseInit): Response - Create JSON response
  • Response.redirect(url: string, status?: number): Response - Create redirect response

KVNamespace

Maps Cloudflare KV operations to Akamai EdgeKV.

Constructor:

new KVNamespace(namespace: string, group?: string)

Methods:

  • get(key: string, type?: 'text' | 'json' | 'arrayBuffer' | 'stream'): Promise<any> - Get value
  • getWithMetadata<T>(key: string, type?): Promise<{ value: any, metadata: T }> - Get with metadata
  • put(key: string, value: string | ArrayBuffer | ReadableStream): Promise<void> - Put value
  • delete(key: string): Promise<void> - Delete value
  • list(options?: KVListOptions): Promise<KVListResult> - List keys (limited support)

Crypto

Web Crypto API polyfill.

Methods:

  • getRandomValues<T extends ArrayBufferView>(array: T): T - Fill array with random values
  • randomUUID(): string - Generate random UUID
  • subtle: SubtleCrypto - Access SubtleCrypto API

Important Notes

EdgeKV Setup

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:

const { EdgeKV } = require('./edgekv.js');

Limitations

  1. KVNamespace.list(): EdgeKV doesn't natively support listing keys, so this method has limited functionality
  2. ReadableStream: Basic implementation provided; may not support all stream features
  3. Crypto.subtle: Some operations may not be available depending on Akamai runtime capabilities

TypeScript Support

The polyfill includes full TypeScript definitions. No additional @types packages needed.

Examples

See the examples/ directory for complete working examples:

  • basic-usage.ts - Basic request/response handling
  • optimizely-integration.ts - Using with Optimizely Edge Delivery SDK
  • kv-storage.ts - EdgeKV integration examples

License

MIT

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

Support

For issues specific to this polyfill, please open a GitHub issue.

For Akamai EdgeWorkers support, see Akamai EdgeWorkers documentation

For Optimizely Edge Delivery SDK support, see Optimizely documentation