@botlr/next 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # @botlr/next
2
+
3
+ ## 0.1.0
4
+
5
+ - First release. `getBotlrForRoute` moves here from the publisher's
6
+ `lib/botlr-sdk/server.ts`, typed against `@botlr/sdk`, plus
7
+ `getCachedBotlr`, `createBotlrFromEnv`, `configFromEnv` and
8
+ `localeFromAcceptLanguage`.
9
+ - Re-exports `@botlr/react` and the `@botlr/sdk` types.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Botlr
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,32 @@
1
- # Temporary Holding Version
1
+ # @botlr/next
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Thin Next.js helpers on top of `@botlr/sdk` and `@botlr/react`. Everything
4
+ from both packages is re-exported, so a Next.js app can import from
5
+ `@botlr/next` alone.
6
+
7
+ ```ts
8
+ // app/[[...slug]]/page.tsx
9
+ import { getBotlrForRoute, SectionRenderer } from "@botlr/next";
10
+
11
+ export default async function Page({ params, searchParams }) {
12
+ const botlr = await getBotlrForRoute({
13
+ appId: process.env.BOTLR_APP_ID!,
14
+ preview: (await searchParams).preview === "true",
15
+ });
16
+ const resolved = await botlr.resolveUrl((await params).slug?.join("/") ?? "");
17
+ // ...render resolved.data.layout with SectionRenderer
18
+ }
19
+ ```
20
+
21
+ - `getBotlrForRoute(params)` builds a client for the current request. The
22
+ locale comes from `Accept-Language` unless given; `baseUrl`, `apiKey` and
23
+ `appId` fall back to `BOTLR_API_URL`, `BOTLR_API_KEY` and `BOTLR_APP_ID`.
24
+ All of them are server-side variables: the API URL is never exposed to the
25
+ browser through a `NEXT_PUBLIC_` name.
26
+ - `getCachedBotlr` is the same, memoised per request with React `cache`.
27
+ - `createBotlrFromEnv(overrides)` needs no request context (scripts,
28
+ `generateStaticParams`).
29
+ - `localeFromAcceptLanguage(header, fallback)` and `configFromEnv(overrides)`
30
+ are the building blocks.
31
+
32
+ `next` and `react` are peer dependencies.
package/dist/index.cjs ADDED
@@ -0,0 +1,113 @@
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/index.ts
22
+ var index_exports = {};
23
+ __export(index_exports, {
24
+ BOTLR_ENV: () => BOTLR_ENV,
25
+ BotlrConflictError: () => import_sdk2.BotlrConflictError,
26
+ BotlrError: () => import_sdk2.BotlrError,
27
+ DEFAULT_API_URL: () => DEFAULT_API_URL,
28
+ configFromEnv: () => configFromEnv,
29
+ createBotlrClient: () => import_sdk2.createBotlrClient,
30
+ createBotlrFromEnv: () => createBotlrFromEnv,
31
+ getBotlrForRoute: () => getBotlrForRoute,
32
+ getCachedBotlr: () => getCachedBotlr,
33
+ localeFromAcceptLanguage: () => localeFromAcceptLanguage
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+
37
+ // src/server.ts
38
+ var import_headers = require("next/headers");
39
+ var import_react = require("react");
40
+ var import_sdk = require("@botlr/sdk");
41
+
42
+ // src/env.ts
43
+ var BOTLR_ENV = {
44
+ apiUrl: "BOTLR_API_URL",
45
+ apiKey: "BOTLR_API_KEY",
46
+ appId: "BOTLR_APP_ID",
47
+ pat: "BOTLR_PAT"
48
+ };
49
+ var DEFAULT_API_URL = "http://localhost:8888";
50
+ function env(name) {
51
+ const value = typeof process !== "undefined" ? process.env?.[name] : void 0;
52
+ return value === "" ? void 0 : value;
53
+ }
54
+ function configFromEnv(overrides = {}) {
55
+ const appId = overrides.appId ?? env(BOTLR_ENV.appId);
56
+ if (!appId) {
57
+ throw new Error(`@botlr/next: pass appId or set ${BOTLR_ENV.appId}`);
58
+ }
59
+ return {
60
+ ...overrides,
61
+ baseUrl: overrides.baseUrl ?? env(BOTLR_ENV.apiUrl) ?? DEFAULT_API_URL,
62
+ appId,
63
+ apiKey: overrides.apiKey ?? env(BOTLR_ENV.apiKey),
64
+ personalToken: overrides.personalToken ?? env(BOTLR_ENV.pat)
65
+ };
66
+ }
67
+
68
+ // src/locale.ts
69
+ function localeFromAcceptLanguage(header, fallback = "en") {
70
+ if (!header) return fallback;
71
+ const first = header.split(",")[0]?.split(";")[0]?.trim();
72
+ return first || fallback;
73
+ }
74
+
75
+ // src/server.ts
76
+ async function getBotlrForRoute(params = {}) {
77
+ const h = await (0, import_headers.headers)();
78
+ const locale = params.locale || localeFromAcceptLanguage(h.get("accept-language"));
79
+ return (0, import_sdk.createBotlrClient)(
80
+ configFromEnv({
81
+ appId: params.appId,
82
+ apiKey: params.apiKey,
83
+ baseUrl: params.baseUrl,
84
+ previewToken: params.previewToken,
85
+ locale,
86
+ preview: params.preview,
87
+ fetch: params.fetch
88
+ })
89
+ );
90
+ }
91
+ var getCachedBotlr = (0, import_react.cache)(getBotlrForRoute);
92
+ function createBotlrFromEnv(overrides = {}) {
93
+ return (0, import_sdk.createBotlrClient)(configFromEnv(overrides));
94
+ }
95
+
96
+ // src/index.ts
97
+ __reExport(index_exports, require("@botlr/react"), module.exports);
98
+ var import_sdk2 = require("@botlr/sdk");
99
+ // Annotate the CommonJS export names for ESM import in node:
100
+ 0 && (module.exports = {
101
+ BOTLR_ENV,
102
+ BotlrConflictError,
103
+ BotlrError,
104
+ DEFAULT_API_URL,
105
+ configFromEnv,
106
+ createBotlrClient,
107
+ createBotlrFromEnv,
108
+ getBotlrForRoute,
109
+ getCachedBotlr,
110
+ localeFromAcceptLanguage,
111
+ ...require("@botlr/react")
112
+ });
113
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/server.ts","../src/env.ts","../src/locale.ts"],"sourcesContent":["export { getBotlrForRoute, getCachedBotlr, createBotlrFromEnv, type GetBotlrParams } from \"./server\";\nexport { configFromEnv, BOTLR_ENV, DEFAULT_API_URL } from \"./env\";\nexport { localeFromAcceptLanguage } from \"./locale\";\n\nexport * from \"@botlr/react\";\nexport type * from \"@botlr/sdk\";\nexport { BotlrError, BotlrConflictError, createBotlrClient } from \"@botlr/sdk\";\n","import { headers } from \"next/headers\";\nimport { cache } from \"react\";\nimport { createBotlrClient, type BotlrClient } from \"@botlr/sdk\";\nimport { configFromEnv } from \"./env\";\nimport { localeFromAcceptLanguage } from \"./locale\";\n\nexport type GetBotlrParams = {\n /** The app instance ID. Falls back to `BOTLR_APP_ID`. */\n appId?: string;\n /** Locale override; defaults to the request's `Accept-Language`, then `en`. */\n locale?: string;\n preview?: boolean;\n /** Site token; falls back to `BOTLR_API_KEY`. Omit in dev mode. */\n apiKey?: string;\n /** Preview JWT, forwarded to `/api/resolve` in preview mode. */\n previewToken?: string;\n /** API origin; falls back to `BOTLR_API_URL`. */\n baseUrl?: string;\n fetch?: typeof fetch;\n};\n\n/**\n * A Botlr client for the current request, for Server Components, route\n * handlers and server actions. Reads the locale from `Accept-Language`\n * unless given.\n *\n * ```ts\n * const botlr = await getBotlrForRoute({ appId: scope.appInstanceId, locale: scope.locale, preview });\n * const pages = await botlr.getPageList({ tags: [\"news\"] });\n * ```\n */\nexport async function getBotlrForRoute(params: GetBotlrParams = {}): Promise<BotlrClient> {\n const h = await headers();\n const locale = params.locale || localeFromAcceptLanguage(h.get(\"accept-language\"));\n return createBotlrClient(\n configFromEnv({\n appId: params.appId,\n apiKey: params.apiKey,\n baseUrl: params.baseUrl,\n previewToken: params.previewToken,\n locale,\n preview: params.preview,\n fetch: params.fetch,\n }),\n );\n}\n\n/**\n * `getBotlrForRoute` memoised per request with React `cache`, so several\n * components in one render share a client.\n */\nexport const getCachedBotlr: (params?: GetBotlrParams) => Promise<BotlrClient> = cache(getBotlrForRoute);\n\n/**\n * A client from the environment alone, with no request context. For scripts,\n * `generateStaticParams`, instrumentation and anywhere `headers()` is not\n * available.\n */\nexport function createBotlrFromEnv(overrides: Partial<GetBotlrParams> = {}): BotlrClient {\n return createBotlrClient(configFromEnv(overrides));\n}\n","import type { BotlrClientConfig } from \"@botlr/sdk\";\n\n/** Environment variables the helpers read. All server-side: the API URL is never exposed to the browser. */\nexport const BOTLR_ENV = {\n apiUrl: \"BOTLR_API_URL\",\n apiKey: \"BOTLR_API_KEY\",\n appId: \"BOTLR_APP_ID\",\n pat: \"BOTLR_PAT\",\n} as const;\n\nexport const DEFAULT_API_URL = \"http://localhost:8888\";\n\nfunction env(name: string): string | undefined {\n const value = typeof process !== \"undefined\" ? process.env?.[name] : undefined;\n return value === \"\" ? undefined : value;\n}\n\n/**\n * Client config from the environment, with `overrides` winning. Throws when\n * no app id is known, since every Botlr request needs one.\n */\nexport function configFromEnv(overrides: Partial<BotlrClientConfig> = {}): BotlrClientConfig {\n const appId = overrides.appId ?? env(BOTLR_ENV.appId);\n if (!appId) {\n throw new Error(`@botlr/next: pass appId or set ${BOTLR_ENV.appId}`);\n }\n return {\n ...overrides,\n baseUrl: overrides.baseUrl ?? env(BOTLR_ENV.apiUrl) ?? DEFAULT_API_URL,\n appId,\n apiKey: overrides.apiKey ?? env(BOTLR_ENV.apiKey),\n personalToken: overrides.personalToken ?? env(BOTLR_ENV.pat),\n };\n}\n","/** The first language of an `Accept-Language` value, or `fallback`. */\nexport function localeFromAcceptLanguage(header: string | null | undefined, fallback = \"en\"): string {\n if (!header) return fallback;\n const first = header.split(\",\")[0]?.split(\";\")[0]?.trim();\n return first || fallback;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,qBAAwB;AACxB,mBAAsB;AACtB,iBAAoD;;;ACC7C,IAAM,YAAY;AAAA,EACvB,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,KAAK;AACP;AAEO,IAAM,kBAAkB;AAE/B,SAAS,IAAI,MAAkC;AAC7C,QAAM,QAAQ,OAAO,YAAY,cAAc,QAAQ,MAAM,IAAI,IAAI;AACrE,SAAO,UAAU,KAAK,SAAY;AACpC;AAMO,SAAS,cAAc,YAAwC,CAAC,GAAsB;AAC3F,QAAM,QAAQ,UAAU,SAAS,IAAI,UAAU,KAAK;AACpD,MAAI,CAAC,OAAO;AACV,UAAM,IAAI,MAAM,kCAAkC,UAAU,KAAK,EAAE;AAAA,EACrE;AACA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,SAAS,UAAU,WAAW,IAAI,UAAU,MAAM,KAAK;AAAA,IACvD;AAAA,IACA,QAAQ,UAAU,UAAU,IAAI,UAAU,MAAM;AAAA,IAChD,eAAe,UAAU,iBAAiB,IAAI,UAAU,GAAG;AAAA,EAC7D;AACF;;;AChCO,SAAS,yBAAyB,QAAmC,WAAW,MAAc;AACnG,MAAI,CAAC,OAAQ,QAAO;AACpB,QAAM,QAAQ,OAAO,MAAM,GAAG,EAAE,CAAC,GAAG,MAAM,GAAG,EAAE,CAAC,GAAG,KAAK;AACxD,SAAO,SAAS;AAClB;;;AF0BA,eAAsB,iBAAiB,SAAyB,CAAC,GAAyB;AACxF,QAAM,IAAI,UAAM,wBAAQ;AACxB,QAAM,SAAS,OAAO,UAAU,yBAAyB,EAAE,IAAI,iBAAiB,CAAC;AACjF,aAAO;AAAA,IACL,cAAc;AAAA,MACZ,OAAO,OAAO;AAAA,MACd,QAAQ,OAAO;AAAA,MACf,SAAS,OAAO;AAAA,MAChB,cAAc,OAAO;AAAA,MACrB;AAAA,MACA,SAAS,OAAO;AAAA,MAChB,OAAO,OAAO;AAAA,IAChB,CAAC;AAAA,EACH;AACF;AAMO,IAAM,qBAAoE,oBAAM,gBAAgB;AAOhG,SAAS,mBAAmB,YAAqC,CAAC,GAAgB;AACvF,aAAO,8BAAkB,cAAc,SAAS,CAAC;AACnD;;;ADxDA,0BAAc,yBAJd;AAMA,IAAAA,cAAkE;","names":["import_sdk"]}
@@ -0,0 +1,60 @@
1
+ import { BotlrClient, BotlrClientConfig } from '@botlr/sdk';
2
+ export * from '@botlr/sdk';
3
+ export { BotlrConflictError, BotlrError, createBotlrClient } from '@botlr/sdk';
4
+ export * from '@botlr/react';
5
+
6
+ type GetBotlrParams = {
7
+ /** The app instance ID. Falls back to `BOTLR_APP_ID`. */
8
+ appId?: string;
9
+ /** Locale override; defaults to the request's `Accept-Language`, then `en`. */
10
+ locale?: string;
11
+ preview?: boolean;
12
+ /** Site token; falls back to `BOTLR_API_KEY`. Omit in dev mode. */
13
+ apiKey?: string;
14
+ /** Preview JWT, forwarded to `/api/resolve` in preview mode. */
15
+ previewToken?: string;
16
+ /** API origin; falls back to `BOTLR_API_URL`. */
17
+ baseUrl?: string;
18
+ fetch?: typeof fetch;
19
+ };
20
+ /**
21
+ * A Botlr client for the current request, for Server Components, route
22
+ * handlers and server actions. Reads the locale from `Accept-Language`
23
+ * unless given.
24
+ *
25
+ * ```ts
26
+ * const botlr = await getBotlrForRoute({ appId: scope.appInstanceId, locale: scope.locale, preview });
27
+ * const pages = await botlr.getPageList({ tags: ["news"] });
28
+ * ```
29
+ */
30
+ declare function getBotlrForRoute(params?: GetBotlrParams): Promise<BotlrClient>;
31
+ /**
32
+ * `getBotlrForRoute` memoised per request with React `cache`, so several
33
+ * components in one render share a client.
34
+ */
35
+ declare const getCachedBotlr: (params?: GetBotlrParams) => Promise<BotlrClient>;
36
+ /**
37
+ * A client from the environment alone, with no request context. For scripts,
38
+ * `generateStaticParams`, instrumentation and anywhere `headers()` is not
39
+ * available.
40
+ */
41
+ declare function createBotlrFromEnv(overrides?: Partial<GetBotlrParams>): BotlrClient;
42
+
43
+ /** Environment variables the helpers read. All server-side: the API URL is never exposed to the browser. */
44
+ declare const BOTLR_ENV: {
45
+ readonly apiUrl: "BOTLR_API_URL";
46
+ readonly apiKey: "BOTLR_API_KEY";
47
+ readonly appId: "BOTLR_APP_ID";
48
+ readonly pat: "BOTLR_PAT";
49
+ };
50
+ declare const DEFAULT_API_URL = "http://localhost:8888";
51
+ /**
52
+ * Client config from the environment, with `overrides` winning. Throws when
53
+ * no app id is known, since every Botlr request needs one.
54
+ */
55
+ declare function configFromEnv(overrides?: Partial<BotlrClientConfig>): BotlrClientConfig;
56
+
57
+ /** The first language of an `Accept-Language` value, or `fallback`. */
58
+ declare function localeFromAcceptLanguage(header: string | null | undefined, fallback?: string): string;
59
+
60
+ export { BOTLR_ENV, DEFAULT_API_URL, type GetBotlrParams, configFromEnv, createBotlrFromEnv, getBotlrForRoute, getCachedBotlr, localeFromAcceptLanguage };
@@ -0,0 +1,60 @@
1
+ import { BotlrClient, BotlrClientConfig } from '@botlr/sdk';
2
+ export * from '@botlr/sdk';
3
+ export { BotlrConflictError, BotlrError, createBotlrClient } from '@botlr/sdk';
4
+ export * from '@botlr/react';
5
+
6
+ type GetBotlrParams = {
7
+ /** The app instance ID. Falls back to `BOTLR_APP_ID`. */
8
+ appId?: string;
9
+ /** Locale override; defaults to the request's `Accept-Language`, then `en`. */
10
+ locale?: string;
11
+ preview?: boolean;
12
+ /** Site token; falls back to `BOTLR_API_KEY`. Omit in dev mode. */
13
+ apiKey?: string;
14
+ /** Preview JWT, forwarded to `/api/resolve` in preview mode. */
15
+ previewToken?: string;
16
+ /** API origin; falls back to `BOTLR_API_URL`. */
17
+ baseUrl?: string;
18
+ fetch?: typeof fetch;
19
+ };
20
+ /**
21
+ * A Botlr client for the current request, for Server Components, route
22
+ * handlers and server actions. Reads the locale from `Accept-Language`
23
+ * unless given.
24
+ *
25
+ * ```ts
26
+ * const botlr = await getBotlrForRoute({ appId: scope.appInstanceId, locale: scope.locale, preview });
27
+ * const pages = await botlr.getPageList({ tags: ["news"] });
28
+ * ```
29
+ */
30
+ declare function getBotlrForRoute(params?: GetBotlrParams): Promise<BotlrClient>;
31
+ /**
32
+ * `getBotlrForRoute` memoised per request with React `cache`, so several
33
+ * components in one render share a client.
34
+ */
35
+ declare const getCachedBotlr: (params?: GetBotlrParams) => Promise<BotlrClient>;
36
+ /**
37
+ * A client from the environment alone, with no request context. For scripts,
38
+ * `generateStaticParams`, instrumentation and anywhere `headers()` is not
39
+ * available.
40
+ */
41
+ declare function createBotlrFromEnv(overrides?: Partial<GetBotlrParams>): BotlrClient;
42
+
43
+ /** Environment variables the helpers read. All server-side: the API URL is never exposed to the browser. */
44
+ declare const BOTLR_ENV: {
45
+ readonly apiUrl: "BOTLR_API_URL";
46
+ readonly apiKey: "BOTLR_API_KEY";
47
+ readonly appId: "BOTLR_APP_ID";
48
+ readonly pat: "BOTLR_PAT";
49
+ };
50
+ declare const DEFAULT_API_URL = "http://localhost:8888";
51
+ /**
52
+ * Client config from the environment, with `overrides` winning. Throws when
53
+ * no app id is known, since every Botlr request needs one.
54
+ */
55
+ declare function configFromEnv(overrides?: Partial<BotlrClientConfig>): BotlrClientConfig;
56
+
57
+ /** The first language of an `Accept-Language` value, or `fallback`. */
58
+ declare function localeFromAcceptLanguage(header: string | null | undefined, fallback?: string): string;
59
+
60
+ export { BOTLR_ENV, DEFAULT_API_URL, type GetBotlrParams, configFromEnv, createBotlrFromEnv, getBotlrForRoute, getCachedBotlr, localeFromAcceptLanguage };
package/dist/index.js ADDED
@@ -0,0 +1,75 @@
1
+ // src/server.ts
2
+ import { headers } from "next/headers";
3
+ import { cache } from "react";
4
+ import { createBotlrClient } from "@botlr/sdk";
5
+
6
+ // src/env.ts
7
+ var BOTLR_ENV = {
8
+ apiUrl: "BOTLR_API_URL",
9
+ apiKey: "BOTLR_API_KEY",
10
+ appId: "BOTLR_APP_ID",
11
+ pat: "BOTLR_PAT"
12
+ };
13
+ var DEFAULT_API_URL = "http://localhost:8888";
14
+ function env(name) {
15
+ const value = typeof process !== "undefined" ? process.env?.[name] : void 0;
16
+ return value === "" ? void 0 : value;
17
+ }
18
+ function configFromEnv(overrides = {}) {
19
+ const appId = overrides.appId ?? env(BOTLR_ENV.appId);
20
+ if (!appId) {
21
+ throw new Error(`@botlr/next: pass appId or set ${BOTLR_ENV.appId}`);
22
+ }
23
+ return {
24
+ ...overrides,
25
+ baseUrl: overrides.baseUrl ?? env(BOTLR_ENV.apiUrl) ?? DEFAULT_API_URL,
26
+ appId,
27
+ apiKey: overrides.apiKey ?? env(BOTLR_ENV.apiKey),
28
+ personalToken: overrides.personalToken ?? env(BOTLR_ENV.pat)
29
+ };
30
+ }
31
+
32
+ // src/locale.ts
33
+ function localeFromAcceptLanguage(header, fallback = "en") {
34
+ if (!header) return fallback;
35
+ const first = header.split(",")[0]?.split(";")[0]?.trim();
36
+ return first || fallback;
37
+ }
38
+
39
+ // src/server.ts
40
+ async function getBotlrForRoute(params = {}) {
41
+ const h = await headers();
42
+ const locale = params.locale || localeFromAcceptLanguage(h.get("accept-language"));
43
+ return createBotlrClient(
44
+ configFromEnv({
45
+ appId: params.appId,
46
+ apiKey: params.apiKey,
47
+ baseUrl: params.baseUrl,
48
+ previewToken: params.previewToken,
49
+ locale,
50
+ preview: params.preview,
51
+ fetch: params.fetch
52
+ })
53
+ );
54
+ }
55
+ var getCachedBotlr = cache(getBotlrForRoute);
56
+ function createBotlrFromEnv(overrides = {}) {
57
+ return createBotlrClient(configFromEnv(overrides));
58
+ }
59
+
60
+ // src/index.ts
61
+ export * from "@botlr/react";
62
+ import { BotlrError, BotlrConflictError, createBotlrClient as createBotlrClient2 } from "@botlr/sdk";
63
+ export {
64
+ BOTLR_ENV,
65
+ BotlrConflictError,
66
+ BotlrError,
67
+ DEFAULT_API_URL,
68
+ configFromEnv,
69
+ createBotlrClient2 as createBotlrClient,
70
+ createBotlrFromEnv,
71
+ getBotlrForRoute,
72
+ getCachedBotlr,
73
+ localeFromAcceptLanguage
74
+ };
75
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/server.ts","../src/env.ts","../src/locale.ts","../src/index.ts"],"sourcesContent":["import { headers } from \"next/headers\";\nimport { cache } from \"react\";\nimport { createBotlrClient, type BotlrClient } from \"@botlr/sdk\";\nimport { configFromEnv } from \"./env\";\nimport { localeFromAcceptLanguage } from \"./locale\";\n\nexport type GetBotlrParams = {\n /** The app instance ID. Falls back to `BOTLR_APP_ID`. */\n appId?: string;\n /** Locale override; defaults to the request's `Accept-Language`, then `en`. */\n locale?: string;\n preview?: boolean;\n /** Site token; falls back to `BOTLR_API_KEY`. Omit in dev mode. */\n apiKey?: string;\n /** Preview JWT, forwarded to `/api/resolve` in preview mode. */\n previewToken?: string;\n /** API origin; falls back to `BOTLR_API_URL`. */\n baseUrl?: string;\n fetch?: typeof fetch;\n};\n\n/**\n * A Botlr client for the current request, for Server Components, route\n * handlers and server actions. Reads the locale from `Accept-Language`\n * unless given.\n *\n * ```ts\n * const botlr = await getBotlrForRoute({ appId: scope.appInstanceId, locale: scope.locale, preview });\n * const pages = await botlr.getPageList({ tags: [\"news\"] });\n * ```\n */\nexport async function getBotlrForRoute(params: GetBotlrParams = {}): Promise<BotlrClient> {\n const h = await headers();\n const locale = params.locale || localeFromAcceptLanguage(h.get(\"accept-language\"));\n return createBotlrClient(\n configFromEnv({\n appId: params.appId,\n apiKey: params.apiKey,\n baseUrl: params.baseUrl,\n previewToken: params.previewToken,\n locale,\n preview: params.preview,\n fetch: params.fetch,\n }),\n );\n}\n\n/**\n * `getBotlrForRoute` memoised per request with React `cache`, so several\n * components in one render share a client.\n */\nexport const getCachedBotlr: (params?: GetBotlrParams) => Promise<BotlrClient> = cache(getBotlrForRoute);\n\n/**\n * A client from the environment alone, with no request context. For scripts,\n * `generateStaticParams`, instrumentation and anywhere `headers()` is not\n * available.\n */\nexport function createBotlrFromEnv(overrides: Partial<GetBotlrParams> = {}): BotlrClient {\n return createBotlrClient(configFromEnv(overrides));\n}\n","import type { BotlrClientConfig } from \"@botlr/sdk\";\n\n/** Environment variables the helpers read. All server-side: the API URL is never exposed to the browser. */\nexport const BOTLR_ENV = {\n apiUrl: \"BOTLR_API_URL\",\n apiKey: \"BOTLR_API_KEY\",\n appId: \"BOTLR_APP_ID\",\n pat: \"BOTLR_PAT\",\n} as const;\n\nexport const DEFAULT_API_URL = \"http://localhost:8888\";\n\nfunction env(name: string): string | undefined {\n const value = typeof process !== \"undefined\" ? process.env?.[name] : undefined;\n return value === \"\" ? undefined : value;\n}\n\n/**\n * Client config from the environment, with `overrides` winning. Throws when\n * no app id is known, since every Botlr request needs one.\n */\nexport function configFromEnv(overrides: Partial<BotlrClientConfig> = {}): BotlrClientConfig {\n const appId = overrides.appId ?? env(BOTLR_ENV.appId);\n if (!appId) {\n throw new Error(`@botlr/next: pass appId or set ${BOTLR_ENV.appId}`);\n }\n return {\n ...overrides,\n baseUrl: overrides.baseUrl ?? env(BOTLR_ENV.apiUrl) ?? DEFAULT_API_URL,\n appId,\n apiKey: overrides.apiKey ?? env(BOTLR_ENV.apiKey),\n personalToken: overrides.personalToken ?? env(BOTLR_ENV.pat),\n };\n}\n","/** The first language of an `Accept-Language` value, or `fallback`. */\nexport function localeFromAcceptLanguage(header: string | null | undefined, fallback = \"en\"): string {\n if (!header) return fallback;\n const first = header.split(\",\")[0]?.split(\";\")[0]?.trim();\n return first || fallback;\n}\n","export { getBotlrForRoute, getCachedBotlr, createBotlrFromEnv, type GetBotlrParams } from \"./server\";\nexport { configFromEnv, BOTLR_ENV, DEFAULT_API_URL } from \"./env\";\nexport { localeFromAcceptLanguage } from \"./locale\";\n\nexport * from \"@botlr/react\";\nexport type * from \"@botlr/sdk\";\nexport { BotlrError, BotlrConflictError, createBotlrClient } from \"@botlr/sdk\";\n"],"mappings":";AAAA,SAAS,eAAe;AACxB,SAAS,aAAa;AACtB,SAAS,yBAA2C;;;ACC7C,IAAM,YAAY;AAAA,EACvB,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,KAAK;AACP;AAEO,IAAM,kBAAkB;AAE/B,SAAS,IAAI,MAAkC;AAC7C,QAAM,QAAQ,OAAO,YAAY,cAAc,QAAQ,MAAM,IAAI,IAAI;AACrE,SAAO,UAAU,KAAK,SAAY;AACpC;AAMO,SAAS,cAAc,YAAwC,CAAC,GAAsB;AAC3F,QAAM,QAAQ,UAAU,SAAS,IAAI,UAAU,KAAK;AACpD,MAAI,CAAC,OAAO;AACV,UAAM,IAAI,MAAM,kCAAkC,UAAU,KAAK,EAAE;AAAA,EACrE;AACA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,SAAS,UAAU,WAAW,IAAI,UAAU,MAAM,KAAK;AAAA,IACvD;AAAA,IACA,QAAQ,UAAU,UAAU,IAAI,UAAU,MAAM;AAAA,IAChD,eAAe,UAAU,iBAAiB,IAAI,UAAU,GAAG;AAAA,EAC7D;AACF;;;AChCO,SAAS,yBAAyB,QAAmC,WAAW,MAAc;AACnG,MAAI,CAAC,OAAQ,QAAO;AACpB,QAAM,QAAQ,OAAO,MAAM,GAAG,EAAE,CAAC,GAAG,MAAM,GAAG,EAAE,CAAC,GAAG,KAAK;AACxD,SAAO,SAAS;AAClB;;;AF0BA,eAAsB,iBAAiB,SAAyB,CAAC,GAAyB;AACxF,QAAM,IAAI,MAAM,QAAQ;AACxB,QAAM,SAAS,OAAO,UAAU,yBAAyB,EAAE,IAAI,iBAAiB,CAAC;AACjF,SAAO;AAAA,IACL,cAAc;AAAA,MACZ,OAAO,OAAO;AAAA,MACd,QAAQ,OAAO;AAAA,MACf,SAAS,OAAO;AAAA,MAChB,cAAc,OAAO;AAAA,MACrB;AAAA,MACA,SAAS,OAAO;AAAA,MAChB,OAAO,OAAO;AAAA,IAChB,CAAC;AAAA,EACH;AACF;AAMO,IAAM,iBAAoE,MAAM,gBAAgB;AAOhG,SAAS,mBAAmB,YAAqC,CAAC,GAAgB;AACvF,SAAO,kBAAkB,cAAc,SAAS,CAAC;AACnD;;;AGxDA,cAAc;AAEd,SAAS,YAAY,oBAAoB,qBAAAA,0BAAyB;","names":["createBotlrClient"]}
package/package.json CHANGED
@@ -1,6 +1,64 @@
1
1
  {
2
2
  "name": "@botlr/next",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Next.js helpers for Botlr: per-request clients from headers and env, on top of @botlr/sdk and @botlr/react.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/botlr-io/botlr.git",
9
+ "directory": "packages/next"
10
+ },
11
+ "homepage": "https://github.com/botlr-io/botlr/tree/main/packages/next#readme",
12
+ "keywords": [
13
+ "botlr",
14
+ "cms",
15
+ "nextjs",
16
+ "react"
17
+ ],
18
+ "type": "module",
19
+ "sideEffects": false,
20
+ "main": "./dist/index.cjs",
21
+ "module": "./dist/index.js",
22
+ "types": "./dist/index.d.ts",
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.ts",
26
+ "import": "./dist/index.js",
27
+ "require": "./dist/index.cjs"
28
+ },
29
+ "./package.json": "./package.json"
30
+ },
31
+ "files": [
32
+ "dist",
33
+ "CHANGELOG.md",
34
+ "README.md"
35
+ ],
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "engines": {
40
+ "node": ">=20"
41
+ },
42
+ "dependencies": {
43
+ "@botlr/react": "^0.1.0",
44
+ "@botlr/sdk": "^0.1.0"
45
+ },
46
+ "peerDependencies": {
47
+ "next": ">=14",
48
+ "react": ">=18"
49
+ },
50
+ "devDependencies": {
51
+ "@types/react": "^19.1.0",
52
+ "next": "16.2.9",
53
+ "react": "^19.1.0",
54
+ "react-dom": "^19.1.0",
55
+ "tsup": "^8.5.0",
56
+ "typescript": "~5.9.3",
57
+ "vitest": "^3.2.4"
58
+ },
59
+ "scripts": {
60
+ "build": "tsup",
61
+ "typecheck": "tsc -p tsconfig.json",
62
+ "test": "vitest run"
63
+ }
6
64
  }