@alore/auth-react-sdk 1.1.0-alpha.8 → 1.1.0-alpha.9

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.
@@ -242,6 +242,7 @@ export declare class AloreAuth {
242
242
  }) => Promise<any>;
243
243
  };
244
244
  private delay;
245
+ private isLocalUrl;
245
246
  fetchWithProgressiveBackoff(url: RequestInfo | URL, options?: RequestInit, config?: FetchWithProgressiveBackoffConfig): Promise<Response>;
246
247
  private parseErrorResponse;
247
248
  private throwParsedResponseError;
@@ -448,6 +448,21 @@ export class AloreAuth {
448
448
  yield new Promise((resolve) => setTimeout(resolve, ms));
449
449
  });
450
450
  }
451
+ // eslint-disable-next-line class-methods-use-this
452
+ isLocalUrl(urlString) {
453
+ try {
454
+ const parsed = new URL(urlString);
455
+ const isHttp = parsed.protocol === 'http:';
456
+ const isLoopbackHost = parsed.hostname === 'localhost' ||
457
+ parsed.hostname === '127.0.0.1' ||
458
+ parsed.hostname === '::1';
459
+ const isPort8000 = parsed.port === '8000';
460
+ return isHttp || isLoopbackHost || isPort8000;
461
+ }
462
+ catch (_e) {
463
+ return false;
464
+ }
465
+ }
451
466
  fetchWithProgressiveBackoff(
452
467
  // eslint-disable-next-line no-undef
453
468
  url,
@@ -457,7 +472,7 @@ export class AloreAuth {
457
472
  const { maxAttempts = 3, initialDelay = 200 } = config || {};
458
473
  let attempt = 0;
459
474
  let delayValue = initialDelay;
460
- const isLocal = this.aloreBaseUrl.includes('localhost') || this.aloreBaseUrl.includes('127.0.0.1');
475
+ const isLocal = this.isLocalUrl(this.aloreBaseUrl);
461
476
  // eslint-disable-next-line no-undef
462
477
  const init = Object.assign(Object.assign({}, options), { credentials: 'include', headers: Object.assign(Object.assign(Object.assign({}, options === null || options === void 0 ? void 0 : options.headers), { 'X-CLIENT-ID': this.clientId }), (isLocal && { 'CF-Connecting-IP': '127.0.0.1' })) });
463
478
  while (attempt < maxAttempts) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alore/auth-react-sdk",
3
- "version": "1.1.0-alpha.8",
3
+ "version": "1.1.0-alpha.9",
4
4
  "repository": "https://github.com/0xCarbon/alore-js",
5
5
  "description": "SDK for Alore Auth",
6
6
  "main": "dist/index.js",