kahana-lib v1.0.31
Kahana Library
An object and reusable function library for kahana
Contents
Data Transfer Objects
Authentication
SignUpDTO
| Field | Type | Required | Description |
|---|---|---|---|
firstName | string | Yes | Please enter your first name. |
lastName | string | Yes | Please enter your last name. |
emailAddress | string | Yes | Please enter a valid email address. |
phoneNumber | string | No | Please enter your phone number. |
password | string | Yes | Please enter a password longer than 8 characters. |
VerifyEmailDTO
| Field | Type | Required | Description |
|---|---|---|---|
emailAddress | string | Yes | Please enter a valid email address. |
token | string | Yes | Please provide your verification token. |
ForgotPasswordDTO
| Field | Type | Required | Description |
|---|---|---|---|
emailAddress | string | Yes | Please enter a valid email address. |
SetPasswordDTO
| Field | Type | Required | Description |
|---|---|---|---|
token | string | Yes | Please provide your verification token. |
password | string | Yes | Please enter a password longer than 8 characters. |
LoginDTO
| Field | Type | Required | Description |
|---|---|---|---|
emailAddress | string | Yes | Please enter a valid email address. |
password | string | Yes | Please enter your password. |
LoginResponse
| Field | Type | Required | Description |
|---|---|---|---|
token | string | Yes | Authentication token. |
twoFactorAction | boolean | Yes | Indicates if a two-factor action is required. |
message | string | No | Optional message. |
Groups
CreateGroupTripDTO
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Oops! Looks like this trip needs a name. |
description | string | Yes | Don't forget to give your trip a description! |
imageUrl | string | No | Hmm, the image URL should be a valid string if provided. |
adminUserId | string | No | Admin user should be a valid string if provided. |
destination | string | Yes | Where's the trip headed? Please provide a destination. |
departureDate | Date | Yes | When does the trip start? Please provide a valid departure date. |
returnDate | Date | Yes | When does the trip end? Please provide a valid return date. |
createdAt | Date | No | Timestamp for when the trip was created. |
updatedAt | Date | No | Timestamp for when the trip was last updated. |
archived | boolean | No | Whether the trip is archived. Defaults to false. |
deletedAt | Date | No | Timestamp for when the trip was deleted. |
CreateInviteDTO
| Field | Type | Required | Description |
|---|---|---|---|
token | string | No | Please enter your authentication token. |
tokenExpiry | Date | No | Expiration date of the token. |
groupId | string | Yes | Please select a group. |
userId | string | Yes | Who's attempting to create this invite. |
status | string | No | Please provide a valid account type. |
VerifyInviteDTO
| Field | Type | Required | Description |
|---|---|---|---|
token | string | Yes | Please enter your authentication token. |
AcceptInviteDTO
| Field | Type | Required | Description |
|---|---|---|---|
token | string | Yes | Token not provided. Please contact our support. |
userId | string | Yes | User ID not provided. Please contact our support. |
UpdateGroupTripDTO
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Please provide a group identifier. |
(Inherits all fields from CreateGroupTripDTO) |
UpdateInviteDTO
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Please select an invite. |
(Inherits all fields from CreateInviteDTO) |
RemoveGroupMemberDTO
| Field | Type | Required | Description |
|---|---|---|---|
groupId | string | Yes | Please select a group. |
userId | string | Yes | Please select a user. |
Exceptions
Base Exception: KahanaException
Description
The KahanaException class serves as the base exception class for all custom exceptions. It provides a structured way to handle errors with the following properties:
| Property | Type | Description |
|---|---|---|
message | string | A message describing the error to a non technical user |
description | string | Additional details about the error for debugging. |
status | number | HTTP status code associated with the error. Defaults to 500. |
context | string | Optional context for additional information about the error. |
data | any | Additional data or payload relevant to the error. |
Derived Exceptions
Each derived exception extends KahanaException, providing more specific error scenarios. All inherited properties (message, description, status, context, and data) are available for each exception.
InvalidCredentialsException
Represents an error caused by invalid login credentials.
InvalidUserException
Represents an error caused by an invalid user.
InactiveUserException
Represents an error caused by attempting to interact with an inactive user.
IncompleteProcessException
Represents an error caused by an incomplete process or workflow.
InvalidAuthorizationException
Represents an error caused by invalid authorization details.
ExpiredAuthorizationException
Represents an error caused by expired authorization.
InvalidPayloadException
Represents an error caused by an invalid payload in a request.
DatabaseProcessException
Represents an error caused by issues during database operations.
MessagingException
Represents an error caused by messaging system failures (e.g., email or SMS).
ThirdPartyIntegrationException
Represents an error caused by a failure in third-party integrations.
ResourceNotFoundException
Represents an error caused by a requested resource not being found.
ResourceExistsException
Represents an error caused by attempting to create a resource that already exists.
UnauthorizedResourceActionException
Represents an error caused by unauthorized actions on a resource.
ExpiredResourceException
Represents an error caused by using an expired resource.
Usage
To throw an exception, create an instance of any of the classes and provide an ErrorContent object.
throw new InvalidCredentialsException({
message: "Invalid credentials",
description: "The username or password provided is incorrect.",
status: 401,
context: "AuthenticationService",
data: { attemptedUserId: "12345" },
});11 months ago
11 months ago
11 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago