;; App identity + storage namespace, the two things a fork must own.
;;
;; APP-SALT namespaces every cryptographic derivation (chat's docs/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, room lists, or block stores. NS derives from the salt by default;
;; override with VITE_STORAGE_NS only if you need a specific prefix.
;;
;; New apps start at /v1; bump the suffix only for a deliberate protocol break
;; (it strands every existing room). OrbitDB's per-room directory is NOT
;; namespaced here: it embeds the roomId, which is already salt-derived and
;; therefore app-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 __NAME__.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 "__HOST__/v1"))
(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 ----------------------------------------------
(def DEV-RELAY-MULTIADDR
"/ip4/127.0.0.1/tcp/9090/ws/p2p/12D3KooWJU33yQvEdNF1AXcm5RWyLLyDKxyKkayRvDpJcJtYqhYt") ; ardz 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 (https://ardegazu.ro/id/) — 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 "".
;; The same audit applies to every goog-define you add here.
(def ID-BRIDGE-URL (or-default VITE-ID-BRIDGE-URL nil))
;; ---- app constants go below (limits, sizes, timings, …) --------------------
;; Demo: the note wall's caps (see app/store.cljs).
(def MAX-NOTES 1000)
(def MAX-TEXT 8000)