This example demonstrates all factory functions from the Optimizely SDK, including static and polling datafile managers.
src/index.ts- Main example demonstrating all SDK factory functionsdatafile.json- Test datafile with Optimizely configurationdatafile-server.js- Simple HTTP server for testing polling datafile manager
Run from the project root to automatically build the SDK, create a tarball, and run the example:
npm run test-typescriptThis will:
- Install SDK dependencies
- Pack the SDK as a tarball (triggers build via
preparescript) - Install the tarball in this example
- Build and run the TypeScript example
- Start the datafile server automatically
- Clean up after completion
In a separate terminal, run:
node datafile-server.jsThis starts an HTTP server at http://localhost:8910 that serves the datafile.json file. The polling project config manager will fetch updates from this server every 10 seconds.
npm start- createStaticProjectConfigManager - Creates a config manager with a static datafile
- createInstance - Creates an Optimizely client instance with the static config manager
- createPollingProjectConfigManager - Creates a config manager that polls for datafile updates from localhost:8910
- getSendBeaconEventDispatcher - Gets the SendBeacon event dispatcher (Node.js returns undefined)
- eventDispatcher - Default event dispatcher
- createForwardingEventProcessor - Creates an event processor that forwards events immediately
- createBatchEventProcessor - Creates an event processor that batches events
- createOdpManager - Creates an Optimizely Data Platform manager
- createVuidManager - Creates a Visitor Unique ID manager
The datafile.json contains a complete Optimizely configuration with:
- 2 feature flags (
flag_1,flag_2) - 4 experiments (
exp_1,exp_2,exp_3,exp_4) - 7 typed audiences based on age conditions
- 2 rollouts with delivery rules
- 1 integer variable (
integer_variable)
This datafile is used for testing SDK functionality with realistic configuration.