react-smart-copy 1.20.0 → 1.22.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.
@@ -0,0 +1,152 @@
1
+
2
+ import { c as CopyInterceptTransform } from "./chunks/copy-interceptor-CZWzGOkL.cjs";
3
+ //#region src/secrets/types.d.ts
4
+ /**
5
+ * Kinds of secrets {@link scanSecrets} finds.
6
+ *
7
+ * - Keys and tokens of services, by their documented formats: `private-key` (PEM and
8
+ * OpenSSH), `aws-access-key-id`, `aws-secret-access-key`, `github-token`, `gitlab-token`,
9
+ * `slack-token`, `slack-webhook`, `stripe-key` (live keys), `google-api-key`,
10
+ * `npm-token`, `pypi-token`, `sendgrid-key`, `twilio-key`, `azure-storage-key`, `jwt`.
11
+ * - Credentials inside other text: `url-credentials` (the password in
12
+ * `postgres://user:password@host`), `connection-string` (`Password=` in a connection string).
13
+ * - Financial data, by checksum: `card-number` (Luhn and card brand), `iban` (mod-97 and length).
14
+ * - `generic-secret`: a random-looking value assigned to a name such as `password`, `token`
15
+ * or `api_key` (`API_KEY="..."`, `"password": "..."`).
16
+ */
17
+ type SecretKind = 'private-key' | 'aws-access-key-id' | 'aws-secret-access-key' | 'github-token' | 'gitlab-token' | 'slack-token' | 'slack-webhook' | 'stripe-key' | 'google-api-key' | 'npm-token' | 'pypi-token' | 'sendgrid-key' | 'twilio-key' | 'azure-storage-key' | 'jwt' | 'url-credentials' | 'connection-string' | 'card-number' | 'iban' | 'generic-secret';
18
+ /** People-facing names of the kinds, for messages and redaction marks. */
19
+ export declare const SECRET_LABELS: Readonly<Record<SecretKind, string>>;
20
+ /** Every kind, in a stable order. */
21
+ export declare const SECRET_KINDS: readonly SecretKind[];
22
+ /**
23
+ * How sure a finding is.
24
+ *
25
+ * - `high`: the documented format of a service, a valid checksum (cards, IBANs), or a
26
+ * structure that only credentials have (a PEM private key, a password in a URL).
27
+ * - `medium`: the shape fits, but other data has it too: an AWS secret key next to its name,
28
+ * a Twilio key, a value assigned to a secret-sounding name.
29
+ */
30
+ type SecretConfidence = 'high' | 'medium';
31
+ interface SecretFinding {
32
+ readonly kind: SecretKind;
33
+ /** {@link SECRET_LABELS} for the kind. */
34
+ readonly label: string;
35
+ readonly confidence: SecretConfidence;
36
+ /** Where the secret is in the scanned text: `text.slice(start, end)` is the secret. */
37
+ readonly start: number;
38
+ readonly end: number;
39
+ /**
40
+ * A preview safe to show and log: at most a known prefix and the last 4 characters
41
+ * (`ghp_` and `a1B2` around an ellipsis; the last 4 digits of a card). Findings never hold the secret.
42
+ */
43
+ readonly masked: string;
44
+ }
45
+ //#endregion
46
+ //#region src/secrets/scan.d.ts
47
+ /** Longest text scanned, in characters. Default 1,000,000; the rest is not scanned (`truncated`). */
48
+ export declare const DEFAULT_SECRET_SCAN_LENGTH = 1000000;
49
+ interface ScanSecretsOptions {
50
+ /** Kinds to look for. Default: every kind. */
51
+ readonly kinds?: readonly SecretKind[];
52
+ /** Least confidence reported. Default `'medium'`: everything. `'high'` leaves out guesses. */
53
+ readonly minConfidence?: SecretConfidence;
54
+ /** Longest text scanned, in characters. Default {@link DEFAULT_SECRET_SCAN_LENGTH}. */
55
+ readonly maxLength?: number;
56
+ }
57
+ interface SecretScan {
58
+ /** In the order they appear; findings never overlap. */
59
+ readonly findings: readonly SecretFinding[];
60
+ /** The text was longer than `maxLength`: only its start was scanned. */
61
+ readonly truncated: boolean;
62
+ }
63
+ /**
64
+ * Finds secrets in `text`: keys and tokens of services by their documented formats, private
65
+ * keys, passwords in URLs and connection strings, card numbers and IBANs by their checksums,
66
+ * and random-looking values assigned to names such as `password` or `api_key`.
67
+ *
68
+ * Findings say where each secret is and what kind it is, with a masked preview; they never
69
+ * hold the secret. Every pattern runs in linear time, so any text is safe to scan. Works
70
+ * anywhere, including servers.
71
+ *
72
+ * @example
73
+ * const { findings } = scanSecrets(pastedText);
74
+ * if (findings.length > 0) warn(`This contains a ${findings[0].label}.`);
75
+ *
76
+ * @throws {CopyFailure} `invalid-payload` for an unknown kind or a negative `maxLength`.
77
+ */
78
+ export declare function scanSecrets(text: string, options?: ScanSecretsOptions): SecretScan;
79
+ //#endregion
80
+ //#region src/secrets/redact.d.ts
81
+ interface RedactSecretsOptions extends ScanSecretsOptions {
82
+ /** What replaces each secret. Default: `[redacted <label>]`, as in `[redacted GitHub token]`. */
83
+ readonly replace?: (finding: SecretFinding) => string;
84
+ }
85
+ interface RedactedText {
86
+ /** The text with each secret replaced. */
87
+ readonly text: string;
88
+ /** What was replaced, at its place in the original text. */
89
+ readonly findings: readonly SecretFinding[];
90
+ /** The text was longer than `maxLength`: the rest was neither scanned nor kept. */
91
+ readonly truncated: boolean;
92
+ }
93
+ /**
94
+ * `text` with every secret {@link scanSecrets} finds replaced, by default with
95
+ * `[redacted <label>]`. Text past `maxLength` is dropped, never passed on unscanned.
96
+ *
97
+ * @example
98
+ * redactSecrets('token: ghp_...').text; // 'token: [redacted GitHub token]'
99
+ */
100
+ export declare function redactSecrets(text: string, options?: RedactSecretsOptions): RedactedText;
101
+ /**
102
+ * A transform for `useCopyInterceptor` and `registerCopyInterceptor`: when what people copy
103
+ * from your page (logs, settings, a support console) holds secrets, the clipboard gets the
104
+ * text with them redacted; other copies are left to the browser. The redacted copy is
105
+ * plain text: formatting around a secret could carry it too.
106
+ *
107
+ * @example
108
+ * useCopyInterceptor(logViewerRef, { transform: secretRedactor() });
109
+ */
110
+ export declare function secretRedactor(options?: RedactSecretsOptions): CopyInterceptTransform;
111
+ //#endregion
112
+ //#region src/secrets/paste.d.ts
113
+ /** What {@link pasteWithoutSecrets} did. */
114
+ type SecretPasteOutcome =
115
+ /** No secrets (or nothing to read): the browser pasted as usual. */
116
+ 'clean' |
117
+ /** The paste was inserted with its secrets redacted. */
118
+ 'redacted' |
119
+ /** The paste was stopped: nothing was inserted. */
120
+ 'blocked';
121
+ interface PasteWithoutSecretsOptions extends RedactSecretsOptions {
122
+ /**
123
+ * `'redact'` (default) inserts the paste with its secrets replaced, into a `<textarea>` or
124
+ * text `<input>`, with undo intact. `'block'` inserts nothing. Where text can't be inserted
125
+ * (another element), a paste with secrets is blocked.
126
+ */
127
+ readonly action?: 'redact' | 'block';
128
+ /** Called when a paste held secrets, with what was found and what was done. */
129
+ readonly onSecrets?: (findings: readonly SecretFinding[], outcome: Exclude<SecretPasteOutcome, 'clean'>) => void;
130
+ }
131
+ /** Structural paste event: a DOM `ClipboardEvent` and React's `onPaste` event both fit. */
132
+ interface SecretPasteEvent {
133
+ readonly clipboardData: {
134
+ getData(format: string): string;
135
+ } | null;
136
+ readonly currentTarget: EventTarget | null;
137
+ readonly target: EventTarget | null;
138
+ readonly defaultPrevented: boolean;
139
+ preventDefault(): void;
140
+ }
141
+ /**
142
+ * A paste handler that keeps secrets out of a field: chat boxes, comments, tickets and
143
+ * forms where an API key or a password pasted by mistake would be seen or stored. A paste
144
+ * without secrets is left to the browser.
145
+ *
146
+ * @example
147
+ * <textarea onPaste={(event) => pasteWithoutSecrets(event, { onSecrets: (found) => toast(`Removed a ${found[0].label}.`) })} />
148
+ */
149
+ export declare function pasteWithoutSecrets(event: SecretPasteEvent, options?: PasteWithoutSecretsOptions): SecretPasteOutcome;
150
+ //#endregion
151
+ export type { PasteWithoutSecretsOptions, RedactSecretsOptions, RedactedText, ScanSecretsOptions, SecretConfidence, SecretFinding, SecretKind, SecretPasteEvent, SecretPasteOutcome, SecretScan };
152
+ //# sourceMappingURL=secrets.d.cts.map
@@ -0,0 +1,152 @@
1
+
2
+ import { c as CopyInterceptTransform } from "./chunks/copy-interceptor-C6NABy1l.js";
3
+ //#region src/secrets/types.d.ts
4
+ /**
5
+ * Kinds of secrets {@link scanSecrets} finds.
6
+ *
7
+ * - Keys and tokens of services, by their documented formats: `private-key` (PEM and
8
+ * OpenSSH), `aws-access-key-id`, `aws-secret-access-key`, `github-token`, `gitlab-token`,
9
+ * `slack-token`, `slack-webhook`, `stripe-key` (live keys), `google-api-key`,
10
+ * `npm-token`, `pypi-token`, `sendgrid-key`, `twilio-key`, `azure-storage-key`, `jwt`.
11
+ * - Credentials inside other text: `url-credentials` (the password in
12
+ * `postgres://user:password@host`), `connection-string` (`Password=` in a connection string).
13
+ * - Financial data, by checksum: `card-number` (Luhn and card brand), `iban` (mod-97 and length).
14
+ * - `generic-secret`: a random-looking value assigned to a name such as `password`, `token`
15
+ * or `api_key` (`API_KEY="..."`, `"password": "..."`).
16
+ */
17
+ type SecretKind = 'private-key' | 'aws-access-key-id' | 'aws-secret-access-key' | 'github-token' | 'gitlab-token' | 'slack-token' | 'slack-webhook' | 'stripe-key' | 'google-api-key' | 'npm-token' | 'pypi-token' | 'sendgrid-key' | 'twilio-key' | 'azure-storage-key' | 'jwt' | 'url-credentials' | 'connection-string' | 'card-number' | 'iban' | 'generic-secret';
18
+ /** People-facing names of the kinds, for messages and redaction marks. */
19
+ export declare const SECRET_LABELS: Readonly<Record<SecretKind, string>>;
20
+ /** Every kind, in a stable order. */
21
+ export declare const SECRET_KINDS: readonly SecretKind[];
22
+ /**
23
+ * How sure a finding is.
24
+ *
25
+ * - `high`: the documented format of a service, a valid checksum (cards, IBANs), or a
26
+ * structure that only credentials have (a PEM private key, a password in a URL).
27
+ * - `medium`: the shape fits, but other data has it too: an AWS secret key next to its name,
28
+ * a Twilio key, a value assigned to a secret-sounding name.
29
+ */
30
+ type SecretConfidence = 'high' | 'medium';
31
+ interface SecretFinding {
32
+ readonly kind: SecretKind;
33
+ /** {@link SECRET_LABELS} for the kind. */
34
+ readonly label: string;
35
+ readonly confidence: SecretConfidence;
36
+ /** Where the secret is in the scanned text: `text.slice(start, end)` is the secret. */
37
+ readonly start: number;
38
+ readonly end: number;
39
+ /**
40
+ * A preview safe to show and log: at most a known prefix and the last 4 characters
41
+ * (`ghp_` and `a1B2` around an ellipsis; the last 4 digits of a card). Findings never hold the secret.
42
+ */
43
+ readonly masked: string;
44
+ }
45
+ //#endregion
46
+ //#region src/secrets/scan.d.ts
47
+ /** Longest text scanned, in characters. Default 1,000,000; the rest is not scanned (`truncated`). */
48
+ export declare const DEFAULT_SECRET_SCAN_LENGTH = 1000000;
49
+ interface ScanSecretsOptions {
50
+ /** Kinds to look for. Default: every kind. */
51
+ readonly kinds?: readonly SecretKind[];
52
+ /** Least confidence reported. Default `'medium'`: everything. `'high'` leaves out guesses. */
53
+ readonly minConfidence?: SecretConfidence;
54
+ /** Longest text scanned, in characters. Default {@link DEFAULT_SECRET_SCAN_LENGTH}. */
55
+ readonly maxLength?: number;
56
+ }
57
+ interface SecretScan {
58
+ /** In the order they appear; findings never overlap. */
59
+ readonly findings: readonly SecretFinding[];
60
+ /** The text was longer than `maxLength`: only its start was scanned. */
61
+ readonly truncated: boolean;
62
+ }
63
+ /**
64
+ * Finds secrets in `text`: keys and tokens of services by their documented formats, private
65
+ * keys, passwords in URLs and connection strings, card numbers and IBANs by their checksums,
66
+ * and random-looking values assigned to names such as `password` or `api_key`.
67
+ *
68
+ * Findings say where each secret is and what kind it is, with a masked preview; they never
69
+ * hold the secret. Every pattern runs in linear time, so any text is safe to scan. Works
70
+ * anywhere, including servers.
71
+ *
72
+ * @example
73
+ * const { findings } = scanSecrets(pastedText);
74
+ * if (findings.length > 0) warn(`This contains a ${findings[0].label}.`);
75
+ *
76
+ * @throws {CopyFailure} `invalid-payload` for an unknown kind or a negative `maxLength`.
77
+ */
78
+ export declare function scanSecrets(text: string, options?: ScanSecretsOptions): SecretScan;
79
+ //#endregion
80
+ //#region src/secrets/redact.d.ts
81
+ interface RedactSecretsOptions extends ScanSecretsOptions {
82
+ /** What replaces each secret. Default: `[redacted <label>]`, as in `[redacted GitHub token]`. */
83
+ readonly replace?: (finding: SecretFinding) => string;
84
+ }
85
+ interface RedactedText {
86
+ /** The text with each secret replaced. */
87
+ readonly text: string;
88
+ /** What was replaced, at its place in the original text. */
89
+ readonly findings: readonly SecretFinding[];
90
+ /** The text was longer than `maxLength`: the rest was neither scanned nor kept. */
91
+ readonly truncated: boolean;
92
+ }
93
+ /**
94
+ * `text` with every secret {@link scanSecrets} finds replaced, by default with
95
+ * `[redacted <label>]`. Text past `maxLength` is dropped, never passed on unscanned.
96
+ *
97
+ * @example
98
+ * redactSecrets('token: ghp_...').text; // 'token: [redacted GitHub token]'
99
+ */
100
+ export declare function redactSecrets(text: string, options?: RedactSecretsOptions): RedactedText;
101
+ /**
102
+ * A transform for `useCopyInterceptor` and `registerCopyInterceptor`: when what people copy
103
+ * from your page (logs, settings, a support console) holds secrets, the clipboard gets the
104
+ * text with them redacted; other copies are left to the browser. The redacted copy is
105
+ * plain text: formatting around a secret could carry it too.
106
+ *
107
+ * @example
108
+ * useCopyInterceptor(logViewerRef, { transform: secretRedactor() });
109
+ */
110
+ export declare function secretRedactor(options?: RedactSecretsOptions): CopyInterceptTransform;
111
+ //#endregion
112
+ //#region src/secrets/paste.d.ts
113
+ /** What {@link pasteWithoutSecrets} did. */
114
+ type SecretPasteOutcome =
115
+ /** No secrets (or nothing to read): the browser pasted as usual. */
116
+ 'clean' |
117
+ /** The paste was inserted with its secrets redacted. */
118
+ 'redacted' |
119
+ /** The paste was stopped: nothing was inserted. */
120
+ 'blocked';
121
+ interface PasteWithoutSecretsOptions extends RedactSecretsOptions {
122
+ /**
123
+ * `'redact'` (default) inserts the paste with its secrets replaced, into a `<textarea>` or
124
+ * text `<input>`, with undo intact. `'block'` inserts nothing. Where text can't be inserted
125
+ * (another element), a paste with secrets is blocked.
126
+ */
127
+ readonly action?: 'redact' | 'block';
128
+ /** Called when a paste held secrets, with what was found and what was done. */
129
+ readonly onSecrets?: (findings: readonly SecretFinding[], outcome: Exclude<SecretPasteOutcome, 'clean'>) => void;
130
+ }
131
+ /** Structural paste event: a DOM `ClipboardEvent` and React's `onPaste` event both fit. */
132
+ interface SecretPasteEvent {
133
+ readonly clipboardData: {
134
+ getData(format: string): string;
135
+ } | null;
136
+ readonly currentTarget: EventTarget | null;
137
+ readonly target: EventTarget | null;
138
+ readonly defaultPrevented: boolean;
139
+ preventDefault(): void;
140
+ }
141
+ /**
142
+ * A paste handler that keeps secrets out of a field: chat boxes, comments, tickets and
143
+ * forms where an API key or a password pasted by mistake would be seen or stored. A paste
144
+ * without secrets is left to the browser.
145
+ *
146
+ * @example
147
+ * <textarea onPaste={(event) => pasteWithoutSecrets(event, { onSecrets: (found) => toast(`Removed a ${found[0].label}.`) })} />
148
+ */
149
+ export declare function pasteWithoutSecrets(event: SecretPasteEvent, options?: PasteWithoutSecretsOptions): SecretPasteOutcome;
150
+ //#endregion
151
+ export type { PasteWithoutSecretsOptions, RedactSecretsOptions, RedactedText, ScanSecretsOptions, SecretConfidence, SecretFinding, SecretKind, SecretPasteEvent, SecretPasteOutcome, SecretScan };
152
+ //# sourceMappingURL=secrets.d.ts.map