nextjs-cms 0.9.28 → 0.9.30

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.
Files changed (91) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +279 -279
  3. package/dist/api/actions/pages.d.ts +3 -3
  4. package/dist/api/index.d.ts +974 -1
  5. package/dist/api/index.d.ts.map +1 -1
  6. package/dist/api/index.js +13 -0
  7. package/dist/api/lib/serverActions.d.ts +49 -13
  8. package/dist/api/lib/serverActions.d.ts.map +1 -1
  9. package/dist/api/lib/serverActions.js +31 -103
  10. package/dist/api/root.d.ts +1916 -18
  11. package/dist/api/root.d.ts.map +1 -1
  12. package/dist/api/root.js +83 -18
  13. package/dist/api/routers/config.d.ts.map +1 -1
  14. package/dist/api/routers/gallery.d.ts +0 -1
  15. package/dist/api/routers/gallery.d.ts.map +1 -1
  16. package/dist/api/routers/gallery.js +8 -36
  17. package/dist/api/routers/hasItemsSection.d.ts +30 -5
  18. package/dist/api/routers/hasItemsSection.d.ts.map +1 -1
  19. package/dist/api/routers/navigation.d.ts +3 -3
  20. package/dist/api/routers/simpleSection.d.ts +15 -3
  21. package/dist/api/routers/simpleSection.d.ts.map +1 -1
  22. package/dist/api/trpc/client.d.ts.map +1 -1
  23. package/dist/api/trpc/client.js +8 -1
  24. package/dist/api/trpc/root.d.ts +3 -3
  25. package/dist/api/trpc/root.d.ts.map +1 -1
  26. package/dist/api/trpc/routers/config.d.ts.map +1 -1
  27. package/dist/api/trpc/routers/hasItemsSection.d.ts.map +1 -1
  28. package/dist/api/trpc/routers/navigation.d.ts +3 -3
  29. package/dist/api/trpc/routers/simpleSection.d.ts.map +1 -1
  30. package/dist/api/trpc/server.d.ts +9 -9
  31. package/dist/api/trpc/server.d.ts.map +1 -1
  32. package/dist/auth/trpc.d.ts +1 -1
  33. package/dist/auth/trpc.d.ts.map +1 -1
  34. package/dist/auth/trpc.js +1 -0
  35. package/dist/cli/lib/db-config.js +10 -10
  36. package/dist/cli/lib/update-sections.d.ts.map +1 -1
  37. package/dist/cli/lib/update-sections.js +24 -29
  38. package/dist/core/db/table-checker/MysqlTable.js +10 -10
  39. package/dist/core/factories/section-factory-with-esbuild.js +9 -9
  40. package/dist/core/factories/section-factory-with-jiti.js +9 -9
  41. package/dist/core/fields/dateRange.d.ts +115 -0
  42. package/dist/core/fields/dateRange.d.ts.map +1 -0
  43. package/dist/core/fields/dateRange.js +149 -0
  44. package/dist/core/sections/category.d.ts +42 -42
  45. package/dist/core/sections/hasItems.d.ts +42 -42
  46. package/dist/core/sections/section.d.ts +22 -22
  47. package/dist/core/sections/simple.d.ts +8 -8
  48. package/dist/plugins/derive.d.ts +0 -8
  49. package/dist/plugins/derive.d.ts.map +1 -1
  50. package/dist/plugins/derive.js +0 -32
  51. package/dist/plugins/server.d.ts +1 -1
  52. package/dist/plugins/server.d.ts.map +1 -1
  53. package/dist/plugins/server.js +1 -1
  54. package/dist/translations/client.d.ts +4 -4
  55. package/dist/translations/locale-cookie.d.ts +24 -0
  56. package/dist/translations/locale-cookie.d.ts.map +1 -0
  57. package/dist/translations/locale-cookie.js +44 -0
  58. package/dist/translations/locale-utils.d.ts +8 -0
  59. package/dist/translations/locale-utils.d.ts.map +1 -0
  60. package/dist/translations/locale-utils.js +11 -0
  61. package/dist/translations/localization.d.ts +40 -0
  62. package/dist/translations/localization.d.ts.map +1 -0
  63. package/dist/translations/localization.js +48 -0
  64. package/dist/validators/dateRange.d.ts +11 -0
  65. package/dist/validators/dateRange.d.ts.map +1 -0
  66. package/dist/validators/dateRange.js +16 -0
  67. package/package.json +3 -3
  68. package/dist/api/client.d.ts +0 -30
  69. package/dist/api/client.d.ts.map +0 -1
  70. package/dist/api/client.js +0 -82
  71. package/dist/api/server.d.ts +0 -2748
  72. package/dist/api/server.d.ts.map +0 -1
  73. package/dist/api/server.js +0 -100
  74. package/dist/api/utils/async-caller-proxy.d.ts +0 -2
  75. package/dist/api/utils/async-caller-proxy.d.ts.map +0 -1
  76. package/dist/api/utils/async-caller-proxy.js +0 -36
  77. package/dist/api/utils/lazy-caller-proxy.d.ts +0 -2
  78. package/dist/api/utils/lazy-caller-proxy.d.ts.map +0 -1
  79. package/dist/api/utils/lazy-caller-proxy.js +0 -36
  80. package/dist/api/utils/router-types.d.ts +0 -7
  81. package/dist/api/utils/router-types.d.ts.map +0 -1
  82. package/dist/api/utils/router-types.js +0 -0
  83. package/dist/plugins/manifest.d.ts +0 -28
  84. package/dist/plugins/manifest.d.ts.map +0 -1
  85. package/dist/plugins/manifest.js +0 -83
  86. package/dist/plugins/registry.d.ts +0 -22
  87. package/dist/plugins/registry.d.ts.map +0 -1
  88. package/dist/plugins/registry.js +0 -25
  89. package/dist/utils/log.d.ts +0 -18
  90. package/dist/utils/log.d.ts.map +0 -1
  91. package/dist/utils/log.js +0 -28
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Localization utilities for resolving localized strings.
3
+ * Supports Payload CMS-style translations where developers can provide
4
+ * translations directly in field labels and section titles.
5
+ */
6
+ /**
7
+ * A localized string can be either:
8
+ * - A plain string (backward compatible)
9
+ * - An object with language codes as keys and translated strings as values
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * // Single language (backward compatible)
14
+ * label: 'Title'
15
+ *
16
+ * // Multiple languages
17
+ * label: {
18
+ * en: 'Title',
19
+ * ar: 'العنوان'
20
+ * }
21
+ * ```
22
+ */
23
+ export type LocalizedString = string | Record<string, string>;
24
+ /**
25
+ * Resolve a localized string to a specific locale.
26
+ * If the string is a plain string, it's returned as-is.
27
+ * If it's an object, the value for the given locale is returned.
28
+ * Falls back to the first available language or the fallback locale if the requested locale is not found.
29
+ *
30
+ * @param localized - The localized string (string or object with language codes)
31
+ * @param locale - The target locale code (e.g., 'en', 'ar')
32
+ * @param fallbackLocale - The fallback locale code if the requested locale is not found
33
+ * @returns The resolved string for the given locale
34
+ */
35
+ export declare function resolveLocalizedString(localized: LocalizedString | undefined, locale: string, fallbackLocale?: string): string;
36
+ /**
37
+ * Check if a value is a localized string object (not a plain string)
38
+ */
39
+ export declare function isLocalizedObject(value: LocalizedString | undefined): value is Record<string, string>;
40
+ //# sourceMappingURL=localization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localization.d.ts","sourceRoot":"","sources":["../../src/translations/localization.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAE7D;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAClC,SAAS,EAAE,eAAe,GAAG,SAAS,EACtC,MAAM,EAAE,MAAM,EACd,cAAc,GAAE,MAAa,GAC9B,MAAM,CA8BR;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,eAAe,GAAG,SAAS,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAErG"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Localization utilities for resolving localized strings.
3
+ * Supports Payload CMS-style translations where developers can provide
4
+ * translations directly in field labels and section titles.
5
+ */
6
+ /**
7
+ * Resolve a localized string to a specific locale.
8
+ * If the string is a plain string, it's returned as-is.
9
+ * If it's an object, the value for the given locale is returned.
10
+ * Falls back to the first available language or the fallback locale if the requested locale is not found.
11
+ *
12
+ * @param localized - The localized string (string or object with language codes)
13
+ * @param locale - The target locale code (e.g., 'en', 'ar')
14
+ * @param fallbackLocale - The fallback locale code if the requested locale is not found
15
+ * @returns The resolved string for the given locale
16
+ */
17
+ export function resolveLocalizedString(localized, locale, fallbackLocale = 'en') {
18
+ if (!localized) {
19
+ return '';
20
+ }
21
+ // If it's a plain string, return as-is (backward compatible)
22
+ if (typeof localized === 'string') {
23
+ return localized;
24
+ }
25
+ // If it's an object, resolve based on locale
26
+ if (typeof localized === 'object') {
27
+ // Try the requested locale first
28
+ if (localized[locale]) {
29
+ return localized[locale];
30
+ }
31
+ // Try the fallback locale
32
+ if (localized[fallbackLocale]) {
33
+ return localized[fallbackLocale];
34
+ }
35
+ // Fall back to the first available language
36
+ const firstKey = Object.keys(localized)[0];
37
+ if (firstKey && localized[firstKey]) {
38
+ return localized[firstKey];
39
+ }
40
+ }
41
+ return '';
42
+ }
43
+ /**
44
+ * Check if a value is a localized string object (not a plain string)
45
+ */
46
+ export function isLocalizedObject(value) {
47
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
48
+ }
@@ -0,0 +1,11 @@
1
+ import * as z from 'zod';
2
+ import type { DateRangeFieldClientConfig } from '../core/fields/index.js';
3
+ /**
4
+ * Returns a record of two Zod schemas keyed by startName and endName.
5
+ * Form.tsx calls `schema.extend(dateRangeFieldSchema(input, language))` to
6
+ * register both date fields in a single call.
7
+ */
8
+ export declare const dateRangeFieldSchema: (field: DateRangeFieldClientConfig, language?: string) => {
9
+ [x: string]: z.ZodDate | z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"">, z.ZodDate]>>;
10
+ };
11
+ //# sourceMappingURL=dateRange.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dateRange.d.ts","sourceRoot":"","sources":["../../src/validators/dateRange.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AACxB,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAA;AAGzE;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAAI,OAAO,0BAA0B,EAAE,iBAAe;;CAStF,CAAA"}
@@ -0,0 +1,16 @@
1
+ import * as z from 'zod';
2
+ import getString from '../translations/index.js';
3
+ /**
4
+ * Returns a record of two Zod schemas keyed by startName and endName.
5
+ * Form.tsx calls `schema.extend(dateRangeFieldSchema(input, language))` to
6
+ * register both date fields in a single call.
7
+ */
8
+ export const dateRangeFieldSchema = (field, language = 'en') => {
9
+ const requiredMessage = getString('requiredField', language);
10
+ const base = z.date(requiredMessage);
11
+ const single = field.required ? base : z.union([z.literal(''), base], requiredMessage).optional();
12
+ return {
13
+ [field.startName]: single,
14
+ [field.endName]: single,
15
+ };
16
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nextjs-cms",
3
- "version": "0.9.28",
3
+ "version": "0.9.30",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "type": "module",
@@ -220,8 +220,8 @@
220
220
  "tsx": "^4.20.6",
221
221
  "typescript": "^5.9.2",
222
222
  "@lzcms/eslint-config": "0.3.0",
223
- "@lzcms/prettier-config": "0.1.0",
224
- "@lzcms/tsconfig": "0.1.0"
223
+ "@lzcms/tsconfig": "0.1.0",
224
+ "@lzcms/prettier-config": "0.1.0"
225
225
  },
226
226
  "license": "MIT",
227
227
  "keywords": [
@@ -1,30 +0,0 @@
1
- import type { QueryClientConfig } from '@tanstack/react-query';
2
- import type { TRPCLink } from '@trpc/client';
3
- import type { CreateTRPCReact } from '@trpc/react-query';
4
- import type { AnyRouter } from '@trpc/server';
5
- import * as React from 'react';
6
- import type { ReactNode } from 'react';
7
- import type { Session } from '../auth/index.js';
8
- import type { SessionProviderProps } from '../auth/react.js';
9
- type SessionOptions = Omit<SessionProviderProps, 'children' | 'session'>;
10
- export interface NextjsCmsProviderTRPCOptions<TRouter extends AnyRouter> {
11
- endpoint?: string;
12
- devtools?: boolean;
13
- queryClientOptions?: QueryClientConfig;
14
- links?: {
15
- beforeHttp?: TRPCLink<TRouter>[];
16
- };
17
- }
18
- export interface NextjsCmsProviderProps<TRouter extends AnyRouter> {
19
- children: ReactNode;
20
- session?: Session | null;
21
- sessionOptions?: SessionOptions;
22
- trpcOptions?: NextjsCmsProviderTRPCOptions<TRouter>;
23
- }
24
- export interface NextjsCmsClient<TRouter extends AnyRouter> {
25
- trpc: CreateTRPCReact<TRouter, unknown>;
26
- NextjsCmsProvider: (props: NextjsCmsProviderProps<TRouter>) => React.JSX.Element;
27
- }
28
- export declare function createNextjsCmsClient<TRouter extends AnyRouter>(): NextjsCmsClient<TRouter>;
29
- export {};
30
- //# sourceMappingURL=client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAG9D,OAAO,KAAK,EAAE,QAAQ,EAAwB,MAAM,cAAc,CAAA;AAElE,OAAO,KAAK,EAAE,eAAe,EAAuB,MAAM,mBAAmB,CAAA;AAC7E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAItC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAE/C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAG5D,KAAK,cAAc,GAAG,IAAI,CAAC,oBAAoB,EAAE,UAAU,GAAG,SAAS,CAAC,CAAA;AAExE,MAAM,WAAW,4BAA4B,CAAC,OAAO,SAAS,SAAS;IACnE,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,kBAAkB,CAAC,EAAE,iBAAiB,CAAA;IACtC,KAAK,CAAC,EAAE;QACJ,UAAU,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAA;KACnC,CAAA;CACJ;AAED,MAAM,WAAW,sBAAsB,CAAC,OAAO,SAAS,SAAS;IAC7D,QAAQ,EAAE,SAAS,CAAA;IACnB,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;IACxB,cAAc,CAAC,EAAE,cAAc,CAAA;IAC/B,WAAW,CAAC,EAAE,4BAA4B,CAAC,OAAO,CAAC,CAAA;CACtD;AAED,MAAM,WAAW,eAAe,CAAC,OAAO,SAAS,SAAS;IACtD,IAAI,EAAE,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IACvC,iBAAiB,EAAE,CAAC,KAAK,EAAE,sBAAsB,CAAC,OAAO,CAAC,KAAK,KAAK,CAAC,GAAG,CAAC,OAAO,CAAA;CACnF;AAyBD,wBAAgB,qBAAqB,CAAC,OAAO,SAAS,SAAS,KAAK,eAAe,CAAC,OAAO,CAAC,CA8D3F"}
@@ -1,82 +0,0 @@
1
- 'use client';
2
- import { defaultShouldDehydrateQuery, QueryClient, QueryClientProvider } from '@tanstack/react-query';
3
- import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
4
- import { httpBatchLink, loggerLink } from '@trpc/client';
5
- import { createTRPCReact } from '@trpc/react-query';
6
- import * as React from 'react';
7
- import { useState } from 'react';
8
- import SuperJSON from 'superjson';
9
- import { getCsrfToken, refreshTokenLink, SessionProvider } from '../auth/react.js';
10
- import { PluginTRPCProvider } from '../plugins/client.js';
11
- function mergeQueryClientOptions(options) {
12
- return {
13
- ...options,
14
- defaultOptions: {
15
- ...options?.defaultOptions,
16
- queries: {
17
- refetchOnWindowFocus: process.env.NODE_ENV === 'development',
18
- retry: 1,
19
- ...options?.defaultOptions?.queries,
20
- },
21
- dehydrate: {
22
- serializeData: SuperJSON.serialize,
23
- shouldDehydrateQuery: (query) => defaultShouldDehydrateQuery(query) || query.state.status === 'pending',
24
- ...options?.defaultOptions?.dehydrate,
25
- },
26
- hydrate: {
27
- deserializeData: SuperJSON.deserialize,
28
- ...options?.defaultOptions?.hydrate,
29
- },
30
- },
31
- };
32
- }
33
- export function createNextjsCmsClient() {
34
- const trpc = createTRPCReact();
35
- const trpcBase = trpc;
36
- let browserQueryClient;
37
- function createQueryClient(options) {
38
- return new QueryClient(mergeQueryClientOptions(options));
39
- }
40
- function getQueryClient(options) {
41
- if (typeof window === 'undefined') {
42
- return createQueryClient(options);
43
- }
44
- if (!browserQueryClient)
45
- browserQueryClient = createQueryClient(options);
46
- return browserQueryClient;
47
- }
48
- function NextjsCmsProvider({ children, session, sessionOptions, trpcOptions }) {
49
- const queryClient = getQueryClient(trpcOptions?.queryClientOptions);
50
- const endpoint = trpcOptions?.endpoint ?? '/api/trpc';
51
- const showDevtools = trpcOptions?.devtools ?? process.env.NODE_ENV === 'development';
52
- const [trpcClient] = useState(() => trpcBase.createClient({
53
- links: [
54
- refreshTokenLink(),
55
- loggerLink({
56
- enabled: (op) => process.env.NODE_ENV === 'development' ||
57
- (op.direction === 'down' && op.result instanceof Error),
58
- }),
59
- ...(trpcOptions?.links?.beforeHttp ?? []),
60
- httpBatchLink({
61
- transformer: SuperJSON,
62
- url: endpoint,
63
- async headers(op) {
64
- const headers = new Headers();
65
- if (op.opList.some((operation) => operation.type === 'mutation')) {
66
- const csrfToken = await getCsrfToken();
67
- headers.set('x-csrf-token', csrfToken);
68
- }
69
- headers.set('x-trpc-source', 'nextjs-react');
70
- return headers;
71
- },
72
- }),
73
- ],
74
- }));
75
- return (React.createElement(QueryClientProvider, { client: queryClient },
76
- React.createElement(trpcBase.Provider, { client: trpcClient, queryClient: queryClient },
77
- React.createElement(SessionProvider, { session: session, ...sessionOptions },
78
- React.createElement(PluginTRPCProvider, { trpc: trpc }, children)),
79
- showDevtools ? React.createElement(ReactQueryDevtools, { initialIsOpen: false }) : null)));
80
- }
81
- return { trpc, NextjsCmsProvider };
82
- }