@zealamic/payload-auth-rbac-plugin 1.0.0-beta.9 → 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 (57) hide show
  1. package/README.md +27 -31
  2. package/assets/cover-photo.jpg +0 -0
  3. package/dist/components/role-permission-matrix-client/default-data.js +3 -2
  4. package/dist/components/role-permission-matrix-client/default-data.js.map +1 -1
  5. package/dist/components/role-permission-matrix-client/index.js +20 -70
  6. package/dist/components/role-permission-matrix-client/index.js.map +1 -1
  7. package/dist/components/role-permission-matrix-client/matrix.module.scss +66 -0
  8. package/dist/components/role-permission-matrix-client/types.d.ts +4 -6
  9. package/dist/components/role-permission-matrix-client/types.js.map +1 -1
  10. package/dist/styles/variables.scss +1 -0
  11. package/docs/COLLECTIONS.md +440 -0
  12. package/docs/TRANSLATIONS.md +469 -0
  13. package/docs/UTILS.md +226 -0
  14. package/package.json +7 -28
  15. package/src/collections/permission-actions/default-data.ts +36 -0
  16. package/src/collections/permission-actions/index.ts +144 -0
  17. package/src/collections/permission-actions/types.ts +56 -0
  18. package/src/collections/permission-features/default-data.ts +30 -0
  19. package/src/collections/permission-features/index.ts +122 -0
  20. package/src/collections/permission-features/types.ts +47 -0
  21. package/src/collections/permissions/default-data.ts +38 -0
  22. package/src/collections/permissions/index.ts +160 -0
  23. package/src/collections/permissions/types.ts +57 -0
  24. package/src/collections/roles/default-data.ts +44 -0
  25. package/src/collections/roles/hooks/sync-permission-matrix-draft.ts +73 -0
  26. package/src/collections/roles/index.ts +178 -0
  27. package/src/collections/roles/types.ts +56 -0
  28. package/src/collections/roles-permissions/default-data.ts +28 -0
  29. package/src/collections/roles-permissions/index.ts +107 -0
  30. package/src/collections/roles-permissions/types.ts +42 -0
  31. package/src/collections/users/default-data.ts +19 -0
  32. package/src/collections/users/index.ts +148 -0
  33. package/src/collections/users/parent-path.ts +310 -0
  34. package/src/collections/users/types.ts +25 -0
  35. package/src/components/role-permission-matrix-client/default-data.ts +25 -0
  36. package/src/components/role-permission-matrix-client/index.tsx +369 -0
  37. package/src/components/role-permission-matrix-client/matrix.module.scss +66 -0
  38. package/src/components/role-permission-matrix-client/types.ts +16 -0
  39. package/src/endpoints/customEndpointHandler.ts +5 -0
  40. package/src/exports/client.ts +1 -0
  41. package/src/exports/rsc.ts +0 -0
  42. package/src/general-types.d.ts +5 -0
  43. package/src/index.ts +249 -0
  44. package/src/lib/constants/general.ts +1 -0
  45. package/src/lib/constants/index.ts +15 -0
  46. package/src/lib/constants/permission-action.ts +9 -0
  47. package/src/lib/constants/permission-feature.ts +4 -0
  48. package/src/lib/constants/permission.ts +4 -0
  49. package/src/lib/constants/role.ts +10 -0
  50. package/src/lib/constants/user.ts +1 -0
  51. package/src/lib/utils/access.ts +611 -0
  52. package/src/lib/utils/data.ts +7 -0
  53. package/src/lib/utils/fields.ts +62 -0
  54. package/src/lib/utils/index.ts +4 -0
  55. package/src/lib/utils/localization.ts +106 -0
  56. package/src/styles/variables.scss +1 -0
  57. package/src/types.ts +64 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zealamic/payload-auth-rbac-plugin",
3
- "version": "1.0.0-beta.9",
3
+ "version": "1.0.1",
4
4
  "description": "A plugin for Payload CMS to manage authentication and authorization",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -46,10 +46,13 @@
46
46
  "types": "./src/general.d.ts",
47
47
  "files": [
48
48
  "dist",
49
- "docs/cover-photo.jpg"
49
+ "docs",
50
+ "assets",
51
+ "src"
50
52
  ],
51
53
  "scripts": {
52
- "build": "yarn copyfiles && yarn build:types && yarn build:swc",
54
+ "copy:styles": "node -e \"require('fs').cpSync('src/styles', 'dist/styles', {recursive:true})\"",
55
+ "build": "yarn copyfiles && yarn build:types && yarn build:swc && yarn copy:styles",
53
56
  "build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
54
57
  "build:types": "tsc --outDir dist --rootDir ./src",
55
58
  "clean": "rimraf {dist,*.tsbuildinfo}",
@@ -106,31 +109,7 @@
106
109
  "node": "^18.20.2 || >=20.9.0"
107
110
  },
108
111
  "publishConfig": {
109
- "access": "public",
110
- "main": "./dist/index.js",
111
- "types": "./dist/index.d.ts",
112
- "exports": {
113
- ".": {
114
- "types": "./dist/index.d.ts",
115
- "default": "./dist/index.js"
116
- },
117
- "./client": {
118
- "types": "./dist/exports/client.d.ts",
119
- "default": "./dist/exports/client.js"
120
- },
121
- "./rsc": {
122
- "types": "./dist/exports/rsc.d.ts",
123
- "default": "./dist/exports/rsc.js"
124
- },
125
- "./types": {
126
- "types": "./dist/types.d.ts",
127
- "default": "./dist/types.js"
128
- },
129
- "./utils": {
130
- "types": "./dist/lib/utils/index.d.ts",
131
- "default": "./dist/lib/utils/index.js"
132
- }
133
- }
112
+ "access": "public"
134
113
  },
135
114
  "registry": "https://registry.npmjs.org/",
136
115
  "dependencies": {}
@@ -0,0 +1,36 @@
1
+ import type { PermissionActionsCollectionTranslations } from "./types.js";
2
+
3
+ export const permissionActionsDefaultTranslations: PermissionActionsCollectionTranslations =
4
+ {
5
+ en: {
6
+ labels: {
7
+ singular: "Permission Action",
8
+ plural: "Permission Actions",
9
+ },
10
+ admin: {
11
+ group: "System",
12
+ },
13
+ fields: {
14
+ code: {
15
+ label: "Code",
16
+ placeholder: "Enter code",
17
+ },
18
+ type: {
19
+ label: "Type",
20
+ placeholder: "Select type",
21
+ mainLabel: "Main",
22
+ subLabel: "Sub",
23
+ },
24
+ sortOrder: {
25
+ label: "Sort Order",
26
+ placeholder: "Enter sort order",
27
+ },
28
+ status: {
29
+ label: "Status",
30
+ placeholder: "Select status",
31
+ activeLabel: "Active",
32
+ inactiveLabel: "Inactive",
33
+ },
34
+ },
35
+ },
36
+ };
@@ -0,0 +1,144 @@
1
+ import type { CollectionConfig } from "payload";
2
+ import { STATUS, TYPE } from "../../lib/constants/permission-action.js";
3
+ import {
4
+ getArrayOfMergedFieldAffectingData,
5
+ getSuperAdminAccess,
6
+ toLocaleRecord,
7
+ toSelectPlaceholder,
8
+ } from "../../lib/utils/index.js";
9
+ import type { PermissionActionsCollectionParams } from "./types.js";
10
+
11
+ export const getPermissionActionsCollection = (
12
+ params: PermissionActionsCollectionParams,
13
+ ) => {
14
+ const {
15
+ translations = {},
16
+ access = {},
17
+ fields = [],
18
+ labels = {},
19
+ admin = {},
20
+ } = params || {};
21
+ const arrTranslationsKeys = Object.keys(translations);
22
+ const permissionActions: CollectionConfig = {
23
+ slug: "permission-actions",
24
+ labels: {
25
+ singular: toLocaleRecord(
26
+ arrTranslationsKeys,
27
+ (locale) => translations[locale]?.labels?.singular,
28
+ ),
29
+ plural: toLocaleRecord(
30
+ arrTranslationsKeys,
31
+ (locale) => translations[locale]?.labels?.plural,
32
+ ),
33
+ ...labels,
34
+ },
35
+ admin: {
36
+ group: toLocaleRecord(
37
+ arrTranslationsKeys,
38
+ (locale) => translations[locale]?.admin?.group,
39
+ ),
40
+ useAsTitle: "code",
41
+ defaultColumns: ["code", "type", "status", "updatedAt"],
42
+ ...admin,
43
+ },
44
+ access: {
45
+ create: getSuperAdminAccess,
46
+ update: getSuperAdminAccess,
47
+ delete: getSuperAdminAccess,
48
+ read: getSuperAdminAccess,
49
+ readVersions: getSuperAdminAccess,
50
+ unlock: getSuperAdminAccess,
51
+ admin: ({ req }) => {
52
+ return getSuperAdminAccess({ req });
53
+ },
54
+ ...access,
55
+ },
56
+ fields: getArrayOfMergedFieldAffectingData({
57
+ fields,
58
+ defaultFields: [
59
+ {
60
+ name: "code",
61
+ type: "text",
62
+ required: true,
63
+ unique: true,
64
+ index: true,
65
+ label: toLocaleRecord(
66
+ arrTranslationsKeys,
67
+ (locale) => translations[locale]?.fields?.code?.label,
68
+ ),
69
+ admin: {
70
+ placeholder: toLocaleRecord(
71
+ arrTranslationsKeys,
72
+ (locale) => translations[locale]?.fields?.code?.placeholder,
73
+ ),
74
+ },
75
+ },
76
+ {
77
+ name: "type",
78
+ type: "select",
79
+ required: true,
80
+ label: toLocaleRecord(
81
+ arrTranslationsKeys,
82
+ (locale) => translations[locale]?.fields?.type?.label,
83
+ ),
84
+ options: Object.values(TYPE).map((type) => ({
85
+ label: toLocaleRecord(
86
+ arrTranslationsKeys,
87
+ (locale) => translations[locale]?.fields?.type?.[`${type}Label`],
88
+ ),
89
+ value: type,
90
+ })),
91
+ admin: {
92
+ placeholder: toSelectPlaceholder(
93
+ arrTranslationsKeys,
94
+ (locale) => translations[locale]?.fields?.type?.placeholder,
95
+ ),
96
+ },
97
+ },
98
+ {
99
+ name: "sortOrder",
100
+ type: "number",
101
+ required: false,
102
+ defaultValue: 0,
103
+ label: toLocaleRecord(
104
+ arrTranslationsKeys,
105
+ (locale) => translations[locale]?.fields?.sortOrder?.label,
106
+ ),
107
+ admin: {
108
+ placeholder: toLocaleRecord(
109
+ arrTranslationsKeys,
110
+ (locale) => translations[locale]?.fields?.sortOrder?.placeholder,
111
+ ),
112
+ },
113
+ },
114
+ {
115
+ name: "status",
116
+ type: "select",
117
+ required: true,
118
+ label: toLocaleRecord(
119
+ arrTranslationsKeys,
120
+ (locale) => translations[locale]?.fields?.status?.label,
121
+ ),
122
+ defaultValue: STATUS.ACTIVE,
123
+ options: Object.values(STATUS).map((status) => ({
124
+ label: toLocaleRecord(
125
+ arrTranslationsKeys,
126
+ (locale) =>
127
+ translations[locale]?.fields?.status?.[`${status}Label`],
128
+ ),
129
+ value: status,
130
+ })),
131
+ admin: {
132
+ placeholder: toSelectPlaceholder(
133
+ arrTranslationsKeys,
134
+ (locale) => translations[locale]?.fields?.status?.placeholder,
135
+ ),
136
+ },
137
+ },
138
+ ],
139
+ }),
140
+ timestamps: true,
141
+ };
142
+
143
+ return permissionActions;
144
+ };
@@ -0,0 +1,56 @@
1
+ import type { CollectionConfig, Field } from "payload";
2
+ import { STATUS, TYPE } from "../../lib/constants/permission-action.js";
3
+
4
+ export type PermissionActionsCollectionTranslations = {
5
+ [locale: string]: {
6
+ labels?: {
7
+ singular?: string;
8
+ plural?: string;
9
+ };
10
+ admin?: {
11
+ group?: string;
12
+ };
13
+ fields?: {
14
+ code?: {
15
+ label?: string;
16
+ placeholder?: string;
17
+ };
18
+ type?: {
19
+ label?: string;
20
+ placeholder?: string;
21
+ mainLabel?: string;
22
+ subLabel?: string;
23
+ };
24
+ sortOrder?: {
25
+ label?: string;
26
+ placeholder?: string;
27
+ };
28
+ status?: {
29
+ label?: string;
30
+ placeholder?: string;
31
+ activeLabel?: string;
32
+ inactiveLabel?: string;
33
+ };
34
+ };
35
+ };
36
+ };
37
+
38
+ export type PermissionActionsCollectionParams = {
39
+ translations?: PermissionActionsCollectionTranslations;
40
+ fields?: Field[];
41
+ access?: CollectionConfig["access"];
42
+ labels?: CollectionConfig["labels"];
43
+ admin?: CollectionConfig["admin"];
44
+ };
45
+
46
+ export type PermissionActionStatus = (typeof STATUS)[keyof typeof STATUS];
47
+
48
+ export type PermissionActionType = (typeof TYPE)[keyof typeof TYPE];
49
+
50
+ export type PermissionAction = {
51
+ id: string | number;
52
+ code?: string | null;
53
+ sortOrder?: number | null;
54
+ type?: PermissionActionType | null;
55
+ status?: PermissionActionStatus | null;
56
+ };
@@ -0,0 +1,30 @@
1
+ import type { PermissionFeaturesCollectionTranslations } from "./types.js";
2
+
3
+ export const permissionFeaturesDefaultTranslations: PermissionFeaturesCollectionTranslations =
4
+ {
5
+ en: {
6
+ labels: {
7
+ singular: "Permission Feature",
8
+ plural: "Permission Features",
9
+ },
10
+ admin: {
11
+ group: "System",
12
+ },
13
+ fields: {
14
+ code: {
15
+ label: "Code",
16
+ placeholder: "Enter code",
17
+ },
18
+ sortOrder: {
19
+ label: "Sort Order",
20
+ placeholder: "Enter sort order",
21
+ },
22
+ status: {
23
+ label: "Status",
24
+ placeholder: "Select status",
25
+ activeLabel: "Active",
26
+ inactiveLabel: "Inactive",
27
+ },
28
+ },
29
+ },
30
+ };
@@ -0,0 +1,122 @@
1
+ import type { CollectionConfig } from "payload";
2
+ import { STATUS } from "../../lib/constants/permission-feature.js";
3
+ import {
4
+ getArrayOfMergedFieldAffectingData,
5
+ getSuperAdminAccess,
6
+ toLocaleRecord,
7
+ toSelectPlaceholder,
8
+ } from "../../lib/utils/index.js";
9
+ import type { PermissionFeaturesCollectionParams } from "./types.js";
10
+
11
+ export const getPermissionFeaturesCollection = (
12
+ params: PermissionFeaturesCollectionParams,
13
+ ) => {
14
+ const {
15
+ translations = {},
16
+ access = {},
17
+ fields = [],
18
+ labels = {},
19
+ admin = {},
20
+ } = params || {};
21
+ const arrTranslationsKeys = Object.keys(translations);
22
+ const permissionFeatures: CollectionConfig = {
23
+ slug: "permission-features",
24
+ labels: {
25
+ singular: toLocaleRecord(
26
+ arrTranslationsKeys,
27
+ (locale) => translations[locale]?.labels?.singular,
28
+ ),
29
+ plural: toLocaleRecord(
30
+ arrTranslationsKeys,
31
+ (locale) => translations[locale]?.labels?.plural,
32
+ ),
33
+ ...labels,
34
+ },
35
+ admin: {
36
+ group: toLocaleRecord(
37
+ arrTranslationsKeys,
38
+ (locale) => translations[locale]?.admin?.group,
39
+ ),
40
+ useAsTitle: "code",
41
+ defaultColumns: ["code", "status", "updatedAt"],
42
+ ...admin,
43
+ },
44
+ access: {
45
+ create: getSuperAdminAccess,
46
+ update: getSuperAdminAccess,
47
+ delete: getSuperAdminAccess,
48
+ read: getSuperAdminAccess,
49
+ readVersions: getSuperAdminAccess,
50
+ unlock: getSuperAdminAccess,
51
+ admin: ({ req }) => {
52
+ return getSuperAdminAccess({ req });
53
+ },
54
+ ...access,
55
+ },
56
+ fields: getArrayOfMergedFieldAffectingData({
57
+ fields,
58
+ defaultFields: [
59
+ {
60
+ name: "code",
61
+ type: "text",
62
+ required: true,
63
+ unique: true,
64
+ index: true,
65
+ label: toLocaleRecord(
66
+ arrTranslationsKeys,
67
+ (locale) => translations[locale]?.fields?.code?.label,
68
+ ),
69
+ admin: {
70
+ placeholder: toLocaleRecord(
71
+ arrTranslationsKeys,
72
+ (locale) => translations[locale]?.fields?.code?.placeholder,
73
+ ),
74
+ },
75
+ },
76
+ {
77
+ name: "sortOrder",
78
+ type: "number",
79
+ required: false,
80
+ defaultValue: 0,
81
+ label: toLocaleRecord(
82
+ arrTranslationsKeys,
83
+ (locale) => translations[locale]?.fields?.sortOrder?.label,
84
+ ),
85
+ admin: {
86
+ placeholder: toLocaleRecord(
87
+ arrTranslationsKeys,
88
+ (locale) => translations[locale]?.fields?.sortOrder?.placeholder,
89
+ ),
90
+ },
91
+ },
92
+ {
93
+ name: "status",
94
+ type: "select",
95
+ required: true,
96
+ label: toLocaleRecord(
97
+ arrTranslationsKeys,
98
+ (locale) => translations[locale]?.fields?.status?.label,
99
+ ),
100
+ defaultValue: STATUS.ACTIVE,
101
+ options: Object.values(STATUS).map((status) => ({
102
+ label: toLocaleRecord(
103
+ arrTranslationsKeys,
104
+ (locale) =>
105
+ translations[locale]?.fields?.status?.[`${status}Label`],
106
+ ),
107
+ value: status,
108
+ })),
109
+ admin: {
110
+ placeholder: toSelectPlaceholder(
111
+ arrTranslationsKeys,
112
+ (locale) => translations[locale]?.fields?.status?.placeholder,
113
+ ),
114
+ },
115
+ },
116
+ ],
117
+ }),
118
+ timestamps: true,
119
+ };
120
+
121
+ return permissionFeatures;
122
+ };
@@ -0,0 +1,47 @@
1
+ import type { CollectionConfig, Field } from "payload";
2
+ import { STATUS } from "../../lib/constants/permission-feature.js";
3
+
4
+ export type PermissionFeaturesCollectionTranslations = {
5
+ [locale: string]: {
6
+ labels?: {
7
+ singular?: string;
8
+ plural?: string;
9
+ };
10
+ admin?: {
11
+ group?: string;
12
+ };
13
+ fields?: {
14
+ code?: {
15
+ label?: string;
16
+ placeholder?: string;
17
+ };
18
+ sortOrder?: {
19
+ label?: string;
20
+ placeholder?: string;
21
+ };
22
+ status?: {
23
+ label?: string;
24
+ placeholder?: string;
25
+ activeLabel?: string;
26
+ inactiveLabel?: string;
27
+ };
28
+ };
29
+ };
30
+ };
31
+
32
+ export type PermissionFeaturesCollectionParams = {
33
+ translations?: PermissionFeaturesCollectionTranslations;
34
+ fields?: Field[];
35
+ access?: CollectionConfig["access"];
36
+ labels?: CollectionConfig["labels"];
37
+ admin?: CollectionConfig["admin"];
38
+ };
39
+
40
+ export type PermissionFeatureStatus = (typeof STATUS)[keyof typeof STATUS];
41
+
42
+ export type PermissionFeature = {
43
+ id: string | number;
44
+ code?: string | null;
45
+ sortOrder?: number | null;
46
+ status?: PermissionFeatureStatus | null;
47
+ };
@@ -0,0 +1,38 @@
1
+ import type { PermissionsCollectionTranslations } from "./types.js";
2
+
3
+ export const permissionsDefaultTranslations: PermissionsCollectionTranslations =
4
+ {
5
+ en: {
6
+ labels: {
7
+ singular: "Permission",
8
+ plural: "Permissions",
9
+ },
10
+ admin: {
11
+ group: "System",
12
+ },
13
+ fields: {
14
+ name: {
15
+ label: "Name",
16
+ placeholder: "Enter name",
17
+ },
18
+ permissionFeature: {
19
+ label: "Permission Feature",
20
+ placeholder: "Select permission feature",
21
+ },
22
+ permissionAction: {
23
+ label: "Permission Action",
24
+ placeholder: "Select permission action",
25
+ },
26
+ sortOrder: {
27
+ label: "Sort Order",
28
+ placeholder: "Enter sort order",
29
+ },
30
+ status: {
31
+ label: "Status",
32
+ placeholder: "Select status",
33
+ activeLabel: "Active",
34
+ inactiveLabel: "Inactive",
35
+ },
36
+ },
37
+ },
38
+ };
@@ -0,0 +1,160 @@
1
+ import type { CollectionConfig } from "payload";
2
+ import { STATUS } from "../../lib/constants/permission.js";
3
+ import {
4
+ getArrayOfMergedFieldAffectingData,
5
+ getSuperAdminAccess,
6
+ toLocaleRecord,
7
+ toSelectPlaceholder,
8
+ } from "../../lib/utils/index.js";
9
+ import type { PermissionsCollectionParams } from "./types.js";
10
+
11
+ export const getPermissionsCollection = (
12
+ params: PermissionsCollectionParams,
13
+ ) => {
14
+ const {
15
+ translations = {},
16
+ access = {},
17
+ fields = [],
18
+ labels = {},
19
+ admin = {},
20
+ } = params || {};
21
+ const arrTranslationsKeys = Object.keys(translations);
22
+ const permissions: CollectionConfig = {
23
+ slug: "permissions",
24
+ labels: {
25
+ singular: toLocaleRecord(
26
+ arrTranslationsKeys,
27
+ (locale) => translations[locale]?.labels?.singular,
28
+ ),
29
+ plural: toLocaleRecord(
30
+ arrTranslationsKeys,
31
+ (locale) => translations[locale]?.labels?.plural,
32
+ ),
33
+ ...labels,
34
+ },
35
+ admin: {
36
+ group: toLocaleRecord(
37
+ arrTranslationsKeys,
38
+ (locale) => translations[locale]?.admin?.group,
39
+ ),
40
+ useAsTitle: "name",
41
+ defaultColumns: [
42
+ "name",
43
+ "permissionFeature",
44
+ "permissionAction",
45
+ "status",
46
+ "updatedAt",
47
+ ],
48
+ ...admin,
49
+ },
50
+ access: {
51
+ create: getSuperAdminAccess,
52
+ update: getSuperAdminAccess,
53
+ delete: getSuperAdminAccess,
54
+ read: getSuperAdminAccess,
55
+ readVersions: getSuperAdminAccess,
56
+ unlock: getSuperAdminAccess,
57
+ admin: ({ req }) => {
58
+ return getSuperAdminAccess({ req });
59
+ },
60
+ ...access,
61
+ },
62
+ fields: getArrayOfMergedFieldAffectingData({
63
+ fields,
64
+ defaultFields: [
65
+ {
66
+ name: "name",
67
+ type: "text",
68
+ required: true,
69
+ label: toLocaleRecord(
70
+ arrTranslationsKeys,
71
+ (locale) => translations[locale]?.fields?.name?.label,
72
+ ),
73
+ admin: {
74
+ placeholder: toLocaleRecord(
75
+ arrTranslationsKeys,
76
+ (locale) => translations[locale]?.fields?.name?.placeholder,
77
+ ),
78
+ },
79
+ },
80
+ {
81
+ name: "permissionFeature",
82
+ type: "relationship",
83
+ required: true,
84
+ relationTo: "permission-features",
85
+ label: toLocaleRecord(
86
+ arrTranslationsKeys,
87
+ (locale) => translations[locale]?.fields?.permissionFeature?.label,
88
+ ),
89
+ admin: {
90
+ placeholder: toSelectPlaceholder(
91
+ arrTranslationsKeys,
92
+ (locale) =>
93
+ translations[locale]?.fields?.permissionFeature?.placeholder,
94
+ ),
95
+ },
96
+ },
97
+ {
98
+ name: "permissionAction",
99
+ type: "relationship",
100
+ required: true,
101
+ relationTo: "permission-actions",
102
+ label: toLocaleRecord(
103
+ arrTranslationsKeys,
104
+ (locale) => translations[locale]?.fields?.permissionAction?.label,
105
+ ),
106
+ admin: {
107
+ placeholder: toSelectPlaceholder(
108
+ arrTranslationsKeys,
109
+ (locale) =>
110
+ translations[locale]?.fields?.permissionAction?.placeholder,
111
+ ),
112
+ },
113
+ },
114
+ {
115
+ name: "sortOrder",
116
+ type: "number",
117
+ required: false,
118
+ defaultValue: 0,
119
+ label: toLocaleRecord(
120
+ arrTranslationsKeys,
121
+ (locale) => translations[locale]?.fields?.sortOrder?.label,
122
+ ),
123
+ admin: {
124
+ placeholder: toLocaleRecord(
125
+ arrTranslationsKeys,
126
+ (locale) => translations[locale]?.fields?.sortOrder?.placeholder,
127
+ ),
128
+ },
129
+ },
130
+ {
131
+ name: "status",
132
+ type: "select",
133
+ required: true,
134
+ label: toLocaleRecord(
135
+ arrTranslationsKeys,
136
+ (locale) => translations[locale]?.fields?.status?.label,
137
+ ),
138
+ defaultValue: STATUS.ACTIVE,
139
+ options: Object.values(STATUS).map((status) => ({
140
+ label: toLocaleRecord(
141
+ arrTranslationsKeys,
142
+ (locale) =>
143
+ translations[locale]?.fields?.status?.[`${status}Label`],
144
+ ),
145
+ value: status,
146
+ })),
147
+ admin: {
148
+ placeholder: toSelectPlaceholder(
149
+ arrTranslationsKeys,
150
+ (locale) => translations[locale]?.fields?.status?.placeholder,
151
+ ),
152
+ },
153
+ },
154
+ ],
155
+ }),
156
+ timestamps: true,
157
+ };
158
+
159
+ return permissions;
160
+ };