@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/dist/index.d.cts
CHANGED
|
@@ -16,6 +16,11 @@ type ActionBindings = Record<string, Binding>;
|
|
|
16
16
|
type ResourceBindings = Record<string, ActionBindings>;
|
|
17
17
|
type BindingsMap = Record<string, ResourceBindings>;
|
|
18
18
|
interface LesslyAppOptions {
|
|
19
|
+
/**
|
|
20
|
+
* Absolute origin ("https://api.lessly.dev") or a path relative to the page
|
|
21
|
+
* ("/api", ""), which is resolved against globalThis.location and therefore
|
|
22
|
+
* only works in a browser.
|
|
23
|
+
*/
|
|
19
24
|
baseUrl: string;
|
|
20
25
|
productId: string;
|
|
21
26
|
getCsrfToken?: () => string | null | undefined;
|
package/dist/index.d.ts
CHANGED
|
@@ -16,6 +16,11 @@ type ActionBindings = Record<string, Binding>;
|
|
|
16
16
|
type ResourceBindings = Record<string, ActionBindings>;
|
|
17
17
|
type BindingsMap = Record<string, ResourceBindings>;
|
|
18
18
|
interface LesslyAppOptions {
|
|
19
|
+
/**
|
|
20
|
+
* Absolute origin ("https://api.lessly.dev") or a path relative to the page
|
|
21
|
+
* ("/api", ""), which is resolved against globalThis.location and therefore
|
|
22
|
+
* only works in a browser.
|
|
23
|
+
*/
|
|
19
24
|
baseUrl: string;
|
|
20
25
|
productId: string;
|
|
21
26
|
getCsrfToken?: () => string | null | undefined;
|
package/dist/index.js
CHANGED
|
@@ -62,8 +62,26 @@ function resolveRequest(binding, input = {}) {
|
|
|
62
62
|
}
|
|
63
63
|
return { path, query, body: Object.keys(body).length > 0 ? body : void 0 };
|
|
64
64
|
}
|
|
65
|
+
function documentBase(baseUrl) {
|
|
66
|
+
const href = globalThis.location?.href;
|
|
67
|
+
if (typeof href !== "string" || href === "") {
|
|
68
|
+
throw new Error(
|
|
69
|
+
`@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".`
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
return href;
|
|
73
|
+
}
|
|
74
|
+
function isAbsolute(baseUrl) {
|
|
75
|
+
try {
|
|
76
|
+
new URL(baseUrl);
|
|
77
|
+
return true;
|
|
78
|
+
} catch {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
65
82
|
function buildUrl(baseUrl, path, query) {
|
|
66
|
-
const
|
|
83
|
+
const base = baseUrl.replace(/\/$/, "") + path;
|
|
84
|
+
const url = isAbsolute(baseUrl) ? new URL(base) : new URL(base, documentBase(baseUrl));
|
|
67
85
|
for (const [k, v] of Object.entries(query)) {
|
|
68
86
|
if (v === void 0 || v === null) continue;
|
|
69
87
|
if (Array.isArray(v)) v.forEach((item) => url.searchParams.append(k, String(item)));
|