Update Supabase version and improve Keystatic's configurations

This commit updates the version of Supabase in multiple packages. It also introduces specificity to environment variables in Keystatic configuration and adds a method to create a 'KeyStatic' reader based on the storage kind. Furthermore, minor adjustments have been made to keep the environment variable names consistent.
This commit is contained in:
giancarlo
2024-04-19 14:40:11 +08:00
parent d733c2e653
commit 19b8cc793e
15 changed files with 124 additions and 63 deletions

View File

@@ -51,7 +51,7 @@
"@makerkit/data-loader-supabase-nextjs": "^1.1.0",
"@marsidev/react-turnstile": "^0.5.4",
"@radix-ui/react-icons": "^1.3.0",
"@supabase/supabase-js": "^2.42.4",
"@supabase/supabase-js": "^2.42.5",
"@tanstack/react-query": "5.29.2",
"@tanstack/react-query-next-experimental": "^5.29.2",
"@tanstack/react-table": "^8.16.0",
@@ -60,7 +60,7 @@
"i18next": "^23.11.2",
"i18next-resources-to-backend": "^1.2.1",
"lucide-react": "^0.368.0",
"next": "14.3.0-canary.9",
"next": "14.3.0-canary.7",
"next-sitemap": "^4.2.3",
"next-themes": "0.3.0",
"react": "18.2.0",

View File

@@ -43,7 +43,7 @@
"@kit/tailwind-config": "workspace:*",
"@kit/tsconfig": "workspace:*",
"@kit/ui": "workspace:^",
"@supabase/supabase-js": "^2.42.4",
"@supabase/supabase-js": "^2.42.5",
"@types/react": "^18.2.79",
"date-fns": "^3.6.0",
"lucide-react": "^0.368.0",

View File

@@ -12,7 +12,8 @@ KEYSTATIC_PATH=content
Additionally, the following environment variables may be required:
```
KEYSTATIC_PATH=local # local, cloud, github
KEYSTATIC_STORAGE_KIND=local # local, cloud, github
KEYSTATIC_PATH=
```
You can also use Keystatic Cloud or GitHub as the storage kind as remote storage.
@@ -20,16 +21,22 @@ You can also use Keystatic Cloud or GitHub as the storage kind as remote storage
If `KEYSTATIC_STORAGE_KIND` is set to `cloud`, the following environment variables are required:
```
KEYSTATIC_STORAGE_KIND=cloud
KEYSTATIC_STORAGE_PROJECT=project-id
```
If `KEYSTATIC_STORAGE_KIND` is set to `github`, the following environment variables are required:
```
KEYSTATIC_STORAGE_REPO=repo-name
KEYSTATIC_STORAGE_BRANCH_PREFIX=branch-prefix
KEYSTATIC_STORAGE_KIND=github
KEYSTATIC_STORAGE_REPO=makerkit/next-supabase-saas-kit-turbo-demo
KEYSTATIC_GITHUB_TOKEN=github_*****************************************************
KEYSTATIC_PATH_PREFIX=apps/web
KEY_STATIC_PATH_PREFIX=content
```
GitHub mode requires the installation of a GitHub app.
Of course, you need to replace the `KEYSTATIC_STORAGE_REPO` and `KEYSTATIC_GITHUB_TOKEN` with your own values.
GitHub mode requires the installation of a GitHub app for displaying the admin.
Please refer to the [Keystatic documentation](https://keystatic.com/docs/github-model) for more information.

View File

@@ -1,17 +1,14 @@
import { Entry, createReader } from '@keystatic/core/reader';
import { Cms, CmsClient } from '@kit/cms';
import config from './keystatic.config';
const reader = createReader('.', config);
type EntryProps = Entry<(typeof config)['collections']['posts']>;
import { createKeystaticReader } from './create-reader';
import { PostEntryProps } from './keystatic.config';
export class KeystaticClient implements CmsClient {
async getContentItems(options: Cms.GetContentItemsOptions) {
const reader = await createKeystaticReader();
const collection =
options.collection as keyof (typeof config)['collections'];
options.collection as keyof (typeof reader)['collections'];
if (!reader.collections[collection]) {
throw new Error(`Collection ${collection} not found`);
@@ -19,6 +16,8 @@ export class KeystaticClient implements CmsClient {
const docs = await reader.collections[collection].all();
console.log(docs);
const startOffset = options?.offset ?? 0;
const endOffset = startOffset + (options?.limit ?? 10);
@@ -87,8 +86,10 @@ export class KeystaticClient implements CmsClient {
}
async getContentItemBySlug(params: { slug: string; collection: string }) {
const reader = await createKeystaticReader();
const collection =
params.collection as keyof (typeof config)['collections'];
params.collection as keyof (typeof reader)['collections'];
if (!reader.collections[collection]) {
throw new Error(`Collection ${collection} not found`);
@@ -127,7 +128,7 @@ export class KeystaticClient implements CmsClient {
private async mapPost<
Type extends {
entry: EntryProps;
entry: PostEntryProps;
slug: string;
},
>(item: Type, children: Type[] = []): Promise<Cms.ContentItem> {

View File

@@ -0,0 +1,41 @@
import { z } from 'zod';
/**
* Create a KeyStatic reader based on the storage kind.
*/
export async function createKeystaticReader() {
switch (process.env.KEYSTATIC_STORAGE_KIND ?? 'local') {
case 'local': {
const { default: config } = await import('./keystatic.config');
const { createReader } = await import('@keystatic/core/reader');
return createReader('.', config);
}
case 'github':
case 'cloud': {
const { default: config } = await import('./keystatic.config');
const githubConfig = z
.object({
token: z.string(),
repo: z.custom<`${string}/${string}`>(),
pathPrefix: z.string().optional(),
})
.parse({
token: process.env.KEYSTATIC_GITHUB_TOKEN,
repo: process.env.KEYSTATIC_STORAGE_REPO,
pathPrefix: process.env.KEYSTATIC_PATH_PREFIX,
});
const { createGitHubReader } = await import(
'@keystatic/core/reader/github'
);
return createGitHubReader(config, githubConfig);
}
default:
throw new Error(`Unknown storage kind`);
}
}

View File

@@ -1,7 +1,7 @@
import { makeRouteHandler } from '@keystatic/next/route-handler';
import keystaticConfig from './keystatic.config';
import config from './keystatic.config';
export const { POST, GET } = makeRouteHandler({
config: keystaticConfig,
config,
});

View File

@@ -1,4 +1,5 @@
import { collection, config, fields } from '@keystatic/core';
import { Entry } from '@keystatic/core/reader';
import { z } from 'zod';
const local = z.object({
@@ -14,19 +15,30 @@ const github = z.object({
kind: z.literal('github'),
repo: z.custom<`${string}/${string}`>(),
branchPrefix: z.string().optional(),
pathPrefix: z.string().optional(),
githubToken: z.string({
required_error: 'Please provide a GitHub token',
}),
});
const storage = z.union([local, cloud, github]).parse({
kind: process.env.KEYSTATIC_STORAGE_KIND ?? 'local',
kind: process.env.KEYSTATIC_STORAGE_KIND,
project: process.env.KEYSTATIC_STORAGE_PROJECT,
repo: process.env.KEYSTATIC_STORAGE_REPO,
branchPrefix: process.env.KEYSTATIC_STORAGE_BRANCH_PREFIX,
githubToken: process.env.KEYSTATIC_GITHUB_TOKEN,
pathPrefix: process.env.KEYSTATIC_PATH_PREFIX,
});
const path = process.env.KEY_STATIC_PATH ?? 'content';
export default createKeyStaticConfig(path);
const keyStaticConfig = createKeyStaticConfig(path);
export default keyStaticConfig;
export type PostEntryProps = Entry<
(typeof keyStaticConfig)['collections']['posts']
>;
function createKeyStaticConfig(path: string) {
return config({

View File

@@ -30,7 +30,7 @@
"@kit/team-accounts": "workspace:^",
"@kit/tsconfig": "workspace:*",
"@kit/ui": "workspace:^",
"@supabase/supabase-js": "^2.42.4",
"@supabase/supabase-js": "^2.42.5",
"lucide-react": "^0.368.0",
"zod": "^3.22.4"
},

View File

@@ -31,7 +31,7 @@
"@kit/tsconfig": "workspace:*",
"@kit/ui": "workspace:^",
"@radix-ui/react-icons": "^1.3.0",
"@supabase/supabase-js": "^2.42.4",
"@supabase/supabase-js": "^2.42.5",
"@tanstack/react-query": "5.29.2",
"@types/react": "^18.2.79",
"@types/react-dom": "^18.2.25",

View File

@@ -35,7 +35,7 @@
"@kit/ui": "workspace:^",
"@makerkit/data-loader-supabase-core": "^0.0.7",
"@makerkit/data-loader-supabase-nextjs": "^1.1.0",
"@supabase/supabase-js": "^2.42.4",
"@supabase/supabase-js": "^2.42.5",
"@tanstack/react-query": "5.29.2",
"@tanstack/react-table": "^8.16.0",
"@types/react": "^18.2.79",

View File

@@ -28,7 +28,7 @@
"@kit/ui": "workspace:^",
"@marsidev/react-turnstile": "^0.5.4",
"@radix-ui/react-icons": "^1.3.0",
"@supabase/supabase-js": "^2.42.4",
"@supabase/supabase-js": "^2.42.5",
"@tanstack/react-query": "5.29.2",
"@types/react": "^18.2.79",
"lucide-react": "^0.368.0",

View File

@@ -29,7 +29,7 @@
"@kit/tailwind-config": "workspace:*",
"@kit/tsconfig": "workspace:*",
"@kit/ui": "workspace:^",
"@supabase/supabase-js": "^2.42.4",
"@supabase/supabase-js": "^2.42.5",
"@tanstack/react-query": "5.29.2",
"@tanstack/react-table": "^8.16.0",
"@types/react": "^18.2.79",

View File

@@ -27,7 +27,7 @@
"@kit/supabase": "workspace:^",
"@kit/tailwind-config": "workspace:*",
"@kit/tsconfig": "workspace:*",
"@supabase/supabase-js": "^2.42.4",
"@supabase/supabase-js": "^2.42.5",
"next": "14.3.0-canary.7",
"zod": "^3.22.4"
},

View File

@@ -29,7 +29,7 @@
"@kit/tsconfig": "workspace:*",
"@supabase/gotrue-js": "2.62.2",
"@supabase/ssr": "^0.3.0",
"@supabase/supabase-js": "^2.42.4",
"@supabase/supabase-js": "^2.42.5",
"@tanstack/react-query": "5.29.2",
"@types/react": "^18.2.79",
"next": "14.3.0-canary.7",

70
pnpm-lock.yaml generated
View File

@@ -105,10 +105,10 @@ importers:
version: link:../../packages/ui
'@makerkit/data-loader-supabase-core':
specifier: ^0.0.7
version: 0.0.7(@supabase/postgrest-js@1.15.2)(@supabase/supabase-js@2.42.4)
version: 0.0.7(@supabase/postgrest-js@1.15.2)(@supabase/supabase-js@2.42.5)
'@makerkit/data-loader-supabase-nextjs':
specifier: ^1.1.0
version: 1.1.0(@supabase/postgrest-js@1.15.2)(@supabase/supabase-js@2.42.4)(@tanstack/react-query@5.29.2)(next@14.3.0-canary.7)(react@18.2.0)
version: 1.1.0(@supabase/postgrest-js@1.15.2)(@supabase/supabase-js@2.42.5)(@tanstack/react-query@5.29.2)(next@14.3.0-canary.7)(react@18.2.0)
'@marsidev/react-turnstile':
specifier: ^0.5.4
version: 0.5.4(react-dom@18.2.0)(react@18.2.0)
@@ -116,8 +116,8 @@ importers:
specifier: ^1.3.0
version: 1.3.0(react@18.2.0)
'@supabase/supabase-js':
specifier: ^2.42.4
version: 2.42.4
specifier: ^2.42.5
version: 2.42.5
'@tanstack/react-query':
specifier: 5.29.2
version: 5.29.2(react@18.2.0)
@@ -285,8 +285,8 @@ importers:
specifier: workspace:^
version: link:../../ui
'@supabase/supabase-js':
specifier: ^2.42.4
version: 2.42.4
specifier: ^2.42.5
version: 2.42.5
'@types/react':
specifier: ^18.2.79
version: 18.2.79
@@ -507,8 +507,8 @@ importers:
specifier: workspace:^
version: link:../ui
'@supabase/supabase-js':
specifier: ^2.42.4
version: 2.42.4
specifier: ^2.42.5
version: 2.42.5
lucide-react:
specifier: ^0.368.0
version: 0.368.0(react@18.2.0)
@@ -581,8 +581,8 @@ importers:
specifier: ^1.3.0
version: 1.3.0(react@18.2.0)
'@supabase/supabase-js':
specifier: ^2.42.4
version: 2.42.4
specifier: ^2.42.5
version: 2.42.5
'@tanstack/react-query':
specifier: 5.29.2
version: 5.29.2(react@18.2.0)
@@ -648,13 +648,13 @@ importers:
version: link:../../ui
'@makerkit/data-loader-supabase-core':
specifier: ^0.0.7
version: 0.0.7(@supabase/postgrest-js@1.15.2)(@supabase/supabase-js@2.42.4)
version: 0.0.7(@supabase/postgrest-js@1.15.2)(@supabase/supabase-js@2.42.5)
'@makerkit/data-loader-supabase-nextjs':
specifier: ^1.1.0
version: 1.1.0(@supabase/postgrest-js@1.15.2)(@supabase/supabase-js@2.42.4)(@tanstack/react-query@5.29.2)(next@14.3.0-canary.7)(react@18.2.0)
version: 1.1.0(@supabase/postgrest-js@1.15.2)(@supabase/supabase-js@2.42.5)(@tanstack/react-query@5.29.2)(next@14.3.0-canary.7)(react@18.2.0)
'@supabase/supabase-js':
specifier: ^2.42.4
version: 2.42.4
specifier: ^2.42.5
version: 2.42.5
'@tanstack/react-query':
specifier: 5.29.2
version: 5.29.2(react@18.2.0)
@@ -713,8 +713,8 @@ importers:
specifier: ^1.3.0
version: 1.3.0(react@18.2.0)
'@supabase/supabase-js':
specifier: ^2.42.4
version: 2.42.4
specifier: ^2.42.5
version: 2.42.5
'@tanstack/react-query':
specifier: 5.29.2
version: 5.29.2(react@18.2.0)
@@ -786,8 +786,8 @@ importers:
specifier: workspace:^
version: link:../../ui
'@supabase/supabase-js':
specifier: ^2.42.4
version: 2.42.4
specifier: ^2.42.5
version: 2.42.5
'@tanstack/react-query':
specifier: 5.29.2
version: 5.29.2(react@18.2.0)
@@ -990,8 +990,8 @@ importers:
specifier: workspace:*
version: link:../../tooling/typescript
'@supabase/supabase-js':
specifier: ^2.42.4
version: 2.42.4
specifier: ^2.42.5
version: 2.42.5
next:
specifier: 14.3.0-canary.7
version: 14.3.0-canary.7(@opentelemetry/api@1.8.0)(react-dom@18.2.0)(react@18.2.0)
@@ -1037,10 +1037,10 @@ importers:
version: 2.62.2
'@supabase/ssr':
specifier: ^0.3.0
version: 0.3.0(@supabase/supabase-js@2.42.4)
version: 0.3.0(@supabase/supabase-js@2.42.5)
'@supabase/supabase-js':
specifier: ^2.42.4
version: 2.42.4
specifier: ^2.42.5
version: 2.42.5
'@tanstack/react-query':
specifier: 5.29.2
version: 5.29.2(react@18.2.0)
@@ -2371,17 +2371,17 @@ packages:
engines: {node: '>=18'}
dev: false
/@makerkit/data-loader-supabase-core@0.0.7(@supabase/postgrest-js@1.15.2)(@supabase/supabase-js@2.42.4):
/@makerkit/data-loader-supabase-core@0.0.7(@supabase/postgrest-js@1.15.2)(@supabase/supabase-js@2.42.5):
resolution: {integrity: sha512-9Zi7GmBZaedHl9x+LnasUL3ztx2oLInwI1uzdw4E830gSNQr/hx5/Sodd1A9cXECn51Ub5HWEJ8kfBZwX0qCKQ==}
peerDependencies:
'@supabase/postgrest-js': '>1.0.0'
'@supabase/supabase-js': '>=2.0.0'
dependencies:
'@supabase/postgrest-js': 1.15.2
'@supabase/supabase-js': 2.42.4
'@supabase/supabase-js': 2.42.5
ts-case-convert: 2.0.7
/@makerkit/data-loader-supabase-nextjs@1.1.0(@supabase/postgrest-js@1.15.2)(@supabase/supabase-js@2.42.4)(@tanstack/react-query@5.29.2)(next@14.3.0-canary.7)(react@18.2.0):
/@makerkit/data-loader-supabase-nextjs@1.1.0(@supabase/postgrest-js@1.15.2)(@supabase/supabase-js@2.42.5)(@tanstack/react-query@5.29.2)(next@14.3.0-canary.7)(react@18.2.0):
resolution: {integrity: sha512-4+QtHMXeOCPFKnP14a/K0mVUGr/809WE1J7RF5Eue45xdXMbvhyWIHqRNvvpUo9N6MnDO7u9IaYKO0aneMPFrw==}
peerDependencies:
'@supabase/supabase-js': '>=2.0.0'
@@ -2389,8 +2389,8 @@ packages:
next: 14.3.0-canary.7
react: 18.2.0
dependencies:
'@makerkit/data-loader-supabase-core': 0.0.7(@supabase/postgrest-js@1.15.2)(@supabase/supabase-js@2.42.4)
'@supabase/supabase-js': 2.42.4
'@makerkit/data-loader-supabase-core': 0.0.7(@supabase/postgrest-js@1.15.2)(@supabase/supabase-js@2.42.5)
'@supabase/supabase-js': 2.42.5
'@tanstack/react-query': 5.29.2(react@18.2.0)
next: 14.3.0-canary.7(@opentelemetry/api@1.8.0)(react-dom@18.2.0)(react@18.2.0)
react: 18.2.0
@@ -5820,8 +5820,8 @@ packages:
engines: {node: '>=12.16'}
dev: false
/@supabase/auth-js@2.63.0:
resolution: {integrity: sha512-yIgcHnlgv24GxHtVGUhwGqAFDyJkPIC/xjx7HostN08A8yCy8HIfl4JEkTKyBqD1v1L05jNEJOUke4Lf4O1+Qg==}
/@supabase/auth-js@2.63.1:
resolution: {integrity: sha512-iwdmIc/w5QN7aMfYThEgUt1l2i0KuohZ4XNk1adECg0LETQYEzmbVToKFKZLLZ+GyNtpsExSgVY/AUWOwubGXA==}
dependencies:
'@supabase/node-fetch': 2.6.15
@@ -5858,12 +5858,12 @@ packages:
- bufferutil
- utf-8-validate
/@supabase/ssr@0.3.0(@supabase/supabase-js@2.42.4):
/@supabase/ssr@0.3.0(@supabase/supabase-js@2.42.5):
resolution: {integrity: sha512-lcVyQ7H6eumb2FB1Wa2N+jYWMfq6CFza3KapikT0fgttMQ+QvDgpNogx9jI8bZgKds+XFSMCojxFvFb+gwdbfA==}
peerDependencies:
'@supabase/supabase-js': ^2.33.1
dependencies:
'@supabase/supabase-js': 2.42.4
'@supabase/supabase-js': 2.42.5
cookie: 0.5.0
ramda: 0.29.1
dev: true
@@ -5873,10 +5873,10 @@ packages:
dependencies:
'@supabase/node-fetch': 2.6.15
/@supabase/supabase-js@2.42.4:
resolution: {integrity: sha512-tRn3wloKnnFdmEr3O2VIaxqzKACpyJ3ymLDmeq0V5lvhkJ+B4VH+QmDrnBbJJUkO2t+IHg65j5jombZxU4yMyw==}
/@supabase/supabase-js@2.42.5:
resolution: {integrity: sha512-T/FlVmNHR/MDl8KhmNLb94dh+cTpqyvFlNI/Zd97dwS1yCm59xM+sTzmQLKnGNY5sPuwp40/w52bWrczdjOYtA==}
dependencies:
'@supabase/auth-js': 2.63.0
'@supabase/auth-js': 2.63.1
'@supabase/functions-js': 2.3.0
'@supabase/node-fetch': 2.6.15
'@supabase/postgrest-js': 1.15.2