@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.
Files changed (253) hide show
  1. package/.claude/settings.local.json +9 -0
  2. package/.env.example +29 -0
  3. package/.github/workflows/ci.yml +160 -0
  4. package/.github/workflows/publish.yml +126 -0
  5. package/.nvmrc +1 -0
  6. package/.prettierignore +2 -0
  7. package/.prettierrc +11 -0
  8. package/CHANGELOG.md +87 -0
  9. package/README.md +364 -0
  10. package/TESTING_AND_DOCUMENTATION_SETUP.md +348 -0
  11. package/dist/access/adminAccessOnly.d.ts +25 -0
  12. package/dist/access/adminAccessOnly.d.ts.map +1 -0
  13. package/dist/access/adminAccessOnly.js +11 -0
  14. package/dist/access/adminAccessOnly.js.map +1 -0
  15. package/dist/access/admins.d.ts +72 -0
  16. package/dist/access/admins.d.ts.map +1 -0
  17. package/dist/access/admins.js +76 -0
  18. package/dist/access/admins.js.map +1 -0
  19. package/dist/access/anyone.d.ts +35 -0
  20. package/dist/access/anyone.d.ts.map +1 -0
  21. package/dist/access/anyone.js +34 -0
  22. package/dist/access/anyone.js.map +1 -0
  23. package/dist/access/authenticated.d.ts +63 -0
  24. package/dist/access/authenticated.d.ts.map +1 -0
  25. package/dist/access/authenticated.js +68 -0
  26. package/dist/access/authenticated.js.map +1 -0
  27. package/dist/access/authenticatedAccessOnly.d.ts +13 -0
  28. package/dist/access/authenticatedAccessOnly.d.ts.map +1 -0
  29. package/dist/access/authenticatedAccessOnly.js +11 -0
  30. package/dist/access/authenticatedAccessOnly.js.map +1 -0
  31. package/dist/access/index.d.ts +7 -0
  32. package/dist/access/index.d.ts.map +1 -0
  33. package/dist/access/index.js +7 -0
  34. package/dist/access/index.js.map +1 -0
  35. package/dist/access/publicReadAuthenticatedAccess.d.ts +13 -0
  36. package/dist/access/publicReadAuthenticatedAccess.d.ts.map +1 -0
  37. package/dist/access/publicReadAuthenticatedAccess.js +12 -0
  38. package/dist/access/publicReadAuthenticatedAccess.js.map +1 -0
  39. package/dist/collections/ContactMessages/hooks/sendEmailNotification.d.ts +31 -0
  40. package/dist/collections/ContactMessages/hooks/sendEmailNotification.d.ts.map +1 -0
  41. package/dist/collections/ContactMessages/hooks/sendEmailNotification.js +29 -0
  42. package/dist/collections/ContactMessages/hooks/sendEmailNotification.js.map +1 -0
  43. package/dist/collections/ContactMessages/index.d.ts +27 -0
  44. package/dist/collections/ContactMessages/index.d.ts.map +1 -0
  45. package/dist/collections/ContactMessages/index.js +81 -0
  46. package/dist/collections/ContactMessages/index.js.map +1 -0
  47. package/dist/collections/EmailTemplates/index.d.ts +26 -0
  48. package/dist/collections/EmailTemplates/index.d.ts.map +1 -0
  49. package/dist/collections/EmailTemplates/index.js +74 -0
  50. package/dist/collections/EmailTemplates/index.js.map +1 -0
  51. package/dist/collections/Media/index.d.ts +3 -0
  52. package/dist/collections/Media/index.d.ts.map +1 -0
  53. package/dist/collections/Media/index.js +22 -0
  54. package/dist/collections/Media/index.js.map +1 -0
  55. package/dist/collections/QueuedEmails/components/HtmlViewer.d.ts +3 -0
  56. package/dist/collections/QueuedEmails/components/HtmlViewer.d.ts.map +1 -0
  57. package/dist/collections/QueuedEmails/components/HtmlViewer.js +11 -0
  58. package/dist/collections/QueuedEmails/components/HtmlViewer.js.map +1 -0
  59. package/dist/collections/QueuedEmails/components/RetryEmailButtons.d.ts +2 -0
  60. package/dist/collections/QueuedEmails/components/RetryEmailButtons.d.ts.map +1 -0
  61. package/dist/collections/QueuedEmails/components/RetryEmailButtons.js +79 -0
  62. package/dist/collections/QueuedEmails/components/RetryEmailButtons.js.map +1 -0
  63. package/dist/collections/QueuedEmails/index.d.ts +3 -0
  64. package/dist/collections/QueuedEmails/index.d.ts.map +1 -0
  65. package/dist/collections/QueuedEmails/index.js +245 -0
  66. package/dist/collections/QueuedEmails/index.js.map +1 -0
  67. package/dist/collections/Users/auth-emails/forgot-password-email.d.ts +51 -0
  68. package/dist/collections/Users/auth-emails/forgot-password-email.d.ts.map +1 -0
  69. package/dist/collections/Users/auth-emails/forgot-password-email.js +90 -0
  70. package/dist/collections/Users/auth-emails/forgot-password-email.js.map +1 -0
  71. package/dist/collections/Users/auth-emails/verify-email.d.ts +51 -0
  72. package/dist/collections/Users/auth-emails/verify-email.d.ts.map +1 -0
  73. package/dist/collections/Users/auth-emails/verify-email.js +80 -0
  74. package/dist/collections/Users/auth-emails/verify-email.js.map +1 -0
  75. package/dist/collections/Users/hooks/ensureFirstUserIsAdmin.d.ts +3 -0
  76. package/dist/collections/Users/hooks/ensureFirstUserIsAdmin.d.ts.map +1 -0
  77. package/dist/collections/Users/hooks/ensureFirstUserIsAdmin.js +19 -0
  78. package/dist/collections/Users/hooks/ensureFirstUserIsAdmin.js.map +1 -0
  79. package/dist/collections/Users/index.d.ts +76 -0
  80. package/dist/collections/Users/index.d.ts.map +1 -0
  81. package/dist/collections/Users/index.js +116 -0
  82. package/dist/collections/Users/index.js.map +1 -0
  83. package/dist/collections/index.d.ts +10 -0
  84. package/dist/collections/index.d.ts.map +1 -0
  85. package/dist/collections/index.js +14 -0
  86. package/dist/collections/index.js.map +1 -0
  87. package/dist/components/index.d.ts +3 -0
  88. package/dist/components/index.d.ts.map +1 -0
  89. package/dist/components/index.js +4 -0
  90. package/dist/components/index.js.map +1 -0
  91. package/dist/forms/states.d.ts +8 -0
  92. package/dist/forms/states.d.ts.map +1 -0
  93. package/dist/forms/states.js +16 -0
  94. package/dist/forms/states.js.map +1 -0
  95. package/dist/forms/translate-errors.d.ts +8 -0
  96. package/dist/forms/translate-errors.d.ts.map +1 -0
  97. package/dist/forms/translate-errors.js +11 -0
  98. package/dist/forms/translate-errors.js.map +1 -0
  99. package/dist/forms/validators.d.ts +10 -0
  100. package/dist/forms/validators.d.ts.map +1 -0
  101. package/dist/forms/validators.js +23 -0
  102. package/dist/forms/validators.js.map +1 -0
  103. package/dist/globals/PrivacyPolicy/hooks/revalidate-cache.d.ts +2 -0
  104. package/dist/globals/PrivacyPolicy/hooks/revalidate-cache.d.ts.map +1 -0
  105. package/dist/globals/PrivacyPolicy/hooks/revalidate-cache.js +5 -0
  106. package/dist/globals/PrivacyPolicy/hooks/revalidate-cache.js.map +1 -0
  107. package/dist/globals/PrivacyPolicy/index.d.ts +3 -0
  108. package/dist/globals/PrivacyPolicy/index.d.ts.map +1 -0
  109. package/dist/globals/PrivacyPolicy/index.js +31 -0
  110. package/dist/globals/PrivacyPolicy/index.js.map +1 -0
  111. package/dist/globals/TermsOfUse/hooks/revalidate-cache.d.ts +2 -0
  112. package/dist/globals/TermsOfUse/hooks/revalidate-cache.d.ts.map +1 -0
  113. package/dist/globals/TermsOfUse/hooks/revalidate-cache.js +5 -0
  114. package/dist/globals/TermsOfUse/hooks/revalidate-cache.js.map +1 -0
  115. package/dist/globals/TermsOfUse/index.d.ts +3 -0
  116. package/dist/globals/TermsOfUse/index.d.ts.map +1 -0
  117. package/dist/globals/TermsOfUse/index.js +31 -0
  118. package/dist/globals/TermsOfUse/index.js.map +1 -0
  119. package/dist/globals/index.d.ts +3 -0
  120. package/dist/globals/index.d.ts.map +1 -0
  121. package/dist/globals/index.js +3 -0
  122. package/dist/globals/index.js.map +1 -0
  123. package/dist/index.d.ts +13 -0
  124. package/dist/index.d.ts.map +1 -0
  125. package/dist/index.js +20 -0
  126. package/dist/index.js.map +1 -0
  127. package/dist/tasks/index.d.ts +2 -0
  128. package/dist/tasks/index.d.ts.map +1 -0
  129. package/dist/tasks/index.js +2 -0
  130. package/dist/tasks/index.js.map +1 -0
  131. package/dist/tasks/process-email-queue.d.ts +46 -0
  132. package/dist/tasks/process-email-queue.d.ts.map +1 -0
  133. package/dist/tasks/process-email-queue.js +199 -0
  134. package/dist/tasks/process-email-queue.js.map +1 -0
  135. package/dist/types/index.d.ts +14 -0
  136. package/dist/types/index.d.ts.map +1 -0
  137. package/dist/types/index.js +2 -0
  138. package/dist/types/index.js.map +1 -0
  139. package/dist/types/slug.d.ts +2 -0
  140. package/dist/types/slug.d.ts.map +1 -0
  141. package/dist/types/slug.js +11 -0
  142. package/dist/types/slug.js.map +1 -0
  143. package/dist/utils/database-dates.d.ts +3 -0
  144. package/dist/utils/database-dates.d.ts.map +1 -0
  145. package/dist/utils/database-dates.js +6 -0
  146. package/dist/utils/database-dates.js.map +1 -0
  147. package/dist/utils/email/generate-email-html.d.ts +23 -0
  148. package/dist/utils/email/generate-email-html.d.ts.map +1 -0
  149. package/dist/utils/email/generate-email-html.js +42 -0
  150. package/dist/utils/email/generate-email-html.js.map +1 -0
  151. package/dist/utils/email/get-email-template.d.ts +8 -0
  152. package/dist/utils/email/get-email-template.d.ts.map +1 -0
  153. package/dist/utils/email/get-email-template.js +14 -0
  154. package/dist/utils/email/get-email-template.js.map +1 -0
  155. package/dist/utils/email/index.d.ts +4 -0
  156. package/dist/utils/email/index.d.ts.map +1 -0
  157. package/dist/utils/email/index.js +4 -0
  158. package/dist/utils/email/index.js.map +1 -0
  159. package/dist/utils/email/queue-email.d.ts +29 -0
  160. package/dist/utils/email/queue-email.d.ts.map +1 -0
  161. package/dist/utils/email/queue-email.js +79 -0
  162. package/dist/utils/email/queue-email.js.map +1 -0
  163. package/dist/utils/get-global.d.ts +6 -0
  164. package/dist/utils/get-global.d.ts.map +1 -0
  165. package/dist/utils/get-global.js +20 -0
  166. package/dist/utils/get-global.js.map +1 -0
  167. package/dist/utils/id-from-payload.d.ts +4 -0
  168. package/dist/utils/id-from-payload.d.ts.map +1 -0
  169. package/dist/utils/id-from-payload.js +10 -0
  170. package/dist/utils/id-from-payload.js.map +1 -0
  171. package/dist/utils/index.d.ts +4 -0
  172. package/dist/utils/index.d.ts.map +1 -0
  173. package/dist/utils/index.js +4 -0
  174. package/dist/utils/index.js.map +1 -0
  175. package/dist/utils/migrations.d.ts +2 -0
  176. package/dist/utils/migrations.d.ts.map +1 -0
  177. package/dist/utils/migrations.js +18 -0
  178. package/dist/utils/migrations.js.map +1 -0
  179. package/dist/utils/payload-client.d.ts +10 -0
  180. package/dist/utils/payload-client.d.ts.map +1 -0
  181. package/dist/utils/payload-client.js +14 -0
  182. package/dist/utils/payload-client.js.map +1 -0
  183. package/dist/utils/slugify.d.ts +8 -0
  184. package/dist/utils/slugify.d.ts.map +1 -0
  185. package/dist/utils/slugify.js +15 -0
  186. package/dist/utils/slugify.js.map +1 -0
  187. package/eslint.config.mjs +90 -0
  188. package/package.json +139 -0
  189. package/pnpm-workspace.yaml +4 -0
  190. package/src/access/adminAccessOnly.ts +13 -0
  191. package/src/access/admins.ts +78 -0
  192. package/src/access/anyone.ts +35 -0
  193. package/src/access/authenticated.ts +70 -0
  194. package/src/access/authenticatedAccessOnly.ts +13 -0
  195. package/src/access/index.ts +6 -0
  196. package/src/access/publicReadAuthenticatedAccess.ts +14 -0
  197. package/src/collections/ContactMessages/hooks/sendEmailNotification.ts +58 -0
  198. package/src/collections/ContactMessages/index.ts +100 -0
  199. package/src/collections/EmailTemplates/index.ts +89 -0
  200. package/src/collections/Media/index.ts +24 -0
  201. package/src/collections/QueuedEmails/components/HtmlViewer.tsx +16 -0
  202. package/src/collections/QueuedEmails/components/RetryEmailButtons.tsx +115 -0
  203. package/src/collections/QueuedEmails/index.ts +246 -0
  204. package/src/collections/Users/auth-emails/forgot-password-email.ts +135 -0
  205. package/src/collections/Users/auth-emails/verify-email.ts +123 -0
  206. package/src/collections/Users/hooks/ensureFirstUserIsAdmin.ts +22 -0
  207. package/src/collections/Users/index.ts +201 -0
  208. package/src/collections/index.ts +23 -0
  209. package/src/components/index.ts +3 -0
  210. package/src/forms/states.ts +23 -0
  211. package/src/forms/translate-errors.ts +13 -0
  212. package/src/forms/validators.ts +33 -0
  213. package/src/globals/PrivacyPolicy/hooks/revalidate-cache.ts +5 -0
  214. package/src/globals/PrivacyPolicy/index.ts +33 -0
  215. package/src/globals/TermsOfUse/hooks/revalidate-cache.ts +5 -0
  216. package/src/globals/TermsOfUse/index.ts +33 -0
  217. package/src/globals/index.ts +2 -0
  218. package/src/index.ts +26 -0
  219. package/src/tasks/index.ts +7 -0
  220. package/src/tasks/process-email-queue.ts +261 -0
  221. package/src/types/index.ts +15 -0
  222. package/src/types/slug.ts +11 -0
  223. package/src/utils/database-dates.ts +6 -0
  224. package/src/utils/email/generate-email-html.ts +63 -0
  225. package/src/utils/email/get-email-template.ts +18 -0
  226. package/src/utils/email/index.ts +3 -0
  227. package/src/utils/email/queue-email.ts +109 -0
  228. package/src/utils/get-global.ts +25 -0
  229. package/src/utils/id-from-payload.ts +11 -0
  230. package/src/utils/index.ts +3 -0
  231. package/src/utils/migrations.ts +18 -0
  232. package/src/utils/payload-client.ts +16 -0
  233. package/src/utils/slugify.ts +21 -0
  234. package/tests/fixtures/email-template.html +58 -0
  235. package/tests/fixtures/sample-data.ts +56 -0
  236. package/tests/helpers/create-test-user.ts +37 -0
  237. package/tests/helpers/init-payload.ts +59 -0
  238. package/tests/setup.integration.ts +9 -0
  239. package/tests/setup.ts +4 -0
  240. package/tests/unit/access/adminAccessOnly.spec.ts +117 -0
  241. package/tests/unit/access/admins.spec.ts +68 -0
  242. package/tests/unit/access/anyone.spec.ts +28 -0
  243. package/tests/unit/access/authenticated.spec.ts +53 -0
  244. package/tests/unit/access/authenticatedAccessOnly.spec.ts +112 -0
  245. package/tests/unit/access/publicReadAuthenticatedAccess.spec.ts +112 -0
  246. package/tests/unit/forms/validators.spec.ts +348 -0
  247. package/tests/unit/utils/database-dates.spec.ts +97 -0
  248. package/tests/unit/utils/id-from-payload.spec.ts +142 -0
  249. package/tests/unit/utils/slugify.spec.ts +185 -0
  250. package/tsconfig.json +31 -0
  251. package/typedoc.json +40 -0
  252. package/vitest.config.ts +31 -0
  253. package/vitest.integration.config.ts +27 -0
@@ -0,0 +1,23 @@
1
+ import { BasePayload } from 'payload';
2
+ import { EmailTemplateCode, Locale } from '../../types';
3
+ /**
4
+ * Generate email HTML from a template stored in the database
5
+ *
6
+ * @param payload - Payload instance
7
+ * @param emailCode - Email template code
8
+ * @param variables - Variables to replace in the template (e.g., { name: 'John', url: 'https://...' })
9
+ * @param locale - Locale for the email
10
+ * @param emailTemplateHtmlPath - Optional path to the HTML template file (default: './emails/template.html')
11
+ * @returns Object with subject and body HTML
12
+ */
13
+ export declare function generateEmailHtmlFromTemplate({ payload, emailCode, variables, locale, emailTemplateHtmlPath, }: {
14
+ payload: BasePayload;
15
+ emailCode: EmailTemplateCode;
16
+ variables: Record<string, string>;
17
+ locale: Locale;
18
+ emailTemplateHtmlPath?: string;
19
+ }): Promise<{
20
+ subject: string;
21
+ body: string;
22
+ } | undefined>;
23
+ //# sourceMappingURL=generate-email-html.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-email-html.d.ts","sourceRoot":"","sources":["../../../src/utils/email/generate-email-html.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAItC,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAExD;;;;;;;;;GASG;AACH,wBAAsB,6BAA6B,CAAC,EAClD,OAAO,EACP,SAAS,EACT,SAAS,EACT,MAAM,EACN,qBAAgD,GACjD,EAAE;IACD,OAAO,EAAE,WAAW,CAAC;IACrB,SAAS,EAAE,iBAAiB,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAAC,CA+BzD"}
@@ -0,0 +1,42 @@
1
+ 'use server';
2
+ import { convertLexicalToHTML } from '@payloadcms/richtext-lexical/html';
3
+ import fs from 'node:fs';
4
+ import path from 'path';
5
+ import { getEmailTemplateByCode } from './get-email-template';
6
+ /**
7
+ * Generate email HTML from a template stored in the database
8
+ *
9
+ * @param payload - Payload instance
10
+ * @param emailCode - Email template code
11
+ * @param variables - Variables to replace in the template (e.g., { name: 'John', url: 'https://...' })
12
+ * @param locale - Locale for the email
13
+ * @param emailTemplateHtmlPath - Optional path to the HTML template file (default: './emails/template.html')
14
+ * @returns Object with subject and body HTML
15
+ */
16
+ export async function generateEmailHtmlFromTemplate({ payload, emailCode, variables, locale, emailTemplateHtmlPath = './emails/template.html', }) {
17
+ const emailTemplate = fs.readFileSync(path.resolve(emailTemplateHtmlPath), 'utf8');
18
+ const templateContent = await getEmailTemplateByCode({
19
+ locale: locale,
20
+ code: emailCode,
21
+ payload: payload,
22
+ });
23
+ if (!templateContent) {
24
+ payload.logger.error(`Email template with code ${emailCode} not found`);
25
+ return;
26
+ }
27
+ const emailContentAsHtml = convertLexicalToHTML({ data: templateContent.body });
28
+ // Replace {{variable}} by the actual value
29
+ const emailContent = emailContentAsHtml.replaceAll(/{{\s*([^}]+)\s*}}/g, (_match, p1) => variables[p1]);
30
+ // Quick fix to replace clickable links {escapeHTML(node.url)} with the variable url value
31
+ // This is a workaround until we have a better solution to handle links in emails
32
+ // TODO check if still needed after Payload CMS Rich Text Editor improvements
33
+ const emailContentWithLinks = emailContent.replace(/href={escapeHTML\(node\.(\w+)\)}/g, (_match, p1) => `href="${variables[p1]}"`);
34
+ const finalEmailBody = emailTemplate
35
+ .replaceAll('{{ emailContent }}', emailContentWithLinks)
36
+ .replaceAll('{{ emailSubject }}', templateContent.subject);
37
+ return {
38
+ subject: templateContent.subject,
39
+ body: finalEmailBody,
40
+ };
41
+ }
42
+ //# sourceMappingURL=generate-email-html.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-email-html.js","sourceRoot":"","sources":["../../../src/utils/email/generate-email-html.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAEzE,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAG9D;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,6BAA6B,CAAC,EAClD,OAAO,EACP,SAAS,EACT,SAAS,EACT,MAAM,EACN,qBAAqB,GAAG,wBAAwB,GAOjD;IACC,MAAM,aAAa,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,EAAE,MAAM,CAAC,CAAC;IAEnF,MAAM,eAAe,GAAG,MAAM,sBAAsB,CAAC;QACnD,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,OAAO;KACjB,CAAC,CAAC;IAEH,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,4BAA4B,SAAS,YAAY,CAAC,CAAC;QACxE,OAAO;IACT,CAAC;IACD,MAAM,kBAAkB,GAAG,oBAAoB,CAAC,EAAE,IAAI,EAAE,eAAe,CAAC,IAAI,EAAE,CAAC,CAAC;IAEhF,2CAA2C;IAC3C,MAAM,YAAY,GAAG,kBAAkB,CAAC,UAAU,CAAC,oBAAoB,EAAE,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;IAExG,0FAA0F;IAC1F,iFAAiF;IACjF,6EAA6E;IAC7E,MAAM,qBAAqB,GAAG,YAAY,CAAC,OAAO,CAAC,mCAAmC,EAAE,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE,CAAC,SAAS,SAAS,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IAEnI,MAAM,cAAc,GAAG,aAAa;SACjC,UAAU,CAAC,oBAAoB,EAAE,qBAAqB,CAAC;SACvD,UAAU,CAAC,oBAAoB,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;IAE7D,OAAO;QACL,OAAO,EAAE,eAAe,CAAC,OAAO;QAChC,IAAI,EAAE,cAAc;KACrB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { BasePayload } from 'payload';
2
+ import { Locale } from '../../types';
3
+ export declare function getEmailTemplateByCode({ locale, code, payload }: {
4
+ locale: Locale;
5
+ code: string;
6
+ payload: BasePayload;
7
+ }): Promise<(import("payload").JsonObject & import("payload").TypeWithID) | null>;
8
+ //# sourceMappingURL=get-email-template.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-email-template.d.ts","sourceRoot":"","sources":["../../../src/utils/email/get-email-template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,wBAAsB,sBAAsB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,WAAW,CAAA;CAAE,iFAc7H"}
@@ -0,0 +1,14 @@
1
+ export async function getEmailTemplateByCode({ locale, code, payload }) {
2
+ const emailContentTemplateDocs = await payload.find({
3
+ collection: 'email-templates',
4
+ where: { code: { equals: code } },
5
+ limit: 1,
6
+ locale: locale,
7
+ });
8
+ if (!emailContentTemplateDocs || emailContentTemplateDocs.totalDocs === 0) {
9
+ payload.logger.error(`Email template with code ${code} not found`);
10
+ return null;
11
+ }
12
+ return emailContentTemplateDocs.docs[0];
13
+ }
14
+ //# sourceMappingURL=get-email-template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-email-template.js","sourceRoot":"","sources":["../../../src/utils/email/get-email-template.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAA0D;IAC5H,MAAM,wBAAwB,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC;QAClD,UAAU,EAAE,iBAAiB;QAC7B,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE;QACjC,KAAK,EAAE,CAAC;QACR,MAAM,EAAE,MAAM;KACf,CAAC,CAAC;IAEH,IAAI,CAAC,wBAAwB,IAAI,wBAAwB,CAAC,SAAS,KAAK,CAAC,EAAE,CAAC;QAC1E,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,4BAA4B,IAAI,YAAY,CAAC,CAAC;QACnE,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,wBAAwB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAC1C,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { getEmailTemplateByCode } from './get-email-template';
2
+ export { generateEmailHtmlFromTemplate } from './generate-email-html';
3
+ export { queueEmail } from './queue-email';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/email/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { getEmailTemplateByCode } from './get-email-template';
2
+ export { generateEmailHtmlFromTemplate } from './generate-email-html';
3
+ export { queueEmail } from './queue-email';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/email/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { BasePayload } from 'payload';
2
+ import { EmailTemplateCode, Locale } from '../../types';
3
+ /**
4
+ * Queue an email to be sent by the email processor job.
5
+ * This function generates the email HTML from template and stores it in the queued-emails collection.
6
+ * The email will be picked up and sent by the process-email-queue job.
7
+ *
8
+ * @param payload - Payload instance
9
+ * @param to - Recipient email address
10
+ * @param cc - Optional CC email addresses
11
+ * @param emailCode - Email template code (e.g., 'verify-email', 'password-lost')
12
+ * @param variables - Variables to replace in the template
13
+ * @param locale - Locale for the email
14
+ * @param maxAttempts - Maximum number of retry attempts (default: 5)
15
+ * @param idempotencyKey - Optional unique key to prevent duplicate emails (e.g., "order-confirmation-123")
16
+ * @param emailTemplateHtmlPath - Optional path to the HTML template file (default: './emails/template.html')
17
+ */
18
+ export declare function queueEmail({ payload, to, cc, emailCode, variables, locale, maxAttempts, idempotencyKey, emailTemplateHtmlPath, }: {
19
+ payload: BasePayload;
20
+ to: string;
21
+ cc?: string[];
22
+ emailCode: EmailTemplateCode;
23
+ variables: Record<string, string>;
24
+ locale: Locale;
25
+ maxAttempts?: number;
26
+ idempotencyKey?: string;
27
+ emailTemplateHtmlPath?: string;
28
+ }): Promise<void>;
29
+ //# sourceMappingURL=queue-email.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue-email.d.ts","sourceRoot":"","sources":["../../../src/utils/email/queue-email.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAExD;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,UAAU,CAAC,EAC/B,OAAO,EACP,EAAE,EACF,EAAE,EACF,SAAS,EACT,SAAS,EACT,MAAM,EACN,WAAe,EACf,cAAc,EACd,qBAAqB,GACtB,EAAE;IACD,OAAO,EAAE,WAAW,CAAC;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC;IACd,SAAS,EAAE,iBAAiB,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC,iBAmEA"}
@@ -0,0 +1,79 @@
1
+ 'use server';
2
+ import { generateEmailHtmlFromTemplate } from './generate-email-html';
3
+ /**
4
+ * Queue an email to be sent by the email processor job.
5
+ * This function generates the email HTML from template and stores it in the queued-emails collection.
6
+ * The email will be picked up and sent by the process-email-queue job.
7
+ *
8
+ * @param payload - Payload instance
9
+ * @param to - Recipient email address
10
+ * @param cc - Optional CC email addresses
11
+ * @param emailCode - Email template code (e.g., 'verify-email', 'password-lost')
12
+ * @param variables - Variables to replace in the template
13
+ * @param locale - Locale for the email
14
+ * @param maxAttempts - Maximum number of retry attempts (default: 5)
15
+ * @param idempotencyKey - Optional unique key to prevent duplicate emails (e.g., "order-confirmation-123")
16
+ * @param emailTemplateHtmlPath - Optional path to the HTML template file (default: './emails/template.html')
17
+ */
18
+ export async function queueEmail({ payload, to, cc, emailCode, variables, locale, maxAttempts = 5, idempotencyKey, emailTemplateHtmlPath, }) {
19
+ try {
20
+ // Check for existing email with the same idempotency key (if provided)
21
+ if (idempotencyKey) {
22
+ const existingEmails = await payload.find({
23
+ collection: 'queued-emails',
24
+ where: {
25
+ idempotencyKey: { equals: idempotencyKey },
26
+ },
27
+ limit: 1,
28
+ });
29
+ if (existingEmails.docs.length > 0) {
30
+ const existingEmail = existingEmails.docs[0];
31
+ // If email is pending, sending, or sent, skip creating a duplicate
32
+ if (existingEmail.status === 'pending' || existingEmail.status === 'sending' || existingEmail.status === 'sent') {
33
+ payload.logger.info(`Email ${emailCode} with idempotency key "${idempotencyKey}" already exists (status: ${existingEmail.status}). Skipping duplicate.`);
34
+ return;
35
+ }
36
+ // If email failed, we'll allow retry by creating a new one (old one stays for debugging)
37
+ payload.logger.info(`Email ${emailCode} with idempotency key "${idempotencyKey}" previously failed. Creating new attempt.`);
38
+ }
39
+ }
40
+ // Generate the email content from template
41
+ const emailContent = await generateEmailHtmlFromTemplate({
42
+ emailCode: emailCode,
43
+ locale: locale,
44
+ payload: payload,
45
+ variables: variables,
46
+ emailTemplateHtmlPath,
47
+ });
48
+ if (!emailContent) {
49
+ const error = `Email template with code ${emailCode} not found`;
50
+ payload.logger.error(error);
51
+ throw new Error(error);
52
+ }
53
+ payload.logger.info(`Queueing email ${emailCode} to ${to} with subject "${emailContent.subject}"`);
54
+ // Create a record in the queued-emails collection
55
+ await payload.create({
56
+ collection: 'queued-emails',
57
+ data: {
58
+ idempotencyKey: idempotencyKey || null,
59
+ status: 'pending',
60
+ code: emailCode,
61
+ recipient: to,
62
+ cc: cc?.join(', '),
63
+ subject: emailContent.subject,
64
+ htmlBody: emailContent.body,
65
+ attemptCount: 0,
66
+ maxAttempts: maxAttempts,
67
+ lastAttemptAt: null,
68
+ sentAt: null,
69
+ lastError: null,
70
+ },
71
+ });
72
+ payload.logger.info(`Email ${emailCode} queued successfully for ${to}`);
73
+ }
74
+ catch (error) {
75
+ payload.logger.error(`Error queueing email ${emailCode} to ${to}: ${error}`);
76
+ throw error;
77
+ }
78
+ }
79
+ //# sourceMappingURL=queue-email.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue-email.js","sourceRoot":"","sources":["../../../src/utils/email/queue-email.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAGb,OAAO,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAC;AAGtE;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,EAC/B,OAAO,EACP,EAAE,EACF,EAAE,EACF,SAAS,EACT,SAAS,EACT,MAAM,EACN,WAAW,GAAG,CAAC,EACf,cAAc,EACd,qBAAqB,GAWtB;IACC,IAAI,CAAC;QACH,uEAAuE;QACvE,IAAI,cAAc,EAAE,CAAC;YACnB,MAAM,cAAc,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC;gBACxC,UAAU,EAAE,eAAe;gBAC3B,KAAK,EAAE;oBACL,cAAc,EAAE,EAAE,MAAM,EAAE,cAAc,EAAE;iBAC3C;gBACD,KAAK,EAAE,CAAC;aACT,CAAC,CAAC;YAEH,IAAI,cAAc,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACnC,MAAM,aAAa,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;gBAC7C,mEAAmE;gBACnE,IAAI,aAAa,CAAC,MAAM,KAAK,SAAS,IAAI,aAAa,CAAC,MAAM,KAAK,SAAS,IAAI,aAAa,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;oBAChH,OAAO,CAAC,MAAM,CAAC,IAAI,CACjB,SAAS,SAAS,0BAA0B,cAAc,6BAA6B,aAAa,CAAC,MAAM,wBAAwB,CACpI,CAAC;oBACF,OAAO;gBACT,CAAC;gBACD,yFAAyF;gBACzF,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,SAAS,0BAA0B,cAAc,4CAA4C,CAAC,CAAC;YAC9H,CAAC;QACH,CAAC;QAED,2CAA2C;QAC3C,MAAM,YAAY,GAAG,MAAM,6BAA6B,CAAC;YACvD,SAAS,EAAE,SAAS;YACpB,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,OAAO;YAChB,SAAS,EAAE,SAAS;YACpB,qBAAqB;SACtB,CAAC,CAAC;QAEH,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,MAAM,KAAK,GAAG,4BAA4B,SAAS,YAAY,CAAC;YAChE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC;QACzB,CAAC;QAED,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,kBAAkB,SAAS,OAAO,EAAE,kBAAkB,YAAY,CAAC,OAAO,GAAG,CAAC,CAAC;QAEnG,kDAAkD;QAClD,MAAM,OAAO,CAAC,MAAM,CAAC;YACnB,UAAU,EAAE,eAAe;YAC3B,IAAI,EAAE;gBACJ,cAAc,EAAE,cAAc,IAAI,IAAI;gBACtC,MAAM,EAAE,SAAS;gBACjB,IAAI,EAAE,SAAS;gBACf,SAAS,EAAE,EAAE;gBACb,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC;gBAClB,OAAO,EAAE,YAAY,CAAC,OAAO;gBAC7B,QAAQ,EAAE,YAAY,CAAC,IAAI;gBAC3B,YAAY,EAAE,CAAC;gBACf,WAAW,EAAE,WAAW;gBACxB,aAAa,EAAE,IAAI;gBACnB,MAAM,EAAE,IAAI;gBACZ,SAAS,EAAE,IAAI;aAChB;SACF,CAAC,CAAC;QAEH,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,SAAS,4BAA4B,EAAE,EAAE,CAAC,CAAC;IAC1E,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,wBAAwB,SAAS,OAAO,EAAE,KAAK,KAAK,EAAE,CAAC,CAAC;QAC7E,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { Config, GlobalSlug } from 'payload';
2
+ /**
3
+ * Strongly typed cached global fetcher
4
+ */
5
+ export declare function getCachedGlobal<TSlug extends GlobalSlug>(slug: TSlug, config: Promise<Config> | Config, depth?: number): Promise<unknown>;
6
+ //# sourceMappingURL=get-global.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-global.d.ts","sourceRoot":"","sources":["../../src/utils/get-global.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAYlD;;GAEG;AACH,wBAAsB,eAAe,CAAC,KAAK,SAAS,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,KAAK,SAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAM1I"}
@@ -0,0 +1,20 @@
1
+ 'use server';
2
+ import { unstable_cache } from 'next/cache';
3
+ import { getPayloadClient } from './payload-client';
4
+ async function getGlobal(slug, config, depth = 0) {
5
+ const payload = await getPayloadClient(config);
6
+ return payload.findGlobal({
7
+ slug,
8
+ depth,
9
+ });
10
+ }
11
+ /**
12
+ * Strongly typed cached global fetcher
13
+ */
14
+ export async function getCachedGlobal(slug, config, depth = 0) {
15
+ const cachedFn = unstable_cache(() => getGlobal(slug, config, depth), [slug], {
16
+ tags: [`global_${slug}`],
17
+ });
18
+ return cachedFn();
19
+ }
20
+ //# sourceMappingURL=get-global.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-global.js","sourceRoot":"","sources":["../../src/utils/get-global.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,KAAK,UAAU,SAAS,CAA2B,IAAW,EAAE,MAAgC,EAAE,KAAK,GAAG,CAAC;IACzG,MAAM,OAAO,GAAG,MAAM,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAE/C,OAAO,OAAO,CAAC,UAAU,CAAC;QACxB,IAAI;QACJ,KAAK;KACN,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAA2B,IAAW,EAAE,MAAgC,EAAE,KAAK,GAAG,CAAC;IACtH,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE;QAC5E,IAAI,EAAE,CAAC,UAAU,IAAI,EAAE,CAAC;KACzB,CAA2B,CAAC;IAE7B,OAAO,QAAQ,EAAE,CAAC;AACpB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare function getId(idOrObject: number | {
2
+ id: number;
3
+ }): number;
4
+ //# sourceMappingURL=id-from-payload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id-from-payload.d.ts","sourceRoot":"","sources":["../../src/utils/id-from-payload.ts"],"names":[],"mappings":"AAAA,wBAAgB,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAUjE"}
@@ -0,0 +1,10 @@
1
+ export function getId(idOrObject) {
2
+ if (typeof idOrObject === 'number') {
3
+ return idOrObject;
4
+ }
5
+ if (typeof idOrObject === 'object' && idOrObject !== null) {
6
+ return idOrObject.id;
7
+ }
8
+ throw new Error('Invalid ID or object');
9
+ }
10
+ //# sourceMappingURL=id-from-payload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id-from-payload.js","sourceRoot":"","sources":["../../src/utils/id-from-payload.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,KAAK,CAAC,UAAmC;IACvD,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QACnC,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;QAC1D,OAAO,UAAU,CAAC,EAAE,CAAC;IACvB,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;AAC1C,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './email';
2
+ export { toDatabaseTZDate } from './database-dates';
3
+ export { getPayloadClient } from './payload-client';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './email';
2
+ export { toDatabaseTZDate } from './database-dates';
3
+ export { getPayloadClient } from './payload-client';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const toRichText: (text: string | null) => string | null;
2
+ //# sourceMappingURL=migrations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../src/utils/migrations.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,GAAG,IAAI,kBAiBpC,CAAC"}
@@ -0,0 +1,18 @@
1
+ export const toRichText = (text) => text
2
+ ? JSON.stringify({
3
+ root: {
4
+ type: 'root',
5
+ children: [
6
+ {
7
+ type: 'paragraph',
8
+ children: [
9
+ {
10
+ text,
11
+ },
12
+ ],
13
+ },
14
+ ],
15
+ },
16
+ })
17
+ : null;
18
+ //# sourceMappingURL=migrations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrations.js","sourceRoot":"","sources":["../../src/utils/migrations.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAmB,EAAE,EAAE,CAChD,IAAI;IACF,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC;QACb,IAAI,EAAE;YACJ,IAAI,EAAE,MAAM;YACZ,QAAQ,EAAE;gBACR;oBACE,IAAI,EAAE,WAAW;oBACjB,QAAQ,EAAE;wBACR;4BACE,IAAI;yBACL;qBACF;iBACF;aACF;SACF;KACF,CAAC;IACJ,CAAC,CAAC,IAAI,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { Config } from 'payload';
2
+ /**
3
+ * Get Payload client instance
4
+ * This is a wrapper around Payload's getPayload function
5
+ *
6
+ * @param config - Your Payload configuration object
7
+ * @returns Payload client instance
8
+ */
9
+ export declare function getPayloadClient(config: Promise<Config> | Config): Promise<import("payload").BasePayload>;
10
+ //# sourceMappingURL=payload-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payload-client.d.ts","sourceRoot":"","sources":["../../src/utils/payload-client.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEtC;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,0CAGtE"}
@@ -0,0 +1,14 @@
1
+ 'use server';
2
+ import { getPayload } from 'payload';
3
+ /**
4
+ * Get Payload client instance
5
+ * This is a wrapper around Payload's getPayload function
6
+ *
7
+ * @param config - Your Payload configuration object
8
+ * @returns Payload client instance
9
+ */
10
+ export async function getPayloadClient(config) {
11
+ // @ts-expect-error - getPayload accepts Config but types show SanitizedConfig
12
+ return getPayload({ config });
13
+ }
14
+ //# sourceMappingURL=payload-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payload-client.js","sourceRoot":"","sources":["../../src/utils/payload-client.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGrC;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,MAAgC;IACrE,8EAA8E;IAC9E,OAAO,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;AAChC,CAAC"}
@@ -0,0 +1,8 @@
1
+ export declare const slugify: (val?: string, // Default to empty string if no value is provided
2
+ options?: {
3
+ trim?: boolean;
4
+ locale?: string;
5
+ lower?: boolean;
6
+ remove?: RegExp;
7
+ }) => string;
8
+ //# sourceMappingURL=slugify.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slugify.d.ts","sourceRoot":"","sources":["../../src/utils/slugify.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,OAAO,GAClB,MAAK,MAAW,EAAE,kDAAkD;AACpE,UAAS;IACP,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACa,WAShC,CAAC"}
@@ -0,0 +1,15 @@
1
+ import slugifyPlugin from 'slugify';
2
+ // Custom slugify utility with configurable options
3
+ // Default options: trimming, lowercase conversion, and removal of special characters
4
+ export const slugify = (val = '', // Default to empty string if no value is provided
5
+ options = { trim: true, lower: true } // Default options
6
+ ) => {
7
+ return slugifyPlugin(val, {
8
+ trim: options.trim ?? true, // Always trim leading/trailing spaces, fallback to true
9
+ lower: options.lower ?? true, // Always convert to lowercase, fallback to true
10
+ locale: options.locale ?? undefined, // Optional locale parameter
11
+ remove: /[*+~.()'"!:@¿¡©®—`^?;,<>/&|=#%$§]/g, // Default regex now includes "?"
12
+ ...options, // Merge provided options with defaults
13
+ });
14
+ };
15
+ //# sourceMappingURL=slugify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slugify.js","sourceRoot":"","sources":["../../src/utils/slugify.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,SAAS,CAAC;AAEpC,mDAAmD;AACnD,qFAAqF;AACrF,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,MAAc,EAAE,EAAE,kDAAkD;AACpE,UAKI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,kBAAkB;EAClD,EAAE;IACF,OAAO,aAAa,CAAC,GAAG,EAAE;QACxB,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,IAAI,EAAE,wDAAwD;QACpF,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,IAAI,EAAE,gDAAgD;QAC9E,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,SAAS,EAAE,4BAA4B;QACjE,MAAM,EAAE,oCAAoC,EAAE,iCAAiC;QAC/E,GAAG,OAAO,EAAE,uCAAuC;KACpD,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1,90 @@
1
+ import eslintPluginImport from 'eslint-plugin-import';
2
+ import jsxA11y from 'eslint-plugin-jsx-a11y';
3
+ import typescriptEslint from 'typescript-eslint';
4
+ import * as fs from 'fs';
5
+
6
+ const eslintIgnore = ['.git/', 'node_modules/', 'dist/', 'build/', 'coverage/', 'docs/', '*.min.js', '*.config.js', '*.d.ts'];
7
+
8
+ const config = typescriptEslint.config(
9
+ {
10
+ ignores: eslintIgnore,
11
+ },
12
+
13
+ typescriptEslint.configs.recommended,
14
+ jsxA11y.flatConfigs.recommended,
15
+ eslintPluginImport.flatConfigs.recommended,
16
+ {
17
+ settings: {
18
+ 'import/resolver': {
19
+ typescript: {
20
+ alwaysTryTypes: true,
21
+ project: './tsconfig.json',
22
+ },
23
+ node: true,
24
+ },
25
+ },
26
+ rules: {
27
+ '@typescript-eslint/no-unused-vars': [
28
+ 'warn',
29
+ {
30
+ argsIgnorePattern: '^_',
31
+ varsIgnorePattern: '^_',
32
+ },
33
+ ],
34
+ 'sort-imports': [
35
+ 'error',
36
+ {
37
+ ignoreCase: true,
38
+ ignoreDeclarationSort: true,
39
+ },
40
+ ],
41
+ 'import/order': [
42
+ 'warn',
43
+ {
44
+ groups: ['external', 'builtin', 'internal', 'sibling', 'parent', 'index'],
45
+ pathGroups: [
46
+ ...getDirectoriesToSort().map((singleDir) => ({
47
+ pattern: `${singleDir}/**`,
48
+ group: 'internal',
49
+ })),
50
+ {
51
+ pattern: 'env',
52
+ group: 'internal',
53
+ },
54
+ {
55
+ pattern: 'theme',
56
+ group: 'internal',
57
+ },
58
+ {
59
+ pattern: 'public/**',
60
+ group: 'internal',
61
+ position: 'after',
62
+ },
63
+ ],
64
+ pathGroupsExcludedImportTypes: ['internal'],
65
+ alphabetize: {
66
+ order: 'asc',
67
+ caseInsensitive: true,
68
+ },
69
+ },
70
+ ],
71
+ 'jsx-a11y/media-has-caption': 'off', // Media elements such as <audio> and <video> must have a <track> for captions.
72
+ },
73
+ },
74
+ {
75
+ files: ['tests/**/*.ts', 'tests/**/*.tsx', '**/*.spec.ts', '**/*.spec.tsx', '**/*.test.ts', '**/*.test.tsx'],
76
+ rules: {
77
+ '@typescript-eslint/no-explicit-any': 'off',
78
+ },
79
+ }
80
+ );
81
+
82
+ function getDirectoriesToSort() {
83
+ const ignoredSortingDirectories = ['.git', '.idea', '.vscode', 'node_modules'];
84
+ return fs
85
+ .readdirSync(process.cwd())
86
+ .filter((file) => fs.statSync(process.cwd() + '/' + file).isDirectory())
87
+ .filter((f) => !ignoredSortingDirectories.includes(f));
88
+ }
89
+
90
+ export default config;