includio-cms 0.20.0 → 0.22.0

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 (101) hide show
  1. package/API.md +22 -21
  2. package/CHANGELOG.md +147 -0
  3. package/DOCS.md +1 -1
  4. package/README.md +138 -32
  5. package/ROADMAP.md +11 -4
  6. package/dist/admin/api/rest/handler.d.ts +13 -1
  7. package/dist/admin/api/rest/handler.js +13 -1
  8. package/dist/admin/api/rest/middleware/apiKey.js +9 -1
  9. package/dist/admin/api/rest/middleware/generateApiKey.d.ts +16 -0
  10. package/dist/admin/api/rest/middleware/generateApiKey.js +19 -0
  11. package/dist/admin/client/collection/collection-entries.svelte +1 -1
  12. package/dist/admin/client/collection/empty-state.svelte +1 -1
  13. package/dist/admin/client/collection/row-actions.svelte +3 -3
  14. package/dist/admin/client/collection/table-toolbar.svelte +3 -1
  15. package/dist/admin/client/entry/entry-header.svelte +3 -1
  16. package/dist/admin/client/users/create-user-dialog.svelte +4 -4
  17. package/dist/admin/client/users/delete-user-dialog.svelte +4 -2
  18. package/dist/admin/client/users/lang.d.ts +10 -2
  19. package/dist/admin/client/users/lang.js +10 -4
  20. package/dist/admin/client/users/users-page.svelte +3 -2
  21. package/dist/admin/components/media/file-upload.svelte +2 -0
  22. package/dist/ai-claude/index.d.ts +9 -1
  23. package/dist/ai-claude/index.js +9 -1
  24. package/dist/ai-openai/index.d.ts +9 -1
  25. package/dist/ai-openai/index.js +9 -1
  26. package/dist/cli/index.js +115 -13
  27. package/dist/cms/runtime/schema.d.ts +2 -0
  28. package/dist/cms/runtime/schema.js +4 -0
  29. package/dist/cms/runtime/types.d.ts +1 -1
  30. package/dist/core/cms.d.ts +13 -1
  31. package/dist/core/cms.js +13 -1
  32. package/dist/core/errors.d.ts +71 -0
  33. package/dist/core/errors.js +179 -0
  34. package/dist/core/server/consentLogs/operations/create.d.ts +13 -1
  35. package/dist/core/server/consentLogs/operations/create.js +13 -1
  36. package/dist/core/server/entries/operations/create.js +6 -1
  37. package/dist/core/server/entries/operations/get.js +14 -3
  38. package/dist/core/server/entries/operations/resolveEntry.d.ts +32 -1
  39. package/dist/core/server/entries/operations/resolveEntry.js +36 -4
  40. package/dist/core/server/entries/operations/update.js +5 -1
  41. package/dist/core/server/fields/utils/resolveMedia.d.ts +18 -1
  42. package/dist/core/server/fields/utils/resolveMedia.js +13 -1
  43. package/dist/core/server/forms/submissions/operations/create.d.ts +21 -1
  44. package/dist/core/server/forms/submissions/operations/create.js +18 -2
  45. package/dist/core/server/forms/submissions/utils/parseMultipart.d.ts +15 -1
  46. package/dist/core/server/forms/submissions/utils/parseMultipart.js +15 -1
  47. package/dist/core/server/media/operations/uploadFile.js +4 -3
  48. package/dist/core/server/media/styles/sharp/generateImageStyle.js +3 -2
  49. package/dist/core/server/media/utils/generateAdminThumbnail.js +3 -2
  50. package/dist/core/server/media/utils/generateBlurDataUrl.js +2 -1
  51. package/dist/db-postgres/index.d.ts +10 -0
  52. package/dist/db-postgres/index.js +10 -0
  53. package/dist/email-nodemailer/index.d.ts +13 -1
  54. package/dist/email-nodemailer/index.js +13 -1
  55. package/dist/entity/index.d.ts +16 -1
  56. package/dist/entity/index.js +16 -1
  57. package/dist/files-local/index.d.ts +12 -1
  58. package/dist/files-local/index.js +12 -1
  59. package/dist/paraglide/messages/_index.d.ts +3 -36
  60. package/dist/paraglide/messages/_index.js +3 -71
  61. package/dist/paraglide/messages/hello_world.d.ts +5 -0
  62. package/dist/paraglide/messages/hello_world.js +33 -0
  63. package/dist/paraglide/messages/login_hello.d.ts +16 -0
  64. package/dist/paraglide/messages/login_hello.js +34 -0
  65. package/dist/paraglide/messages/login_please_login.d.ts +16 -0
  66. package/dist/paraglide/messages/login_please_login.js +34 -0
  67. package/dist/server/auth.d.ts +11 -0
  68. package/dist/server/auth.js +11 -0
  69. package/dist/server/security/csp.d.ts +16 -0
  70. package/dist/server/security/csp.js +33 -0
  71. package/dist/server/security/csrf.d.ts +13 -0
  72. package/dist/server/security/csrf.js +49 -0
  73. package/dist/server/security/index.d.ts +3 -0
  74. package/dist/server/security/index.js +3 -0
  75. package/dist/server/security/rate-limit.d.ts +44 -0
  76. package/dist/server/security/rate-limit.js +97 -0
  77. package/dist/server/utils/withTimeout.d.ts +21 -0
  78. package/dist/server/utils/withTimeout.js +37 -0
  79. package/dist/sveltekit/config.d.ts +67 -4
  80. package/dist/sveltekit/config.js +73 -4
  81. package/dist/sveltekit/server/handle.d.ts +15 -1
  82. package/dist/sveltekit/server/handle.js +22 -1
  83. package/dist/sveltekit/server/index.d.ts +1 -0
  84. package/dist/sveltekit/server/index.js +1 -0
  85. package/dist/sveltekit/server/layout.d.ts +12 -1
  86. package/dist/sveltekit/server/layout.js +12 -1
  87. package/dist/sveltekit/server/preview.d.ts +21 -1
  88. package/dist/sveltekit/server/preview.js +21 -1
  89. package/dist/types/cms.d.ts +4 -0
  90. package/dist/types/cms.schema.d.ts +452 -0
  91. package/dist/types/cms.schema.js +629 -0
  92. package/dist/updates/0.21.0/index.d.ts +2 -0
  93. package/dist/updates/0.21.0/index.js +55 -0
  94. package/dist/updates/0.22.0/index.d.ts +2 -0
  95. package/dist/updates/0.22.0/index.js +75 -0
  96. package/dist/updates/index.js +3 -1
  97. package/package.json +12 -2
  98. package/dist/paraglide/messages/en.d.ts +0 -5
  99. package/dist/paraglide/messages/en.js +0 -14
  100. package/dist/paraglide/messages/pl.d.ts +0 -5
  101. package/dist/paraglide/messages/pl.js +0 -14
@@ -1,6 +1,7 @@
1
1
  import { getCMS } from '../../../../cms.js';
2
2
  import sharp from 'sharp';
3
3
  import { calculateFocalCropRegion } from '../../utils/calculateFocalCropRegion.js';
4
+ import { withTimeout, sharpTimeoutMs } from '../../../../../server/utils/withTimeout.js';
4
5
  export async function generateImageStyle(mediaFileId, style) {
5
6
  const mediaFile = await getCMS().databaseAdapter.getMediaFile({
6
7
  data: {
@@ -19,7 +20,7 @@ export async function generateImageStyle(mediaFileId, style) {
19
20
  }
20
21
  export async function generateImageStyleFromBuffer(buf, mediaFile, style) {
21
22
  // Read EXIF orientation before processing
22
- const metadata = await sharp(buf).metadata();
23
+ const metadata = await withTimeout(sharp(buf).metadata(), sharpTimeoutMs(), 'sharp.metadata');
23
24
  // .rotate() applies EXIF orientation to pixels AND strips the tag from output.
24
25
  // Prevents double-rotation in WebP/JPEG where EXIF orientation tag may persist.
25
26
  let sharpInstance = sharp(buf).rotate();
@@ -79,7 +80,7 @@ export async function generateImageStyleFromBuffer(buf, mediaFile, style) {
79
80
  const originalExt = mediaFile.mimeType?.split('/').pop() ?? mediaFile.url.split('.').pop();
80
81
  const format = style.format ?? originalExt ?? 'jpeg';
81
82
  sharpInstance = sharpInstance.toFormat(format, style.quality != null ? { quality: Math.max(1, Math.min(100, style.quality)) } : undefined);
82
- const outputBuffer = await sharpInstance.toBuffer();
83
+ const outputBuffer = await withTimeout(sharpInstance.toBuffer(), sharpTimeoutMs(), 'sharp.toBuffer');
83
84
  return getCMS().filesAdapter.uploadFile(new File([new Uint8Array(outputBuffer)], `${mediaFile.id}_${style.name}_${Date.now().toString(36)}.${format}`, {
84
85
  type: `image/${format}`
85
86
  }));
@@ -1,14 +1,15 @@
1
1
  import { getCMS } from '../../../cms.js';
2
2
  import { isProcessableImage } from '../../fields/utils/imageStyles.js';
3
3
  import sharp from 'sharp';
4
+ import { withTimeout, sharpTimeoutMs } from '../../../../server/utils/withTimeout.js';
4
5
  const THUMB_WIDTH = 400;
5
6
  const THUMB_QUALITY = 70;
6
7
  export async function generateAdminThumbnail(buffer, mediaFile) {
7
- const output = await sharp(buffer)
8
+ const output = await withTimeout(sharp(buffer)
8
9
  .rotate()
9
10
  .resize(THUMB_WIDTH, undefined, { withoutEnlargement: true })
10
11
  .toFormat('webp', { quality: THUMB_QUALITY })
11
- .toBuffer();
12
+ .toBuffer(), sharpTimeoutMs(), 'sharp.adminThumbnail');
12
13
  const filename = `${mediaFile.id}_admin_thumb_${Date.now().toString(36)}.webp`;
13
14
  const uploaded = await getCMS().filesAdapter.uploadFile(new File([new Uint8Array(output)], filename, { type: 'image/webp' }));
14
15
  return uploaded.url;
@@ -1,5 +1,6 @@
1
1
  import sharp from 'sharp';
2
+ import { withTimeout, sharpTimeoutMs } from '../../../../server/utils/withTimeout.js';
2
3
  export async function generateBlurDataUrl(buffer) {
3
- const blurBuffer = await sharp(buffer).resize(20).blur(10).toFormat('webp').toBuffer();
4
+ const blurBuffer = await withTimeout(sharp(buffer).resize(20).blur(10).toFormat('webp').toBuffer(), sharpTimeoutMs(), 'sharp.blurDataUrl');
4
5
  return `data:image/webp;base64,${blurBuffer.toString('base64')}`;
5
6
  }
@@ -9,6 +9,16 @@ export type DatabaseAdapterWithDrizzle = DatabaseAdapter & {
9
9
  };
10
10
  /**
11
11
  * Postgres database adapter (drizzle + `postgres`).
12
+ *
13
+ * @param config - Connection options. `databaseUrl` is required.
14
+ * @returns A `DatabaseAdapter` wired to drizzle, plus `_drizzle` for advanced
15
+ * queries from project code.
12
16
  * @public
17
+ * @example
18
+ * ```ts
19
+ * import { pg } from 'includio-cms/db-postgres';
20
+ *
21
+ * const db = pg({ databaseUrl: process.env.DATABASE_URL! });
22
+ * ```
13
23
  */
14
24
  export declare function pg(config: Config): DatabaseAdapterWithDrizzle;
@@ -267,7 +267,17 @@ export * from './schema/index.js';
267
267
  export * from '../server/db/schema/auth-schema.js';
268
268
  /**
269
269
  * Postgres database adapter (drizzle + `postgres`).
270
+ *
271
+ * @param config - Connection options. `databaseUrl` is required.
272
+ * @returns A `DatabaseAdapter` wired to drizzle, plus `_drizzle` for advanced
273
+ * queries from project code.
270
274
  * @public
275
+ * @example
276
+ * ```ts
277
+ * import { pg } from 'includio-cms/db-postgres';
278
+ *
279
+ * const db = pg({ databaseUrl: process.env.DATABASE_URL! });
280
+ * ```
271
281
  */
272
282
  export function pg(config) {
273
283
  const client = postgres(config.databaseUrl);
@@ -10,9 +10,21 @@ interface Options {
10
10
  *
11
11
  * `nodemailer` is an **optional peer dependency** — install it in your project
12
12
  * (`pnpm add nodemailer`) when using this adapter. The SDK loads lazily on first
13
- * `sendMail()`; missing peer throws a clear error.
13
+ * `sendMail()`; a missing peer throws a clear error.
14
14
  *
15
+ * @param options - SMTP transport options + default From address/name.
16
+ * @returns An `EmailAdapter` ready to use in `defineConfig({ email })`.
15
17
  * @public
18
+ * @example
19
+ * ```ts
20
+ * import { nodemailerAdapter } from 'includio-cms/email-nodemailer';
21
+ *
22
+ * const email = nodemailerAdapter({
23
+ * defaultFromAddress: 'no-reply@example.com',
24
+ * defaultFromName: 'Example',
25
+ * transportOptions: { host: 'smtp.example.com', port: 587 }
26
+ * });
27
+ * ```
16
28
  */
17
29
  export declare function nodemailerAdapter(options: Options): EmailAdapter;
18
30
  export {};
@@ -3,9 +3,21 @@
3
3
  *
4
4
  * `nodemailer` is an **optional peer dependency** — install it in your project
5
5
  * (`pnpm add nodemailer`) when using this adapter. The SDK loads lazily on first
6
- * `sendMail()`; missing peer throws a clear error.
6
+ * `sendMail()`; a missing peer throws a clear error.
7
7
  *
8
+ * @param options - SMTP transport options + default From address/name.
9
+ * @returns An `EmailAdapter` ready to use in `defineConfig({ email })`.
8
10
  * @public
11
+ * @example
12
+ * ```ts
13
+ * import { nodemailerAdapter } from 'includio-cms/email-nodemailer';
14
+ *
15
+ * const email = nodemailerAdapter({
16
+ * defaultFromAddress: 'no-reply@example.com',
17
+ * defaultFromName: 'Example',
18
+ * transportOptions: { host: 'smtp.example.com', port: 587 }
19
+ * });
20
+ * ```
9
21
  */
10
22
  export function nodemailerAdapter(options) {
11
23
  let transporter = null;
@@ -8,8 +8,23 @@ interface CreateOptions {
8
8
  sortOrder?: number;
9
9
  }
10
10
  /**
11
- * Creates a high-level Entity API (CRUD + publish/archive) bound to a CMS instance and a user.
11
+ * Creates a high-level Entity API (CRUD + publish/archive) bound to a CMS
12
+ * instance and a user. Use it from scripts, migrations, webhooks, or anywhere
13
+ * server-side that needs programmatic content access.
14
+ *
15
+ * @param cms - The CMS instance (typically from `getCMS()`).
16
+ * @param opts - Optional. `userId` is recorded as the `createdBy` for every
17
+ * write (default: `'system'`).
18
+ * @returns An object with `create`, `update`, `publish`, `unpublish`,
19
+ * `archive`, `unarchive`, `delete`, `list`, and `createAndPublish` methods.
12
20
  * @public
21
+ * @example
22
+ * ```ts
23
+ * import { getCMS, createEntityAPI } from 'includio-cms';
24
+ *
25
+ * const api = createEntityAPI(getCMS(), { userId: 'migration-script' });
26
+ * await api.createAndPublish('posts', { title: { en: 'Hello' } });
27
+ * ```
13
28
  */
14
29
  export declare function createEntityAPI(cms: CMS, opts?: EntityAPIOptions): {
15
30
  create(slug: string, data?: EntryData, options?: CreateOptions & {
@@ -2,8 +2,23 @@ import { generateZodSchemaFromFields } from '../core/fields/fieldSchemaToTs.js';
2
2
  import { getFieldsFromConfig } from '../core/fields/layoutUtils.js';
3
3
  import { _getRawEntries as getRawEntries } from '../core/server/entries/operations/get.js';
4
4
  /**
5
- * Creates a high-level Entity API (CRUD + publish/archive) bound to a CMS instance and a user.
5
+ * Creates a high-level Entity API (CRUD + publish/archive) bound to a CMS
6
+ * instance and a user. Use it from scripts, migrations, webhooks, or anywhere
7
+ * server-side that needs programmatic content access.
8
+ *
9
+ * @param cms - The CMS instance (typically from `getCMS()`).
10
+ * @param opts - Optional. `userId` is recorded as the `createdBy` for every
11
+ * write (default: `'system'`).
12
+ * @returns An object with `create`, `update`, `publish`, `unpublish`,
13
+ * `archive`, `unarchive`, `delete`, `list`, and `createAndPublish` methods.
6
14
  * @public
15
+ * @example
16
+ * ```ts
17
+ * import { getCMS, createEntityAPI } from 'includio-cms';
18
+ *
19
+ * const api = createEntityAPI(getCMS(), { userId: 'migration-script' });
20
+ * await api.createAndPublish('posts', { title: { en: 'Hello' } });
21
+ * ```
7
22
  */
8
23
  export function createEntityAPI(cms, opts) {
9
24
  const db = cms.databaseAdapter;
@@ -6,7 +6,18 @@ export interface LocalFilesConfig {
6
6
  ffprobePath?: string;
7
7
  }
8
8
  /**
9
- * Local-disk files adapter. Stores uploads under `./static/uploads` (dev) or `/data/uploads` (prod).
9
+ * Local-disk files adapter. Stores uploads under `./static/uploads` (dev) or
10
+ * `/data/uploads` (prod, switched on `NODE_ENV`).
11
+ *
12
+ * @param config - Optional. Override `ffmpegPath` / `ffprobePath` if the
13
+ * binaries are not on `PATH`.
14
+ * @returns A `FilesAdapter` for local filesystem uploads.
10
15
  * @public
16
+ * @example
17
+ * ```ts
18
+ * import { local } from 'includio-cms/files-local';
19
+ *
20
+ * const files = local();
21
+ * ```
11
22
  */
12
23
  export declare function local(config?: LocalFilesConfig): FilesAdapter;
@@ -21,8 +21,19 @@ async function ensureDir(dir) {
21
21
  }
22
22
  }
23
23
  /**
24
- * Local-disk files adapter. Stores uploads under `./static/uploads` (dev) or `/data/uploads` (prod).
24
+ * Local-disk files adapter. Stores uploads under `./static/uploads` (dev) or
25
+ * `/data/uploads` (prod, switched on `NODE_ENV`).
26
+ *
27
+ * @param config - Optional. Override `ffmpegPath` / `ffprobePath` if the
28
+ * binaries are not on `PATH`.
29
+ * @returns A `FilesAdapter` for local filesystem uploads.
25
30
  * @public
31
+ * @example
32
+ * ```ts
33
+ * import { local } from 'includio-cms/files-local';
34
+ *
35
+ * const files = local();
36
+ * ```
26
37
  */
27
38
  export function local(config) {
28
39
  if (config?.ffmpegPath || config?.ffprobePath) {
@@ -1,36 +1,3 @@
1
- export function hello_world(inputs: {
2
- name: NonNullable<unknown>;
3
- }, options?: {
4
- locale?: "en" | "pl";
5
- }): string;
6
- /**
7
- * This function has been compiled by [Paraglide JS](https://inlang.com/m/gerre34r).
8
- *
9
- * - Changing this function will be over-written by the next build.
10
- *
11
- * - If you want to change the translations, you can either edit the source files e.g. `en.json`, or
12
- * use another inlang app like [Fink](https://inlang.com/m/tdozzpar) or the [VSCode extension Sherlock](https://inlang.com/m/r7kp499g).
13
- *
14
- * @param {{}} inputs
15
- * @param {{ locale?: "en" | "pl" }} options
16
- * @returns {string}
17
- */
18
- declare function login_hello(inputs?: {}, options?: {
19
- locale?: "en" | "pl";
20
- }): string;
21
- /**
22
- * This function has been compiled by [Paraglide JS](https://inlang.com/m/gerre34r).
23
- *
24
- * - Changing this function will be over-written by the next build.
25
- *
26
- * - If you want to change the translations, you can either edit the source files e.g. `en.json`, or
27
- * use another inlang app like [Fink](https://inlang.com/m/tdozzpar) or the [VSCode extension Sherlock](https://inlang.com/m/r7kp499g).
28
- *
29
- * @param {{}} inputs
30
- * @param {{ locale?: "en" | "pl" }} options
31
- * @returns {string}
32
- */
33
- declare function login_please_login(inputs?: {}, options?: {
34
- locale?: "en" | "pl";
35
- }): string;
36
- export { login_hello as login.hello, login_please_login as login.please_login };
1
+ export * from "./hello_world.js";
2
+ export * from "./login_hello.js";
3
+ export * from "./login_please_login.js";
@@ -1,72 +1,4 @@
1
1
  /* eslint-disable */
2
- import { getLocale, trackMessageCall, experimentalMiddlewareLocaleSplitting, isServer } from "../runtime.js"
3
- import * as en from "./en.js"
4
- import * as pl from "./pl.js"
5
- /**
6
- * This function has been compiled by [Paraglide JS](https://inlang.com/m/gerre34r).
7
- *
8
- * - Changing this function will be over-written by the next build.
9
- *
10
- * - If you want to change the translations, you can either edit the source files e.g. `en.json`, or
11
- * use another inlang app like [Fink](https://inlang.com/m/tdozzpar) or the [VSCode extension Sherlock](https://inlang.com/m/r7kp499g).
12
- *
13
- * @param {{ name: NonNullable<unknown> }} inputs
14
- * @param {{ locale?: "en" | "pl" }} options
15
- * @returns {string}
16
- */
17
- /* @__NO_SIDE_EFFECTS__ */
18
- export const hello_world = (inputs, options = {}) => {
19
- if (experimentalMiddlewareLocaleSplitting && isServer === false) {
20
- return /** @type {any} */ (globalThis).__paraglide_ssr.hello_world(inputs)
21
- }
22
- const locale = options.locale ?? getLocale()
23
- trackMessageCall("hello_world", locale)
24
- if (locale === "en") return en.hello_world(inputs)
25
- return pl.hello_world(inputs)
26
- };
27
- /**
28
- * This function has been compiled by [Paraglide JS](https://inlang.com/m/gerre34r).
29
- *
30
- * - Changing this function will be over-written by the next build.
31
- *
32
- * - If you want to change the translations, you can either edit the source files e.g. `en.json`, or
33
- * use another inlang app like [Fink](https://inlang.com/m/tdozzpar) or the [VSCode extension Sherlock](https://inlang.com/m/r7kp499g).
34
- *
35
- * @param {{}} inputs
36
- * @param {{ locale?: "en" | "pl" }} options
37
- * @returns {string}
38
- */
39
- /* @__NO_SIDE_EFFECTS__ */
40
- const login_hello = (inputs = {}, options = {}) => {
41
- if (experimentalMiddlewareLocaleSplitting && isServer === false) {
42
- return /** @type {any} */ (globalThis).__paraglide_ssr.login_hello(inputs)
43
- }
44
- const locale = options.locale ?? getLocale()
45
- trackMessageCall("login_hello", locale)
46
- if (locale === "en") return en.login_hello(inputs)
47
- return pl.login_hello(inputs)
48
- };
49
- export { login_hello as "login.hello" }
50
- /**
51
- * This function has been compiled by [Paraglide JS](https://inlang.com/m/gerre34r).
52
- *
53
- * - Changing this function will be over-written by the next build.
54
- *
55
- * - If you want to change the translations, you can either edit the source files e.g. `en.json`, or
56
- * use another inlang app like [Fink](https://inlang.com/m/tdozzpar) or the [VSCode extension Sherlock](https://inlang.com/m/r7kp499g).
57
- *
58
- * @param {{}} inputs
59
- * @param {{ locale?: "en" | "pl" }} options
60
- * @returns {string}
61
- */
62
- /* @__NO_SIDE_EFFECTS__ */
63
- const login_please_login = (inputs = {}, options = {}) => {
64
- if (experimentalMiddlewareLocaleSplitting && isServer === false) {
65
- return /** @type {any} */ (globalThis).__paraglide_ssr.login_please_login(inputs)
66
- }
67
- const locale = options.locale ?? getLocale()
68
- trackMessageCall("login_please_login", locale)
69
- if (locale === "en") return en.login_please_login(inputs)
70
- return pl.login_please_login(inputs)
71
- };
72
- export { login_please_login as "login.please_login" }
2
+ export * from './hello_world.js'
3
+ export * from './login_hello.js'
4
+ export * from './login_please_login.js'
@@ -0,0 +1,5 @@
1
+ export function hello_world(inputs: {
2
+ name: NonNullable<unknown>;
3
+ }, options?: {
4
+ locale?: "en" | "pl";
5
+ }): string;
@@ -0,0 +1,33 @@
1
+ /* eslint-disable */
2
+ import { getLocale, trackMessageCall, experimentalMiddlewareLocaleSplitting, isServer } from '../runtime.js';
3
+
4
+ const en_hello_world = /** @type {(inputs: { name: NonNullable<unknown> }) => string} */ (i) => {
5
+ return `Hello, ${i.name} from en!`
6
+ };
7
+
8
+ const pl_hello_world = /** @type {(inputs: { name: NonNullable<unknown> }) => string} */ (i) => {
9
+ return `Hello, ${i.name} from pl!`
10
+ };
11
+
12
+ /**
13
+ * This function has been compiled by [Paraglide JS](https://inlang.com/m/gerre34r).
14
+ *
15
+ * - Changing this function will be over-written by the next build.
16
+ *
17
+ * - If you want to change the translations, you can either edit the source files e.g. `en.json`, or
18
+ * use another inlang app like [Fink](https://inlang.com/m/tdozzpar) or the [VSCode extension Sherlock](https://inlang.com/m/r7kp499g).
19
+ *
20
+ * @param {{ name: NonNullable<unknown> }} inputs
21
+ * @param {{ locale?: "en" | "pl" }} options
22
+ * @returns {string}
23
+ */
24
+ /* @__NO_SIDE_EFFECTS__ */
25
+ export const hello_world = (inputs, options = {}) => {
26
+ if (experimentalMiddlewareLocaleSplitting && isServer === false) {
27
+ return /** @type {any} */ (globalThis).__paraglide_ssr.hello_world(inputs)
28
+ }
29
+ const locale = options.locale ?? getLocale()
30
+ trackMessageCall("hello_world", locale)
31
+ if (locale === "en") return en_hello_world(inputs)
32
+ return pl_hello_world(inputs)
33
+ };
@@ -0,0 +1,16 @@
1
+ export { login_hello as login.hello };
2
+ /**
3
+ * This function has been compiled by [Paraglide JS](https://inlang.com/m/gerre34r).
4
+ *
5
+ * - Changing this function will be over-written by the next build.
6
+ *
7
+ * - If you want to change the translations, you can either edit the source files e.g. `en.json`, or
8
+ * use another inlang app like [Fink](https://inlang.com/m/tdozzpar) or the [VSCode extension Sherlock](https://inlang.com/m/r7kp499g).
9
+ *
10
+ * @param {{}} inputs
11
+ * @param {{ locale?: "en" | "pl" }} options
12
+ * @returns {string}
13
+ */
14
+ declare function login_hello(inputs?: {}, options?: {
15
+ locale?: "en" | "pl";
16
+ }): string;
@@ -0,0 +1,34 @@
1
+ /* eslint-disable */
2
+ import { getLocale, trackMessageCall, experimentalMiddlewareLocaleSplitting, isServer } from '../runtime.js';
3
+
4
+ const en_login_hello = /** @type {(inputs: {}) => string} */ () => {
5
+ return `Welcome back`
6
+ };
7
+
8
+ const pl_login_hello = /** @type {(inputs: {}) => string} */ () => {
9
+ return `Witaj ponownie`
10
+ };
11
+
12
+ /**
13
+ * This function has been compiled by [Paraglide JS](https://inlang.com/m/gerre34r).
14
+ *
15
+ * - Changing this function will be over-written by the next build.
16
+ *
17
+ * - If you want to change the translations, you can either edit the source files e.g. `en.json`, or
18
+ * use another inlang app like [Fink](https://inlang.com/m/tdozzpar) or the [VSCode extension Sherlock](https://inlang.com/m/r7kp499g).
19
+ *
20
+ * @param {{}} inputs
21
+ * @param {{ locale?: "en" | "pl" }} options
22
+ * @returns {string}
23
+ */
24
+ /* @__NO_SIDE_EFFECTS__ */
25
+ const login_hello = (inputs = {}, options = {}) => {
26
+ if (experimentalMiddlewareLocaleSplitting && isServer === false) {
27
+ return /** @type {any} */ (globalThis).__paraglide_ssr.login_hello(inputs)
28
+ }
29
+ const locale = options.locale ?? getLocale()
30
+ trackMessageCall("login_hello", locale)
31
+ if (locale === "en") return en_login_hello(inputs)
32
+ return pl_login_hello(inputs)
33
+ };
34
+ export { login_hello as "login.hello" }
@@ -0,0 +1,16 @@
1
+ export { login_please_login as login.please_login };
2
+ /**
3
+ * This function has been compiled by [Paraglide JS](https://inlang.com/m/gerre34r).
4
+ *
5
+ * - Changing this function will be over-written by the next build.
6
+ *
7
+ * - If you want to change the translations, you can either edit the source files e.g. `en.json`, or
8
+ * use another inlang app like [Fink](https://inlang.com/m/tdozzpar) or the [VSCode extension Sherlock](https://inlang.com/m/r7kp499g).
9
+ *
10
+ * @param {{}} inputs
11
+ * @param {{ locale?: "en" | "pl" }} options
12
+ * @returns {string}
13
+ */
14
+ declare function login_please_login(inputs?: {}, options?: {
15
+ locale?: "en" | "pl";
16
+ }): string;
@@ -0,0 +1,34 @@
1
+ /* eslint-disable */
2
+ import { getLocale, trackMessageCall, experimentalMiddlewareLocaleSplitting, isServer } from '../runtime.js';
3
+
4
+ const en_login_please_login = /** @type {(inputs: {}) => string} */ () => {
5
+ return `Login to your account`
6
+ };
7
+
8
+ const pl_login_please_login = /** @type {(inputs: {}) => string} */ () => {
9
+ return `Zaloguj się na swoje konto`
10
+ };
11
+
12
+ /**
13
+ * This function has been compiled by [Paraglide JS](https://inlang.com/m/gerre34r).
14
+ *
15
+ * - Changing this function will be over-written by the next build.
16
+ *
17
+ * - If you want to change the translations, you can either edit the source files e.g. `en.json`, or
18
+ * use another inlang app like [Fink](https://inlang.com/m/tdozzpar) or the [VSCode extension Sherlock](https://inlang.com/m/r7kp499g).
19
+ *
20
+ * @param {{}} inputs
21
+ * @param {{ locale?: "en" | "pl" }} options
22
+ * @returns {string}
23
+ */
24
+ /* @__NO_SIDE_EFFECTS__ */
25
+ const login_please_login = (inputs = {}, options = {}) => {
26
+ if (experimentalMiddlewareLocaleSplitting && isServer === false) {
27
+ return /** @type {any} */ (globalThis).__paraglide_ssr.login_please_login(inputs)
28
+ }
29
+ const locale = options.locale ?? getLocale()
30
+ trackMessageCall("login_please_login", locale)
31
+ if (locale === "en") return en_login_please_login(inputs)
32
+ return pl_login_please_login(inputs)
33
+ };
34
+ export { login_please_login as "login.please_login" }
@@ -1,5 +1,16 @@
1
1
  /**
2
2
  * Returns the underlying `better-auth` instance from the initialized CMS.
3
+ * Use it to integrate with custom auth flows or read session data.
4
+ *
5
+ * @returns The `better-auth` instance configured by the CMS.
6
+ * @throws {Error} when the CMS was started without `auth` config.
3
7
  * @public
8
+ * @example
9
+ * ```ts
10
+ * import { getAuth } from 'includio-cms/sveltekit/server';
11
+ *
12
+ * const auth = getAuth();
13
+ * const session = await auth.api.getSession({ headers: request.headers });
14
+ * ```
4
15
  */
5
16
  export declare function getAuth(): import("better-auth", { with: { "resolution-mode": "require" } }).Auth<import("better-auth", { with: { "resolution-mode": "require" } }).BetterAuthOptions>;
@@ -1,7 +1,18 @@
1
1
  import { getCMS } from '../core/cms.js';
2
2
  /**
3
3
  * Returns the underlying `better-auth` instance from the initialized CMS.
4
+ * Use it to integrate with custom auth flows or read session data.
5
+ *
6
+ * @returns The `better-auth` instance configured by the CMS.
7
+ * @throws {Error} when the CMS was started without `auth` config.
4
8
  * @public
9
+ * @example
10
+ * ```ts
11
+ * import { getAuth } from 'includio-cms/sveltekit/server';
12
+ *
13
+ * const auth = getAuth();
14
+ * const session = await auth.api.getSession({ headers: request.headers });
15
+ * ```
5
16
  */
6
17
  export function getAuth() {
7
18
  return getCMS().auth;
@@ -0,0 +1,16 @@
1
+ export interface CspOptions {
2
+ scriptSrc?: string[];
3
+ styleSrc?: string[];
4
+ imgSrc?: string[];
5
+ mediaSrc?: string[];
6
+ fontSrc?: string[];
7
+ connectSrc?: string[];
8
+ frameAncestors?: string[];
9
+ }
10
+ /**
11
+ * Build a Content-Security-Policy header value with v1.0 defaults.
12
+ * `'unsafe-inline'` is allowed on `script-src`/`style-src` because TipTap and
13
+ * paraglide emit inline code; documented in `KNOWN-RISKS.md`.
14
+ * @internal
15
+ */
16
+ export declare function buildCspHeader(opts?: CspOptions): string;
@@ -0,0 +1,33 @@
1
+ const DEFAULTS = {
2
+ scriptSrc: ["'self'", "'unsafe-inline'"],
3
+ styleSrc: ["'self'", "'unsafe-inline'"],
4
+ imgSrc: ["'self'", 'data:', 'blob:'],
5
+ mediaSrc: ["'self'", 'blob:'],
6
+ fontSrc: ["'self'", 'data:'],
7
+ connectSrc: ["'self'"],
8
+ frameAncestors: ["'self'"]
9
+ };
10
+ /**
11
+ * Build a Content-Security-Policy header value with v1.0 defaults.
12
+ * `'unsafe-inline'` is allowed on `script-src`/`style-src` because TipTap and
13
+ * paraglide emit inline code; documented in `KNOWN-RISKS.md`.
14
+ * @internal
15
+ */
16
+ export function buildCspHeader(opts = {}) {
17
+ const merge = (key, extra) => {
18
+ const base = DEFAULTS[key];
19
+ return extra && extra.length ? Array.from(new Set([...base, ...extra])) : [...base];
20
+ };
21
+ return [
22
+ `default-src 'self'`,
23
+ `script-src ${merge('scriptSrc', opts.scriptSrc).join(' ')}`,
24
+ `style-src ${merge('styleSrc', opts.styleSrc).join(' ')}`,
25
+ `img-src ${merge('imgSrc', opts.imgSrc).join(' ')}`,
26
+ `media-src ${merge('mediaSrc', opts.mediaSrc).join(' ')}`,
27
+ `font-src ${merge('fontSrc', opts.fontSrc).join(' ')}`,
28
+ `connect-src ${merge('connectSrc', opts.connectSrc).join(' ')}`,
29
+ `object-src 'none'`,
30
+ `base-uri 'self'`,
31
+ `frame-ancestors ${merge('frameAncestors', opts.frameAncestors).join(' ')}`
32
+ ].join('; ');
33
+ }
@@ -0,0 +1,13 @@
1
+ import type { Handle, RequestEvent } from '@sveltejs/kit';
2
+ /**
3
+ * Returns true when a request is CSRF-safe: a non-mutating method, or a mutating
4
+ * method whose Origin/Referer matches the request URL origin (or the env allowlist).
5
+ * @internal
6
+ */
7
+ export declare function isCsrfSafe(event: RequestEvent): boolean;
8
+ /**
9
+ * SvelteKit handle that rejects mutating requests under `/admin/api/*` lacking a
10
+ * matching Origin/Referer header. Other paths and safe methods pass through.
11
+ * @internal
12
+ */
13
+ export declare const csrfGuard: Handle;
@@ -0,0 +1,49 @@
1
+ const MUTATING_METHODS = new Set(['POST', 'PUT', 'PATCH', 'DELETE']);
2
+ function getAllowedOrigins() {
3
+ const env = process.env.INCLUDIO_CSRF_ALLOWED_ORIGINS ?? '';
4
+ return new Set(env
5
+ .split(',')
6
+ .map((s) => s.trim())
7
+ .filter(Boolean));
8
+ }
9
+ /**
10
+ * Returns true when a request is CSRF-safe: a non-mutating method, or a mutating
11
+ * method whose Origin/Referer matches the request URL origin (or the env allowlist).
12
+ * @internal
13
+ */
14
+ export function isCsrfSafe(event) {
15
+ const method = event.request.method.toUpperCase();
16
+ if (!MUTATING_METHODS.has(method))
17
+ return true;
18
+ const expected = event.url.origin;
19
+ const allowed = getAllowedOrigins();
20
+ const origin = event.request.headers.get('origin');
21
+ if (origin)
22
+ return origin === expected || allowed.has(origin);
23
+ const referer = event.request.headers.get('referer');
24
+ if (referer) {
25
+ try {
26
+ const refOrigin = new URL(referer).origin;
27
+ return refOrigin === expected || allowed.has(refOrigin);
28
+ }
29
+ catch {
30
+ return false;
31
+ }
32
+ }
33
+ return false;
34
+ }
35
+ /**
36
+ * SvelteKit handle that rejects mutating requests under `/admin/api/*` lacking a
37
+ * matching Origin/Referer header. Other paths and safe methods pass through.
38
+ * @internal
39
+ */
40
+ export const csrfGuard = async ({ event, resolve }) => {
41
+ if (!event.url.pathname.startsWith('/admin/api/'))
42
+ return resolve(event);
43
+ if (isCsrfSafe(event))
44
+ return resolve(event);
45
+ return new Response(JSON.stringify({ error: 'csrf_rejected' }), {
46
+ status: 403,
47
+ headers: { 'content-type': 'application/json' }
48
+ });
49
+ };
@@ -0,0 +1,3 @@
1
+ export { csrfGuard, isCsrfSafe } from './csrf.js';
2
+ export { rateLimitGuard, MemoryRateLimitStore, type RateLimitStore, type RateLimitResult, type RateLimitGuardOptions } from './rate-limit.js';
3
+ export { buildCspHeader, type CspOptions } from './csp.js';