frontend client for gemstone. decentralised workplace app
1import { didSchema, type Did } from "@/lib/types/atproto";
2import { getConstellationBacklinks } from "@/lib/utils/constellation";
3import type { Result } from "@/lib/utils/result";
4import { z } from "zod";
5
6// TODO: use prism instead of constellation, so that we can get the full record
7// in the future. that way we can track the status of an invite.
8export const getInvitesFromConstellation = async (
9 did: Did,
10): Promise<
11 Result<
12 {
13 invites: Array<{
14 did: `did:${string}:${string}`;
15 collection: "systems.gmstn.development.channel.invite";
16 rkey: string;
17 }>;
18 },
19 unknown
20 >
21> => {
22 const backlinksResult = await getConstellationBacklinks({
23 subject: did,
24 source: {
25 nsid: "systems.gmstn.development.channel.invite",
26 fieldName: "recipient",
27 },
28 });
29
30 if (!backlinksResult.ok) return { ok: false, error: backlinksResult.error };
31
32 const {
33 success,
34 error,
35 data: records,
36 } = z
37 .array(
38 z.object({
39 did: didSchema,
40 collection: z.literal(
41 "systems.gmstn.development.channel.invite",
42 ),
43 rkey: z.string(),
44 }),
45 )
46 .safeParse(backlinksResult.data);
47
48 if (!success) return { ok: false, error };
49
50 return {
51 ok: true,
52 data: {
53 invites: [...records],
54 },
55 };
56};