@stone-js/browser-core
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -84,9 +84,2 @@ import { InitializationError, ErrorOptions, IncomingEventOptions, IncomingEvent, OutgoingResponseOptions, OutgoingResponse } from '@stone-js/core'; | ||
/** | ||
* Custom error for Browser operations. | ||
*/ | ||
declare class BrowserError extends InitializationError { | ||
constructor(message: string, options?: ErrorOptions); | ||
} | ||
/** | ||
* Class representing a collection of Cookies. | ||
@@ -193,2 +186,9 @@ */ | ||
/** | ||
* Custom error for Browser operations. | ||
*/ | ||
declare class BrowserError extends InitializationError { | ||
constructor(message: string, options?: ErrorOptions); | ||
} | ||
/** | ||
* IncomingBrowserEventOptions interface. | ||
@@ -236,3 +236,3 @@ */ | ||
*/ | ||
protected constructor({ url, locale, metadata, protocol, source, cookies, queryString }: IncomingBrowserEventOptions); | ||
protected constructor({ url, source, locale, metadata, protocol, cookies, queryString }: IncomingBrowserEventOptions); | ||
/** @returns The decoded pathname of the URL. */ | ||
@@ -379,2 +379,9 @@ get decodedPathname(): string | undefined; | ||
/** | ||
* Check if the current event method matches the given method. | ||
* | ||
* @param method - The method to check. | ||
* @returns True if the event method matches, otherwise false. | ||
*/ | ||
isMethod(method: string): boolean; | ||
/** | ||
* Retrieve a value from the query parameters. | ||
@@ -410,2 +417,9 @@ * | ||
/** | ||
* Create an instance of OutgoingBrowserResponse. | ||
* | ||
* @param options - Options for the outgoing browser response. | ||
* @returns A new instance of OutgoingBrowserResponse. | ||
*/ | ||
static create(options: OutgoingBrowserResponseOptions): OutgoingBrowserResponse; | ||
/** | ||
* Constructor for OutgoingBrowserResponse. | ||
@@ -417,4 +431,84 @@ * Initializes headers and cookies based on the provided options. | ||
constructor(options: OutgoingBrowserResponseOptions); | ||
/** | ||
* Check if the status code falls within the specified range. | ||
* | ||
* @param start - The starting value of the range (inclusive). | ||
* @param end - The ending value of the range (exclusive). | ||
* @returns True if the status code is within the specified range, otherwise false. | ||
*/ | ||
isInStatusRange(start: number, end: number): boolean; | ||
/** | ||
* Check if the status code is invalid. | ||
* | ||
* @returns True if the status code is invalid, otherwise false. | ||
*/ | ||
isInvalid(): boolean; | ||
/** | ||
* Check if the status code represents an informational response (1xx). | ||
* | ||
* @returns True if the status code is informational, otherwise false. | ||
*/ | ||
is1xx(): boolean; | ||
/** | ||
* Check if the status code represents a successful response (2xx). | ||
* | ||
* @returns True if the status code is successful, otherwise false. | ||
*/ | ||
is2xx(): boolean; | ||
/** | ||
* Check if the status code represents a redirection response (3xx). | ||
* | ||
* @returns True if the status code is a redirection, otherwise false. | ||
*/ | ||
is3xx(): boolean; | ||
/** | ||
* Check if the status code represents a client error response (4xx). | ||
* | ||
* @returns True if the status code is a client error, otherwise false. | ||
*/ | ||
is4xx(): boolean; | ||
/** | ||
* Check if the status code represents a server error response (5xx). | ||
* | ||
* @returns True if the status code is a server error, otherwise false. | ||
*/ | ||
is5xx(): boolean; | ||
/** | ||
* Check if the status code is not an error (i.e., not 4xx or 5xx). | ||
* | ||
* @returns True if the status code is not an error, otherwise false. | ||
*/ | ||
isNotError(): boolean; | ||
/** | ||
* Check if the status code is an error (i.e., 4xx or 5xx). | ||
* | ||
* @returns True if the status code is an error, otherwise false. | ||
*/ | ||
isError(): boolean; | ||
/** | ||
* Check if the status code is 200 (OK). | ||
* | ||
* @returns True if the status code is 200, otherwise false. | ||
*/ | ||
isOk(): boolean; | ||
/** | ||
* Check if the status code is 401 (Unauthorized). | ||
* | ||
* @returns True if the status code is 401, otherwise false. | ||
*/ | ||
isUnauthorized(): boolean; | ||
/** | ||
* Check if the status code is 403 (Forbidden). | ||
* | ||
* @returns True if the status code is 403, otherwise false. | ||
*/ | ||
isForbidden(): boolean; | ||
/** | ||
* Check if the status code is 404 (Not Found). | ||
* | ||
* @returns True if the status code is 404, otherwise false. | ||
*/ | ||
isNotFound(): boolean; | ||
} | ||
export { BrowserError, Cookie, CookieCollection, type CookieOptions, CookieSameSite, type HttpMethod, type IRoute, IncomingBrowserEvent, type IncomingBrowserEventOptions, OutgoingBrowserResponse, type OutgoingBrowserResponseOptions }; |
@@ -85,2 +85,12 @@ import { serialize, parse } from 'cookie'; | ||
/** | ||
* Custom error for Browser operations. | ||
*/ | ||
class BrowserError extends InitializationError { | ||
constructor(message, options) { | ||
super(message, options); | ||
this.name = 'BrowserError'; | ||
} | ||
} | ||
/** | ||
* Class representing a collection of Cookies. | ||
@@ -246,12 +256,2 @@ */ | ||
/** | ||
* Custom error for Browser operations. | ||
*/ | ||
class BrowserError extends InitializationError { | ||
constructor(message, options) { | ||
super(message, options); | ||
this.name = 'BrowserError'; | ||
} | ||
} | ||
/** | ||
* Class representing an IncomingBrowserEvent. | ||
@@ -284,3 +284,3 @@ * | ||
static create(options) { | ||
return new this(options); | ||
return new IncomingBrowserEvent(options); | ||
} | ||
@@ -293,3 +293,3 @@ /** | ||
*/ | ||
constructor({ url, locale = 'en', metadata = {}, protocol = 'http', source = undefined, cookies = undefined, queryString = undefined }) { | ||
constructor({ url, source, locale = 'en', metadata = {}, protocol = 'http', cookies = undefined, queryString = undefined }) { | ||
super({ type: IncomingBrowserEvent.INCOMING_BROWSER_EVENT, source, metadata, locale }); | ||
@@ -481,2 +481,11 @@ if (!(url instanceof URL)) { | ||
/** | ||
* Check if the current event method matches the given method. | ||
* | ||
* @param method - The method to check. | ||
* @returns True if the event method matches, otherwise false. | ||
*/ | ||
isMethod(method) { | ||
return this.method.toUpperCase() === method.toUpperCase(); | ||
} | ||
/** | ||
* Retrieve a value from the query parameters. | ||
@@ -513,2 +522,11 @@ * | ||
/** | ||
* Create an instance of OutgoingBrowserResponse. | ||
* | ||
* @param options - Options for the outgoing browser response. | ||
* @returns A new instance of OutgoingBrowserResponse. | ||
*/ | ||
static create(options) { | ||
return new OutgoingBrowserResponse(options); | ||
} | ||
/** | ||
* Constructor for OutgoingBrowserResponse. | ||
@@ -522,4 +540,112 @@ * Initializes headers and cookies based on the provided options. | ||
} | ||
/** | ||
* Check if the status code falls within the specified range. | ||
* | ||
* @param start - The starting value of the range (inclusive). | ||
* @param end - The ending value of the range (exclusive). | ||
* @returns True if the status code is within the specified range, otherwise false. | ||
*/ | ||
isInStatusRange(start, end) { | ||
const code = this.statusCode ?? 500; | ||
return code >= start && code < end; | ||
} | ||
/** | ||
* Check if the status code is invalid. | ||
* | ||
* @returns True if the status code is invalid, otherwise false. | ||
*/ | ||
isInvalid() { | ||
const code = this.statusCode ?? 500; | ||
return code < 100 || code >= 600; | ||
} | ||
/** | ||
* Check if the status code represents an informational response (1xx). | ||
* | ||
* @returns True if the status code is informational, otherwise false. | ||
*/ | ||
is1xx() { | ||
return this.isInStatusRange(100, 200); | ||
} | ||
/** | ||
* Check if the status code represents a successful response (2xx). | ||
* | ||
* @returns True if the status code is successful, otherwise false. | ||
*/ | ||
is2xx() { | ||
return this.isInStatusRange(200, 300); | ||
} | ||
/** | ||
* Check if the status code represents a redirection response (3xx). | ||
* | ||
* @returns True if the status code is a redirection, otherwise false. | ||
*/ | ||
is3xx() { | ||
return this.isInStatusRange(300, 400); | ||
} | ||
/** | ||
* Check if the status code represents a client error response (4xx). | ||
* | ||
* @returns True if the status code is a client error, otherwise false. | ||
*/ | ||
is4xx() { | ||
return this.isInStatusRange(400, 500); | ||
} | ||
/** | ||
* Check if the status code represents a server error response (5xx). | ||
* | ||
* @returns True if the status code is a server error, otherwise false. | ||
*/ | ||
is5xx() { | ||
return this.isInStatusRange(500, 600); | ||
} | ||
/** | ||
* Check if the status code is not an error (i.e., not 4xx or 5xx). | ||
* | ||
* @returns True if the status code is not an error, otherwise false. | ||
*/ | ||
isNotError() { | ||
return !this.isError(); | ||
} | ||
/** | ||
* Check if the status code is an error (i.e., 4xx or 5xx). | ||
* | ||
* @returns True if the status code is an error, otherwise false. | ||
*/ | ||
isError() { | ||
return this.is4xx() || this.is5xx(); | ||
} | ||
/** | ||
* Check if the status code is 200 (OK). | ||
* | ||
* @returns True if the status code is 200, otherwise false. | ||
*/ | ||
isOk() { | ||
return this.statusCode === 200; | ||
} | ||
/** | ||
* Check if the status code is 401 (Unauthorized). | ||
* | ||
* @returns True if the status code is 401, otherwise false. | ||
*/ | ||
isUnauthorized() { | ||
return this.statusCode === 401; | ||
} | ||
/** | ||
* Check if the status code is 403 (Forbidden). | ||
* | ||
* @returns True if the status code is 403, otherwise false. | ||
*/ | ||
isForbidden() { | ||
return this.statusCode === 403; | ||
} | ||
/** | ||
* Check if the status code is 404 (Not Found). | ||
* | ||
* @returns True if the status code is 404, otherwise false. | ||
*/ | ||
isNotFound() { | ||
return this.statusCode === 404; | ||
} | ||
} | ||
export { BrowserError, Cookie, CookieCollection, CookieSameSite, IncomingBrowserEvent, OutgoingBrowserResponse }; |
{ | ||
"name": "@stone-js/browser-core", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Stone.js Browser core", | ||
@@ -51,3 +51,3 @@ "author": "Mr. Stone <evensstone@gmail.com>", | ||
"peerDependencies": { | ||
"@stone-js/core": "^0.0.36" | ||
"@stone-js/core": "^0.0.4" | ||
}, | ||
@@ -62,3 +62,3 @@ "dependencies": { | ||
"@rollup/plugin-multi-entry": "^6.0.1", | ||
"@rollup/plugin-node-resolve": "^15.2.3", | ||
"@rollup/plugin-node-resolve": "^16.0.0", | ||
"@rollup/plugin-typescript": "^12.1.1", | ||
@@ -69,3 +69,3 @@ "@types/node": "^22.9.0", | ||
"rimraf": "^6.0.1", | ||
"rollup": "^4.1.5", | ||
"rollup": "^4.31.0", | ||
"rollup-plugin-delete": "^2.1.0", | ||
@@ -72,0 +72,0 @@ "rollup-plugin-dts": "^6.1.1", |
48558
1138