Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
e65d4ee
chore: update Optimizely SDK version to ^6.1.0
mikechu-optimizely Sep 18, 2025
7a640e0
chore: update project version to 2.0.0 and change license to Apache-2.0
mikechu-optimizely Sep 18, 2025
dc97646
chore: update prettier version to ^3.6.2 in devDependencies
mikechu-optimizely Sep 18, 2025
5b8221a
refactor: ran prettier
mikechu-optimizely Sep 18, 2025
3abde31
fix: update Optimizely SDK import to use universal bundle
mikechu-optimizely Sep 18, 2025
fdeb882
docs: update copyright year and formatting in license header
mikechu-optimizely Sep 18, 2025
5a8bb69
feat: migrate configuration from wrangler.toml to wrangler.jsonc
mikechu-optimizely Sep 18, 2025
8a77cd5
fix: remove uuid dependency and use crypto.randomUUID for user ID gen…
mikechu-optimizely Sep 18, 2025
f68b3da
chore: update cookie dependency version to ^1.0.2 in package.json and…
mikechu-optimizely Sep 18, 2025
0c3e84c
build: remove custom build leverage default esbuild
mikechu-optimizely Sep 18, 2025
e8ec1e5
fix: update SDK import path and convert to ES module format
mikechu-optimizely Sep 18, 2025
d135972
refactor: lint fix
mikechu-optimizely Sep 18, 2025
94f723f
doc: update copyright
mikechu-optimizely Sep 18, 2025
7bb9fd2
refactor: replace console.log with console.info for decision logging
mikechu-optimizely Sep 18, 2025
e27abd1
fix: add missing "type" field in package.json for module support
mikechu-optimizely Sep 18, 2025
0757085
refactor: rearrange package.json
mikechu-optimizely Sep 18, 2025
7535c62
test: add vitest + miniflare
mikechu-optimizely Sep 18, 2025
5df56fc
feat: add biomejs + update format & add lint scripts
mikechu-optimizely Sep 18, 2025
feb7e74
refactor: run biome format
mikechu-optimizely Sep 18, 2025
b9e67cc
refactor: run biome lint
mikechu-optimizely Sep 18, 2025
2f98dbe
chore: clean up .gitignore by removing unused entries and organizing …
mikechu-optimizely Sep 18, 2025
04a1a77
chore: remove webpack configuration file
mikechu-optimizely Sep 18, 2025
c297210
feat: add build script to --dry-run a deployment
mikechu-optimizely Sep 18, 2025
47d6c8e
feat: implement caching for Optimizely client and refactor datafile f…
mikechu-optimizely Sep 18, 2025
6fe5fe3
feat: update getOptimizelyClient to use SDK key from environment vari…
mikechu-optimizely Sep 18, 2025
b48348c
chore: remove .editorconfig file
mikechu-optimizely Sep 18, 2025
9fe30af
docs: update README to reflect repo modernization
mikechu-optimizely Sep 18, 2025
0c94a88
test(wip): initial test suite
mikechu-optimizely Sep 18, 2025
1e5f83d
refactor: lint/format
mikechu-optimizely Sep 18, 2025
c92bc48
chore: set the correct next major semver
mikechu-optimizely Sep 19, 2025
2b21d23
test: remove unnecessary crypto mock and clean up test setup
mikechu-optimizely Sep 19, 2025
ab2214a
refactor: lint & format
mikechu-optimizely Sep 19, 2025
24bf516
Update README.md
mikechu-optimizely Sep 19, 2025
b8a4114
Update .biome.jsonc
mikechu-optimizely Sep 19, 2025
e9d6b7c
fix: add missing parameter to getOptimizelyClient function
mikechu-optimizely Sep 19, 2025
039df35
Merge branch 'mike/fssdk-11466-upgrade-fx-js-version' of github.com:o…
mikechu-optimizely Sep 19, 2025
0a7cb12
feat: add CloudflareRequestHandler class for handling fetch requests
mikechu-optimizely Sep 22, 2025
367a111
fix: datafile fetching and v6 client initialization logic
mikechu-optimizely Sep 22, 2025
11d3551
test: add unit tests for CloudflareRequestHandler class
mikechu-optimizely Sep 22, 2025
1ae4ce5
fix: update getDatafile call and improve request handler tests
mikechu-optimizely Sep 22, 2025
a0325ce
feat: enhance CloudflareRequestHandler to utilize execution context f…
mikechu-optimizely Sep 22, 2025
8aa1725
fix: update requestHandler initialization and context handling in get…
mikechu-optimizely Sep 22, 2025
39ddda2
Update src/optimizely_helper.js
mikechu-optimizely Sep 22, 2025
2bedafd
Update src/optimizely_helper.js
mikechu-optimizely Sep 22, 2025
8cd2dae
Update test/setup.js
mikechu-optimizely Sep 22, 2025
19ddb5e
fix: format & lint
mikechu-optimizely Sep 22, 2025
9b84fb4
feat: update precommit script to include test execution
mikechu-optimizely Sep 25, 2025
b78fc9f
fix: improve event handling and reduce datafile cache TTL
mikechu-optimizely Sep 25, 2025
0397984
refactor: simplify request handling and improve response parsing
mikechu-optimizely Sep 25, 2025
5769b5f
refactor: enhance datafile caching logic and error handling
mikechu-optimizely Oct 1, 2025
241f2c0
fix: improve error handling for datafile fetching and caching
mikechu-optimizely Oct 1, 2025
f41f36f
fix: biome.jsonc name + updated configuration version
mikechu-optimizely Oct 1, 2025
44c7da0
fix: add dist/ directory to .gitignore for better packaging management
mikechu-optimizely Oct 1, 2025
afda97f
fix: simplify format and lint scripts in package.json
mikechu-optimizely Oct 1, 2025
6739a8b
refactor: update formatting & lints
mikechu-optimizely Oct 1, 2025
f312f51
fix: improve datafile cache TTL handling and fallback logic
mikechu-optimizely Oct 1, 2025
1042eb7
doc: enhance internal documentation for Cloudflare Worker and Optimiz…
mikechu-optimizely Oct 1, 2025
97d8599
doc: update README to include ttl & important file info
mikechu-optimizely Oct 1, 2025
7587ed3
fix: set datafile cache TTL to default value of 300 seconds
mikechu-optimizely Oct 9, 2025
f2e3189
fix: enhance error handling for Optimizely client and user context in…
mikechu-optimizely Oct 9, 2025
e0916cc
fix: update constructor and method parameters for clarity and consist…
mikechu-optimizely Oct 9, 2025
06993cb
doc: updated changelog for version
mikechu-optimizely Oct 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Optimizely SDK Configuration
# Get your SDK key from the Optimizely dashboard: Settings > Environments
OPTIMIZELY_SDK_KEY=your_optimizely_sdk_key

# Optional: Set datafile cache TTL in seconds (default is 300 seconds / 5 minutes)
# Example values: "300" (5 minutes), "600" (10 minutes), etc
OPTIMIZELY_DATAFILE_CACHE_TTL_SECONDS="300"

# Optional: Set log level for development (Error, Warn, Info, Debug)
# LOG_LEVEL=Error
105 changes: 25 additions & 80 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,96 +11,41 @@ report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
## Node / dependency folders
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity
## Build / test output
dist/
coverage/
.nyc_output/
*.lcov

# dotenv environment variables file
## Environment files
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache
## Cloudflare Wrangler
.wrangler/

# Next.js build output
.next
## Logs
logs
*.log

# Nuxt.js build / generate output
.nuxt
dist
## Editor / OS files
.DS_Store
.vscode/
thumbs.db

# Gatsby files
## Tool caches
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/
.rpt2_cache/

# DynamoDB Local files
.dynamodb/
## npm
.npm
.npmrc

# TernJS port file
.tern-port
## Misc
.node_repl_history

worker
## Distribution / packaging
dist/
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["biomejs.biome"]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"cSpell.words": ["miniflare"]
}
53 changes: 49 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,63 @@
# Change Log

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [1.0.0] - October 10, 2025

### Changed

- Updated `@optimizely/optimizely-sdk` to version `6.1.0` with ES modules support.
- Migrated from addEventListener pattern to modern Cloudflare Workers fetch handler export syntax.
- Replaced `uuid` package with native `crypto.randomUUID()` for user ID generation.
- Replaced Webpack build with native ES modules.
- Migrated configuration from `wrangler.toml` to `wrangler.jsonc`.
- Refactored request handler to return standardized response format: `{statusCode: number, body: string, headers: Object}`.
- Implemented graceful degradation: worker continues to function even if Optimizely initialization fails.
- Enhanced error handling with try-catch blocks around all Optimizely operations - errors are logged but don't break the worker.
- Added comprehensive JSDoc documentation throughout the codebase.
- Improved datafile caching with module-scope cache and configurable TTL via `OPTIMIZELY_DATAFILE_CACHE_TTL_SECONDS` environment variable (default: 300 seconds).
- Updated `cookie` package from `0.4.2` to `1.0.2`.
- Migrated from Prettier to Biome for code formatting and linting.

### Added

- New `CloudflareRequestHandler` class implementing custom request handler for Cloudflare Workers environment.
- New `getOptimizelyClient` helper function for centralized client management with smart caching.
- New `getDatafile` helper function for fetching datafiles from Optimizely CDN.
- Comprehensive unit test suite using Vitest and vitest-environment-miniflare.
- Test files: `index.test.js`, `optimizely_helper.test.js`, `request_handler.test.js`.
- Test utilities and setup files for easier testing.
- `biome.jsonc` configuration for code quality tools.
- `vitest.config.js` for test configuration.

### Removed

- Removed `uuid` package dependency (replaced with native Web Crypto API).
- Removed Webpack build configuration (`webpack.config.js`).
- Removed old `wrangler.toml` (replaced with `wrangler.jsonc`).
- Removed Prettier in favor of Biome.

### Fixed

- Response body is now always returned as a string for consistent interface with Optimizely SDK expectations.
- Worker no longer returns 500 errors on Optimizely failures; continues with degraded functionality.
- Improved AbortError handling in request handler with proper error wrapping.

## [0.2.0] - April 4, 2022

### Added

- Added cookie based user id memorization to support sticky [bucketing](https://docs.developers.optimizely.com/full-stack/v4.0/docs/how-bucketing-works).

### Changed

- Updated `@optimizely/optimizely-sdk` version to `4.9.1`.

## [0.1.0] - November 18, 2021

### Added

- First version of Cloudflare worker template with datafile caching and event dispatcher.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ The YEAR above should be the year of the contribution. If work on the file has b

## Contact

If you have questions, please contact [email protected].
If you have questions, please contact [email protected].
Loading