Skip to content

Commit 4bbfa0e

Browse files
committed
Refactor SessionClient class to expose methods and defaultOptions as public, enhancing accessibility for TLS session management
1 parent fddc180 commit 4bbfa0e

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

src/index.ts

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ export interface CookieResponse {
402402
* SessionClient class for managing TLS client sessions
403403
*/
404404
export class SessionClient {
405-
private readonly defaultOptions: Required<TlsClientDefaultOptions>;
405+
public defaultOptions: TlsClientDefaultOptions;
406406
private readonly sessionId: string;
407407
private readonly moduleClient: ModuleClient;
408408
private pool: Piscina | null = null;
@@ -517,7 +517,7 @@ export class SessionClient {
517517
* @param {Cookie[]} cookies - Array of cookies to set as defaults
518518
* @returns {void}
519519
*/
520-
setDefaultCookies(cookies: Cookie[]): void {
520+
public setDefaultCookies(cookies: Cookie[]): void {
521521
this.defaultOptions.defaultCookies = cookies;
522522
}
523523

@@ -526,7 +526,7 @@ export class SessionClient {
526526
* @param {Record<string, string>} headers - Object containing header key-value pairs
527527
* @returns {void}
528528
*/
529-
setDefaultHeaders(headers: Record<string, string>): void {
529+
public setDefaultHeaders(headers: Record<string, string>): void {
530530
this.defaultOptions.defaultHeaders = headers;
531531
}
532532

@@ -569,7 +569,7 @@ export class SessionClient {
569569
* @description Gets the session ID if session rotation is not enabled.
570570
* @returns {string} The session ID, or null if session rotation is enabled.
571571
*/
572-
getSession(): string {
572+
public getSession(): string {
573573
return this.sessionId;
574574
}
575575

@@ -578,7 +578,7 @@ export class SessionClient {
578578
* @param {string} [id=this.sessionId] - The ID associated with the memory to free.
579579
* @returns {Promise<unknown>} Promise that resolves when the session is destroyed
580580
*/
581-
async destroySession(id: string = this.sessionId): Promise<unknown> {
581+
public async destroySession(id: string = this.sessionId): Promise<unknown> {
582582
return this.exec('destroySession', [id]);
583583
}
584584

@@ -617,7 +617,7 @@ export class SessionClient {
617617
* @param {Partial<TlsClientOptions>} [options={}] - The request options
618618
* @returns {Promise<TlsClientResponse>} The response from the server
619619
*/
620-
async get(url: URL | string, options: Partial<TlsClientOptions> = {}): Promise<TlsClientResponse> {
620+
public async get(url: URL | string, options: Partial<TlsClientOptions> = {}): Promise<TlsClientResponse> {
621621
return this.request({
622622
sessionId: this.sessionId,
623623
requestUrl: this.convertUrl(url),
@@ -635,7 +635,11 @@ export class SessionClient {
635635
* @param {Partial<TlsClientOptions>} [options={}] - The request options
636636
* @returns {Promise<TlsClientResponse>} The response from the server
637637
*/
638-
async post(url: URL | string, body: unknown, options: Partial<TlsClientOptions> = {}): Promise<TlsClientResponse> {
638+
public async post(
639+
url: URL | string,
640+
body: unknown,
641+
options: Partial<TlsClientOptions> = {}
642+
): Promise<TlsClientResponse> {
639643
return this.request({
640644
sessionId: this.sessionId,
641645
requestUrl: this.convertUrl(url),
@@ -653,7 +657,11 @@ export class SessionClient {
653657
* @param {Partial<TlsClientOptions>} [options={}] - The request options
654658
* @returns {Promise<TlsClientResponse>} The response from the server
655659
*/
656-
async put(url: URL | string, body: unknown, options: Partial<TlsClientOptions> = {}): Promise<TlsClientResponse> {
660+
public async put(
661+
url: URL | string,
662+
body: unknown,
663+
options: Partial<TlsClientOptions> = {}
664+
): Promise<TlsClientResponse> {
657665
return this.request({
658666
sessionId: this.sessionId,
659667
requestUrl: this.convertUrl(url),
@@ -670,7 +678,7 @@ export class SessionClient {
670678
* @param {Partial<TlsClientOptions>} [options={}] - The request options
671679
* @returns {Promise<TlsClientResponse>} The response from the server
672680
*/
673-
async delete(url: URL | string, options: Partial<TlsClientOptions> = {}): Promise<TlsClientResponse> {
681+
public async delete(url: URL | string, options: Partial<TlsClientOptions> = {}): Promise<TlsClientResponse> {
674682
return this.request({
675683
sessionId: this.sessionId,
676684
requestUrl: this.convertUrl(url),
@@ -687,7 +695,7 @@ export class SessionClient {
687695
* @param {Partial<TlsClientOptions>} [options={}] - The request options
688696
* @returns {Promise<TlsClientResponse>} The response from the server
689697
*/
690-
async head(url: URL | string, options: Partial<TlsClientOptions> = {}): Promise<TlsClientResponse> {
698+
public async head(url: URL | string, options: Partial<TlsClientOptions> = {}): Promise<TlsClientResponse> {
691699
return this.request({
692700
sessionId: this.sessionId,
693701
requestUrl: this.convertUrl(url),
@@ -705,7 +713,11 @@ export class SessionClient {
705713
* @param {Partial<TlsClientOptions>} [options={}] - The request options
706714
* @returns {Promise<TlsClientResponse>} The response from the server
707715
*/
708-
async patch(url: URL | string, body: unknown, options: Partial<TlsClientOptions> = {}): Promise<TlsClientResponse> {
716+
public async patch(
717+
url: URL | string,
718+
body: unknown,
719+
options: Partial<TlsClientOptions> = {}
720+
): Promise<TlsClientResponse> {
709721
return this.request({
710722
sessionId: this.sessionId,
711723
requestUrl: this.convertUrl(url),
@@ -722,7 +734,7 @@ export class SessionClient {
722734
* @param {Partial<TlsClientOptions>} [options={}] - The request options
723735
* @returns {Promise<TlsClientResponse>} The response from the server
724736
*/
725-
async options(url: URL | string, options: Partial<TlsClientOptions> = {}): Promise<TlsClientResponse> {
737+
public async options(url: URL | string, options: Partial<TlsClientOptions> = {}): Promise<TlsClientResponse> {
726738
return this.request({
727739
sessionId: this.sessionId,
728740
requestUrl: this.convertUrl(url),
@@ -739,7 +751,7 @@ export class SessionClient {
739751
* @param {string} url - The URL to get cookies for.
740752
* @returns {Promise<CookieResponse>} Promise that resolves to the cookie response
741753
*/
742-
async getCookiesFromSession(sessionId: string, url: string): Promise<CookieResponse> {
754+
public async getCookiesFromSession(sessionId: string, url: string): Promise<CookieResponse> {
743755
if (!sessionId || !url) throw new Error('Missing sessionId or url parameter');
744756
await this.init();
745757

@@ -755,7 +767,7 @@ export class SessionClient {
755767
* @param {Cookie[]} cookies - The cookies to add.
756768
* @returns {Promise<CookieResponse>} Promise that resolves to the cookie response
757769
*/
758-
async addCookiesToSession(sessionId: string, url: string, cookies: Cookie[]): Promise<CookieResponse> {
770+
public async addCookiesToSession(sessionId: string, url: string, cookies: Cookie[]): Promise<CookieResponse> {
759771
if (!sessionId || !url || !cookies) throw new Error('Missing sessionId, url or cookies parameter');
760772
await this.init();
761773

@@ -767,7 +779,7 @@ export class SessionClient {
767779
* @description Destroy all existing sessions in order to release allocated memory.
768780
* @returns {Promise<unknown>} Promise that resolves when all sessions are destroyed
769781
*/
770-
destroyAll(): Promise<unknown> {
782+
public destroyAll(): Promise<unknown> {
771783
return this.exec('destroyAll', []);
772784
}
773785

0 commit comments

Comments
 (0)