@noya-app/noya-api-client-react 0.1.47 → 0.1.48

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.mjs CHANGED
@@ -2539,6 +2539,111 @@ function useNoyaTemplates() {
2539
2539
  loading: loading === "fetching"
2540
2540
  };
2541
2541
  }
2542
+ function useWorkspaceAccess(workspaceId) {
2543
+ const session = useNoyaSession();
2544
+ const { workspaces, loading } = useNoyaWorkspaces();
2545
+ return useMemo2(() => {
2546
+ const userId = session?.user?.id;
2547
+ const workspace = workspaces.find((w) => w.id === workspaceId);
2548
+ if (!workspace || !userId) {
2549
+ return {
2550
+ isMember: false,
2551
+ role: null,
2552
+ isOwner: false,
2553
+ isAdmin: false,
2554
+ workspaceId,
2555
+ loading
2556
+ };
2557
+ }
2558
+ const member = workspace.members.find((m) => m.userId === userId);
2559
+ const role = member?.role ?? null;
2560
+ return {
2561
+ isMember: !!member,
2562
+ role,
2563
+ isOwner: role === "OWNER",
2564
+ isAdmin: role === "OWNER" || role === "ADMIN",
2565
+ workspaceId,
2566
+ loading
2567
+ };
2568
+ }, [session?.user?.id, workspaces, workspaceId, loading]);
2569
+ }
2570
+ function useFileAccess(file) {
2571
+ const session = useNoyaSession();
2572
+ const { workspaces, loading: workspacesLoading } = useNoyaWorkspaces();
2573
+ return useMemo2(() => {
2574
+ const userId = session?.user?.id;
2575
+ const noAccess = {
2576
+ isOwner: false,
2577
+ canView: false,
2578
+ canEdit: false,
2579
+ accessSource: "none",
2580
+ loading: workspacesLoading
2581
+ };
2582
+ if (!file) return noAccess;
2583
+ const isOwner = !!(userId && file.user?.id === userId);
2584
+ if (isOwner) {
2585
+ return {
2586
+ isOwner: true,
2587
+ canView: true,
2588
+ canEdit: true,
2589
+ accessSource: "owner",
2590
+ loading: false
2591
+ };
2592
+ }
2593
+ if (file.workspaceId && userId) {
2594
+ const workspace = workspaces.find((w) => w.id === file.workspaceId);
2595
+ const isMember = workspace?.members.some((m) => m.userId === userId);
2596
+ if (isMember) {
2597
+ const workspaceAccess = file.workspaceAccess ?? "private";
2598
+ if (workspaceAccess === "write") {
2599
+ return {
2600
+ isOwner: false,
2601
+ canView: true,
2602
+ canEdit: true,
2603
+ accessSource: "workspace",
2604
+ loading: false
2605
+ };
2606
+ }
2607
+ if (workspaceAccess === "read") {
2608
+ return {
2609
+ isOwner: false,
2610
+ canView: true,
2611
+ canEdit: false,
2612
+ accessSource: "workspace",
2613
+ loading: false
2614
+ };
2615
+ }
2616
+ }
2617
+ }
2618
+ const publicAccess = file.access ?? "private";
2619
+ if (publicAccess === "write") {
2620
+ return {
2621
+ isOwner: false,
2622
+ canView: true,
2623
+ canEdit: true,
2624
+ accessSource: "public",
2625
+ loading: false
2626
+ };
2627
+ }
2628
+ if (publicAccess === "read") {
2629
+ return {
2630
+ isOwner: false,
2631
+ canView: true,
2632
+ canEdit: false,
2633
+ accessSource: "public",
2634
+ loading: false
2635
+ };
2636
+ }
2637
+ return noAccess;
2638
+ }, [session?.user?.id, file, workspaces, workspacesLoading]);
2639
+ }
2640
+ function useIsFileOwner(file) {
2641
+ const session = useNoyaSession();
2642
+ return useMemo2(() => {
2643
+ if (!file || !session?.user?.id) return false;
2644
+ return file.user?.id === session.user.id;
2645
+ }, [file, session?.user?.id]);
2646
+ }
2542
2647
 
2543
2648
  // ../../node_modules/@sinclair/typebox/build/esm/type/guard/value.mjs
2544
2649
  var value_exports = {};
@@ -15267,9 +15372,11 @@ function useActivityEventsList(fileId, select, options = {}) {
15267
15372
  export {
15268
15373
  NoyaAPIProvider,
15269
15374
  useActivityEventsList,
15375
+ useFileAccess,
15270
15376
  useFileList,
15271
15377
  useFileListItem,
15272
15378
  useIsBeta,
15379
+ useIsFileOwner,
15273
15380
  useMetadata,
15274
15381
  useNetworkRequests,
15275
15382
  useNoyaAssets,
@@ -15303,6 +15410,7 @@ export {
15303
15410
  useOptionalNoyaUserData,
15304
15411
  useResourcesList,
15305
15412
  useTable,
15306
- useUser
15413
+ useUser,
15414
+ useWorkspaceAccess
15307
15415
  };
15308
15416
  //# sourceMappingURL=index.mjs.map