{"version":3,"file":"permissions.cjs","names":[],"sources":["../../../../src/rest/commands/read/permissions.ts"],"sourcesContent":["import type { DirectusPermission } from '../../../schema/permission.js';\nimport type { AllCollections, ApplyQueryFields, Query } from '../../../types/index.js';\nimport type { RestCommand } from '../../types.js';\nimport { throwIfEmpty } from '../../utils/index.js';\n\nexport type ReadPermissionOutput<\n\tSchema,\n\tTQuery extends Query<Schema, Item>,\n\tItem extends object = DirectusPermission<Schema>,\n> = ApplyQueryFields<Schema, Item, TQuery['fields']>;\n\nexport type ReadItemPermissionsOutput = {\n\tupdate: { access: boolean; presets?: Record<string, any> | null; fields?: string[] | null };\n\tdelete: { access: boolean };\n\tshare: { access: boolean };\n};\n\nexport type ReadUserPermissionsOutput = Record<\n\tstring,\n\tRecord<\n\t\t'create' | 'update' | 'delete' | 'read' | 'share',\n\t\t{\n\t\t\taccess: 'none' | 'partial' | 'full';\n\t\t\tfields?: string[];\n\t\t\tpresets?: Record<string, any>;\n\t\t}\n\t>\n>;\n\n/**\n * List all Permissions that exist in Directus.\n * @param query The query parameters\n * @returns An array of up to limit Permission objects. If no items are available, data will be an empty array.\n */\nexport const readPermissions =\n\t<Schema, const TQuery extends Query<Schema, DirectusPermission<Schema>>>(\n\t\tquery?: TQuery,\n\t): RestCommand<ReadPermissionOutput<Schema, TQuery>[], Schema> =>\n\t() => ({\n\t\tpath: `/permissions`,\n\t\tparams: query ?? {},\n\t\tmethod: 'GET',\n\t});\n\n/**\n * List all Permissions that exist in Directus.\n * @param key The primary key of the permission\n * @param query The query parameters\n * @returns Returns a Permission object if a valid primary key was provided.\n * @throws Will throw if key is empty\n */\nexport const readPermission =\n\t<Schema, const TQuery extends Query<Schema, DirectusPermission<Schema>>>(\n\t\tkey: DirectusPermission<Schema>['id'],\n\t\tquery?: TQuery,\n\t): RestCommand<ReadPermissionOutput<Schema, TQuery>, Schema> =>\n\t() => {\n\t\tthrowIfEmpty(String(key), 'Key cannot be empty');\n\n\t\treturn {\n\t\t\tpath: `/permissions/${key}`,\n\t\t\tparams: query ?? {},\n\t\t\tmethod: 'GET',\n\t\t};\n\t};\n\n/**\n * Check the current user's permissions on a specific item.\n * @param collection The collection of the item\n * @param key The primary key of the item\n * @returns Returns a ItemPermissions object if a valid collection / primary key was provided.\n */\nexport const readItemPermissions =\n\t<Schema, Collection extends AllCollections<Schema>>(\n\t\tcollection: Collection,\n\t\tkey?: string | number,\n\t): RestCommand<ReadItemPermissionsOutput, Schema> =>\n\t() => {\n\t\tthrowIfEmpty(String(collection), 'Collection cannot be empty');\n\n\t\tconst item = key ? `${collection as string}/${key}` : `${collection as string}`;\n\n\t\treturn {\n\t\t\tpath: `/permissions/me/${item}`,\n\t\t\tmethod: 'GET',\n\t\t};\n\t};\n\n/**\n * Check the current user's permissions.\n */\nexport const readUserPermissions =\n\t<Schema>(): RestCommand<ReadUserPermissionsOutput, Schema> =>\n\t() => ({\n\t\tpath: `/permissions/me`,\n\t\tmethod: 'GET',\n\t});\n"],"mappings":"kDAkCa,EAEX,QAEM,CACN,KAAM,eACN,OAAQ,GAAS,EAAE,CACnB,OAAQ,MACR,EASW,GAEX,EACA,SAGA,EAAA,aAAa,OAAO,EAAI,CAAE,sBAAsB,CAEzC,CACN,KAAM,gBAAgB,IACtB,OAAQ,GAAS,EAAE,CACnB,OAAQ,MACR,EASU,GAEX,EACA,SAGA,EAAA,aAAa,OAAO,EAAW,CAAE,6BAA6B,CAIvD,CACN,KAAM,mBAHM,EAAM,GAAG,EAAqB,GAAG,IAAQ,GAAG,MAIxD,OAAQ,MACR,EAMU,WAEL,CACN,KAAM,kBACN,OAAQ,MACR"}