@pagamio/frontend-commons-lib 0.8.291 → 0.8.293
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/lib/api/client.js
CHANGED
|
@@ -159,7 +159,25 @@ export class ApiClient {
|
|
|
159
159
|
* Creates a URL with query parameters.
|
|
160
160
|
*/
|
|
161
161
|
createUrl(endpoint, params) {
|
|
162
|
-
const
|
|
162
|
+
const raw = endpoint.startsWith('http') ? endpoint : `${this.config.baseURL}${endpoint}`;
|
|
163
|
+
// Absolute URLs work directly. Relative paths need a base for the URL
|
|
164
|
+
// constructor — use window.location.origin in the browser, or the
|
|
165
|
+
// server-side API_BASE_URL during SSR.
|
|
166
|
+
let url;
|
|
167
|
+
if (raw.startsWith('http')) {
|
|
168
|
+
url = new URL(raw);
|
|
169
|
+
}
|
|
170
|
+
else if (typeof window !== 'undefined') {
|
|
171
|
+
url = new URL(raw, window.location.origin);
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
// SSR: resolve relative path against the backend URL so server-side
|
|
175
|
+
// fetch calls go directly to the backend (no proxy needed server→server).
|
|
176
|
+
const ssrBase = process.env?.API_BASE_URL?.replace(/\/api\/v1$/, '');
|
|
177
|
+
if (!ssrBase)
|
|
178
|
+
throw new Error('API_BASE_URL env var is required for SSR');
|
|
179
|
+
url = new URL(raw, ssrBase);
|
|
180
|
+
}
|
|
163
181
|
if (params) {
|
|
164
182
|
Object.entries(params).forEach(([key, value]) => {
|
|
165
183
|
url.searchParams.append(key, value);
|
|
@@ -63,7 +63,19 @@ export class LogoutService {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
async invalidateServerSession(endpoint, token) {
|
|
66
|
-
|
|
66
|
+
let fullEndpoint = endpoint.startsWith('http') ? endpoint : `${this.baseUrl}${endpoint}`;
|
|
67
|
+
// Resolve relative URLs for SSR — Node's fetch requires absolute URLs.
|
|
68
|
+
if (!fullEndpoint.startsWith('http')) {
|
|
69
|
+
if (typeof window !== 'undefined') {
|
|
70
|
+
fullEndpoint = `${window.location.origin}${fullEndpoint}`;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
const serverBase = process.env?.API_BASE_URL?.replace(/\/api\/v1$/, '');
|
|
74
|
+
if (!serverBase)
|
|
75
|
+
throw new Error('API_BASE_URL env var is required for SSR');
|
|
76
|
+
fullEndpoint = `${serverBase}${fullEndpoint}`;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
67
79
|
const response = await fetch(fullEndpoint, {
|
|
68
80
|
method: 'POST',
|
|
69
81
|
headers: {
|
|
@@ -64,7 +64,20 @@ export class TokenManager {
|
|
|
64
64
|
// Requests go through the same-origin proxy so cookies are first-party
|
|
65
65
|
// and sent automatically with credentials: 'same-origin'.
|
|
66
66
|
const oldRefreshToken = this.getRefreshToken();
|
|
67
|
-
|
|
67
|
+
// Resolve relative URLs for SSR — Node's fetch requires absolute URLs.
|
|
68
|
+
let refreshUrl = `${this.baseUrl}${this.refreshEndpoint}`;
|
|
69
|
+
if (!refreshUrl.startsWith('http')) {
|
|
70
|
+
if (typeof window !== 'undefined') {
|
|
71
|
+
refreshUrl = `${window.location.origin}${refreshUrl}`;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
const serverBase = process.env?.API_BASE_URL?.replace(/\/api\/v1$/, '');
|
|
75
|
+
if (!serverBase)
|
|
76
|
+
throw new Error('API_BASE_URL env var is required for SSR');
|
|
77
|
+
refreshUrl = `${serverBase}${refreshUrl}`;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const response = await fetch(refreshUrl, {
|
|
68
81
|
method: 'POST',
|
|
69
82
|
credentials: 'same-origin',
|
|
70
83
|
headers: {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pagamio/frontend-commons-lib",
|
|
3
3
|
"description": "Pagamio library for Frontend reusable components like the form engine and table container",
|
|
4
|
-
"version": "0.8.
|
|
4
|
+
"version": "0.8.293",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
7
7
|
"provenance": false
|