space-react-client 0.3.0 → 0.3.2

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.
Files changed (3) hide show
  1. package/dist/index.d.ts +3341 -2598
  2. package/dist/index.js +8 -6
  3. package/package.json +5 -1
package/dist/index.js CHANGED
@@ -69,7 +69,7 @@ class TokenService {
69
69
  }
70
70
  _validToken() {
71
71
  if (!this.tokenPayload) {
72
- console.warn('Token payload is not set. Please call updateLocalPricingToken first.');
72
+ console.warn('Token payload is not set. Please call TokenService.update first.');
73
73
  return false;
74
74
  }
75
75
  if (isTokenExpired(this.tokenPayload)) {
@@ -107,12 +107,14 @@ class TokenService {
107
107
  class SpaceClient {
108
108
  constructor(config) {
109
109
  this.userId = null;
110
- this.httpUrl = config.url.endsWith('/')
111
- ? config.url.slice(0, -1) + '/api/v1'
112
- : config.url + '/api/v1';
113
- this.wsUrl = config.url.replace(/^http/, 'ws') + '/events/pricings';
110
+ const normalizedUrl = config.url.endsWith('/') ? config.url.slice(0, -1) : config.url;
111
+ const parsedUrl = new URL(normalizedUrl);
112
+ const basePath = parsedUrl.pathname === '/' ? '' : parsedUrl.pathname.replace(/\/+$/, '');
113
+ const socketPath = `${basePath}/events`;
114
+ this.httpUrl = `${normalizedUrl}/api/v1`;
115
+ this.wsUrl = `${parsedUrl.protocol === 'https:' ? 'wss:' : 'ws:'}//${parsedUrl.host}${basePath}`;
114
116
  this.socketClient = io(this.wsUrl, {
115
- path: '/events',
117
+ path: socketPath,
116
118
  transports: ['websocket'],
117
119
  });
118
120
  this.pricingSocketNamespace = this.socketClient.io.socket('/pricings');
package/package.json CHANGED
@@ -1,11 +1,15 @@
1
1
  {
2
2
  "name": "space-react-client",
3
3
  "type": "module",
4
- "version": "0.3.0",
4
+ "version": "0.3.2",
5
5
  "description": "",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
8
8
  "types": "dist/index.d.ts",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/Alex-GF/space-react-client"
12
+ },
9
13
  "exports": {
10
14
  ".": {
11
15
  "types": "./dist/index.d.ts",