@growthbook/edge-utils 0.1.7 → 0.2.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 +23 -1
- package/dist/app.d.ts +1 -1
- package/dist/app.js +161 -60
- package/dist/app.js.map +1 -1
- package/dist/attributes.d.ts +1 -1
- package/dist/attributes.js +5 -6
- package/dist/attributes.js.map +1 -1
- package/dist/config.d.ts +8 -1
- package/dist/config.js +44 -19
- package/dist/config.js.map +1 -1
- package/dist/domMutations.d.ts +5 -2
- package/dist/domMutations.js +21 -7
- package/dist/domMutations.js.map +1 -1
- package/dist/generated/sdkWrapper.d.ts +1 -1
- package/dist/generated/sdkWrapper.js +1 -1
- package/dist/generated/sdkWrapper.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/inject.d.ts +5 -4
- package/dist/inject.js +6 -6
- package/dist/inject.js.map +1 -1
- package/dist/redirect.d.ts +4 -4
- package/dist/redirect.js +4 -4
- package/dist/redirect.js.map +1 -1
- package/dist/routing.d.ts +1 -1
- package/dist/routing.js +8 -8
- package/dist/routing.js.map +1 -1
- package/dist/stickyBucketService.js +1 -1
- package/dist/stickyBucketService.js.map +1 -1
- package/dist/types.d.ts +57 -7
- package/package.json +8 -6
- package/src/app.ts +177 -91
- package/src/attributes.ts +2 -3
- package/src/config.ts +42 -2
- package/src/domMutations.ts +16 -4
- package/src/generated/sdkWrapper.ts +1 -1
- package/src/index.ts +9 -0
- package/src/inject.ts +10 -7
- package/src/redirect.ts +6 -6
- package/src/routing.ts +9 -7
- package/src/types.ts +60 -7
package/README.md
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
[GrowthBook](https://www.growthbook.io) is a modular Feature Flagging and Experimentation platform.
|
|
4
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.
|
|
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 while also supporting manual feature flagging and experimentation. 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
6
|
|
|
7
7
|
- Automatically run server-side or hybrid Visual Experiments without redraw flicker.
|
|
8
8
|
- Automatically run server-side or hybrid URL Redirect Experiments without flicker or delay.
|
|
9
|
+
- Perform custom feature flagging and experimentation logic using [lifecycle hooks](#lifecycle-hooks).
|
|
9
10
|
- 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
|
|
|
11
12
|
> [!NOTE]
|
|
@@ -60,6 +61,9 @@ The GrowthBook Edge App supports a number of configuration options available via
|
|
|
60
61
|
#### Proxy behavior
|
|
61
62
|
- `PROXY_TARGET` - Non-edge url to your website
|
|
62
63
|
- `FORWARD_PROXY_HEADERS` - "true" or "1" to preserve response headers from your server (default : `true`)
|
|
64
|
+
- `FOLLOW_REDIRECTS` - "true" or "1" to follow redirects when processing an origin response (default : `true`)
|
|
65
|
+
- `USE_DEFAULT_CONTENT_TYPE` - "true" or "1" to assume a content-type of "text-html" if no "Content-Type" header was set (default `false`).
|
|
66
|
+
- `PROCESS_TEXT_HTML_ONLY` - "true" or "1" to only process server responses with the `Content-Type: text/html` header set – others will be proxied through (default `true`).
|
|
63
67
|
- `NODE_ENV` - default: `production`
|
|
64
68
|
- `ROUTES` - JSON encoded array of Routes, rules for intercepting, proxy passing, or erroring based on request URL pattern matching
|
|
65
69
|
|
|
@@ -93,9 +97,27 @@ The GrowthBook Edge App supports a number of configuration options available via
|
|
|
93
97
|
- `UUID_KEY` - Customize the user identifier name (default `id`)
|
|
94
98
|
- `SKIP_AUTO_ATTRIBUTES` "true" or "1" to skip auto-generating targeting attributes (default `false`)
|
|
95
99
|
|
|
100
|
+
#### Lifecycle hooks
|
|
101
|
+
- `ALWAYS_PARSE_DOM` - Normally the worker will only build a virtual DOM if there are visual changes. Set to "true" or "1" to always build a virtual DOM so that you can access it in lifecycle hooks (ex: `onBodyReady`)
|
|
102
|
+
|
|
96
103
|
#### Misc
|
|
97
104
|
- `CONTENT_SECURITY_POLICY` - CSP header value
|
|
98
105
|
|
|
106
|
+
|
|
107
|
+
## Lifecycle hooks
|
|
108
|
+
You can perform custom logic and optionally return a response at various stages in the Edge App's lifecycle. This allows for expressiveness of custom routing, user attribute mutation, header and body (DOM) mutation, and custom feature flag and experiment implementations – while preserving the ability to automatically run Visual and URL Redirect experiments and SDK hydration.
|
|
109
|
+
|
|
110
|
+
With each hook, you may mutate any of the provided attributes *or* return an early response to halt the Edge App processing. The following hooks are available
|
|
111
|
+
|
|
112
|
+
- `onRequest` - Fired on initial user request. Can exit early based on requested URL.
|
|
113
|
+
- `onRoute` - Fired after standard routing has been processed. Can exit early (proxy) based on manual routing logic.
|
|
114
|
+
- `onUserAttributes` - Fired after auto-attributes have been assigned to the user. Either enhance the provided `attributes` object or exit early if desired.
|
|
115
|
+
- `onGrowthBookInit` - Fired after the Edge App's internal GrowthBook SDK has been initialized. Call SDK functions or exit early if desired.
|
|
116
|
+
- `onBeforeOriginFetch` - Similar hook to the above; triggers after any URL Redirect experiments have run but before any origin requests have been made.
|
|
117
|
+
- `onOriginFetch` - Fired immediately after the origin fetch has been made, but before the full response body has been captured. Useful for exiting early based on response status or headers.
|
|
118
|
+
- `onBodyReadyParams` - Fired once the entire response body has been parsed. In addition to early exiting, you may begin to mutate the final response body via `resHeaders` and the `setBody()` method. The text `body` as well as the optional parsed virtual DOM `root` (disabled by default, use `ALWAYS_PARSE_DOM` to enable) are exposed. NOTE: If mutating the `root` DOM, it is your responsibility to `setBody()` with the latest changes before the response is returned.
|
|
119
|
+
- `onBeforeResponse` - The final hook fired before the response is returned to the user, triggering after both visual editor changes and client SDK hydration have been injected. While the virtual DOM is no longer available, this hook can be used to apply any final changes the body via `setBody()`.
|
|
120
|
+
|
|
99
121
|
## Further reading
|
|
100
122
|
|
|
101
123
|
See the Edge App [documentation](https://docs.growthbook.io/lib/edge/other) for more details and examples.
|
package/dist/app.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Context } from "./types";
|
|
2
2
|
export declare function edgeApp<Req, Res>(context: Context<Req, Res>, req: Req, res?: Res, next?: any): Promise<unknown>;
|
|
3
|
-
export declare function getOriginUrl(context: Context, currentURL: string): string;
|
|
3
|
+
export declare function getOriginUrl<Req, Res>(context: Context<Req, Res>, currentURL: string): string;
|
package/dist/app.js
CHANGED
|
@@ -12,7 +12,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.edgeApp = edgeApp;
|
|
16
|
+
exports.getOriginUrl = getOriginUrl;
|
|
16
17
|
const growthbook_1 = require("@growthbook/growthbook");
|
|
17
18
|
const attributes_1 = require("./attributes");
|
|
18
19
|
const inject_1 = require("./inject");
|
|
@@ -20,54 +21,79 @@ const domMutations_1 = require("./domMutations");
|
|
|
20
21
|
const redirect_1 = __importDefault(require("./redirect"));
|
|
21
22
|
const routing_1 = require("./routing");
|
|
22
23
|
const stickyBucketService_1 = require("./stickyBucketService");
|
|
24
|
+
const node_html_parser_1 = require("node-html-parser");
|
|
25
|
+
const pako_1 = __importDefault(require("pako"));
|
|
23
26
|
function edgeApp(context, req, res,
|
|
24
27
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
28
|
next) {
|
|
26
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
27
29
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
31
|
+
/**
|
|
32
|
+
* 1. Init app variables
|
|
33
|
+
*/
|
|
34
|
+
// Request vars:
|
|
35
|
+
let requestUrl = context.helpers.getRequestURL(req);
|
|
36
|
+
let originUrl = getOriginUrl(context, requestUrl);
|
|
37
|
+
// Response vars:
|
|
38
|
+
let originResponse = undefined;
|
|
39
|
+
let resHeaders = {};
|
|
40
|
+
const respCookies = {};
|
|
41
|
+
const setRespCookie = (key, value) => {
|
|
42
|
+
respCookies[key] = value;
|
|
36
43
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
44
|
+
// Initial hook:
|
|
45
|
+
let hookResp;
|
|
46
|
+
hookResp = yield ((_b = (_a = context === null || context === void 0 ? void 0 : context.hooks) === null || _a === void 0 ? void 0 : _a.onRequest) === null || _b === void 0 ? void 0 : _b.call(_a, { context, req, res, next, requestUrl, originUrl }));
|
|
47
|
+
if (hookResp)
|
|
48
|
+
return hookResp;
|
|
49
|
+
// DOM mutations
|
|
50
|
+
let domChanges = [];
|
|
51
|
+
const resetDomChanges = () => (domChanges = []);
|
|
52
|
+
// Experiments that triggered prior to final redirect
|
|
53
|
+
let preRedirectChangeIds = [];
|
|
54
|
+
const setPreRedirectChangeIds = (changeIds) => (preRedirectChangeIds = changeIds);
|
|
55
|
+
/**
|
|
56
|
+
* 2. Early exits based on method, routes, etc
|
|
57
|
+
*/
|
|
42
58
|
// Non GET requests are proxied
|
|
43
|
-
if (
|
|
44
|
-
return
|
|
59
|
+
if (context.helpers.getRequestMethod(req) !== "GET") {
|
|
60
|
+
return context.helpers.proxyRequest(context, req, res, next);
|
|
45
61
|
}
|
|
46
62
|
// Check the url for routing rules (default behavior is intercept)
|
|
47
|
-
const route = (0, routing_1.getRoute)(context,
|
|
63
|
+
const route = (0, routing_1.getRoute)(context, requestUrl);
|
|
48
64
|
if (route.behavior === "error") {
|
|
49
|
-
return
|
|
65
|
+
return context.helpers.sendResponse(context, res, {}, route.body || "", {}, route.statusCode);
|
|
50
66
|
}
|
|
51
67
|
if (route.behavior === "proxy") {
|
|
52
|
-
return
|
|
68
|
+
return context.helpers.proxyRequest(context, req, res, next);
|
|
53
69
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
70
|
+
// Custom route behavior via hook:
|
|
71
|
+
hookResp = yield ((_d = (_c = context === null || context === void 0 ? void 0 : context.hooks) === null || _c === void 0 ? void 0 : _c.onRoute) === null || _d === void 0 ? void 0 : _d.call(_c, { context, req, res, next, requestUrl, originUrl, route }));
|
|
72
|
+
if (hookResp)
|
|
73
|
+
return hookResp;
|
|
74
|
+
/**
|
|
75
|
+
* 3. User attributes & uuid
|
|
76
|
+
*/
|
|
77
|
+
const attributes = (0, attributes_1.getUserAttributes)(context, req, requestUrl, setRespCookie);
|
|
78
|
+
// Hook to allow enriching user attributes, etc
|
|
79
|
+
hookResp = yield ((_f = (_e = context === null || context === void 0 ? void 0 : context.hooks) === null || _e === void 0 ? void 0 : _e.onUserAttributes) === null || _f === void 0 ? void 0 : _f.call(_e, { context, req, res, next, requestUrl, originUrl, route, attributes }));
|
|
80
|
+
if (hookResp)
|
|
81
|
+
return hookResp;
|
|
82
|
+
/**
|
|
83
|
+
* 4. Init GrowthBook SDK
|
|
84
|
+
*/
|
|
85
|
+
(0, growthbook_1.setPolyfills)({
|
|
86
|
+
localStorage: (_g = context.config) === null || _g === void 0 ? void 0 : _g.localStorage,
|
|
87
|
+
SubtleCrypto: (_h = context.config) === null || _h === void 0 ? void 0 : _h.crypto,
|
|
88
|
+
});
|
|
63
89
|
if (context.config.staleTTL !== undefined)
|
|
64
90
|
(0, growthbook_1.configureCache)({ staleTTL: context.config.staleTTL });
|
|
65
91
|
if (context.config.fetchFeaturesCall)
|
|
66
92
|
growthbook_1.helpers.fetchFeaturesCall = context.config.fetchFeaturesCall;
|
|
67
|
-
let stickyBucketService
|
|
93
|
+
let stickyBucketService;
|
|
68
94
|
if (context.config.enableStickyBucketing) {
|
|
69
95
|
stickyBucketService =
|
|
70
|
-
(
|
|
96
|
+
(_j = context.config.edgeStickyBucketService) !== null && _j !== void 0 ? _j : new stickyBucketService_1.EdgeStickyBucketService({
|
|
71
97
|
context,
|
|
72
98
|
prefix: context.config.stickyBucketPrefix,
|
|
73
99
|
req,
|
|
@@ -80,9 +106,10 @@ next) {
|
|
|
80
106
|
attributes,
|
|
81
107
|
applyDomChangesCallback: (changes) => {
|
|
82
108
|
domChanges.push(changes);
|
|
83
|
-
return () => {
|
|
109
|
+
return () => {
|
|
110
|
+
};
|
|
84
111
|
},
|
|
85
|
-
url,
|
|
112
|
+
url: requestUrl,
|
|
86
113
|
disableVisualExperiments: ["skip", "browser"].includes(context.config.runVisualEditorExperiments),
|
|
87
114
|
disableJsInjection: context.config.disableJsInjection,
|
|
88
115
|
disableUrlRedirectExperiments: ["skip", "browser"].includes(context.config.runUrlRedirectExperiments),
|
|
@@ -93,57 +120,126 @@ next) {
|
|
|
93
120
|
yield growthbook.init({
|
|
94
121
|
payload: context.config.payload,
|
|
95
122
|
});
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
123
|
+
// Hook to perform any custom logic given the initialized SDK
|
|
124
|
+
hookResp = yield ((_l = (_k = context === null || context === void 0 ? void 0 : context.hooks) === null || _k === void 0 ? void 0 : _k.onGrowthbookInit) === null || _l === void 0 ? void 0 : _l.call(_k, { context, req, res, next, requestUrl, originUrl, route, attributes, growthbook }));
|
|
125
|
+
if (hookResp)
|
|
126
|
+
return hookResp;
|
|
127
|
+
/**
|
|
128
|
+
* 5. Run URL redirect tests before fetching from origin
|
|
129
|
+
*/
|
|
130
|
+
const redirectRequestUrl = yield (0, redirect_1.default)({
|
|
131
|
+
context,
|
|
99
132
|
req,
|
|
100
|
-
|
|
133
|
+
setRespCookie,
|
|
101
134
|
growthbook,
|
|
102
|
-
previousUrl:
|
|
135
|
+
previousUrl: requestUrl,
|
|
103
136
|
resetDomChanges,
|
|
104
137
|
setPreRedirectChangeIds: setPreRedirectChangeIds,
|
|
105
138
|
});
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
139
|
+
originUrl = getOriginUrl(context, redirectRequestUrl);
|
|
140
|
+
// Pre-origin-fetch hook (after redirect logic):
|
|
141
|
+
hookResp = yield ((_o = (_m = context === null || context === void 0 ? void 0 : context.hooks) === null || _m === void 0 ? void 0 : _m.onBeforeOriginFetch) === null || _o === void 0 ? void 0 : _o.call(_m, { context, req, res, next, requestUrl, redirectRequestUrl, originUrl, route, attributes, growthbook }));
|
|
142
|
+
if (hookResp)
|
|
143
|
+
return hookResp;
|
|
144
|
+
/**
|
|
145
|
+
* 6. Fetch from origin, parse body / DOM
|
|
146
|
+
*/
|
|
109
147
|
try {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
148
|
+
originResponse = (yield context.helpers.fetch(context, originUrl, req));
|
|
149
|
+
}
|
|
150
|
+
catch (e) {
|
|
151
|
+
console.error(e);
|
|
152
|
+
}
|
|
153
|
+
const originStatus = originResponse ? parseInt(originResponse.status ? originResponse.status + "" : "400") : 500;
|
|
154
|
+
// On fetch hook (for custom response processing, etc)
|
|
155
|
+
hookResp = yield ((_q = (_p = context === null || context === void 0 ? void 0 : context.hooks) === null || _p === void 0 ? void 0 : _p.onOriginFetch) === null || _q === void 0 ? void 0 : _q.call(_p, { context, req, res, next, requestUrl, redirectRequestUrl, originUrl, route, attributes, growthbook, originResponse, originStatus }));
|
|
156
|
+
if (hookResp)
|
|
157
|
+
return hookResp;
|
|
158
|
+
// Standard error response handling
|
|
159
|
+
if (originStatus >= 500 || !originResponse) {
|
|
160
|
+
console.error("Fetch: 5xx status returned");
|
|
161
|
+
return context.helpers.sendResponse(context, res, {}, "Error fetching page", {}, 500);
|
|
162
|
+
}
|
|
163
|
+
if (originStatus >= 400) {
|
|
164
|
+
return originResponse;
|
|
165
|
+
}
|
|
166
|
+
// Got a valid response, begin processing
|
|
167
|
+
const originHeaders = headersToObject(originResponse.headers);
|
|
168
|
+
if (context.config.forwardProxyHeaders) {
|
|
169
|
+
resHeaders = Object.assign(Object.assign({}, originHeaders), resHeaders);
|
|
170
|
+
}
|
|
171
|
+
// At minimum, the content-type is forwarded
|
|
172
|
+
resHeaders["content-type"] = originHeaders === null || originHeaders === void 0 ? void 0 : originHeaders["content-type"];
|
|
173
|
+
if (context.config.useDefaultContentType && !resHeaders["content-type"]) {
|
|
174
|
+
resHeaders["content-type"] = "text/html";
|
|
175
|
+
}
|
|
176
|
+
if (context.config.processTextHtmlOnly && !((_r = resHeaders["content-type"]) !== null && _r !== void 0 ? _r : "").includes("text/html")) {
|
|
177
|
+
return context.helpers.proxyRequest(context, req, res, next);
|
|
178
|
+
}
|
|
179
|
+
const { csp, nonce } = (0, inject_1.getCspInfo)(context);
|
|
180
|
+
if (csp) {
|
|
181
|
+
resHeaders["content-security-policy"] = csp;
|
|
182
|
+
}
|
|
183
|
+
let body = "";
|
|
184
|
+
try {
|
|
185
|
+
// Check if content-encoding is gzip
|
|
186
|
+
if (originHeaders["content-encoding"] === "gzip") {
|
|
187
|
+
const buffer = yield originResponse.arrayBuffer();
|
|
188
|
+
body = pako_1.default.inflate(new Uint8Array(buffer), { to: "string" });
|
|
189
|
+
delete resHeaders["content-encoding"]; // do not forward this header since it's now unzipped
|
|
115
190
|
}
|
|
116
|
-
|
|
117
|
-
|
|
191
|
+
else {
|
|
192
|
+
body = (_s = yield (originResponse === null || originResponse === void 0 ? void 0 : originResponse.text())) !== null && _s !== void 0 ? _s : "";
|
|
118
193
|
}
|
|
119
194
|
}
|
|
120
195
|
catch (e) {
|
|
121
196
|
console.error(e);
|
|
122
|
-
return (_u = (_t = context.helpers).sendResponse) === null || _u === void 0 ? void 0 : _u.call(_t, context, res, headers, "Error fetching page", cookies, 500);
|
|
123
197
|
}
|
|
124
|
-
|
|
125
|
-
|
|
198
|
+
let setBody = (s) => {
|
|
199
|
+
body = s;
|
|
200
|
+
};
|
|
201
|
+
let root;
|
|
202
|
+
if (context.config.alwaysParseDOM) {
|
|
203
|
+
root = (0, node_html_parser_1.parse)(body);
|
|
126
204
|
}
|
|
127
|
-
|
|
128
|
-
|
|
205
|
+
// Body ready hook (pre-DOM-mutations):
|
|
206
|
+
hookResp = yield ((_u = (_t = context === null || context === void 0 ? void 0 : context.hooks) === null || _t === void 0 ? void 0 : _t.onBodyReady) === null || _u === void 0 ? void 0 : _u.call(_t, { context, req, res, next, requestUrl, redirectRequestUrl, originUrl, route, attributes, growthbook, originResponse, originStatus, originHeaders, resHeaders, body, setBody, root }));
|
|
207
|
+
if (hookResp)
|
|
208
|
+
return hookResp;
|
|
209
|
+
/**
|
|
210
|
+
* 7. Apply visual editor DOM mutations
|
|
211
|
+
*/
|
|
212
|
+
yield (0, domMutations_1.applyDomMutations)({
|
|
129
213
|
body,
|
|
214
|
+
setBody,
|
|
215
|
+
root,
|
|
130
216
|
nonce,
|
|
131
217
|
domChanges,
|
|
132
218
|
});
|
|
133
|
-
|
|
134
|
-
|
|
219
|
+
/**
|
|
220
|
+
* 8. Inject the client-facing GrowthBook SDK (auto-wrapper)
|
|
221
|
+
*/
|
|
222
|
+
(0, inject_1.injectScript)({
|
|
223
|
+
context,
|
|
135
224
|
body,
|
|
225
|
+
setBody,
|
|
136
226
|
nonce,
|
|
137
227
|
growthbook,
|
|
138
228
|
attributes,
|
|
139
229
|
preRedirectChangeIds,
|
|
140
|
-
url,
|
|
141
|
-
oldUrl,
|
|
230
|
+
url: redirectRequestUrl,
|
|
231
|
+
oldUrl: requestUrl,
|
|
142
232
|
});
|
|
143
|
-
|
|
233
|
+
// Final hook (post-mutations) before sending back
|
|
234
|
+
hookResp = yield ((_w = (_v = context === null || context === void 0 ? void 0 : context.hooks) === null || _v === void 0 ? void 0 : _v.onBeforeResponse) === null || _w === void 0 ? void 0 : _w.call(_v, { context, req, res, next, requestUrl, redirectRequestUrl, originUrl, route, attributes, growthbook, originResponse, originStatus, originHeaders, resHeaders, body, setBody }));
|
|
235
|
+
if (hookResp)
|
|
236
|
+
return hookResp;
|
|
237
|
+
/**
|
|
238
|
+
* 9. Send mutated response
|
|
239
|
+
*/
|
|
240
|
+
return context.helpers.sendResponse(context, res, resHeaders, body, respCookies);
|
|
144
241
|
});
|
|
145
242
|
}
|
|
146
|
-
exports.edgeApp = edgeApp;
|
|
147
243
|
function getOriginUrl(context, currentURL) {
|
|
148
244
|
const proxyTarget = context.config.proxyTarget;
|
|
149
245
|
const currentParsedURL = new URL(currentURL);
|
|
@@ -172,5 +268,10 @@ function getOriginUrl(context, currentURL) {
|
|
|
172
268
|
}
|
|
173
269
|
return newURL;
|
|
174
270
|
}
|
|
175
|
-
|
|
271
|
+
function headersToObject(headers) {
|
|
272
|
+
if (headers && typeof headers.entries === "function") {
|
|
273
|
+
return Object.fromEntries(headers.entries());
|
|
274
|
+
}
|
|
275
|
+
return headers || {};
|
|
276
|
+
}
|
|
176
277
|
//# sourceMappingURL=app.js.map
|
package/dist/app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAwBA,0BAmPC;AAGD,oCA8BC;AA5SD,uDAMgC;AAEhC,6CAAiD;AACjD,qCAAoD;AACpD,iDAAmD;AACnD,0DAAkC;AAClC,uCAAqC;AACrC,+DAAgE;AAChE,uDAAsD;AACtD,gDAAwB;AASxB,SAAsB,OAAO,CAC3B,OAA0B,EAC1B,GAAQ,EACR,GAA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AAI,IAAI,KAAK,KAAK,EAAE,CAAC;QAC7D,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;IACvB,CAAC;IACD,MAAM,IAAI,GAAG,gBAAgB,CAAC,QAAQ,EAAE,CAAC;IACzC,IAAI,gBAAgB,CAAC,MAAM,EAAE,CAAC;QAC5B,MAAM,IAAI,gBAAgB,CAAC,MAAM,CAAC;IACpC,CAAC;IACD,IAAI,gBAAgB,CAAC,IAAI,EAAE,CAAC;QAC1B,MAAM,IAAI,gBAAgB,CAAC,IAAI,CAAC;IAClC,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,eAAe,CAAC,OAAY;IACnC,IAAI,OAAO,IAAI,OAAO,OAAO,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;QACrD,OAAO,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,OAAO,IAAI,EAAE,CAAC;AACvB,CAAC"}
|
package/dist/attributes.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Attributes } from "@growthbook/growthbook";
|
|
2
2
|
import { Context } from "./types";
|
|
3
|
-
export declare function getUserAttributes<Req, Res>(ctx: Context<Req, Res>, req: Req, url: string,
|
|
3
|
+
export declare function getUserAttributes<Req, Res>(ctx: Context<Req, Res>, req: Req, url: string, setRespCookie: (key: string, value: string) => void): Attributes;
|
|
4
4
|
export declare function getUUID<Req, Res>(ctx: Context<Req, Res>, req: Req): any;
|
|
5
5
|
export declare function getAutoAttributes<Req, Res>(ctx: Context<Req, Res>, req: Req, url: string): Attributes;
|
package/dist/attributes.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getUserAttributes = getUserAttributes;
|
|
4
|
+
exports.getUUID = getUUID;
|
|
5
|
+
exports.getAutoAttributes = getAutoAttributes;
|
|
4
6
|
// Get the user's attributes by merging the UUID cookie with any auto-attributes
|
|
5
|
-
function getUserAttributes(ctx, req, url,
|
|
7
|
+
function getUserAttributes(ctx, req, url, setRespCookie) {
|
|
6
8
|
const { config, helpers } = ctx;
|
|
7
9
|
const providedAttributes = config.attributes || {};
|
|
8
10
|
if (config.skipAutoAttributes) {
|
|
@@ -14,12 +16,11 @@ function getUserAttributes(ctx, req, url, setCookie) {
|
|
|
14
16
|
if (!(helpers === null || helpers === void 0 ? void 0 : helpers.setCookie)) {
|
|
15
17
|
throw new Error("Missing required dependencies");
|
|
16
18
|
}
|
|
17
|
-
|
|
19
|
+
setRespCookie(config.uuidCookieName, uuid);
|
|
18
20
|
}
|
|
19
21
|
const autoAttributes = getAutoAttributes(ctx, req, url);
|
|
20
22
|
return Object.assign(Object.assign({}, autoAttributes), providedAttributes);
|
|
21
23
|
}
|
|
22
|
-
exports.getUserAttributes = getUserAttributes;
|
|
23
24
|
// Get or create a UUID for the user:
|
|
24
25
|
// - Try to get the UUID from the cookie
|
|
25
26
|
// - Or create a new one and store in the cookie
|
|
@@ -39,7 +40,6 @@ function getUUID(ctx, req) {
|
|
|
39
40
|
// get the existing UUID from cookie if set, otherwise create one
|
|
40
41
|
return helpers.getCookie(req, config.uuidCookieName) || genUUID();
|
|
41
42
|
}
|
|
42
|
-
exports.getUUID = getUUID;
|
|
43
43
|
// Infer attributes from the request
|
|
44
44
|
// - UUID will come from the cookie or be generated
|
|
45
45
|
// - Other attributes come from the request headers and URL
|
|
@@ -73,7 +73,6 @@ function getAutoAttributes(ctx, req, url) {
|
|
|
73
73
|
}
|
|
74
74
|
return autoAttributes;
|
|
75
75
|
}
|
|
76
|
-
exports.getAutoAttributes = getAutoAttributes;
|
|
77
76
|
function getUtmAttributes(urlObj) {
|
|
78
77
|
// Store utm- params in sessionStorage for future page loads
|
|
79
78
|
let utms = {};
|
package/dist/attributes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attributes.js","sourceRoot":"","sources":["../src/attributes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"attributes.js","sourceRoot":"","sources":["../src/attributes.ts"],"names":[],"mappings":";;AAIA,8CAuBC;AAKD,0BAqBC;AAKD,8CAsCC;AA7FD,gFAAgF;AAChF,SAAgB,iBAAiB,CAC/B,GAAsB,EACtB,GAAQ,EACR,GAAW,EACX,aAAmD;IAEnD,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,CAAC;IAEhC,MAAM,kBAAkB,GAAG,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC;IACnD,IAAI,MAAM,CAAC,kBAAkB,EAAE,CAAC;QAC9B,OAAO,kBAAkB,CAAC;IAC5B,CAAC;IACD,2CAA2C;IAC3C,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC/B,IAAI,MAAM,CAAC,WAAW,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC;QAChD,IAAI,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,CAAA,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;QACnD,CAAC;QACD,aAAa,CAAC,MAAM,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;IAC7C,CAAC;IAED,MAAM,cAAc,GAAG,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IACxD,uCAAY,cAAc,GAAK,kBAAkB,EAAG;AACtD,CAAC;AAED,qCAAqC;AACrC,wCAAwC;AACxC,gDAAgD;AAChD,SAAgB,OAAO,CAAW,GAAsB,EAAE,GAAQ;IAChE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,CAAC;IAEhC,MAAM,MAAM,GAAG,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,MAAI,UAAU,aAAV,UAAU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C;QAClD,CAAC,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;YAChE,+BAA+B;YAC/B,MAAM,KAAK,GAAG,OAAO,CAAC,EAAE,CAAC;YACzB,+BAA+B;YAC/B,MAAM,IAAI,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAErD,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;gBACtB,IAAI,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;YACvC,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/config.d.ts
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import { Config, Context, ExperimentRunEnvironment } from "./types";
|
|
2
|
-
|
|
2
|
+
type Req = any;
|
|
3
|
+
type Res = any;
|
|
4
|
+
export declare const defaultContext: Context<Req, Res>;
|
|
3
5
|
export interface ConfigEnv {
|
|
4
6
|
PROXY_TARGET?: string;
|
|
5
7
|
FORWARD_PROXY_HEADERS?: string;
|
|
8
|
+
FOLLOW_REDIRECTS?: string;
|
|
9
|
+
USE_DEFAULT_CONTENT_TYPE?: string;
|
|
10
|
+
PROCESS_TEXT_HTML_ONLY?: string;
|
|
6
11
|
NODE_ENV?: string;
|
|
7
12
|
MAX_PAYLOAD_SIZE?: string;
|
|
8
13
|
ROUTES?: string;
|
|
9
14
|
RUN_VISUAL_EDITOR_EXPERIMENTS?: ExperimentRunEnvironment;
|
|
10
15
|
DISABLE_JS_INJECTION?: string;
|
|
16
|
+
ALWAYS_PARSE_DOM?: string;
|
|
11
17
|
RUN_URL_REDIRECT_EXPERIMENTS?: ExperimentRunEnvironment;
|
|
12
18
|
RUN_CROSS_ORIGIN_URL_REDIRECT_EXPERIMENTS?: ExperimentRunEnvironment;
|
|
13
19
|
INJECT_REDIRECT_URL_SCRIPT?: string;
|
|
@@ -33,3 +39,4 @@ export interface ConfigEnv {
|
|
|
33
39
|
[key: string]: any;
|
|
34
40
|
}
|
|
35
41
|
export declare function getConfig(env: ConfigEnv): Config;
|
|
42
|
+
export {};
|