Files
myeasycms-v2/packages/cms/keystatic/src/keystatic-storage.ts
Giancarlo Buomprisco 7ebff31475 Next.js Supabase V3 (#463)
Version 3 of the kit:
- Radix UI replaced with Base UI (using the Shadcn UI patterns)
- next-intl replaces react-i18next
- enhanceAction deprecated; usage moved to next-safe-action
- main layout now wrapped with [locale] path segment
- Teams only mode
- Layout updates
- Zod v4
- Next.js 16.2
- Typescript 6
- All other dependencies updated
- Removed deprecated Edge CSRF
- Dynamic Github Action runner
2026-03-24 13:40:38 +08:00

78 lines
2.5 KiB
TypeScript

import { CloudConfig, GitHubConfig, LocalConfig } from '@keystatic/core';
import * as z from 'zod';
/**
* @name STORAGE_KIND
* @description The kind of storage to use for the Keystatic reader.
*
* This can be provided through the `KEYSTATIC_STORAGE_KIND` environment variable or 'NEXT_PUBLIC_KEYSTATIC_STORAGE_KIND'.
* The previous environment variable `KEYSTATIC_STORAGE_KIND` is deprecated - as Keystatic may need this to be available in the client-side.
*
*/
const STORAGE_KIND =
process.env.NEXT_PUBLIC_KEYSTATIC_STORAGE_KIND ??
/* @deprecated */
process.env.KEYSTATIC_STORAGE_KIND ??
'local';
/**
* @name REPO
* @description The repository to use for the GitHub storage.
* This can be provided through the `NEXT_PUBLIC_KEYSTATIC_STORAGE_REPO` environment variable. The previous environment variable `KEYSTATIC_STORAGE_REPO` is deprecated.
*/
const REPO =
process.env.NEXT_PUBLIC_KEYSTATIC_STORAGE_REPO ??
/* @deprecated */
process.env.KEYSTATIC_STORAGE_REPO;
const BRANCH_PREFIX = process.env.KEYSTATIC_STORAGE_BRANCH_PREFIX;
const PATH_PREFIX = process.env.KEYSTATIC_PATH_PREFIX;
const PROJECT = process.env.KEYSTATIC_STORAGE_PROJECT;
/**
* @name local
* @description The configuration for the local storage.
*/
const local = z.object({
kind: z.literal('local'),
}) satisfies z.ZodType<LocalConfig['storage']>;
/**
* @name cloud
* @description The configuration for the cloud storage.
*/
const cloud = z.object({
kind: z.literal('cloud'),
project: z
.string({
error: `The Keystatic Cloud project. Please provide the value through the "KEYSTATIC_STORAGE_PROJECT" environment variable.`,
})
.min(1),
branchPrefix: z.string().optional(),
pathPrefix: z.string().optional(),
}) satisfies z.ZodType<CloudConfig['storage']>;
/**
* @name github
* @description The configuration for the GitHub storage.
*/
const github = z.object({
kind: z.literal('github'),
repo: z.custom<`${string}/${string}`>(),
branchPrefix: z.string().optional(),
pathPrefix: z.string().optional(),
}) satisfies z.ZodType<GitHubConfig['storage']>;
/**
* @name KeystaticStorage
* @description The configuration for the Keystatic storage. This is used to determine where the content is stored.
* This configuration is validated through Zod to ensure that the configuration is correct.
*/
export const KeystaticStorage = z.union([local, cloud, github]).parse({
kind: STORAGE_KIND,
project: PROJECT,
repo: REPO,
branchPrefix: BRANCH_PREFIX,
pathPrefix: PATH_PREFIX,
});