@zaptek/application-livel 0.0.0-stage → 0.15.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.
Files changed (65) hide show
  1. package/CHANGELOG.md +150 -0
  2. package/README.md +49 -2
  3. package/dist/client/livel-application-client.d.ts +32 -0
  4. package/dist/client/livel-application-client.js +71 -0
  5. package/dist/components/files/file-download-button.component.d.ts +7 -0
  6. package/dist/components/files/file-download-button.component.js +36 -0
  7. package/dist/components/files/file-upload-button.component.d.ts +11 -0
  8. package/dist/components/files/file-upload-button.component.js +41 -0
  9. package/dist/components/files/index.d.ts +4 -0
  10. package/dist/components/files/index.js +2 -0
  11. package/dist/components/index.d.ts +4 -0
  12. package/dist/components/index.js +3 -0
  13. package/dist/components/livel-application.provider.d.ts +20 -0
  14. package/dist/components/livel-application.provider.js +75 -0
  15. package/dist/components/livel-data-connection-status.component.d.ts +4 -0
  16. package/dist/components/livel-data-connection-status.component.js +122 -0
  17. package/dist/dev/dev-errors.contract.d.ts +23 -0
  18. package/dist/dev/dev-errors.contract.js +2 -0
  19. package/dist/hooks/files.hooks.d.ts +51 -0
  20. package/dist/hooks/files.hooks.js +296 -0
  21. package/dist/hooks/index.d.ts +6 -0
  22. package/dist/hooks/index.js +3 -0
  23. package/dist/hooks/rpc.hooks.d.ts +8 -0
  24. package/dist/hooks/rpc.hooks.js +26 -0
  25. package/dist/host/embedded-host.d.ts +8 -0
  26. package/dist/host/embedded-host.js +47 -0
  27. package/dist/host/livel-host.contract.d.ts +17 -0
  28. package/dist/host/livel-host.contract.js +1 -0
  29. package/dist/host/livel-host.d.ts +14 -0
  30. package/dist/host/livel-host.js +1 -0
  31. package/dist/index.d.ts +9 -0
  32. package/dist/index.js +4 -0
  33. package/dist/rpc/rpc-caller.d.ts +9 -0
  34. package/dist/rpc/rpc-caller.js +10 -0
  35. package/dist/vite/index.d.ts +1 -0
  36. package/dist/vite/index.js +1 -0
  37. package/dist/vite/livel-dev-errors.plugin.d.ts +13 -0
  38. package/dist/vite/livel-dev-errors.plugin.js +109 -0
  39. package/docs/README.md +24 -0
  40. package/docs/authentication.md +66 -0
  41. package/docs/data.md +134 -0
  42. package/docs/files.md +130 -0
  43. package/docs/getting-started.md +83 -0
  44. package/docs/rpc.md +49 -0
  45. package/docs/troubleshooting.md +15 -0
  46. package/package.json +66 -3
  47. package/template/.env.example +8 -0
  48. package/template/AGENTS.md +104 -0
  49. package/template/README.md +83 -0
  50. package/template/_gitignore +11 -0
  51. package/template/components.json +25 -0
  52. package/template/livel.json +14 -0
  53. package/template/package.json +48 -0
  54. package/template/pnpm-workspace.yaml +28 -0
  55. package/template/src/components/route-error.tsx +33 -0
  56. package/template/src/components/ui/button.tsx +57 -0
  57. package/template/src/components/ui/toast.tsx +221 -0
  58. package/template/src/lib/utils.ts +1 -0
  59. package/template/src/routeTree.gen.ts +68 -0
  60. package/template/src/router.tsx +19 -0
  61. package/template/src/routes/__root.tsx +53 -0
  62. package/template/src/routes/index.tsx +85 -0
  63. package/template/src/styles.css +148 -0
  64. package/template/tsconfig.json +21 -0
  65. package/template/vite.config.ts +28 -0
@@ -0,0 +1,23 @@
1
+ /** Path where the application's dev server streams its errors (SSE). */
2
+ export declare const livelDevErrorsPath = "/__livel/dev-errors";
3
+ /**
4
+ * A module of the application that fails to build on the dev server, in the
5
+ * browser or the server bundle. Runtime errors in the browser travel through
6
+ * the host bridge instead.
7
+ */
8
+ export type LivelDevError = {
9
+ message: string;
10
+ stack?: string;
11
+ /** Source file and position, when the bundler knows them. */
12
+ file?: string;
13
+ /** Code excerpt around the error, when the bundler knows it. */
14
+ frame?: string;
15
+ plugin?: string;
16
+ };
17
+ /** One message of the stream: the current error, or that there is none. */
18
+ export type LivelDevErrorEvent = {
19
+ type: "error";
20
+ error: LivelDevError;
21
+ } | {
22
+ type: "cleared";
23
+ };
@@ -0,0 +1,2 @@
1
+ /** Path where the application's dev server streams its errors (SSE). */
2
+ export const livelDevErrorsPath = "/__livel/dev-errors";
@@ -0,0 +1,51 @@
1
+ import { type PaginatedData } from "@zaptek/resource";
2
+ export type PaginationOptions = {
3
+ /** First page is 1. */
4
+ page?: number;
5
+ /** Results per page, from 1 to 1000; 50 by default. */
6
+ limit?: number;
7
+ };
8
+ /** Only the stable ID is assumed; callers can supply their own row type. */
9
+ export type FileRecord = {
10
+ id: string;
11
+ };
12
+ export type UploadedFile = FileRecord & {
13
+ url: string;
14
+ };
15
+ export type FileFilters = PaginationOptions & {
16
+ search?: string;
17
+ type?: string;
18
+ is_public?: boolean;
19
+ enabled?: boolean;
20
+ };
21
+ export type UploadFilesInput = {
22
+ files: File[];
23
+ is_public?: boolean;
24
+ metadata?: Record<string, unknown>;
25
+ folder?: string;
26
+ expires_at?: string | null;
27
+ };
28
+ export type UpdateFileInput = {
29
+ id: string;
30
+ name?: string;
31
+ metadata?: Record<string, unknown>;
32
+ };
33
+ export type ChangeFileVisibilityInput = {
34
+ id: string;
35
+ is_public: boolean;
36
+ };
37
+ /** Files already registered when a multi-file upload fails partway through. */
38
+ export declare function getCompletedUploads(error: unknown): UploadedFile[];
39
+ /** Reads file metadata from the current workspace under the member's RLS. */
40
+ export declare function useFiles<TFile extends FileRecord = FileRecord>(filters?: FileFilters): import("@tanstack/react-query").UseQueryResult<PaginatedData<TFile>, Error>;
41
+ export declare function useFile<TFile extends FileRecord = FileRecord>(id: string | null): import("@tanstack/react-query").UseQueryResult<import("@tanstack/react-query").NoInfer<TFile | null>, Error>;
42
+ /** Resolves a fresh URL for previewing an accessible file. */
43
+ export declare function useFileDownloadUrl(fileId: string | null): import("@tanstack/react-query").UseQueryResult<string, Error>;
44
+ /** Gets an attachment URL on demand, so a download never uses an expired link. */
45
+ export declare function useDownloadFile(): import("@tanstack/react-query").UseMutationResult<string, Error, string, unknown>;
46
+ /** Uses Livel's signed upload ticket, then registers the Storage object. */
47
+ export declare function useUploadFiles(): import("@tanstack/react-query").UseMutationResult<UploadedFile[], Error, UploadFilesInput, unknown>;
48
+ export declare function useUpdateFile<TFile extends FileRecord = FileRecord>(): import("@tanstack/react-query").UseMutationResult<TFile, Error, UpdateFileInput, unknown>;
49
+ export declare function useDeleteFile<TFile extends FileRecord = FileRecord>(): import("@tanstack/react-query").UseMutationResult<TFile, Error, string, unknown>;
50
+ export declare function useDeleteFiles<TFile extends FileRecord = FileRecord>(): import("@tanstack/react-query").UseMutationResult<TFile[], Error, string[], unknown>;
51
+ export declare function useChangeFileVisibility<TFile extends FileRecord = FileRecord>(): import("@tanstack/react-query").UseMutationResult<TFile, Error, ChangeFileVisibilityInput, unknown>;
@@ -0,0 +1,296 @@
1
+ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
2
+ import { useLivelApplication } from "../components/livel-application.provider.js";
3
+ import { buildPaginatedResponse } from "@zaptek/resource";
4
+ import { useRpcQuery } from "./rpc.hooks.js";
5
+ function normalizePagination(options) {
6
+ const page = Number.isInteger(options.page) && options.page > 0 ? options.page : 1;
7
+ const limit = Number.isInteger(options.limit)
8
+ ? Math.min(1000, Math.max(1, options.limit))
9
+ : 50;
10
+ return { page, limit, from: (page - 1) * limit, to: page * limit - 1 };
11
+ }
12
+ function fileKeys(workspaceId) {
13
+ return ["livel-application", workspaceId, "files"];
14
+ }
15
+ async function invalidateFileQueries(queryClient, workspaceId) {
16
+ await Promise.all([
17
+ queryClient.invalidateQueries({
18
+ queryKey: fileKeys(workspaceId),
19
+ }),
20
+ queryClient.invalidateQueries({
21
+ queryKey: [
22
+ "livel-application",
23
+ workspaceId,
24
+ "rpc",
25
+ ["files", "get_file_download_url"],
26
+ ],
27
+ }),
28
+ ]);
29
+ }
30
+ function requireConnectedClient(client, status) {
31
+ if (status !== "ready" || !client) {
32
+ throw new Error("Livel application is not connected");
33
+ }
34
+ return client;
35
+ }
36
+ function isRecord(value) {
37
+ return typeof value === "object" && value !== null && !Array.isArray(value);
38
+ }
39
+ function requirePreparedUpload(value) {
40
+ if (!isRecord(value) ||
41
+ typeof value.token !== "string" ||
42
+ typeof value.ticket !== "string" ||
43
+ !isRecord(value.upload) ||
44
+ typeof value.upload.bucket !== "string" ||
45
+ typeof value.upload.path !== "string" ||
46
+ typeof value.upload.type !== "string") {
47
+ throw new Error("Livel returned an invalid file upload ticket");
48
+ }
49
+ return value;
50
+ }
51
+ function requireFileRecord(value) {
52
+ if (!isRecord(value) || typeof value.id !== "string") {
53
+ throw new Error("Livel returned an invalid file record");
54
+ }
55
+ return value;
56
+ }
57
+ function requireUploadedFile(value) {
58
+ if (!isRecord(value) || typeof value.url !== "string") {
59
+ throw new Error("Livel returned an invalid uploaded file");
60
+ }
61
+ requireFileRecord(value);
62
+ return value;
63
+ }
64
+ /** Files already registered when a multi-file upload fails partway through. */
65
+ export function getCompletedUploads(error) {
66
+ if (!(error instanceof AggregateError) || !isRecord(error.cause)) {
67
+ return [];
68
+ }
69
+ const uploadedFiles = error.cause.uploaded_files;
70
+ return Array.isArray(uploadedFiles)
71
+ ? uploadedFiles.map(requireUploadedFile)
72
+ : [];
73
+ }
74
+ function requireFileRecords(value) {
75
+ if (!Array.isArray(value)) {
76
+ throw new Error("Livel returned an invalid file list");
77
+ }
78
+ return value.map(requireFileRecord);
79
+ }
80
+ function selectDownloadUrl(response) {
81
+ if (!isRecord(response) || typeof response.url !== "string") {
82
+ throw new Error("Livel returned an invalid file download URL");
83
+ }
84
+ return response.url;
85
+ }
86
+ /** Reads file metadata from the current workspace under the member's RLS. */
87
+ export function useFiles(filters = {}) {
88
+ const { client, status } = useLivelApplication();
89
+ const { page, limit, from, to } = normalizePagination(filters);
90
+ const workspaceId = client?.workspace_id ?? null;
91
+ return useQuery({
92
+ queryKey: [
93
+ ...fileKeys(workspaceId),
94
+ "list",
95
+ {
96
+ search: filters.search,
97
+ type: filters.type,
98
+ is_public: filters.is_public,
99
+ page,
100
+ limit,
101
+ },
102
+ ],
103
+ enabled: status === "ready" && !!client && filters.enabled !== false,
104
+ queryFn: async () => {
105
+ const connectedClient = requireConnectedClient(client, status);
106
+ let query = connectedClient.supabase
107
+ .from("files")
108
+ .select("*", { count: "exact" })
109
+ .eq("workspace_id", connectedClient.workspace_id);
110
+ if (filters.search)
111
+ query = query.ilike("name", `%${filters.search}%`);
112
+ if (filters.type) {
113
+ query = filters.type.endsWith("/")
114
+ ? query.like("type", `${filters.type}%`)
115
+ : query.eq("type", filters.type);
116
+ }
117
+ if (filters.is_public !== undefined) {
118
+ query = query.eq("is_public", filters.is_public);
119
+ }
120
+ const { data, count } = await query
121
+ .order("created_at", { ascending: false })
122
+ .order("id", { ascending: true })
123
+ .range(from, to)
124
+ .throwOnError();
125
+ return buildPaginatedResponse(data, count, { page, limit });
126
+ },
127
+ });
128
+ }
129
+ export function useFile(id) {
130
+ const { client, status } = useLivelApplication();
131
+ const workspaceId = client?.workspace_id ?? null;
132
+ return useQuery({
133
+ queryKey: [...fileKeys(workspaceId), "detail", id],
134
+ enabled: status === "ready" && !!client && !!id,
135
+ queryFn: async () => {
136
+ const connectedClient = requireConnectedClient(client, status);
137
+ if (!id)
138
+ throw new Error("A file ID is required");
139
+ const { data } = await connectedClient.supabase
140
+ .from("files")
141
+ .select("*")
142
+ .eq("id", id)
143
+ .eq("workspace_id", connectedClient.workspace_id)
144
+ .maybeSingle()
145
+ .throwOnError();
146
+ return data;
147
+ },
148
+ });
149
+ }
150
+ /** Resolves a fresh URL for previewing an accessible file. */
151
+ export function useFileDownloadUrl(fileId) {
152
+ return useRpcQuery({
153
+ path: ["files", "get_file_download_url"],
154
+ input: { file_id: fileId },
155
+ enabled: !!fileId,
156
+ select: selectDownloadUrl,
157
+ staleTime: 50 * 60 * 1000,
158
+ });
159
+ }
160
+ /** Gets an attachment URL on demand, so a download never uses an expired link. */
161
+ export function useDownloadFile() {
162
+ const { client, status } = useLivelApplication();
163
+ return useMutation({
164
+ mutationFn: async (fileId) => {
165
+ const connectedClient = requireConnectedClient(client, status);
166
+ return selectDownloadUrl(await connectedClient.rpc.call(["files", "get_file_download_url"], {
167
+ file_id: fileId,
168
+ download: true,
169
+ }));
170
+ },
171
+ });
172
+ }
173
+ /** Uses Livel's signed upload ticket, then registers the Storage object. */
174
+ export function useUploadFiles() {
175
+ const { client, status } = useLivelApplication();
176
+ const queryClient = useQueryClient();
177
+ return useMutation({
178
+ mutationFn: async ({ files, is_public = false, metadata = {}, folder, expires_at = null, }) => {
179
+ const connectedClient = requireConnectedClient(client, status);
180
+ const uploadedFiles = [];
181
+ for (const file of files) {
182
+ try {
183
+ const type = file.type || "application/octet-stream";
184
+ const prepared = requirePreparedUpload(await connectedClient.rpc.call(["files", "prepare_file_upload"], {
185
+ name: file.name,
186
+ type,
187
+ size: file.size,
188
+ is_public: is_public,
189
+ metadata,
190
+ folder,
191
+ expires_at: expires_at,
192
+ }));
193
+ const { error } = await connectedClient.supabase.storage
194
+ .from(prepared.upload.bucket)
195
+ .uploadToSignedUrl(prepared.upload.path, prepared.token, file, {
196
+ cacheControl: "3600",
197
+ contentType: prepared.upload.type,
198
+ });
199
+ if (error)
200
+ throw error;
201
+ uploadedFiles.push(requireUploadedFile(await connectedClient.rpc.call(["files", "complete_file_upload"], {
202
+ ticket: prepared.ticket,
203
+ })));
204
+ }
205
+ catch (error) {
206
+ throw new AggregateError([error], "File upload failed", {
207
+ cause: { uploaded_files: uploadedFiles },
208
+ });
209
+ }
210
+ }
211
+ return uploadedFiles;
212
+ },
213
+ onSuccess: async () => {
214
+ await invalidateFileQueries(queryClient, client?.workspace_id ?? null);
215
+ },
216
+ onError: async () => {
217
+ await invalidateFileQueries(queryClient, client?.workspace_id ?? null);
218
+ },
219
+ });
220
+ }
221
+ export function useUpdateFile() {
222
+ const { client, status } = useLivelApplication();
223
+ const queryClient = useQueryClient();
224
+ return useMutation({
225
+ mutationFn: async ({ id, name, metadata }) => {
226
+ const connectedClient = requireConnectedClient(client, status);
227
+ if (name === undefined && metadata === undefined) {
228
+ throw new Error("A file name or metadata update is required");
229
+ }
230
+ const { data } = await connectedClient.supabase
231
+ .from("files")
232
+ .update({ name, metadata })
233
+ .eq("id", id)
234
+ .eq("workspace_id", connectedClient.workspace_id)
235
+ .select("*")
236
+ .single()
237
+ .throwOnError();
238
+ return data;
239
+ },
240
+ onSuccess: async () => {
241
+ await invalidateFileQueries(queryClient, client?.workspace_id ?? null);
242
+ },
243
+ });
244
+ }
245
+ export function useDeleteFile() {
246
+ const { client, status } = useLivelApplication();
247
+ const queryClient = useQueryClient();
248
+ return useMutation({
249
+ mutationFn: async (fileId) => {
250
+ const connectedClient = requireConnectedClient(client, status);
251
+ return requireFileRecord(await connectedClient.rpc.call(["files", "delete_file"], {
252
+ file_id: fileId,
253
+ }));
254
+ },
255
+ onSuccess: async () => {
256
+ await invalidateFileQueries(queryClient, client?.workspace_id ?? null);
257
+ },
258
+ onError: async () => {
259
+ await invalidateFileQueries(queryClient, client?.workspace_id ?? null);
260
+ },
261
+ });
262
+ }
263
+ export function useDeleteFiles() {
264
+ const { client, status } = useLivelApplication();
265
+ const queryClient = useQueryClient();
266
+ return useMutation({
267
+ mutationFn: async (fileIds) => {
268
+ const connectedClient = requireConnectedClient(client, status);
269
+ return requireFileRecords(await connectedClient.rpc.call(["files", "delete_files"], {
270
+ file_ids: fileIds,
271
+ }));
272
+ },
273
+ onSuccess: async () => {
274
+ await invalidateFileQueries(queryClient, client?.workspace_id ?? null);
275
+ },
276
+ onError: async () => {
277
+ await invalidateFileQueries(queryClient, client?.workspace_id ?? null);
278
+ },
279
+ });
280
+ }
281
+ export function useChangeFileVisibility() {
282
+ const { client, status } = useLivelApplication();
283
+ const queryClient = useQueryClient();
284
+ return useMutation({
285
+ mutationFn: async ({ id, is_public }) => {
286
+ const connectedClient = requireConnectedClient(client, status);
287
+ return requireFileRecord(await connectedClient.rpc.call(["files", "change_file_visibility"], {
288
+ file_id: id,
289
+ is_public: is_public,
290
+ }));
291
+ },
292
+ onSuccess: async () => {
293
+ await invalidateFileQueries(queryClient, client?.workspace_id ?? null);
294
+ },
295
+ });
296
+ }
@@ -0,0 +1,6 @@
1
+ export { useReportError, useLivelApplication, } from "../components/livel-application.provider.js";
2
+ export type { LivelApplicationState, LivelApplicationStatus, } from "../components/livel-application.provider.js";
3
+ export { useRpcQuery } from "./rpc.hooks.js";
4
+ export type { RpcQueryOptions } from "./rpc.hooks.js";
5
+ export { getCompletedUploads, useChangeFileVisibility, useDeleteFile, useDeleteFiles, useDownloadFile, useFile, useFileDownloadUrl, useFiles, useUpdateFile, useUploadFiles, } from "./files.hooks.js";
6
+ export type { ChangeFileVisibilityInput, FileFilters, FileRecord, PaginationOptions, UpdateFileInput, UploadedFile, UploadFilesInput, } from "./files.hooks.js";
@@ -0,0 +1,3 @@
1
+ export { useReportError, useLivelApplication, } from "../components/livel-application.provider.js";
2
+ export { useRpcQuery } from "./rpc.hooks.js";
3
+ export { getCompletedUploads, useChangeFileVisibility, useDeleteFile, useDeleteFiles, useDownloadFile, useFile, useFileDownloadUrl, useFiles, useUpdateFile, useUploadFiles, } from "./files.hooks.js";
@@ -0,0 +1,8 @@
1
+ import { type UseQueryOptions, type UseQueryResult } from "@tanstack/react-query";
2
+ export type RpcQueryOptions<Selected = unknown> = Omit<UseQueryOptions<unknown, Error, Selected>, "queryKey" | "queryFn" | "queryKeyHashFn" | "enabled" | "initialData"> & {
3
+ path: readonly string[];
4
+ input?: unknown;
5
+ enabled?: boolean;
6
+ };
7
+ /** Queries a platform procedure with the current authenticated iframe session. */
8
+ export declare function useRpcQuery<Selected = unknown>({ path, input, enabled, ...queryOptions }: RpcQueryOptions<Selected>): UseQueryResult<Selected, Error>;
@@ -0,0 +1,26 @@
1
+ import { useQuery, } from "@tanstack/react-query";
2
+ import { useLivelApplication } from "../components/livel-application.provider.js";
3
+ /** Queries a platform procedure with the current authenticated iframe session. */
4
+ export function useRpcQuery({ path, input, enabled, ...queryOptions }) {
5
+ const { client, status } = useLivelApplication();
6
+ return useQuery({
7
+ ...queryOptions,
8
+ queryKey: [
9
+ "livel-application",
10
+ client?.workspace_id ?? null,
11
+ "rpc",
12
+ path,
13
+ input,
14
+ ],
15
+ enabled: status === "ready" && !!client && enabled !== false,
16
+ queryFn: async () => {
17
+ if (!client)
18
+ throw new Error("Application RPC is not connected");
19
+ const response = await client.rpc.call(path, input);
20
+ if (response === undefined) {
21
+ throw new Error("Application RPC returned no data");
22
+ }
23
+ return response;
24
+ },
25
+ });
26
+ }
@@ -0,0 +1,8 @@
1
+ import type { LivelHost } from "./livel-host.js";
2
+ /**
3
+ * Livel's page embedding the application: a Penpal bridge with the parent
4
+ * window, accepted only from `host_origin`. The member's session stays in
5
+ * Livel, which returns a fresh access token on every request. Uncaught errors
6
+ * and unhandled rejections are reported to it. Browser only.
7
+ */
8
+ export declare function createEmbeddedHost(hostOrigin: string): LivelHost;
@@ -0,0 +1,47 @@
1
+ import { connect, WindowMessenger } from "penpal";
2
+ const connectionTimeoutMs = 10_000;
3
+ function toApplicationError(error) {
4
+ const url = window.location.href;
5
+ if (error instanceof Error) {
6
+ return { message: error.message || error.name, stack: error.stack, url };
7
+ }
8
+ return { message: String(error), url };
9
+ }
10
+ /**
11
+ * Livel's page embedding the application: a Penpal bridge with the parent
12
+ * window, accepted only from `host_origin`. The member's session stays in
13
+ * Livel, which returns a fresh access token on every request. Uncaught errors
14
+ * and unhandled rejections are reported to it. Browser only.
15
+ */
16
+ export function createEmbeddedHost(hostOrigin) {
17
+ if (typeof window === "undefined" || window.parent === window) {
18
+ throw new Error("An embedded Livel application must run in Livel's iframe");
19
+ }
20
+ const connection = connect({
21
+ messenger: new WindowMessenger({
22
+ remoteWindow: window.parent,
23
+ allowedOrigins: [hostOrigin],
24
+ }),
25
+ timeout: connectionTimeoutMs,
26
+ });
27
+ // Reporting is best effort: Livel may be unreachable or predate the method.
28
+ const reportError = (error) => {
29
+ void connection.promise
30
+ .then(host => host.reportError(toApplicationError(error)))
31
+ .catch(() => { });
32
+ };
33
+ const onError = (event) => reportError(event.error ?? event.message);
34
+ const onRejection = (event) => reportError(event.reason);
35
+ window.addEventListener("error", onError);
36
+ window.addEventListener("unhandledrejection", onRejection);
37
+ return {
38
+ ready: connection.promise.then(() => true, () => false),
39
+ getAccessToken: async () => (await connection.promise).getAccessToken(),
40
+ reportError,
41
+ dispose: () => {
42
+ window.removeEventListener("error", onError);
43
+ window.removeEventListener("unhandledrejection", onRejection);
44
+ connection.destroy();
45
+ },
46
+ };
47
+ }
@@ -0,0 +1,17 @@
1
+ /** A runtime error of the application, as Livel receives it. */
2
+ export type LivelApplicationError = {
3
+ message: string;
4
+ stack?: string;
5
+ /** Page of the application where the error happened. */
6
+ url: string;
7
+ };
8
+ /**
9
+ * Methods the Livel platform exposes to an application iframe over Penpal.
10
+ * The platform implements this contract; applications only call it.
11
+ */
12
+ export type LivelHostMethods = {
13
+ /** Current Supabase access token of the member, refreshed by Livel. */
14
+ getAccessToken: () => Promise<string | null>;
15
+ /** Shows a runtime error to the member, who can ask Livel to fix it. */
16
+ reportError: (error: LivelApplicationError) => Promise<void>;
17
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Where the application gets its member session from. Inside Livel's iframe
3
+ * it is the parent window ({@link createEmbeddedHost}); a standalone
4
+ * application will provide its own sign-in behind the same contract.
5
+ */
6
+ export type LivelHost = {
7
+ /** Resolves to `true` once a session can be requested, `false` if never. */
8
+ ready: Promise<boolean>;
9
+ /** Current access token of the member, or `null` when signed out. */
10
+ getAccessToken: () => Promise<string | null>;
11
+ /** Shows a runtime error to the member when the host supports it. */
12
+ reportError: (error: unknown) => void;
13
+ dispose: () => void;
14
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ export { createLivelApplicationClient, readLivelApplicationConfig, } from "./client/livel-application-client.js";
2
+ export type { LivelApplicationClient, LivelApplicationConfig, } from "./client/livel-application-client.js";
3
+ export { createEmbeddedHost } from "./host/embedded-host.js";
4
+ export type { LivelHost } from "./host/livel-host.js";
5
+ export type { LivelApplicationError, LivelHostMethods, } from "./host/livel-host.contract.js";
6
+ export { createRpcCaller } from "./rpc/rpc-caller.js";
7
+ export type { RpcCaller, RpcCallerOptions } from "./rpc/rpc-caller.js";
8
+ export { livelDevErrorsPath } from "./dev/dev-errors.contract.js";
9
+ export type { LivelDevError, LivelDevErrorEvent, } from "./dev/dev-errors.contract.js";
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { createLivelApplicationClient, readLivelApplicationConfig, } from "./client/livel-application-client.js";
2
+ export { createEmbeddedHost } from "./host/embedded-host.js";
3
+ export { createRpcCaller } from "./rpc/rpc-caller.js";
4
+ export { livelDevErrorsPath } from "./dev/dev-errors.contract.js";
@@ -0,0 +1,9 @@
1
+ export type RpcCallerOptions = {
2
+ url: string;
3
+ headers?: () => Record<string, string> | Promise<Record<string, string>>;
4
+ };
5
+ export type RpcCaller = {
6
+ call(path: readonly string[], input?: unknown): Promise<unknown>;
7
+ };
8
+ /** Low-level RPC transport. Resource-specific methods build on this caller. */
9
+ export declare function createRpcCaller({ url, headers }: RpcCallerOptions): RpcCaller;
@@ -0,0 +1,10 @@
1
+ import { RPCLink } from "@orpc/client/fetch";
2
+ /** Low-level RPC transport. Resource-specific methods build on this caller. */
3
+ export function createRpcCaller({ url, headers }) {
4
+ const link = new RPCLink({ url, headers });
5
+ return {
6
+ call(path, input) {
7
+ return link.call(path, input, { context: {} });
8
+ },
9
+ };
10
+ }
@@ -0,0 +1 @@
1
+ export { livelDevErrors } from "./livel-dev-errors.plugin.js";
@@ -0,0 +1 @@
1
+ export { livelDevErrors } from "./livel-dev-errors.plugin.js";
@@ -0,0 +1,13 @@
1
+ import { type Plugin } from "vite";
2
+ /**
3
+ * Streams the dev server's build errors to Livel, which shows them over the
4
+ * preview and offers to fix them. It works even when the application cannot
5
+ * load, since only the dev server sees these errors. They come from Vite's
6
+ * logger (`customLogger`, wrapping any logger already configured), where Vite
7
+ * reports every module that fails to transform, for the browser or the server.
8
+ *
9
+ * The error clears once its module builds again; an error tied to no module
10
+ * clears on the next file change, and comes back if it persists.
11
+ * Dev server only.
12
+ */
13
+ export declare function livelDevErrors(): Plugin;