UNPKG

@smart-consulting/lattice-services

Version:

Collection of common types and functions for connecting to Lattice services

133 lines (132 loc) 4.97 kB
import { AxiosResponse } from 'axios'; import * as t from 'io-ts'; declare const corgisAuth0Namespace = "https://wsp-lattice.io/"; declare const corgisAuth0PermissionsNamespace = "https://wsp-lattice.io/user_authorization"; declare const userPermissionsType: t.PartialC<{ corgis: t.ArrayC<t.StringC>; adminservice: t.ArrayC<t.StringC>; }>; declare const userProfileFromServer: t.TypeC<{ aud: t.StringC; exp: t.NumberC; "https://wsp-lattice.io/": t.TypeC<{ team: t.StringC; }>; "https://wsp-lattice.io/user_authorization": t.TypeC<{ permissions: t.PartialC<{ corgis: t.ArrayC<t.StringC>; adminservice: t.ArrayC<t.StringC>; }>; }>; iat: t.NumberC; iss: t.StringC; name: t.StringC; nickname: t.StringC; nonce: t.StringC; picture: t.StringC; sub: t.StringC; updated_at: t.StringC; }>; declare const ioTeamConfig: t.TypeC<{ _id: t.StringC; name: t.StringC; description: t.StringC; members: t.UnionC<[t.ArrayC<t.StringC>, t.UndefinedC]>; }>; declare const ioTeamMember: t.TypeC<{ email: t.StringC; email_verified: t.BooleanC; user_id: t.StringC; picture: t.StringC; nickname: t.StringC; updated_at: t.StringC; created_at: t.StringC; name: t.StringC; app_metadata: t.TypeC<{}>; last_login: t.UnionC<[t.StringC, t.NullC]>; logins_count: t.UnionC<[t.NumberC, t.NullC]>; }>; declare const ioTeamMemberTotal: t.TypeC<{ total: t.NumberC; users: t.ArrayC<t.UnionC<[t.TypeC<{ email: t.StringC; email_verified: t.BooleanC; user_id: t.StringC; picture: t.StringC; nickname: t.StringC; updated_at: t.StringC; created_at: t.StringC; name: t.StringC; app_metadata: t.TypeC<{}>; last_login: t.UnionC<[t.StringC, t.NullC]>; logins_count: t.UnionC<[t.NumberC, t.NullC]>; }>, t.UndefinedC]>>; }>; declare const ioTeamResponse: t.TypeC<{ status: t.StringC; detail: t.StringC; }>; declare type userPermissions = t.TypeOf<typeof userPermissionsType>; export declare type UserProfile = Pick<t.TypeOf<typeof userProfileFromServer>, 'name' | 'nickname' | 'picture' | 'sub'> & { team: string; permissions: userPermissions; }; export declare type TeamConfig = t.TypeOf<typeof ioTeamConfig>; export declare type TeamMember = t.TypeOf<typeof ioTeamMember>; export declare type TeamMemberTotal = t.TypeOf<typeof ioTeamMemberTotal>; export declare type TeamResponse = t.TypeOf<typeof ioTeamResponse>; export declare const AUTH_USER_PROFILE_ROUTE = "/user-profile"; export declare function getProfile(): Promise<UserProfile>; /** * Build a tcs URL based on the host and api version. * Prepends the AUTH_SERVICE_HOST environment variable to the URL * * @param route - The absolute route path for the URL. Must begin with a '/'. EG: '/health' * @param version - The API version for the host. Defaults to version 1 * * @returns The full URL to use as an XHR request */ export declare function buildAuthUrl(route: string, version?: number): string; /** * Retain team list from auth service * @param userID : Auth0 User ID */ export declare function getTeamList(userID: string): Promise<TeamConfig[]>; /** * Update active (current) team in Auth service * @param userID : Auth0 user ID * @param teamId : UUID of new current team */ export declare function updateTeamAssigns(userID: string, teamId: string): Promise<boolean>; /** * Retain active (current) team of the user * @param userID : Auth0 user ID */ export declare function getActiveTeam(userID: string): Promise<TeamConfig>; export declare const ERROR_GET_MEMBER: Error; /** * Retrieve list of members from given team in Auth service * @param teamID : Team ID string * @param per_page : Optional number of items to be displayed on each page * @param page : Optional page number */ export declare function getMemberList(teamID: string, per_page?: number, page?: number): Promise<TeamMemberTotal>; /** * Check if given user email belongs to specified team. * Return relevant response status/message if user is successfully found or later added to the team; * otherwise, return error response. * @param email : string - User email value * @param teamId : string - Team ID value * @param connection : string - Optional Auth0 connection value */ export declare function inviteUserToTeam(email: string, teamId: string, connection?: string): Promise<AxiosResponse>; export declare const ERROR_REMOVE_USER: Error; /** * Remove given user from specified team. * Return relevant response status/message if user is successfully removed from the team; * otherwise, either return error response or throw error to client log * @param teamId : string - Team ID value * @param userId : string - User ID value e.g. Auth0|xxx */ export declare function removeUser(teamId: string, userId: string): Promise<TeamResponse | AxiosResponse>; export {};