@heroku/js-blanket 0.0.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/.c8rc.json +11 -0
- package/.editorconfig +11 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +41 -0
- package/.github/copilot-instructions.md +117 -0
- package/.github/workflows/ci.yml +25 -0
- package/.husky/pre-commit +1 -0
- package/.lintstagedrc.json +4 -0
- package/.tool-versions +1 -0
- package/CODEOWNERS +8 -0
- package/CODE_OF_CONDUCT.md +111 -0
- package/CONTRIBUTING.md +123 -0
- package/LICENSE +206 -0
- package/README.md +218 -0
- package/SECURITY.md +8 -0
- package/docs/examples/logging-integration.md +736 -0
- package/eslint.config.mjs +108 -0
- package/package.json +80 -0
- package/prettier.config.mjs +10 -0
- package/scripts/test-setup.mjs +24 -0
- package/src/adapters/logging/generic.test.ts +531 -0
- package/src/adapters/logging/generic.ts +21 -0
- package/src/core/patterns.ts +22 -0
- package/src/core/presets.ts +122 -0
- package/src/core/scrubber.test.ts +465 -0
- package/src/core/scrubber.ts +284 -0
- package/src/core/types.test.ts +516 -0
- package/src/core/types.ts +176 -0
- package/src/index.test.ts +41 -0
- package/src/index.ts +8 -0
- package/tsconfig.cjs.json +12 -0
- package/tsconfig.esm.json +12 -0
- package/tsconfig.json +32 -0
- package/tsconfig.test.json +9 -0
package/README.md
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
# Heroku JS Blanket
|
|
2
|
+
|
|
3
|
+
A framework-agnostic sensitive data scrubbing library for logging, exception
|
|
4
|
+
handling, and monitoring services for NodeJS and JavaScript projects. If you
|
|
5
|
+
need to remove PII from structured data, JS Blanket has you covered.
|
|
6
|
+
|
|
7
|
+
This project provides a core scrubbing engine with preset field lists for common
|
|
8
|
+
PII patterns, making it easy to integrate with any logging or error monitoring
|
|
9
|
+
service.
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Deep Object Traversal**: Handles nested objects, arrays, and circular
|
|
14
|
+
references safely
|
|
15
|
+
- **Multiple Scrubbing Modes**: Field-based, path-based, and pattern-based
|
|
16
|
+
scrubbing
|
|
17
|
+
- **Immutable Operations**: Never modifies input data - always returns new
|
|
18
|
+
objects
|
|
19
|
+
- **Preset Field Lists**: Battle-tested PII patterns (HEROKU_FIELDS,
|
|
20
|
+
GDPR_FIELDS, PCI_FIELDS)
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
### Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# npm
|
|
28
|
+
npm install @heroku/js-blanket
|
|
29
|
+
|
|
30
|
+
# pnpm
|
|
31
|
+
pnpm add @heroku/js-blanket
|
|
32
|
+
|
|
33
|
+
# yarn
|
|
34
|
+
yarn add @heroku/js-blanket
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Usage Examples
|
|
38
|
+
|
|
39
|
+
Framework-specific examples
|
|
40
|
+
[here](https://github.com/heroku/js-blanket/tree/main/docs/examples).
|
|
41
|
+
|
|
42
|
+
## Core Scrubber API
|
|
43
|
+
|
|
44
|
+
The `Scrubber` class provides flexible PII scrubbing with three modes:
|
|
45
|
+
|
|
46
|
+
### Field-Based Scrubbing
|
|
47
|
+
|
|
48
|
+
Scrubs values based on field names (exact match or regex):
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import { Scrubber } from '@heroku/js-blanket';
|
|
52
|
+
|
|
53
|
+
const scrubber = new Scrubber({
|
|
54
|
+
fields: ['password', 'apiToken', /.*_token$/i],
|
|
55
|
+
replacement: '[REDACTED]',
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const data = {
|
|
59
|
+
user: 'john',
|
|
60
|
+
password: 'secret123',
|
|
61
|
+
oauth_token: 'abc-def-ghi',
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const result = scrubber.scrub(data);
|
|
65
|
+
// Result: { user: 'john', password: '[REDACTED]', oauth_token: '[REDACTED]' }
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Path-Based Scrubbing
|
|
69
|
+
|
|
70
|
+
Scrubs values at specific paths using dot notation:
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
const scrubber = new Scrubber({
|
|
74
|
+
paths: ['user.email', 'user.profile.ssn'],
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const data = {
|
|
78
|
+
user: {
|
|
79
|
+
name: 'John',
|
|
80
|
+
email: 'john@example.com',
|
|
81
|
+
profile: { ssn: '123-45-6789' },
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const result = scrubber.scrub(data);
|
|
86
|
+
// Result: { user: { name: 'John', email: '[SCRUBBED]', profile: { ssn: '[SCRUBBED]' } } }
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Pattern-Based Scrubbing
|
|
90
|
+
|
|
91
|
+
Scrubs content matching regex patterns:
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
const scrubber = new Scrubber({
|
|
95
|
+
patterns: [
|
|
96
|
+
/\b[\w._%+-]+@[\w.-]+\.[a-zA-Z]{2,}\b/g, // Email addresses
|
|
97
|
+
/\b\d{3}-\d{2}-\d{4}\b/g, // SSN patterns
|
|
98
|
+
/\b\d{13,19}\b/g, // Credit card numbers
|
|
99
|
+
],
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const data = {
|
|
103
|
+
message: 'Contact john@example.com or call 123-45-6789',
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const result = scrubber.scrub(data);
|
|
107
|
+
// Result: { message: 'Contact [SCRUBBED] or call [SCRUBBED]' }
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Preset Field Lists
|
|
111
|
+
|
|
112
|
+
Use battle-tested preset field lists for common PII patterns:
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
import { HEROKU_FIELDS, GDPR_FIELDS, PCI_FIELDS } from '@heroku/js-blanket';
|
|
116
|
+
|
|
117
|
+
// Heroku-specific sensitive fields
|
|
118
|
+
const scrubber = new Scrubber({
|
|
119
|
+
fields: HEROKU_FIELDS, // heroku_oauth_token, sudo_oauth_token, www-sso-session, etc.
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// GDPR compliance fields
|
|
123
|
+
const gdprScrubber = new Scrubber({
|
|
124
|
+
fields: GDPR_FIELDS, // email, ip_address, phone_number, ssn, date_of_birth, etc.
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// PCI compliance fields
|
|
128
|
+
const pciScrubber = new Scrubber({
|
|
129
|
+
fields: PCI_FIELDS, // credit_card, cvv, card_number, expiration_date, etc.
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// Combine multiple presets
|
|
133
|
+
const scrubber = new Scrubber({
|
|
134
|
+
fields: [...HEROKU_FIELDS, ...GDPR_FIELDS, ...PCI_FIELDS],
|
|
135
|
+
});
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Code Quality and Testing
|
|
139
|
+
|
|
140
|
+
This project uses pnpm for package management and includes comprehensive code
|
|
141
|
+
quality tools to maintain high standards.
|
|
142
|
+
|
|
143
|
+
### Available Scripts
|
|
144
|
+
|
|
145
|
+
A list of useful scripts when developing against the codebase:
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
# All code quality checks and tests
|
|
149
|
+
pnpm check
|
|
150
|
+
|
|
151
|
+
# Run the full test suite with coverage reporting
|
|
152
|
+
pnpm test
|
|
153
|
+
|
|
154
|
+
# Check code quality with ESLint
|
|
155
|
+
pnpm lint
|
|
156
|
+
|
|
157
|
+
# Automatically fix linting issues and format code with Prettier
|
|
158
|
+
pnpm format
|
|
159
|
+
|
|
160
|
+
# Run TypeScript type checking
|
|
161
|
+
pnpm type-check
|
|
162
|
+
|
|
163
|
+
# Run the continuous integration checks (linting, type checking, and tests)
|
|
164
|
+
pnpm ci
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Development Workflow
|
|
168
|
+
|
|
169
|
+
For the best development experience:
|
|
170
|
+
|
|
171
|
+
1. **Before starting work**: Ensure dependencies are installed with
|
|
172
|
+
`pnpm install`.
|
|
173
|
+
2. **During development**: Run `pnpm type-check` periodically to catch type
|
|
174
|
+
errors early.
|
|
175
|
+
3. **Before committing**: Run `pnpm check` to ensure all quality standards are
|
|
176
|
+
met.
|
|
177
|
+
4. **Fix issues quickly**: Use `pnpm format` to auto-fix formatting and linting
|
|
178
|
+
issues.
|
|
179
|
+
|
|
180
|
+
### Testing Requirements
|
|
181
|
+
|
|
182
|
+
Tests are located in `src/**/*.test.ts` and run against the compiled JavaScript
|
|
183
|
+
in `dist/`. The test suite includes:
|
|
184
|
+
|
|
185
|
+
- Unit tests for all public APIs
|
|
186
|
+
- Type safety validation tests
|
|
187
|
+
- Coverage reporting with c8 (HTML and text-summary)
|
|
188
|
+
|
|
189
|
+
Tests automatically run in silent mode (`LOG_LEVEL=silent`) to keep output
|
|
190
|
+
clean.
|
|
191
|
+
|
|
192
|
+
### Build Outputs
|
|
193
|
+
|
|
194
|
+
The library produces dual builds for maximum compatibility:
|
|
195
|
+
|
|
196
|
+
- **CommonJS** (`dist/cjs/`): Use for Node.js and older bundlers
|
|
197
|
+
- **ES Modules** (`dist/esm/`): Use for modern bundlers and tree-shaking support
|
|
198
|
+
|
|
199
|
+
Both outputs include TypeScript declaration files (`.d.ts`) for type
|
|
200
|
+
information.
|
|
201
|
+
|
|
202
|
+
## License
|
|
203
|
+
|
|
204
|
+
Apache-2.0. See `LICENSE` for details.
|
|
205
|
+
|
|
206
|
+
## Contributing
|
|
207
|
+
|
|
208
|
+
We welcome issues and PRs. Please follow conventional commits, keep changes
|
|
209
|
+
under 200 lines per commit, and ensure tests and type checks pass. See
|
|
210
|
+
`CONTRIBUTING.md` for details.
|
|
211
|
+
|
|
212
|
+
## Documentation
|
|
213
|
+
|
|
214
|
+
For more detailed examples and use cases:
|
|
215
|
+
|
|
216
|
+
- [Logging Integration Examples](docs/examples/logging-integration.md)
|
|
217
|
+
- [Migration Guides](docs/MIGRATION.md)
|
|
218
|
+
- [Project Status](docs/PROJECT-STATUS.md)
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
## Security
|
|
2
|
+
|
|
3
|
+
Please report any security issue to
|
|
4
|
+
[security@salesforce.com](mailto:security@salesforce.com) as soon as it is
|
|
5
|
+
discovered. This library limits its runtime dependencies in order to reduce the
|
|
6
|
+
total cost of ownership as much as can be, but all consumers should remain
|
|
7
|
+
vigilant and have their security stakeholders review all third-party products
|
|
8
|
+
(3PP) like this one and their dependencies.
|