@xleddyl/nuxt-cms 0.1.9 → 0.1.10

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 (38) hide show
  1. package/dist/module.json +1 -1
  2. package/dist/module.mjs +5 -1
  3. package/dist/runtime/app/components/cms/BlocksField.vue +59 -16
  4. package/dist/runtime/app/components/cms/ConfirmModal.d.vue.ts +20 -0
  5. package/dist/runtime/app/components/cms/ConfirmModal.vue +43 -0
  6. package/dist/runtime/app/components/cms/ConfirmModal.vue.d.ts +20 -0
  7. package/dist/runtime/app/components/cms/MediaGallery.vue +9 -2
  8. package/dist/runtime/app/components/cms/RelationField.vue +56 -10
  9. package/dist/runtime/app/components/cms/RichTextField.vue +63 -2
  10. package/dist/runtime/app/composables/cms-confirm.d.ts +4 -0
  11. package/dist/runtime/app/composables/cms-confirm.js +7 -0
  12. package/dist/runtime/app/i18n/en.json +32 -2
  13. package/dist/runtime/app/i18n/it.json +32 -2
  14. package/dist/runtime/app/pages/admin-collection.vue +89 -14
  15. package/dist/runtime/app/pages/admin-entry.vue +12 -5
  16. package/dist/runtime/server/api/collection.get.d.ts +1 -3
  17. package/dist/runtime/server/api/collection.get.js +34 -8
  18. package/dist/runtime/server/api/collection.post.js +11 -7
  19. package/dist/runtime/server/api/collection.put.js +11 -7
  20. package/dist/runtime/server/api/item.get.js +3 -2
  21. package/dist/runtime/server/api/item.put.js +12 -8
  22. package/dist/runtime/server/api/media-presign.post.js +2 -1
  23. package/dist/runtime/server/api/media.post.js +2 -1
  24. package/dist/runtime/server/plugins/migrate-postgres.js +9 -1
  25. package/dist/runtime/server/plugins/migrate-sqlite.js +9 -1
  26. package/dist/runtime/server/routes/auth/login.post.js +1 -1
  27. package/dist/runtime/server/utils/db-postgres.d.ts +4 -0
  28. package/dist/runtime/server/utils/db-postgres.js +3 -0
  29. package/dist/runtime/server/utils/db-sqlite.d.ts +2 -0
  30. package/dist/runtime/server/utils/db-sqlite.js +19 -0
  31. package/dist/runtime/server/utils/graphql.js +10 -4
  32. package/dist/runtime/server/utils/media.d.ts +1 -0
  33. package/dist/runtime/server/utils/media.js +27 -0
  34. package/dist/runtime/server/utils/relations.d.ts +3 -2
  35. package/dist/runtime/server/utils/relations.js +2 -4
  36. package/dist/runtime/server/utils/require-admin.js +15 -1
  37. package/dist/runtime/shared/index.d.ts +69 -1
  38. package/package.json +4 -1
@@ -1,6 +1,20 @@
1
- import { createError } from "h3";
1
+ import { createError, getRequestHeader, getRequestHost } from "h3";
2
2
  import { getUserSession, useRuntimeConfig } from "#imports";
3
+ function assertSameOrigin(event) {
4
+ const origin = getRequestHeader(event, "origin");
5
+ if (!origin) return;
6
+ let originHost;
7
+ try {
8
+ originHost = new URL(origin).host;
9
+ } catch {
10
+ originHost = void 0;
11
+ }
12
+ if (!originHost || originHost !== getRequestHost(event, { xForwardedHost: true })) {
13
+ throw createError({ statusCode: 403, statusMessage: "Cross-origin request rejected" });
14
+ }
15
+ }
3
16
  export async function requireAdmin(event) {
17
+ assertSameOrigin(event);
4
18
  const session = await getUserSession(event);
5
19
  const email = session.user?.email;
6
20
  if (!email) {
@@ -59,4 +59,72 @@ export interface CmsEntry {
59
59
  table?: CmsTable;
60
60
  }
61
61
  export type CmsConfig = Record<string, CmsEntry>;
62
- export declare function defineCmsConfig<T extends CmsConfig>(config: T): T;
62
+ interface FieldInputBase {
63
+ label: string;
64
+ required?: boolean;
65
+ }
66
+ export interface TextFieldInput extends FieldInputBase {
67
+ type: 'text';
68
+ textarea?: boolean;
69
+ translatable?: boolean;
70
+ }
71
+ export interface RichtextFieldInput extends FieldInputBase {
72
+ type: 'richtext';
73
+ translatable?: boolean;
74
+ }
75
+ export interface NumberFieldInput extends FieldInputBase {
76
+ type: 'number';
77
+ integer?: boolean;
78
+ }
79
+ export interface BooleanFieldInput extends FieldInputBase {
80
+ type: 'boolean';
81
+ }
82
+ export interface DateFieldInput extends FieldInputBase {
83
+ type: 'date';
84
+ }
85
+ export interface EmailFieldInput extends FieldInputBase {
86
+ type: 'email';
87
+ }
88
+ export interface SlugFieldInput extends FieldInputBase {
89
+ type: 'slug';
90
+ from: string;
91
+ }
92
+ export interface SelectFieldInput extends FieldInputBase {
93
+ type: 'select';
94
+ options: string[];
95
+ }
96
+ export interface JsonFieldInput extends FieldInputBase {
97
+ type: 'json';
98
+ }
99
+ export interface MediaFieldInput extends FieldInputBase {
100
+ type: 'media';
101
+ mediaType?: MediaType;
102
+ accept?: string[];
103
+ }
104
+ export interface RelationFieldInput extends FieldInputBase {
105
+ type: 'relation';
106
+ to: string;
107
+ cardinality?: 'many-to-one' | 'one-to-one' | 'many-to-many';
108
+ onDelete?: 'set null' | 'cascade' | 'restrict';
109
+ }
110
+ export type BlockFieldInput = Omit<TextFieldInput, 'translatable'> | Omit<RichtextFieldInput, 'translatable'> | NumberFieldInput | BooleanFieldInput | DateFieldInput | EmailFieldInput | SelectFieldInput | JsonFieldInput | MediaFieldInput;
111
+ export interface BlockInput {
112
+ label: string;
113
+ fields: Record<string, BlockFieldInput>;
114
+ }
115
+ export interface BlocksFieldInput extends FieldInputBase {
116
+ type: 'blocks';
117
+ blocks: Record<string, BlockInput>;
118
+ }
119
+ export type CmsFieldInput = TextFieldInput | RichtextFieldInput | NumberFieldInput | BooleanFieldInput | DateFieldInput | EmailFieldInput | SlugFieldInput | SelectFieldInput | JsonFieldInput | MediaFieldInput | RelationFieldInput | BlocksFieldInput;
120
+ export interface CmsEntryInput {
121
+ id: string;
122
+ label: string;
123
+ kind: 'collection' | 'single';
124
+ titleField?: string;
125
+ drafts?: boolean;
126
+ fields: Record<string, CmsFieldInput>;
127
+ }
128
+ export type CmsConfigInput = Record<string, CmsEntryInput>;
129
+ export declare function defineCmsConfig<T extends CmsConfigInput>(config: T): T;
130
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xleddyl/nuxt-cms",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "description": "Lightweight CMS that ships with your Nuxt app: runs on the Nitro server, content types defined in code, /cms admin panel, GraphQL API, SQLite or Postgres. No external CMS needed!",
5
5
  "license": "MIT",
6
6
  "author": "Edoardo Alberti (https://github.com/xleddyl)",
@@ -75,10 +75,12 @@
75
75
  "@types/node": "latest",
76
76
  "@types/pg": "^8.11.0",
77
77
  "changelogen": "^0.6.0",
78
+ "h3": "^1.15.11",
78
79
  "nuxt": "^4.4.8",
79
80
  "prettier": "3.1.1",
80
81
  "prettier-plugin-tailwindcss": "0.6.11",
81
82
  "typescript": "~6.0.3",
83
+ "vitest": "^4.1.9",
82
84
  "vue-tsc": "^3.3.3"
83
85
  },
84
86
  "scripts": {
@@ -86,6 +88,7 @@
86
88
  "dev:build": "nuxt build playground",
87
89
  "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt prepare playground",
88
90
  "db:studio": "drizzle-kit studio --config=playground/.nuxt/cms/drizzle.config.ts",
91
+ "test": "vitest run",
89
92
  "test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit",
90
93
  "format": "prettier --write \"**/*.{ts,tsx,js,jsx,md,html,json,sql,vue}\" --log-level error",
91
94
  "release": "changelogen --release --push"