From 75983dc98ee0654f9af2aed7e08119527cfa4a3a Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Tue, 14 Sep 2021 15:08:13 +0200 Subject: [PATCH] Migrate to host/id based seed node records Instead of having one record per service, we configure the host and expect services to run on certain ports. --- src/Form.svelte | 5 ++++- src/api.ts | 9 +++++---- src/base/projects/Browser.svelte | 4 ++-- src/base/registrations/View.svelte | 12 +++++++----- src/base/registrations/registrar.ts | 10 +++++----- src/base/registrations/resolver.ts | 2 +- src/config.json | 2 +- src/config.ts | 9 ++++----- src/profile.ts | 2 +- src/utils.ts | 14 +++----------- 10 files changed, 33 insertions(+), 36 deletions(-) diff --git a/src/Form.svelte b/src/Form.svelte index 9cfd651e2..d5f79d3f5 100644 --- a/src/Form.svelte +++ b/src/Form.svelte @@ -23,7 +23,10 @@ // Maximum is 15 characters. // For simplification of the regex pattern we use a combined version of both requirements. handle: /^[a-zA-Z0-9-_]{1,39}$/, - address: /^0x[a-zA-Z0-9]{40}$/ + address: /^0x[a-zA-Z0-9]{40}$/, + id: /^[a-z0-9]+$/, + // Just make sure there is a TLD at the end. + domain: /\.[a-z]{2,}$/, }; diff --git a/src/api.ts b/src/api.ts index 68c266633..5a65bb004 100644 --- a/src/api.ts +++ b/src/api.ts @@ -5,8 +5,8 @@ export async function get( params: Record, config: Config ): Promise { - if (! config.seed.api) { - throw new Error("Seed HTTP API unavailable"); + if (! config.seed.host) { + throw new Error("Seed host unavailable"); } const query: Record = {}; @@ -14,9 +14,10 @@ export async function get( query[key] = val.toString(); } - const base = config.seed.api.replace(/\/$/, ""); + const base = config.seed.host; + const port = config.seed.port; const search = new URLSearchParams(query).toString(); - const baseUrl = `${base}/v1/${path}`; + const baseUrl = `https://${base}:${port}/v1/${path}`; const url = search ? `${baseUrl}?${search}` : baseUrl; let response = null; diff --git a/src/base/projects/Browser.svelte b/src/base/projects/Browser.svelte index b31cea8ed..f40daaf58 100644 --- a/src/base/projects/Browser.svelte +++ b/src/base/projects/Browser.svelte @@ -188,9 +188,9 @@
{tree.stats.contributors} contributor(s)
- {#if config.seed.api} + {#if config.seed.host}
- {utils.formatSeedApi(config.seed.api)} + {config.seed.host}
{/if}
diff --git a/src/base/registrations/View.svelte b/src/base/registrations/View.svelte index 1bf790339..29555034d 100644 --- a/src/base/registrations/View.svelte +++ b/src/base/registrations/View.svelte @@ -75,12 +75,14 @@ { name: "github", validate: "handle", label: "GitHub", placeholder: "GitHub username, eg. 'acme'", description: "The GitHub username associated with this name.", value: r.profile.github, editable: true }, - { name: "seed.id", label: "Seed ID", placeholder: "hynkyn...3nrzc@seed.acme.org:8887", - description: "The ID of a Radicle Link node that hosts entities associated with this name.", + { name: "seed.host", label: "Seed Host", validate: "domain", placeholder: "seed.acme.org", + description: "The seed host address. " + + "Only domain names with TLS are supported. " + + `HTTP(S) API requests use port ${config.seed.port}.`, + value: r.profile.seedHost, editable: true }, + { name: "seed.id", label: "Seed ID", validate: "id", placeholder: "hynkyndc6w3p8urucakobzncqny7xxtw88...", + description: "The Device ID of a Radicle Link node that hosts entities associated with this name.", value: r.profile.seedId, editable: true }, - { name: "seed.api", label: "Seed API", validate: "url", placeholder: "https://seed.acme.org:8888", - description: "The HTTP address of a node that serves Radicle entities over HTTP.", - value: r.profile.seedApi, editable: true }, ]; state = { status: Status.Found, registration: r }; } else { diff --git a/src/base/registrations/registrar.ts b/src/base/registrations/registrar.ts index 3c3addab8..152f6cd6b 100644 --- a/src/base/registrations/registrar.ts +++ b/src/base/registrations/registrar.ts @@ -20,7 +20,7 @@ export interface EnsProfile { owner?: string; address: string | null; seedId: string | null; - seedApi: string | null; + seedHost: string | null; url: string | null; avatar: string | null; twitter: string | null; @@ -72,12 +72,12 @@ export async function getRegistration(name: string, config: Config): Promise r.status == "fulfilled" ? r.value : null); return { @@ -88,7 +88,7 @@ export async function getRegistration(name: string, config: Config): Promise> config)[network.name]; const ceramic = new CeramicClient(config.ceramic.api); const idx = new IDX({ ceramic }); @@ -97,7 +96,7 @@ export class Config { signer: wc.signer, state: walletConnectState, }; - this.seed = { api }; + this.seed = config.radicle.seed; this.registrar = cfg.registrar; this.radToken = cfg.radToken; this.orgFactory = cfg.orgFactory; @@ -126,10 +125,10 @@ export class Config { } // Return the config with an overwritten seed URL. - withSeed(seed: string): Config { + withSeed(seedHost: string): Config { const cfg = {} as Config; Object.assign(cfg, this); - cfg.seed.api = seed.replace(/\/$/, ""); + cfg.seed.host = seedHost; return cfg; } diff --git a/src/profile.ts b/src/profile.ts index d41af7e19..7bd54d55a 100644 --- a/src/profile.ts +++ b/src/profile.ts @@ -73,7 +73,7 @@ export class Profile { // Using undefined as return type if nothing to be returned since it works better with links get seed(): string | undefined { - return this.profile?.ens?.seedApi ?? undefined; + return this.profile?.ens?.seedHost ?? undefined; } // Return the profile-specific config. This sets various URLs in the config, diff --git a/src/utils.ts b/src/utils.ts index d86d93d01..da125bb7f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -63,14 +63,6 @@ export function formatHash(hash: string): string { + hash.substring(hash.length - 4, hash.length); } -export function formatSeedApi(input: string): string { - const match = input.match(/^https?:\/\/([^:]+)/); - if (match) { - return match[1]; - } - return input; -} - export function formatNetwork(input: { name: string }): string { let name = input.name; @@ -256,13 +248,13 @@ export async function resolveEnsProfile(address: string, profileType: ProfileTyp } } else if (profileType === ProfileType.Project) { const avatar = await getAvatar(name, config); - const seedApi = await getSeed(name, config); + const seedHost = await getSeed(name, config); return { name, address, avatar, - seedApi, + seedHost, url: null, seedId: null, twitter: null, @@ -277,7 +269,7 @@ export async function resolveEnsProfile(address: string, profileType: ProfileTyp avatar, url: null, seedId: null, - seedApi: null, + seedHost: null, twitter: null, github: null, };