@tessellation/http 0.0.0-stage → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +412 -2
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/lib/auth/api-key.d.ts +17 -0
- package/dist/lib/auth/api-key.d.ts.map +1 -0
- package/dist/lib/auth/api-key.js +48 -0
- package/dist/lib/auth/jwt.d.ts +33 -0
- package/dist/lib/auth/jwt.d.ts.map +1 -0
- package/dist/lib/auth/jwt.js +227 -0
- package/dist/lib/auth/provide-auth.d.ts +30 -0
- package/dist/lib/auth/provide-auth.d.ts.map +1 -0
- package/dist/lib/auth/provide-auth.js +69 -0
- package/dist/lib/auth/strategy.d.ts +47 -0
- package/dist/lib/auth/strategy.d.ts.map +1 -0
- package/dist/lib/auth/strategy.js +18 -0
- package/dist/lib/compile.d.ts +46 -0
- package/dist/lib/compile.d.ts.map +1 -0
- package/dist/lib/compile.js +126 -0
- package/dist/lib/compression.d.ts +23 -0
- package/dist/lib/compression.d.ts.map +1 -0
- package/dist/lib/compression.js +86 -0
- package/dist/lib/config.d.ts +173 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +93 -0
- package/dist/lib/cors.d.ts +41 -0
- package/dist/lib/cors.d.ts.map +1 -0
- package/dist/lib/cors.js +101 -0
- package/dist/lib/docs.d.ts +15 -0
- package/dist/lib/docs.d.ts.map +1 -0
- package/dist/lib/docs.js +93 -0
- package/dist/lib/engine.d.ts +83 -0
- package/dist/lib/engine.d.ts.map +1 -0
- package/dist/lib/engine.js +562 -0
- package/dist/lib/errors.d.ts +31 -0
- package/dist/lib/errors.d.ts.map +1 -0
- package/dist/lib/errors.js +55 -0
- package/dist/lib/etag.d.ts +5 -0
- package/dist/lib/etag.d.ts.map +1 -0
- package/dist/lib/etag.js +30 -0
- package/dist/lib/headers.d.ts +3 -0
- package/dist/lib/headers.d.ts.map +1 -0
- package/dist/lib/headers.js +14 -0
- package/dist/lib/json-schema.d.ts +11 -0
- package/dist/lib/json-schema.d.ts.map +1 -0
- package/dist/lib/json-schema.js +23 -0
- package/dist/lib/openapi.d.ts +18 -0
- package/dist/lib/openapi.d.ts.map +1 -0
- package/dist/lib/openapi.js +218 -0
- package/dist/lib/rate-limit.d.ts +52 -0
- package/dist/lib/rate-limit.d.ts.map +1 -0
- package/dist/lib/rate-limit.js +87 -0
- package/dist/lib/reply.d.ts +27 -0
- package/dist/lib/reply.d.ts.map +1 -0
- package/dist/lib/reply.js +52 -0
- package/dist/lib/request.d.ts +55 -0
- package/dist/lib/request.d.ts.map +1 -0
- package/dist/lib/request.js +36 -0
- package/dist/lib/router.d.ts +35 -0
- package/dist/lib/router.d.ts.map +1 -0
- package/dist/lib/router.js +173 -0
- package/dist/lib/routes.d.ts +196 -0
- package/dist/lib/routes.d.ts.map +1 -0
- package/dist/lib/routes.js +98 -0
- package/dist/lib/security-headers.d.ts +19 -0
- package/dist/lib/security-headers.d.ts.map +1 -0
- package/dist/lib/security-headers.js +22 -0
- package/dist/lib/serializer.d.ts +35 -0
- package/dist/lib/serializer.d.ts.map +1 -0
- package/dist/lib/serializer.js +147 -0
- package/dist/lib/server.d.ts +86 -0
- package/dist/lib/server.d.ts.map +1 -0
- package/dist/lib/server.js +255 -0
- package/dist/lib/testing.d.ts +21 -0
- package/dist/lib/testing.d.ts.map +1 -0
- package/dist/lib/testing.js +62 -0
- package/dist/lib/transports/node.d.ts +4 -0
- package/dist/lib/transports/node.d.ts.map +1 -0
- package/dist/lib/transports/node.js +249 -0
- package/dist/lib/transports/transport.d.ts +32 -0
- package/dist/lib/transports/transport.d.ts.map +1 -0
- package/dist/lib/transports/transport.js +1 -0
- package/dist/lib/transports/uws.d.ts +8 -0
- package/dist/lib/transports/uws.d.ts.map +1 -0
- package/dist/lib/transports/uws.js +246 -0
- package/dist/lib/websocket.d.ts +71 -0
- package/dist/lib/websocket.d.ts.map +1 -0
- package/dist/lib/websocket.js +125 -0
- package/package.json +67 -3
- package/src/index.ts +103 -0
- package/src/lib/auth/api-key.ts +73 -0
- package/src/lib/auth/jwt.ts +339 -0
- package/src/lib/auth/provide-auth.ts +99 -0
- package/src/lib/auth/strategy.ts +66 -0
- package/src/lib/compile.ts +207 -0
- package/src/lib/compression.ts +121 -0
- package/src/lib/config.ts +107 -0
- package/src/lib/cors.ts +146 -0
- package/src/lib/docs.ts +115 -0
- package/src/lib/engine.ts +770 -0
- package/src/lib/errors.ts +84 -0
- package/src/lib/etag.ts +37 -0
- package/src/lib/headers.ts +18 -0
- package/src/lib/json-schema.ts +36 -0
- package/src/lib/openapi.ts +299 -0
- package/src/lib/rate-limit.ts +142 -0
- package/src/lib/reply.ts +70 -0
- package/src/lib/request.ts +83 -0
- package/src/lib/router.ts +217 -0
- package/src/lib/routes.ts +414 -0
- package/src/lib/security-headers.ts +38 -0
- package/src/lib/serializer.ts +203 -0
- package/src/lib/server.ts +352 -0
- package/src/lib/testing.ts +88 -0
- package/src/lib/transports/node.ts +315 -0
- package/src/lib/transports/transport.ts +39 -0
- package/src/lib/transports/uws.ts +310 -0
- package/src/lib/websocket.ts +184 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { constants, createHmac, createPublicKey, timingSafeEqual, verify, } from 'node:crypto';
|
|
2
|
+
import { HttpError } from '../errors.js';
|
|
3
|
+
/** Each algorithm, the key type it needs and its hash. */
|
|
4
|
+
const ALGORITHMS = {
|
|
5
|
+
HS256: { kind: 'secret', hash: 'sha256' },
|
|
6
|
+
HS384: { kind: 'secret', hash: 'sha384' },
|
|
7
|
+
HS512: { kind: 'secret', hash: 'sha512' },
|
|
8
|
+
RS256: { kind: 'rsa', hash: 'sha256' },
|
|
9
|
+
RS384: { kind: 'rsa', hash: 'sha384' },
|
|
10
|
+
RS512: { kind: 'rsa', hash: 'sha512' },
|
|
11
|
+
PS256: { kind: 'rsa-pss', hash: 'sha256' },
|
|
12
|
+
PS384: { kind: 'rsa-pss', hash: 'sha384' },
|
|
13
|
+
PS512: { kind: 'rsa-pss', hash: 'sha512' },
|
|
14
|
+
ES256: { kind: 'ec', hash: 'sha256' },
|
|
15
|
+
ES384: { kind: 'ec', hash: 'sha384' },
|
|
16
|
+
ES512: { kind: 'ec', hash: 'sha512' },
|
|
17
|
+
EdDSA: { kind: 'ed', hash: null },
|
|
18
|
+
};
|
|
19
|
+
/** Authenticates `Authorization: Bearer <JWT>` requests. */
|
|
20
|
+
export function jwtAuth(options) {
|
|
21
|
+
const name = options.name ?? 'bearer';
|
|
22
|
+
const sources = [options.secret, options.publicKey, options.jwksUrl].filter((s) => s !== undefined);
|
|
23
|
+
if (sources.length !== 1) {
|
|
24
|
+
throw new Error('jwtAuth() needs exactly one of secret, publicKey or jwksUrl.');
|
|
25
|
+
}
|
|
26
|
+
const algorithms = new Set(options.algorithms ??
|
|
27
|
+
(options.secret !== undefined
|
|
28
|
+
? ['HS256']
|
|
29
|
+
: ['RS256', 'PS256', 'ES256', 'EdDSA']));
|
|
30
|
+
for (const algorithm of algorithms) {
|
|
31
|
+
const known = ALGORITHMS[algorithm];
|
|
32
|
+
if (known === undefined) {
|
|
33
|
+
throw new Error(`Unsupported JWT algorithm "${algorithm}".`);
|
|
34
|
+
}
|
|
35
|
+
if ((known.kind === 'secret') !== (options.secret !== undefined)) {
|
|
36
|
+
throw new Error(`JWT algorithm ${algorithm} ${known.kind === 'secret' ? 'needs a secret' : 'needs a public key'}.`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const secret = options.secret === undefined ? undefined : Buffer.from(options.secret);
|
|
40
|
+
const publicKey = options.publicKey === undefined ? undefined : toKey(options.publicKey);
|
|
41
|
+
const jwks = options.jwksUrl === undefined ? undefined : new Jwks(options.jwksUrl);
|
|
42
|
+
const issuers = toList(options.issuer);
|
|
43
|
+
const audiences = toList(options.audience);
|
|
44
|
+
const tolerance = options.clockTolerance ?? 5000;
|
|
45
|
+
const toPrincipal = options.principal ?? defaultPrincipal;
|
|
46
|
+
return {
|
|
47
|
+
name,
|
|
48
|
+
scheme: { type: 'http', scheme: 'bearer', bearerFormat: 'JWT' },
|
|
49
|
+
async authenticate(request) {
|
|
50
|
+
const authorization = request.headers['authorization'];
|
|
51
|
+
if (authorization === undefined || !/^bearer\s/i.test(authorization)) {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
const token = authorization.slice(7).trim();
|
|
55
|
+
const parts = token.split('.');
|
|
56
|
+
if (parts.length !== 3) {
|
|
57
|
+
throw invalid('The token is malformed.');
|
|
58
|
+
}
|
|
59
|
+
const [encodedHeader, encodedPayload, encodedSignature] = parts;
|
|
60
|
+
const header = decodeJson(encodedHeader);
|
|
61
|
+
const algorithm = header['alg'];
|
|
62
|
+
if (typeof algorithm !== 'string' || !algorithms.has(algorithm)) {
|
|
63
|
+
throw invalid('The token algorithm is not accepted.');
|
|
64
|
+
}
|
|
65
|
+
const { kind, hash } = ALGORITHMS[algorithm];
|
|
66
|
+
const data = Buffer.from(`${encodedHeader}.${encodedPayload}`);
|
|
67
|
+
const signature = Buffer.from(encodedSignature, 'base64url');
|
|
68
|
+
let valid;
|
|
69
|
+
if (kind === 'secret') {
|
|
70
|
+
const expected = createHmac(hash, secret)
|
|
71
|
+
.update(data)
|
|
72
|
+
.digest();
|
|
73
|
+
valid =
|
|
74
|
+
expected.length === signature.length &&
|
|
75
|
+
timingSafeEqual(expected, signature);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
const key = publicKey ??
|
|
79
|
+
(await jwks.key(typeof header['kid'] === 'string' ? header['kid'] : undefined));
|
|
80
|
+
if (!keyMatches(key, kind)) {
|
|
81
|
+
throw invalid('The token algorithm does not match the key.');
|
|
82
|
+
}
|
|
83
|
+
valid = verify(hash, data, kind === 'rsa-pss'
|
|
84
|
+
? {
|
|
85
|
+
key,
|
|
86
|
+
padding: constants.RSA_PKCS1_PSS_PADDING,
|
|
87
|
+
saltLength: constants.RSA_PSS_SALTLEN_DIGEST,
|
|
88
|
+
}
|
|
89
|
+
: kind === 'ec'
|
|
90
|
+
? { key, dsaEncoding: 'ieee-p1363' }
|
|
91
|
+
: key, signature);
|
|
92
|
+
}
|
|
93
|
+
if (!valid) {
|
|
94
|
+
throw invalid('The token signature is not valid.');
|
|
95
|
+
}
|
|
96
|
+
const claims = decodeJson(encodedPayload);
|
|
97
|
+
const now = Date.now();
|
|
98
|
+
if (claims['exp'] !== undefined &&
|
|
99
|
+
(typeof claims['exp'] !== 'number' ||
|
|
100
|
+
now > claims['exp'] * 1000 + tolerance)) {
|
|
101
|
+
throw invalid('The token has expired.');
|
|
102
|
+
}
|
|
103
|
+
if (claims['nbf'] !== undefined &&
|
|
104
|
+
(typeof claims['nbf'] !== 'number' ||
|
|
105
|
+
now < claims['nbf'] * 1000 - tolerance)) {
|
|
106
|
+
throw invalid('The token is not valid yet.');
|
|
107
|
+
}
|
|
108
|
+
if (issuers !== undefined && !issuers.includes(claims['iss'])) {
|
|
109
|
+
throw invalid('The token issuer is not accepted.');
|
|
110
|
+
}
|
|
111
|
+
if (audiences !== undefined) {
|
|
112
|
+
const audience = toList(claims['aud']) ?? [];
|
|
113
|
+
if (!audience.some((value) => audiences.includes(value))) {
|
|
114
|
+
throw invalid('The token audience is not accepted.');
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return { ...toPrincipal(claims), strategy: name };
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function defaultPrincipal(claims) {
|
|
122
|
+
if (typeof claims['sub'] !== 'string') {
|
|
123
|
+
throw invalid('The token has no subject.');
|
|
124
|
+
}
|
|
125
|
+
const roles = Array.isArray(claims['roles'])
|
|
126
|
+
? claims['roles'].filter((role) => typeof role === 'string')
|
|
127
|
+
: typeof claims['scope'] === 'string'
|
|
128
|
+
? claims['scope'].split(' ').filter((scope) => scope !== '')
|
|
129
|
+
: [];
|
|
130
|
+
return { id: claims['sub'], roles, claims };
|
|
131
|
+
}
|
|
132
|
+
function invalid(message) {
|
|
133
|
+
return new HttpError(401, message, {
|
|
134
|
+
headers: { 'www-authenticate': 'Bearer error="invalid_token"' },
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
function decodeJson(part) {
|
|
138
|
+
try {
|
|
139
|
+
const value = JSON.parse(Buffer.from(part, 'base64url').toString('utf8'));
|
|
140
|
+
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
141
|
+
return value;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
// reported below
|
|
146
|
+
}
|
|
147
|
+
throw invalid('The token is malformed.');
|
|
148
|
+
}
|
|
149
|
+
function toKey(key) {
|
|
150
|
+
if (typeof key === 'string') {
|
|
151
|
+
return createPublicKey(key);
|
|
152
|
+
}
|
|
153
|
+
if ('asymmetricKeyType' in key) {
|
|
154
|
+
return key;
|
|
155
|
+
}
|
|
156
|
+
return createPublicKey({ key: key, format: 'jwk' });
|
|
157
|
+
}
|
|
158
|
+
function keyMatches(key, kind) {
|
|
159
|
+
const type = key.asymmetricKeyType;
|
|
160
|
+
switch (kind) {
|
|
161
|
+
case 'rsa':
|
|
162
|
+
case 'rsa-pss':
|
|
163
|
+
return type === 'rsa' || type === 'rsa-pss';
|
|
164
|
+
case 'ec':
|
|
165
|
+
return type === 'ec';
|
|
166
|
+
case 'ed':
|
|
167
|
+
return type === 'ed25519' || type === 'ed448';
|
|
168
|
+
default:
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function toList(value) {
|
|
173
|
+
return value === undefined
|
|
174
|
+
? undefined
|
|
175
|
+
: typeof value === 'string'
|
|
176
|
+
? [value]
|
|
177
|
+
: value;
|
|
178
|
+
}
|
|
179
|
+
/** Keys from a JWKS endpoint, cached and refreshed when an unknown key id appears. */
|
|
180
|
+
class Jwks {
|
|
181
|
+
url;
|
|
182
|
+
keys = new Map();
|
|
183
|
+
fetched = 0;
|
|
184
|
+
pending;
|
|
185
|
+
constructor(url) {
|
|
186
|
+
this.url = url;
|
|
187
|
+
}
|
|
188
|
+
async key(kid) {
|
|
189
|
+
const stale = Date.now() - this.fetched > 10 * 60_000;
|
|
190
|
+
// Refresh for unknown ids (key rotation), at most every 30 seconds.
|
|
191
|
+
const unknown = kid !== undefined &&
|
|
192
|
+
!this.keys.has(kid) &&
|
|
193
|
+
Date.now() - this.fetched > 30_000;
|
|
194
|
+
if (stale || unknown) {
|
|
195
|
+
this.pending ??= this.refresh().finally(() => {
|
|
196
|
+
this.pending = undefined;
|
|
197
|
+
});
|
|
198
|
+
await this.pending;
|
|
199
|
+
}
|
|
200
|
+
const key = kid === undefined
|
|
201
|
+
? this.keys.size === 1
|
|
202
|
+
? [...this.keys.values()][0]
|
|
203
|
+
: undefined
|
|
204
|
+
: this.keys.get(kid);
|
|
205
|
+
if (key === undefined) {
|
|
206
|
+
throw invalid('The token was signed with an unknown key.');
|
|
207
|
+
}
|
|
208
|
+
return key;
|
|
209
|
+
}
|
|
210
|
+
async refresh() {
|
|
211
|
+
const response = await fetch(this.url, {
|
|
212
|
+
signal: AbortSignal.timeout(5000),
|
|
213
|
+
});
|
|
214
|
+
if (!response.ok) {
|
|
215
|
+
throw new HttpError(503, 'The signing keys could not be loaded.');
|
|
216
|
+
}
|
|
217
|
+
const { keys = [] } = (await response.json());
|
|
218
|
+
const next = new Map();
|
|
219
|
+
for (const jwk of keys) {
|
|
220
|
+
if (jwk.use === undefined || jwk.use === 'sig') {
|
|
221
|
+
next.set(jwk.kid ?? '', createPublicKey({ key: jwk, format: 'jwk' }));
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
this.keys = next;
|
|
225
|
+
this.fetched = Date.now();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type Provider } from '@tessellation/core';
|
|
2
|
+
import type { Middleware } from '../routes.js';
|
|
3
|
+
import { type AuthStrategy, type Principal } from './strategy.js';
|
|
4
|
+
/** Marks middleware that requires authentication, for OpenAPI `security`. */
|
|
5
|
+
export declare const SECURED: unique symbol;
|
|
6
|
+
/**
|
|
7
|
+
* Authenticates every request with the first strategy that recognizes its
|
|
8
|
+
* credentials. The principal is then available through `principal()`,
|
|
9
|
+
* `requirePrincipal()` and `CurrentPrincipal`, and logs written while
|
|
10
|
+
* handling the request carry its id. Unauthenticated requests continue
|
|
11
|
+
* anonymously; protect routes with `authenticated()` or `requireRoles()`.
|
|
12
|
+
*
|
|
13
|
+
* Strategies can be given as factories, which run in the injection context
|
|
14
|
+
* (to read config, for example):
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* provideAuth(
|
|
18
|
+
* () => apiKeyAuth({ keys: inject(AuthConfig).apiKeys }),
|
|
19
|
+
* () => jwtAuth({ jwksUrl: inject(AuthConfig).jwksUrl }),
|
|
20
|
+
* )
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function provideAuth(...strategies: (AuthStrategy | (() => AuthStrategy))[]): Provider[];
|
|
24
|
+
/** Rejects unauthenticated requests with 401. */
|
|
25
|
+
export declare function authenticated(): Middleware;
|
|
26
|
+
/** Rejects requests whose principal lacks any of `roles` (401 if unauthenticated, 403 otherwise). */
|
|
27
|
+
export declare function requireRoles(...roles: string[]): Middleware;
|
|
28
|
+
/** Rejects requests whose principal fails `check` (401 if unauthenticated, 403 otherwise). */
|
|
29
|
+
export declare function authorize(check: (principal: Principal) => boolean | Promise<boolean>, message?: string): Middleware;
|
|
30
|
+
//# sourceMappingURL=provide-auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provide-auth.d.ts","sourceRoot":"","sources":["../../../src/lib/auth/provide-auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,QAAQ,EACd,MAAM,oBAAoB,CAAC;AAG5B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,OAAO,EAEL,KAAK,YAAY,EAEjB,KAAK,SAAS,EAEf,MAAM,eAAe,CAAC;AAEvB,6EAA6E;AAC7E,eAAO,MAAM,OAAO,eAAoB,CAAC;AAEzC;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,CACzB,GAAG,UAAU,EAAE,CAAC,YAAY,GAAG,CAAC,MAAM,YAAY,CAAC,CAAC,EAAE,GACrD,QAAQ,EAAE,CASZ;AAsBD,iDAAiD;AACjD,wBAAgB,aAAa,IAAI,UAAU,CAK1C;AAED,qGAAqG;AACrG,wBAAgB,YAAY,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,UAAU,CAK3D;AAED,8FAA8F;AAC9F,wBAAgB,SAAS,CACvB,KAAK,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,EAC3D,OAAO,SAAoC,GAC1C,UAAU,CAOZ"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { addLogFields, inject, provide, } from '@tessellation/core';
|
|
2
|
+
import { forbidden } from '../errors.js';
|
|
3
|
+
import { provideHttpMiddleware } from '../server.js';
|
|
4
|
+
import { AUTH_STRATEGIES, CurrentPrincipal, requirePrincipal, } from './strategy.js';
|
|
5
|
+
/** Marks middleware that requires authentication, for OpenAPI `security`. */
|
|
6
|
+
export const SECURED = Symbol('secured');
|
|
7
|
+
/**
|
|
8
|
+
* Authenticates every request with the first strategy that recognizes its
|
|
9
|
+
* credentials. The principal is then available through `principal()`,
|
|
10
|
+
* `requirePrincipal()` and `CurrentPrincipal`, and logs written while
|
|
11
|
+
* handling the request carry its id. Unauthenticated requests continue
|
|
12
|
+
* anonymously; protect routes with `authenticated()` or `requireRoles()`.
|
|
13
|
+
*
|
|
14
|
+
* Strategies can be given as factories, which run in the injection context
|
|
15
|
+
* (to read config, for example):
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* provideAuth(
|
|
19
|
+
* () => apiKeyAuth({ keys: inject(AuthConfig).apiKeys }),
|
|
20
|
+
* () => jwtAuth({ jwksUrl: inject(AuthConfig).jwksUrl }),
|
|
21
|
+
* )
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function provideAuth(...strategies) {
|
|
25
|
+
return [
|
|
26
|
+
...strategies.map((strategy) => typeof strategy === 'function'
|
|
27
|
+
? provide(AUTH_STRATEGIES, { useFactory: strategy, multi: true })
|
|
28
|
+
: provide(AUTH_STRATEGIES, { useValue: strategy, multi: true })),
|
|
29
|
+
provideHttpMiddleware(authenticate),
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
const authenticate = async (context, next) => {
|
|
33
|
+
const strategies = inject(AUTH_STRATEGIES);
|
|
34
|
+
for (const strategy of strategies) {
|
|
35
|
+
let found = strategy.authenticate(context.request);
|
|
36
|
+
if (found instanceof Promise) {
|
|
37
|
+
found = await found;
|
|
38
|
+
}
|
|
39
|
+
if (found !== undefined) {
|
|
40
|
+
// Request logs from here on (and the access log) carry the principal.
|
|
41
|
+
addLogFields({ principal: found.id });
|
|
42
|
+
return CurrentPrincipal.run(found, next);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return next();
|
|
46
|
+
};
|
|
47
|
+
function secured(middleware) {
|
|
48
|
+
return Object.assign(middleware, { [SECURED]: true });
|
|
49
|
+
}
|
|
50
|
+
/** Rejects unauthenticated requests with 401. */
|
|
51
|
+
export function authenticated() {
|
|
52
|
+
return secured((_context, next) => {
|
|
53
|
+
requirePrincipal();
|
|
54
|
+
return next();
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/** Rejects requests whose principal lacks any of `roles` (401 if unauthenticated, 403 otherwise). */
|
|
58
|
+
export function requireRoles(...roles) {
|
|
59
|
+
return authorize((current) => roles.every((role) => current.roles.includes(role)), `This requires the role${roles.length === 1 ? '' : 's'} ${roles.join(', ')}.`);
|
|
60
|
+
}
|
|
61
|
+
/** Rejects requests whose principal fails `check` (401 if unauthenticated, 403 otherwise). */
|
|
62
|
+
export function authorize(check, message = 'You are not allowed to do this.') {
|
|
63
|
+
return secured(async (_context, next) => {
|
|
64
|
+
if (!(await check(requirePrincipal()))) {
|
|
65
|
+
throw forbidden(message);
|
|
66
|
+
}
|
|
67
|
+
return next();
|
|
68
|
+
});
|
|
69
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { AsyncContext, InjectionToken } from '@tessellation/core';
|
|
2
|
+
import type { HttpRequest } from '../request.js';
|
|
3
|
+
/** Who is making the request. */
|
|
4
|
+
export interface Principal {
|
|
5
|
+
/** A stable identifier, such as a user id or JWT `sub`. */
|
|
6
|
+
readonly id: string;
|
|
7
|
+
/** The name of the strategy that authenticated the request. */
|
|
8
|
+
readonly strategy: string;
|
|
9
|
+
readonly roles: readonly string[];
|
|
10
|
+
/** Everything else known about the principal, such as JWT claims. */
|
|
11
|
+
readonly claims: Readonly<Record<string, unknown>>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A way of authenticating requests. `authenticate()` returns a principal
|
|
15
|
+
* for valid credentials, `undefined` when the request carries no
|
|
16
|
+
* credentials for this strategy (so the next one is tried), and throws
|
|
17
|
+
* (such as `unauthorized()`) for invalid ones.
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* const sessionAuth: AuthStrategy = {
|
|
21
|
+
* name: 'session',
|
|
22
|
+
* scheme: { type: 'apiKey', in: 'cookie', name: 'sid' },
|
|
23
|
+
* async authenticate(request) {
|
|
24
|
+
* const sid = parseCookies(request.header('cookie')).sid;
|
|
25
|
+
* if (sid === undefined) return undefined;
|
|
26
|
+
* const session = await sessions.find(sid);
|
|
27
|
+
* if (session === undefined) throw unauthorized('Session expired.');
|
|
28
|
+
* return { id: session.userId, strategy: 'session', roles: session.roles, claims: {} };
|
|
29
|
+
* },
|
|
30
|
+
* };
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export interface AuthStrategy {
|
|
34
|
+
readonly name: string;
|
|
35
|
+
/** The OpenAPI security scheme describing this strategy. */
|
|
36
|
+
readonly scheme?: Readonly<Record<string, unknown>>;
|
|
37
|
+
authenticate(request: HttpRequest): Principal | undefined | Promise<Principal | undefined>;
|
|
38
|
+
}
|
|
39
|
+
/** The strategies registered with `provideAuth()`, tried in order. */
|
|
40
|
+
export declare const AUTH_STRATEGIES: InjectionToken<AuthStrategy[]>;
|
|
41
|
+
/** The principal of the current request, set by `provideAuth()`. */
|
|
42
|
+
export declare const CurrentPrincipal: AsyncContext<Principal>;
|
|
43
|
+
/** The current request's principal, if it is authenticated. */
|
|
44
|
+
export declare function principal(): Principal | undefined;
|
|
45
|
+
/** The current request's principal; throws 401 if it is not authenticated. */
|
|
46
|
+
export declare function requirePrincipal(): Principal;
|
|
47
|
+
//# sourceMappingURL=strategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategy.d.ts","sourceRoot":"","sources":["../../../src/lib/auth/strategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGlE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,iCAAiC;AACjC,MAAM,WAAW,SAAS;IACxB,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,+DAA+D;IAC/D,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,qEAAqE;IACrE,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACpD;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,4DAA4D;IAC5D,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACpD,YAAY,CACV,OAAO,EAAE,WAAW,GACnB,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC,CAAC;CAC3D;AAED,sEAAsE;AACtE,eAAO,MAAM,eAAe,gCAE3B,CAAC;AAEF,oEAAoE;AACpE,eAAO,MAAM,gBAAgB,yBAA2C,CAAC;AAEzE,+DAA+D;AAC/D,wBAAgB,SAAS,IAAI,SAAS,GAAG,SAAS,CAEjD;AAED,8EAA8E;AAC9E,wBAAgB,gBAAgB,IAAI,SAAS,CAM5C"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AsyncContext, InjectionToken } from '@tessellation/core';
|
|
2
|
+
import { unauthorized } from '../errors.js';
|
|
3
|
+
/** The strategies registered with `provideAuth()`, tried in order. */
|
|
4
|
+
export const AUTH_STRATEGIES = new InjectionToken('AUTH_STRATEGIES');
|
|
5
|
+
/** The principal of the current request, set by `provideAuth()`. */
|
|
6
|
+
export const CurrentPrincipal = new AsyncContext('principal');
|
|
7
|
+
/** The current request's principal, if it is authenticated. */
|
|
8
|
+
export function principal() {
|
|
9
|
+
return CurrentPrincipal.get();
|
|
10
|
+
}
|
|
11
|
+
/** The current request's principal; throws 401 if it is not authenticated. */
|
|
12
|
+
export function requirePrincipal() {
|
|
13
|
+
const current = CurrentPrincipal.get();
|
|
14
|
+
if (current === undefined) {
|
|
15
|
+
throw unauthorized('Authentication is required.');
|
|
16
|
+
}
|
|
17
|
+
return current;
|
|
18
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Provider, StandardSchemaV1 } from '@tessellation/core';
|
|
2
|
+
import type { GroupDefinition, HttpMethod, Middleware, RouteDefinition, RouteDocs } from './routes.js';
|
|
3
|
+
import { type Serializer } from './serializer.js';
|
|
4
|
+
import type { WebSocketHandlers } from './websocket.js';
|
|
5
|
+
type Schema = StandardSchemaV1;
|
|
6
|
+
/** A level of the path that declared a params schema. */
|
|
7
|
+
export interface ParamLevel {
|
|
8
|
+
/** The params introduced by this level's path segment. */
|
|
9
|
+
readonly names: readonly string[];
|
|
10
|
+
readonly schema: Schema;
|
|
11
|
+
}
|
|
12
|
+
export interface CompiledRoute {
|
|
13
|
+
readonly method: HttpMethod;
|
|
14
|
+
/** Full path pattern, such as `/api/users/:userId`. */
|
|
15
|
+
readonly path: string;
|
|
16
|
+
/** Param names in the order the router returns their values. */
|
|
17
|
+
readonly paramNames: readonly string[];
|
|
18
|
+
readonly paramLevels: readonly ParamLevel[];
|
|
19
|
+
readonly query: Schema | undefined;
|
|
20
|
+
readonly body: Schema | undefined;
|
|
21
|
+
/** Response schemas by status code. */
|
|
22
|
+
readonly responses: ReadonlyMap<number, Schema>;
|
|
23
|
+
readonly middleware: readonly Middleware[];
|
|
24
|
+
readonly providers: readonly Provider[];
|
|
25
|
+
readonly handler: RouteDefinition['options']['handler'];
|
|
26
|
+
readonly docs: RouteDocs & {
|
|
27
|
+
readonly tags: readonly string[];
|
|
28
|
+
/** Whether middleware on the route requires authentication. */
|
|
29
|
+
readonly secured: boolean;
|
|
30
|
+
};
|
|
31
|
+
/** Compiled JSON serializers by status code. */
|
|
32
|
+
readonly serializers: Map<number, Serializer>;
|
|
33
|
+
/** Handlers for WebSocket routes. */
|
|
34
|
+
readonly websocket: WebSocketHandlers<unknown> | undefined;
|
|
35
|
+
}
|
|
36
|
+
/** Flattens route trees into routes with their full paths and inherited settings. */
|
|
37
|
+
export declare function compileRoutes(trees: readonly GroupDefinition[], options?: {
|
|
38
|
+
prefix?: string;
|
|
39
|
+
middleware?: readonly Middleware[];
|
|
40
|
+
}): CompiledRoute[];
|
|
41
|
+
export declare function isSchema(value: unknown): value is Schema;
|
|
42
|
+
/** Ensures a leading slash and no trailing slash (except for the root). */
|
|
43
|
+
export declare function normalizePath(path: string): string;
|
|
44
|
+
export declare function joinPaths(base: string, path: string): string;
|
|
45
|
+
export {};
|
|
46
|
+
//# sourceMappingURL=compile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/lib/compile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAKrE,OAAO,KAAK,EACV,eAAe,EACf,UAAU,EACV,UAAU,EACV,eAAe,EACf,SAAS,EAEV,MAAM,aAAa,CAAC;AACrB,OAAO,EAAqB,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD,KAAK,MAAM,GAAG,gBAAgB,CAAC;AAE/B,yDAAyD;AACzD,MAAM,WAAW,UAAU;IACzB,0DAA0D;IAC1D,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,uDAAuD;IACvD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,gEAAgE;IAChE,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IAC5C,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,uCAAuC;IACvC,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChD,QAAQ,CAAC,UAAU,EAAE,SAAS,UAAU,EAAE,CAAC;IAC3C,QAAQ,CAAC,SAAS,EAAE,SAAS,QAAQ,EAAE,CAAC;IACxC,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,CAAC;IACxD,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG;QACzB,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;QACjC,+DAA+D;QAC/D,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;KAC3B,CAAC;IACF,gDAAgD;IAChD,QAAQ,CAAC,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAC9C,qCAAqC;IACrC,QAAQ,CAAC,SAAS,EAAE,iBAAiB,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;CAC5D;AAWD,qFAAqF;AACrF,wBAAgB,aAAa,CAC3B,KAAK,EAAE,SAAS,eAAe,EAAE,EACjC,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,SAAS,UAAU,EAAE,CAAA;CAAO,GACpE,aAAa,EAAE,CAgBjB;AAuGD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAOxD;AAED,2EAA2E;AAC3E,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAMlD;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAM5D"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { jsonSchemaOf } from './json-schema.js';
|
|
2
|
+
import { SECURED } from './auth/provide-auth.js';
|
|
3
|
+
import { parsePattern } from './router.js';
|
|
4
|
+
import { compileSerializer } from './serializer.js';
|
|
5
|
+
/** Flattens route trees into routes with their full paths and inherited settings. */
|
|
6
|
+
export function compileRoutes(trees, options = {}) {
|
|
7
|
+
const compiled = [];
|
|
8
|
+
const root = {
|
|
9
|
+
path: normalizePath(options.prefix ?? '/'),
|
|
10
|
+
paramLevels: [],
|
|
11
|
+
middleware: [...(options.middleware ?? [])],
|
|
12
|
+
providers: [],
|
|
13
|
+
tags: [],
|
|
14
|
+
hidden: false,
|
|
15
|
+
};
|
|
16
|
+
for (const tree of trees) {
|
|
17
|
+
visit(tree, root, compiled);
|
|
18
|
+
}
|
|
19
|
+
return compiled;
|
|
20
|
+
}
|
|
21
|
+
function visit(node, scope, out) {
|
|
22
|
+
const path = joinPaths(scope.path, node.path);
|
|
23
|
+
const levels = [...scope.paramLevels];
|
|
24
|
+
const paramsSchema = node.options.params;
|
|
25
|
+
if (paramsSchema !== undefined) {
|
|
26
|
+
const names = parsePattern(normalizePath(node.path))
|
|
27
|
+
.filter((segment) => segment.kind !== 'static')
|
|
28
|
+
.map((segment) => segment.value);
|
|
29
|
+
if (names.length === 0) {
|
|
30
|
+
throw new Error(`"${path}" declares a params schema but its own path "${node.path}" has no parameters.`);
|
|
31
|
+
}
|
|
32
|
+
levels.push({ names, schema: paramsSchema });
|
|
33
|
+
}
|
|
34
|
+
const middleware = [...scope.middleware, ...(node.options.middleware ?? [])];
|
|
35
|
+
const providers = [...scope.providers, ...(node.options.providers ?? [])];
|
|
36
|
+
const tags = [...scope.tags, ...(node.options.tags ?? [])];
|
|
37
|
+
const hidden = scope.hidden || node.options.hidden === true;
|
|
38
|
+
if (node.kind === 'group') {
|
|
39
|
+
const child = {
|
|
40
|
+
path,
|
|
41
|
+
paramLevels: levels,
|
|
42
|
+
middleware,
|
|
43
|
+
providers,
|
|
44
|
+
tags,
|
|
45
|
+
hidden,
|
|
46
|
+
};
|
|
47
|
+
for (const childNode of node.children) {
|
|
48
|
+
visit(childNode, child, out);
|
|
49
|
+
}
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const { options } = node;
|
|
53
|
+
const responses = responseSchemas(options.response);
|
|
54
|
+
out.push({
|
|
55
|
+
method: node.method,
|
|
56
|
+
path,
|
|
57
|
+
paramNames: parsePattern(path)
|
|
58
|
+
.filter((segment) => segment.kind !== 'static')
|
|
59
|
+
.map((segment) => segment.value),
|
|
60
|
+
paramLevels: levels,
|
|
61
|
+
query: options.query,
|
|
62
|
+
body: options.body,
|
|
63
|
+
responses,
|
|
64
|
+
middleware,
|
|
65
|
+
providers,
|
|
66
|
+
handler: options.handler,
|
|
67
|
+
docs: {
|
|
68
|
+
summary: options.summary,
|
|
69
|
+
description: options.description,
|
|
70
|
+
operationId: options.operationId,
|
|
71
|
+
deprecated: options.deprecated,
|
|
72
|
+
hidden,
|
|
73
|
+
tags: [...new Set(tags)],
|
|
74
|
+
secured: middleware.some((entry) => SECURED in entry),
|
|
75
|
+
},
|
|
76
|
+
serializers: serializersFor(responses),
|
|
77
|
+
websocket: options.websocket,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/** Serializers for response schemas that can be expressed as JSON Schema. */
|
|
81
|
+
function serializersFor(responses) {
|
|
82
|
+
const serializers = new Map();
|
|
83
|
+
for (const [status, schema] of responses) {
|
|
84
|
+
const json = jsonSchemaOf(schema, 'output');
|
|
85
|
+
if (json !== undefined) {
|
|
86
|
+
serializers.set(status, compileSerializer(json));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return serializers;
|
|
90
|
+
}
|
|
91
|
+
function responseSchemas(response) {
|
|
92
|
+
const result = new Map();
|
|
93
|
+
if (response === undefined) {
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
if (isSchema(response)) {
|
|
97
|
+
result.set(200, response);
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
for (const [status, schema] of Object.entries(response)) {
|
|
101
|
+
const code = Number(status);
|
|
102
|
+
if (!Number.isInteger(code) || code < 100 || code > 599) {
|
|
103
|
+
throw new Error(`Invalid response status "${status}".`);
|
|
104
|
+
}
|
|
105
|
+
result.set(code, schema);
|
|
106
|
+
}
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
export function isSchema(value) {
|
|
110
|
+
return (typeof value === 'object' &&
|
|
111
|
+
value !== null &&
|
|
112
|
+
'~standard' in value &&
|
|
113
|
+
typeof value['~standard'].validate === 'function');
|
|
114
|
+
}
|
|
115
|
+
/** Ensures a leading slash and no trailing slash (except for the root). */
|
|
116
|
+
export function normalizePath(path) {
|
|
117
|
+
const trimmed = path.replace(/\/+$/, '');
|
|
118
|
+
if (trimmed === '') {
|
|
119
|
+
return '/';
|
|
120
|
+
}
|
|
121
|
+
return trimmed.startsWith('/') ? trimmed : `/${trimmed}`;
|
|
122
|
+
}
|
|
123
|
+
export function joinPaths(base, path) {
|
|
124
|
+
const joined = `${normalizePath(base)}/${normalizePath(path)}`.replace(/\/{2,}/g, '/');
|
|
125
|
+
return normalizePath(joined);
|
|
126
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type Encoding = 'zstd' | 'br' | 'gzip';
|
|
2
|
+
export interface CompressionOptions {
|
|
3
|
+
/** Encodings to offer, most preferred first. Defaults to zstd, br, gzip. */
|
|
4
|
+
encodings?: readonly Encoding[];
|
|
5
|
+
/** Smallest body worth compressing, in bytes. Defaults to 1024. */
|
|
6
|
+
threshold?: number;
|
|
7
|
+
}
|
|
8
|
+
/** Negotiates and applies response compression. */
|
|
9
|
+
export declare class Compressor {
|
|
10
|
+
private readonly encodings;
|
|
11
|
+
private readonly threshold;
|
|
12
|
+
/** Compressed copies of byte bodies, such as static assets served from memory. */
|
|
13
|
+
private readonly cache;
|
|
14
|
+
constructor(options?: CompressionOptions);
|
|
15
|
+
/**
|
|
16
|
+
* Compresses `body` if the response and the client allow it, updating the
|
|
17
|
+
* headers. Returns the body to send.
|
|
18
|
+
*/
|
|
19
|
+
apply(acceptEncoding: string | undefined, headers: Record<string, string>, body: string | Uint8Array): Promise<string | Uint8Array>;
|
|
20
|
+
/** The most preferred encoding the client accepts (q > 0), if any. */
|
|
21
|
+
negotiate(acceptEncoding: string | undefined): Encoding | undefined;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=compression.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compression.d.ts","sourceRoot":"","sources":["../../src/lib/compression.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,IAAI,GAAG,MAAM,CAAC;AAE9C,MAAM,WAAW,kBAAkB;IACjC,4EAA4E;IAC5E,SAAS,CAAC,EAAE,SAAS,QAAQ,EAAE,CAAC;IAChC,mEAAmE;IACnE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAqBD,mDAAmD;AACnD,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAsB;IAChD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,kFAAkF;IAClF,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAoD;gBAE9D,OAAO,GAAE,kBAAuB;IAK5C;;;OAGG;IACG,KAAK,CACT,cAAc,EAAE,MAAM,GAAG,SAAS,EAClC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,IAAI,EAAE,MAAM,GAAG,UAAU,GACxB,OAAO,CAAC,MAAM,GAAG,UAAU,CAAC;IAyC/B,sEAAsE;IACtE,SAAS,CAAC,cAAc,EAAE,MAAM,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS;CAyBpE"}
|