@rotorsoft/act 1.37.2 → 1.37.4

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/dist/index.js CHANGED
@@ -40,7 +40,7 @@ import {
40
40
  sleep,
41
41
  store,
42
42
  validate
43
- } from "./chunk-SIOPY6HT.js";
43
+ } from "./chunk-FBZY2F5W.js";
44
44
  import {
45
45
  ActorSchema,
46
46
  CausationEventSchema,
@@ -68,10 +68,12 @@ import {
68
68
  TargetSchema,
69
69
  ValidationError,
70
70
  ZodEmpty,
71
+ def_of,
72
+ output_of,
71
73
  pii_fields,
72
74
  pii_schemas,
73
75
  sensitive
74
- } from "./chunk-2H5MBVSQ.js";
76
+ } from "./chunk-CB2OLGJK.js";
75
77
 
76
78
  // src/signals.ts
77
79
  process.once("SIGINT", async (arg) => {
@@ -4414,7 +4416,6 @@ import { z as z4 } from "zod";
4414
4416
 
4415
4417
  // src/internal/date-reviver.ts
4416
4418
  import { z as z3 } from "zod";
4417
- var def_of = (schema) => schema._zod?.def ?? schema.def;
4418
4419
  function variant_schema(schema) {
4419
4420
  const shape = def_of(schema)?.shape;
4420
4421
  if (!shape) {
@@ -4465,6 +4466,8 @@ function date_reviver_schema(schema) {
4465
4466
  }
4466
4467
  case "nullable":
4467
4468
  return inner()?.nullable();
4469
+ case "pipe":
4470
+ return date_reviver_schema(def.out);
4468
4471
  case "optional":
4469
4472
  case "nonoptional":
4470
4473
  case "readonly":
@@ -4492,13 +4495,14 @@ function event_tags(schema) {
4492
4495
  };
4493
4496
  const dated_pii = Object.keys(pii_dates).length > 0;
4494
4497
  return {
4495
- sensitive: Object.keys(pii),
4498
+ sensitive: pii,
4496
4499
  date_reviver: data_reviver_schema && revive(data_reviver_schema),
4497
4500
  pii_date_reviver: dated_pii ? revive(z4.looseObject(pii_dates)) : void 0
4498
4501
  };
4499
4502
  }
4500
4503
  function make_event_reader(tags, disclosure, predicate = null) {
4501
- const { sensitive: sensitive2, date_reviver, pii_date_reviver } = tags;
4504
+ const { date_reviver, pii_date_reviver } = tags;
4505
+ const sensitive2 = Object.keys(tags.sensitive);
4502
4506
  if (!date_reviver && sensitive2.length === 0) return void 0;
4503
4507
  const gate = sensitive2.length === 0 ? IDENTITY_GATE : disclosure === "strip" ? ((event) => pii_strip(event, sensitive2)) : make_gate(sensitive2, predicate);
4504
4508
  if (!date_reviver) return gate;
@@ -4540,7 +4544,8 @@ function build_events(registry, states, lanes, owners) {
4540
4544
  }
4541
4545
  const event = event_tags(def.schema);
4542
4546
  tags.set(event_name, event);
4543
- if (event.sensitive.length > 0) sensitive2.set(event_name, event.sensitive);
4547
+ const fields = Object.keys(event.sensitive);
4548
+ if (fields.length > 0) sensitive2.set(event_name, fields);
4544
4549
  const query_reader = make_event_reader(event, "redact", null);
4545
4550
  if (query_reader) query_readers.set(event_name, query_reader);
4546
4551
  const handler_reader = make_event_reader(event, "strip");
@@ -4556,11 +4561,21 @@ function build_events(registry, states, lanes, owners) {
4556
4561
  }
4557
4562
  }
4558
4563
  if (lane_errors.length > 0) throw new Error(lane_errors[0]);
4564
+ const advised = /* @__PURE__ */ new Set();
4559
4565
  for (const state2 of states.values()) {
4566
+ const shape = state2.state.shape ?? {};
4560
4567
  const state_fields = /* @__PURE__ */ new Map();
4561
4568
  for (const event_name of Object.keys(state2.events)) {
4562
4569
  const fields = sensitive2.get(event_name);
4563
- if (fields) state_fields.set(event_name, fields);
4570
+ if (!fields) continue;
4571
+ state_fields.set(event_name, fields);
4572
+ const event = tags.get(event_name);
4573
+ for (const field of fields) {
4574
+ if (!reads_as_string(event.sensitive[field]))
4575
+ advised.add(`${event_name}.${field}`);
4576
+ if (shape[field] && !reads_as_string(shape[field]))
4577
+ advised.add(`${state2.name}.${field}`);
4578
+ }
4564
4579
  }
4565
4580
  if (state_fields.size > 0) {
4566
4581
  if (state2.snap)
@@ -4584,7 +4599,12 @@ function build_events(registry, states, lanes, owners) {
4584
4599
  if (readers.size === 0) continue;
4585
4600
  state2.view = (event, actor) => (readers.get(event.name) ?? IDENTITY_GATE)(event, actor);
4586
4601
  }
4587
- return { sensitive: sensitive2, query_readers, handler_readers };
4602
+ const advisory = advised.size > 0 ? `Act has ${advised.size} sensitive field(s) whose type isn't a string: ${[...advised].join(", ")}. A caller who may not see one reads "[REDACTED]" or "[SHREDDED]" there instead, which its type doesn't allow. Declare sensitive fields as strings. See docs/docs/guides/sensitive-data.md.` : void 0;
4603
+ return { sensitive: sensitive2, advisory, query_readers, handler_readers };
4604
+ }
4605
+ function reads_as_string(schema) {
4606
+ const type = def_of(output_of(schema))?.type;
4607
+ return type === "string" || type === "transform";
4588
4608
  }
4589
4609
 
4590
4610
  // src/builders/act-builder.ts
@@ -4639,24 +4659,6 @@ function act() {
4639
4659
  const fold_specs = [];
4640
4660
  const lanes = [];
4641
4661
  let _built = false;
4642
- const advise_pii_types = () => {
4643
- const fields = /* @__PURE__ */ new Set();
4644
- for (const state2 of states.values()) {
4645
- const shape = state2.state.shape ?? {};
4646
- for (const [event, schema] of Object.entries(state2.events))
4647
- for (const [field, field_schema] of Object.entries(
4648
- pii_schemas(schema)
4649
- )) {
4650
- if (!reads_as_string(field_schema)) fields.add(`${event}.${field}`);
4651
- if (shape[field] && !reads_as_string(shape[field]))
4652
- fields.add(`${state2.name}.${field}`);
4653
- }
4654
- }
4655
- if (fields.size > 0)
4656
- log().warn(
4657
- `Act has ${fields.size} sensitive field(s) whose type isn't a string: ${[...fields].join(", ")}. A caller who may not see one reads "[REDACTED]" or "[SHREDDED]" there instead, which its type doesn't allow. Declare sensitive fields as strings. See docs/docs/guides/sensitive-data.md.`
4658
- );
4659
- };
4660
4662
  const read_wrap = (original) => {
4661
4663
  const wrapped = async (events, stream) => {
4662
4664
  const read = events.map((e) => _hr.get(e.name)?.(e) ?? e);
@@ -4795,7 +4797,7 @@ function act() {
4795
4797
  for (const [name, gate] of built.query_readers) _qg.set(name, gate);
4796
4798
  for (const [name, gate] of built.handler_readers) _hr.set(name, gate);
4797
4799
  finalize_deprecations();
4798
- advise_pii_types();
4800
+ if (built.advisory) log().warn(built.advisory);
4799
4801
  for (const state2 of states.values()) {
4800
4802
  if (state2.disclose) _dp.set(state2.name, state2.disclose);
4801
4803
  if (state2.autoclose) _ac.set(state2.name, state2.autoclose);
@@ -4826,12 +4828,6 @@ function act() {
4826
4828
  };
4827
4829
  return builder;
4828
4830
  }
4829
- function reads_as_string(schema) {
4830
- const def = schema._zod.def;
4831
- if (def.type === "string" || def.type === "transform") return true;
4832
- if (def.out) return reads_as_string(def.out);
4833
- return def.innerType ? reads_as_string(def.innerType) : false;
4834
- }
4835
4831
 
4836
4832
  // src/builders/projection-builder.ts
4837
4833
  function _projection(target) {