crumbtrail-react 0.2.0
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/LICENSE +21 -0
- package/dist/index.cjs +226 -0
- package/dist/index.d.cts +32 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +198 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Crumbtrail
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
CrumbtrailErrorBoundary: () => CrumbtrailErrorBoundary,
|
|
24
|
+
useBugState: () => useBugState
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
|
|
28
|
+
// src/use-bug-state.ts
|
|
29
|
+
var import_react = require("react");
|
|
30
|
+
var REDACTED_VALUE = "[REDACTED]";
|
|
31
|
+
var SENSITIVE_NAME_RE = /(^|[^a-z0-9])(access[-_]?token|api[-_]?key|auth|authorization|bearer|card[-_]?number|client[-_]?secret|cookie|credential(s)?|creds|csrf|cvv|cvc|id[-_]?token|jsessionid|jwt|mfa|otp|pass[-_]?phrase|pass(code|word)?|passwd|password[-_]?confirmation|pin|private[-_]?key|pwd|refresh[-_]?token|secret|security[-_]?code|session|session[-_]?id|sid|ssn|token|verification[-_]?code|xsrf)([^a-z0-9]|$)/i;
|
|
32
|
+
var PII_NAME_RE = /(^|[^a-z0-9])(email|phone|address|dob|birthdate|postal|zip)([^a-z0-9]|$)/i;
|
|
33
|
+
var SENSITIVE_COMPACT_NAMES = /* @__PURE__ */ new Set([
|
|
34
|
+
"accesskey",
|
|
35
|
+
"accesstoken",
|
|
36
|
+
"accesstokens",
|
|
37
|
+
"apikey",
|
|
38
|
+
"apikeys",
|
|
39
|
+
"apisecret",
|
|
40
|
+
"apisecrets",
|
|
41
|
+
"auth",
|
|
42
|
+
"authentication",
|
|
43
|
+
"authenticationinfo",
|
|
44
|
+
"authkey",
|
|
45
|
+
"authtoken",
|
|
46
|
+
"authorization",
|
|
47
|
+
"authorizationinfo",
|
|
48
|
+
"bearer",
|
|
49
|
+
"cardnumber",
|
|
50
|
+
"clientsecret",
|
|
51
|
+
"clientsecrets",
|
|
52
|
+
"cookie",
|
|
53
|
+
"credentials",
|
|
54
|
+
"creds",
|
|
55
|
+
"csrf",
|
|
56
|
+
"csrfkey",
|
|
57
|
+
"csrftoken",
|
|
58
|
+
"cvc",
|
|
59
|
+
"cvv",
|
|
60
|
+
"idtoken",
|
|
61
|
+
"idtokens",
|
|
62
|
+
"jsessionid",
|
|
63
|
+
"jwt",
|
|
64
|
+
"mfa",
|
|
65
|
+
"otp",
|
|
66
|
+
"passcode",
|
|
67
|
+
"passphrase",
|
|
68
|
+
"passwd",
|
|
69
|
+
"password",
|
|
70
|
+
"passwordconfirmation",
|
|
71
|
+
"passwords",
|
|
72
|
+
"pin",
|
|
73
|
+
"privatekey",
|
|
74
|
+
"proxyauthentication",
|
|
75
|
+
"proxyauthenticationinfo",
|
|
76
|
+
"pwd",
|
|
77
|
+
"refreshtoken",
|
|
78
|
+
"refreshtokens",
|
|
79
|
+
"secret",
|
|
80
|
+
"secrets",
|
|
81
|
+
"securitycode",
|
|
82
|
+
"session",
|
|
83
|
+
"sessionid",
|
|
84
|
+
"sessiontoken",
|
|
85
|
+
"sessiontokens",
|
|
86
|
+
"sid",
|
|
87
|
+
"ssn",
|
|
88
|
+
"token",
|
|
89
|
+
"tokenkey",
|
|
90
|
+
"tokens",
|
|
91
|
+
"verificationcode",
|
|
92
|
+
"xapikey",
|
|
93
|
+
"xauthkey",
|
|
94
|
+
"xauthtoken",
|
|
95
|
+
"xcsrf",
|
|
96
|
+
"xcsrfkey",
|
|
97
|
+
"xcsrftoken",
|
|
98
|
+
"xsrf",
|
|
99
|
+
"xsrfkey",
|
|
100
|
+
"xsrftoken",
|
|
101
|
+
"xxsrf",
|
|
102
|
+
"xxsrfkey",
|
|
103
|
+
"xxsrftoken"
|
|
104
|
+
]);
|
|
105
|
+
var SENSITIVE_COMPACT_SUFFIXES = [
|
|
106
|
+
"accesstoken",
|
|
107
|
+
"accesstokens",
|
|
108
|
+
"apikey",
|
|
109
|
+
"apikeys",
|
|
110
|
+
"apisecret",
|
|
111
|
+
"apisecrets",
|
|
112
|
+
"authtoken",
|
|
113
|
+
"clientsecret",
|
|
114
|
+
"clientsecrets",
|
|
115
|
+
"csrftoken",
|
|
116
|
+
"idtoken",
|
|
117
|
+
"idtokens",
|
|
118
|
+
"privatekey",
|
|
119
|
+
"refreshtoken",
|
|
120
|
+
"refreshtokens",
|
|
121
|
+
"sessiontoken",
|
|
122
|
+
"sessiontokens",
|
|
123
|
+
"xsrftoken"
|
|
124
|
+
];
|
|
125
|
+
var TOKEN_RE = /\b(?:Bearer|Token|Basic)\s+[A-Za-z0-9._~+/=-]{8,}\b|\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b|(?:sk|pk|rk|ghp|gho|ghu|ghs|glpat|xox[baprs])[-_][A-Za-z0-9_.=-]{12,}|\b[A-Fa-f0-9]{32,}\b|\b[A-Za-z0-9_-]{40,}\b/gi;
|
|
126
|
+
var JSON_LIKE_KEY_RE = /["']?([A-Za-z0-9_.-]{1,120})["']?\s*:/g;
|
|
127
|
+
function isSensitiveName(name) {
|
|
128
|
+
const normalized = name.replace(/([a-z])([A-Z])/g, "$1_$2");
|
|
129
|
+
const compact = normalized.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
130
|
+
return SENSITIVE_NAME_RE.test(name) || PII_NAME_RE.test(name) || SENSITIVE_NAME_RE.test(normalized) || PII_NAME_RE.test(normalized) || SENSITIVE_COMPACT_NAMES.has(compact) || SENSITIVE_COMPACT_SUFFIXES.some(
|
|
131
|
+
(suffix) => compact.length > suffix.length && compact.endsWith(suffix)
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
function redactJsonLikeString(value) {
|
|
135
|
+
const trimmed = value.trim();
|
|
136
|
+
if (!/[{[]/.test(value)) return void 0;
|
|
137
|
+
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
138
|
+
try {
|
|
139
|
+
const parsed = JSON.parse(value);
|
|
140
|
+
return JSON.stringify(redactReactSnapshot(parsed));
|
|
141
|
+
} catch {
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
JSON_LIKE_KEY_RE.lastIndex = 0;
|
|
145
|
+
for (const match of value.matchAll(JSON_LIKE_KEY_RE)) {
|
|
146
|
+
const key = match[1];
|
|
147
|
+
if (key && isSensitiveName(key)) return REDACTED_VALUE;
|
|
148
|
+
}
|
|
149
|
+
return void 0;
|
|
150
|
+
}
|
|
151
|
+
function redactReactSnapshot(value, keyName) {
|
|
152
|
+
if (keyName && isSensitiveName(keyName)) return REDACTED_VALUE;
|
|
153
|
+
if (typeof value === "string") {
|
|
154
|
+
const jsonLike = redactJsonLikeString(value);
|
|
155
|
+
if (jsonLike !== void 0) return jsonLike;
|
|
156
|
+
if (/^\s*[^:=\n\r]{1,120}\s*[:=]/.test(value)) {
|
|
157
|
+
return value.replace(
|
|
158
|
+
/^(\s*[^:=\n\r]{1,120}\s*[:=]).*$/s,
|
|
159
|
+
(_match, key) => {
|
|
160
|
+
return isSensitiveName(key) ? `${key}${REDACTED_VALUE}` : value.replace(TOKEN_RE, REDACTED_VALUE);
|
|
161
|
+
}
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
return value.replace(TOKEN_RE, REDACTED_VALUE);
|
|
165
|
+
}
|
|
166
|
+
if (Array.isArray(value))
|
|
167
|
+
return value.map((entry) => redactReactSnapshot(entry));
|
|
168
|
+
if (value && typeof value === "object") {
|
|
169
|
+
const output = {};
|
|
170
|
+
for (const [key, entry] of Object.entries(
|
|
171
|
+
value
|
|
172
|
+
)) {
|
|
173
|
+
output[key] = redactReactSnapshot(entry, key);
|
|
174
|
+
}
|
|
175
|
+
return output;
|
|
176
|
+
}
|
|
177
|
+
return value;
|
|
178
|
+
}
|
|
179
|
+
function useBugState(logger, name, value, options = {}) {
|
|
180
|
+
const valueRef = (0, import_react.useRef)(value);
|
|
181
|
+
valueRef.current = value;
|
|
182
|
+
(0, import_react.useEffect)(() => {
|
|
183
|
+
if (!logger || typeof logger.registerStateProvider !== "function") return;
|
|
184
|
+
return logger.registerStateProvider(
|
|
185
|
+
name,
|
|
186
|
+
() => options.captureRawState ? valueRef.current : redactReactSnapshot(valueRef.current)
|
|
187
|
+
);
|
|
188
|
+
}, [logger, name, options.captureRawState]);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// src/error-boundary.ts
|
|
192
|
+
var import_react2 = require("react");
|
|
193
|
+
var CrumbtrailErrorBoundary = class extends import_react2.Component {
|
|
194
|
+
constructor(props) {
|
|
195
|
+
super(props);
|
|
196
|
+
this.state = { hasError: false };
|
|
197
|
+
}
|
|
198
|
+
static getDerivedStateFromError(_error) {
|
|
199
|
+
return { hasError: true };
|
|
200
|
+
}
|
|
201
|
+
componentDidCatch(error, errorInfo) {
|
|
202
|
+
this.props.logger.addEvent({
|
|
203
|
+
type: "err",
|
|
204
|
+
data: {
|
|
205
|
+
msg: redactReactSnapshot(error.message),
|
|
206
|
+
stack: redactReactSnapshot(error.stack),
|
|
207
|
+
componentStack: redactReactSnapshot(errorInfo.componentStack),
|
|
208
|
+
source: "react-error-boundary"
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
resetError() {
|
|
213
|
+
this.setState({ hasError: false });
|
|
214
|
+
}
|
|
215
|
+
render() {
|
|
216
|
+
if (this.state.hasError) {
|
|
217
|
+
return this.props.fallback ?? null;
|
|
218
|
+
}
|
|
219
|
+
return this.props.children;
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
223
|
+
0 && (module.exports = {
|
|
224
|
+
CrumbtrailErrorBoundary,
|
|
225
|
+
useBugState
|
|
226
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Component, ReactNode, ErrorInfo } from 'react';
|
|
2
|
+
|
|
3
|
+
interface BugStateLogger {
|
|
4
|
+
registerStateProvider(name: string, provider: () => unknown): () => void;
|
|
5
|
+
}
|
|
6
|
+
interface UseBugStateOptions {
|
|
7
|
+
captureRawState?: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare function useBugState(logger: BugStateLogger | null | undefined, name: string, value: unknown, options?: UseBugStateOptions): void;
|
|
10
|
+
|
|
11
|
+
interface CrumbtrailErrorBoundaryProps {
|
|
12
|
+
logger: BugStateLogger & {
|
|
13
|
+
addEvent(partial: {
|
|
14
|
+
type: string;
|
|
15
|
+
data: Record<string, unknown>;
|
|
16
|
+
}): void;
|
|
17
|
+
};
|
|
18
|
+
children: ReactNode;
|
|
19
|
+
fallback?: ReactNode;
|
|
20
|
+
}
|
|
21
|
+
interface State {
|
|
22
|
+
hasError: boolean;
|
|
23
|
+
}
|
|
24
|
+
declare class CrumbtrailErrorBoundary extends Component<CrumbtrailErrorBoundaryProps, State> {
|
|
25
|
+
constructor(props: CrumbtrailErrorBoundaryProps);
|
|
26
|
+
static getDerivedStateFromError(_error: Error): State;
|
|
27
|
+
componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
|
|
28
|
+
resetError(): void;
|
|
29
|
+
render(): ReactNode;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { type BugStateLogger, CrumbtrailErrorBoundary, type CrumbtrailErrorBoundaryProps, useBugState };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Component, ReactNode, ErrorInfo } from 'react';
|
|
2
|
+
|
|
3
|
+
interface BugStateLogger {
|
|
4
|
+
registerStateProvider(name: string, provider: () => unknown): () => void;
|
|
5
|
+
}
|
|
6
|
+
interface UseBugStateOptions {
|
|
7
|
+
captureRawState?: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare function useBugState(logger: BugStateLogger | null | undefined, name: string, value: unknown, options?: UseBugStateOptions): void;
|
|
10
|
+
|
|
11
|
+
interface CrumbtrailErrorBoundaryProps {
|
|
12
|
+
logger: BugStateLogger & {
|
|
13
|
+
addEvent(partial: {
|
|
14
|
+
type: string;
|
|
15
|
+
data: Record<string, unknown>;
|
|
16
|
+
}): void;
|
|
17
|
+
};
|
|
18
|
+
children: ReactNode;
|
|
19
|
+
fallback?: ReactNode;
|
|
20
|
+
}
|
|
21
|
+
interface State {
|
|
22
|
+
hasError: boolean;
|
|
23
|
+
}
|
|
24
|
+
declare class CrumbtrailErrorBoundary extends Component<CrumbtrailErrorBoundaryProps, State> {
|
|
25
|
+
constructor(props: CrumbtrailErrorBoundaryProps);
|
|
26
|
+
static getDerivedStateFromError(_error: Error): State;
|
|
27
|
+
componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
|
|
28
|
+
resetError(): void;
|
|
29
|
+
render(): ReactNode;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { type BugStateLogger, CrumbtrailErrorBoundary, type CrumbtrailErrorBoundaryProps, useBugState };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
// src/use-bug-state.ts
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
3
|
+
var REDACTED_VALUE = "[REDACTED]";
|
|
4
|
+
var SENSITIVE_NAME_RE = /(^|[^a-z0-9])(access[-_]?token|api[-_]?key|auth|authorization|bearer|card[-_]?number|client[-_]?secret|cookie|credential(s)?|creds|csrf|cvv|cvc|id[-_]?token|jsessionid|jwt|mfa|otp|pass[-_]?phrase|pass(code|word)?|passwd|password[-_]?confirmation|pin|private[-_]?key|pwd|refresh[-_]?token|secret|security[-_]?code|session|session[-_]?id|sid|ssn|token|verification[-_]?code|xsrf)([^a-z0-9]|$)/i;
|
|
5
|
+
var PII_NAME_RE = /(^|[^a-z0-9])(email|phone|address|dob|birthdate|postal|zip)([^a-z0-9]|$)/i;
|
|
6
|
+
var SENSITIVE_COMPACT_NAMES = /* @__PURE__ */ new Set([
|
|
7
|
+
"accesskey",
|
|
8
|
+
"accesstoken",
|
|
9
|
+
"accesstokens",
|
|
10
|
+
"apikey",
|
|
11
|
+
"apikeys",
|
|
12
|
+
"apisecret",
|
|
13
|
+
"apisecrets",
|
|
14
|
+
"auth",
|
|
15
|
+
"authentication",
|
|
16
|
+
"authenticationinfo",
|
|
17
|
+
"authkey",
|
|
18
|
+
"authtoken",
|
|
19
|
+
"authorization",
|
|
20
|
+
"authorizationinfo",
|
|
21
|
+
"bearer",
|
|
22
|
+
"cardnumber",
|
|
23
|
+
"clientsecret",
|
|
24
|
+
"clientsecrets",
|
|
25
|
+
"cookie",
|
|
26
|
+
"credentials",
|
|
27
|
+
"creds",
|
|
28
|
+
"csrf",
|
|
29
|
+
"csrfkey",
|
|
30
|
+
"csrftoken",
|
|
31
|
+
"cvc",
|
|
32
|
+
"cvv",
|
|
33
|
+
"idtoken",
|
|
34
|
+
"idtokens",
|
|
35
|
+
"jsessionid",
|
|
36
|
+
"jwt",
|
|
37
|
+
"mfa",
|
|
38
|
+
"otp",
|
|
39
|
+
"passcode",
|
|
40
|
+
"passphrase",
|
|
41
|
+
"passwd",
|
|
42
|
+
"password",
|
|
43
|
+
"passwordconfirmation",
|
|
44
|
+
"passwords",
|
|
45
|
+
"pin",
|
|
46
|
+
"privatekey",
|
|
47
|
+
"proxyauthentication",
|
|
48
|
+
"proxyauthenticationinfo",
|
|
49
|
+
"pwd",
|
|
50
|
+
"refreshtoken",
|
|
51
|
+
"refreshtokens",
|
|
52
|
+
"secret",
|
|
53
|
+
"secrets",
|
|
54
|
+
"securitycode",
|
|
55
|
+
"session",
|
|
56
|
+
"sessionid",
|
|
57
|
+
"sessiontoken",
|
|
58
|
+
"sessiontokens",
|
|
59
|
+
"sid",
|
|
60
|
+
"ssn",
|
|
61
|
+
"token",
|
|
62
|
+
"tokenkey",
|
|
63
|
+
"tokens",
|
|
64
|
+
"verificationcode",
|
|
65
|
+
"xapikey",
|
|
66
|
+
"xauthkey",
|
|
67
|
+
"xauthtoken",
|
|
68
|
+
"xcsrf",
|
|
69
|
+
"xcsrfkey",
|
|
70
|
+
"xcsrftoken",
|
|
71
|
+
"xsrf",
|
|
72
|
+
"xsrfkey",
|
|
73
|
+
"xsrftoken",
|
|
74
|
+
"xxsrf",
|
|
75
|
+
"xxsrfkey",
|
|
76
|
+
"xxsrftoken"
|
|
77
|
+
]);
|
|
78
|
+
var SENSITIVE_COMPACT_SUFFIXES = [
|
|
79
|
+
"accesstoken",
|
|
80
|
+
"accesstokens",
|
|
81
|
+
"apikey",
|
|
82
|
+
"apikeys",
|
|
83
|
+
"apisecret",
|
|
84
|
+
"apisecrets",
|
|
85
|
+
"authtoken",
|
|
86
|
+
"clientsecret",
|
|
87
|
+
"clientsecrets",
|
|
88
|
+
"csrftoken",
|
|
89
|
+
"idtoken",
|
|
90
|
+
"idtokens",
|
|
91
|
+
"privatekey",
|
|
92
|
+
"refreshtoken",
|
|
93
|
+
"refreshtokens",
|
|
94
|
+
"sessiontoken",
|
|
95
|
+
"sessiontokens",
|
|
96
|
+
"xsrftoken"
|
|
97
|
+
];
|
|
98
|
+
var TOKEN_RE = /\b(?:Bearer|Token|Basic)\s+[A-Za-z0-9._~+/=-]{8,}\b|\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b|(?:sk|pk|rk|ghp|gho|ghu|ghs|glpat|xox[baprs])[-_][A-Za-z0-9_.=-]{12,}|\b[A-Fa-f0-9]{32,}\b|\b[A-Za-z0-9_-]{40,}\b/gi;
|
|
99
|
+
var JSON_LIKE_KEY_RE = /["']?([A-Za-z0-9_.-]{1,120})["']?\s*:/g;
|
|
100
|
+
function isSensitiveName(name) {
|
|
101
|
+
const normalized = name.replace(/([a-z])([A-Z])/g, "$1_$2");
|
|
102
|
+
const compact = normalized.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
103
|
+
return SENSITIVE_NAME_RE.test(name) || PII_NAME_RE.test(name) || SENSITIVE_NAME_RE.test(normalized) || PII_NAME_RE.test(normalized) || SENSITIVE_COMPACT_NAMES.has(compact) || SENSITIVE_COMPACT_SUFFIXES.some(
|
|
104
|
+
(suffix) => compact.length > suffix.length && compact.endsWith(suffix)
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
function redactJsonLikeString(value) {
|
|
108
|
+
const trimmed = value.trim();
|
|
109
|
+
if (!/[{[]/.test(value)) return void 0;
|
|
110
|
+
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
111
|
+
try {
|
|
112
|
+
const parsed = JSON.parse(value);
|
|
113
|
+
return JSON.stringify(redactReactSnapshot(parsed));
|
|
114
|
+
} catch {
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
JSON_LIKE_KEY_RE.lastIndex = 0;
|
|
118
|
+
for (const match of value.matchAll(JSON_LIKE_KEY_RE)) {
|
|
119
|
+
const key = match[1];
|
|
120
|
+
if (key && isSensitiveName(key)) return REDACTED_VALUE;
|
|
121
|
+
}
|
|
122
|
+
return void 0;
|
|
123
|
+
}
|
|
124
|
+
function redactReactSnapshot(value, keyName) {
|
|
125
|
+
if (keyName && isSensitiveName(keyName)) return REDACTED_VALUE;
|
|
126
|
+
if (typeof value === "string") {
|
|
127
|
+
const jsonLike = redactJsonLikeString(value);
|
|
128
|
+
if (jsonLike !== void 0) return jsonLike;
|
|
129
|
+
if (/^\s*[^:=\n\r]{1,120}\s*[:=]/.test(value)) {
|
|
130
|
+
return value.replace(
|
|
131
|
+
/^(\s*[^:=\n\r]{1,120}\s*[:=]).*$/s,
|
|
132
|
+
(_match, key) => {
|
|
133
|
+
return isSensitiveName(key) ? `${key}${REDACTED_VALUE}` : value.replace(TOKEN_RE, REDACTED_VALUE);
|
|
134
|
+
}
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
return value.replace(TOKEN_RE, REDACTED_VALUE);
|
|
138
|
+
}
|
|
139
|
+
if (Array.isArray(value))
|
|
140
|
+
return value.map((entry) => redactReactSnapshot(entry));
|
|
141
|
+
if (value && typeof value === "object") {
|
|
142
|
+
const output = {};
|
|
143
|
+
for (const [key, entry] of Object.entries(
|
|
144
|
+
value
|
|
145
|
+
)) {
|
|
146
|
+
output[key] = redactReactSnapshot(entry, key);
|
|
147
|
+
}
|
|
148
|
+
return output;
|
|
149
|
+
}
|
|
150
|
+
return value;
|
|
151
|
+
}
|
|
152
|
+
function useBugState(logger, name, value, options = {}) {
|
|
153
|
+
const valueRef = useRef(value);
|
|
154
|
+
valueRef.current = value;
|
|
155
|
+
useEffect(() => {
|
|
156
|
+
if (!logger || typeof logger.registerStateProvider !== "function") return;
|
|
157
|
+
return logger.registerStateProvider(
|
|
158
|
+
name,
|
|
159
|
+
() => options.captureRawState ? valueRef.current : redactReactSnapshot(valueRef.current)
|
|
160
|
+
);
|
|
161
|
+
}, [logger, name, options.captureRawState]);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// src/error-boundary.ts
|
|
165
|
+
import { Component } from "react";
|
|
166
|
+
var CrumbtrailErrorBoundary = class extends Component {
|
|
167
|
+
constructor(props) {
|
|
168
|
+
super(props);
|
|
169
|
+
this.state = { hasError: false };
|
|
170
|
+
}
|
|
171
|
+
static getDerivedStateFromError(_error) {
|
|
172
|
+
return { hasError: true };
|
|
173
|
+
}
|
|
174
|
+
componentDidCatch(error, errorInfo) {
|
|
175
|
+
this.props.logger.addEvent({
|
|
176
|
+
type: "err",
|
|
177
|
+
data: {
|
|
178
|
+
msg: redactReactSnapshot(error.message),
|
|
179
|
+
stack: redactReactSnapshot(error.stack),
|
|
180
|
+
componentStack: redactReactSnapshot(errorInfo.componentStack),
|
|
181
|
+
source: "react-error-boundary"
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
resetError() {
|
|
186
|
+
this.setState({ hasError: false });
|
|
187
|
+
}
|
|
188
|
+
render() {
|
|
189
|
+
if (this.state.hasError) {
|
|
190
|
+
return this.props.fallback ?? null;
|
|
191
|
+
}
|
|
192
|
+
return this.props.children;
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
export {
|
|
196
|
+
CrumbtrailErrorBoundary,
|
|
197
|
+
useBugState
|
|
198
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "crumbtrail-react",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.cjs"
|
|
13
|
+
},
|
|
14
|
+
"./package.json": "./package.json"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"react": ">=18"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@testing-library/react": "^16.1.0",
|
|
24
|
+
"@types/react": "^19.0.0",
|
|
25
|
+
"@types/react-dom": "^19.0.0",
|
|
26
|
+
"happy-dom": "^17.4.0",
|
|
27
|
+
"react": "^19.0.0",
|
|
28
|
+
"react-dom": "^19.0.0",
|
|
29
|
+
"typescript": "^5.7.0",
|
|
30
|
+
"vitest": "^3.1.0"
|
|
31
|
+
},
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"homepage": "https://github.com/crumbtrail-dev/crumbtrail-js/tree/main/packages/react#readme",
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/crumbtrail-dev/crumbtrail-js/issues"
|
|
36
|
+
},
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "git+https://github.com/crumbtrail-dev/crumbtrail-js.git",
|
|
40
|
+
"directory": "packages/react"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsup",
|
|
47
|
+
"test": "vitest run --passWithNoTests",
|
|
48
|
+
"test:coverage": "vitest run --coverage --passWithNoTests",
|
|
49
|
+
"test:watch": "vitest",
|
|
50
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
51
|
+
"clean": "rm -rf dist"
|
|
52
|
+
}
|
|
53
|
+
}
|