@vltpkg/registry-client 0.0.0-0.1730724342581 → 0.0.0-3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/esm/add-header.d.ts +1 -1
- package/dist/esm/add-header.d.ts.map +1 -1
- package/dist/esm/add-header.js +4 -1
- package/dist/esm/add-header.js.map +1 -1
- package/dist/esm/auth.d.ts +9 -0
- package/dist/esm/auth.d.ts.map +1 -0
- package/dist/esm/auth.js +39 -0
- package/dist/esm/auth.js.map +1 -0
- package/dist/esm/cache-entry.d.ts +5 -5
- package/dist/esm/cache-entry.d.ts.map +1 -1
- package/dist/esm/cache-entry.js +3 -17
- package/dist/esm/cache-entry.js.map +1 -1
- package/dist/esm/delete-header.d.ts +2 -0
- package/dist/esm/delete-header.d.ts.map +1 -0
- package/dist/esm/delete-header.js +32 -0
- package/dist/esm/delete-header.js.map +1 -0
- package/dist/esm/env.d.ts +0 -4
- package/dist/esm/env.d.ts.map +1 -1
- package/dist/esm/env.js +0 -3
- package/dist/esm/env.js.map +1 -1
- package/dist/esm/handle-304-response.d.ts +2 -2
- package/dist/esm/handle-304-response.d.ts.map +1 -1
- package/dist/esm/handle-304-response.js.map +1 -1
- package/dist/esm/index.d.ts +67 -7
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +215 -57
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/is-iterable.d.ts +2 -0
- package/dist/esm/is-iterable.d.ts.map +1 -0
- package/dist/esm/is-iterable.js +2 -0
- package/dist/esm/is-iterable.js.map +1 -0
- package/dist/esm/otplease.d.ts +4 -0
- package/dist/esm/otplease.d.ts.map +1 -0
- package/dist/esm/otplease.js +55 -0
- package/dist/esm/otplease.js.map +1 -0
- package/dist/esm/raw-header.d.ts +1 -1
- package/dist/esm/raw-header.d.ts.map +1 -1
- package/dist/esm/redirect.d.ts +2 -2
- package/dist/esm/redirect.d.ts.map +1 -1
- package/dist/esm/redirect.js +1 -0
- package/dist/esm/redirect.js.map +1 -1
- package/dist/esm/set-cache-headers.d.ts +2 -2
- package/dist/esm/set-cache-headers.d.ts.map +1 -1
- package/dist/esm/set-cache-headers.js +1 -1
- package/dist/esm/set-cache-headers.js.map +1 -1
- package/dist/esm/token-response.d.ts +5 -0
- package/dist/esm/token-response.d.ts.map +1 -0
- package/dist/esm/token-response.js +5 -0
- package/dist/esm/token-response.js.map +1 -0
- package/dist/esm/web-auth-challenge.d.ts +6 -0
- package/dist/esm/web-auth-challenge.d.ts.map +1 -0
- package/dist/esm/web-auth-challenge.js +7 -0
- package/dist/esm/web-auth-challenge.js.map +1 -0
- package/package.json +28 -17
- package/dist/esm/serdes.d.ts +0 -15
- package/dist/esm/serdes.d.ts.map +0 -1
- package/dist/esm/serdes.js +0 -19
- package/dist/esm/serdes.js.map +0 -1
package/README.md
CHANGED
package/dist/esm/add-header.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const addHeader: <H extends [string, string[] | string][] | Iterable<[string, string[] | string | undefined]> | Record<string, string[] | string | undefined> | string[]>(headers: H | null | undefined, key: string, value
|
|
1
|
+
export declare const addHeader: <H extends [string, string[] | string][] | Iterable<[string, string[] | string | undefined]> | Record<string, string[] | string | undefined> | string[]>(headers: H | null | undefined, key: string, value?: string) => H;
|
|
2
2
|
//# sourceMappingURL=add-header.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add-header.d.ts","sourceRoot":"","sources":["../../src/add-header.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,SAAS,GACpB,CAAC,SACG,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,GAC7B,QAAQ,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,CAAC,CAAC,GACjD,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,CAAC,GAC7C,MAAM,EAAE,WAEH,CAAC,GAAG,IAAI,GAAG,SAAS,OACxB,MAAM,
|
|
1
|
+
{"version":3,"file":"add-header.d.ts","sourceRoot":"","sources":["../../src/add-header.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,SAAS,GACpB,CAAC,SACG,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,GAC7B,QAAQ,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,CAAC,CAAC,GACjD,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,CAAC,GAC7C,MAAM,EAAE,WAEH,CAAC,GAAG,IAAI,GAAG,SAAS,OACxB,MAAM,UACH,MAAM,KACb,CAkBF,CAAA"}
|
package/dist/esm/add-header.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import { deleteHeader } from "./delete-header.js";
|
|
2
|
+
import { isIterable } from "./is-iterable.js";
|
|
2
3
|
// this does some rude things with types, but not much way around it,
|
|
3
4
|
// since the opts.headers type is so loosey goosey to begin with.
|
|
4
5
|
export const addHeader = (headers, key, value) => {
|
|
6
|
+
if (!value)
|
|
7
|
+
return deleteHeader(headers, key);
|
|
5
8
|
if (!headers)
|
|
6
9
|
return { [key]: value };
|
|
7
10
|
if (Array.isArray(headers)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add-header.js","sourceRoot":"","sources":["../../src/add-header.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"add-header.js","sourceRoot":"","sources":["../../src/add-header.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,qEAAqE;AACrE,iEAAiE;AACjE,MAAM,CAAC,MAAM,SAAS,GAAG,CAOvB,OAA6B,EAC7B,GAAW,EACX,KAAc,EACX,EAAE;IACL,IAAI,CAAC,KAAK;QAAE,OAAO,YAAY,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;IAE7C,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAO,CAAA;IAC1C,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3B,IAAI,CAAC,OAAO,CAAC,MAAM;YAAE,OAAO,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAiB,CAAA;QAC1D,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YAC1B,OAA8B,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAA;;YAC9C,OAAoB,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;QAC3C,OAAO,OAAO,CAAA;IAChB,CAAC;SAAM,IACL,UAAU,CAA0C,OAAO,CAAC,EAC5D,CAAC;QACD,OAAO,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,CAAiB,CAAA;IACnD,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;QACpB,OAAO,OAAO,CAAA;IAChB,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { deleteHeader } from './delete-header.ts'\nimport { isIterable } from './is-iterable.ts'\n\n// this does some rude things with types, but not much way around it,\n// since the opts.headers type is so loosey goosey to begin with.\nexport const addHeader = <\n H extends\n | [string, string[] | string][]\n | Iterable<[string, string[] | string | undefined]>\n | Record<string, string[] | string | undefined>\n | string[],\n>(\n headers: H | null | undefined,\n key: string,\n value?: string,\n): H => {\n if (!value) return deleteHeader(headers, key)\n\n if (!headers) return { [key]: value } as H\n if (Array.isArray(headers)) {\n if (!headers.length) return [[key, value]] as unknown as H\n if (Array.isArray(headers[0]))\n (headers as [string, string][]).push([key, value])\n else (headers as string[]).push(key, value)\n return headers\n } else if (\n isIterable<[string, string[] | string | undefined]>(headers)\n ) {\n return [...headers, [key, value]] as unknown as H\n } else {\n headers[key] = value\n return headers\n }\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Keychain } from '@vltpkg/keychain';
|
|
2
|
+
export type Token = `Bearer ${string}` | `Basic ${string}`;
|
|
3
|
+
export declare const keychains: Map<string, Keychain<Token>>;
|
|
4
|
+
export declare const getKC: (identity: string) => Keychain<Token>;
|
|
5
|
+
export declare const isToken: (t: any) => t is Token;
|
|
6
|
+
export declare const deleteToken: (registry: string, identity: string) => Promise<void>;
|
|
7
|
+
export declare const setToken: (registry: string, token: Token, identity: string) => Promise<void>;
|
|
8
|
+
export declare const getToken: (registry: string, identity: string) => Promise<Token | undefined>;
|
|
9
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAE3C,MAAM,MAAM,KAAK,GAAG,UAAU,MAAM,EAAE,GAAG,SAAS,MAAM,EAAE,CAAA;AAG1D,eAAO,MAAM,SAAS,8BAAqC,CAAA;AAE3D,eAAO,MAAM,KAAK,aAAc,MAAM,oBAOrC,CAAA;AAED,eAAO,MAAM,OAAO,MAAO,GAAG,KAAG,CAAC,IAAI,KAEe,CAAA;AAErD,eAAO,MAAM,WAAW,aACZ,MAAM,YACN,MAAM,KACf,OAAO,CAAC,IAAI,CAKd,CAAA;AAED,eAAO,MAAM,QAAQ,aACT,MAAM,SACT,KAAK,YACF,MAAM,KACf,OAAO,CAAC,IAAI,CAGd,CAAA;AAED,eAAO,MAAM,QAAQ,aACT,MAAM,YACN,MAAM,KACf,OAAO,CAAC,KAAK,GAAG,SAAS,CAc3B,CAAA"}
|
package/dist/esm/auth.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Keychain } from '@vltpkg/keychain';
|
|
2
|
+
// just exported for testing
|
|
3
|
+
export const keychains = new Map();
|
|
4
|
+
export const getKC = (identity) => {
|
|
5
|
+
const kc = keychains.get(identity);
|
|
6
|
+
if (kc)
|
|
7
|
+
return kc;
|
|
8
|
+
const i = identity ? `vlt/auth/${identity}` : 'vlt/auth';
|
|
9
|
+
const nkc = new Keychain(i);
|
|
10
|
+
keychains.set(identity, nkc);
|
|
11
|
+
return nkc;
|
|
12
|
+
};
|
|
13
|
+
export const isToken = (t) => typeof t === 'string' &&
|
|
14
|
+
(t.startsWith('Bearer ') || t.startsWith('Basic '));
|
|
15
|
+
export const deleteToken = async (registry, identity) => {
|
|
16
|
+
const kc = getKC(identity);
|
|
17
|
+
await kc.load();
|
|
18
|
+
kc.delete(new URL(registry).origin);
|
|
19
|
+
await kc.save();
|
|
20
|
+
};
|
|
21
|
+
export const setToken = async (registry, token, identity) => {
|
|
22
|
+
const kc = getKC(identity);
|
|
23
|
+
return kc.set(new URL(registry).origin, token);
|
|
24
|
+
};
|
|
25
|
+
export const getToken = async (registry, identity) => {
|
|
26
|
+
const kc = getKC(identity);
|
|
27
|
+
registry = new URL(registry).origin;
|
|
28
|
+
const envReg = process.env.VLT_REGISTRY;
|
|
29
|
+
if (envReg && registry === new URL(envReg).origin) {
|
|
30
|
+
const envTok = process.env.VLT_TOKEN;
|
|
31
|
+
if (envTok)
|
|
32
|
+
return `Bearer ${envTok}`;
|
|
33
|
+
}
|
|
34
|
+
const tok = process.env[`VLT_TOKEN_${registry.replace(/[^a-zA-Z0-9]+/g, '_')}`];
|
|
35
|
+
if (tok)
|
|
36
|
+
return `Bearer ${tok}`;
|
|
37
|
+
return kc.get(registry);
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EA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,EAAE,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;AAChD,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,EAC3B,QAAgB,EAChB,QAAgB,EACY,EAAE;IAC9B,MAAM,EAAE,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAA;IAC1B,QAAQ,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAA;IACnC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,CAAA;IACvC,IAAI,MAAM,IAAI,QAAQ,KAAK,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC;QAClD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,CAAA;QACpC,IAAI,MAAM;YAAE,OAAO,UAAU,MAAM,EAAE,CAAA;IACvC,CAAC;IACD,MAAM,GAAG,GACP,OAAO,CAAC,GAAG,CACT,aAAa,QAAQ,CAAC,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC,EAAE,CACvD,CAAA;IACH,IAAI,GAAG;QAAE,OAAO,UAAU,GAAG,EAAE,CAAA;IAC/B,OAAO,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;AACzB,CAAC,CAAA","sourcesContent":["import { Keychain } from '@vltpkg/keychain'\n\nexport type Token = `Bearer ${string}` | `Basic ${string}`\n\n// just exported for testing\nexport const keychains = new Map<string, Keychain<Token>>()\n\nexport const getKC = (identity: string) => {\n const kc = keychains.get(identity)\n if (kc) return kc\n const i = identity ? `vlt/auth/${identity}` : 'vlt/auth'\n const nkc = new Keychain<Token>(i)\n keychains.set(identity, nkc)\n return nkc\n}\n\nexport const isToken = (t: any): t is Token =>\n typeof t === 'string' &&\n (t.startsWith('Bearer ') || t.startsWith('Basic '))\n\nexport const deleteToken = async (\n registry: string,\n identity: string,\n): Promise<void> => {\n const kc = getKC(identity)\n await kc.load()\n kc.delete(new URL(registry).origin)\n await kc.save()\n}\n\nexport const setToken = async (\n registry: string,\n token: Token,\n identity: string,\n): Promise<void> => {\n const kc = getKC(identity)\n return kc.set(new URL(registry).origin, token)\n}\n\nexport const getToken = async (\n registry: string,\n identity: string,\n): Promise<Token | undefined> => {\n const kc = getKC(identity)\n registry = new URL(registry).origin\n const envReg = process.env.VLT_REGISTRY\n if (envReg && registry === new URL(envReg).origin) {\n const envTok = process.env.VLT_TOKEN\n if (envTok) return `Bearer ${envTok}`\n }\n const tok =\n process.env[\n `VLT_TOKEN_${registry.replace(/[^a-zA-Z0-9]+/g, '_')}`\n ]\n if (tok) return `Bearer ${tok}`\n return kc.get(registry)\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
type JSONObj = Record<string, JSONField>;
|
|
1
|
+
import type { Integrity, JSONField } from '@vltpkg/types';
|
|
2
|
+
import type { InspectOptions } from 'util';
|
|
3
|
+
export type JSONObj = Record<string, JSONField>;
|
|
4
4
|
declare const kCustomInspect: unique symbol;
|
|
5
5
|
export declare class CacheEntry {
|
|
6
6
|
#private;
|
|
@@ -13,7 +13,7 @@ export declare class CacheEntry {
|
|
|
13
13
|
get valid(): boolean;
|
|
14
14
|
addBody(b: Buffer): void;
|
|
15
15
|
get statusCode(): number;
|
|
16
|
-
get headers(): Buffer[];
|
|
16
|
+
get headers(): Buffer<ArrayBufferLike>[];
|
|
17
17
|
/**
|
|
18
18
|
* check that the sri integrity string that was provided to the ctor
|
|
19
19
|
* matches the body that we actually received. This should only be called
|
|
@@ -29,7 +29,7 @@ export declare class CacheEntry {
|
|
|
29
29
|
/**
|
|
30
30
|
* Give it a key, and it'll return the buffer of that header value
|
|
31
31
|
*/
|
|
32
|
-
getHeader(h: string): Buffer | undefined;
|
|
32
|
+
getHeader(h: string): Buffer<ArrayBufferLike> | undefined;
|
|
33
33
|
/**
|
|
34
34
|
* Set a header to a specific value
|
|
35
35
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache-entry.d.ts","sourceRoot":"","sources":["../../src/cache-entry.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"cache-entry.d.ts","sourceRoot":"","sources":["../../src/cache-entry.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAIzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAA;AAI1C,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;AAyB/C,QAAA,MAAM,cAAc,eAA2C,CAAA;AAE/D,qBAAa,UAAU;;gBAUnB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EAAE,EACjB,SAAS,CAAC,EAAE,SAAS;IAiBvB,CAAC,cAAc,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,MAAM;IAehE;;;OAGG;IACH,IAAI,KAAK,IAAI,OAAO,CAsBnB;IAED,OAAO,CAAC,CAAC,EAAE,MAAM;IAKjB,IAAI,UAAU,WAEb;IACD,IAAI,OAAO,8BAEV;IAED;;;;;;;;OAQG;IACH,cAAc,IAAI,OAAO;IAIzB,IAAI,eAAe,IAAI,SAAS,CAM/B;IACD,IAAI,SAAS,mCAEZ;IAED;;OAEG;IACH,SAAS,CAAC,CAAC,EAAE,MAAM;IAInB;;OAEG;IACH,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;IAI3C;;OAEG;IACH,MAAM,IAAI,MAAM;IAWhB,IAAI,IAAI,IAAI,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAEvC;IAGD,IAAI,MAAM,IAAI,OAAO,CAYpB;IAGD,IAAI,MAAM,IAAI,OAAO,CAcpB;IAED;;;;OAIG;IACH,KAAK;IAmBL;;;OAGG;IACH,IAAI;IAKJ;;OAEG;IACH,IAAI,IAAI,OAAO;IAOf;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU;IAiCzC;;OAEG;IAGH,MAAM,IAAI,MAAM;CAoCjB"}
|
package/dist/esm/cache-entry.js
CHANGED
|
@@ -23,8 +23,7 @@ import ccp from 'cache-control-parser';
|
|
|
23
23
|
import { createHash } from 'crypto';
|
|
24
24
|
import { inspect } from 'util';
|
|
25
25
|
import { gunzipSync } from 'zlib';
|
|
26
|
-
import { getRawHeader, setRawHeader } from
|
|
27
|
-
import { deserialize, serialize, serializedHeader } from './serdes.js';
|
|
26
|
+
import { getRawHeader, setRawHeader } from "./raw-header.js";
|
|
28
27
|
const readSize = (buf, offset) => {
|
|
29
28
|
const a = buf[offset];
|
|
30
29
|
const b = buf[offset + 1];
|
|
@@ -173,13 +172,10 @@ export class CacheEntry {
|
|
|
173
172
|
get isJSON() {
|
|
174
173
|
if (this.#isJSON !== undefined)
|
|
175
174
|
return this.#isJSON;
|
|
176
|
-
const ser = serializedHeader && this.getHeader(serializedHeader);
|
|
177
|
-
if (ser)
|
|
178
|
-
return (this.#isJSON = true);
|
|
179
175
|
const ct = this.getHeader('content-type')?.toString();
|
|
180
176
|
// if it says it's json, assume json
|
|
181
177
|
if (ct)
|
|
182
|
-
return /\bjson\b/.test(ct);
|
|
178
|
+
return (this.#isJSON = /\bjson\b/.test(ct));
|
|
183
179
|
const text = this.text();
|
|
184
180
|
// don't cache, because we might just not have it yet.
|
|
185
181
|
if (!text)
|
|
@@ -247,18 +243,8 @@ export class CacheEntry {
|
|
|
247
243
|
json() {
|
|
248
244
|
if (this.#json !== undefined)
|
|
249
245
|
return this.#json;
|
|
250
|
-
const ser = serializedHeader && this.getHeader(serializedHeader);
|
|
251
|
-
if (ser) {
|
|
252
|
-
/* c8 ignore start - very rare, but theoretically possible to throw */
|
|
253
|
-
try {
|
|
254
|
-
return (this.#json = deserialize(ser));
|
|
255
|
-
}
|
|
256
|
-
catch { }
|
|
257
|
-
/* c8 ignore stop */
|
|
258
|
-
}
|
|
259
246
|
const obj = JSON.parse(this.text());
|
|
260
|
-
|
|
261
|
-
this.setHeader(serializedHeader, serialize(obj));
|
|
247
|
+
this.#json = obj;
|
|
262
248
|
return obj;
|
|
263
249
|
}
|
|
264
250
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache-entry.js","sourceRoot":"","sources":["../../src/cache-entry.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,EAAE;AACF,4EAA4E;AAC5E,yDAAyD;AACzD,EAAE;AACF,sBAAsB;AACtB,EAAE;AACF,gBAAgB;AAChB,yBAAyB;AACzB,YAAY;AACZ,SAAS;AACT,EAAE;AACF,0EAA0E;AAC1E,+CAA+C;AAC/C,EAAE;AACF,8EAA8E;AAC9E,4DAA4D;AAC5D,EAAE;AACF,2EAA2E;AAC3E,eAAe;AAEf,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAE3C,OAAO,GAAG,MAAM,sBAAsB,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACnC,OAAO,EAAE,OAAO,EAAuB,MAAM,MAAM,CAAA;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AACjC,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC5D,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAItE,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAE,MAAc,EAAE,EAAE;IAC/C,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,CAAA;IACrB,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IACzB,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,GAA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,CAAC,GAAG,IAAI;gBAChB,EAAE,GAAG,IAAI;aACV,EACD,CAAC,CACF,CAAA;YACD,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;QACvB,CAAC;QAED,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAA;QACnC,KAAK,CAAC,GAAG,CACP;YACE,CAAC,UAAU,IAAI,EAAE,CAAC,GAAG,IAAI;YACzB,CAAC,UAAU,IAAI,EAAE,CAAC,GAAG,IAAI;YACzB,CAAC,UAAU,IAAI,CAAC,CAAC,GAAG,IAAI;YACxB,UAAU,GAAG,IAAI;SAClB,EACD,CAAC,CACF,CAAA;QACD,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QACrB,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAA;QAC1B,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,CAAA;IAC7D,CAAC;CACF","sourcesContent":["// A response object in the cache.\n//\n// The cache stores Buffer objects, and it's convenient to have headers/body\n// together, so we have a simple data structure for this.\n//\n// The shape of it is:\n//\n// [head length]\n// <status code in ascii>\n// [headers]\n// [body]\n//\n// The [UInt32BE head length] is 4 bytes specifying the full length of the\n// status code plus all header keys and values.\n//\n// The [headers] section is key/value/key2/value2/... where each key and value\n// is a 4-byte Uint32BE length, followed by that many bytes.\n//\n// From there, the body can be of any indeterminate length, and is the rest\n// of the file.\n\nimport { error } from '@vltpkg/error-cause'\nimport { type Integrity, type JSONField } from '@vltpkg/types'\nimport ccp from 'cache-control-parser'\nimport { createHash } from 'crypto'\nimport { inspect, type InspectOptions } from 'util'\nimport { gunzipSync } from 'zlib'\nimport { getRawHeader, setRawHeader } from './raw-header.js'\nimport { deserialize, serialize, serializedHeader } from './serdes.js'\n\ntype JSONObj = Record<string, JSONField>\n\nconst readSize = (buf: Buffer, offset: number) => {\n const a = buf[offset]\n const b = buf[offset + 1]\n const c = buf[offset + 2]\n const d = buf[offset + 3]\n\n // not possible, we check the length\n /* c8 ignore start */\n if (\n a === undefined ||\n b === undefined ||\n c === undefined ||\n d === undefined\n ) {\n throw error('Invalid buffer, not long enough to readSize', {\n found: buf.length,\n })\n }\n /* c8 ignore stop */\n\n return (a << 24) | (b << 16) | (c << 8) | d\n}\n\nconst kCustomInspect = Symbol.for('nodejs.util.inspect.custom')\n\nexport class CacheEntry {\n #statusCode: number\n #headers: Buffer[]\n #body: Buffer[] = []\n #bodyLength = 0\n #integrity?: Integrity\n #integrityActual?: Integrity\n #json?: JSONObj\n\n constructor(\n statusCode: number,\n headers: Buffer[],\n integrity?: Integrity,\n ) {\n this.#integrity = integrity\n this.#statusCode = statusCode\n this.#headers = headers\n }\n\n get #headersAsObject(): [string, string][] {\n const ret: [string, string][] = []\n for (let i = 0; i < this.#headers.length - 1; i += 2) {\n const key = String(this.#headers[i])\n const val = String(this.#headers[i + 1])\n ret.push([key, val])\n }\n return ret\n }\n\n [kCustomInspect](depth: number, options: InspectOptions): string {\n const str = inspect(\n {\n statusCode: this.statusCode,\n headers: this.#headersAsObject,\n text: this.text(),\n },\n {\n depth,\n ...options,\n },\n )\n return `@vltpkg/registry-client.CacheEntry ${str}`\n }\n\n /**\n * `true` if the entry represents a cached response that is still\n * valid to use.\n */\n get valid(): boolean {\n const cc_ = this.getHeader('cache-control')?.toString()\n const cc = cc_ ? ccp.parse(cc_) : {}\n const ct = this.getHeader('content-type')?.toString() ?? ''\n const dh = this.getHeader('date')?.toString()\n\n // immutable = never changes\n if (cc.immutable) return true\n\n // some registries do text/json, some do application/json,\n // some do application/vnd.npm.install-v1+json\n // If it's NOT json, it's an immutable tarball\n if (ct !== '' && !/\\bjson\\b/.test(ct)) return true\n\n // see if the max-age has not yet been crossed\n // default to 5m if maxage is not set, as some registries\n // do not set a cache control header at all.\n const ma = cc['max-age'] || cc['s-maxage'] || 300\n if (ma && dh) {\n return Date.parse(dh) + ma * 1000 > Date.now()\n }\n return false\n }\n\n addBody(b: Buffer) {\n this.#body.push(b)\n this.#bodyLength += b.byteLength\n }\n\n get statusCode() {\n return this.#statusCode\n }\n get headers() {\n return this.#headers\n }\n\n /**\n * check that the sri integrity string that was provided to the ctor\n * matches the body that we actually received. This should only be called\n * AFTER the entire body has been completely downloaded.\n *\n * Note that this will *usually* not be true if the value is coming out of\n * the cache, because the cache entries are un-gzipped in place. It should\n * _only_ be called for artifacts that come from an actual http response.\n */\n checkIntegrity(): boolean {\n if (!this.#integrity) return false\n return this.integrityActual === this.#integrity\n }\n get integrityActual(): Integrity {\n if (this.#integrityActual) return this.#integrityActual\n const hash = createHash('sha512')\n for (const buf of this.#body) hash.update(buf)\n this.#integrityActual = `sha512-${hash.digest('base64')}`\n return this.#integrityActual\n }\n get integrity() {\n return this.#integrity\n }\n\n /**\n * Give it a key, and it'll return the buffer of that header value\n */\n getHeader(h: string) {\n return getRawHeader(this.#headers, h)\n }\n\n /**\n * Set a header to a specific value\n */\n setHeader(h: string, value: Buffer | string) {\n this.#headers = setRawHeader(this.#headers, h, value)\n }\n\n /**\n * Return the body of the entry as a Buffer\n */\n buffer(): Buffer {\n const b = this.#body[0]\n if (!b) return Buffer.allocUnsafe(0)\n if (this.#body.length === 1) return b\n const cat = Buffer.concat(this.#body, this.#bodyLength)\n this.#body = [cat]\n return cat\n }\n\n // return the buffer if it's a tarball, or the parsed\n // JSON if it's not.\n get body(): Buffer | Record<string, any> {\n return this.isJSON ? this.json() : this.buffer()\n }\n\n #isJSON?: boolean\n get isJSON(): boolean {\n if (this.#isJSON !== undefined) return this.#isJSON\n const ser = serializedHeader && this.getHeader(serializedHeader)\n if (ser) return (this.#isJSON = true)\n const ct = this.getHeader('content-type')?.toString()\n // if it says it's json, assume json\n if (ct) return /\\bjson\\b/.test(ct)\n const text = this.text()\n // don't cache, because we might just not have it yet.\n if (!text) return false\n // all registry json starts with {, and no tarball ever can.\n this.#isJSON = text.startsWith('{')\n if (this.#isJSON) this.setHeader('content-type', 'text/json')\n return this.#isJSON\n }\n\n #isGzip?: boolean\n get isGzip(): boolean {\n if (this.#isGzip !== undefined) return this.#isGzip\n const ce = this.getHeader('content-encoding')?.toString()\n if (ce && !/\\bgzip\\b/.test(ce)) return (this.#isGzip = false)\n const buf = this.buffer()\n if (buf.length < 2) return false\n this.#isGzip = buf[0] === 0x1f && buf[1] === 0x8b\n if (this.#isGzip) {\n this.setHeader('content-encoding', 'gzip')\n } else {\n this.setHeader('content-encoding', 'identity')\n this.setHeader('content-length', String(this.#bodyLength))\n }\n return this.#isGzip\n }\n\n /**\n * Un-gzip encode the body.\n * Returns true if it was previously gzip (so something was done), otherwise\n * returns false.\n */\n unzip() {\n if (this.isGzip) {\n // we know that if we know it's gzip, that the body has been\n // flattened to a single buffer, so save the extra call.\n /* c8 ignore start */\n if (this.#body[0] == null)\n throw error('Invalid buffer, cant unzip')\n /* c8 ignore stop */\n const b = gunzipSync(this.#body[0])\n this.setHeader('content-encoding', 'identity')\n this.#body = [b]\n this.#bodyLength = b.byteLength\n this.setHeader('content-length', String(this.#bodyLength))\n this.#isGzip = false\n return true\n }\n return false\n }\n\n /**\n * Return the body of the entry as utf8 text\n * Automatically unzips if the content is gzip encoded\n */\n text() {\n this.unzip()\n return this.buffer().toString()\n }\n\n /**\n * Parse the entry body as JSON and return the result\n */\n json(): JSONObj {\n if (this.#json !== undefined) return this.#json\n const ser = serializedHeader && this.getHeader(serializedHeader)\n if (ser) {\n /* c8 ignore start - very rare, but theoretically possible to throw */\n try {\n return (this.#json = deserialize(ser) as JSONObj)\n } catch {}\n /* c8 ignore stop */\n }\n const obj = JSON.parse(this.text()) as JSONObj\n if (serializedHeader)\n this.setHeader(serializedHeader, serialize(obj))\n return obj\n }\n\n /**\n * Pass the contents of a @vltpkg/cache.Cache object as a buffer,\n * and this static method will decode it into a CacheEntry representing\n * the cached response.\n */\n static decode(buffer: Buffer): CacheEntry {\n if (buffer.length < 4) {\n return new CacheEntry(0, [])\n }\n const headSize = readSize(buffer, 0)\n if (buffer.length < headSize) {\n return new CacheEntry(0, [])\n }\n const statusCode = Number(buffer.subarray(4, 7).toString())\n const headersBuffer = buffer.subarray(7, headSize)\n // walk through the headers array, building up the rawHeaders Buffer[]\n const headers: Buffer[] = []\n let i = 0\n while (i < headersBuffer.length - 4) {\n const size = readSize(headersBuffer, i)\n headers.push(headersBuffer.subarray(i + 4, i + size))\n i += size\n }\n const c = new CacheEntry(statusCode, headers)\n const body = buffer.subarray(headSize)\n c.#body = [body]\n c.#bodyLength = body.byteLength\n c.setHeader('content-length', String(c.#bodyLength))\n if (c.isJSON) {\n try {\n c.json()\n } catch {\n return new CacheEntry(0, [])\n }\n }\n return c\n }\n\n /**\n * Encode the entry as a single Buffer for writing to the cache\n */\n // TODO: should this maybe not concat, and just return Buffer[]?\n // Then we can writev it to the cache file and save the memory copy\n encode(): Buffer {\n // store json results as a serialized object.\n if (this.isJSON) this.json()\n const sb = Buffer.from(String(this.#statusCode))\n const chunks: Buffer[] = [sb]\n let headLength = sb.byteLength + 4\n for (const h of this.#headers) {\n const hlBuf = Buffer.allocUnsafe(4)\n const hl = h.byteLength + 4\n headLength += hl\n hlBuf.set(\n [\n (hl >> 24) & 0xff,\n (hl >> 16) & 0xff,\n (hl >> 8) & 0xff,\n hl & 0xff,\n ],\n 0,\n )\n chunks.push(hlBuf, h)\n }\n\n const hlBuf = Buffer.allocUnsafe(4)\n hlBuf.set(\n [\n (headLength >> 24) & 0xff,\n (headLength >> 16) & 0xff,\n (headLength >> 8) & 0xff,\n headLength & 0xff,\n ],\n 0,\n )\n chunks.unshift(hlBuf)\n chunks.push(...this.#body)\n return Buffer.concat(chunks, headLength + this.#bodyLength)\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"cache-entry.js","sourceRoot":"","sources":["../../src/cache-entry.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,EAAE;AACF,4EAA4E;AAC5E,yDAAyD;AACzD,EAAE;A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CAAA;YACnC,MAAM,EAAE,GAAG,CAAC,CAAC,UAAU,GAAG,CAAC,CAAA;YAC3B,UAAU,IAAI,EAAE,CAAA;YAChB,KAAK,CAAC,GAAG,CACP;gBACE,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI;gBACjB,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI;gBACjB,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,IAAI;gBAChB,EAAE,GAAG,IAAI;aACV,EACD,CAAC,CACF,CAAA;YACD,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;QACvB,CAAC;QAED,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAA;QACnC,KAAK,CAAC,GAAG,CACP;YACE,CAAC,UAAU,IAAI,EAAE,CAAC,GAAG,IAAI;YACzB,CAAC,UAAU,IAAI,EAAE,CAAC,GAAG,IAAI;YACzB,CAAC,UAAU,IAAI,CAAC,CAAC,GAAG,IAAI;YACxB,UAAU,GAAG,IAAI;SAClB,EACD,CAAC,CACF,CAAA;QACD,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QACrB,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAA;QAC1B,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,CAAA;IAC7D,CAAC;CACF","sourcesContent":["// A response object in the cache.\n//\n// The cache stores Buffer objects, and it's convenient to have headers/body\n// together, so we have a simple data structure for this.\n//\n// The shape of it is:\n//\n// [head length]\n// <status code in ascii>\n// [headers]\n// [body]\n//\n// The [UInt32BE head length] is 4 bytes specifying the full length of the\n// status code plus all header keys and values.\n//\n// The [headers] section is key/value/key2/value2/... where each key and value\n// is a 4-byte Uint32BE length, followed by that many bytes.\n//\n// From there, the body can be of any indeterminate length, and is the rest\n// of the file.\n\nimport { error } from '@vltpkg/error-cause'\nimport type { Integrity, JSONField } from '@vltpkg/types'\nimport ccp from 'cache-control-parser'\nimport { createHash } from 'crypto'\nimport { inspect } from 'util'\nimport type { InspectOptions } from 'util'\nimport { gunzipSync } from 'zlib'\nimport { getRawHeader, setRawHeader } from './raw-header.ts'\n\nexport type JSONObj = Record<string, JSONField>\n\nconst readSize = (buf: Buffer, offset: number) => {\n const a = buf[offset]\n const b = buf[offset + 1]\n const c = buf[offset + 2]\n const d = buf[offset + 3]\n\n // not possible, we check the length\n /* c8 ignore start */\n if (\n a === undefined ||\n b === undefined ||\n c === undefined ||\n d === undefined\n ) {\n throw error('Invalid buffer, not long enough to readSize', {\n found: buf.length,\n })\n }\n /* c8 ignore stop */\n\n return (a << 24) | (b << 16) | (c << 8) | d\n}\n\nconst kCustomInspect = Symbol.for('nodejs.util.inspect.custom')\n\nexport class CacheEntry {\n #statusCode: number\n #headers: Buffer[]\n #body: Buffer[] = []\n #bodyLength = 0\n #integrity?: Integrity\n #integrityActual?: Integrity\n #json?: JSONObj\n\n constructor(\n statusCode: number,\n headers: Buffer[],\n integrity?: Integrity,\n ) {\n this.#integrity = integrity\n this.#statusCode = statusCode\n this.#headers = headers\n }\n\n get #headersAsObject(): [string, string][] {\n const ret: [string, string][] = []\n for (let i = 0; i < this.#headers.length - 1; i += 2) {\n const key = String(this.#headers[i])\n const val = String(this.#headers[i + 1])\n ret.push([key, val])\n }\n return ret\n }\n\n [kCustomInspect](depth: number, options: InspectOptions): string {\n const str = inspect(\n {\n statusCode: this.statusCode,\n headers: this.#headersAsObject,\n text: this.text(),\n },\n {\n depth,\n ...options,\n },\n )\n return `@vltpkg/registry-client.CacheEntry ${str}`\n }\n\n /**\n * `true` if the entry represents a cached response that is still\n * valid to use.\n */\n get valid(): boolean {\n const cc_ = this.getHeader('cache-control')?.toString()\n const cc = cc_ ? ccp.parse(cc_) : {}\n const ct = this.getHeader('content-type')?.toString() ?? ''\n const dh = this.getHeader('date')?.toString()\n\n // immutable = never changes\n if (cc.immutable) return true\n\n // some registries do text/json, some do application/json,\n // some do application/vnd.npm.install-v1+json\n // If it's NOT json, it's an immutable tarball\n if (ct !== '' && !/\\bjson\\b/.test(ct)) return true\n\n // see if the max-age has not yet been crossed\n // default to 5m if maxage is not set, as some registries\n // do not set a cache control header at all.\n const ma = cc['max-age'] || cc['s-maxage'] || 300\n if (ma && dh) {\n return Date.parse(dh) + ma * 1000 > Date.now()\n }\n return false\n }\n\n addBody(b: Buffer) {\n this.#body.push(b)\n this.#bodyLength += b.byteLength\n }\n\n get statusCode() {\n return this.#statusCode\n }\n get headers() {\n return this.#headers\n }\n\n /**\n * check that the sri integrity string that was provided to the ctor\n * matches the body that we actually received. This should only be called\n * AFTER the entire body has been completely downloaded.\n *\n * Note that this will *usually* not be true if the value is coming out of\n * the cache, because the cache entries are un-gzipped in place. It should\n * _only_ be called for artifacts that come from an actual http response.\n */\n checkIntegrity(): boolean {\n if (!this.#integrity) return false\n return this.integrityActual === this.#integrity\n }\n get integrityActual(): Integrity {\n if (this.#integrityActual) return this.#integrityActual\n const hash = createHash('sha512')\n for (const buf of this.#body) hash.update(buf)\n this.#integrityActual = `sha512-${hash.digest('base64')}`\n return this.#integrityActual\n }\n get integrity() {\n return this.#integrity\n }\n\n /**\n * Give it a key, and it'll return the buffer of that header value\n */\n getHeader(h: string) {\n return getRawHeader(this.#headers, h)\n }\n\n /**\n * Set a header to a specific value\n */\n setHeader(h: string, value: Buffer | string) {\n this.#headers = setRawHeader(this.#headers, h, value)\n }\n\n /**\n * Return the body of the entry as a Buffer\n */\n buffer(): Buffer {\n const b = this.#body[0]\n if (!b) return Buffer.allocUnsafe(0)\n if (this.#body.length === 1) return b\n const cat = Buffer.concat(this.#body, this.#bodyLength)\n this.#body = [cat]\n return cat\n }\n\n // return the buffer if it's a tarball, or the parsed\n // JSON if it's not.\n get body(): Buffer | Record<string, any> {\n return this.isJSON ? this.json() : this.buffer()\n }\n\n #isJSON?: boolean\n get isJSON(): boolean {\n if (this.#isJSON !== undefined) return this.#isJSON\n const ct = this.getHeader('content-type')?.toString()\n // if it says it's json, assume json\n if (ct) return (this.#isJSON = /\\bjson\\b/.test(ct))\n const text = this.text()\n // don't cache, because we might just not have it yet.\n if (!text) return false\n // all registry json starts with {, and no tarball ever can.\n this.#isJSON = text.startsWith('{')\n if (this.#isJSON) this.setHeader('content-type', 'text/json')\n return this.#isJSON\n }\n\n #isGzip?: boolean\n get isGzip(): boolean {\n if (this.#isGzip !== undefined) return this.#isGzip\n const ce = this.getHeader('content-encoding')?.toString()\n if (ce && !/\\bgzip\\b/.test(ce)) return (this.#isGzip = false)\n const buf = this.buffer()\n if (buf.length < 2) return false\n this.#isGzip = buf[0] === 0x1f && buf[1] === 0x8b\n if (this.#isGzip) {\n this.setHeader('content-encoding', 'gzip')\n } else {\n this.setHeader('content-encoding', 'identity')\n this.setHeader('content-length', String(this.#bodyLength))\n }\n return this.#isGzip\n }\n\n /**\n * Un-gzip encode the body.\n * Returns true if it was previously gzip (so something was done), otherwise\n * returns false.\n */\n unzip() {\n if (this.isGzip) {\n // we know that if we know it's gzip, that the body has been\n // flattened to a single buffer, so save the extra call.\n /* c8 ignore start */\n if (this.#body[0] == null)\n throw error('Invalid buffer, cant unzip')\n /* c8 ignore stop */\n const b = gunzipSync(this.#body[0])\n this.setHeader('content-encoding', 'identity')\n this.#body = [b]\n this.#bodyLength = b.byteLength\n this.setHeader('content-length', String(this.#bodyLength))\n this.#isGzip = false\n return true\n }\n return false\n }\n\n /**\n * Return the body of the entry as utf8 text\n * Automatically unzips if the content is gzip encoded\n */\n text() {\n this.unzip()\n return this.buffer().toString()\n }\n\n /**\n * Parse the entry body as JSON and return the result\n */\n json(): JSONObj {\n if (this.#json !== undefined) return this.#json\n const obj = JSON.parse(this.text()) as JSONObj\n this.#json = obj\n return obj\n }\n\n /**\n * Pass the contents of a @vltpkg/cache.Cache object as a buffer,\n * and this static method will decode it into a CacheEntry representing\n * the cached response.\n */\n static decode(buffer: Buffer): CacheEntry {\n if (buffer.length < 4) {\n return new CacheEntry(0, [])\n }\n const headSize = readSize(buffer, 0)\n if (buffer.length < headSize) {\n return new CacheEntry(0, [])\n }\n const statusCode = Number(buffer.subarray(4, 7).toString())\n const headersBuffer = buffer.subarray(7, headSize)\n // walk through the headers array, building up the rawHeaders Buffer[]\n const headers: Buffer[] = []\n let i = 0\n while (i < headersBuffer.length - 4) {\n const size = readSize(headersBuffer, i)\n headers.push(headersBuffer.subarray(i + 4, i + size))\n i += size\n }\n const c = new CacheEntry(statusCode, headers)\n const body = buffer.subarray(headSize)\n c.#body = [body]\n c.#bodyLength = body.byteLength\n c.setHeader('content-length', String(c.#bodyLength))\n if (c.isJSON) {\n try {\n c.json()\n } catch {\n return new CacheEntry(0, [])\n }\n }\n return c\n }\n\n /**\n * Encode the entry as a single Buffer for writing to the cache\n */\n // TODO: should this maybe not concat, and just return Buffer[]?\n // Then we can writev it to the cache file and save the memory copy\n encode(): Buffer {\n // store json results as a serialized object.\n if (this.isJSON) this.json()\n const sb = Buffer.from(String(this.#statusCode))\n const chunks: Buffer[] = [sb]\n let headLength = sb.byteLength + 4\n for (const h of this.#headers) {\n const hlBuf = Buffer.allocUnsafe(4)\n const hl = h.byteLength + 4\n headLength += hl\n hlBuf.set(\n [\n (hl >> 24) & 0xff,\n (hl >> 16) & 0xff,\n (hl >> 8) & 0xff,\n hl & 0xff,\n ],\n 0,\n )\n chunks.push(hlBuf, h)\n }\n\n const hlBuf = Buffer.allocUnsafe(4)\n hlBuf.set(\n [\n (headLength >> 24) & 0xff,\n (headLength >> 16) & 0xff,\n (headLength >> 8) & 0xff,\n headLength & 0xff,\n ],\n 0,\n )\n chunks.unshift(hlBuf)\n chunks.push(...this.#body)\n return Buffer.concat(chunks, headLength + this.#bodyLength)\n }\n}\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const deleteHeader: <H extends [string, string[] | string][] | Iterable<[string, string[] | string | undefined]> | Record<string, string[] | string | undefined> | string[]>(headers: H | null | undefined, key: string) => H;
|
|
2
|
+
//# sourceMappingURL=delete-header.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-header.d.ts","sourceRoot":"","sources":["../../src/delete-header.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,YAAY,GACvB,CAAC,SACG,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,GAC7B,QAAQ,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,CAAC,CAAC,GACjD,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,CAAC,GAC7C,MAAM,EAAE,WAEH,CAAC,GAAG,IAAI,GAAG,SAAS,OACxB,MAAM,KACV,CA2BF,CAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { isIterable } from "./is-iterable.js";
|
|
2
|
+
export const deleteHeader = (headers, key) => {
|
|
3
|
+
if (!headers)
|
|
4
|
+
return {};
|
|
5
|
+
if (Array.isArray(headers)) {
|
|
6
|
+
if (!headers.length)
|
|
7
|
+
return headers;
|
|
8
|
+
if (Array.isArray(headers[0])) {
|
|
9
|
+
const index = headers.findIndex(([k]) => k.toLowerCase() === key.toLowerCase());
|
|
10
|
+
if (index !== -1)
|
|
11
|
+
headers.splice(index, 1);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
const h = headers;
|
|
15
|
+
for (let i = 0; i < h.length; i += 2) {
|
|
16
|
+
if (h[i]?.toLowerCase() === key.toLowerCase()) {
|
|
17
|
+
headers.splice(i, 2);
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return headers;
|
|
23
|
+
}
|
|
24
|
+
else if (isIterable(headers)) {
|
|
25
|
+
return deleteHeader([...headers], key);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
delete headers[key];
|
|
29
|
+
return headers;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=delete-header.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-header.js","sourceRoot":"","sources":["../../src/delete-header.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,MAAM,CAAC,MAAM,YAAY,GAAG,CAO1B,OAA6B,EAC7B,GAAW,EACR,EAAE;IACL,IAAI,CAAC,OAAO;QAAE,OAAO,EAAO,CAAA;IAC5B,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3B,IAAI,CAAC,OAAO,CAAC,MAAM;YAAE,OAAO,OAAO,CAAA;QACnC,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAC9B,MAAM,KAAK,GAAI,OAA8B,CAAC,SAAS,CACrD,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,KAAK,GAAG,CAAC,WAAW,EAAE,CAC/C,CAAA;YACD,IAAI,KAAK,KAAK,CAAC,CAAC;gBAAE,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;QAC5C,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,GAAG,OAAmB,CAAA;YAC7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;gBACrC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,KAAK,GAAG,CAAC,WAAW,EAAE,EAAE,CAAC;oBAC9C,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;oBACpB,MAAK;gBACP,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,OAAO,CAAA;IAChB,CAAC;SAAM,IACL,UAAU,CAA0C,OAAO,CAAC,EAC5D,CAAC;QACD,OAAO,YAAY,CAAC,CAAC,GAAG,OAAO,CAAiB,EAAE,GAAG,CAAC,CAAA;IACxD,CAAC;SAAM,CAAC;QACN,OAAO,OAAO,CAAC,GAAG,CAAC,CAAA;QACnB,OAAO,OAAO,CAAA;IAChB,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { isIterable } from './is-iterable.ts'\n\nexport const deleteHeader = <\n H extends\n | [string, string[] | string][]\n | Iterable<[string, string[] | string | undefined]>\n | Record<string, string[] | string | undefined>\n | string[],\n>(\n headers: H | null | undefined,\n key: string,\n): H => {\n if (!headers) return {} as H\n if (Array.isArray(headers)) {\n if (!headers.length) return headers\n if (Array.isArray(headers[0])) {\n const index = (headers as [string, string][]).findIndex(\n ([k]) => k.toLowerCase() === key.toLowerCase(),\n )\n if (index !== -1) headers.splice(index, 1)\n } else {\n const h = headers as string[]\n for (let i = 0; i < h.length; i += 2) {\n if (h[i]?.toLowerCase() === key.toLowerCase()) {\n headers.splice(i, 2)\n break\n }\n }\n }\n return headers\n } else if (\n isIterable<[string, string[] | string | undefined]>(headers)\n ) {\n return deleteHeader([...headers] as unknown as H, key)\n } else {\n delete headers[key]\n return headers\n }\n}\n"]}
|
package/dist/esm/env.d.ts
CHANGED
|
@@ -4,8 +4,4 @@ export declare const isNode: boolean;
|
|
|
4
4
|
export declare const bun: string | undefined;
|
|
5
5
|
export declare const deno: string | undefined;
|
|
6
6
|
export declare const node: string | undefined;
|
|
7
|
-
export declare const engine: {
|
|
8
|
-
name: string;
|
|
9
|
-
version: string;
|
|
10
|
-
} | undefined;
|
|
11
7
|
//# sourceMappingURL=env.d.ts.map
|
package/dist/esm/env.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/env.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,MAAM,SAAc,CAAA;AACjC,eAAO,MAAM,KAAK,SAAwB,CAAA;AAG1C,eAAO,MAAM,MAAM,SAA+C,CAAA;AAGlE,eAAO,MAAM,GAAG,oBAAwC,CAAA;AACxD,eAAO,MAAM,IAAI,oBAA0C,CAAA;AAC3D,eAAO,MAAM,IAAI,oBAA0C,CAAA
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/env.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,MAAM,SAAc,CAAA;AACjC,eAAO,MAAM,KAAK,SAAwB,CAAA;AAG1C,eAAO,MAAM,MAAM,SAA+C,CAAA;AAGlE,eAAO,MAAM,GAAG,oBAAwC,CAAA;AACxD,eAAO,MAAM,IAAI,oBAA0C,CAAA;AAC3D,eAAO,MAAM,IAAI,oBAA0C,CAAA"}
|
package/dist/esm/env.js
CHANGED
|
@@ -10,7 +10,4 @@ export const isNode = !isDeno && !isBun && 'node' in proc.versions;
|
|
|
10
10
|
export const bun = isBun ? proc.versions.bun : undefined;
|
|
11
11
|
export const deno = isDeno ? proc.versions.deno : undefined;
|
|
12
12
|
export const node = isNode ? proc.versions.node : undefined;
|
|
13
|
-
export const engine = isNode || isDeno ? { name: 'v8', version: proc.versions.v8 }
|
|
14
|
-
: isBun && bun ? { name: 'bun', version: bun }
|
|
15
|
-
: undefined;
|
|
16
13
|
//# sourceMappingURL=env.js.map
|
package/dist/esm/env.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.js","sourceRoot":"","sources":["../../src/env.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,cAAc,CAAA;AAE/B,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,UAGrB,CAAA;AAED,MAAM,KAAK,GAAG,CAAC,CAAU,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,CAAC,CAAA;AAE1D,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,CAAA;AACjC,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,MAA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G,CAAC,CAAC,CAAC,SAAS,CAAA;AACxD,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAA;AAC3D,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAA","sourcesContent":["import proc from 'node:process'\n\nconst { Deno, Bun } = globalThis as typeof globalThis & {\n Deno: undefined | object\n Bun: undefined | object\n}\n\nconst isObj = (v: unknown) => typeof v === 'object' && !!v\n\nexport const isDeno = isObj(Deno)\nexport const isBun = !isDeno && isObj(Bun)\n// bun and deno also report 'node' in process.versions so its only\n// node if it is not bun or deno\nexport const isNode = !isDeno && !isBun && 'node' in proc.versions\n\n// All the runtimes put their versions into process.versions\nexport const bun = isBun ? proc.versions.bun : undefined\nexport const deno = isDeno ? proc.versions.deno : undefined\nexport const node = isNode ? proc.versions.node : undefined\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { Dispatcher } from 'undici';
|
|
2
|
+
import type { CacheEntry } from './cache-entry.ts';
|
|
3
3
|
export declare const handle304Response: (resp: Dispatcher.ResponseData, entry?: CacheEntry) => entry is CacheEntry;
|
|
4
4
|
//# sourceMappingURL=handle-304-response.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handle-304-response.d.ts","sourceRoot":"","sources":["../../src/handle-304-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"handle-304-response.d.ts","sourceRoot":"","sources":["../../src/handle-304-response.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACxC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAElD,eAAO,MAAM,iBAAiB,SACtB,UAAU,CAAC,YAAY,UACrB,UAAU,KACjB,KAAK,IAAI,UASX,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handle-304-response.js","sourceRoot":"","sources":["../../src/handle-304-response.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,IAA6B,EAC7B,KAAkB,EACG,EAAE;IACvB,IAAI,IAAI,CAAC,UAAU,KAAK,GAAG,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAA;IAEnD,MAAM,CAAC,GACL,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;IAC7D,KAAK,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;IACvC,2CAA2C;IAC3C,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAA;IAClB,OAAO,IAAI,CAAA;AACb,CAAC,CAAA","sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"handle-304-response.js","sourceRoot":"","sources":["../../src/handle-304-response.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,IAA6B,EAC7B,KAAkB,EACG,EAAE;IACvB,IAAI,IAAI,CAAC,UAAU,KAAK,GAAG,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAA;IAEnD,MAAM,CAAC,GACL,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;IAC7D,KAAK,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;IACvC,2CAA2C;IAC3C,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAA;IAClB,OAAO,IAAI,CAAA;AACb,CAAC,CAAA","sourcesContent":["import type { Dispatcher } from 'undici'\nimport type { CacheEntry } from './cache-entry.ts'\n\nexport const handle304Response = (\n resp: Dispatcher.ResponseData,\n entry?: CacheEntry,\n): entry is CacheEntry => {\n if (resp.statusCode !== 304 || !entry) return false\n\n const d =\n String(resp.headers.date ?? '') || new Date().toUTCString()\n entry.setHeader('date', Buffer.from(d))\n // shouldn't have a body, but just in case.\n resp.body.resume()\n return true\n}\n"]}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,16 +1,36 @@
|
|
|
1
1
|
import { Cache } from '@vltpkg/cache';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
2
|
+
import type { Integrity } from '@vltpkg/types';
|
|
3
|
+
import { RetryAgent } from 'undici';
|
|
4
|
+
import type { Dispatcher } from 'undici';
|
|
5
|
+
import { deleteToken, getKC, isToken, keychains, setToken } from './auth.ts';
|
|
6
|
+
import type { Token } from './auth.ts';
|
|
7
|
+
import { CacheEntry } from './cache-entry.ts';
|
|
8
|
+
import type { JSONObj } from './cache-entry.ts';
|
|
9
|
+
import type { TokenResponse } from './token-response.ts';
|
|
10
|
+
import type { WebAuthChallenge } from './web-auth-challenge.ts';
|
|
11
|
+
export { type JSONObj, type CacheEntry, type Token, type WebAuthChallenge, type TokenResponse, };
|
|
12
|
+
export { keychains, getKC, setToken, deleteToken, isToken };
|
|
6
13
|
export type RegistryClientOptions = {
|
|
7
14
|
/**
|
|
8
15
|
* Path on disk where the cache should be stored
|
|
9
16
|
* @default `$HOME/.config/vlt/cache`
|
|
10
17
|
*/
|
|
11
18
|
cache?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Number of retries to perform when encountering network errors or
|
|
21
|
+
* likely-transient errors from git hosts.
|
|
22
|
+
*/
|
|
23
|
+
'fetch-retries'?: number;
|
|
24
|
+
/** The exponential backoff factor to use when retrying git hosts */
|
|
25
|
+
'fetch-retry-factor'?: number;
|
|
26
|
+
/** Number of milliseconds before starting first retry */
|
|
27
|
+
'fetch-retry-mintimeout'?: number;
|
|
28
|
+
/** Maximum number of milliseconds between two retries */
|
|
29
|
+
'fetch-retry-maxtimeout'?: number;
|
|
30
|
+
/** the identity to use for storing auth tokens */
|
|
31
|
+
identity?: string;
|
|
12
32
|
};
|
|
13
|
-
export type RegistryClientRequestOptions = Omit<Dispatcher.
|
|
33
|
+
export type RegistryClientRequestOptions = Omit<Dispatcher.RequestOptions, 'method' | 'path'> & {
|
|
14
34
|
/**
|
|
15
35
|
* `path` should not be set when using the RegistryClient.
|
|
16
36
|
* It will be overwritten with the path on the URL being requested.
|
|
@@ -42,12 +62,52 @@ export type RegistryClientRequestOptions = Omit<Dispatcher.DispatchOptions, 'met
|
|
|
42
62
|
* @internal
|
|
43
63
|
*/
|
|
44
64
|
redirections?: Set<string>;
|
|
65
|
+
/**
|
|
66
|
+
* Set to `false` to suppress ANY lookups from cache. This will also
|
|
67
|
+
* prevent storing the result to the cache.
|
|
68
|
+
*/
|
|
69
|
+
cache?: false;
|
|
70
|
+
/**
|
|
71
|
+
* Set to pass an `npm-otp` header on the request.
|
|
72
|
+
*
|
|
73
|
+
* This should not be set except by the RegistryClient itself, when
|
|
74
|
+
* we receive a 401 response with an OTP challenge.
|
|
75
|
+
* @internal
|
|
76
|
+
*/
|
|
77
|
+
otp?: string;
|
|
45
78
|
};
|
|
46
79
|
export declare const userAgent: string;
|
|
47
80
|
export declare class RegistryClient {
|
|
48
|
-
|
|
81
|
+
#private;
|
|
82
|
+
agent: RetryAgent;
|
|
49
83
|
cache: Cache;
|
|
50
|
-
|
|
84
|
+
identity: string;
|
|
85
|
+
constructor(options: RegistryClientOptions);
|
|
86
|
+
/**
|
|
87
|
+
* Fetch the entire set of a paginated list of objects
|
|
88
|
+
*/
|
|
89
|
+
scroll<T>(url: URL | string, options?: RegistryClientRequestOptions, seek?: (obj: T) => boolean): Promise<T[]>;
|
|
90
|
+
/**
|
|
91
|
+
* find a given item in a paginated set
|
|
92
|
+
*/
|
|
93
|
+
seek<T>(url: URL | string, seek: (obj: T) => boolean, options?: RegistryClientRequestOptions): Promise<T | undefined>;
|
|
94
|
+
/**
|
|
95
|
+
* Log out from the registry specified, attempting to destroy the
|
|
96
|
+
* token if the registry supports that endpoint.
|
|
97
|
+
*/
|
|
98
|
+
logout(registry: string): Promise<void>;
|
|
99
|
+
/**
|
|
100
|
+
* Log into the registry specified
|
|
101
|
+
*
|
|
102
|
+
* Does not return the token or expose it, just saves to the auth keychain
|
|
103
|
+
* and returns void if it worked. Otherwise, error is raised.
|
|
104
|
+
*/
|
|
105
|
+
login(registry: string): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Given a {@link WebAuthChallenge}, open the `loginUrl` in a browser and
|
|
108
|
+
* hang on the `doneUrl` until it returns a {@link TokenResponse} object.
|
|
109
|
+
*/
|
|
110
|
+
webAuthOpener({ doneUrl, loginUrl }: WebAuthChallenge): Promise<TokenResponse>;
|
|
51
111
|
request(url: URL | string, options?: RegistryClientRequestOptions): Promise<CacheEntry>;
|
|
52
112
|
}
|
|
53
113
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAGrC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAK9C,OAAO,EAAS,UAAU,EAAE,MAAM,QAAQ,CAAA;AAC1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAExC,OAAO,EACL,WAAW,EACX,KAAK,EAEL,OAAO,EACP,SAAS,EACT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