docpouch-client 1.1.2 → 1.1.3
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/coverage/lcov-report/index.html +15 -15
- package/coverage/lcov.info +694 -626
- package/dist/index.d.ts +20 -2
- package/dist/index.js +19 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,18 @@ export default class docPouchClient {
|
|
|
11
11
|
* @type {string}
|
|
12
12
|
*/
|
|
13
13
|
baseUrl: string;
|
|
14
|
+
/**
|
|
15
|
+
* The port number to use for HTTP and WebSocket connections when the
|
|
16
|
+
* base URL does not already include an explicit port. Stored from
|
|
17
|
+
* the constructor argument so the {@link request} method can
|
|
18
|
+
* build full URLs (e.g. for the OIDC dynamic client registration
|
|
19
|
+
* endpoint at `/oidc/reg`) even when the caller passes a host
|
|
20
|
+
* without a port. A port that already appears in the base URL
|
|
21
|
+
* takes precedence.
|
|
22
|
+
*
|
|
23
|
+
* @type {number}
|
|
24
|
+
*/
|
|
25
|
+
port: number;
|
|
14
26
|
/**
|
|
15
27
|
* Socket.IO socket instance for real-time communication with the server.
|
|
16
28
|
*
|
|
@@ -58,8 +70,14 @@ export default class docPouchClient {
|
|
|
58
70
|
/**
|
|
59
71
|
* Creates an instance of docPouchClient.
|
|
60
72
|
*
|
|
61
|
-
* @param {string} host - The base URL for the server.
|
|
62
|
-
*
|
|
73
|
+
* @param {string} host - The base URL for the server. May be a bare
|
|
74
|
+
* host (`http://localhost`), a host with an explicit port
|
|
75
|
+
* (`http://localhost:3030`), or a full URL with a path. When the
|
|
76
|
+
* value does not already contain a port number, the supplied
|
|
77
|
+
* `port` argument is appended to every HTTP request built by
|
|
78
|
+
* {@link request} (in addition to the WebSocket connection).
|
|
79
|
+
* @param {number} [port=80] - The port number to use when the
|
|
80
|
+
* `host` does not already specify one (default is 80).
|
|
63
81
|
* @param {(event: I_EventString, data: I_WsMessage) => void} [callback] - Optional callback function for socket events.
|
|
64
82
|
*/
|
|
65
83
|
constructor(host: string, port?: number, callback?: (event: I_EventString, data: I_WsMessage) => void);
|
package/dist/index.js
CHANGED
|
@@ -9,8 +9,14 @@ export default class docPouchClient {
|
|
|
9
9
|
/**
|
|
10
10
|
* Creates an instance of docPouchClient.
|
|
11
11
|
*
|
|
12
|
-
* @param {string} host - The base URL for the server.
|
|
13
|
-
*
|
|
12
|
+
* @param {string} host - The base URL for the server. May be a bare
|
|
13
|
+
* host (`http://localhost`), a host with an explicit port
|
|
14
|
+
* (`http://localhost:3030`), or a full URL with a path. When the
|
|
15
|
+
* value does not already contain a port number, the supplied
|
|
16
|
+
* `port` argument is appended to every HTTP request built by
|
|
17
|
+
* {@link request} (in addition to the WebSocket connection).
|
|
18
|
+
* @param {number} [port=80] - The port number to use when the
|
|
19
|
+
* `host` does not already specify one (default is 80).
|
|
14
20
|
* @param {(event: I_EventString, data: I_WsMessage) => void} [callback] - Optional callback function for socket events.
|
|
15
21
|
*/
|
|
16
22
|
constructor(host, port = 80, callback) {
|
|
@@ -47,6 +53,7 @@ export default class docPouchClient {
|
|
|
47
53
|
*/
|
|
48
54
|
this.events = {};
|
|
49
55
|
this.baseUrl = host;
|
|
56
|
+
this.port = port;
|
|
50
57
|
const socketUrl = host.includes('://') ? host : `https://${host}`;
|
|
51
58
|
const socketUrlWithPort = socketUrl.includes(':') && !socketUrl.endsWith(':')
|
|
52
59
|
? socketUrl
|
|
@@ -831,7 +838,16 @@ export default class docPouchClient {
|
|
|
831
838
|
body: body ? JSON.stringify(body) : undefined
|
|
832
839
|
};
|
|
833
840
|
const normalizedEndpoint = endpoint.startsWith('/') ? endpoint : `/${endpoint}`;
|
|
834
|
-
const
|
|
841
|
+
const trimmedBaseUrl = this.baseUrl.endsWith('/') ? this.baseUrl.slice(0, -1) : this.baseUrl;
|
|
842
|
+
// If the caller's `host` already includes a port (e.g.
|
|
843
|
+
// `http://localhost:3030`) we must not append `this.port` or
|
|
844
|
+
// the URL would end up like `http://localhost:3030:3030` or
|
|
845
|
+
// `http://localhost:3030:80`. Only fall back to the constructor
|
|
846
|
+
// `port` argument when the URL has no port of its own.
|
|
847
|
+
const hasExplicitPort = /:\d+(?=\/|$)/.test(trimmedBaseUrl);
|
|
848
|
+
const normalizedBaseUrl = !hasExplicitPort && this.port
|
|
849
|
+
? `${trimmedBaseUrl}:${this.port}`
|
|
850
|
+
: trimmedBaseUrl;
|
|
835
851
|
const url = `${normalizedBaseUrl}${normalizedEndpoint}`;
|
|
836
852
|
const response = await fetch(url, options);
|
|
837
853
|
if (!response.ok) {
|