@growthbook/edge-utils 0.0.7 → 0.1.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/README.md +100 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# GrowthBook Edge App _(base)_
|
|
2
|
+
|
|
3
|
+
[GrowthBook](https://www.growthbook.io) is a modular Feature Flagging and Experimentation platform.
|
|
4
|
+
|
|
5
|
+
The **GrowthBook Edge App** provides turnkey Visual Editor and URL Redirect experimentation on edge without any of the flicker associated with front-end experiments. It runs as a smart proxy layer between your application and your end users. It also can inject a fully-hydrated front-end SDK onto the rendered page, meaning no extra network requests needed.
|
|
6
|
+
|
|
7
|
+
- Automatically run server-side or hybrid Visual Experiments without redraw flicker.
|
|
8
|
+
- Automatically run server-side or hybrid URL Redirect Experiments without flicker or delay.
|
|
9
|
+
- Inject the JavaScript SDK with hydrated payload, allowing the front-end to pick up where the edge left off without any extra network requests.
|
|
10
|
+
|
|
11
|
+
> [!NOTE]
|
|
12
|
+
>
|
|
13
|
+
> This is a vendor-agnostic **base app** for the GrowthBook Edge App. It is used by our vendor-specific Edge Apps (CloudFlare Workers, Lambda@Edge). You can also easily build a custom implementation for your edge provider.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
### Implement our Edge App request handler
|
|
18
|
+
|
|
19
|
+
To run the edge app, add our base app to request handler to your project. You will need to manually build app context and helper functions:
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
import { edgeApp, getConfig } from "@growthbook/edge-utils";
|
|
23
|
+
|
|
24
|
+
export async function handler(request, env) {
|
|
25
|
+
const context = await init(env);
|
|
26
|
+
return edgeApp(context, request);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function init(env) {
|
|
30
|
+
const context = getConfig(env);
|
|
31
|
+
context.helpers = {
|
|
32
|
+
// define utility functions for request/response manipulation
|
|
33
|
+
};
|
|
34
|
+
return context;
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Set up environment variables
|
|
39
|
+
|
|
40
|
+
Add these required fields, at minimum, to your environment variables:
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
PROXY_TARGET="https://internal.mysite.io" # The non-edge URL to your website
|
|
44
|
+
GROWTHBOOK_API_HOST="https://cdn.growthbook.io"
|
|
45
|
+
GROWTHBOOK_CLIENT_KEY="abc123"
|
|
46
|
+
GROWTHBOOK_DECRYPTION_KEY="qwerty1234" # Optional
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
See the complete list of environment variables in the [Configuration](#configuration) section.
|
|
50
|
+
|
|
51
|
+
### Set up payload caching (optional)
|
|
52
|
+
|
|
53
|
+
Set up an edge key-val store and optionally use a GrowthBook SDK Webhook to keep feature and experiment values synced between GrowthBook and your edge worker. This eliminates network requests from your edge to GrowthBook.
|
|
54
|
+
|
|
55
|
+
## Configuration
|
|
56
|
+
|
|
57
|
+
The GrowthBook Edge App supports a number of configuration options available via environment variables:
|
|
58
|
+
|
|
59
|
+
#### Proxy behavior
|
|
60
|
+
- `PROXY_TARGET` - Non-edge url to your website
|
|
61
|
+
- `FORWARD_PROXY_HEADERS` - "true" or "1" to preserve response headers from your server (default : `true`)
|
|
62
|
+
- `NODE_ENV` - default: `production`
|
|
63
|
+
- `ROUTES` - JSON encoded array of Routes, rules for intercepting, proxy passing, or erroring based on request URL pattern matching
|
|
64
|
+
|
|
65
|
+
#### Experiment behavior
|
|
66
|
+
- `RUN_VISUAL_EDITOR_EXPERIMENTS` - One of `everywhere`, `edge`, `browser`, or `skip` (default `everywhere`)
|
|
67
|
+
- `DISABLE_JS_INJECTION` - "true" or "1" to skip injecting JavaScript coming from a Visual Experiment (default `false`)
|
|
68
|
+
- `RUN_URL_REDIRECT_EXPERIMENTS` - One of `everywhere`, `edge`, `browser`, or `skip` (default `browser`)
|
|
69
|
+
- `RUN_CROSS_ORIGIN_URL_REDIRECT_EXPERIMENTS` - One of `everywhere`, `edge`, `browser`, or `skip` (default `browser`)
|
|
70
|
+
- `INJECT_REDIRECT_URL_SCRIPT` - "true" or "1" to mutate browser URL via window.history.replaceState() to reflect the redirected URL (default `true`)
|
|
71
|
+
- `MAX_REDIRECTS` - Number of on-edge redirects calculated before bailing out. Only the final redirect is fetched from your origin. (default `5`)
|
|
72
|
+
|
|
73
|
+
#### Front-end SDK hydration
|
|
74
|
+
- `SCRIPT_INJECTION_PATTERN` - Inject the GrowthBook SDK before this token (default `</head>`)
|
|
75
|
+
- `DISABLE_INJECTIONS` - "true" or "1" to disable SDK injection entirely, including tracking callbacks (default `false`)
|
|
76
|
+
|
|
77
|
+
#### GrowthBook SDK behavior
|
|
78
|
+
- `GROWTHBOOK_API_HOST` - Required
|
|
79
|
+
- `GROWTHBOOK_CLIENT_KEY` - Required
|
|
80
|
+
- `GROWTHBOOK_DECRYPTION_KEY` - Required when using an encrypted SDK Connection
|
|
81
|
+
<br /><br />
|
|
82
|
+
- `STALE_TTL` - In-memory SDK cache TTL (default 1 min = `60000`).
|
|
83
|
+
- `GROWTHBOOK_TRACKING_CALLBACK` - String representation of custom JavaScript client-side tracking callback.
|
|
84
|
+
- `ENABLE_STREAMING` - "true" or "1" to enable front-end SSE streaming (default `false`)
|
|
85
|
+
- `ENABLE_STICKY_BUCKETING` - "true" or "1" to enable Sticky Bucketing, cookie-based by default (default `false`)
|
|
86
|
+
- `STICKY_BUCKET_PREFIX` - The name prefix for Sticky Bucketing cookies (default `gbStickyBuckets__`)
|
|
87
|
+
|
|
88
|
+
#### User Attribute behavior
|
|
89
|
+
- `PERSIST_UUID` - "true" or "1" to write the user's ID to cookie from the edge server instead of from the browser (default `false`)
|
|
90
|
+
- `NO_AUTO_COOKIES` - "true" or "1" to avoid writing any cookies (excluding Sticky Buckets) until user permission is granted on front-end via `document.dispatchEvent(new CustomEvent("growthbookpersist"));` (default `false`)
|
|
91
|
+
- `UUID_COOKIE_NAME` - Customize the cookie name for persisting the user's ID (default `gbuuid`)
|
|
92
|
+
- `UUID_KEY` - Customize the user identifier name (default `id`)
|
|
93
|
+
- `SKIP_AUTO_ATTRIBUTES` "true" or "1" to skip auto-generating targeting attributes (default `false`)
|
|
94
|
+
|
|
95
|
+
#### Misc
|
|
96
|
+
- `CONTENT_SECURITY_POLICY` - CSP header value
|
|
97
|
+
|
|
98
|
+
## Further reading
|
|
99
|
+
|
|
100
|
+
See the Edge App [documentation](https://docs.growthbook.io/lib/edge/other) for more details and examples.
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@growthbook/edge-utils",
|
|
3
3
|
"description": "Edge worker base app",
|
|
4
|
-
"version": "0.0
|
|
4
|
+
"version": "0.1.0",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "git+https://github.com/growthbook/growthbook-proxy.git",
|
|
10
|
-
"directory": "packages/
|
|
10
|
+
"directory": "packages/lib/edge-utils"
|
|
11
11
|
},
|
|
12
12
|
"author": "Bryce Fitzsimons",
|
|
13
13
|
"scripts": {
|