tina4-nodejs 3.13.154 → 3.13.156

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
@@ -14,13 +14,13 @@ Even if the skill text is not currently loaded, these are non-negotiable:
14
14
 
15
15
  The full discipline lives in `.claude/skills/tina4-maintainer/SKILL.md`; this block is the always-on floor.
16
16
 
17
- # CLAUDE.md - AI Developer Guide for tina4-nodejs (v3.13.154)
17
+ # CLAUDE.md - AI Developer Guide for tina4-nodejs (v3.13.156)
18
18
 
19
19
  > This file helps AI assistants (Claude, Copilot, Cursor, etc.) understand and work on this codebase effectively.
20
20
 
21
21
  ## What This Project Is
22
22
 
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
+ Tina4 for Node.js/TypeScript v3.13.156 - The Intelligent Native Application 4ramework. A convention-over-configuration structural paradigm. The developer writes TypeScript; Tina4 is invisible infrastructure.
24
24
 
25
25
  The philosophy: zero ceremony, batteries included, file system as source of truth.
26
26
 
@@ -1042,7 +1042,10 @@ import { Queue } from "@tina4/core";
1042
1042
 
1043
1043
  const queue = new Queue("emails", 3 /* maxRetries */);
1044
1044
 
1045
- const id = queue.push({ to: "a@b.c", body: "hi" }, 0 /* delaySec */, 0 /* priority */);
1045
+ const id = queue.push({ to: "a@b.c", body: "hi" }, 0 /* delaySec */, 0 /* priority */, false /* raw */);
1046
+ // raw=true is Kafka-only: produce the value with NO envelope and no injected id, for a non-Tina4
1047
+ // consumer. file/rabbitmq/mongodb refuse raw=true by name. TINA4_KAFKA_AUTO_OFFSET_RESET
1048
+ // (earliest default, or latest) sets where a NEW consumer group starts.
1046
1049
  const job = queue.pop();
1047
1050
  queue.size("pending");
1048
1051
  queue.purge("completed");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tina4-nodejs",
3
- "version": "3.13.154",
3
+ "version": "3.13.156",
4
4
  "type": "module",
5
5
  "description": "Tina4 for Node.js/TypeScript - native TypeScript conventions and shared Tina4 contracts",
6
6
  "keywords": [
@@ -20823,6 +20823,16 @@ var init_router = __esm({
20823
20823
  this.route.noAuth = true;
20824
20824
  return this;
20825
20825
  }
20826
+ /**
20827
+ * Opt a route OUT of CSRF form-token validation (webhooks / server-to-server
20828
+ * callbacks that carry no browser session). `.noAuth()` no longer skips CSRF
20829
+ * (#265): a public form stays CSRF-protected. CSRF (origin) and auth
20830
+ * (identity) are orthogonal — chain `.noAuth().noCsrf()` for a public webhook.
20831
+ */
20832
+ noCsrf() {
20833
+ this.route.noCsrf = true;
20834
+ return this;
20835
+ }
20826
20836
  /**
20827
20837
  * RBAC: require ONE of the named roles (OR). Reads the verified JWT `roles`
20828
20838
  * claim. Chain .role()/.can() for AND. Implies auth. Feature 138 / ADR-0058.
@@ -20915,6 +20925,7 @@ var init_router = __esm({
20915
20925
  secure: secureDefault,
20916
20926
  cached: definition.cached,
20917
20927
  noAuth: definition.noAuth,
20928
+ noCsrf: definition.noCsrf,
20918
20929
  template: definition.template,
20919
20930
  requiredRoles: definition.requiredRoles,
20920
20931
  requiredPerms: definition.requiredPerms
@@ -21065,6 +21076,7 @@ var init_router = __esm({
21065
21076
  secure: route.secure,
21066
21077
  cached: route.cached,
21067
21078
  noAuth: route.noAuth,
21079
+ noCsrf: route.noCsrf,
21068
21080
  requiredRoles: route.requiredRoles,
21069
21081
  requiredPerms: route.requiredPerms
21070
21082
  };
@@ -22177,7 +22189,7 @@ function csrfMethodIsSafe(method) {
22177
22189
  }
22178
22190
  function csrfRouteSkips(req2) {
22179
22191
  const route = req2._route ?? req2.route;
22180
- return Boolean(route?.noAuth);
22192
+ return Boolean(route?.noCsrf);
22181
22193
  }
22182
22194
  function csrfBearerIsValid(req2, secret) {
22183
22195
  const authHeader = req2.headers.authorization ?? "";
@@ -23561,6 +23573,9 @@ __export(routeDiscovery_exports, {
23561
23573
  });
23562
23574
  import { readdirSync as readdirSync5, statSync as statSync7, mkdirSync as mkdirSync9, writeFileSync as writeFileSync6, existsSync as existsSync10 } from "node:fs";
23563
23575
  import { join as join13, relative, basename as basename3, extname as extname2 } from "node:path";
23576
+ function boolExport(value) {
23577
+ return typeof value === "boolean" ? value : void 0;
23578
+ }
23564
23579
  async function discoverRoutes(routesDir) {
23565
23580
  _lastRoutesDir = routesDir;
23566
23581
  const definitions = [];
@@ -23588,9 +23603,10 @@ async function discoverRoutes(routesDir) {
23588
23603
  }
23589
23604
  const meta = mod.meta;
23590
23605
  const template = typeof mod.template === "string" ? mod.template : void 0;
23591
- const secure = typeof mod.secure === "boolean" ? mod.secure : void 0;
23592
- const noAuth = typeof mod.noAuth === "boolean" ? mod.noAuth : void 0;
23593
- definitions.push({ method, pattern, handler, filePath, meta, template, secure, noAuth });
23606
+ const secure = boolExport(mod.secure);
23607
+ const noAuth = boolExport(mod.noAuth);
23608
+ const noCsrf = boolExport(mod.noCsrf);
23609
+ definitions.push({ method, pattern, handler, filePath, meta, template, secure, noAuth, noCsrf });
23594
23610
  _seenFiles.add(filePath);
23595
23611
  _seenMtimes.set(filePath, currentMtime);
23596
23612
  registeredFromThisScan++;
@@ -34444,7 +34460,12 @@ var init_mongoBackend = __esm({
34444
34460
  return null;
34445
34461
  }
34446
34462
  }
34447
- push(queue, payload, delay2, priority) {
34463
+ push(queue, payload, delay2, priority, raw = false) {
34464
+ if (raw) {
34465
+ throw new Error(
34466
+ "The mongodb queue backend cannot honour push(raw=true): raw emits the message with no Tina4 envelope, which only a message bus consumed by non-Tina4 systems (Kafka) needs. This backend stores an internal envelope (payload/priority/attempts) that pop(), the retry lifecycle and dead-lettering depend on, so there is nothing to omit. Use the kafka backend for raw external messages."
34467
+ );
34468
+ }
34448
34469
  const id = randomUUID5();
34449
34470
  const now = (/* @__PURE__ */ new Date()).toISOString();
34450
34471
  const job = {
@@ -34684,7 +34705,12 @@ var init_liteBackend = __esm({
34684
34705
  */
34685
34706
  close() {
34686
34707
  }
34687
- push(queue, payload, delay2, priority) {
34708
+ push(queue, payload, delay2, priority, raw = false) {
34709
+ if (raw) {
34710
+ throw new Error(
34711
+ "The file queue backend cannot honour push(raw=true): raw emits the message with no Tina4 envelope, which only a message bus consumed by non-Tina4 systems (Kafka) needs. This backend stores an internal envelope (id/status/attempts/delayUntil) that pop(), the retry lifecycle and dead-lettering depend on, so there is nothing to omit. Use the kafka backend for raw external messages."
34712
+ );
34713
+ }
34688
34714
  const dir = this.ensureDir(queue);
34689
34715
  const id = randomUUID6();
34690
34716
  const now = (/* @__PURE__ */ new Date()).toISOString();
@@ -35330,12 +35356,16 @@ var init_queue = __esm({
35330
35356
  * queue.push(payload, delay, priority) — with delay and priority
35331
35357
  *
35332
35358
  * @param priority — Higher value = higher priority. Default 0.
35359
+ * @param raw — Kafka-only (tina4-nodejs#264): produce the value with NO Tina4
35360
+ * envelope and no injected id, for a non-Tina4 consumer. The file/rabbitmq/
35361
+ * mongodb backends refuse raw=true by name (the envelope is internal
35362
+ * bookkeeping pop/retries/dead-lettering depend on). Default false.
35333
35363
  */
35334
- push(payload, delay2, priority = 0) {
35364
+ push(payload, delay2, priority = 0, raw = false) {
35335
35365
  if (this.externalBackend) {
35336
- return this.externalBackend.push(this.topic, payload, delay2, priority);
35366
+ return this.externalBackend.push(this.topic, payload, delay2, priority, raw);
35337
35367
  }
35338
- return this.liteBackend.push(this.topic, payload, delay2, priority);
35368
+ return this.liteBackend.push(this.topic, payload, delay2, priority, raw);
35339
35369
  }
35340
35370
  /**
35341
35371
  * Atomically claim the next available job from this queue's topic. Returns null if empty.
@@ -35566,11 +35596,11 @@ var init_queue = __esm({
35566
35596
  * shares the same retarget path consume()/process() use — keeping produce and
35567
35597
  * consume symmetric on the same topic argument.
35568
35598
  */
35569
- produce(topic, payload, priority = 0, delay2 = 0) {
35599
+ produce(topic, payload, priority = 0, delay2 = 0, raw = false) {
35570
35600
  const previous = this.topic;
35571
35601
  this.retarget(topic);
35572
35602
  try {
35573
- return this.push(payload, delay2, priority);
35603
+ return this.push(payload, delay2, priority, raw);
35574
35604
  } finally {
35575
35605
  this.retarget(previous);
35576
35606
  }
@@ -49561,7 +49591,12 @@ var init_rabbitmqBackend = __esm({
49561
49591
  return "";
49562
49592
  }
49563
49593
  }
49564
- push(queue, payload, _delay) {
49594
+ push(queue, payload, _delay, _priority, raw = false) {
49595
+ if (raw) {
49596
+ throw new Error(
49597
+ "The rabbitmq queue backend cannot honour push(raw=true): raw emits the message with no Tina4 envelope, which only a message bus consumed by non-Tina4 systems (Kafka) needs. This backend stores an internal envelope (payload/priority/attempts) that pop(), the retry lifecycle and dead-lettering depend on, so there is nothing to omit. Use the kafka backend for raw external messages."
49598
+ );
49599
+ }
49565
49600
  const id = randomUUID8();
49566
49601
  const now = (/* @__PURE__ */ new Date()).toISOString();
49567
49602
  const job = {
@@ -49626,6 +49661,9 @@ function kafkaSecurityConfig(env = process.env) {
49626
49661
  }
49627
49662
  return config;
49628
49663
  }
49664
+ function kafkaOffsetReset(env = process.env) {
49665
+ return env.TINA4_KAFKA_AUTO_OFFSET_RESET || env.KAFKA_AUTO_OFFSET_RESET || "earliest";
49666
+ }
49629
49667
  var API_PRODUCE, API_FETCH, KafkaBackend;
49630
49668
  var init_kafkaBackend = __esm({
49631
49669
  "../core/src/queueBackends/kafkaBackend.ts"() {
@@ -49675,7 +49713,7 @@ var init_kafkaBackend = __esm({
49675
49713
  "bootstrap.servers": this.brokers,
49676
49714
  "client.id": "tina4-nodejs",
49677
49715
  "group.id": this.groupId,
49678
- "auto.offset.reset": "earliest",
49716
+ "auto.offset.reset": kafkaOffsetReset(),
49679
49717
  "enable.auto.commit": false,
49680
49718
  ...this.securityConfig()
49681
49719
  };
@@ -50121,18 +50159,26 @@ var init_kafkaBackend = __esm({
50121
50159
  );
50122
50160
  }
50123
50161
  }
50124
- push(queue, payload, _delay) {
50125
- const id = randomUUID9();
50126
- const now = (/* @__PURE__ */ new Date()).toISOString();
50127
- const job = {
50162
+ /**
50163
+ * Serialize the record value. raw (tina4-nodejs#264) emits the payload exactly
50164
+ * as given — no {id, payload, status, attempts, ...} envelope — so a non-Tina4
50165
+ * consumer reading the topic gets the schema it expects; otherwise the Tina4 job
50166
+ * envelope. pop() unwraps both shapes (payload ?? the whole record).
50167
+ */
50168
+ static encodeJob(id, payload, raw) {
50169
+ if (raw) return JSON.stringify(payload);
50170
+ return JSON.stringify({
50128
50171
  id,
50129
50172
  payload,
50130
50173
  status: "pending",
50131
- createdAt: now,
50174
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
50132
50175
  attempts: 0,
50133
50176
  delayUntil: null
50134
- };
50135
- const body = JSON.stringify(job);
50177
+ });
50178
+ }
50179
+ push(queue, payload, _delay, _priority, raw = false) {
50180
+ const id = randomUUID9();
50181
+ const body = _KafkaBackend.encodeJob(id, payload, raw);
50136
50182
  let result = "";
50137
50183
  for (let attempt = 1; attempt <= 10; attempt++) {
50138
50184
  result = this.execSync("publish", queue, body);
@@ -51069,6 +51115,7 @@ __export(src_exports3, {
51069
51115
  isTrustedProxy: () => isTrustedProxy,
51070
51116
  isTruthy: () => isTruthy,
51071
51117
  isValidSessionId: () => isValidSessionId,
51118
+ kafkaOffsetReset: () => kafkaOffsetReset,
51072
51119
  kafkaSecurityConfig: () => kafkaSecurityConfig,
51073
51120
  loadEnv: () => loadEnv,
51074
51121
  loopbackBindHosts: () => loopbackBindHosts,
@@ -20822,6 +20822,16 @@ var init_router = __esm({
20822
20822
  this.route.noAuth = true;
20823
20823
  return this;
20824
20824
  }
20825
+ /**
20826
+ * Opt a route OUT of CSRF form-token validation (webhooks / server-to-server
20827
+ * callbacks that carry no browser session). `.noAuth()` no longer skips CSRF
20828
+ * (#265): a public form stays CSRF-protected. CSRF (origin) and auth
20829
+ * (identity) are orthogonal — chain `.noAuth().noCsrf()` for a public webhook.
20830
+ */
20831
+ noCsrf() {
20832
+ this.route.noCsrf = true;
20833
+ return this;
20834
+ }
20825
20835
  /**
20826
20836
  * RBAC: require ONE of the named roles (OR). Reads the verified JWT `roles`
20827
20837
  * claim. Chain .role()/.can() for AND. Implies auth. Feature 138 / ADR-0058.
@@ -20914,6 +20924,7 @@ var init_router = __esm({
20914
20924
  secure: secureDefault,
20915
20925
  cached: definition.cached,
20916
20926
  noAuth: definition.noAuth,
20927
+ noCsrf: definition.noCsrf,
20917
20928
  template: definition.template,
20918
20929
  requiredRoles: definition.requiredRoles,
20919
20930
  requiredPerms: definition.requiredPerms
@@ -21064,6 +21075,7 @@ var init_router = __esm({
21064
21075
  secure: route.secure,
21065
21076
  cached: route.cached,
21066
21077
  noAuth: route.noAuth,
21078
+ noCsrf: route.noCsrf,
21067
21079
  requiredRoles: route.requiredRoles,
21068
21080
  requiredPerms: route.requiredPerms
21069
21081
  };
@@ -22176,7 +22188,7 @@ function csrfMethodIsSafe(method) {
22176
22188
  }
22177
22189
  function csrfRouteSkips(req2) {
22178
22190
  const route = req2._route ?? req2.route;
22179
- return Boolean(route?.noAuth);
22191
+ return Boolean(route?.noCsrf);
22180
22192
  }
22181
22193
  function csrfBearerIsValid(req2, secret) {
22182
22194
  const authHeader = req2.headers.authorization ?? "";
@@ -23560,6 +23572,9 @@ __export(routeDiscovery_exports, {
23560
23572
  });
23561
23573
  import { readdirSync as readdirSync5, statSync as statSync7, mkdirSync as mkdirSync8, writeFileSync as writeFileSync5, existsSync as existsSync9 } from "node:fs";
23562
23574
  import { join as join12, relative, basename as basename2, extname as extname2 } from "node:path";
23575
+ function boolExport(value) {
23576
+ return typeof value === "boolean" ? value : void 0;
23577
+ }
23563
23578
  async function discoverRoutes(routesDir) {
23564
23579
  _lastRoutesDir = routesDir;
23565
23580
  const definitions = [];
@@ -23587,9 +23602,10 @@ async function discoverRoutes(routesDir) {
23587
23602
  }
23588
23603
  const meta = mod.meta;
23589
23604
  const template = typeof mod.template === "string" ? mod.template : void 0;
23590
- const secure = typeof mod.secure === "boolean" ? mod.secure : void 0;
23591
- const noAuth = typeof mod.noAuth === "boolean" ? mod.noAuth : void 0;
23592
- definitions.push({ method, pattern, handler, filePath, meta, template, secure, noAuth });
23605
+ const secure = boolExport(mod.secure);
23606
+ const noAuth = boolExport(mod.noAuth);
23607
+ const noCsrf = boolExport(mod.noCsrf);
23608
+ definitions.push({ method, pattern, handler, filePath, meta, template, secure, noAuth, noCsrf });
23593
23609
  _seenFiles.add(filePath);
23594
23610
  _seenMtimes.set(filePath, currentMtime);
23595
23611
  registeredFromThisScan++;
@@ -34400,7 +34416,12 @@ var init_mongoBackend = __esm({
34400
34416
  return null;
34401
34417
  }
34402
34418
  }
34403
- push(queue, payload, delay2, priority) {
34419
+ push(queue, payload, delay2, priority, raw = false) {
34420
+ if (raw) {
34421
+ throw new Error(
34422
+ "The mongodb queue backend cannot honour push(raw=true): raw emits the message with no Tina4 envelope, which only a message bus consumed by non-Tina4 systems (Kafka) needs. This backend stores an internal envelope (payload/priority/attempts) that pop(), the retry lifecycle and dead-lettering depend on, so there is nothing to omit. Use the kafka backend for raw external messages."
34423
+ );
34424
+ }
34404
34425
  const id = randomUUID5();
34405
34426
  const now = (/* @__PURE__ */ new Date()).toISOString();
34406
34427
  const job = {
@@ -34640,7 +34661,12 @@ var init_liteBackend = __esm({
34640
34661
  */
34641
34662
  close() {
34642
34663
  }
34643
- push(queue, payload, delay2, priority) {
34664
+ push(queue, payload, delay2, priority, raw = false) {
34665
+ if (raw) {
34666
+ throw new Error(
34667
+ "The file queue backend cannot honour push(raw=true): raw emits the message with no Tina4 envelope, which only a message bus consumed by non-Tina4 systems (Kafka) needs. This backend stores an internal envelope (id/status/attempts/delayUntil) that pop(), the retry lifecycle and dead-lettering depend on, so there is nothing to omit. Use the kafka backend for raw external messages."
34668
+ );
34669
+ }
34644
34670
  const dir = this.ensureDir(queue);
34645
34671
  const id = randomUUID6();
34646
34672
  const now = (/* @__PURE__ */ new Date()).toISOString();
@@ -35286,12 +35312,16 @@ var init_queue = __esm({
35286
35312
  * queue.push(payload, delay, priority) — with delay and priority
35287
35313
  *
35288
35314
  * @param priority — Higher value = higher priority. Default 0.
35315
+ * @param raw — Kafka-only (tina4-nodejs#264): produce the value with NO Tina4
35316
+ * envelope and no injected id, for a non-Tina4 consumer. The file/rabbitmq/
35317
+ * mongodb backends refuse raw=true by name (the envelope is internal
35318
+ * bookkeeping pop/retries/dead-lettering depend on). Default false.
35289
35319
  */
35290
- push(payload, delay2, priority = 0) {
35320
+ push(payload, delay2, priority = 0, raw = false) {
35291
35321
  if (this.externalBackend) {
35292
- return this.externalBackend.push(this.topic, payload, delay2, priority);
35322
+ return this.externalBackend.push(this.topic, payload, delay2, priority, raw);
35293
35323
  }
35294
- return this.liteBackend.push(this.topic, payload, delay2, priority);
35324
+ return this.liteBackend.push(this.topic, payload, delay2, priority, raw);
35295
35325
  }
35296
35326
  /**
35297
35327
  * Atomically claim the next available job from this queue's topic. Returns null if empty.
@@ -35522,11 +35552,11 @@ var init_queue = __esm({
35522
35552
  * shares the same retarget path consume()/process() use — keeping produce and
35523
35553
  * consume symmetric on the same topic argument.
35524
35554
  */
35525
- produce(topic, payload, priority = 0, delay2 = 0) {
35555
+ produce(topic, payload, priority = 0, delay2 = 0, raw = false) {
35526
35556
  const previous = this.topic;
35527
35557
  this.retarget(topic);
35528
35558
  try {
35529
- return this.push(payload, delay2, priority);
35559
+ return this.push(payload, delay2, priority, raw);
35530
35560
  } finally {
35531
35561
  this.retarget(previous);
35532
35562
  }
@@ -49499,7 +49529,12 @@ var init_rabbitmqBackend = __esm({
49499
49529
  return "";
49500
49530
  }
49501
49531
  }
49502
- push(queue, payload, _delay) {
49532
+ push(queue, payload, _delay, _priority, raw = false) {
49533
+ if (raw) {
49534
+ throw new Error(
49535
+ "The rabbitmq queue backend cannot honour push(raw=true): raw emits the message with no Tina4 envelope, which only a message bus consumed by non-Tina4 systems (Kafka) needs. This backend stores an internal envelope (payload/priority/attempts) that pop(), the retry lifecycle and dead-lettering depend on, so there is nothing to omit. Use the kafka backend for raw external messages."
49536
+ );
49537
+ }
49503
49538
  const id = randomUUID8();
49504
49539
  const now = (/* @__PURE__ */ new Date()).toISOString();
49505
49540
  const job = {
@@ -49564,6 +49599,9 @@ function kafkaSecurityConfig(env = process.env) {
49564
49599
  }
49565
49600
  return config;
49566
49601
  }
49602
+ function kafkaOffsetReset(env = process.env) {
49603
+ return env.TINA4_KAFKA_AUTO_OFFSET_RESET || env.KAFKA_AUTO_OFFSET_RESET || "earliest";
49604
+ }
49567
49605
  var API_PRODUCE, API_FETCH, KafkaBackend;
49568
49606
  var init_kafkaBackend = __esm({
49569
49607
  "src/queueBackends/kafkaBackend.ts"() {
@@ -49613,7 +49651,7 @@ var init_kafkaBackend = __esm({
49613
49651
  "bootstrap.servers": this.brokers,
49614
49652
  "client.id": "tina4-nodejs",
49615
49653
  "group.id": this.groupId,
49616
- "auto.offset.reset": "earliest",
49654
+ "auto.offset.reset": kafkaOffsetReset(),
49617
49655
  "enable.auto.commit": false,
49618
49656
  ...this.securityConfig()
49619
49657
  };
@@ -50059,18 +50097,26 @@ var init_kafkaBackend = __esm({
50059
50097
  );
50060
50098
  }
50061
50099
  }
50062
- push(queue, payload, _delay) {
50063
- const id = randomUUID9();
50064
- const now = (/* @__PURE__ */ new Date()).toISOString();
50065
- const job = {
50100
+ /**
50101
+ * Serialize the record value. raw (tina4-nodejs#264) emits the payload exactly
50102
+ * as given — no {id, payload, status, attempts, ...} envelope — so a non-Tina4
50103
+ * consumer reading the topic gets the schema it expects; otherwise the Tina4 job
50104
+ * envelope. pop() unwraps both shapes (payload ?? the whole record).
50105
+ */
50106
+ static encodeJob(id, payload, raw) {
50107
+ if (raw) return JSON.stringify(payload);
50108
+ return JSON.stringify({
50066
50109
  id,
50067
50110
  payload,
50068
50111
  status: "pending",
50069
- createdAt: now,
50112
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
50070
50113
  attempts: 0,
50071
50114
  delayUntil: null
50072
- };
50073
- const body = JSON.stringify(job);
50115
+ });
50116
+ }
50117
+ push(queue, payload, _delay, _priority, raw = false) {
50118
+ const id = randomUUID9();
50119
+ const body = _KafkaBackend.encodeJob(id, payload, raw);
50074
50120
  let result = "";
50075
50121
  for (let attempt = 1; attempt <= 10; attempt++) {
50076
50122
  result = this.execSync("publish", queue, body);
@@ -51007,6 +51053,7 @@ __export(index_exports, {
51007
51053
  isTrustedProxy: () => isTrustedProxy,
51008
51054
  isTruthy: () => isTruthy,
51009
51055
  isValidSessionId: () => isValidSessionId,
51056
+ kafkaOffsetReset: () => kafkaOffsetReset,
51010
51057
  kafkaSecurityConfig: () => kafkaSecurityConfig,
51011
51058
  loadEnv: () => loadEnv,
51012
51059
  loopbackBindHosts: () => loopbackBindHosts,
@@ -51398,6 +51445,7 @@ export {
51398
51445
  isTrustedProxy,
51399
51446
  isTruthy,
51400
51447
  isValidSessionId,
51448
+ kafkaOffsetReset,
51401
51449
  kafkaSecurityConfig,
51402
51450
  loadEnv,
51403
51451
  loopbackBindHosts,
@@ -140,7 +140,7 @@ export type { ImapMessage, ImapFullMessage, ImapAttachment } from "./messenger.j
140
140
  export { LiteBackend } from "./queueBackends/liteBackend.js";
141
141
  export { RabbitMQBackend, parseAmqpUrl } from "./queueBackends/rabbitmqBackend.js";
142
142
  export type { RabbitMQConfig } from "./queueBackends/rabbitmqBackend.js";
143
- export { KafkaBackend, kafkaSecurityConfig } from "./queueBackends/kafkaBackend.js";
143
+ export { KafkaBackend, kafkaSecurityConfig, kafkaOffsetReset } from "./queueBackends/kafkaBackend.js";
144
144
  export type {
145
145
  KafkaConfig,
146
146
  KafkaSecurityConfig,
@@ -1073,8 +1073,12 @@ function csrfMethodIsSafe(method: string | undefined): boolean {
1073
1073
  }
1074
1074
 
1075
1075
  function csrfRouteSkips(req: Tina4Request): boolean {
1076
+ // #265 / CSRF-DEC-03: .noAuth() no longer skips CSRF — a public form must be
1077
+ // open to anonymous visitors AND protected against cross-site posts. Only an
1078
+ // explicit .noCsrf() (webhooks / server-to-server callbacks with no browser
1079
+ // session) opts out. noAuth controls IDENTITY (who); CSRF controls ORIGIN.
1076
1080
  const route = (req as any)._route ?? (req as any).route;
1077
- return Boolean(route?.noAuth);
1081
+ return Boolean(route?.noCsrf);
1078
1082
  }
1079
1083
 
1080
1084
  function csrfBearerIsValid(req: Tina4Request, secret: string): boolean {
@@ -1108,15 +1112,18 @@ function csrfSessionMatches(req: Tina4Request, payload: Record<string, unknown>)
1108
1112
  * Class-based CSRF middleware using the before/after convention.
1109
1113
  * Validates form tokens on state-changing requests (POST, PUT, PATCH, DELETE).
1110
1114
  *
1111
- * OFF by default — a default app has NO CSRF gate because the middleware is
1112
- * NOT attached. Set TINA4_CSRF=true (or 1/yes/on) and the framework
1113
- * auto-attaches it at boot (see attachCsrfFromEnv); or register it explicitly
1114
- * via Router.use(CsrfMiddleware). Once attached, TINA4_CSRF=false (or 0/no) is
1115
- * the kill switch that disables enforcement again.
1115
+ * NOT attached by default — a default app has NO CSRF gate because the
1116
+ * middleware is NOT attached. Set TINA4_CSRF=true (or 1/yes/on) and the
1117
+ * framework auto-attaches it at boot (see attachCsrfFromEnv); or register it
1118
+ * explicitly via Router.use(CsrfMiddleware). Once attached it enforces unless
1119
+ * the kill switch TINA4_CSRF=false (or 0/no) is set — so with it attached but
1120
+ * TINA4_CSRF unset, enforcement is ON (the attach is the opt-in).
1116
1121
  *
1117
1122
  * Behaviour (identical to the Python master, feature 37):
1118
1123
  * - Skips GET, HEAD, OPTIONS requests.
1119
- * - Skips routes marked .noAuth().
1124
+ * - Skips routes that opt out with .noCsrf() (server-to-server webhooks).
1125
+ * .noAuth() does NOT skip CSRF (#265): a public form can be open to
1126
+ * anonymous visitors AND still protected against cross-site posts.
1120
1127
  * - Fails CLOSED: with TINA4_SECRET unset the signing secret resolves to
1121
1128
  * blank (there is NO built-in default), and a blank HMAC key is publicly
1122
1129
  * reproducible — so no token can be trusted and every write is rejected
@@ -125,7 +125,7 @@ export interface ConsumeOptions {
125
125
  }
126
126
 
127
127
  export interface QueueBackendInterface {
128
- push(queue: string, payload: unknown, delay?: number, priority?: number): string;
128
+ push(queue: string, payload: unknown, delay?: number, priority?: number, raw?: boolean): string;
129
129
  pop(queue: string): QueueJob | null;
130
130
  size(queue: string, status?: string): number;
131
131
  clear(queue: string): void;
@@ -303,15 +303,19 @@ export class Queue {
303
303
  * queue.push(payload, delay, priority) — with delay and priority
304
304
  *
305
305
  * @param priority — Higher value = higher priority. Default 0.
306
+ * @param raw — Kafka-only (tina4-nodejs#264): produce the value with NO Tina4
307
+ * envelope and no injected id, for a non-Tina4 consumer. The file/rabbitmq/
308
+ * mongodb backends refuse raw=true by name (the envelope is internal
309
+ * bookkeeping pop/retries/dead-lettering depend on). Default false.
306
310
  */
307
- push(payload: unknown, delay?: number, priority: number = 0): string {
311
+ push(payload: unknown, delay?: number, priority: number = 0, raw: boolean = false): string {
308
312
  if (this.externalBackend) {
309
313
  // priority goes to the external backend too. It used to be passed only to
310
314
  // liteBackend, so switching to mongodb silently turned a prioritised
311
315
  // queue into a FIFO one.
312
- return this.externalBackend.push(this.topic, payload, delay, priority);
316
+ return this.externalBackend.push(this.topic, payload, delay, priority, raw);
313
317
  }
314
- return this.liteBackend.push(this.topic, payload, delay, priority);
318
+ return this.liteBackend.push(this.topic, payload, delay, priority, raw);
315
319
  }
316
320
 
317
321
  /**
@@ -598,11 +602,11 @@ export class Queue {
598
602
  * shares the same retarget path consume()/process() use — keeping produce and
599
603
  * consume symmetric on the same topic argument.
600
604
  */
601
- produce(topic: string, payload: unknown, priority: number = 0, delay: number = 0): string {
605
+ produce(topic: string, payload: unknown, priority: number = 0, delay: number = 0, raw: boolean = false): string {
602
606
  const previous = this.topic;
603
607
  this.retarget(topic);
604
608
  try {
605
- return this.push(payload, delay, priority);
609
+ return this.push(payload, delay, priority, raw);
606
610
  } finally {
607
611
  this.retarget(previous);
608
612
  }
@@ -99,8 +99,26 @@ export function kafkaSecurityConfig(
99
99
  return config;
100
100
  }
101
101
 
102
+ /**
103
+ * Resolve the consumer's auto.offset.reset policy from the environment.
104
+ *
105
+ * Where a NEW consumer group (one with no committed offset) starts reading:
106
+ * "earliest" (the default, unchanged) replays the retained backlog; "latest"
107
+ * skips it. Read from the Tina4-namespaced env var FIRST
108
+ * (`TINA4_KAFKA_AUTO_OFFSET_RESET`) and fall back to the bare librdkafka-
109
+ * convention name (`KAFKA_AUTO_OFFSET_RESET`) — the same precedence the TLS/SASL
110
+ * keys use. A blank value falls through to the default (tina4-nodejs#263).
111
+ *
112
+ * Surfaced on the declared consumer config for parity/introspection; this
113
+ * backend reads records over the raw protocol from the earliest retained offset.
114
+ * Mirrors Python's `KafkaConnector._offset_reset`.
115
+ */
116
+ export function kafkaOffsetReset(env: NodeJS.ProcessEnv = process.env): string {
117
+ return env.TINA4_KAFKA_AUTO_OFFSET_RESET || env.KAFKA_AUTO_OFFSET_RESET || "earliest";
118
+ }
119
+
102
120
  export interface QueueBackend {
103
- push(queue: string, payload: unknown, delay?: number, priority?: number): string;
121
+ push(queue: string, payload: unknown, delay?: number, priority?: number, raw?: boolean): string;
104
122
  pop(queue: string): QueueJob | null;
105
123
  size(queue: string): number;
106
124
  clear(queue: string): void;
@@ -182,7 +200,7 @@ export class KafkaBackend implements QueueBackend {
182
200
  "bootstrap.servers": this.brokers,
183
201
  "client.id": "tina4-nodejs",
184
202
  "group.id": this.groupId,
185
- "auto.offset.reset": "earliest",
203
+ "auto.offset.reset": kafkaOffsetReset(),
186
204
  "enable.auto.commit": false,
187
205
  ...this.securityConfig(),
188
206
  };
@@ -646,25 +664,33 @@ export class KafkaBackend implements QueueBackend {
646
664
  }
647
665
  }
648
666
 
649
- push(queue: string, payload: unknown, _delay?: number): string {
650
- const id = randomUUID();
651
- const now = new Date().toISOString();
652
-
653
- const job = {
667
+ /**
668
+ * Serialize the record value. raw (tina4-nodejs#264) emits the payload exactly
669
+ * as given — no {id, payload, status, attempts, ...} envelope — so a non-Tina4
670
+ * consumer reading the topic gets the schema it expects; otherwise the Tina4 job
671
+ * envelope. pop() unwraps both shapes (payload ?? the whole record).
672
+ */
673
+ private static encodeJob(id: string, payload: unknown, raw: boolean): string {
674
+ if (raw) return JSON.stringify(payload);
675
+ return JSON.stringify({
654
676
  id,
655
677
  payload,
656
678
  status: "pending",
657
- createdAt: now,
679
+ createdAt: new Date().toISOString(),
658
680
  attempts: 0,
659
681
  delayUntil: null,
660
- };
682
+ });
683
+ }
684
+
685
+ push(queue: string, payload: unknown, _delay?: number, _priority?: number, raw: boolean = false): string {
686
+ const id = randomUUID();
661
687
 
662
688
  // Topic auto-creation is ASYNCHRONOUS, so a brand-new topic answers
663
689
  // UNKNOWN_TOPIC_OR_PARTITION (3) or LEADER_NOT_AVAILABLE (5) on the first
664
690
  // attempt while the controller is still electing a leader. Retry those
665
691
  // (same 10 attempts / 200ms as the Python and PHP backends) instead of
666
692
  // failing a cold-start push; every other code throws immediately.
667
- const body = JSON.stringify(job);
693
+ const body = KafkaBackend.encodeJob(id, payload, raw);
668
694
  let result = "";
669
695
  for (let attempt = 1; attempt <= 10; attempt++) {
670
696
  result = this.execSync("publish", queue, body);
@@ -95,7 +95,17 @@ export class LiteBackend {
95
95
  // descriptor synchronously, so no handle survives a call.
96
96
  }
97
97
 
98
- push(queue: string, payload: unknown, delay?: number, priority?: number): string {
98
+ push(queue: string, payload: unknown, delay?: number, priority?: number, raw: boolean = false): string {
99
+ if (raw) {
100
+ throw new Error(
101
+ "The file queue backend cannot honour push(raw=true): raw emits the " +
102
+ "message with no Tina4 envelope, which only a message bus consumed by " +
103
+ "non-Tina4 systems (Kafka) needs. This backend stores an internal " +
104
+ "envelope (id/status/attempts/delayUntil) that pop(), the retry " +
105
+ "lifecycle and dead-lettering depend on, so there is nothing to omit. " +
106
+ "Use the kafka backend for raw external messages.",
107
+ );
108
+ }
99
109
  const dir = this.ensureDir(queue);
100
110
  const id = randomUUID();
101
111
  const now = new Date().toISOString();
@@ -54,7 +54,7 @@ export interface MongoConfig {
54
54
  }
55
55
 
56
56
  export interface QueueBackend {
57
- push(queue: string, payload: unknown, delay?: number, priority?: number): string;
57
+ push(queue: string, payload: unknown, delay?: number, priority?: number, raw?: boolean): string;
58
58
  pop(queue: string): QueueJob | null;
59
59
  size(queue: string): number;
60
60
  clear(queue: string): void;
@@ -542,7 +542,17 @@ export class MongoBackend implements QueueBackend {
542
542
  }
543
543
  }
544
544
 
545
- push(queue: string, payload: unknown, delay?: number, priority?: number): string {
545
+ push(queue: string, payload: unknown, delay?: number, priority?: number, raw: boolean = false): string {
546
+ if (raw) {
547
+ throw new Error(
548
+ "The mongodb queue backend cannot honour push(raw=true): raw emits the " +
549
+ "message with no Tina4 envelope, which only a message bus consumed by " +
550
+ "non-Tina4 systems (Kafka) needs. This backend stores an internal " +
551
+ "envelope (payload/priority/attempts) that pop(), the retry lifecycle " +
552
+ "and dead-lettering depend on, so there is nothing to omit. Use the " +
553
+ "kafka backend for raw external messages.",
554
+ );
555
+ }
546
556
  const id = randomUUID();
547
557
  const now = new Date().toISOString();
548
558
 
@@ -108,7 +108,7 @@ export function parseAmqpUrl(url: string): RabbitMQConfig {
108
108
  }
109
109
 
110
110
  export interface QueueBackend {
111
- push(queue: string, payload: unknown, delay?: number, priority?: number): string;
111
+ push(queue: string, payload: unknown, delay?: number, priority?: number, raw?: boolean): string;
112
112
  pop(queue: string): QueueJob | null;
113
113
  size(queue: string): number;
114
114
  clear(queue: string): void;
@@ -591,7 +591,17 @@ export class RabbitMQBackend implements QueueBackend {
591
591
  }
592
592
  }
593
593
 
594
- push(queue: string, payload: unknown, _delay?: number): string {
594
+ push(queue: string, payload: unknown, _delay?: number, _priority?: number, raw: boolean = false): string {
595
+ if (raw) {
596
+ throw new Error(
597
+ "The rabbitmq queue backend cannot honour push(raw=true): raw emits the " +
598
+ "message with no Tina4 envelope, which only a message bus consumed by " +
599
+ "non-Tina4 systems (Kafka) needs. This backend stores an internal " +
600
+ "envelope (payload/priority/attempts) that pop(), the retry lifecycle " +
601
+ "and dead-lettering depend on, so there is nothing to omit. Use the " +
602
+ "kafka backend for raw external messages.",
603
+ );
604
+ }
595
605
  const id = randomUUID();
596
606
  const now = new Date().toISOString();
597
607
 
@@ -12,6 +12,16 @@ import type { RouteDefinition, RouteHandler, RouteMeta } from "./types.js";
12
12
 
13
13
  const VALID_METHODS = new Set(["get", "post", "put", "delete", "patch"]);
14
14
 
15
+ /**
16
+ * A route file may export a boolean flag (`secure`, `noAuth`, `noCsrf`). Only a
17
+ * real boolean is honoured — anything else (including an accidental truthy
18
+ * string) is ignored and the framework's default applies. Shared so each flag
19
+ * reads the same way (and the discovery loop stays flat).
20
+ */
21
+ function boolExport(value: unknown): boolean | undefined {
22
+ return typeof value === "boolean" ? value : undefined;
23
+ }
24
+
15
25
  /**
16
26
  * Files already discovered by a prior scan. Lets rediscoverRoutes() pick up
17
27
  * only the freshly-added files without double-registering anything that was
@@ -72,16 +82,20 @@ export async function discoverRoutes(routesDir: string): Promise<RouteDefinition
72
82
 
73
83
  const meta: RouteMeta | undefined = mod.meta;
74
84
  const template: string | undefined = typeof mod.template === "string" ? mod.template : undefined;
75
- // Auth opt-outs a route file can export (parity with the imperative
76
- // `.noAuth()` / AutoCrud `secure: false`). A generated public write file
77
- // (`generate route … --public`, or the always-public auth login/register)
78
- // does `export const secure = false;`; without threading it here the
79
- // router would keep its secure-by-default write gate and the opt-out
80
- // would be inert. Only booleans are honoured — anything else is ignored.
81
- const secure: boolean | undefined = typeof mod.secure === "boolean" ? mod.secure : undefined;
82
- const noAuth: boolean | undefined = typeof mod.noAuth === "boolean" ? mod.noAuth : undefined;
83
-
84
- definitions.push({ method, pattern, handler, filePath, meta, template, secure, noAuth });
85
+ // Flags a route file can export (parity with the imperative modifiers),
86
+ // each honoured only as a real boolean (see boolExport):
87
+ // - `secure` / `noAuth`: the write-auth opt-out (`.noAuth()` / AutoCrud
88
+ // `secure: false`). A generated public write file does
89
+ // `export const secure = false;`; without threading it the router keeps
90
+ // its secure-by-default write gate and the opt-out is inert.
91
+ // - `noCsrf`: the CSRF opt-out (`.noCsrf()`) for a server-to-server
92
+ // webhook. #265: `noAuth` no longer skips CSRF, so a public webhook that
93
+ // must bypass the form-token check opts out explicitly here.
94
+ const secure = boolExport(mod.secure);
95
+ const noAuth = boolExport(mod.noAuth);
96
+ const noCsrf = boolExport(mod.noCsrf);
97
+
98
+ definitions.push({ method, pattern, handler, filePath, meta, template, secure, noAuth, noCsrf });
85
99
  _seenFiles.add(filePath);
86
100
  _seenMtimes.set(filePath, currentMtime);
87
101
  registeredFromThisScan++;
@@ -78,6 +78,7 @@ interface MatchResult {
78
78
  secure?: boolean;
79
79
  cached?: boolean;
80
80
  noAuth?: boolean;
81
+ noCsrf?: boolean;
81
82
  requiredRoles?: string[][];
82
83
  requiredPerms?: string[][];
83
84
  }
@@ -94,6 +95,7 @@ interface CompiledRoute {
94
95
  secure?: boolean;
95
96
  cached?: boolean;
96
97
  noAuth?: boolean;
98
+ noCsrf?: boolean;
97
99
  cacheStore?: Map<string, { data: unknown; expires: number }>;
98
100
  cacheTtl?: number;
99
101
  template?: string;
@@ -140,6 +142,17 @@ export class RouteRef {
140
142
  return this;
141
143
  }
142
144
 
145
+ /**
146
+ * Opt a route OUT of CSRF form-token validation (webhooks / server-to-server
147
+ * callbacks that carry no browser session). `.noAuth()` no longer skips CSRF
148
+ * (#265): a public form stays CSRF-protected. CSRF (origin) and auth
149
+ * (identity) are orthogonal — chain `.noAuth().noCsrf()` for a public webhook.
150
+ */
151
+ noCsrf(): this {
152
+ this.route.noCsrf = true;
153
+ return this;
154
+ }
155
+
143
156
  /**
144
157
  * RBAC: require ONE of the named roles (OR). Reads the verified JWT `roles`
145
158
  * claim. Chain .role()/.can() for AND. Implies auth. Feature 138 / ADR-0058.
@@ -262,6 +275,7 @@ export class Router {
262
275
  secure: secureDefault,
263
276
  cached: definition.cached,
264
277
  noAuth: definition.noAuth,
278
+ noCsrf: definition.noCsrf,
265
279
  template: definition.template,
266
280
  requiredRoles: definition.requiredRoles,
267
281
  requiredPerms: definition.requiredPerms,
@@ -438,6 +452,7 @@ export class Router {
438
452
  secure: route.secure,
439
453
  cached: route.cached,
440
454
  noAuth: route.noAuth,
455
+ noCsrf: route.noCsrf,
441
456
  requiredRoles: route.requiredRoles,
442
457
  requiredPerms: route.requiredPerms,
443
458
  };
@@ -177,6 +177,8 @@ export interface RouteDefinition {
177
177
  cached?: boolean;
178
178
  /** Opt out of secure-by-default auth on write routes */
179
179
  noAuth?: boolean;
180
+ /** Opt out of CSRF form-token validation (webhooks / server-to-server callbacks) — #265 */
181
+ noCsrf?: boolean;
180
182
  /** RBAC role guard groups (Feature 138): OR within a group, AND across groups */
181
183
  requiredRoles?: string[][];
182
184
  /** RBAC permission guard groups (Feature 138) */
@@ -4681,6 +4681,16 @@ var init_router = __esm({
4681
4681
  this.route.noAuth = true;
4682
4682
  return this;
4683
4683
  }
4684
+ /**
4685
+ * Opt a route OUT of CSRF form-token validation (webhooks / server-to-server
4686
+ * callbacks that carry no browser session). `.noAuth()` no longer skips CSRF
4687
+ * (#265): a public form stays CSRF-protected. CSRF (origin) and auth
4688
+ * (identity) are orthogonal — chain `.noAuth().noCsrf()` for a public webhook.
4689
+ */
4690
+ noCsrf() {
4691
+ this.route.noCsrf = true;
4692
+ return this;
4693
+ }
4684
4694
  /**
4685
4695
  * RBAC: require ONE of the named roles (OR). Reads the verified JWT `roles`
4686
4696
  * claim. Chain .role()/.can() for AND. Implies auth. Feature 138 / ADR-0058.
@@ -4773,6 +4783,7 @@ var init_router = __esm({
4773
4783
  secure: secureDefault,
4774
4784
  cached: definition.cached,
4775
4785
  noAuth: definition.noAuth,
4786
+ noCsrf: definition.noCsrf,
4776
4787
  template: definition.template,
4777
4788
  requiredRoles: definition.requiredRoles,
4778
4789
  requiredPerms: definition.requiredPerms
@@ -4923,6 +4934,7 @@ var init_router = __esm({
4923
4934
  secure: route.secure,
4924
4935
  cached: route.cached,
4925
4936
  noAuth: route.noAuth,
4937
+ noCsrf: route.noCsrf,
4926
4938
  requiredRoles: route.requiredRoles,
4927
4939
  requiredPerms: route.requiredPerms
4928
4940
  };
@@ -9108,7 +9120,7 @@ function csrfMethodIsSafe(method) {
9108
9120
  }
9109
9121
  function csrfRouteSkips(req2) {
9110
9122
  const route = req2._route ?? req2.route;
9111
- return Boolean(route?.noAuth);
9123
+ return Boolean(route?.noCsrf);
9112
9124
  }
9113
9125
  function csrfBearerIsValid(req2, secret) {
9114
9126
  const authHeader = req2.headers.authorization ?? "";
@@ -10492,6 +10504,9 @@ __export(routeDiscovery_exports, {
10492
10504
  });
10493
10505
  import { readdirSync as readdirSync2, statSync as statSync5, mkdirSync as mkdirSync4, writeFileSync as writeFileSync3, existsSync as existsSync6 } from "node:fs";
10494
10506
  import { join as join7, relative, basename as basename2, extname } from "node:path";
10507
+ function boolExport(value) {
10508
+ return typeof value === "boolean" ? value : void 0;
10509
+ }
10495
10510
  async function discoverRoutes(routesDir) {
10496
10511
  _lastRoutesDir = routesDir;
10497
10512
  const definitions = [];
@@ -10519,9 +10534,10 @@ async function discoverRoutes(routesDir) {
10519
10534
  }
10520
10535
  const meta = mod.meta;
10521
10536
  const template = typeof mod.template === "string" ? mod.template : void 0;
10522
- const secure = typeof mod.secure === "boolean" ? mod.secure : void 0;
10523
- const noAuth = typeof mod.noAuth === "boolean" ? mod.noAuth : void 0;
10524
- definitions.push({ method, pattern, handler, filePath, meta, template, secure, noAuth });
10537
+ const secure = boolExport(mod.secure);
10538
+ const noAuth = boolExport(mod.noAuth);
10539
+ const noCsrf = boolExport(mod.noCsrf);
10540
+ definitions.push({ method, pattern, handler, filePath, meta, template, secure, noAuth, noCsrf });
10525
10541
  _seenFiles.add(filePath);
10526
10542
  _seenMtimes.set(filePath, currentMtime);
10527
10543
  registeredFromThisScan++;
@@ -21332,7 +21348,12 @@ var init_mongoBackend = __esm({
21332
21348
  return null;
21333
21349
  }
21334
21350
  }
21335
- push(queue, payload, delay2, priority) {
21351
+ push(queue, payload, delay2, priority, raw = false) {
21352
+ if (raw) {
21353
+ throw new Error(
21354
+ "The mongodb queue backend cannot honour push(raw=true): raw emits the message with no Tina4 envelope, which only a message bus consumed by non-Tina4 systems (Kafka) needs. This backend stores an internal envelope (payload/priority/attempts) that pop(), the retry lifecycle and dead-lettering depend on, so there is nothing to omit. Use the kafka backend for raw external messages."
21355
+ );
21356
+ }
21336
21357
  const id = randomUUID4();
21337
21358
  const now = (/* @__PURE__ */ new Date()).toISOString();
21338
21359
  const job = {
@@ -21572,7 +21593,12 @@ var init_liteBackend = __esm({
21572
21593
  */
21573
21594
  close() {
21574
21595
  }
21575
- push(queue, payload, delay2, priority) {
21596
+ push(queue, payload, delay2, priority, raw = false) {
21597
+ if (raw) {
21598
+ throw new Error(
21599
+ "The file queue backend cannot honour push(raw=true): raw emits the message with no Tina4 envelope, which only a message bus consumed by non-Tina4 systems (Kafka) needs. This backend stores an internal envelope (id/status/attempts/delayUntil) that pop(), the retry lifecycle and dead-lettering depend on, so there is nothing to omit. Use the kafka backend for raw external messages."
21600
+ );
21601
+ }
21576
21602
  const dir = this.ensureDir(queue);
21577
21603
  const id = randomUUID5();
21578
21604
  const now = (/* @__PURE__ */ new Date()).toISOString();
@@ -22218,12 +22244,16 @@ var init_queue = __esm({
22218
22244
  * queue.push(payload, delay, priority) — with delay and priority
22219
22245
  *
22220
22246
  * @param priority — Higher value = higher priority. Default 0.
22247
+ * @param raw — Kafka-only (tina4-nodejs#264): produce the value with NO Tina4
22248
+ * envelope and no injected id, for a non-Tina4 consumer. The file/rabbitmq/
22249
+ * mongodb backends refuse raw=true by name (the envelope is internal
22250
+ * bookkeeping pop/retries/dead-lettering depend on). Default false.
22221
22251
  */
22222
- push(payload, delay2, priority = 0) {
22252
+ push(payload, delay2, priority = 0, raw = false) {
22223
22253
  if (this.externalBackend) {
22224
- return this.externalBackend.push(this.topic, payload, delay2, priority);
22254
+ return this.externalBackend.push(this.topic, payload, delay2, priority, raw);
22225
22255
  }
22226
- return this.liteBackend.push(this.topic, payload, delay2, priority);
22256
+ return this.liteBackend.push(this.topic, payload, delay2, priority, raw);
22227
22257
  }
22228
22258
  /**
22229
22259
  * Atomically claim the next available job from this queue's topic. Returns null if empty.
@@ -22454,11 +22484,11 @@ var init_queue = __esm({
22454
22484
  * shares the same retarget path consume()/process() use — keeping produce and
22455
22485
  * consume symmetric on the same topic argument.
22456
22486
  */
22457
- produce(topic, payload, priority = 0, delay2 = 0) {
22487
+ produce(topic, payload, priority = 0, delay2 = 0, raw = false) {
22458
22488
  const previous = this.topic;
22459
22489
  this.retarget(topic);
22460
22490
  try {
22461
- return this.push(payload, delay2, priority);
22491
+ return this.push(payload, delay2, priority, raw);
22462
22492
  } finally {
22463
22493
  this.retarget(previous);
22464
22494
  }
@@ -36962,7 +36992,12 @@ var init_rabbitmqBackend = __esm({
36962
36992
  return "";
36963
36993
  }
36964
36994
  }
36965
- push(queue, payload, _delay) {
36995
+ push(queue, payload, _delay, _priority, raw = false) {
36996
+ if (raw) {
36997
+ throw new Error(
36998
+ "The rabbitmq queue backend cannot honour push(raw=true): raw emits the message with no Tina4 envelope, which only a message bus consumed by non-Tina4 systems (Kafka) needs. This backend stores an internal envelope (payload/priority/attempts) that pop(), the retry lifecycle and dead-lettering depend on, so there is nothing to omit. Use the kafka backend for raw external messages."
36999
+ );
37000
+ }
36966
37001
  const id = randomUUID8();
36967
37002
  const now = (/* @__PURE__ */ new Date()).toISOString();
36968
37003
  const job = {
@@ -37027,6 +37062,9 @@ function kafkaSecurityConfig(env = process.env) {
37027
37062
  }
37028
37063
  return config;
37029
37064
  }
37065
+ function kafkaOffsetReset(env = process.env) {
37066
+ return env.TINA4_KAFKA_AUTO_OFFSET_RESET || env.KAFKA_AUTO_OFFSET_RESET || "earliest";
37067
+ }
37030
37068
  var API_PRODUCE, API_FETCH, KafkaBackend;
37031
37069
  var init_kafkaBackend = __esm({
37032
37070
  "../core/src/queueBackends/kafkaBackend.ts"() {
@@ -37076,7 +37114,7 @@ var init_kafkaBackend = __esm({
37076
37114
  "bootstrap.servers": this.brokers,
37077
37115
  "client.id": "tina4-nodejs",
37078
37116
  "group.id": this.groupId,
37079
- "auto.offset.reset": "earliest",
37117
+ "auto.offset.reset": kafkaOffsetReset(),
37080
37118
  "enable.auto.commit": false,
37081
37119
  ...this.securityConfig()
37082
37120
  };
@@ -37522,18 +37560,26 @@ var init_kafkaBackend = __esm({
37522
37560
  );
37523
37561
  }
37524
37562
  }
37525
- push(queue, payload, _delay) {
37526
- const id = randomUUID9();
37527
- const now = (/* @__PURE__ */ new Date()).toISOString();
37528
- const job = {
37563
+ /**
37564
+ * Serialize the record value. raw (tina4-nodejs#264) emits the payload exactly
37565
+ * as given — no {id, payload, status, attempts, ...} envelope — so a non-Tina4
37566
+ * consumer reading the topic gets the schema it expects; otherwise the Tina4 job
37567
+ * envelope. pop() unwraps both shapes (payload ?? the whole record).
37568
+ */
37569
+ static encodeJob(id, payload, raw) {
37570
+ if (raw) return JSON.stringify(payload);
37571
+ return JSON.stringify({
37529
37572
  id,
37530
37573
  payload,
37531
37574
  status: "pending",
37532
- createdAt: now,
37575
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
37533
37576
  attempts: 0,
37534
37577
  delayUntil: null
37535
- };
37536
- const body = JSON.stringify(job);
37578
+ });
37579
+ }
37580
+ push(queue, payload, _delay, _priority, raw = false) {
37581
+ const id = randomUUID9();
37582
+ const body = _KafkaBackend.encodeJob(id, payload, raw);
37537
37583
  let result = "";
37538
37584
  for (let attempt = 1; attempt <= 10; attempt++) {
37539
37585
  result = this.execSync("publish", queue, body);
@@ -38470,6 +38516,7 @@ __export(src_exports2, {
38470
38516
  isTrustedProxy: () => isTrustedProxy,
38471
38517
  isTruthy: () => isTruthy,
38472
38518
  isValidSessionId: () => isValidSessionId,
38519
+ kafkaOffsetReset: () => kafkaOffsetReset,
38473
38520
  kafkaSecurityConfig: () => kafkaSecurityConfig,
38474
38521
  loadEnv: () => loadEnv,
38475
38522
  loopbackBindHosts: () => loopbackBindHosts,
@@ -68,7 +68,7 @@ export type { ImapMessage, ImapFullMessage, ImapAttachment } from "./messenger.j
68
68
  export { LiteBackend } from "./queueBackends/liteBackend.js";
69
69
  export { RabbitMQBackend, parseAmqpUrl } from "./queueBackends/rabbitmqBackend.js";
70
70
  export type { RabbitMQConfig } from "./queueBackends/rabbitmqBackend.js";
71
- export { KafkaBackend, kafkaSecurityConfig } from "./queueBackends/kafkaBackend.js";
71
+ export { KafkaBackend, kafkaSecurityConfig, kafkaOffsetReset } from "./queueBackends/kafkaBackend.js";
72
72
  export type { KafkaConfig, KafkaSecurityConfig, KafkaClientConfig, } from "./queueBackends/kafkaBackend.js";
73
73
  export { MongoBackend } from "./queueBackends/mongoBackend.js";
74
74
  export type { MongoConfig as MongoQueueConfig } from "./queueBackends/mongoBackend.js";
@@ -383,15 +383,18 @@ export declare class SecurityHeadersMiddleware {
383
383
  * Class-based CSRF middleware using the before/after convention.
384
384
  * Validates form tokens on state-changing requests (POST, PUT, PATCH, DELETE).
385
385
  *
386
- * OFF by default — a default app has NO CSRF gate because the middleware is
387
- * NOT attached. Set TINA4_CSRF=true (or 1/yes/on) and the framework
388
- * auto-attaches it at boot (see attachCsrfFromEnv); or register it explicitly
389
- * via Router.use(CsrfMiddleware). Once attached, TINA4_CSRF=false (or 0/no) is
390
- * the kill switch that disables enforcement again.
386
+ * NOT attached by default — a default app has NO CSRF gate because the
387
+ * middleware is NOT attached. Set TINA4_CSRF=true (or 1/yes/on) and the
388
+ * framework auto-attaches it at boot (see attachCsrfFromEnv); or register it
389
+ * explicitly via Router.use(CsrfMiddleware). Once attached it enforces unless
390
+ * the kill switch TINA4_CSRF=false (or 0/no) is set — so with it attached but
391
+ * TINA4_CSRF unset, enforcement is ON (the attach is the opt-in).
391
392
  *
392
393
  * Behaviour (identical to the Python master, feature 37):
393
394
  * - Skips GET, HEAD, OPTIONS requests.
394
- * - Skips routes marked .noAuth().
395
+ * - Skips routes that opt out with .noCsrf() (server-to-server webhooks).
396
+ * .noAuth() does NOT skip CSRF (#265): a public form can be open to
397
+ * anonymous visitors AND still protected against cross-site posts.
395
398
  * - Fails CLOSED: with TINA4_SECRET unset the signing secret resolves to
396
399
  * blank (there is NO built-in default), and a blank HMAC key is publicly
397
400
  * reproducible — so no token can be trusted and every write is rejected
@@ -57,7 +57,7 @@ export interface ConsumeOptions {
57
57
  id?: string;
58
58
  }
59
59
  export interface QueueBackendInterface {
60
- push(queue: string, payload: unknown, delay?: number, priority?: number): string;
60
+ push(queue: string, payload: unknown, delay?: number, priority?: number, raw?: boolean): string;
61
61
  pop(queue: string): QueueJob | null;
62
62
  size(queue: string, status?: string): number;
63
63
  clear(queue: string): void;
@@ -129,8 +129,12 @@ export declare class Queue {
129
129
  * queue.push(payload, delay, priority) — with delay and priority
130
130
  *
131
131
  * @param priority — Higher value = higher priority. Default 0.
132
+ * @param raw — Kafka-only (tina4-nodejs#264): produce the value with NO Tina4
133
+ * envelope and no injected id, for a non-Tina4 consumer. The file/rabbitmq/
134
+ * mongodb backends refuse raw=true by name (the envelope is internal
135
+ * bookkeeping pop/retries/dead-lettering depend on). Default false.
132
136
  */
133
- push(payload: unknown, delay?: number, priority?: number): string;
137
+ push(payload: unknown, delay?: number, priority?: number, raw?: boolean): string;
134
138
  /**
135
139
  * Atomically claim the next available job from this queue's topic. Returns null if empty.
136
140
  */
@@ -240,7 +244,7 @@ export declare class Queue {
240
244
  * shares the same retarget path consume()/process() use — keeping produce and
241
245
  * consume symmetric on the same topic argument.
242
246
  */
243
- produce(topic: string, payload: unknown, priority?: number, delay?: number): string;
247
+ produce(topic: string, payload: unknown, priority?: number, delay?: number, raw?: boolean): string;
244
248
  /**
245
249
  * Consume jobs from a topic using a generator (yield pattern).
246
250
  *
@@ -43,8 +43,23 @@ export interface KafkaClientConfig extends KafkaSecurityConfig {
43
43
  * `_security_config` (same key set, same precedence, same omit-when-unset).
44
44
  */
45
45
  export declare function kafkaSecurityConfig(env?: NodeJS.ProcessEnv): KafkaSecurityConfig;
46
+ /**
47
+ * Resolve the consumer's auto.offset.reset policy from the environment.
48
+ *
49
+ * Where a NEW consumer group (one with no committed offset) starts reading:
50
+ * "earliest" (the default, unchanged) replays the retained backlog; "latest"
51
+ * skips it. Read from the Tina4-namespaced env var FIRST
52
+ * (`TINA4_KAFKA_AUTO_OFFSET_RESET`) and fall back to the bare librdkafka-
53
+ * convention name (`KAFKA_AUTO_OFFSET_RESET`) — the same precedence the TLS/SASL
54
+ * keys use. A blank value falls through to the default (tina4-nodejs#263).
55
+ *
56
+ * Surfaced on the declared consumer config for parity/introspection; this
57
+ * backend reads records over the raw protocol from the earliest retained offset.
58
+ * Mirrors Python's `KafkaConnector._offset_reset`.
59
+ */
60
+ export declare function kafkaOffsetReset(env?: NodeJS.ProcessEnv): string;
46
61
  export interface QueueBackend {
47
- push(queue: string, payload: unknown, delay?: number, priority?: number): string;
62
+ push(queue: string, payload: unknown, delay?: number, priority?: number, raw?: boolean): string;
48
63
  pop(queue: string): QueueJob | null;
49
64
  size(queue: string): number;
50
65
  clear(queue: string): void;
@@ -110,7 +125,14 @@ export declare class KafkaBackend implements QueueBackend {
110
125
  * covers user-visible error messages, not just behaviour.
111
126
  */
112
127
  private static assertNoError;
113
- push(queue: string, payload: unknown, _delay?: number): string;
128
+ /**
129
+ * Serialize the record value. raw (tina4-nodejs#264) emits the payload exactly
130
+ * as given — no {id, payload, status, attempts, ...} envelope — so a non-Tina4
131
+ * consumer reading the topic gets the schema it expects; otherwise the Tina4 job
132
+ * envelope. pop() unwraps both shapes (payload ?? the whole record).
133
+ */
134
+ private static encodeJob;
135
+ push(queue: string, payload: unknown, _delay?: number, _priority?: number, raw?: boolean): string;
114
136
  pop(queue: string): QueueJob | null;
115
137
  size(_queue: string): number;
116
138
  clear(_queue: string): void;
@@ -29,7 +29,7 @@ export declare class LiteBackend {
29
29
  * by construction — there is nothing to drop.
30
30
  */
31
31
  close(): void;
32
- push(queue: string, payload: unknown, delay?: number, priority?: number): string;
32
+ push(queue: string, payload: unknown, delay?: number, priority?: number, raw?: boolean): string;
33
33
  /**
34
34
  * Return [filename, jobData] for every pending, non-delayed job, ordered by
35
35
  * the dequeue policy: highest priority first, ties broken oldest-first by
@@ -18,7 +18,7 @@ export interface MongoConfig {
18
18
  maxRetries?: number;
19
19
  }
20
20
  export interface QueueBackend {
21
- push(queue: string, payload: unknown, delay?: number, priority?: number): string;
21
+ push(queue: string, payload: unknown, delay?: number, priority?: number, raw?: boolean): string;
22
22
  pop(queue: string): QueueJob | null;
23
23
  size(queue: string): number;
24
24
  clear(queue: string): void;
@@ -74,7 +74,7 @@ export declare class MongoBackend implements QueueBackend {
74
74
  */
75
75
  private execSync;
76
76
  popById(queue: string, id: string): QueueJob | null;
77
- push(queue: string, payload: unknown, delay?: number, priority?: number): string;
77
+ push(queue: string, payload: unknown, delay?: number, priority?: number, raw?: boolean): string;
78
78
  pop(queue: string): QueueJob | null;
79
79
  size(queue: string, status?: string): number;
80
80
  /**
@@ -21,7 +21,7 @@ export interface RabbitMQConfig {
21
21
  */
22
22
  export declare function parseAmqpUrl(url: string): RabbitMQConfig;
23
23
  export interface QueueBackend {
24
- push(queue: string, payload: unknown, delay?: number, priority?: number): string;
24
+ push(queue: string, payload: unknown, delay?: number, priority?: number, raw?: boolean): string;
25
25
  pop(queue: string): QueueJob | null;
26
26
  size(queue: string): number;
27
27
  clear(queue: string): void;
@@ -48,7 +48,7 @@ export declare class RabbitMQBackend implements QueueBackend {
48
48
  * Execute an AMQP operation synchronously via a child process.
49
49
  */
50
50
  private execSync;
51
- push(queue: string, payload: unknown, _delay?: number): string;
51
+ push(queue: string, payload: unknown, _delay?: number, _priority?: number, raw?: boolean): string;
52
52
  pop(queue: string): QueueJob | null;
53
53
  size(queue: string): number;
54
54
  clear(_queue: string): void;
@@ -17,6 +17,7 @@ interface MatchResult {
17
17
  secure?: boolean;
18
18
  cached?: boolean;
19
19
  noAuth?: boolean;
20
+ noCsrf?: boolean;
20
21
  requiredRoles?: string[][];
21
22
  requiredPerms?: string[][];
22
23
  }
@@ -32,6 +33,7 @@ interface CompiledRoute {
32
33
  secure?: boolean;
33
34
  cached?: boolean;
34
35
  noAuth?: boolean;
36
+ noCsrf?: boolean;
35
37
  cacheStore?: Map<string, {
36
38
  data: unknown;
37
39
  expires: number;
@@ -68,6 +70,13 @@ export declare class RouteRef {
68
70
  secure(): this;
69
71
  /** Opt out of secure-by-default auth (for public write routes). */
70
72
  noAuth(): this;
73
+ /**
74
+ * Opt a route OUT of CSRF form-token validation (webhooks / server-to-server
75
+ * callbacks that carry no browser session). `.noAuth()` no longer skips CSRF
76
+ * (#265): a public form stays CSRF-protected. CSRF (origin) and auth
77
+ * (identity) are orthogonal — chain `.noAuth().noCsrf()` for a public webhook.
78
+ */
79
+ noCsrf(): this;
71
80
  /**
72
81
  * RBAC: require ONE of the named roles (OR). Reads the verified JWT `roles`
73
82
  * claim. Chain .role()/.can() for AND. Implies auth. Feature 138 / ADR-0058.
@@ -154,6 +154,8 @@ export interface RouteDefinition {
154
154
  cached?: boolean;
155
155
  /** Opt out of secure-by-default auth on write routes */
156
156
  noAuth?: boolean;
157
+ /** Opt out of CSRF form-token validation (webhooks / server-to-server callbacks) — #265 */
158
+ noCsrf?: boolean;
157
159
  /** RBAC role guard groups (Feature 138): OR within a group, AND across groups */
158
160
  requiredRoles?: string[][];
159
161
  /** RBAC permission guard groups (Feature 138) */