@stackone/redaction 1.1.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 +50 -0
- package/dist/edge/index.d.mts +78 -0
- package/dist/edge/index.mjs +1 -0
- package/dist/node/index.d.mts +77 -0
- package/dist/node/index.d.ts +77 -0
- package/dist/node/index.js +1 -0
- package/dist/node/index.mjs +1 -0
- package/package.json +59 -0
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# @stackone/redaction
|
|
2
|
+
|
|
3
|
+
## Description
|
|
4
|
+
|
|
5
|
+
This package contains utility functions for data redaction used by the **StackOne** packages. It provides methods to redact sensitive information in objects, URLs, and paths.
|
|
6
|
+
|
|
7
|
+
This package uses the tech stack provided by the **Connect Monorepo** global setup. Please check the [root README](../../README.md) for more information.
|
|
8
|
+
|
|
9
|
+
## Requirements
|
|
10
|
+
|
|
11
|
+
Please check the [root README](../../README.md) for requirements.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# install dependencies
|
|
17
|
+
$ npm run install
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Available commands
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
# clean build output
|
|
24
|
+
$ npm run clean
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# build package
|
|
29
|
+
$ npm run build
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# run tests
|
|
34
|
+
$ npm run test
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# run tests on watch mode
|
|
39
|
+
$ npm run test:watch
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
# run linter
|
|
44
|
+
$ npm run lint
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# run linter and try to fix any error
|
|
49
|
+
$ npm run lint:fix
|
|
50
|
+
```
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
//#region ../logger/src/types.d.ts
|
|
2
|
+
interface ILogger {
|
|
3
|
+
debug({
|
|
4
|
+
category,
|
|
5
|
+
message,
|
|
6
|
+
traceId,
|
|
7
|
+
context
|
|
8
|
+
}: {
|
|
9
|
+
category?: string;
|
|
10
|
+
message: string;
|
|
11
|
+
traceId?: string;
|
|
12
|
+
context?: Record<string, unknown>;
|
|
13
|
+
}): void;
|
|
14
|
+
info({
|
|
15
|
+
category,
|
|
16
|
+
message,
|
|
17
|
+
traceId,
|
|
18
|
+
context
|
|
19
|
+
}: {
|
|
20
|
+
category?: string;
|
|
21
|
+
message: string;
|
|
22
|
+
traceId?: string;
|
|
23
|
+
context?: Record<string, unknown>;
|
|
24
|
+
}): void;
|
|
25
|
+
warning({
|
|
26
|
+
category,
|
|
27
|
+
message,
|
|
28
|
+
traceId,
|
|
29
|
+
error,
|
|
30
|
+
code,
|
|
31
|
+
context
|
|
32
|
+
}: {
|
|
33
|
+
category?: string;
|
|
34
|
+
message: string;
|
|
35
|
+
traceId?: string;
|
|
36
|
+
error?: LogError;
|
|
37
|
+
code?: string;
|
|
38
|
+
context?: Record<string, unknown>;
|
|
39
|
+
}): void;
|
|
40
|
+
error({
|
|
41
|
+
category,
|
|
42
|
+
message,
|
|
43
|
+
traceId,
|
|
44
|
+
error,
|
|
45
|
+
code,
|
|
46
|
+
context
|
|
47
|
+
}: {
|
|
48
|
+
category?: string;
|
|
49
|
+
message: string;
|
|
50
|
+
traceId?: string;
|
|
51
|
+
error?: LogError;
|
|
52
|
+
code: string;
|
|
53
|
+
context?: Record<string, unknown>;
|
|
54
|
+
}): void;
|
|
55
|
+
}
|
|
56
|
+
type LogError = Error & {
|
|
57
|
+
response?: {
|
|
58
|
+
data?: unknown;
|
|
59
|
+
};
|
|
60
|
+
context?: Record<string, unknown>;
|
|
61
|
+
url?: string;
|
|
62
|
+
};
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/shared/index.d.ts
|
|
65
|
+
declare enum CensorType {
|
|
66
|
+
FULL = "FULL",
|
|
67
|
+
PARTIAL = "PARTIAL",
|
|
68
|
+
}
|
|
69
|
+
declare const redactUrl: (value: string | undefined, censorType?: CensorType, logger?: ILogger) => string | undefined;
|
|
70
|
+
declare const redactPath: (value: string | undefined, censorType?: CensorType, logger?: ILogger) => string | undefined;
|
|
71
|
+
declare const redactFields: <T extends Record<string, unknown> | string>(value: T | undefined, censorType?: CensorType) => T | undefined;
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/edge/index.d.ts
|
|
74
|
+
declare const safeClone: <T>(value: T) => T;
|
|
75
|
+
declare const redactObject: <T>(obj: T, censorType?: CensorType) => T;
|
|
76
|
+
declare const I_AM_EDGE = true;
|
|
77
|
+
//#endregion
|
|
78
|
+
export { I_AM_EDGE, redactFields, redactObject, redactPath, redactUrl, safeClone };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isMissing as e}from"@stackone/utils";const t=[`client_secret`,`access_token`,`refresh_token`,`api_key`,`password`,`job_board_token`,`private_key`,`certificate`,`service_user_token`,`key_id`,`secret_key`,`provhash`,`admin_key`,`session_key`,`id_token`,`authorization`,`bh_rest_token`,`external_trigger_token`,`tempauth`],n=[`req.headers.authorization`,`req.headers.cookie`,`req.headers.cookies`,`req.headers["set-cookie"]`,`req.headers["set-cookies"]`,`req.headers.httpsAgent.options.cert`,`req.headers.httpsAgent.options.key`,`req.headers["x-stackone-external-trigger-token"]`,`error.config.headers.authorization`,`error.config.data`,`error.config.headers.cookie`,`error.config.headers.cookies`,`error.config.headers["set-cookie"]`,`error.config.headers["set-cookies"]`,`error.config.httpsAgent.options.cert`,`error.config.httpsAgent.options.key`,`err.config.headers.authorization`,`err.config.data`,`err.config.headers.cookie`,`err.config.headers.cookies`,`err.config.headers["set-cookie"]`,`err.config.headers["set-cookies"]`,`err.config.httpsAgent.options.cert`,`err.config.httpsAgent.options.key`,`res.headers.authorization`,`res.headers.cookie`,`res.headers.cookies`,`res.headers["set-cookie"]`,`res.headers["set-cookies"]`,`res.headers.httpsAgent.options.cert`,`res.headers.httpsAgent.options.key`,`context.credentials`,...t],r=`**redacted**`;let i=function(e){return e.FULL=`FULL`,e.PARTIAL=`PARTIAL`,e}({});const a=e=>r,o=e=>typeof e==`string`?e.startsWith(r)?e:e.length<=10?r:`${r}${e.slice(-5)}`:r,s=e=>`${e.charAt(0).toUpperCase()}${e.slice(1)}`,c=e=>{let t=e.split(`.`);if(t.length<2)return s(e);let n=t.pop()??``,r=s(n);return[...t,r].join(`.`)},l=e=>{let t=e.lastIndexOf(`[`),n=e.indexOf(`]`,t);if(t===-1||n===-1)return;let r=e.slice(t,n+1),i=r.replace(/(["'])([^"']*)(["'])/g,(e,t,n)=>n?t+s(n)+t:t+t);return`${e.slice(0,t)}${i}${e.slice(n+1)}`},u=e=>{let t=l(e);return t||c(e)},d=(e=[],t=!0)=>{if(!t)return[];let n=e.map(e=>u(e));return[...e,...n]},f=(e=[],t=!0)=>{if(!t)return[];let n=new Set;return e.forEach(e=>{if(n.add(e),e.includes(`_`)){let t=e.replace(/_([a-z])/g,(e,t)=>t.toUpperCase());n.add(t)}else{let t=e.replace(/([A-Z])/g,`_$1`).toLowerCase();n.add(t)}}),Array.from(n)},p={[i.FULL]:a,[i.PARTIAL]:o},m=f(t),h=d(n),g=(t,n=i.FULL,r)=>{if(!e(t))try{let e=new URL(t),r=[...e.searchParams].reduce((e,[t,r])=>{let i=t.toLowerCase();return e.set(t,m.some(e=>e.toLowerCase()===i)?p[n](r):r),e},new URLSearchParams);return`${e.origin}${e.pathname}${r.toString()?`?`+r:``}${e.hash}`}catch(e){return r?.warning({message:`Invalid URL provided, unable to redact`,context:{value:t,error:e},category:`redactUrl`}),t}},_=(t,n=i.FULL,r)=>{if(!e(t))try{let[e,r]=t.split(`?`);if(!r)return t;let i=[...new URLSearchParams(r)].reduce((e,[t,r])=>{let i=t.toLowerCase();return e.set(t,m.some(e=>e.toLowerCase()===i)?p[n](r):r),e},new URLSearchParams);return`${e}?${i}`}catch(e){return r?.warning({message:`Invalid path provided, unable to redact`,context:{value:t,error:e},category:`redactPath`}),t}},v=(t,n=i.FULL)=>{if(!e(t))return typeof t==`string`?p[n](t):Object.entries(t).reduce((e,[t,r])=>(e[t]=m.some(e=>e.toLowerCase()===t.toLowerCase())?p[n](r):r,e),{})};let y;const b=()=>(e(y)&&(y={[i.FULL]:C({paths:h,serialize:!1,censor:p[i.FULL]}),[i.PARTIAL]:C({paths:h,serialize:!1,censor:p[i.PARTIAL]})}),y),x=e=>e.replace(/\[(\d+)\]/g,`.$1`).split(`.`).filter(Boolean),S=()=>`***`,C=e=>{let t=(e.paths??[]).map(x),n=typeof e.censor==`function`?e.censor:S,r=!!e.serialize,i=e=>{if(typeof e!=`object`||!e)return r?String(e):e;for(let r of t){let t=e;for(let e=0;e<r.length-1&&t&&typeof t==`object`;e++)t=t[r[e]];let i=r[r.length-1];t&&Object.prototype.hasOwnProperty.call(t,i)&&(t[i]=n(t[i]))}return r?JSON.stringify(e):e};return i.restore=()=>{},i},w=e=>{let t=globalThis.structuredClone;return typeof t==`function`?t(e):JSON.parse(JSON.stringify(e))},T=(e,t=i.FULL)=>{if(typeof e!=`object`||!e)return e;let n=w(e),r=b();return r[t](n)},E=!0;export{E as I_AM_EDGE,v as redactFields,T as redactObject,_ as redactPath,g as redactUrl,w as safeClone};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
//#region ../logger/src/types.d.ts
|
|
2
|
+
interface ILogger {
|
|
3
|
+
debug({
|
|
4
|
+
category,
|
|
5
|
+
message,
|
|
6
|
+
traceId,
|
|
7
|
+
context
|
|
8
|
+
}: {
|
|
9
|
+
category?: string;
|
|
10
|
+
message: string;
|
|
11
|
+
traceId?: string;
|
|
12
|
+
context?: Record<string, unknown>;
|
|
13
|
+
}): void;
|
|
14
|
+
info({
|
|
15
|
+
category,
|
|
16
|
+
message,
|
|
17
|
+
traceId,
|
|
18
|
+
context
|
|
19
|
+
}: {
|
|
20
|
+
category?: string;
|
|
21
|
+
message: string;
|
|
22
|
+
traceId?: string;
|
|
23
|
+
context?: Record<string, unknown>;
|
|
24
|
+
}): void;
|
|
25
|
+
warning({
|
|
26
|
+
category,
|
|
27
|
+
message,
|
|
28
|
+
traceId,
|
|
29
|
+
error,
|
|
30
|
+
code,
|
|
31
|
+
context
|
|
32
|
+
}: {
|
|
33
|
+
category?: string;
|
|
34
|
+
message: string;
|
|
35
|
+
traceId?: string;
|
|
36
|
+
error?: LogError;
|
|
37
|
+
code?: string;
|
|
38
|
+
context?: Record<string, unknown>;
|
|
39
|
+
}): void;
|
|
40
|
+
error({
|
|
41
|
+
category,
|
|
42
|
+
message,
|
|
43
|
+
traceId,
|
|
44
|
+
error,
|
|
45
|
+
code,
|
|
46
|
+
context
|
|
47
|
+
}: {
|
|
48
|
+
category?: string;
|
|
49
|
+
message: string;
|
|
50
|
+
traceId?: string;
|
|
51
|
+
error?: LogError;
|
|
52
|
+
code: string;
|
|
53
|
+
context?: Record<string, unknown>;
|
|
54
|
+
}): void;
|
|
55
|
+
}
|
|
56
|
+
type LogError = Error & {
|
|
57
|
+
response?: {
|
|
58
|
+
data?: unknown;
|
|
59
|
+
};
|
|
60
|
+
context?: Record<string, unknown>;
|
|
61
|
+
url?: string;
|
|
62
|
+
};
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/shared/index.d.ts
|
|
65
|
+
declare enum CensorType {
|
|
66
|
+
FULL = "FULL",
|
|
67
|
+
PARTIAL = "PARTIAL",
|
|
68
|
+
}
|
|
69
|
+
declare const redactUrl: (value: string | undefined, censorType?: CensorType, logger?: ILogger) => string | undefined;
|
|
70
|
+
declare const redactPath: (value: string | undefined, censorType?: CensorType, logger?: ILogger) => string | undefined;
|
|
71
|
+
declare const redactFields: <T extends Record<string, unknown> | string>(value: T | undefined, censorType?: CensorType) => T | undefined;
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/node/index.d.ts
|
|
74
|
+
declare const redactObject: <T>(obj: T, censorType?: CensorType) => T;
|
|
75
|
+
declare const I_AM_EDGE = false;
|
|
76
|
+
//#endregion
|
|
77
|
+
export { I_AM_EDGE, redactFields, redactObject, redactPath, redactUrl };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
//#region ../logger/src/types.d.ts
|
|
2
|
+
interface ILogger {
|
|
3
|
+
debug({
|
|
4
|
+
category,
|
|
5
|
+
message,
|
|
6
|
+
traceId,
|
|
7
|
+
context
|
|
8
|
+
}: {
|
|
9
|
+
category?: string;
|
|
10
|
+
message: string;
|
|
11
|
+
traceId?: string;
|
|
12
|
+
context?: Record<string, unknown>;
|
|
13
|
+
}): void;
|
|
14
|
+
info({
|
|
15
|
+
category,
|
|
16
|
+
message,
|
|
17
|
+
traceId,
|
|
18
|
+
context
|
|
19
|
+
}: {
|
|
20
|
+
category?: string;
|
|
21
|
+
message: string;
|
|
22
|
+
traceId?: string;
|
|
23
|
+
context?: Record<string, unknown>;
|
|
24
|
+
}): void;
|
|
25
|
+
warning({
|
|
26
|
+
category,
|
|
27
|
+
message,
|
|
28
|
+
traceId,
|
|
29
|
+
error,
|
|
30
|
+
code,
|
|
31
|
+
context
|
|
32
|
+
}: {
|
|
33
|
+
category?: string;
|
|
34
|
+
message: string;
|
|
35
|
+
traceId?: string;
|
|
36
|
+
error?: LogError;
|
|
37
|
+
code?: string;
|
|
38
|
+
context?: Record<string, unknown>;
|
|
39
|
+
}): void;
|
|
40
|
+
error({
|
|
41
|
+
category,
|
|
42
|
+
message,
|
|
43
|
+
traceId,
|
|
44
|
+
error,
|
|
45
|
+
code,
|
|
46
|
+
context
|
|
47
|
+
}: {
|
|
48
|
+
category?: string;
|
|
49
|
+
message: string;
|
|
50
|
+
traceId?: string;
|
|
51
|
+
error?: LogError;
|
|
52
|
+
code: string;
|
|
53
|
+
context?: Record<string, unknown>;
|
|
54
|
+
}): void;
|
|
55
|
+
}
|
|
56
|
+
type LogError = Error & {
|
|
57
|
+
response?: {
|
|
58
|
+
data?: unknown;
|
|
59
|
+
};
|
|
60
|
+
context?: Record<string, unknown>;
|
|
61
|
+
url?: string;
|
|
62
|
+
};
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/shared/index.d.ts
|
|
65
|
+
declare enum CensorType {
|
|
66
|
+
FULL = "FULL",
|
|
67
|
+
PARTIAL = "PARTIAL",
|
|
68
|
+
}
|
|
69
|
+
declare const redactUrl: (value: string | undefined, censorType?: CensorType, logger?: ILogger) => string | undefined;
|
|
70
|
+
declare const redactPath: (value: string | undefined, censorType?: CensorType, logger?: ILogger) => string | undefined;
|
|
71
|
+
declare const redactFields: <T extends Record<string, unknown> | string>(value: T | undefined, censorType?: CensorType) => T | undefined;
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/node/index.d.ts
|
|
74
|
+
declare const redactObject: <T>(obj: T, censorType?: CensorType) => T;
|
|
75
|
+
declare const I_AM_EDGE = false;
|
|
76
|
+
//#endregion
|
|
77
|
+
export { I_AM_EDGE, redactFields, redactObject, redactPath, redactUrl };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));const c=s(require(`@stackone/utils`)),l=s(require(`fast-redact`)),u=[`client_secret`,`access_token`,`refresh_token`,`api_key`,`password`,`job_board_token`,`private_key`,`certificate`,`service_user_token`,`key_id`,`secret_key`,`provhash`,`admin_key`,`session_key`,`id_token`,`authorization`,`bh_rest_token`,`external_trigger_token`,`tempauth`],d=[`req.headers.authorization`,`req.headers.cookie`,`req.headers.cookies`,`req.headers["set-cookie"]`,`req.headers["set-cookies"]`,`req.headers.httpsAgent.options.cert`,`req.headers.httpsAgent.options.key`,`req.headers["x-stackone-external-trigger-token"]`,`error.config.headers.authorization`,`error.config.data`,`error.config.headers.cookie`,`error.config.headers.cookies`,`error.config.headers["set-cookie"]`,`error.config.headers["set-cookies"]`,`error.config.httpsAgent.options.cert`,`error.config.httpsAgent.options.key`,`err.config.headers.authorization`,`err.config.data`,`err.config.headers.cookie`,`err.config.headers.cookies`,`err.config.headers["set-cookie"]`,`err.config.headers["set-cookies"]`,`err.config.httpsAgent.options.cert`,`err.config.httpsAgent.options.key`,`res.headers.authorization`,`res.headers.cookie`,`res.headers.cookies`,`res.headers["set-cookie"]`,`res.headers["set-cookies"]`,`res.headers.httpsAgent.options.cert`,`res.headers.httpsAgent.options.key`,`context.credentials`,...u],f=`**redacted**`;let p=function(e){return e.FULL=`FULL`,e.PARTIAL=`PARTIAL`,e}({});const m=e=>f,h=e=>typeof e==`string`?e.startsWith(f)?e:e.length<=10?f:`${f}${e.slice(-5)}`:f,g=e=>`${e.charAt(0).toUpperCase()}${e.slice(1)}`,_=e=>{let t=e.split(`.`);if(t.length<2)return g(e);let n=t.pop()??``,r=g(n);return[...t,r].join(`.`)},v=e=>{let t=e.lastIndexOf(`[`),n=e.indexOf(`]`,t);if(t===-1||n===-1)return;let r=e.slice(t,n+1),i=r.replace(/(["'])([^"']*)(["'])/g,(e,t,n)=>n?t+g(n)+t:t+t);return`${e.slice(0,t)}${i}${e.slice(n+1)}`},y=e=>{let t=v(e);return t||_(e)},b=(e=[],t=!0)=>{if(!t)return[];let n=e.map(e=>y(e));return[...e,...n]},x=(e=[],t=!0)=>{if(!t)return[];let n=new Set;return e.forEach(e=>{if(n.add(e),e.includes(`_`)){let t=e.replace(/_([a-z])/g,(e,t)=>t.toUpperCase());n.add(t)}else{let t=e.replace(/([A-Z])/g,`_$1`).toLowerCase();n.add(t)}}),Array.from(n)},S={[p.FULL]:m,[p.PARTIAL]:h},C=x(u),w=b(d),T=(e,t=p.FULL,n)=>{if(!(0,c.isMissing)(e))try{let n=new URL(e),r=[...n.searchParams].reduce((e,[n,r])=>{let i=n.toLowerCase();return e.set(n,C.some(e=>e.toLowerCase()===i)?S[t](r):r),e},new URLSearchParams);return`${n.origin}${n.pathname}${r.toString()?`?`+r:``}${n.hash}`}catch(t){return n?.warning({message:`Invalid URL provided, unable to redact`,context:{value:e,error:t},category:`redactUrl`}),e}},E=(e,t=p.FULL,n)=>{if(!(0,c.isMissing)(e))try{let[n,r]=e.split(`?`);if(!r)return e;let i=[...new URLSearchParams(r)].reduce((e,[n,r])=>{let i=n.toLowerCase();return e.set(n,C.some(e=>e.toLowerCase()===i)?S[t](r):r),e},new URLSearchParams);return`${n}?${i}`}catch(t){return n?.warning({message:`Invalid path provided, unable to redact`,context:{value:e,error:t},category:`redactPath`}),e}},D=(e,t=p.FULL)=>{if(!(0,c.isMissing)(e))return typeof e==`string`?S[t](e):Object.entries(e).reduce((e,[n,r])=>(e[n]=C.some(e=>e.toLowerCase()===n.toLowerCase())?S[t](r):r,e),{})};let O;const k=()=>((0,c.isMissing)(O)&&(O={[p.FULL]:(0,l.default)({paths:w,serialize:!1,censor:S[p.FULL]}),[p.PARTIAL]:(0,l.default)({paths:w,serialize:!1,censor:S[p.PARTIAL]})}),O),A=(e,t=p.FULL)=>{if((0,c.isMissing)(e)||typeof e!=`object`||!e)return e;let n=k();return n[t]((0,c.deepCopy)(e))},j=!1;exports.I_AM_EDGE=j,exports.redactFields=D,exports.redactObject=A,exports.redactPath=E,exports.redactUrl=T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{deepCopy as e,isMissing as t}from"@stackone/utils";import n from"fast-redact";const r=[`client_secret`,`access_token`,`refresh_token`,`api_key`,`password`,`job_board_token`,`private_key`,`certificate`,`service_user_token`,`key_id`,`secret_key`,`provhash`,`admin_key`,`session_key`,`id_token`,`authorization`,`bh_rest_token`,`external_trigger_token`,`tempauth`],i=[`req.headers.authorization`,`req.headers.cookie`,`req.headers.cookies`,`req.headers["set-cookie"]`,`req.headers["set-cookies"]`,`req.headers.httpsAgent.options.cert`,`req.headers.httpsAgent.options.key`,`req.headers["x-stackone-external-trigger-token"]`,`error.config.headers.authorization`,`error.config.data`,`error.config.headers.cookie`,`error.config.headers.cookies`,`error.config.headers["set-cookie"]`,`error.config.headers["set-cookies"]`,`error.config.httpsAgent.options.cert`,`error.config.httpsAgent.options.key`,`err.config.headers.authorization`,`err.config.data`,`err.config.headers.cookie`,`err.config.headers.cookies`,`err.config.headers["set-cookie"]`,`err.config.headers["set-cookies"]`,`err.config.httpsAgent.options.cert`,`err.config.httpsAgent.options.key`,`res.headers.authorization`,`res.headers.cookie`,`res.headers.cookies`,`res.headers["set-cookie"]`,`res.headers["set-cookies"]`,`res.headers.httpsAgent.options.cert`,`res.headers.httpsAgent.options.key`,`context.credentials`,...r],a=`**redacted**`;let o=function(e){return e.FULL=`FULL`,e.PARTIAL=`PARTIAL`,e}({});const s=e=>a,c=e=>typeof e==`string`?e.startsWith(a)?e:e.length<=10?a:`${a}${e.slice(-5)}`:a,l=e=>`${e.charAt(0).toUpperCase()}${e.slice(1)}`,u=e=>{let t=e.split(`.`);if(t.length<2)return l(e);let n=t.pop()??``,r=l(n);return[...t,r].join(`.`)},d=e=>{let t=e.lastIndexOf(`[`),n=e.indexOf(`]`,t);if(t===-1||n===-1)return;let r=e.slice(t,n+1),i=r.replace(/(["'])([^"']*)(["'])/g,(e,t,n)=>n?t+l(n)+t:t+t);return`${e.slice(0,t)}${i}${e.slice(n+1)}`},f=e=>{let t=d(e);return t||u(e)},p=(e=[],t=!0)=>{if(!t)return[];let n=e.map(e=>f(e));return[...e,...n]},m=(e=[],t=!0)=>{if(!t)return[];let n=new Set;return e.forEach(e=>{if(n.add(e),e.includes(`_`)){let t=e.replace(/_([a-z])/g,(e,t)=>t.toUpperCase());n.add(t)}else{let t=e.replace(/([A-Z])/g,`_$1`).toLowerCase();n.add(t)}}),Array.from(n)},h={[o.FULL]:s,[o.PARTIAL]:c},g=m(r),_=p(i),v=(e,n=o.FULL,r)=>{if(!t(e))try{let t=new URL(e),r=[...t.searchParams].reduce((e,[t,r])=>{let i=t.toLowerCase();return e.set(t,g.some(e=>e.toLowerCase()===i)?h[n](r):r),e},new URLSearchParams);return`${t.origin}${t.pathname}${r.toString()?`?`+r:``}${t.hash}`}catch(t){return r?.warning({message:`Invalid URL provided, unable to redact`,context:{value:e,error:t},category:`redactUrl`}),e}},y=(e,n=o.FULL,r)=>{if(!t(e))try{let[t,r]=e.split(`?`);if(!r)return e;let i=[...new URLSearchParams(r)].reduce((e,[t,r])=>{let i=t.toLowerCase();return e.set(t,g.some(e=>e.toLowerCase()===i)?h[n](r):r),e},new URLSearchParams);return`${t}?${i}`}catch(t){return r?.warning({message:`Invalid path provided, unable to redact`,context:{value:e,error:t},category:`redactPath`}),e}},b=(e,n=o.FULL)=>{if(!t(e))return typeof e==`string`?h[n](e):Object.entries(e).reduce((e,[t,r])=>(e[t]=g.some(e=>e.toLowerCase()===t.toLowerCase())?h[n](r):r,e),{})};let x;const S=()=>(t(x)&&(x={[o.FULL]:n({paths:_,serialize:!1,censor:h[o.FULL]}),[o.PARTIAL]:n({paths:_,serialize:!1,censor:h[o.PARTIAL]})}),x),C=(n,r=o.FULL)=>{if(t(n)||typeof n!=`object`||!n)return n;let i=S();return i[r](e(n))},w=!1;export{w as I_AM_EDGE,b as redactFields,C as redactObject,y as redactPath,v as redactUrl};
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stackone/redaction",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/node/index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"package.json",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"browser": {
|
|
15
|
+
"types": "./dist/edge/index.d.ts",
|
|
16
|
+
"import": "./dist/edge/index.mjs",
|
|
17
|
+
"require": "./dist/edge/index.mjs"
|
|
18
|
+
},
|
|
19
|
+
"types": "./dist/node/index.d.ts",
|
|
20
|
+
"import": "./dist/node/index.mjs",
|
|
21
|
+
"require": "./dist/node/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./edge": {
|
|
24
|
+
"types": "./dist/edge/index.d.ts",
|
|
25
|
+
"import": "./dist/edge/index.mjs",
|
|
26
|
+
"require": "./dist/edge/index.mjs"
|
|
27
|
+
},
|
|
28
|
+
"./package.json": "./package.json"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"clean": "rimraf dist",
|
|
32
|
+
"prebuild": "npm run clean",
|
|
33
|
+
"build": "npm run clean && tsdown -c tsdown.config.ts --env.NODE_ENV=production --minify",
|
|
34
|
+
"prebuild:dev": "npm run clean",
|
|
35
|
+
"build:dev": "tsdown --env.NODE_ENV=development",
|
|
36
|
+
"code:format": "biome format ./src ./*.mjs",
|
|
37
|
+
"code:format:fix": "biome format --write ./src ./*.mjs",
|
|
38
|
+
"code:lint": "biome lint --error-on-warnings ./src ./*.mjs",
|
|
39
|
+
"code:lint:fix": "biome lint --write ./src ./*.mjs",
|
|
40
|
+
"code:check": "biome check ./src ./*.mjs",
|
|
41
|
+
"code:check:fix": "biome check --write ./src ./*.mjs",
|
|
42
|
+
"lint": "npm run code:check",
|
|
43
|
+
"lint:fix": "npm run code:check:fix",
|
|
44
|
+
"test": "vitest run",
|
|
45
|
+
"test:watch": "vitest watch",
|
|
46
|
+
"publish-release": "npm publish --access=public"
|
|
47
|
+
},
|
|
48
|
+
"keywords": [],
|
|
49
|
+
"author": "StackOne",
|
|
50
|
+
"license": "ISC",
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@stackone/logger": "*",
|
|
53
|
+
"@stackone/utils": "*",
|
|
54
|
+
"fast-redact": "^3.3.0"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"tsdown": "^0.12.9"
|
|
58
|
+
}
|
|
59
|
+
}
|