@noya-app/noya-api-client-react 0.1.46 → 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/.turbo/turbo-build.log +17 -18
- package/CHANGELOG.md +15 -0
- package/dist/index.d.mts +60 -1
- package/dist/index.d.ts +60 -1
- package/dist/index.js +132 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +128 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/react/hooks.ts +205 -0
package/dist/index.mjs
CHANGED
|
@@ -2457,6 +2457,24 @@ function useNoyaWorkspaces() {
|
|
|
2457
2457
|
}, [client, fetchWorkspaces]);
|
|
2458
2458
|
return workspaces;
|
|
2459
2459
|
}
|
|
2460
|
+
function useNoyaWorkspaceMembers(workspaceId) {
|
|
2461
|
+
const { workspaces, loading } = useNoyaWorkspaces();
|
|
2462
|
+
return useMemo2(() => {
|
|
2463
|
+
const workspace = workspaces.find((w) => w.id === workspaceId);
|
|
2464
|
+
const members = workspace?.members.map((m) => ({
|
|
2465
|
+
userId: m.userId,
|
|
2466
|
+
name: m.user.name,
|
|
2467
|
+
email: m.user.email,
|
|
2468
|
+
image: m.user.image,
|
|
2469
|
+
role: m.role
|
|
2470
|
+
})) ?? [];
|
|
2471
|
+
const membersById = /* @__PURE__ */ new Map();
|
|
2472
|
+
for (const member of members) {
|
|
2473
|
+
membersById.set(member.userId, member);
|
|
2474
|
+
}
|
|
2475
|
+
return { members, membersById, loading };
|
|
2476
|
+
}, [workspaces, workspaceId, loading]);
|
|
2477
|
+
}
|
|
2460
2478
|
function useNoyaMultiplayerRoomToken(fileId) {
|
|
2461
2479
|
const client = useNoyaClientOrFallback();
|
|
2462
2480
|
const multiplayerRoomToken = useObservable(
|
|
@@ -2521,6 +2539,111 @@ function useNoyaTemplates() {
|
|
|
2521
2539
|
loading: loading === "fetching"
|
|
2522
2540
|
};
|
|
2523
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
|
+
}
|
|
2524
2647
|
|
|
2525
2648
|
// ../../node_modules/@sinclair/typebox/build/esm/type/guard/value.mjs
|
|
2526
2649
|
var value_exports = {};
|
|
@@ -15249,9 +15372,11 @@ function useActivityEventsList(fileId, select, options = {}) {
|
|
|
15249
15372
|
export {
|
|
15250
15373
|
NoyaAPIProvider,
|
|
15251
15374
|
useActivityEventsList,
|
|
15375
|
+
useFileAccess,
|
|
15252
15376
|
useFileList,
|
|
15253
15377
|
useFileListItem,
|
|
15254
15378
|
useIsBeta,
|
|
15379
|
+
useIsFileOwner,
|
|
15255
15380
|
useMetadata,
|
|
15256
15381
|
useNetworkRequests,
|
|
15257
15382
|
useNoyaAssets,
|
|
@@ -15275,6 +15400,7 @@ export {
|
|
|
15275
15400
|
useNoyaUserData,
|
|
15276
15401
|
useNoyaWorkspaceBilling,
|
|
15277
15402
|
useNoyaWorkspaceInvitations,
|
|
15403
|
+
useNoyaWorkspaceMembers,
|
|
15278
15404
|
useNoyaWorkspaces,
|
|
15279
15405
|
useOptionalNoyaClient,
|
|
15280
15406
|
useOptionalNoyaCreators,
|
|
@@ -15284,6 +15410,7 @@ export {
|
|
|
15284
15410
|
useOptionalNoyaUserData,
|
|
15285
15411
|
useResourcesList,
|
|
15286
15412
|
useTable,
|
|
15287
|
-
useUser
|
|
15413
|
+
useUser,
|
|
15414
|
+
useWorkspaceAccess
|
|
15288
15415
|
};
|
|
15289
15416
|
//# sourceMappingURL=index.mjs.map
|