@voyantjs/plugin-sanity-cms 0.24.0 → 0.24.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voyantjs/plugin-sanity-cms",
3
- "version": "0.24.0",
3
+ "version": "0.24.1",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "exports": {
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "zod": "^4.3.6",
30
- "@voyantjs/core": "0.24.0"
30
+ "@voyantjs/core": "0.24.1"
31
31
  },
32
32
  "devDependencies": {
33
33
  "typescript": "^6.0.2",
package/dist/client.d.ts DELETED
@@ -1,54 +0,0 @@
1
- import type { SanityDocBody, SanityFetch } from "./types.js";
2
- /**
3
- * Options for {@link createSanityClient}.
4
- */
5
- export interface SanityClientOptions {
6
- /** Sanity project ID (the short slug from sanity.io/manage). */
7
- projectId: string;
8
- /** Sanity dataset (e.g. `"production"`). */
9
- dataset: string;
10
- /**
11
- * Sanity API token with write access. Sent as
12
- * `Authorization: Bearer ${token}`.
13
- */
14
- token: string;
15
- /**
16
- * Sanity API version (date-based, e.g. `"2024-01-01"`). Defaults to
17
- * `"2024-01-01"`.
18
- */
19
- apiVersion?: string;
20
- /**
21
- * Field on the Sanity document that stores the Voyant record's ID.
22
- * Defaults to `"voyantId"`. A matching field (+unique index) must be
23
- * declared in the Sanity schema.
24
- */
25
- voyantIdField?: string;
26
- /**
27
- * Sanity API host. Defaults to `"api.sanity.io"`. Override for regional
28
- * hosts, proxies, or self-hosted deployments.
29
- */
30
- apiHost?: string;
31
- /** Override `fetch` (e.g. in tests). Defaults to global `fetch`. */
32
- fetch?: SanityFetch;
33
- }
34
- export interface SanityClient {
35
- /**
36
- * Create or replace a document whose {@link SanityClientOptions.voyantIdField}
37
- * equals `voyantId`.
38
- */
39
- upsertByVoyantId(documentType: string, voyantId: string, body: SanityDocBody): Promise<{
40
- _id: string;
41
- created: boolean;
42
- }>;
43
- /**
44
- * Delete a document whose `voyantId` field equals the given value.
45
- * Returns `false` if no matching document was found.
46
- */
47
- deleteByVoyantId(documentType: string, voyantId: string): Promise<boolean>;
48
- /** Find at most one document whose `voyantId` field equals the given value. */
49
- findByVoyantId(documentType: string, voyantId: string): Promise<{
50
- _id: string;
51
- } | null>;
52
- }
53
- export declare function createSanityClient(options: SanityClientOptions): SanityClient;
54
- //# sourceMappingURL=client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE5D;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,gEAAgE;IAChE,SAAS,EAAE,MAAM,CAAA;IACjB,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAA;IACf;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,oEAAoE;IACpE,KAAK,CAAC,EAAE,WAAW,CAAA;CACpB;AAWD,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,gBAAgB,CACd,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,aAAa,GAClB,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAA;IAC7C;;;OAGG;IACH,gBAAgB,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAC1E,+EAA+E;IAC/E,cAAc,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC,CAAA;CACxF;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,YAAY,CAiH7E"}
package/dist/client.js DELETED
@@ -1,91 +0,0 @@
1
- export function createSanityClient(options) {
2
- const apiVersion = options.apiVersion ?? "2024-01-01";
3
- const voyantIdField = options.voyantIdField ?? "voyantId";
4
- const apiHost = options.apiHost ?? "api.sanity.io";
5
- const baseUrl = `https://${options.projectId}.${apiHost}/v${apiVersion}/data`;
6
- const fetchImpl = options.fetch ?? globalThis.fetch;
7
- function headers() {
8
- return {
9
- Authorization: `Bearer ${options.token}`,
10
- "Content-Type": "application/json",
11
- };
12
- }
13
- async function request(method, path, body) {
14
- if (!fetchImpl) {
15
- throw new Error("Sanity client requires a fetch implementation");
16
- }
17
- const init = {
18
- method,
19
- headers: headers(),
20
- };
21
- if (body !== undefined)
22
- init.body = JSON.stringify(body);
23
- const response = await fetchImpl(`${baseUrl}${path}`, init);
24
- let text = "";
25
- let json = null;
26
- try {
27
- text = await response.text();
28
- json = text ? JSON.parse(text) : null;
29
- }
30
- catch {
31
- // leave json as null, surface text
32
- }
33
- return { ok: response.ok, status: response.status, json, text };
34
- }
35
- async function findByVoyantId(documentType, voyantId) {
36
- // GROQ parameters are JSON-encoded values attached as $-prefixed query params.
37
- const groq = `*[_type == $type && ${voyantIdField} == $vid][0]{_id}`;
38
- const query = [
39
- `query=${encodeURIComponent(groq)}`,
40
- `$type=${encodeURIComponent(JSON.stringify(documentType))}`,
41
- `$vid=${encodeURIComponent(JSON.stringify(voyantId))}`,
42
- ].join("&");
43
- const res = await request("GET", `/query/${options.dataset}?${query}`);
44
- if (!res.ok) {
45
- throw new Error(`Sanity findByVoyantId(${documentType}) failed (${res.status}): ${res.text}`);
46
- }
47
- const body = (res.json ?? {});
48
- const first = body.result;
49
- if (!first)
50
- return null;
51
- return { _id: first._id };
52
- }
53
- async function mutate(mutations) {
54
- return request("POST", `/mutate/${options.dataset}?returnIds=true&visibility=sync`, {
55
- mutations,
56
- });
57
- }
58
- async function upsertByVoyantId(documentType, voyantId, body) {
59
- const existing = await findByVoyantId(documentType, voyantId);
60
- const docFields = { ...body, [voyantIdField]: voyantId };
61
- if (existing) {
62
- const res = await mutate([{ patch: { id: existing._id, set: docFields } }]);
63
- if (!res.ok) {
64
- throw new Error(`Sanity update(${documentType}/${existing._id}) failed (${res.status}): ${res.text}`);
65
- }
66
- return { _id: existing._id, created: false };
67
- }
68
- const createDoc = { _type: documentType, ...docFields };
69
- const res = await mutate([{ create: createDoc }]);
70
- if (!res.ok) {
71
- throw new Error(`Sanity create(${documentType}) failed (${res.status}): ${res.text}`);
72
- }
73
- const json = (res.json ?? {});
74
- const id = json.results?.[0]?.id;
75
- if (!id) {
76
- throw new Error(`Sanity create(${documentType}) response missing id`);
77
- }
78
- return { _id: id, created: true };
79
- }
80
- async function deleteByVoyantId(documentType, voyantId) {
81
- const existing = await findByVoyantId(documentType, voyantId);
82
- if (!existing)
83
- return false;
84
- const res = await mutate([{ delete: { id: existing._id } }]);
85
- if (!res.ok) {
86
- throw new Error(`Sanity delete(${documentType}/${existing._id}) failed (${res.status}): ${res.text}`);
87
- }
88
- return true;
89
- }
90
- return { upsertByVoyantId, deleteByVoyantId, findByVoyantId };
91
- }
package/dist/index.d.ts DELETED
@@ -1,8 +0,0 @@
1
- export type { SanityClient, SanityClientOptions } from "./client.js";
2
- export { createSanityClient } from "./client.js";
3
- export type { SanityCmsPluginOptions, SanityLogger, SanityMapFn, SanitySyncEventNames, } from "./plugin.js";
4
- export { sanityCmsPlugin } from "./plugin.js";
5
- export type { ResolvedSanitySyncEventNames, SanitySyncRuntime } from "./runtime.js";
6
- export { createSanitySyncRuntime } from "./runtime.js";
7
- export type { SanityDocBody, SanityFetch, VoyantEntityEvent } from "./types.js";
8
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAChD,YAAY,EACV,sBAAsB,EACtB,YAAY,EACZ,WAAW,EACX,oBAAoB,GACrB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,YAAY,EAAE,4BAA4B,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AACnF,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAA;AACtD,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA"}
package/dist/index.js DELETED
@@ -1,3 +0,0 @@
1
- export { createSanityClient } from "./client.js";
2
- export { sanityCmsPlugin } from "./plugin.js";
3
- export { createSanitySyncRuntime } from "./runtime.js";
package/dist/plugin.d.ts DELETED
@@ -1,21 +0,0 @@
1
- import type { Plugin } from "@voyantjs/core";
2
- import type { SanityClientOptions } from "./client.js";
3
- import type { SanityDocBody, VoyantEntityEvent } from "./types.js";
4
- export interface SanitySyncEventNames {
5
- created?: string;
6
- updated?: string;
7
- deleted?: string;
8
- }
9
- export type SanityMapFn = (event: VoyantEntityEvent) => SanityDocBody;
10
- export interface SanityLogger {
11
- error: (message: string, meta?: unknown) => void;
12
- info?: (message: string, meta?: unknown) => void;
13
- }
14
- export interface SanityCmsPluginOptions extends SanityClientOptions {
15
- documentType: string;
16
- events?: SanitySyncEventNames;
17
- mapEvent?: SanityMapFn;
18
- logger?: SanityLogger;
19
- }
20
- export declare function sanityCmsPlugin(options: SanityCmsPluginOptions): Plugin;
21
- //# sourceMappingURL=plugin.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAc,MAAM,gBAAgB,CAAA;AAGxD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEtD,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAGlE,MAAM,WAAW,oBAAoB;IACnC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,MAAM,WAAW,GAAG,CAAC,KAAK,EAAE,iBAAiB,KAAK,aAAa,CAAA;AAErE,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;IAChD,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;CACjD;AAED,MAAM,WAAW,sBAAuB,SAAQ,mBAAmB;IACjE,YAAY,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,oBAAoB,CAAA;IAC7B,QAAQ,CAAC,EAAE,WAAW,CAAA;IACtB,MAAM,CAAC,EAAE,YAAY,CAAA;CACtB;AASD,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,MAAM,CAgDvE"}
package/dist/plugin.js DELETED
@@ -1,81 +0,0 @@
1
- import { ZodError } from "zod";
2
- import { createSanitySyncRuntime } from "./runtime.js";
3
- import { sanityCmsPluginOptionsSchema } from "./validation.js";
4
- function coerceEvent(data) {
5
- if (data == null || typeof data !== "object")
6
- return null;
7
- const maybe = data;
8
- if (typeof maybe.id !== "string")
9
- return null;
10
- return maybe;
11
- }
12
- export function sanityCmsPlugin(options) {
13
- const validatedOptions = parseSanityCmsPluginOptions(options);
14
- const { client, mapEvent, logger, eventNames } = createSanitySyncRuntime(validatedOptions);
15
- const subscribers = [
16
- {
17
- event: eventNames.created,
18
- handler: async (envelope) => {
19
- const event = coerceEvent(envelope.data);
20
- if (!event)
21
- return;
22
- try {
23
- await client.upsertByVoyantId(validatedOptions.documentType, event.id, mapEvent(event));
24
- }
25
- catch (err) {
26
- logger.error(`[sanity-cms] upsert on "${eventNames.created}" failed for ${event.id}`, err);
27
- }
28
- },
29
- },
30
- {
31
- event: eventNames.updated,
32
- handler: async (envelope) => {
33
- const event = coerceEvent(envelope.data);
34
- if (!event)
35
- return;
36
- try {
37
- await client.upsertByVoyantId(validatedOptions.documentType, event.id, mapEvent(event));
38
- }
39
- catch (err) {
40
- logger.error(`[sanity-cms] upsert on "${eventNames.updated}" failed for ${event.id}`, err);
41
- }
42
- },
43
- },
44
- {
45
- event: eventNames.deleted,
46
- handler: async (envelope) => {
47
- const event = coerceEvent(envelope.data);
48
- if (!event)
49
- return;
50
- try {
51
- await client.deleteByVoyantId(validatedOptions.documentType, event.id);
52
- }
53
- catch (err) {
54
- logger.error(`[sanity-cms] delete on "${eventNames.deleted}" failed for ${event.id}`, err);
55
- }
56
- },
57
- },
58
- ];
59
- return {
60
- name: "sanity-cms",
61
- version: "0.1.0",
62
- subscribers,
63
- };
64
- }
65
- function parseSanityCmsPluginOptions(options) {
66
- try {
67
- return sanityCmsPluginOptionsSchema.parse(options);
68
- }
69
- catch (error) {
70
- if (error instanceof ZodError) {
71
- const detail = error.issues
72
- .map((issue) => {
73
- const path = issue.path.join(".") || "options";
74
- return `${path}: ${issue.message}`;
75
- })
76
- .join("; ");
77
- throw new Error(`Invalid Sanity CMS plugin options: ${detail}`);
78
- }
79
- throw error;
80
- }
81
- }
package/dist/runtime.d.ts DELETED
@@ -1,15 +0,0 @@
1
- import { createSanityClient } from "./client.js";
2
- import type { SanityCmsPluginOptions, SanityLogger, SanityMapFn } from "./plugin.js";
3
- export interface ResolvedSanitySyncEventNames {
4
- created: string;
5
- updated: string;
6
- deleted: string;
7
- }
8
- export interface SanitySyncRuntime {
9
- client: ReturnType<typeof createSanityClient>;
10
- logger: SanityLogger;
11
- mapEvent: SanityMapFn;
12
- eventNames: ResolvedSanitySyncEventNames;
13
- }
14
- export declare function createSanitySyncRuntime(options: SanityCmsPluginOptions): SanitySyncRuntime;
15
- //# sourceMappingURL=runtime.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,KAAK,EAAE,sBAAsB,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAGpF,MAAM,WAAW,4BAA4B;IAC3C,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAA;IAC7C,MAAM,EAAE,YAAY,CAAA;IACpB,QAAQ,EAAE,WAAW,CAAA;IACrB,UAAU,EAAE,4BAA4B,CAAA;CACzC;AAOD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,sBAAsB,GAAG,iBAAiB,CAW1F"}
package/dist/runtime.js DELETED
@@ -1,17 +0,0 @@
1
- import { createSanityClient } from "./client.js";
2
- function defaultMapEvent(event) {
3
- const { id: _id, ...rest } = event;
4
- return rest;
5
- }
6
- export function createSanitySyncRuntime(options) {
7
- return {
8
- client: createSanityClient(options),
9
- logger: options.logger ?? console,
10
- mapEvent: options.mapEvent ?? defaultMapEvent,
11
- eventNames: {
12
- created: options.events?.created ?? "product.created",
13
- updated: options.events?.updated ?? "product.updated",
14
- deleted: options.events?.deleted ?? "product.deleted",
15
- },
16
- };
17
- }
package/dist/types.d.ts DELETED
@@ -1,31 +0,0 @@
1
- /**
2
- * Minimal shape Voyant events expose when carrying a record identifier.
3
- * The plugin accepts anything with `id: string`; everything else is passed
4
- * through to `mapEvent` untouched.
5
- */
6
- export interface VoyantEntityEvent {
7
- id: string;
8
- [key: string]: unknown;
9
- }
10
- /**
11
- * A Sanity document body, as a bag of properties. Sanity assigns `_id` +
12
- * `_type` on creation; the plugin sets a `voyantId` field (configurable)
13
- * for idempotent lookups.
14
- */
15
- export type SanityDocBody = Record<string, unknown>;
16
- /**
17
- * Minimal `fetch` shape the Sanity client depends on. Works with the global
18
- * `fetch` in Node 18+ / Cloudflare Workers / browsers, and is trivially
19
- * stubbable in tests.
20
- */
21
- export type SanityFetch = (input: string, init: {
22
- method: string;
23
- headers: Record<string, string>;
24
- body?: string;
25
- }) => Promise<{
26
- ok: boolean;
27
- status: number;
28
- json: () => Promise<unknown>;
29
- text: () => Promise<string>;
30
- }>;
31
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAA;IACV,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEnD;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,CACxB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE;IACJ,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,KACE,OAAO,CAAC;IACX,EAAE,EAAE,OAAO,CAAA;IACX,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;IAC5B,IAAI,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAA;CAC5B,CAAC,CAAA"}
package/dist/types.js DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1,17 +0,0 @@
1
- import { z } from "zod";
2
- import type { SanityLogger, SanityMapFn, SanitySyncEventNames } from "./plugin.js";
3
- import type { SanityFetch } from "./types.js";
4
- export declare const sanityCmsPluginOptionsSchema: z.ZodObject<{
5
- projectId: z.ZodString;
6
- dataset: z.ZodString;
7
- token: z.ZodString;
8
- documentType: z.ZodString;
9
- apiVersion: z.ZodOptional<z.ZodString>;
10
- voyantIdField: z.ZodOptional<z.ZodString>;
11
- apiHost: z.ZodOptional<z.ZodString>;
12
- fetch: z.ZodOptional<z.ZodCustom<SanityFetch | undefined, SanityFetch | undefined>>;
13
- events: z.ZodOptional<z.ZodCustom<SanitySyncEventNames | undefined, SanitySyncEventNames | undefined>>;
14
- mapEvent: z.ZodOptional<z.ZodCustom<SanityMapFn | undefined, SanityMapFn | undefined>>;
15
- logger: z.ZodOptional<z.ZodCustom<SanityLogger | undefined, SanityLogger | undefined>>;
16
- }, z.core.$strip>;
17
- //# sourceMappingURL=validation.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,KAAK,EAEV,YAAY,EACZ,WAAW,EACX,oBAAoB,EACrB,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAkC7C,eAAO,MAAM,4BAA4B;;;;;;;;;;;;iBAYK,CAAA"}
@@ -1,31 +0,0 @@
1
- import { z } from "zod";
2
- const optionalString = z.string().trim().min(1).optional();
3
- const optionalFetch = z.custom((value) => value === undefined || typeof value === "function", "Expected a fetch implementation function");
4
- const optionalLogger = z.custom((value) => value === undefined ||
5
- (typeof value === "object" &&
6
- value !== null &&
7
- typeof value.error === "function" &&
8
- ((value.info ?? undefined) === undefined ||
9
- typeof value.info === "function")), "Expected a logger with an error function");
10
- const optionalMapEvent = z.custom((value) => value === undefined || typeof value === "function", "Expected a mapEvent function");
11
- const optionalEvents = z.custom((value) => {
12
- if (value === undefined)
13
- return true;
14
- if (typeof value !== "object" || value === null)
15
- return false;
16
- const events = value;
17
- return [events.created, events.updated, events.deleted].every((entry) => entry === undefined || (typeof entry === "string" && entry.trim().length > 0));
18
- }, "Expected event names to be non-empty strings");
19
- export const sanityCmsPluginOptionsSchema = z.object({
20
- projectId: z.string().trim().min(1),
21
- dataset: z.string().trim().min(1),
22
- token: z.string().trim().min(1),
23
- documentType: z.string().trim().min(1),
24
- apiVersion: optionalString,
25
- voyantIdField: optionalString,
26
- apiHost: optionalString,
27
- fetch: optionalFetch.optional(),
28
- events: optionalEvents.optional(),
29
- mapEvent: optionalMapEvent.optional(),
30
- logger: optionalLogger.optional(),
31
- });