@doubling/types 0.2.1 → 0.3.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/README.md +16 -2
- package/dist/firestore.d.ts +2 -0
- package/dist/firestore.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/scrub.d.ts +41 -0
- package/dist/scrub.d.ts.map +1 -0
- package/dist/scrub.js +206 -0
- package/dist/scrub.js.map +1 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# @doubling/types
|
|
2
2
|
|
|
3
|
-
Shared TypeScript interfaces and pure helpers consumed by `web/` and `sync
|
|
3
|
+
Shared TypeScript interfaces and pure helpers consumed by `web/` and `sync/` (verified via each package's `package.json` dependency and `import … from '@doubling/types'` sites). Single source of truth for Firestore document shapes (file/folder entities, org membership, teams, user profiles), file-extension to MIME mappings, and storage-path helpers.
|
|
4
|
+
|
|
5
|
+
`functions/` does **not** depend on this package: it deliberately keeps a local mirror of `OrgMember` (see `functions/src/index.ts`, "kept local because functions/…") pending a later migration. Root [`../DESIGN.md` §5](../DESIGN.md) describes the shapes as consumed by web, sync, and functions — that is a *structural* statement (functions stores the same documents), not a package dependency.
|
|
4
6
|
|
|
5
7
|
Lives at the repo root as an npm workspace (`@doubling/types`). The compiled output is shipped at `dist/`, regenerated on `npm install` via the `prepare` script and rebuilt explicitly via `npm run build`.
|
|
6
8
|
|
|
@@ -31,4 +33,16 @@ Edit `EXT_TO_MIME` in `src/mime.ts`. That's it. Both `web/` and `sync/` pick up
|
|
|
31
33
|
npm run -w types build
|
|
32
34
|
```
|
|
33
35
|
|
|
34
|
-
Emits `dist/index.js` plus `dist/*.d.ts`. The `dist/` directory is gitignored; CI runs the build automatically via the `prepare` script on `npm install
|
|
36
|
+
Emits `dist/index.js` plus `dist/*.d.ts`. The `dist/` directory is gitignored; CI runs the build automatically via the `prepare` script on `npm install` (`prepack` re-runs `tsc` before packaging). Only `dist/` and `README.md` are shipped in the published tarball (see the `files` field in `package.json`).
|
|
37
|
+
|
|
38
|
+
## Publish
|
|
39
|
+
|
|
40
|
+
Published to the public npm registry as `@doubling/types`. The [`.github/workflows/publish-types.yml`](../.github/workflows/publish-types.yml) workflow (**Publish Types to npm**) fires on every published GitHub Release, gated on the `@doubling/types@` tag prefix so a sibling `sync` release does not trigger it. It runs `npm ci`, `npm run build -w types`, skips cleanly if `types/package.json`'s version is already on npm, then `npm publish --access public` via npm Trusted Publishing (OIDC — no `NPM_TOKEN`). `workflow_dispatch` is exposed for bootstrap and transient-failure recovery. Version bumps are cut by Changesets (see `CHANGELOG.md`).
|
|
41
|
+
|
|
42
|
+
The package is published because `@doubling/compound-sync` is itself a published npm package that depends on `@doubling/types` at runtime, so the dependency must resolve from the registry outside the monorepo.
|
|
43
|
+
|
|
44
|
+
## Docs
|
|
45
|
+
|
|
46
|
+
- [`DESIGN.md`](DESIGN.md) — detailed design (exported symbols, path scheme, trade-offs).
|
|
47
|
+
- Root [`../DESIGN.md` §5](../DESIGN.md) — canonical data model.
|
|
48
|
+
- [`../docs/features/sync/index.md`](../docs/features/sync/index.md) — shared-schema bullet in the sync feature docs.
|
package/dist/firestore.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export interface FileEntity extends EntityBase {
|
|
|
19
19
|
storagePath?: string;
|
|
20
20
|
content?: string | null;
|
|
21
21
|
frontmatter?: unknown;
|
|
22
|
+
contentLoadFailed?: true;
|
|
22
23
|
}
|
|
23
24
|
export interface FolderEntity extends EntityBase {
|
|
24
25
|
type: 'folder';
|
|
@@ -37,6 +38,7 @@ export interface OrgMember {
|
|
|
37
38
|
email?: string;
|
|
38
39
|
role?: string;
|
|
39
40
|
orgName?: string;
|
|
41
|
+
teamIds?: string[];
|
|
40
42
|
}
|
|
41
43
|
export interface Team {
|
|
42
44
|
id: string;
|
package/dist/firestore.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"firestore.d.ts","sourceRoot":"","sources":["../src/firestore.ts"],"names":[],"mappings":"AAoBA,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,SAAS,CAAC;AAKvC,UAAU,UAAU;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,KAAK,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC7B;AASD,MAAM,WAAW,UAAW,SAAQ,UAAU;IAC5C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,WAAW,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"firestore.d.ts","sourceRoot":"","sources":["../src/firestore.ts"],"names":[],"mappings":"AAoBA,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,SAAS,CAAC;AAKvC,UAAU,UAAU;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,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E,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAGD,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAKD,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,EAAE;AACF,6DAA6D;AAC7D,qEAAqE;AACrE,6DAA6D;AAC7D,qCAAqC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,EAAE;AACF,6DAA6D;AAC7D,qEAAqE;AACrE,6DAA6D;AAC7D,qCAAqC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
|
package/dist/scrub.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The only shape allowed for context we attach deliberately.
|
|
3
|
+
*
|
|
4
|
+
* Everything here is non-identifying metadata that the operation log
|
|
5
|
+
* already models (see sync/operation-log.ts). Notably absent, and
|
|
6
|
+
* absent on purpose: `path`, `name`, `content`, `email`.
|
|
7
|
+
*/
|
|
8
|
+
export interface SafeContext {
|
|
9
|
+
orgId?: string;
|
|
10
|
+
userId?: string;
|
|
11
|
+
teamId?: string;
|
|
12
|
+
opType?: string;
|
|
13
|
+
scope?: string;
|
|
14
|
+
entityType?: 'file' | 'folder';
|
|
15
|
+
/** Extension only — 'md', 'pdf'. Never the filename. */
|
|
16
|
+
ext?: string;
|
|
17
|
+
mimeType?: string;
|
|
18
|
+
sizeBytes?: number;
|
|
19
|
+
/** Shape of the path, not its content. */
|
|
20
|
+
pathDepth?: number;
|
|
21
|
+
nameLength?: number;
|
|
22
|
+
errorCode?: string;
|
|
23
|
+
agentVersion?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Redact a single string.
|
|
27
|
+
*
|
|
28
|
+
* Order matters: query strings first (Firebase Storage signed URLs
|
|
29
|
+
* carry `?token=`), then the most specific path forms, then bare
|
|
30
|
+
* filenames, then the length cap.
|
|
31
|
+
*/
|
|
32
|
+
export declare function redactString(input: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Scrub an error event in place-safe fashion (returns a new object).
|
|
35
|
+
*
|
|
36
|
+
* Returns `null` if scrubbing itself throws. Failing closed is the only
|
|
37
|
+
* acceptable behaviour here: dropping one event costs a diagnostic,
|
|
38
|
+
* leaking one costs customer data.
|
|
39
|
+
*/
|
|
40
|
+
export declare function scrubEvent<T extends object>(event: T): T | null;
|
|
41
|
+
//# sourceMappingURL=scrub.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrub.d.ts","sourceRoot":"","sources":["../src/scrub.ts"],"names":[],"mappings":"AA2BA;;;;;;GAMG;AACH,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC/B,wDAAwD;IACxD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0CAA0C;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AA8DD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CA6BlD;AAmCD;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,GAAG,IAAI,CA0E/D"}
|
package/dist/scrub.js
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
// PII scrubbing for error telemetry.
|
|
2
|
+
//
|
|
3
|
+
// Compound is a file-sync product. File paths, file names and file
|
|
4
|
+
// CONTENTS are customer data, and the daemon runs on customer machines.
|
|
5
|
+
// Nothing resembling any of it may leave with an error report.
|
|
6
|
+
//
|
|
7
|
+
// Two layers, deliberately:
|
|
8
|
+
//
|
|
9
|
+
// 1. SafeContext — a typed allowlist for anything we attach on
|
|
10
|
+
// purpose. With `exactOptionalPropertyTypes` on, passing `{ path }`
|
|
11
|
+
// is a COMPILE error. PII discipline enforced by the compiler
|
|
12
|
+
// rather than by review.
|
|
13
|
+
//
|
|
14
|
+
// 2. scrubEvent — a redaction pass over everything the SDK populates
|
|
15
|
+
// on its own: messages, exception values, stack frames, breadcrumbs,
|
|
16
|
+
// request data. Layer 1 cannot help there, because none of it is
|
|
17
|
+
// ours to choose.
|
|
18
|
+
//
|
|
19
|
+
// Lives in @doubling/types so web, sync and desktop share one
|
|
20
|
+
// implementation. `functions/` keeps a small local copy: `firebase
|
|
21
|
+
// deploy` runs a standalone `npm ci --workspaces=false`, which cannot
|
|
22
|
+
// resolve a workspace dependency.
|
|
23
|
+
//
|
|
24
|
+
// Deliberately dependency-free and framework-agnostic — it takes and
|
|
25
|
+
// returns a plain object, so it is trivially testable without a Sentry
|
|
26
|
+
// SDK present.
|
|
27
|
+
// Folder names that begin a sync-relative path. Kept as literals rather
|
|
28
|
+
// than imported from paths.ts so this module stays dependency-free and
|
|
29
|
+
// so a rename there cannot silently narrow the redaction.
|
|
30
|
+
const SYNC_ROOTS = ['Private', 'Shared with Me', 'Shared by Me'];
|
|
31
|
+
const EMAIL_RE = /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g;
|
|
32
|
+
// Absolute filesystem paths. These leak the OS username as well as the
|
|
33
|
+
// file, which is why they are redacted even though the daemon's own
|
|
34
|
+
// install directory is not itself secret.
|
|
35
|
+
const ABS_PATH_RE = /(?:\/Users\/|\/home\/|\/var\/folders\/|[A-Za-z]:\\Users\\)[^\s"')\]]+/g;
|
|
36
|
+
// Extensions we recognise. Used both to anchor path matching and to
|
|
37
|
+
// catch bare filenames.
|
|
38
|
+
const EXT_ALT = 'md|markdown|txt|json|ya?ml|csv|pdf|png|jpe?g|gif|heic|docx?|xlsx?|base';
|
|
39
|
+
const SYNC_ROOT_ALT = `(?:${SYNC_ROOTS.map(escapeRegExp).join('|')}|[^\\s"']+ Teamspace)`;
|
|
40
|
+
// A sync-relative path ENDING IN A KNOWN EXTENSION, allowing spaces
|
|
41
|
+
// inside segments.
|
|
42
|
+
//
|
|
43
|
+
// Spaces matter here: "Private/notes/Q3 Budget.md" is an entirely
|
|
44
|
+
// ordinary filename, and a pattern that stops at the first space
|
|
45
|
+
// reports it as two tokens with a misleading depth and extension. Both
|
|
46
|
+
// halves still get redacted — nothing leaks either way — but the shape
|
|
47
|
+
// metadata is the whole point of keeping a token at all, so it should
|
|
48
|
+
// be right.
|
|
49
|
+
//
|
|
50
|
+
// Non-greedy and anchored on the extension so it cannot run on into the
|
|
51
|
+
// prose that follows the path in a log line.
|
|
52
|
+
const SYNC_PATH_EXT_RE = new RegExp(`${SYNC_ROOT_ALT}/[^"')\\]]+?\\.(?:${EXT_ALT})\\b`, 'gi');
|
|
53
|
+
// Extension-less sync paths (folders). No space allowance: without an
|
|
54
|
+
// extension to anchor on, permitting spaces would swallow the rest of
|
|
55
|
+
// the sentence.
|
|
56
|
+
const SYNC_PATH_RE = new RegExp(`${SYNC_ROOT_ALT}/[^\\s"')\\]]+`, 'g');
|
|
57
|
+
// Any remaining bare filename with a plausible extension.
|
|
58
|
+
const FILENAME_RE = new RegExp(`[^\\s"'/\\\\)\\]]+\\.(?:${EXT_ALT})\\b`, 'gi');
|
|
59
|
+
// Content interpolated into a message is the failure mode this cannot
|
|
60
|
+
// enumerate its way out of, so there is a blunt length cap as backstop.
|
|
61
|
+
const MAX_STRING = 200;
|
|
62
|
+
function escapeRegExp(s) {
|
|
63
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
64
|
+
}
|
|
65
|
+
function depthOf(p) {
|
|
66
|
+
return p.split('/').filter(Boolean).length;
|
|
67
|
+
}
|
|
68
|
+
/** Replace a matched path with its shape: depth, extension, name length. */
|
|
69
|
+
function summarisePath(match) {
|
|
70
|
+
const name = match.split('/').pop() ?? '';
|
|
71
|
+
const dot = name.lastIndexOf('.');
|
|
72
|
+
const ext = dot > 0 ? name.slice(dot + 1).toLowerCase() : 'none';
|
|
73
|
+
return `<path:d${depthOf(match)}:ext=${ext}:len=${name.length}>`;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Redact a single string.
|
|
77
|
+
*
|
|
78
|
+
* Order matters: query strings first (Firebase Storage signed URLs
|
|
79
|
+
* carry `?token=`), then the most specific path forms, then bare
|
|
80
|
+
* filenames, then the length cap.
|
|
81
|
+
*/
|
|
82
|
+
export function redactString(input) {
|
|
83
|
+
if (typeof input !== 'string' || input.length === 0)
|
|
84
|
+
return input;
|
|
85
|
+
let out = input;
|
|
86
|
+
// Strip query strings and fragments wholesale. A Storage download URL
|
|
87
|
+
// carries an access token; a redacted path with a live token attached
|
|
88
|
+
// would be worse than the path alone.
|
|
89
|
+
out = out.replace(/([?#])[^\s"')\]]*/g, '$1<redacted>');
|
|
90
|
+
out = out.replace(EMAIL_RE, '<email>');
|
|
91
|
+
out = out.replace(ABS_PATH_RE, (m) => `<abs-path:d${depthOf(m)}>`);
|
|
92
|
+
// Extension-anchored first: it is the more specific pattern, and
|
|
93
|
+
// running the looser one first would truncate at the first space.
|
|
94
|
+
out = out.replace(SYNC_PATH_EXT_RE, summarisePath);
|
|
95
|
+
out = out.replace(SYNC_PATH_RE, summarisePath);
|
|
96
|
+
out = out.replace(FILENAME_RE, (m) => {
|
|
97
|
+
const dot = m.lastIndexOf('.');
|
|
98
|
+
return `<file:ext=${m.slice(dot + 1).toLowerCase()}:len=${m.length}>`;
|
|
99
|
+
});
|
|
100
|
+
if (out.length > MAX_STRING) {
|
|
101
|
+
out = `${out.slice(0, MAX_STRING)}…[truncated]`;
|
|
102
|
+
}
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
105
|
+
/** Recursively redact every string in a value, depth-capped. */
|
|
106
|
+
function redactDeep(value, depth = 0) {
|
|
107
|
+
if (depth > 4)
|
|
108
|
+
return '<depth-capped>';
|
|
109
|
+
if (typeof value === 'string')
|
|
110
|
+
return redactString(value);
|
|
111
|
+
if (Array.isArray(value))
|
|
112
|
+
return value.map((v) => redactDeep(v, depth + 1));
|
|
113
|
+
if (value !== null && typeof value === 'object') {
|
|
114
|
+
const out = {};
|
|
115
|
+
for (const [k, v] of Object.entries(value)) {
|
|
116
|
+
out[k] = redactDeep(v, depth + 1);
|
|
117
|
+
}
|
|
118
|
+
return out;
|
|
119
|
+
}
|
|
120
|
+
return value;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Scrub an error event in place-safe fashion (returns a new object).
|
|
124
|
+
*
|
|
125
|
+
* Returns `null` if scrubbing itself throws. Failing closed is the only
|
|
126
|
+
* acceptable behaviour here: dropping one event costs a diagnostic,
|
|
127
|
+
* leaking one costs customer data.
|
|
128
|
+
*/
|
|
129
|
+
export function scrubEvent(event) {
|
|
130
|
+
try {
|
|
131
|
+
// `T extends object` rather than `T extends ScrubbableEvent`: the
|
|
132
|
+
// point of this module is to stay usable without the Sentry SDK,
|
|
133
|
+
// and an SDK's own ErrorEvent type does not structurally satisfy a
|
|
134
|
+
// hand-written interface (its optional fields are narrower than the
|
|
135
|
+
// `unknown` used here). Callers get their exact type back; the
|
|
136
|
+
// internal view is the structural subset we actually walk.
|
|
137
|
+
const out = { ...event };
|
|
138
|
+
if (typeof out.message === 'string')
|
|
139
|
+
out.message = redactString(out.message);
|
|
140
|
+
if (typeof out.transaction === 'string')
|
|
141
|
+
out.transaction = redactString(out.transaction);
|
|
142
|
+
if (typeof out.culprit === 'string')
|
|
143
|
+
out.culprit = redactString(out.culprit);
|
|
144
|
+
if (out.logentry)
|
|
145
|
+
out.logentry = redactDeep(out.logentry);
|
|
146
|
+
if (out.exception?.values) {
|
|
147
|
+
out.exception = {
|
|
148
|
+
...out.exception,
|
|
149
|
+
values: out.exception.values.map((v) => {
|
|
150
|
+
const val = { ...v };
|
|
151
|
+
if (typeof val['value'] === 'string')
|
|
152
|
+
val['value'] = redactString(val['value']);
|
|
153
|
+
if (typeof val['type'] === 'string')
|
|
154
|
+
val['type'] = redactString(val['type']);
|
|
155
|
+
const st = val['stacktrace'];
|
|
156
|
+
if (st?.frames) {
|
|
157
|
+
val['stacktrace'] = {
|
|
158
|
+
...st,
|
|
159
|
+
frames: st.frames.map((f) => {
|
|
160
|
+
const frame = { ...f };
|
|
161
|
+
for (const k of ['filename', 'abs_path', 'module']) {
|
|
162
|
+
if (typeof frame[k] === 'string')
|
|
163
|
+
frame[k] = redactString(frame[k]);
|
|
164
|
+
}
|
|
165
|
+
// Local variables can hold an entire file body: the
|
|
166
|
+
// daemon throws from inside pushFileToCloud, whose
|
|
167
|
+
// scope holds `data: string | Buffer`. Never send them.
|
|
168
|
+
delete frame['vars'];
|
|
169
|
+
return frame;
|
|
170
|
+
}),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
return val;
|
|
174
|
+
}),
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
if (out.breadcrumbs)
|
|
178
|
+
out.breadcrumbs = redactDeep(out.breadcrumbs);
|
|
179
|
+
if (out.request) {
|
|
180
|
+
// Keep only a redacted URL. Bodies, headers and cookies carry
|
|
181
|
+
// auth tokens and file content and are never worth the risk.
|
|
182
|
+
const url = out.request['url'];
|
|
183
|
+
out.request = typeof url === 'string' ? { url: redactString(url) } : {};
|
|
184
|
+
}
|
|
185
|
+
// Identify the user by opaque uid only. Email is PII and the
|
|
186
|
+
// username is often the person's real name.
|
|
187
|
+
if (out.user) {
|
|
188
|
+
const id = out.user['id'];
|
|
189
|
+
out.user = id === undefined ? {} : { id };
|
|
190
|
+
}
|
|
191
|
+
// Dropped wholesale rather than redacted: `extra` is the field
|
|
192
|
+
// callers reach for when they have something interesting and
|
|
193
|
+
// unstructured, which is exactly when it holds a path or a body.
|
|
194
|
+
// Deliberate context goes through SafeContext instead.
|
|
195
|
+
delete out.extra;
|
|
196
|
+
if (out.contexts)
|
|
197
|
+
out.contexts = redactDeep(out.contexts);
|
|
198
|
+
if (out.tags)
|
|
199
|
+
out.tags = redactDeep(out.tags);
|
|
200
|
+
return out;
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=scrub.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrub.js","sourceRoot":"","sources":["../src/scrub.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,EAAE;AACF,mEAAmE;AACnE,wEAAwE;AACxE,+DAA+D;AAC/D,EAAE;AACF,4BAA4B;AAC5B,EAAE;AACF,iEAAiE;AACjE,yEAAyE;AACzE,mEAAmE;AACnE,8BAA8B;AAC9B,EAAE;AACF,uEAAuE;AACvE,0EAA0E;AAC1E,sEAAsE;AACtE,uBAAuB;AACvB,EAAE;AACF,8DAA8D;AAC9D,mEAAmE;AACnE,sEAAsE;AACtE,kCAAkC;AAClC,EAAE;AACF,qEAAqE;AACrE,uEAAuE;AACvE,eAAe;AA2Bf,wEAAwE;AACxE,uEAAuE;AACvE,0DAA0D;AAC1D,MAAM,UAAU,GAAG,CAAC,SAAS,EAAE,gBAAgB,EAAE,cAAc,CAAC,CAAC;AAEjE,MAAM,QAAQ,GAAG,iDAAiD,CAAC;AAEnE,uEAAuE;AACvE,oEAAoE;AACpE,0CAA0C;AAC1C,MAAM,WAAW,GAAG,wEAAwE,CAAC;AAE7F,oEAAoE;AACpE,wBAAwB;AACxB,MAAM,OAAO,GAAG,wEAAwE,CAAC;AAEzF,MAAM,aAAa,GAAG,MAAM,UAAU,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,uBAAuB,CAAC;AAE1F,oEAAoE;AACpE,mBAAmB;AACnB,EAAE;AACF,kEAAkE;AAClE,iEAAiE;AACjE,uEAAuE;AACvE,uEAAuE;AACvE,sEAAsE;AACtE,YAAY;AACZ,EAAE;AACF,wEAAwE;AACxE,6CAA6C;AAC7C,MAA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 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@doubling/types",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Shared Firestore document interfaces and MIME / path helpers consumed by web/ and sync/. Single source of truth so the two consumers can never drift on a document shape (DOU-182, TS Phase 2 of the monorepo TypeScript migration).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
],
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build": "tsc",
|
|
20
|
+
"test": "node --test \"src/**/*.test.ts\"",
|
|
20
21
|
"typecheck": "tsc --noEmit",
|
|
21
22
|
"prepare": "tsc",
|
|
22
23
|
"prepack": "tsc"
|