frontend client for gemstone. decentralised workplace app
at main 1.2 kB view raw
1import { 2 getOwnerDidResponseSchema, 3 httpSuccessResponseSchema, 4} from "@/lib/types/http/responses"; 5import { z } from "zod"; 6 7export const getOwnerInfoFromShard = async (shardDomain: string) => { 8 const reqUrl = new URL( 9 (shardDomain.startsWith("localhost") 10 ? `http://${shardDomain}` 11 : `https://${shardDomain}`) + 12 "/xrpc/systems.gmstn.development.shard.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 shard'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 shard's owner info.", 40 z.treeifyError(error), 41 ); 42 return; 43 } 44 return result; 45};