@tmlmobilidade/external 20260901.1137.45 → 20260901.1533.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/clients/cp/auth.d.ts +3 -7
- package/dist/clients/cp/auth.js +16 -17
- package/package.json +1 -1
|
@@ -15,13 +15,9 @@ export declare class CPAuthClient {
|
|
|
15
15
|
static getInstance(): Promise<CPAuthClient>;
|
|
16
16
|
private connect;
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* connections, validating the necessary environment variables for each case.
|
|
21
|
-
* This method is called internally by the service and should not be used directly.
|
|
22
|
-
* @throws Will throw an error if required environment variables are missing or if the SSH tunnel setup fails.
|
|
23
|
-
* @returns A promise that resolves to the authentication URL.
|
|
18
|
+
* Resolves the auth host/port: direct to CP_AUTH_HOST:443, or via SSH tunnel
|
|
19
|
+
* when `CP_TUNNEL_ENABLED=true` (`cpSshTunnel` returns null otherwise).
|
|
24
20
|
*/
|
|
25
|
-
private
|
|
21
|
+
private getAuthenticationEndpoint;
|
|
26
22
|
}
|
|
27
23
|
export declare const cpAuthClient: CPAuthClient;
|
package/dist/clients/cp/auth.js
CHANGED
|
@@ -50,10 +50,10 @@ export class CPAuthClient {
|
|
|
50
50
|
//
|
|
51
51
|
Logger.info({ message: '[CPAuthClient] Connecting and fetching token...' });
|
|
52
52
|
//
|
|
53
|
-
//
|
|
54
|
-
const port = await this.
|
|
53
|
+
// Resolve host/port (direct or via SSH tunnel when CP_TUNNEL_ENABLED=true).
|
|
54
|
+
const { host, port } = await this.getAuthenticationEndpoint();
|
|
55
55
|
//
|
|
56
|
-
// Make the POST request to the Authentication API
|
|
56
|
+
// Make the POST request to the Authentication API,
|
|
57
57
|
// and handle the response, extracting the access token or throwing an error if the request fails.
|
|
58
58
|
const responseResult = await new Promise((resolve, reject) => {
|
|
59
59
|
//
|
|
@@ -68,10 +68,10 @@ export class CPAuthClient {
|
|
|
68
68
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
69
69
|
'host': process.env.CP_AUTH_HOST,
|
|
70
70
|
},
|
|
71
|
-
host
|
|
71
|
+
host,
|
|
72
72
|
method: 'POST',
|
|
73
73
|
path: process.env.CP_AUTH_PATH,
|
|
74
|
-
port
|
|
74
|
+
port,
|
|
75
75
|
rejectUnauthorized: false,
|
|
76
76
|
servername: process.env.CP_AUTH_HOST,
|
|
77
77
|
};
|
|
@@ -104,17 +104,11 @@ export class CPAuthClient {
|
|
|
104
104
|
this.token = responseResult.access_token;
|
|
105
105
|
}
|
|
106
106
|
/**
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* connections, validating the necessary environment variables for each case.
|
|
110
|
-
* This method is called internally by the service and should not be used directly.
|
|
111
|
-
* @throws Will throw an error if required environment variables are missing or if the SSH tunnel setup fails.
|
|
112
|
-
* @returns A promise that resolves to the authentication URL.
|
|
107
|
+
* Resolves the auth host/port: direct to CP_AUTH_HOST:443, or via SSH tunnel
|
|
108
|
+
* when `CP_TUNNEL_ENABLED=true` (`cpSshTunnel` returns null otherwise).
|
|
113
109
|
*/
|
|
114
|
-
async
|
|
110
|
+
async getAuthenticationEndpoint() {
|
|
115
111
|
//
|
|
116
|
-
//
|
|
117
|
-
// Validate required environment variables
|
|
118
112
|
if (!process.env.CP_AUTH_HOST || !process.env.CP_AUTH_PATH) {
|
|
119
113
|
throw new Error('Missing CP_AUTH_HOST or CP_AUTH_PATH environment variables.');
|
|
120
114
|
}
|
|
@@ -123,14 +117,19 @@ export class CPAuthClient {
|
|
|
123
117
|
}
|
|
124
118
|
if (!this.tunnel) {
|
|
125
119
|
this.tunnel = cpSshTunnel({ dstAddr: process.env.CP_AUTH_HOST, dstPort: 443 });
|
|
126
|
-
|
|
120
|
+
if (this.tunnel) {
|
|
121
|
+
Logger.info({ message: '[CPAuthClient] Setting up SSH Tunnel...' });
|
|
122
|
+
await this.tunnel.connect();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (!this.tunnel) {
|
|
126
|
+
return { host: process.env.CP_AUTH_HOST, port: 443 };
|
|
127
127
|
}
|
|
128
|
-
Logger.info({ message: '[CPAuthClient] Setting up SSH Tunnel...' });
|
|
129
128
|
const addr = this.tunnel.server.address();
|
|
130
129
|
if (!addr || typeof addr !== 'object') {
|
|
131
130
|
throw new Error('[CPAuthClient] Failed to retrieve SSH tunnel address.');
|
|
132
131
|
}
|
|
133
|
-
return addr.port;
|
|
132
|
+
return { host: 'localhost', port: addr.port };
|
|
134
133
|
}
|
|
135
134
|
}
|
|
136
135
|
/* * */
|