diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..de01662 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,62 @@ +/// +declare module "@digipolis/authz" { + export type Source = "authzv2" | "meauthz" | "meauthzv2" | "externalAuthz"; + export interface BaseConfig { + debug?: boolean; + disabled?: boolean; + cache?: boolean; + tokenLocation?: string; + source: Source; + sources: { + externalAuthz?: Function; + url?: string; + apiKey?: string; + applicationId?: string; + }; + } + + export interface Config extends BaseConfig { + debug: boolean; + set: boolean; + disabled: boolean; + tokenLocation: string; + cache: boolean; + } + + function checkOneOfPermissions( + authToken: string, + requiredPermissions?: string | string[], + requestedsource?: Source + ): void; + function checkPermission( + authToken: string, + requiredPermissions?: string | string[], + requestedsource?: Source + ): void; + function config(config: BaseConfig, force?: boolean): Config; + function getConfig(): Config; + function getPermissions(authToken: string, datasource: Source): string[]; + function hasOneOfPermissions( + requiredPermissions: string | string[], + source: Source + ): Promise; + function hasPermission( + requiredPermissions: string | string[], + source: Source + ): Promise; + function hasPermissions( + requiredPermissions: string | string[], + source: Source + ): Promise; + + export = { + checkOneOfPermissions, + checkPermission, + config, + getConfig, + getPermissions, + hasOneOfPermissions, + hasPermission, + hasPermissions, + }; +} diff --git a/package.json b/package.json index f6aea50..2aae3ed 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "@digipolis/authz", "version": "1.4.1", "description": "Authorization module which can be used to check the permissions of an authenticated user.", + "types": "index.d.ts", "scripts": { "test": "mocha ./test && npm run lint", "lint": "eslint \"**/*.js\"",