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

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 = {};
@@ -5190,14 +5295,6 @@ var Emitter = class {
5190
5295
  bufferedEvents = [];
5191
5296
  };
5192
5297
 
5193
- // ../state-manager/src/AIManager.ts
5194
- import { isDeepEqual } from "@noya-app/noya-utils";
5195
- import { Observable as Observable2 } from "@noya-app/observable";
5196
-
5197
- // ../state-manager/src/AssetManager.ts
5198
- import { Base64, uuid } from "@noya-app/noya-utils";
5199
- import { Observable as Observable3 } from "@noya-app/observable";
5200
-
5201
5298
  // ../noya-schemas/src/nullable.ts
5202
5299
  var Nullable = (schema) => Type.Union([Type.Null(), schema]);
5203
5300
 
@@ -5599,6 +5696,14 @@ function validateUUID(value) {
5599
5696
  format_exports.Set("color", () => true);
5600
5697
  format_exports.Set("uuid", validateUUID);
5601
5698
 
5699
+ // ../state-manager/src/AIManager.ts
5700
+ import { Base64, isDeepEqual } from "@noya-app/noya-utils";
5701
+ import { Observable as Observable2 } from "@noya-app/observable";
5702
+
5703
+ // ../state-manager/src/AssetManager.ts
5704
+ import { Base64 as Base642, uuid } from "@noya-app/noya-utils";
5705
+ import { Observable as Observable3 } from "@noya-app/observable";
5706
+
5602
5707
  // ../state-manager/src/ConnectionEventManager.ts
5603
5708
  import { Observable as Observable4 } from "@noya-app/observable";
5604
5709
 
@@ -10553,7 +10658,7 @@ import { Observable as Observable17 } from "@noya-app/observable";
10553
10658
  import { Observable as Observable18 } from "@noya-app/observable";
10554
10659
 
10555
10660
  // ../state-manager/src/TranscriptionManager.ts
10556
- import { Base64 as Base642 } from "@noya-app/noya-utils";
10661
+ import { Base64 as Base643 } from "@noya-app/noya-utils";
10557
10662
  import { Observable as Observable19 } from "@noya-app/observable";
10558
10663
 
10559
10664
  // ../state-manager/src/UserManager.ts
@@ -10683,7 +10788,7 @@ if (typeof window !== "undefined") {
10683
10788
  import { uuid as uuid10 } from "@noya-app/noya-utils";
10684
10789
 
10685
10790
  // ../state-manager/src/sync/localRpcHelpers.ts
10686
- import { Base64 as Base643 } from "@noya-app/noya-utils";
10791
+ import { Base64 as Base644 } from "@noya-app/noya-utils";
10687
10792
 
10688
10793
  // ../state-manager/src/sync/localStorageSync.ts
10689
10794
  import { uuid as uuid11 } from "@noya-app/noya-utils";
@@ -11223,7 +11328,7 @@ import React35 from "react";
11223
11328
  import { createRoot } from "react-dom/client";
11224
11329
 
11225
11330
  // ../noya-multiplayer-react/src/inspector/StateInspector.tsx
11226
- import { Base64 as Base644, memoize, uuid as uuid13 } from "@noya-app/noya-utils";
11331
+ import { Base64 as Base645, memoize, uuid as uuid13 } from "@noya-app/noya-utils";
11227
11332
  import React34, {
11228
11333
  useCallback as useCallback12,
11229
11334
  useEffect as useEffect14,
@@ -14770,7 +14875,7 @@ var StateInspector = memoGeneric(function StateInspector2({
14770
14875
  type: "asset",
14771
14876
  path: file.name || uuid13(),
14772
14877
  asset: {
14773
- content: Base644.encode(await file.arrayBuffer()),
14878
+ content: Base645.encode(await file.arrayBuffer()),
14774
14879
  contentType: file.type,
14775
14880
  encoding: "base64"
14776
14881
  }
@@ -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