Skip to content

Commit 91b24c5

Browse files
authored
feat: client-side local evaluation and core evaluation package (#81)
1 parent 1fc5e55 commit 91b24c5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+9741
-2046
lines changed

examples/react-app/amplitude-integration/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6-
"@amplitude/analytics-browser": "^1.5.4",
6+
"@amplitude/analytics-browser": "^1.12.1",
77
"@amplitude/experiment-js-client": "^1.5.6",
88
"@types/node": "^16.11.29",
99
"@types/react": "^18.0.7",

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"eslint-plugin-jest": "^27.2.1",
3232
"eslint-plugin-prettier": "^3.1.4",
3333
"jest": "^29.5.0",
34-
"jest-environment-jsdom": "^29.5.0",
34+
"jest-environment-jsdom": "^29.6.4",
3535
"lerna": "^6.6.1",
3636
"node-fetch": "^2.6.0",
3737
"prettier": "^2.0.5",

packages/experiment-browser/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
},
3636
"dependencies": {
3737
"@amplitude/analytics-connector": "^1.5.0",
38+
"@amplitude/experiment-core": "^0.6.0",
3839
"@amplitude/ua-parser-js": "^0.7.31",
3940
"base64-js": "1.5.1",
4041
"unfetch": "4.1.0"

packages/experiment-browser/rollup.config.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ const configs = [
7171
entryFileNames: 'experiment.esm.js',
7272
format: 'esm',
7373
}),
74-
external: ['@amplitude/ua-parser-js', '@amplitude/analytics-connector'],
74+
external: [
75+
'@amplitude/ua-parser-js',
76+
'@amplitude/analytics-connector',
77+
'@amplitude/experiment-core',
78+
],
7579
},
7680

7781
// modern build for field "es2015" - not ie, esm, es2015 syntax
@@ -81,7 +85,11 @@ const configs = [
8185
entryFileNames: 'experiment.es2015.js',
8286
format: 'esm',
8387
}),
84-
external: ['@amplitude/ua-parser-js', '@amplitude/analytics-connector'],
88+
external: [
89+
'@amplitude/ua-parser-js',
90+
'@amplitude/analytics-connector',
91+
'@amplitude/experiment-core',
92+
],
8593
},
8694
];
8795

packages/experiment-browser/src/config.ts

+36-1
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,22 @@ export interface ExperimentConfig {
4343
source?: Source;
4444

4545
/**
46-
* The server endpoint from which to request variants.
46+
* The domain from which to request variants using remote evaluation.
4747
*/
4848
serverUrl?: string;
4949

50+
/**
51+
* The domain to request flag configurations used in local evaluation from.
52+
*/
53+
flagsServerUrl?: string;
54+
55+
/**
56+
* The amplitude data center to fetch flags and variants from. If set,
57+
* automatically sets the {@link serverUrl} and {@link flagsServerUrl}
58+
* configurations.
59+
*/
60+
serverZone?: string;
61+
5062
/**
5163
* The request timeout, in milliseconds, when fetching variants.
5264
*/
@@ -65,6 +77,21 @@ export interface ExperimentConfig {
6577
*/
6678
automaticExposureTracking?: boolean;
6779

80+
/**
81+
* Enable or disable local evaluation flag configuration polling on `start()`.
82+
*/
83+
pollOnStart?: boolean;
84+
85+
/**
86+
* Explicitly enable or disable calling {@link fetch()} on {@link start()}:
87+
*
88+
* - `true`: fetch will always be called on start.
89+
* - `false`: fetch will never be called on start.
90+
* - `undefined`: the SDK will determine whether to call fetch based on the
91+
* flags returned in the result.
92+
*/
93+
fetchOnStart?: boolean;
94+
6895
/**
6996
* This config only matters if you are using the amplitude analytics SDK
7097
* integration initialized by calling
@@ -120,9 +147,13 @@ export interface ExperimentConfig {
120147
| **initialVariants** | `null` |
121148
| **source** | `Source.LocalStorage` |
122149
| **serverUrl** | `"https://api.lab.amplitude.com"` |
150+
| **flagsServerUrl** | `"https://flag.lab.amplitude.com"` |
151+
| **serverZone** | `"US"` |
123152
| **assignmentTimeoutMillis** | `10000` |
124153
| **retryFailedAssignment** | `true` |
125154
| **automaticExposureTracking** | `true` |
155+
| **pollOnStart** | `true` |
156+
| **fetchOnStart** | `undefined` |
126157
| **automaticFetchOnAmplitudeIdentityChange** | `false` |
127158
| **userProvider** | `null` |
128159
| **analyticsProvider** | `null` |
@@ -138,9 +169,13 @@ export const Defaults: ExperimentConfig = {
138169
initialVariants: {},
139170
source: Source.LocalStorage,
140171
serverUrl: 'https://api.lab.amplitude.com',
172+
flagsServerUrl: 'https://flag.lab.amplitude.com',
173+
serverZone: 'US',
141174
fetchTimeoutMillis: 10000,
142175
retryFetchOnFailure: true,
143176
automaticExposureTracking: true,
177+
pollOnStart: true,
178+
fetchOnStart: undefined,
144179
automaticFetchOnAmplitudeIdentityChange: false,
145180
userProvider: null,
146181
analyticsProvider: null,

0 commit comments

Comments
 (0)