@fewchurs/next 0.0.0-stage → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,28 @@
1
+ import { DeviceIdResolver } from './identity.js';
2
+ import '@fewchurs/react/core';
3
+
4
+ interface HandlerOptions {
5
+ apiKey?: string;
6
+ baseUrl?: string;
7
+ /** Where the handler is mounted, when it is not `/api/fewchurs`. */
8
+ apiPath?: string;
9
+ /** Return a stable, hashed id for the signed-in visitor so votes follow the account. */
10
+ deviceId?: DeviceIdResolver;
11
+ }
12
+ type RouteParams = {
13
+ route?: string[];
14
+ };
15
+ type RouteContext = {
16
+ params: Promise<RouteParams>;
17
+ };
18
+ type RouteHandler = (request: Request, context: RouteContext) => Promise<Response>;
19
+ declare function createHandler(options?: HandlerOptions): {
20
+ GET: RouteHandler;
21
+ POST: RouteHandler;
22
+ DELETE: RouteHandler;
23
+ };
24
+ declare const GET: RouteHandler;
25
+ declare const POST: RouteHandler;
26
+ declare const DELETE: RouteHandler;
27
+
28
+ export { DELETE, GET, type HandlerOptions, POST, type RouteHandler, createHandler };
@@ -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/handler.ts
21
+ var handler_exports = {};
22
+ __export(handler_exports, {
23
+ DELETE: () => DELETE,
24
+ GET: () => GET,
25
+ POST: () => POST,
26
+ createHandler: () => createHandler
27
+ });
28
+ module.exports = __toCommonJS(handler_exports);
29
+ var import_server_only2 = require("server-only");
30
+ var import_core2 = require("@fewchurs/react/core");
31
+
32
+ // src/config.ts
33
+ var import_server_only = require("server-only");
34
+ var import_core = require("@fewchurs/react/core");
35
+ var DEFAULT_API_PATH = "/api/fewchurs";
36
+ function resolveApiKey(apiKey) {
37
+ return apiKey ?? process.env.FEWCHURS_API_KEY;
38
+ }
39
+ function resolveBaseUrl(baseUrl) {
40
+ return baseUrl ?? process.env.FEWCHURS_BASE_URL ?? import_core.DEFAULT_BASE_URL;
41
+ }
42
+ function resolveApiPath(apiPath) {
43
+ return (apiPath ?? process.env.FEWCHURS_API_PATH ?? DEFAULT_API_PATH).replace(/\/$/, "");
44
+ }
45
+
46
+ // src/version.ts
47
+ var SDK_VERSION = "1.0.1";
48
+
49
+ // src/constants.ts
50
+ var DEVICE_ID_COOKIE = "fewchurs_did";
51
+ var DEVICE_ID_MAX_AGE = 60 * 60 * 24 * 365;
52
+ var SDK_HEADER = `next/${SDK_VERSION}`;
53
+
54
+ // src/handler.ts
55
+ var ALLOWED = [
56
+ { method: "GET", pattern: /^config$/ },
57
+ { method: "GET", pattern: /^features$/ },
58
+ { method: "POST", pattern: /^features$/ },
59
+ { method: "GET", pattern: /^features\/[^/]+$/ },
60
+ { method: "POST", pattern: /^features\/[^/]+\/vote$/ },
61
+ { method: "DELETE", pattern: /^features\/[^/]+\/vote$/ },
62
+ { method: "POST", pattern: /^features\/[^/]+\/follow$/ },
63
+ { method: "DELETE", pattern: /^features\/[^/]+\/follow$/ },
64
+ { method: "GET", pattern: /^features\/[^/]+\/comments$/ },
65
+ { method: "POST", pattern: /^comments$/ }
66
+ ];
67
+ var DEVICE_ID_PATTERN = /^[A-Za-z0-9_-]{8,128}$/;
68
+ function createHandler(options = {}) {
69
+ async function handle(request, context) {
70
+ const path = await routePath(request, context, resolveApiPath(options.apiPath));
71
+ if (!ALLOWED.some((route) => route.method === request.method && route.pattern.test(path))) {
72
+ return json({ error: { code: "not_found", message: "Unknown Fewchurs route." } }, 404);
73
+ }
74
+ const apiKey = resolveApiKey(options.apiKey);
75
+ if (!apiKey) {
76
+ console.error(
77
+ "[fewchurs] No API key. Set FEWCHURS_API_KEY, or pass apiKey to createHandler()."
78
+ );
79
+ return json({ error: { code: "internal", message: "Fewchurs is not configured." } }, 500);
80
+ }
81
+ const cookieValue = readCookie(request, DEVICE_ID_COOKIE);
82
+ const custom = options.deviceId ? await options.deviceId() : null;
83
+ const deviceId = custom ?? cookieValue ?? claimedDeviceId(request) ?? (0, import_core2.createDeviceId)();
84
+ const target = `${resolveBaseUrl(options.baseUrl)}/${path}${new URL(request.url).search}`;
85
+ const headers = {
86
+ Authorization: `Bearer ${apiKey}`,
87
+ "X-Device-Id": deviceId,
88
+ "X-Fewchurs-Sdk": request.headers.get("x-fewchurs-sdk") ?? SDK_HEADER,
89
+ Accept: "application/json"
90
+ };
91
+ const language = request.headers.get("accept-language");
92
+ if (language) headers["Accept-Language"] = language;
93
+ const body = request.method === "GET" ? void 0 : await request.text();
94
+ if (body) headers["Content-Type"] = "application/json";
95
+ let upstream;
96
+ try {
97
+ upstream = await fetch(target, { method: request.method, headers, body, cache: "no-store" });
98
+ } catch {
99
+ return json({ error: { code: "internal", message: "Could not reach Fewchurs." } }, 502);
100
+ }
101
+ const response = new Response(await upstream.text(), {
102
+ status: upstream.status,
103
+ headers: { "Content-Type": "application/json", "Cache-Control": "no-store" }
104
+ });
105
+ if (!custom && deviceId !== cookieValue) {
106
+ response.headers.append("Set-Cookie", serializeCookie(deviceId));
107
+ }
108
+ return response;
109
+ }
110
+ return { GET: handle, POST: handle, DELETE: handle };
111
+ }
112
+ var defaultHandler = createHandler();
113
+ var GET = defaultHandler.GET;
114
+ var POST = defaultHandler.POST;
115
+ var DELETE = defaultHandler.DELETE;
116
+ async function routePath(request, context, apiPath) {
117
+ const params = await context?.params;
118
+ if (params?.route?.length) return params.route.map(encodeURIComponent).join("/");
119
+ const { pathname } = new URL(request.url);
120
+ const index = pathname.indexOf(apiPath);
121
+ return index === -1 ? "" : pathname.slice(index + apiPath.length).replace(/^\//, "");
122
+ }
123
+ function claimedDeviceId(request) {
124
+ const claimed = request.headers.get("x-device-id");
125
+ return claimed && DEVICE_ID_PATTERN.test(claimed) ? claimed : null;
126
+ }
127
+ function readCookie(request, name) {
128
+ const header = request.headers.get("cookie");
129
+ if (!header) return null;
130
+ const match = header.match(new RegExp(`(?:^|;\\s*)${name}=([^;]*)`));
131
+ return match?.[1] ? decodeURIComponent(match[1]) : null;
132
+ }
133
+ function serializeCookie(deviceId) {
134
+ const parts = [
135
+ `${DEVICE_ID_COOKIE}=${encodeURIComponent(deviceId)}`,
136
+ "Path=/",
137
+ `Max-Age=${DEVICE_ID_MAX_AGE}`,
138
+ "HttpOnly",
139
+ "SameSite=Lax"
140
+ ];
141
+ if (process.env.NODE_ENV === "production") parts.push("Secure");
142
+ return parts.join("; ");
143
+ }
144
+ function json(body, status) {
145
+ return new Response(JSON.stringify(body), {
146
+ status,
147
+ headers: { "Content-Type": "application/json", "Cache-Control": "no-store" }
148
+ });
149
+ }
150
+ // Annotate the CommonJS export names for ESM import in node:
151
+ 0 && (module.exports = {
152
+ DELETE,
153
+ GET,
154
+ POST,
155
+ createHandler
156
+ });
157
+ //# sourceMappingURL=handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/handler.ts","../src/config.ts","../src/version.ts","../src/constants.ts"],"sourcesContent":["import \"server-only\";\nimport { createDeviceId } from \"@fewchurs/react/core\";\nimport { resolveApiKey, resolveApiPath, resolveBaseUrl } from \"./config\";\nimport { DEVICE_ID_COOKIE, DEVICE_ID_MAX_AGE, SDK_HEADER } from \"./constants\";\nimport type { DeviceIdResolver } from \"./identity\";\n\nexport interface HandlerOptions {\n apiKey?: string;\n baseUrl?: string;\n /** Where the handler is mounted, when it is not `/api/fewchurs`. */\n apiPath?: string;\n /** Return a stable, hashed id for the signed-in visitor so votes follow the account. */\n deviceId?: DeviceIdResolver;\n}\n\ntype RouteParams = { route?: string[] };\n\n/** What Next passes: a Promise in 15, a plain object in 14. Both are awaited the same way. */\ntype IncomingContext = { params?: RouteParams | Promise<RouteParams> };\n\n// Next 15's route check wants a required second argument whose `params` is a Promise. The\n// handler itself takes `IncomingContext`, so Next 14's plain object still works at runtime.\ntype RouteContext = { params: Promise<RouteParams> };\n\nexport type RouteHandler = (request: Request, context: RouteContext) => Promise<Response>;\n\n/** Only the endpoints the board needs: everything else is a 404, not a proxy to the API. */\nconst ALLOWED: Array<{ method: string; pattern: RegExp }> = [\n { method: \"GET\", pattern: /^config$/ },\n { method: \"GET\", pattern: /^features$/ },\n { method: \"POST\", pattern: /^features$/ },\n { method: \"GET\", pattern: /^features\\/[^/]+$/ },\n { method: \"POST\", pattern: /^features\\/[^/]+\\/vote$/ },\n { method: \"DELETE\", pattern: /^features\\/[^/]+\\/vote$/ },\n { method: \"POST\", pattern: /^features\\/[^/]+\\/follow$/ },\n { method: \"DELETE\", pattern: /^features\\/[^/]+\\/follow$/ },\n { method: \"GET\", pattern: /^features\\/[^/]+\\/comments$/ },\n { method: \"POST\", pattern: /^comments$/ },\n];\n\nconst DEVICE_ID_PATTERN = /^[A-Za-z0-9_-]{8,128}$/;\n\nexport function createHandler(options: HandlerOptions = {}): {\n GET: RouteHandler;\n POST: RouteHandler;\n DELETE: RouteHandler;\n} {\n async function handle(request: Request, context?: IncomingContext): Promise<Response> {\n const path = await routePath(request, context, resolveApiPath(options.apiPath));\n\n if (!ALLOWED.some((route) => route.method === request.method && route.pattern.test(path))) {\n return json({ error: { code: \"not_found\", message: \"Unknown Fewchurs route.\" } }, 404);\n }\n\n const apiKey = resolveApiKey(options.apiKey);\n if (!apiKey) {\n console.error(\n \"[fewchurs] No API key. Set FEWCHURS_API_KEY, or pass apiKey to createHandler().\",\n );\n return json({ error: { code: \"internal\", message: \"Fewchurs is not configured.\" } }, 500);\n }\n\n const cookieValue = readCookie(request, DEVICE_ID_COOKIE);\n const custom = options.deviceId ? await options.deviceId() : null;\n const deviceId = custom ?? cookieValue ?? claimedDeviceId(request) ?? createDeviceId();\n\n const target = `${resolveBaseUrl(options.baseUrl)}/${path}${new URL(request.url).search}`;\n const headers: Record<string, string> = {\n Authorization: `Bearer ${apiKey}`,\n \"X-Device-Id\": deviceId,\n \"X-Fewchurs-Sdk\": request.headers.get(\"x-fewchurs-sdk\") ?? SDK_HEADER,\n Accept: \"application/json\",\n };\n const language = request.headers.get(\"accept-language\");\n if (language) headers[\"Accept-Language\"] = language;\n\n const body = request.method === \"GET\" ? undefined : await request.text();\n if (body) headers[\"Content-Type\"] = \"application/json\";\n\n let upstream: Response;\n try {\n upstream = await fetch(target, { method: request.method, headers, body, cache: \"no-store\" });\n } catch {\n return json({ error: { code: \"internal\", message: \"Could not reach Fewchurs.\" } }, 502);\n }\n\n const response = new Response(await upstream.text(), {\n status: upstream.status,\n headers: { \"Content-Type\": \"application/json\", \"Cache-Control\": \"no-store\" },\n });\n\n // A visitor keeps the same id across requests without the browser ever seeing the key,\n // and an httpOnly cookie means page scripts cannot read or change it either.\n if (!custom && deviceId !== cookieValue) {\n response.headers.append(\"Set-Cookie\", serializeCookie(deviceId));\n }\n\n return response;\n }\n\n return { GET: handle, POST: handle, DELETE: handle };\n}\n\nconst defaultHandler = createHandler();\n\nexport const GET = defaultHandler.GET;\nexport const POST = defaultHandler.POST;\nexport const DELETE = defaultHandler.DELETE;\n\nasync function routePath(\n request: Request,\n context: IncomingContext | undefined,\n apiPath: string,\n): Promise<string> {\n const params = await context?.params;\n if (params?.route?.length) return params.route.map(encodeURIComponent).join(\"/\");\n\n const { pathname } = new URL(request.url);\n const index = pathname.indexOf(apiPath);\n return index === -1 ? \"\" : pathname.slice(index + apiPath.length).replace(/^\\//, \"\");\n}\n\n/**\n * The first request from a server-rendered board carries the id the page was rendered with,\n * so adopting it keeps the server's `hasVoted` answers and the browser's in agreement.\n */\nfunction claimedDeviceId(request: Request): string | null {\n const claimed = request.headers.get(\"x-device-id\");\n return claimed && DEVICE_ID_PATTERN.test(claimed) ? claimed : null;\n}\n\nfunction readCookie(request: Request, name: string): string | null {\n const header = request.headers.get(\"cookie\");\n if (!header) return null;\n const match = header.match(new RegExp(`(?:^|;\\\\s*)${name}=([^;]*)`));\n return match?.[1] ? decodeURIComponent(match[1]) : null;\n}\n\nfunction serializeCookie(deviceId: string): string {\n const parts = [\n `${DEVICE_ID_COOKIE}=${encodeURIComponent(deviceId)}`,\n \"Path=/\",\n `Max-Age=${DEVICE_ID_MAX_AGE}`,\n \"HttpOnly\",\n \"SameSite=Lax\",\n ];\n if (process.env.NODE_ENV === \"production\") parts.push(\"Secure\");\n return parts.join(\"; \");\n}\n\nfunction json(body: unknown, status: number): Response {\n return new Response(JSON.stringify(body), {\n status,\n headers: { \"Content-Type\": \"application/json\", \"Cache-Control\": \"no-store\" },\n });\n}\n","import \"server-only\";\nimport { createFewchursClient, DEFAULT_BASE_URL, type FewchursClient } from \"@fewchurs/react/core\";\n\nexport const DEFAULT_API_PATH = \"/api/fewchurs\";\n\nexport interface ServerConfig {\n apiKey?: string;\n baseUrl?: string;\n language?: string;\n}\n\nexport function resolveApiKey(apiKey?: string): string | undefined {\n return apiKey ?? process.env.FEWCHURS_API_KEY;\n}\n\nexport function resolveBaseUrl(baseUrl?: string): string {\n return baseUrl ?? process.env.FEWCHURS_BASE_URL ?? DEFAULT_BASE_URL;\n}\n\nexport function resolveApiPath(apiPath?: string): string {\n return (apiPath ?? process.env.FEWCHURS_API_PATH ?? DEFAULT_API_PATH).replace(/\\/$/, \"\");\n}\n\nexport function serverClient(deviceId: string | null, config: ServerConfig = {}): FewchursClient {\n const apiKey = resolveApiKey(config.apiKey);\n if (!apiKey) {\n throw new Error(\n \"[fewchurs] No API key. Set FEWCHURS_API_KEY in your environment, or pass apiKey to the server component or createHandler().\",\n );\n }\n\n return createFewchursClient({\n apiKey,\n baseUrl: resolveBaseUrl(config.baseUrl),\n deviceId,\n language: config.language,\n });\n}\n","// Generated by tools/stamp-version.mjs from @fewchurs/next's package.json. Do not edit by hand.\nexport const SDK_VERSION = \"1.0.1\";\n","import { SDK_VERSION } from \"./version\";\n\nexport const DEVICE_ID_COOKIE = \"fewchurs_did\";\nexport const DEVICE_ID_MAX_AGE = 60 * 60 * 24 * 365;\nexport { SDK_VERSION };\nexport const SDK_HEADER = `next/${SDK_VERSION}`;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,sBAAO;AACP,IAAAC,eAA+B;;;ACD/B,yBAAO;AACP,kBAA4E;AAErE,IAAM,mBAAmB;AAQzB,SAAS,cAAc,QAAqC;AACjE,SAAO,UAAU,QAAQ,IAAI;AAC/B;AAEO,SAAS,eAAe,SAA0B;AACvD,SAAO,WAAW,QAAQ,IAAI,qBAAqB;AACrD;AAEO,SAAS,eAAe,SAA0B;AACvD,UAAQ,WAAW,QAAQ,IAAI,qBAAqB,kBAAkB,QAAQ,OAAO,EAAE;AACzF;;;ACpBO,IAAM,cAAc;;;ACCpB,IAAM,mBAAmB;AACzB,IAAM,oBAAoB,KAAK,KAAK,KAAK;AAEzC,IAAM,aAAa,QAAQ,WAAW;;;AHsB7C,IAAM,UAAsD;AAAA,EAC1D,EAAE,QAAQ,OAAO,SAAS,WAAW;AAAA,EACrC,EAAE,QAAQ,OAAO,SAAS,aAAa;AAAA,EACvC,EAAE,QAAQ,QAAQ,SAAS,aAAa;AAAA,EACxC,EAAE,QAAQ,OAAO,SAAS,oBAAoB;AAAA,EAC9C,EAAE,QAAQ,QAAQ,SAAS,0BAA0B;AAAA,EACrD,EAAE,QAAQ,UAAU,SAAS,0BAA0B;AAAA,EACvD,EAAE,QAAQ,QAAQ,SAAS,4BAA4B;AAAA,EACvD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S,QAAQ,QAAQ,IAAI,QAAQ;AAC3C,MAAI,CAAC,OAAQ,QAAO;AACpB,QAAM,QAAQ,OAAO,MAAM,IAAI,OAAO,cAAc,IAAI,UAAU,CAAC;AACnE,SAAO,QAAQ,CAAC,IAAI,mBAAmB,MAAM,CAAC,CAAC,IAAI;AACrD;AAEA,SAAS,gBAAgB,UAA0B;AACjD,QAAM,QAAQ;AAAA,IACZ,GAAG,gBAAgB,IAAI,mBAAmB,QAAQ,CAAC;AAAA,IACnD;AAAA,IACA,WAAW,iBAAiB;AAAA,IAC5B;AAAA,IACA;AAAA,EACF;AACA,MAAI,QAAQ,IAAI,aAAa,aAAc,OAAM,KAAK,QAAQ;AAC9D,SAAO,MAAM,KAAK,IAAI;AACxB;AAEA,SAAS,KAAK,MAAe,QAA0B;AACrD,SAAO,IAAI,SAAS,KAAK,UAAU,IAAI,GAAG;AAAA,IACxC;AAAA,IACA,SAAS,EAAE,gBAAgB,oBAAoB,iBAAiB,WAAW;AAAA,EAC7E,CAAC;AACH;","names":["import_server_only","import_core"]}
@@ -0,0 +1,14 @@
1
+ import {
2
+ DELETE,
3
+ GET,
4
+ POST,
5
+ createHandler
6
+ } from "./chunk-KPJHLDQU.mjs";
7
+ import "./chunk-W6QR6DEB.mjs";
8
+ export {
9
+ DELETE,
10
+ GET,
11
+ POST,
12
+ createHandler
13
+ };
14
+ //# sourceMappingURL=handler.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,26 @@
1
+ export { createDeviceId } from '@fewchurs/react/core';
2
+
3
+ declare const DEVICE_ID_COOKIE = "fewchurs_did";
4
+ declare const DEVICE_ID_MAX_AGE: number;
5
+
6
+ type DeviceIdResolver = () => string | Promise<string>;
7
+ /** The visitor's id, or null when nothing has been stored for them yet. */
8
+ declare function readDeviceId(): Promise<string | null>;
9
+ /**
10
+ * Reads the cookie, falling back to a fresh id. The value is not persisted here: a server
11
+ * component cannot set cookies, so the route handler stores it on the first request instead.
12
+ */
13
+ declare function resolveDeviceId(custom?: DeviceIdResolver): Promise<string>;
14
+ declare function deviceIdCookie(deviceId: string): {
15
+ name: string;
16
+ value: string;
17
+ options: {
18
+ httpOnly: true;
19
+ sameSite: "lax";
20
+ path: string;
21
+ maxAge: number;
22
+ secure: boolean;
23
+ };
24
+ };
25
+
26
+ export { DEVICE_ID_COOKIE, DEVICE_ID_MAX_AGE, type DeviceIdResolver, deviceIdCookie, readDeviceId, resolveDeviceId };
@@ -0,0 +1,26 @@
1
+ export { createDeviceId } from '@fewchurs/react/core';
2
+
3
+ declare const DEVICE_ID_COOKIE = "fewchurs_did";
4
+ declare const DEVICE_ID_MAX_AGE: number;
5
+
6
+ type DeviceIdResolver = () => string | Promise<string>;
7
+ /** The visitor's id, or null when nothing has been stored for them yet. */
8
+ declare function readDeviceId(): Promise<string | null>;
9
+ /**
10
+ * Reads the cookie, falling back to a fresh id. The value is not persisted here: a server
11
+ * component cannot set cookies, so the route handler stores it on the first request instead.
12
+ */
13
+ declare function resolveDeviceId(custom?: DeviceIdResolver): Promise<string>;
14
+ declare function deviceIdCookie(deviceId: string): {
15
+ name: string;
16
+ value: string;
17
+ options: {
18
+ httpOnly: true;
19
+ sameSite: "lax";
20
+ path: string;
21
+ maxAge: number;
22
+ secure: boolean;
23
+ };
24
+ };
25
+
26
+ export { DEVICE_ID_COOKIE, DEVICE_ID_MAX_AGE, type DeviceIdResolver, deviceIdCookie, readDeviceId, resolveDeviceId };
@@ -0,0 +1,74 @@
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/identity.ts
21
+ var identity_exports = {};
22
+ __export(identity_exports, {
23
+ DEVICE_ID_COOKIE: () => DEVICE_ID_COOKIE,
24
+ DEVICE_ID_MAX_AGE: () => DEVICE_ID_MAX_AGE,
25
+ createDeviceId: () => import_core.createDeviceId,
26
+ deviceIdCookie: () => deviceIdCookie,
27
+ readDeviceId: () => readDeviceId,
28
+ resolveDeviceId: () => resolveDeviceId
29
+ });
30
+ module.exports = __toCommonJS(identity_exports);
31
+ var import_server_only = require("server-only");
32
+ var import_headers = require("next/headers");
33
+ var import_core = require("@fewchurs/react/core");
34
+
35
+ // src/version.ts
36
+ var SDK_VERSION = "1.0.1";
37
+
38
+ // src/constants.ts
39
+ var DEVICE_ID_COOKIE = "fewchurs_did";
40
+ var DEVICE_ID_MAX_AGE = 60 * 60 * 24 * 365;
41
+ var SDK_HEADER = `next/${SDK_VERSION}`;
42
+
43
+ // src/identity.ts
44
+ async function readDeviceId() {
45
+ const store = await (0, import_headers.cookies)();
46
+ return store.get(DEVICE_ID_COOKIE)?.value ?? null;
47
+ }
48
+ async function resolveDeviceId(custom) {
49
+ if (custom) return custom();
50
+ return await readDeviceId() ?? (0, import_core.createDeviceId)();
51
+ }
52
+ function deviceIdCookie(deviceId) {
53
+ return {
54
+ name: DEVICE_ID_COOKIE,
55
+ value: deviceId,
56
+ options: {
57
+ httpOnly: true,
58
+ sameSite: "lax",
59
+ path: "/",
60
+ maxAge: DEVICE_ID_MAX_AGE,
61
+ secure: process.env.NODE_ENV === "production"
62
+ }
63
+ };
64
+ }
65
+ // Annotate the CommonJS export names for ESM import in node:
66
+ 0 && (module.exports = {
67
+ DEVICE_ID_COOKIE,
68
+ DEVICE_ID_MAX_AGE,
69
+ createDeviceId,
70
+ deviceIdCookie,
71
+ readDeviceId,
72
+ resolveDeviceId
73
+ });
74
+ //# sourceMappingURL=identity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/identity.ts","../src/version.ts","../src/constants.ts"],"sourcesContent":["import \"server-only\";\nimport { cookies } from \"next/headers\";\nimport { createDeviceId } from \"@fewchurs/react/core\";\nimport { DEVICE_ID_COOKIE, DEVICE_ID_MAX_AGE } from \"./constants\";\n\nexport { DEVICE_ID_COOKIE, DEVICE_ID_MAX_AGE };\n\nexport type DeviceIdResolver = () => string | Promise<string>;\n\n/** The visitor's id, or null when nothing has been stored for them yet. */\nexport async function readDeviceId(): Promise<string | null> {\n const store = await cookies();\n return store.get(DEVICE_ID_COOKIE)?.value ?? null;\n}\n\n/**\n * Reads the cookie, falling back to a fresh id. The value is not persisted here: a server\n * component cannot set cookies, so the route handler stores it on the first request instead.\n */\nexport async function resolveDeviceId(custom?: DeviceIdResolver): Promise<string> {\n if (custom) return custom();\n return (await readDeviceId()) ?? createDeviceId();\n}\n\nexport function deviceIdCookie(deviceId: string): {\n name: string;\n value: string;\n options: {\n httpOnly: true;\n sameSite: \"lax\";\n path: string;\n maxAge: number;\n secure: boolean;\n };\n} {\n return {\n name: DEVICE_ID_COOKIE,\n value: deviceId,\n options: {\n httpOnly: true,\n sameSite: \"lax\",\n path: \"/\",\n maxAge: DEVICE_ID_MAX_AGE,\n secure: process.env.NODE_ENV === \"production\",\n },\n };\n}\n\nexport { createDeviceId };\n","// Generated by tools/stamp-version.mjs from @fewchurs/next's package.json. Do not edit by hand.\nexport const SDK_VERSION = \"1.0.1\";\n","import { SDK_VERSION } from \"./version\";\n\nexport const DEVICE_ID_COOKIE = \"fewchurs_did\";\nexport const DEVICE_ID_MAX_AGE = 60 * 60 * 24 * 365;\nexport { SDK_VERSION };\nexport const SDK_HEADER = `next/${SDK_VERSION}`;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAO;AACP,qBAAwB;AACxB,kBAA+B;;;ACDxB,IAAM,cAAc;;;ACCpB,IAAM,mBAAmB;AACzB,IAAM,oBAAoB,KAAK,KAAK,KAAK;AAEzC,IAAM,aAAa,QAAQ,WAAW;;;AFK7C,eAAsB,eAAuC;AAC3D,QAAM,QAAQ,UAAM,wBAAQ;AAC5B,SAAO,MAAM,IAAI,gBAAgB,GAAG,SAAS;AAC/C;AAMA,eAAsB,gBAAgB,QAA4C;AAChF,MAAI,OAAQ,QAAO,OAAO;AAC1B,SAAQ,MAAM,aAAa,SAAM,4BAAe;AAClD;AAEO,SAAS,eAAe,UAU7B;AACA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,SAAS;AAAA,MACP,UAAU;AAAA,MACV,UAAU;AAAA,MACV,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,QAAQ,QAAQ,IAAI,aAAa;AAAA,IACnC;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,19 @@
1
+ import {
2
+ createDeviceId,
3
+ deviceIdCookie,
4
+ readDeviceId,
5
+ resolveDeviceId
6
+ } from "./chunk-QULKPZB4.mjs";
7
+ import {
8
+ DEVICE_ID_COOKIE,
9
+ DEVICE_ID_MAX_AGE
10
+ } from "./chunk-W6QR6DEB.mjs";
11
+ export {
12
+ DEVICE_ID_COOKIE,
13
+ DEVICE_ID_MAX_AGE,
14
+ createDeviceId,
15
+ deviceIdCookie,
16
+ readDeviceId,
17
+ resolveDeviceId
18
+ };
19
+ //# sourceMappingURL=identity.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,27 @@
1
+ import { FewchursBoardProps as FewchursBoardProps$1 } from '@fewchurs/react';
2
+ import { DeviceIdResolver } from './identity.mjs';
3
+ export { DEVICE_ID_COOKIE, readDeviceId, resolveDeviceId } from './identity.mjs';
4
+ export { HandlerOptions, RouteHandler, createHandler } from './handler.mjs';
5
+ export { Comment, CommentPage, Feature, FeaturePage, FeatureSort, FeatureStatus, FewchursConfig, FewchursError } from '@fewchurs/react/core';
6
+
7
+ /** Function props cannot cross the server/client boundary — compose in your own client file. */
8
+ type SerializableBoardProps = Omit<FewchursBoardProps$1, "renderHeader" | "renderEmpty" | "renderFeature" | "children">;
9
+ interface FewchursBoardProps extends SerializableBoardProps {
10
+ /** Defaults to `process.env.FEWCHURS_API_KEY`. Never reaches the browser. */
11
+ apiKey?: string;
12
+ baseUrl?: string;
13
+ /** Where your route handler is mounted. Defaults to `/api/fewchurs`. */
14
+ apiPath?: string;
15
+ language?: string;
16
+ deviceId?: DeviceIdResolver;
17
+ }
18
+ declare function FewchursBoard({ apiKey, baseUrl, apiPath, language, deviceId: deviceIdOption, ...board }: FewchursBoardProps): Promise<React.JSX.Element>;
19
+
20
+ declare const DEFAULT_API_PATH = "/api/fewchurs";
21
+ interface ServerConfig {
22
+ apiKey?: string;
23
+ baseUrl?: string;
24
+ language?: string;
25
+ }
26
+
27
+ export { DEFAULT_API_PATH, DeviceIdResolver, FewchursBoard, type FewchursBoardProps, type ServerConfig };
@@ -0,0 +1,27 @@
1
+ import { FewchursBoardProps as FewchursBoardProps$1 } from '@fewchurs/react';
2
+ import { DeviceIdResolver } from './identity.js';
3
+ export { DEVICE_ID_COOKIE, readDeviceId, resolveDeviceId } from './identity.js';
4
+ export { HandlerOptions, RouteHandler, createHandler } from './handler.js';
5
+ export { Comment, CommentPage, Feature, FeaturePage, FeatureSort, FeatureStatus, FewchursConfig, FewchursError } from '@fewchurs/react/core';
6
+
7
+ /** Function props cannot cross the server/client boundary — compose in your own client file. */
8
+ type SerializableBoardProps = Omit<FewchursBoardProps$1, "renderHeader" | "renderEmpty" | "renderFeature" | "children">;
9
+ interface FewchursBoardProps extends SerializableBoardProps {
10
+ /** Defaults to `process.env.FEWCHURS_API_KEY`. Never reaches the browser. */
11
+ apiKey?: string;
12
+ baseUrl?: string;
13
+ /** Where your route handler is mounted. Defaults to `/api/fewchurs`. */
14
+ apiPath?: string;
15
+ language?: string;
16
+ deviceId?: DeviceIdResolver;
17
+ }
18
+ declare function FewchursBoard({ apiKey, baseUrl, apiPath, language, deviceId: deviceIdOption, ...board }: FewchursBoardProps): Promise<React.JSX.Element>;
19
+
20
+ declare const DEFAULT_API_PATH = "/api/fewchurs";
21
+ interface ServerConfig {
22
+ apiKey?: string;
23
+ baseUrl?: string;
24
+ language?: string;
25
+ }
26
+
27
+ export { DEFAULT_API_PATH, DeviceIdResolver, FewchursBoard, type FewchursBoardProps, type ServerConfig };