UNPKG

@casual-simulation/aux-common

Version:
234 lines 8.42 kB
import type { WebsocketErrorCode } from '../websockets'; import type { AuthorizeActionMissingPermission, ConnectionIndicator, DenialReason, PublicUserInfo, ResourceKinds, SubjectType } from '../common'; import type { Observable } from 'rxjs'; import type { NotAuthorizedError, ServerError } from '../Errors'; /** * Defines an interface that is able to provide events for when authentication information is requested or provided to partitions. */ export declare class PartitionAuthSource { private _onAuthRequest; private _onAuthResponse; private _onAuthPermissionRequest; private _onAuthPermissionResult; private _onAuthExternalPermissionRequest; private _onAuthExternalPermissionResult; private _indicators; private _promises; /** * Gets an observable for when a partition requests or provides authentication information. */ get onAuthMessage(): Observable<PartitionAuthMessage>; /** * Gets an observable for when a partition requests permission. */ get onAuthPermissionRequest(): Observable<PartitionAuthRequestPermission>; /** * Gets an observable for when a partition provides permission result. */ get onAuthPermissionResult(): Observable<PartitionAuthPermissionResult>; /** * Gets an observable for when an external permissions request is recieved. */ get onAuthExternalPermissionRequest(): Observable<PartitionAuthExternalRequestPermission>; /** * Gets an observable for when an external permissions result is recieved. */ get onAuthExternalPermissionResult(): Observable<PartitionAuthExternalPermissionResult>; /** * Gets an observable for when a partition requests authentication information. */ get onAuthRequest(): Observable<PartitionAuthRequest>; /** * Gets an observable for when auth information should be provided to a partition. */ get onAuthResponse(): Observable<PartitionAuthResponse>; constructor(initialIndicators?: Map<string, ConnectionIndicator>); /** * Gets the connection indicator that is currently stored for the given origin. * @param origin The origin. * @returns Returns the connection indicator or null if none is stored. */ getConnectionIndicatorForOrigin(origin: string): ConnectionIndicator | null; /** * Gets an observable that resolves when there is an auth response for the given HTTP origin. * @param origin The origin. */ onAuthResponseForOrigin(origin: string): Observable<PartitionAuthResponse>; /** * Sends a request for authentication information. Returns an observable that resolves with the first response for the origin. * @param request The request that should be sent. */ sendAuthRequest(request: PartitionAuthRequest): Promise<PartitionAuthResponse>; /** * Sends a response for authentication information. * @param response The response that should be sent. */ sendAuthResponse(response: PartitionAuthResponse): void; /** * Sends the given request for permission. * @param request The request. */ sendAuthPermissionRequest(request: PartitionAuthRequestPermission): void; /** * Sends the given permission result. * @param result The result. */ sendAuthPermissionResult(result: PartitionAuthPermissionResult): void; /** * Sends the given request for permission. * @param request The request. */ sendAuthExternalPermissionRequest(request: PartitionAuthExternalRequestPermission): void; /** * Sends the given permission result. * @param result The result. */ sendAuthExternalPermissionResult(result: PartitionAuthExternalPermissionResult): void; /** * Sends the given auth message. * @param message The message that should be sent. */ sendAuthMessage(message: PartitionAuthMessage): void; } export type PartitionAuthMessage = PartitionAuthRequest | PartitionAuthResponse | PartitionAuthRequestPermission | PartitionAuthPermissionResult | PartitionAuthExternalRequestPermission | PartitionAuthExternalPermissionResult; export interface PartitionAuthRequest { type: 'request'; /** * The HTTP origin for the partition. */ origin: string; /** * The kind of the request. * - "need_indicator" means that the partition does not have an indicator and needs one in order to login. * - "invalid_indicator" means that the partition has an indicator and tried to connect, but the indicator was rejected upon login. * - "not_authorized" means that the partition has an indicator logged in, but was rejected when trying to access a resource. */ kind: 'need_indicator' | 'invalid_indicator' | 'not_authorized'; /** * The error code that occurred. */ errorCode?: WebsocketErrorCode; /** * The error message that ocurred. */ errorMessage?: string; /** * The indicator that was used to connect. */ indicator?: ConnectionIndicator; /** * The denial reason. Only present if the kind is "not_authorized". */ reason?: DenialReason; /** * The resource that the denial occurred for. */ resource?: PartitionResource; } export type PartitionResource = PartitionInstResource; export interface PartitionInstResource { type: 'inst'; /** * The name of the record. */ recordName: string | null; /** * The name of the inst. */ inst: string; /** * The branch that is being loaded. */ branch: string; } export type PartitionAuthResponse = PartitionAuthResponseSuccess | PartitionAuthResponseFailure; export interface PartitionAuthResponseBase { type: 'response'; /** * The origin for the partition. */ origin: string; } export interface PartitionAuthResponseSuccess extends PartitionAuthResponseBase { success: true; /** * The connection indicator that should be used. */ indicator: ConnectionIndicator; } export interface PartitionAuthResponseFailure extends PartitionAuthResponseBase { success: false; } export interface PartitionAuthRequestPermission { type: 'permission_request'; /** * The origin for the partition. */ origin: string; /** * The reason why permission is being requested. */ reason: AuthorizeActionMissingPermission; } export type PartitionAuthPermissionResult = PartitionAuthPermissionResultSuccess | PartitionAuthPermissionResultFailure; export interface PartitionAuthPermissionResultSuccess { type: 'permission_result'; success: true; origin: string; recordName: string; resourceKind: ResourceKinds; resourceId: string; subjectType: SubjectType; subjectId: string; } export interface PartitionAuthPermissionResultFailure { type: 'permission_result'; success: false; origin: string; recordName: string; resourceKind: ResourceKinds; resourceId: string; subjectType: SubjectType; subjectId: string; errorCode: NotAuthorizedError | ServerError | WebsocketErrorCode; errorMessage: string; } export interface PartitionAuthExternalRequestPermission { type: 'external_permission_request'; /** * The origin for the partition. */ origin: string; /** * The reason why permission is being requested. */ reason: AuthorizeActionMissingPermission; /** * The information about the user that is requesting the permission. */ user: PublicUserInfo | null; } export type PartitionAuthExternalPermissionResult = PartitionAuthExternalPermissionResultSuccess | PartitionAuthExternalPermissionResultFailure; export interface PartitionAuthExternalPermissionResultSuccess { type: 'external_permission_result'; success: true; origin: string; recordName: string; resourceKind: ResourceKinds; resourceId: string; subjectType: SubjectType; subjectId: string; } export interface PartitionAuthExternalPermissionResultFailure { type: 'external_permission_result'; success: false; origin: string; recordName: string; resourceKind: ResourceKinds; resourceId: string; subjectType: SubjectType; subjectId: string; errorCode: NotAuthorizedError | ServerError | WebsocketErrorCode; errorMessage: string; } //# sourceMappingURL=PartitionAuthSource.d.ts.map