decentralised sync engine
at main 2.7 kB view raw
1import { didSchema } from "@/lib/types/atproto"; 2import "dotenv/config"; 3import { z } from "zod"; 4 5const nodeEnv = process.env.NODE_ENV; 6export const NODE_ENV = nodeEnv ?? "development"; 7 8export const isDev = NODE_ENV === "development"; 9export const __DEV__ = isDev; 10 11const serverPort = process.env.SERVER_PORT; 12if (!serverPort) 13 console.warn( 14 "Environment variable SERVER_PORT not set. Defaulting to 7338", 15 ); 16export const SERVER_PORT = Number.parseInt(serverPort ?? "7338"); 17 18const serviceDid = process.env.SERVICE_DID; 19const { 20 success: serviceDidParseSuccess, 21 error: serviceDidParseError, 22 data: serviceDidParsed, 23} = didSchema.safeParse(serviceDid); 24if (!serviceDidParseSuccess) { 25 console.warn(serviceDidParseError); 26 console.warn( 27 "Environment variable SERVICE_DID not set. Defaulting to `did:web:localhost`", 28 ); 29} 30export const SERVICE_DID = serviceDidParsed ?? `did:web:localhost%3A${SERVER_PORT.toString()}`; 31 32const constellationUrl = process.env.CONSTELLATION_URL; 33let constellationUrlParsed: URL | undefined; 34try { 35 constellationUrlParsed = new URL(constellationUrl ?? ""); 36} catch (err) { 37 console.warn( 38 "Invalid CONSTELLATION_URL. Please ensure that the environment variable is a valid URL.", 39 ); 40 console.warn("Falling back to default constellation instance."); 41 console.warn(err); 42} 43export const CONSTELLATION_URL = 44 constellationUrlParsed ?? new URL("https://constellation.microcosm.blue/"); 45 46const ownerDid = process.env.OWNER_DID; 47const { 48 success: ownerDidParseSuccess, 49 error: ownerDidParseError, 50 data: ownerDidParsed, 51} = didSchema.safeParse(ownerDid); 52if (!ownerDidParseSuccess) { 53 console.error( 54 "Could not parse OWNER_DID environment variable. Ensure that it is set and that it is a valid ATProto DID.", 55 ); 56 console.error( 57 "See the example environment variables file for more information. `.example.env` in the project root.", 58 ); 59 console.error( 60 "If you are doing local development, you must still set an owner did. This must point to a repo containing the records from the bootstrap.", 61 ); 62 throw new Error(z.prettifyError(ownerDidParseError)); 63} 64export const OWNER_DID = ownerDidParsed; 65 66const prismUrl = process.env.PRISM_URL; 67let prismUrlParsed: URL | undefined; 68try { 69 prismUrlParsed = new URL(prismUrl ?? ""); 70} catch (err) { 71 console.warn( 72 "Invalid PRISM_URL. Please ensure that the environment variable is a valid URL.", 73 ); 74 console.warn("Falling back to default prism instance."); 75 console.warn(err); 76} 77export const PRISM_URL = 78 prismUrlParsed ?? new URL("wss://jetstream.gmstn.systems/subscribe");