@ebay-dt/bonfire-next 0.1.0-alpha.0 → 0.1.0-alpha.2
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 +254 -31
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/lifecycle-provider.d.ts +2 -1
- package/dist/client/lifecycle-provider.d.ts.map +1 -1
- package/dist/client/lifecycle-provider.js +5 -7
- package/dist/client/lifecycle-provider.js.map +1 -1
- package/dist/server/agent-actions.d.ts +13 -0
- package/dist/server/agent-actions.d.ts.map +1 -0
- package/dist/server/agent-actions.js +80 -0
- package/dist/server/agent-actions.js.map +1 -0
- package/dist/server/auth-boundary.d.ts +1 -0
- package/dist/server/auth-boundary.d.ts.map +1 -1
- package/dist/server/auth-boundary.js +10 -3
- package/dist/server/auth-boundary.js.map +1 -1
- package/dist/server/auth-routes.d.ts.map +1 -1
- package/dist/server/auth-routes.js.map +1 -1
- package/dist/server/create-bonfire-next.d.ts +12 -1
- package/dist/server/create-bonfire-next.d.ts.map +1 -1
- package/dist/server/create-bonfire-next.js +41 -1
- package/dist/server/create-bonfire-next.js.map +1 -1
- package/dist/server/index.d.ts +4 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +1 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/login-page-model.d.ts.map +1 -1
- package/dist/server/login-page-model.js.map +1 -1
- package/dist/server/prototype-actions.d.ts +7 -3
- package/dist/server/prototype-actions.d.ts.map +1 -1
- package/dist/server/prototype-actions.js +84 -5
- package/dist/server/prototype-actions.js.map +1 -1
- package/dist/server/prototype-dashboard.d.ts +2 -1
- package/dist/server/prototype-dashboard.d.ts.map +1 -1
- package/dist/server/prototype-dashboard.js +3 -0
- package/dist/server/prototype-dashboard.js.map +1 -1
- package/dist/server/prototype-environment.d.ts +18 -0
- package/dist/server/prototype-environment.d.ts.map +1 -0
- package/dist/server/prototype-environment.js +67 -0
- package/dist/server/prototype-environment.js.map +1 -0
- package/dist/server/prototype-routes.d.ts.map +1 -1
- package/dist/server/prototype-routes.js +9 -4
- package/dist/server/prototype-routes.js.map +1 -1
- package/dist/server/session.d.ts.map +1 -1
- package/dist/server/session.js.map +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type PrototypeRef, type PrototypeTheme, type ThemeRegistry } from "@ebay-dt/bonfire-core";
|
|
2
|
+
import type { PrototypeCatalogLike } from "@ebay-dt/bonfire-node";
|
|
3
|
+
export type PrototypeRouteModel = {
|
|
4
|
+
ref: PrototypeRef;
|
|
5
|
+
url: string;
|
|
6
|
+
theme?: PrototypeTheme;
|
|
7
|
+
themeRegistry?: ThemeRegistry;
|
|
8
|
+
};
|
|
9
|
+
type PrototypeEnvironmentModelLoaderOptions = {
|
|
10
|
+
catalog: PrototypeCatalogLike;
|
|
11
|
+
themeRegistry?: ThemeRegistry;
|
|
12
|
+
};
|
|
13
|
+
declare function createPrototypeEnvironmentModelLoader(options: PrototypeEnvironmentModelLoaderOptions): {
|
|
14
|
+
getRouteModel: (input: PrototypeRef) => Promise<PrototypeRouteModel | null>;
|
|
15
|
+
getCurrentRouteModel: () => Promise<PrototypeRouteModel | null>;
|
|
16
|
+
};
|
|
17
|
+
export { createPrototypeEnvironmentModelLoader };
|
|
18
|
+
//# sourceMappingURL=prototype-environment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prototype-environment.d.ts","sourceRoot":"","sources":["../../src/server/prototype-environment.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,aAAa,EACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAGlE,MAAM,MAAM,mBAAmB,GAAG;IAChC,GAAG,EAAE,YAAY,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B,CAAC;AAEF,KAAK,sCAAsC,GAAG;IAC5C,OAAO,EAAE,oBAAoB,CAAC;IAC9B,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B,CAAC;AAeF,iBAAS,qCAAqC,CAC5C,OAAO,EAAE,sCAAsC;2BAGtC,YAAY,KAClB,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;gCAyCC,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;EAU3E;AAED,OAAO,EAAE,qCAAqC,EAAE,CAAC","sourcesContent":["import { headers } from \"next/headers.js\";\nimport {\n createDefaultPrototypeTheme,\n definePrototypeRef,\n parsePrototypeTheme,\n parsePrototypePath,\n type PrototypeRef,\n type PrototypeTheme,\n type ThemeRegistry,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeCatalogLike } from \"@ebay-dt/bonfire-node\";\nimport { BONFIRE_PATHNAME_HEADER } from \"./auth-boundary.js\";\n\nexport type PrototypeRouteModel = {\n ref: PrototypeRef;\n url: string;\n theme?: PrototypeTheme;\n themeRegistry?: ThemeRegistry;\n};\n\ntype PrototypeEnvironmentModelLoaderOptions = {\n catalog: PrototypeCatalogLike;\n themeRegistry?: ThemeRegistry;\n};\n\nfunction normalizeRouteTheme(\n theme: PrototypeTheme | undefined,\n themeRegistry: ThemeRegistry | undefined,\n) {\n if (theme !== undefined) {\n return parsePrototypeTheme(theme, \"theme\", themeRegistry);\n }\n if (themeRegistry !== undefined) {\n return createDefaultPrototypeTheme(themeRegistry);\n }\n return undefined;\n}\n\nfunction createPrototypeEnvironmentModelLoader(\n options: PrototypeEnvironmentModelLoaderOptions,\n) {\n async function getRouteModel(\n input: PrototypeRef,\n ): Promise<PrototypeRouteModel | null> {\n let ref: PrototypeRef;\n try {\n ref = definePrototypeRef(input);\n } catch {\n return null;\n }\n\n const summary = await options.catalog.getSummary(ref);\n if (summary === null) return null;\n\n let theme: PrototypeTheme | undefined;\n try {\n theme = normalizeRouteTheme(summary.theme, options.themeRegistry);\n } catch {\n return null;\n }\n\n return {\n ref: summary.ref,\n url: summary.url,\n ...(theme === undefined ? {} : { theme }),\n ...(options.themeRegistry === undefined\n ? {}\n : { themeRegistry: options.themeRegistry }),\n };\n }\n\n /**\n * Resolves the route model for the request currently being rendered,\n * using the pathname forwarded by `createAuthProxy` (see\n * `BONFIRE_PATHNAME_HEADER`). Intended for a shared prototype route-group\n * layout that mounts `PrototypeEnvironment` around both `AppHeader` and\n * `{children}`. The layout is entered from the dashboard and intentionally\n * remains stable while navigating within the prototype route group.\n *\n * Returns `null` when the current request is not a prototype route, or\n * when the pathname header is unavailable (for example, a request that\n * bypassed the proxy). Hosts that support soft navigation between\n * prototypes should resolve by prototype-specific route params instead.\n */\n async function getCurrentRouteModel(): Promise<PrototypeRouteModel | null> {\n const requestHeaders = await headers();\n const pathname = requestHeaders.get(BONFIRE_PATHNAME_HEADER);\n if (pathname === null) return null;\n const ref = parsePrototypePath(pathname);\n if (ref === null) return null;\n return getRouteModel(ref);\n }\n\n return { getRouteModel, getCurrentRouteModel };\n}\n\nexport { createPrototypeEnvironmentModelLoader };\n"]}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { headers } from "next/headers.js";
|
|
2
|
+
import { createDefaultPrototypeTheme, definePrototypeRef, parsePrototypeTheme, parsePrototypePath, } from "@ebay-dt/bonfire-core";
|
|
3
|
+
import { BONFIRE_PATHNAME_HEADER } from "./auth-boundary.js";
|
|
4
|
+
function normalizeRouteTheme(theme, themeRegistry) {
|
|
5
|
+
if (theme !== undefined) {
|
|
6
|
+
return parsePrototypeTheme(theme, "theme", themeRegistry);
|
|
7
|
+
}
|
|
8
|
+
if (themeRegistry !== undefined) {
|
|
9
|
+
return createDefaultPrototypeTheme(themeRegistry);
|
|
10
|
+
}
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
function createPrototypeEnvironmentModelLoader(options) {
|
|
14
|
+
async function getRouteModel(input) {
|
|
15
|
+
let ref;
|
|
16
|
+
try {
|
|
17
|
+
ref = definePrototypeRef(input);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
const summary = await options.catalog.getSummary(ref);
|
|
23
|
+
if (summary === null)
|
|
24
|
+
return null;
|
|
25
|
+
let theme;
|
|
26
|
+
try {
|
|
27
|
+
theme = normalizeRouteTheme(summary.theme, options.themeRegistry);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
ref: summary.ref,
|
|
34
|
+
url: summary.url,
|
|
35
|
+
...(theme === undefined ? {} : { theme }),
|
|
36
|
+
...(options.themeRegistry === undefined
|
|
37
|
+
? {}
|
|
38
|
+
: { themeRegistry: options.themeRegistry }),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Resolves the route model for the request currently being rendered,
|
|
43
|
+
* using the pathname forwarded by `createAuthProxy` (see
|
|
44
|
+
* `BONFIRE_PATHNAME_HEADER`). Intended for a shared prototype route-group
|
|
45
|
+
* layout that mounts `PrototypeEnvironment` around both `AppHeader` and
|
|
46
|
+
* `{children}`. The layout is entered from the dashboard and intentionally
|
|
47
|
+
* remains stable while navigating within the prototype route group.
|
|
48
|
+
*
|
|
49
|
+
* Returns `null` when the current request is not a prototype route, or
|
|
50
|
+
* when the pathname header is unavailable (for example, a request that
|
|
51
|
+
* bypassed the proxy). Hosts that support soft navigation between
|
|
52
|
+
* prototypes should resolve by prototype-specific route params instead.
|
|
53
|
+
*/
|
|
54
|
+
async function getCurrentRouteModel() {
|
|
55
|
+
const requestHeaders = await headers();
|
|
56
|
+
const pathname = requestHeaders.get(BONFIRE_PATHNAME_HEADER);
|
|
57
|
+
if (pathname === null)
|
|
58
|
+
return null;
|
|
59
|
+
const ref = parsePrototypePath(pathname);
|
|
60
|
+
if (ref === null)
|
|
61
|
+
return null;
|
|
62
|
+
return getRouteModel(ref);
|
|
63
|
+
}
|
|
64
|
+
return { getRouteModel, getCurrentRouteModel };
|
|
65
|
+
}
|
|
66
|
+
export { createPrototypeEnvironmentModelLoader };
|
|
67
|
+
//# sourceMappingURL=prototype-environment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prototype-environment.js","sourceRoot":"","sources":["../../src/server/prototype-environment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EACL,2BAA2B,EAC3B,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,GAInB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAc7D,SAAS,mBAAmB,CAC1B,KAAiC,EACjC,aAAwC;IAExC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC;IAC5D,CAAC;IACD,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;QAChC,OAAO,2BAA2B,CAAC,aAAa,CAAC,CAAC;IACpD,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,qCAAqC,CAC5C,OAA+C;IAE/C,KAAK,UAAU,aAAa,CAC1B,KAAmB;QAEnB,IAAI,GAAiB,CAAC;QACtB,IAAI,CAAC;YACH,GAAG,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;QAClC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QACtD,IAAI,OAAO,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC;QAElC,IAAI,KAAiC,CAAC;QACtC,IAAI,CAAC;YACH,KAAK,GAAG,mBAAmB,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;QACpE,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO;YACL,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;YACzC,GAAG,CAAC,OAAO,CAAC,aAAa,KAAK,SAAS;gBACrC,CAAC,CAAC,EAAE;gBACJ,CAAC,CAAC,EAAE,aAAa,EAAE,OAAO,CAAC,aAAa,EAAE,CAAC;SAC9C,CAAC;IACJ,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,KAAK,UAAU,oBAAoB;QACjC,MAAM,cAAc,GAAG,MAAM,OAAO,EAAE,CAAC;QACvC,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;QAC7D,IAAI,QAAQ,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC;QACnC,MAAM,GAAG,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAC;QACzC,IAAI,GAAG,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC;QAC9B,OAAO,aAAa,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;IAED,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,CAAC;AACjD,CAAC;AAED,OAAO,EAAE,qCAAqC,EAAE,CAAC","sourcesContent":["import { headers } from \"next/headers.js\";\nimport {\n createDefaultPrototypeTheme,\n definePrototypeRef,\n parsePrototypeTheme,\n parsePrototypePath,\n type PrototypeRef,\n type PrototypeTheme,\n type ThemeRegistry,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeCatalogLike } from \"@ebay-dt/bonfire-node\";\nimport { BONFIRE_PATHNAME_HEADER } from \"./auth-boundary.js\";\n\nexport type PrototypeRouteModel = {\n ref: PrototypeRef;\n url: string;\n theme?: PrototypeTheme;\n themeRegistry?: ThemeRegistry;\n};\n\ntype PrototypeEnvironmentModelLoaderOptions = {\n catalog: PrototypeCatalogLike;\n themeRegistry?: ThemeRegistry;\n};\n\nfunction normalizeRouteTheme(\n theme: PrototypeTheme | undefined,\n themeRegistry: ThemeRegistry | undefined,\n) {\n if (theme !== undefined) {\n return parsePrototypeTheme(theme, \"theme\", themeRegistry);\n }\n if (themeRegistry !== undefined) {\n return createDefaultPrototypeTheme(themeRegistry);\n }\n return undefined;\n}\n\nfunction createPrototypeEnvironmentModelLoader(\n options: PrototypeEnvironmentModelLoaderOptions,\n) {\n async function getRouteModel(\n input: PrototypeRef,\n ): Promise<PrototypeRouteModel | null> {\n let ref: PrototypeRef;\n try {\n ref = definePrototypeRef(input);\n } catch {\n return null;\n }\n\n const summary = await options.catalog.getSummary(ref);\n if (summary === null) return null;\n\n let theme: PrototypeTheme | undefined;\n try {\n theme = normalizeRouteTheme(summary.theme, options.themeRegistry);\n } catch {\n return null;\n }\n\n return {\n ref: summary.ref,\n url: summary.url,\n ...(theme === undefined ? {} : { theme }),\n ...(options.themeRegistry === undefined\n ? {}\n : { themeRegistry: options.themeRegistry }),\n };\n }\n\n /**\n * Resolves the route model for the request currently being rendered,\n * using the pathname forwarded by `createAuthProxy` (see\n * `BONFIRE_PATHNAME_HEADER`). Intended for a shared prototype route-group\n * layout that mounts `PrototypeEnvironment` around both `AppHeader` and\n * `{children}`. The layout is entered from the dashboard and intentionally\n * remains stable while navigating within the prototype route group.\n *\n * Returns `null` when the current request is not a prototype route, or\n * when the pathname header is unavailable (for example, a request that\n * bypassed the proxy). Hosts that support soft navigation between\n * prototypes should resolve by prototype-specific route params instead.\n */\n async function getCurrentRouteModel(): Promise<PrototypeRouteModel | null> {\n const requestHeaders = await headers();\n const pathname = requestHeaders.get(BONFIRE_PATHNAME_HEADER);\n if (pathname === null) return null;\n const ref = parsePrototypePath(pathname);\n if (ref === null) return null;\n return getRouteModel(ref);\n }\n\n return { getRouteModel, getCurrentRouteModel };\n}\n\nexport { createPrototypeEnvironmentModelLoader };\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prototype-routes.d.ts","sourceRoot":"","sources":["../../src/server/prototype-routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAEL,KAAK,eAAe,
|
|
1
|
+
{"version":3,"file":"prototype-routes.d.ts","sourceRoot":"","sources":["../../src/server/prototype-routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAEL,KAAK,eAAe,EAErB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAItE,KAAK,qBAAqB,GAAG;IAC3B,UAAU,EAAE,OAAO,CAAC;IACpB,cAAc,EAAE,MAAM,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;IACtD,SAAS,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACrC,UAAU,EAAE,MAAM,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC;CACpD,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CAChD,CAAC;AAyBF,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,qBAAqB,GAC7B,eAAe,CA2GjB","sourcesContent":["import type { NextRequest } from \"next/server.js\";\nimport {\n definePrototypeRef,\n type BonfireIdentity,\n type DirtyObservationValue,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeLifecycle } from \"@ebay-dt/bonfire-node\";\nimport type { PrototypeWatcher } from \"@ebay-dt/bonfire-node/watcher\";\n\nconst encoder = new TextEncoder();\n\ntype PrototypeRouteOptions = {\n production: boolean;\n getCurrentUser: () => Promise<BonfireIdentity | null>;\n lifecycle: PrototypeLifecycle | null;\n getWatcher: () => Promise<PrototypeWatcher | null>;\n};\n\nexport type PrototypeRoutes = {\n dirty(request: NextRequest): Promise<Response>;\n};\n\nfunction errorResponse(status: number) {\n return new Response(null, {\n status,\n headers: { \"Cache-Control\": \"no-store\" },\n });\n}\n\nfunction dirtyMessage(value: DirtyObservationValue) {\n return encoder.encode(\n `data: ${JSON.stringify({\n dirty: value.status === \"dirty\",\n ...(value.previewUrl !== undefined\n ? { previewUrl: value.previewUrl }\n : {}),\n })}\\n\\n`,\n );\n}\n\nfunction queryValue(request: NextRequest, name: string) {\n const values = request.nextUrl.searchParams.getAll(name);\n return values.length === 1 ? values[0] : null;\n}\n\nexport function createPrototypeRoutes(\n options: PrototypeRouteOptions,\n): PrototypeRoutes {\n async function dirty(request: NextRequest) {\n if (options.production) return errorResponse(404);\n\n const identity = await options.getCurrentUser();\n if (identity === null) return errorResponse(401);\n\n const login = queryValue(request, \"login\");\n const slug = queryValue(request, \"slug\");\n if (login === null || slug === null) return errorResponse(400);\n\n let ref;\n try {\n ref = definePrototypeRef({ login, slug });\n } catch {\n return errorResponse(400);\n }\n if (ref.login !== identity.login) return errorResponse(403);\n if (options.lifecycle === null) return errorResponse(404);\n\n let initial: Awaited<ReturnType<PrototypeLifecycle[\"getDirtyState\"]>>;\n try {\n initial = await options.lifecycle.getDirtyState(identity, { ref });\n } catch {\n return errorResponse(500);\n }\n if (!initial.ok) {\n switch (initial.error.code) {\n case \"unauthenticated\":\n return errorResponse(401);\n case \"forbidden\":\n return errorResponse(403);\n case \"invalid-input\":\n return errorResponse(400);\n case \"not-found\":\n return errorResponse(404);\n default:\n return errorResponse(500);\n }\n }\n\n let watcher: PrototypeWatcher | null;\n try {\n watcher = await options.getWatcher();\n } catch {\n return errorResponse(500);\n }\n if (watcher === null) return errorResponse(404);\n\n let closeStream: () => void = () => undefined;\n const stream = new ReadableStream({\n start(controller) {\n let closed = false;\n let unsubscribe: () => void = () => undefined;\n\n const close = () => {\n if (closed) return;\n closed = true;\n unsubscribe();\n request.signal.removeEventListener(\"abort\", close);\n try {\n controller.close();\n } catch {\n // The stream may already have been closed by the client.\n }\n };\n\n closeStream = close;\n request.signal.addEventListener(\"abort\", close, { once: true });\n if (request.signal.aborted) {\n close();\n return;\n }\n\n try {\n controller.enqueue(dirtyMessage(initial.value));\n unsubscribe = watcher.subscribe({\n ref,\n initial: initial.value,\n onChange(value) {\n if (closed) return;\n try {\n controller.enqueue(dirtyMessage(value));\n } catch {\n close();\n }\n },\n });\n } catch {\n close();\n }\n },\n cancel() {\n closeStream();\n },\n });\n\n return new Response(stream, {\n headers: {\n \"Cache-Control\": \"no-cache, no-store\",\n Connection: \"keep-alive\",\n \"Content-Type\": \"text/event-stream\",\n },\n });\n }\n\n return { dirty };\n}\n"]}
|
|
@@ -6,8 +6,13 @@ function errorResponse(status) {
|
|
|
6
6
|
headers: { "Cache-Control": "no-store" },
|
|
7
7
|
});
|
|
8
8
|
}
|
|
9
|
-
function dirtyMessage(
|
|
10
|
-
return encoder.encode(`data: ${JSON.stringify({
|
|
9
|
+
function dirtyMessage(value) {
|
|
10
|
+
return encoder.encode(`data: ${JSON.stringify({
|
|
11
|
+
dirty: value.status === "dirty",
|
|
12
|
+
...(value.previewUrl !== undefined
|
|
13
|
+
? { previewUrl: value.previewUrl }
|
|
14
|
+
: {}),
|
|
15
|
+
})}\n\n`);
|
|
11
16
|
}
|
|
12
17
|
function queryValue(request, name) {
|
|
13
18
|
const values = request.nextUrl.searchParams.getAll(name);
|
|
@@ -90,7 +95,7 @@ export function createPrototypeRoutes(options) {
|
|
|
90
95
|
return;
|
|
91
96
|
}
|
|
92
97
|
try {
|
|
93
|
-
controller.enqueue(dirtyMessage(initial.value
|
|
98
|
+
controller.enqueue(dirtyMessage(initial.value));
|
|
94
99
|
unsubscribe = watcher.subscribe({
|
|
95
100
|
ref,
|
|
96
101
|
initial: initial.value,
|
|
@@ -98,7 +103,7 @@ export function createPrototypeRoutes(options) {
|
|
|
98
103
|
if (closed)
|
|
99
104
|
return;
|
|
100
105
|
try {
|
|
101
|
-
controller.enqueue(dirtyMessage(value
|
|
106
|
+
controller.enqueue(dirtyMessage(value));
|
|
102
107
|
}
|
|
103
108
|
catch {
|
|
104
109
|
close();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prototype-routes.js","sourceRoot":"","sources":["../../src/server/prototype-routes.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,
|
|
1
|
+
{"version":3,"file":"prototype-routes.js","sourceRoot":"","sources":["../../src/server/prototype-routes.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,GAGnB,MAAM,uBAAuB,CAAC;AAI/B,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAalC,SAAS,aAAa,CAAC,MAAc;IACnC,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE;QACxB,MAAM;QACN,OAAO,EAAE,EAAE,eAAe,EAAE,UAAU,EAAE;KACzC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,YAAY,CAAC,KAA4B;IAChD,OAAO,OAAO,CAAC,MAAM,CACnB,SAAS,IAAI,CAAC,SAAS,CAAC;QACtB,KAAK,EAAE,KAAK,CAAC,MAAM,KAAK,OAAO;QAC/B,GAAG,CAAC,KAAK,CAAC,UAAU,KAAK,SAAS;YAChC,CAAC,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,EAAE;YAClC,CAAC,CAAC,EAAE,CAAC;KACR,CAAC,MAAM,CACT,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,OAAoB,EAAE,IAAY;IACpD,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACzD,OAAO,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AAC,CAAC;gBAEF,WAAW,GAAG,KAAK,CAAC;gBACpB,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;gBAChE,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;oBAC3B,KAAK,EAAE,CAAC;oBACR,OAAO;gBACT,CAAC;gBAED,IAAI,CAAC;oBACH,UAAU,CAAC,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;oBAChD,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC;wBAC9B,GAAG;wBACH,OAAO,EAAE,OAAO,CAAC,KAAK;wBACtB,QAAQ,CAAC,KAAK;4BACZ,IAAI,MAAM;gCAAE,OAAO;4BACnB,IAAI,CAAC;gCACH,UAAU,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;4BAC1C,CAAC;4BAAC,MAAM,CAAC;gCACP,KAAK,EAAE,CAAC;4BACV,CAAC;wBACH,CAAC;qBACF,CAAC,CAAC;gBACL,CAAC;gBAAC,MAAM,CAAC;oBACP,KAAK,EAAE,CAAC;gBACV,CAAC;YACH,CAAC;YACD,MAAM;gBACJ,WAAW,EAAE,CAAC;YAChB,CAAC;SACF,CAAC,CAAC;QAEH,OAAO,IAAI,QAAQ,CAAC,MAAM,EAAE;YAC1B,OAAO,EAAE;gBACP,eAAe,EAAE,oBAAoB;gBACrC,UAAU,EAAE,YAAY;gBACxB,cAAc,EAAE,mBAAmB;aACpC;SACF,CAAC,CAAC;IACL,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,CAAC;AACnB,CAAC","sourcesContent":["import type { NextRequest } from \"next/server.js\";\nimport {\n definePrototypeRef,\n type BonfireIdentity,\n type DirtyObservationValue,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeLifecycle } from \"@ebay-dt/bonfire-node\";\nimport type { PrototypeWatcher } from \"@ebay-dt/bonfire-node/watcher\";\n\nconst encoder = new TextEncoder();\n\ntype PrototypeRouteOptions = {\n production: boolean;\n getCurrentUser: () => Promise<BonfireIdentity | null>;\n lifecycle: PrototypeLifecycle | null;\n getWatcher: () => Promise<PrototypeWatcher | null>;\n};\n\nexport type PrototypeRoutes = {\n dirty(request: NextRequest): Promise<Response>;\n};\n\nfunction errorResponse(status: number) {\n return new Response(null, {\n status,\n headers: { \"Cache-Control\": \"no-store\" },\n });\n}\n\nfunction dirtyMessage(value: DirtyObservationValue) {\n return encoder.encode(\n `data: ${JSON.stringify({\n dirty: value.status === \"dirty\",\n ...(value.previewUrl !== undefined\n ? { previewUrl: value.previewUrl }\n : {}),\n })}\\n\\n`,\n );\n}\n\nfunction queryValue(request: NextRequest, name: string) {\n const values = request.nextUrl.searchParams.getAll(name);\n return values.length === 1 ? values[0] : null;\n}\n\nexport function createPrototypeRoutes(\n options: PrototypeRouteOptions,\n): PrototypeRoutes {\n async function dirty(request: NextRequest) {\n if (options.production) return errorResponse(404);\n\n const identity = await options.getCurrentUser();\n if (identity === null) return errorResponse(401);\n\n const login = queryValue(request, \"login\");\n const slug = queryValue(request, \"slug\");\n if (login === null || slug === null) return errorResponse(400);\n\n let ref;\n try {\n ref = definePrototypeRef({ login, slug });\n } catch {\n return errorResponse(400);\n }\n if (ref.login !== identity.login) return errorResponse(403);\n if (options.lifecycle === null) return errorResponse(404);\n\n let initial: Awaited<ReturnType<PrototypeLifecycle[\"getDirtyState\"]>>;\n try {\n initial = await options.lifecycle.getDirtyState(identity, { ref });\n } catch {\n return errorResponse(500);\n }\n if (!initial.ok) {\n switch (initial.error.code) {\n case \"unauthenticated\":\n return errorResponse(401);\n case \"forbidden\":\n return errorResponse(403);\n case \"invalid-input\":\n return errorResponse(400);\n case \"not-found\":\n return errorResponse(404);\n default:\n return errorResponse(500);\n }\n }\n\n let watcher: PrototypeWatcher | null;\n try {\n watcher = await options.getWatcher();\n } catch {\n return errorResponse(500);\n }\n if (watcher === null) return errorResponse(404);\n\n let closeStream: () => void = () => undefined;\n const stream = new ReadableStream({\n start(controller) {\n let closed = false;\n let unsubscribe: () => void = () => undefined;\n\n const close = () => {\n if (closed) return;\n closed = true;\n unsubscribe();\n request.signal.removeEventListener(\"abort\", close);\n try {\n controller.close();\n } catch {\n // The stream may already have been closed by the client.\n }\n };\n\n closeStream = close;\n request.signal.addEventListener(\"abort\", close, { once: true });\n if (request.signal.aborted) {\n close();\n return;\n }\n\n try {\n controller.enqueue(dirtyMessage(initial.value));\n unsubscribe = watcher.subscribe({\n ref,\n initial: initial.value,\n onChange(value) {\n if (closed) return;\n try {\n controller.enqueue(dirtyMessage(value));\n } catch {\n close();\n }\n },\n });\n } catch {\n close();\n }\n },\n cancel() {\n closeStream();\n },\n });\n\n return new Response(stream, {\n headers: {\n \"Cache-Control\": \"no-cache, no-store\",\n Connection: \"keep-alive\",\n \"Content-Type\": \"text/event-stream\",\n },\n });\n }\n\n return { dirty };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/server/session.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,uBAAuB,CAAC;AAE/B,eAAO,MAAM,wBAAwB,QAAoB,CAAC;AAC1D,eAAO,MAAM,eAAe,QAA2B,CAAC;AACxD,eAAO,MAAM,iBAAiB,UAAU,CAAC;AAGzC,KAAK,kBAAkB,GAAG;IACxB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;IACjD,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,GAAG,IAAI,CAAC;IACtE,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B,CAAC;AAEF,KAAK,oBAAoB,GAAG;IAC1B,QAAQ,EAAE,OAA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,EAAE,oBAAoB,GAAG,IAAI,CAAC;IACtE,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B,CAAC;AAEF,KAAK,oBAAoB,GAAG;IAC1B,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,KAAK,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,KAAK,0BAA0B,GAAG,MAAM,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAEpE,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,YACE,OAAO,SAA2D,EAInE;CACF;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,OAAO,2BAQ5C;AAsBD,wBAAsB,WAAW,CAC/B,QAAQ,EAAE,eAAe,EACzB,MAAM,EAAE,OAAO,EACf,GAAG,SAAa,mBAUjB;AAED,wBAAsB,aAAa,CACjC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,OAAO,EACf,GAAG,SAAa;;;;UAiBjB;AAED,KAAK,qBAAqB,GAAG;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,UAAU,EAAE,OAAO,CAAC;IACpB,cAAc,CAAC,EAAE,0BAA0B,CAAC;CAC7C,CAAC;AAEF,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,qBAAqB;;;;;;;8BAuB1B,eAAe;;EAyBvD","sourcesContent":["import { cookies as nextCookies } from \"next/headers.js\";\nimport { jwtVerify, SignJWT } from \"jose\";\nimport {\n getSessionCookieName,\n parseBonfireIdentity,\n type BonfireIdentity,\n} from \"@ebay-dt/bonfire-core\";\n\nexport const SESSION_DURATION_SECONDS = 30 * 24 * 60 * 60;\nexport const SESSION_MAX_AGE = SESSION_DURATION_SECONDS;\nexport const SESSION_ALGORITHM = \"HS256\";\nconst MINIMUM_SECRET_BYTES = 32;\n\ntype SessionCookieStore = {\n get(name: string): { value: string } | undefined;\n set(name: string, value: string, options: SessionCookieOptions): void;\n delete(name: string): void;\n};\n\ntype SessionCookieOptions = {\n httpOnly: boolean;\n secure: boolean;\n sameSite: \"lax\";\n path: string;\n maxAge: number;\n};\n\ntype SessionCookieStoreProvider = () => Promise<SessionCookieStore>;\n\nexport class SessionSecretError extends Error {\n constructor(\n message = \"BF_SESSION_SECRET must contain at least 32 UTF-8 bytes\",\n ) {\n super(message);\n this.name = \"SessionSecretError\";\n }\n}\n\nexport function getSessionKey(secret: unknown) {\n if (\n typeof secret !== \"string\" ||\n Buffer.byteLength(secret, \"utf8\") < MINIMUM_SECRET_BYTES\n ) {\n throw new SessionSecretError();\n }\n return new TextEncoder().encode(secret);\n}\n\nfunction identityPayload(payload: Record<string, unknown>) {\n const allowedClaims = new Set([\"login\", \"name\", \"avatar_url\", \"exp\"]);\n const unexpectedClaim = Object.keys(payload).find(\n (claim) => !allowedClaims.has(claim),\n );\n if (unexpectedClaim) throw new Error(\"unexpected session claim\");\n if (typeof payload.exp !== \"number\" || !Number.isInteger(payload.exp)) {\n throw new Error(\"invalid session expiration\");\n }\n\n const identity = parseBonfireIdentity({\n login: payload.login,\n ...(Object.hasOwn(payload, \"name\") ? { name: payload.name } : {}),\n avatar_url: payload.avatar_url,\n });\n return { ...identity, exp: payload.exp } satisfies BonfireIdentity & {\n exp: number;\n };\n}\n\nexport async function signSession(\n identity: BonfireIdentity,\n secret: unknown,\n now = Date.now(),\n) {\n const key = getSessionKey(secret);\n const parsedIdentity = parseBonfireIdentity(identity);\n const expiration = Math.floor(now / 1000) + SESSION_DURATION_SECONDS;\n\n return new SignJWT(parsedIdentity)\n .setProtectedHeader({ alg: SESSION_ALGORITHM })\n .setExpirationTime(expiration)\n .sign(key);\n}\n\nexport async function verifySession(\n token: string,\n secret: unknown,\n now = Date.now(),\n) {\n const key = getSessionKey(secret);\n try {\n const result = await jwtVerify(token, key, {\n algorithms: [SESSION_ALGORITHM],\n currentDate: new Date(now),\n });\n const payload = identityPayload(result.payload);\n return {\n login: payload.login,\n name: payload.name,\n avatar_url: payload.avatar_url,\n };\n } catch {\n return null;\n }\n}\n\ntype SessionAdapterOptions = {\n appId: string;\n sessionSecret: string | undefined;\n production: boolean;\n getCookieStore?: SessionCookieStoreProvider;\n};\n\nexport function createSessionAdapter(options: SessionAdapterOptions) {\n const cookieName = getSessionCookieName(options.appId);\n if (!options.production && options.sessionSecret === undefined) {\n throw new SessionSecretError(\n \"BF_SESSION_SECRET is required for development sessions\",\n );\n }\n if (options.sessionSecret !== undefined) getSessionKey(options.sessionSecret);\n\n const getCookieStore =\n options.getCookieStore ??\n (() => nextCookies() as Promise<SessionCookieStore>);\n\n async function getSession() {\n if (options.production && options.sessionSecret === undefined) return null;\n if (options.sessionSecret === undefined) return null;\n\n const cookieStore = await getCookieStore();\n const token = cookieStore.get(cookieName)?.value;\n if (!token) return null;\n return verifySession(token, options.sessionSecret);\n }\n\n async function createSession(identity: BonfireIdentity) {\n if (options.production && options.sessionSecret === undefined) return;\n if (options.sessionSecret === undefined) {\n throw new SessionSecretError(\n \"BF_SESSION_SECRET is required for development sessions\",\n );\n }\n\n const token = await signSession(identity, options.sessionSecret);\n const cookieStore = await getCookieStore();\n cookieStore.set(cookieName, token, {\n httpOnly: true,\n secure: options.production,\n sameSite: \"lax\",\n path: \"/\",\n maxAge: SESSION_MAX_AGE,\n });\n }\n\n async function clearSession() {\n const cookieStore = await getCookieStore();\n cookieStore.delete(cookieName);\n }\n\n return { cookieName, getSession, createSession, clearSession };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/server/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC1C,OAAO,EACL,oBAAoB,EACpB,oBAAoB,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,WAAW,GAAG,MAAM,cAAc,EAAE,CAAC;QAC3C,WAAW,CAAC,GAAG,CAAC,UAAU,EAAE,KAAK,EAAE;YACjC,QAAQ,EAAE,IAAI;YACd,MAAM,EAAE,OAAO,CAAC,UAAU;YAC1B,QAAQ,EAAE,KAAK;YACf,IAAI,EAAE,GAAG;YACT,MAAM,EAAE,eAAe;SACxB,CAAC,CAAC;IACL,CAAC;IAED,KAAK,UAAU,YAAY;QACzB,MAAM,WAAW,GAAG,MAAM,cAAc,EAAE,CAAC;QAC3C,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IACjC,CAAC;IAED,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC;AACjE,CAAC","sourcesContent":["import { cookies as nextCookies } from \"next/headers.js\";\nimport { jwtVerify, SignJWT } from \"jose\";\nimport {\n getSessionCookieName,\n parseBonfireIdentity,\n type BonfireIdentity,\n} from \"@ebay-dt/bonfire-core\";\n\nexport const SESSION_DURATION_SECONDS = 30 * 24 * 60 * 60;\nexport const SESSION_MAX_AGE = SESSION_DURATION_SECONDS;\nexport const SESSION_ALGORITHM = \"HS256\";\nconst MINIMUM_SECRET_BYTES = 32;\n\ntype SessionCookieStore = {\n get(name: string): { value: string } | undefined;\n set(name: string, value: string, options: SessionCookieOptions): void;\n delete(name: string): void;\n};\n\ntype SessionCookieOptions = {\n httpOnly: boolean;\n secure: boolean;\n sameSite: \"lax\";\n path: string;\n maxAge: number;\n};\n\ntype SessionCookieStoreProvider = () => Promise<SessionCookieStore>;\n\nexport class SessionSecretError extends Error {\n constructor(\n message = \"BF_SESSION_SECRET must contain at least 32 UTF-8 bytes\",\n ) {\n super(message);\n this.name = \"SessionSecretError\";\n }\n}\n\nexport function getSessionKey(secret: unknown) {\n if (\n typeof secret !== \"string\" ||\n Buffer.byteLength(secret, \"utf8\") < MINIMUM_SECRET_BYTES\n ) {\n throw new SessionSecretError();\n }\n return new TextEncoder().encode(secret);\n}\n\nfunction identityPayload(payload: Record<string, unknown>) {\n const allowedClaims = new Set([\"login\", \"name\", \"avatar_url\", \"exp\"]);\n const unexpectedClaim = Object.keys(payload).find(\n (claim) => !allowedClaims.has(claim),\n );\n if (unexpectedClaim) throw new Error(\"unexpected session claim\");\n if (typeof payload.exp !== \"number\" || !Number.isInteger(payload.exp)) {\n throw new Error(\"invalid session expiration\");\n }\n\n const identity = parseBonfireIdentity({\n login: payload.login,\n ...(Object.hasOwn(payload, \"name\") ? { name: payload.name } : {}),\n avatar_url: payload.avatar_url,\n });\n return { ...identity, exp: payload.exp } satisfies BonfireIdentity & {\n exp: number;\n };\n}\n\nexport async function signSession(\n identity: BonfireIdentity,\n secret: unknown,\n now = Date.now(),\n) {\n const key = getSessionKey(secret);\n const parsedIdentity = parseBonfireIdentity(identity);\n const expiration = Math.floor(now / 1000) + SESSION_DURATION_SECONDS;\n\n return new SignJWT(parsedIdentity)\n .setProtectedHeader({ alg: SESSION_ALGORITHM })\n .setExpirationTime(expiration)\n .sign(key);\n}\n\nexport async function verifySession(\n token: string,\n secret: unknown,\n now = Date.now(),\n) {\n const key = getSessionKey(secret);\n try {\n const result = await jwtVerify(token, key, {\n algorithms: [SESSION_ALGORITHM],\n currentDate: new Date(now),\n });\n const payload = identityPayload(result.payload);\n return {\n login: payload.login,\n name: payload.name,\n avatar_url: payload.avatar_url,\n };\n } catch {\n return null;\n }\n}\n\ntype SessionAdapterOptions = {\n appId: string;\n sessionSecret: string | undefined;\n production: boolean;\n getCookieStore?: SessionCookieStoreProvider;\n};\n\nexport function createSessionAdapter(options: SessionAdapterOptions) {\n const cookieName = getSessionCookieName(options.appId);\n if (!options.production && options.sessionSecret === undefined) {\n throw new SessionSecretError(\n \"BF_SESSION_SECRET is required for development sessions\",\n );\n }\n if (options.sessionSecret !== undefined) getSessionKey(options.sessionSecret);\n\n const getCookieStore =\n options.getCookieStore ??\n (() => nextCookies() as Promise<SessionCookieStore>);\n\n async function getSession() {\n if (options.production && options.sessionSecret === undefined) return null;\n if (options.sessionSecret === undefined) return null;\n\n const cookieStore = await getCookieStore();\n const token = cookieStore.get(cookieName)?.value;\n if (!token) return null;\n return verifySession(token, options.sessionSecret);\n }\n\n async function createSession(identity: BonfireIdentity) {\n if (options.production && options.sessionSecret === undefined) return;\n if (options.sessionSecret === undefined) {\n throw new SessionSecretError(\n \"BF_SESSION_SECRET is required for development sessions\",\n );\n }\n\n const token = await signSession(identity, options.sessionSecret);\n const cookieStore = await getCookieStore();\n cookieStore.set(cookieName, token, {\n httpOnly: true,\n secure: options.production,\n sameSite: \"lax\",\n path: \"/\",\n maxAge: SESSION_MAX_AGE,\n });\n }\n\n async function clearSession() {\n const cookieStore = await getCookieStore();\n cookieStore.delete(cookieName);\n }\n\n return { cookieName, getSession, createSession, clearSession };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ebay-dt/bonfire-next",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.2",
|
|
4
4
|
"description": "Next.js server integration for Bonfire.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -31,18 +31,18 @@
|
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@ebay-dt/bonfire-core": "0.1.0-alpha.
|
|
35
|
-
"@ebay-dt/bonfire-node": "0.1.0-alpha.
|
|
34
|
+
"@ebay-dt/bonfire-core": "0.1.0-alpha.2",
|
|
35
|
+
"@ebay-dt/bonfire-node": "0.1.0-alpha.2",
|
|
36
36
|
"jose": "^6.1.3"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@ebay-dt/bonfire-react": "0.1.0-alpha.
|
|
39
|
+
"@ebay-dt/bonfire-react": "0.1.0-alpha.2",
|
|
40
40
|
"next": ">=16.2 <17",
|
|
41
41
|
"react": ">=19.2 <20",
|
|
42
42
|
"react-dom": ">=19.2 <20"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@ebay-dt/bonfire-react": "0.1.0-alpha.
|
|
45
|
+
"@ebay-dt/bonfire-react": "0.1.0-alpha.2",
|
|
46
46
|
"@repo/eslint-config": "0.0.0",
|
|
47
47
|
"@repo/typescript-config": "0.0.0",
|
|
48
48
|
"@types/node": "20.19.43",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"vitest": "^5.0.0"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
|
-
"build": "tsc -p tsconfig.build.json",
|
|
59
|
+
"build": "tsc -p tsconfig.build.json && node ../../scripts/embed-source-map-sources.mjs dist",
|
|
60
60
|
"dev": "tsc -p tsconfig.build.json --watch --preserveWatchOutput",
|
|
61
61
|
"check": "tsc -p tsconfig.json --noEmit",
|
|
62
62
|
"lint": "eslint .",
|