@lepsto/sdk-app 87.0.1 → 87.2.0
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/dist/_types/index.d.ts +1 -0
- package/dist/_types/runtime/platform-base-url.d.ts +16 -0
- package/dist/index.cjs +30 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +30 -5
- package/dist/index.js.map +1 -1
- package/docs/recipes/sdk-usage.md +4 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -35,11 +35,15 @@ function isAccessDenied(err) {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
// src/runtime/csrf.ts
|
|
38
|
-
var
|
|
38
|
+
var CSRF_COOKIES = ["lepsto_csrf", "lessly_csrf"];
|
|
39
39
|
function readCsrfCookie() {
|
|
40
40
|
if (typeof document === "undefined" || !document) return null;
|
|
41
|
-
const
|
|
42
|
-
|
|
41
|
+
for (const name of CSRF_COOKIES) {
|
|
42
|
+
const match = document.cookie.match(new RegExp(`(?:^|; )${name}=([^;]*)`));
|
|
43
|
+
const value = match ? decodeURIComponent(match[1]) : "";
|
|
44
|
+
if (value) return value;
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
43
47
|
}
|
|
44
48
|
|
|
45
49
|
// src/runtime/request.ts
|
|
@@ -125,7 +129,7 @@ async function executeRequest(opts, binding, input) {
|
|
|
125
129
|
throw new LesslyApiError(
|
|
126
130
|
0,
|
|
127
131
|
"csrf_cookie_missing",
|
|
128
|
-
`CSRF cookie "lessly_csrf" is missing; the session must be re-established before mutating requests (${binding.method} ${binding.path}).`,
|
|
132
|
+
`CSRF cookie "lepsto_csrf" (or the legacy "lessly_csrf") is missing; the session must be re-established before mutating requests (${binding.method} ${binding.path}).`,
|
|
129
133
|
null
|
|
130
134
|
);
|
|
131
135
|
}
|
|
@@ -1223,12 +1227,33 @@ function accessReason(op) {
|
|
|
1223
1227
|
return "Not available for your role. Ask an admin of this product.";
|
|
1224
1228
|
}
|
|
1225
1229
|
|
|
1230
|
+
// src/runtime/platform-base-url.ts
|
|
1231
|
+
var PLATFORM_DOMAINS = ["lessly.dev", "lessly.com", "lepsto.dev", "lepsto.com"];
|
|
1232
|
+
function registrableDomain(hostname) {
|
|
1233
|
+
const host = hostname.toLowerCase().replace(/\.$/, "");
|
|
1234
|
+
return PLATFORM_DOMAINS.find((domain) => host === domain || host.endsWith(`.${domain}`));
|
|
1235
|
+
}
|
|
1236
|
+
function currentHostname() {
|
|
1237
|
+
const hostname = globalThis.location?.hostname;
|
|
1238
|
+
return typeof hostname === "string" && hostname !== "" ? hostname : void 0;
|
|
1239
|
+
}
|
|
1240
|
+
function platformApiBaseUrl(fallback) {
|
|
1241
|
+
const hostname = currentHostname();
|
|
1242
|
+
const domain = hostname === void 0 ? void 0 : registrableDomain(hostname);
|
|
1243
|
+
if (domain !== void 0) return `https://api.${domain}`;
|
|
1244
|
+
if (fallback !== void 0) return fallback;
|
|
1245
|
+
const found = hostname === void 0 ? "no globalThis.location.hostname is available (SSR, Node or a test environment)" : `host "${hostname}" is not a platform host`;
|
|
1246
|
+
throw new Error(
|
|
1247
|
+
`@lepsto/sdk-app: cannot derive the platform API base URL \u2014 ${found}. Accepted registrable domains (and any subdomain of them): ${PLATFORM_DOMAINS.join(", ")}. Pass a fallback to platformApiBaseUrl(), or an explicit baseUrl to createLesslyApp().`
|
|
1248
|
+
);
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1226
1251
|
// src/runtime/operations.ts
|
|
1227
1252
|
var operations2 = operations;
|
|
1228
1253
|
|
|
1229
1254
|
// src/runtime/compositions.ts
|
|
1230
1255
|
var compositions2 = compositions;
|
|
1231
1256
|
|
|
1232
|
-
export { LesslyApiError, accessReason, compositions2 as compositions, connectStream, createLesslyApp, isAccessDenied, operations2 as operations };
|
|
1257
|
+
export { LesslyApiError, accessReason, compositions2 as compositions, connectStream, createLesslyApp, isAccessDenied, operations2 as operations, platformApiBaseUrl };
|
|
1233
1258
|
//# sourceMappingURL=index.js.map
|
|
1234
1259
|
//# sourceMappingURL=index.js.map
|