tina4-nodejs 3.13.152 → 3.13.154

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CLAUDE.md CHANGED
@@ -10,16 +10,17 @@ Even if the skill text is not currently loaded, these are non-negotiable:
10
10
  - Plan-driven: track work in `plan/<task>.md` (Scope / Parity / Tests / Bugs / Commits).
11
11
  - Verify before claiming: re-run the FULL suite green yourself on CI or the lab at the exact HEAD — never trust an unrun green.
12
12
  - Dashboard reporting: status as tables, terse.
13
+ - Stay on skill: check every move against this floor as you work; the moment you - or work you are reviewing - drift, warn in one line (name the rule + the correction) and steer back the same turn. Warn, do not block.
13
14
 
14
15
  The full discipline lives in `.claude/skills/tina4-maintainer/SKILL.md`; this block is the always-on floor.
15
16
 
16
- # CLAUDE.md - AI Developer Guide for tina4-nodejs (v3.13.152)
17
+ # CLAUDE.md - AI Developer Guide for tina4-nodejs (v3.13.154)
17
18
 
18
19
  > This file helps AI assistants (Claude, Copilot, Cursor, etc.) understand and work on this codebase effectively.
19
20
 
20
21
  ## What This Project Is
21
22
 
22
- Tina4 for Node.js/TypeScript v3.13.152 - The Intelligent Native Application 4ramework. A convention-over-configuration structural paradigm. The developer writes TypeScript; Tina4 is invisible infrastructure.
23
+ Tina4 for Node.js/TypeScript v3.13.154 - The Intelligent Native Application 4ramework. A convention-over-configuration structural paradigm. The developer writes TypeScript; Tina4 is invisible infrastructure.
23
24
 
24
25
  The philosophy: zero ceremony, batteries included, file system as source of truth.
25
26
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tina4-nodejs",
3
- "version": "3.13.152",
3
+ "version": "3.13.154",
4
4
  "type": "module",
5
5
  "description": "Tina4 for Node.js/TypeScript - native TypeScript conventions and shared Tina4 contracts",
6
6
  "keywords": [
@@ -13552,6 +13552,16 @@ function currentCspNonce() {
13552
13552
  function cspNonce() {
13553
13553
  return currentCspNonce();
13554
13554
  }
13555
+ function applyNonceToDirective(directives, directive, defaultValue, token) {
13556
+ const existing = directives.find(([name]) => name === directive);
13557
+ const resolved = (existing ? existing[1] : defaultValue).split(/\s+/);
13558
+ if (resolved.includes("'unsafe-inline'")) return;
13559
+ if (!existing) {
13560
+ directives.push([directive, `${defaultValue} ${token}`.trim()]);
13561
+ } else if (!resolved.includes(token)) {
13562
+ existing[1] = `${existing[1]} ${token}`.trim();
13563
+ }
13564
+ }
13555
13565
  function injectNonceIntoCsp(csp, nonce) {
13556
13566
  const token = `'nonce-${nonce}'`;
13557
13567
  const directives = [];
@@ -13566,14 +13576,7 @@ function injectNonceIntoCsp(csp, nonce) {
13566
13576
  const defaultEntry = directives.find(([name]) => name === "default-src");
13567
13577
  const defaultValue = defaultEntry && defaultEntry[1] ? defaultEntry[1] : "'self'";
13568
13578
  for (const directive of ["style-src", "script-src"]) {
13569
- const existing = directives.find(([name]) => name === directive);
13570
- if (existing) {
13571
- if (!existing[1].split(/\s+/).includes(token)) {
13572
- existing[1] = `${existing[1]} ${token}`.trim();
13573
- }
13574
- } else {
13575
- directives.push([directive, `${defaultValue} ${token}`.trim()]);
13576
- }
13579
+ applyNonceToDirective(directives, directive, defaultValue, token);
13577
13580
  }
13578
13581
  return directives.map(([name, value]) => value ? `${name} ${value}` : name).join("; ");
13579
13582
  }
@@ -18737,8 +18740,12 @@ async function realtime(options = {}) {
18737
18740
  if (features.includes("files")) registerFiles(paths, options.storage);
18738
18741
  return paths;
18739
18742
  }
18743
+ function rtcRequireAuth() {
18744
+ const raw = (process.env.TINA4_RTC_REQUIRE_AUTH ?? "true").trim().toLowerCase();
18745
+ return !["false", "0", "no", "off"].includes(raw);
18746
+ }
18740
18747
  function registerConfig(paths, features) {
18741
- Router.get(paths.config, async (_req, res) => {
18748
+ const route = Router.get(paths.config, async (_req, res) => {
18742
18749
  const body = { backend: "mesh" };
18743
18750
  if (features.includes("calls")) {
18744
18751
  body.iceServers = iceServers();
@@ -18751,9 +18758,10 @@ function registerConfig(paths, features) {
18751
18758
  if (features.includes("files")) body.files = paths.files;
18752
18759
  return res.json(body, HTTP_OK);
18753
18760
  });
18761
+ if (rtcRequireAuth()) route.secure();
18754
18762
  }
18755
18763
  function registerCalls(paths) {
18756
- Router.websocket(`${paths.signalling}/{room}`, (connection, event, data) => {
18764
+ const route = Router.websocket(`${paths.signalling}/{room}`, (connection, event, data) => {
18757
18765
  const room = connection.params.room ?? "";
18758
18766
  if (!room) return;
18759
18767
  const key = `rtc:${room}`;
@@ -18763,6 +18771,7 @@ function registerCalls(paths) {
18763
18771
  connection.broadcastToRoom(key, data, true);
18764
18772
  }
18765
18773
  });
18774
+ if (rtcRequireAuth()) route.secure();
18766
18775
  }
18767
18776
  function registerChat(paths) {
18768
18777
  Router.websocket(`${paths.chat}/{channel}`, chatHandler, { secured: true });
@@ -13551,6 +13551,16 @@ function currentCspNonce() {
13551
13551
  function cspNonce() {
13552
13552
  return currentCspNonce();
13553
13553
  }
13554
+ function applyNonceToDirective(directives, directive, defaultValue, token) {
13555
+ const existing = directives.find(([name]) => name === directive);
13556
+ const resolved = (existing ? existing[1] : defaultValue).split(/\s+/);
13557
+ if (resolved.includes("'unsafe-inline'")) return;
13558
+ if (!existing) {
13559
+ directives.push([directive, `${defaultValue} ${token}`.trim()]);
13560
+ } else if (!resolved.includes(token)) {
13561
+ existing[1] = `${existing[1]} ${token}`.trim();
13562
+ }
13563
+ }
13554
13564
  function injectNonceIntoCsp(csp, nonce) {
13555
13565
  const token = `'nonce-${nonce}'`;
13556
13566
  const directives = [];
@@ -13565,14 +13575,7 @@ function injectNonceIntoCsp(csp, nonce) {
13565
13575
  const defaultEntry = directives.find(([name]) => name === "default-src");
13566
13576
  const defaultValue = defaultEntry && defaultEntry[1] ? defaultEntry[1] : "'self'";
13567
13577
  for (const directive of ["style-src", "script-src"]) {
13568
- const existing = directives.find(([name]) => name === directive);
13569
- if (existing) {
13570
- if (!existing[1].split(/\s+/).includes(token)) {
13571
- existing[1] = `${existing[1]} ${token}`.trim();
13572
- }
13573
- } else {
13574
- directives.push([directive, `${defaultValue} ${token}`.trim()]);
13575
- }
13578
+ applyNonceToDirective(directives, directive, defaultValue, token);
13576
13579
  }
13577
13580
  return directives.map(([name, value]) => value ? `${name} ${value}` : name).join("; ");
13578
13581
  }
@@ -18736,8 +18739,12 @@ async function realtime(options = {}) {
18736
18739
  if (features.includes("files")) registerFiles(paths, options.storage);
18737
18740
  return paths;
18738
18741
  }
18742
+ function rtcRequireAuth() {
18743
+ const raw = (process.env.TINA4_RTC_REQUIRE_AUTH ?? "true").trim().toLowerCase();
18744
+ return !["false", "0", "no", "off"].includes(raw);
18745
+ }
18739
18746
  function registerConfig(paths, features) {
18740
- Router.get(paths.config, async (_req, res) => {
18747
+ const route = Router.get(paths.config, async (_req, res) => {
18741
18748
  const body = { backend: "mesh" };
18742
18749
  if (features.includes("calls")) {
18743
18750
  body.iceServers = iceServers();
@@ -18750,9 +18757,10 @@ function registerConfig(paths, features) {
18750
18757
  if (features.includes("files")) body.files = paths.files;
18751
18758
  return res.json(body, HTTP_OK);
18752
18759
  });
18760
+ if (rtcRequireAuth()) route.secure();
18753
18761
  }
18754
18762
  function registerCalls(paths) {
18755
- Router.websocket(`${paths.signalling}/{room}`, (connection, event, data) => {
18763
+ const route = Router.websocket(`${paths.signalling}/{room}`, (connection, event, data) => {
18756
18764
  const room = connection.params.room ?? "";
18757
18765
  if (!room) return;
18758
18766
  const key = `rtc:${room}`;
@@ -18762,6 +18770,7 @@ function registerCalls(paths) {
18762
18770
  connection.broadcastToRoom(key, data, true);
18763
18771
  }
18764
18772
  });
18773
+ if (rtcRequireAuth()) route.secure();
18765
18774
  }
18766
18775
  function registerChat(paths) {
18767
18776
  Router.websocket(`${paths.chat}/{channel}`, chatHandler, { secured: true });
@@ -94,6 +94,33 @@ export function cspNonce(): string {
94
94
  * `'self'`) so the framework's own nonce'd content always works; when present
95
95
  * the nonce is appended (idempotently). Every other directive is kept, in order.
96
96
  */
97
+ /**
98
+ * Add the nonce to one directive, deriving an absent one from default-src.
99
+ *
100
+ * ADR-0100: a directive whose resolved value - present, or the default-src it
101
+ * falls back to - already carries 'unsafe-inline' is the app's explicit opt-in
102
+ * to inline. A browser ignores 'unsafe-inline' the moment a nonce joins the same
103
+ * directive (CSP Level 2+), so a nonce here would silently block the inline the
104
+ * app asked for; leave it, the app's choice wins. Otherwise the nonce is added
105
+ * idempotently, and an absent directive is spawned from default-src so the
106
+ * framework's own inline runs.
107
+ */
108
+ function applyNonceToDirective(
109
+ directives: Array<[string, string]>,
110
+ directive: string,
111
+ defaultValue: string,
112
+ token: string,
113
+ ): void {
114
+ const existing = directives.find(([name]) => name === directive);
115
+ const resolved = (existing ? existing[1] : defaultValue).split(/\s+/);
116
+ if (resolved.includes("'unsafe-inline'")) return;
117
+ if (!existing) {
118
+ directives.push([directive, `${defaultValue} ${token}`.trim()]);
119
+ } else if (!resolved.includes(token)) {
120
+ existing[1] = `${existing[1]} ${token}`.trim();
121
+ }
122
+ }
123
+
97
124
  export function injectNonceIntoCsp(csp: string, nonce: string): string {
98
125
  const token = `'nonce-${nonce}'`;
99
126
  const directives: Array<[string, string]> = [];
@@ -110,14 +137,7 @@ export function injectNonceIntoCsp(csp: string, nonce: string): string {
110
137
  const defaultValue = defaultEntry && defaultEntry[1] ? defaultEntry[1] : "'self'";
111
138
 
112
139
  for (const directive of ["style-src", "script-src"]) {
113
- const existing = directives.find(([name]) => name === directive);
114
- if (existing) {
115
- if (!existing[1].split(/\s+/).includes(token)) {
116
- existing[1] = `${existing[1]} ${token}`.trim();
117
- }
118
- } else {
119
- directives.push([directive, `${defaultValue} ${token}`.trim()]);
120
- }
140
+ applyNonceToDirective(directives, directive, defaultValue, token);
121
141
  }
122
142
 
123
143
  return directives
@@ -5495,6 +5495,16 @@ function currentCspNonce() {
5495
5495
  function cspNonce() {
5496
5496
  return currentCspNonce();
5497
5497
  }
5498
+ function applyNonceToDirective(directives, directive, defaultValue, token) {
5499
+ const existing = directives.find(([name]) => name === directive);
5500
+ const resolved = (existing ? existing[1] : defaultValue).split(/\s+/);
5501
+ if (resolved.includes("'unsafe-inline'")) return;
5502
+ if (!existing) {
5503
+ directives.push([directive, `${defaultValue} ${token}`.trim()]);
5504
+ } else if (!resolved.includes(token)) {
5505
+ existing[1] = `${existing[1]} ${token}`.trim();
5506
+ }
5507
+ }
5498
5508
  function injectNonceIntoCsp(csp, nonce) {
5499
5509
  const token = `'nonce-${nonce}'`;
5500
5510
  const directives = [];
@@ -5509,14 +5519,7 @@ function injectNonceIntoCsp(csp, nonce) {
5509
5519
  const defaultEntry = directives.find(([name]) => name === "default-src");
5510
5520
  const defaultValue = defaultEntry && defaultEntry[1] ? defaultEntry[1] : "'self'";
5511
5521
  for (const directive of ["style-src", "script-src"]) {
5512
- const existing = directives.find(([name]) => name === directive);
5513
- if (existing) {
5514
- if (!existing[1].split(/\s+/).includes(token)) {
5515
- existing[1] = `${existing[1]} ${token}`.trim();
5516
- }
5517
- } else {
5518
- directives.push([directive, `${defaultValue} ${token}`.trim()]);
5519
- }
5522
+ applyNonceToDirective(directives, directive, defaultValue, token);
5520
5523
  }
5521
5524
  return directives.map(([name, value]) => value ? `${name} ${value}` : name).join("; ");
5522
5525
  }
@@ -50694,8 +50697,12 @@ async function realtime(options = {}) {
50694
50697
  if (features.includes("files")) registerFiles(paths, options.storage);
50695
50698
  return paths;
50696
50699
  }
50700
+ function rtcRequireAuth() {
50701
+ const raw = (process.env.TINA4_RTC_REQUIRE_AUTH ?? "true").trim().toLowerCase();
50702
+ return !["false", "0", "no", "off"].includes(raw);
50703
+ }
50697
50704
  function registerConfig(paths, features) {
50698
- Router.get(paths.config, async (_req, res) => {
50705
+ const route = Router.get(paths.config, async (_req, res) => {
50699
50706
  const body = { backend: "mesh" };
50700
50707
  if (features.includes("calls")) {
50701
50708
  body.iceServers = iceServers();
@@ -50708,9 +50715,10 @@ function registerConfig(paths, features) {
50708
50715
  if (features.includes("files")) body.files = paths.files;
50709
50716
  return res.json(body, HTTP_OK);
50710
50717
  });
50718
+ if (rtcRequireAuth()) route.secure();
50711
50719
  }
50712
50720
  function registerCalls(paths) {
50713
- Router.websocket(`${paths.signalling}/{room}`, (connection, event, data) => {
50721
+ const route = Router.websocket(`${paths.signalling}/{room}`, (connection, event, data) => {
50714
50722
  const room = connection.params.room ?? "";
50715
50723
  if (!room) return;
50716
50724
  const key = `rtc:${room}`;
@@ -50720,6 +50728,7 @@ function registerCalls(paths) {
50720
50728
  connection.broadcastToRoom(key, data, true);
50721
50729
  }
50722
50730
  });
50731
+ if (rtcRequireAuth()) route.secure();
50723
50732
  }
50724
50733
  function registerChat(paths) {
50725
50734
  Router.websocket(`${paths.chat}/{channel}`, chatHandler, { secured: true });
@@ -121,8 +121,19 @@ export async function realtime(options: RealtimeOptions = {}): Promise<Record<st
121
121
 
122
122
  // ── route registration ──────────────────────────────────────────────
123
123
 
124
+ /**
125
+ * ADR-0101: the config route mints TURN credentials and the signalling socket
126
+ * relays calls, so both require a valid token UNLESS the app opts out with
127
+ * TINA4_RTC_REQUIRE_AUTH=false (anonymous calling). Secure-by-default: only an
128
+ * explicit false/0/no/off opens them.
129
+ */
130
+ function rtcRequireAuth(): boolean {
131
+ const raw = (process.env.TINA4_RTC_REQUIRE_AUTH ?? "true").trim().toLowerCase();
132
+ return !["false", "0", "no", "off"].includes(raw);
133
+ }
134
+
124
135
  function registerConfig(paths: Record<string, string>, features: string[]): void {
125
- Router.get(paths.config, async (_req: Tina4Request, res: Tina4Response) => {
136
+ const route = Router.get(paths.config, async (_req: Tina4Request, res: Tina4Response) => {
126
137
  const body: Record<string, unknown> = { backend: "mesh" };
127
138
  if (features.includes("calls")) {
128
139
  body.iceServers = iceServers();
@@ -135,12 +146,14 @@ function registerConfig(paths: Record<string, string>, features: string[]): void
135
146
  if (features.includes("files")) body.files = paths.files;
136
147
  return res.json(body, HTTP_OK);
137
148
  });
149
+ if (rtcRequireAuth()) route.secure(); // ADR-0101
138
150
  }
139
151
 
140
152
  function registerCalls(paths: Record<string, string>): void {
141
- // WebRTC signalling relay (mesh). Public room; Tina4 never parses the SDP,
142
- // peers filter by `to`. The room id comes from the {room} path param.
143
- Router.websocket(`${paths.signalling}/{room}`, (connection, event, data) => {
153
+ // WebRTC signalling relay (mesh). Tina4 never parses the SDP, peers filter by
154
+ // `to`; the media is E2E between peers. The room requires auth by default
155
+ // (ADR-0101) unless TINA4_RTC_REQUIRE_AUTH=false.
156
+ const route = Router.websocket(`${paths.signalling}/{room}`, (connection, event, data) => {
144
157
  const room = connection.params.room ?? "";
145
158
  if (!room) return;
146
159
  const key = `rtc:${room}`;
@@ -150,6 +163,7 @@ function registerCalls(paths: Record<string, string>): void {
150
163
  connection.broadcastToRoom(key, data, true);
151
164
  }
152
165
  });
166
+ if (rtcRequireAuth()) route.secure(); // ADR-0101
153
167
  }
154
168
 
155
169
  function registerChat(paths: Record<string, string>): void {
@@ -22,15 +22,6 @@ export declare function currentCspNonce(): string;
22
22
  * <script nonce="{{ csp_nonce() }}"> ... </script>
23
23
  */
24
24
  export declare function cspNonce(): string;
25
- /**
26
- * Return `csp` with `'nonce-<nonce>'` present in style-src AND script-src.
27
- *
28
- * For the default `default-src 'self'` this yields
29
- * `default-src 'self'; style-src 'self' 'nonce-X'; script-src 'self' 'nonce-X'`.
30
- * When a directive is absent it is derived from `default-src` (falling back to
31
- * `'self'`) so the framework's own nonce'd content always works; when present
32
- * the nonce is appended (idempotently). Every other directive is kept, in order.
33
- */
34
25
  export declare function injectNonceIntoCsp(csp: string, nonce: string): string;
35
26
  /**
36
27
  * Build the CSP header value for `nonce` from the environment.