docpouch-client 1.1.2 → 1.1.4
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 +27 -6
- package/package.json +41 -41
- package/test-post-logout.js +0 -24
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
|
|
@@ -619,8 +626,13 @@ export default class docPouchClient {
|
|
|
619
626
|
return false;
|
|
620
627
|
}
|
|
621
628
|
// Check URL query parameters for logout confirmation
|
|
622
|
-
|
|
623
|
-
const
|
|
629
|
+
// Also check hash parameters for hash-mode routing compatibility
|
|
630
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
631
|
+
const hashQuery = window.location.hash.includes('?')
|
|
632
|
+
? window.location.hash.split('?')[1]
|
|
633
|
+
: window.location.hash.replace(/^#\/?/, '');
|
|
634
|
+
const hashParams = new URLSearchParams(hashQuery);
|
|
635
|
+
const logoutParam = searchParams.get('logout') || hashParams.get('logout');
|
|
624
636
|
// If logout parameter is explicitly 'no', user cancelled
|
|
625
637
|
if (logoutParam === 'no') {
|
|
626
638
|
// Clear the logout in progress flag
|
|
@@ -649,7 +661,7 @@ export default class docPouchClient {
|
|
|
649
661
|
if (logoutParam === null) {
|
|
650
662
|
// Check if this is a post-logout redirect - assume logout was successful
|
|
651
663
|
// unless there's an error parameter
|
|
652
|
-
const errorParam =
|
|
664
|
+
const errorParam = searchParams.get('error') || hashParams.get('error');
|
|
653
665
|
if (!errorParam) {
|
|
654
666
|
// Clear the logout in progress flag
|
|
655
667
|
if (typeof window !== 'undefined' && window.sessionStorage) {
|
|
@@ -831,7 +843,16 @@ export default class docPouchClient {
|
|
|
831
843
|
body: body ? JSON.stringify(body) : undefined
|
|
832
844
|
};
|
|
833
845
|
const normalizedEndpoint = endpoint.startsWith('/') ? endpoint : `/${endpoint}`;
|
|
834
|
-
const
|
|
846
|
+
const trimmedBaseUrl = this.baseUrl.endsWith('/') ? this.baseUrl.slice(0, -1) : this.baseUrl;
|
|
847
|
+
// If the caller's `host` already includes a port (e.g.
|
|
848
|
+
// `http://localhost:3030`) we must not append `this.port` or
|
|
849
|
+
// the URL would end up like `http://localhost:3030:3030` or
|
|
850
|
+
// `http://localhost:3030:80`. Only fall back to the constructor
|
|
851
|
+
// `port` argument when the URL has no port of its own.
|
|
852
|
+
const hasExplicitPort = /:\d+(?=\/|$)/.test(trimmedBaseUrl);
|
|
853
|
+
const normalizedBaseUrl = !hasExplicitPort && this.port
|
|
854
|
+
? `${trimmedBaseUrl}:${this.port}`
|
|
855
|
+
: trimmedBaseUrl;
|
|
835
856
|
const url = `${normalizedBaseUrl}${normalizedEndpoint}`;
|
|
836
857
|
const response = await fetch(url, options);
|
|
837
858
|
if (!response.ok) {
|
package/package.json
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "docpouch-client",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"main": "dist/index.js",
|
|
5
|
-
"types": "dist/index.d.ts",
|
|
6
|
-
"exports": {
|
|
7
|
-
".": {
|
|
8
|
-
"import": "./dist/index.js",
|
|
9
|
-
"require": "./dist/index.js"
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
"type": "module",
|
|
13
|
-
"scripts": {
|
|
14
|
-
"build": "tsc -p tsconfig.build.json",
|
|
15
|
-
"test": "node --experimental-vm-modules --no-warnings ./node_modules/jest/bin/jest.js --forceExit --silent"
|
|
16
|
-
},
|
|
17
|
-
"keywords": [
|
|
18
|
-
"docPouch",
|
|
19
|
-
"API"
|
|
20
|
-
],
|
|
21
|
-
"author": "Jan Frecè",
|
|
22
|
-
"license": "MIT",
|
|
23
|
-
"description": "Client SDK for DocPouch API - supports JWT and OIDC authentication",
|
|
24
|
-
"repository": {
|
|
25
|
-
"type": "git",
|
|
26
|
-
"url": "git+https://github.com/BFH-JTF/docpouch-client.git"
|
|
27
|
-
},
|
|
28
|
-
"devDependencies": {
|
|
29
|
-
"@types/express": "^5.0.6",
|
|
30
|
-
"@types/jest": "^30.0.0",
|
|
31
|
-
"@types/node": "^25.9.1",
|
|
32
|
-
"express": "^5.2.1",
|
|
33
|
-
"jest": "^30.4.2",
|
|
34
|
-
"socket.io": "^4.8.3",
|
|
35
|
-
"ts-jest": "^29.4.10",
|
|
36
|
-
"typescript": "^6.0.3"
|
|
37
|
-
},
|
|
38
|
-
"dependencies": {
|
|
39
|
-
"socket.io-client": "^4.8.3"
|
|
40
|
-
}
|
|
41
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "docpouch-client",
|
|
3
|
+
"version": "1.1.4",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/index.js",
|
|
9
|
+
"require": "./dist/index.js"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"type": "module",
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc -p tsconfig.build.json",
|
|
15
|
+
"test": "node --experimental-vm-modules --no-warnings ./node_modules/jest/bin/jest.js --forceExit --silent"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"docPouch",
|
|
19
|
+
"API"
|
|
20
|
+
],
|
|
21
|
+
"author": "Jan Frecè",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"description": "Client SDK for DocPouch API - supports JWT and OIDC authentication",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/BFH-JTF/docpouch-client.git"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/express": "^5.0.6",
|
|
30
|
+
"@types/jest": "^30.0.0",
|
|
31
|
+
"@types/node": "^25.9.1",
|
|
32
|
+
"express": "^5.2.1",
|
|
33
|
+
"jest": "^30.4.2",
|
|
34
|
+
"socket.io": "^4.8.3",
|
|
35
|
+
"ts-jest": "^29.4.10",
|
|
36
|
+
"typescript": "^6.0.3"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"socket.io-client": "^4.8.3"
|
|
40
|
+
}
|
|
41
|
+
}
|
package/test-post-logout.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// Test script to verify post_logout_redirect_uris functionality
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
|
|
4
|
-
// Read the built client to verify the changes
|
|
5
|
-
const clientCode = fs.readFileSync('dist/index.js', 'utf8');
|
|
6
|
-
|
|
7
|
-
console.log('Checking for post_logout_redirect_uris support...');
|
|
8
|
-
|
|
9
|
-
// Check if the interfaces include post_logout_redirect_uris
|
|
10
|
-
const hasRegistrationInterface = clientCode.includes('post_logout_redirect_uris?: string[]');
|
|
11
|
-
const hasResponseInterface = clientCode.includes('post_logout_redirect_uris?: string[]');
|
|
12
|
-
|
|
13
|
-
// Check if logout methods use postLogoutRedirectUri
|
|
14
|
-
const usesPostLogoutUri = clientCode.includes('this.oidcConfig.postLogoutRedirectUri');
|
|
15
|
-
|
|
16
|
-
console.log('I_OidcClientRegistration has post_logout_redirect_uris:', hasRegistrationInterface);
|
|
17
|
-
console.log('I_OidcClientResponse has post_logout_redirect_uris:', hasResponseInterface);
|
|
18
|
-
console.log('Logout methods use postLogoutRedirectUri:', usesPostLogoutUri);
|
|
19
|
-
|
|
20
|
-
if (hasRegistrationInterface && hasResponseInterface && usesPostLogoutUri) {
|
|
21
|
-
console.log('✅ All post_logout_redirect_uris functionality is properly implemented!');
|
|
22
|
-
} else {
|
|
23
|
-
console.log('❌ Some post_logout_redirect_uris functionality is missing');
|
|
24
|
-
}
|