@yak-io/prismic 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/LICENSE ADDED
@@ -0,0 +1,36 @@
1
+ Yak Proprietary License
2
+
3
+ Copyright (c) 2025 Yak. All rights reserved.
4
+
5
+ This software and associated documentation files (the "Software") are the
6
+ proprietary property of Yak and are protected by copyright law.
7
+
8
+ GRANT OF LICENSE:
9
+ Subject to the terms of this license and your valid subscription or agreement
10
+ with Yak, you are granted a limited, non-exclusive, non-transferable license
11
+ to use the Software solely for integrating the Yak chatbot widget into your
12
+ applications as intended and documented.
13
+
14
+ RESTRICTIONS:
15
+ You may NOT:
16
+ - Modify, adapt, alter, translate, or create derivative works of the Software
17
+ - Reverse engineer, disassemble, decompile, or otherwise attempt to derive
18
+ the source code of the Software
19
+ - Redistribute, sublicense, lease, rent, or lend the Software to third parties
20
+ - Remove or alter any proprietary notices, labels, or marks on the Software
21
+ - Use the Software for any purpose other than as expressly permitted herein
22
+
23
+ NO WARRANTY:
24
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL YAK
27
+ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
28
+ CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
+
31
+ TERMINATION:
32
+ This license is effective until terminated. Your rights under this license
33
+ will terminate automatically without notice if you fail to comply with any
34
+ of its terms.
35
+
36
+ For licensing inquiries, contact: support@yak.io
package/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # @yak-io/prismic
2
+
3
+ Adapters that turn Prismic CMS documents into Yak routes, tools, and schema sources. This package plugs directly into `@yak-io/javascript` and works seamlessly with the Next.js and Nuxt helpers.
4
+
5
+ ## What you get
6
+
7
+ - `createPrismicRouteAdapter` – produces a `RouteSource` from Prismic documents. Use it when your routes live in Prismic instead of (or alongside) the filesystem.
8
+ - `createPrismicToolAdapter` – produces a `ToolSource` exposing `prismic.getByUID`, `prismic.getAllByType`, and `prismic.search` as tools the LLM can invoke.
9
+ - `createPrismicSchemaSource` – produces a `SchemaSource` describing the Prismic content model so the LLM understands document types and fields.
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ pnpm add @yak-io/prismic @yak-io/javascript @prismicio/client
15
+ ```
16
+
17
+ `@prismicio/client` is a peer dependency (v7+).
18
+
19
+ ## Usage
20
+
21
+ ### 1. Create a Prismic client
22
+
23
+ ```ts
24
+ import * as prismic from "@prismicio/client";
25
+
26
+ const client = prismic.createClient("your-repo-name", {
27
+ accessToken: process.env.PRISMIC_ACCESS_TOKEN,
28
+ });
29
+ ```
30
+
31
+ ### 2. Use it with a Yak handler
32
+
33
+ ```ts
34
+ import { createNextYakHandler } from "@yak-io/nextjs/server";
35
+ import {
36
+ createPrismicRouteAdapter,
37
+ createPrismicToolAdapter,
38
+ } from "@yak-io/prismic";
39
+
40
+ const prismicRoutes = createPrismicRouteAdapter({
41
+ client,
42
+ documentTypes: ["page", "blog_post"],
43
+ resolveRoute: (doc) => ({
44
+ path: `/${doc.uid}`,
45
+ title: doc.data.meta_title ?? doc.data.title,
46
+ description: doc.data.meta_description,
47
+ }),
48
+ });
49
+
50
+ const prismicTools = createPrismicToolAdapter({
51
+ client,
52
+ allowedTypes: ["page", "blog_post"],
53
+ });
54
+
55
+ export const { GET, POST } = createNextYakHandler({
56
+ routes: prismicRoutes,
57
+ tools: prismicTools,
58
+ });
59
+ ```
60
+
61
+ The adapters return standard `RouteSource` / `ToolSource` shapes, so you can compose them with filesystem routes, tRPC tools, or any other source by passing arrays.
62
+
63
+ ### 3. Optionally expose the content model
64
+
65
+ Inside your client-side `getConfig` provider:
66
+
67
+ ```ts
68
+ import { createPrismicSchemaSource } from "@yak-io/prismic";
69
+
70
+ const getConfig = async () => {
71
+ const res = await fetch("/api/yak");
72
+ const config = await res.json();
73
+ const schemaSource = await createPrismicSchemaSource({
74
+ client,
75
+ mode: "graphql",
76
+ });
77
+ return { ...config, schemaSources: [schemaSource] };
78
+ };
79
+ ```
80
+
81
+ ## Types
82
+
83
+ All route/tool/schema types are re-exported from `@yak-io/javascript/server`:
84
+
85
+ ```ts
86
+ import type { RouteSource, ToolSource, SchemaSource } from "@yak-io/prismic";
87
+ ```
88
+
89
+ ## Security tips
90
+
91
+ - Always set `allowedTypes` on the tool adapter — without it the LLM can fetch any document type in your repository.
92
+ - `resolveRoute` returning `null` skips a document — use this to filter drafts or hidden pages out of the manifest.
93
+
94
+ ## License
95
+
96
+ Proprietary - see LICENSE file
@@ -0,0 +1,7 @@
1
+ export { createPrismicRouteAdapter } from "./route-adapter.js";
2
+ export { createPrismicToolAdapter } from "./tool-adapter.js";
3
+ export { createPrismicSchemaSource } from "./schema-source.js";
4
+ export type { PrismicRouteAdapterConfig, PrismicToolAdapterConfig, PrismicSchemaSourceConfig, PrismicGraphQLSchemaSourceConfig, } from "./types.js";
5
+ export type { RouteInfo, RouteSource, ToolDefinition, ToolExecutor, ToolManifest, ToolSource, } from "@yak-io/javascript/server";
6
+ export type { GraphQLSchemaSource, OpenAPISchemaSource, SchemaSource } from "@yak-io/javascript";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,YAAY,EACV,yBAAyB,EACzB,wBAAwB,EACxB,yBAAyB,EACzB,gCAAgC,GACjC,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,SAAS,EACT,WAAW,EACX,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,UAAU,GACX,MAAM,2BAA2B,CAAC;AAEnC,YAAY,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { createPrismicRouteAdapter } from "./route-adapter.js";
2
+ export { createPrismicToolAdapter } from "./tool-adapter.js";
3
+ export { createPrismicSchemaSource } from "./schema-source.js";
@@ -0,0 +1,4 @@
1
+ import type { RouteSource } from "@yak-io/javascript/server";
2
+ import type { PrismicRouteAdapterConfig } from "./types.js";
3
+ export declare function createPrismicRouteAdapter(config: PrismicRouteAdapterConfig): RouteSource;
4
+ //# sourceMappingURL=route-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route-adapter.d.ts","sourceRoot":"","sources":["../src/route-adapter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAa,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAE5D,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,yBAAyB,GAAG,WAAW,CAqBxF"}
@@ -0,0 +1,22 @@
1
+ import * as prismic from "@prismicio/client";
2
+ export function createPrismicRouteAdapter(config) {
3
+ return {
4
+ id: config.id ?? "prismic",
5
+ getRoutes: async () => {
6
+ const docs = await config.client.dangerouslyGetAll({
7
+ filters: [
8
+ prismic.filter.any("document.type", config.documentTypes),
9
+ ...(config.filters ?? []),
10
+ ],
11
+ });
12
+ const routes = [];
13
+ for (const doc of docs) {
14
+ const route = config.resolveRoute(doc);
15
+ if (route !== null) {
16
+ routes.push(route);
17
+ }
18
+ }
19
+ return routes;
20
+ },
21
+ };
22
+ }
@@ -0,0 +1,4 @@
1
+ import type { GraphQLSchemaSource } from "@yak-io/javascript";
2
+ import type { PrismicSchemaSourceConfig } from "./types.js";
3
+ export declare function createPrismicSchemaSource(config: PrismicSchemaSourceConfig): Promise<GraphQLSchemaSource>;
4
+ //# sourceMappingURL=schema-source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-source.d.ts","sourceRoot":"","sources":["../src/schema-source.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AA2F5D,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,yBAAyB,GAChC,OAAO,CAAC,mBAAmB,CAAC,CAkC9B"}
@@ -0,0 +1,112 @@
1
+ const INTROSPECTION_QUERY = `query IntrospectionQuery {
2
+ __schema {
3
+ queryType { name }
4
+ mutationType { name }
5
+ subscriptionType { name }
6
+ types {
7
+ ...FullType
8
+ }
9
+ directives {
10
+ name
11
+ description
12
+ locations
13
+ args { ...InputValue }
14
+ }
15
+ }
16
+ }
17
+ fragment FullType on __Type {
18
+ kind
19
+ name
20
+ description
21
+ fields(includeDeprecated: true) {
22
+ name
23
+ description
24
+ args { ...InputValue }
25
+ type { ...TypeRef }
26
+ isDeprecated
27
+ deprecationReason
28
+ }
29
+ inputFields { ...InputValue }
30
+ interfaces { ...TypeRef }
31
+ enumValues(includeDeprecated: true) {
32
+ name
33
+ description
34
+ isDeprecated
35
+ deprecationReason
36
+ }
37
+ possibleTypes { ...TypeRef }
38
+ }
39
+ fragment InputValue on __InputValue {
40
+ name
41
+ description
42
+ type { ...TypeRef }
43
+ defaultValue
44
+ }
45
+ fragment TypeRef on __Type {
46
+ kind
47
+ name
48
+ ofType {
49
+ kind
50
+ name
51
+ ofType {
52
+ kind
53
+ name
54
+ ofType {
55
+ kind
56
+ name
57
+ ofType {
58
+ kind
59
+ name
60
+ ofType {
61
+ kind
62
+ name
63
+ ofType {
64
+ kind
65
+ name
66
+ ofType { kind name }
67
+ }
68
+ }
69
+ }
70
+ }
71
+ }
72
+ }
73
+ }`;
74
+ function deriveGraphQLEndpoint(restEndpoint) {
75
+ const trimmed = restEndpoint.replace(/\/api\/v\d+\/?$/, "");
76
+ return `${trimmed}/graphql`;
77
+ }
78
+ async function loadGraphQLModule() {
79
+ try {
80
+ return await import("graphql");
81
+ }
82
+ catch {
83
+ throw new Error("createPrismicSchemaSource with mode 'graphql' requires the 'graphql' package. Install it as a peer dependency: pnpm add graphql");
84
+ }
85
+ }
86
+ export async function createPrismicSchemaSource(config) {
87
+ if (config.mode !== "graphql") {
88
+ throw new Error(`Unsupported schema source mode: ${config.mode}`);
89
+ }
90
+ const fetchFn = config.fetchFn ?? fetch;
91
+ const endpoint = deriveGraphQLEndpoint(config.client.endpoint);
92
+ const response = await fetchFn(endpoint, {
93
+ method: "POST",
94
+ headers: { "Content-Type": "application/json" },
95
+ body: JSON.stringify({ query: INTROSPECTION_QUERY }),
96
+ });
97
+ if (!response.ok) {
98
+ throw new Error(`Prismic GraphQL introspection failed: ${response.status} ${response.statusText}`);
99
+ }
100
+ const payload = (await response.json());
101
+ if (payload.errors || !payload.data) {
102
+ throw new Error("Prismic GraphQL introspection returned no data");
103
+ }
104
+ const { buildClientSchema, printSchema } = await loadGraphQLModule();
105
+ const schema = buildClientSchema(payload.data);
106
+ const sdl = printSchema(schema);
107
+ return {
108
+ name: config.name ?? "prismic",
109
+ type: "graphql",
110
+ schema: sdl,
111
+ };
112
+ }
@@ -0,0 +1,4 @@
1
+ import type { ToolSource } from "@yak-io/javascript/server";
2
+ import type { PrismicToolAdapterConfig } from "./types.js";
3
+ export declare function createPrismicToolAdapter(config: PrismicToolAdapterConfig): ToolSource;
4
+ //# sourceMappingURL=tool-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-adapter.d.ts","sourceRoot":"","sources":["../src/tool-adapter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAgC,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC1F,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AA2E3D,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,wBAAwB,GAAG,UAAU,CA4DrF"}
@@ -0,0 +1,119 @@
1
+ import * as prismic from "@prismicio/client";
2
+ const TOOL_DEFINITIONS = [
3
+ {
4
+ name: "prismic.getByUID",
5
+ description: "Fetch a single Prismic document by document type and UID. Use this when you know the exact UID of a page or post.",
6
+ inputSchema: {
7
+ type: "object",
8
+ properties: {
9
+ type: {
10
+ type: "string",
11
+ description: "The Prismic custom type (for example 'page' or 'blog_post')",
12
+ },
13
+ uid: {
14
+ type: "string",
15
+ description: "The unique identifier of the document",
16
+ },
17
+ },
18
+ required: ["type", "uid"],
19
+ },
20
+ },
21
+ {
22
+ name: "prismic.getAllByType",
23
+ description: "Fetch all Prismic documents of a given type. Use this to list pages or posts of a particular kind.",
24
+ inputSchema: {
25
+ type: "object",
26
+ properties: {
27
+ type: {
28
+ type: "string",
29
+ description: "The Prismic custom type to list",
30
+ },
31
+ limit: {
32
+ type: "number",
33
+ description: "Maximum number of documents to return (default 20)",
34
+ },
35
+ },
36
+ required: ["type"],
37
+ },
38
+ },
39
+ {
40
+ name: "prismic.search",
41
+ description: "Full-text search across Prismic documents. Returns documents whose fields match the query.",
42
+ inputSchema: {
43
+ type: "object",
44
+ properties: {
45
+ query: {
46
+ type: "string",
47
+ description: "The free-text search query",
48
+ },
49
+ types: {
50
+ type: "array",
51
+ items: { type: "string" },
52
+ description: "Optional list of document types to restrict the search to. Defaults to all allowed types.",
53
+ },
54
+ },
55
+ required: ["query"],
56
+ },
57
+ },
58
+ ];
59
+ function buildGraphQuery(fields, type) {
60
+ const typeFields = fields?.[type];
61
+ if (!typeFields || typeFields.length === 0) {
62
+ return undefined;
63
+ }
64
+ return `{ ${type} { ${typeFields.join(" ")} } }`;
65
+ }
66
+ export function createPrismicToolAdapter(config) {
67
+ const allowed = new Set(config.allowedTypes);
68
+ const assertAllowed = (type) => {
69
+ if (typeof type !== "string" || !allowed.has(type)) {
70
+ throw new Error(`Prismic document type '${String(type)}' is not in allowedTypes`);
71
+ }
72
+ return type;
73
+ };
74
+ const executor = async (name, args) => {
75
+ const input = (args ?? {});
76
+ switch (name) {
77
+ case "prismic.getByUID": {
78
+ const type = assertAllowed(input.type);
79
+ const uid = input.uid;
80
+ if (typeof uid !== "string" || uid.length === 0) {
81
+ throw new Error("prismic.getByUID requires a 'uid' string");
82
+ }
83
+ const graphQuery = buildGraphQuery(config.fields, type);
84
+ return await config.client.getByUID(type, uid, graphQuery ? { graphQuery } : undefined);
85
+ }
86
+ case "prismic.getAllByType": {
87
+ const type = assertAllowed(input.type);
88
+ const limit = typeof input.limit === "number" ? input.limit : 20;
89
+ const graphQuery = buildGraphQuery(config.fields, type);
90
+ return await config.client.getAllByType(type, {
91
+ limit,
92
+ ...(graphQuery ? { graphQuery } : {}),
93
+ });
94
+ }
95
+ case "prismic.search": {
96
+ const query = input.query;
97
+ if (typeof query !== "string" || query.length === 0) {
98
+ throw new Error("prismic.search requires a 'query' string");
99
+ }
100
+ const requestedTypes = Array.isArray(input.types)
101
+ ? input.types.map((t) => assertAllowed(t))
102
+ : [...allowed];
103
+ return await config.client.get({
104
+ filters: [
105
+ prismic.filter.fulltext("document", query),
106
+ prismic.filter.any("document.type", requestedTypes),
107
+ ],
108
+ });
109
+ }
110
+ default:
111
+ throw new Error(`Unknown Prismic tool: ${name}`);
112
+ }
113
+ };
114
+ return {
115
+ id: config.id ?? "prismic",
116
+ getTools: async () => TOOL_DEFINITIONS,
117
+ executeTool: executor,
118
+ };
119
+ }
@@ -0,0 +1,23 @@
1
+ import type { Client, PrismicDocument } from "@prismicio/client";
2
+ import type { RouteInfo } from "@yak-io/javascript/server";
3
+ export type PrismicRouteAdapterConfig = {
4
+ id?: string;
5
+ client: Client;
6
+ documentTypes: string[];
7
+ resolveRoute: (doc: PrismicDocument) => RouteInfo | null;
8
+ filters?: string[];
9
+ };
10
+ export type PrismicToolAdapterConfig = {
11
+ id?: string;
12
+ client: Client;
13
+ allowedTypes: string[];
14
+ fields?: Record<string, string[]>;
15
+ };
16
+ export type PrismicGraphQLSchemaSourceConfig = {
17
+ client: Client;
18
+ mode: "graphql";
19
+ name?: string;
20
+ fetchFn?: typeof fetch;
21
+ };
22
+ export type PrismicSchemaSourceConfig = PrismicGraphQLSchemaSourceConfig;
23
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAE3D,MAAM,MAAM,yBAAyB,GAAG;IACtC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,YAAY,EAAE,CAAC,GAAG,EAAE,eAAe,KAAK,SAAS,GAAG,IAAI,CAAC;IACzD,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,gCAAgC,GAAG;IAC7C,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,KAAK,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG,gCAAgC,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@yak-io/prismic",
3
+ "version": "0.1.0",
4
+ "description": "Prismic CMS adapter for yak chatbot - exposes Prismic documents as routes, tools, and schema sources",
5
+ "type": "module",
6
+ "license": "SEE LICENSE IN LICENSE",
7
+ "author": "Yak <support@yak.io>",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/388-labs/yak.git",
11
+ "directory": "packages/prismic"
12
+ },
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "keywords": [
17
+ "yak",
18
+ "chatbot",
19
+ "ai",
20
+ "prismic",
21
+ "cms"
22
+ ],
23
+ "engines": {
24
+ "node": ">=18"
25
+ },
26
+ "files": [
27
+ "dist",
28
+ "LICENSE"
29
+ ],
30
+ "sideEffects": false,
31
+ "main": "./dist/index.js",
32
+ "module": "./dist/index.js",
33
+ "types": "./dist/index.d.ts",
34
+ "exports": {
35
+ ".": {
36
+ "types": "./dist/index.d.ts",
37
+ "import": "./dist/index.js",
38
+ "default": "./dist/index.js"
39
+ },
40
+ "./package.json": "./package.json"
41
+ },
42
+ "dependencies": {
43
+ "@yak-io/javascript": "0.7.0"
44
+ },
45
+ "peerDependencies": {
46
+ "@prismicio/client": "^7.0.0",
47
+ "graphql": "^16.0.0"
48
+ },
49
+ "peerDependenciesMeta": {
50
+ "graphql": {
51
+ "optional": true
52
+ }
53
+ },
54
+ "devDependencies": {
55
+ "@prismicio/client": "^7.13.1",
56
+ "@types/node": "^24.12.4",
57
+ "graphql": "^16.9.0",
58
+ "typescript": "^5.3.0",
59
+ "@repo/typescript-config": "0.0.0"
60
+ },
61
+ "scripts": {
62
+ "build": "tsc",
63
+ "check-types": "tsc --noEmit",
64
+ "test": "vitest run",
65
+ "lint": "biome lint ./src --fix",
66
+ "format": "biome format ./src --write"
67
+ }
68
+ }