@placeos/ts-client 4.7.9 → 4.7.10

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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.7.9",
2
+ "version": "4.7.10",
3
3
  "license": "MIT",
4
4
  "name": "@placeos/ts-client",
5
5
  "author": "Alex Sorafumo <alex@place.tech>",
@@ -90,6 +90,25 @@ const _online_observer = _online.asObservable();
90
90
 
91
91
  let _failed_count = 0;
92
92
 
93
+ /**
94
+ * @private
95
+ * Resolve a URL against the authority's domain if it is a relative path.
96
+ * If the URL is already absolute (starts with http:// or https://), return as-is.
97
+ * If the URL is relative (starts with /), prepend the protocol and authority domain.
98
+ */
99
+ function resolveAuthorityUrl(url: string): string {
100
+ if (!url || url.startsWith('http://') || url.startsWith('https://')) {
101
+ return url;
102
+ }
103
+ const domain = _authority?.domain;
104
+ if (domain) {
105
+ const secure =
106
+ _options.secure || window.location?.protocol.indexOf('https') >= 0;
107
+ return `${secure ? 'https:' : 'http:'}//${domain}${url}`;
108
+ }
109
+ return url;
110
+ }
111
+
93
112
  /** API Endpoint for the retrieved version of PlaceOS */
94
113
  export function apiEndpoint(): string {
95
114
  const secure =
@@ -398,7 +417,9 @@ export function authorise(
398
417
  * Logout and clear user credentials for the application
399
418
  */
400
419
  export function logout(): void {
401
- const url = _authority ? _authority.logout_url : '/logout';
420
+ const url = resolveAuthorityUrl(
421
+ _authority ? _authority.logout_url : '/logout',
422
+ );
402
423
  fetch(url, {
403
424
  method: 'GET',
404
425
  redirect: 'manual',
@@ -582,10 +603,12 @@ export function sendToLogin(api_authority: PlaceAuthority): void {
582
603
  /* istanbul ignore else */
583
604
  if (_options.handle_login !== false && !_redirecting) {
584
605
  log('Auth', 'Redirecting to login page...');
585
- // Redirect to login form
586
- const url = api_authority!.login_url?.replace(
587
- '{{url}}',
588
- encodeURIComponent(window.location?.href),
606
+ // Redirect to login form, resolving relative URLs against the authority domain
607
+ const url = resolveAuthorityUrl(
608
+ api_authority!.login_url?.replace(
609
+ '{{url}}',
610
+ encodeURIComponent(window.location?.href),
611
+ ),
589
612
  );
590
613
  setTimeout(() => window.location?.assign(url), 300);
591
614
  _redirecting = true;