@taruvi/sdk 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taruvi/sdk",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "Taruvi SDK",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
@@ -15,7 +15,7 @@
15
15
  "author": "Curran C Doddabele",
16
16
  "license": "MIT",
17
17
  "peerDependencies": {
18
- "@types/node": ">=18 <21",
18
+ "@types/node": ">=18 <25",
19
19
  "typescript": ">=5.7 <6",
20
20
  "axios": ">=1 <2"
21
21
  }
@@ -29,9 +29,10 @@ export class Auth {
29
29
 
30
30
  const config = this.client.getConfig()
31
31
  const callback = callbackUrl || window.location.origin + window.location.pathname
32
+ const deskUrl = config.deskUrl || config.baseUrl
32
33
 
33
34
  // Redirect to /accounts/login/ with redirect_to parameter
34
- const loginUrl = `${config.baseUrl}/accounts/login/?redirect_to=${encodeURIComponent(callback)}`
35
+ const loginUrl = `${deskUrl}/accounts/login/?redirect_to=${encodeURIComponent(callback)}`
35
36
 
36
37
  // Optional: Store state before redirecting
37
38
  if (typeof sessionStorage !== "undefined") {
@@ -73,9 +74,10 @@ export class Auth {
73
74
 
74
75
  /**
75
76
  * Logout user and redirect to logout page
76
- * @param callbackUrl - URL to redirect to after logout (defaults to home page)
77
+ * Fetches frontendUrl from site settings for redirect
78
+ * @param callbackUrl - URL to redirect to after logout (overrides frontendUrl from settings)
77
79
  */
78
- logout(callbackUrl?: string): void {
80
+ async logout(callbackUrl?: string): Promise<void> {
79
81
  if (typeof window === "undefined") {
80
82
  console.error("logout() can only be called in browser environment")
81
83
  return
@@ -85,10 +87,24 @@ export class Auth {
85
87
  this.client.tokenClient.clearTokens()
86
88
 
87
89
  const config = this.client.getConfig()
88
- const callback = callbackUrl || window.location.origin
90
+ const deskUrl = config.deskUrl || config.baseUrl
91
+ let callback: string = callbackUrl || ""
92
+
93
+ // If no callback provided, fetch frontendUrl from site settings
94
+ if (!callback) {
95
+ try {
96
+ const settings = await this.client.httpClient.get<{ frontend_url?: string }>(
97
+ `api/sites/${config.appSlug}/metadata`
98
+ )
99
+ callback = settings.frontend_url || window.location.origin
100
+ } catch (error) {
101
+ console.error("Failed to fetch site settings, using origin:", error)
102
+ callback = window.location.origin
103
+ }
104
+ }
89
105
 
90
106
  // Redirect to /accounts/logout/
91
- const logoutUrl = `${config.baseUrl}/accounts/logout/?redirect_to=${encodeURIComponent(callback)}`
107
+ const logoutUrl = `${deskUrl}/accounts/logout/?redirect_to=${encodeURIComponent(callback)}`
92
108
 
93
109
  window.location.href = logoutUrl
94
110
  }
@@ -200,18 +216,4 @@ export class Auth {
200
216
  return null
201
217
  }
202
218
  }
203
-
204
- /**
205
- * Legacy method: Redirect to login using desk URL
206
- * @deprecated Use login() instead
207
- */
208
- async redirectToLogin(): Promise<void> {
209
- const config = this.client.getConfig()
210
- const currentUrl = typeof window !== "undefined" ? window.location.href : ""
211
-
212
- const deskUrl = config.deskUrl || config.baseUrl
213
- if (typeof window !== "undefined") {
214
- window.location.href = `${deskUrl}?redirect=${encodeURIComponent(currentUrl)}`
215
- }
216
- }
217
219
  }