@growthbook/edge-utils 0.0.1
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/LICENSE +21 -0
- package/dist/app.d.ts +3 -0
- package/dist/app.js +171 -0
- package/dist/app.js.map +1 -0
- package/dist/attributes.d.ts +5 -0
- package/dist/attributes.js +76 -0
- package/dist/attributes.js.map +1 -0
- package/dist/config.d.ts +33 -0
- package/dist/config.js +91 -0
- package/dist/config.js.map +1 -0
- package/dist/domMutations.d.ts +6 -0
- package/dist/domMutations.js +151 -0
- package/dist/domMutations.js.map +1 -0
- package/dist/generated/sdkWrapper.d.ts +1 -0
- package/dist/generated/sdkWrapper.js +5 -0
- package/dist/generated/sdkWrapper.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/inject.d.ts +16 -0
- package/dist/inject.js +136 -0
- package/dist/inject.js.map +1 -0
- package/dist/redirect.d.ts +11 -0
- package/dist/redirect.js +43 -0
- package/dist/redirect.js.map +1 -0
- package/dist/routing.d.ts +2 -0
- package/dist/routing.js +47 -0
- package/dist/routing.js.map +1 -0
- package/dist/stickyBucketService.d.ts +14 -0
- package/dist/stickyBucketService.js +49 -0
- package/dist/stickyBucketService.js.map +1 -0
- package/dist/types.d.ts +60 -0
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -0
- package/package.json +31 -0
- package/scripts/generate-sdk-wrapper.js +22 -0
- package/src/app.ts +210 -0
- package/src/attributes.ts +97 -0
- package/src/config.ts +166 -0
- package/src/domMutations.ts +157 -0
- package/src/generated/sdkWrapper.ts +2 -0
- package/src/index.ts +13 -0
- package/src/inject.ts +230 -0
- package/src/redirect.ts +53 -0
- package/src/routing.ts +44 -0
- package/src/stickyBucketService.ts +48 -0
- package/src/types.ts +98 -0
- package/tsconfig.json +27 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
Attributes,
|
|
5
|
+
FeatureApiResponse,
|
|
6
|
+
LocalStorageCompat,
|
|
7
|
+
StickyBucketService,
|
|
8
|
+
TrackingCallback,
|
|
9
|
+
} from "@growthbook/growthbook";
|
|
10
|
+
|
|
11
|
+
export interface Context<Req = unknown, Res = unknown> {
|
|
12
|
+
config: Config;
|
|
13
|
+
helpers: Helpers<Req, Res>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface Config {
|
|
17
|
+
proxyTarget: string;
|
|
18
|
+
forwardProxyHeaders: boolean;
|
|
19
|
+
environment: string;
|
|
20
|
+
maxPayloadSize?: string;
|
|
21
|
+
routes?: Route[];
|
|
22
|
+
|
|
23
|
+
runVisualEditorExperiments: ExperimentRunEnvironment; // default: everywhere
|
|
24
|
+
disableJsInjection: boolean;
|
|
25
|
+
|
|
26
|
+
runUrlRedirectExperiments: ExperimentRunEnvironment; // default: browser
|
|
27
|
+
runCrossOriginUrlRedirectExperiments: ExperimentRunEnvironment; // default: browser
|
|
28
|
+
injectRedirectUrlScript: boolean;
|
|
29
|
+
maxRedirects: number;
|
|
30
|
+
|
|
31
|
+
scriptInjectionPattern: string;
|
|
32
|
+
disableInjections: boolean;
|
|
33
|
+
|
|
34
|
+
enableStreaming: boolean;
|
|
35
|
+
enableStickyBucketing: boolean;
|
|
36
|
+
stickyBucketPrefix?: string;
|
|
37
|
+
|
|
38
|
+
contentSecurityPolicy?: string; // __NONCE__ will be replaced with a generated nonce string
|
|
39
|
+
nonce?: string; // can be used instead of __NONCE__ if known
|
|
40
|
+
|
|
41
|
+
crypto?: any;
|
|
42
|
+
localStorage?: LocalStorageCompat;
|
|
43
|
+
|
|
44
|
+
growthbook: {
|
|
45
|
+
apiHost: string;
|
|
46
|
+
clientKey: string;
|
|
47
|
+
decryptionKey?: string;
|
|
48
|
+
trackingCallback?: string; // (experiment, result) => void;
|
|
49
|
+
edgeTrackingCallback?: TrackingCallback;
|
|
50
|
+
attributes?: Attributes;
|
|
51
|
+
edgeStickyBucketService?: StickyBucketService;
|
|
52
|
+
payload?: FeatureApiResponse;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
persistUuid: boolean;
|
|
56
|
+
uuidCookieName: string;
|
|
57
|
+
uuidKey: string;
|
|
58
|
+
skipAutoAttributes: boolean;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export type ExperimentRunEnvironment =
|
|
62
|
+
| "everywhere"
|
|
63
|
+
| "edge"
|
|
64
|
+
| "browser"
|
|
65
|
+
| "skip";
|
|
66
|
+
|
|
67
|
+
export interface Helpers<Req, Res> {
|
|
68
|
+
// routing
|
|
69
|
+
getRequestURL?: (req: Req) => string;
|
|
70
|
+
getRequestMethod?: (req: Req) => string;
|
|
71
|
+
getRequestHeader?: (req: Req, key: string) => string | undefined;
|
|
72
|
+
sendResponse?: (
|
|
73
|
+
ctx: Context<Req, Res>,
|
|
74
|
+
res?: Res,
|
|
75
|
+
headers?: Record<string, any>,
|
|
76
|
+
body?: string,
|
|
77
|
+
cookies?: Record<string, string>,
|
|
78
|
+
status?: number,
|
|
79
|
+
) => unknown;
|
|
80
|
+
fetch?: (ctx: Context<Req, Res>, url: string) => Promise<Res>;
|
|
81
|
+
proxyRequest?: (
|
|
82
|
+
ctx: Context<Req, Res>,
|
|
83
|
+
req: Req,
|
|
84
|
+
res?: Res,
|
|
85
|
+
next?: any,
|
|
86
|
+
) => Promise<unknown>;
|
|
87
|
+
getCookie?: (req: Req, key: string) => string;
|
|
88
|
+
setCookie?: (res: Res, key: string, value: string) => void;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export type Route = {
|
|
92
|
+
pattern: string;
|
|
93
|
+
type?: "regex" | "simple";
|
|
94
|
+
behavior?: "intercept" | "proxy" | "error";
|
|
95
|
+
includeFileExtensions?: boolean;
|
|
96
|
+
statusCode?: number;
|
|
97
|
+
body?: string;
|
|
98
|
+
};
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"strict": true,
|
|
5
|
+
"esModuleInterop": true,
|
|
6
|
+
"allowSyntheticDefaultImports": true,
|
|
7
|
+
"target": "es6",
|
|
8
|
+
"lib": [
|
|
9
|
+
"es6",
|
|
10
|
+
"dom",
|
|
11
|
+
"es2016"
|
|
12
|
+
],
|
|
13
|
+
"noImplicitAny": true,
|
|
14
|
+
"moduleResolution": "node",
|
|
15
|
+
"sourceMap": true,
|
|
16
|
+
"outDir": "dist",
|
|
17
|
+
"declaration": true,
|
|
18
|
+
"typeRoots": ["node_modules/@types", "./typings"],
|
|
19
|
+
"strictNullChecks": true,
|
|
20
|
+
"strictBindCallApply": true,
|
|
21
|
+
"strictPropertyInitialization": true,
|
|
22
|
+
"incremental": true
|
|
23
|
+
},
|
|
24
|
+
"include": [
|
|
25
|
+
"src/**/*"
|
|
26
|
+
]
|
|
27
|
+
}
|