@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 @@
|
|
|
1
|
+
{"version":3,"file":"translate-errors.d.ts","sourceRoot":"","sources":["../../src/forms/translate-errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,MAAM,EAAE,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC;;;;;GAQlG"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { getTranslations } from 'next-intl/server';
|
|
2
|
+
// Utility to translate error keys using i18n
|
|
3
|
+
export async function translateFormErrors(errors) {
|
|
4
|
+
const t = await getTranslations();
|
|
5
|
+
const translate = (messages) => messages?.map((msg) => t(msg)) ?? [];
|
|
6
|
+
return {
|
|
7
|
+
fieldErrors: Object.fromEntries(Object.entries(errors.fieldErrors).map(([field, msgs]) => [field, translate(msgs)])),
|
|
8
|
+
formErrors: translate(errors.formErrors),
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=translate-errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translate-errors.js","sourceRoot":"","sources":["../../src/forms/translate-errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGnD,6CAA6C;AAC7C,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAyB,MAAiC;IACjG,MAAM,CAAC,GAAG,MAAM,eAAe,EAAE,CAAC;IAClC,MAAM,SAAS,GAAG,CAAC,QAAmB,EAAE,EAAE,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IAEhF,OAAO;QACL,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,SAAS,CAAC,IAAgB,CAAC,CAAC,CAAC,CAAC;QAChI,UAAU,EAAE,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC;KACzC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const requiredString: (message: string) => z.ZodString;
|
|
3
|
+
export declare const requiredPasswordString: (minLength: number, requiredMessage: string, minLengthMessage: string) => z.ZodPipeline<z.ZodString, z.ZodString>;
|
|
4
|
+
export declare const requiredEmailString: ({ required, email }: {
|
|
5
|
+
required: string;
|
|
6
|
+
email: string;
|
|
7
|
+
}) => z.ZodPipeline<z.ZodString, z.ZodString>;
|
|
8
|
+
export declare const validHoneyPot: (message: string) => z.ZodEffects<z.ZodString, string, string>;
|
|
9
|
+
export declare const requiredCheckbox: (message: string) => z.ZodEffects<z.ZodBoolean, boolean, boolean>;
|
|
10
|
+
//# sourceMappingURL=validators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/forms/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,cAAc,GAAI,SAAS,MAAM,gBAI/B,CAAC;AAEhB,eAAO,MAAM,sBAAsB,GAAI,WAAW,MAAM,EAAE,iBAAiB,MAAM,EAAE,kBAAkB,MAAM,4CAOtG,CAAC;AAEN,eAAO,MAAM,mBAAmB,GAAI,qBAAqB;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,4CAK7C,CAAC;AAEhD,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,8CAGP,CAAC;AAEvC,eAAO,MAAM,gBAAgB,GAAI,SAAS,MAAM,iDAGvB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const requiredString = (message) => z
|
|
3
|
+
.string({ errorMap: () => ({ message }) }) // Same error message for all errors
|
|
4
|
+
.trim()
|
|
5
|
+
.nonempty();
|
|
6
|
+
export const requiredPasswordString = (minLength, requiredMessage, minLengthMessage) => z
|
|
7
|
+
.string({ errorMap: () => ({ message: requiredMessage }) }) // Same error message for all errors
|
|
8
|
+
.trim()
|
|
9
|
+
.nonempty()
|
|
10
|
+
.pipe(z.string().min(minLength, { message: minLengthMessage }) // Ensure password is at least 12 characters long
|
|
11
|
+
);
|
|
12
|
+
export const requiredEmailString = ({ required, email }) => z
|
|
13
|
+
.string() // Same error message for all errors
|
|
14
|
+
.trim()
|
|
15
|
+
.nonempty({ message: required })
|
|
16
|
+
.pipe(z.string().email({ message: email })); // “email” runs only if nonempty passed
|
|
17
|
+
export const validHoneyPot = (message) => z
|
|
18
|
+
.string({ errorMap: () => ({ message }) }) // Same error message for all errors
|
|
19
|
+
.refine((val) => val.length === 0); // Must be empty
|
|
20
|
+
export const requiredCheckbox = (message) => z
|
|
21
|
+
.boolean({ errorMap: () => ({ message }) }) // Same error message for all errors
|
|
22
|
+
.refine((val) => val); // Must be true
|
|
23
|
+
//# sourceMappingURL=validators.js.map
|
|
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AAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,oCAAoC;KAC9E,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,gBAAgB;AAExD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAAe,EAAE,EAAE,CAClD,CAAC;KACE,OAAO,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,oCAAoC;KAC/E,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,eAAe"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"revalidate-cache.d.ts","sourceRoot":"","sources":["../../../../src/globals/PrivacyPolicy/hooks/revalidate-cache.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe,qBAE3B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"revalidate-cache.js","sourceRoot":"","sources":["../../../../src/globals/PrivacyPolicy/hooks/revalidate-cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,IAAI,EAAE;IACxC,cAAc,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;AAChC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/globals/PrivacyPolicy/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAK5C,eAAO,MAAM,aAAa,EAAE,YA2B3B,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { revalidateCache } from './hooks/revalidate-cache';
|
|
2
|
+
import { authenticatedAccessOnly } from '../../access/authenticatedAccessOnly';
|
|
3
|
+
export const PrivacyPolicy = {
|
|
4
|
+
slug: 'privacy-policy',
|
|
5
|
+
label: { fr: 'Politique de confidentialité', nl: 'Privacybeleid', en: 'Privacy Policy' },
|
|
6
|
+
admin: {
|
|
7
|
+
group: { fr: 'Légal', nl: 'Juridisch', en: 'Legal' },
|
|
8
|
+
hideAPIURL: true,
|
|
9
|
+
},
|
|
10
|
+
access: authenticatedAccessOnly,
|
|
11
|
+
hooks: {
|
|
12
|
+
afterChange: [revalidateCache],
|
|
13
|
+
},
|
|
14
|
+
fields: [
|
|
15
|
+
{
|
|
16
|
+
name: 'title',
|
|
17
|
+
label: { fr: 'Titre', nl: 'Titel', en: 'Title' },
|
|
18
|
+
type: 'text',
|
|
19
|
+
required: true,
|
|
20
|
+
localized: true,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: 'content',
|
|
24
|
+
label: { fr: 'Contenu', nl: 'Inhoud', en: 'Content' },
|
|
25
|
+
type: 'richText',
|
|
26
|
+
required: true,
|
|
27
|
+
localized: true,
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/globals/PrivacyPolicy/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAE/E,MAAM,CAAC,MAAM,aAAa,GAAiB;IACzC,IAAI,EAAE,gBAAgB;IACtB,KAAK,EAAE,EAAE,EAAE,EAAE,8BAA8B,EAAE,EAAE,EAAE,eAAe,EAAE,EAAE,EAAE,gBAAgB,EAAE;IACxF,KAAK,EAAE;QACL,KAAK,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,OAAO,EAAE;QACpD,UAAU,EAAE,IAAI;KACjB;IACD,MAAM,EAAE,uBAAuB;IAC/B,KAAK,EAAE;QACL,WAAW,EAAE,CAAC,eAAe,CAAC;KAC/B;IACD,MAAM,EAAE;QACN;YACE,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE;YAChD,IAAI,EAAE,MAAM;YACZ,QAAQ,EAAE,IAAI;YACd,SAAS,EAAE,IAAI;SAChB;QACD;YACE,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE;YACrD,IAAI,EAAE,UAAU;YAChB,QAAQ,EAAE,IAAI;YACd,SAAS,EAAE,IAAI;SAChB;KACF;CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"revalidate-cache.d.ts","sourceRoot":"","sources":["../../../../src/globals/TermsOfUse/hooks/revalidate-cache.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe,qBAE3B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"revalidate-cache.js","sourceRoot":"","sources":["../../../../src/globals/TermsOfUse/hooks/revalidate-cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,IAAI,EAAE;IACxC,cAAc,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;AAChC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/globals/TermsOfUse/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAK5C,eAAO,MAAM,UAAU,EAAE,YA2BxB,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { revalidateCache } from './hooks/revalidate-cache';
|
|
2
|
+
import { authenticatedAccessOnly } from '../../access/authenticatedAccessOnly';
|
|
3
|
+
export const TermsOfUse = {
|
|
4
|
+
slug: 'terms-of-use',
|
|
5
|
+
label: { fr: "Conditions d'utilisation", nl: 'Gebruiksvoorwaarden', en: 'Terms of Use' },
|
|
6
|
+
admin: {
|
|
7
|
+
group: { fr: 'Légal', nl: 'Juridisch', en: 'Legal' },
|
|
8
|
+
hideAPIURL: true,
|
|
9
|
+
},
|
|
10
|
+
access: authenticatedAccessOnly,
|
|
11
|
+
hooks: {
|
|
12
|
+
afterChange: [revalidateCache],
|
|
13
|
+
},
|
|
14
|
+
fields: [
|
|
15
|
+
{
|
|
16
|
+
name: 'title',
|
|
17
|
+
label: { fr: 'Titre', nl: 'Titel', en: 'Title' },
|
|
18
|
+
type: 'text',
|
|
19
|
+
required: true,
|
|
20
|
+
localized: true,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: 'content',
|
|
24
|
+
label: { fr: 'Contenu', nl: 'Inhoud', en: 'Content' },
|
|
25
|
+
type: 'richText',
|
|
26
|
+
required: true,
|
|
27
|
+
localized: true,
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/globals/TermsOfUse/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAE/E,MAAM,CAAC,MAAM,UAAU,GAAiB;IACtC,IAAI,EAAE,cAAc;IACpB,KAAK,EAAE,EAAE,EAAE,EAAE,0BAA0B,EAAE,EAAE,EAAE,qBAAqB,EAAE,EAAE,EAAE,cAAc,EAAE;IACxF,KAAK,EAAE;QACL,KAAK,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,OAAO,EAAE;QACpD,UAAU,EAAE,IAAI;KACjB;IACD,MAAM,EAAE,uBAAuB;IAC/B,KAAK,EAAE;QACL,WAAW,EAAE,CAAC,eAAe,CAAC;KAC/B;IACD,MAAM,EAAE;QACN;YACE,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE;YAChD,IAAI,EAAE,MAAM;YACZ,QAAQ,EAAE,IAAI;YACd,SAAS,EAAE,IAAI;SAChB;QACD;YACE,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE;YACrD,IAAI,EAAE,UAAU;YAChB,QAAQ,EAAE,IAAI;YACd,SAAS,EAAE,IAAI;SAChB;KACF;CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/globals/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/globals/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @latte-macchiat-io/latte-payload
|
|
3
|
+
*
|
|
4
|
+
* Reusable Payload CMS collections, utilities, and components for Latte projects
|
|
5
|
+
*/
|
|
6
|
+
export * from './collections';
|
|
7
|
+
export * from './globals';
|
|
8
|
+
export * from './access';
|
|
9
|
+
export * from './tasks';
|
|
10
|
+
export * from './utils';
|
|
11
|
+
export * from './components';
|
|
12
|
+
export * from './types';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,eAAe,CAAC;AAG9B,cAAc,WAAW,CAAC;AAG1B,cAAc,UAAU,CAAC;AAGzB,cAAc,SAAS,CAAC;AAGxB,cAAc,SAAS,CAAC;AAGxB,cAAc,cAAc,CAAC;AAG7B,cAAc,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @latte-macchiat-io/latte-payload
|
|
3
|
+
*
|
|
4
|
+
* Reusable Payload CMS collections, utilities, and components for Latte projects
|
|
5
|
+
*/
|
|
6
|
+
// Collections
|
|
7
|
+
export * from './collections';
|
|
8
|
+
// Globals
|
|
9
|
+
export * from './globals';
|
|
10
|
+
// Access Control
|
|
11
|
+
export * from './access';
|
|
12
|
+
// Tasks
|
|
13
|
+
export * from './tasks';
|
|
14
|
+
// Utilities
|
|
15
|
+
export * from './utils';
|
|
16
|
+
// Components
|
|
17
|
+
export * from './components';
|
|
18
|
+
// Types
|
|
19
|
+
export * from './types';
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc;AACd,cAAc,eAAe,CAAC;AAE9B,UAAU;AACV,cAAc,WAAW,CAAC;AAE1B,iBAAiB;AACjB,cAAc,UAAU,CAAC;AAEzB,QAAQ;AACR,cAAc,SAAS,CAAC;AAExB,YAAY;AACZ,cAAc,SAAS,CAAC;AAExB,aAAa;AACb,cAAc,cAAc,CAAC;AAE7B,QAAQ;AACR,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tasks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,EAC3B,2BAA2B,EAC3B,qBAAqB,EACrB,8BAA8B,EAC9B,KAAK,uBAAuB,GAC7B,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tasks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,EAC3B,2BAA2B,EAC3B,qBAAqB,EACrB,8BAA8B,GAE/B,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { TaskConfig } from 'payload';
|
|
2
|
+
export declare const processEmailQueueName = "process-email-queue";
|
|
3
|
+
export declare const processEmailQueueAutoRunConfig: {
|
|
4
|
+
queue: string;
|
|
5
|
+
cron: string;
|
|
6
|
+
};
|
|
7
|
+
export interface ProcessEmailQueueConfig {
|
|
8
|
+
/**
|
|
9
|
+
* Timezone for email timestamps
|
|
10
|
+
* @default 'Europe/Brussels'
|
|
11
|
+
*/
|
|
12
|
+
timezone?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Maximum number of emails to process per run
|
|
15
|
+
* @default 100
|
|
16
|
+
*/
|
|
17
|
+
maxEmailsPerRun?: number;
|
|
18
|
+
/**
|
|
19
|
+
* Delay between sending emails in milliseconds (for rate limiting)
|
|
20
|
+
* @default 1000 (1 second - respects Resend's 2 requests/second limit)
|
|
21
|
+
*/
|
|
22
|
+
delayBetweenEmails?: number;
|
|
23
|
+
/**
|
|
24
|
+
* Default "from" email address
|
|
25
|
+
* Falls back to process.env.SMTP_FROM_ADDRESS
|
|
26
|
+
*/
|
|
27
|
+
defaultFromAddress?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Optional error reporter (e.g., Sentry)
|
|
30
|
+
*/
|
|
31
|
+
errorReporter?: {
|
|
32
|
+
captureException: (error: Error, context?: any) => void;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Create process-email-queue task with custom configuration
|
|
37
|
+
*
|
|
38
|
+
* @param config - Optional configuration
|
|
39
|
+
* @returns TaskConfig for process-email-queue
|
|
40
|
+
*/
|
|
41
|
+
export declare function createProcessEmailQueueTask(config?: ProcessEmailQueueConfig): TaskConfig<'process-email-queue'>;
|
|
42
|
+
/**
|
|
43
|
+
* Default process-email-queue task
|
|
44
|
+
*/
|
|
45
|
+
export declare const processEmailQueueTaskConfig: TaskConfig<"process-email-queue">;
|
|
46
|
+
//# sourceMappingURL=process-email-queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-email-queue.d.ts","sourceRoot":"","sources":["../../src/tasks/process-email-queue.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGrC,eAAO,MAAM,qBAAqB,wBAAwB,CAAC;AAE3D,eAAO,MAAM,8BAA8B;;;CAG1C,CAAC;AAKF,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B;;OAEG;IACH,aAAa,CAAC,EAAE;QAEd,gBAAgB,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;KACzD,CAAC;CACH;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,CAAC,EAAE,uBAAuB,GAAG,UAAU,CAAC,qBAAqB,CAAC,CAyM/G;AAED;;GAEG;AACH,eAAO,MAAM,2BAA2B,mCAAgC,CAAC"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { TZDate } from '@date-fns/tz';
|
|
2
|
+
import { toDatabaseTZDate } from '../utils';
|
|
3
|
+
export const processEmailQueueName = 'process-email-queue';
|
|
4
|
+
export const processEmailQueueAutoRunConfig = {
|
|
5
|
+
queue: processEmailQueueName,
|
|
6
|
+
cron: '* * * * *', // Every minute
|
|
7
|
+
};
|
|
8
|
+
// Utility function to add delay between emails to respect rate limits
|
|
9
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
10
|
+
/**
|
|
11
|
+
* Create process-email-queue task with custom configuration
|
|
12
|
+
*
|
|
13
|
+
* @param config - Optional configuration
|
|
14
|
+
* @returns TaskConfig for process-email-queue
|
|
15
|
+
*/
|
|
16
|
+
export function createProcessEmailQueueTask(config) {
|
|
17
|
+
const timezone = config?.timezone || 'Europe/Brussels';
|
|
18
|
+
const maxEmailsPerRun = config?.maxEmailsPerRun || 100;
|
|
19
|
+
const delayBetweenEmails = config?.delayBetweenEmails || 1000;
|
|
20
|
+
return {
|
|
21
|
+
slug: 'process-email-queue',
|
|
22
|
+
label: 'Process Email Queue',
|
|
23
|
+
retries: {
|
|
24
|
+
attempts: 3,
|
|
25
|
+
backoff: { delay: 2000, type: 'exponential' },
|
|
26
|
+
},
|
|
27
|
+
inputSchema: undefined, // No input - auto-triggered by cron
|
|
28
|
+
outputSchema: [
|
|
29
|
+
{
|
|
30
|
+
name: 'processedCount',
|
|
31
|
+
type: 'number',
|
|
32
|
+
required: true,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'sentCount',
|
|
36
|
+
type: 'number',
|
|
37
|
+
required: true,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: 'failedCount',
|
|
41
|
+
type: 'number',
|
|
42
|
+
required: true,
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
// Auto-enqueue to run following the cron schedule
|
|
46
|
+
schedule: [
|
|
47
|
+
{
|
|
48
|
+
queue: processEmailQueueAutoRunConfig.queue,
|
|
49
|
+
cron: processEmailQueueAutoRunConfig.cron,
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
handler: async ({ req }) => {
|
|
53
|
+
const { payload } = req;
|
|
54
|
+
payload.logger.info(`[(Task)ProcessEmailQueue] Task started`);
|
|
55
|
+
let processedCount = 0;
|
|
56
|
+
let sentCount = 0;
|
|
57
|
+
let failedCount = 0;
|
|
58
|
+
try {
|
|
59
|
+
// Find all emails that need to be sent (pending or failed with retries remaining)
|
|
60
|
+
// Note: We can't directly compare attemptCount < maxAttempts in the query,
|
|
61
|
+
// so we fetch all pending/failed emails and filter them in code
|
|
62
|
+
const allPendingOrFailed = await payload.find({
|
|
63
|
+
collection: 'queued-emails',
|
|
64
|
+
where: {
|
|
65
|
+
or: [
|
|
66
|
+
{
|
|
67
|
+
status: { equals: 'pending' },
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
status: { equals: 'failed' },
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
sort: 'createdAt', // Process oldest emails first
|
|
75
|
+
limit: 200, // Fetch more to filter down to maxEmailsPerRun eligible
|
|
76
|
+
pagination: false,
|
|
77
|
+
});
|
|
78
|
+
// Filter emails that still have retries remaining
|
|
79
|
+
const emailsToSend = {
|
|
80
|
+
docs: allPendingOrFailed.docs.filter((email) => email.attemptCount < email.maxAttempts).slice(0, maxEmailsPerRun),
|
|
81
|
+
};
|
|
82
|
+
payload.logger.info(`[(Task)ProcessEmailQueue] Found ${emailsToSend.docs.length} emails to process`);
|
|
83
|
+
if (emailsToSend.docs.length === 0) {
|
|
84
|
+
return {
|
|
85
|
+
output: {
|
|
86
|
+
processedCount: 0,
|
|
87
|
+
sentCount: 0,
|
|
88
|
+
failedCount: 0,
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
// Process each email
|
|
93
|
+
for (const email of emailsToSend.docs) {
|
|
94
|
+
processedCount++;
|
|
95
|
+
try {
|
|
96
|
+
payload.logger.info(`[(Task)ProcessEmailQueue] Processing email ${email.id} (${email.code}) to ${email.recipient} (attempt ${email.attemptCount + 1}/${email.maxAttempts})`);
|
|
97
|
+
// Mark as sending to prevent duplicate processing
|
|
98
|
+
await payload.update({
|
|
99
|
+
collection: 'queued-emails',
|
|
100
|
+
id: email.id,
|
|
101
|
+
data: {
|
|
102
|
+
status: 'sending',
|
|
103
|
+
lastAttemptAt: toDatabaseTZDate(TZDate.tz(timezone)),
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
// Parse CC if it exists
|
|
107
|
+
const ccArray = email.cc ? email.cc.split(',').map((e) => e.trim()) : undefined;
|
|
108
|
+
const fromAddress = config?.defaultFromAddress || process.env.SMTP_FROM_ADDRESS;
|
|
109
|
+
// Send the email using Payload's email service
|
|
110
|
+
await payload.sendEmail({
|
|
111
|
+
from: fromAddress,
|
|
112
|
+
to: email.recipient,
|
|
113
|
+
cc: ccArray,
|
|
114
|
+
subject: email.subject,
|
|
115
|
+
html: email.htmlBody,
|
|
116
|
+
});
|
|
117
|
+
// Mark as sent
|
|
118
|
+
await payload.update({
|
|
119
|
+
collection: 'queued-emails',
|
|
120
|
+
id: email.id,
|
|
121
|
+
data: {
|
|
122
|
+
status: 'sent',
|
|
123
|
+
sentAt: toDatabaseTZDate(TZDate.tz(timezone)),
|
|
124
|
+
attemptCount: email.attemptCount + 1,
|
|
125
|
+
lastError: null,
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
sentCount++;
|
|
129
|
+
payload.logger.info(`[(Task)ProcessEmailQueue] Successfully sent email ${email.id} to ${email.recipient}`);
|
|
130
|
+
// Add delay between emails to respect rate limits
|
|
131
|
+
// Only delay if there are more emails to process
|
|
132
|
+
if (processedCount < emailsToSend.docs.length) {
|
|
133
|
+
await sleep(delayBetweenEmails);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
failedCount++;
|
|
138
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
139
|
+
const now = toDatabaseTZDate(TZDate.tz(timezone));
|
|
140
|
+
const newAttemptCount = email.attemptCount + 1;
|
|
141
|
+
payload.logger.error(`[(Task)ProcessEmailQueue] Failed to send email ${email.id} to ${email.recipient}: ${errorMessage}`);
|
|
142
|
+
// Append to error history
|
|
143
|
+
const errorHistory = email.errorHistory || [];
|
|
144
|
+
errorHistory.push({
|
|
145
|
+
timestamp: now,
|
|
146
|
+
timestamp_tz: timezone,
|
|
147
|
+
attemptNumber: newAttemptCount,
|
|
148
|
+
error: errorMessage,
|
|
149
|
+
});
|
|
150
|
+
// Update email status to failed with error message
|
|
151
|
+
await payload.update({
|
|
152
|
+
collection: 'queued-emails',
|
|
153
|
+
id: email.id,
|
|
154
|
+
data: {
|
|
155
|
+
status: 'failed',
|
|
156
|
+
attemptCount: newAttemptCount,
|
|
157
|
+
lastError: errorMessage,
|
|
158
|
+
lastAttemptAt: now,
|
|
159
|
+
errorHistory: errorHistory,
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
// Report to error tracker if configured
|
|
163
|
+
if (config?.errorReporter && error instanceof Error) {
|
|
164
|
+
config.errorReporter.captureException(error, {
|
|
165
|
+
extra: {
|
|
166
|
+
emailId: email.id,
|
|
167
|
+
emailCode: email.code,
|
|
168
|
+
recipient: email.recipient,
|
|
169
|
+
attemptCount: newAttemptCount,
|
|
170
|
+
maxAttempts: email.maxAttempts,
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
payload.logger.info(`[(Task)ProcessEmailQueue] Task completed - Processed: ${processedCount}, Sent: ${sentCount}, Failed: ${failedCount}`);
|
|
177
|
+
return {
|
|
178
|
+
output: {
|
|
179
|
+
processedCount,
|
|
180
|
+
sentCount,
|
|
181
|
+
failedCount,
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
payload.logger.error(`[(Task)ProcessEmailQueue] Critical error: ${error}`);
|
|
187
|
+
if (config?.errorReporter && error instanceof Error) {
|
|
188
|
+
config.errorReporter.captureException(error);
|
|
189
|
+
}
|
|
190
|
+
throw error;
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Default process-email-queue task
|
|
197
|
+
*/
|
|
198
|
+
export const processEmailQueueTaskConfig = createProcessEmailQueueTask();
|
|
199
|
+
//# sourceMappingURL=process-email-queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-email-queue.js","sourceRoot":"","sources":["../../src/tasks/process-email-queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C,MAAM,CAAC,MAAM,qBAAqB,GAAG,qBAAqB,CAAC;AAE3D,MAAM,CAAC,MAAM,8BAA8B,GAAG;IAC5C,KAAK,EAAE,qBAAqB;IAC5B,IAAI,EAAE,WAAW,EAAE,eAAe;CACnC,CAAC;AAEF,sEAAsE;AACtE,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAoChF;;;;;GAKG;AACH,MAAM,UAAU,2BAA2B,CAAC,MAAgC;IAC1E,MAAM,QAAQ,GAAG,MAAM,EAAE,QAAQ,IAAI,iBAAiB,CAAC;IACvD,MAAM,eAAe,GAAG,MAAM,EAAE,eAAe,IAAI,GAAG,CAAC;IACvD,MAAM,kBAAkB,GAAG,MAAM,EAAE,kBAAkB,IAAI,IAAI,CAAC;I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KAAK,CAAC,SAAS;oCAC1B,YAAY,EAAE,eAAe;oCAC7B,WAAW,EAAE,KAAK,CAAC,WAAW;iCAC/B;6BACF,CAAC,CAAC;wBACL,CAAC;oBACH,CAAC;gBACH,CAAC;gBAED,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,yDAAyD,cAAc,WAAW,SAAS,aAAa,WAAW,EAAE,CAAC,CAAC;gBAE3I,OAAO;oBACL,MAAM,EAAE;wBACN,cAAc;wBACd,SAAS;wBACT,WAAW;qBACZ;iBACF,CAAC;YACJ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,6CAA6C,KAAK,EAAE,CAAC,CAAC;gBAC3E,IAAI,MAAM,EAAE,aAAa,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;oBACpD,MAAM,CAAC,aAAa,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;gBAC/C,CAAC;gBACD,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,2BAA2B,EAAE,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supported locales for the Latte Payload package
|
|
3
|
+
* Extend this type if you need additional locales
|
|
4
|
+
*/
|
|
5
|
+
export type Locale = 'en' | 'fr' | 'nl';
|
|
6
|
+
/**
|
|
7
|
+
* Email template codes
|
|
8
|
+
*/
|
|
9
|
+
export type EmailTemplateCode = 'verify-email' | 'password-lost' | string;
|
|
10
|
+
/**
|
|
11
|
+
* Queued email status
|
|
12
|
+
*/
|
|
13
|
+
export type QueuedEmailStatus = 'pending' | 'sending' | 'sent' | 'failed';
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,MAAM,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAExC;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,cAAc,GAAG,eAAe,GAAG,MAAM,CAAC;AAE1E;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slug.d.ts","sourceRoot":"","sources":["../../src/types/slug.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,SAAS,4BAOpB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { slugField as payLoadSlugField } from 'payload';
|
|
2
|
+
import { slugify } from '../utils/slugify';
|
|
3
|
+
export const slugField = payLoadSlugField({
|
|
4
|
+
name: 'slug',
|
|
5
|
+
useAsSlug: 'name',
|
|
6
|
+
position: 'sidebar',
|
|
7
|
+
required: true,
|
|
8
|
+
localized: true,
|
|
9
|
+
slugify: ({ valueToSlugify, req }) => slugify(valueToSlugify, { locale: req.locale ?? undefined }),
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=slug.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slug.js","sourceRoot":"","sources":["../../src/types/slug.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,gBAAgB,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,MAAM,CAAC,MAAM,SAAS,GAAG,gBAAgB,CAAC;IACxC,IAAI,EAAE,MAAM;IACZ,SAAS,EAAE,MAAM;IACjB,QAAQ,EAAE,SAAS;IACnB,QAAQ,EAAE,IAAI;IACd,SAAS,EAAE,IAAI;IACf,OAAO,EAAE,CAAC,EAAE,cAAc,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;CACnG,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database-dates.d.ts","sourceRoot":"","sources":["../../src/utils/database-dates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAG9D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database-dates.js","sourceRoot":"","sources":["../../src/utils/database-dates.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,gBAAgB,CAAC,IAAqB;IACpD,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC1C,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;AAC5B,CAAC"}
|