{"version":3,"file":"policies.cjs","names":[],"sources":["../../../../src/rest/commands/read/policies.ts"],"sourcesContent":["import type { DirectusPolicy } from '../../../schema/policy.js';\nimport type { ApplyQueryFields, Query } from '../../../types/index.js';\nimport type { RestCommand } from '../../types.js';\nimport { throwIfEmpty } from '../../utils/index.js';\n\nexport type ReadPolicyOutput<\n\tSchema,\n\tTQuery extends Query<Schema, Item>,\n\tItem extends object = DirectusPolicy<Schema>,\n> = ApplyQueryFields<Schema, Item, TQuery['fields']>;\n\nexport type ReadPolicyGlobalsOutput = {\n\tapp_access: boolean;\n\tadmin_access: boolean;\n\tenforce_tfa: boolean;\n};\n\n/**\n * List all policies that exist in the project.\n * @param query The query parameters\n * @returns An array of up to limit Policy objects. If no items are available, data will be an empty array.\n */\nexport const readPolicies =\n\t<Schema, const TQuery extends Query<Schema, DirectusPolicy<Schema>>>(\n\t\tquery?: TQuery,\n\t): RestCommand<ReadPolicyOutput<Schema, TQuery>[], Schema> =>\n\t() => ({\n\t\tpath: `/policies`,\n\t\tparams: query ?? {},\n\t\tmethod: 'GET',\n\t});\n\n/**\n * Read a specific policy.\n * @param key The primary key of the permission\n * @param query The query parameters\n * @returns Returns a Policy object if a valid primary key was provided.\n * @throws Will throw if key is empty\n */\nexport const readPolicy =\n\t<Schema, const TQuery extends Query<Schema, DirectusPolicy<Schema>>>(\n\t\tkey: DirectusPolicy<Schema>['id'],\n\t\tquery?: TQuery,\n\t): RestCommand<ReadPolicyOutput<Schema, TQuery>, Schema> =>\n\t() => {\n\t\tthrowIfEmpty(String(key), 'Key cannot be empty');\n\n\t\treturn {\n\t\t\tpath: `/policies/${key}`,\n\t\t\tparams: query ?? {},\n\t\t\tmethod: 'GET',\n\t\t};\n\t};\n\n/**\n * Check the current user's policy globals.\n */\nexport const readPolicyGlobals =\n\t<Schema>(): RestCommand<ReadPolicyGlobalsOutput, Schema> =>\n\t() => ({\n\t\tpath: `/policies/me/globals`,\n\t\tmethod: 'GET',\n\t});\n"],"mappings":"kDAsBa,EAEX,QAEM,CACN,KAAM,YACN,OAAQ,GAAS,EAAE,CACnB,OAAQ,MACR,EASW,GAEX,EACA,SAGA,EAAA,aAAa,OAAO,EAAI,CAAE,sBAAsB,CAEzC,CACN,KAAM,aAAa,IACnB,OAAQ,GAAS,EAAE,CACnB,OAAQ,MACR,EAMU,WAEL,CACN,KAAM,uBACN,OAAQ,MACR"}