@splithub/next 0.0.0-stage → 0.1.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/README.md +88 -2
- package/dist/chunk-LD54CWVU.js +131 -0
- package/dist/chunk-LD54CWVU.js.map +1 -0
- package/dist/client.cjs +65 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +26 -0
- package/dist/client.d.ts +26 -0
- package/dist/client.js +32 -0
- package/dist/client.js.map +1 -0
- package/dist/index.cjs +157 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +34 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/remote-D7AfTTCw.d.cts +17 -0
- package/dist/remote-D7AfTTCw.d.ts +17 -0
- package/dist/server.cjs +116 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +32 -0
- package/dist/server.d.ts +32 -0
- package/dist/server.js +47 -0
- package/dist/server.js.map +1 -0
- package/package.json +56 -3
package/README.md
CHANGED
|
@@ -1,3 +1,89 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @splithub/next
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
SplitHub for Next.js (App Router, 14+). Three entry points:
|
|
4
|
+
|
|
5
|
+
| Import | Runs | What it gives you |
|
|
6
|
+
|---|---|---|
|
|
7
|
+
| `@splithub/next` | edge (middleware) | `splithubMiddleware(config)`: visitor cookie, header for RSC, invisible rewrites for `redirect` experiments, edge exposures |
|
|
8
|
+
| `@splithub/next/server` | Server Components, Route Handlers | `getVisitorId(config)`, `getSplitHub(config)` → `.variant(id)`, `.value(id)` |
|
|
9
|
+
| `@splithub/next/client` | Client Components | `SplitHubNextProvider`, `Experiment`, `Variant`, `useVariant`, `useValue`, `useTrack`, `Exposure` |
|
|
10
|
+
|
|
11
|
+
## Setup (what `npx splithub init` does)
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
// middleware.ts
|
|
15
|
+
import { splithubMiddleware } from '@splithub/next';
|
|
16
|
+
import config from './splithub.config';
|
|
17
|
+
export default splithubMiddleware(config);
|
|
18
|
+
export const config = { matcher: ['/((?!_next|api|.*\\..*).*)'] };
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
// app/api/splithub/[[...path]]/route.ts (self-hosted mode)
|
|
23
|
+
import { createSplitHubHandler } from '@splithub/node';
|
|
24
|
+
import { sqliteStore } from '@splithub/adapter-sqlite';
|
|
25
|
+
import config from '../../../../splithub.config';
|
|
26
|
+
const handler = createSplitHubHandler({ config, store: sqliteStore(), adminToken: process.env.SPLITHUB_ADMIN_TOKEN });
|
|
27
|
+
export const POST = handler;
|
|
28
|
+
export const GET = handler;
|
|
29
|
+
export const runtime = 'nodejs';
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
// app/layout.tsx (Server Component)
|
|
34
|
+
import { SplitHubNextProvider } from '@splithub/next/client';
|
|
35
|
+
import { getSplitHub } from '@splithub/next/server';
|
|
36
|
+
import config from '../splithub.config';
|
|
37
|
+
|
|
38
|
+
export default async function RootLayout({ children }) {
|
|
39
|
+
const sh = await getSplitHub(config);
|
|
40
|
+
return (
|
|
41
|
+
<html><body>
|
|
42
|
+
<SplitHubNextProvider config={config} visitorId={sh.visitorId ?? undefined} remoteOverrides={sh.overrides}>
|
|
43
|
+
{children}
|
|
44
|
+
</SplitHubNextProvider>
|
|
45
|
+
</body></html>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Live overrides (cloud mode)
|
|
51
|
+
|
|
52
|
+
`npx splithub pause <id>` (or the dashboard) pauses an experiment, changes
|
|
53
|
+
traffic/weights or swaps `value` payloads without a deploy. The middleware and
|
|
54
|
+
`getSplitHub` fetch `GET /v1/overrides/<pk>.json` at most once per 60 s per
|
|
55
|
+
isolate and apply it on top of the config file; the layout passes the same
|
|
56
|
+
overrides to the client provider so hydration agrees. Opt out with
|
|
57
|
+
`splithubMiddleware(config, { remote: false })`.
|
|
58
|
+
|
|
59
|
+
## Using experiments
|
|
60
|
+
|
|
61
|
+
Client Components: same API as `@splithub/react`, imported from `@splithub/next/client`.
|
|
62
|
+
|
|
63
|
+
Server Components:
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
import { getSplitHub } from '@splithub/next/server';
|
|
67
|
+
import { Exposure } from '@splithub/next/client';
|
|
68
|
+
|
|
69
|
+
export default async function Page() {
|
|
70
|
+
const sh = await getSplitHub(config);
|
|
71
|
+
const title = sh.value<string>('hero-title');
|
|
72
|
+
return (
|
|
73
|
+
<>
|
|
74
|
+
<h1>{title}</h1>
|
|
75
|
+
<Exposure id="hero-title" /> {/* records the exposure once on the client */}
|
|
76
|
+
</>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Redirect experiments need no code: declare `kind: 'redirect'` with `match` and
|
|
82
|
+
per-variant `to`, and the middleware rewrites the request. The URL in the
|
|
83
|
+
address bar does not change and the visitor sees no flash.
|
|
84
|
+
|
|
85
|
+
## Why no flicker
|
|
86
|
+
|
|
87
|
+
The middleware decides the visitor id before anything renders, Server
|
|
88
|
+
Components compute the same deterministic assignment as the client, and the
|
|
89
|
+
client provider receives that id as a prop. Both sides agree on the first byte.
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// src/remote.ts
|
|
2
|
+
import { CLOUD_ENDPOINT, fetchRemoteOverrides, resolveOverridesUrl, REMOTE_TTL_MS } from "@splithub/core";
|
|
3
|
+
var memo = /* @__PURE__ */ new Map();
|
|
4
|
+
async function getRemoteOverrides(config, options = {}) {
|
|
5
|
+
if (config.storage.mode !== "cloud" || !config.storage.key) return null;
|
|
6
|
+
const ttl = options.ttlMs ?? REMOTE_TTL_MS;
|
|
7
|
+
const url = resolveOverridesUrl(config.storage.endpoint ?? CLOUD_ENDPOINT, config.storage.key);
|
|
8
|
+
const entry = memo.get(url);
|
|
9
|
+
const now = Date.now();
|
|
10
|
+
if (entry && now - entry.at < ttl) return entry.value;
|
|
11
|
+
if (entry?.pending) return entry.value ?? entry.pending;
|
|
12
|
+
const pending = fetchRemoteOverrides(url, options.fetchImpl).then((value) => {
|
|
13
|
+
memo.set(url, { at: Date.now(), value: value ?? entry?.value ?? null, pending: null });
|
|
14
|
+
return value ?? entry?.value ?? null;
|
|
15
|
+
});
|
|
16
|
+
memo.set(url, { at: entry?.at ?? 0, value: entry?.value ?? null, pending });
|
|
17
|
+
return entry ? entry.value : pending;
|
|
18
|
+
}
|
|
19
|
+
function clearRemoteMemo() {
|
|
20
|
+
memo.clear();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// src/middleware.ts
|
|
24
|
+
import {
|
|
25
|
+
applyRemoteOverrides,
|
|
26
|
+
assign,
|
|
27
|
+
CLOUD_ENDPOINT as CLOUD_ENDPOINT2,
|
|
28
|
+
newId,
|
|
29
|
+
newVisitorId,
|
|
30
|
+
parseCookies,
|
|
31
|
+
parseForceParam,
|
|
32
|
+
parseUserAgent,
|
|
33
|
+
SDK_VERSION
|
|
34
|
+
} from "@splithub/core";
|
|
35
|
+
import { NextResponse } from "next/server";
|
|
36
|
+
var VISITOR_HEADER = "x-splithub-vid";
|
|
37
|
+
var ONE_YEAR = 60 * 60 * 24 * 365;
|
|
38
|
+
function defaultExclude(pathname) {
|
|
39
|
+
return pathname.startsWith("/_next") || pathname.startsWith("/api/") || /\.[a-z0-9]+$/i.test(pathname);
|
|
40
|
+
}
|
|
41
|
+
function matchPath(pattern, pathname) {
|
|
42
|
+
if (pattern.endsWith("*")) return pathname.startsWith(pattern.slice(0, -1));
|
|
43
|
+
return pattern === pathname || `${pattern}/` === pathname;
|
|
44
|
+
}
|
|
45
|
+
function requestContext(headers, url, visitor) {
|
|
46
|
+
const ua = parseUserAgent(headers.get("user-agent"));
|
|
47
|
+
const country = headers.get("cf-ipcountry") ?? headers.get("x-vercel-ip-country") ?? headers.get("x-country") ?? void 0;
|
|
48
|
+
const region = headers.get("x-vercel-ip-country-region") ?? headers.get("cf-region") ?? void 0;
|
|
49
|
+
const city = headers.get("x-vercel-ip-city") ?? headers.get("cf-ipcity") ?? void 0;
|
|
50
|
+
return {
|
|
51
|
+
country: country ?? void 0,
|
|
52
|
+
region: region ? decodeURIComponent(region) : void 0,
|
|
53
|
+
city: city ? decodeURIComponent(city) : void 0,
|
|
54
|
+
device: ua.device,
|
|
55
|
+
browser: ua.browser,
|
|
56
|
+
os: ua.os,
|
|
57
|
+
language: headers.get("accept-language") ?? void 0,
|
|
58
|
+
referrer: headers.get("referer") ?? void 0,
|
|
59
|
+
url,
|
|
60
|
+
cookies: parseCookies(headers.get("cookie")),
|
|
61
|
+
...visitor ? { visitor } : {}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function ingestTarget(config, origin) {
|
|
65
|
+
if (config.storage.mode === "self") return { url: new URL(config.storage.endpoint, origin).toString() };
|
|
66
|
+
return { url: config.storage.endpoint ?? CLOUD_ENDPOINT2, key: config.storage.key };
|
|
67
|
+
}
|
|
68
|
+
function splithubMiddleware(baseConfig, options = {}) {
|
|
69
|
+
const exclude = options.exclude ?? defaultExclude;
|
|
70
|
+
const trackRedirects = options.trackRedirects ?? true;
|
|
71
|
+
const useRemote = options.remote ?? true;
|
|
72
|
+
return async function middleware(request, event) {
|
|
73
|
+
const pathname = request.nextUrl.pathname;
|
|
74
|
+
if (exclude(pathname)) return NextResponse.next();
|
|
75
|
+
const config = useRemote ? applyRemoteOverrides(baseConfig, await getRemoteOverrides(baseConfig)) : baseConfig;
|
|
76
|
+
let visitorId = request.cookies.get(config.visitorKey)?.value ?? null;
|
|
77
|
+
const isNewVisitor = !visitorId;
|
|
78
|
+
if (!visitorId) visitorId = newVisitorId();
|
|
79
|
+
const overrides = parseForceParam(request.nextUrl.search);
|
|
80
|
+
const context = requestContext(request.headers, request.nextUrl.href, isNewVisitor ? "new" : "returning");
|
|
81
|
+
const requestHeaders = new Headers(request.headers);
|
|
82
|
+
requestHeaders.set(VISITOR_HEADER, visitorId);
|
|
83
|
+
let response = null;
|
|
84
|
+
const cookiesToSet = [];
|
|
85
|
+
for (const experiment of config.experiments) {
|
|
86
|
+
if (experiment.kind !== "redirect" || experiment.status !== "running" || !experiment.match) continue;
|
|
87
|
+
if (!matchPath(experiment.match, pathname)) continue;
|
|
88
|
+
const assignment = assign(config, experiment.key, visitorId, { overrides, context });
|
|
89
|
+
const variant = assignment.variant;
|
|
90
|
+
if (!variant?.to) continue;
|
|
91
|
+
if (variant.to !== pathname) {
|
|
92
|
+
const url = request.nextUrl.clone();
|
|
93
|
+
url.pathname = variant.to;
|
|
94
|
+
response = NextResponse.rewrite(url, { request: { headers: requestHeaders } });
|
|
95
|
+
}
|
|
96
|
+
const exposureCookie = `sh_x_${experiment.key}`;
|
|
97
|
+
if (trackRedirects && assignment.reason === "assigned" && request.cookies.get(exposureCookie)?.value !== variant.key) {
|
|
98
|
+
cookiesToSet.push({ name: exposureCookie, value: variant.key });
|
|
99
|
+
const target = ingestTarget(config, request.nextUrl.origin);
|
|
100
|
+
const batch = {
|
|
101
|
+
project: config.project,
|
|
102
|
+
sdk: `next/${SDK_VERSION}`,
|
|
103
|
+
events: [
|
|
104
|
+
{ id: newId("e_"), type: "exposure", exp: experiment.key, var: variant.key, vid: visitorId, sid: "edge", ts: Date.now(), url: pathname }
|
|
105
|
+
]
|
|
106
|
+
};
|
|
107
|
+
const headers = { "content-type": "application/json" };
|
|
108
|
+
if (target.key) headers.authorization = `Bearer ${target.key}`;
|
|
109
|
+
const send = fetch(target.url, { method: "POST", headers, body: JSON.stringify(batch) }).catch(() => void 0);
|
|
110
|
+
if (event?.waitUntil) event.waitUntil(send);
|
|
111
|
+
}
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
response ?? (response = NextResponse.next({ request: { headers: requestHeaders } }));
|
|
115
|
+
if (isNewVisitor) {
|
|
116
|
+
response.cookies.set(config.visitorKey, visitorId, { maxAge: ONE_YEAR, path: "/", sameSite: "lax" });
|
|
117
|
+
}
|
|
118
|
+
for (const c of cookiesToSet) response.cookies.set(c.name, c.value, { maxAge: ONE_YEAR, path: "/", sameSite: "lax" });
|
|
119
|
+
return response;
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export {
|
|
124
|
+
getRemoteOverrides,
|
|
125
|
+
clearRemoteMemo,
|
|
126
|
+
VISITOR_HEADER,
|
|
127
|
+
matchPath,
|
|
128
|
+
requestContext,
|
|
129
|
+
splithubMiddleware
|
|
130
|
+
};
|
|
131
|
+
//# sourceMappingURL=chunk-LD54CWVU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/remote.ts","../src/middleware.ts"],"sourcesContent":["import { CLOUD_ENDPOINT, fetchRemoteOverrides, resolveOverridesUrl, REMOTE_TTL_MS, type RemoteOverrides, type SplitHubConfig } from '@splithub/core';\n\ninterface MemoEntry {\n at: number;\n value: RemoteOverrides | null;\n pending: Promise<RemoteOverrides | null> | null;\n}\n\n// Module-level memo: edge isolates and Node servers keep it across requests,\n// so at most one fetch per TTL per public key.\nconst memo = new Map<string, MemoEntry>();\n\nexport interface RemoteOptions {\n ttlMs?: number;\n /** Override the fetch implementation (tests). */\n fetchImpl?: typeof fetch;\n}\n\n/**\n * Live overrides for a cloud-mode config, cached in memory for `ttlMs`\n * (default 60s). Returns null in self mode or when the cloud is unreachable\n * (the config file then applies as-is).\n */\nexport async function getRemoteOverrides(config: SplitHubConfig, options: RemoteOptions = {}): Promise<RemoteOverrides | null> {\n if (config.storage.mode !== 'cloud' || !config.storage.key) return null;\n const ttl = options.ttlMs ?? REMOTE_TTL_MS;\n const url = resolveOverridesUrl(config.storage.endpoint ?? CLOUD_ENDPOINT, config.storage.key);\n const entry = memo.get(url);\n const now = Date.now();\n if (entry && now - entry.at < ttl) return entry.value;\n if (entry?.pending) return entry.value ?? entry.pending;\n\n const pending = fetchRemoteOverrides(url, options.fetchImpl).then((value) => {\n memo.set(url, { at: Date.now(), value: value ?? entry?.value ?? null, pending: null });\n return value ?? entry?.value ?? null;\n });\n memo.set(url, { at: entry?.at ?? 0, value: entry?.value ?? null, pending });\n // Serve stale while revalidating; first call waits.\n return entry ? entry.value : pending;\n}\n\n/** Tests only. */\nexport function clearRemoteMemo(): void {\n memo.clear();\n}\n","import {\n applyRemoteOverrides,\n assign,\n CLOUD_ENDPOINT,\n newId,\n newVisitorId,\n parseCookies,\n parseForceParam,\n parseUserAgent,\n SDK_VERSION,\n type EventBatch,\n type SplitHubConfig,\n type TargetingContext,\n} from '@splithub/core';\nimport { NextResponse, type NextFetchEvent, type NextRequest } from 'next/server';\nimport { getRemoteOverrides } from './remote';\n\nexport const VISITOR_HEADER = 'x-splithub-vid';\nconst ONE_YEAR = 60 * 60 * 24 * 365;\n\nexport interface MiddlewareOptions {\n /** Return true to skip a path entirely. Defaults to `_next`, `api` and files with an extension. */\n exclude?: (pathname: string) => boolean;\n /** Send exposures for redirect experiments from the edge. Default true. */\n trackRedirects?: boolean;\n /** Apply live overrides from the cloud (cloud mode only). Default true. */\n remote?: boolean;\n}\n\nfunction defaultExclude(pathname: string): boolean {\n return pathname.startsWith('/_next') || pathname.startsWith('/api/') || /\\.[a-z0-9]+$/i.test(pathname);\n}\n\n/** `match` is an exact path, or a prefix ending with `*`. */\nexport function matchPath(pattern: string, pathname: string): boolean {\n if (pattern.endsWith('*')) return pathname.startsWith(pattern.slice(0, -1));\n return pattern === pathname || `${pattern}/` === pathname;\n}\n\n/** Targeting context from request headers: Cloudflare / Vercel geo, user agent, language, referrer, cookies. */\nexport function requestContext(headers: Headers, url: string, visitor?: 'new' | 'returning'): TargetingContext {\n const ua = parseUserAgent(headers.get('user-agent'));\n const country = headers.get('cf-ipcountry') ?? headers.get('x-vercel-ip-country') ?? headers.get('x-country') ?? undefined;\n const region = headers.get('x-vercel-ip-country-region') ?? headers.get('cf-region') ?? undefined;\n const city = headers.get('x-vercel-ip-city') ?? headers.get('cf-ipcity') ?? undefined;\n return {\n country: country ?? undefined,\n region: region ? decodeURIComponent(region) : undefined,\n city: city ? decodeURIComponent(city) : undefined,\n device: ua.device,\n browser: ua.browser,\n os: ua.os,\n language: headers.get('accept-language') ?? undefined,\n referrer: headers.get('referer') ?? undefined,\n url,\n cookies: parseCookies(headers.get('cookie')),\n ...(visitor ? { visitor } : {}),\n };\n}\n\nfunction ingestTarget(config: SplitHubConfig, origin: string): { url: string; key?: string } {\n if (config.storage.mode === 'self') return { url: new URL(config.storage.endpoint, origin).toString() };\n return { url: config.storage.endpoint ?? CLOUD_ENDPOINT, key: config.storage.key };\n}\n\n/**\n * Next.js middleware:\n * 1. ensures the `sh_vid` visitor cookie, so SSR and the client agree on variants;\n * 2. forwards the visitor id to Server Components via the `x-splithub-vid` header;\n * 3. serves redirect experiments with an invisible rewrite (URL unchanged, no flash);\n * 4. records the redirect exposure from the edge, deduplicated with a cookie.\n *\n * ```ts\n * // middleware.ts\n * import { splithubMiddleware } from '@splithub/next';\n * import config from './splithub.config';\n * export default splithubMiddleware(config);\n * export const config = { matcher: ['/((?!_next|api|.*\\\\..*).*)'] };\n * ```\n */\nexport function splithubMiddleware(baseConfig: SplitHubConfig, options: MiddlewareOptions = {}) {\n const exclude = options.exclude ?? defaultExclude;\n const trackRedirects = options.trackRedirects ?? true;\n const useRemote = options.remote ?? true;\n\n return async function middleware(request: NextRequest, event?: NextFetchEvent): Promise<NextResponse> {\n const pathname = request.nextUrl.pathname;\n if (exclude(pathname)) return NextResponse.next();\n\n const config = useRemote ? applyRemoteOverrides(baseConfig, await getRemoteOverrides(baseConfig)) : baseConfig;\n\n let visitorId = request.cookies.get(config.visitorKey)?.value ?? null;\n const isNewVisitor = !visitorId;\n if (!visitorId) visitorId = newVisitorId();\n\n const overrides = parseForceParam(request.nextUrl.search);\n const context = requestContext(request.headers, request.nextUrl.href, isNewVisitor ? 'new' : 'returning');\n const requestHeaders = new Headers(request.headers);\n requestHeaders.set(VISITOR_HEADER, visitorId);\n\n let response: NextResponse | null = null;\n const cookiesToSet: Array<{ name: string; value: string }> = [];\n\n for (const experiment of config.experiments) {\n if (experiment.kind !== 'redirect' || experiment.status !== 'running' || !experiment.match) continue;\n if (!matchPath(experiment.match, pathname)) continue;\n\n const assignment = assign(config, experiment.key, visitorId, { overrides, context });\n const variant = assignment.variant;\n if (!variant?.to) continue;\n\n if (variant.to !== pathname) {\n const url = request.nextUrl.clone();\n url.pathname = variant.to;\n response = NextResponse.rewrite(url, { request: { headers: requestHeaders } });\n }\n\n const exposureCookie = `sh_x_${experiment.key}`;\n if (trackRedirects && assignment.reason === 'assigned' && request.cookies.get(exposureCookie)?.value !== variant.key) {\n cookiesToSet.push({ name: exposureCookie, value: variant.key });\n const target = ingestTarget(config, request.nextUrl.origin);\n const batch: EventBatch = {\n project: config.project,\n sdk: `next/${SDK_VERSION}`,\n events: [\n { id: newId('e_'), type: 'exposure', exp: experiment.key, var: variant.key, vid: visitorId, sid: 'edge', ts: Date.now(), url: pathname },\n ],\n };\n const headers: Record<string, string> = { 'content-type': 'application/json' };\n if (target.key) headers.authorization = `Bearer ${target.key}`;\n const send = fetch(target.url, { method: 'POST', headers, body: JSON.stringify(batch) }).catch(() => undefined);\n if (event?.waitUntil) event.waitUntil(send);\n }\n break; // the first matching redirect experiment wins\n }\n\n response ??= NextResponse.next({ request: { headers: requestHeaders } });\n\n if (isNewVisitor) {\n response.cookies.set(config.visitorKey, visitorId, { maxAge: ONE_YEAR, path: '/', sameSite: 'lax' });\n }\n for (const c of cookiesToSet) response.cookies.set(c.name, c.value, { maxAge: ONE_YEAR, path: '/', sameSite: 'lax' });\n return response;\n };\n}\n"],"mappings":";AAAA,SAAS,gBAAgB,sBAAsB,qBAAqB,qBAAgE;AAUpI,IAAM,OAAO,oBAAI,IAAuB;AAaxC,eAAsB,mBAAmB,QAAwB,UAAyB,CAAC,GAAoC;AAC7H,MAAI,OAAO,QAAQ,SAAS,WAAW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AQ;AAAA,YACN,EAAE,IAAI,MAAM,IAAI,GAAG,MAAM,YAAY,KAAK,WAAW,KAAK,KAAK,QAAQ,KAAK,KAAK,WAAW,KAAK,QAAQ,IAAI,KAAK,IAAI,GAAG,KAAK,SAAS;AAAA,UACzI;AAAA,QACF;AACA,cAAM,UAAkC,EAAE,gBAAgB,mBAAmB;AAC7E,YAAI,OAAO,IAAK,SAAQ,gBAAgB,UAAU,OAAO,GAAG;AAC5D,cAAM,OAAO,MAAM,OAAO,KAAK,EAAE,QAAQ,QAAQ,SAAS,MAAM,KAAK,UAAU,KAAK,EAAE,CAAC,EAAE,MAAM,MAAM,MAAS;AAC9G,YAAI,OAAO,UAAW,OAAM,UAAU,IAAI;AAAA,MAC5C;AACA;AAAA,IACF;AAEA,4BAAa,aAAa,KAAK,EAAE,SAAS,EAAE,SAAS,eAAe,EAAE,CAAC;AAEvE,QAAI,cAAc;AAChB,eAAS,QAAQ,IAAI,OAAO,YAAY,WAAW,EAAE,QAAQ,UAAU,MAAM,KAAK,UAAU,MAAM,CAAC;AAAA,IACrG;AACA,eAAW,KAAK,aAAc,UAAS,QAAQ,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,UAAU,MAAM,KAAK,UAAU,MAAM,CAAC;AACpH,WAAO;AAAA,EACT;AACF;","names":["CLOUD_ENDPOINT","CLOUD_ENDPOINT"]}
|
package/dist/client.cjs
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
"use client";
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
|
|
22
|
+
// src/client.tsx
|
|
23
|
+
var client_exports = {};
|
|
24
|
+
__export(client_exports, {
|
|
25
|
+
Experiment: () => import_react3.Experiment,
|
|
26
|
+
Exposure: () => Exposure,
|
|
27
|
+
SplitHubNextProvider: () => SplitHubNextProvider,
|
|
28
|
+
SplitHubProvider: () => import_react3.SplitHubProvider,
|
|
29
|
+
Variant: () => import_react3.Variant,
|
|
30
|
+
usePageview: () => import_react3.usePageview,
|
|
31
|
+
useSplitHub: () => import_react3.useSplitHub,
|
|
32
|
+
useTrack: () => import_react3.useTrack,
|
|
33
|
+
useValue: () => import_react3.useValue,
|
|
34
|
+
useVariant: () => import_react3.useVariant
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(client_exports);
|
|
37
|
+
var import_react = require("@splithub/react");
|
|
38
|
+
var import_react2 = require("react");
|
|
39
|
+
var import_react3 = require("@splithub/react");
|
|
40
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
41
|
+
function SplitHubNextProvider({ remoteOverrides, remote, ...props }) {
|
|
42
|
+
const remoteOptions = remoteOverrides !== void 0 ? { ...remote ?? {}, overrides: remoteOverrides } : remote;
|
|
43
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.SplitHubProvider, { ...props, remote: remoteOptions });
|
|
44
|
+
}
|
|
45
|
+
function Exposure({ id }) {
|
|
46
|
+
const client = (0, import_react.useSplitHub)();
|
|
47
|
+
(0, import_react2.useEffect)(() => {
|
|
48
|
+
client.exposure(id);
|
|
49
|
+
}, [client, id]);
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
53
|
+
0 && (module.exports = {
|
|
54
|
+
Experiment,
|
|
55
|
+
Exposure,
|
|
56
|
+
SplitHubNextProvider,
|
|
57
|
+
SplitHubProvider,
|
|
58
|
+
Variant,
|
|
59
|
+
usePageview,
|
|
60
|
+
useSplitHub,
|
|
61
|
+
useTrack,
|
|
62
|
+
useValue,
|
|
63
|
+
useVariant
|
|
64
|
+
});
|
|
65
|
+
//# sourceMappingURL=client.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client.tsx"],"sourcesContent":["'use client';\n\nimport type { RemoteOverrides } from '@splithub/core';\nimport { SplitHubProvider, useSplitHub, type SplitHubProviderProps } from '@splithub/react';\nimport { useEffect } from 'react';\n\nexport { SplitHubProvider, useSplitHub, Experiment, Variant, useVariant, useValue, useTrack, usePageview } from '@splithub/react';\n\nexport interface SplitHubNextProviderProps extends SplitHubProviderProps {\n /** Overrides the server applied (`(await getSplitHub(config)).overrides`), so client and server agree. */\n remoteOverrides?: RemoteOverrides | null;\n}\n\n/**\n * Same as SplitHubProvider; pass `visitorId` from the server layout so SSR\n * and hydration agree:\n *\n * ```tsx\n * // app/layout.tsx (server component)\n * const sh = await getSplitHub(config);\n * <SplitHubNextProvider config={config} visitorId={sh.visitorId ?? undefined} remoteOverrides={sh.overrides}>{children}</SplitHubNextProvider>\n * ```\n */\nexport function SplitHubNextProvider({ remoteOverrides, remote, ...props }: SplitHubNextProviderProps) {\n const remoteOptions = remoteOverrides !== undefined ? { ...(remote ?? {}), overrides: remoteOverrides } : remote;\n return <SplitHubProvider {...props} remote={remoteOptions} />;\n}\n\n/** Records an exposure for an experiment rendered by a Server Component. */\nexport function Exposure({ id }: { id: string }) {\n const client = useSplitHub();\n useEffect(() => {\n client.exposure(id);\n }, [client, id]);\n return null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAA0E;AAC1E,IAAAA,gBAA0B;AAE1B,IAAAA,gBAAgH;AAmBvG;AAFF,SAAS,qBAAqB,EAAE,iBAAiB,QAAQ,GAAG,MAAM,GAA8B;AACrG,QAAM,gBAAgB,oBAAoB,SAAY,EAAE,GAAI,UAAU,CAAC,GAAI,WAAW,gBAAgB,IAAI;AAC1G,SAAO,4CAAC,iCAAkB,GAAG,OAAO,QAAQ,eAAe;AAC7D;AAGO,SAAS,SAAS,EAAE,GAAG,GAAmB;AAC/C,QAAM,aAAS,0BAAY;AAC3B,+BAAU,MAAM;AACd,WAAO,SAAS,EAAE;AAAA,EACpB,GAAG,CAAC,QAAQ,EAAE,CAAC;AACf,SAAO;AACT;","names":["import_react"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { RemoteOverrides } from '@splithub/core';
|
|
3
|
+
import { SplitHubProviderProps } from '@splithub/react';
|
|
4
|
+
export { Experiment, SplitHubProvider, Variant, usePageview, useSplitHub, useTrack, useValue, useVariant } from '@splithub/react';
|
|
5
|
+
|
|
6
|
+
interface SplitHubNextProviderProps extends SplitHubProviderProps {
|
|
7
|
+
/** Overrides the server applied (`(await getSplitHub(config)).overrides`), so client and server agree. */
|
|
8
|
+
remoteOverrides?: RemoteOverrides | null;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Same as SplitHubProvider; pass `visitorId` from the server layout so SSR
|
|
12
|
+
* and hydration agree:
|
|
13
|
+
*
|
|
14
|
+
* ```tsx
|
|
15
|
+
* // app/layout.tsx (server component)
|
|
16
|
+
* const sh = await getSplitHub(config);
|
|
17
|
+
* <SplitHubNextProvider config={config} visitorId={sh.visitorId ?? undefined} remoteOverrides={sh.overrides}>{children}</SplitHubNextProvider>
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
declare function SplitHubNextProvider({ remoteOverrides, remote, ...props }: SplitHubNextProviderProps): react_jsx_runtime.JSX.Element;
|
|
21
|
+
/** Records an exposure for an experiment rendered by a Server Component. */
|
|
22
|
+
declare function Exposure({ id }: {
|
|
23
|
+
id: string;
|
|
24
|
+
}): null;
|
|
25
|
+
|
|
26
|
+
export { Exposure, SplitHubNextProvider, type SplitHubNextProviderProps };
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { RemoteOverrides } from '@splithub/core';
|
|
3
|
+
import { SplitHubProviderProps } from '@splithub/react';
|
|
4
|
+
export { Experiment, SplitHubProvider, Variant, usePageview, useSplitHub, useTrack, useValue, useVariant } from '@splithub/react';
|
|
5
|
+
|
|
6
|
+
interface SplitHubNextProviderProps extends SplitHubProviderProps {
|
|
7
|
+
/** Overrides the server applied (`(await getSplitHub(config)).overrides`), so client and server agree. */
|
|
8
|
+
remoteOverrides?: RemoteOverrides | null;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Same as SplitHubProvider; pass `visitorId` from the server layout so SSR
|
|
12
|
+
* and hydration agree:
|
|
13
|
+
*
|
|
14
|
+
* ```tsx
|
|
15
|
+
* // app/layout.tsx (server component)
|
|
16
|
+
* const sh = await getSplitHub(config);
|
|
17
|
+
* <SplitHubNextProvider config={config} visitorId={sh.visitorId ?? undefined} remoteOverrides={sh.overrides}>{children}</SplitHubNextProvider>
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
declare function SplitHubNextProvider({ remoteOverrides, remote, ...props }: SplitHubNextProviderProps): react_jsx_runtime.JSX.Element;
|
|
21
|
+
/** Records an exposure for an experiment rendered by a Server Component. */
|
|
22
|
+
declare function Exposure({ id }: {
|
|
23
|
+
id: string;
|
|
24
|
+
}): null;
|
|
25
|
+
|
|
26
|
+
export { Exposure, SplitHubNextProvider, type SplitHubNextProviderProps };
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use client";
|
|
3
|
+
|
|
4
|
+
// src/client.tsx
|
|
5
|
+
import { SplitHubProvider, useSplitHub } from "@splithub/react";
|
|
6
|
+
import { useEffect } from "react";
|
|
7
|
+
import { SplitHubProvider as SplitHubProvider2, useSplitHub as useSplitHub2, Experiment, Variant, useVariant, useValue, useTrack, usePageview } from "@splithub/react";
|
|
8
|
+
import { jsx } from "react/jsx-runtime";
|
|
9
|
+
function SplitHubNextProvider({ remoteOverrides, remote, ...props }) {
|
|
10
|
+
const remoteOptions = remoteOverrides !== void 0 ? { ...remote ?? {}, overrides: remoteOverrides } : remote;
|
|
11
|
+
return /* @__PURE__ */ jsx(SplitHubProvider, { ...props, remote: remoteOptions });
|
|
12
|
+
}
|
|
13
|
+
function Exposure({ id }) {
|
|
14
|
+
const client = useSplitHub();
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
client.exposure(id);
|
|
17
|
+
}, [client, id]);
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
Experiment,
|
|
22
|
+
Exposure,
|
|
23
|
+
SplitHubNextProvider,
|
|
24
|
+
SplitHubProvider2 as SplitHubProvider,
|
|
25
|
+
Variant,
|
|
26
|
+
usePageview,
|
|
27
|
+
useSplitHub2 as useSplitHub,
|
|
28
|
+
useTrack,
|
|
29
|
+
useValue,
|
|
30
|
+
useVariant
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client.tsx"],"sourcesContent":["'use client';\n\nimport type { RemoteOverrides } from '@splithub/core';\nimport { SplitHubProvider, useSplitHub, type SplitHubProviderProps } from '@splithub/react';\nimport { useEffect } from 'react';\n\nexport { SplitHubProvider, useSplitHub, Experiment, Variant, useVariant, useValue, useTrack, usePageview } from '@splithub/react';\n\nexport interface SplitHubNextProviderProps extends SplitHubProviderProps {\n /** Overrides the server applied (`(await getSplitHub(config)).overrides`), so client and server agree. */\n remoteOverrides?: RemoteOverrides | null;\n}\n\n/**\n * Same as SplitHubProvider; pass `visitorId` from the server layout so SSR\n * and hydration agree:\n *\n * ```tsx\n * // app/layout.tsx (server component)\n * const sh = await getSplitHub(config);\n * <SplitHubNextProvider config={config} visitorId={sh.visitorId ?? undefined} remoteOverrides={sh.overrides}>{children}</SplitHubNextProvider>\n * ```\n */\nexport function SplitHubNextProvider({ remoteOverrides, remote, ...props }: SplitHubNextProviderProps) {\n const remoteOptions = remoteOverrides !== undefined ? { ...(remote ?? {}), overrides: remoteOverrides } : remote;\n return <SplitHubProvider {...props} remote={remoteOptions} />;\n}\n\n/** Records an exposure for an experiment rendered by a Server Component. */\nexport function Exposure({ id }: { id: string }) {\n const client = useSplitHub();\n useEffect(() => {\n client.exposure(id);\n }, [client, id]);\n return null;\n}\n"],"mappings":";;;;AAGA,SAAS,kBAAkB,mBAA+C;AAC1E,SAAS,iBAAiB;AAE1B,SAAS,oBAAAA,mBAAkB,eAAAC,cAAa,YAAY,SAAS,YAAY,UAAU,UAAU,mBAAmB;AAmBvG;AAFF,SAAS,qBAAqB,EAAE,iBAAiB,QAAQ,GAAG,MAAM,GAA8B;AACrG,QAAM,gBAAgB,oBAAoB,SAAY,EAAE,GAAI,UAAU,CAAC,GAAI,WAAW,gBAAgB,IAAI;AAC1G,SAAO,oBAAC,oBAAkB,GAAG,OAAO,QAAQ,eAAe;AAC7D;AAGO,SAAS,SAAS,EAAE,GAAG,GAAmB;AAC/C,QAAM,SAAS,YAAY;AAC3B,YAAU,MAAM;AACd,WAAO,SAAS,EAAE;AAAA,EACpB,GAAG,CAAC,QAAQ,EAAE,CAAC;AACf,SAAO;AACT;","names":["SplitHubProvider","useSplitHub"]}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
VISITOR_HEADER: () => VISITOR_HEADER,
|
|
24
|
+
clearRemoteMemo: () => clearRemoteMemo,
|
|
25
|
+
defineConfig: () => import_core3.defineConfig,
|
|
26
|
+
getRemoteOverrides: () => getRemoteOverrides,
|
|
27
|
+
matchPath: () => matchPath,
|
|
28
|
+
splithubMiddleware: () => splithubMiddleware
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(src_exports);
|
|
31
|
+
|
|
32
|
+
// src/middleware.ts
|
|
33
|
+
var import_core2 = require("@splithub/core");
|
|
34
|
+
var import_server = require("next/server");
|
|
35
|
+
|
|
36
|
+
// src/remote.ts
|
|
37
|
+
var import_core = require("@splithub/core");
|
|
38
|
+
var memo = /* @__PURE__ */ new Map();
|
|
39
|
+
async function getRemoteOverrides(config, options = {}) {
|
|
40
|
+
if (config.storage.mode !== "cloud" || !config.storage.key) return null;
|
|
41
|
+
const ttl = options.ttlMs ?? import_core.REMOTE_TTL_MS;
|
|
42
|
+
const url = (0, import_core.resolveOverridesUrl)(config.storage.endpoint ?? import_core.CLOUD_ENDPOINT, config.storage.key);
|
|
43
|
+
const entry = memo.get(url);
|
|
44
|
+
const now = Date.now();
|
|
45
|
+
if (entry && now - entry.at < ttl) return entry.value;
|
|
46
|
+
if (entry?.pending) return entry.value ?? entry.pending;
|
|
47
|
+
const pending = (0, import_core.fetchRemoteOverrides)(url, options.fetchImpl).then((value) => {
|
|
48
|
+
memo.set(url, { at: Date.now(), value: value ?? entry?.value ?? null, pending: null });
|
|
49
|
+
return value ?? entry?.value ?? null;
|
|
50
|
+
});
|
|
51
|
+
memo.set(url, { at: entry?.at ?? 0, value: entry?.value ?? null, pending });
|
|
52
|
+
return entry ? entry.value : pending;
|
|
53
|
+
}
|
|
54
|
+
function clearRemoteMemo() {
|
|
55
|
+
memo.clear();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// src/middleware.ts
|
|
59
|
+
var VISITOR_HEADER = "x-splithub-vid";
|
|
60
|
+
var ONE_YEAR = 60 * 60 * 24 * 365;
|
|
61
|
+
function defaultExclude(pathname) {
|
|
62
|
+
return pathname.startsWith("/_next") || pathname.startsWith("/api/") || /\.[a-z0-9]+$/i.test(pathname);
|
|
63
|
+
}
|
|
64
|
+
function matchPath(pattern, pathname) {
|
|
65
|
+
if (pattern.endsWith("*")) return pathname.startsWith(pattern.slice(0, -1));
|
|
66
|
+
return pattern === pathname || `${pattern}/` === pathname;
|
|
67
|
+
}
|
|
68
|
+
function requestContext(headers, url, visitor) {
|
|
69
|
+
const ua = (0, import_core2.parseUserAgent)(headers.get("user-agent"));
|
|
70
|
+
const country = headers.get("cf-ipcountry") ?? headers.get("x-vercel-ip-country") ?? headers.get("x-country") ?? void 0;
|
|
71
|
+
const region = headers.get("x-vercel-ip-country-region") ?? headers.get("cf-region") ?? void 0;
|
|
72
|
+
const city = headers.get("x-vercel-ip-city") ?? headers.get("cf-ipcity") ?? void 0;
|
|
73
|
+
return {
|
|
74
|
+
country: country ?? void 0,
|
|
75
|
+
region: region ? decodeURIComponent(region) : void 0,
|
|
76
|
+
city: city ? decodeURIComponent(city) : void 0,
|
|
77
|
+
device: ua.device,
|
|
78
|
+
browser: ua.browser,
|
|
79
|
+
os: ua.os,
|
|
80
|
+
language: headers.get("accept-language") ?? void 0,
|
|
81
|
+
referrer: headers.get("referer") ?? void 0,
|
|
82
|
+
url,
|
|
83
|
+
cookies: (0, import_core2.parseCookies)(headers.get("cookie")),
|
|
84
|
+
...visitor ? { visitor } : {}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function ingestTarget(config, origin) {
|
|
88
|
+
if (config.storage.mode === "self") return { url: new URL(config.storage.endpoint, origin).toString() };
|
|
89
|
+
return { url: config.storage.endpoint ?? import_core2.CLOUD_ENDPOINT, key: config.storage.key };
|
|
90
|
+
}
|
|
91
|
+
function splithubMiddleware(baseConfig, options = {}) {
|
|
92
|
+
const exclude = options.exclude ?? defaultExclude;
|
|
93
|
+
const trackRedirects = options.trackRedirects ?? true;
|
|
94
|
+
const useRemote = options.remote ?? true;
|
|
95
|
+
return async function middleware(request, event) {
|
|
96
|
+
const pathname = request.nextUrl.pathname;
|
|
97
|
+
if (exclude(pathname)) return import_server.NextResponse.next();
|
|
98
|
+
const config = useRemote ? (0, import_core2.applyRemoteOverrides)(baseConfig, await getRemoteOverrides(baseConfig)) : baseConfig;
|
|
99
|
+
let visitorId = request.cookies.get(config.visitorKey)?.value ?? null;
|
|
100
|
+
const isNewVisitor = !visitorId;
|
|
101
|
+
if (!visitorId) visitorId = (0, import_core2.newVisitorId)();
|
|
102
|
+
const overrides = (0, import_core2.parseForceParam)(request.nextUrl.search);
|
|
103
|
+
const context = requestContext(request.headers, request.nextUrl.href, isNewVisitor ? "new" : "returning");
|
|
104
|
+
const requestHeaders = new Headers(request.headers);
|
|
105
|
+
requestHeaders.set(VISITOR_HEADER, visitorId);
|
|
106
|
+
let response = null;
|
|
107
|
+
const cookiesToSet = [];
|
|
108
|
+
for (const experiment of config.experiments) {
|
|
109
|
+
if (experiment.kind !== "redirect" || experiment.status !== "running" || !experiment.match) continue;
|
|
110
|
+
if (!matchPath(experiment.match, pathname)) continue;
|
|
111
|
+
const assignment = (0, import_core2.assign)(config, experiment.key, visitorId, { overrides, context });
|
|
112
|
+
const variant = assignment.variant;
|
|
113
|
+
if (!variant?.to) continue;
|
|
114
|
+
if (variant.to !== pathname) {
|
|
115
|
+
const url = request.nextUrl.clone();
|
|
116
|
+
url.pathname = variant.to;
|
|
117
|
+
response = import_server.NextResponse.rewrite(url, { request: { headers: requestHeaders } });
|
|
118
|
+
}
|
|
119
|
+
const exposureCookie = `sh_x_${experiment.key}`;
|
|
120
|
+
if (trackRedirects && assignment.reason === "assigned" && request.cookies.get(exposureCookie)?.value !== variant.key) {
|
|
121
|
+
cookiesToSet.push({ name: exposureCookie, value: variant.key });
|
|
122
|
+
const target = ingestTarget(config, request.nextUrl.origin);
|
|
123
|
+
const batch = {
|
|
124
|
+
project: config.project,
|
|
125
|
+
sdk: `next/${import_core2.SDK_VERSION}`,
|
|
126
|
+
events: [
|
|
127
|
+
{ id: (0, import_core2.newId)("e_"), type: "exposure", exp: experiment.key, var: variant.key, vid: visitorId, sid: "edge", ts: Date.now(), url: pathname }
|
|
128
|
+
]
|
|
129
|
+
};
|
|
130
|
+
const headers = { "content-type": "application/json" };
|
|
131
|
+
if (target.key) headers.authorization = `Bearer ${target.key}`;
|
|
132
|
+
const send = fetch(target.url, { method: "POST", headers, body: JSON.stringify(batch) }).catch(() => void 0);
|
|
133
|
+
if (event?.waitUntil) event.waitUntil(send);
|
|
134
|
+
}
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
response ?? (response = import_server.NextResponse.next({ request: { headers: requestHeaders } }));
|
|
138
|
+
if (isNewVisitor) {
|
|
139
|
+
response.cookies.set(config.visitorKey, visitorId, { maxAge: ONE_YEAR, path: "/", sameSite: "lax" });
|
|
140
|
+
}
|
|
141
|
+
for (const c of cookiesToSet) response.cookies.set(c.name, c.value, { maxAge: ONE_YEAR, path: "/", sameSite: "lax" });
|
|
142
|
+
return response;
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// src/index.ts
|
|
147
|
+
var import_core3 = require("@splithub/core");
|
|
148
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
149
|
+
0 && (module.exports = {
|
|
150
|
+
VISITOR_HEADER,
|
|
151
|
+
clearRemoteMemo,
|
|
152
|
+
defineConfig,
|
|
153
|
+
getRemoteOverrides,
|
|
154
|
+
matchPath,
|
|
155
|
+
splithubMiddleware
|
|
156
|
+
});
|
|
157
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/middleware.ts","../src/remote.ts"],"sourcesContent":["export { splithubMiddleware, matchPath, VISITOR_HEADER } from './middleware';\nexport type { MiddlewareOptions } from './middleware';\nexport { getRemoteOverrides, clearRemoteMemo } from './remote';\nexport { defineConfig } from '@splithub/core';\nexport type { SplitHubConfig, SplitHubConfigInput } from '@splithub/core';\n","import {\n applyRemoteOverrides,\n assign,\n CLOUD_ENDPOINT,\n newId,\n newVisitorId,\n parseCookies,\n parseForceParam,\n parseUserAgent,\n SDK_VERSION,\n type EventBatch,\n type SplitHubConfig,\n type TargetingContext,\n} from '@splithub/core';\nimport { NextResponse, type NextFetchEvent, type NextRequest } from 'next/server';\nimport { getRemoteOverrides } from './remote';\n\nexport const VISITOR_HEADER = 'x-splithub-vid';\nconst ONE_YEAR = 60 * 60 * 24 * 365;\n\nexport interface MiddlewareOptions {\n /** Return true to skip a path entirely. Defaults to `_next`, `api` and files with an extension. */\n exclude?: (pathname: string) => boolean;\n /** Send exposures for redirect experiments from the edge. Default true. */\n trackRedirects?: boolean;\n /** Apply live overrides from the cloud (cloud mode only). Default true. */\n remote?: boolean;\n}\n\nfunction defaultExclude(pathname: string): boolean {\n return pathname.startsWith('/_next') || pathname.startsWith('/api/') || /\\.[a-z0-9]+$/i.test(pathname);\n}\n\n/** `match` is an exact path, or a prefix ending with `*`. */\nexport function matchPath(pattern: string, pathname: string): boolean {\n if (pattern.endsWith('*')) return pathname.startsWith(pattern.slice(0, -1));\n return pattern === pathname || `${pattern}/` === pathname;\n}\n\n/** Targeting context from request headers: Cloudflare / Vercel geo, user agent, language, referrer, cookies. */\nexport function requestContext(headers: Headers, url: string, visitor?: 'new' | 'returning'): TargetingContext {\n const ua = parseUserAgent(headers.get('user-agent'));\n const country = headers.get('cf-ipcountry') ?? headers.get('x-vercel-ip-country') ?? headers.get('x-country') ?? undefined;\n const region = headers.get('x-vercel-ip-country-region') ?? headers.get('cf-region') ?? undefined;\n const city = headers.get('x-vercel-ip-city') ?? headers.get('cf-ipcity') ?? undefined;\n return {\n country: country ?? undefined,\n region: region ? decodeURIComponent(region) : undefined,\n city: city ? decodeURIComponent(city) : undefined,\n device: ua.device,\n browser: ua.browser,\n os: ua.os,\n language: headers.get('accept-language') ?? undefined,\n referrer: headers.get('referer') ?? undefined,\n url,\n cookies: parseCookies(headers.get('cookie')),\n ...(visitor ? { visitor } : {}),\n };\n}\n\nfunction ingestTarget(config: SplitHubConfig, origin: string): { url: string; key?: string } {\n if (config.storage.mode === 'self') return { url: new URL(config.storage.endpoint, origin).toString() };\n return { url: config.storage.endpoint ?? CLOUD_ENDPOINT, key: config.storage.key };\n}\n\n/**\n * Next.js middleware:\n * 1. ensures the `sh_vid` visitor cookie, so SSR and the client agree on variants;\n * 2. forwards the visitor id to Server Components via the `x-splithub-vid` header;\n * 3. serves redirect experiments with an invisible rewrite (URL unchanged, no flash);\n * 4. records the redirect exposure from the edge, deduplicated with a cookie.\n *\n * ```ts\n * // middleware.ts\n * import { splithubMiddleware } from '@splithub/next';\n * import config from './splithub.config';\n * export default splithubMiddleware(config);\n * export const config = { matcher: ['/((?!_next|api|.*\\\\..*).*)'] };\n * ```\n */\nexport function splithubMiddleware(baseConfig: SplitHubConfig, options: MiddlewareOptions = {}) {\n const exclude = options.exclude ?? defaultExclude;\n const trackRedirects = options.trackRedirects ?? true;\n const useRemote = options.remote ?? true;\n\n return async function middleware(request: NextRequest, event?: NextFetchEvent): Promise<NextResponse> {\n const pathname = request.nextUrl.pathname;\n if (exclude(pathname)) return NextResponse.next();\n\n const config = useRemote ? applyRemoteOverrides(baseConfig, await getRemoteOverrides(baseConfig)) : baseConfig;\n\n let visitorId = request.cookies.get(config.visitorKey)?.value ?? null;\n const isNewVisitor = !visitorId;\n if (!visitorId) visitorId = newVisitorId();\n\n const overrides = parseForceParam(request.nextUrl.search);\n const context = requestContext(request.headers, request.nextUrl.href, isNewVisitor ? 'new' : 'returning');\n const requestHeaders = new Headers(request.headers);\n requestHeaders.set(VISITOR_HEADER, visitorId);\n\n let response: NextResponse | null = null;\n const cookiesToSet: Array<{ name: string; value: string }> = [];\n\n for (const experiment of config.experiments) {\n if (experiment.kind !== 'redirect' || experiment.status !== 'running' || !experiment.match) continue;\n if (!matchPath(experiment.match, pathname)) continue;\n\n const assignment = assign(config, experiment.key, visitorId, { overrides, context });\n const variant = assignment.variant;\n if (!variant?.to) continue;\n\n if (variant.to !== pathname) {\n const url = request.nextUrl.clone();\n url.pathname = variant.to;\n response = NextResponse.rewrite(url, { request: { headers: requestHeaders } });\n }\n\n const exposureCookie = `sh_x_${experiment.key}`;\n if (trackRedirects && assignment.reason === 'assigned' && request.cookies.get(exposureCookie)?.value !== variant.key) {\n cookiesToSet.push({ name: exposureCookie, value: variant.key });\n const target = ingestTarget(config, request.nextUrl.origin);\n const batch: EventBatch = {\n project: config.project,\n sdk: `next/${SDK_VERSION}`,\n events: [\n { id: newId('e_'), type: 'exposure', exp: experiment.key, var: variant.key, vid: visitorId, sid: 'edge', ts: Date.now(), url: pathname },\n ],\n };\n const headers: Record<string, string> = { 'content-type': 'application/json' };\n if (target.key) headers.authorization = `Bearer ${target.key}`;\n const send = fetch(target.url, { method: 'POST', headers, body: JSON.stringify(batch) }).catch(() => undefined);\n if (event?.waitUntil) event.waitUntil(send);\n }\n break; // the first matching redirect experiment wins\n }\n\n response ??= NextResponse.next({ request: { headers: requestHeaders } });\n\n if (isNewVisitor) {\n response.cookies.set(config.visitorKey, visitorId, { maxAge: ONE_YEAR, path: '/', sameSite: 'lax' });\n }\n for (const c of cookiesToSet) response.cookies.set(c.name, c.value, { maxAge: ONE_YEAR, path: '/', sameSite: 'lax' });\n return response;\n };\n}\n","import { CLOUD_ENDPOINT, fetchRemoteOverrides, resolveOverridesUrl, REMOTE_TTL_MS, type RemoteOverrides, type SplitHubConfig } from '@splithub/core';\n\ninterface MemoEntry {\n at: number;\n value: RemoteOverrides | null;\n pending: Promise<RemoteOverrides | null> | null;\n}\n\n// Module-level memo: edge isolates and Node servers keep it across requests,\n// so at most one fetch per TTL per public key.\nconst memo = new Map<string, MemoEntry>();\n\nexport interface RemoteOptions {\n ttlMs?: number;\n /** Override the fetch implementation (tests). */\n fetchImpl?: typeof fetch;\n}\n\n/**\n * Live overrides for a cloud-mode config, cached in memory for `ttlMs`\n * (default 60s). Returns null in self mode or when the cloud is unreachable\n * (the config file then applies as-is).\n */\nexport async function getRemoteOverrides(config: SplitHubConfig, options: RemoteOptions = {}): Promise<RemoteOverrides | null> {\n if (config.storage.mode !== 'cloud' || !config.storage.key) return null;\n const ttl = options.ttlMs ?? REMOTE_TTL_MS;\n const url = resolveOverridesUrl(config.storage.endpoint ?? CLOUD_ENDPOINT, config.storage.key);\n const entry = memo.get(url);\n const now = Date.now();\n if (entry && now - entry.at < ttl) return entry.value;\n if (entry?.pending) return entry.value ?? entry.pending;\n\n const pending = fetchRemoteOverrides(url, options.fetchImpl).then((value) => {\n memo.set(url, { at: Date.now(), value: value ?? entry?.value ?? null, pending: null });\n return value ?? entry?.value ?? null;\n });\n memo.set(url, { at: entry?.at ?? 0, value: entry?.value ?? null, pending });\n // Serve stale while revalidating; first call waits.\n return entry ? entry.value : pending;\n}\n\n/** Tests only. */\nexport function clearRemoteMemo(): void {\n memo.clear();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,eAaO;AACP,oBAAoE;;;ACdpE,kBAAoI;AAUpI,IAAM,OAAO,oBAAI,IAAuB;AAaxC,eAAsB,mBAAmB,QAAwB,UAAyB,CAAC,GAAoC;AAC7H,MAAI,OAAO,QAAQ,SAAS,WAAW,CAAC,OAAO,QAAQ,IAAK,QAAO;AACnE,QAAM,MAAM,QAAQ,SAAS;AAC7B,QAAM,UAAM,iCAAoB,OAAO,QAAQ,YAAY,4BAAgB,OAAO,QAAQ,GAAG;AAC7F,QAAM,QAAQ,KAAK,IAAI,GAAG;AAC1B,QAAM,MAAM,KAAK,IAAI;AACrB,MAAI,SAAS,MAAM,MAAM,KAAK,IAAK,QAAO,MAAM;AAChD,MAAI,OAAO,QAAS,QAAO,MAAM,SAAS,MAAM;AAEhD,QAAM,cAAU,kCAAqB,KAAK,QAAQ,SAAS,EAAE,KAAK,CAAC,UAAU;AAC3E,SAAK,IAAI,KAAK,EAAE,IAAI,KAAK,IAAI,GAAG,OAAO,SAAS,OAAO,SAAS,MAAM,SAAS,KAAK,CAAC;AACrF,WAAO,SAAS,OAAO,SAAS;AAAA,EAClC,CAAC;AACD,OAAK,IAAI,KAAK,EAAE,IAAI,OAAO,MAAM,GAAG,OAAO,OAAO,SAAS,MAAM,QAAQ,CAAC;AAE1E,SAAO,QAAQ,MAAM,QAAQ;AAC/B;AAGO,SAAS,kBAAwB;AACtC,OAAK,MAAM;AACb;;;AD3BO,IAAM,iBAAiB;AAC9B,IAAM,WAAW,KAAK,KAAK,KAAK;AAWhC,SAAS,eAAe,UAA2B;AACjD,SAAO,SAAS,WAAW,QAAQ,KAAK,SAAS,WAAW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, defineConfig } from '@splithub/core';
|
|
3
|
+
import { NextRequest, NextFetchEvent, NextResponse } from 'next/server';
|
|
4
|
+
export { c as clearRemoteMemo, g as getRemoteOverrides } from './remote-D7AfTTCw.cjs';
|
|
5
|
+
|
|
6
|
+
declare const VISITOR_HEADER = "x-splithub-vid";
|
|
7
|
+
interface MiddlewareOptions {
|
|
8
|
+
/** Return true to skip a path entirely. Defaults to `_next`, `api` and files with an extension. */
|
|
9
|
+
exclude?: (pathname: string) => boolean;
|
|
10
|
+
/** Send exposures for redirect experiments from the edge. Default true. */
|
|
11
|
+
trackRedirects?: boolean;
|
|
12
|
+
/** Apply live overrides from the cloud (cloud mode only). Default true. */
|
|
13
|
+
remote?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** `match` is an exact path, or a prefix ending with `*`. */
|
|
16
|
+
declare function matchPath(pattern: string, pathname: string): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Next.js middleware:
|
|
19
|
+
* 1. ensures the `sh_vid` visitor cookie, so SSR and the client agree on variants;
|
|
20
|
+
* 2. forwards the visitor id to Server Components via the `x-splithub-vid` header;
|
|
21
|
+
* 3. serves redirect experiments with an invisible rewrite (URL unchanged, no flash);
|
|
22
|
+
* 4. records the redirect exposure from the edge, deduplicated with a cookie.
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* // middleware.ts
|
|
26
|
+
* import { splithubMiddleware } from '@splithub/next';
|
|
27
|
+
* import config from './splithub.config';
|
|
28
|
+
* export default splithubMiddleware(config);
|
|
29
|
+
* export const config = { matcher: ['/((?!_next|api|.*\\..*).*)'] };
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
declare function splithubMiddleware(baseConfig: SplitHubConfig, options?: MiddlewareOptions): (request: NextRequest, event?: NextFetchEvent) => Promise<NextResponse>;
|
|
33
|
+
|
|
34
|
+
export { type MiddlewareOptions, VISITOR_HEADER, matchPath, splithubMiddleware };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { SplitHubConfig } from '@splithub/core';
|
|
2
|
+
export { SplitHubConfig, SplitHubConfigInput, defineConfig } from '@splithub/core';
|
|
3
|
+
import { NextRequest, NextFetchEvent, NextResponse } from 'next/server';
|
|
4
|
+
export { c as clearRemoteMemo, g as getRemoteOverrides } from './remote-D7AfTTCw.js';
|
|
5
|
+
|
|
6
|
+
declare const VISITOR_HEADER = "x-splithub-vid";
|
|
7
|
+
interface MiddlewareOptions {
|
|
8
|
+
/** Return true to skip a path entirely. Defaults to `_next`, `api` and files with an extension. */
|
|
9
|
+
exclude?: (pathname: string) => boolean;
|
|
10
|
+
/** Send exposures for redirect experiments from the edge. Default true. */
|
|
11
|
+
trackRedirects?: boolean;
|
|
12
|
+
/** Apply live overrides from the cloud (cloud mode only). Default true. */
|
|
13
|
+
remote?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** `match` is an exact path, or a prefix ending with `*`. */
|
|
16
|
+
declare function matchPath(pattern: string, pathname: string): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Next.js middleware:
|
|
19
|
+
* 1. ensures the `sh_vid` visitor cookie, so SSR and the client agree on variants;
|
|
20
|
+
* 2. forwards the visitor id to Server Components via the `x-splithub-vid` header;
|
|
21
|
+
* 3. serves redirect experiments with an invisible rewrite (URL unchanged, no flash);
|
|
22
|
+
* 4. records the redirect exposure from the edge, deduplicated with a cookie.
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* // middleware.ts
|
|
26
|
+
* import { splithubMiddleware } from '@splithub/next';
|
|
27
|
+
* import config from './splithub.config';
|
|
28
|
+
* export default splithubMiddleware(config);
|
|
29
|
+
* export const config = { matcher: ['/((?!_next|api|.*\\..*).*)'] };
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
declare function splithubMiddleware(baseConfig: SplitHubConfig, options?: MiddlewareOptions): (request: NextRequest, event?: NextFetchEvent) => Promise<NextResponse>;
|
|
33
|
+
|
|
34
|
+
export { type MiddlewareOptions, VISITOR_HEADER, matchPath, splithubMiddleware };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
VISITOR_HEADER,
|
|
3
|
+
clearRemoteMemo,
|
|
4
|
+
getRemoteOverrides,
|
|
5
|
+
matchPath,
|
|
6
|
+
splithubMiddleware
|
|
7
|
+
} from "./chunk-LD54CWVU.js";
|
|
8
|
+
|
|
9
|
+
// src/index.ts
|
|
10
|
+
import { defineConfig } from "@splithub/core";
|
|
11
|
+
export {
|
|
12
|
+
VISITOR_HEADER,
|
|
13
|
+
clearRemoteMemo,
|
|
14
|
+
defineConfig,
|
|
15
|
+
getRemoteOverrides,
|
|
16
|
+
matchPath,
|
|
17
|
+
splithubMiddleware
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { splithubMiddleware, matchPath, VISITOR_HEADER } from './middleware';\nexport type { MiddlewareOptions } from './middleware';\nexport { getRemoteOverrides, clearRemoteMemo } from './remote';\nexport { defineConfig } from '@splithub/core';\nexport type { SplitHubConfig, SplitHubConfigInput } from '@splithub/core';\n"],"mappings":";;;;;;;;;AAGA,SAAS,oBAAoB;","names":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SplitHubConfig, RemoteOverrides } from '@splithub/core';
|
|
2
|
+
|
|
3
|
+
interface RemoteOptions {
|
|
4
|
+
ttlMs?: number;
|
|
5
|
+
/** Override the fetch implementation (tests). */
|
|
6
|
+
fetchImpl?: typeof fetch;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Live overrides for a cloud-mode config, cached in memory for `ttlMs`
|
|
10
|
+
* (default 60s). Returns null in self mode or when the cloud is unreachable
|
|
11
|
+
* (the config file then applies as-is).
|
|
12
|
+
*/
|
|
13
|
+
declare function getRemoteOverrides(config: SplitHubConfig, options?: RemoteOptions): Promise<RemoteOverrides | null>;
|
|
14
|
+
/** Tests only. */
|
|
15
|
+
declare function clearRemoteMemo(): void;
|
|
16
|
+
|
|
17
|
+
export { clearRemoteMemo as c, getRemoteOverrides as g };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SplitHubConfig, RemoteOverrides } from '@splithub/core';
|
|
2
|
+
|
|
3
|
+
interface RemoteOptions {
|
|
4
|
+
ttlMs?: number;
|
|
5
|
+
/** Override the fetch implementation (tests). */
|
|
6
|
+
fetchImpl?: typeof fetch;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Live overrides for a cloud-mode config, cached in memory for `ttlMs`
|
|
10
|
+
* (default 60s). Returns null in self mode or when the cloud is unreachable
|
|
11
|
+
* (the config file then applies as-is).
|
|
12
|
+
*/
|
|
13
|
+
declare function getRemoteOverrides(config: SplitHubConfig, options?: RemoteOptions): Promise<RemoteOverrides | null>;
|
|
14
|
+
/** Tests only. */
|
|
15
|
+
declare function clearRemoteMemo(): void;
|
|
16
|
+
|
|
17
|
+
export { clearRemoteMemo as c, getRemoteOverrides as g };
|
package/dist/server.cjs
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/server.ts
|
|
21
|
+
var server_exports = {};
|
|
22
|
+
__export(server_exports, {
|
|
23
|
+
getRemoteOverrides: () => getRemoteOverrides,
|
|
24
|
+
getSplitHub: () => getSplitHub,
|
|
25
|
+
getVisitorId: () => getVisitorId
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(server_exports);
|
|
28
|
+
var import_core3 = require("@splithub/core");
|
|
29
|
+
|
|
30
|
+
// src/remote.ts
|
|
31
|
+
var import_core = require("@splithub/core");
|
|
32
|
+
var memo = /* @__PURE__ */ new Map();
|
|
33
|
+
async function getRemoteOverrides(config, options = {}) {
|
|
34
|
+
if (config.storage.mode !== "cloud" || !config.storage.key) return null;
|
|
35
|
+
const ttl = options.ttlMs ?? import_core.REMOTE_TTL_MS;
|
|
36
|
+
const url = (0, import_core.resolveOverridesUrl)(config.storage.endpoint ?? import_core.CLOUD_ENDPOINT, config.storage.key);
|
|
37
|
+
const entry = memo.get(url);
|
|
38
|
+
const now = Date.now();
|
|
39
|
+
if (entry && now - entry.at < ttl) return entry.value;
|
|
40
|
+
if (entry?.pending) return entry.value ?? entry.pending;
|
|
41
|
+
const pending = (0, import_core.fetchRemoteOverrides)(url, options.fetchImpl).then((value) => {
|
|
42
|
+
memo.set(url, { at: Date.now(), value: value ?? entry?.value ?? null, pending: null });
|
|
43
|
+
return value ?? entry?.value ?? null;
|
|
44
|
+
});
|
|
45
|
+
memo.set(url, { at: entry?.at ?? 0, value: entry?.value ?? null, pending });
|
|
46
|
+
return entry ? entry.value : pending;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// src/server.ts
|
|
50
|
+
var import_headers = require("next/headers");
|
|
51
|
+
|
|
52
|
+
// src/middleware.ts
|
|
53
|
+
var import_core2 = require("@splithub/core");
|
|
54
|
+
var import_server = require("next/server");
|
|
55
|
+
var VISITOR_HEADER = "x-splithub-vid";
|
|
56
|
+
var ONE_YEAR = 60 * 60 * 24 * 365;
|
|
57
|
+
function requestContext(headers2, url, visitor) {
|
|
58
|
+
const ua = (0, import_core2.parseUserAgent)(headers2.get("user-agent"));
|
|
59
|
+
const country = headers2.get("cf-ipcountry") ?? headers2.get("x-vercel-ip-country") ?? headers2.get("x-country") ?? void 0;
|
|
60
|
+
const region = headers2.get("x-vercel-ip-country-region") ?? headers2.get("cf-region") ?? void 0;
|
|
61
|
+
const city = headers2.get("x-vercel-ip-city") ?? headers2.get("cf-ipcity") ?? void 0;
|
|
62
|
+
return {
|
|
63
|
+
country: country ?? void 0,
|
|
64
|
+
region: region ? decodeURIComponent(region) : void 0,
|
|
65
|
+
city: city ? decodeURIComponent(city) : void 0,
|
|
66
|
+
device: ua.device,
|
|
67
|
+
browser: ua.browser,
|
|
68
|
+
os: ua.os,
|
|
69
|
+
language: headers2.get("accept-language") ?? void 0,
|
|
70
|
+
referrer: headers2.get("referer") ?? void 0,
|
|
71
|
+
url,
|
|
72
|
+
cookies: (0, import_core2.parseCookies)(headers2.get("cookie")),
|
|
73
|
+
...visitor ? { visitor } : {}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/server.ts
|
|
78
|
+
async function getVisitorId(config) {
|
|
79
|
+
const h = await (0, import_headers.headers)();
|
|
80
|
+
const fromHeader = h.get(VISITOR_HEADER);
|
|
81
|
+
if (fromHeader) return fromHeader;
|
|
82
|
+
const c = await (0, import_headers.cookies)();
|
|
83
|
+
return c.get(config.visitorKey)?.value ?? null;
|
|
84
|
+
}
|
|
85
|
+
async function getSplitHub(baseConfig) {
|
|
86
|
+
const [visitorId, overrides] = await Promise.all([getVisitorId(baseConfig), getRemoteOverrides(baseConfig)]);
|
|
87
|
+
const config = (0, import_core3.applyRemoteOverrides)(baseConfig, overrides);
|
|
88
|
+
const h = await (0, import_headers.headers)();
|
|
89
|
+
const context = { ...requestContext(h, h.get("x-url") ?? h.get("referer") ?? ""), ...overrides?.ctx ?? {} };
|
|
90
|
+
const control = (key) => (0, import_core3.getExperiment)(config, key)?.variants[0];
|
|
91
|
+
const opts = { context };
|
|
92
|
+
return {
|
|
93
|
+
visitorId,
|
|
94
|
+
context,
|
|
95
|
+
overrides,
|
|
96
|
+
config,
|
|
97
|
+
assignment(key) {
|
|
98
|
+
return visitorId ? (0, import_core3.assign)(config, key, visitorId, opts) : { experiment: key, variant: null, reason: "not_running" };
|
|
99
|
+
},
|
|
100
|
+
variant(key) {
|
|
101
|
+
const a = visitorId ? (0, import_core3.assign)(config, key, visitorId, opts) : null;
|
|
102
|
+
return (a?.variant ?? control(key))?.key ?? "control";
|
|
103
|
+
},
|
|
104
|
+
value(key) {
|
|
105
|
+
const a = visitorId ? (0, import_core3.assign)(config, key, visitorId, opts) : null;
|
|
106
|
+
return (a?.variant ?? control(key))?.value;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
111
|
+
0 && (module.exports = {
|
|
112
|
+
getRemoteOverrides,
|
|
113
|
+
getSplitHub,
|
|
114
|
+
getVisitorId
|
|
115
|
+
});
|
|
116
|
+
//# sourceMappingURL=server.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server.ts","../src/remote.ts","../src/middleware.ts"],"sourcesContent":["import { applyRemoteOverrides, assign, getExperiment, type Assignment, type RemoteOverrides, type SplitHubConfig, type TargetingContext } from '@splithub/core';\nimport { getRemoteOverrides } from './remote';\nimport { cookies, headers } from 'next/headers';\nimport { requestContext, VISITOR_HEADER } from './middleware';\n\nexport { getRemoteOverrides } from './remote';\n\n/**\n * Visitor id for the current request (header set by the middleware, else the\n * cookie). Null when the middleware is not installed and no cookie exists.\n */\nexport async function getVisitorId(config: SplitHubConfig): Promise<string | null> {\n const h = await headers();\n const fromHeader = h.get(VISITOR_HEADER);\n if (fromHeader) return fromHeader;\n const c = await cookies();\n return c.get(config.visitorKey)?.value ?? null;\n}\n\nexport interface ServerSplitHub {\n visitorId: string | null;\n /** Targeting context built from the request headers (geo, device, language, referrer). */\n context: TargetingContext;\n /** Live overrides applied to this request; pass them to <SplitHubNextProvider remoteOverrides={...}> so hydration agrees. */\n overrides: RemoteOverrides | null;\n /** Config with overrides applied. */\n config: SplitHubConfig;\n assignment(experimentKey: string): Assignment;\n /** Variant key; control when unassigned. No exposure is recorded on the server: render `<Exposure id>` from `@splithub/next/client`. */\n variant(experimentKey: string): string;\n value<T = unknown>(experimentKey: string): T;\n}\n\n/**\n * Assignments inside Server Components and Route Handlers:\n *\n * ```tsx\n * const sh = await getSplitHub(config);\n * const title = sh.value<string>('hero-title');\n * ```\n */\nexport async function getSplitHub(baseConfig: SplitHubConfig): Promise<ServerSplitHub> {\n const [visitorId, overrides] = await Promise.all([getVisitorId(baseConfig), getRemoteOverrides(baseConfig)]);\n const config = applyRemoteOverrides(baseConfig, overrides);\n const h = await headers();\n const context: TargetingContext = { ...requestContext(h, h.get('x-url') ?? h.get('referer') ?? ''), ...(overrides?.ctx ?? {}) };\n const control = (key: string) => getExperiment(config, key)?.variants[0];\n const opts = { context };\n return {\n visitorId,\n context,\n overrides,\n config,\n assignment(key) {\n return visitorId ? assign(config, key, visitorId, opts) : { experiment: key, variant: null, reason: 'not_running' };\n },\n variant(key) {\n const a = visitorId ? assign(config, key, visitorId, opts) : null;\n return (a?.variant ?? control(key))?.key ?? 'control';\n },\n value<T>(key: string): T {\n const a = visitorId ? assign(config, key, visitorId, opts) : null;\n return (a?.variant ?? control(key))?.value as T;\n },\n };\n}\n","import { CLOUD_ENDPOINT, fetchRemoteOverrides, resolveOverridesUrl, REMOTE_TTL_MS, type RemoteOverrides, type SplitHubConfig } from '@splithub/core';\n\ninterface MemoEntry {\n at: number;\n value: RemoteOverrides | null;\n pending: Promise<RemoteOverrides | null> | null;\n}\n\n// Module-level memo: edge isolates and Node servers keep it across requests,\n// so at most one fetch per TTL per public key.\nconst memo = new Map<string, MemoEntry>();\n\nexport interface RemoteOptions {\n ttlMs?: number;\n /** Override the fetch implementation (tests). */\n fetchImpl?: typeof fetch;\n}\n\n/**\n * Live overrides for a cloud-mode config, cached in memory for `ttlMs`\n * (default 60s). Returns null in self mode or when the cloud is unreachable\n * (the config file then applies as-is).\n */\nexport async function getRemoteOverrides(config: SplitHubConfig, options: RemoteOptions = {}): Promise<RemoteOverrides | null> {\n if (config.storage.mode !== 'cloud' || !config.storage.key) return null;\n const ttl = options.ttlMs ?? REMOTE_TTL_MS;\n const url = resolveOverridesUrl(config.storage.endpoint ?? CLOUD_ENDPOINT, config.storage.key);\n const entry = memo.get(url);\n const now = Date.now();\n if (entry && now - entry.at < ttl) return entry.value;\n if (entry?.pending) return entry.value ?? entry.pending;\n\n const pending = fetchRemoteOverrides(url, options.fetchImpl).then((value) => {\n memo.set(url, { at: Date.now(), value: value ?? entry?.value ?? null, pending: null });\n return value ?? entry?.value ?? null;\n });\n memo.set(url, { at: entry?.at ?? 0, value: entry?.value ?? null, pending });\n // Serve stale while revalidating; first call waits.\n return entry ? entry.value : pending;\n}\n\n/** Tests only. */\nexport function clearRemoteMemo(): void {\n memo.clear();\n}\n","import {\n applyRemoteOverrides,\n assign,\n CLOUD_ENDPOINT,\n newId,\n newVisitorId,\n parseCookies,\n parseForceParam,\n parseUserAgent,\n SDK_VERSION,\n type EventBatch,\n type SplitHubConfig,\n type TargetingContext,\n} from '@splithub/core';\nimport { NextResponse, type NextFetchEvent, type NextRequest } from 'next/server';\nimport { getRemoteOverrides } from './remote';\n\nexport const VISITOR_HEADER = 'x-splithub-vid';\nconst ONE_YEAR = 60 * 60 * 24 * 365;\n\nexport interface MiddlewareOptions {\n /** Return true to skip a path entirely. Defaults to `_next`, `api` and files with an extension. */\n exclude?: (pathname: string) => boolean;\n /** Send exposures for redirect experiments from the edge. Default true. */\n trackRedirects?: boolean;\n /** Apply live overrides from the cloud (cloud mode only). Default true. */\n remote?: boolean;\n}\n\nfunction defaultExclude(pathname: string): boolean {\n return pathname.startsWith('/_next') || pathname.startsWith('/api/') || /\\.[a-z0-9]+$/i.test(pathname);\n}\n\n/** `match` is an exact path, or a prefix ending with `*`. */\nexport function matchPath(pattern: string, pathname: string): boolean {\n if (pattern.endsWith('*')) return pathname.startsWith(pattern.slice(0, -1));\n return pattern === pathname || `${pattern}/` === pathname;\n}\n\n/** Targeting context from request headers: Cloudflare / Vercel geo, user agent, language, referrer, cookies. */\nexport function requestContext(headers: Headers, url: string, visitor?: 'new' | 'returning'): TargetingContext {\n const ua = parseUserAgent(headers.get('user-agent'));\n const country = headers.get('cf-ipcountry') ?? headers.get('x-vercel-ip-country') ?? headers.get('x-country') ?? undefined;\n const region = headers.get('x-vercel-ip-country-region') ?? headers.get('cf-region') ?? undefined;\n const city = headers.get('x-vercel-ip-city') ?? headers.get('cf-ipcity') ?? undefined;\n return {\n country: country ?? undefined,\n region: region ? decodeURIComponent(region) : undefined,\n city: city ? decodeURIComponent(city) : undefined,\n device: ua.device,\n browser: ua.browser,\n os: ua.os,\n language: headers.get('accept-language') ?? undefined,\n referrer: headers.get('referer') ?? undefined,\n url,\n cookies: parseCookies(headers.get('cookie')),\n ...(visitor ? { visitor } : {}),\n };\n}\n\nfunction ingestTarget(config: SplitHubConfig, origin: string): { url: string; key?: string } {\n if (config.storage.mode === 'self') return { url: new URL(config.storage.endpoint, origin).toString() };\n return { url: config.storage.endpoint ?? CLOUD_ENDPOINT, key: config.storage.key };\n}\n\n/**\n * Next.js middleware:\n * 1. ensures the `sh_vid` visitor cookie, so SSR and the client agree on variants;\n * 2. forwards the visitor id to Server Components via the `x-splithub-vid` header;\n * 3. serves redirect experiments with an invisible rewrite (URL unchanged, no flash);\n * 4. records the redirect exposure from the edge, deduplicated with a cookie.\n *\n * ```ts\n * // middleware.ts\n * import { splithubMiddleware } from '@splithub/next';\n * import config from './splithub.config';\n * export default splithubMiddleware(config);\n * export const config = { matcher: ['/((?!_next|api|.*\\\\..*).*)'] };\n * ```\n */\nexport function splithubMiddleware(baseConfig: SplitHubConfig, options: MiddlewareOptions = {}) {\n const exclude = options.exclude ?? defaultExclude;\n const trackRedirects = options.trackRedirects ?? true;\n const useRemote = options.remote ?? true;\n\n return async function middleware(request: NextRequest, event?: NextFetchEvent): Promise<NextResponse> {\n const pathname = request.nextUrl.pathname;\n if (exclude(pathname)) return NextResponse.next();\n\n const config = useRemote ? applyRemoteOverrides(baseConfig, await getRemoteOverrides(baseConfig)) : baseConfig;\n\n let visitorId = request.cookies.get(config.visitorKey)?.value ?? null;\n const isNewVisitor = !visitorId;\n if (!visitorId) visitorId = newVisitorId();\n\n const overrides = parseForceParam(request.nextUrl.search);\n const context = requestContext(request.headers, request.nextUrl.href, isNewVisitor ? 'new' : 'returning');\n const requestHeaders = new Headers(request.headers);\n requestHeaders.set(VISITOR_HEADER, visitorId);\n\n let response: NextResponse | null = null;\n const cookiesToSet: Array<{ name: string; value: string }> = [];\n\n for (const experiment of config.experiments) {\n if (experiment.kind !== 'redirect' || experiment.status !== 'running' || !experiment.match) continue;\n if (!matchPath(experiment.match, pathname)) continue;\n\n const assignment = assign(config, experiment.key, visitorId, { overrides, context });\n const variant = assignment.variant;\n if (!variant?.to) continue;\n\n if (variant.to !== pathname) {\n const url = request.nextUrl.clone();\n url.pathname = variant.to;\n response = NextResponse.rewrite(url, { request: { headers: requestHeaders } });\n }\n\n const exposureCookie = `sh_x_${experiment.key}`;\n if (trackRedirects && assignment.reason === 'assigned' && request.cookies.get(exposureCookie)?.value !== variant.key) {\n cookiesToSet.push({ name: exposureCookie, value: variant.key });\n const target = ingestTarget(config, request.nextUrl.origin);\n const batch: EventBatch = {\n project: config.project,\n sdk: `next/${SDK_VERSION}`,\n events: [\n { id: newId('e_'), type: 'exposure', exp: experiment.key, var: variant.key, vid: visitorId, sid: 'edge', ts: Date.now(), url: pathname },\n ],\n };\n const headers: Record<string, string> = { 'content-type': 'application/json' };\n if (target.key) headers.authorization = `Bearer ${target.key}`;\n const send = fetch(target.url, { method: 'POST', headers, body: JSON.stringify(batch) }).catch(() => undefined);\n if (event?.waitUntil) event.waitUntil(send);\n }\n break; // the first matching redirect experiment wins\n }\n\n response ??= NextResponse.next({ request: { headers: requestHeaders } });\n\n if (isNewVisitor) {\n response.cookies.set(config.visitorKey, visitorId, { maxAge: ONE_YEAR, path: '/', sameSite: 'lax' });\n }\n for (const c of cookiesToSet) response.cookies.set(c.name, c.value, { maxAge: ONE_YEAR, path: '/', sameSite: 'lax' });\n return response;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,eAA+I;;;ACA/I,kBAAoI;AAUpI,IAAM,OAAO,oBAAI,IAAuB;AAaxC,eAAsB,mBAAmB,QAAwB,UAAyB,CAAC,GAAoC;AAC7H,MAAI,OAAO,QAAQ,SAAS,WAAW,CAAC,OAAO,QAAQ,IAAK,QAAO;AACnE,QAAM,MAAM,QAAQ,SAAS;AAC7B,QAAM,UAAM,iCAAoB,OAAO,QAAQ,YAAY,4BAAgB,OAAO,QAAQ,GAAG;AAC7F,QAAM,QAAQ,KAAK,IAAI,GAAG;AAC1B,QAAM,MAAM,KAAK,IAAI;AACrB,MAAI,SAAS,MAAM,MAAM,KAAK,IAAK,QAAO,MAAM;AAChD,MAAI,OAAO,QAAS,QAAO,MAAM,SAAS,MAAM;AAEhD,QAAM,cAAU,kCAAqB,KAAK,QAAQ,SAAS,EAAE,KAAK,CAAC,UAAU;AAC3E,SAAK,IAAI,KAAK,EAAE,IAAI,KAAK,IAAI,GAAG,OAAO,SAAS,OAAO,SAAS,MAAM,SAAS,KAAK,CAAC;AACrF,WAAO,SAAS,OAAO,SAAS;AAAA,EAClC,CAAC;AACD,OAAK,IAAI,KAAK,EAAE,IAAI,OAAO,MAAM,GAAG,OAAO,OAAO,SAAS,M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AC,aAAa,UAAU,GAAG,mBAAmB,UAAU,CAAC,CAAC;AAC3G,QAAM,aAAS,mCAAqB,YAAY,SAAS;AACzD,QAAM,IAAI,UAAM,wBAAQ;AACxB,QAAM,UAA4B,EAAE,GAAG,eAAe,GAAG,EAAE,IAAI,OAAO,KAAK,EAAE,IAAI,SAAS,KAAK,EAAE,GAAG,GAAI,WAAW,OAAO,CAAC,EAAG;AAC9H,QAAM,UAAU,CAAC,YAAgB,4BAAc,QAAQ,GAAG,GAAG,SAAS,CAAC;AACvE,QAAM,OAAO,EAAE,QAAQ;AACvB,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW,KAAK;AACd,aAAO,gBAAY,qBAAO,QAAQ,KAAK,WAAW,IAAI,IAAI,EAAE,YAAY,KAAK,SAAS,MAAM,QAAQ,cAAc;AAAA,IACpH;AAAA,IACA,QAAQ,KAAK;AACX,YAAM,IAAI,gBAAY,qBAAO,QAAQ,KAAK,WAAW,IAAI,IAAI;AAC7D,cAAQ,GAAG,WAAW,QAAQ,GAAG,IAAI,OAAO;AAAA,IAC9C;AAAA,IACA,MAAS,KAAgB;AACvB,YAAM,IAAI,gBAAY,qBAAO,QAAQ,KAAK,WAAW,IAAI,IAAI;AAC7D,cAAQ,GAAG,WAAW,QAAQ,GAAG,IAAI;AAAA,IACvC;AAAA,EACF;AACF;","names":["import_core","import_core","headers"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { SplitHubConfig, TargetingContext, RemoteOverrides, Assignment } from '@splithub/core';
|
|
2
|
+
export { g as getRemoteOverrides } from './remote-D7AfTTCw.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Visitor id for the current request (header set by the middleware, else the
|
|
6
|
+
* cookie). Null when the middleware is not installed and no cookie exists.
|
|
7
|
+
*/
|
|
8
|
+
declare function getVisitorId(config: SplitHubConfig): Promise<string | null>;
|
|
9
|
+
interface ServerSplitHub {
|
|
10
|
+
visitorId: string | null;
|
|
11
|
+
/** Targeting context built from the request headers (geo, device, language, referrer). */
|
|
12
|
+
context: TargetingContext;
|
|
13
|
+
/** Live overrides applied to this request; pass them to <SplitHubNextProvider remoteOverrides={...}> so hydration agrees. */
|
|
14
|
+
overrides: RemoteOverrides | null;
|
|
15
|
+
/** Config with overrides applied. */
|
|
16
|
+
config: SplitHubConfig;
|
|
17
|
+
assignment(experimentKey: string): Assignment;
|
|
18
|
+
/** Variant key; control when unassigned. No exposure is recorded on the server: render `<Exposure id>` from `@splithub/next/client`. */
|
|
19
|
+
variant(experimentKey: string): string;
|
|
20
|
+
value<T = unknown>(experimentKey: string): T;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Assignments inside Server Components and Route Handlers:
|
|
24
|
+
*
|
|
25
|
+
* ```tsx
|
|
26
|
+
* const sh = await getSplitHub(config);
|
|
27
|
+
* const title = sh.value<string>('hero-title');
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
declare function getSplitHub(baseConfig: SplitHubConfig): Promise<ServerSplitHub>;
|
|
31
|
+
|
|
32
|
+
export { type ServerSplitHub, getSplitHub, getVisitorId };
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { SplitHubConfig, TargetingContext, RemoteOverrides, Assignment } from '@splithub/core';
|
|
2
|
+
export { g as getRemoteOverrides } from './remote-D7AfTTCw.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Visitor id for the current request (header set by the middleware, else the
|
|
6
|
+
* cookie). Null when the middleware is not installed and no cookie exists.
|
|
7
|
+
*/
|
|
8
|
+
declare function getVisitorId(config: SplitHubConfig): Promise<string | null>;
|
|
9
|
+
interface ServerSplitHub {
|
|
10
|
+
visitorId: string | null;
|
|
11
|
+
/** Targeting context built from the request headers (geo, device, language, referrer). */
|
|
12
|
+
context: TargetingContext;
|
|
13
|
+
/** Live overrides applied to this request; pass them to <SplitHubNextProvider remoteOverrides={...}> so hydration agrees. */
|
|
14
|
+
overrides: RemoteOverrides | null;
|
|
15
|
+
/** Config with overrides applied. */
|
|
16
|
+
config: SplitHubConfig;
|
|
17
|
+
assignment(experimentKey: string): Assignment;
|
|
18
|
+
/** Variant key; control when unassigned. No exposure is recorded on the server: render `<Exposure id>` from `@splithub/next/client`. */
|
|
19
|
+
variant(experimentKey: string): string;
|
|
20
|
+
value<T = unknown>(experimentKey: string): T;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Assignments inside Server Components and Route Handlers:
|
|
24
|
+
*
|
|
25
|
+
* ```tsx
|
|
26
|
+
* const sh = await getSplitHub(config);
|
|
27
|
+
* const title = sh.value<string>('hero-title');
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
declare function getSplitHub(baseConfig: SplitHubConfig): Promise<ServerSplitHub>;
|
|
31
|
+
|
|
32
|
+
export { type ServerSplitHub, getSplitHub, getVisitorId };
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {
|
|
2
|
+
VISITOR_HEADER,
|
|
3
|
+
getRemoteOverrides,
|
|
4
|
+
requestContext
|
|
5
|
+
} from "./chunk-LD54CWVU.js";
|
|
6
|
+
|
|
7
|
+
// src/server.ts
|
|
8
|
+
import { applyRemoteOverrides, assign, getExperiment } from "@splithub/core";
|
|
9
|
+
import { cookies, headers } from "next/headers";
|
|
10
|
+
async function getVisitorId(config) {
|
|
11
|
+
const h = await headers();
|
|
12
|
+
const fromHeader = h.get(VISITOR_HEADER);
|
|
13
|
+
if (fromHeader) return fromHeader;
|
|
14
|
+
const c = await cookies();
|
|
15
|
+
return c.get(config.visitorKey)?.value ?? null;
|
|
16
|
+
}
|
|
17
|
+
async function getSplitHub(baseConfig) {
|
|
18
|
+
const [visitorId, overrides] = await Promise.all([getVisitorId(baseConfig), getRemoteOverrides(baseConfig)]);
|
|
19
|
+
const config = applyRemoteOverrides(baseConfig, overrides);
|
|
20
|
+
const h = await headers();
|
|
21
|
+
const context = { ...requestContext(h, h.get("x-url") ?? h.get("referer") ?? ""), ...overrides?.ctx ?? {} };
|
|
22
|
+
const control = (key) => getExperiment(config, key)?.variants[0];
|
|
23
|
+
const opts = { context };
|
|
24
|
+
return {
|
|
25
|
+
visitorId,
|
|
26
|
+
context,
|
|
27
|
+
overrides,
|
|
28
|
+
config,
|
|
29
|
+
assignment(key) {
|
|
30
|
+
return visitorId ? assign(config, key, visitorId, opts) : { experiment: key, variant: null, reason: "not_running" };
|
|
31
|
+
},
|
|
32
|
+
variant(key) {
|
|
33
|
+
const a = visitorId ? assign(config, key, visitorId, opts) : null;
|
|
34
|
+
return (a?.variant ?? control(key))?.key ?? "control";
|
|
35
|
+
},
|
|
36
|
+
value(key) {
|
|
37
|
+
const a = visitorId ? assign(config, key, visitorId, opts) : null;
|
|
38
|
+
return (a?.variant ?? control(key))?.value;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
getRemoteOverrides,
|
|
44
|
+
getSplitHub,
|
|
45
|
+
getVisitorId
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["import { applyRemoteOverrides, assign, getExperiment, type Assignment, type RemoteOverrides, type SplitHubConfig, type TargetingContext } from '@splithub/core';\nimport { getRemoteOverrides } from './remote';\nimport { cookies, headers } from 'next/headers';\nimport { requestContext, VISITOR_HEADER } from './middleware';\n\nexport { getRemoteOverrides } from './remote';\n\n/**\n * Visitor id for the current request (header set by the middleware, else the\n * cookie). Null when the middleware is not installed and no cookie exists.\n */\nexport async function getVisitorId(config: SplitHubConfig): Promise<string | null> {\n const h = await headers();\n const fromHeader = h.get(VISITOR_HEADER);\n if (fromHeader) return fromHeader;\n const c = await cookies();\n return c.get(config.visitorKey)?.value ?? null;\n}\n\nexport interface ServerSplitHub {\n visitorId: string | null;\n /** Targeting context built from the request headers (geo, device, language, referrer). */\n context: TargetingContext;\n /** Live overrides applied to this request; pass them to <SplitHubNextProvider remoteOverrides={...}> so hydration agrees. */\n overrides: RemoteOverrides | null;\n /** Config with overrides applied. */\n config: SplitHubConfig;\n assignment(experimentKey: string): Assignment;\n /** Variant key; control when unassigned. No exposure is recorded on the server: render `<Exposure id>` from `@splithub/next/client`. */\n variant(experimentKey: string): string;\n value<T = unknown>(experimentKey: string): T;\n}\n\n/**\n * Assignments inside Server Components and Route Handlers:\n *\n * ```tsx\n * const sh = await getSplitHub(config);\n * const title = sh.value<string>('hero-title');\n * ```\n */\nexport async function getSplitHub(baseConfig: SplitHubConfig): Promise<ServerSplitHub> {\n const [visitorId, overrides] = await Promise.all([getVisitorId(baseConfig), getRemoteOverrides(baseConfig)]);\n const config = applyRemoteOverrides(baseConfig, overrides);\n const h = await headers();\n const context: TargetingContext = { ...requestContext(h, h.get('x-url') ?? h.get('referer') ?? ''), ...(overrides?.ctx ?? {}) };\n const control = (key: string) => getExperiment(config, key)?.variants[0];\n const opts = { context };\n return {\n visitorId,\n context,\n overrides,\n config,\n assignment(key) {\n return visitorId ? assign(config, key, visitorId, opts) : { experiment: key, variant: null, reason: 'not_running' };\n },\n variant(key) {\n const a = visitorId ? assign(config, key, visitorId, opts) : null;\n return (a?.variant ?? control(key))?.key ?? 'control';\n },\n value<T>(key: string): T {\n const a = visitorId ? assign(config, key, visitorId, opts) : null;\n return (a?.variant ?? control(key))?.value as T;\n },\n };\n}\n"],"mappings":";;;;;;;AAAA,SAAS,sBAAsB,QAAQ,qBAAwG;AAE/I,SAAS,SAAS,eAAe;AASjC,eAAsB,aAAa,QAAgD;AACjF,QAAM,IAAI,MAAM,QAAQ;AACxB,QAAM,aAAa,EAAE,IAAI,cAAc;AACvC,MAAI,WAAY,QAAO;AACvB,QAAM,IAAI,MAAM,QAAQ;AACxB,SAAO,EAAE,IAAI,OAAO,UAAU,GAAG,SAAS;AAC5C;AAwBA,eAAsB,YAAY,YAAqD;AACrF,QAAM,CAAC,WAAW,SAAS,IAAI,MAAM,QAAQ,IAAI,CAAC,aAAa,UAAU,GAAG,mBAAmB,UAAU,CAAC,CAAC;AAC3G,QAAM,SAAS,qBAAqB,YAAY,SAAS;AACzD,QAAM,IAAI,MAAM,QAAQ;AACxB,QAAM,UAA4B,EAAE,GAAG,eAAe,GAAG,EAAE,IAAI,OAAO,KAAK,EAAE,IAAI,SAAS,KAAK,EAAE,GAAG,GAAI,WAAW,OAAO,CAAC,EAAG;AAC9H,QAAM,UAAU,CAAC,QAAgB,cAAc,QAAQ,GAAG,GAAG,SAAS,CAAC;AACvE,QAAM,OAAO,EAAE,QAAQ;AACvB,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW,KAAK;AACd,aAAO,YAAY,OAAO,QAAQ,KAAK,WAAW,IAAI,IAAI,EAAE,YAAY,KAAK,SAAS,MAAM,QAAQ,cAAc;AAAA,IACpH;AAAA,IACA,QAAQ,KAAK;AACX,YAAM,IAAI,YAAY,OAAO,QAAQ,KAAK,WAAW,IAAI,IAAI;AAC7D,cAAQ,GAAG,WAAW,QAAQ,GAAG,IAAI,OAAO;AAAA,IAC9C;AAAA,IACA,MAAS,KAAgB;AACvB,YAAM,IAAI,YAAY,OAAO,QAAQ,KAAK,WAAW,IAAI,IAAI;AAC7D,cAAQ,GAAG,WAAW,QAAQ,GAAG,IAAI;AAAA,IACvC;AAAA,EACF;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@splithub/next",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "SplitHub for Next.js: middleware, server components, redirect tests and the route for your own database.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/index.cjs"
|
|
15
|
+
},
|
|
16
|
+
"./server": {
|
|
17
|
+
"types": "./dist/server.d.ts",
|
|
18
|
+
"import": "./dist/server.js",
|
|
19
|
+
"require": "./dist/server.cjs"
|
|
20
|
+
},
|
|
21
|
+
"./client": {
|
|
22
|
+
"types": "./dist/client.d.ts",
|
|
23
|
+
"import": "./dist/client.js",
|
|
24
|
+
"require": "./dist/client.cjs"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"README.md"
|
|
30
|
+
],
|
|
31
|
+
"sideEffects": false,
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"next": ">=14",
|
|
34
|
+
"react": ">=18"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@splithub/react": "0.1.1",
|
|
38
|
+
"@splithub/core": "0.1.1"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/react": "^18.3.12",
|
|
42
|
+
"next": "^15.1.0",
|
|
43
|
+
"react": "^18.3.1",
|
|
44
|
+
"react-dom": "^18.3.1",
|
|
45
|
+
"rimraf": "^5.0.5",
|
|
46
|
+
"tsup": "^8.3.5",
|
|
47
|
+
"typescript": "^5.6.3",
|
|
48
|
+
"vitest": "^4.1.11"
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
},
|
|
53
|
+
"homepage": "https://splithub.io",
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "rimraf dist && tsup",
|
|
56
|
+
"test": "vitest run",
|
|
57
|
+
"typecheck": "tsc --noEmit"
|
|
58
|
+
}
|
|
6
59
|
}
|