@latte-macchiat-io/latte-payload 1.0.1
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.
- package/.claude/settings.local.json +9 -0
- package/.env.example +29 -0
- package/.github/workflows/ci.yml +160 -0
- package/.github/workflows/publish.yml +126 -0
- package/.nvmrc +1 -0
- package/.prettierignore +2 -0
- package/.prettierrc +11 -0
- package/CHANGELOG.md +87 -0
- package/README.md +364 -0
- package/TESTING_AND_DOCUMENTATION_SETUP.md +348 -0
- package/dist/access/adminAccessOnly.d.ts +25 -0
- package/dist/access/adminAccessOnly.d.ts.map +1 -0
- package/dist/access/adminAccessOnly.js +11 -0
- package/dist/access/adminAccessOnly.js.map +1 -0
- package/dist/access/admins.d.ts +72 -0
- package/dist/access/admins.d.ts.map +1 -0
- package/dist/access/admins.js +76 -0
- package/dist/access/admins.js.map +1 -0
- package/dist/access/anyone.d.ts +35 -0
- package/dist/access/anyone.d.ts.map +1 -0
- package/dist/access/anyone.js +34 -0
- package/dist/access/anyone.js.map +1 -0
- package/dist/access/authenticated.d.ts +63 -0
- package/dist/access/authenticated.d.ts.map +1 -0
- package/dist/access/authenticated.js +68 -0
- package/dist/access/authenticated.js.map +1 -0
- package/dist/access/authenticatedAccessOnly.d.ts +13 -0
- package/dist/access/authenticatedAccessOnly.d.ts.map +1 -0
- package/dist/access/authenticatedAccessOnly.js +11 -0
- package/dist/access/authenticatedAccessOnly.js.map +1 -0
- package/dist/access/index.d.ts +7 -0
- package/dist/access/index.d.ts.map +1 -0
- package/dist/access/index.js +7 -0
- package/dist/access/index.js.map +1 -0
- package/dist/access/publicReadAuthenticatedAccess.d.ts +13 -0
- package/dist/access/publicReadAuthenticatedAccess.d.ts.map +1 -0
- package/dist/access/publicReadAuthenticatedAccess.js +12 -0
- package/dist/access/publicReadAuthenticatedAccess.js.map +1 -0
- package/dist/collections/ContactMessages/hooks/sendEmailNotification.d.ts +31 -0
- package/dist/collections/ContactMessages/hooks/sendEmailNotification.d.ts.map +1 -0
- package/dist/collections/ContactMessages/hooks/sendEmailNotification.js +29 -0
- package/dist/collections/ContactMessages/hooks/sendEmailNotification.js.map +1 -0
- package/dist/collections/ContactMessages/index.d.ts +27 -0
- package/dist/collections/ContactMessages/index.d.ts.map +1 -0
- package/dist/collections/ContactMessages/index.js +81 -0
- package/dist/collections/ContactMessages/index.js.map +1 -0
- package/dist/collections/EmailTemplates/index.d.ts +26 -0
- package/dist/collections/EmailTemplates/index.d.ts.map +1 -0
- package/dist/collections/EmailTemplates/index.js +74 -0
- package/dist/collections/EmailTemplates/index.js.map +1 -0
- package/dist/collections/Media/index.d.ts +3 -0
- package/dist/collections/Media/index.d.ts.map +1 -0
- package/dist/collections/Media/index.js +22 -0
- package/dist/collections/Media/index.js.map +1 -0
- package/dist/collections/QueuedEmails/components/HtmlViewer.d.ts +3 -0
- package/dist/collections/QueuedEmails/components/HtmlViewer.d.ts.map +1 -0
- package/dist/collections/QueuedEmails/components/HtmlViewer.js +11 -0
- package/dist/collections/QueuedEmails/components/HtmlViewer.js.map +1 -0
- package/dist/collections/QueuedEmails/components/RetryEmailButtons.d.ts +2 -0
- package/dist/collections/QueuedEmails/components/RetryEmailButtons.d.ts.map +1 -0
- package/dist/collections/QueuedEmails/components/RetryEmailButtons.js +79 -0
- package/dist/collections/QueuedEmails/components/RetryEmailButtons.js.map +1 -0
- package/dist/collections/QueuedEmails/index.d.ts +3 -0
- package/dist/collections/QueuedEmails/index.d.ts.map +1 -0
- package/dist/collections/QueuedEmails/index.js +245 -0
- package/dist/collections/QueuedEmails/index.js.map +1 -0
- package/dist/collections/Users/auth-emails/forgot-password-email.d.ts +51 -0
- package/dist/collections/Users/auth-emails/forgot-password-email.d.ts.map +1 -0
- package/dist/collections/Users/auth-emails/forgot-password-email.js +90 -0
- package/dist/collections/Users/auth-emails/forgot-password-email.js.map +1 -0
- package/dist/collections/Users/auth-emails/verify-email.d.ts +51 -0
- package/dist/collections/Users/auth-emails/verify-email.d.ts.map +1 -0
- package/dist/collections/Users/auth-emails/verify-email.js +80 -0
- package/dist/collections/Users/auth-emails/verify-email.js.map +1 -0
- package/dist/collections/Users/hooks/ensureFirstUserIsAdmin.d.ts +3 -0
- package/dist/collections/Users/hooks/ensureFirstUserIsAdmin.d.ts.map +1 -0
- package/dist/collections/Users/hooks/ensureFirstUserIsAdmin.js +19 -0
- package/dist/collections/Users/hooks/ensureFirstUserIsAdmin.js.map +1 -0
- package/dist/collections/Users/index.d.ts +76 -0
- package/dist/collections/Users/index.d.ts.map +1 -0
- package/dist/collections/Users/index.js +116 -0
- package/dist/collections/Users/index.js.map +1 -0
- package/dist/collections/index.d.ts +10 -0
- package/dist/collections/index.d.ts.map +1 -0
- package/dist/collections/index.js +14 -0
- package/dist/collections/index.js.map +1 -0
- package/dist/components/index.d.ts +3 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +4 -0
- package/dist/components/index.js.map +1 -0
- package/dist/forms/states.d.ts +8 -0
- package/dist/forms/states.d.ts.map +1 -0
- package/dist/forms/states.js +16 -0
- package/dist/forms/states.js.map +1 -0
- package/dist/forms/translate-errors.d.ts +8 -0
- package/dist/forms/translate-errors.d.ts.map +1 -0
- package/dist/forms/translate-errors.js +11 -0
- package/dist/forms/translate-errors.js.map +1 -0
- package/dist/forms/validators.d.ts +10 -0
- package/dist/forms/validators.d.ts.map +1 -0
- package/dist/forms/validators.js +23 -0
- package/dist/forms/validators.js.map +1 -0
- package/dist/globals/PrivacyPolicy/hooks/revalidate-cache.d.ts +2 -0
- package/dist/globals/PrivacyPolicy/hooks/revalidate-cache.d.ts.map +1 -0
- package/dist/globals/PrivacyPolicy/hooks/revalidate-cache.js +5 -0
- package/dist/globals/PrivacyPolicy/hooks/revalidate-cache.js.map +1 -0
- package/dist/globals/PrivacyPolicy/index.d.ts +3 -0
- package/dist/globals/PrivacyPolicy/index.d.ts.map +1 -0
- package/dist/globals/PrivacyPolicy/index.js +31 -0
- package/dist/globals/PrivacyPolicy/index.js.map +1 -0
- package/dist/globals/TermsOfUse/hooks/revalidate-cache.d.ts +2 -0
- package/dist/globals/TermsOfUse/hooks/revalidate-cache.d.ts.map +1 -0
- package/dist/globals/TermsOfUse/hooks/revalidate-cache.js +5 -0
- package/dist/globals/TermsOfUse/hooks/revalidate-cache.js.map +1 -0
- package/dist/globals/TermsOfUse/index.d.ts +3 -0
- package/dist/globals/TermsOfUse/index.d.ts.map +1 -0
- package/dist/globals/TermsOfUse/index.js +31 -0
- package/dist/globals/TermsOfUse/index.js.map +1 -0
- package/dist/globals/index.d.ts +3 -0
- package/dist/globals/index.d.ts.map +1 -0
- package/dist/globals/index.js +3 -0
- package/dist/globals/index.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/tasks/index.d.ts +2 -0
- package/dist/tasks/index.d.ts.map +1 -0
- package/dist/tasks/index.js +2 -0
- package/dist/tasks/index.js.map +1 -0
- package/dist/tasks/process-email-queue.d.ts +46 -0
- package/dist/tasks/process-email-queue.d.ts.map +1 -0
- package/dist/tasks/process-email-queue.js +199 -0
- package/dist/tasks/process-email-queue.js.map +1 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/slug.d.ts +2 -0
- package/dist/types/slug.d.ts.map +1 -0
- package/dist/types/slug.js +11 -0
- package/dist/types/slug.js.map +1 -0
- package/dist/utils/database-dates.d.ts +3 -0
- package/dist/utils/database-dates.d.ts.map +1 -0
- package/dist/utils/database-dates.js +6 -0
- package/dist/utils/database-dates.js.map +1 -0
- package/dist/utils/email/generate-email-html.d.ts +23 -0
- package/dist/utils/email/generate-email-html.d.ts.map +1 -0
- package/dist/utils/email/generate-email-html.js +42 -0
- package/dist/utils/email/generate-email-html.js.map +1 -0
- package/dist/utils/email/get-email-template.d.ts +8 -0
- package/dist/utils/email/get-email-template.d.ts.map +1 -0
- package/dist/utils/email/get-email-template.js +14 -0
- package/dist/utils/email/get-email-template.js.map +1 -0
- package/dist/utils/email/index.d.ts +4 -0
- package/dist/utils/email/index.d.ts.map +1 -0
- package/dist/utils/email/index.js +4 -0
- package/dist/utils/email/index.js.map +1 -0
- package/dist/utils/email/queue-email.d.ts +29 -0
- package/dist/utils/email/queue-email.d.ts.map +1 -0
- package/dist/utils/email/queue-email.js +79 -0
- package/dist/utils/email/queue-email.js.map +1 -0
- package/dist/utils/get-global.d.ts +6 -0
- package/dist/utils/get-global.d.ts.map +1 -0
- package/dist/utils/get-global.js +20 -0
- package/dist/utils/get-global.js.map +1 -0
- package/dist/utils/id-from-payload.d.ts +4 -0
- package/dist/utils/id-from-payload.d.ts.map +1 -0
- package/dist/utils/id-from-payload.js +10 -0
- package/dist/utils/id-from-payload.js.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/migrations.d.ts +2 -0
- package/dist/utils/migrations.d.ts.map +1 -0
- package/dist/utils/migrations.js +18 -0
- package/dist/utils/migrations.js.map +1 -0
- package/dist/utils/payload-client.d.ts +10 -0
- package/dist/utils/payload-client.d.ts.map +1 -0
- package/dist/utils/payload-client.js +14 -0
- package/dist/utils/payload-client.js.map +1 -0
- package/dist/utils/slugify.d.ts +8 -0
- package/dist/utils/slugify.d.ts.map +1 -0
- package/dist/utils/slugify.js +15 -0
- package/dist/utils/slugify.js.map +1 -0
- package/eslint.config.mjs +90 -0
- package/package.json +139 -0
- package/pnpm-workspace.yaml +4 -0
- package/src/access/adminAccessOnly.ts +13 -0
- package/src/access/admins.ts +78 -0
- package/src/access/anyone.ts +35 -0
- package/src/access/authenticated.ts +70 -0
- package/src/access/authenticatedAccessOnly.ts +13 -0
- package/src/access/index.ts +6 -0
- package/src/access/publicReadAuthenticatedAccess.ts +14 -0
- package/src/collections/ContactMessages/hooks/sendEmailNotification.ts +58 -0
- package/src/collections/ContactMessages/index.ts +100 -0
- package/src/collections/EmailTemplates/index.ts +89 -0
- package/src/collections/Media/index.ts +24 -0
- package/src/collections/QueuedEmails/components/HtmlViewer.tsx +16 -0
- package/src/collections/QueuedEmails/components/RetryEmailButtons.tsx +115 -0
- package/src/collections/QueuedEmails/index.ts +246 -0
- package/src/collections/Users/auth-emails/forgot-password-email.ts +135 -0
- package/src/collections/Users/auth-emails/verify-email.ts +123 -0
- package/src/collections/Users/hooks/ensureFirstUserIsAdmin.ts +22 -0
- package/src/collections/Users/index.ts +201 -0
- package/src/collections/index.ts +23 -0
- package/src/components/index.ts +3 -0
- package/src/forms/states.ts +23 -0
- package/src/forms/translate-errors.ts +13 -0
- package/src/forms/validators.ts +33 -0
- package/src/globals/PrivacyPolicy/hooks/revalidate-cache.ts +5 -0
- package/src/globals/PrivacyPolicy/index.ts +33 -0
- package/src/globals/TermsOfUse/hooks/revalidate-cache.ts +5 -0
- package/src/globals/TermsOfUse/index.ts +33 -0
- package/src/globals/index.ts +2 -0
- package/src/index.ts +26 -0
- package/src/tasks/index.ts +7 -0
- package/src/tasks/process-email-queue.ts +261 -0
- package/src/types/index.ts +15 -0
- package/src/types/slug.ts +11 -0
- package/src/utils/database-dates.ts +6 -0
- package/src/utils/email/generate-email-html.ts +63 -0
- package/src/utils/email/get-email-template.ts +18 -0
- package/src/utils/email/index.ts +3 -0
- package/src/utils/email/queue-email.ts +109 -0
- package/src/utils/get-global.ts +25 -0
- package/src/utils/id-from-payload.ts +11 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/migrations.ts +18 -0
- package/src/utils/payload-client.ts +16 -0
- package/src/utils/slugify.ts +21 -0
- package/tests/fixtures/email-template.html +58 -0
- package/tests/fixtures/sample-data.ts +56 -0
- package/tests/helpers/create-test-user.ts +37 -0
- package/tests/helpers/init-payload.ts +59 -0
- package/tests/setup.integration.ts +9 -0
- package/tests/setup.ts +4 -0
- package/tests/unit/access/adminAccessOnly.spec.ts +117 -0
- package/tests/unit/access/admins.spec.ts +68 -0
- package/tests/unit/access/anyone.spec.ts +28 -0
- package/tests/unit/access/authenticated.spec.ts +53 -0
- package/tests/unit/access/authenticatedAccessOnly.spec.ts +112 -0
- package/tests/unit/access/publicReadAuthenticatedAccess.spec.ts +112 -0
- package/tests/unit/forms/validators.spec.ts +348 -0
- package/tests/unit/utils/database-dates.spec.ts +97 -0
- package/tests/unit/utils/id-from-payload.spec.ts +142 -0
- package/tests/unit/utils/slugify.spec.ts +185 -0
- package/tsconfig.json +31 -0
- package/typedoc.json +40 -0
- package/vitest.config.ts +31 -0
- package/vitest.integration.config.ts +27 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { PayloadRequest } from 'payload';
|
|
2
|
+
export declare const adminAccessOnly: {
|
|
3
|
+
admin: ({ req }: {
|
|
4
|
+
req: PayloadRequest;
|
|
5
|
+
}) => boolean;
|
|
6
|
+
create: ({ req }: {
|
|
7
|
+
req: PayloadRequest;
|
|
8
|
+
}) => boolean;
|
|
9
|
+
delete: ({ req }: {
|
|
10
|
+
req: PayloadRequest;
|
|
11
|
+
}) => boolean;
|
|
12
|
+
read: ({ req }: {
|
|
13
|
+
req: PayloadRequest;
|
|
14
|
+
}) => boolean;
|
|
15
|
+
readVersions: ({ req }: {
|
|
16
|
+
req: PayloadRequest;
|
|
17
|
+
}) => boolean;
|
|
18
|
+
unlock: ({ req }: {
|
|
19
|
+
req: PayloadRequest;
|
|
20
|
+
}) => boolean;
|
|
21
|
+
update: ({ req }: {
|
|
22
|
+
req: PayloadRequest;
|
|
23
|
+
}) => boolean;
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=adminAccessOnly.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adminAccessOnly.d.ts","sourceRoot":"","sources":["../../src/access/adminAccessOnly.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAIzC,eAAO,MAAM,eAAe;qBACT;QAAE,GAAG,EAAE,cAAc,CAAA;KAAE;;;;;;;;;;;;;;;;;;;CAOzC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { admins } from './admins';
|
|
2
|
+
export const adminAccessOnly = {
|
|
3
|
+
admin: ({ req }) => Boolean(req.user?.roles?.includes('admin')),
|
|
4
|
+
create: admins,
|
|
5
|
+
delete: admins,
|
|
6
|
+
read: admins,
|
|
7
|
+
readVersions: admins,
|
|
8
|
+
unlock: admins,
|
|
9
|
+
update: admins,
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=adminAccessOnly.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adminAccessOnly.js","sourceRoot":"","sources":["../../src/access/adminAccessOnly.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,KAAK,EAAE,CAAC,EAAE,GAAG,EAA2B,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;IACxF,MAAM,EAAE,MAAM;IACd,MAAM,EAAE,MAAM;IACd,IAAI,EAAE,MAAM;IACZ,YAAY,EAAE,MAAM;IACpB,MAAM,EAAE,MAAM;IACd,MAAM,EAAE,MAAM;CACf,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { FieldAccess, PayloadRequest } from 'payload';
|
|
2
|
+
/**
|
|
3
|
+
* Access control function that restricts access to admin users only.
|
|
4
|
+
*
|
|
5
|
+
* @description
|
|
6
|
+
* This function checks if the authenticated user has the 'admin' role in their roles array.
|
|
7
|
+
* Commonly used for collection-level or operation-level access control in PayloadCMS.
|
|
8
|
+
*
|
|
9
|
+
* @param {Object} params - Access control parameters
|
|
10
|
+
* @param {PayloadRequest} params.req - The Payload request object containing user information
|
|
11
|
+
*
|
|
12
|
+
* @returns {boolean} True if user has admin role, false otherwise
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // Use in a collection config
|
|
17
|
+
* export const AdminOnlyCollection: CollectionConfig = {
|
|
18
|
+
* slug: 'admin-only',
|
|
19
|
+
* access: {
|
|
20
|
+
* create: admins,
|
|
21
|
+
* read: admins,
|
|
22
|
+
* update: admins,
|
|
23
|
+
* delete: admins,
|
|
24
|
+
* },
|
|
25
|
+
* fields: [...],
|
|
26
|
+
* };
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* // Use for specific operations
|
|
32
|
+
* if (admins({ req })) {
|
|
33
|
+
* // User is admin, allow operation
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @see {@link adminsFieldLevel} for field-level admin access control
|
|
38
|
+
* @see {@link adminAccessOnly} for a complete access control object with all operations restricted to admins
|
|
39
|
+
*/
|
|
40
|
+
export declare const admins: ({ req }: {
|
|
41
|
+
req: PayloadRequest;
|
|
42
|
+
}) => boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Field-level access control function that restricts field access to admin users only.
|
|
45
|
+
*
|
|
46
|
+
* @description
|
|
47
|
+
* Similar to {@link admins} but designed for use with field-level access control.
|
|
48
|
+
* Checks if the user has the 'admin' role to determine field visibility/editability.
|
|
49
|
+
*
|
|
50
|
+
* @param {Object} params - Field access parameters
|
|
51
|
+
* @param {Object} params.req - The request object
|
|
52
|
+
* @param {Object} params.req.user - The authenticated user
|
|
53
|
+
*
|
|
54
|
+
* @returns {boolean} True if user has admin role, false otherwise
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* // Restrict field to admins only
|
|
59
|
+
* {
|
|
60
|
+
* name: 'sensitiveField',
|
|
61
|
+
* type: 'text',
|
|
62
|
+
* access: {
|
|
63
|
+
* read: adminsFieldLevel,
|
|
64
|
+
* update: adminsFieldLevel,
|
|
65
|
+
* },
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @see {@link admins} for collection-level admin access control
|
|
70
|
+
*/
|
|
71
|
+
export declare const adminsFieldLevel: FieldAccess<any, any>;
|
|
72
|
+
//# sourceMappingURL=admins.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admins.d.ts","sourceRoot":"","sources":["../../src/access/admins.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,eAAO,MAAM,MAAM,GAAI,SAAS;IAAE,GAAG,EAAE,cAAc,CAAA;CAAE,YAGtD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,eAAO,MAAM,gBAAgB,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,CAGlD,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Access control function that restricts access to admin users only.
|
|
3
|
+
*
|
|
4
|
+
* @description
|
|
5
|
+
* This function checks if the authenticated user has the 'admin' role in their roles array.
|
|
6
|
+
* Commonly used for collection-level or operation-level access control in PayloadCMS.
|
|
7
|
+
*
|
|
8
|
+
* @param {Object} params - Access control parameters
|
|
9
|
+
* @param {PayloadRequest} params.req - The Payload request object containing user information
|
|
10
|
+
*
|
|
11
|
+
* @returns {boolean} True if user has admin role, false otherwise
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // Use in a collection config
|
|
16
|
+
* export const AdminOnlyCollection: CollectionConfig = {
|
|
17
|
+
* slug: 'admin-only',
|
|
18
|
+
* access: {
|
|
19
|
+
* create: admins,
|
|
20
|
+
* read: admins,
|
|
21
|
+
* update: admins,
|
|
22
|
+
* delete: admins,
|
|
23
|
+
* },
|
|
24
|
+
* fields: [...],
|
|
25
|
+
* };
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* // Use for specific operations
|
|
31
|
+
* if (admins({ req })) {
|
|
32
|
+
* // User is admin, allow operation
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @see {@link adminsFieldLevel} for field-level admin access control
|
|
37
|
+
* @see {@link adminAccessOnly} for a complete access control object with all operations restricted to admins
|
|
38
|
+
*/
|
|
39
|
+
export const admins = ({ req }) => {
|
|
40
|
+
// Return true or false based on if the user has an admin role
|
|
41
|
+
return Boolean(req.user?.roles?.includes('admin'));
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Field-level access control function that restricts field access to admin users only.
|
|
45
|
+
*
|
|
46
|
+
* @description
|
|
47
|
+
* Similar to {@link admins} but designed for use with field-level access control.
|
|
48
|
+
* Checks if the user has the 'admin' role to determine field visibility/editability.
|
|
49
|
+
*
|
|
50
|
+
* @param {Object} params - Field access parameters
|
|
51
|
+
* @param {Object} params.req - The request object
|
|
52
|
+
* @param {Object} params.req.user - The authenticated user
|
|
53
|
+
*
|
|
54
|
+
* @returns {boolean} True if user has admin role, false otherwise
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* // Restrict field to admins only
|
|
59
|
+
* {
|
|
60
|
+
* name: 'sensitiveField',
|
|
61
|
+
* type: 'text',
|
|
62
|
+
* access: {
|
|
63
|
+
* read: adminsFieldLevel,
|
|
64
|
+
* update: adminsFieldLevel,
|
|
65
|
+
* },
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @see {@link admins} for collection-level admin access control
|
|
70
|
+
*/
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
72
|
+
export const adminsFieldLevel = ({ req: { user } }) => {
|
|
73
|
+
// Return true or false based on if the user has an admin role
|
|
74
|
+
return Boolean(user?.roles?.includes('admin'));
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=admins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admins.js","sourceRoot":"","sources":["../../src/access/admins.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,EAAE,GAAG,EAA2B,EAAE,EAAE;IACzD,8DAA8D;IAC9D,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;AACrD,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,8DAA8D;AAC9D,MAAM,CAAC,MAAM,gBAAgB,GAA0B,CAAC,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE;IAC3E,8DAA8D;IAC9D,OAAO,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;AACjD,CAAC,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Access } from 'payload';
|
|
2
|
+
/**
|
|
3
|
+
* Access control function that allows unrestricted public access.
|
|
4
|
+
*
|
|
5
|
+
* @description
|
|
6
|
+
* This function always returns true, allowing access to all users regardless of authentication status.
|
|
7
|
+
* Use this for truly public content like blog posts, landing pages, or public API endpoints.
|
|
8
|
+
*
|
|
9
|
+
* @returns {boolean} Always returns true
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // Use for public content
|
|
14
|
+
* export const BlogPostsCollection: CollectionConfig = {
|
|
15
|
+
* slug: 'blog-posts',
|
|
16
|
+
* access: {
|
|
17
|
+
* read: anyone, // Anyone can read
|
|
18
|
+
* create: admins, // Only admins can create
|
|
19
|
+
* update: admins,
|
|
20
|
+
* delete: admins,
|
|
21
|
+
* },
|
|
22
|
+
* fields: [...],
|
|
23
|
+
* };
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* // Use with publicReadAuthenticatedAccess for read-only public access
|
|
29
|
+
* import { publicReadAuthenticatedAccess } from '@latte-macchiat-io/latte-payload/access';
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @see {@link publicReadAuthenticatedAccess} for public read with authenticated write pattern
|
|
33
|
+
*/
|
|
34
|
+
export declare const anyone: Access;
|
|
35
|
+
//# sourceMappingURL=anyone.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anyone.d.ts","sourceRoot":"","sources":["../../src/access/anyone.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,MAAM,EAAE,MAAmB,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Access control function that allows unrestricted public access.
|
|
3
|
+
*
|
|
4
|
+
* @description
|
|
5
|
+
* This function always returns true, allowing access to all users regardless of authentication status.
|
|
6
|
+
* Use this for truly public content like blog posts, landing pages, or public API endpoints.
|
|
7
|
+
*
|
|
8
|
+
* @returns {boolean} Always returns true
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Use for public content
|
|
13
|
+
* export const BlogPostsCollection: CollectionConfig = {
|
|
14
|
+
* slug: 'blog-posts',
|
|
15
|
+
* access: {
|
|
16
|
+
* read: anyone, // Anyone can read
|
|
17
|
+
* create: admins, // Only admins can create
|
|
18
|
+
* update: admins,
|
|
19
|
+
* delete: admins,
|
|
20
|
+
* },
|
|
21
|
+
* fields: [...],
|
|
22
|
+
* };
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* // Use with publicReadAuthenticatedAccess for read-only public access
|
|
28
|
+
* import { publicReadAuthenticatedAccess } from '@latte-macchiat-io/latte-payload/access';
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @see {@link publicReadAuthenticatedAccess} for public read with authenticated write pattern
|
|
32
|
+
*/
|
|
33
|
+
export const anyone = () => true;
|
|
34
|
+
//# sourceMappingURL=anyone.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anyone.js","sourceRoot":"","sources":["../../src/access/anyone.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,CAAC,MAAM,MAAM,GAAW,GAAG,EAAE,CAAC,IAAI,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Access, FieldAccess } from 'payload';
|
|
2
|
+
/**
|
|
3
|
+
* Access control function that allows access to any authenticated user.
|
|
4
|
+
*
|
|
5
|
+
* @description
|
|
6
|
+
* This function checks if there is an authenticated user in the request, regardless of their role.
|
|
7
|
+
* Useful for content that should be accessible to all logged-in users but not to the public.
|
|
8
|
+
*
|
|
9
|
+
* @param {Object} params - Access control parameters
|
|
10
|
+
* @param {Object} params.req - The request object
|
|
11
|
+
* @param {Object} params.req.user - The authenticated user (if any)
|
|
12
|
+
*
|
|
13
|
+
* @returns {boolean} True if user is authenticated, false otherwise
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // Use in a collection config
|
|
18
|
+
* export const UserContentCollection: CollectionConfig = {
|
|
19
|
+
* slug: 'user-content',
|
|
20
|
+
* access: {
|
|
21
|
+
* create: authenticated,
|
|
22
|
+
* read: authenticated,
|
|
23
|
+
* update: authenticated,
|
|
24
|
+
* delete: authenticated,
|
|
25
|
+
* },
|
|
26
|
+
* fields: [...],
|
|
27
|
+
* };
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @see {@link authenticatedFieldLevel} for field-level authenticated access control
|
|
31
|
+
* @see {@link authenticatedAccessOnly} for a complete access control object
|
|
32
|
+
*/
|
|
33
|
+
export declare const authenticated: Access;
|
|
34
|
+
/**
|
|
35
|
+
* Field-level access control function that restricts field access to authenticated users.
|
|
36
|
+
*
|
|
37
|
+
* @description
|
|
38
|
+
* Similar to {@link authenticated} but designed for use with field-level access control.
|
|
39
|
+
* Checks if the user is authenticated to determine field visibility/editability.
|
|
40
|
+
*
|
|
41
|
+
* @param {Object} params - Field access parameters
|
|
42
|
+
* @param {Object} params.req - The request object
|
|
43
|
+
* @param {Object} params.req.user - The authenticated user (if any)
|
|
44
|
+
*
|
|
45
|
+
* @returns {boolean} True if user is authenticated, false otherwise
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* // Hide field from unauthenticated users
|
|
50
|
+
* {
|
|
51
|
+
* name: 'memberOnlyField',
|
|
52
|
+
* type: 'text',
|
|
53
|
+
* access: {
|
|
54
|
+
* read: authenticatedFieldLevel,
|
|
55
|
+
* update: authenticatedFieldLevel,
|
|
56
|
+
* },
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @see {@link authenticated} for collection-level authenticated access control
|
|
61
|
+
*/
|
|
62
|
+
export declare const authenticatedFieldLevel: FieldAccess;
|
|
63
|
+
//# sourceMappingURL=authenticated.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authenticated.d.ts","sourceRoot":"","sources":["../../src/access/authenticated.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,aAAa,EAAE,MAG3B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,uBAAuB,EAAE,WAGrC,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Access control function that allows access to any authenticated user.
|
|
3
|
+
*
|
|
4
|
+
* @description
|
|
5
|
+
* This function checks if there is an authenticated user in the request, regardless of their role.
|
|
6
|
+
* Useful for content that should be accessible to all logged-in users but not to the public.
|
|
7
|
+
*
|
|
8
|
+
* @param {Object} params - Access control parameters
|
|
9
|
+
* @param {Object} params.req - The request object
|
|
10
|
+
* @param {Object} params.req.user - The authenticated user (if any)
|
|
11
|
+
*
|
|
12
|
+
* @returns {boolean} True if user is authenticated, false otherwise
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // Use in a collection config
|
|
17
|
+
* export const UserContentCollection: CollectionConfig = {
|
|
18
|
+
* slug: 'user-content',
|
|
19
|
+
* access: {
|
|
20
|
+
* create: authenticated,
|
|
21
|
+
* read: authenticated,
|
|
22
|
+
* update: authenticated,
|
|
23
|
+
* delete: authenticated,
|
|
24
|
+
* },
|
|
25
|
+
* fields: [...],
|
|
26
|
+
* };
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @see {@link authenticatedFieldLevel} for field-level authenticated access control
|
|
30
|
+
* @see {@link authenticatedAccessOnly} for a complete access control object
|
|
31
|
+
*/
|
|
32
|
+
export const authenticated = ({ req: { user } }) => {
|
|
33
|
+
// Return true or false based on if the user is authenticated
|
|
34
|
+
return Boolean(!!user);
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Field-level access control function that restricts field access to authenticated users.
|
|
38
|
+
*
|
|
39
|
+
* @description
|
|
40
|
+
* Similar to {@link authenticated} but designed for use with field-level access control.
|
|
41
|
+
* Checks if the user is authenticated to determine field visibility/editability.
|
|
42
|
+
*
|
|
43
|
+
* @param {Object} params - Field access parameters
|
|
44
|
+
* @param {Object} params.req - The request object
|
|
45
|
+
* @param {Object} params.req.user - The authenticated user (if any)
|
|
46
|
+
*
|
|
47
|
+
* @returns {boolean} True if user is authenticated, false otherwise
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* // Hide field from unauthenticated users
|
|
52
|
+
* {
|
|
53
|
+
* name: 'memberOnlyField',
|
|
54
|
+
* type: 'text',
|
|
55
|
+
* access: {
|
|
56
|
+
* read: authenticatedFieldLevel,
|
|
57
|
+
* update: authenticatedFieldLevel,
|
|
58
|
+
* },
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @see {@link authenticated} for collection-level authenticated access control
|
|
63
|
+
*/
|
|
64
|
+
export const authenticatedFieldLevel = ({ req: { user } }) => {
|
|
65
|
+
// Return true or false based on if the user is authenticated
|
|
66
|
+
return Boolean(!!user);
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=authenticated.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authenticated.js","sourceRoot":"","sources":["../../src/access/authenticated.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,MAAM,aAAa,GAAW,CAAC,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE;IACzD,6DAA6D;IAC7D,OAAO,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAgB,CAAC,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE;IACxE,6DAA6D;IAC7D,OAAO,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PayloadRequest } from 'payload';
|
|
2
|
+
export declare const authenticatedAccessOnly: {
|
|
3
|
+
admin: ({ req }: {
|
|
4
|
+
req: PayloadRequest;
|
|
5
|
+
}) => boolean;
|
|
6
|
+
create: import("payload").Access;
|
|
7
|
+
delete: import("payload").Access;
|
|
8
|
+
read: import("payload").Access;
|
|
9
|
+
readVersions: import("payload").Access;
|
|
10
|
+
unlock: import("payload").Access;
|
|
11
|
+
update: import("payload").Access;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=authenticatedAccessOnly.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authenticatedAccessOnly.d.ts","sourceRoot":"","sources":["../../src/access/authenticatedAccessOnly.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAIzC,eAAO,MAAM,uBAAuB;qBACjB;QAAE,GAAG,EAAE,cAAc,CAAA;KAAE;;;;;;;CAOzC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { authenticated } from './authenticated';
|
|
2
|
+
export const authenticatedAccessOnly = {
|
|
3
|
+
admin: ({ req }) => !!req.user,
|
|
4
|
+
create: authenticated,
|
|
5
|
+
delete: authenticated,
|
|
6
|
+
read: authenticated,
|
|
7
|
+
readVersions: authenticated,
|
|
8
|
+
unlock: authenticated,
|
|
9
|
+
update: authenticated,
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=authenticatedAccessOnly.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authenticatedAccessOnly.js","sourceRoot":"","sources":["../../src/access/authenticatedAccessOnly.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,KAAK,EAAE,CAAC,EAAE,GAAG,EAA2B,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI;IACvD,MAAM,EAAE,aAAa;IACrB,MAAM,EAAE,aAAa;IACrB,IAAI,EAAE,aAAa;IACnB,YAAY,EAAE,aAAa;IAC3B,MAAM,EAAE,aAAa;IACrB,MAAM,EAAE,aAAa;CACtB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { anyone } from './anyone';
|
|
2
|
+
export { authenticated, authenticatedFieldLevel } from './authenticated';
|
|
3
|
+
export { admins, adminsFieldLevel } from './admins';
|
|
4
|
+
export { adminAccessOnly } from './adminAccessOnly';
|
|
5
|
+
export { authenticatedAccessOnly } from './authenticatedAccessOnly';
|
|
6
|
+
export { publicReadAuthenticatedAccess } from './publicReadAuthenticatedAccess';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/access/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { anyone } from './anyone';
|
|
2
|
+
export { authenticated, authenticatedFieldLevel } from './authenticated';
|
|
3
|
+
export { admins, adminsFieldLevel } from './admins';
|
|
4
|
+
export { adminAccessOnly } from './adminAccessOnly';
|
|
5
|
+
export { authenticatedAccessOnly } from './authenticatedAccessOnly';
|
|
6
|
+
export { publicReadAuthenticatedAccess } from './publicReadAuthenticatedAccess';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/access/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PayloadRequest } from 'payload';
|
|
2
|
+
export declare const publicReadAuthenticatedAccess: {
|
|
3
|
+
admin: ({ req }: {
|
|
4
|
+
req: PayloadRequest;
|
|
5
|
+
}) => boolean;
|
|
6
|
+
create: import("payload").Access;
|
|
7
|
+
delete: import("payload").Access;
|
|
8
|
+
read: import("payload").Access;
|
|
9
|
+
readVersions: import("payload").Access;
|
|
10
|
+
unlock: import("payload").Access;
|
|
11
|
+
update: import("payload").Access;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=publicReadAuthenticatedAccess.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publicReadAuthenticatedAccess.d.ts","sourceRoot":"","sources":["../../src/access/publicReadAuthenticatedAccess.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAKzC,eAAO,MAAM,6BAA6B;qBACvB;QAAE,GAAG,EAAE,cAAc,CAAA;KAAE;;;;;;;CAOzC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { anyone } from './anyone';
|
|
2
|
+
import { authenticated } from './authenticated';
|
|
3
|
+
export const publicReadAuthenticatedAccess = {
|
|
4
|
+
admin: ({ req }) => !!req.user,
|
|
5
|
+
create: authenticated,
|
|
6
|
+
delete: authenticated,
|
|
7
|
+
read: anyone,
|
|
8
|
+
readVersions: authenticated,
|
|
9
|
+
unlock: authenticated,
|
|
10
|
+
update: authenticated,
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=publicReadAuthenticatedAccess.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publicReadAuthenticatedAccess.js","sourceRoot":"","sources":["../../src/access/publicReadAuthenticatedAccess.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,MAAM,CAAC,MAAM,6BAA6B,GAAG;IAC3C,KAAK,EAAE,CAAC,EAAE,GAAG,EAA2B,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI;IACvD,MAAM,EAAE,aAAa;IACrB,MAAM,EAAE,aAAa;IACrB,IAAI,EAAE,MAAM;IACZ,YAAY,EAAE,aAAa;IAC3B,MAAM,EAAE,aAAa;IACrB,MAAM,EAAE,aAAa;CACtB,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { CollectionAfterChangeHook } from 'payload';
|
|
2
|
+
export interface SendEmailNotificationConfig {
|
|
3
|
+
/**
|
|
4
|
+
* Email address to send notifications to
|
|
5
|
+
* If not provided, uses process.env.EMAIL_DEFAULT_CONTACT_ADDRESS
|
|
6
|
+
*/
|
|
7
|
+
contactEmail?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Subject for the notification email
|
|
10
|
+
* Default: 'Nouveau message de contact'
|
|
11
|
+
*/
|
|
12
|
+
subject?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Custom email body generator
|
|
15
|
+
* @param doc - The contact message document
|
|
16
|
+
* @returns Email body text
|
|
17
|
+
*/
|
|
18
|
+
generateEmailBody?: (doc: any) => string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Create a sendEmailNotification hook with custom configuration
|
|
22
|
+
*
|
|
23
|
+
* @param config - Optional configuration for email notifications
|
|
24
|
+
* @returns CollectionAfterChangeHook
|
|
25
|
+
*/
|
|
26
|
+
export declare function createSendEmailNotificationHook(config?: SendEmailNotificationConfig): CollectionAfterChangeHook<any>;
|
|
27
|
+
/**
|
|
28
|
+
* Default sendEmailNotification hook
|
|
29
|
+
*/
|
|
30
|
+
export declare const sendEmailNotification: CollectionAfterChangeHook<any>;
|
|
31
|
+
//# sourceMappingURL=sendEmailNotification.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sendEmailNotification.d.ts","sourceRoot":"","sources":["../../../../src/collections/ContactMessages/hooks/sendEmailNotification.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAEpD,MAAM,WAAW,2BAA2B;IAC1C;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;OAIG;IAEH,iBAAiB,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,CAAC;CAC1C;AAED;;;;;GAKG;AAEH,wBAAgB,+BAA+B,CAAC,MAAM,CAAC,EAAE,2BAA2B,GAAG,yBAAyB,CAAC,GAAG,CAAC,CAqBpH;AAED;;GAEG;AACH,eAAO,MAAM,qBAAqB,gCAAoC,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a sendEmailNotification hook with custom configuration
|
|
3
|
+
*
|
|
4
|
+
* @param config - Optional configuration for email notifications
|
|
5
|
+
* @returns CollectionAfterChangeHook
|
|
6
|
+
*/
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
|
+
export function createSendEmailNotificationHook(config) {
|
|
9
|
+
return async ({ req: { payload }, doc }) => {
|
|
10
|
+
const toEmail = config?.contactEmail || process.env.EMAIL_DEFAULT_CONTACT_ADDRESS;
|
|
11
|
+
if (!toEmail) {
|
|
12
|
+
payload.logger.error('No contact email address configured for sendEmailNotification hook');
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
payload.logger.info('Sending email notification to the admin');
|
|
16
|
+
const emailBody = config?.generateEmailBody?.(doc) ||
|
|
17
|
+
`Un nouveau message de contact a été reçu de la part de ${doc.name} (${doc.email}).\n\nSujet: ${doc.subject}\n\nMessage: ${doc.message}`;
|
|
18
|
+
await payload.sendEmail({
|
|
19
|
+
to: toEmail,
|
|
20
|
+
subject: config?.subject || 'Nouveau message de contact',
|
|
21
|
+
text: emailBody,
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Default sendEmailNotification hook
|
|
27
|
+
*/
|
|
28
|
+
export const sendEmailNotification = createSendEmailNotificationHook();
|
|
29
|
+
//# sourceMappingURL=sendEmailNotification.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sendEmailNotification.js","sourceRoot":"","sources":["../../../../src/collections/ContactMessages/hooks/sendEmailNotification.ts"],"names":[],"mappings":"AAwBA;;;;;GAKG;AACH,8DAA8D;AAC9D,MAAM,UAAU,+BAA+B,CAAC,MAAoC;IAClF,OAAO,KAAK,EAAE,EAAE,GAAG,EAAE,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE;QACzC,MAAM,OAAO,GAAG,MAAM,EAAE,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC;QAElF,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,oEAAoE,CAAC,CAAC;YAC3F,OAAO;QACT,CAAC;QAED,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,yCAAyC,CAAC,CAAC;QAE/D,MAAM,SAAS,GACb,MAAM,EAAE,iBAAiB,EAAE,CAAC,GAAG,CAAC;YAChC,0DAA0D,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,KAAK,gBAAgB,GAAG,CAAC,OAAO,gBAAgB,GAAG,CAAC,OAAO,EAAE,CAAC;QAE3I,MAAM,OAAO,CAAC,SAAS,CAAC;YACtB,EAAE,EAAE,OAAO;YACX,OAAO,EAAE,MAAM,EAAE,OAAO,IAAI,4BAA4B;YACxD,IAAI,EAAE,SAAS;SAChB,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,+BAA+B,EAAE,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CollectionConfig } from 'payload';
|
|
2
|
+
import { createSendEmailNotificationHook, type SendEmailNotificationConfig } from './hooks/sendEmailNotification';
|
|
3
|
+
import type { Locale } from '../../types';
|
|
4
|
+
export interface ContactMessagesConfig {
|
|
5
|
+
/**
|
|
6
|
+
* Allowed locales for contact messages
|
|
7
|
+
* @default ['en', 'fr', 'nl']
|
|
8
|
+
*/
|
|
9
|
+
locales?: Locale[];
|
|
10
|
+
/**
|
|
11
|
+
* Configuration for email notifications
|
|
12
|
+
*/
|
|
13
|
+
emailNotificationConfig?: SendEmailNotificationConfig;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Create ContactMessages collection with optional configuration
|
|
17
|
+
*
|
|
18
|
+
* @param config - Optional configuration for the ContactMessages collection
|
|
19
|
+
* @returns CollectionConfig for ContactMessages
|
|
20
|
+
*/
|
|
21
|
+
export declare function createContactMessagesCollection(config?: ContactMessagesConfig): CollectionConfig;
|
|
22
|
+
/**
|
|
23
|
+
* Default ContactMessages collection
|
|
24
|
+
*/
|
|
25
|
+
export declare const ContactMessages: CollectionConfig;
|
|
26
|
+
export { createSendEmailNotificationHook, type SendEmailNotificationConfig };
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/collections/ContactMessages/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C,OAAO,EAAE,+BAA+B,EAAyB,KAAK,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAEzI,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAEnB;;OAEG;IACH,uBAAuB,CAAC,EAAE,2BAA2B,CAAC;CACvD;AAED;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAAC,MAAM,CAAC,EAAE,qBAAqB,GAAG,gBAAgB,CAkEhG;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,kBAAoC,CAAC;AAGjE,OAAO,EAAE,+BAA+B,EAAE,KAAK,2BAA2B,EAAE,CAAC"}
|