@lessly/sdk-app 32.1.0 → 32.1.1
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/README.md +1 -1
- package/dist/index.cjs +19 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +19 -1
- package/dist/index.js.map +1 -1
- package/docs/recipes/local-dev.md +4 -0
- package/docs/recipes/sdk-usage.md +20 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ Create a client with `createLesslyApp`, then call operations through the Proxy n
|
|
|
14
14
|
import { createLesslyApp } from '@lessly/sdk-app';
|
|
15
15
|
|
|
16
16
|
const sdk = createLesslyApp({
|
|
17
|
-
baseUrl: 'https://api.lessly.dev',
|
|
17
|
+
baseUrl: 'https://api.lessly.dev', // or a page-relative '/api' in the browser
|
|
18
18
|
productId: 'prod_123',
|
|
19
19
|
// getCsrfToken defaults to reading the `lessly_csrf` cookie; override for SSR/tests.
|
|
20
20
|
});
|
package/dist/index.cjs
CHANGED
|
@@ -64,8 +64,26 @@ function resolveRequest(binding, input = {}) {
|
|
|
64
64
|
}
|
|
65
65
|
return { path, query, body: Object.keys(body).length > 0 ? body : void 0 };
|
|
66
66
|
}
|
|
67
|
+
function documentBase(baseUrl) {
|
|
68
|
+
const href = globalThis.location?.href;
|
|
69
|
+
if (typeof href !== "string" || href === "") {
|
|
70
|
+
throw new Error(
|
|
71
|
+
`@lessly/sdk-app: relative baseUrl "${baseUrl}" cannot be resolved outside a browser (globalThis.location is unavailable). Pass an absolute baseUrl, e.g. "https://api.lessly.dev".`
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
return href;
|
|
75
|
+
}
|
|
76
|
+
function isAbsolute(baseUrl) {
|
|
77
|
+
try {
|
|
78
|
+
new URL(baseUrl);
|
|
79
|
+
return true;
|
|
80
|
+
} catch {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
67
84
|
function buildUrl(baseUrl, path, query) {
|
|
68
|
-
const
|
|
85
|
+
const base = baseUrl.replace(/\/$/, "") + path;
|
|
86
|
+
const url = isAbsolute(baseUrl) ? new URL(base) : new URL(base, documentBase(baseUrl));
|
|
69
87
|
for (const [k, v] of Object.entries(query)) {
|
|
70
88
|
if (v === void 0 || v === null) continue;
|
|
71
89
|
if (Array.isArray(v)) v.forEach((item) => url.searchParams.append(k, String(item)));
|