@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/_types/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export type { LesslyClientBase } from './runtime/createLesslyApp.js';
|
|
|
3
3
|
export { connectStream } from './runtime/connectStream.js';
|
|
4
4
|
export { LesslyApiError, isAccessDenied } from './runtime/errors.js';
|
|
5
5
|
export { accessReason } from './runtime/access-reason.js';
|
|
6
|
+
export { platformApiBaseUrl } from './runtime/platform-base-url.js';
|
|
6
7
|
export { operations } from './runtime/operations.js';
|
|
7
8
|
export { compositions } from './runtime/compositions.js';
|
|
8
9
|
export type { LesslyAppOptions, HttpMethod, Binding, BindingsMap, ParamSpec, ParamIn, ToolLevel, ToolComposition, Operation, } from './runtime/types.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The platform API origin for the host this document is served on — `https://api.<registrable
|
|
3
|
+
* domain>` — so an App built ONCE keeps pointing at the right API after the platform moves from
|
|
4
|
+
* `lessly` to `lepsto`, with no rebuild on the cutover night. On a `lessly` host the result is
|
|
5
|
+
* byte-identical to the value Apps hardcode today, so adopting it is inert until the move.
|
|
6
|
+
*
|
|
7
|
+
* Additive and entirely opt-in: `LesslyAppOptions.baseUrl` stays REQUIRED and this SDK never
|
|
8
|
+
* calls this helper on a caller's behalf. It is something an App may pass in
|
|
9
|
+
* (`createLesslyApp({ baseUrl: platformApiBaseUrl(), ... })`), not a default.
|
|
10
|
+
*
|
|
11
|
+
* @param fallback returned instead of throwing when the host is not a recognised platform host,
|
|
12
|
+
* or when there is no `location` at all (SSR, Node, tests).
|
|
13
|
+
* @throws when the host is unrecognised (or absent) and no `fallback` was passed. The message
|
|
14
|
+
* names what was found and what is accepted.
|
|
15
|
+
*/
|
|
16
|
+
export declare function platformApiBaseUrl(fallback?: string): string;
|
package/dist/index.cjs
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
|
}
|
|
@@ -12608,6 +12612,27 @@ function accessReason(op) {
|
|
|
12608
12612
|
return "Not available for your role. Ask an admin of this product.";
|
|
12609
12613
|
}
|
|
12610
12614
|
|
|
12615
|
+
// src/runtime/platform-base-url.ts
|
|
12616
|
+
var PLATFORM_DOMAINS = ["lessly.dev", "lessly.com", "lepsto.dev", "lepsto.com"];
|
|
12617
|
+
function registrableDomain(hostname) {
|
|
12618
|
+
const host = hostname.toLowerCase().replace(/\.$/, "");
|
|
12619
|
+
return PLATFORM_DOMAINS.find((domain) => host === domain || host.endsWith(`.${domain}`));
|
|
12620
|
+
}
|
|
12621
|
+
function currentHostname() {
|
|
12622
|
+
const hostname = globalThis.location?.hostname;
|
|
12623
|
+
return typeof hostname === "string" && hostname !== "" ? hostname : void 0;
|
|
12624
|
+
}
|
|
12625
|
+
function platformApiBaseUrl(fallback) {
|
|
12626
|
+
const hostname = currentHostname();
|
|
12627
|
+
const domain = hostname === void 0 ? void 0 : registrableDomain(hostname);
|
|
12628
|
+
if (domain !== void 0) return `https://api.${domain}`;
|
|
12629
|
+
if (fallback !== void 0) return fallback;
|
|
12630
|
+
const found = hostname === void 0 ? "no globalThis.location.hostname is available (SSR, Node or a test environment)" : `host "${hostname}" is not a platform host`;
|
|
12631
|
+
throw new Error(
|
|
12632
|
+
`@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().`
|
|
12633
|
+
);
|
|
12634
|
+
}
|
|
12635
|
+
|
|
12611
12636
|
// src/runtime/operations.ts
|
|
12612
12637
|
var operations2 = operations;
|
|
12613
12638
|
|
|
@@ -12621,5 +12646,6 @@ exports.connectStream = connectStream;
|
|
|
12621
12646
|
exports.createLesslyApp = createLesslyApp;
|
|
12622
12647
|
exports.isAccessDenied = isAccessDenied;
|
|
12623
12648
|
exports.operations = operations2;
|
|
12649
|
+
exports.platformApiBaseUrl = platformApiBaseUrl;
|
|
12624
12650
|
//# sourceMappingURL=index.cjs.map
|
|
12625
12651
|
//# sourceMappingURL=index.cjs.map
|