@manyrows/appkit-react 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -15,7 +15,47 @@ type ManyRowsAppKitReady = {
15
15
  baseURL: string;
16
16
  version: string;
17
17
  };
18
- type ManyRowsAppKitSnapshot = any;
18
+ type AppKitAccount = {
19
+ email: string;
20
+ name: string;
21
+ };
22
+ type AppKitProjectAccess = {
23
+ name: string;
24
+ roles: string[];
25
+ permissions: string[];
26
+ };
27
+ type AppKitFeatureFlag = {
28
+ key: string;
29
+ enabled: boolean;
30
+ };
31
+ type AppKitConfigValue = {
32
+ key: string;
33
+ type: string;
34
+ value?: any;
35
+ };
36
+ type AppKitAppData = {
37
+ account?: AppKitAccount;
38
+ workspaceSlug: string;
39
+ workspaceName: string;
40
+ projectAccess: boolean;
41
+ project?: AppKitProjectAccess;
42
+ featureFlags?: AppKitFeatureFlag[];
43
+ config?: AppKitConfigValue[];
44
+ };
45
+ type ManyRowsAppKitSnapshot = {
46
+ status: "checking" | "authenticated" | "unauthenticated";
47
+ jwtToken: string | null;
48
+ appData: AppKitAppData | null;
49
+ workspaceBaseURL: string;
50
+ appId: string;
51
+ app: {
52
+ id: string;
53
+ name: string;
54
+ workspaceSlug: string;
55
+ workspaceName: string;
56
+ allowRegistration: boolean;
57
+ } | null;
58
+ };
19
59
  type ManyRowsAppKitHandle = {
20
60
  version: string;
21
61
  info(): ManyRowsAppKitReady | null;
@@ -26,6 +66,101 @@ type ManyRowsAppKitHandle = {
26
66
  setToken(tok: string | null): void;
27
67
  destroy(): void;
28
68
  };
69
+ type ImageVariant = {
70
+ id: string;
71
+ variant: string;
72
+ s3Key: string;
73
+ content_type: string;
74
+ format: string;
75
+ size_bytes: number;
76
+ sha256_hex: string;
77
+ ext: string;
78
+ width: number;
79
+ height: number;
80
+ etag: string;
81
+ versionId: string;
82
+ objectURL: string;
83
+ expiresAt: string;
84
+ };
85
+ type ImageResource = {
86
+ imageId: string;
87
+ title: string;
88
+ description: string;
89
+ originalName: string;
90
+ uploadedAt: string;
91
+ uploadedBy?: string;
92
+ refType?: string;
93
+ refId?: string;
94
+ variants: ImageVariant[];
95
+ };
96
+ type ImageListResponse = {
97
+ images: ImageResource[];
98
+ page: number;
99
+ pageSize: number;
100
+ total: number;
101
+ pageCount: number;
102
+ };
103
+ type ImageUploadOptions = {
104
+ file: File;
105
+ title: string;
106
+ description?: string;
107
+ variants?: string;
108
+ refType?: string;
109
+ refId?: string;
110
+ };
111
+ type ImageUpdateOptions = {
112
+ title: string;
113
+ description?: string;
114
+ refType?: string;
115
+ refId?: string;
116
+ };
117
+ type UploadProgress = {
118
+ status: "idle" | "uploading" | "success" | "conflict" | "error";
119
+ progress: number;
120
+ bytesUploaded: number;
121
+ bytesTotal: number;
122
+ error: string | null;
123
+ /** Set when status is "conflict" — the ID of the existing image with identical content. */
124
+ existingImageId?: string;
125
+ /** Set when status is "conflict" — the ID of the existing file with identical content. */
126
+ existingFileId?: string;
127
+ };
128
+ type FileResource = {
129
+ fileId: string;
130
+ title: string;
131
+ description: string;
132
+ originalName: string;
133
+ contentType: string;
134
+ format: string;
135
+ sizeBytes: number;
136
+ ext: string;
137
+ objectURL: string;
138
+ expiresAt: string;
139
+ uploadedAt: string;
140
+ uploadedBy?: string;
141
+ refType?: string;
142
+ refId?: string;
143
+ };
144
+ type FileListResponse = {
145
+ files: FileResource[];
146
+ page: number;
147
+ pageSize: number;
148
+ total: number;
149
+ pageCount: number;
150
+ };
151
+ type FileUploadOptions = {
152
+ file: File;
153
+ title: string;
154
+ description?: string;
155
+ refType?: string;
156
+ refId?: string;
157
+ };
158
+ type FileUpdateOptions = {
159
+ title: string;
160
+ description?: string;
161
+ refType?: string;
162
+ refId?: string;
163
+ };
29
164
 
30
165
  type AppKitContextValue = {
31
166
  status: "idle" | "loading" | "mounted" | "error";
@@ -59,8 +194,16 @@ type AppKitTheme = {
59
194
  type AppKitProps = {
60
195
  workspace: string;
61
196
  appId: string;
197
+ /**
198
+ * Base URL of the ManyRows service.
199
+ * Defaults to "https://app.manyrows.com".
200
+ */
62
201
  baseURL?: string;
63
202
  theme?: AppKitTheme;
203
+ /**
204
+ * URL of the AppKit runtime script.
205
+ * Defaults to `{baseURL}/appkit/assets/appkit.js`.
206
+ */
64
207
  src?: string;
65
208
  timeoutMs?: number;
66
209
  silent?: boolean;
@@ -96,4 +239,294 @@ interface UserButtonProps {
96
239
  }
97
240
  declare function UserButton({ size }: UserButtonProps): react_jsx_runtime.JSX.Element;
98
241
 
99
- export { AppKit, AppKitAuthed, type AppKitTheme, type ManyRowsAppKitError, type ManyRowsAppKitErrorCode, type ManyRowsAppKitHandle, type ManyRowsAppKitReady, type ManyRowsAppKitSnapshot, UserButton, type UserButtonProps, useAppKit };
242
+ /**
243
+ * Returns the authenticated user's account, or null if not authenticated.
244
+ *
245
+ * ```tsx
246
+ * const user = useUser();
247
+ * if (!user) return <p>Not logged in</p>;
248
+ * return <p>Hello, {user.name || user.email}</p>;
249
+ * ```
250
+ */
251
+ declare function useUser(): AppKitAccount | null;
252
+ /**
253
+ * Returns the current project access info (name, roles, permissions), or null.
254
+ */
255
+ declare function useProject(): AppKitProjectAccess | null;
256
+ /**
257
+ * Returns the user's roles in the current project.
258
+ *
259
+ * ```tsx
260
+ * const roles = useRoles(); // ["admin", "editor"]
261
+ * ```
262
+ */
263
+ declare function useRoles(): string[];
264
+ /**
265
+ * Returns the user's permissions in the current project.
266
+ *
267
+ * ```tsx
268
+ * const permissions = usePermissions(); // ["read", "write", "delete"]
269
+ * ```
270
+ */
271
+ declare function usePermissions(): string[];
272
+ /**
273
+ * Returns true if the user has the given permission.
274
+ *
275
+ * ```tsx
276
+ * const canEdit = usePermission("edit"); // true
277
+ * ```
278
+ */
279
+ declare function usePermission(permission: string): boolean;
280
+ /**
281
+ * Returns true if the user has the given role.
282
+ *
283
+ * ```tsx
284
+ * const isAdmin = useRole("admin"); // true
285
+ * ```
286
+ */
287
+ declare function useRole(role: string): boolean;
288
+ /**
289
+ * Returns all feature flags for the current app/environment.
290
+ *
291
+ * ```tsx
292
+ * const flags = useFeatureFlags(); // [{ key: "dark-mode", enabled: true }]
293
+ * ```
294
+ */
295
+ declare function useFeatureFlags(): AppKitFeatureFlag[];
296
+ /**
297
+ * Returns whether a specific feature flag is enabled.
298
+ *
299
+ * ```tsx
300
+ * const darkMode = useFeatureFlag("dark-mode"); // true
301
+ * ```
302
+ */
303
+ declare function useFeatureFlag(key: string): boolean;
304
+ /**
305
+ * Returns all config values for the current app/environment.
306
+ *
307
+ * ```tsx
308
+ * const config = useConfig(); // [{ key: "api-url", type: "string", value: "https://..." }]
309
+ * ```
310
+ */
311
+ declare function useConfig(): AppKitConfigValue[];
312
+ /**
313
+ * Returns a specific config value by key, or the fallback if not found.
314
+ *
315
+ * ```tsx
316
+ * const apiUrl = useConfigValue("api-url"); // "https://api.example.com"
317
+ * const limit = useConfigValue("max-items", 100); // 100 if not set
318
+ * ```
319
+ */
320
+ declare function useConfigValue<T = any>(key: string, fallback?: T): T | undefined;
321
+ /**
322
+ * Returns the JWT token for making authenticated API calls.
323
+ *
324
+ * ```tsx
325
+ * const token = useToken();
326
+ * fetch("/api/data", { headers: { Authorization: `Bearer ${token}` } });
327
+ * ```
328
+ */
329
+ declare function useToken(): string | null;
330
+
331
+ type UseImagesOptions = {
332
+ page?: number;
333
+ pageSize?: number;
334
+ q?: string;
335
+ refType?: string;
336
+ refId?: string;
337
+ enabled?: boolean;
338
+ };
339
+ type UseImagesReturn = {
340
+ images: ImageResource[];
341
+ page: number;
342
+ pageSize: number;
343
+ total: number;
344
+ pageCount: number;
345
+ loading: boolean;
346
+ error: string | null;
347
+ refetch: () => void;
348
+ setPage: (page: number) => void;
349
+ setQuery: (q: string) => void;
350
+ available: boolean;
351
+ removeImage: (imageId: string) => Promise<void>;
352
+ updateImage: (imageId: string, opts: ImageUpdateOptions) => Promise<void>;
353
+ };
354
+ declare function useImages(opts?: UseImagesOptions): UseImagesReturn;
355
+
356
+ type UseImageUploadReturn = {
357
+ upload: (opts: ImageUploadOptions) => Promise<void>;
358
+ cancel: () => void;
359
+ progress: UploadProgress;
360
+ reset: () => void;
361
+ available: boolean;
362
+ };
363
+ declare function useImageUpload(): UseImageUploadReturn;
364
+
365
+ type UseImageOptions = {
366
+ enabled?: boolean;
367
+ };
368
+ type UseImageReturn = {
369
+ image: ImageResource | null;
370
+ loading: boolean;
371
+ error: string | null;
372
+ refetch: () => void;
373
+ available: boolean;
374
+ };
375
+ declare function useImage(imageId: string | null | undefined, opts?: UseImageOptions): UseImageReturn;
376
+
377
+ interface ImageUploaderProps {
378
+ onUpload?: () => void;
379
+ onError?: (error: string) => void;
380
+ defaultTitle?: string;
381
+ defaultDescription?: string;
382
+ variants?: string;
383
+ showFields?: boolean;
384
+ showVariantPicker?: boolean;
385
+ accept?: string;
386
+ maxSize?: number;
387
+ refType?: string;
388
+ refId?: string;
389
+ className?: string;
390
+ style?: React.CSSProperties;
391
+ label?: string;
392
+ disabled?: boolean;
393
+ }
394
+ declare function ImageUploader({ onUpload, onError, defaultTitle, defaultDescription, variants: variantsProp, showFields, showVariantPicker, accept, maxSize, refType, refId, className, style, label, disabled, }: ImageUploaderProps): react_jsx_runtime.JSX.Element | null;
395
+
396
+ interface ImagePickerProps {
397
+ onSelect?: (image: ImageResource) => void;
398
+ onClose?: () => void;
399
+ mode?: "modal" | "inline";
400
+ pageSize?: number;
401
+ showSearch?: boolean;
402
+ searchPlaceholder?: string;
403
+ selectedImageId?: string;
404
+ columns?: number;
405
+ showActions?: boolean;
406
+ refType?: string;
407
+ refId?: string;
408
+ /** Increment to trigger a refetch (e.g. after an upload). */
409
+ refreshSignal?: number;
410
+ className?: string;
411
+ style?: React.CSSProperties;
412
+ }
413
+ declare function ImagePicker({ onSelect, onClose, mode, pageSize, showSearch, searchPlaceholder, selectedImageId, columns, showActions, refType, refId, refreshSignal, className, style, }: ImagePickerProps): react_jsx_runtime.JSX.Element | null;
414
+
415
+ interface ImageDetailsProps {
416
+ image: ImageResource;
417
+ onClose: () => void;
418
+ onEdit?: (image: ImageResource) => void;
419
+ onDelete?: (image: ImageResource) => void;
420
+ className?: string;
421
+ style?: React.CSSProperties;
422
+ }
423
+ declare function ImageDetails({ image, onClose, onEdit, onDelete, className, style, }: ImageDetailsProps): react_jsx_runtime.JSX.Element;
424
+
425
+ interface MrImageProps {
426
+ image: ImageResource;
427
+ width?: number;
428
+ height?: number;
429
+ variant?: string;
430
+ alt?: string;
431
+ className?: string;
432
+ style?: React.CSSProperties;
433
+ loading?: "lazy" | "eager";
434
+ objectFit?: React.CSSProperties["objectFit"];
435
+ sizes?: string;
436
+ onLoad?: () => void;
437
+ onError?: () => void;
438
+ }
439
+ declare function MrImage({ image, width, height, variant: variantName, alt, className, style, loading, objectFit, sizes, onLoad, onError, }: MrImageProps): react_jsx_runtime.JSX.Element;
440
+
441
+ type UseFilesOptions = {
442
+ page?: number;
443
+ pageSize?: number;
444
+ q?: string;
445
+ refType?: string;
446
+ refId?: string;
447
+ enabled?: boolean;
448
+ };
449
+ type UseFilesReturn = {
450
+ files: FileResource[];
451
+ page: number;
452
+ pageSize: number;
453
+ total: number;
454
+ pageCount: number;
455
+ loading: boolean;
456
+ error: string | null;
457
+ refetch: () => void;
458
+ setPage: (page: number) => void;
459
+ setQuery: (q: string) => void;
460
+ available: boolean;
461
+ removeFile: (fileId: string) => Promise<void>;
462
+ updateFile: (fileId: string, opts: FileUpdateOptions) => Promise<void>;
463
+ };
464
+ declare function useFiles(opts?: UseFilesOptions): UseFilesReturn;
465
+
466
+ type UseFileOptions = {
467
+ enabled?: boolean;
468
+ };
469
+ type UseFileReturn = {
470
+ file: FileResource | null;
471
+ loading: boolean;
472
+ error: string | null;
473
+ refetch: () => void;
474
+ available: boolean;
475
+ };
476
+ declare function useFile(fileId: string | null | undefined, opts?: UseFileOptions): UseFileReturn;
477
+
478
+ type UseFileUploadReturn = {
479
+ upload: (opts: FileUploadOptions) => Promise<void>;
480
+ cancel: () => void;
481
+ progress: UploadProgress;
482
+ reset: () => void;
483
+ available: boolean;
484
+ };
485
+ declare function useFileUpload(): UseFileUploadReturn;
486
+
487
+ interface FileUploaderProps {
488
+ onUpload?: () => void;
489
+ onError?: (error: string) => void;
490
+ defaultTitle?: string;
491
+ defaultDescription?: string;
492
+ showFields?: boolean;
493
+ accept?: string;
494
+ maxSize?: number;
495
+ refType?: string;
496
+ refId?: string;
497
+ className?: string;
498
+ style?: React.CSSProperties;
499
+ label?: string;
500
+ disabled?: boolean;
501
+ }
502
+ declare function FileUploader({ onUpload, onError, defaultTitle, defaultDescription, showFields, accept, maxSize, refType, refId, className, style, label, disabled, }: FileUploaderProps): react_jsx_runtime.JSX.Element | null;
503
+
504
+ interface FilePickerProps {
505
+ onSelect?: (file: FileResource) => void;
506
+ onClose?: () => void;
507
+ mode?: "modal" | "inline";
508
+ pageSize?: number;
509
+ showSearch?: boolean;
510
+ searchPlaceholder?: string;
511
+ selectedFileId?: string;
512
+ showActions?: boolean;
513
+ refType?: string;
514
+ refId?: string;
515
+ /** Increment to trigger a refetch (e.g. after an upload). */
516
+ refreshSignal?: number;
517
+ className?: string;
518
+ style?: React.CSSProperties;
519
+ }
520
+ declare function FilePicker({ onSelect, onClose, mode, pageSize, showSearch, searchPlaceholder, selectedFileId, showActions, refType, refId, refreshSignal, className, style, }: FilePickerProps): react_jsx_runtime.JSX.Element | null;
521
+
522
+ interface FileDetailsProps {
523
+ file: FileResource;
524
+ onClose: () => void;
525
+ onEdit?: (file: FileResource) => void;
526
+ onDelete?: (file: FileResource) => void;
527
+ className?: string;
528
+ style?: React.CSSProperties;
529
+ }
530
+ declare function FileDetails({ file, onClose, onEdit, onDelete, className, style, }: FileDetailsProps): react_jsx_runtime.JSX.Element;
531
+
532
+ export { AppKit, type AppKitAccount, type AppKitAppData, AppKitAuthed, type AppKitConfigValue, type AppKitFeatureFlag, type AppKitProjectAccess, type AppKitTheme, FileDetails, type FileDetailsProps, type FileListResponse, FilePicker, type FilePickerProps, type FileResource, type FileUpdateOptions, type FileUploadOptions, FileUploader, type FileUploaderProps, ImageDetails, type ImageDetailsProps, type ImageListResponse, ImagePicker, type ImagePickerProps, type ImageResource, type ImageUpdateOptions, type ImageUploadOptions, ImageUploader, type ImageUploaderProps, type ImageVariant, type ManyRowsAppKitError, type ManyRowsAppKitErrorCode, type ManyRowsAppKitHandle, type ManyRowsAppKitReady, type ManyRowsAppKitSnapshot, MrImage, type MrImageProps, type UploadProgress, type UseFileOptions, type UseFileReturn, type UseFileUploadReturn, type UseFilesOptions, type UseFilesReturn, type UseImageOptions, type UseImageReturn, type UseImageUploadReturn, type UseImagesOptions, type UseImagesReturn, UserButton, type UserButtonProps, useAppKit, useConfig, useConfigValue, useFeatureFlag, useFeatureFlags, useFile, useFileUpload, useFiles, useImage, useImageUpload, useImages, usePermission, usePermissions, useProject, useRole, useRoles, useToken, useUser };