Skip to content

Commit

Permalink
move types
Browse files Browse the repository at this point in the history
  • Loading branch information
4rthem committed Jan 5, 2024
1 parent a09d06d commit e63fb45
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 60 deletions.
14 changes: 0 additions & 14 deletions lib/js/auth/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import OAuthClient, {
AuthEvent,
AuthEventHandler,
configureClientAuthentication,
configureClientCredentialsGrantType,
isValidSession,
LoginEvent,
loginEventType,
LogoutEvent,
logoutEventType,
LogoutOptions,
RefreshTokenEvent,
refreshTokenEventType,
sessionExpiredEventType,
} from "./src/client/OAuthClient";
Expand All @@ -29,13 +23,5 @@ export {
isValidSession,
keycloakNormalizer,
};
export type {
AuthEvent,
AuthEventHandler,
LogoutEvent,
LogoutOptions,
LoginEvent,
RefreshTokenEvent,
}

export * from './src/types';
4 changes: 1 addition & 3 deletions lib/js/auth/src/client/KeycloakClient.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import OAuthClient, {
LogoutEvent,
logoutEventType,
LogoutOptions,
normalizeRedirectUri,
OAuthClientOptions
} from "./OAuthClient";
import {KeycloakUserInfoResponse} from "../types";
import {KeycloakUserInfoResponse, LogoutEvent, LogoutOptions} from "../types";

type Options = {
realm: string;
Expand Down
51 changes: 9 additions & 42 deletions lib/js/auth/src/client/OAuthClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,21 @@ import axios, {AxiosError, AxiosHeaders, AxiosInstance, InternalAxiosRequestConf
import {jwtDecode} from "jwt-decode";
import {CookieStorage, IStorage} from "@alchemy/storage";
import {createHttpClient, HttpClient} from "@alchemy/api";
import {AuthTokens, TokenResponseWithTokens, UserInfoResponse} from "../types";

export type TokenResponse = {
access_token: string;
refresh_token: string;
token_type: string;
expires_in: number;
refresh_expires_in: number;
device_token?: string;
};

interface ValidationError {
error: string;
error_description: string;
}

export type AuthEvent = {
type: string;
preventDefault?: boolean,
stopPropagation?: boolean,
};

export type LoginEvent = {
tokens: AuthTokens;
} & AuthEvent;

export type LogoutOptions = {
quiet?: boolean;
redirectPath?: string | undefined;
noEvent?: boolean;
};

export type LogoutEvent = LogoutOptions & AuthEvent;

export type SessionExpiredEvent = AuthEvent;

export type RefreshTokenEvent = {
tokens: AuthTokens;
} & AuthEvent;

export type AuthEventHandler<E extends AuthEvent = AuthEvent> = (event: E) => Promise<void>;
import {
AuthEvent,
AuthEventHandler,
AuthTokens, LoginEvent,
LogoutEvent,
LogoutOptions, RefreshTokenEvent, SessionExpiredEvent, TokenResponse,
TokenResponseWithTokens,
UserInfoResponse, ValidationError
} from "../types";

export const loginEventType = 'login';
export const refreshTokenEventType = 'refreshToken';
export const logoutEventType = 'logout';
export const sessionExpiredEventType = 'sessionExpired';


type Options = {
storage?: IStorage;
clientId: string;
Expand Down
40 changes: 39 additions & 1 deletion lib/js/auth/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,42 @@
import {TokenResponse} from "./client/OAuthClient";
export interface ValidationError {
error: string;
error_description: string;
}

export type AuthEvent = {
type: string;
preventDefault?: boolean,
stopPropagation?: boolean,
};

export type LoginEvent = {
tokens: AuthTokens;
} & AuthEvent;

export type LogoutOptions = {
quiet?: boolean;
redirectPath?: string | undefined;
noEvent?: boolean;
};

export type LogoutEvent = LogoutOptions & AuthEvent;

export type SessionExpiredEvent = AuthEvent;

export type RefreshTokenEvent = {
tokens: AuthTokens;
} & AuthEvent;

export type AuthEventHandler<E extends AuthEvent = AuthEvent> = (event: E) => Promise<void>;

export type TokenResponse = {
access_token: string;
refresh_token: string;
token_type: string;
expires_in: number;
refresh_expires_in: number;
device_token?: string;
};

export type AuthTokens = {
accessToken: string;
Expand Down

0 comments on commit e63fb45

Please sign in to comment.