@loupeink/core 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Loupe
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs ADDED
@@ -0,0 +1,356 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ LocalStorageQueueStorage: () => LocalStorageQueueStorage,
24
+ addShape: () => addShape,
25
+ clearAll: () => clearAll,
26
+ createInitialState: () => createInitialState,
27
+ createOfflineQueue: () => createOfflineQueue,
28
+ deleteFeedbackItem: () => deleteFeedbackItem,
29
+ ensureCompany: () => ensureCompany,
30
+ ensureProject: () => ensureProject,
31
+ redo: () => redo,
32
+ replaceShape: () => replaceShape,
33
+ syncFeedbackItem: () => syncFeedbackItem,
34
+ syncProject: () => syncProject,
35
+ undo: () => undo,
36
+ uploadScreenshotBytes: () => uploadScreenshotBytes,
37
+ useAppStore: () => useAppStore,
38
+ useAuthStore: () => useAuthStore,
39
+ useSyncStore: () => useSyncStore
40
+ });
41
+ module.exports = __toCommonJS(index_exports);
42
+
43
+ // src/annotation/annotationState.ts
44
+ function createInitialState(existingAnnotations) {
45
+ return {
46
+ shapes: existingAnnotations ? [...existingAnnotations] : [],
47
+ redoStack: []
48
+ };
49
+ }
50
+ function addShape(state, shape) {
51
+ return {
52
+ shapes: [...state.shapes, shape],
53
+ redoStack: []
54
+ };
55
+ }
56
+ function undo(state) {
57
+ if (state.shapes.length === 0) return state;
58
+ const shapes = state.shapes.slice(0, -1);
59
+ const popped = state.shapes[state.shapes.length - 1];
60
+ return {
61
+ shapes,
62
+ redoStack: [...state.redoStack, popped]
63
+ };
64
+ }
65
+ function redo(state) {
66
+ if (state.redoStack.length === 0) return state;
67
+ const redoStack = state.redoStack.slice(0, -1);
68
+ const popped = state.redoStack[state.redoStack.length - 1];
69
+ return {
70
+ shapes: [...state.shapes, popped],
71
+ redoStack
72
+ };
73
+ }
74
+ function replaceShape(state, index, shape) {
75
+ const shapes = [...state.shapes];
76
+ shapes[index] = shape;
77
+ return {
78
+ shapes,
79
+ redoStack: []
80
+ };
81
+ }
82
+ function clearAll(_state) {
83
+ return {
84
+ shapes: [],
85
+ redoStack: []
86
+ };
87
+ }
88
+
89
+ // src/stores/syncStore.ts
90
+ var import_zustand = require("zustand");
91
+ var useSyncStore = (0, import_zustand.create)((set) => ({
92
+ companyId: null,
93
+ isSyncing: false,
94
+ pendingCount: 0,
95
+ lastSyncedAt: null,
96
+ error: null,
97
+ setCompanyId: (id) => set({ companyId: id }),
98
+ setIsSyncing: (val) => set({ isSyncing: val }),
99
+ incrementPending: () => set((state) => ({ pendingCount: state.pendingCount + 1 })),
100
+ decrementPending: () => set((state) => ({ pendingCount: Math.max(0, state.pendingCount - 1) })),
101
+ setError: (err) => set({ error: err }),
102
+ setLastSyncedAt: (ts) => set({ lastSyncedAt: ts })
103
+ }));
104
+
105
+ // src/stores/authStore.ts
106
+ var import_zustand2 = require("zustand");
107
+ var useAuthStore = (0, import_zustand2.create)((set, get) => ({
108
+ session: null,
109
+ user: null,
110
+ loading: true,
111
+ _supabase: null,
112
+ initialize: async (supabase) => {
113
+ if (!supabase) {
114
+ set({ loading: false });
115
+ return () => {
116
+ };
117
+ }
118
+ set({ _supabase: supabase });
119
+ const { data } = await supabase.auth.getSession();
120
+ set({ session: data.session, user: data.session?.user ?? null, loading: false });
121
+ const { data: listener } = supabase.auth.onAuthStateChange((_event, session) => {
122
+ set({ session, user: session?.user ?? null });
123
+ });
124
+ return () => listener.subscription.unsubscribe();
125
+ },
126
+ signInWithEmail: async (email, password) => {
127
+ const supabase = get()._supabase;
128
+ if (!supabase) return { error: "Supabase not configured" };
129
+ const { error } = await supabase.auth.signInWithPassword({ email, password });
130
+ return { error: error?.message ?? null };
131
+ },
132
+ signUpWithEmail: async (email, password) => {
133
+ const supabase = get()._supabase;
134
+ if (!supabase) return { error: "Supabase not configured" };
135
+ const { error } = await supabase.auth.signUp({ email, password });
136
+ return { error: error?.message ?? null };
137
+ },
138
+ signInWithGitHub: async (redirectUrl) => {
139
+ const supabase = get()._supabase;
140
+ if (!supabase) return { error: "Supabase not configured" };
141
+ const { error } = await supabase.auth.signInWithOAuth({
142
+ provider: "github",
143
+ options: { redirectTo: redirectUrl }
144
+ });
145
+ return { error: error?.message ?? null };
146
+ },
147
+ signOut: async () => {
148
+ const supabase = get()._supabase;
149
+ if (!supabase) return;
150
+ await supabase.auth.signOut();
151
+ set({ session: null, user: null });
152
+ }
153
+ }));
154
+
155
+ // src/stores/appStore.ts
156
+ var import_zustand3 = require("zustand");
157
+ var useAppStore = (0, import_zustand3.create)((set) => ({
158
+ theme: "dark",
159
+ isFirstLaunch: true,
160
+ isInitialized: false,
161
+ initialize: (settings) => set({ theme: settings.theme, isFirstLaunch: settings.isFirstLaunch, isInitialized: true }),
162
+ setTheme: (theme) => set({ theme }),
163
+ setFirstLaunch: (isFirst) => set({ isFirstLaunch: isFirst })
164
+ }));
165
+
166
+ // src/queue/offlineQueue.ts
167
+ var MAX_QUEUE_SIZE = 50;
168
+ function createOfflineQueue(storage) {
169
+ async function enqueue(item) {
170
+ const queue = await storage.getQueue();
171
+ queue.push(item);
172
+ if (queue.length > MAX_QUEUE_SIZE) {
173
+ queue.shift();
174
+ }
175
+ await storage.setQueue(queue);
176
+ }
177
+ async function drain(syncFn) {
178
+ const queue = await storage.getQueue();
179
+ if (queue.length === 0) return;
180
+ const remaining = [];
181
+ for (const item of queue) {
182
+ if (typeof navigator !== "undefined" && !navigator.onLine) {
183
+ remaining.push(item);
184
+ continue;
185
+ }
186
+ try {
187
+ await syncFn(item);
188
+ } catch {
189
+ remaining.push(item);
190
+ }
191
+ }
192
+ await storage.setQueue(remaining);
193
+ if (remaining.length > 0) {
194
+ setTimeout(() => drain(syncFn).catch(console.error), 15e3);
195
+ }
196
+ }
197
+ return { enqueue, drain };
198
+ }
199
+
200
+ // src/queue/localStorage.ts
201
+ var LocalStorageQueueStorage = class {
202
+ constructor() {
203
+ this.key = "loupe_offline_queue";
204
+ }
205
+ async getQueue() {
206
+ try {
207
+ return JSON.parse(localStorage.getItem(this.key) ?? "[]");
208
+ } catch {
209
+ return [];
210
+ }
211
+ }
212
+ async setQueue(items) {
213
+ localStorage.setItem(this.key, JSON.stringify(items));
214
+ }
215
+ };
216
+
217
+ // src/storage/storageUpload.ts
218
+ async function uploadScreenshotBytes(supabase, bytes, companyId, projectId, feedbackId, filename = "screenshot.png") {
219
+ const storagePath = `${companyId}/${projectId}/${feedbackId}/${filename}`;
220
+ const { error } = await supabase.storage.from("screenshots").upload(storagePath, bytes, { contentType: "image/png", upsert: true });
221
+ if (error) {
222
+ throw new Error(`Storage upload failed: ${error.message}`);
223
+ }
224
+ }
225
+
226
+ // src/sync/syncService.ts
227
+ async function ensureCompany(supabase) {
228
+ const cached = useSyncStore.getState().companyId;
229
+ if (cached) return cached;
230
+ const { data: { user } } = await supabase.auth.getUser();
231
+ if (!user) throw new Error("Not authenticated");
232
+ const { data: profile, error: profileError } = await supabase.from("profiles").select("id, company_id").eq("id", user.id).single();
233
+ if (profileError) throw new Error(`Profile fetch failed: ${profileError.message}`);
234
+ if (profile?.company_id) {
235
+ useSyncStore.getState().setCompanyId(profile.company_id);
236
+ return profile.company_id;
237
+ }
238
+ const { data: companyId, error: rpcError } = await supabase.rpc("ensure_company_for_user");
239
+ if (rpcError || !companyId) {
240
+ throw new Error(`Company creation failed: ${rpcError?.message ?? "unknown error"}`);
241
+ }
242
+ useSyncStore.getState().setCompanyId(companyId);
243
+ return companyId;
244
+ }
245
+ async function ensureProject(supabase, localProject, companyId, userId) {
246
+ const { data: { user: currentUser } } = await supabase.auth.getUser();
247
+ const createdBy = userId ?? currentUser?.id ?? "";
248
+ const { error } = await supabase.from("projects").upsert(
249
+ {
250
+ id: localProject.id,
251
+ company_id: companyId,
252
+ created_by: createdBy,
253
+ name: localProject.name,
254
+ title: localProject.title,
255
+ project_type: localProject.projectType ?? "general",
256
+ source: "desktop"
257
+ },
258
+ { onConflict: "id" }
259
+ ).select("id").single();
260
+ if (error) throw new Error(`Project sync failed: ${error.message}`);
261
+ return localProject.id;
262
+ }
263
+ async function syncFeedbackItem(supabase, feedbackItem, projectId, companyId, screenshots) {
264
+ const { data: { user } } = await supabase.auth.getUser();
265
+ if (!user) return;
266
+ if (typeof navigator !== "undefined" && !navigator.onLine) {
267
+ throw new Error("Offline \u2014 caller should enqueue");
268
+ }
269
+ const resolvedCompanyId = companyId || await ensureCompany(supabase);
270
+ let uploadedScreenshotPath;
271
+ let uploadedAnnotatedPath;
272
+ if (feedbackItem.screenshotPath && screenshots?.screenshotBytes) {
273
+ try {
274
+ await uploadScreenshotBytes(supabase, screenshots.screenshotBytes, resolvedCompanyId, projectId, feedbackItem.id, "screenshot.png");
275
+ uploadedScreenshotPath = `${resolvedCompanyId}/${projectId}/${feedbackItem.id}/screenshot.png`;
276
+ } catch (uploadErr) {
277
+ console.warn("[syncFeedbackItem] screenshot upload failed:", uploadErr);
278
+ }
279
+ }
280
+ if (feedbackItem.annotatedScreenshotPath && screenshots?.annotatedBytes) {
281
+ try {
282
+ await uploadScreenshotBytes(supabase, screenshots.annotatedBytes, resolvedCompanyId, projectId, feedbackItem.id, "annotated.png");
283
+ uploadedAnnotatedPath = `${resolvedCompanyId}/${projectId}/${feedbackItem.id}/annotated.png`;
284
+ } catch (uploadErr) {
285
+ console.warn("[syncFeedbackItem] annotated screenshot upload failed:", uploadErr);
286
+ }
287
+ }
288
+ const { error } = await supabase.from("feedback_items").upsert(
289
+ {
290
+ id: feedbackItem.id,
291
+ project_id: projectId,
292
+ company_id: resolvedCompanyId,
293
+ created_by: user.id,
294
+ comment: feedbackItem.comment,
295
+ media_timestamp: feedbackItem.timestamp ?? null,
296
+ severity: feedbackItem.severity ?? null,
297
+ tags: feedbackItem.tags,
298
+ ...uploadedScreenshotPath !== void 0 ? { screenshot_path: uploadedScreenshotPath } : {},
299
+ ...uploadedAnnotatedPath !== void 0 ? { annotated_screenshot_path: uploadedAnnotatedPath } : {}
300
+ },
301
+ { onConflict: "id" }
302
+ ).select("id").single();
303
+ if (error) throw new Error(error.message);
304
+ const now = (/* @__PURE__ */ new Date()).toISOString();
305
+ console.log(`[sync] feedback ${feedbackItem.id} synced at ${now}`);
306
+ useSyncStore.getState().setLastSyncedAt(now);
307
+ }
308
+ async function deleteFeedbackItem(supabase, feedbackId, projectId) {
309
+ const { data: { user } } = await supabase.auth.getUser();
310
+ if (!user) return;
311
+ try {
312
+ const companyId = useSyncStore.getState().companyId || await ensureCompany(supabase);
313
+ const storagePaths = [
314
+ `${companyId}/${projectId}/${feedbackId}/screenshot.png`,
315
+ `${companyId}/${projectId}/${feedbackId}/annotated.png`
316
+ ];
317
+ await supabase.storage.from("screenshots").remove(storagePaths);
318
+ const { error } = await supabase.from("feedback_items").delete().eq("id", feedbackId);
319
+ if (error) console.error("[deleteFeedbackItem] DB delete failed:", error.message);
320
+ } catch (err) {
321
+ console.error("[deleteFeedbackItem] failed:", err);
322
+ }
323
+ }
324
+ async function syncProject(supabase, project) {
325
+ const { data: { user } } = await supabase.auth.getUser();
326
+ if (!user) return;
327
+ if (typeof navigator !== "undefined" && !navigator.onLine) return;
328
+ try {
329
+ const companyId = await ensureCompany(supabase);
330
+ await ensureProject(supabase, project, companyId, user.id);
331
+ useSyncStore.getState().setLastSyncedAt((/* @__PURE__ */ new Date()).toISOString());
332
+ } catch (err) {
333
+ console.error("[syncProject] failed:", err);
334
+ }
335
+ }
336
+ // Annotate the CommonJS export names for ESM import in node:
337
+ 0 && (module.exports = {
338
+ LocalStorageQueueStorage,
339
+ addShape,
340
+ clearAll,
341
+ createInitialState,
342
+ createOfflineQueue,
343
+ deleteFeedbackItem,
344
+ ensureCompany,
345
+ ensureProject,
346
+ redo,
347
+ replaceShape,
348
+ syncFeedbackItem,
349
+ syncProject,
350
+ undo,
351
+ uploadScreenshotBytes,
352
+ useAppStore,
353
+ useAuthStore,
354
+ useSyncStore
355
+ });
356
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/annotation/annotationState.ts","../src/stores/syncStore.ts","../src/stores/authStore.ts","../src/stores/appStore.ts","../src/queue/offlineQueue.ts","../src/queue/localStorage.ts","../src/storage/storageUpload.ts","../src/sync/syncService.ts"],"sourcesContent":["// @loupeink/core — Platform-agnostic shared types, stores, and services\n\n// Types\nexport type { WindowInfo, ProjectType, Project, AnnotationShape, FeedbackPoint, OverlayPosition } from './types/project';\n\n// Annotation state\nexport type { AnnotationState } from './annotation/annotationState';\nexport { createInitialState, addShape, undo, redo, replaceShape, clearAll } from './annotation/annotationState';\n\n// Stores\nexport { useSyncStore } from './stores/syncStore';\nexport { useAuthStore } from './stores/authStore';\nexport { useAppStore } from './stores/appStore';\n\n// Queue\nexport type { QueueItem, IQueueStorage } from './queue/types';\nexport { createOfflineQueue } from './queue/offlineQueue';\nexport { LocalStorageQueueStorage } from './queue/localStorage';\n\n// Storage\nexport { uploadScreenshotBytes } from './storage/storageUpload';\n\n// Sync service\nexport { ensureCompany, ensureProject, syncFeedbackItem, deleteFeedbackItem, syncProject } from './sync/syncService';\n","import type { AnnotationShape } from \"../types/project\";\n\nexport interface AnnotationState {\n shapes: AnnotationShape[];\n redoStack: AnnotationShape[];\n}\n\nexport function createInitialState(\n existingAnnotations?: AnnotationShape[],\n): AnnotationState {\n return {\n shapes: existingAnnotations ? [...existingAnnotations] : [],\n redoStack: [],\n };\n}\n\nexport function addShape(\n state: AnnotationState,\n shape: AnnotationShape,\n): AnnotationState {\n return {\n shapes: [...state.shapes, shape],\n redoStack: [],\n };\n}\n\nexport function undo(state: AnnotationState): AnnotationState {\n if (state.shapes.length === 0) return state;\n const shapes = state.shapes.slice(0, -1);\n const popped = state.shapes[state.shapes.length - 1];\n return {\n shapes,\n redoStack: [...state.redoStack, popped],\n };\n}\n\nexport function redo(state: AnnotationState): AnnotationState {\n if (state.redoStack.length === 0) return state;\n const redoStack = state.redoStack.slice(0, -1);\n const popped = state.redoStack[state.redoStack.length - 1];\n return {\n shapes: [...state.shapes, popped],\n redoStack,\n };\n}\n\nexport function replaceShape(\n state: AnnotationState,\n index: number,\n shape: AnnotationShape,\n): AnnotationState {\n const shapes = [...state.shapes];\n shapes[index] = shape;\n return {\n shapes,\n redoStack: [],\n };\n}\n\nexport function clearAll(_state: AnnotationState): AnnotationState {\n return {\n shapes: [],\n redoStack: [],\n };\n}\n","import { create } from \"zustand\";\n\ninterface SyncState {\n companyId: string | null;\n isSyncing: boolean;\n pendingCount: number;\n lastSyncedAt: string | null;\n error: string | null;\n // Actions\n setCompanyId: (id: string | null) => void;\n setIsSyncing: (val: boolean) => void;\n incrementPending: () => void;\n decrementPending: () => void;\n setError: (err: string | null) => void;\n setLastSyncedAt: (ts: string | null) => void;\n}\n\nexport const useSyncStore = create<SyncState>((set) => ({\n companyId: null,\n isSyncing: false,\n pendingCount: 0,\n lastSyncedAt: null,\n error: null,\n\n setCompanyId: (id) => set({ companyId: id }),\n setIsSyncing: (val) => set({ isSyncing: val }),\n incrementPending: () => set((state) => ({ pendingCount: state.pendingCount + 1 })),\n decrementPending: () =>\n set((state) => ({ pendingCount: Math.max(0, state.pendingCount - 1) })),\n setError: (err) => set({ error: err }),\n setLastSyncedAt: (ts) => set({ lastSyncedAt: ts }),\n}));\n","import type { Session, SupabaseClient, User } from \"@supabase/supabase-js\";\nimport { create } from \"zustand\";\n\ninterface AuthState {\n session: Session | null;\n user: User | null;\n loading: boolean;\n _supabase: SupabaseClient | null;\n initialize: (supabase: SupabaseClient | null) => Promise<() => void>;\n signInWithEmail: (email: string, password: string) => Promise<{ error: string | null }>;\n signUpWithEmail: (email: string, password: string) => Promise<{ error: string | null }>;\n signInWithGitHub: (redirectUrl?: string) => Promise<{ error: string | null }>;\n signOut: () => Promise<void>;\n}\n\nexport const useAuthStore = create<AuthState>((set, get) => ({\n session: null,\n user: null,\n loading: true,\n _supabase: null,\n\n initialize: async (supabase) => {\n if (!supabase) {\n set({ loading: false });\n return () => {};\n }\n set({ _supabase: supabase });\n const { data } = await supabase.auth.getSession();\n set({ session: data.session, user: data.session?.user ?? null, loading: false });\n const { data: listener } = supabase.auth.onAuthStateChange((_event, session) => {\n set({ session, user: session?.user ?? null });\n });\n return () => listener.subscription.unsubscribe();\n },\n\n signInWithEmail: async (email, password) => {\n const supabase = get()._supabase;\n if (!supabase) return { error: \"Supabase not configured\" };\n const { error } = await supabase.auth.signInWithPassword({ email, password });\n return { error: error?.message ?? null };\n },\n\n signUpWithEmail: async (email, password) => {\n const supabase = get()._supabase;\n if (!supabase) return { error: \"Supabase not configured\" };\n const { error } = await supabase.auth.signUp({ email, password });\n return { error: error?.message ?? null };\n },\n\n signInWithGitHub: async (redirectUrl) => {\n const supabase = get()._supabase;\n if (!supabase) return { error: \"Supabase not configured\" };\n const { error } = await supabase.auth.signInWithOAuth({\n provider: \"github\",\n options: { redirectTo: redirectUrl },\n });\n return { error: error?.message ?? null };\n },\n\n signOut: async () => {\n const supabase = get()._supabase;\n if (!supabase) return;\n await supabase.auth.signOut();\n set({ session: null, user: null });\n },\n}));\n","import { create } from \"zustand\";\n\ntype Theme = \"dark\" | \"light\";\n\ninterface AppStore {\n theme: Theme;\n isFirstLaunch: boolean;\n isInitialized: boolean;\n initialize: (settings: { theme: Theme; isFirstLaunch: boolean }) => void;\n setTheme: (theme: Theme) => void;\n setFirstLaunch: (isFirst: boolean) => void;\n}\n\nexport const useAppStore = create<AppStore>((set) => ({\n theme: \"dark\",\n isFirstLaunch: true,\n isInitialized: false,\n initialize: (settings) => set({ theme: settings.theme, isFirstLaunch: settings.isFirstLaunch, isInitialized: true }),\n setTheme: (theme) => set({ theme }),\n setFirstLaunch: (isFirst) => set({ isFirstLaunch: isFirst }),\n}));\n","import type { IQueueStorage, QueueItem } from \"./types\";\n\nconst MAX_QUEUE_SIZE = 50;\n\nexport function createOfflineQueue(storage: IQueueStorage) {\n async function enqueue(item: QueueItem): Promise<void> {\n const queue = await storage.getQueue();\n queue.push(item);\n if (queue.length > MAX_QUEUE_SIZE) {\n queue.shift();\n }\n await storage.setQueue(queue);\n }\n\n async function drain(syncFn: (item: QueueItem) => Promise<void>): Promise<void> {\n const queue = await storage.getQueue();\n if (queue.length === 0) return;\n\n const remaining: QueueItem[] = [];\n\n for (const item of queue) {\n if (typeof navigator !== \"undefined\" && !navigator.onLine) {\n remaining.push(item);\n continue;\n }\n try {\n await syncFn(item);\n } catch {\n remaining.push(item);\n }\n }\n\n await storage.setQueue(remaining);\n\n if (remaining.length > 0) {\n setTimeout(() => drain(syncFn).catch(console.error), 15_000);\n }\n }\n\n return { enqueue, drain };\n}\n","import type { IQueueStorage, QueueItem } from \"./types\";\n\nexport class LocalStorageQueueStorage implements IQueueStorage {\n private readonly key = \"loupe_offline_queue\";\n\n async getQueue(): Promise<QueueItem[]> {\n try {\n return JSON.parse(localStorage.getItem(this.key) ?? \"[]\") as QueueItem[];\n } catch {\n return [];\n }\n }\n\n async setQueue(items: QueueItem[]): Promise<void> {\n localStorage.setItem(this.key, JSON.stringify(items));\n }\n}\n","import type { SupabaseClient } from \"@supabase/supabase-js\";\n\n/**\n * Uploads screenshot bytes to Supabase Storage.\n * Accepts supabase client as first parameter — no global import.\n *\n * Storage path format: {companyId}/{projectId}/{feedbackId}/{filename}\n */\nexport async function uploadScreenshotBytes(\n supabase: SupabaseClient,\n bytes: Uint8Array,\n companyId: string,\n projectId: string,\n feedbackId: string,\n filename: string = \"screenshot.png\",\n): Promise<void> {\n const storagePath = `${companyId}/${projectId}/${feedbackId}/${filename}`;\n\n const { error } = await supabase.storage\n .from(\"screenshots\")\n .upload(storagePath, bytes, { contentType: \"image/png\", upsert: true });\n\n if (error) {\n throw new Error(`Storage upload failed: ${error.message}`);\n }\n}\n","import type { SupabaseClient } from \"@supabase/supabase-js\";\nimport { useSyncStore } from \"../stores/syncStore\";\nimport { uploadScreenshotBytes } from \"../storage/storageUpload\";\nimport type { FeedbackPoint, Project } from \"../types/project\";\n\n// ─── ensureCompany ────────────────────────────────────────────────────────────\n\nexport async function ensureCompany(supabase: SupabaseClient): Promise<string> {\n const cached = useSyncStore.getState().companyId;\n if (cached) return cached;\n\n const { data: { user } } = await supabase.auth.getUser();\n if (!user) throw new Error(\"Not authenticated\");\n\n const { data: profile, error: profileError } = await supabase\n .from(\"profiles\")\n .select(\"id, company_id\")\n .eq(\"id\", user.id)\n .single();\n\n if (profileError) throw new Error(`Profile fetch failed: ${profileError.message}`);\n\n if (profile?.company_id) {\n useSyncStore.getState().setCompanyId(profile.company_id as string);\n return profile.company_id as string;\n }\n\n const { data: companyId, error: rpcError } = await supabase.rpc(\"ensure_company_for_user\");\n if (rpcError || !companyId) {\n throw new Error(`Company creation failed: ${rpcError?.message ?? \"unknown error\"}`);\n }\n\n useSyncStore.getState().setCompanyId(companyId);\n return companyId;\n}\n\n// ─── ensureProject ────────────────────────────────────────────────────────────\n\nexport async function ensureProject(\n supabase: SupabaseClient,\n localProject: Project,\n companyId: string,\n userId?: string,\n): Promise<string> {\n const { data: { user: currentUser } } = await supabase.auth.getUser();\n const createdBy = userId ?? currentUser?.id ?? \"\";\n\n const { error } = await supabase\n .from(\"projects\")\n .upsert(\n {\n id: localProject.id,\n company_id: companyId,\n created_by: createdBy,\n name: localProject.name,\n title: localProject.title,\n project_type: localProject.projectType ?? \"general\",\n source: \"desktop\",\n },\n { onConflict: \"id\" },\n )\n .select(\"id\")\n .single();\n\n if (error) throw new Error(`Project sync failed: ${error.message}`);\n return localProject.id;\n}\n\n// ─── syncFeedbackItem ─────────────────────────────────────────────────────────\n\nexport async function syncFeedbackItem(\n supabase: SupabaseClient,\n feedbackItem: FeedbackPoint,\n projectId: string,\n companyId: string,\n screenshots?: {\n screenshotBytes?: Uint8Array;\n annotatedBytes?: Uint8Array;\n },\n): Promise<void> {\n const { data: { user } } = await supabase.auth.getUser();\n if (!user) return;\n\n if (typeof navigator !== \"undefined\" && !navigator.onLine) {\n // Caller handles queuing — this function only syncs\n throw new Error(\"Offline — caller should enqueue\");\n }\n\n const resolvedCompanyId = companyId || (await ensureCompany(supabase));\n\n let uploadedScreenshotPath: string | undefined;\n let uploadedAnnotatedPath: string | undefined;\n\n if (feedbackItem.screenshotPath && screenshots?.screenshotBytes) {\n try {\n await uploadScreenshotBytes(supabase, screenshots.screenshotBytes, resolvedCompanyId, projectId, feedbackItem.id, \"screenshot.png\");\n uploadedScreenshotPath = `${resolvedCompanyId}/${projectId}/${feedbackItem.id}/screenshot.png`;\n } catch (uploadErr) {\n console.warn(\"[syncFeedbackItem] screenshot upload failed:\", uploadErr);\n }\n }\n\n if (feedbackItem.annotatedScreenshotPath && screenshots?.annotatedBytes) {\n try {\n await uploadScreenshotBytes(supabase, screenshots.annotatedBytes, resolvedCompanyId, projectId, feedbackItem.id, \"annotated.png\");\n uploadedAnnotatedPath = `${resolvedCompanyId}/${projectId}/${feedbackItem.id}/annotated.png`;\n } catch (uploadErr) {\n console.warn(\"[syncFeedbackItem] annotated screenshot upload failed:\", uploadErr);\n }\n }\n\n const { error } = await supabase\n .from(\"feedback_items\")\n .upsert(\n {\n id: feedbackItem.id,\n project_id: projectId,\n company_id: resolvedCompanyId,\n created_by: user.id,\n comment: feedbackItem.comment,\n media_timestamp: feedbackItem.timestamp ?? null,\n severity: feedbackItem.severity ?? null,\n tags: feedbackItem.tags,\n ...(uploadedScreenshotPath !== undefined ? { screenshot_path: uploadedScreenshotPath } : {}),\n ...(uploadedAnnotatedPath !== undefined ? { annotated_screenshot_path: uploadedAnnotatedPath } : {}),\n },\n { onConflict: \"id\" },\n )\n .select(\"id\")\n .single();\n\n if (error) throw new Error(error.message);\n\n const now = new Date().toISOString();\n console.log(`[sync] feedback ${feedbackItem.id} synced at ${now}`);\n useSyncStore.getState().setLastSyncedAt(now);\n}\n\n// ─── deleteFeedbackItem ───────────────────────────────────────────────────────\n\nexport async function deleteFeedbackItem(\n supabase: SupabaseClient,\n feedbackId: string,\n projectId: string,\n): Promise<void> {\n const { data: { user } } = await supabase.auth.getUser();\n if (!user) return;\n\n try {\n const companyId = useSyncStore.getState().companyId || (await ensureCompany(supabase));\n\n const storagePaths = [\n `${companyId}/${projectId}/${feedbackId}/screenshot.png`,\n `${companyId}/${projectId}/${feedbackId}/annotated.png`,\n ];\n await supabase.storage.from(\"screenshots\").remove(storagePaths);\n\n const { error } = await supabase.from(\"feedback_items\").delete().eq(\"id\", feedbackId);\n if (error) console.error(\"[deleteFeedbackItem] DB delete failed:\", error.message);\n } catch (err) {\n console.error(\"[deleteFeedbackItem] failed:\", err);\n }\n}\n\n// ─── syncProject ──────────────────────────────────────────────────────────────\n\nexport async function syncProject(supabase: SupabaseClient, project: Project): Promise<void> {\n const { data: { user } } = await supabase.auth.getUser();\n if (!user) return;\n\n if (typeof navigator !== \"undefined\" && !navigator.onLine) return;\n\n try {\n const companyId = await ensureCompany(supabase);\n await ensureProject(supabase, project, companyId, user.id);\n useSyncStore.getState().setLastSyncedAt(new Date().toISOString());\n } catch (err) {\n console.error(\"[syncProject] failed:\", err);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACOO,SAAS,mBACd,qBACiB;AACjB,SAAO;AAAA,IACL,QAAQ,sBAAsB,CAAC,GAAG,mBAAmB,IAAI,CAAC;AAAA,IAC1D,WAAW,CAAC;AAAA,EACd;AACF;AAEO,SAAS,SACd,OACA,OACiB;AACjB,SAAO;AAAA,IACL,QAAQ,CAAC,GAAG,MAAM,QAAQ,KAAK;AAAA,IAC/B,WAAW,CAAC;AAAA,EACd;AACF;AAEO,SAAS,KAAK,OAAyC;AAC5D,MAAI,MAAM,OAAO,WAAW,EAAG,QAAO;AACtC,QAAM,SAAS,MAAM,OAAO,MAAM,GAAG,EAAE;AACvC,QAAM,SAAS,MAAM,OAAO,MAAM,OAAO,SAAS,CAAC;AACnD,SAAO;AAAA,IACL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E,gBAAgB,GAAG;AAC7C;AAIA,eAAsB,mBACpB,UACA,YACA,WACe;AACf,QAAM,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,MAAM,SAAS,KAAK,QAAQ;AACvD,MAAI,CAAC,KAAM;AAEX,MAAI;AACF,UAAM,YAAY,aAAa,SAAS,EAAE,aAAc,MAAM,cAAc,QAAQ;AAEpF,UAAM,eAAe;AAAA,MACnB,GAAG,SAAS,IAAI,SAAS,IAAI,UAAU;AAAA,MACvC,GAAG,SAAS,IAAI,SAAS,IAAI,UAAU;AAAA,IACzC;AACA,UAAM,SAAS,QAAQ,KAAK,aAAa,EAAE,OAAO,YAAY;AAE9D,UAAM,EAAE,MAAM,IAAI,MAAM,SAAS,KAAK,gBAAgB,EAAE,OAAO,EAAE,GAAG,MAAM,UAAU;AACpF,QAAI,MAAO,SAAQ,MAAM,0CAA0C,MAAM,OAAO;AAAA,EAClF,SAAS,KAAK;AACZ,YAAQ,MAAM,gCAAgC,GAAG;AAAA,EACnD;AACF;AAIA,eAAsB,YAAY,UAA0B,SAAiC;AAC3F,QAAM,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,MAAM,SAAS,KAAK,QAAQ;AACvD,MAAI,CAAC,KAAM;AAEX,MAAI,OAAO,cAAc,eAAe,CAAC,UAAU,OAAQ;AAE3D,MAAI;AACF,UAAM,YAAY,MAAM,cAAc,QAAQ;AAC9C,UAAM,cAAc,UAAU,SAAS,WAAW,KAAK,EAAE;AACzD,iBAAa,SAAS,EAAE,iBAAgB,oBAAI,KAAK,GAAE,YAAY,CAAC;AAAA,EAClE,SAAS,KAAK;AACZ,YAAQ,MAAM,yBAAyB,GAAG;AAAA,EAC5C;AACF;","names":["import_zustand","import_zustand"]}
@@ -0,0 +1,145 @@
1
+ import * as zustand from 'zustand';
2
+ import { Session, User, SupabaseClient } from '@supabase/supabase-js';
3
+
4
+ interface WindowInfo {
5
+ id: string;
6
+ title: string;
7
+ appName: string;
8
+ }
9
+ type ProjectType = "video" | "design" | "website" | "general";
10
+ interface Project {
11
+ id: string;
12
+ name: string;
13
+ title: string;
14
+ projectType?: ProjectType;
15
+ createdAt: string;
16
+ updatedAt: string;
17
+ feedbackPoints: FeedbackPoint[];
18
+ overlayPosition?: OverlayPosition;
19
+ }
20
+ interface AnnotationShape {
21
+ type: "rect" | "arrow" | "freehand" | "text" | "blur" | "circle" | "line";
22
+ points: number[][];
23
+ color: string;
24
+ strokeWidth: number;
25
+ pressure?: number[];
26
+ text?: string;
27
+ fontSize?: number;
28
+ }
29
+ interface FeedbackPoint {
30
+ id: string;
31
+ comment: string;
32
+ timestamp?: string;
33
+ severity?: "critical" | "major" | "minor" | "suggestion";
34
+ tags: string[];
35
+ screenshotPath?: string;
36
+ annotatedScreenshotPath?: string;
37
+ annotations?: AnnotationShape[];
38
+ status?: string;
39
+ createdAt: string;
40
+ }
41
+ interface OverlayPosition {
42
+ x: number;
43
+ y: number;
44
+ width: number;
45
+ height: number;
46
+ }
47
+
48
+ interface AnnotationState {
49
+ shapes: AnnotationShape[];
50
+ redoStack: AnnotationShape[];
51
+ }
52
+ declare function createInitialState(existingAnnotations?: AnnotationShape[]): AnnotationState;
53
+ declare function addShape(state: AnnotationState, shape: AnnotationShape): AnnotationState;
54
+ declare function undo(state: AnnotationState): AnnotationState;
55
+ declare function redo(state: AnnotationState): AnnotationState;
56
+ declare function replaceShape(state: AnnotationState, index: number, shape: AnnotationShape): AnnotationState;
57
+ declare function clearAll(_state: AnnotationState): AnnotationState;
58
+
59
+ interface SyncState {
60
+ companyId: string | null;
61
+ isSyncing: boolean;
62
+ pendingCount: number;
63
+ lastSyncedAt: string | null;
64
+ error: string | null;
65
+ setCompanyId: (id: string | null) => void;
66
+ setIsSyncing: (val: boolean) => void;
67
+ incrementPending: () => void;
68
+ decrementPending: () => void;
69
+ setError: (err: string | null) => void;
70
+ setLastSyncedAt: (ts: string | null) => void;
71
+ }
72
+ declare const useSyncStore: zustand.UseBoundStore<zustand.StoreApi<SyncState>>;
73
+
74
+ interface AuthState {
75
+ session: Session | null;
76
+ user: User | null;
77
+ loading: boolean;
78
+ _supabase: SupabaseClient | null;
79
+ initialize: (supabase: SupabaseClient | null) => Promise<() => void>;
80
+ signInWithEmail: (email: string, password: string) => Promise<{
81
+ error: string | null;
82
+ }>;
83
+ signUpWithEmail: (email: string, password: string) => Promise<{
84
+ error: string | null;
85
+ }>;
86
+ signInWithGitHub: (redirectUrl?: string) => Promise<{
87
+ error: string | null;
88
+ }>;
89
+ signOut: () => Promise<void>;
90
+ }
91
+ declare const useAuthStore: zustand.UseBoundStore<zustand.StoreApi<AuthState>>;
92
+
93
+ type Theme = "dark" | "light";
94
+ interface AppStore {
95
+ theme: Theme;
96
+ isFirstLaunch: boolean;
97
+ isInitialized: boolean;
98
+ initialize: (settings: {
99
+ theme: Theme;
100
+ isFirstLaunch: boolean;
101
+ }) => void;
102
+ setTheme: (theme: Theme) => void;
103
+ setFirstLaunch: (isFirst: boolean) => void;
104
+ }
105
+ declare const useAppStore: zustand.UseBoundStore<zustand.StoreApi<AppStore>>;
106
+
107
+ interface QueueItem {
108
+ feedbackItem: FeedbackPoint;
109
+ projectId: string;
110
+ companyId: string;
111
+ }
112
+ interface IQueueStorage {
113
+ getQueue(): Promise<QueueItem[]>;
114
+ setQueue(items: QueueItem[]): Promise<void>;
115
+ }
116
+
117
+ declare function createOfflineQueue(storage: IQueueStorage): {
118
+ enqueue: (item: QueueItem) => Promise<void>;
119
+ drain: (syncFn: (item: QueueItem) => Promise<void>) => Promise<void>;
120
+ };
121
+
122
+ declare class LocalStorageQueueStorage implements IQueueStorage {
123
+ private readonly key;
124
+ getQueue(): Promise<QueueItem[]>;
125
+ setQueue(items: QueueItem[]): Promise<void>;
126
+ }
127
+
128
+ /**
129
+ * Uploads screenshot bytes to Supabase Storage.
130
+ * Accepts supabase client as first parameter — no global import.
131
+ *
132
+ * Storage path format: {companyId}/{projectId}/{feedbackId}/{filename}
133
+ */
134
+ declare function uploadScreenshotBytes(supabase: SupabaseClient, bytes: Uint8Array, companyId: string, projectId: string, feedbackId: string, filename?: string): Promise<void>;
135
+
136
+ declare function ensureCompany(supabase: SupabaseClient): Promise<string>;
137
+ declare function ensureProject(supabase: SupabaseClient, localProject: Project, companyId: string, userId?: string): Promise<string>;
138
+ declare function syncFeedbackItem(supabase: SupabaseClient, feedbackItem: FeedbackPoint, projectId: string, companyId: string, screenshots?: {
139
+ screenshotBytes?: Uint8Array;
140
+ annotatedBytes?: Uint8Array;
141
+ }): Promise<void>;
142
+ declare function deleteFeedbackItem(supabase: SupabaseClient, feedbackId: string, projectId: string): Promise<void>;
143
+ declare function syncProject(supabase: SupabaseClient, project: Project): Promise<void>;
144
+
145
+ export { type AnnotationShape, type AnnotationState, type FeedbackPoint, type IQueueStorage, LocalStorageQueueStorage, type OverlayPosition, type Project, type ProjectType, type QueueItem, type WindowInfo, addShape, clearAll, createInitialState, createOfflineQueue, deleteFeedbackItem, ensureCompany, ensureProject, redo, replaceShape, syncFeedbackItem, syncProject, undo, uploadScreenshotBytes, useAppStore, useAuthStore, useSyncStore };
@@ -0,0 +1,145 @@
1
+ import * as zustand from 'zustand';
2
+ import { Session, User, SupabaseClient } from '@supabase/supabase-js';
3
+
4
+ interface WindowInfo {
5
+ id: string;
6
+ title: string;
7
+ appName: string;
8
+ }
9
+ type ProjectType = "video" | "design" | "website" | "general";
10
+ interface Project {
11
+ id: string;
12
+ name: string;
13
+ title: string;
14
+ projectType?: ProjectType;
15
+ createdAt: string;
16
+ updatedAt: string;
17
+ feedbackPoints: FeedbackPoint[];
18
+ overlayPosition?: OverlayPosition;
19
+ }
20
+ interface AnnotationShape {
21
+ type: "rect" | "arrow" | "freehand" | "text" | "blur" | "circle" | "line";
22
+ points: number[][];
23
+ color: string;
24
+ strokeWidth: number;
25
+ pressure?: number[];
26
+ text?: string;
27
+ fontSize?: number;
28
+ }
29
+ interface FeedbackPoint {
30
+ id: string;
31
+ comment: string;
32
+ timestamp?: string;
33
+ severity?: "critical" | "major" | "minor" | "suggestion";
34
+ tags: string[];
35
+ screenshotPath?: string;
36
+ annotatedScreenshotPath?: string;
37
+ annotations?: AnnotationShape[];
38
+ status?: string;
39
+ createdAt: string;
40
+ }
41
+ interface OverlayPosition {
42
+ x: number;
43
+ y: number;
44
+ width: number;
45
+ height: number;
46
+ }
47
+
48
+ interface AnnotationState {
49
+ shapes: AnnotationShape[];
50
+ redoStack: AnnotationShape[];
51
+ }
52
+ declare function createInitialState(existingAnnotations?: AnnotationShape[]): AnnotationState;
53
+ declare function addShape(state: AnnotationState, shape: AnnotationShape): AnnotationState;
54
+ declare function undo(state: AnnotationState): AnnotationState;
55
+ declare function redo(state: AnnotationState): AnnotationState;
56
+ declare function replaceShape(state: AnnotationState, index: number, shape: AnnotationShape): AnnotationState;
57
+ declare function clearAll(_state: AnnotationState): AnnotationState;
58
+
59
+ interface SyncState {
60
+ companyId: string | null;
61
+ isSyncing: boolean;
62
+ pendingCount: number;
63
+ lastSyncedAt: string | null;
64
+ error: string | null;
65
+ setCompanyId: (id: string | null) => void;
66
+ setIsSyncing: (val: boolean) => void;
67
+ incrementPending: () => void;
68
+ decrementPending: () => void;
69
+ setError: (err: string | null) => void;
70
+ setLastSyncedAt: (ts: string | null) => void;
71
+ }
72
+ declare const useSyncStore: zustand.UseBoundStore<zustand.StoreApi<SyncState>>;
73
+
74
+ interface AuthState {
75
+ session: Session | null;
76
+ user: User | null;
77
+ loading: boolean;
78
+ _supabase: SupabaseClient | null;
79
+ initialize: (supabase: SupabaseClient | null) => Promise<() => void>;
80
+ signInWithEmail: (email: string, password: string) => Promise<{
81
+ error: string | null;
82
+ }>;
83
+ signUpWithEmail: (email: string, password: string) => Promise<{
84
+ error: string | null;
85
+ }>;
86
+ signInWithGitHub: (redirectUrl?: string) => Promise<{
87
+ error: string | null;
88
+ }>;
89
+ signOut: () => Promise<void>;
90
+ }
91
+ declare const useAuthStore: zustand.UseBoundStore<zustand.StoreApi<AuthState>>;
92
+
93
+ type Theme = "dark" | "light";
94
+ interface AppStore {
95
+ theme: Theme;
96
+ isFirstLaunch: boolean;
97
+ isInitialized: boolean;
98
+ initialize: (settings: {
99
+ theme: Theme;
100
+ isFirstLaunch: boolean;
101
+ }) => void;
102
+ setTheme: (theme: Theme) => void;
103
+ setFirstLaunch: (isFirst: boolean) => void;
104
+ }
105
+ declare const useAppStore: zustand.UseBoundStore<zustand.StoreApi<AppStore>>;
106
+
107
+ interface QueueItem {
108
+ feedbackItem: FeedbackPoint;
109
+ projectId: string;
110
+ companyId: string;
111
+ }
112
+ interface IQueueStorage {
113
+ getQueue(): Promise<QueueItem[]>;
114
+ setQueue(items: QueueItem[]): Promise<void>;
115
+ }
116
+
117
+ declare function createOfflineQueue(storage: IQueueStorage): {
118
+ enqueue: (item: QueueItem) => Promise<void>;
119
+ drain: (syncFn: (item: QueueItem) => Promise<void>) => Promise<void>;
120
+ };
121
+
122
+ declare class LocalStorageQueueStorage implements IQueueStorage {
123
+ private readonly key;
124
+ getQueue(): Promise<QueueItem[]>;
125
+ setQueue(items: QueueItem[]): Promise<void>;
126
+ }
127
+
128
+ /**
129
+ * Uploads screenshot bytes to Supabase Storage.
130
+ * Accepts supabase client as first parameter — no global import.
131
+ *
132
+ * Storage path format: {companyId}/{projectId}/{feedbackId}/{filename}
133
+ */
134
+ declare function uploadScreenshotBytes(supabase: SupabaseClient, bytes: Uint8Array, companyId: string, projectId: string, feedbackId: string, filename?: string): Promise<void>;
135
+
136
+ declare function ensureCompany(supabase: SupabaseClient): Promise<string>;
137
+ declare function ensureProject(supabase: SupabaseClient, localProject: Project, companyId: string, userId?: string): Promise<string>;
138
+ declare function syncFeedbackItem(supabase: SupabaseClient, feedbackItem: FeedbackPoint, projectId: string, companyId: string, screenshots?: {
139
+ screenshotBytes?: Uint8Array;
140
+ annotatedBytes?: Uint8Array;
141
+ }): Promise<void>;
142
+ declare function deleteFeedbackItem(supabase: SupabaseClient, feedbackId: string, projectId: string): Promise<void>;
143
+ declare function syncProject(supabase: SupabaseClient, project: Project): Promise<void>;
144
+
145
+ export { type AnnotationShape, type AnnotationState, type FeedbackPoint, type IQueueStorage, LocalStorageQueueStorage, type OverlayPosition, type Project, type ProjectType, type QueueItem, type WindowInfo, addShape, clearAll, createInitialState, createOfflineQueue, deleteFeedbackItem, ensureCompany, ensureProject, redo, replaceShape, syncFeedbackItem, syncProject, undo, uploadScreenshotBytes, useAppStore, useAuthStore, useSyncStore };
package/dist/index.js ADDED
@@ -0,0 +1,313 @@
1
+ // src/annotation/annotationState.ts
2
+ function createInitialState(existingAnnotations) {
3
+ return {
4
+ shapes: existingAnnotations ? [...existingAnnotations] : [],
5
+ redoStack: []
6
+ };
7
+ }
8
+ function addShape(state, shape) {
9
+ return {
10
+ shapes: [...state.shapes, shape],
11
+ redoStack: []
12
+ };
13
+ }
14
+ function undo(state) {
15
+ if (state.shapes.length === 0) return state;
16
+ const shapes = state.shapes.slice(0, -1);
17
+ const popped = state.shapes[state.shapes.length - 1];
18
+ return {
19
+ shapes,
20
+ redoStack: [...state.redoStack, popped]
21
+ };
22
+ }
23
+ function redo(state) {
24
+ if (state.redoStack.length === 0) return state;
25
+ const redoStack = state.redoStack.slice(0, -1);
26
+ const popped = state.redoStack[state.redoStack.length - 1];
27
+ return {
28
+ shapes: [...state.shapes, popped],
29
+ redoStack
30
+ };
31
+ }
32
+ function replaceShape(state, index, shape) {
33
+ const shapes = [...state.shapes];
34
+ shapes[index] = shape;
35
+ return {
36
+ shapes,
37
+ redoStack: []
38
+ };
39
+ }
40
+ function clearAll(_state) {
41
+ return {
42
+ shapes: [],
43
+ redoStack: []
44
+ };
45
+ }
46
+
47
+ // src/stores/syncStore.ts
48
+ import { create } from "zustand";
49
+ var useSyncStore = create((set) => ({
50
+ companyId: null,
51
+ isSyncing: false,
52
+ pendingCount: 0,
53
+ lastSyncedAt: null,
54
+ error: null,
55
+ setCompanyId: (id) => set({ companyId: id }),
56
+ setIsSyncing: (val) => set({ isSyncing: val }),
57
+ incrementPending: () => set((state) => ({ pendingCount: state.pendingCount + 1 })),
58
+ decrementPending: () => set((state) => ({ pendingCount: Math.max(0, state.pendingCount - 1) })),
59
+ setError: (err) => set({ error: err }),
60
+ setLastSyncedAt: (ts) => set({ lastSyncedAt: ts })
61
+ }));
62
+
63
+ // src/stores/authStore.ts
64
+ import { create as create2 } from "zustand";
65
+ var useAuthStore = create2((set, get) => ({
66
+ session: null,
67
+ user: null,
68
+ loading: true,
69
+ _supabase: null,
70
+ initialize: async (supabase) => {
71
+ if (!supabase) {
72
+ set({ loading: false });
73
+ return () => {
74
+ };
75
+ }
76
+ set({ _supabase: supabase });
77
+ const { data } = await supabase.auth.getSession();
78
+ set({ session: data.session, user: data.session?.user ?? null, loading: false });
79
+ const { data: listener } = supabase.auth.onAuthStateChange((_event, session) => {
80
+ set({ session, user: session?.user ?? null });
81
+ });
82
+ return () => listener.subscription.unsubscribe();
83
+ },
84
+ signInWithEmail: async (email, password) => {
85
+ const supabase = get()._supabase;
86
+ if (!supabase) return { error: "Supabase not configured" };
87
+ const { error } = await supabase.auth.signInWithPassword({ email, password });
88
+ return { error: error?.message ?? null };
89
+ },
90
+ signUpWithEmail: async (email, password) => {
91
+ const supabase = get()._supabase;
92
+ if (!supabase) return { error: "Supabase not configured" };
93
+ const { error } = await supabase.auth.signUp({ email, password });
94
+ return { error: error?.message ?? null };
95
+ },
96
+ signInWithGitHub: async (redirectUrl) => {
97
+ const supabase = get()._supabase;
98
+ if (!supabase) return { error: "Supabase not configured" };
99
+ const { error } = await supabase.auth.signInWithOAuth({
100
+ provider: "github",
101
+ options: { redirectTo: redirectUrl }
102
+ });
103
+ return { error: error?.message ?? null };
104
+ },
105
+ signOut: async () => {
106
+ const supabase = get()._supabase;
107
+ if (!supabase) return;
108
+ await supabase.auth.signOut();
109
+ set({ session: null, user: null });
110
+ }
111
+ }));
112
+
113
+ // src/stores/appStore.ts
114
+ import { create as create3 } from "zustand";
115
+ var useAppStore = create3((set) => ({
116
+ theme: "dark",
117
+ isFirstLaunch: true,
118
+ isInitialized: false,
119
+ initialize: (settings) => set({ theme: settings.theme, isFirstLaunch: settings.isFirstLaunch, isInitialized: true }),
120
+ setTheme: (theme) => set({ theme }),
121
+ setFirstLaunch: (isFirst) => set({ isFirstLaunch: isFirst })
122
+ }));
123
+
124
+ // src/queue/offlineQueue.ts
125
+ var MAX_QUEUE_SIZE = 50;
126
+ function createOfflineQueue(storage) {
127
+ async function enqueue(item) {
128
+ const queue = await storage.getQueue();
129
+ queue.push(item);
130
+ if (queue.length > MAX_QUEUE_SIZE) {
131
+ queue.shift();
132
+ }
133
+ await storage.setQueue(queue);
134
+ }
135
+ async function drain(syncFn) {
136
+ const queue = await storage.getQueue();
137
+ if (queue.length === 0) return;
138
+ const remaining = [];
139
+ for (const item of queue) {
140
+ if (typeof navigator !== "undefined" && !navigator.onLine) {
141
+ remaining.push(item);
142
+ continue;
143
+ }
144
+ try {
145
+ await syncFn(item);
146
+ } catch {
147
+ remaining.push(item);
148
+ }
149
+ }
150
+ await storage.setQueue(remaining);
151
+ if (remaining.length > 0) {
152
+ setTimeout(() => drain(syncFn).catch(console.error), 15e3);
153
+ }
154
+ }
155
+ return { enqueue, drain };
156
+ }
157
+
158
+ // src/queue/localStorage.ts
159
+ var LocalStorageQueueStorage = class {
160
+ constructor() {
161
+ this.key = "loupe_offline_queue";
162
+ }
163
+ async getQueue() {
164
+ try {
165
+ return JSON.parse(localStorage.getItem(this.key) ?? "[]");
166
+ } catch {
167
+ return [];
168
+ }
169
+ }
170
+ async setQueue(items) {
171
+ localStorage.setItem(this.key, JSON.stringify(items));
172
+ }
173
+ };
174
+
175
+ // src/storage/storageUpload.ts
176
+ async function uploadScreenshotBytes(supabase, bytes, companyId, projectId, feedbackId, filename = "screenshot.png") {
177
+ const storagePath = `${companyId}/${projectId}/${feedbackId}/${filename}`;
178
+ const { error } = await supabase.storage.from("screenshots").upload(storagePath, bytes, { contentType: "image/png", upsert: true });
179
+ if (error) {
180
+ throw new Error(`Storage upload failed: ${error.message}`);
181
+ }
182
+ }
183
+
184
+ // src/sync/syncService.ts
185
+ async function ensureCompany(supabase) {
186
+ const cached = useSyncStore.getState().companyId;
187
+ if (cached) return cached;
188
+ const { data: { user } } = await supabase.auth.getUser();
189
+ if (!user) throw new Error("Not authenticated");
190
+ const { data: profile, error: profileError } = await supabase.from("profiles").select("id, company_id").eq("id", user.id).single();
191
+ if (profileError) throw new Error(`Profile fetch failed: ${profileError.message}`);
192
+ if (profile?.company_id) {
193
+ useSyncStore.getState().setCompanyId(profile.company_id);
194
+ return profile.company_id;
195
+ }
196
+ const { data: companyId, error: rpcError } = await supabase.rpc("ensure_company_for_user");
197
+ if (rpcError || !companyId) {
198
+ throw new Error(`Company creation failed: ${rpcError?.message ?? "unknown error"}`);
199
+ }
200
+ useSyncStore.getState().setCompanyId(companyId);
201
+ return companyId;
202
+ }
203
+ async function ensureProject(supabase, localProject, companyId, userId) {
204
+ const { data: { user: currentUser } } = await supabase.auth.getUser();
205
+ const createdBy = userId ?? currentUser?.id ?? "";
206
+ const { error } = await supabase.from("projects").upsert(
207
+ {
208
+ id: localProject.id,
209
+ company_id: companyId,
210
+ created_by: createdBy,
211
+ name: localProject.name,
212
+ title: localProject.title,
213
+ project_type: localProject.projectType ?? "general",
214
+ source: "desktop"
215
+ },
216
+ { onConflict: "id" }
217
+ ).select("id").single();
218
+ if (error) throw new Error(`Project sync failed: ${error.message}`);
219
+ return localProject.id;
220
+ }
221
+ async function syncFeedbackItem(supabase, feedbackItem, projectId, companyId, screenshots) {
222
+ const { data: { user } } = await supabase.auth.getUser();
223
+ if (!user) return;
224
+ if (typeof navigator !== "undefined" && !navigator.onLine) {
225
+ throw new Error("Offline \u2014 caller should enqueue");
226
+ }
227
+ const resolvedCompanyId = companyId || await ensureCompany(supabase);
228
+ let uploadedScreenshotPath;
229
+ let uploadedAnnotatedPath;
230
+ if (feedbackItem.screenshotPath && screenshots?.screenshotBytes) {
231
+ try {
232
+ await uploadScreenshotBytes(supabase, screenshots.screenshotBytes, resolvedCompanyId, projectId, feedbackItem.id, "screenshot.png");
233
+ uploadedScreenshotPath = `${resolvedCompanyId}/${projectId}/${feedbackItem.id}/screenshot.png`;
234
+ } catch (uploadErr) {
235
+ console.warn("[syncFeedbackItem] screenshot upload failed:", uploadErr);
236
+ }
237
+ }
238
+ if (feedbackItem.annotatedScreenshotPath && screenshots?.annotatedBytes) {
239
+ try {
240
+ await uploadScreenshotBytes(supabase, screenshots.annotatedBytes, resolvedCompanyId, projectId, feedbackItem.id, "annotated.png");
241
+ uploadedAnnotatedPath = `${resolvedCompanyId}/${projectId}/${feedbackItem.id}/annotated.png`;
242
+ } catch (uploadErr) {
243
+ console.warn("[syncFeedbackItem] annotated screenshot upload failed:", uploadErr);
244
+ }
245
+ }
246
+ const { error } = await supabase.from("feedback_items").upsert(
247
+ {
248
+ id: feedbackItem.id,
249
+ project_id: projectId,
250
+ company_id: resolvedCompanyId,
251
+ created_by: user.id,
252
+ comment: feedbackItem.comment,
253
+ media_timestamp: feedbackItem.timestamp ?? null,
254
+ severity: feedbackItem.severity ?? null,
255
+ tags: feedbackItem.tags,
256
+ ...uploadedScreenshotPath !== void 0 ? { screenshot_path: uploadedScreenshotPath } : {},
257
+ ...uploadedAnnotatedPath !== void 0 ? { annotated_screenshot_path: uploadedAnnotatedPath } : {}
258
+ },
259
+ { onConflict: "id" }
260
+ ).select("id").single();
261
+ if (error) throw new Error(error.message);
262
+ const now = (/* @__PURE__ */ new Date()).toISOString();
263
+ console.log(`[sync] feedback ${feedbackItem.id} synced at ${now}`);
264
+ useSyncStore.getState().setLastSyncedAt(now);
265
+ }
266
+ async function deleteFeedbackItem(supabase, feedbackId, projectId) {
267
+ const { data: { user } } = await supabase.auth.getUser();
268
+ if (!user) return;
269
+ try {
270
+ const companyId = useSyncStore.getState().companyId || await ensureCompany(supabase);
271
+ const storagePaths = [
272
+ `${companyId}/${projectId}/${feedbackId}/screenshot.png`,
273
+ `${companyId}/${projectId}/${feedbackId}/annotated.png`
274
+ ];
275
+ await supabase.storage.from("screenshots").remove(storagePaths);
276
+ const { error } = await supabase.from("feedback_items").delete().eq("id", feedbackId);
277
+ if (error) console.error("[deleteFeedbackItem] DB delete failed:", error.message);
278
+ } catch (err) {
279
+ console.error("[deleteFeedbackItem] failed:", err);
280
+ }
281
+ }
282
+ async function syncProject(supabase, project) {
283
+ const { data: { user } } = await supabase.auth.getUser();
284
+ if (!user) return;
285
+ if (typeof navigator !== "undefined" && !navigator.onLine) return;
286
+ try {
287
+ const companyId = await ensureCompany(supabase);
288
+ await ensureProject(supabase, project, companyId, user.id);
289
+ useSyncStore.getState().setLastSyncedAt((/* @__PURE__ */ new Date()).toISOString());
290
+ } catch (err) {
291
+ console.error("[syncProject] failed:", err);
292
+ }
293
+ }
294
+ export {
295
+ LocalStorageQueueStorage,
296
+ addShape,
297
+ clearAll,
298
+ createInitialState,
299
+ createOfflineQueue,
300
+ deleteFeedbackItem,
301
+ ensureCompany,
302
+ ensureProject,
303
+ redo,
304
+ replaceShape,
305
+ syncFeedbackItem,
306
+ syncProject,
307
+ undo,
308
+ uploadScreenshotBytes,
309
+ useAppStore,
310
+ useAuthStore,
311
+ useSyncStore
312
+ };
313
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/annotation/annotationState.ts","../src/stores/syncStore.ts","../src/stores/authStore.ts","../src/stores/appStore.ts","../src/queue/offlineQueue.ts","../src/queue/localStorage.ts","../src/storage/storageUpload.ts","../src/sync/syncService.ts"],"sourcesContent":["import type { AnnotationShape } from \"../types/project\";\n\nexport interface AnnotationState {\n shapes: AnnotationShape[];\n redoStack: AnnotationShape[];\n}\n\nexport function createInitialState(\n existingAnnotations?: AnnotationShape[],\n): AnnotationState {\n return {\n shapes: existingAnnotations ? [...existingAnnotations] : [],\n redoStack: [],\n };\n}\n\nexport function addShape(\n state: AnnotationState,\n shape: AnnotationShape,\n): AnnotationState {\n return {\n shapes: [...state.shapes, shape],\n redoStack: [],\n };\n}\n\nexport function undo(state: AnnotationState): AnnotationState {\n if (state.shapes.length === 0) return state;\n const shapes = state.shapes.slice(0, -1);\n const popped = state.shapes[state.shapes.length - 1];\n return {\n shapes,\n redoStack: [...state.redoStack, popped],\n };\n}\n\nexport function redo(state: AnnotationState): AnnotationState {\n if (state.redoStack.length === 0) return state;\n const redoStack = state.redoStack.slice(0, -1);\n const popped = state.redoStack[state.redoStack.length - 1];\n return {\n shapes: [...state.shapes, popped],\n redoStack,\n };\n}\n\nexport function replaceShape(\n state: AnnotationState,\n index: number,\n shape: AnnotationShape,\n): AnnotationState {\n const shapes = [...state.shapes];\n shapes[index] = shape;\n return {\n shapes,\n redoStack: [],\n };\n}\n\nexport function clearAll(_state: AnnotationState): AnnotationState {\n return {\n shapes: [],\n redoStack: [],\n };\n}\n","import { create } from \"zustand\";\n\ninterface SyncState {\n companyId: string | null;\n isSyncing: boolean;\n pendingCount: number;\n lastSyncedAt: string | null;\n error: string | null;\n // Actions\n setCompanyId: (id: string | null) => void;\n setIsSyncing: (val: boolean) => void;\n incrementPending: () => void;\n decrementPending: () => void;\n setError: (err: string | null) => void;\n setLastSyncedAt: (ts: string | null) => void;\n}\n\nexport const useSyncStore = create<SyncState>((set) => ({\n companyId: null,\n isSyncing: false,\n pendingCount: 0,\n lastSyncedAt: null,\n error: null,\n\n setCompanyId: (id) => set({ companyId: id }),\n setIsSyncing: (val) => set({ isSyncing: val }),\n incrementPending: () => set((state) => ({ pendingCount: state.pendingCount + 1 })),\n decrementPending: () =>\n set((state) => ({ pendingCount: Math.max(0, state.pendingCount - 1) })),\n setError: (err) => set({ error: err }),\n setLastSyncedAt: (ts) => set({ lastSyncedAt: ts }),\n}));\n","import type { Session, SupabaseClient, User } from \"@supabase/supabase-js\";\nimport { create } from \"zustand\";\n\ninterface AuthState {\n session: Session | null;\n user: User | null;\n loading: boolean;\n _supabase: SupabaseClient | null;\n initialize: (supabase: SupabaseClient | null) => Promise<() => void>;\n signInWithEmail: (email: string, password: string) => Promise<{ error: string | null }>;\n signUpWithEmail: (email: string, password: string) => Promise<{ error: string | null }>;\n signInWithGitHub: (redirectUrl?: string) => Promise<{ error: string | null }>;\n signOut: () => Promise<void>;\n}\n\nexport const useAuthStore = create<AuthState>((set, get) => ({\n session: null,\n user: null,\n loading: true,\n _supabase: null,\n\n initialize: async (supabase) => {\n if (!supabase) {\n set({ loading: false });\n return () => {};\n }\n set({ _supabase: supabase });\n const { data } = await supabase.auth.getSession();\n set({ session: data.session, user: data.session?.user ?? null, loading: false });\n const { data: listener } = supabase.auth.onAuthStateChange((_event, session) => {\n set({ session, user: session?.user ?? null });\n });\n return () => listener.subscription.unsubscribe();\n },\n\n signInWithEmail: async (email, password) => {\n const supabase = get()._supabase;\n if (!supabase) return { error: \"Supabase not configured\" };\n const { error } = await supabase.auth.signInWithPassword({ email, password });\n return { error: error?.message ?? null };\n },\n\n signUpWithEmail: async (email, password) => {\n const supabase = get()._supabase;\n if (!supabase) return { error: \"Supabase not configured\" };\n const { error } = await supabase.auth.signUp({ email, password });\n return { error: error?.message ?? null };\n },\n\n signInWithGitHub: async (redirectUrl) => {\n const supabase = get()._supabase;\n if (!supabase) return { error: \"Supabase not configured\" };\n const { error } = await supabase.auth.signInWithOAuth({\n provider: \"github\",\n options: { redirectTo: redirectUrl },\n });\n return { error: error?.message ?? null };\n },\n\n signOut: async () => {\n const supabase = get()._supabase;\n if (!supabase) return;\n await supabase.auth.signOut();\n set({ session: null, user: null });\n },\n}));\n","import { create } from \"zustand\";\n\ntype Theme = \"dark\" | \"light\";\n\ninterface AppStore {\n theme: Theme;\n isFirstLaunch: boolean;\n isInitialized: boolean;\n initialize: (settings: { theme: Theme; isFirstLaunch: boolean }) => void;\n setTheme: (theme: Theme) => void;\n setFirstLaunch: (isFirst: boolean) => void;\n}\n\nexport const useAppStore = create<AppStore>((set) => ({\n theme: \"dark\",\n isFirstLaunch: true,\n isInitialized: false,\n initialize: (settings) => set({ theme: settings.theme, isFirstLaunch: settings.isFirstLaunch, isInitialized: true }),\n setTheme: (theme) => set({ theme }),\n setFirstLaunch: (isFirst) => set({ isFirstLaunch: isFirst }),\n}));\n","import type { IQueueStorage, QueueItem } from \"./types\";\n\nconst MAX_QUEUE_SIZE = 50;\n\nexport function createOfflineQueue(storage: IQueueStorage) {\n async function enqueue(item: QueueItem): Promise<void> {\n const queue = await storage.getQueue();\n queue.push(item);\n if (queue.length > MAX_QUEUE_SIZE) {\n queue.shift();\n }\n await storage.setQueue(queue);\n }\n\n async function drain(syncFn: (item: QueueItem) => Promise<void>): Promise<void> {\n const queue = await storage.getQueue();\n if (queue.length === 0) return;\n\n const remaining: QueueItem[] = [];\n\n for (const item of queue) {\n if (typeof navigator !== \"undefined\" && !navigator.onLine) {\n remaining.push(item);\n continue;\n }\n try {\n await syncFn(item);\n } catch {\n remaining.push(item);\n }\n }\n\n await storage.setQueue(remaining);\n\n if (remaining.length > 0) {\n setTimeout(() => drain(syncFn).catch(console.error), 15_000);\n }\n }\n\n return { enqueue, drain };\n}\n","import type { IQueueStorage, QueueItem } from \"./types\";\n\nexport class LocalStorageQueueStorage implements IQueueStorage {\n private readonly key = \"loupe_offline_queue\";\n\n async getQueue(): Promise<QueueItem[]> {\n try {\n return JSON.parse(localStorage.getItem(this.key) ?? \"[]\") as QueueItem[];\n } catch {\n return [];\n }\n }\n\n async setQueue(items: QueueItem[]): Promise<void> {\n localStorage.setItem(this.key, JSON.stringify(items));\n }\n}\n","import type { SupabaseClient } from \"@supabase/supabase-js\";\n\n/**\n * Uploads screenshot bytes to Supabase Storage.\n * Accepts supabase client as first parameter — no global import.\n *\n * Storage path format: {companyId}/{projectId}/{feedbackId}/{filename}\n */\nexport async function uploadScreenshotBytes(\n supabase: SupabaseClient,\n bytes: Uint8Array,\n companyId: string,\n projectId: string,\n feedbackId: string,\n filename: string = \"screenshot.png\",\n): Promise<void> {\n const storagePath = `${companyId}/${projectId}/${feedbackId}/${filename}`;\n\n const { error } = await supabase.storage\n .from(\"screenshots\")\n .upload(storagePath, bytes, { contentType: \"image/png\", upsert: true });\n\n if (error) {\n throw new Error(`Storage upload failed: ${error.message}`);\n }\n}\n","import type { SupabaseClient } from \"@supabase/supabase-js\";\nimport { useSyncStore } from \"../stores/syncStore\";\nimport { uploadScreenshotBytes } from \"../storage/storageUpload\";\nimport type { FeedbackPoint, Project } from \"../types/project\";\n\n// ─── ensureCompany ────────────────────────────────────────────────────────────\n\nexport async function ensureCompany(supabase: SupabaseClient): Promise<string> {\n const cached = useSyncStore.getState().companyId;\n if (cached) return cached;\n\n const { data: { user } } = await supabase.auth.getUser();\n if (!user) throw new Error(\"Not authenticated\");\n\n const { data: profile, error: profileError } = await supabase\n .from(\"profiles\")\n .select(\"id, company_id\")\n .eq(\"id\", user.id)\n .single();\n\n if (profileError) throw new Error(`Profile fetch failed: ${profileError.message}`);\n\n if (profile?.company_id) {\n useSyncStore.getState().setCompanyId(profile.company_id as string);\n return profile.company_id as string;\n }\n\n const { data: companyId, error: rpcError } = await supabase.rpc(\"ensure_company_for_user\");\n if (rpcError || !companyId) {\n throw new Error(`Company creation failed: ${rpcError?.message ?? \"unknown error\"}`);\n }\n\n useSyncStore.getState().setCompanyId(companyId);\n return companyId;\n}\n\n// ─── ensureProject ────────────────────────────────────────────────────────────\n\nexport async function ensureProject(\n supabase: SupabaseClient,\n localProject: Project,\n companyId: string,\n userId?: string,\n): Promise<string> {\n const { data: { user: currentUser } } = await supabase.auth.getUser();\n const createdBy = userId ?? currentUser?.id ?? \"\";\n\n const { error } = await supabase\n .from(\"projects\")\n .upsert(\n {\n id: localProject.id,\n company_id: companyId,\n created_by: createdBy,\n name: localProject.name,\n title: localProject.title,\n project_type: localProject.projectType ?? \"general\",\n source: \"desktop\",\n },\n { onConflict: \"id\" },\n )\n .select(\"id\")\n .single();\n\n if (error) throw new Error(`Project sync failed: ${error.message}`);\n return localProject.id;\n}\n\n// ─── syncFeedbackItem ─────────────────────────────────────────────────────────\n\nexport async function syncFeedbackItem(\n supabase: SupabaseClient,\n feedbackItem: FeedbackPoint,\n projectId: string,\n companyId: string,\n screenshots?: {\n screenshotBytes?: Uint8Array;\n annotatedBytes?: Uint8Array;\n },\n): Promise<void> {\n const { data: { user } } = await supabase.auth.getUser();\n if (!user) return;\n\n if (typeof navigator !== \"undefined\" && !navigator.onLine) {\n // Caller handles queuing — this function only syncs\n throw new Error(\"Offline — caller should enqueue\");\n }\n\n const resolvedCompanyId = companyId || (await ensureCompany(supabase));\n\n let uploadedScreenshotPath: string | undefined;\n let uploadedAnnotatedPath: string | undefined;\n\n if (feedbackItem.screenshotPath && screenshots?.screenshotBytes) {\n try {\n await uploadScreenshotBytes(supabase, screenshots.screenshotBytes, resolvedCompanyId, projectId, feedbackItem.id, \"screenshot.png\");\n uploadedScreenshotPath = `${resolvedCompanyId}/${projectId}/${feedbackItem.id}/screenshot.png`;\n } catch (uploadErr) {\n console.warn(\"[syncFeedbackItem] screenshot upload failed:\", uploadErr);\n }\n }\n\n if (feedbackItem.annotatedScreenshotPath && screenshots?.annotatedBytes) {\n try {\n await uploadScreenshotBytes(supabase, screenshots.annotatedBytes, resolvedCompanyId, projectId, feedbackItem.id, \"annotated.png\");\n uploadedAnnotatedPath = `${resolvedCompanyId}/${projectId}/${feedbackItem.id}/annotated.png`;\n } catch (uploadErr) {\n console.warn(\"[syncFeedbackItem] annotated screenshot upload failed:\", uploadErr);\n }\n }\n\n const { error } = await supabase\n .from(\"feedback_items\")\n .upsert(\n {\n id: feedbackItem.id,\n project_id: projectId,\n company_id: resolvedCompanyId,\n created_by: user.id,\n comment: feedbackItem.comment,\n media_timestamp: feedbackItem.timestamp ?? null,\n severity: feedbackItem.severity ?? null,\n tags: feedbackItem.tags,\n ...(uploadedScreenshotPath !== undefined ? { screenshot_path: uploadedScreenshotPath } : {}),\n ...(uploadedAnnotatedPath !== undefined ? { annotated_screenshot_path: uploadedAnnotatedPath } : {}),\n },\n { onConflict: \"id\" },\n )\n .select(\"id\")\n .single();\n\n if (error) throw new Error(error.message);\n\n const now = new Date().toISOString();\n console.log(`[sync] feedback ${feedbackItem.id} synced at ${now}`);\n useSyncStore.getState().setLastSyncedAt(now);\n}\n\n// ─── deleteFeedbackItem ───────────────────────────────────────────────────────\n\nexport async function deleteFeedbackItem(\n supabase: SupabaseClient,\n feedbackId: string,\n projectId: string,\n): Promise<void> {\n const { data: { user } } = await supabase.auth.getUser();\n if (!user) return;\n\n try {\n const companyId = useSyncStore.getState().companyId || (await ensureCompany(supabase));\n\n const storagePaths = [\n `${companyId}/${projectId}/${feedbackId}/screenshot.png`,\n `${companyId}/${projectId}/${feedbackId}/annotated.png`,\n ];\n await supabase.storage.from(\"screenshots\").remove(storagePaths);\n\n const { error } = await supabase.from(\"feedback_items\").delete().eq(\"id\", feedbackId);\n if (error) console.error(\"[deleteFeedbackItem] DB delete failed:\", error.message);\n } catch (err) {\n console.error(\"[deleteFeedbackItem] failed:\", err);\n }\n}\n\n// ─── syncProject ──────────────────────────────────────────────────────────────\n\nexport async function syncProject(supabase: SupabaseClient, project: Project): Promise<void> {\n const { data: { user } } = await supabase.auth.getUser();\n if (!user) return;\n\n if (typeof navigator !== \"undefined\" && !navigator.onLine) return;\n\n try {\n const companyId = await ensureCompany(supabase);\n await ensureProject(supabase, project, companyId, user.id);\n useSyncStore.getState().setLastSyncedAt(new Date().toISOString());\n } catch (err) {\n console.error(\"[syncProject] failed:\", err);\n }\n}\n"],"mappings":";AAOO,SAAS,mBACd,qBACiB;AACjB,SAAO;AAAA,IACL,QAAQ,sBAAsB,CAAC,GAAG,mBAAmB,IAAI,CAAC;AAAA,IAC1D,WAAW,CAAC;AAAA,EACd;AACF;AAEO,SAAS,SACd,OACA,OACiB;AACjB,SAAO;AAAA,IACL,QAAQ,CAAC,GAAG,MAAM,QAAQ,KAAK;AAAA,IAC/B,WAAW,CAAC;AAAA,EACd;AACF;AAEO,SAAS,KAAK,OAAyC;AAC5D,MAAI,MAAM,OAAO,WAAW,EAAG,QAAO;AACtC,QAAM,SAA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/core",
3
+ "version": "1.0.0",
4
+ "license": "MIT",
5
+ "private": false,
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": { "types": "./dist/index.d.ts", "default": "./dist/index.js" },
12
+ "require": { "types": "./dist/index.d.ts", "default": "./dist/index.cjs" }
13
+ }
14
+ },
15
+ "publishConfig": { "access": "public" },
16
+ "files": ["dist"],
17
+ "scripts": {
18
+ "build": "tsup",
19
+ "test": "vitest",
20
+ "prepublishOnly": "npm run build"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/loupeink/core"
25
+ },
26
+ "dependencies": {
27
+ "zustand": "^5.0.0",
28
+ "@supabase/supabase-js": "^2.99.2"
29
+ },
30
+ "devDependencies": {
31
+ "jsdom": "^25.0.0",
32
+ "tsup": "^8.0.0",
33
+ "typescript": "~5.7.0",
34
+ "vitest": "^2.0.0",
35
+ "@types/node": "^20.0.0"
36
+ }
37
+ }