@venizia/ignis-helpers 0.4.8 → 0.5.0-1
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/dist/esm/common/constants/http.d.ts +17 -1
- package/dist/esm/common/constants/http.js +17 -0
- package/dist/esm/common/constants/http.js.map +1 -1
- package/dist/esm/common/redact.js +2 -0
- package/dist/esm/common/redact.js.map +1 -1
- package/dist/esm/core.d.ts +5 -2
- package/dist/esm/core.js +5 -2
- package/dist/esm/core.js.map +1 -1
- package/dist/esm/modules/network/http-request/base-network-request.helper.d.ts +5 -0
- package/dist/esm/modules/network/http-request/base-network-request.helper.js +14 -17
- package/dist/esm/modules/network/http-request/base-network-request.helper.js.map +1 -1
- package/dist/esm/modules/network/http-request/common/constants.d.ts +2 -1
- package/dist/esm/modules/network/http-request/common/constants.js +2 -1
- package/dist/esm/modules/network/http-request/common/constants.js.map +1 -1
- package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.d.ts +37 -11
- package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.js +181 -38
- package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.js.map +1 -1
- package/dist/esm/modules/network/http-request/fetcher/base-fetcher.d.ts +204 -18
- package/dist/esm/modules/network/http-request/fetcher/base-fetcher.js +433 -13
- package/dist/esm/modules/network/http-request/fetcher/base-fetcher.js.map +1 -1
- package/dist/esm/modules/network/http-request/fetcher/common/body-limit.d.ts +36 -0
- package/dist/esm/modules/network/http-request/fetcher/common/body-limit.js +119 -0
- package/dist/esm/modules/network/http-request/fetcher/common/body-limit.js.map +1 -0
- package/dist/esm/modules/network/http-request/fetcher/common/errors.d.ts +40 -0
- package/dist/esm/modules/network/http-request/fetcher/common/errors.js +37 -0
- package/dist/esm/modules/network/http-request/fetcher/common/errors.js.map +1 -0
- package/dist/esm/modules/network/http-request/fetcher/common/guard.d.ts +27 -0
- package/dist/esm/modules/network/http-request/fetcher/common/guard.js +2 -0
- package/dist/esm/modules/network/http-request/fetcher/common/guard.js.map +1 -0
- package/dist/esm/modules/network/http-request/fetcher/common/index.d.ts +6 -0
- package/dist/esm/modules/network/http-request/fetcher/common/index.js +6 -0
- package/dist/esm/modules/network/http-request/fetcher/common/index.js.map +1 -1
- package/dist/esm/modules/network/http-request/fetcher/common/request-context.d.ts +15 -0
- package/dist/esm/modules/network/http-request/fetcher/common/request-context.js +11 -0
- package/dist/esm/modules/network/http-request/fetcher/common/request-context.js.map +1 -0
- package/dist/esm/modules/network/http-request/fetcher/common/response-reader.d.ts +133 -0
- package/dist/esm/modules/network/http-request/fetcher/common/response-reader.js +264 -0
- package/dist/esm/modules/network/http-request/fetcher/common/response-reader.js.map +1 -0
- package/dist/esm/modules/network/http-request/fetcher/common/types.d.ts +65 -1
- package/dist/esm/modules/network/http-request/fetcher/common/types.js.map +1 -1
- package/dist/esm/modules/network/http-request/fetcher/common/utilities.d.ts +68 -0
- package/dist/esm/modules/network/http-request/fetcher/common/utilities.js +143 -0
- package/dist/esm/modules/network/http-request/fetcher/common/utilities.js.map +1 -0
- package/dist/esm/modules/network/http-request/fetcher/index.d.ts +2 -1
- package/dist/esm/modules/network/http-request/fetcher/index.js +2 -1
- package/dist/esm/modules/network/http-request/fetcher/index.js.map +1 -1
- package/dist/esm/modules/network/http-request/fetcher/native-fetcher.d.ts +85 -0
- package/dist/esm/modules/network/http-request/fetcher/native-fetcher.js +221 -0
- package/dist/esm/modules/network/http-request/fetcher/native-fetcher.js.map +1 -0
- package/dist/esm/modules/network/utilities/index.d.ts +1 -0
- package/dist/esm/modules/network/utilities/index.js +1 -0
- package/dist/esm/modules/network/utilities/index.js.map +1 -1
- package/dist/esm/modules/network/utilities/query-string.d.ts +6 -23
- package/dist/esm/modules/network/utilities/query-string.js +3 -17
- package/dist/esm/modules/network/utilities/query-string.js.map +1 -1
- package/dist/esm/modules/network/utilities/url-builder.d.ts +39 -0
- package/dist/esm/modules/network/utilities/url-builder.js +102 -0
- package/dist/esm/modules/network/utilities/url-builder.js.map +1 -0
- package/dist/esm/modules/network/utilities/url-safety/common/constants.d.ts +0 -3
- package/dist/esm/modules/network/utilities/url-safety/common/constants.js.map +1 -1
- package/dist/esm/modules/network/utilities/url-safety/common/errors.d.ts +38 -0
- package/dist/esm/modules/network/utilities/url-safety/common/errors.js +33 -1
- package/dist/esm/modules/network/utilities/url-safety/common/errors.js.map +1 -1
- package/dist/esm/modules/network/utilities/url-safety/common/types.d.ts +26 -3
- package/dist/esm/modules/network/utilities/url-safety/common/types.js.map +1 -1
- package/dist/esm/modules/network/utilities/url-safety/guard.d.ts +46 -0
- package/dist/esm/modules/network/utilities/url-safety/guard.js +145 -0
- package/dist/esm/modules/network/utilities/url-safety/guard.js.map +1 -0
- package/dist/esm/modules/network/utilities/url-safety/index.d.ts +1 -1
- package/dist/esm/modules/network/utilities/url-safety/index.js +1 -1
- package/dist/esm/modules/network/utilities/url-safety/index.js.map +1 -1
- package/dist/esm/modules/network/utilities/url-safety/policy.d.ts +52 -2
- package/dist/esm/modules/network/utilities/url-safety/policy.js +161 -14
- package/dist/esm/modules/network/utilities/url-safety/policy.js.map +1 -1
- package/dist/esm/modules/queue/bullmq/helper.d.ts +43 -7
- package/dist/esm/modules/queue/bullmq/helper.js +70 -2
- package/dist/esm/modules/queue/bullmq/helper.js.map +1 -1
- package/dist/esm/modules/retry/helper.d.ts +3 -1
- package/dist/esm/modules/retry/helper.js +8 -4
- package/dist/esm/modules/retry/helper.js.map +1 -1
- package/dist/esm/utilities/request.utility.d.ts +1 -25
- package/dist/esm/utilities/request.utility.js +0 -46
- package/dist/esm/utilities/request.utility.js.map +1 -1
- package/package.json +4 -4
- package/dist/esm/modules/network/http-request/fetcher/node-fetcher.d.ts +0 -41
- package/dist/esm/modules/network/http-request/fetcher/node-fetcher.js +0 -111
- package/dist/esm/modules/network/http-request/fetcher/node-fetcher.js.map +0 -1
- package/dist/esm/modules/network/utilities/url-safety/ingest.d.ts +0 -95
- package/dist/esm/modules/network/utilities/url-safety/ingest.js +0 -328
- package/dist/esm/modules/network/utilities/url-safety/ingest.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ValueOf } from '../types/index.js';
|
|
1
|
+
import { type TConstValue, type ValueOf } from '../types/index.js';
|
|
2
2
|
/** HTTP constants: header names, CORS headers, header values, methods, protocols and status codes. Header names, methods and protocols are lowercase. */
|
|
3
3
|
export declare class HTTP {
|
|
4
4
|
/** Standard and common HTTP headers (lowercase per HTTP/2 convention). */
|
|
@@ -50,6 +50,7 @@ export declare class HTTP {
|
|
|
50
50
|
readonly X_FORWARDED_FOR: "x-forwarded-for";
|
|
51
51
|
readonly X_FORWARDED_HOST: "x-forwarded-host";
|
|
52
52
|
readonly X_FORWARDED_PROTO: "x-forwarded-proto";
|
|
53
|
+
readonly X_REAL_IP: "x-real-ip";
|
|
53
54
|
readonly X_RATELIMIT_LIMIT: "x-ratelimit-limit";
|
|
54
55
|
readonly X_RATELIMIT_REMAINING: "x-ratelimit-remaining";
|
|
55
56
|
readonly X_RATELIMIT_RESET: "x-ratelimit-reset";
|
|
@@ -61,6 +62,10 @@ export declare class HTTP {
|
|
|
61
62
|
readonly RESPONSE_COUNT_DATA: "x-response-count";
|
|
62
63
|
readonly RESPONSE_FORMAT: "x-response-format";
|
|
63
64
|
readonly RESPONSE_EXTRA: "x-response-extra";
|
|
65
|
+
readonly AUTH_PROVIDER: "x-auth-provider";
|
|
66
|
+
readonly LOCALE: "x-locale";
|
|
67
|
+
readonly TIMEZONE: "timezone";
|
|
68
|
+
readonly TIMEZONE_OFFSET: "timezone-offset";
|
|
64
69
|
};
|
|
65
70
|
/**
|
|
66
71
|
* The headers IGNIS adds to a request and to a response, for a CORS configuration that lists them
|
|
@@ -78,6 +83,8 @@ export declare class HTTP {
|
|
|
78
83
|
readonly APPLICATION_GZIP: "application/gzip";
|
|
79
84
|
readonly APPLICATION_JAVASCRIPT: "application/javascript";
|
|
80
85
|
readonly APPLICATION_JSON: "application/json";
|
|
86
|
+
/** A JSON body with its charset named, the value a client sends by default. */
|
|
87
|
+
readonly APPLICATION_JSON_UTF8: "application/json; charset=utf-8";
|
|
81
88
|
readonly APPLICATION_MSGPACK: "application/msgpack";
|
|
82
89
|
readonly APPLICATION_NDJSON: "application/x-ndjson";
|
|
83
90
|
readonly APPLICATION_OCTET_STREAM: "application/octet-stream";
|
|
@@ -191,4 +198,13 @@ export type THttpMethod = ValueOf<typeof HTTP.Methods> | Uppercase<ValueOf<typeo
|
|
|
191
198
|
export type THttpProtocol = ValueOf<typeof HTTP.Protocols> | Uppercase<ValueOf<typeof HTTP.Protocols>>;
|
|
192
199
|
/** A numeric HTTP status code from any class in `HTTP.ResultCodes`. */
|
|
193
200
|
export type THttpResultCode = ValueOf<typeof HTTP.ResultCodes>;
|
|
201
|
+
/** How a client treats a download: ATTACHMENT saves it, INLINE shows it. */
|
|
202
|
+
export declare class ContentDispositionTypes {
|
|
203
|
+
static readonly ATTACHMENT = "attachment";
|
|
204
|
+
static readonly INLINE = "inline";
|
|
205
|
+
static readonly SCHEME_SET: Set<string>;
|
|
206
|
+
static isValid(value: string): boolean;
|
|
207
|
+
}
|
|
208
|
+
/** Valid Content-Disposition type values. */
|
|
209
|
+
export type TContentDispositionType = TConstValue<typeof ContentDispositionTypes>;
|
|
194
210
|
//# sourceMappingURL=http.d.ts.map
|
|
@@ -56,6 +56,7 @@ export class HTTP {
|
|
|
56
56
|
X_FORWARDED_FOR: 'x-forwarded-for',
|
|
57
57
|
X_FORWARDED_HOST: 'x-forwarded-host',
|
|
58
58
|
X_FORWARDED_PROTO: 'x-forwarded-proto',
|
|
59
|
+
X_REAL_IP: 'x-real-ip',
|
|
59
60
|
// Rate limiting (de facto standard)
|
|
60
61
|
X_RATELIMIT_LIMIT: 'x-ratelimit-limit',
|
|
61
62
|
X_RATELIMIT_REMAINING: 'x-ratelimit-remaining',
|
|
@@ -69,6 +70,11 @@ export class HTTP {
|
|
|
69
70
|
RESPONSE_COUNT_DATA: 'x-response-count',
|
|
70
71
|
RESPONSE_FORMAT: 'x-response-format',
|
|
71
72
|
RESPONSE_EXTRA: 'x-response-extra',
|
|
73
|
+
// Client context
|
|
74
|
+
AUTH_PROVIDER: 'x-auth-provider',
|
|
75
|
+
LOCALE: 'x-locale',
|
|
76
|
+
TIMEZONE: 'timezone',
|
|
77
|
+
TIMEZONE_OFFSET: 'timezone-offset',
|
|
72
78
|
}; }
|
|
73
79
|
/**
|
|
74
80
|
* The headers IGNIS adds to a request and to a response, for a CORS configuration that lists them
|
|
@@ -99,6 +105,8 @@ export class HTTP {
|
|
|
99
105
|
APPLICATION_GZIP: 'application/gzip',
|
|
100
106
|
APPLICATION_JAVASCRIPT: 'application/javascript',
|
|
101
107
|
APPLICATION_JSON: 'application/json',
|
|
108
|
+
/** A JSON body with its charset named, the value a client sends by default. */
|
|
109
|
+
APPLICATION_JSON_UTF8: 'application/json; charset=utf-8',
|
|
102
110
|
APPLICATION_MSGPACK: 'application/msgpack',
|
|
103
111
|
APPLICATION_NDJSON: 'application/x-ndjson',
|
|
104
112
|
APPLICATION_OCTET_STREAM: 'application/octet-stream',
|
|
@@ -210,4 +218,13 @@ export class HTTP {
|
|
|
210
218
|
},
|
|
211
219
|
}; }
|
|
212
220
|
}
|
|
221
|
+
/** How a client treats a download: ATTACHMENT saves it, INLINE shows it. */
|
|
222
|
+
export class ContentDispositionTypes {
|
|
223
|
+
static { this.ATTACHMENT = 'attachment'; }
|
|
224
|
+
static { this.INLINE = 'inline'; }
|
|
225
|
+
static { this.SCHEME_SET = new Set([this.ATTACHMENT, this.INLINE]); }
|
|
226
|
+
static isValid(value) {
|
|
227
|
+
return this.SCHEME_SET.has(value);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
213
230
|
//# sourceMappingURL=http.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../../src/common/constants/http.ts"],"names":[],"mappings":"AAEA,yJAAyJ;AACzJ,MAAM,OAAO,IAA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AG;YACpB,SAAS,EAAE,GAAG;YACd,QAAQ,EAAE,GAAG;YACb,gBAAgB,EAAE,GAAG;YACrB,aAAa,EAAE,GAAG;YAClB,cAAc,EAAE,GAAG;YACnB,QAAQ,EAAE,GAAG;YACb,IAAI,EAAE,GAAG;YACT,cAAc,EAAE,GAAG;YACnB,kBAAkB,EAAE,GAAG;YACvB,eAAe,EAAE,GAAG;YACpB,UAAU,EAAE,GAAG;YACf,oBAAoB,EAAE,GAAG;YACzB,mBAAmB,EAAE,GAAG;YACxB,iBAAiB,EAAE,GAAG;YACtB,mBAAmB,EAAE,GAAG;YACxB,MAAM,EAAE,GAAG;YACX,gBAAgB,EAAE,GAAG;YACrB,QAAQ,EAAE,GAAG;YACb,eAAe,EAAE,GAAG;YACpB,oBAAoB,EAAE,GAAG;YACzB,eAAe,EAAE,GAAG;YACpB,2BAA2B,EAAE,GAAG;YAChC,0BAA0B,EAAE,GAAG;SAChC;QAED,0BAA0B;QAC1B,IAAI,EAAE;YACJ,mBAAmB,EAAE,GAAG;YACxB,cAAc,EAAE,GAAG;YACnB,UAAU,EAAE,GAAG;YACf,kBAAkB,EAAE,GAAG;YACvB,cAAc,EAAE,GAAG;YACnB,uBAAuB,EAAE,GAAG;YAC5B,mBAAmB,EAAE,GAAG;YACxB,YAAY,EAAE,GAAG;YACjB,6BAA6B,EAAE,GAAG;SACnC;KACO,CAAC","sourcesContent":["import { type ValueOf } from '../types';\n\n/** HTTP constants: header names, CORS headers, header values, methods, protocols and status codes. Header names, methods and protocols are lowercase. */\nexport class HTTP {\n /** Standard and common HTTP headers (lowercase per HTTP/2 convention). */\n static readonly Headers = {\n // Content\n CONTENT_DISPOSITION: 'content-disposition',\n CONTENT_ENCODING: 'content-encoding',\n CONTENT_LENGTH: 'content-length',\n CONTENT_TYPE: 'content-type',\n CONTENT_RANGE: 'content-range',\n CONTENT_SECURITY_POLICY: 'content-security-policy',\n ACCEPT_RANGES: 'accept-ranges',\n RANGE: 'range',\n\n // Request - content negotiation & conditionals\n ACCEPT: 'accept',\n ACCEPT_ENCODING: 'accept-encoding',\n ACCEPT_LANGUAGE: 'accept-language',\n AUTHORIZATION: 'authorization',\n COOKIE: 'cookie',\n HOST: 'host',\n IF_MATCH: 'if-match',\n IF_MODIFIED_SINCE: 'if-modified-since',\n IF_NONE_MATCH: 'if-none-match',\n ORIGIN: 'origin',\n REFERER: 'referer',\n USER_AGENT: 'user-agent',\n\n // Response - caching, auth challenges & redirects\n ALLOW: 'allow',\n CACHE_CONTROL: 'cache-control',\n ETAG: 'etag',\n LAST_MODIFIED: 'last-modified',\n LOCATION: 'location',\n RETRY_AFTER: 'retry-after',\n SET_COOKIE: 'set-cookie',\n VARY: 'vary',\n WWW_AUTHENTICATE: 'www-authenticate',\n\n // CORS (RFC 6454 / Fetch spec)\n ACCESS_CONTROL_ALLOW_CREDENTIALS: 'access-control-allow-credentials',\n ACCESS_CONTROL_ALLOW_HEADERS: 'access-control-allow-headers',\n ACCESS_CONTROL_ALLOW_METHODS: 'access-control-allow-methods',\n ACCESS_CONTROL_ALLOW_ORIGIN: 'access-control-allow-origin',\n ACCESS_CONTROL_EXPOSE_HEADERS: 'access-control-expose-headers',\n ACCESS_CONTROL_MAX_AGE: 'access-control-max-age',\n ACCESS_CONTROL_REQUEST_HEADERS: 'access-control-request-headers',\n ACCESS_CONTROL_REQUEST_METHOD: 'access-control-request-method',\n\n // Transport\n CONNECTION: 'connection',\n TRANSFER_ENCODING: 'transfer-encoding',\n UPGRADE: 'upgrade',\n\n // Security\n STRICT_TRANSPORT_SECURITY: 'strict-transport-security',\n X_CONTENT_TYPE_OPTIONS: 'x-content-type-options',\n X_FRAME_OPTIONS: 'x-frame-options',\n\n // Proxy / forwarding (de facto standard)\n FORWARDED: 'forwarded',\n X_FORWARDED_FOR: 'x-forwarded-for',\n X_FORWARDED_HOST: 'x-forwarded-host',\n X_FORWARDED_PROTO: 'x-forwarded-proto',\n\n // Rate limiting (de facto standard)\n X_RATELIMIT_LIMIT: 'x-ratelimit-limit',\n X_RATELIMIT_REMAINING: 'x-ratelimit-remaining',\n X_RATELIMIT_RESET: 'x-ratelimit-reset',\n\n // IGNIS custom\n REQUEST_TRACING_ID: 'x-request-id',\n REQUEST_DEVICE_INFO: 'x-device-info',\n REQUEST_CHANNEL: 'x-request-channel',\n REQUEST_COUNT_DATA: 'x-request-count',\n REQUEST_EXTRA: 'x-request-extra',\n RESPONSE_COUNT_DATA: 'x-response-count',\n RESPONSE_FORMAT: 'x-response-format',\n RESPONSE_EXTRA: 'x-response-extra',\n } as const;\n\n /**\n * The headers IGNIS adds to a request and to a response, for a CORS configuration that lists them\n * by hand: spread `ALLOW` into the allowed request headers and `EXPOSE` into the exposed ones, so\n * a header IGNIS adds later needs no change there.\n */\n static readonly CorsHeaders = {\n ALLOW: [\n 'x-request-id',\n 'x-request-count',\n 'x-request-extra',\n 'x-request-channel',\n 'x-device-info',\n ],\n EXPOSE: [\n 'content-range',\n 'x-request-id',\n 'x-response-count',\n 'x-response-format',\n 'x-response-extra',\n ],\n } as const;\n\n /** Common MIME / Content-Type values. */\n static readonly HeaderValues = {\n // Application\n APPLICATION_FORM_URLENCODED: 'application/x-www-form-urlencoded',\n APPLICATION_GRAPHQL_JSON: 'application/graphql+json',\n APPLICATION_GZIP: 'application/gzip',\n APPLICATION_JAVASCRIPT: 'application/javascript',\n APPLICATION_JSON: 'application/json',\n APPLICATION_MSGPACK: 'application/msgpack',\n APPLICATION_NDJSON: 'application/x-ndjson',\n APPLICATION_OCTET_STREAM: 'application/octet-stream',\n APPLICATION_PDF: 'application/pdf',\n APPLICATION_PROTOBUF: 'application/x-protobuf',\n APPLICATION_XML: 'application/xml',\n APPLICATION_ZIP: 'application/zip',\n\n // Multipart\n MULTIPART_FORM_DATA: 'multipart/form-data',\n\n // Text\n TEXT_CSS: 'text/css',\n TEXT_CSV: 'text/csv',\n TEXT_EVENT_STREAM: 'text/event-stream',\n TEXT_HTML: 'text/html',\n TEXT_PLAIN: 'text/plain',\n TEXT_XML: 'text/xml',\n\n // Image\n IMAGE_GIF: 'image/gif',\n IMAGE_JPEG: 'image/jpeg',\n IMAGE_PNG: 'image/png',\n IMAGE_SVG: 'image/svg+xml',\n IMAGE_WEBP: 'image/webp',\n\n // Range units\n RANGE_UNIT_BYTES: 'bytes',\n } as const;\n\n /** Standard HTTP methods (lowercase). */\n static readonly Methods = {\n GET: 'get',\n POST: 'post',\n PUT: 'put',\n PATCH: 'patch',\n DELETE: 'delete',\n HEAD: 'head',\n OPTIONS: 'options',\n QUERY: 'query',\n } as const;\n\n /** Standard HTTP protocols (lowercase). */\n static readonly Protocols = {\n HTTP: 'http',\n HTTPS: 'https',\n } as const;\n\n /** HTTP status codes grouped by class (1xx - 5xx). */\n static readonly ResultCodes = {\n /** 1xx - Informational. */\n RS_1: {\n Continue: 100,\n SwitchingProtocols: 101,\n EarlyHints: 103,\n },\n\n /** 2xx - Success. */\n RS_2: {\n Ok: 200,\n Created: 201,\n Accepted: 202,\n NonAuthoritativeInformation: 203,\n NoContent: 204,\n ResetContent: 205,\n PartialContent: 206,\n MultiStatus: 207,\n },\n\n /** 3xx - Redirection. */\n RS_3: {\n MovedPermanently: 301,\n Found: 302,\n NotModified: 304,\n TemporaryRedirect: 307,\n PermanentRedirect: 308,\n },\n\n /** 4xx - Client error. */\n RS_4: {\n BadRequest: 400,\n Unauthorized: 401,\n PaymentRequired: 402,\n Forbidden: 403,\n NotFound: 404,\n MethodNotAllowed: 405,\n NotAcceptable: 406,\n RequestTimeout: 408,\n Conflict: 409,\n Gone: 410,\n LengthRequired: 411,\n PreconditionFailed: 412,\n ContentTooLarge: 413,\n URITooLong: 414,\n UnsupportedMediaType: 415,\n RangeNotSatisfiable: 416,\n ExpectationFailed: 417,\n UnprocessableEntity: 422,\n Locked: 423,\n FailedDependency: 424,\n TooEarly: 425,\n UpgradeRequired: 426,\n PreconditionRequired: 428,\n TooManyRequests: 429,\n RequestHeaderFieldsTooLarge: 431,\n UnavailableForLegalReasons: 451,\n },\n\n /** 5xx - Server error. */\n RS_5: {\n InternalServerError: 500,\n NotImplemented: 501,\n BadGateway: 502,\n ServiceUnavailable: 503,\n GatewayTimeout: 504,\n HTTPVersionNotSupported: 505,\n InsufficientStorage: 507,\n LoopDetected: 508,\n NetworkAuthenticationRequired: 511,\n },\n } as const;\n}\n\n/** An HTTP method from `HTTP.Methods`, in lowercase or uppercase. */\nexport type THttpMethod = ValueOf<typeof HTTP.Methods> | Uppercase<ValueOf<typeof HTTP.Methods>>;\n/** An HTTP protocol from `HTTP.Protocols`, in lowercase or uppercase. */\nexport type THttpProtocol =\n | ValueOf<typeof HTTP.Protocols>\n | Uppercase<ValueOf<typeof HTTP.Protocols>>;\n/** A numeric HTTP status code from any class in `HTTP.ResultCodes`. */\nexport type THttpResultCode = ValueOf<typeof HTTP.ResultCodes>;\n"]}
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../../src/common/constants/http.ts"],"names":[],"mappings":"AAEA,yJAAyJ;AACzJ,MAAM,OAAO,IAAI;IACf,0EAA0E;aAC1D,YAAO,GAAG;QACxB,UAAU;QACV,mBAAmB,EAAE,qBAAqB;QAC1C,gBAAgB,EAAE,kBAAkB;QACpC,cAAc,EAAE,gBAAgB;QAChC,YAAY,EAAE,cAAc;QAC5B,aAAa,EAAE,eAAe;QAC9B,uBAAuB,EAAE,yBAAyB;QAClD,aAAa,EAAE,eAAe;QAC9B,KAAK,EAAE,OAAO;QAEd,+CAA+C;QAC/C,MAAM,EAAE,QAAQ;QAChB,eAAe,EAAE,iBAAiB;QAClC,eAAe,EAAE,iBAAiB;QAClC,aAAa,EAAE,eAAe;QAC9B,MAAM,EAAE,QAAQ;QAChB,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,UAAU;QACpB,iBAAiB,EAAE,mBAAmB;QACtC,aAAa,EAAE,eAAe;QAC9B,MAAM,EAAE,QAAQ;QAChB,OAAO,EAAE,SAAS;QAClB,UAAU,EAAE,YAAY;QAExB,kDA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BAAgB,EAAE,GAAG;YACrB,QAAQ,EAAE,GAAG;YACb,eAAe,EAAE,GAAG;YACpB,oBAAoB,EAAE,GAAG;YACzB,eAAe,EAAE,GAAG;YACpB,2BAA2B,EAAE,GAAG;YAChC,0BAA0B,EAAE,GAAG;SAChC;QAED,0BAA0B;QAC1B,IAAI,EAAE;YACJ,mBAAmB,EAAE,GAAG;YACxB,cAAc,EAAE,GAAG;YACnB,UAAU,EAAE,GAAG;YACf,kBAAkB,EAAE,GAAG;YACvB,cAAc,EAAE,GAAG;YACnB,uBAAuB,EAAE,GAAG;YAC5B,mBAAmB,EAAE,GAAG;YACxB,YAAY,EAAE,GAAG;YACjB,6BAA6B,EAAE,GAAG;SACnC;KACO,CAAC;;AAYb,4EAA4E;AAC5E,MAAM,OAAO,uBAAuB;aAClB,eAAU,GAAG,YAAY,CAAC;aAC1B,WAAM,GAAG,QAAQ,CAAC;aAElB,eAAU,GAAG,IAAI,GAAG,CAAS,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAE7E,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC","sourcesContent":["import { type TConstValue, type ValueOf } from '../types';\n\n/** HTTP constants: header names, CORS headers, header values, methods, protocols and status codes. Header names, methods and protocols are lowercase. */\nexport class HTTP {\n /** Standard and common HTTP headers (lowercase per HTTP/2 convention). */\n static readonly Headers = {\n // Content\n CONTENT_DISPOSITION: 'content-disposition',\n CONTENT_ENCODING: 'content-encoding',\n CONTENT_LENGTH: 'content-length',\n CONTENT_TYPE: 'content-type',\n CONTENT_RANGE: 'content-range',\n CONTENT_SECURITY_POLICY: 'content-security-policy',\n ACCEPT_RANGES: 'accept-ranges',\n RANGE: 'range',\n\n // Request - content negotiation & conditionals\n ACCEPT: 'accept',\n ACCEPT_ENCODING: 'accept-encoding',\n ACCEPT_LANGUAGE: 'accept-language',\n AUTHORIZATION: 'authorization',\n COOKIE: 'cookie',\n HOST: 'host',\n IF_MATCH: 'if-match',\n IF_MODIFIED_SINCE: 'if-modified-since',\n IF_NONE_MATCH: 'if-none-match',\n ORIGIN: 'origin',\n REFERER: 'referer',\n USER_AGENT: 'user-agent',\n\n // Response - caching, auth challenges & redirects\n ALLOW: 'allow',\n CACHE_CONTROL: 'cache-control',\n ETAG: 'etag',\n LAST_MODIFIED: 'last-modified',\n LOCATION: 'location',\n RETRY_AFTER: 'retry-after',\n SET_COOKIE: 'set-cookie',\n VARY: 'vary',\n WWW_AUTHENTICATE: 'www-authenticate',\n\n // CORS (RFC 6454 / Fetch spec)\n ACCESS_CONTROL_ALLOW_CREDENTIALS: 'access-control-allow-credentials',\n ACCESS_CONTROL_ALLOW_HEADERS: 'access-control-allow-headers',\n ACCESS_CONTROL_ALLOW_METHODS: 'access-control-allow-methods',\n ACCESS_CONTROL_ALLOW_ORIGIN: 'access-control-allow-origin',\n ACCESS_CONTROL_EXPOSE_HEADERS: 'access-control-expose-headers',\n ACCESS_CONTROL_MAX_AGE: 'access-control-max-age',\n ACCESS_CONTROL_REQUEST_HEADERS: 'access-control-request-headers',\n ACCESS_CONTROL_REQUEST_METHOD: 'access-control-request-method',\n\n // Transport\n CONNECTION: 'connection',\n TRANSFER_ENCODING: 'transfer-encoding',\n UPGRADE: 'upgrade',\n\n // Security\n STRICT_TRANSPORT_SECURITY: 'strict-transport-security',\n X_CONTENT_TYPE_OPTIONS: 'x-content-type-options',\n X_FRAME_OPTIONS: 'x-frame-options',\n\n // Proxy / forwarding (de facto standard)\n FORWARDED: 'forwarded',\n X_FORWARDED_FOR: 'x-forwarded-for',\n X_FORWARDED_HOST: 'x-forwarded-host',\n X_FORWARDED_PROTO: 'x-forwarded-proto',\n X_REAL_IP: 'x-real-ip',\n\n // Rate limiting (de facto standard)\n X_RATELIMIT_LIMIT: 'x-ratelimit-limit',\n X_RATELIMIT_REMAINING: 'x-ratelimit-remaining',\n X_RATELIMIT_RESET: 'x-ratelimit-reset',\n\n // IGNIS custom\n REQUEST_TRACING_ID: 'x-request-id',\n REQUEST_DEVICE_INFO: 'x-device-info',\n REQUEST_CHANNEL: 'x-request-channel',\n REQUEST_COUNT_DATA: 'x-request-count',\n REQUEST_EXTRA: 'x-request-extra',\n RESPONSE_COUNT_DATA: 'x-response-count',\n RESPONSE_FORMAT: 'x-response-format',\n RESPONSE_EXTRA: 'x-response-extra',\n\n // Client context\n AUTH_PROVIDER: 'x-auth-provider',\n LOCALE: 'x-locale',\n TIMEZONE: 'timezone',\n TIMEZONE_OFFSET: 'timezone-offset',\n } as const;\n\n /**\n * The headers IGNIS adds to a request and to a response, for a CORS configuration that lists them\n * by hand: spread `ALLOW` into the allowed request headers and `EXPOSE` into the exposed ones, so\n * a header IGNIS adds later needs no change there.\n */\n static readonly CorsHeaders = {\n ALLOW: [\n 'x-request-id',\n 'x-request-count',\n 'x-request-extra',\n 'x-request-channel',\n 'x-device-info',\n ],\n EXPOSE: [\n 'content-range',\n 'x-request-id',\n 'x-response-count',\n 'x-response-format',\n 'x-response-extra',\n ],\n } as const;\n\n /** Common MIME / Content-Type values. */\n static readonly HeaderValues = {\n // Application\n APPLICATION_FORM_URLENCODED: 'application/x-www-form-urlencoded',\n APPLICATION_GRAPHQL_JSON: 'application/graphql+json',\n APPLICATION_GZIP: 'application/gzip',\n APPLICATION_JAVASCRIPT: 'application/javascript',\n APPLICATION_JSON: 'application/json',\n /** A JSON body with its charset named, the value a client sends by default. */\n APPLICATION_JSON_UTF8: 'application/json; charset=utf-8',\n APPLICATION_MSGPACK: 'application/msgpack',\n APPLICATION_NDJSON: 'application/x-ndjson',\n APPLICATION_OCTET_STREAM: 'application/octet-stream',\n APPLICATION_PDF: 'application/pdf',\n APPLICATION_PROTOBUF: 'application/x-protobuf',\n APPLICATION_XML: 'application/xml',\n APPLICATION_ZIP: 'application/zip',\n\n // Multipart\n MULTIPART_FORM_DATA: 'multipart/form-data',\n\n // Text\n TEXT_CSS: 'text/css',\n TEXT_CSV: 'text/csv',\n TEXT_EVENT_STREAM: 'text/event-stream',\n TEXT_HTML: 'text/html',\n TEXT_PLAIN: 'text/plain',\n TEXT_XML: 'text/xml',\n\n // Image\n IMAGE_GIF: 'image/gif',\n IMAGE_JPEG: 'image/jpeg',\n IMAGE_PNG: 'image/png',\n IMAGE_SVG: 'image/svg+xml',\n IMAGE_WEBP: 'image/webp',\n\n // Range units\n RANGE_UNIT_BYTES: 'bytes',\n } as const;\n\n /** Standard HTTP methods (lowercase). */\n static readonly Methods = {\n GET: 'get',\n POST: 'post',\n PUT: 'put',\n PATCH: 'patch',\n DELETE: 'delete',\n HEAD: 'head',\n OPTIONS: 'options',\n QUERY: 'query',\n } as const;\n\n /** Standard HTTP protocols (lowercase). */\n static readonly Protocols = {\n HTTP: 'http',\n HTTPS: 'https',\n } as const;\n\n /** HTTP status codes grouped by class (1xx - 5xx). */\n static readonly ResultCodes = {\n /** 1xx - Informational. */\n RS_1: {\n Continue: 100,\n SwitchingProtocols: 101,\n EarlyHints: 103,\n },\n\n /** 2xx - Success. */\n RS_2: {\n Ok: 200,\n Created: 201,\n Accepted: 202,\n NonAuthoritativeInformation: 203,\n NoContent: 204,\n ResetContent: 205,\n PartialContent: 206,\n MultiStatus: 207,\n },\n\n /** 3xx - Redirection. */\n RS_3: {\n MovedPermanently: 301,\n Found: 302,\n NotModified: 304,\n TemporaryRedirect: 307,\n PermanentRedirect: 308,\n },\n\n /** 4xx - Client error. */\n RS_4: {\n BadRequest: 400,\n Unauthorized: 401,\n PaymentRequired: 402,\n Forbidden: 403,\n NotFound: 404,\n MethodNotAllowed: 405,\n NotAcceptable: 406,\n RequestTimeout: 408,\n Conflict: 409,\n Gone: 410,\n LengthRequired: 411,\n PreconditionFailed: 412,\n ContentTooLarge: 413,\n URITooLong: 414,\n UnsupportedMediaType: 415,\n RangeNotSatisfiable: 416,\n ExpectationFailed: 417,\n UnprocessableEntity: 422,\n Locked: 423,\n FailedDependency: 424,\n TooEarly: 425,\n UpgradeRequired: 426,\n PreconditionRequired: 428,\n TooManyRequests: 429,\n RequestHeaderFieldsTooLarge: 431,\n UnavailableForLegalReasons: 451,\n },\n\n /** 5xx - Server error. */\n RS_5: {\n InternalServerError: 500,\n NotImplemented: 501,\n BadGateway: 502,\n ServiceUnavailable: 503,\n GatewayTimeout: 504,\n HTTPVersionNotSupported: 505,\n InsufficientStorage: 507,\n LoopDetected: 508,\n NetworkAuthenticationRequired: 511,\n },\n } as const;\n}\n\n/** An HTTP method from `HTTP.Methods`, in lowercase or uppercase. */\nexport type THttpMethod = ValueOf<typeof HTTP.Methods> | Uppercase<ValueOf<typeof HTTP.Methods>>;\n/** An HTTP protocol from `HTTP.Protocols`, in lowercase or uppercase. */\nexport type THttpProtocol =\n | ValueOf<typeof HTTP.Protocols>\n | Uppercase<ValueOf<typeof HTTP.Protocols>>;\n/** A numeric HTTP status code from any class in `HTTP.ResultCodes`. */\nexport type THttpResultCode = ValueOf<typeof HTTP.ResultCodes>;\n\n/** How a client treats a download: ATTACHMENT saves it, INLINE shows it. */\nexport class ContentDispositionTypes {\n static readonly ATTACHMENT = 'attachment';\n static readonly INLINE = 'inline';\n\n static readonly SCHEME_SET = new Set<string>([this.ATTACHMENT, this.INLINE]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** Valid Content-Disposition type values. */\nexport type TContentDispositionType = TConstValue<typeof ContentDispositionTypes>;\n"]}
|
|
@@ -19,6 +19,8 @@ const SECRET_KEY_PATTERN = new RegExp([
|
|
|
19
19
|
// HTTP HEADER spellings: header names are kebab-case and often `x-`-prefixed, none of which the camelCase list above matches; `vault` is included so `X-Vault-Token` (node-vault's auth header) is caught.
|
|
20
20
|
'|^(x-)?(api|auth|access|secret|session|csrf|xsrf|vault)-(key|token|secret|id)$',
|
|
21
21
|
'|^(cookie|set-cookie|proxy-authorization|www-authenticate)$',
|
|
22
|
+
// Signed assertions travel in a header such as `x-service-assertion`; the signed value is a bearer credential for its lifetime.
|
|
23
|
+
'|(^|-)assertion$',
|
|
22
24
|
// Named secrets that no suffix rule reaches. An explicit list, never a blanket `*Key` or `code`: those would mask
|
|
23
25
|
// `primaryKey`, `cacheKey` and every status `code`. Cloud and signing keys, session and one-time values, signatures,
|
|
24
26
|
// card and national-id numbers, and the kebab spellings of tokens and secrets (the suffix rules above need a letter or
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redact.js","sourceRoot":"","sources":["../../../src/common/redact.ts"],"names":[],"mappings":"AAAA,gHAAgH;AAChH,MAAM,kBAAkB,GAAG,IAAI,MAAM,CACnC;IACE,qDAAqD;IACrD,6EAA6E;IAC7E,qFAAqF;IACrF,oEAAoE;IAEpE,iKAAiK;IACjK,qCAAqC;IAErC,8MAA8M;IAC9M,yBAAyB;IAEzB,8RAA8R;IAC9R,2BAA2B;IAE3B,4JAA4J;IAC5J,qDAAqD;IAErD,uMAAuM;IACvM,uCAAuC;IAEvC,yIAAyI;IACzI,+BAA+B;IAE/B,2MAA2M;IAC3M,gFAAgF;IAChF,6DAA6D;IAE7D,kHAAkH;IAClH,qHAAqH;IACrH,uHAAuH;IACvH,kCAAkC;IAClC,sNAAsN;IACtN,sIAAsI;IACtI,qHAAqH;IACrH,8DAA8D;IAC9D,4DAA4D;IAC5D,gEAAgE;IAChE,yFAAyF;CAC1F,CAAC,IAAI,CAAC,EAAE,CAAC,EACV,GAAG,CACJ,CAAC;AAEF,uEAAuE;AACvE,MAAM,CAAC,MAAM,QAAQ,GAAG,YAAY,CAAC;AAErC;;;;GAIG;AACH,MAAM,oBAAoB,GAAG,wCAAwC,CAAC;AAEtE,4GAA4G;AAC5G,MAAM,qBAAqB,GAAG,wBAAwB,CAAC;AAEvD,6GAA6G;AAC7G,MAAM,mBAAmB,GAAG,6CAA6C,CAAC;AAE1E,qIAAqI;AACrI,MAAM,wBAAwB,GAC5B,mOAAmO,CAAC;AAEtO,kIAAkI;AAClI,M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KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;IAC/E,CAAC;IAED,omBAAomB;IACpmB,MAAM,CAAC,UAAU,CAAC,IAAyD;QACzE,OAAO,YAAY,CAAC,IAAI,CAAC,KAAK,EAAE;YAC9B,IAAI,EAAE,IAAI,OAAO,EAAU;YAC3B,QAAQ,EAAE,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC;YACxC,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,QAAQ;YAC7B,iGAAiG;YACjG,qDAAqD;YACrD,eAAe,EAAE,sBAAsB,EAAE;SAC1C,CAAC,CAAC;IACL,CAAC;IAED,qUAAqU;IACrU,MAAM,CAAC,oBAAoB,CAAC,IAAsC;QAChE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QAE5B,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/B,OAAO,GAAG,CAAC;QACb,CAAC;QAED,IAAI,MAAW,CAAC;QAEhB,IAAI,CAAC;YACH,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QACxB,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,GAAG,CAAC;QACb,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;YACrB,OAAO,GAAG,CAAC;QACb,CAAC;QAED,MAAM,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAE3B,OAAO,kBAAkB,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC/C,CAAC;CACF","sourcesContent":["/** Keys whose VALUES must never reach a log line - matched case-insensitively on the key name, at any depth. */\nconst SECRET_KEY_PATTERN = new RegExp(\n [\n // Options-object spellings (camelCase / snake_case).\n '^(pass|password|passphrase|secret|token|apiKey|api_key|accessKey|access_key',\n '|secretKey|secret_key|privateKey|private_key|key|cert|ca|pfx|credential|credentials',\n '|authorization|auth|jwtSecret|applicationSecret|connectionString)$',\n\n // Vault wire spellings (snake_case): node-vault's AppRole login/response bodies carry these exact keys, and none are matched by the anchored options list above.\n '|^(client_token|secret_id|role_id)$',\n\n // Any `*_token` (snake_case) or `*Token` (camelCase) key; a preceding character is required so the bare word `token` (already covered above) is not the whole match, and so ordinary words are not swallowed.\n '|_token$|[a-z0-9]token$',\n\n // The `*Secret` counterpart the `*Token` rule always lacked. `clientSecret` / `client_secret` is the RFC 6749 parameter name and a live field on the search connector's model options, and `webhookSecret` is the standard spelling everywhere; none of them matched the anchored list above.\n '|_secret$|[a-z0-9]secret$',\n\n // Connection descriptors: `connectionString` was anchored above but its snake_case twin was not, and `dsn` is the third common spelling for the same thing.\n '|^(connection_string|dsn|database_url|databaseUrl)$',\n\n // Any `*_credential` / `*Credential` key, singular or plural - `dbCredential`, `api_credentials`. The bare words are anchored above; this catches the prefixed forms, the way the `*Secret` rule does.\n '|_credentials?$|[a-z0-9]credentials?$',\n\n // Any `*_password` / `*Password` key - `dbPassword`, `admin_password`. The bare word is anchored above; this catches the prefixed forms.\n '|_password$|[a-z0-9]password$',\n\n // HTTP HEADER spellings: header names are kebab-case and often `x-`-prefixed, none of which the camelCase list above matches; `vault` is included so `X-Vault-Token` (node-vault's auth header) is caught.\n '|^(x-)?(api|auth|access|secret|session|csrf|xsrf|vault)-(key|token|secret|id)$',\n '|^(cookie|set-cookie|proxy-authorization|www-authenticate)$',\n\n // Named secrets that no suffix rule reaches. An explicit list, never a blanket `*Key` or `code`: those would mask\n // `primaryKey`, `cacheKey` and every status `code`. Cloud and signing keys, session and one-time values, signatures,\n // card and national-id numbers, and the kebab spellings of tokens and secrets (the suffix rules above need a letter or\n // an underscore before the word).\n '|^(secret_?access_?key|aws_?secret_?access_?key|signing_?key|encryption_?key|master_?key|hmac_?key|account_?key|storage_?key|license_?key|reset_?key|reset_?code|verification_?code|authorization_?code|auth_?code)$',\n '|^(jwt|session_?id|sid|signature|sig|passwd|pwd|passcode|pass_phrase|secret_?answer|otp|totp|cvv|cvc|card_?number|ssn|national_?id)$',\n '|^(redis_?url|mongo_?uri|mongo_?url|webhook_?url|private_?key_?pem|password_?hash|mfa_?code|otp_?code|x_?api_?key)$',\n '|^(api_?keys|refresh_?tokens|access_?tokens|secrets|tokens)$',\n '|^(x-amz-signature|x-amz-security-token|x-amz-credential)$',\n '|^(id|refresh|access|bearer|auth|api|session|csrf|xsrf)-token$',\n '|^(client|api|app|webhook)-secret$|^(private|signing|secret|api|access|encryption)-key$',\n ].join(''),\n 'i',\n);\n\n/** The placeholder that replaces a secret value in redacted output. */\nexport const REDACTED = '[REDACTED]';\n\n/**\n * `://user:password@host`: the password of a url's userinfo, wherever the url sits inside a string. Anchored on `://`\n * (not on the scheme, whose letters a pattern would rescan from every start) and every run is bounded, so the cost is\n * linear in the string. The password runs to the LAST `@` before a space or slash, so one that holds an `@` is whole.\n */\nconst URL_USERINFO_PATTERN = /(:\\/\\/[^\\s/:@]{0,256}):[^\\s/]{1,256}@/g;\n\n/** `://token@host`: a userinfo with no password is the credential itself (`https://<token>@github.com`). */\nconst URL_USER_ONLY_PATTERN = /:\\/\\/[^\\s/:@]{1,256}@/g;\n\n/** `Bearer abc...` and `Basic abc...` credentials, as an `Authorization` header or a message quotes them. */\nconst AUTH_SCHEME_PATTERN = /\\b(Bearer|Basic)\\s+[A-Za-z0-9._~+/=-]{8,}/gi;\n\n/** A credential-like `name=value` after a query, fragment, list or space: `?access_token=...`, `#id_token=...`, `, password=...`. */\nconst QUERY_CREDENTIAL_PATTERN =\n /([?&;,#\\s])(access_token|refresh_token|id_token|token|api_key|apikey|x-api-key|key|auth|password|passwd|pwd|secret|client_secret|signature|sig|x-amz-signature|x-amz-security-token|jwt|session_id|sessionid|code)=([^&\\s#,)]*)/gi;\n\n/** A string with the credentials it carries masked: a connection url's password, a bearer token, a credential query parameter. */\nconst scrubString = (value: string): string => {\n if (!value.includes('@') && !value.includes('=') && !/bearer|basic/i.test(value)) {\n return value;\n }\n\n return value\n .replace(URL_USERINFO_PATTERN, `$1:${'[REDACTED]'}@`)\n .replace(URL_USER_ONLY_PATTERN, `://${'[REDACTED]'}@`)\n .replace(AUTH_SCHEME_PATTERN, `$1 ${'[REDACTED]'}`)\n .replace(QUERY_CREDENTIAL_PATTERN, `$1$2=${'[REDACTED]'}`);\n};\n\n/** Kill-switch for local debugging: only the literal `false` disables redaction (fail-closed); read per call so it can be flipped at runtime. Never disable in production. `force` is the caller opting out of the switch: it always masks. */\nconst isRedactionEnabled = (force?: boolean): boolean =>\n force === true || globalThis.process?.env?.APP_ENV_LOGGER_DO_REDACT !== 'false';\n\n/** Longest string a log line carries whole. `APP_ENV_LOGGER_MAX_STRING_LENGTH=0` turns capping off. */\nconst DEFAULT_MAX_STRING_LENGTH = 2048;\n\nconst resolveMaxStringLength = (): number => {\n const configured = Number(globalThis.process?.env?.APP_ENV_LOGGER_MAX_STRING_LENGTH);\n\n return Number.isFinite(configured) && configured >= 0 ? configured : DEFAULT_MAX_STRING_LENGTH;\n};\n\n/**\n * Keys whose value is long BY NATURE and useless truncated. A stack trace is the whole reason you\n * are reading the line.\n */\nconst UNCAPPED_KEYS = new Set(['stack', 'stacktrace', 'stack_trace']);\n\n/**\n * Caps a long string, keeping the ORIGINAL LENGTH in the marker - that number is what tells you the\n * payload was a 300 KB image rather than a truncated sentence.\n *\n * A base64 body is the case this exists for: one `data:image/png;base64,...` field turns a request\n * log into hundreds of kilobytes, and nothing about it is readable.\n */\nconst capString = (opts: { value: string; key?: string; limit: number }): string => {\n const { value, key, limit } = opts;\n\n if (limit === 0 || value.length <= limit || (key && UNCAPPED_KEYS.has(key.toLowerCase()))) {\n return value;\n }\n\n return `${value.slice(0, limit)}... [truncated, ${value.length} chars total]`;\n};\n\ntype TSanitizeContext = {\n seen: WeakSet<object>;\n doRedact: boolean;\n /** Levels still allowed BELOW the current one; `Infinity` walks the whole graph. */\n depth: number;\n /** Longest string kept whole; 0 keeps every string. */\n maxStringLength: number;\n /** The key this value was found under, so a stack trace can be exempted from capping. */\n key?: string;\n};\n\nconst deepSanitize = (value: unknown, context: TSanitizeContext): unknown => {\n const { seen, doRedact, depth } = context;\n\n if (typeof value === 'string') {\n const text = doRedact ? scrubString(value) : value;\n\n return capString({ value: text, key: context.key, limit: context.maxStringLength });\n }\n\n // A function is not data, and an own `toJSON` on an object would run after this walk, inside `JSON.stringify`, and\n // hand back keys the walk never saw. Naming it keeps the redacted copy free of code.\n if (typeof value === 'function') {\n return '[Function]';\n }\n\n if (value === null || typeof value !== 'object') {\n return value;\n }\n\n // A Date holds its value in an internal slot, so the generic branch below - which reads Object.keys() - would flatten it to `{}`. Checked BEFORE `seen`: a Date cannot carry a cycle, and entering the set would make a second reference to the same instance read as `[Circular]`.\n if (value instanceof Date) {\n return value;\n }\n\n if (seen.has(value)) {\n return '[Circular]';\n }\n\n if (ArrayBuffer.isView(value) || value instanceof ArrayBuffer) {\n return `[Binary ${(value as ArrayBufferView).byteLength ?? 0} bytes]`;\n }\n\n if (depth <= 0) {\n return Array.isArray(value) ? '[Array]' : '[Object]';\n }\n\n seen.add(value);\n const nested: TSanitizeContext = {\n seen,\n doRedact,\n depth: depth - 1,\n maxStringLength: context.maxStringLength,\n };\n\n // Error keeps name/message/stack NON-enumerable, so Object.keys() skips them and naive redaction would drop the message - reproject into a plain object carrying those fields plus its redacted enumerable own-props.\n if (value instanceof Error) {\n const source = value;\n const result: Record<string, unknown> = {\n name: value.name,\n message: doRedact ? scrubString(value.message) : value.message,\n stack: doRedact && value.stack ? scrubString(value.stack) : value.stack,\n };\n\n for (const [key, entry] of Object.entries(source)) {\n result[key] =\n doRedact && SECRET_KEY_PATTERN.test(key)\n ? REDACTED\n : deepSanitize(entry, { ...nested, key });\n }\n\n return result;\n }\n\n if (Array.isArray(value)) {\n return value.map((entry) => deepSanitize(entry, nested));\n }\n\n const source = value;\n const result: Record<string, unknown> = {};\n\n for (const [key, entry] of Object.entries(source)) {\n if (doRedact && SECRET_KEY_PATTERN.test(key)) {\n result[key] = REDACTED;\n continue;\n }\n\n result[key] = deepSanitize(entry, { ...nested, key });\n }\n\n return result;\n};\n\n/** Makes a log argument safe to print: masks secret-looking keys, breaks cycles, caps long strings and strips URL credentials. `APP_ENV_LOGGER_DO_REDACT=false` turns off the key masking only. */\nexport class RedactUtility {\n /**\n * Redacts every secret-looking KEY (not value shape - buffers/typed arrays are summarized, not\n * serialized). `APP_ENV_LOGGER_DO_REDACT=false` makes this the identity function.\n *\n * `depth` bounds the walk, exactly as {@link RedactUtility.toJsonSafe} already does. It defaults to\n * `Infinity` for callers that really do want the whole graph, but the logger passes its own bound:\n * rendering only inspects a handful of levels, so walking to `Infinity` did work whose result was\n * thrown away - 12x on a deep graph, and a `RangeError` on a very deep chain.\n *\n * `force: true` masks secret-looking KEYS even when `APP_ENV_LOGGER_DO_REDACT=false`. The result is still the\n * log-shaped copy: long strings are capped, a second reference to one object reads `[Circular]`, binary is\n * summarized, and a key is masked by name only (a card number under `number` is not). It is not a faithful\n * redacted document. The logger never sets it.\n */\n static redactSecrets(opts: {\n value: unknown;\n seen?: WeakSet<object>;\n depth?: number;\n force?: boolean;\n }): unknown {\n const { value, seen, depth = Infinity, force } = opts;\n\n if (!isRedactionEnabled(force)) {\n return value;\n }\n\n return deepSanitize(value, {\n seen: seen ?? new WeakSet<object>(),\n doRedact: true,\n depth,\n maxStringLength: resolveMaxStringLength(),\n });\n }\n\n /** Masks the credentials a plain string carries (a url's password, a bearer token, credential query parameters). For a log line's string argument; objects go through {@link RedactUtility.redactSecrets}. `force: true` scrubs even when `APP_ENV_LOGGER_DO_REDACT=false`. */\n static scrubText(opts: { value: string; force?: boolean }): string {\n return isRedactionEnabled(opts.force) ? scrubString(opts.value) : opts.value;\n }\n\n /** Projects a value into something `JSON.stringify` can render: it answers `[Circular]` for the WHOLE payload when one cycle sits anywhere inside it, so cycles must be broken per-branch first. `depth` bounds the walk the way `util.inspect` does - a log argument may hold a live connector or request context, whose graph is effectively unbounded. The projection itself is unconditional: `APP_ENV_LOGGER_DO_REDACT=false` turns off the key masking, never the structural pass. `force: true` keeps the key masking on whatever the switch says; the projection stays lossy, as in {@link RedactUtility.redactSecrets}. */\n static toJsonSafe(opts: { value: unknown; depth?: number; force?: boolean }): unknown {\n return deepSanitize(opts.value, {\n seen: new WeakSet<object>(),\n doRedact: isRedactionEnabled(opts.force),\n depth: opts.depth ?? Infinity,\n // Capping is STRUCTURAL, like the projection itself: turning redaction off is about key masking,\n // never about letting a 300 KB base64 field through.\n maxStringLength: resolveMaxStringLength(),\n });\n }\n\n /** Strips credentials from a connection URL's authority section (`user:hunter2@host` -> `user:[REDACTED]@host`) - {@link RedactUtility.redactSecrets} matches on KEY names and can't see them there. A value that fails to parse as a URL is returned unchanged. `force: true` strips even when `APP_ENV_LOGGER_DO_REDACT=false`. */\n static redactUrlCredentials(opts: { url: string; force?: boolean }): string {\n const { url, force } = opts;\n\n if (!isRedactionEnabled(force)) {\n return url;\n }\n\n let parsed: URL;\n\n try {\n parsed = new URL(url);\n } catch {\n return url;\n }\n\n if (!parsed.password) {\n return url;\n }\n\n parsed.password = REDACTED;\n\n return decodeURIComponent(parsed.toString());\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"redact.js","sourceRoot":"","sources":["../../../src/common/redact.ts"],"names":[],"mappings":"AAAA,gHAAgH;AAChH,MAAM,kBAAkB,GAAG,IAAI,MAAM,CACnC;IACE,qDAAqD;IACrD,6EAA6E;IAC7E,qFAAqF;IACrF,oEAAoE;IAEpE,iKAAiK;IACjK,qCAAqC;IAErC,8MAA8M;IAC9M,yBAAyB;IAEzB,8RAA8R;IAC9R,2BAA2B;IAE3B,4JAA4J;IAC5J,qDAAqD;IAErD,uMAAuM;IACvM,uCAAuC;IAEvC,yIAAyI;IACzI,+BAA+B;IAE/B,2MAA2M;IAC3M,gFAAgF;IAChF,6DAA6D;IAE7D,gIAAgI;IAChI,kBAAkB;IAElB,kHAAkH;IAClH,qHAAq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AG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QACxB,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,GAAG,CAAC;QACb,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;YACrB,OAAO,GAAG,CAAC;QACb,CAAC;QAED,MAAM,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAE3B,OAAO,kBAAkB,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC/C,CAAC;CACF","sourcesContent":["/** Keys whose VALUES must never reach a log line - matched case-insensitively on the key name, at any depth. */\nconst SECRET_KEY_PATTERN = new RegExp(\n [\n // Options-object spellings (camelCase / snake_case).\n '^(pass|password|passphrase|secret|token|apiKey|api_key|accessKey|access_key',\n '|secretKey|secret_key|privateKey|private_key|key|cert|ca|pfx|credential|credentials',\n '|authorization|auth|jwtSecret|applicationSecret|connectionString)$',\n\n // Vault wire spellings (snake_case): node-vault's AppRole login/response bodies carry these exact keys, and none are matched by the anchored options list above.\n '|^(client_token|secret_id|role_id)$',\n\n // Any `*_token` (snake_case) or `*Token` (camelCase) key; a preceding character is required so the bare word `token` (already covered above) is not the whole match, and so ordinary words are not swallowed.\n '|_token$|[a-z0-9]token$',\n\n // The `*Secret` counterpart the `*Token` rule always lacked. `clientSecret` / `client_secret` is the RFC 6749 parameter name and a live field on the search connector's model options, and `webhookSecret` is the standard spelling everywhere; none of them matched the anchored list above.\n '|_secret$|[a-z0-9]secret$',\n\n // Connection descriptors: `connectionString` was anchored above but its snake_case twin was not, and `dsn` is the third common spelling for the same thing.\n '|^(connection_string|dsn|database_url|databaseUrl)$',\n\n // Any `*_credential` / `*Credential` key, singular or plural - `dbCredential`, `api_credentials`. The bare words are anchored above; this catches the prefixed forms, the way the `*Secret` rule does.\n '|_credentials?$|[a-z0-9]credentials?$',\n\n // Any `*_password` / `*Password` key - `dbPassword`, `admin_password`. The bare word is anchored above; this catches the prefixed forms.\n '|_password$|[a-z0-9]password$',\n\n // HTTP HEADER spellings: header names are kebab-case and often `x-`-prefixed, none of which the camelCase list above matches; `vault` is included so `X-Vault-Token` (node-vault's auth header) is caught.\n '|^(x-)?(api|auth|access|secret|session|csrf|xsrf|vault)-(key|token|secret|id)$',\n '|^(cookie|set-cookie|proxy-authorization|www-authenticate)$',\n\n // Signed assertions travel in a header such as `x-service-assertion`; the signed value is a bearer credential for its lifetime.\n '|(^|-)assertion$',\n\n // Named secrets that no suffix rule reaches. An explicit list, never a blanket `*Key` or `code`: those would mask\n // `primaryKey`, `cacheKey` and every status `code`. Cloud and signing keys, session and one-time values, signatures,\n // card and national-id numbers, and the kebab spellings of tokens and secrets (the suffix rules above need a letter or\n // an underscore before the word).\n '|^(secret_?access_?key|aws_?secret_?access_?key|signing_?key|encryption_?key|master_?key|hmac_?key|account_?key|storage_?key|license_?key|reset_?key|reset_?code|verification_?code|authorization_?code|auth_?code)$',\n '|^(jwt|session_?id|sid|signature|sig|passwd|pwd|passcode|pass_phrase|secret_?answer|otp|totp|cvv|cvc|card_?number|ssn|national_?id)$',\n '|^(redis_?url|mongo_?uri|mongo_?url|webhook_?url|private_?key_?pem|password_?hash|mfa_?code|otp_?code|x_?api_?key)$',\n '|^(api_?keys|refresh_?tokens|access_?tokens|secrets|tokens)$',\n '|^(x-amz-signature|x-amz-security-token|x-amz-credential)$',\n '|^(id|refresh|access|bearer|auth|api|session|csrf|xsrf)-token$',\n '|^(client|api|app|webhook)-secret$|^(private|signing|secret|api|access|encryption)-key$',\n ].join(''),\n 'i',\n);\n\n/** The placeholder that replaces a secret value in redacted output. */\nexport const REDACTED = '[REDACTED]';\n\n/**\n * `://user:password@host`: the password of a url's userinfo, wherever the url sits inside a string. Anchored on `://`\n * (not on the scheme, whose letters a pattern would rescan from every start) and every run is bounded, so the cost is\n * linear in the string. The password runs to the LAST `@` before a space or slash, so one that holds an `@` is whole.\n */\nconst URL_USERINFO_PATTERN = /(:\\/\\/[^\\s/:@]{0,256}):[^\\s/]{1,256}@/g;\n\n/** `://token@host`: a userinfo with no password is the credential itself (`https://<token>@github.com`). */\nconst URL_USER_ONLY_PATTERN = /:\\/\\/[^\\s/:@]{1,256}@/g;\n\n/** `Bearer abc...` and `Basic abc...` credentials, as an `Authorization` header or a message quotes them. */\nconst AUTH_SCHEME_PATTERN = /\\b(Bearer|Basic)\\s+[A-Za-z0-9._~+/=-]{8,}/gi;\n\n/** A credential-like `name=value` after a query, fragment, list or space: `?access_token=...`, `#id_token=...`, `, password=...`. */\nconst QUERY_CREDENTIAL_PATTERN =\n /([?&;,#\\s])(access_token|refresh_token|id_token|token|api_key|apikey|x-api-key|key|auth|password|passwd|pwd|secret|client_secret|signature|sig|x-amz-signature|x-amz-security-token|jwt|session_id|sessionid|code)=([^&\\s#,)]*)/gi;\n\n/** A string with the credentials it carries masked: a connection url's password, a bearer token, a credential query parameter. */\nconst scrubString = (value: string): string => {\n if (!value.includes('@') && !value.includes('=') && !/bearer|basic/i.test(value)) {\n return value;\n }\n\n return value\n .replace(URL_USERINFO_PATTERN, `$1:${'[REDACTED]'}@`)\n .replace(URL_USER_ONLY_PATTERN, `://${'[REDACTED]'}@`)\n .replace(AUTH_SCHEME_PATTERN, `$1 ${'[REDACTED]'}`)\n .replace(QUERY_CREDENTIAL_PATTERN, `$1$2=${'[REDACTED]'}`);\n};\n\n/** Kill-switch for local debugging: only the literal `false` disables redaction (fail-closed); read per call so it can be flipped at runtime. Never disable in production. `force` is the caller opting out of the switch: it always masks. */\nconst isRedactionEnabled = (force?: boolean): boolean =>\n force === true || globalThis.process?.env?.APP_ENV_LOGGER_DO_REDACT !== 'false';\n\n/** Longest string a log line carries whole. `APP_ENV_LOGGER_MAX_STRING_LENGTH=0` turns capping off. */\nconst DEFAULT_MAX_STRING_LENGTH = 2048;\n\nconst resolveMaxStringLength = (): number => {\n const configured = Number(globalThis.process?.env?.APP_ENV_LOGGER_MAX_STRING_LENGTH);\n\n return Number.isFinite(configured) && configured >= 0 ? configured : DEFAULT_MAX_STRING_LENGTH;\n};\n\n/**\n * Keys whose value is long BY NATURE and useless truncated. A stack trace is the whole reason you\n * are reading the line.\n */\nconst UNCAPPED_KEYS = new Set(['stack', 'stacktrace', 'stack_trace']);\n\n/**\n * Caps a long string, keeping the ORIGINAL LENGTH in the marker - that number is what tells you the\n * payload was a 300 KB image rather than a truncated sentence.\n *\n * A base64 body is the case this exists for: one `data:image/png;base64,...` field turns a request\n * log into hundreds of kilobytes, and nothing about it is readable.\n */\nconst capString = (opts: { value: string; key?: string; limit: number }): string => {\n const { value, key, limit } = opts;\n\n if (limit === 0 || value.length <= limit || (key && UNCAPPED_KEYS.has(key.toLowerCase()))) {\n return value;\n }\n\n return `${value.slice(0, limit)}... [truncated, ${value.length} chars total]`;\n};\n\ntype TSanitizeContext = {\n seen: WeakSet<object>;\n doRedact: boolean;\n /** Levels still allowed BELOW the current one; `Infinity` walks the whole graph. */\n depth: number;\n /** Longest string kept whole; 0 keeps every string. */\n maxStringLength: number;\n /** The key this value was found under, so a stack trace can be exempted from capping. */\n key?: string;\n};\n\nconst deepSanitize = (value: unknown, context: TSanitizeContext): unknown => {\n const { seen, doRedact, depth } = context;\n\n if (typeof value === 'string') {\n const text = doRedact ? scrubString(value) : value;\n\n return capString({ value: text, key: context.key, limit: context.maxStringLength });\n }\n\n // A function is not data, and an own `toJSON` on an object would run after this walk, inside `JSON.stringify`, and\n // hand back keys the walk never saw. Naming it keeps the redacted copy free of code.\n if (typeof value === 'function') {\n return '[Function]';\n }\n\n if (value === null || typeof value !== 'object') {\n return value;\n }\n\n // A Date holds its value in an internal slot, so the generic branch below - which reads Object.keys() - would flatten it to `{}`. Checked BEFORE `seen`: a Date cannot carry a cycle, and entering the set would make a second reference to the same instance read as `[Circular]`.\n if (value instanceof Date) {\n return value;\n }\n\n if (seen.has(value)) {\n return '[Circular]';\n }\n\n if (ArrayBuffer.isView(value) || value instanceof ArrayBuffer) {\n return `[Binary ${(value as ArrayBufferView).byteLength ?? 0} bytes]`;\n }\n\n if (depth <= 0) {\n return Array.isArray(value) ? '[Array]' : '[Object]';\n }\n\n seen.add(value);\n const nested: TSanitizeContext = {\n seen,\n doRedact,\n depth: depth - 1,\n maxStringLength: context.maxStringLength,\n };\n\n // Error keeps name/message/stack NON-enumerable, so Object.keys() skips them and naive redaction would drop the message - reproject into a plain object carrying those fields plus its redacted enumerable own-props.\n if (value instanceof Error) {\n const source = value;\n const result: Record<string, unknown> = {\n name: value.name,\n message: doRedact ? scrubString(value.message) : value.message,\n stack: doRedact && value.stack ? scrubString(value.stack) : value.stack,\n };\n\n for (const [key, entry] of Object.entries(source)) {\n result[key] =\n doRedact && SECRET_KEY_PATTERN.test(key)\n ? REDACTED\n : deepSanitize(entry, { ...nested, key });\n }\n\n return result;\n }\n\n if (Array.isArray(value)) {\n return value.map((entry) => deepSanitize(entry, nested));\n }\n\n const source = value;\n const result: Record<string, unknown> = {};\n\n for (const [key, entry] of Object.entries(source)) {\n if (doRedact && SECRET_KEY_PATTERN.test(key)) {\n result[key] = REDACTED;\n continue;\n }\n\n result[key] = deepSanitize(entry, { ...nested, key });\n }\n\n return result;\n};\n\n/** Makes a log argument safe to print: masks secret-looking keys, breaks cycles, caps long strings and strips URL credentials. `APP_ENV_LOGGER_DO_REDACT=false` turns off the key masking only. */\nexport class RedactUtility {\n /**\n * Redacts every secret-looking KEY (not value shape - buffers/typed arrays are summarized, not\n * serialized). `APP_ENV_LOGGER_DO_REDACT=false` makes this the identity function.\n *\n * `depth` bounds the walk, exactly as {@link RedactUtility.toJsonSafe} already does. It defaults to\n * `Infinity` for callers that really do want the whole graph, but the logger passes its own bound:\n * rendering only inspects a handful of levels, so walking to `Infinity` did work whose result was\n * thrown away - 12x on a deep graph, and a `RangeError` on a very deep chain.\n *\n * `force: true` masks secret-looking KEYS even when `APP_ENV_LOGGER_DO_REDACT=false`. The result is still the\n * log-shaped copy: long strings are capped, a second reference to one object reads `[Circular]`, binary is\n * summarized, and a key is masked by name only (a card number under `number` is not). It is not a faithful\n * redacted document. The logger never sets it.\n */\n static redactSecrets(opts: {\n value: unknown;\n seen?: WeakSet<object>;\n depth?: number;\n force?: boolean;\n }): unknown {\n const { value, seen, depth = Infinity, force } = opts;\n\n if (!isRedactionEnabled(force)) {\n return value;\n }\n\n return deepSanitize(value, {\n seen: seen ?? new WeakSet<object>(),\n doRedact: true,\n depth,\n maxStringLength: resolveMaxStringLength(),\n });\n }\n\n /** Masks the credentials a plain string carries (a url's password, a bearer token, credential query parameters). For a log line's string argument; objects go through {@link RedactUtility.redactSecrets}. `force: true` scrubs even when `APP_ENV_LOGGER_DO_REDACT=false`. */\n static scrubText(opts: { value: string; force?: boolean }): string {\n return isRedactionEnabled(opts.force) ? scrubString(opts.value) : opts.value;\n }\n\n /** Projects a value into something `JSON.stringify` can render: it answers `[Circular]` for the WHOLE payload when one cycle sits anywhere inside it, so cycles must be broken per-branch first. `depth` bounds the walk the way `util.inspect` does - a log argument may hold a live connector or request context, whose graph is effectively unbounded. The projection itself is unconditional: `APP_ENV_LOGGER_DO_REDACT=false` turns off the key masking, never the structural pass. `force: true` keeps the key masking on whatever the switch says; the projection stays lossy, as in {@link RedactUtility.redactSecrets}. */\n static toJsonSafe(opts: { value: unknown; depth?: number; force?: boolean }): unknown {\n return deepSanitize(opts.value, {\n seen: new WeakSet<object>(),\n doRedact: isRedactionEnabled(opts.force),\n depth: opts.depth ?? Infinity,\n // Capping is STRUCTURAL, like the projection itself: turning redaction off is about key masking,\n // never about letting a 300 KB base64 field through.\n maxStringLength: resolveMaxStringLength(),\n });\n }\n\n /** Strips credentials from a connection URL's authority section (`user:hunter2@host` -> `user:[REDACTED]@host`) - {@link RedactUtility.redactSecrets} matches on KEY names and can't see them there. A value that fails to parse as a URL is returned unchanged. `force: true` strips even when `APP_ENV_LOGGER_DO_REDACT=false`. */\n static redactUrlCredentials(opts: { url: string; force?: boolean }): string {\n const { url, force } = opts;\n\n if (!isRedactionEnabled(force)) {\n return url;\n }\n\n let parsed: URL;\n\n try {\n parsed = new URL(url);\n } catch {\n return url;\n }\n\n if (!parsed.password) {\n return url;\n }\n\n parsed.password = REDACTED;\n\n return decodeURIComponent(parsed.toString());\n }\n}\n"]}
|
package/dist/esm/core.d.ts
CHANGED
|
@@ -6,16 +6,19 @@ export type { ILogger, ILoggerProvider, TLogLevel } from './modules/logger/commo
|
|
|
6
6
|
export { ConsoleLogger } from './modules/logger/base/console.js';
|
|
7
7
|
export { LoggerFactory } from './modules/logger/factory.js';
|
|
8
8
|
export * from './modules/network/http-request/fetcher/base-fetcher.js';
|
|
9
|
-
export * from './modules/network/http-request/fetcher/
|
|
9
|
+
export * from './modules/network/http-request/fetcher/common/index.js';
|
|
10
|
+
export * from './modules/network/http-request/fetcher/native-fetcher.js';
|
|
10
11
|
export * from './modules/network/http-request/base-network-request.helper.js';
|
|
11
12
|
export * from './modules/pool/index.js';
|
|
12
13
|
export * from './modules/queue/internal/hf/index.js';
|
|
13
14
|
export * from './modules/temporal/index.js';
|
|
14
15
|
export * from './modules/uid/index.js';
|
|
15
16
|
export * from './modules/network/utilities/url-safety/common/constants.js';
|
|
16
|
-
export type { IUrlSafetyPolicy } from './modules/network/utilities/url-safety/common/types.js';
|
|
17
|
+
export type { IUrlSafetyPolicy, IUrlTrustedHosts, TTrustedOrigin, } from './modules/network/utilities/url-safety/common/types.js';
|
|
18
|
+
export { UrlFetchError, UrlSafetyErrors, } from './modules/network/utilities/url-safety/common/errors.js';
|
|
17
19
|
export * from './modules/network/utilities/url-safety/policy.js';
|
|
18
20
|
export * from './modules/network/utilities/query-string.js';
|
|
21
|
+
export * from './modules/network/utilities/url-builder.js';
|
|
19
22
|
export { RetryBackoffStrategies, RetryJitterModes } from './modules/retry/common/constants.js';
|
|
20
23
|
export type { TRetryBackoffStrategy, TRetryJitterMode } from './modules/retry/common/constants.js';
|
|
21
24
|
export type { IRetryBackoffOptions, IRetryContext } from './modules/retry/common/types.js';
|
package/dist/esm/core.js
CHANGED
|
@@ -9,20 +9,23 @@ export { LogLevels } from './modules/logger/common/types.js';
|
|
|
9
9
|
export { ConsoleLogger } from './modules/logger/base/console.js';
|
|
10
10
|
export { LoggerFactory } from './modules/logger/factory.js';
|
|
11
11
|
export * from './modules/network/http-request/fetcher/base-fetcher.js';
|
|
12
|
+
export * from './modules/network/http-request/fetcher/common/index.js';
|
|
12
13
|
// The node fetcher carries no node builtin - its one `querystring.stringify` is written out - so the
|
|
13
14
|
// framework HTTP layer is reachable from a browser bundle, and a connector on HTTP need not
|
|
14
15
|
// re-implement one.
|
|
15
|
-
export * from './modules/network/http-request/fetcher/
|
|
16
|
+
export * from './modules/network/http-request/fetcher/native-fetcher.js';
|
|
16
17
|
export * from './modules/network/http-request/base-network-request.helper.js';
|
|
17
18
|
export * from './modules/pool/index.js';
|
|
18
19
|
export * from './modules/queue/internal/hf/index.js';
|
|
19
20
|
export * from './modules/temporal/index.js';
|
|
20
21
|
export * from './modules/uid/index.js';
|
|
21
22
|
// The url guard, pure half only: `UrlPolicy` decides a url and a literal address with string and
|
|
22
|
-
// number work. Its sibling `
|
|
23
|
+
// number work. Its sibling `UrlGuard` reaches `node:dns` and stays out of this subpath.
|
|
23
24
|
export * from './modules/network/utilities/url-safety/common/constants.js';
|
|
25
|
+
export { UrlFetchError, UrlSafetyErrors, } from './modules/network/utilities/url-safety/common/errors.js';
|
|
24
26
|
export * from './modules/network/utilities/url-safety/policy.js';
|
|
25
27
|
export * from './modules/network/utilities/query-string.js';
|
|
28
|
+
export * from './modules/network/utilities/url-builder.js';
|
|
26
29
|
export { RetryBackoffStrategies, RetryJitterModes } from './modules/retry/common/constants.js';
|
|
27
30
|
export { RetryHelper } from './modules/retry/helper.js';
|
|
28
31
|
export { SlugHelper } from './modules/slug/helper.js';
|
package/dist/esm/core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../src/core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5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Ac,yCAAyC,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAG5F,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAcrD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,gGAAgG;AAChG,6FAA6F;AAC7F,iGAAiG;AACjG,0DAA0D;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAEnE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACnF,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAEvE,uHAAuH;AACvH,gGAAgG;AAChG,0EAA0E;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,gDAAgD,CAAC;AACzF,OAAO,EAAE,IAAI,EAAE,MAAM,4CAA4C,CAAC;AAOlE,+FAA+F;AAC/F,6GAA6G;AAC7G,wCAAwC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,2CAA2C,CAAC","sourcesContent":["export { BaseHelper } from './modules/base';\n// By name, never `export *` from `./modules/env`: that barrel also carries `Environment` and\n// `applicationEnvironment`, both of which read `process.env`.\nexport { EnvironmentNames } from './modules/env/names';\nexport * from './modules/error';\nexport { LogLevels } from './modules/logger/common/types';\nexport type { ILogger, ILoggerProvider, TLogLevel } from './modules/logger/common/types';\n// The one way to get a logger, the same in the browser and on the server: `LoggerFactory` imports nothing from node, and its\n// default provider is the console. An application chooses another with `LoggerFactory.use({ provider, level })`.\nexport { ConsoleLogger } from './modules/logger/base/console';\nexport { LoggerFactory } from './modules/logger/factory';\nexport * from './modules/network/http-request/fetcher/base-fetcher';\nexport * from './modules/network/http-request/fetcher/common';\n// The node fetcher carries no node builtin - its one `querystring.stringify` is written out - so the\n// framework HTTP layer is reachable from a browser bundle, and a connector on HTTP need not\n// re-implement one.\nexport * from './modules/network/http-request/fetcher/native-fetcher';\nexport * from './modules/network/http-request/base-network-request.helper';\nexport * from './modules/pool';\nexport * from './modules/queue/internal/hf';\nexport * from './modules/temporal';\nexport * from './modules/uid';\n// The url guard, pure half only: `UrlPolicy` decides a url and a literal address with string and\n// number work. Its sibling `UrlGuard` reaches `node:dns` and stays out of this subpath.\nexport * from './modules/network/utilities/url-safety/common/constants';\nexport type {\n IUrlSafetyPolicy,\n IUrlTrustedHosts,\n TTrustedOrigin,\n} from './modules/network/utilities/url-safety/common/types';\nexport {\n UrlFetchError,\n UrlSafetyErrors,\n} from './modules/network/utilities/url-safety/common/errors';\nexport * from './modules/network/utilities/url-safety/policy';\nexport * from './modules/network/utilities/query-string';\nexport * from './modules/network/utilities/url-builder';\nexport { RetryBackoffStrategies, RetryJitterModes } from './modules/retry/common/constants';\nexport type { TRetryBackoffStrategy, TRetryJitterMode } from './modules/retry/common/constants';\nexport type { IRetryBackoffOptions, IRetryContext } from './modules/retry/common/types';\nexport { RetryHelper } from './modules/retry/helper';\nexport { SlugHelper } from './modules/slug/helper';\nexport { TreeBuilder } from './modules/tree/builder';\nexport type {\n IBuildOptions,\n IHeightWhereOptions,\n ILeavesOptions,\n INodeWithPath,\n IPrintOptions,\n ITreeNode,\n IWalkAsyncOptions,\n IWalkOptions,\n TNodePredicate,\n TOnVisit,\n TOnVisitAsync,\n} from './modules/tree/common/types';\nexport { TreeWalker } from './modules/tree/walk';\n\n// Pure value/type utilities that already live under the root barrel's `./utilities` re-export -\n// that barrel also carries node-only siblings (module.utility.ts, request.utility.ts), so it\n// cannot itself become a subpath. Named one at a time here instead of widening the barrel: every\n// symbol below is verified free of node builtins/globals.\nexport { BuildInfoRegistry } from './utilities/build-info.utility';\nexport type { IBuildInfo, TBuildInfoRecord } from './utilities/build-info.utility';\nexport { EchoUtility } from './utilities/echo.utility';\nexport { ParseUtility } from './utilities/parse.utility';\nexport { PerformanceUtility } from './utilities/performance.utility';\nexport { PromiseUtility } from './utilities/promise.utility';\nexport { RecordUtility } from './utilities/record.utility';\nexport { FormBodyUtility, RequestBodyErrors } from './utilities/form-body.utility';\nexport { ProjectRootRegistry } from './utilities/project-root.utility';\n\n// `ECDH` is the one crypto algorithm that is browser-pure: it runs over `crypto.subtle`, `btoa` and `atob`. It and its\n// base class come by leaf path, never the algorithms barrel, which also carries `AES` and `RSA`\n// (server code: they use `Buffer`, and `AES` reads files with `node:fs`).\nexport { AbstractCryptoAlgorithm } from './modules/crypto/algorithms/abstract.algorithm';\nexport { ECDH } from './modules/crypto/algorithms/ecdh.algorithm';\nexport type {\n ECDHAlgorithmType,\n IECDHEncryptedPayload,\n IECDHExtraOptions,\n} from './modules/crypto/algorithms/ecdh.algorithm';\n\n// Type-only: erased at compile time, so re-exporting these carries no runtime/bundle cost even\n// though the concrete classes they describe (the other crypto algorithms, the ioredis-backed helper) are not\n// themselves part of this pure surface.\nexport { AESAlgorithms } from './modules/crypto/algorithms/aes.constants';\nexport type { AESAlgorithmType } from './modules/crypto/algorithms/aes.constants';\nexport type { IRedisHelper } from './modules/redis/common/interfaces';\n"]}
|
|
@@ -11,9 +11,14 @@ export declare class BaseNetworkRequest<T extends TFetcherVariant> extends BaseH
|
|
|
11
11
|
baseUrl?: string;
|
|
12
12
|
fetcher: IFetchable<T, IRequestOptions, TFetcherResponse<T>, TFetcherWorker<T>>;
|
|
13
13
|
});
|
|
14
|
+
/** The paths as one path: each with one leading slash. */
|
|
14
15
|
getRequestPath(opts: {
|
|
15
16
|
paths: Array<string>;
|
|
16
17
|
}): string;
|
|
18
|
+
/**
|
|
19
|
+
* The url of a request: the base and the paths, checked by `UrlBuilder.join`. A path may not be a dot segment, hide one,
|
|
20
|
+
* carry a backslash or a control character; a relative base is resolved against the page.
|
|
21
|
+
*/
|
|
17
22
|
getRequestUrl(opts: {
|
|
18
23
|
baseUrl?: string;
|
|
19
24
|
paths: Array<string>;
|
|
@@ -2,6 +2,7 @@ import { HTTP } from '../../../common/constants/http.js';
|
|
|
2
2
|
import { ObjectUtility } from '@venizia/ignis-inversion';
|
|
3
3
|
import { BaseHelper } from '../../base.js';
|
|
4
4
|
import { getError } from '../../error/index.js';
|
|
5
|
+
import { UrlBuilder } from '../utilities/url-builder.js';
|
|
5
6
|
/** Base of a client for one third-party HTTP API: holds the `baseUrl` and a fetcher, and builds request urls from path segments. `getRequestUrl` throws a 500 error when no base url is set. */
|
|
6
7
|
export class BaseNetworkRequest extends BaseHelper {
|
|
7
8
|
constructor(opts) {
|
|
@@ -9,32 +10,28 @@ export class BaseNetworkRequest extends BaseHelper {
|
|
|
9
10
|
this.baseUrl = opts.baseUrl ?? '';
|
|
10
11
|
this.fetcher = opts.fetcher;
|
|
11
12
|
}
|
|
13
|
+
/** The paths as one path: each with one leading slash. */
|
|
12
14
|
getRequestPath(opts) {
|
|
13
|
-
|
|
14
|
-
const rs = paths
|
|
15
|
-
.map((path) => {
|
|
16
|
-
if (!path.startsWith('/')) {
|
|
17
|
-
path = `/${path}`;
|
|
18
|
-
}
|
|
19
|
-
return path;
|
|
20
|
-
})
|
|
21
|
-
.join('');
|
|
22
|
-
return rs;
|
|
15
|
+
return UrlBuilder.toText({ baseUrl: '', paths: opts?.paths ?? [] });
|
|
23
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* The url of a request: the base and the paths, checked by `UrlBuilder.join`. A path may not be a dot segment, hide one,
|
|
19
|
+
* carry a backslash or a control character; a relative base is resolved against the page.
|
|
20
|
+
*/
|
|
24
21
|
getRequestUrl(opts) {
|
|
25
|
-
|
|
26
|
-
const paths = opts?.paths ?? [];
|
|
22
|
+
const baseUrl = opts?.baseUrl ?? this.baseUrl ?? '';
|
|
27
23
|
if (!baseUrl || ObjectUtility.isEmpty({ value: baseUrl })) {
|
|
28
24
|
throw getError({
|
|
29
25
|
statusCode: HTTP.ResultCodes.RS_5.InternalServerError,
|
|
30
26
|
message: '[getRequestUrl] Invalid configuration for third party request base url!',
|
|
31
27
|
});
|
|
32
28
|
}
|
|
33
|
-
|
|
34
|
-
baseUrl
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
const url = UrlBuilder.join({
|
|
30
|
+
baseUrl,
|
|
31
|
+
paths: opts?.paths ?? [],
|
|
32
|
+
scope: this.scope,
|
|
33
|
+
});
|
|
34
|
+
return url.toString();
|
|
38
35
|
}
|
|
39
36
|
getNetworkService() {
|
|
40
37
|
return this.fetcher;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-network-request.helper.js","sourceRoot":"","sources":["../../../../../src/modules/network/http-request/base-network-request.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"base-network-request.helper.js","sourceRoot":"","sources":["../../../../../src/modules/network/http-request/base-network-request.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,U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CAAC;IAClC,CAAC;CACF","sourcesContent":["import { HTTP } from '@/common/constants/http';\nimport { ObjectUtility } from '@venizia/ignis-inversion';\nimport { BaseHelper } from '@/modules/base';\nimport { getError } from '@/modules/error';\nimport { UrlBuilder } from '../utilities/url-builder';\nimport { type TFetcherVariant } from './common';\nimport { type IFetchable, type IRequestOptions } from './fetcher/base-fetcher';\nimport { type TFetcherResponse, type TFetcherWorker } from './fetcher/common';\n\n/** Base of a client for one third-party HTTP API: holds the `baseUrl` and a fetcher, and builds request urls from path segments. `getRequestUrl` throws a 500 error when no base url is set. */\nexport class BaseNetworkRequest<T extends TFetcherVariant> extends BaseHelper {\n protected baseUrl: string;\n protected fetcher: IFetchable<T, IRequestOptions, TFetcherResponse<T>, TFetcherWorker<T>>;\n\n constructor(opts: {\n name: string;\n baseUrl?: string;\n fetcher: IFetchable<T, IRequestOptions, TFetcherResponse<T>, TFetcherWorker<T>>;\n }) {\n super({ scope: opts.name, identifier: opts.name });\n this.baseUrl = opts.baseUrl ?? '';\n this.fetcher = opts.fetcher;\n }\n\n /** The paths as one path: each with one leading slash. */\n getRequestPath(opts: { paths: Array<string> }) {\n return UrlBuilder.toText({ baseUrl: '', paths: opts?.paths ?? [] });\n }\n\n /**\n * The url of a request: the base and the paths, checked by `UrlBuilder.join`. A path may not be a dot segment, hide one,\n * carry a backslash or a control character; a relative base is resolved against the page.\n */\n getRequestUrl(opts: { baseUrl?: string; paths: Array<string> }) {\n const baseUrl = opts?.baseUrl ?? this.baseUrl ?? '';\n\n if (!baseUrl || ObjectUtility.isEmpty({ value: baseUrl })) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: '[getRequestUrl] Invalid configuration for third party request base url!',\n });\n }\n\n const url = UrlBuilder.join({\n baseUrl,\n paths: opts?.paths ?? [],\n scope: this.scope,\n });\n\n return url.toString();\n }\n\n getNetworkService() {\n return this.fetcher;\n }\n\n getWorker(): TFetcherWorker<T> {\n return this.fetcher.getWorker();\n }\n}\n"]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { TConstValue } from '../../../../common/types/index.js';
|
|
2
2
|
/** The HTTP clients a fetcher can be built on. */
|
|
3
3
|
export declare class FetcherVariants {
|
|
4
|
-
|
|
4
|
+
/** The built-in `fetch` (Bun's, or a browser's). */
|
|
5
|
+
static readonly NATIVE = "native";
|
|
5
6
|
static readonly AXIOS = "axios";
|
|
6
7
|
}
|
|
7
8
|
/** Valid fetcher variant values. */
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** The HTTP clients a fetcher can be built on. */
|
|
2
2
|
export class FetcherVariants {
|
|
3
|
-
|
|
3
|
+
/** The built-in `fetch` (Bun's, or a browser's). */
|
|
4
|
+
static { this.NATIVE = 'native'; }
|
|
4
5
|
static { this.AXIOS = 'axios'; }
|
|
5
6
|
}
|
|
6
7
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../../src/modules/network/http-request/common/constants.ts"],"names":[],"mappings":"AAEA,kDAAkD;AAClD,MAAM,OAAO,eAAe;
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../../src/modules/network/http-request/common/constants.ts"],"names":[],"mappings":"AAEA,kDAAkD;AAClD,MAAM,OAAO,eAAe;IAC1B,oDAAoD;aACpC,WAAM,GAAG,QAAQ,CAAC;aAClB,UAAK,GAAG,OAAO,CAAC","sourcesContent":["import type { TConstValue } from '@/common/types';\n\n/** The HTTP clients a fetcher can be built on. */\nexport class FetcherVariants {\n /** The built-in `fetch` (Bun's, or a browser's). */\n static readonly NATIVE = 'native';\n static readonly AXIOS = 'axios';\n}\n\n/** Valid fetcher variant values. */\nexport type TFetcherVariant = TConstValue<typeof FetcherVariants>;\n"]}
|
|
@@ -1,30 +1,39 @@
|
|
|
1
|
-
import { type THttpMethod } from '../../../../common/index.js';
|
|
2
1
|
import { type AxiosInstance, type AxiosRequestConfig, type AxiosResponse } from 'axios';
|
|
2
|
+
import type { IUrlSafetyPolicy } from '../../utilities/url-safety/common/types.js';
|
|
3
3
|
import { BaseNetworkRequest } from '../base-network-request.helper.js';
|
|
4
4
|
import type { ILogger } from '../../../logger/common/types.js';
|
|
5
|
-
import { AbstractNetworkFetchableHelper, type IRequestOptions } from './base-fetcher.js';
|
|
5
|
+
import { AbstractNetworkFetchableHelper, type IFetchExchange, type IFetchExchangeRequest, type IRequestOptions } from './base-fetcher.js';
|
|
6
|
+
import type { IFetchGuard } from './common/guard.js';
|
|
7
|
+
import type { IFetcherDefaults, IFetcherHooks } from './common/types.js';
|
|
8
|
+
/** The fields of an axios config the pipeline owns. */
|
|
9
|
+
type TOwnedAxiosFields = 'url' | 'method' | 'params' | 'data' | 'headers' | 'signal' | 'timeout' | 'maxRedirects' | 'validateStatus';
|
|
6
10
|
/** Request accepted by `AxiosFetcher`: an axios config where `body` is sent as the axios `data`. `rejectUnauthorized` set here overrides the instance setting for this call. */
|
|
7
|
-
export interface IAxiosRequestOptions extends AxiosRequestConfig, IRequestOptions {
|
|
11
|
+
export interface IAxiosRequestOptions extends Omit<AxiosRequestConfig, TOwnedAxiosFields>, IRequestOptions {
|
|
8
12
|
url: string;
|
|
9
|
-
method?: THttpMethod;
|
|
10
13
|
params?: Record<string, unknown>;
|
|
11
14
|
body?: Record<string, unknown>;
|
|
12
|
-
headers?: Record<string, string>;
|
|
13
15
|
/** Whether this call rejects an HTTPS server whose certificate fails verification; `false` turns verification off for this call. */
|
|
14
16
|
rejectUnauthorized?: boolean;
|
|
15
17
|
}
|
|
16
|
-
/** Fetcher over an axios instance (`getWorker()`). HTTPS calls share one keep-alive agent that verifies certificates unless `rejectUnauthorized` is `false`; an `httpsAgent` passed in the request wins. */
|
|
18
|
+
/** Fetcher over an axios instance (`getWorker()`): the pipeline of `AbstractNetworkFetchableHelper` with axios as the client. HTTPS calls share one keep-alive agent that verifies certificates unless `rejectUnauthorized` is `false`; an `httpsAgent` passed in the request wins - and is refused together with a `guard`, because an agent of the caller's could connect elsewhere than the vetted address. */
|
|
17
19
|
export declare class AxiosFetcher extends AbstractNetworkFetchableHelper<'axios', IAxiosRequestOptions, AxiosResponse<unknown>, AxiosInstance> {
|
|
18
20
|
/**
|
|
19
21
|
* One agent for the instance, not one per request. Built here so TLS verification is decided
|
|
20
22
|
* ONCE, at construction, rather than per call - and so connections are actually reused: a fresh
|
|
21
23
|
* agent per request forces a new TCP and TLS handshake every time (measured: 10 handshakes for 10
|
|
22
|
-
* requests, versus 1).
|
|
24
|
+
* requests, versus 1). A guarded call never uses it: it gets an agent of its own that answers one vetted address and is dropped with the call, so no pin outlives it.
|
|
23
25
|
*/
|
|
24
26
|
private readonly httpsAgent;
|
|
27
|
+
private readonly isRejectingUnauthorized;
|
|
28
|
+
/** What the caller put in `defaultConfigs`: a guarded call checks it like its own options. */
|
|
29
|
+
private readonly configured;
|
|
25
30
|
constructor(opts: {
|
|
26
31
|
name: string;
|
|
27
|
-
defaultConfigs
|
|
32
|
+
defaultConfigs?: AxiosRequestConfig;
|
|
33
|
+
defaults?: IFetcherDefaults;
|
|
34
|
+
hooks?: IFetcherHooks;
|
|
35
|
+
/** The server half of the url guard (`UrlGuard`); a call that passes `guard` needs it. */
|
|
36
|
+
guardEngine?: IFetchGuard;
|
|
28
37
|
logger?: ILogger;
|
|
29
38
|
/**
|
|
30
39
|
* Whether this instance rejects an HTTPS server whose certificate fails verification.
|
|
@@ -33,17 +42,34 @@ export declare class AxiosFetcher extends AbstractNetworkFetchableHelper<'axios'
|
|
|
33
42
|
*/
|
|
34
43
|
rejectUnauthorized?: boolean;
|
|
35
44
|
});
|
|
36
|
-
|
|
45
|
+
protected assertCallSupported(opts: {
|
|
46
|
+
guard?: IUrlSafetyPolicy;
|
|
47
|
+
extra: Record<string | symbol, unknown>;
|
|
48
|
+
}): void;
|
|
49
|
+
protected buildUrl(opts: {
|
|
50
|
+
url: string;
|
|
51
|
+
params?: Record<string, unknown>;
|
|
52
|
+
}): string;
|
|
53
|
+
/** An axios body-size overflow is the cap's refusal (permanent), not a transport error the retry would repeat. */
|
|
54
|
+
private refineError;
|
|
55
|
+
protected exchange(opts: IFetchExchangeRequest): Promise<IFetchExchange<AxiosResponse<unknown>>>;
|
|
37
56
|
}
|
|
38
57
|
/** Options of `AxiosNetworkRequest`: an axios config with `baseUrl` in place of `baseURL`. */
|
|
39
58
|
export interface IAxiosNetworkRequestOptions {
|
|
40
59
|
name: string;
|
|
41
|
-
networkOptions: Omit<AxiosRequestConfig, 'baseURL'> & {
|
|
60
|
+
networkOptions: Omit<AxiosRequestConfig, 'baseURL' | 'headers' | 'timeout'> & {
|
|
42
61
|
baseUrl?: string;
|
|
62
|
+
headers?: Record<string, string>;
|
|
63
|
+
/** Per attempt, in milliseconds. @default 60000 */
|
|
64
|
+
timeout?: number;
|
|
43
65
|
};
|
|
66
|
+
defaults?: IFetcherDefaults;
|
|
67
|
+
hooks?: IFetcherHooks;
|
|
68
|
+
guardEngine?: IFetchGuard;
|
|
44
69
|
}
|
|
45
|
-
/** `BaseNetworkRequest` over an `AxiosFetcher`. Defaults: JSON content type
|
|
70
|
+
/** `BaseNetworkRequest` over an `AxiosFetcher`. Defaults: JSON content type and a 60000 ms `timeout`; a status outside 2xx throws a `UrlFetchError`. */
|
|
46
71
|
export declare class AxiosNetworkRequest extends BaseNetworkRequest<'axios'> {
|
|
47
72
|
constructor(opts: IAxiosNetworkRequestOptions);
|
|
48
73
|
}
|
|
74
|
+
export {};
|
|
49
75
|
//# sourceMappingURL=axios-fetcher.d.ts.map
|