@savant-realms/federated-auth-realm-sdk-ts-js 0.4.3 → 0.4.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.
@@ -1,3 +1,4 @@
1
+ import { AxiosRequestConfig } from 'axios';
1
2
  export interface RealmInfo {
2
3
  id: string;
3
4
  url: string;
@@ -10,9 +11,15 @@ export interface SRWPWhisperRequest {
10
11
  timestamp: number;
11
12
  knownRealms: RealmInfo[];
12
13
  }
14
+ export interface SRWPDiscoveryClientConfig {
15
+ baseURL: string;
16
+ timeout?: number;
17
+ headers?: AxiosRequestConfig['headers'];
18
+ httpsAgent?: AxiosRequestConfig['httpsAgent'];
19
+ }
13
20
  export declare class SRWPDiscoveryClient {
14
21
  private client;
15
- constructor(baseURL: string);
22
+ constructor(config: string | SRWPDiscoveryClientConfig);
16
23
  whisper(data: SRWPWhisperRequest): Promise<{
17
24
  message: string;
18
25
  }>;
@@ -20,4 +27,5 @@ export declare class SRWPDiscoveryClient {
20
27
  bootstrap(peerUrl: string): Promise<{
21
28
  message: string;
22
29
  }>;
30
+ private resolveBaseUrl;
23
31
  }
package/dist/discovery.js CHANGED
@@ -6,13 +6,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.SRWPDiscoveryClient = void 0;
7
7
  const axios_1 = __importDefault(require("axios"));
8
8
  class SRWPDiscoveryClient {
9
- constructor(baseURL) {
10
- this.client = axios_1.default.create({
11
- baseURL,
9
+ constructor(config) {
10
+ const baseURL = typeof config === 'string' ? config : config.baseURL;
11
+ const resolvedBaseURL = this.resolveBaseUrl(baseURL);
12
+ const axiosConfig = {
13
+ baseURL: resolvedBaseURL,
12
14
  headers: {
13
15
  'Content-Type': 'application/json',
14
16
  },
15
- });
17
+ };
18
+ if (typeof config === 'object') {
19
+ if (config.headers) {
20
+ axiosConfig.headers = {
21
+ ...axiosConfig.headers,
22
+ ...config.headers,
23
+ };
24
+ }
25
+ if (config.timeout !== undefined) {
26
+ axiosConfig.timeout = config.timeout;
27
+ }
28
+ if (config.httpsAgent) {
29
+ axiosConfig.httpsAgent = config.httpsAgent;
30
+ }
31
+ }
32
+ this.client = axios_1.default.create(axiosConfig);
16
33
  }
17
34
  async whisper(data) {
18
35
  const response = await this.client.post('/whisper', data);
@@ -28,5 +45,29 @@ class SRWPDiscoveryClient {
28
45
  });
29
46
  return response.data;
30
47
  }
48
+ resolveBaseUrl(baseURL) {
49
+ if (!baseURL) {
50
+ throw new Error('SRWP baseURL is required');
51
+ }
52
+ let candidate = baseURL.trim();
53
+ if (!candidate) {
54
+ throw new Error('SRWP baseURL is required');
55
+ }
56
+ if (!/^https?:\/\//i.test(candidate)) {
57
+ const normalized = candidate.replace(/^\/+/, '');
58
+ const isLocalHost = normalized.startsWith('localhost') ||
59
+ normalized.startsWith('127.') ||
60
+ normalized.startsWith('0.0.0.0');
61
+ candidate = `${isLocalHost ? 'http' : 'https'}://${normalized}`;
62
+ }
63
+ let parsed;
64
+ try {
65
+ parsed = new URL(candidate);
66
+ }
67
+ catch {
68
+ throw new Error(`Invalid SRWP baseURL provided: ${baseURL}. Expected a fully qualified URL.`);
69
+ }
70
+ return `${parsed.origin}/srwp`;
71
+ }
31
72
  }
32
73
  exports.SRWPDiscoveryClient = SRWPDiscoveryClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@savant-realms/federated-auth-realm-sdk-ts-js",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "description": "Federated Auth Realm - SDK Ts/Js",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",