roles-privileges-payload-plugin 1.1.1 → 1.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 (48) hide show
  1. package/README.md +15 -0
  2. package/dist/collections/roles.d.ts +2 -2
  3. package/dist/collections/roles.js +27 -45
  4. package/dist/collections/roles.js.map +1 -1
  5. package/dist/components/PrivilegesSelect.d.ts +2 -2
  6. package/dist/components/PrivilegesSelect.js +89 -71
  7. package/dist/components/PrivilegesSelect.js.map +1 -1
  8. package/dist/exports/utilities.d.ts +5 -4
  9. package/dist/exports/utilities.js +10 -8
  10. package/dist/exports/utilities.js.map +1 -1
  11. package/dist/fields/slug/SlugComponent.d.ts +9 -0
  12. package/dist/fields/slug/SlugComponent.js +83 -0
  13. package/dist/fields/slug/SlugComponent.js.map +1 -0
  14. package/dist/fields/slug/formatSlug.d.ts +3 -0
  15. package/dist/fields/slug/formatSlug.js +15 -0
  16. package/dist/fields/slug/formatSlug.js.map +1 -0
  17. package/dist/fields/slug/index.d.ts +8 -0
  18. package/dist/fields/slug/index.js +47 -0
  19. package/dist/fields/slug/index.js.map +1 -0
  20. package/dist/fields/slug/index.scss +12 -0
  21. package/dist/index.d.ts +17 -7
  22. package/dist/index.js +59 -10
  23. package/dist/index.js.map +1 -1
  24. package/dist/roles-privileges-payload-plugin-1.2.0.tgz +0 -0
  25. package/dist/translations/index.js +4 -4
  26. package/dist/translations/index.js.map +1 -1
  27. package/dist/translations/languages/en.js +19 -18
  28. package/dist/translations/languages/en.js.map +1 -1
  29. package/dist/translations/languages/fr.js +19 -18
  30. package/dist/translations/languages/fr.js.map +1 -1
  31. package/dist/translations/types.d.ts +43 -42
  32. package/dist/translations/types.js.map +1 -1
  33. package/dist/utils/assignSuperAdminToFirstUser.d.ts +10 -0
  34. package/dist/utils/assignSuperAdminToFirstUser.js +70 -0
  35. package/dist/utils/assignSuperAdminToFirstUser.js.map +1 -0
  36. package/dist/utils/createCustomPrivilege.d.ts +9 -9
  37. package/dist/utils/createCustomPrivilege.js +4 -4
  38. package/dist/utils/createCustomPrivilege.js.map +1 -1
  39. package/dist/utils/generateGlobalPrivileges.d.ts +4 -4
  40. package/dist/utils/generateGlobalPrivileges.js +4 -4
  41. package/dist/utils/generateGlobalPrivileges.js.map +1 -1
  42. package/dist/utils/generatePrivileges.d.ts +6 -6
  43. package/dist/utils/generatePrivileges.js +6 -6
  44. package/dist/utils/generatePrivileges.js.map +1 -1
  45. package/dist/utils/seedSuperAdminRole.js +7 -7
  46. package/dist/utils/seedSuperAdminRole.js.map +1 -1
  47. package/package.json +15 -15
  48. package/dist/roles-privileges-payload-plugin-1.1.1.tgz +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/generateGlobalPrivileges.ts"],"sourcesContent":["import type { GlobalConfig } from 'payload'\nimport { translations } from '../translations/index.js'\n\n/**\n * Available privilege types for all global operations\n */\nexport type GlobalPrivilegeType = 'read' | 'readDrafts' | 'readVersions' | 'update'\n\n/**\n * Interface for a single privilege\n */\nexport interface GlobalPrivilege {\n privilegeKey: string\n label: Record<string, string>\n description: Record<string, string>\n isCustom?: boolean\n}\n\n/**\n * Interface for a global's privileges\n */\nexport interface GlobalPrivileges {\n globalSlug: string\n globalLabel: Record<string, string>\n description: Record<string, string>\n privileges: {\n read: GlobalPrivilege\n readDrafts: GlobalPrivilege\n readVersions: GlobalPrivilege\n update: GlobalPrivilege\n }\n}\n\n/**\n * Map to store all generated global privileges by global slug\n */\nexport const allGlobalPrivilegesMap = new Map<string, GlobalPrivileges>()\n\n/**\n * Generate privilege key from global slug and operation\n */\nexport const generateGlobalPrivilegeKey = (\n globalSlug: string,\n operation: GlobalPrivilegeType,\n): string => {\n return `${globalSlug}-${operation}`\n}\n\n/**\n * Capitalize first letter of a string\n */\nconst capitalize = (str: string): string => {\n return str.charAt(0).toUpperCase() + str.slice(1)\n}\n\n/**\n * Get label from global config or use slug\n */\nconst getGlobalLabel = (global: GlobalConfig): Record<string, string> => {\n if (global.label) {\n if (typeof global.label === 'string') {\n // Return the string for all languages (will be used as fallback)\n return { _default: global.label }\n }\n if (typeof global.label === 'object' && !Array.isArray(global.label)) {\n return global.label as Record<string, string>\n }\n }\n\n // Default to slug\n return { _default: global.slug }\n}\n\n/**\n * Get operation prefix translations for each language\n */\nconst getGlobalOperationPrefix = (operation: GlobalPrivilegeType, lang: string): string => {\n const langTranslations = translations[lang] || translations.en\n const key =\n `privilege-prefix-global-${operation}` as keyof (typeof langTranslations)['plugin-roles-privileges']\n return (\n (langTranslations['plugin-roles-privileges'][key] as string) ||\n (translations.en['plugin-roles-privileges'][key] as string)\n )\n}\n\n/**\n * Generate operation labels based on operation type\n */\nconst getGlobalOperationLabels = (\n operation: GlobalPrivilegeType,\n label: Record<string, string>,\n): Record<string, string> => {\n const result: Record<string, string> = {}\n\n // Get all available languages from label\n const languages = Object.keys(label)\n\n for (const lang of languages) {\n const labelText = label[lang]\n const prefix = getGlobalOperationPrefix(operation, lang)\n result[lang] = `${prefix} ${labelText}`\n }\n\n return result\n}\n\n/**\n * Get operation description templates for each language\n */\nconst getGlobalOperationDescriptionTemplate = (\n operation: GlobalPrivilegeType,\n lang: string,\n): string => {\n const langTranslations = translations[lang] || translations.en\n const key =\n `privilege-template-global-${operation}` as keyof (typeof langTranslations)['plugin-roles-privileges']\n return (\n (langTranslations['plugin-roles-privileges'][key] as string) ||\n (translations.en['plugin-roles-privileges'][key] as string)\n )\n}\n\n/**\n * Generate operation descriptions based on operation type\n */\nconst getGlobalOperationDescriptions = (\n operation: GlobalPrivilegeType,\n label: Record<string, string>,\n): Record<string, string> => {\n const result: Record<string, string> = {}\n\n // Get all available languages\n const languages = Object.keys(label)\n\n for (const lang of languages) {\n const labelText = label[lang].toLowerCase()\n const template = getGlobalOperationDescriptionTemplate(operation, lang)\n result[lang] = template.replace('{label}', labelText)\n }\n\n return result\n}\n\n/**\n * Generate a single privilege for a global operation\n */\nconst generateGlobalPrivilege = (\n globalSlug: string,\n operation: GlobalPrivilegeType,\n label: Record<string, string>,\n): GlobalPrivilege => {\n return {\n privilegeKey: generateGlobalPrivilegeKey(globalSlug, operation),\n label: getGlobalOperationLabels(operation, label),\n description: getGlobalOperationDescriptions(operation, label),\n }\n}\n\n/**\n * Generate read and update privileges for a global\n */\nexport const generateGlobalPrivileges = (global: GlobalConfig): GlobalPrivileges => {\n const label = getGlobalLabel(global)\n\n const description: Record<string, string> = {}\n const languages = Object.keys(label)\n for (const lang of languages) {\n const labelText = label[lang].toLowerCase()\n const langTranslations = translations[lang] || translations.en\n const template =\n (langTranslations['plugin-roles-privileges']['privilege-global-description'] as string) ||\n (translations.en['plugin-roles-privileges']['privilege-global-description'] as string)\n description[lang] = template.replace('{label}', labelText)\n }\n\n const globalPrivileges: GlobalPrivileges = {\n globalSlug: global.slug,\n globalLabel: label,\n description,\n privileges: {\n read: generateGlobalPrivilege(global.slug, 'read', label),\n readDrafts: generateGlobalPrivilege(global.slug, 'readDrafts', label),\n readVersions: generateGlobalPrivilege(global.slug, 'readVersions', label),\n update: generateGlobalPrivilege(global.slug, 'update', label),\n },\n }\n\n // Store in the map\n allGlobalPrivilegesMap.set(global.slug, globalPrivileges)\n\n return globalPrivileges\n}\n\n/**\n * Get all global privilege keys\n */\nexport const getAllGlobalPrivilegeKeys = (): string[] => {\n const keys: string[] = []\n allGlobalPrivilegesMap.forEach((globalPrivileges) => {\n Object.values(globalPrivileges.privileges).forEach((privilege) => {\n keys.push(privilege.privilegeKey)\n })\n })\n return keys\n}\n\n/**\n * Get all global privileges as a flat array\n */\nexport const getAllGlobalPrivileges = (): GlobalPrivilege[] => {\n const privileges: GlobalPrivilege[] = []\n allGlobalPrivilegesMap.forEach((globalPrivileges) => {\n Object.values(globalPrivileges.privileges).forEach((privilege) => {\n privileges.push(privilege)\n })\n })\n return privileges\n}\n"],"names":["translations","allGlobalPrivilegesMap","Map","generateGlobalPrivilegeKey","globalSlug","operation","capitalize","str","charAt","toUpperCase","slice","getGlobalLabel","global","label","_default","Array","isArray","slug","getGlobalOperationPrefix","lang","langTranslations","en","key","getGlobalOperationLabels","result","languages","Object","keys","labelText","prefix","getGlobalOperationDescriptionTemplate","getGlobalOperationDescriptions","toLowerCase","template","replace","generateGlobalPrivilege","privilegeKey","description","generateGlobalPrivileges","globalPrivileges","globalLabel","privileges","read","readDrafts","readVersions","update","set","getAllGlobalPrivilegeKeys","forEach","values","privilege","push","getAllGlobalPrivileges"],"mappings":"AACA,SAASA,YAAY,QAAQ,2BAA0B;AAgCvD;;CAEC,GACD,OAAO,MAAMC,yBAAyB,IAAIC,MAA+B;AAEzE;;CAEC,GACD,OAAO,MAAMC,6BAA6B,CACxCC,YACAC;IAEA,OAAO,GAAGD,WAAW,CAAC,EAAEC,WAAW;AACrC,EAAC;AAED;;CAEC,GACD,MAAMC,aAAa,CAACC;IAClB,OAAOA,IAAIC,MAAM,CAAC,GAAGC,WAAW,KAAKF,IAAIG,KAAK,CAAC;AACjD;AAEA;;CAEC,GACD,MAAMC,iBAAiB,CAACC;IACtB,IAAIA,OAAOC,KAAK,EAAE;QAChB,IAAI,OAAOD,OAAOC,KAAK,KAAK,UAAU;YACpC,iEAAiE;YACjE,OAAO;gBAAEC,UAAUF,OAAOC,KAAK;YAAC;QAClC;QACA,IAAI,OAAOD,OAAOC,KAAK,KAAK,YAAY,CAACE,MAAMC,OAAO,CAACJ,OAAOC,KAAK,GAAG;YACpE,OAAOD,OAAOC,KAAK;QACrB;IACF;IAEA,kBAAkB;IAClB,OAAO;QAAEC,UAAUF,OAAOK,IAAI;IAAC;AACjC;AAEA;;CAEC,GACD,MAAMC,2BAA2B,CAACb,WAAgCc;IAChE,MAAMC,mBAAmBpB,YAAY,CAACmB,KAAK,IAAInB,aAAaqB,EAAE;IAC9D,MAAMC,MACJ,CAAC,wBAAwB,EAAEjB,WAAW;IACxC,OACE,AAACe,gBAAgB,CAAC,0BAA0B,CAACE,IAAI,IAChDtB,aAAaqB,EAAE,CAAC,0BAA0B,CAACC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,WAAWU,IAAI,CAACD;QAClB;IACF;IACA,OAAOT;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/utils/generateGlobalPrivileges.ts"],"sourcesContent":["import type { GlobalConfig } from 'payload'\n\nimport { translations } from '../translations/index.js'\n\n/**\n * Available privilege types for all global operations\n */\nexport type GlobalPrivilegeType = 'read' | 'readDrafts' | 'readVersions' | 'update'\n\n/**\n * Interface for a single privilege\n */\nexport interface GlobalPrivilege {\n description: Record<string, string>\n isCustom?: boolean\n label: Record<string, string>\n privilegeKey: string\n}\n\n/**\n * Interface for a global's privileges\n */\nexport interface GlobalPrivileges {\n description: Record<string, string>\n globalLabel: Record<string, string>\n globalSlug: string\n privileges: {\n read: GlobalPrivilege\n readDrafts: GlobalPrivilege\n readVersions: GlobalPrivilege\n update: GlobalPrivilege\n }\n}\n\n/**\n * Map to store all generated global privileges by global slug\n */\nexport const allGlobalPrivilegesMap = new Map<string, GlobalPrivileges>()\n\n/**\n * Generate privilege key from global slug and operation\n */\nexport const generateGlobalPrivilegeKey = (\n globalSlug: string,\n operation: GlobalPrivilegeType,\n): string => {\n return `${globalSlug}-${operation}`\n}\n\n/**\n * Capitalize first letter of a string\n */\nconst capitalize = (str: string): string => {\n return str.charAt(0).toUpperCase() + str.slice(1)\n}\n\n/**\n * Get label from global config or use slug\n */\nconst getGlobalLabel = (global: GlobalConfig): Record<string, string> => {\n if (global.label) {\n if (typeof global.label === 'string') {\n // Return the string for all languages (will be used as fallback)\n return { _default: global.label }\n }\n if (typeof global.label === 'object' && !Array.isArray(global.label)) {\n return global.label\n }\n }\n\n // Default to slug\n return { _default: global.slug }\n}\n\n/**\n * Get operation prefix translations for each language\n */\nconst getGlobalOperationPrefix = (operation: GlobalPrivilegeType, lang: string): string => {\n const langTranslations = translations[lang] || translations.en\n const key =\n `privilege-prefix-global-${operation}` as keyof (typeof langTranslations)['plugin-roles-privileges']\n return (\n langTranslations['plugin-roles-privileges'][key] ||\n translations.en['plugin-roles-privileges'][key]\n )\n}\n\n/**\n * Generate operation labels based on operation type\n */\nconst getGlobalOperationLabels = (\n operation: GlobalPrivilegeType,\n label: Record<string, string>,\n): Record<string, string> => {\n const result: Record<string, string> = {}\n\n // Get all available languages from label\n const languages = Object.keys(label)\n\n for (const lang of languages) {\n const labelText = label[lang]\n const prefix = getGlobalOperationPrefix(operation, lang)\n result[lang] = `${prefix} ${labelText}`\n }\n\n return result\n}\n\n/**\n * Get operation description templates for each language\n */\nconst getGlobalOperationDescriptionTemplate = (\n operation: GlobalPrivilegeType,\n lang: string,\n): string => {\n const langTranslations = translations[lang] || translations.en\n const key =\n `privilege-template-global-${operation}` as keyof (typeof langTranslations)['plugin-roles-privileges']\n return (\n langTranslations['plugin-roles-privileges'][key] ||\n translations.en['plugin-roles-privileges'][key]\n )\n}\n\n/**\n * Generate operation descriptions based on operation type\n */\nconst getGlobalOperationDescriptions = (\n operation: GlobalPrivilegeType,\n label: Record<string, string>,\n): Record<string, string> => {\n const result: Record<string, string> = {}\n\n // Get all available languages\n const languages = Object.keys(label)\n\n for (const lang of languages) {\n const labelText = label[lang].toLowerCase()\n const template = getGlobalOperationDescriptionTemplate(operation, lang)\n result[lang] = template.replace('{label}', labelText)\n }\n\n return result\n}\n\n/**\n * Generate a single privilege for a global operation\n */\nconst generateGlobalPrivilege = (\n globalSlug: string,\n operation: GlobalPrivilegeType,\n label: Record<string, string>,\n): GlobalPrivilege => {\n return {\n description: getGlobalOperationDescriptions(operation, label),\n label: getGlobalOperationLabels(operation, label),\n privilegeKey: generateGlobalPrivilegeKey(globalSlug, operation),\n }\n}\n\n/**\n * Generate read and update privileges for a global\n */\nexport const generateGlobalPrivileges = (global: GlobalConfig): GlobalPrivileges => {\n const label = getGlobalLabel(global)\n\n const description: Record<string, string> = {}\n const languages = Object.keys(label)\n for (const lang of languages) {\n const labelText = label[lang].toLowerCase()\n const langTranslations = translations[lang] || translations.en\n const template =\n langTranslations['plugin-roles-privileges']['privilege-global-description'] ||\n translations.en['plugin-roles-privileges']['privilege-global-description']\n description[lang] = template.replace('{label}', labelText)\n }\n\n const globalPrivileges: GlobalPrivileges = {\n description,\n globalLabel: label,\n globalSlug: global.slug,\n privileges: {\n read: generateGlobalPrivilege(global.slug, 'read', label),\n readDrafts: generateGlobalPrivilege(global.slug, 'readDrafts', label),\n readVersions: generateGlobalPrivilege(global.slug, 'readVersions', label),\n update: generateGlobalPrivilege(global.slug, 'update', label),\n },\n }\n\n // Store in the map\n allGlobalPrivilegesMap.set(global.slug, globalPrivileges)\n\n return globalPrivileges\n}\n\n/**\n * Get all global privilege keys\n */\nexport const getAllGlobalPrivilegeKeys = (): string[] => {\n const keys: string[] = []\n allGlobalPrivilegesMap.forEach((globalPrivileges) => {\n Object.values(globalPrivileges.privileges).forEach((privilege) => {\n keys.push(privilege.privilegeKey)\n })\n })\n return keys\n}\n\n/**\n * Get all global privileges as a flat array\n */\nexport const getAllGlobalPrivileges = (): GlobalPrivilege[] => {\n const privileges: GlobalPrivilege[] = []\n allGlobalPrivilegesMap.forEach((globalPrivileges) => {\n Object.values(globalPrivileges.privileges).forEach((privilege) => {\n privileges.push(privilege)\n })\n })\n return privileges\n}\n"],"names":["translations","allGlobalPrivilegesMap","Map","generateGlobalPrivilegeKey","globalSlug","operation","capitalize","str","charAt","toUpperCase","slice","getGlobalLabel","global","label","_default","Array","isArray","slug","getGlobalOperationPrefix","lang","langTranslations","en","key","getGlobalOperationLabels","result","languages","Object","keys","labelText","prefix","getGlobalOperationDescriptionTemplate","getGlobalOperationDescriptions","toLowerCase","template","replace","generateGlobalPrivilege","description","privilegeKey","generateGlobalPrivileges","globalPrivileges","globalLabel","privileges","read","readDrafts","readVersions","update","set","getAllGlobalPrivilegeKeys","forEach","values","privilege","push","getAllGlobalPrivileges"],"mappings":"AAEA,SAASA,YAAY,QAAQ,2BAA0B;AAgCvD;;CAEC,GACD,OAAO,MAAMC,yBAAyB,IAAIC,MAA+B;AAEzE;;CAEC,GACD,OAAO,MAAMC,6BAA6B,CACxCC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YAAYQ,OAAOK,IAAI;QACvBwB,YAAY;YACVC,MAAMP,wBAAwBvB,OAAOK,IAAI,EAAE,QAAQJ;YACnD8B,YAAYR,wBAAwBvB,OAAOK,IAAI,EAAE,cAAcJ;YAC/D+B,cAAcT,wBAAwBvB,OAAOK,IAAI,EAAE,gBAAgBJ;YACnEgC,QAAQV,wBAAwBvB,OAAOK,IAAI,EAAE,UAAUJ;QACzD;IACF;IAEA,mBAAmB;IACnBZ,uBAAuB6C,GAAG,CAAClC,OAAOK,IAAI,EAAEsB;IAExC,OAAOA;AACT,EAAC;AAED;;CAEC,GACD,OAAO,MAAMQ,4BAA4B;IACvC,MAAMpB,OAAiB,EAAE;IACzB1B,uBAAuB+C,OAAO,CAAC,CAACT;QAC9Bb,OAAOuB,MAAM,CAACV,iBAAiBE,UAAU,EAAEO,OAAO,CAAC,CAACE;YAClDvB,KAAKwB,IAAI,CAACD,UAAUb,YAAY;QAClC;IACF;IACA,OAAOV;AACT,EAAC;AAED;;CAEC,GACD,OAAO,MAAMyB,yBAAyB;IACpC,MAAMX,aAAgC,EAAE;IACxCxC,uBAAuB+C,OAAO,CAAC,CAACT;QAC9Bb,OAAOuB,MAAM,CAACV,iBAAiBE,UAAU,EAAEO,OAAO,CAAC,CAACE;YAClDT,WAAWU,IAAI,CAACD;QAClB;IACF;IACA,OAAOT;AACT,EAAC"}
@@ -2,31 +2,31 @@ import type { CollectionConfig } from 'payload';
2
2
  /**
3
3
  * Available privilege types for all collection operations
4
4
  */
5
- export type PrivilegeType = 'admin' | 'create' | 'read' | 'readVersions' | 'update' | 'delete' | 'unlock';
5
+ export type PrivilegeType = 'admin' | 'create' | 'delete' | 'read' | 'readVersions' | 'unlock' | 'update';
6
6
  /**
7
7
  * Interface for a single privilege
8
8
  */
9
9
  export interface Privilege {
10
- privilegeKey: string;
11
- label: Record<string, string>;
12
10
  description: Record<string, string>;
13
11
  isCustom?: boolean;
12
+ label: Record<string, string>;
13
+ privilegeKey: string;
14
14
  }
15
15
  /**
16
16
  * Interface for a collection's privileges
17
17
  */
18
18
  export interface CollectionPrivileges {
19
- collectionSlug: string;
20
19
  collectionLabel: Record<string, string>;
20
+ collectionSlug: string;
21
21
  description: Record<string, string>;
22
22
  privileges: {
23
23
  admin: Privilege;
24
24
  create: Privilege;
25
+ delete: Privilege;
25
26
  read: Privilege;
26
27
  readVersions: Privilege;
27
- update: Privilege;
28
- delete: Privilege;
29
28
  unlock: Privilege;
29
+ update: Privilege;
30
30
  };
31
31
  }
32
32
  /**
@@ -100,9 +100,9 @@ import { translations } from '../translations/index.js';
100
100
  * Generate a single privilege for a collection operation
101
101
  */ const generatePrivilege = (collectionSlug, operation, singularLabel, pluralLabel)=>{
102
102
  return {
103
- privilegeKey: generatePrivilegeKey(collectionSlug, operation),
103
+ description: getOperationDescriptions(operation, singularLabel, pluralLabel),
104
104
  label: getOperationLabels(operation, singularLabel),
105
- description: getOperationDescriptions(operation, singularLabel, pluralLabel)
105
+ privilegeKey: generatePrivilegeKey(collectionSlug, operation)
106
106
  };
107
107
  };
108
108
  /**
@@ -119,17 +119,17 @@ import { translations } from '../translations/index.js';
119
119
  description[lang] = template.replace('{label}', plural);
120
120
  }
121
121
  const collectionPrivileges = {
122
- collectionSlug: collection.slug,
123
122
  collectionLabel: pluralLabel,
123
+ collectionSlug: collection.slug,
124
124
  description,
125
125
  privileges: {
126
126
  admin: generatePrivilege(collection.slug, 'admin', singularLabel, pluralLabel),
127
127
  create: generatePrivilege(collection.slug, 'create', singularLabel, pluralLabel),
128
+ delete: generatePrivilege(collection.slug, 'delete', singularLabel, pluralLabel),
128
129
  read: generatePrivilege(collection.slug, 'read', singularLabel, pluralLabel),
129
130
  readVersions: generatePrivilege(collection.slug, 'readVersions', singularLabel, pluralLabel),
130
- update: generatePrivilege(collection.slug, 'update', singularLabel, pluralLabel),
131
- delete: generatePrivilege(collection.slug, 'delete', singularLabel, pluralLabel),
132
- unlock: generatePrivilege(collection.slug, 'unlock', singularLabel, pluralLabel)
131
+ unlock: generatePrivilege(collection.slug, 'unlock', singularLabel, pluralLabel),
132
+ update: generatePrivilege(collection.slug, 'update', singularLabel, pluralLabel)
133
133
  }
134
134
  };
135
135
  // Store in the map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/generatePrivileges.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload'\nimport { translations } from '../translations/index.js'\n\n/**\n * Available privilege types for all collection operations\n */\nexport type PrivilegeType =\n | 'admin'\n | 'create'\n | 'read'\n | 'readVersions'\n | 'update'\n | 'delete'\n | 'unlock'\n\n/**\n * Interface for a single privilege\n */\nexport interface Privilege {\n privilegeKey: string\n label: Record<string, string>\n description: Record<string, string>\n isCustom?: boolean\n}\n\n/**\n * Interface for a collection's privileges\n */\nexport interface CollectionPrivileges {\n collectionSlug: string\n collectionLabel: Record<string, string>\n description: Record<string, string>\n privileges: {\n admin: Privilege\n create: Privilege\n read: Privilege\n readVersions: Privilege\n update: Privilege\n delete: Privilege\n unlock: Privilege\n }\n}\n\n/**\n * Map to store all generated privileges by collection slug\n */\nexport const allPrivilegesMap = new Map<string, CollectionPrivileges>()\n\n/**\n * Generate privilege key from collection slug and operation\n */\nexport const generatePrivilegeKey = (collectionSlug: string, operation: PrivilegeType): string => {\n return `${collectionSlug}-${operation}`\n}\n\n/**\n * Capitalize first letter of a string\n */\nconst capitalize = (str: string): string => {\n return str.charAt(0).toUpperCase() + str.slice(1)\n}\n\n/**\n * Get singular label from collection config or use slug\n */\nconst getSingularLabel = (collection: CollectionConfig): Record<string, string> => {\n if (collection.labels?.singular) {\n if (typeof collection.labels.singular === 'string') {\n // Return the string for all languages (will be used as fallback)\n return { _default: collection.labels.singular }\n }\n if (\n typeof collection.labels.singular === 'object' &&\n !Array.isArray(collection.labels.singular)\n ) {\n return collection.labels.singular as Record<string, string>\n }\n }\n\n // Default to slug\n return { _default: collection.slug }\n}\n\n/**\n * Get plural label from collection config or use slug\n */\nconst getPluralLabel = (collection: CollectionConfig): Record<string, string> => {\n if (collection.labels?.plural) {\n if (typeof collection.labels.plural === 'string') {\n // Return the string for all languages (will be used as fallback)\n return { _default: collection.labels.plural }\n }\n if (typeof collection.labels.plural === 'object' && !Array.isArray(collection.labels.plural)) {\n return collection.labels.plural as Record<string, string>\n }\n }\n\n // Default to slug\n return { _default: collection.slug }\n}\n\n/**\n * Get operation prefix translations for each language\n */\nconst getOperationPrefix = (operation: PrivilegeType, lang: string): string => {\n const langTranslations = translations[lang] || translations.en\n const key =\n `privilege-prefix-${operation}` as keyof (typeof langTranslations)['plugin-roles-privileges']\n return (\n (langTranslations['plugin-roles-privileges'][key] as string) ||\n (translations.en['plugin-roles-privileges'][key] as string)\n )\n}\n\n/**\n * Generate operation labels based on operation type\n */\nconst getOperationLabels = (\n operation: PrivilegeType,\n singularLabel: Record<string, string>,\n): Record<string, string> => {\n const result: Record<string, string> = {}\n\n // Get all available languages from singularLabel\n const languages = Object.keys(singularLabel)\n\n for (const lang of languages) {\n const label = singularLabel[lang]\n const prefix = getOperationPrefix(operation, lang)\n result[lang] = operation === 'readVersions' ? `${prefix} ${label}` : `${prefix} ${label}`\n }\n\n return result\n}\n\n/**\n * Get operation description templates for each language\n */\nconst getOperationDescriptionTemplate = (\n operation: PrivilegeType,\n lang: string,\n): { template: string; usePlural: boolean } => {\n const langTranslations = translations[lang] || translations.en\n const templateKey =\n `privilege-template-${operation}` as keyof (typeof langTranslations)['plugin-roles-privileges']\n const pluralKey =\n `privilege-template-${operation}-plural` as keyof (typeof langTranslations)['plugin-roles-privileges']\n\n const template =\n (langTranslations['plugin-roles-privileges'][templateKey] as string) ||\n (translations.en['plugin-roles-privileges'][templateKey] as string)\n const usePlural = (langTranslations['plugin-roles-privileges'][pluralKey] as string) === 'true'\n\n return { template, usePlural }\n}\n\n/**\n * Generate operation descriptions based on operation type\n */\nconst getOperationDescriptions = (\n operation: PrivilegeType,\n singularLabel: Record<string, string>,\n pluralLabel: Record<string, string>,\n): Record<string, string> => {\n const result: Record<string, string> = {}\n\n // Get all available languages\n const languages = Object.keys(singularLabel)\n\n for (const lang of languages) {\n const { template, usePlural } = getOperationDescriptionTemplate(operation, lang)\n const labelToUse = usePlural ? pluralLabel[lang] : singularLabel[lang]\n result[lang] = template.replace('{label}', labelToUse.toLowerCase())\n }\n\n return result\n}\n\n/**\n * Generate a single privilege for a collection operation\n */\nconst generatePrivilege = (\n collectionSlug: string,\n operation: PrivilegeType,\n singularLabel: Record<string, string>,\n pluralLabel: Record<string, string>,\n): Privilege => {\n return {\n privilegeKey: generatePrivilegeKey(collectionSlug, operation),\n label: getOperationLabels(operation, singularLabel),\n description: getOperationDescriptions(operation, singularLabel, pluralLabel),\n }\n}\n\n/**\n * Generate all CRUD privileges for a collection\n */\nexport const generateCollectionPrivileges = (\n collection: CollectionConfig,\n): CollectionPrivileges => {\n const singularLabel = getSingularLabel(collection)\n const pluralLabel = getPluralLabel(collection)\n\n const description: Record<string, string> = {}\n const languages = Object.keys(pluralLabel)\n for (const lang of languages) {\n const plural = pluralLabel[lang].toLowerCase()\n const langTranslations = translations[lang] || translations.en\n const template =\n (langTranslations['plugin-roles-privileges']['privilege-collection-description'] as string) ||\n (translations.en['plugin-roles-privileges']['privilege-collection-description'] as string)\n description[lang] = template.replace('{label}', plural)\n }\n\n const collectionPrivileges: CollectionPrivileges = {\n collectionSlug: collection.slug,\n collectionLabel: pluralLabel,\n description,\n privileges: {\n admin: generatePrivilege(collection.slug, 'admin', singularLabel, pluralLabel),\n create: generatePrivilege(collection.slug, 'create', singularLabel, pluralLabel),\n read: generatePrivilege(collection.slug, 'read', singularLabel, pluralLabel),\n readVersions: generatePrivilege(collection.slug, 'readVersions', singularLabel, pluralLabel),\n update: generatePrivilege(collection.slug, 'update', singularLabel, pluralLabel),\n delete: generatePrivilege(collection.slug, 'delete', singularLabel, pluralLabel),\n unlock: generatePrivilege(collection.slug, 'unlock', singularLabel, pluralLabel),\n },\n }\n\n // Store in the map\n allPrivilegesMap.set(collection.slug, collectionPrivileges)\n\n return collectionPrivileges\n}\n\n/**\n * Get all privilege keys as a union type\n */\nexport const getAllPrivilegeKeys = (): string[] => {\n const keys: string[] = []\n allPrivilegesMap.forEach((collectionPrivileges) => {\n Object.values(collectionPrivileges.privileges).forEach((privilege) => {\n keys.push(privilege.privilegeKey)\n })\n })\n return keys\n}\n\n/**\n * Get all privileges as a flat array\n */\nexport const getAllPrivileges = (): Privilege[] => {\n const privileges: Privilege[] = []\n allPrivilegesMap.forEach((collectionPrivileges) => {\n Object.values(collectionPrivileges.privileges).forEach((privilege) => {\n privileges.push(privilege)\n })\n })\n return privileges\n}\n"],"names":["translations","allPrivilegesMap","Map","generatePrivilegeKey","collectionSlug","operation","capitalize","str","charAt","toUpperCase","slice","getSingularLabel","collection","labels","singular","_default","Array","isArray","slug","getPluralLabel","plural","getOperationPrefix","lang","langTranslations","en","key","getOperationLabels","singularLabel","result","languages","Object","keys","label","prefix","getOperationDescriptionTemplate","templateKey","pluralKey","template","usePlural","getOperationDescriptions","pluralLabel","labelToUse","replace","toLowerCase","generatePrivilege","privilegeKey","description","generateCollectionPrivileges","collectionPrivileges","collectionLabel","privileges","admin","create","read","readVersions","update","delete","unlock","set","getAllPrivilegeKeys","forEach","values","privilege","push","getAllPrivileges"],"mappings":"AACA,SAASA,YAAY,QAAQ,2BAA0B;AA0CvD;;CAEC,GACD,OAAO,MAAMC,mBAAmB,IAAIC,MAAmC;AAEvE;;CAEC,GACD,OAAO,MAAMC,uBAAuB,CAACC,gBAAwBC;IAC3D,OAAO,GAAGD,eAAe,CAAC,EAAEC,WAAW;AACzC,EAAC;AAED;;CAEC,GACD,MAAMC,aAAa,CAACC;IAClB,OAAOA,IAAIC,MAAM,CAAC,GAAGC,WAAW,KAAKF,IAAIG,KAAK,CAAC;AACjD;AAEA;;CAEC,GACD,MAAMC,mBAAmB,CAACC;IACxB,IAAIA,WAAWC,MAAM,EAAEC,UAAU;QAC/B,IAAI,OAAOF,WAAWC,MAAM,CAACC,QAAQ,KAAK,UAAU;YA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AC,CAACZ;QACxBlB,OAAO+B,MAAM,CAACb,qBAAqBE,UAAU,EAAEU,OAAO,CAAC,CAACE;YACtD/B,KAAKgC,IAAI,CAACD,UAAUjB,YAAY;QAClC;IACF;IACA,OAAOd;AACT,EAAC;AAED;;CAEC,GACD,OAAO,MAAMiC,mBAAmB;IAC9B,MAAMd,aAA0B,EAAE;IAClCjD,iBAAiB2D,OAAO,CAAC,CAACZ;QACxBlB,OAAO+B,MAAM,CAACb,qBAAqBE,UAAU,EAAEU,OAAO,CAAC,CAACE;YACtDZ,WAAWa,IAAI,CAACD;QAClB;IACF;IACA,OAAOZ;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/utils/generatePrivileges.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload'\n\nimport { translations } from '../translations/index.js'\n\n/**\n * Available privilege types for all collection operations\n */\nexport type PrivilegeType =\n | 'admin'\n | 'create'\n | 'delete'\n | 'read'\n | 'readVersions'\n | 'unlock'\n | 'update'\n\n/**\n * Interface for a single privilege\n */\nexport interface Privilege {\n description: Record<string, string>\n isCustom?: boolean\n label: Record<string, string>\n privilegeKey: string\n}\n\n/**\n * Interface for a collection's privileges\n */\nexport interface CollectionPrivileges {\n collectionLabel: Record<string, string>\n collectionSlug: string\n description: Record<string, string>\n privileges: {\n admin: Privilege\n create: Privilege\n delete: Privilege\n read: Privilege\n readVersions: Privilege\n unlock: Privilege\n update: Privilege\n }\n}\n\n/**\n * Map to store all generated privileges by collection slug\n */\nexport const allPrivilegesMap = new Map<string, CollectionPrivileges>()\n\n/**\n * Generate privilege key from collection slug and operation\n */\nexport const generatePrivilegeKey = (collectionSlug: string, operation: PrivilegeType): string => {\n return `${collectionSlug}-${operation}`\n}\n\n/**\n * Capitalize first letter of a string\n */\nconst capitalize = (str: string): string => {\n return str.charAt(0).toUpperCase() + str.slice(1)\n}\n\n/**\n * Get singular label from collection config or use slug\n */\nconst getSingularLabel = (collection: CollectionConfig): Record<string, string> => {\n if (collection.labels?.singular) {\n if (typeof collection.labels.singular === 'string') {\n // Return the string for all languages (will be used as fallback)\n return { _default: collection.labels.singular }\n }\n if (\n typeof collection.labels.singular === 'object' &&\n !Array.isArray(collection.labels.singular)\n ) {\n return collection.labels.singular\n }\n }\n\n // Default to slug\n return { _default: collection.slug }\n}\n\n/**\n * Get plural label from collection config or use slug\n */\nconst getPluralLabel = (collection: CollectionConfig): Record<string, string> => {\n if (collection.labels?.plural) {\n if (typeof collection.labels.plural === 'string') {\n // Return the string for all languages (will be used as fallback)\n return { _default: collection.labels.plural }\n }\n if (typeof collection.labels.plural === 'object' && !Array.isArray(collection.labels.plural)) {\n return collection.labels.plural\n }\n }\n\n // Default to slug\n return { _default: collection.slug }\n}\n\n/**\n * Get operation prefix translations for each language\n */\nconst getOperationPrefix = (operation: PrivilegeType, lang: string): string => {\n const langTranslations = translations[lang] || translations.en\n const key =\n `privilege-prefix-${operation}` as keyof (typeof langTranslations)['plugin-roles-privileges']\n return (\n langTranslations['plugin-roles-privileges'][key] ||\n translations.en['plugin-roles-privileges'][key]\n )\n}\n\n/**\n * Generate operation labels based on operation type\n */\nconst getOperationLabels = (\n operation: PrivilegeType,\n singularLabel: Record<string, string>,\n): Record<string, string> => {\n const result: Record<string, string> = {}\n\n // Get all available languages from singularLabel\n const languages = Object.keys(singularLabel)\n\n for (const lang of languages) {\n const label = singularLabel[lang]\n const prefix = getOperationPrefix(operation, lang)\n result[lang] = operation === 'readVersions' ? `${prefix} ${label}` : `${prefix} ${label}`\n }\n\n return result\n}\n\n/**\n * Get operation description templates for each language\n */\nconst getOperationDescriptionTemplate = (\n operation: PrivilegeType,\n lang: string,\n): { template: string; usePlural: boolean } => {\n const langTranslations = translations[lang] || translations.en\n const templateKey =\n `privilege-template-${operation}` as keyof (typeof langTranslations)['plugin-roles-privileges']\n const pluralKey =\n `privilege-template-${operation}-plural` as keyof (typeof langTranslations)['plugin-roles-privileges']\n\n const template =\n langTranslations['plugin-roles-privileges'][templateKey] ||\n translations.en['plugin-roles-privileges'][templateKey]\n const usePlural = langTranslations['plugin-roles-privileges'][pluralKey] === 'true'\n\n return { template, usePlural }\n}\n\n/**\n * Generate operation descriptions based on operation type\n */\nconst getOperationDescriptions = (\n operation: PrivilegeType,\n singularLabel: Record<string, string>,\n pluralLabel: Record<string, string>,\n): Record<string, string> => {\n const result: Record<string, string> = {}\n\n // Get all available languages\n const languages = Object.keys(singularLabel)\n\n for (const lang of languages) {\n const { template, usePlural } = getOperationDescriptionTemplate(operation, lang)\n const labelToUse = usePlural ? pluralLabel[lang] : singularLabel[lang]\n result[lang] = template.replace('{label}', labelToUse.toLowerCase())\n }\n\n return result\n}\n\n/**\n * Generate a single privilege for a collection operation\n */\nconst generatePrivilege = (\n collectionSlug: string,\n operation: PrivilegeType,\n singularLabel: Record<string, string>,\n pluralLabel: Record<string, string>,\n): Privilege => {\n return {\n description: getOperationDescriptions(operation, singularLabel, pluralLabel),\n label: getOperationLabels(operation, singularLabel),\n privilegeKey: generatePrivilegeKey(collectionSlug, operation),\n }\n}\n\n/**\n * Generate all CRUD privileges for a collection\n */\nexport const generateCollectionPrivileges = (\n collection: CollectionConfig,\n): CollectionPrivileges => {\n const singularLabel = getSingularLabel(collection)\n const pluralLabel = getPluralLabel(collection)\n\n const description: Record<string, string> = {}\n const languages = Object.keys(pluralLabel)\n for (const lang of languages) {\n const plural = pluralLabel[lang].toLowerCase()\n const langTranslations = translations[lang] || translations.en\n const template =\n langTranslations['plugin-roles-privileges']['privilege-collection-description'] ||\n translations.en['plugin-roles-privileges']['privilege-collection-description']\n description[lang] = template.replace('{label}', plural)\n }\n\n const collectionPrivileges: CollectionPrivileges = {\n collectionLabel: pluralLabel,\n collectionSlug: collection.slug,\n description,\n privileges: {\n admin: generatePrivilege(collection.slug, 'admin', singularLabel, pluralLabel),\n create: generatePrivilege(collection.slug, 'create', singularLabel, pluralLabel),\n delete: generatePrivilege(collection.slug, 'delete', singularLabel, pluralLabel),\n read: generatePrivilege(collection.slug, 'read', singularLabel, pluralLabel),\n readVersions: generatePrivilege(collection.slug, 'readVersions', singularLabel, pluralLabel),\n unlock: generatePrivilege(collection.slug, 'unlock', singularLabel, pluralLabel),\n update: generatePrivilege(collection.slug, 'update', singularLabel, pluralLabel),\n },\n }\n\n // Store in the map\n allPrivilegesMap.set(collection.slug, collectionPrivileges)\n\n return collectionPrivileges\n}\n\n/**\n * Get all privilege keys as a union type\n */\nexport const getAllPrivilegeKeys = (): string[] => {\n const keys: string[] = []\n allPrivilegesMap.forEach((collectionPrivileges) => {\n Object.values(collectionPrivileges.privileges).forEach((privilege) => {\n keys.push(privilege.privilegeKey)\n })\n })\n return keys\n}\n\n/**\n * Get all privileges as a flat array\n */\nexport const getAllPrivileges = (): Privilege[] => {\n const privileges: Privilege[] = []\n allPrivilegesMap.forEach((collectionPrivileges) => {\n Object.values(collectionPrivileges.privileges).forEach((privilege) => {\n privileges.push(privilege)\n })\n })\n return privileges\n}\n"],"names":["translations","allPrivilegesMap","Map","generatePrivilegeKey","collectionSlug","operation","capitalize","str","charAt","toUpperCase","slice","getSingularLabel","collection","labels","singular","_default","Array","isArray","slug","getPluralLabel","plural","getOperationPrefix","lang","langTranslations","en","key","getOperationLabels","singularLabel","result","languages","Object","keys","label","prefix","getOperationDescriptionTemplate","templateKey","pluralKey","template","usePlural","getOperationDescriptions","pluralLabel","labelToUse","replace","toLowerCase","generatePrivilege","description","privilegeKey","generateCollectionPrivileges","collectionPrivileges","collectionLabel","privileges","admin","create","delete","read","readVersions","unlock","update","set","getAllPrivilegeKeys","forEach","values","privilege","push","getAllPrivileges"],"mappings":"AAEA,SAASA,YAAY,QAAQ,2BAA0B;AA0CvD;;CAEC,GACD,OAAO,MAAMC,mBAAmB,IAAIC,MAAmC;AAEvE;;CAEC,GACD,OAAO,MAAMC,uBAAuB,CAACC,gBAAwBC;IAC3D,OAAO,GAAGD,eAAe,CAAC,EAAEC,WAAW;AACzC,EAAC;AAED;;CAEC,GACD,MAAMC,aAAa,CAACC;IAClB,OAAO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,mBAAmB;IACnBvC,iBAAiByD,GAAG,CAAC9C,WAAWM,IAAI,EAAE8B;IAEtC,OAAOA;AACT,EAAC;AAED;;CAEC,GACD,OAAO,MAAMW,sBAAsB;IACjC,MAAM5B,OAAiB,EAAE;IACzB9B,iBAAiB2D,OAAO,CAAC,CAACZ;QACxBlB,OAAO+B,MAAM,CAACb,qBAAqBE,UAAU,EAAEU,OAAO,CAAC,CAACE;YACtD/B,KAAKgC,IAAI,CAACD,UAAUhB,YAAY;QAClC;IACF;IACA,OAAOf;AACT,EAAC;AAED;;CAEC,GACD,OAAO,MAAMiC,mBAAmB;IAC9B,MAAMd,aAA0B,EAAE;IAClCjD,iBAAiB2D,OAAO,CAAC,CAACZ;QACxBlB,OAAO+B,MAAM,CAACb,qBAAqBE,UAAU,EAAEU,OAAO,CAAC,CAACE;YACtDZ,WAAWa,IAAI,CAACD;QAClB;IACF;IACA,OAAOZ;AACT,EAAC"}
@@ -19,23 +19,23 @@ import { getAllPrivileges } from './generatePrivileges.js';
19
19
  ;
20
20
  const existingRole = await payload.find({
21
21
  collection: 'roles',
22
+ limit: 1,
22
23
  where: {
23
24
  slug: {
24
25
  equals: 'super-admin'
25
26
  }
26
- },
27
- limit: 1
27
+ }
28
28
  });
29
29
  if (existingRole.docs.length > 0) {
30
30
  // Update existing Super Admin role
31
31
  await payload.update({
32
- collection: 'roles',
33
32
  id: existingRole.docs[0].id,
33
+ collection: 'roles',
34
34
  data: {
35
- title: 'Super Admin',
36
35
  slug: 'super-admin',
36
+ description: 'Super administrator with full system access and all privileges',
37
37
  privileges: privilegesArray,
38
- description: 'Super administrator with full system access and all privileges'
38
+ title: 'Super Admin'
39
39
  }
40
40
  });
41
41
  payload.logger.info('✅ Super Admin role updated with all privileges');
@@ -44,10 +44,10 @@ import { getAllPrivileges } from './generatePrivileges.js';
44
44
  await payload.create({
45
45
  collection: 'roles',
46
46
  data: {
47
- title: 'Super Admin',
48
47
  slug: 'super-admin',
48
+ description: 'Super administrator with full system access and all privileges',
49
49
  privileges: privilegesArray,
50
- description: 'Super administrator with full system access and all privileges'
50
+ title: 'Super Admin'
51
51
  }
52
52
  });
53
53
  payload.logger.info('✅ Super Admin role created with all privileges');
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/seedSuperAdminRole.ts"],"sourcesContent":["import type { Payload } from 'payload'\nimport { getAllGlobalPrivileges } from './generateGlobalPrivileges.js'\nimport { getAllPrivileges } from './generatePrivileges.js'\n\n/**\n * Seeds or updates the Super Admin role with all available privileges\n * This ensures the Super Admin role always has access to all privileges in the system\n */\nexport const seedSuperAdminRole = async (payload: Payload): Promise<void> => {\n try {\n // Get all available privileges from collections and globals\n const collectionPrivileges = getAllPrivileges()\n const globalPrivileges = getAllGlobalPrivileges()\n\n const privilegesArray = [\n ...collectionPrivileges.map((privilege) => ({\n privilege: privilege.privilegeKey,\n })),\n ...globalPrivileges.map((privilege) => ({\n privilege: privilege.privilegeKey,\n })),\n ] // Check if Super Admin role exists\n const existingRole = await payload.find({\n collection: 'roles',\n where: {\n slug: {\n equals: 'super-admin',\n },\n },\n limit: 1,\n })\n\n if (existingRole.docs.length > 0) {\n // Update existing Super Admin role\n await payload.update({\n collection: 'roles',\n id: existingRole.docs[0].id,\n data: {\n title: 'Super Admin',\n slug: 'super-admin',\n privileges: privilegesArray,\n description: 'Super administrator with full system access and all privileges',\n },\n })\n payload.logger.info('✅ Super Admin role updated with all privileges')\n } else {\n // Create new Super Admin role\n await payload.create({\n collection: 'roles',\n data: {\n title: 'Super Admin',\n slug: 'super-admin',\n privileges: privilegesArray,\n description: 'Super administrator with full system access and all privileges',\n },\n })\n payload.logger.info('✅ Super Admin role created with all privileges')\n }\n } catch (error) {\n payload.logger.error('❌ Error seeding Super Admin role:', error)\n }\n}\n"],"names":["getAllGlobalPrivileges","getAllPrivileges","seedSuperAdminRole","payload","collectionPrivileges","globalPrivileges","privilegesArray","map","privilege","privilegeKey","existingRole","find","collection","where","slug","equals","limit","docs","length","update","id","data","title","privileges","description","logger","info","create","error"],"mappings":"AACA,SAASA,sBAAsB,QAAQ,gCAA+B;AACtE,SAASC,gBAAgB,QAAQ,0BAAyB;AAE1D;;;CAGC,GACD,OAAO,MAAMC,qBAAqB,OAAOC;IACvC,IAAI;QACF,4DAA4D;QAC5D,MAAMC,uBAAuBH;QAC7B,MAAMI,mBAAmBL;QAEzB,MAAMM,kBAAkB;eACnBF,qBAAqBG,GAAG,CAAC,CAACC,YAAe,CAAA;oBAC1CA,WAAWA,UAAUC,YAAY;gBACnC,CAAA;eACGJ,iBAAiBE,GAAG,CAAC,CAACC,YAAe,CAAA;oBACtCA,WAAWA,UAAUC,YAAY;gBACnC,CAAA;SACD,CAAC,mCAAmC;;QACrC,MAAMC,eAAe,MAAMP,QAAQQ,IAAI,CAAC;YACtCC,YAAY;YACZC,OAAO;gBACLC,MAAM;oBACJC,QAAQ;gBACV;YACF;YACAC,OAAO;QACT;QAEA,IAAIN,aAAaO,IAAI,CAACC,MAAM,GAAG,GAAG;YAChC,mCAAmC;YACnC,MAAMf,QAAQgB,MAAM,CAAC;gBACnBP,YAAY;gBACZQ,IAAIV,aAAaO,IAAI,CAAC,EAAE,CAACG,EAAE;gBAC3BC,MAAM;oBACJC,OAAO;oBACPR,MAAM;oBACNS,YAAYjB;oBACZkB,aAAa;gBACf;YACF;YACArB,QAAQsB,MAAM,CAACC,IAAI,CAAC;QACtB,OAAO;YACL,8BAA8B;YAC9B,MAAMvB,QAAQwB,MAAM,CAAC;gBACnBf,YAAY;gBACZS,MAAM;oBACJC,OAAO;oBACPR,MAAM;oBACNS,YAAYjB;oBACZkB,aAAa;gBACf;YACF;YACArB,QAAQsB,MAAM,CAACC,IAAI,CAAC;QACtB;IACF,EAAE,OAAOE,OAAO;QACdzB,QAAQsB,MAAM,CAACG,KAAK,CAAC,qCAAqCA;IAC5D;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/utils/seedSuperAdminRole.ts"],"sourcesContent":["import type { Payload } from 'payload'\n\nimport { getAllGlobalPrivileges } from './generateGlobalPrivileges.js'\nimport { getAllPrivileges } from './generatePrivileges.js'\n\n/**\n * Seeds or updates the Super Admin role with all available privileges\n * This ensures the Super Admin role always has access to all privileges in the system\n */\nexport const seedSuperAdminRole = async (payload: Payload): Promise<void> => {\n try {\n // Get all available privileges from collections and globals\n const collectionPrivileges = getAllPrivileges()\n const globalPrivileges = getAllGlobalPrivileges()\n\n const privilegesArray = [\n ...collectionPrivileges.map((privilege) => ({\n privilege: privilege.privilegeKey,\n })),\n ...globalPrivileges.map((privilege) => ({\n privilege: privilege.privilegeKey,\n })),\n ] // Check if Super Admin role exists\n const existingRole = await payload.find({\n collection: 'roles',\n limit: 1,\n where: {\n slug: {\n equals: 'super-admin',\n },\n },\n })\n\n if (existingRole.docs.length > 0) {\n // Update existing Super Admin role\n await payload.update({\n id: existingRole.docs[0].id,\n collection: 'roles',\n data: {\n slug: 'super-admin',\n description: 'Super administrator with full system access and all privileges',\n privileges: privilegesArray,\n title: 'Super Admin',\n },\n })\n payload.logger.info('✅ Super Admin role updated with all privileges')\n } else {\n // Create new Super Admin role\n await payload.create({\n collection: 'roles',\n data: {\n slug: 'super-admin',\n description: 'Super administrator with full system access and all privileges',\n privileges: privilegesArray,\n title: 'Super Admin',\n },\n })\n payload.logger.info('✅ Super Admin role created with all privileges')\n }\n } catch (error) {\n payload.logger.error('❌ Error seeding Super Admin role:', error)\n }\n}\n"],"names":["getAllGlobalPrivileges","getAllPrivileges","seedSuperAdminRole","payload","collectionPrivileges","globalPrivileges","privilegesArray","map","privilege","privilegeKey","existingRole","find","collection","limit","where","slug","equals","docs","length","update","id","data","description","privileges","title","logger","info","create","error"],"mappings":"AAEA,SAASA,sBAAsB,QAAQ,gCAA+B;AACtE,SAASC,gBAAgB,QAAQ,0BAAyB;AAE1D;;;CAGC,GACD,OAAO,MAAMC,qBAAqB,OAAOC;IACvC,IAAI;QACF,4DAA4D;QAC5D,MAAMC,uBAAuBH;QAC7B,MAAMI,mBAAmBL;QAEzB,MAAMM,kBAAkB;eACnBF,qBAAqBG,GAAG,CAAC,CAACC,YAAe,CAAA;oBAC1CA,WAAWA,UAAUC,YAAY;gBACnC,CAAA;eACGJ,iBAAiBE,GAAG,CAAC,CAACC,YAAe,CAAA;oBACtCA,WAAWA,UAAUC,YAAY;gBACnC,CAAA;SACD,CAAC,mCAAmC;;QACrC,MAAMC,eAAe,MAAMP,QAAQQ,IAAI,CAAC;YACtCC,YAAY;YACZC,OAAO;YACPC,OAAO;gBACLC,MAAM;oBACJC,QAAQ;gBACV;YACF;QACF;QAEA,IAAIN,aAAaO,IAAI,CAACC,MAAM,GAAG,GAAG;YAChC,mCAAmC;YACnC,MAAMf,QAAQgB,MAAM,CAAC;gBACnBC,IAAIV,aAAaO,IAAI,CAAC,EAAE,CAACG,EAAE;gBAC3BR,YAAY;gBACZS,MAAM;oBACJN,MAAM;oBACNO,aAAa;oBACbC,YAAYjB;oBACZkB,OAAO;gBACT;YACF;YACArB,QAAQsB,MAAM,CAACC,IAAI,CAAC;QACtB,OAAO;YACL,8BAA8B;YAC9B,MAAMvB,QAAQwB,MAAM,CAAC;gBACnBf,YAAY;gBACZS,MAAM;oBACJN,MAAM;oBACNO,aAAa;oBACbC,YAAYjB;oBACZkB,OAAO;gBACT;YACF;YACArB,QAAQsB,MAAM,CAACC,IAAI,CAAC;QACtB;IACF,EAAE,OAAOE,OAAO;QACdzB,QAAQsB,MAAM,CAACG,KAAK,CAAC,qCAAqCA;IAC5D;AACF,EAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roles-privileges-payload-plugin",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "Automatic role-based access control (RBAC) plugin for Payload CMS that generates granular CRUD privileges for all collections with beautiful UI and zero configuration",
5
5
  "keywords": [
6
6
  "payload",
@@ -34,28 +34,28 @@
34
34
  "type": "module",
35
35
  "exports": {
36
36
  ".": {
37
- "import": "./src/index.ts",
38
- "types": "./src/index.ts",
39
- "default": "./src/index.ts"
37
+ "import": "./dist/index.js",
38
+ "types": "./dist/index.d.ts",
39
+ "default": "./dist/index.js"
40
40
  },
41
41
  "./client": {
42
- "import": "./src/exports/client.ts",
43
- "types": "./src/exports/client.ts",
44
- "default": "./src/exports/client.ts"
42
+ "import": "./dist/exports/client.js",
43
+ "types": "./dist/exports/client.d.ts",
44
+ "default": "./dist/exports/client.js"
45
45
  },
46
46
  "./utilities": {
47
- "import": "./src/exports/utilities.ts",
48
- "types": "./src/exports/utilities.ts",
49
- "default": "./src/exports/utilities.ts"
47
+ "import": "./dist/exports/utilities.js",
48
+ "types": "./dist/exports/utilities.d.ts",
49
+ "default": "./dist/exports/utilities.js"
50
50
  },
51
51
  "./types": {
52
- "import": "./src/exports/types.ts",
53
- "types": "./src/exports/types.ts",
54
- "default": "./src/exports/types.ts"
52
+ "import": "./dist/exports/types.js",
53
+ "types": "./dist/exports/types.d.ts",
54
+ "default": "./dist/exports/types.js"
55
55
  }
56
56
  },
57
- "main": "./src/index.ts",
58
- "types": "./src/index.ts",
57
+ "main": "./dist/index.js",
58
+ "types": "./dist/index.d.ts",
59
59
  "files": [
60
60
  "dist"
61
61
  ],