chore: prettier

This commit is contained in:
Derrick Hammer 2024-03-13 10:22:23 -04:00
parent 4797ea7be2
commit 3250edf166
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
3 changed files with 341 additions and 311 deletions

View File

@ -1,103 +1,133 @@
import { import {
LoginRequest, LoginResponse, LoginRequest,
OTPDisableRequest, LoginResponse,
OTPGenerateResponse, OTPDisableRequest,
OTPValidateRequest, OTPGenerateResponse,
OTPVerifyRequest, OTPValidateRequest,
PasswordResetVerifyRequest, postApiAuthPasswordResetRequest, OTPVerifyRequest,
RegisterRequest, PasswordResetVerifyRequest,
VerifyEmailRequest, postApiAuthPasswordResetRequest,
} from './account/generated/index.js'; RegisterRequest,
VerifyEmailRequest,
} from "./account/generated/index.js";
import { import {
postApiAuthLogin, postApiAuthLogin,
postApiAuthRegister, postApiAuthRegister,
postApiAuthVerifyEmail, postApiAuthVerifyEmail,
getApiAuthOtpGenerate, getApiAuthOtpGenerate,
postApiAuthOtpVerify, postApiAuthOtpVerify,
postApiAuthOtpValidate, postApiAuthOtpValidate,
postApiAuthOtpDisable, postApiAuthOtpDisable,
PasswordResetRequest, PasswordResetRequest,
postApiAuthPasswordResetConfirm, postApiAuthPasswordResetConfirm,
} from './account/generated/index.js'; } from "./account/generated/index.js";
import { AxiosResponse } from 'axios'; import { AxiosResponse } from "axios";
export default class AccountApi { export default class AccountApi {
private apiUrl: string; private apiUrl: string;
private jwtToken?: string; private jwtToken?: string;
constructor(apiUrl: string) { constructor(apiUrl: string) {
this.apiUrl = apiUrl; this.apiUrl = apiUrl;
}
public static create(apiUrl: string): AccountApi {
return new AccountApi(apiUrl);
}
public async login(loginRequest: LoginRequest): Promise<boolean> {
let ret = this.checkSuccessVal<LoginResponse>(
await postApiAuthLogin(loginRequest, { baseURL: this.apiUrl }),
);
if (ret) {
this.jwtToken = (ret as LoginResponse).token;
} }
public static create(apiUrl: string): AccountApi { return false;
return new AccountApi(apiUrl); }
public async register(registerRequest: RegisterRequest): Promise<boolean> {
return this.checkSuccessBool(
await postApiAuthRegister(registerRequest, this.buildOptions()),
);
}
public async verifyEmail(
verifyEmailRequest: VerifyEmailRequest,
): Promise<boolean> {
return this.checkSuccessBool(
await postApiAuthVerifyEmail(verifyEmailRequest, this.buildOptions()),
);
}
public async generateOtp(): Promise<boolean | OTPGenerateResponse> {
return this.checkSuccessVal<OTPGenerateResponse>(
await getApiAuthOtpGenerate(this.buildOptions()),
);
}
public async verifyOtp(otpVerifyRequest: OTPVerifyRequest): Promise<boolean> {
return this.checkSuccessBool(
await postApiAuthOtpVerify(otpVerifyRequest, this.buildOptions()),
);
}
public async validateOtp(
otpValidateRequest: OTPValidateRequest,
): Promise<boolean> {
return this.checkSuccessBool(
await postApiAuthOtpValidate(otpValidateRequest, this.buildOptions()),
);
}
public async disableOtp(
otpDisableRequest: OTPDisableRequest,
): Promise<boolean> {
return this.checkSuccessBool(
await postApiAuthOtpDisable(otpDisableRequest, this.buildOptions()),
);
}
public async requestPasswordReset(
passwordResetRequest: PasswordResetRequest,
): Promise<boolean> {
return this.checkSuccessBool(
await postApiAuthPasswordResetRequest(
passwordResetRequest,
this.buildOptions(),
),
);
}
public async confirmPasswordReset(
passwordResetVerifyRequest: PasswordResetVerifyRequest,
): Promise<boolean> {
return this.checkSuccessBool(
await postApiAuthPasswordResetConfirm(
passwordResetVerifyRequest,
this.buildOptions(),
),
);
}
private checkSuccessBool(ret: AxiosResponse<void>): boolean {
return ret.status === 200;
}
private checkSuccessVal<T>(ret: AxiosResponse<T>): T | boolean {
if (ret.status === 200) {
return ret.data as T;
} }
public async login(loginRequest: LoginRequest): Promise<boolean> { return false;
let ret = this.checkSuccessVal<LoginResponse>(await postApiAuthLogin(loginRequest, { baseURL: this.apiUrl })) }
if (ret) {
this.jwtToken = (ret as LoginResponse).token;
}
return false; private buildOptions(): any {
} return {
baseURL: this.apiUrl,
public async register(registerRequest: RegisterRequest): Promise<boolean> { headers: {
return this.checkSuccessBool(await postApiAuthRegister(registerRequest, this.buildOptions())); Authorization: `Bearer ${this.jwtToken}`,
} },
};
public async verifyEmail(verifyEmailRequest: VerifyEmailRequest): Promise<boolean> { }
return this.checkSuccessBool(await postApiAuthVerifyEmail(verifyEmailRequest, this.buildOptions()));
}
public async generateOtp(): Promise<boolean | OTPGenerateResponse> {
return this.checkSuccessVal<OTPGenerateResponse>(await getApiAuthOtpGenerate( this.buildOptions()));
}
public async verifyOtp(otpVerifyRequest: OTPVerifyRequest): Promise<boolean> {
return this.checkSuccessBool(await postApiAuthOtpVerify(otpVerifyRequest, this.buildOptions()));
}
public async validateOtp(otpValidateRequest: OTPValidateRequest): Promise<boolean> {
return this.checkSuccessBool(await postApiAuthOtpValidate(otpValidateRequest, this.buildOptions()));
}
public async disableOtp(otpDisableRequest: OTPDisableRequest): Promise<boolean> {
return this.checkSuccessBool(await postApiAuthOtpDisable(otpDisableRequest, this.buildOptions()));
}
public async requestPasswordReset(
passwordResetRequest: PasswordResetRequest,
): Promise<boolean> {
return this.checkSuccessBool(await postApiAuthPasswordResetRequest(passwordResetRequest, this.buildOptions()));
}
public async confirmPasswordReset(
passwordResetVerifyRequest: PasswordResetVerifyRequest,
): Promise<boolean> {
return this.checkSuccessBool(await postApiAuthPasswordResetConfirm(passwordResetVerifyRequest, this.buildOptions()));
}
private checkSuccessBool(ret: AxiosResponse<void>): boolean {
return ret.status === 200;
}
private checkSuccessVal<T>(ret: AxiosResponse<T>): T | boolean {
if (ret.status === 200) {
return ret.data as T;
}
return false;
}
private buildOptions(): any {
return {
baseURL: this.apiUrl,
headers: {
Authorization: `Bearer ${this.jwtToken}`,
},
};
}
} }

View File

@ -1,210 +1,210 @@
openapi: 3.0.0 openapi: 3.0.0
info: info:
title: Account Management API title: Account Management API
version: "1.0" version: "1.0"
description: API for managing user accounts, including login, registration, OTP operations, and password resets. description: API for managing user accounts, including login, registration, OTP operations, and password resets.
paths: paths:
/api/auth/login: /api/auth/login:
post: post:
summary: Login to the system summary: Login to the system
requestBody: requestBody:
required: true required: true
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/LoginRequest' $ref: "#/components/schemas/LoginRequest"
responses: responses:
'200': "200":
description: Successfully logged in description: Successfully logged in
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/LoginResponse' $ref: "#/components/schemas/LoginResponse"
'401': "401":
description: Unauthorized description: Unauthorized
/api/auth/register: /api/auth/register:
post: post:
summary: Register a new account summary: Register a new account
requestBody: requestBody:
required: true required: true
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/RegisterRequest' $ref: "#/components/schemas/RegisterRequest"
responses: responses:
'200': "200":
description: Successfully registered description: Successfully registered
'400': "400":
description: Bad Request description: Bad Request
/api/auth/verify-email: /api/auth/verify-email:
post: post:
summary: Verify email address summary: Verify email address
requestBody: requestBody:
required: true required: true
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/VerifyEmailRequest' $ref: "#/components/schemas/VerifyEmailRequest"
responses: responses:
'200': "200":
description: Email verified successfully description: Email verified successfully
/api/auth/otp/generate: /api/auth/otp/generate:
get: get:
summary: Generate OTP for two-factor authentication summary: Generate OTP for two-factor authentication
responses: responses:
'200': "200":
description: OTP generated successfully description: OTP generated successfully
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/OTPGenerateResponse' $ref: "#/components/schemas/OTPGenerateResponse"
/api/auth/otp/verify: /api/auth/otp/verify:
post: post:
summary: Verify OTP for enabling two-factor authentication summary: Verify OTP for enabling two-factor authentication
requestBody: requestBody:
required: true required: true
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/OTPVerifyRequest' $ref: "#/components/schemas/OTPVerifyRequest"
responses: responses:
'200': "200":
description: OTP verified successfully description: OTP verified successfully
/api/auth/otp/validate: /api/auth/otp/validate:
post: post:
summary: Validate OTP for two-factor authentication login summary: Validate OTP for two-factor authentication login
requestBody: requestBody:
required: true required: true
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/OTPValidateRequest' $ref: "#/components/schemas/OTPValidateRequest"
responses: responses:
'200': "200":
description: OTP validated successfully description: OTP validated successfully
/api/auth/otp/disable: /api/auth/otp/disable:
post: post:
summary: Disable OTP for two-factor authentication summary: Disable OTP for two-factor authentication
requestBody: requestBody:
required: true required: true
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/OTPDisableRequest' $ref: "#/components/schemas/OTPDisableRequest"
responses: responses:
'200': "200":
description: OTP disabled successfully description: OTP disabled successfully
/api/auth/password-reset/request: /api/auth/password-reset/request:
post: post:
summary: Request a password reset summary: Request a password reset
requestBody: requestBody:
required: true required: true
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/PasswordResetRequest' $ref: "#/components/schemas/PasswordResetRequest"
responses: responses:
'200': "200":
description: Password reset requested successfully description: Password reset requested successfully
/api/auth/password-reset/confirm: /api/auth/password-reset/confirm:
post: post:
summary: Confirm a password reset summary: Confirm a password reset
requestBody: requestBody:
required: true required: true
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/PasswordResetVerifyRequest' $ref: "#/components/schemas/PasswordResetVerifyRequest"
responses: responses:
'200': "200":
description: Password reset successfully description: Password reset successfully
components: components:
schemas: schemas:
LoginRequest: LoginRequest:
type: object type: object
required: required:
- email - email
- password - password
properties: properties:
email: email:
type: string type: string
password: password:
type: string type: string
LoginResponse: LoginResponse:
type: object type: object
properties: properties:
token: token:
type: string type: string
RegisterRequest: RegisterRequest:
type: object type: object
required: required:
- firstName - firstName
- lastName - lastName
- email - email
- password - password
properties: properties:
firstName: firstName:
type: string type: string
lastName: lastName:
type: string type: string
email: email:
type: string type: string
password: password:
type: string type: string
VerifyEmailRequest: VerifyEmailRequest:
type: object type: object
required: required:
- email - email
- token - token
properties: properties:
email: email:
type: string type: string
token: token:
type: string type: string
OTPGenerateResponse: OTPGenerateResponse:
type: object type: object
properties: properties:
OTP: OTP:
type: string type: string
OTPVerifyRequest: OTPVerifyRequest:
type: object type: object
required: required:
- OTP - OTP
properties: properties:
OTP: OTP:
type: string type: string
OTPValidateRequest: OTPValidateRequest:
type: object type: object
required: required:
- OTP - OTP
properties: properties:
OTP: OTP:
type: string type: string
OTPDisableRequest: OTPDisableRequest:
type: object type: object
required: required:
- password - password
properties: properties:
password: password:
type: string type: string
PasswordResetRequest: PasswordResetRequest:
type: object type: object
required: required:
- email - email
properties: properties:
email: email:
type: string type: string
PasswordResetVerifyRequest: PasswordResetVerifyRequest:
type: object type: object
required: required:
- email - email
- token - token
- password - password
properties: properties:
email: email:
type: string type: string
token: token:
type: string type: string
password: password:
type: string type: string

View File

@ -1,21 +1,21 @@
import AccountApi from './account.js'; import AccountApi from "./account.js";
export class Sdk { export class Sdk {
private apiUrl: string; private apiUrl: string;
private accountApi?: AccountApi; private accountApi?: AccountApi;
constructor(apiUrl: string) { constructor(apiUrl: string) {
this.apiUrl = apiUrl; this.apiUrl = apiUrl;
} }
public static create(apiUrl: string): Sdk { public static create(apiUrl: string): Sdk {
return new Sdk(apiUrl); return new Sdk(apiUrl);
} }
public account(): AccountApi { public account(): AccountApi {
if (!this.accountApi) { if (!this.accountApi) {
this.accountApi = AccountApi.create(this.apiUrl); this.accountApi = AccountApi.create(this.apiUrl);
}
return this.accountApi;
} }
return this.accountApi;
}
} }