embassy
Version:
Simple JSON Web Tokens (JWT) with embedded scopes for services
38 lines (37 loc) • 1.71 kB
TypeScript
import { DomainKey, DomainScopes, ScopeLoopFunction } from './types';
/**
* Given an array of combined scope strings in the format `domain|scope` or just
* `scope`, will provide a mapping of all domains in the array to the scopes
* that appeared for them. Strings with no `domain|` prefix will use the default
* "app" scope.
*
* @param combined - An array of strings in the format `domain|scope`. If the
* domain portion is missing, the default scope of "app" will be used.
* @returns a map of domains to arrays of scopes within that domain
*/
export declare function combinedToDomainScopes(combined: string[]): DomainScopes;
/**
* Runs a given function across each provided scope.
*
* @param domainScopesOrCombined - A DomainScopes map or scopes against which to
* execute the function, or an array of combined-format domain|scope strings
* @param fn - The function to execute for each domain/scope pair, iteratively.
*/
export declare function forEachScope(domainScopesOrCombined: DomainScopes | string[], fn: ScopeLoopFunction): Promise<void>;
/**
* Given a string that may have a domain included in the format `domain|key`
* or `domain|complex|key`, returns an object that splits out the domain up
* to the first `|` symbol. The examples above would result in:
*
* ```typescript
* { domain: 'domain', key: 'key' } // First
* { domain: 'domain', key: 'complex|key' } // Second
* ```
*
* In the event a `|` character is not included, the default domain "app" will
* be used.
*
* @param combined - A string that may have a `domain:` prefix
* @returns an object defining the components of the combined string
*/
export declare function splitCombined(combined: string): DomainKey;