chat / client / src / sueta / config.cljs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
;; ported-from: src/config.ts (+ the VITE_* env plumbing that lived in room.ts)
;;
;; App identity + storage namespace, the two things a fork must own.
;;
;; APP-SALT namespaces every cryptographic derivation (PROTOCOL.md §1) — two
;; apps with identical room secrets never meet. NS namespaces every persistent
;; browser store (localStorage keys, IndexedDB databases) so two apps built on
;; this template can share an origin without sharing identity seeds, TOFU
;; bindings, room lists, or block stores. NS derives from the salt by default;
;; override with VITE_STORAGE_NS only if you need a specific prefix.
;;
;; OrbitDB's per-room directory is NOT namespaced here: it embeds the roomId,
;; which is already salt-derived and therefore fork-unique (lib/log.cljs).
;;
;; Vite's `import.meta.env.VITE_*` becomes a goog-define: scripts/dev.mjs and
;; scripts/build.mjs read the SAME env var names ardz already exports and pass
;; them via --config-merge. An empty string means "unset" (the TS wrote `??`,
;; which is nullish — a goog-define cannot be nil, so "" is the sentinel).
;; `import.meta.env.DEV` becomes goog.DEBUG.
(ns sueta.config)

(goog-define VITE-APP-SALT "")
(goog-define VITE-STORAGE-NS "")
(goog-define VITE-RELAY-MULTIADDR "")
(goog-define VITE-TURN-CREDS-URL "")
(goog-define VITE-DISCOVERY-TOPIC "")
(goog-define VITE-MAILBOX-URL "")
(goog-define VITE-MAILBOX-CREDS-URL "")
(goog-define VITE-ID-BRIDGE-URL "")

;; The build injects the version.json number; the banner and the lobby show it.
(goog-define APP-VERSION 0)

(defn- unset?
  "The goog-define sentinel for \"the env var was absent\"."
  [s]
  (or (nil? s) (identical? "" s)))

(defn- or-default [v d] (if (unset? v) d v))

(def APP-SALT (or-default VITE-APP-SALT "chat.ardegazu.ro/v2"))

(defn- slug [s]
  (-> ^string s
      (.toLowerCase)
      (.replace (js/RegExp. "[^a-z0-9]+" "g") "-")
      (.replace (js/RegExp. "^-+|-+$" "g") "")))

(def NS (or-default VITE-STORAGE-NS (slug APP-SALT)))

(defn ns-key
  "localStorage key inside this app's namespace, e.g. (ns-key \"id\") → \"<ns>:id\"."
  [k]
  (str NS ":" k))

(defn ns-db
  "IndexedDB database name inside this app's namespace, e.g. (ns-db \"blocks\")."
  [d]
  (str NS "-" d))

;; ---- relay / mailbox defaults (room.ts's DEFAULTS) -------------------------

(def DEV-RELAY-MULTIADDR
  "/ip4/127.0.0.1/tcp/9090/ws/p2p/12D3KooWJU33yQvEdNF1AXcm5RWyLLyDKxyKkayRvDpJcJtYqhYt") ; deploy/relay --dev

(def PROD-RELAY-MULTIADDR
  "/dns4/signal.ardegazu.ro/tcp/443/tls/ws/p2p/12D3KooWQzZvygPwd2F4JAqqf6tfBSJ29YtjzzftUyJ37RLCG5WT")

(def RELAY-MULTIADDR
  (or-default VITE-RELAY-MULTIADDR
              (if ^boolean goog.DEBUG DEV-RELAY-MULTIADDR PROD-RELAY-MULTIADDR)))

(def TURN-CREDS-URL
  (or-default VITE-TURN-CREDS-URL "https://signal.ardegazu.ro/turn-credentials"))

(def DISCOVERY-TOPIC
  (or-default VITE-DISCOVERY-TOPIC "_peer-discovery._p2p._pubsub"))

;; Offline mailbox: production discovers it via the relay descriptor; the env
;; pair is the dev/self-host path (a dev ip4 multiaddr skips the descriptor
;; fetch entirely, so there is nothing to discover from).
(def MAILBOX-URL (or-default VITE-MAILBOX-URL nil))
(def MAILBOX-CREDS-URL (or-default VITE-MAILBOX-CREDS-URL nil))

;; MUST go through or-default: id-kit's IdBridge defaults its bridgeUrl with
;; `(if (some? u) u DEFAULT-BRIDGE-URL)`, and `some?` is TRUE for "". Passing the
;; goog-define's ""-sentinel straight through therefore does NOT select id-kit's
;; default — it reaches `new URL("")`, which throws "Invalid URL" and kills the
;; whole room boot. nil is what id-kit's nullish check wants (as with MAILBOX-URL
;; above), and it is what TS passed: `import.meta.env.VITE_ID_BRIDGE_URL` is
;; `undefined` when unset, never "".
(def ID-BRIDGE-URL (or-default VITE-ID-BRIDGE-URL nil))

static mirror of HEAD · about · clone: git clone https://git.ardegazu.ro/chat.git