@lessly/sdk-app 32.0.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.
Files changed (39) hide show
  1. package/README.md +1 -1
  2. package/dist/analytics/index.d.cts +1 -1
  3. package/dist/analytics/index.d.ts +1 -1
  4. package/dist/brain/index.d.cts +1 -1
  5. package/dist/brain/index.d.ts +1 -1
  6. package/dist/{client.gen-Bqi5pP6g.d.cts → client.gen-BaBUJ3xx.d.cts} +38 -0
  7. package/dist/{client.gen-Bqi5pP6g.d.ts → client.gen-BaBUJ3xx.d.ts} +38 -0
  8. package/dist/consent/index.d.cts +1 -1
  9. package/dist/consent/index.d.ts +1 -1
  10. package/dist/deployment/index.d.cts +1 -1
  11. package/dist/deployment/index.d.ts +1 -1
  12. package/dist/index.cjs +19 -1
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.cts +6 -1
  15. package/dist/index.d.ts +6 -1
  16. package/dist/index.js +19 -1
  17. package/dist/index.js.map +1 -1
  18. package/dist/mail/index.d.cts +2 -2
  19. package/dist/mail/index.d.ts +2 -2
  20. package/dist/observe/index.d.cts +1 -1
  21. package/dist/observe/index.d.ts +1 -1
  22. package/dist/organization/index.d.cts +1 -1
  23. package/dist/organization/index.d.ts +1 -1
  24. package/dist/playground/index.d.cts +1 -1
  25. package/dist/playground/index.d.ts +1 -1
  26. package/dist/realtime/index.d.cts +1 -1
  27. package/dist/realtime/index.d.ts +1 -1
  28. package/dist/support/index.d.cts +1 -1
  29. package/dist/support/index.d.ts +1 -1
  30. package/dist/tracking/index.d.cts +1 -1
  31. package/dist/tracking/index.d.ts +1 -1
  32. package/dist/users/index.d.cts +1 -1
  33. package/dist/users/index.d.ts +1 -1
  34. package/dist/waitlist/index.d.cts +1 -1
  35. package/dist/waitlist/index.d.ts +1 -1
  36. package/docs/recipes/local-dev.md +4 -0
  37. package/docs/recipes/sdk-usage.md +20 -0
  38. package/package.json +2 -2
  39. package/src/gen/types.gen.ts +38 -0
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { G as GeneratedClient } from './client.gen-Bqi5pP6g.cjs';
1
+ import { G as GeneratedClient } from './client.gen-BaBUJ3xx.cjs';
2
2
 
3
3
  type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
4
4
  type ParamIn = 'path' | 'query' | 'body';
@@ -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
@@ -1,4 +1,4 @@
1
- import { G as GeneratedClient } from './client.gen-Bqi5pP6g.js';
1
+ import { G as GeneratedClient } from './client.gen-BaBUJ3xx.js';
2
2
 
3
3
  type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
4
4
  type ParamIn = 'path' | 'query' | 'body';
@@ -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 url = new URL(baseUrl.replace(/\/$/, "") + path);
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)));