payload-plugin-backup-postgres 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +355 -2
  3. package/dist/backup-dashboard.css +1149 -0
  4. package/dist/client.d.ts +3 -0
  5. package/dist/client.js +3 -0
  6. package/dist/client.js.map +1 -0
  7. package/dist/collections/BackupSettings.d.ts +6 -0
  8. package/dist/collections/BackupSettings.js +91 -0
  9. package/dist/collections/BackupSettings.js.map +1 -0
  10. package/dist/collections/BackupTasks.d.ts +2 -0
  11. package/dist/collections/BackupTasks.js +63 -0
  12. package/dist/collections/BackupTasks.js.map +1 -0
  13. package/dist/components/BackupDashboard/BackupItemActions.client.d.ts +7 -0
  14. package/dist/components/BackupDashboard/BackupItemActions.client.js +90 -0
  15. package/dist/components/BackupDashboard/BackupItemActions.client.js.map +1 -0
  16. package/dist/components/BackupDashboard/BackupListCollapsible.client.d.ts +16 -0
  17. package/dist/components/BackupDashboard/BackupListCollapsible.client.js +597 -0
  18. package/dist/components/BackupDashboard/BackupListCollapsible.client.js.map +1 -0
  19. package/dist/components/BackupDashboard/BackupSettingsModal.client.d.ts +2 -0
  20. package/dist/components/BackupDashboard/BackupSettingsModal.client.js +1027 -0
  21. package/dist/components/BackupDashboard/BackupSettingsModal.client.js.map +1 -0
  22. package/dist/components/BackupDashboard/CollectionBackupPreviewBody.client.d.ts +18 -0
  23. package/dist/components/BackupDashboard/CollectionBackupPreviewBody.client.js +267 -0
  24. package/dist/components/BackupDashboard/CollectionBackupPreviewBody.client.js.map +1 -0
  25. package/dist/components/BackupDashboard/ManualBackupDialog.client.d.ts +1 -0
  26. package/dist/components/BackupDashboard/ManualBackupDialog.client.js +276 -0
  27. package/dist/components/BackupDashboard/ManualBackupDialog.client.js.map +1 -0
  28. package/dist/components/BackupDashboard/RestoreBackupDialog.client.d.ts +6 -0
  29. package/dist/components/BackupDashboard/RestoreBackupDialog.client.js +551 -0
  30. package/dist/components/BackupDashboard/RestoreBackupDialog.client.js.map +1 -0
  31. package/dist/components/BackupDashboard/TaskActionButton.client.d.ts +29 -0
  32. package/dist/components/BackupDashboard/TaskActionButton.client.js +273 -0
  33. package/dist/components/BackupDashboard/TaskActionButton.client.js.map +1 -0
  34. package/dist/components/BackupDashboard/backupDashboardInlineCss.d.ts +1 -0
  35. package/dist/components/BackupDashboard/backupDashboardInlineCss.js +3 -0
  36. package/dist/components/BackupDashboard/backupDashboardInlineCss.js.map +1 -0
  37. package/dist/components/BackupDashboard/index.client.d.ts +8 -0
  38. package/dist/components/BackupDashboard/index.client.js +9 -0
  39. package/dist/components/BackupDashboard/index.client.js.map +1 -0
  40. package/dist/components/BackupDashboard/index.d.ts +15 -0
  41. package/dist/components/BackupDashboard/index.js +246 -0
  42. package/dist/components/BackupDashboard/index.js.map +1 -0
  43. package/dist/core/archive.d.ts +8 -0
  44. package/dist/core/archive.js +47 -0
  45. package/dist/core/archive.js.map +1 -0
  46. package/dist/core/backup.d.ts +54 -0
  47. package/dist/core/backup.js +282 -0
  48. package/dist/core/backup.js.map +1 -0
  49. package/dist/core/backupArchiveRead.d.ts +15 -0
  50. package/dist/core/backupArchiveRead.js +30 -0
  51. package/dist/core/backupArchiveRead.js.map +1 -0
  52. package/dist/core/backupBlobIO.d.ts +54 -0
  53. package/dist/core/backupBlobIO.js +179 -0
  54. package/dist/core/backupBlobIO.js.map +1 -0
  55. package/dist/core/backupBlobTransfer.d.ts +29 -0
  56. package/dist/core/backupBlobTransfer.js +85 -0
  57. package/dist/core/backupBlobTransfer.js.map +1 -0
  58. package/dist/core/backupSettings.d.ts +35 -0
  59. package/dist/core/backupSettings.js +100 -0
  60. package/dist/core/backupSettings.js.map +1 -0
  61. package/dist/core/backupSourcePreview.d.ts +10 -0
  62. package/dist/core/backupSourcePreview.js +46 -0
  63. package/dist/core/backupSourcePreview.js.map +1 -0
  64. package/dist/core/blobTokenValidate.d.ts +14 -0
  65. package/dist/core/blobTokenValidate.js +75 -0
  66. package/dist/core/blobTokenValidate.js.map +1 -0
  67. package/dist/core/db.d.ts +56 -0
  68. package/dist/core/db.js +161 -0
  69. package/dist/core/db.js.map +1 -0
  70. package/dist/core/pgArchive.d.ts +37 -0
  71. package/dist/core/pgArchive.js +57 -0
  72. package/dist/core/pgArchive.js.map +1 -0
  73. package/dist/core/restore.d.ts +46 -0
  74. package/dist/core/restore.js +439 -0
  75. package/dist/core/restore.js.map +1 -0
  76. package/dist/core/restorePreview.d.ts +76 -0
  77. package/dist/core/restorePreview.js +222 -0
  78. package/dist/core/restorePreview.js.map +1 -0
  79. package/dist/core/restoreResult.d.ts +34 -0
  80. package/dist/core/restoreResult.js +45 -0
  81. package/dist/core/restoreResult.js.map +1 -0
  82. package/dist/core/storage/config.d.ts +31 -0
  83. package/dist/core/storage/config.js +60 -0
  84. package/dist/core/storage/config.js.map +1 -0
  85. package/dist/core/storage/index.d.ts +23 -0
  86. package/dist/core/storage/index.js +25 -0
  87. package/dist/core/storage/index.js.map +1 -0
  88. package/dist/core/storage/s3.d.ts +35 -0
  89. package/dist/core/storage/s3.js +200 -0
  90. package/dist/core/storage/s3.js.map +1 -0
  91. package/dist/core/storage/types.d.ts +60 -0
  92. package/dist/core/storage/types.js +6 -0
  93. package/dist/core/storage/types.js.map +1 -0
  94. package/dist/core/storage/vercelBlob.d.ts +25 -0
  95. package/dist/core/storage/vercelBlob.js +53 -0
  96. package/dist/core/storage/vercelBlob.js.map +1 -0
  97. package/dist/core/tableGroups.d.ts +25 -0
  98. package/dist/core/tableGroups.js +80 -0
  99. package/dist/core/tableGroups.js.map +1 -0
  100. package/dist/core/taskProgress.d.ts +39 -0
  101. package/dist/core/taskProgress.js +104 -0
  102. package/dist/core/taskProgress.js.map +1 -0
  103. package/dist/core/vercelBackupCron.d.ts +8 -0
  104. package/dist/core/vercelBackupCron.js +38 -0
  105. package/dist/core/vercelBackupCron.js.map +1 -0
  106. package/dist/endpoints/index.d.ts +3 -0
  107. package/dist/endpoints/index.js +29 -0
  108. package/dist/endpoints/index.js.map +1 -0
  109. package/dist/endpoints/paths/admin-backup-download.d.ts +8 -0
  110. package/dist/endpoints/paths/admin-backup-download.js +73 -0
  111. package/dist/endpoints/paths/admin-backup-download.js.map +1 -0
  112. package/dist/endpoints/paths/admin-delete.d.ts +3 -0
  113. package/dist/endpoints/paths/admin-delete.js +61 -0
  114. package/dist/endpoints/paths/admin-delete.js.map +1 -0
  115. package/dist/endpoints/paths/admin-manual.d.ts +3 -0
  116. package/dist/endpoints/paths/admin-manual.js +62 -0
  117. package/dist/endpoints/paths/admin-manual.js.map +1 -0
  118. package/dist/endpoints/paths/admin-preview.d.ts +6 -0
  119. package/dist/endpoints/paths/admin-preview.js +109 -0
  120. package/dist/endpoints/paths/admin-preview.js.map +1 -0
  121. package/dist/endpoints/paths/admin-restore.d.ts +3 -0
  122. package/dist/endpoints/paths/admin-restore.js +77 -0
  123. package/dist/endpoints/paths/admin-restore.js.map +1 -0
  124. package/dist/endpoints/paths/admin-settings.d.ts +3 -0
  125. package/dist/endpoints/paths/admin-settings.js +263 -0
  126. package/dist/endpoints/paths/admin-settings.js.map +1 -0
  127. package/dist/endpoints/paths/admin-task.d.ts +3 -0
  128. package/dist/endpoints/paths/admin-task.js +34 -0
  129. package/dist/endpoints/paths/admin-task.js.map +1 -0
  130. package/dist/endpoints/paths/admin-validate-blob-token.d.ts +8 -0
  131. package/dist/endpoints/paths/admin-validate-blob-token.js +26 -0
  132. package/dist/endpoints/paths/admin-validate-blob-token.js.map +1 -0
  133. package/dist/endpoints/paths/cron-list.d.ts +2 -0
  134. package/dist/endpoints/paths/cron-list.js +34 -0
  135. package/dist/endpoints/paths/cron-list.js.map +1 -0
  136. package/dist/endpoints/paths/cron-restore.d.ts +2 -0
  137. package/dist/endpoints/paths/cron-restore.js +71 -0
  138. package/dist/endpoints/paths/cron-restore.js.map +1 -0
  139. package/dist/endpoints/paths/cron-run.d.ts +3 -0
  140. package/dist/endpoints/paths/cron-run.js +46 -0
  141. package/dist/endpoints/paths/cron-run.js.map +1 -0
  142. package/dist/endpoints/shared.d.ts +12 -0
  143. package/dist/endpoints/shared.js +52 -0
  144. package/dist/endpoints/shared.js.map +1 -0
  145. package/dist/exports/client.d.ts +1 -0
  146. package/dist/exports/client.js +3 -0
  147. package/dist/exports/client.js.map +1 -0
  148. package/dist/exports/rsc.d.ts +1 -0
  149. package/dist/exports/rsc.js +3 -0
  150. package/dist/exports/rsc.js.map +1 -0
  151. package/dist/index.d.ts +25 -0
  152. package/dist/index.js +18 -0
  153. package/dist/index.js.map +1 -0
  154. package/dist/plugin.d.ts +3 -0
  155. package/dist/plugin.js +75 -0
  156. package/dist/plugin.js.map +1 -0
  157. package/dist/publicApiPaths.d.ts +18 -0
  158. package/dist/publicApiPaths.js +19 -0
  159. package/dist/publicApiPaths.js.map +1 -0
  160. package/dist/types.d.ts +16 -0
  161. package/dist/types.js +3 -0
  162. package/dist/types.js.map +1 -0
  163. package/dist/utils/backupSelection.d.ts +6 -0
  164. package/dist/utils/backupSelection.js +16 -0
  165. package/dist/utils/backupSelection.js.map +1 -0
  166. package/dist/utils/blobName.d.ts +32 -0
  167. package/dist/utils/blobName.js +99 -0
  168. package/dist/utils/blobName.js.map +1 -0
  169. package/dist/utils/dashboardRoleAccess.d.ts +23 -0
  170. package/dist/utils/dashboardRoleAccess.js +64 -0
  171. package/dist/utils/dashboardRoleAccess.js.map +1 -0
  172. package/dist/utils/dialogBackdrop.d.ts +9 -0
  173. package/dist/utils/dialogBackdrop.js +17 -0
  174. package/dist/utils/dialogBackdrop.js.map +1 -0
  175. package/dist/utils/formatBytes.d.ts +2 -0
  176. package/dist/utils/formatBytes.js +20 -0
  177. package/dist/utils/formatBytes.js.map +1 -0
  178. package/dist/utils/hostname.d.ts +4 -0
  179. package/dist/utils/hostname.js +32 -0
  180. package/dist/utils/hostname.js.map +1 -0
  181. package/dist/utils/index.d.ts +5 -0
  182. package/dist/utils/index.js +7 -0
  183. package/dist/utils/index.js.map +1 -0
  184. package/dist/utils/maskBlobToken.d.ts +11 -0
  185. package/dist/utils/maskBlobToken.js +42 -0
  186. package/dist/utils/maskBlobToken.js.map +1 -0
  187. package/package.json +140 -3
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Resolves which users may see/use the backup dashboard when no custom `access`
3
+ * option is passed to the plugin. Driven by the `PAYLOAD_BACKUP_ALLOWED_ROLES`
4
+ * environment variable.
5
+ *
6
+ * Syntax:
7
+ * PAYLOAD_BACKUP_ALLOWED_ROLES=admin,editor // any user whose roles[].slug matches
8
+ * PAYLOAD_BACKUP_ALLOWED_ROLES=* // any authenticated user
9
+ * (unset / empty) // backwards-compatible default:
10
+ * // - roles present -> require `admin`
11
+ * // - no roles field -> allow
12
+ */ export const BACKUP_ALLOWED_ROLES_ENV = 'PAYLOAD_BACKUP_ALLOWED_ROLES';
13
+ /** Parses the env var value into a normalized list of role slugs (lower-cased, trimmed). */ export function parseAllowedRolesEnv(raw) {
14
+ if (!raw) {
15
+ return [];
16
+ }
17
+ return raw.split(',').map((s)=>s.trim().toLowerCase()).filter((s)=>s.length > 0);
18
+ }
19
+ function extractRoleSlugs(user) {
20
+ const roles = user.roles;
21
+ if (!Array.isArray(roles)) {
22
+ return null;
23
+ }
24
+ const slugs = [];
25
+ for (const entry of roles){
26
+ if (typeof entry === 'string') {
27
+ slugs.push(entry.toLowerCase());
28
+ } else if (entry && typeof entry === 'object' && typeof entry.slug === 'string') {
29
+ slugs.push(entry.slug.toLowerCase());
30
+ }
31
+ }
32
+ return slugs;
33
+ }
34
+ /**
35
+ * Returns true when the authenticated user is allowed to view the backup dashboard based
36
+ * on the `PAYLOAD_BACKUP_ALLOWED_ROLES` env var. Unauthenticated users always return false.
37
+ *
38
+ * Exported for unit testing and for advanced consumers that want to reuse the same check
39
+ * (e.g. wrap it inside their own `access` option).
40
+ */ export function isUserAllowedByEnvRoles(user, envValue = process.env[BACKUP_ALLOWED_ROLES_ENV]) {
41
+ if (!user) {
42
+ return false;
43
+ }
44
+ const allowed = parseAllowedRolesEnv(envValue);
45
+ const userRoles = extractRoleSlugs(user);
46
+ // Env var not set -> backwards-compatible default.
47
+ if (allowed.length === 0) {
48
+ if (userRoles === null || userRoles.length === 0) {
49
+ return true;
50
+ }
51
+ return userRoles.includes('admin');
52
+ }
53
+ // Wildcard -> any authenticated user.
54
+ if (allowed.includes('*')) {
55
+ return true;
56
+ }
57
+ // Explicit allow-list requires the user to actually expose roles that match.
58
+ if (!userRoles || userRoles.length === 0) {
59
+ return false;
60
+ }
61
+ return userRoles.some((slug)=>allowed.includes(slug));
62
+ }
63
+
64
+ //# sourceMappingURL=dashboardRoleAccess.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/dashboardRoleAccess.ts"],"sourcesContent":["/**\n * Resolves which users may see/use the backup dashboard when no custom `access`\n * option is passed to the plugin. Driven by the `PAYLOAD_BACKUP_ALLOWED_ROLES`\n * environment variable.\n *\n * Syntax:\n * PAYLOAD_BACKUP_ALLOWED_ROLES=admin,editor // any user whose roles[].slug matches\n * PAYLOAD_BACKUP_ALLOWED_ROLES=* // any authenticated user\n * (unset / empty) // backwards-compatible default:\n * // - roles present -> require `admin`\n * // - no roles field -> allow\n */\n\nexport const BACKUP_ALLOWED_ROLES_ENV = 'PAYLOAD_BACKUP_ALLOWED_ROLES'\n\n/** Parses the env var value into a normalized list of role slugs (lower-cased, trimmed). */\nexport function parseAllowedRolesEnv(raw: string | undefined): string[] {\n if (!raw) {\n return []\n }\n return raw\n .split(',')\n .map((s) => s.trim().toLowerCase())\n .filter((s) => s.length > 0)\n}\n\nfunction extractRoleSlugs(user: Record<string, unknown>): null | string[] {\n const roles = user.roles as Array<{ slug?: unknown } | string> | undefined\n if (!Array.isArray(roles)) {\n return null\n }\n const slugs: string[] = []\n for (const entry of roles) {\n if (typeof entry === 'string') {\n slugs.push(entry.toLowerCase())\n } else if (entry && typeof entry === 'object' && typeof entry.slug === 'string') {\n slugs.push(entry.slug.toLowerCase())\n }\n }\n return slugs\n}\n\n/**\n * Returns true when the authenticated user is allowed to view the backup dashboard based\n * on the `PAYLOAD_BACKUP_ALLOWED_ROLES` env var. Unauthenticated users always return false.\n *\n * Exported for unit testing and for advanced consumers that want to reuse the same check\n * (e.g. wrap it inside their own `access` option).\n */\nexport function isUserAllowedByEnvRoles(\n user: null | Record<string, unknown>,\n envValue: string | undefined = process.env[BACKUP_ALLOWED_ROLES_ENV],\n): boolean {\n if (!user) {\n return false\n }\n const allowed = parseAllowedRolesEnv(envValue)\n const userRoles = extractRoleSlugs(user)\n\n // Env var not set -> backwards-compatible default.\n if (allowed.length === 0) {\n if (userRoles === null || userRoles.length === 0) {\n return true\n }\n return userRoles.includes('admin')\n }\n\n // Wildcard -> any authenticated user.\n if (allowed.includes('*')) {\n return true\n }\n\n // Explicit allow-list requires the user to actually expose roles that match.\n if (!userRoles || userRoles.length === 0) {\n return false\n }\n return userRoles.some((slug) => allowed.includes(slug))\n}\n"],"names":["BACKUP_ALLOWED_ROLES_ENV","parseAllowedRolesEnv","raw","split","map","s","trim","toLowerCase","filter","length","extractRoleSlugs","user","roles","Array","isArray","slugs","entry","push","slug","isUserAllowedByEnvRoles","envValue","process","env","allowed","userRoles","includes","some"],"mappings":"AAAA;;;;;;;;;;;CAWC,GAED,OAAO,MAAMA,2BAA2B,+BAA8B;AAEtE,0FAA0F,GAC1F,OAAO,SAASC,qBAAqBC,GAAuB;IAC1D,IAAI,CAACA,KAAK;QACR,OAAO,EAAE;IACX;IACA,OAAOA,IACJC,KAAK,CAAC,KACNC,GAAG,CAAC,CAACC,IAAMA,EAAEC,IAAI,GAAGC,WAAW,IAC/BC,MAAM,CAAC,CAACH,IAAMA,EAAEI,MAAM,GAAG;AAC9B;AAEA,SAASC,iBAAiBC,IAA6B;IACrD,MAAMC,QAAQD,KAAKC,KAAK;IACxB,IAAI,CAACC,MAAMC,OAAO,CAACF,QAAQ;QACzB,OAAO;IACT;IACA,MAAMG,QAAkB,EAAE;IAC1B,KAAK,MAAMC,SAASJ,MAAO;QACzB,IAAI,OAAOI,UAAU,UAAU;YAC7BD,MAAME,IAAI,CAACD,MAAMT,WAAW;QAC9B,OAAO,IAAIS,SAAS,OAAOA,UAAU,YAAY,OAAOA,MAAME,IAAI,KAAK,UAAU;YAC/EH,MAAME,IAAI,CAACD,MAAME,IAAI,CAACX,WAAW;QACnC;IACF;IACA,OAAOQ;AACT;AAEA;;;;;;CAMC,GACD,OAAO,SAASI,wBACdR,IAAoC,EACpCS,WAA+BC,QAAQC,GAAG,CAACtB,yBAAyB;IAEpE,IAAI,CAACW,MAAM;QACT,OAAO;IACT;IACA,MAAMY,UAAUtB,qBAAqBmB;IACrC,MAAMI,YAAYd,iBAAiBC;IAEnC,mDAAmD;IACnD,IAAIY,QAAQd,MAAM,KAAK,GAAG;QACxB,IAAIe,cAAc,QAAQA,UAAUf,MAAM,KAAK,GAAG;YAChD,OAAO;QACT;QACA,OAAOe,UAAUC,QAAQ,CAAC;IAC5B;IAEA,sCAAsC;IACtC,IAAIF,QAAQE,QAAQ,CAAC,MAAM;QACzB,OAAO;IACT;IAEA,6EAA6E;IAC7E,IAAI,CAACD,aAAaA,UAAUf,MAAM,KAAK,GAAG;QACxC,OAAO;IACT;IACA,OAAOe,UAAUE,IAAI,CAAC,CAACR,OAASK,QAAQE,QAAQ,CAACP;AACnD"}
@@ -0,0 +1,9 @@
1
+ import type { MouseEvent, PointerEvent, RefObject } from 'react';
2
+ /** Mouse or pointer event with viewport coordinates (native {@code <dialog>} backdrop close). */
3
+ export type DialogBackdropPointer = Pick<MouseEvent<HTMLDialogElement>, 'clientX' | 'clientY'> | Pick<PointerEvent<HTMLDialogElement>, 'clientX' | 'clientY'>;
4
+ /**
5
+ * Closes a native {@code <dialog>} when the pointer event is outside the dialog panel
6
+ * (on the dimmed backdrop). Modal dialogs only expose the panel in {@code getBoundingClientRect()},
7
+ * not the full viewport overlay.
8
+ */
9
+ export declare function closeNativeDialogOnBackdropPointer(event: DialogBackdropPointer, dialogRef: RefObject<HTMLDialogElement | null>): void;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Closes a native {@code <dialog>} when the pointer event is outside the dialog panel
3
+ * (on the dimmed backdrop). Modal dialogs only expose the panel in {@code getBoundingClientRect()},
4
+ * not the full viewport overlay.
5
+ */ export function closeNativeDialogOnBackdropPointer(event, dialogRef) {
6
+ const el = dialogRef.current;
7
+ if (!el) {
8
+ return;
9
+ }
10
+ const r = el.getBoundingClientRect();
11
+ const { clientX: x, clientY: y } = event;
12
+ if (x < r.left || x > r.right || y < r.top || y > r.bottom) {
13
+ el.close();
14
+ }
15
+ }
16
+
17
+ //# sourceMappingURL=dialogBackdrop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/dialogBackdrop.ts"],"sourcesContent":["import type { MouseEvent, PointerEvent, RefObject } from 'react'\n\n/** Mouse or pointer event with viewport coordinates (native {@code <dialog>} backdrop close). */\nexport type DialogBackdropPointer =\n | Pick<MouseEvent<HTMLDialogElement>, 'clientX' | 'clientY'>\n | Pick<PointerEvent<HTMLDialogElement>, 'clientX' | 'clientY'>\n\n/**\n * Closes a native {@code <dialog>} when the pointer event is outside the dialog panel\n * (on the dimmed backdrop). Modal dialogs only expose the panel in {@code getBoundingClientRect()},\n * not the full viewport overlay.\n */\nexport function closeNativeDialogOnBackdropPointer(\n event: DialogBackdropPointer,\n dialogRef: RefObject<HTMLDialogElement | null>,\n): void {\n const el = dialogRef.current\n if (!el) {\n return\n }\n const r = el.getBoundingClientRect()\n const { clientX: x, clientY: y } = event\n if (x < r.left || x > r.right || y < r.top || y > r.bottom) {\n el.close()\n }\n}\n"],"names":["closeNativeDialogOnBackdropPointer","event","dialogRef","el","current","r","getBoundingClientRect","clientX","x","clientY","y","left","right","top","bottom","close"],"mappings":"AAOA;;;;CAIC,GACD,OAAO,SAASA,mCACdC,KAA4B,EAC5BC,SAA8C;IAE9C,MAAMC,KAAKD,UAAUE,OAAO;IAC5B,IAAI,CAACD,IAAI;QACP;IACF;IACA,MAAME,IAAIF,GAAGG,qBAAqB;IAClC,MAAM,EAAEC,SAASC,CAAC,EAAEC,SAASC,CAAC,EAAE,GAAGT;IACnC,IAAIO,IAAIH,EAAEM,IAAI,IAAIH,IAAIH,EAAEO,KAAK,IAAIF,IAAIL,EAAEQ,GAAG,IAAIH,IAAIL,EAAES,MAAM,EAAE;QAC1DX,GAAGY,KAAK;IACV;AACF"}
@@ -0,0 +1,2 @@
1
+ /** Human-readable file size (binary units: KiB, MiB, GiB — shown as KB/MB/GB for familiarity). */
2
+ export declare function formatBytes(bytes: number): string;
@@ -0,0 +1,20 @@
1
+ /** Human-readable file size (binary units: KiB, MiB, GiB — shown as KB/MB/GB for familiarity). */ export function formatBytes(bytes) {
2
+ if (!Number.isFinite(bytes) || bytes < 0) {
3
+ return '—';
4
+ }
5
+ if (bytes < 1024) {
6
+ return `${Math.round(bytes)} B`;
7
+ }
8
+ const kb = bytes / 1024;
9
+ if (kb < 1024) {
10
+ return kb < 10 ? `${kb.toFixed(1)} KB` : `${Math.round(kb)} KB`;
11
+ }
12
+ const mb = kb / 1024;
13
+ if (mb < 1024) {
14
+ return mb < 10 ? `${mb.toFixed(1)} MB` : `${mb.toFixed(1)} MB`;
15
+ }
16
+ const gb = mb / 1024;
17
+ return gb < 10 ? `${gb.toFixed(2)} GB` : `${gb.toFixed(1)} GB`;
18
+ }
19
+
20
+ //# sourceMappingURL=formatBytes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/formatBytes.ts"],"sourcesContent":["/** Human-readable file size (binary units: KiB, MiB, GiB — shown as KB/MB/GB for familiarity). */\nexport function formatBytes(bytes: number): string {\n if (!Number.isFinite(bytes) || bytes < 0) {\n return '—'\n }\n if (bytes < 1024) {\n return `${Math.round(bytes)} B`\n }\n const kb = bytes / 1024\n if (kb < 1024) {\n return kb < 10 ? `${kb.toFixed(1)} KB` : `${Math.round(kb)} KB`\n }\n const mb = kb / 1024\n if (mb < 1024) {\n return mb < 10 ? `${mb.toFixed(1)} MB` : `${mb.toFixed(1)} MB`\n }\n const gb = mb / 1024\n return gb < 10 ? `${gb.toFixed(2)} GB` : `${gb.toFixed(1)} GB`\n}\n"],"names":["formatBytes","bytes","Number","isFinite","Math","round","kb","toFixed","mb","gb"],"mappings":"AAAA,gGAAgG,GAChG,OAAO,SAASA,YAAYC,KAAa;IACvC,IAAI,CAACC,OAAOC,QAAQ,CAACF,UAAUA,QAAQ,GAAG;QACxC,OAAO;IACT;IACA,IAAIA,QAAQ,MAAM;QAChB,OAAO,GAAGG,KAAKC,KAAK,CAACJ,OAAO,EAAE,CAAC;IACjC;IACA,MAAMK,KAAKL,QAAQ;IACnB,IAAIK,KAAK,MAAM;QACb,OAAOA,KAAK,KAAK,GAAGA,GAAGC,OAAO,CAAC,GAAG,GAAG,CAAC,GAAG,GAAGH,KAAKC,KAAK,CAACC,IAAI,GAAG,CAAC;IACjE;IACA,MAAME,KAAKF,KAAK;IAChB,IAAIE,KAAK,MAAM;QACb,OAAOA,KAAK,KAAK,GAAGA,GAAGD,OAAO,CAAC,GAAG,GAAG,CAAC,GAAG,GAAGC,GAAGD,OAAO,CAAC,GAAG,GAAG,CAAC;IAChE;IACA,MAAME,KAAKD,KAAK;IAChB,OAAOC,KAAK,KAAK,GAAGA,GAAGF,OAAO,CAAC,GAAG,GAAG,CAAC,GAAG,GAAGE,GAAGF,OAAO,CAAC,GAAG,GAAG,CAAC;AAChE"}
@@ -0,0 +1,4 @@
1
+ export declare function getConnectionString(): string | undefined;
2
+ /** `host/dbname` of the Postgres connection (credentials are never included). */
3
+ export declare function getCurrentDbName(): string;
4
+ export declare function getCurrentHostname(): string;
@@ -0,0 +1,32 @@
1
+ const CONNECTION_ENV_KEYS = [
2
+ 'DATABASE_URI',
3
+ 'DATABASE_URL',
4
+ 'POSTGRES_URL',
5
+ 'POSTGRES_URI'
6
+ ];
7
+ export function getConnectionString() {
8
+ for (const key of CONNECTION_ENV_KEYS){
9
+ const v = process.env[key]?.trim();
10
+ if (v) {
11
+ return v;
12
+ }
13
+ }
14
+ return undefined;
15
+ }
16
+ /** `host/dbname` of the Postgres connection (credentials are never included). */ export function getCurrentDbName() {
17
+ try {
18
+ const { hostname, pathname } = new URL(getConnectionString());
19
+ return hostname + pathname;
20
+ } catch {
21
+ return 'none';
22
+ }
23
+ }
24
+ export function getCurrentHostname() {
25
+ try {
26
+ return process.env.NEXT_PUBLIC_SERVER_URL ? new URL(process.env.NEXT_PUBLIC_SERVER_URL).hostname : process.env.VERCEL_URL ?? 'none';
27
+ } catch {
28
+ return process.env.VERCEL_URL || 'none';
29
+ }
30
+ }
31
+
32
+ //# sourceMappingURL=hostname.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/hostname.ts"],"sourcesContent":["const CONNECTION_ENV_KEYS = ['DATABASE_URI', 'DATABASE_URL', 'POSTGRES_URL', 'POSTGRES_URI']\n\nexport function getConnectionString(): string | undefined {\n for (const key of CONNECTION_ENV_KEYS) {\n const v = process.env[key]?.trim()\n if (v) {\n return v\n }\n }\n return undefined\n}\n\n/** `host/dbname` of the Postgres connection (credentials are never included). */\nexport function getCurrentDbName(): string {\n try {\n const { hostname, pathname } = new URL(getConnectionString()!)\n return hostname + pathname\n } catch {\n return 'none'\n }\n}\n\nexport function getCurrentHostname(): string {\n try {\n return process.env.NEXT_PUBLIC_SERVER_URL ?\n new URL(process.env.NEXT_PUBLIC_SERVER_URL).hostname\n : (process.env.VERCEL_URL ?? 'none')\n } catch {\n return process.env.VERCEL_URL! || 'none'\n }\n}\n"],"names":["CONNECTION_ENV_KEYS","getConnectionString","key","v","process","env","trim","undefined","getCurrentDbName","hostname","pathname","URL","getCurrentHostname","NEXT_PUBLIC_SERVER_URL","VERCEL_URL"],"mappings":"AAAA,MAAMA,sBAAsB;IAAC;IAAgB;IAAgB;IAAgB;CAAe;AAE5F,OAAO,SAASC;IACd,KAAK,MAAMC,OAAOF,oBAAqB;QACrC,MAAMG,IAAIC,QAAQC,GAAG,CAACH,IAAI,EAAEI;QAC5B,IAAIH,GAAG;YACL,OAAOA;QACT;IACF;IACA,OAAOI;AACT;AAEA,+EAA+E,GAC/E,OAAO,SAASC;IACd,IAAI;QACF,MAAM,EAAEC,QAAQ,EAAEC,QAAQ,EAAE,GAAG,IAAIC,IAAIV;QACvC,OAAOQ,WAAWC;IACpB,EAAE,OAAM;QACN,OAAO;IACT;AACF;AAEA,OAAO,SAASE;IACd,IAAI;QACF,OAAOR,QAAQC,GAAG,CAACQ,sBAAsB,GACrC,IAAIF,IAAIP,QAAQC,GAAG,CAACQ,sBAAsB,EAAEJ,QAAQ,GACnDL,QAAQC,GAAG,CAACS,UAAU,IAAI;IACjC,EAAE,OAAM;QACN,OAAOV,QAAQC,GAAG,CAACS,UAAU,IAAK;IACpC;AACF"}
@@ -0,0 +1,5 @@
1
+ export * from './blobName.js';
2
+ export * from './dashboardRoleAccess.js';
3
+ export * from './formatBytes.js';
4
+ export * from './hostname.js';
5
+ export * from './maskBlobToken.js';
@@ -0,0 +1,7 @@
1
+ export * from './blobName.js';
2
+ export * from './dashboardRoleAccess.js';
3
+ export * from './formatBytes.js';
4
+ export * from './hostname.js';
5
+ export * from './maskBlobToken.js';
6
+
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["export * from './blobName'\nexport * from './dashboardRoleAccess'\nexport * from './formatBytes'\nexport * from './hostname'\nexport * from './maskBlobToken'\n"],"names":[],"mappings":"AAAA,cAAc,aAAY;AAC1B,cAAc,wBAAuB;AACrC,cAAc,gBAAe;AAC7B,cAAc,aAAY;AAC1B,cAAc,kBAAiB"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Mask a Vercel Blob read/write token for display in the admin UI (never send the full secret).
3
+ * Shape: prefix + fixed-length asterisk run + suffix (length of real token does not change star count).
4
+ * Example: vercel_blob_rw_yfn + 23×* + bsM7
5
+ */
6
+ export declare function maskBlobReadWriteToken(raw: string): string;
7
+ /**
8
+ * When a token is already stored, treat the client value as "do not change the stored token" if
9
+ * they left the masked placeholder or cleared the field while editing other settings.
10
+ */
11
+ export declare function shouldPreserveBackupBlobTokenField(clientValue: string, hadStoredToken: boolean): boolean;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Mask a Vercel Blob read/write token for display in the admin UI (never send the full secret).
3
+ * Shape: prefix + fixed-length asterisk run + suffix (length of real token does not change star count).
4
+ * Example: vercel_blob_rw_yfn + 23×* + bsM7
5
+ */ export function maskBlobReadWriteToken(raw) {
6
+ const t = raw.trim();
7
+ if (t.length === 0) {
8
+ return '';
9
+ }
10
+ /** Fixed number of asterisks between prefix and suffix (UI stays compact for any token length). */ const middleRun = 32;
11
+ const prefixLen = Math.min(18, Math.max(8, Math.floor(t.length * 0.42)));
12
+ const suffixLen = Math.min(4, Math.max(3, Math.floor(t.length * 0.12)));
13
+ if (t.length <= prefixLen + suffixLen + 6) {
14
+ const headLen = Math.min(6, t.length);
15
+ const head = t.slice(0, headLen);
16
+ const tailLen = Math.min(3, Math.max(0, t.length - headLen));
17
+ const tail = tailLen > 0 ? t.slice(-tailLen) : '';
18
+ const middle = '*'.repeat(middleRun);
19
+ return tail ? `${head}${middle}${tail}` : `${head}${middle}`;
20
+ }
21
+ const prefix = t.slice(0, prefixLen);
22
+ const suffix = t.slice(-suffixLen);
23
+ return `${prefix}${'*'.repeat(middleRun)}${suffix}`;
24
+ }
25
+ /**
26
+ * When a token is already stored, treat the client value as "do not change the stored token" if
27
+ * they left the masked placeholder or cleared the field while editing other settings.
28
+ */ export function shouldPreserveBackupBlobTokenField(clientValue, hadStoredToken) {
29
+ if (!hadStoredToken) {
30
+ return false;
31
+ }
32
+ const v = clientValue.trim();
33
+ if (v.length === 0) {
34
+ return true;
35
+ }
36
+ if (/\*{2,}/.test(v)) {
37
+ return true;
38
+ }
39
+ return false;
40
+ }
41
+
42
+ //# sourceMappingURL=maskBlobToken.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/maskBlobToken.ts"],"sourcesContent":["/**\n * Mask a Vercel Blob read/write token for display in the admin UI (never send the full secret).\n * Shape: prefix + fixed-length asterisk run + suffix (length of real token does not change star count).\n * Example: vercel_blob_rw_yfn + 23×* + bsM7\n */\nexport function maskBlobReadWriteToken(raw: string): string {\n const t = raw.trim()\n if (t.length === 0) {\n return ''\n }\n\n /** Fixed number of asterisks between prefix and suffix (UI stays compact for any token length). */\n const middleRun = 32\n\n const prefixLen = Math.min(18, Math.max(8, Math.floor(t.length * 0.42)))\n const suffixLen = Math.min(4, Math.max(3, Math.floor(t.length * 0.12)))\n\n if (t.length <= prefixLen + suffixLen + 6) {\n const headLen = Math.min(6, t.length)\n const head = t.slice(0, headLen)\n const tailLen = Math.min(3, Math.max(0, t.length - headLen))\n const tail = tailLen > 0 ? t.slice(-tailLen) : ''\n const middle = '*'.repeat(middleRun)\n return tail ? `${head}${middle}${tail}` : `${head}${middle}`\n }\n\n const prefix = t.slice(0, prefixLen)\n const suffix = t.slice(-suffixLen)\n return `${prefix}${'*'.repeat(middleRun)}${suffix}`\n}\n\n/**\n * When a token is already stored, treat the client value as \"do not change the stored token\" if\n * they left the masked placeholder or cleared the field while editing other settings.\n */\nexport function shouldPreserveBackupBlobTokenField(\n clientValue: string,\n hadStoredToken: boolean,\n): boolean {\n if (!hadStoredToken) {\n return false\n }\n const v = clientValue.trim()\n if (v.length === 0) {\n return true\n }\n if (/\\*{2,}/.test(v)) {\n return true\n }\n return false\n}\n"],"names":["maskBlobReadWriteToken","raw","t","trim","length","middleRun","prefixLen","Math","min","max","floor","suffixLen","headLen","head","slice","tailLen","tail","middle","repeat","prefix","suffix","shouldPreserveBackupBlobTokenField","clientValue","hadStoredToken","v","test"],"mappings":"AAAA;;;;CAIC,GACD,OAAO,SAASA,uBAAuBC,GAAW;IAChD,MAAMC,IAAID,IAAIE,IAAI;IAClB,IAAID,EAAEE,MAAM,KAAK,GAAG;QAClB,OAAO;IACT;IAEA,iGAAiG,GACjG,MAAMC,YAAY;IAElB,MAAMC,YAAYC,KAAKC,GAAG,CAAC,IAAID,KAAKE,GAAG,CAAC,GAAGF,KAAKG,KAAK,CAACR,EAAEE,MAAM,GAAG;IACjE,MAAMO,YAAYJ,KAAKC,GAAG,CAAC,GAAGD,KAAKE,GAAG,CAAC,GAAGF,KAAKG,KAAK,CAACR,EAAEE,MAAM,GAAG;IAEhE,IAAIF,EAAEE,MAAM,IAAIE,YAAYK,YAAY,GAAG;QACzC,MAAMC,UAAUL,KAAKC,GAAG,CAAC,GAAGN,EAAEE,MAAM;QACpC,MAAMS,OAAOX,EAAEY,KAAK,CAAC,GAAGF;QACxB,MAAMG,UAAUR,KAAKC,GAAG,CAAC,GAAGD,KAAKE,GAAG,CAAC,GAAGP,EAAEE,MAAM,GAAGQ;QACnD,MAAMI,OAAOD,UAAU,IAAIb,EAAEY,KAAK,CAAC,CAACC,WAAW;QAC/C,MAAME,SAAS,IAAIC,MAAM,CAACb;QAC1B,OAAOW,OAAO,GAAGH,OAAOI,SAASD,MAAM,GAAG,GAAGH,OAAOI,QAAQ;IAC9D;IAEA,MAAME,SAASjB,EAAEY,KAAK,CAAC,GAAGR;IAC1B,MAAMc,SAASlB,EAAEY,KAAK,CAAC,CAACH;IACxB,OAAO,GAAGQ,SAAS,IAAID,MAAM,CAACb,aAAae,QAAQ;AACrD;AAEA;;;CAGC,GACD,OAAO,SAASC,mCACdC,WAAmB,EACnBC,cAAuB;IAEvB,IAAI,CAACA,gBAAgB;QACnB,OAAO;IACT;IACA,MAAMC,IAAIF,YAAYnB,IAAI;IAC1B,IAAIqB,EAAEpB,MAAM,KAAK,GAAG;QAClB,OAAO;IACT;IACA,IAAI,SAASqB,IAAI,CAACD,IAAI;QACpB,OAAO;IACT;IACA,OAAO;AACT"}
package/package.json CHANGED
@@ -1,6 +1,143 @@
1
1
  {
2
2
  "name": "payload-plugin-backup-postgres",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0",
4
+ "description": "Payload CMS plugin for PostgreSQL backup and recovery via Vercel Blob or AWS S3 (S3-compatible: R2, MinIO)",
5
+ "keywords": [
6
+ "payload",
7
+ "payloadcms",
8
+ "payload-cms",
9
+ "payload-plugin",
10
+ "payloadcms-plugin",
11
+ "payload-backup",
12
+ "payload-restore",
13
+ "backup",
14
+ "restore",
15
+ "recovery",
16
+ "database-backup",
17
+ "cms-backup",
18
+ "vercel",
19
+ "vercel-blob",
20
+ "cron",
21
+ "scheduled-backups",
22
+ "admin-dashboard",
23
+ "nextjs",
24
+ "react",
25
+ "typescript",
26
+ "payblocks",
27
+ "postgres",
28
+ "postgresql",
29
+ "drizzle"
30
+ ],
31
+ "license": "MIT",
32
+ "type": "module",
33
+ "exports": {
34
+ ".": {
35
+ "import": "./dist/index.js",
36
+ "types": "./dist/index.d.ts",
37
+ "default": "./dist/index.js"
38
+ },
39
+ "./client": {
40
+ "import": "./dist/exports/client.js",
41
+ "types": "./dist/exports/client.d.ts",
42
+ "default": "./dist/exports/client.js"
43
+ },
44
+ "./rsc": {
45
+ "import": "./dist/exports/rsc.js",
46
+ "types": "./dist/exports/rsc.d.ts",
47
+ "default": "./dist/exports/rsc.js"
48
+ },
49
+ "./styles.css": "./dist/backup-dashboard.css"
50
+ },
51
+ "main": "./dist/index.js",
52
+ "types": "./dist/index.d.ts",
53
+ "files": [
54
+ "dist"
55
+ ],
56
+ "dependencies": {
57
+ "@vercel/blob": "^2.3.3",
58
+ "cronstrue": "^3.14.0",
59
+ "tar-stream": "^3.1.7"
60
+ },
61
+ "devDependencies": {
62
+ "@aws-sdk/client-s3": "^3.700.0",
63
+ "@aws-sdk/lib-storage": "^3.700.0",
64
+ "@aws-sdk/s3-request-presigner": "^3.700.0",
65
+ "@changesets/cli": "^3.0.3",
66
+ "@eslint/eslintrc": "^3.2.0",
67
+ "@payloadcms/db-postgres": "3.82.1",
68
+ "@payloadcms/eslint-config": "3.28.0",
69
+ "@payloadcms/translations": "3.82.1",
70
+ "@payloadcms/ui": "3.82.1",
71
+ "@swc/cli": "0.6.0",
72
+ "@types/node": "22.19.9",
73
+ "@types/pg": "^8.11.10",
74
+ "@types/react": "19.2.14",
75
+ "@types/react-dom": "19.2.3",
76
+ "@types/tar-stream": "^3.1.4",
77
+ "@vitest/coverage-v8": "^4.1.5",
78
+ "copyfiles": "2.4.1",
79
+ "eslint": "^9.23.0",
80
+ "next": "16.2.3",
81
+ "payload": "3.82.1",
82
+ "pg": "^8.13.0",
83
+ "prettier": "^3.4.2",
84
+ "react": "19.2.4",
85
+ "react-dom": "19.2.4",
86
+ "rimraf": "3.0.2",
87
+ "sass": "^1.85.0",
88
+ "typescript": "5.7.3",
89
+ "vite-tsconfig-paths": "6.0.5",
90
+ "vitest": "4.1.5"
91
+ },
92
+ "peerDependencies": {
93
+ "@aws-sdk/client-s3": "^3.0.0",
94
+ "@aws-sdk/lib-storage": "^3.0.0",
95
+ "@aws-sdk/s3-request-presigner": "^3.0.0",
96
+ "@payloadcms/db-postgres": "^3.0.0",
97
+ "@payloadcms/ui": "^3.0.0",
98
+ "next": "^15.0.0 || ^16.0.0",
99
+ "payload": "^3.0.0",
100
+ "react": "^19.0.0"
101
+ },
102
+ "peerDependenciesMeta": {
103
+ "@aws-sdk/client-s3": {
104
+ "optional": true
105
+ },
106
+ "@aws-sdk/lib-storage": {
107
+ "optional": true
108
+ },
109
+ "@aws-sdk/s3-request-presigner": {
110
+ "optional": true
111
+ },
112
+ "@payloadcms/db-postgres": {
113
+ "optional": true
114
+ }
115
+ },
116
+ "engines": {
117
+ "node": ">=22.0.0",
118
+ "pnpm": "^11.0.0"
119
+ },
120
+ "publishConfig": {
121
+ "access": "public"
122
+ },
123
+ "scripts": {
124
+ "release": "bun run build && changeset publish",
125
+ "build": "pnpm copyfiles && pnpm build:css && pnpm build:embed-css && pnpm build:types && pnpm build:swc && pnpm build:esm-ext",
126
+ "build:css": "sass src/components/BackupDashboard/index.scss dist/backup-dashboard.css --no-source-map --pkg-importer=node --quiet-deps --silence-deprecation=import",
127
+ "build:embed-css": "node ./scripts/embed-backup-css.mjs",
128
+ "build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
129
+ "build:types": "tsc -p tsconfig.build.json",
130
+ "clean": "rimraf {dist,*.tsbuildinfo}",
131
+ "copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
132
+ "format": "prettier --write . --cache --log-level warn",
133
+ "format:check": "prettier --check . --cache --log-level warn",
134
+ "lint": "eslint \"src/**/*.{ts,tsx}\" \"tests/**/*.{ts,tsx}\"",
135
+ "lint:fix": "eslint \"src/**/*.{ts,tsx}\" \"tests/**/*.{ts,tsx}\" --fix",
136
+ "test": "vitest run",
137
+ "test:int": "vitest run",
138
+ "test:int:cov": "vitest run --coverage",
139
+ "test:int:watch": "vitest",
140
+ "typecheck": "tsc --noEmit",
141
+ "build:esm-ext": "node ./scripts/fix-esm-extensions.mjs dist"
142
+ }
6
143
  }