@capxul/observability 4.1.4 → 4.2.0-rc.10

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.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { i as redactUrlSecrets, n as isCredentialField, r as redactSecrets, t as CAPXUL_ERROR_CODES } from "./src-CWfRYsBI.mjs";
1
2
  import { Effect, Schema, SchemaGetter } from "effect";
2
3
  //#region ../errors/src/chain-cause.ts
3
4
  /**
@@ -35,39 +36,6 @@ const CHAIN_UPSTREAMS = [
35
36
  "gateway"
36
37
  ];
37
38
  //#endregion
38
- //#region ../errors/src/errors.ts
39
- const CAPXUL_ERROR_CODES = [
40
- "NOT_AUTHENTICATED",
41
- "EMAIL_DELIVERY_FAILED",
42
- "PROFILE_NOT_FOUND",
43
- "SMART_ACCOUNT_MISSING",
44
- "PLAYER_NOT_FOUND",
45
- "ACCOUNT_NOT_FOUND",
46
- "ACCOUNT_CLAIMED_BY_OTHER_SIGNER",
47
- "PROVIDER_ERROR",
48
- "CAPABILITY_UNAVAILABLE",
49
- "INVALID_INPUT",
50
- "ENV_MISSING",
51
- "NOT_IMPLEMENTED",
52
- "VERIFICATION_REQUIRED",
53
- "INSUFFICIENT_BALANCE",
54
- "INVALID_RECIPIENT",
55
- "ROLE_PERMISSION_DENIED",
56
- "TRANSACTION_FAILED",
57
- "RATE_LIMITED",
58
- "NETWORK_ERROR",
59
- "UNKNOWN",
60
- "OTP_EXPIRED",
61
- "SIGNER_REJECTED",
62
- "CANCELLED",
63
- "WRONG_STATE",
64
- "STALE_EPOCH",
65
- "SUPERSEDED",
66
- "WORK_DIED",
67
- "ACTOR_STOPPED"
68
- ];
69
- new Set(CAPXUL_ERROR_CODES);
70
- //#endregion
71
39
  //#region ../types/src/index.ts
72
40
  const EVM_ADDRESS_RE = /^0x[0-9a-f]{40}$/i;
73
41
  const BYTES32_RE = /^0x[0-9a-f]{64}$/i;
@@ -146,6 +114,8 @@ const CAPXUL_OPERATIONS = {
146
114
  emitAnnotationSaved: "activity.emitAnnotationSaved",
147
115
  get: "activity.get",
148
116
  list: "activity.list",
117
+ /** The SDK's live Activity read over the indexer's SSE stream. */
118
+ subscribe: "activity.subscribe",
149
119
  summary: "activity.summary"
150
120
  },
151
121
  addressBook: {
@@ -505,6 +475,7 @@ const TELEMETRY_EVENT_NAMES = [
505
475
  "auth_otp_expired",
506
476
  "auth_verified",
507
477
  "auth_failed",
478
+ "identity_refused",
508
479
  "auth_signed_out",
509
480
  "onboarding_intent_selected",
510
481
  "onboarding_profile_submitted",
@@ -553,7 +524,18 @@ const TELEMETRY_EVENT_NAMES = [
553
524
  "activity_annotation_saved",
554
525
  "ui_activity_action_completed",
555
526
  "contact_relationship_changed",
556
- "ui_contact_action_completed"
527
+ "ui_contact_action_completed",
528
+ "access_recovery_completed",
529
+ "ui_access_step_completed",
530
+ "org_invite_progressed",
531
+ "invoice_issued",
532
+ "invoice_request_transitioned",
533
+ "ui_invoice_step_completed",
534
+ "ui_treasury_step_completed",
535
+ "ui_receive_step_completed",
536
+ "payroll_group_changed",
537
+ "payroll_run_transitioned",
538
+ "ui_payroll_action_completed"
557
539
  ];
558
540
  const TELEMETRY_JOURNEYS = {
559
541
  returning_user_login: {
@@ -901,6 +883,17 @@ const AuthFailedProps = Schema.Struct({
901
883
  auth_type: OptionalString,
902
884
  reason: OptionalString
903
885
  });
886
+ const IdentityRefusedProps = Schema.Struct({
887
+ ...TelemetryEnvelopeProps,
888
+ /** The refused identity event tag, for example CreateOrganization. */
889
+ event: OptionalString,
890
+ /** The machine's refusal code: WRONG_STATE, SUPERSEDED or STALE_EPOCH. */
891
+ refusal_code: OptionalString,
892
+ /** The machine slot the request targeted, for example identity:org. */
893
+ slot: OptionalString,
894
+ /** The machine state at refusal, for example authenticated:claiming. */
895
+ state: OptionalString
896
+ });
904
897
  const AuthSignedOutProps = Schema.Struct(TelemetryEnvelopeProps);
905
898
  const ProvisioningSafeCreatedProps = Schema.Struct({
906
899
  ...TelemetryEnvelopeProps,
@@ -1288,10 +1281,24 @@ const DepositSettledProps = Schema.Struct({
1288
1281
  });
1289
1282
  const PermissionMirrorVerificationProps = Schema.Struct({
1290
1283
  ...TelemetryEnvelopeProps,
1284
+ /** The RECEIPT verification outcome. What the mirror then did is separate. */
1291
1285
  outcome: Schema.String,
1292
1286
  reason: Schema.String,
1293
1287
  chain_id: Schema.Number,
1294
- retry_count: Schema.Number
1288
+ retry_count: Schema.Number,
1289
+ /**
1290
+ * #1960 R02, consumed by R03. A verified receipt is not an applied Permission:
1291
+ * these two optional fields let the producer say what the applying mutation
1292
+ * actually returned, and which command it was, without either fact rewriting
1293
+ * the receipt outcome above. Absent when application has not happened yet.
1294
+ */
1295
+ application_result: Schema.optional(Schema.Literals([
1296
+ "applied",
1297
+ "replayed",
1298
+ "conflicting_replay",
1299
+ "revision_mismatch"
1300
+ ])),
1301
+ command_id: OptionalString
1295
1302
  });
1296
1303
  const MovementScanWindowProps = Schema.Struct({
1297
1304
  ...TelemetryEnvelopeProps,
@@ -1337,6 +1344,10 @@ const AuthFailedTelemetryEventSchema = Schema.Struct({
1337
1344
  name: Schema.Literal("auth_failed"),
1338
1345
  props: AuthFailedProps
1339
1346
  });
1347
+ const IdentityRefusedTelemetryEventSchema = Schema.Struct({
1348
+ name: Schema.Literal("identity_refused"),
1349
+ props: IdentityRefusedProps
1350
+ });
1340
1351
  const AuthSignedOutTelemetryEventSchema = Schema.Struct({
1341
1352
  name: Schema.Literal("auth_signed_out"),
1342
1353
  props: AuthSignedOutProps
@@ -1517,6 +1528,10 @@ const MovementScanIncidentTelemetryEventSchema = Schema.Struct({
1517
1528
  name: Schema.Literal("movement_scan_incident"),
1518
1529
  props: MovementScanIncidentProps
1519
1530
  });
1531
+ /** The one spelling of "whose scope did this happen in" across every surface. */
1532
+ const ScopeKindSchema = Schema.Literals(["account", "organization"]);
1533
+ const AccountKindSchema = Schema.Literals(["personalSafe", "orgTreasury"]);
1534
+ const OptionalReasonCode = Schema.optional(Schema.Literals(CAPXUL_ERROR_CODES));
1520
1535
  const ActivityReferenceProps = {
1521
1536
  reference_kind: Schema.Literals(["payment", "movement"]),
1522
1537
  reference_id: Schema.String
@@ -1547,8 +1562,8 @@ const ActivityFilterProps = {
1547
1562
  };
1548
1563
  const ActivityActionProps = {
1549
1564
  ...TelemetryEnvelopeProps,
1550
- scope_kind: Schema.Literals(["account", "organization"]),
1551
- reason_code: Schema.optional(Schema.Literals(CAPXUL_ERROR_CODES))
1565
+ scope_kind: ScopeKindSchema,
1566
+ reason_code: OptionalReasonCode
1552
1567
  };
1553
1568
  const ContactRelationshipChangedTelemetryEventSchema = Schema.Struct({
1554
1569
  name: Schema.Literal("contact_relationship_changed"),
@@ -1560,7 +1575,7 @@ const ContactRelationshipChangedTelemetryEventSchema = Schema.Struct({
1560
1575
  "hidden",
1561
1576
  "restored"
1562
1577
  ]),
1563
- scope_kind: Schema.Literals(["account", "organization"]),
1578
+ scope_kind: ScopeKindSchema,
1564
1579
  scope_id: Schema.String,
1565
1580
  owner_party_id: Schema.String,
1566
1581
  party_id: Schema.String,
@@ -1576,9 +1591,9 @@ const ContactRelationshipChangedTelemetryEventSchema = Schema.Struct({
1576
1591
  });
1577
1592
  const ContactActionProps = {
1578
1593
  ...TelemetryEnvelopeProps,
1579
- scope_kind: Schema.Literals(["account", "organization"]),
1594
+ scope_kind: ScopeKindSchema,
1580
1595
  party_id: OptionalString,
1581
- reason_code: Schema.optional(Schema.Literals(CAPXUL_ERROR_CODES))
1596
+ reason_code: OptionalReasonCode
1582
1597
  };
1583
1598
  const UiContactActionCompletedTelemetryEventSchema = Schema.Struct({
1584
1599
  name: Schema.Literal("ui_contact_action_completed"),
@@ -1605,7 +1620,7 @@ const ActivityAnnotationSavedTelemetryEventSchema = Schema.Struct({
1605
1620
  props: Schema.Struct({
1606
1621
  ...TelemetryEnvelopeProps,
1607
1622
  ...ActivityReferenceProps,
1608
- scope_kind: Schema.Literals(["account", "organization"]),
1623
+ scope_kind: ScopeKindSchema,
1609
1624
  scope_id: Schema.String,
1610
1625
  occurred_at: Schema.Number
1611
1626
  })
@@ -1660,8 +1675,206 @@ const UiActivityActionCompletedTelemetryEventSchema = Schema.Struct({
1660
1675
  })
1661
1676
  ])
1662
1677
  });
1678
+ /**
1679
+ * Reliability closeout (#1960 R02) — the shape every explicit UI observation
1680
+ * below shares. `scope_kind` says whose surface the person was looking at,
1681
+ * `organization_id` is the verified Organization the producer resolved (absent
1682
+ * on a personal action), and `reason_code` is a catalog error code, never copy.
1683
+ */
1684
+ const UiStepProps = {
1685
+ ...TelemetryEnvelopeProps,
1686
+ scope_kind: ScopeKindSchema,
1687
+ organization_id: OptionalOrgId,
1688
+ reason_code: OptionalReasonCode
1689
+ };
1690
+ const AccessRecoveryCompletedProps = Schema.Union([Schema.Struct({
1691
+ ...TelemetryEnvelopeProps,
1692
+ recovery: Schema.Literal("session_restoration"),
1693
+ outcome: Schema.Literals([
1694
+ "restored",
1695
+ "absent",
1696
+ "failed"
1697
+ ]),
1698
+ reason_code: OptionalReasonCode,
1699
+ organization_id: OptionalOrgId
1700
+ }), Schema.Struct({
1701
+ ...TelemetryEnvelopeProps,
1702
+ recovery: Schema.Literal("signer_readiness"),
1703
+ outcome: Schema.Literals(["ready", "unavailable"]),
1704
+ reason_code: OptionalReasonCode,
1705
+ organization_id: OptionalOrgId
1706
+ })]);
1707
+ const AccessRecoveryCompletedTelemetryEventSchema = Schema.Struct({
1708
+ name: Schema.Literal("access_recovery_completed"),
1709
+ props: AccessRecoveryCompletedProps
1710
+ });
1711
+ const UiAccessStepCompletedTelemetryEventSchema = Schema.Struct({
1712
+ name: Schema.Literal("ui_access_step_completed"),
1713
+ props: Schema.Struct({
1714
+ ...UiStepProps,
1715
+ step: Schema.Literals([
1716
+ "dashboard_granted",
1717
+ "redirect_completed",
1718
+ "gate_error_displayed",
1719
+ "retry_selected",
1720
+ "capability_refusal_displayed",
1721
+ "signer_refusal_displayed"
1722
+ ]),
1723
+ capability: Schema.optional(Schema.Literals(["spend", "managePeople"])),
1724
+ probe: Schema.optional(Schema.Literals([
1725
+ "session",
1726
+ "membership",
1727
+ "lifecycle"
1728
+ ])),
1729
+ reason: Schema.optional(Schema.Literals([
1730
+ "loading",
1731
+ "no-permission",
1732
+ "org-unavailable"
1733
+ ]))
1734
+ })
1735
+ });
1736
+ const OrgInviteProgressedTelemetryEventSchema = Schema.Struct({
1737
+ name: Schema.Literal("org_invite_progressed"),
1738
+ props: Schema.Struct({
1739
+ ...TelemetryEnvelopeProps,
1740
+ organization_id: OrgIdTelemetrySchema,
1741
+ progress: Schema.Literals([
1742
+ "account_ready",
1743
+ "permission_applied",
1744
+ "membership_activated",
1745
+ "revoked"
1746
+ ]),
1747
+ /** The invited Party. The initiating actor stays on the envelope's identity. */
1748
+ member_party_id: Schema.String,
1749
+ occurred_at: Schema.Number
1750
+ })
1751
+ });
1752
+ const InvoiceIssuedTelemetryEventSchema = Schema.Struct({
1753
+ name: Schema.Literal("invoice_issued"),
1754
+ props: Schema.Struct({
1755
+ ...TelemetryEnvelopeProps,
1756
+ request_id: Schema.String,
1757
+ issuer_scope_kind: ScopeKindSchema,
1758
+ issuer_scope_id: Schema.String,
1759
+ payer_party_id: OptionalString,
1760
+ occurred_at: Schema.Number
1761
+ })
1762
+ });
1763
+ const InvoiceRequestTransitionedTelemetryEventSchema = Schema.Struct({
1764
+ name: Schema.Literal("invoice_request_transitioned"),
1765
+ props: Schema.Struct({
1766
+ ...TelemetryEnvelopeProps,
1767
+ request_id: Schema.String,
1768
+ transition: Schema.Literals([
1769
+ "approval_prepared",
1770
+ "declined",
1771
+ "cancelled"
1772
+ ]),
1773
+ actor_scope_kind: ScopeKindSchema,
1774
+ actor_scope_id: Schema.String,
1775
+ occurred_at: Schema.Number
1776
+ })
1777
+ });
1778
+ const UiInvoiceStepCompletedTelemetryEventSchema = Schema.Struct({
1779
+ name: Schema.Literal("ui_invoice_step_completed"),
1780
+ props: Schema.Struct({
1781
+ ...UiStepProps,
1782
+ step: Schema.Literals([
1783
+ "opened",
1784
+ "previewed",
1785
+ "dismissed",
1786
+ "submitted",
1787
+ "result_displayed",
1788
+ "refusal_displayed",
1789
+ "retry_selected"
1790
+ ]),
1791
+ request_id: OptionalString
1792
+ })
1793
+ });
1794
+ const UiTreasuryStepCompletedTelemetryEventSchema = Schema.Struct({
1795
+ name: Schema.Literal("ui_treasury_step_completed"),
1796
+ props: Schema.Struct({
1797
+ ...UiStepProps,
1798
+ step: Schema.Literals([
1799
+ "balance_displayed",
1800
+ "read_refusal_displayed",
1801
+ "retry_selected",
1802
+ "recovery_completed"
1803
+ ]),
1804
+ account_kind: Schema.optional(AccountKindSchema)
1805
+ })
1806
+ });
1807
+ const UiReceiveStepCompletedTelemetryEventSchema = Schema.Struct({
1808
+ name: Schema.Literal("ui_receive_step_completed"),
1809
+ props: Schema.Struct({
1810
+ ...UiStepProps,
1811
+ step: Schema.Literals([
1812
+ "instructions_displayed",
1813
+ "address_copied",
1814
+ "copy_failed",
1815
+ "refusal_displayed",
1816
+ "retry_selected"
1817
+ ]),
1818
+ account_kind: Schema.optional(AccountKindSchema)
1819
+ })
1820
+ });
1821
+ const PayrollGroupChangedTelemetryEventSchema = Schema.Struct({
1822
+ name: Schema.Literal("payroll_group_changed"),
1823
+ props: Schema.Struct({
1824
+ ...TelemetryEnvelopeProps,
1825
+ organization_id: OrgIdTelemetrySchema,
1826
+ change: Schema.Literals([
1827
+ "created",
1828
+ "updated",
1829
+ "deleted"
1830
+ ]),
1831
+ group_id: Schema.String,
1832
+ member_count: Schema.Number,
1833
+ occurred_at: Schema.Number
1834
+ })
1835
+ });
1836
+ const PayrollRunTransitionedTelemetryEventSchema = Schema.Struct({
1837
+ name: Schema.Literal("payroll_run_transitioned"),
1838
+ props: Schema.Struct({
1839
+ ...TelemetryEnvelopeProps,
1840
+ organization_id: OrgIdTelemetrySchema,
1841
+ transition: Schema.Literals([
1842
+ "prepared",
1843
+ "authorized",
1844
+ "settled"
1845
+ ]),
1846
+ run_id: Schema.String,
1847
+ payment_count: Schema.optional(Schema.Number),
1848
+ occurred_at: Schema.Number
1849
+ })
1850
+ });
1851
+ const UiPayrollActionCompletedTelemetryEventSchema = Schema.Struct({
1852
+ name: Schema.Literal("ui_payroll_action_completed"),
1853
+ props: Schema.Struct({
1854
+ ...UiStepProps,
1855
+ action: Schema.Literals([
1856
+ "opened",
1857
+ "refusal_displayed",
1858
+ "recovery_completed",
1859
+ "cancelled",
1860
+ "submitted_displayed"
1861
+ ]),
1862
+ run_id: OptionalString
1863
+ })
1864
+ });
1663
1865
  const TELEMETRY_EVENT_SCHEMAS = {
1664
1866
  contact_relationship_changed: ContactRelationshipChangedTelemetryEventSchema,
1867
+ access_recovery_completed: AccessRecoveryCompletedTelemetryEventSchema,
1868
+ ui_access_step_completed: UiAccessStepCompletedTelemetryEventSchema,
1869
+ org_invite_progressed: OrgInviteProgressedTelemetryEventSchema,
1870
+ invoice_issued: InvoiceIssuedTelemetryEventSchema,
1871
+ invoice_request_transitioned: InvoiceRequestTransitionedTelemetryEventSchema,
1872
+ ui_invoice_step_completed: UiInvoiceStepCompletedTelemetryEventSchema,
1873
+ ui_treasury_step_completed: UiTreasuryStepCompletedTelemetryEventSchema,
1874
+ ui_receive_step_completed: UiReceiveStepCompletedTelemetryEventSchema,
1875
+ payroll_group_changed: PayrollGroupChangedTelemetryEventSchema,
1876
+ payroll_run_transitioned: PayrollRunTransitionedTelemetryEventSchema,
1877
+ ui_payroll_action_completed: UiPayrollActionCompletedTelemetryEventSchema,
1665
1878
  ui_contact_action_completed: UiContactActionCompletedTelemetryEventSchema,
1666
1879
  activity_annotation_saved: ActivityAnnotationSavedTelemetryEventSchema,
1667
1880
  ui_activity_action_completed: UiActivityActionCompletedTelemetryEventSchema,
@@ -1670,6 +1883,7 @@ const TELEMETRY_EVENT_SCHEMAS = {
1670
1883
  auth_otp_expired: AuthOtpExpiredTelemetryEventSchema,
1671
1884
  auth_verified: AuthVerifiedTelemetryEventSchema,
1672
1885
  auth_failed: AuthFailedTelemetryEventSchema,
1886
+ identity_refused: IdentityRefusedTelemetryEventSchema,
1673
1887
  auth_signed_out: AuthSignedOutTelemetryEventSchema,
1674
1888
  onboarding_intent_selected: OnboardingIntentSelectedTelemetryEventSchema,
1675
1889
  onboarding_profile_submitted: OnboardingProfileSubmittedTelemetryEventSchema,
@@ -1723,7 +1937,14 @@ const FINANCIAL_OPS_TARGET_TELEMETRY_PRODUCERS = [];
1723
1937
  * A domain node removes its entry when it adds the producer. The telemetry
1724
1938
  * gate rejects an entry that has a producer.
1725
1939
  */
1726
- const CONTRACT_FIRST_TELEMETRY_EVENTS = [];
1940
+ const CONTRACT_FIRST_TELEMETRY_EVENTS = [
1941
+ "access_recovery_completed",
1942
+ "org_invite_progressed",
1943
+ "invoice_issued",
1944
+ "invoice_request_transitioned",
1945
+ "payroll_group_changed",
1946
+ "payroll_run_transitioned"
1947
+ ];
1727
1948
  /**
1728
1949
  * Catalog events whose product mapper remains gated on the #1150 frontend
1729
1950
  * adoption. L1 S1 removes their retired SDK-flow producers without inventing
@@ -1739,7 +1960,12 @@ const BROWSER_GATED_TELEMETRY_EVENTS = [
1739
1960
  "onboarding_organization_submitted",
1740
1961
  "onboarding_dashboard_reached",
1741
1962
  "ui_activity_action_completed",
1742
- "ui_contact_action_completed"
1963
+ "ui_contact_action_completed",
1964
+ "ui_access_step_completed",
1965
+ "ui_invoice_step_completed",
1966
+ "ui_treasury_step_completed",
1967
+ "ui_receive_step_completed",
1968
+ "ui_payroll_action_completed"
1743
1969
  ];
1744
1970
  let trackHandler = () => {};
1745
1971
  function setTrackHandler(handler) {
@@ -1775,22 +2001,24 @@ function redactTelemetryProps(name, props, options = {}) {
1775
2001
  * The callback mutates and returns the supplied event, matching PostHog's
1776
2002
  * `before_send` contract while preserving the event's full structural type.
1777
2003
  */
1778
- function sanitizePostHogBrowserEvent(event) {
2004
+ function sanitizePostHogBrowserEvent(event, urlPolicy = "path-only") {
1779
2005
  if (event === null) return event;
2006
+ const transportToken = event.properties.token;
1780
2007
  const seen = /* @__PURE__ */ new WeakSet();
1781
- sanitizePostHogBrowserValue(event.properties, seen);
1782
- if (event.$set !== void 0) sanitizePostHogBrowserValue(event.$set, seen);
1783
- if (event.$set_once !== void 0) sanitizePostHogBrowserValue(event.$set_once, seen);
2008
+ sanitizePostHogBrowserValue(event.properties, seen, urlPolicy);
2009
+ if (transportToken !== void 0) event.properties.token = transportToken;
2010
+ if (event.$set !== void 0) sanitizePostHogBrowserValue(event.$set, seen, urlPolicy);
2011
+ if (event.$set_once !== void 0) sanitizePostHogBrowserValue(event.$set_once, seen, urlPolicy);
1784
2012
  return event;
1785
2013
  }
1786
2014
  /**
1787
2015
  * Drop local events before transport. Sanitize and stamp every other browser
1788
2016
  * event with `capxul_env` and `producer: "browser"`.
1789
2017
  */
1790
- function createCapxulBeforeSend(capxulEnv) {
2018
+ function createCapxulBeforeSend(capxulEnv, urlPolicy = "path-only") {
1791
2019
  return (event) => {
1792
2020
  if (capxulEnv === "local") return null;
1793
- const sanitized = sanitizePostHogBrowserEvent(event);
2021
+ const sanitized = sanitizePostHogBrowserEvent(event, urlPolicy);
1794
2022
  if (sanitized === null) return sanitized;
1795
2023
  sanitized.properties.capxul_env = capxulEnv;
1796
2024
  sanitized.properties.producer ??= "browser";
@@ -1821,67 +2049,64 @@ function utilityAppAnalytics(input) {
1821
2049
  before_send: createCapxulBeforeSend(input.capxulEnv)
1822
2050
  };
1823
2051
  }
1824
- const CREDENTIAL_HEADERS = /* @__PURE__ */ new Set([
1825
- "authorization",
1826
- "proxy-authorization",
1827
- "proxy-authenticate",
1828
- "www-authenticate",
1829
- "cookie",
1830
- "set-cookie",
1831
- "x-api-key",
1832
- "x-auth-token"
1833
- ]);
1834
- /** Any JSON field whose name says "credential", however it is spelled. */
1835
- const CREDENTIAL_FIELD_NAME = /(?:otp|code|pass(?:word|wd|phrase)?|token|secret|credential|api[_-]?key|private[_-]?key|authorization|cookie|session)/iu;
1836
- /** Secret material in captured text: bearer tokens, JWTs, keys, and credential fields. */
1837
- const NETWORK_TEXT_MASKS = [
1838
- [/\bBearer\s+[^\s,;"]+/giu, "Bearer [REDACTED]"],
1839
- [/\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b/gu, "[REDACTED]"],
1840
- [/\b0x[a-fA-F0-9]{40,}\b/gu, "[REDACTED]"],
1841
- [/\b([A-Za-z_][A-Za-z0-9_.-]*=)[^&\s"]+/gu, "$1[REDACTED]"]
1842
- ];
1843
- /** `"name": "value"` JSON pairs; the name decides whether the value is masked. */
1844
- const JSON_STRING_FIELD = /("([^"\\]*)"\s*:\s*")((?:[^"\\]|\\.)*)(")/gu;
1845
- const QUERY_PAIR = /\b([A-Za-z_][A-Za-z0-9_.-]*=)[^&\s"]+/gu;
1846
- function maskNetworkText(text) {
1847
- return NETWORK_TEXT_MASKS.slice(0, 3).reduce((current, [pattern, replacement]) => current.replace(pattern, replacement), text).replace(JSON_STRING_FIELD, (whole, open, name, _value, close) => CREDENTIAL_FIELD_NAME.test(name) ? `${open}[REDACTED]${close}` : whole).replace(QUERY_PAIR, (whole, name) => CREDENTIAL_FIELD_NAME.test(name) ? `${name}[REDACTED]` : whole);
2052
+ /** In unstructured bodies, preserve text around explicitly named credentials. */
2053
+ const NETWORK_FIELD = /((?:"?)([A-Za-z_][A-Za-z0-9_.-]*)(?:"?)\s*[:=]\s*)("(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|[^\s,;&}]+)/gu;
2054
+ function maskNetworkText(text, context) {
2055
+ return redactSecrets(text).replace(NETWORK_FIELD, (whole, prefix, name, value) => {
2056
+ if (!isCredentialField(name, context)) return whole;
2057
+ const quote = value.startsWith("\"") ? "\"" : value.startsWith("'") ? "'" : "";
2058
+ return `${prefix}${quote}[REDACTED]${quote}`;
2059
+ });
1848
2060
  }
1849
2061
  function maskNetworkHeaders(headers) {
1850
2062
  if (headers === void 0) return void 0;
1851
2063
  const masked = {};
1852
- for (const [name, value] of Object.entries(headers)) masked[name] = CREDENTIAL_HEADERS.has(name.toLowerCase()) ? "[REDACTED]" : maskNetworkText(value);
2064
+ for (const [name, value] of Object.entries(headers)) masked[name] = isCredentialField(name, "header") ? "[REDACTED]" : /^(?:location|content-location|referer)$/iu.test(name) ? redactUrlSecrets(value) : maskNetworkText(value);
1853
2065
  return masked;
1854
2066
  }
1855
- /** Mask by KEY at every depth: a credential-named field loses its whole value. */
1856
- function maskJsonValue(value, depth = 0) {
1857
- if (typeof value === "string") return maskNetworkText(value);
2067
+ function maskJsonValue(value, depth = 0, context) {
2068
+ if (typeof value === "function" || typeof value === "symbol") return "[UNREADABLE]";
2069
+ if (typeof value === "string") return maskNetworkText(value, context);
1858
2070
  if (typeof value !== "object" || value === null) return value;
1859
2071
  if (depth >= 16) return "[REDACTED]";
1860
- if (Array.isArray(value)) return value.map((item) => maskJsonValue(item, depth + 1));
1861
- const masked = {};
1862
- for (const [key, nested] of Object.entries(value)) masked[key] = CREDENTIAL_FIELD_NAME.test(key) ? "[REDACTED]" : maskJsonValue(nested, depth + 1);
2072
+ if (Array.isArray(value)) return value.map((item) => maskJsonValue(item, depth + 1, context));
2073
+ const masked = Object.create(null);
2074
+ for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
2075
+ if (!descriptor.enumerable) continue;
2076
+ masked[key] = isCredentialField(key, context) ? "[REDACTED]" : !("value" in descriptor) ? "[UNREADABLE]" : typeof descriptor.value === "string" && isPostHogUrlProperty(key) ? redactUrlSecrets(descriptor.value) : maskJsonValue(descriptor.value, depth + 1, context);
2077
+ }
1863
2078
  return masked;
1864
2079
  }
1865
- function maskNetworkBody(body) {
1866
- if (typeof body !== "string") return body;
2080
+ function maskNetworkBody(body, context) {
1867
2081
  try {
1868
- const parsed = JSON.parse(body);
1869
- if (typeof parsed === "object" && parsed !== null) return JSON.stringify(maskJsonValue(parsed));
1870
- } catch {}
1871
- return maskNetworkText(body);
2082
+ if (typeof body !== "string") return maskJsonValue(body, 0, context);
2083
+ let parsed;
2084
+ try {
2085
+ parsed = JSON.parse(body);
2086
+ } catch {
2087
+ if (/^[^=&\s]+=[\s\S]*$/u.test(body)) return new URLSearchParams(Array.from(new URLSearchParams(body), ([name, value]) => [name, isCredentialField(name, context) ? "[REDACTED]" : maskNetworkText(value)])).toString();
2088
+ return maskNetworkText(body, context);
2089
+ }
2090
+ return JSON.stringify(maskJsonValue(parsed, 0, context));
2091
+ } catch {
2092
+ return "[UNREADABLE]";
2093
+ }
1872
2094
  }
1873
- /**
1874
- * Replay keeps the request line, status, timing, headers, and bodies, so a
1875
- * failed call carries its evidence. Credential headers and secret material
1876
- * never leave the browser: bearer tokens, cookies, API keys, and the OTP a
1877
- * user just typed are masked before the recording is sent.
1878
- */
2095
+ /** Keep request evidence while masking credential values at the browser boundary. */
1879
2096
  function maskCapturedNetworkRequest(request) {
2097
+ const requestUrl = request.name ?? request.url ?? "";
2098
+ let context;
2099
+ try {
2100
+ const path = new URL(requestUrl, "https://capxul.invalid").pathname;
2101
+ if (/\/(?:auth|oauth|sign-in|signin|login|verify-otp|verify-email)(?:\/|$)/iu.test(path)) context = "authentication";
2102
+ } catch {}
1880
2103
  return {
1881
2104
  ...request,
2105
+ ...request.name === void 0 ? {} : { name: redactUrlSecrets(request.name) },
2106
+ ...request.url === void 0 ? {} : { url: redactUrlSecrets(request.url) },
1882
2107
  requestHeaders: maskNetworkHeaders(request.requestHeaders),
1883
2108
  responseHeaders: maskNetworkHeaders(request.responseHeaders),
1884
- requestBody: maskNetworkBody(request.requestBody),
2109
+ requestBody: maskNetworkBody(request.requestBody, context),
1885
2110
  responseBody: maskNetworkBody(request.responseBody)
1886
2111
  };
1887
2112
  }
@@ -1911,13 +2136,20 @@ function productAppAnalytics(input) {
1911
2136
  save_referrer: false,
1912
2137
  session_recording: {
1913
2138
  maskAllInputs: true,
1914
- maskInputFn: (text, element) => element?.getAttribute("autocomplete")?.toLowerCase().split(/\s+/u).includes("one-time-code") ? "*".repeat(text.length) : text,
2139
+ maskInputFn: (text, element) => {
2140
+ const autocomplete = element?.getAttribute("autocomplete")?.toLowerCase().split(/\s+/u) ?? [];
2141
+ return element?.getAttribute("type")?.toLowerCase() === "password" || autocomplete.some((value) => [
2142
+ "one-time-code",
2143
+ "current-password",
2144
+ "new-password"
2145
+ ].includes(value)) || isCredentialField(element?.getAttribute("name") ?? "") || isCredentialField(element?.getAttribute("id") ?? "") ? "*".repeat(text.length) : maskNetworkText(text);
2146
+ },
1915
2147
  captureCanvas: { recordCanvas: false },
1916
2148
  recordHeaders: true,
1917
2149
  recordBody: true,
1918
2150
  maskCapturedNetworkRequestFn: maskCapturedNetworkRequest
1919
2151
  },
1920
- before_send: createCapxulBeforeSend(input.capxulEnv)
2152
+ before_send: createCapxulBeforeSend(input.capxulEnv, "diagnostic")
1921
2153
  };
1922
2154
  }
1923
2155
  /**
@@ -1974,11 +2206,15 @@ function createPostHogBrowserPageviewTracker(client) {
1974
2206
  } catch {}
1975
2207
  };
1976
2208
  }
1977
- function sanitizePostHogBrowserValue(value, seen) {
2209
+ function sanitizePostHogBrowserValue(value, seen, urlPolicy) {
1978
2210
  if (typeof value !== "object" || value === null || seen.has(value)) return;
1979
2211
  seen.add(value);
1980
2212
  if (Array.isArray(value)) {
1981
- for (const item of value) sanitizePostHogBrowserValue(item, seen);
2213
+ for (let index = 0; index < value.length; index++) {
2214
+ const item = value[index];
2215
+ if (typeof item === "string") value[index] = maskNetworkText(item);
2216
+ else sanitizePostHogBrowserValue(item, seen, urlPolicy);
2217
+ }
1982
2218
  return;
1983
2219
  }
1984
2220
  const properties = value;
@@ -1987,11 +2223,15 @@ function sanitizePostHogBrowserValue(value, seen) {
1987
2223
  delete properties[key];
1988
2224
  continue;
1989
2225
  }
1990
- if (typeof nestedValue === "string" && isPostHogUrlProperty(key)) {
1991
- properties[key] = stripUrlQueryAndFragment(nestedValue);
2226
+ if (isCredentialField(key)) {
2227
+ properties[key] = "[REDACTED]";
2228
+ continue;
2229
+ }
2230
+ if (typeof nestedValue === "string") {
2231
+ properties[key] = isPostHogUrlProperty(key) ? urlPolicy === "path-only" ? stripUrlQueryAndFragment(nestedValue) : redactUrlSecrets(nestedValue) : maskNetworkText(nestedValue);
1992
2232
  continue;
1993
2233
  }
1994
- sanitizePostHogBrowserValue(nestedValue, seen);
2234
+ sanitizePostHogBrowserValue(nestedValue, seen, urlPolicy);
1995
2235
  }
1996
2236
  }
1997
2237
  const POSTHOG_QUERY_DERIVED_PROPERTY_NAMES = [
@@ -2307,4 +2547,4 @@ function rotr(value, bits) {
2307
2547
  return value >>> bits | value << 32 - bits;
2308
2548
  }
2309
2549
  //#endregion
2310
- export { AccountBalanceFailedTelemetryEventSchema, AccountBalanceReadTelemetryEventSchema, ActivityAnnotationSavedTelemetryEventSchema, AuthFailedTelemetryEventSchema, AuthOtpDeliveredTelemetryEventSchema, AuthOtpExpiredTelemetryEventSchema, AuthOtpRequestedTelemetryEventSchema, AuthSignedOutTelemetryEventSchema, AuthVerifiedTelemetryEventSchema, BROWSER_GATED_TELEMETRY_EVENTS, BootstrapFailedTelemetryEventSchema, BootstrapResolvedTelemetryEventSchema, BundlerErrorTelemetryEventSchema, CAPXUL_ENVS, CAPXUL_OPERATIONS, CONTRACT_FIRST_TELEMETRY_EVENTS, ChainAttemptSchema, ChainUpstreamFallbackTelemetryEventSchema, ChainUpstreamSchema, ContactRelationshipChangedTelemetryEventSchema, DepositInitiatedTelemetryEventSchema, DepositSettledTelemetryEventSchema, FINANCIAL_OPS_TARGET_TELEMETRY_PRODUCERS, FailureModeSchema, FaucetConfirmedTelemetryEventSchema, FaucetFailedTelemetryEventSchema, FaucetRequestedTelemetryEventSchema, InMemoryTelemetryBusAdapter, MemberActivationFailedTelemetryEventSchema, MemberActivationReadyTelemetryEventSchema, MemberActivationStartedTelemetryEventSchema, MovementScanCheckpointTelemetryEventSchema, MovementScanIncidentTelemetryEventSchema, MovementScanWindowTelemetryEventSchema, OnboardingDashboardReachedTelemetryEventSchema, OnboardingIntentSelectedTelemetryEventSchema, OnboardingOrganizationSubmittedTelemetryEventSchema, OnboardingProfileSubmittedTelemetryEventSchema, OperationRetriedTelemetryEventSchema, OrgCreateFailedTelemetryEventSchema, OrgCreateStartedTelemetryEventSchema, OrgCreatedTelemetryEventSchema, OrgInviteAcceptedTelemetryEventSchema, OrgInviteExpiredTelemetryEventSchema, OrgInviteSentTelemetryEventSchema, OrgRolesSeededTelemetryEventSchema, OrgSafeConfirmedTelemetryEventSchema, OrgSafeCreatedTelemetryEventSchema, OrganizationCreationFailedTelemetryEventSchema, OrganizationCreationReadyTelemetryEventSchema, OrganizationCreationStartedTelemetryEventSchema, PII, PRODUCT_MAPPER_GATED_TELEMETRY_EVENTS, PaymentFailedTelemetryEventSchema, PaymentInitiatedTelemetryEventSchema, PaymentLifecycleTransitionTelemetryEventSchema, PaymentSettledTelemetryEventSchema, PaymentVerificationRetryTelemetryEventSchema, PermissionMirrorVerificationTelemetryEventSchema, PostHogTelemetryAdapter, ProvisioningSafeConfirmedTelemetryEventSchema, ProvisioningSafeCreatedTelemetryEventSchema, QuickPayExternalAddressAcknowledgedTelemetryEventSchema, ReceiptPendingTelemetryEventSchema, RecordingTelemetryAdapter, ResponseHeadersSchema, SYNCABLE_CAPXUL_ENVS, TELEMETRY_EVENT_NAMES, TELEMETRY_EVENT_SCHEMAS, TELEMETRY_JOURNEYS, TELEMETRY_PRODUCERS, UiActivityActionCompletedTelemetryEventSchema, UiContactActionCompletedTelemetryEventSchema, createCapxulBeforeSend, createPostHogBrowserPageviewTracker, getTrackHandler, initializeCapxulBrowserAnalytics, initializePostHogBrowserAnalytics, isCapxulOperation, maskCapturedNetworkRequest, normalizeCapxulOperation, productAppAnalytics, redactTelemetryEvent, redactTelemetryProps, sanitizePostHogBrowserEvent, setTrackHandler, stampTelemetryEnvelope, track, utilityAppAnalytics };
2550
+ export { AccessRecoveryCompletedTelemetryEventSchema, AccountBalanceFailedTelemetryEventSchema, AccountBalanceReadTelemetryEventSchema, ActivityAnnotationSavedTelemetryEventSchema, AuthFailedTelemetryEventSchema, AuthOtpDeliveredTelemetryEventSchema, AuthOtpExpiredTelemetryEventSchema, AuthOtpRequestedTelemetryEventSchema, AuthSignedOutTelemetryEventSchema, AuthVerifiedTelemetryEventSchema, BROWSER_GATED_TELEMETRY_EVENTS, BootstrapFailedTelemetryEventSchema, BootstrapResolvedTelemetryEventSchema, BundlerErrorTelemetryEventSchema, CAPXUL_ENVS, CAPXUL_OPERATIONS, CONTRACT_FIRST_TELEMETRY_EVENTS, ChainAttemptSchema, ChainUpstreamFallbackTelemetryEventSchema, ChainUpstreamSchema, ContactRelationshipChangedTelemetryEventSchema, DepositInitiatedTelemetryEventSchema, DepositSettledTelemetryEventSchema, FINANCIAL_OPS_TARGET_TELEMETRY_PRODUCERS, FailureModeSchema, FaucetConfirmedTelemetryEventSchema, FaucetFailedTelemetryEventSchema, FaucetRequestedTelemetryEventSchema, IdentityRefusedTelemetryEventSchema, InMemoryTelemetryBusAdapter, InvoiceIssuedTelemetryEventSchema, InvoiceRequestTransitionedTelemetryEventSchema, MemberActivationFailedTelemetryEventSchema, MemberActivationReadyTelemetryEventSchema, MemberActivationStartedTelemetryEventSchema, MovementScanCheckpointTelemetryEventSchema, MovementScanIncidentTelemetryEventSchema, MovementScanWindowTelemetryEventSchema, OnboardingDashboardReachedTelemetryEventSchema, OnboardingIntentSelectedTelemetryEventSchema, OnboardingOrganizationSubmittedTelemetryEventSchema, OnboardingProfileSubmittedTelemetryEventSchema, OperationRetriedTelemetryEventSchema, OrgCreateFailedTelemetryEventSchema, OrgCreateStartedTelemetryEventSchema, OrgCreatedTelemetryEventSchema, OrgInviteAcceptedTelemetryEventSchema, OrgInviteExpiredTelemetryEventSchema, OrgInviteProgressedTelemetryEventSchema, OrgInviteSentTelemetryEventSchema, OrgRolesSeededTelemetryEventSchema, OrgSafeConfirmedTelemetryEventSchema, OrgSafeCreatedTelemetryEventSchema, OrganizationCreationFailedTelemetryEventSchema, OrganizationCreationReadyTelemetryEventSchema, OrganizationCreationStartedTelemetryEventSchema, PII, PRODUCT_MAPPER_GATED_TELEMETRY_EVENTS, PaymentFailedTelemetryEventSchema, PaymentInitiatedTelemetryEventSchema, PaymentLifecycleTransitionTelemetryEventSchema, PaymentSettledTelemetryEventSchema, PaymentVerificationRetryTelemetryEventSchema, PayrollGroupChangedTelemetryEventSchema, PayrollRunTransitionedTelemetryEventSchema, PermissionMirrorVerificationTelemetryEventSchema, PostHogTelemetryAdapter, ProvisioningSafeConfirmedTelemetryEventSchema, ProvisioningSafeCreatedTelemetryEventSchema, QuickPayExternalAddressAcknowledgedTelemetryEventSchema, ReceiptPendingTelemetryEventSchema, RecordingTelemetryAdapter, ResponseHeadersSchema, SYNCABLE_CAPXUL_ENVS, TELEMETRY_EVENT_NAMES, TELEMETRY_EVENT_SCHEMAS, TELEMETRY_JOURNEYS, TELEMETRY_PRODUCERS, UiAccessStepCompletedTelemetryEventSchema, UiActivityActionCompletedTelemetryEventSchema, UiContactActionCompletedTelemetryEventSchema, UiInvoiceStepCompletedTelemetryEventSchema, UiPayrollActionCompletedTelemetryEventSchema, UiReceiveStepCompletedTelemetryEventSchema, UiTreasuryStepCompletedTelemetryEventSchema, createCapxulBeforeSend, createPostHogBrowserPageviewTracker, getTrackHandler, initializeCapxulBrowserAnalytics, initializePostHogBrowserAnalytics, isCapxulOperation, maskCapturedNetworkRequest, normalizeCapxulOperation, productAppAnalytics, redactTelemetryEvent, redactTelemetryProps, sanitizePostHogBrowserEvent, setTrackHandler, stampTelemetryEnvelope, track, utilityAppAnalytics };