frontend client for gemstone. decentralised workplace app
1import {
2 getOwnerDidResponseSchema,
3 httpSuccessResponseSchema,
4} from "@/lib/types/http/responses";
5import { z } from "zod";
6
7export const getOwnerInfoFromLattice = async (latticeDomain: string) => {
8 const reqUrl = new URL(
9 (latticeDomain.startsWith("localhost")
10 ? `http://${latticeDomain}`
11 : `https://${latticeDomain}`) +
12 "/xrpc/systems.gmstn.development.lattice.getOwner",
13 );
14 const req = new Request(reqUrl);
15 const res = await fetch(req);
16 const data: unknown = await res.json();
17
18 const {
19 success: httpResponseParseSuccess,
20 error: httpResponseParseError,
21 data: httpResponse,
22 } = httpSuccessResponseSchema.safeParse(data);
23 if (!httpResponseParseSuccess) {
24 console.error(
25 "Could not get lattice's owner info.",
26 z.treeifyError(httpResponseParseError),
27 );
28 return;
29 }
30
31 const {
32 success,
33 error,
34 data: result,
35 } = getOwnerDidResponseSchema.safeParse(httpResponse.data);
36
37 if (!success) {
38 console.error(
39 "Could not get lattice's owner info.",
40 z.treeifyError(error),
41 );
42 return;
43 }
44 return result;
45};