@vltpkg/registry-client 0.0.0-8 → 1.0.0-rc.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/README.md +1 -1
- package/dist/esm/cache-entry.d.ts +37 -10
- package/dist/esm/cache-entry.d.ts.map +1 -1
- package/dist/esm/cache-entry.js +157 -76
- package/dist/esm/cache-entry.js.map +1 -1
- package/dist/esm/handle-304-response.js +1 -1
- package/dist/esm/handle-304-response.js.map +1 -1
- package/dist/esm/index.d.ts +4 -4
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +72 -47
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/otplease.d.ts.map +1 -1
- package/dist/esm/otplease.js +33 -25
- package/dist/esm/otplease.js.map +1 -1
- package/dist/esm/raw-header.d.ts +3 -3
- package/dist/esm/raw-header.d.ts.map +1 -1
- package/dist/esm/raw-header.js +12 -11
- package/dist/esm/raw-header.js.map +1 -1
- package/dist/esm/redirect.d.ts +1 -1
- package/dist/esm/redirect.d.ts.map +1 -1
- package/dist/esm/redirect.js +5 -1
- package/dist/esm/redirect.js.map +1 -1
- package/dist/esm/revalidate.d.ts +1 -1
- package/dist/esm/revalidate.d.ts.map +1 -1
- package/dist/esm/revalidate.js +11 -5
- package/dist/esm/revalidate.js.map +1 -1
- package/dist/esm/set-raw-header.d.ts +1 -1
- package/dist/esm/set-raw-header.d.ts.map +1 -1
- package/dist/esm/set-raw-header.js +6 -4
- package/dist/esm/set-raw-header.js.map +1 -1
- package/dist/esm/string-encoding.d.ts +9 -0
- package/dist/esm/string-encoding.d.ts.map +1 -0
- package/dist/esm/string-encoding.js +25 -0
- package/dist/esm/string-encoding.js.map +1 -0
- package/dist/esm/token-response.d.ts +1 -1
- package/dist/esm/token-response.d.ts.map +1 -1
- package/dist/esm/token-response.js +5 -2
- package/dist/esm/token-response.js.map +1 -1
- package/dist/esm/web-auth-challenge.d.ts +2 -2
- package/dist/esm/web-auth-challenge.d.ts.map +1 -1
- package/dist/esm/web-auth-challenge.js +13 -6
- package/dist/esm/web-auth-challenge.js.map +1 -1
- package/package.json +20 -19
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otplease.d.ts","sourceRoot":"","sources":["../../src/otplease.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACxC,OAAO,KAAK,EACV,cAAc,EACd,4BAA4B,EAC7B,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"otplease.d.ts","sourceRoot":"","sources":["../../src/otplease.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACxC,OAAO,KAAK,EACV,cAAc,EACd,4BAA4B,EAC7B,MAAM,YAAY,CAAA;AAqBnB,eAAO,MAAM,QAAQ,WACX,cAAc,WACb,4BAA4B,YAC3B,UAAU,CAAC,YAAY,KAChC,OAAO,CAAC,4BAA4B,GAAG,SAAS,CAuDlD,CAAA"}
|
package/dist/esm/otplease.js
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import { error } from '@vltpkg/error-cause';
|
|
2
|
-
import {
|
|
2
|
+
import { getWebAuthChallenge } from "./web-auth-challenge.js";
|
|
3
3
|
import { urlOpen } from '@vltpkg/url-open';
|
|
4
4
|
import { createInterface } from 'node:readline/promises';
|
|
5
|
+
// eslint-disable-next-line no-console
|
|
6
|
+
const log = (msg) => console.error(msg);
|
|
7
|
+
const question = async (text) => {
|
|
8
|
+
const rl = createInterface({
|
|
9
|
+
input: process.stdin,
|
|
10
|
+
output: process.stdout,
|
|
11
|
+
});
|
|
12
|
+
const answer = await rl.question(text);
|
|
13
|
+
rl.close();
|
|
14
|
+
return answer;
|
|
15
|
+
};
|
|
5
16
|
const otpChallengeNotice = /^Open ([^ ]+) to use your security key for authentication or enter OTP from your authenticator app/i;
|
|
6
17
|
export const otplease = async (client, options, response) => {
|
|
7
18
|
const waHeader = String(response.headers['www-authenticate'] ?? '');
|
|
@@ -13,43 +24,40 @@ export const otplease = async (client, options, response) => {
|
|
|
13
24
|
}
|
|
14
25
|
if (wwwAuth.has('otp')) {
|
|
15
26
|
// do a web auth opener to get otp token
|
|
16
|
-
const challenge = await response.body.json();
|
|
17
|
-
if (
|
|
27
|
+
const challenge = getWebAuthChallenge(await response.body.json().catch(() => null));
|
|
28
|
+
if (challenge) {
|
|
18
29
|
return {
|
|
19
30
|
...options,
|
|
20
31
|
otp: (await client.webAuthOpener(challenge)).token,
|
|
21
32
|
};
|
|
22
33
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return { ...options, otp };
|
|
35
|
-
}
|
|
34
|
+
const { 'npm-notice': npmNotice } = response.headers;
|
|
35
|
+
if (npmNotice) {
|
|
36
|
+
const notice = String(npmNotice);
|
|
37
|
+
const match = otpChallengeNotice.exec(notice);
|
|
38
|
+
if (match?.[1]) {
|
|
39
|
+
await urlOpen(match[1]);
|
|
40
|
+
log(notice);
|
|
41
|
+
return {
|
|
42
|
+
...options,
|
|
43
|
+
otp: await question('OTP: '),
|
|
44
|
+
};
|
|
36
45
|
}
|
|
37
|
-
throw error('Unrecognized OTP authentication challenge', {
|
|
38
|
-
response,
|
|
39
|
-
});
|
|
40
46
|
}
|
|
47
|
+
throw error('Unrecognized OTP authentication challenge', {
|
|
48
|
+
response,
|
|
49
|
+
});
|
|
41
50
|
}
|
|
42
51
|
if (wwwAuth.size) {
|
|
43
52
|
throw error('Unknown authentication challenge', { response });
|
|
44
53
|
}
|
|
45
54
|
// see if the body is prompting for otp
|
|
46
|
-
const text = await response.body.text();
|
|
55
|
+
const text = await response.body.text().catch(() => '');
|
|
47
56
|
if (text.toLowerCase().includes('one-time pass')) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
return { ...options, otp };
|
|
57
|
+
return {
|
|
58
|
+
...options,
|
|
59
|
+
otp: await question(text),
|
|
60
|
+
};
|
|
53
61
|
}
|
|
54
62
|
};
|
|
55
63
|
//# sourceMappingURL=otplease.js.map
|
package/dist/esm/otplease.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otplease.js","sourceRoot":"","sources":["../../src/otplease.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAM3C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"otplease.js","sourceRoot":"","sources":["../../src/otplease.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAM3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAExD,sCAAsC;AACtC,MAAM,GAAG,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;AAE/C,MAAM,QAAQ,GAAG,KAAK,EAAE,IAAY,EAAmB,EAAE;IACvD,MAAM,EAAE,GAAG,eAAe,CAAC;QACzB,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC,CAAA;IACF,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IACtC,EAAE,CAAC,KAAK,EAAE,CAAA;IACV,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAED,MAAM,kBAAkB,GACtB,qGAAqG,CAAA;AAEvG,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,EAC3B,MAAsB,EACtB,OAAqC,EACrC,QAAiC,EACkB,EAAE;IACrD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C;iBAC7B,CAAA;YACH,CAAC;QACH,CAAC;QAED,MAAM,KAAK,CAAC,2CAA2C,EAAE;YACvD,QAAQ;SACT,CAAC,CAAA;IACJ,CAAC;IAED,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,MAAM,KAAK,CAAC,kCAAkC,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAA;IAC/D,CAAC;IAED,uCAAuC;IACvC,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAA;IACvD,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC;QACjD,OAAO;YACL,GAAG,OAAO;YACV,GAAG,EAAE,MAAM,QAAQ,CAAC,IAAI,CAAC;SAC1B,CAAA;IACH,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport type { Dispatcher } from 'undici'\nimport type {\n RegistryClient,\n RegistryClientRequestOptions,\n} from './index.ts'\nimport { getWebAuthChallenge } from './web-auth-challenge.ts'\nimport { urlOpen } from '@vltpkg/url-open'\nimport { createInterface } from 'node:readline/promises'\n\n// eslint-disable-next-line no-console\nconst log = (msg: string) => console.error(msg)\n\nconst question = async (text: string): Promise<string> => {\n const rl = createInterface({\n input: process.stdin,\n output: process.stdout,\n })\n const answer = await rl.question(text)\n rl.close()\n return answer\n}\n\nconst otpChallengeNotice =\n /^Open ([^ ]+) to use your security key for authentication or enter OTP from your authenticator app/i\n\nexport const otplease = async (\n client: RegistryClient,\n options: RegistryClientRequestOptions,\n response: Dispatcher.ResponseData,\n): Promise<RegistryClientRequestOptions | undefined> => {\n const waHeader = String(response.headers['www-authenticate'] ?? '')\n const wwwAuth = new Set(\n waHeader ? waHeader.toLowerCase().split(/,\\s*/) : [],\n )\n\n if (wwwAuth.has('ipaddress')) {\n throw error('Authorization is not allowed from your ip address', {\n response,\n })\n }\n\n if (wwwAuth.has('otp')) {\n // do a web auth opener to get otp token\n const challenge = getWebAuthChallenge(\n await response.body.json().catch(() => null),\n )\n if (challenge) {\n return {\n ...options,\n otp: (await client.webAuthOpener(challenge)).token,\n }\n }\n\n const { 'npm-notice': npmNotice } = response.headers\n if (npmNotice) {\n const notice = String(npmNotice)\n const match = otpChallengeNotice.exec(notice)\n if (match?.[1]) {\n await urlOpen(match[1])\n log(notice)\n return {\n ...options,\n otp: await question('OTP: '),\n }\n }\n }\n\n throw error('Unrecognized OTP authentication challenge', {\n response,\n })\n }\n\n if (wwwAuth.size) {\n throw error('Unknown authentication challenge', { response })\n }\n\n // see if the body is prompting for otp\n const text = await response.body.text().catch(() => '')\n if (text.toLowerCase().includes('one-time pass')) {\n return {\n ...options,\n otp: await question(text),\n }\n }\n}\n"]}
|
package/dist/esm/raw-header.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Give it a key, and it'll return the
|
|
2
|
+
* Give it a key, and it'll return the value of that header as a Uint8Array
|
|
3
3
|
*/
|
|
4
|
-
export declare const getRawHeader: (headers:
|
|
4
|
+
export declare const getRawHeader: (headers: Uint8Array[], key: string) => Uint8Array | undefined;
|
|
5
5
|
/**
|
|
6
6
|
* Give it a key and value, and it'll overwrite or add the header entry
|
|
7
7
|
*/
|
|
8
|
-
export declare const setRawHeader: (headers:
|
|
8
|
+
export declare const setRawHeader: (headers: Uint8Array[], key: string, value: Uint8Array | string) => Uint8Array[];
|
|
9
9
|
//# sourceMappingURL=raw-header.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"raw-header.d.ts","sourceRoot":"","sources":["../../src/raw-header.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"raw-header.d.ts","sourceRoot":"","sources":["../../src/raw-header.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,eAAO,MAAM,YAAY,YACd,UAAU,EAAE,OAChB,MAAM,KACV,UAAU,GAAG,SAYf,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,YACd,UAAU,EAAE,OAChB,MAAM,SACJ,UAAU,GAAG,MAAM,KACzB,UAAU,EAmBZ,CAAA"}
|
package/dist/esm/raw-header.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import { getDecodedValue, getEncondedValue, } from "./string-encoding.js";
|
|
1
2
|
/**
|
|
2
|
-
* Give it a key, and it'll return the
|
|
3
|
+
* Give it a key, and it'll return the value of that header as a Uint8Array
|
|
3
4
|
*/
|
|
4
|
-
export const getRawHeader = (headers,
|
|
5
|
-
k =
|
|
5
|
+
export const getRawHeader = (headers, key) => {
|
|
6
|
+
const k = key.toLowerCase();
|
|
6
7
|
for (let i = 0; i < headers.length; i += 2) {
|
|
7
8
|
const name = headers[i];
|
|
8
9
|
if (name &&
|
|
9
|
-
name.length ===
|
|
10
|
-
name
|
|
10
|
+
name.length === key.length &&
|
|
11
|
+
getDecodedValue(name).toLowerCase() === k) {
|
|
11
12
|
return headers[i + 1];
|
|
12
13
|
}
|
|
13
14
|
}
|
|
@@ -15,21 +16,21 @@ export const getRawHeader = (headers, k) => {
|
|
|
15
16
|
/**
|
|
16
17
|
* Give it a key and value, and it'll overwrite or add the header entry
|
|
17
18
|
*/
|
|
18
|
-
export const setRawHeader = (headers,
|
|
19
|
-
k =
|
|
20
|
-
const
|
|
19
|
+
export const setRawHeader = (headers, key, value) => {
|
|
20
|
+
const k = key.toLowerCase();
|
|
21
|
+
const encVal = typeof value === 'string' ? getEncondedValue(value) : value;
|
|
21
22
|
for (let i = 0; i < headers.length; i += 2) {
|
|
22
23
|
const name = headers[i];
|
|
23
24
|
if (name &&
|
|
24
25
|
name.length === k.length &&
|
|
25
|
-
name
|
|
26
|
+
getDecodedValue(name).toLowerCase() === k) {
|
|
26
27
|
return [
|
|
27
28
|
...headers.slice(0, i + 1),
|
|
28
|
-
|
|
29
|
+
encVal,
|
|
29
30
|
...headers.slice(i + 2),
|
|
30
31
|
];
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
|
-
return [...headers,
|
|
34
|
+
return [...headers, getEncondedValue(k), encVal];
|
|
34
35
|
};
|
|
35
36
|
//# sourceMappingURL=raw-header.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"raw-header.js","sourceRoot":"","sources":["../../src/raw-header.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,
|
|
1
|
+
{"version":3,"file":"raw-header.js","sourceRoot":"","sources":["../../src/raw-header.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,gBAAgB,GACjB,MAAM,sBAAsB,CAAA;AAE7B;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,OAAqB,EACrB,GAAW,EACa,EAAE;IAC1B,MAAM,CAAC,GAAG,GAAG,CAAC,WAAW,EAAE,CAAA;IAC3B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3C,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;QACvB,IACE,IAAI;YACJ,IAAI,CAAC,MAAM,KAAK,GAAG,CAAC,MAAM;YAC1B,eAAe,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,KAAK,CAAC,EACzC,CAAC;YACD,OAAO,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;QACvB,CAAC;IACH,CAAC;AACH,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,OAAqB,EACrB,GAAW,EACX,KAA0B,EACZ,EAAE;IAChB,MAAM,CAAC,GAAG,GAAG,CAAC,WAAW,EAAE,CAAA;IAC3B,MAAM,MAAM,GACV,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;IAC7D,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3C,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;QACvB,IACE,IAAI;YACJ,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;YACxB,eAAe,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,KAAK,CAAC,EACzC,CAAC;YACD,OAAO;gBACL,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;gBAC1B,MAAM;gBACN,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC;aACxB,CAAA;QACH,CAAC;IACH,CAAC;IACD,OAAO,CAAC,GAAG,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;AAClD,CAAC,CAAA","sourcesContent":["import {\n getDecodedValue,\n getEncondedValue,\n} from './string-encoding.ts'\n\n/**\n * Give it a key, and it'll return the value of that header as a Uint8Array\n */\nexport const getRawHeader = (\n headers: Uint8Array[],\n key: string,\n): Uint8Array | undefined => {\n const k = key.toLowerCase()\n for (let i = 0; i < headers.length; i += 2) {\n const name = headers[i]\n if (\n name &&\n name.length === key.length &&\n getDecodedValue(name).toLowerCase() === k\n ) {\n return headers[i + 1]\n }\n }\n}\n\n/**\n * Give it a key and value, and it'll overwrite or add the header entry\n */\nexport const setRawHeader = (\n headers: Uint8Array[],\n key: string,\n value: Uint8Array | string,\n): Uint8Array[] => {\n const k = key.toLowerCase()\n const encVal =\n typeof value === 'string' ? getEncondedValue(value) : value\n for (let i = 0; i < headers.length; i += 2) {\n const name = headers[i]\n if (\n name &&\n name.length === k.length &&\n getDecodedValue(name).toLowerCase() === k\n ) {\n return [\n ...headers.slice(0, i + 1),\n encVal,\n ...headers.slice(i + 2),\n ]\n }\n }\n return [...headers, getEncondedValue(k), encVal]\n}\n"]}
|
package/dist/esm/redirect.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { RegistryClientRequestOptions } from './index.ts';
|
|
|
3
3
|
export type RedirectStatus = 301 | 302 | 303 | 307 | 308;
|
|
4
4
|
export type RedirectResponse = CacheEntry & {
|
|
5
5
|
statusCode: RedirectStatus;
|
|
6
|
-
getHeader(key: 'location'):
|
|
6
|
+
getHeader(key: 'location'): Uint8Array | undefined;
|
|
7
7
|
};
|
|
8
8
|
export declare const isRedirect: (response: CacheEntry) => response is RedirectResponse;
|
|
9
9
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirect.d.ts","sourceRoot":"","sources":["../../src/redirect.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAA;AAE9D,MAAM,MAAM,cAAc,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAA;AAIxD,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG;IAC1C,UAAU,EAAE,cAAc,CAAA;IAC1B,SAAS,CAAC,GAAG,EAAE,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"redirect.d.ts","sourceRoot":"","sources":["../../src/redirect.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAA;AAE9D,MAAM,MAAM,cAAc,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAA;AAIxD,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG;IAC1C,UAAU,EAAE,cAAc,CAAA;IAC1B,SAAS,CAAC,GAAG,EAAE,UAAU,GAAG,UAAU,GAAG,SAAS,CAAA;CACnD,CAAA;AAED,eAAO,MAAM,UAAU,aACX,UAAU,KACnB,QAAQ,IAAI,gBAE2B,CAAA;AAE1C;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,QAAQ,YACV,4BAA4B,YAC3B,gBAAgB,QACpB,GAAG,KACR,EAAE,GAAG,CAAC,GAAG,EAAE,4BAA4B,CA6CzC,CAAA"}
|
package/dist/esm/redirect.js
CHANGED
|
@@ -27,7 +27,11 @@ export const redirect = (options, response, from) => {
|
|
|
27
27
|
url: from,
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
|
-
const location =
|
|
30
|
+
const location = response.getHeaderString('location');
|
|
31
|
+
/* c8 ignore start */
|
|
32
|
+
if (!location)
|
|
33
|
+
throw error('Location header missing from redirect response');
|
|
34
|
+
/* c8 ignore stop */
|
|
31
35
|
const nextURL = new URL(location, from);
|
|
32
36
|
if (redirections.has(String(nextURL))) {
|
|
33
37
|
throw error('Redirection cycle detected', {
|
package/dist/esm/redirect.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirect.js","sourceRoot":"","sources":["../../src/redirect.ts"],"names":[],"mappings":"AAAA,oEAAoE;AAEpE,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAM3C,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAA;AAO3D,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,QAAoB,EACU,EAAE,CAChC,gBAAgB,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC;IACzC,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;AAE1C;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,OAAqC,EACrC,QAA0B,EAC1B,IAAS,EACiC,EAAE;IAC5C,MAAM,E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E,CAAC,GAAG,YAAY,CAAC;YACxB,GAAG,EAAE,IAAI;SACV,CAAC,CAAA;IACJ,CAAC;IACD,MAAM,QAAQ,GAAG,QAAQ,CAAC,eAAe,CAAC,UAAU,CAAC,CAAA;IACrD,qBAAqB;IACrB,IAAI,CAAC,QAAQ;QACX,MAAM,KAAK,CAAC,gDAAgD,CAAC,CAAA;IAC/D,oBAAoB;IACpB,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;IACvC,IAAI,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC;QACtC,MAAM,KAAK,CAAC,4BAA4B,EAAE;YACxC,GAAG,EAAE,eAAe;YACpB,KAAK,EAAE,CAAC,GAAG,YAAY,CAAC;YACxB,GAAG,EAAE,IAAI;SACV,CAAC,CAAA;IACJ,CAAC;IACD,MAAM,WAAW,GAAiC;QAChD,GAAG,OAAO;QACV,YAAY;KACb,CAAA;IACD,4FAA4F;IAC5F,OAAO,WAAW,CAAC,IAAI,CAAA;IACvB,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAA;IACjC,QAAQ,QAAQ,CAAC,UAAU,EAAE,CAAC;QAC5B,KAAK,GAAG,CAAC,CAAC,CAAC;YACT,kCAAkC;YAClC,WAAW,CAAC,MAAM,GAAG,KAAK,CAAA;YAC1B,WAAW,CAAC,IAAI,GAAG,SAAS,CAAA;YAC5B,cAAc;QAChB,CAAC;QACD,KAAK,GAAG,CAAC;QACT,KAAK,GAAG,CAAC,CAAC,mDAAmD;QAC7D,KAAK,GAAG,CAAC;QACT,KAAK,GAAG,CAAC,CAAC,CAAC;YACT,OAAO,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;QAC/B,CAAC;IACH,CAAC;AACH,CAAC,CAAA","sourcesContent":["// given a RegistryClientOptions object, and a redirection response,\n\nimport { error } from '@vltpkg/error-cause'\nimport type { CacheEntry } from './cache-entry.ts'\nimport type { RegistryClientRequestOptions } from './index.ts'\n\nexport type RedirectStatus = 301 | 302 | 303 | 307 | 308\n\nconst redirectStatuses = new Set([301, 302, 303, 307, 308])\n\nexport type RedirectResponse = CacheEntry & {\n statusCode: RedirectStatus\n getHeader(key: 'location'): Uint8Array | undefined\n}\n\nexport const isRedirect = (\n response: CacheEntry,\n): response is RedirectResponse =>\n redirectStatuses.has(response.statusCode) &&\n !!response.getHeader('location')?.length\n\n/**\n * If this response is allowed to follow the redirect (because max has not\n * been hit, and the new location has not been seen already), then return\n * the [url, options] to use for the subsequent request.\n *\n * Return [] if the response should be returned as-is.\n *\n * Throws an error if maxRedirections is hit or the redirections set already\n * contains the new location.\n *\n * Ensure that the response is in fact a redirection first, by calling\n * {@link isRedirect} on it.\n */\nexport const redirect = (\n options: RegistryClientRequestOptions,\n response: RedirectResponse,\n from: URL,\n): [] | [URL, RegistryClientRequestOptions] => {\n const { redirections = new Set<string>(), maxRedirections = 10 } =\n options\n if (maxRedirections <= 0) return []\n if (redirections.size >= maxRedirections) {\n throw error('Maximum redirections exceeded', {\n max: maxRedirections,\n found: [...redirections],\n url: from,\n })\n }\n const location = response.getHeaderString('location')\n /* c8 ignore start */\n if (!location)\n throw error('Location header missing from redirect response')\n /* c8 ignore stop */\n const nextURL = new URL(location, from)\n if (redirections.has(String(nextURL))) {\n throw error('Redirection cycle detected', {\n max: maxRedirections,\n found: [...redirections],\n url: from,\n })\n }\n const nextOptions: RegistryClientRequestOptions = {\n ...options,\n redirections,\n }\n // eslint-disable-next-line @typescript-eslint/no-deprecated -- thats why we are deleting it\n delete nextOptions.path\n redirections.add(String(nextURL))\n switch (response.statusCode) {\n case 303: {\n // drop body, change method to GET\n nextOptions.method = 'GET'\n nextOptions.body = undefined\n // fallthrough\n }\n case 301:\n case 302: // some user agents treat as 303, but they're wrong\n case 307:\n case 308: {\n return [nextURL, nextOptions]\n }\n }\n}\n"]}
|
package/dist/esm/revalidate.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"revalidate.d.ts","sourceRoot":"","sources":["../../src/revalidate.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,wBAAwB,QAAuB,CAAA;AAM5D,eAAO,MAAM,IAAI,WAAkB,MAAM;;
|
|
1
|
+
{"version":3,"file":"revalidate.d.ts","sourceRoot":"","sources":["../../src/revalidate.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,wBAAwB,QAAuB,CAAA;AAM5D,eAAO,MAAM,IAAI,WAAkB,MAAM;;sBA8CxC,CAAA"}
|
package/dist/esm/revalidate.js
CHANGED
|
@@ -7,8 +7,9 @@ export const __CODE_SPLIT_SCRIPT_NAME = import.meta.filename;
|
|
|
7
7
|
const isMain = (path) => path === __CODE_SPLIT_SCRIPT_NAME ||
|
|
8
8
|
path === pathToFileURL(__CODE_SPLIT_SCRIPT_NAME).toString();
|
|
9
9
|
export const main = async (cache, input = process.stdin) => {
|
|
10
|
-
if (!cache)
|
|
11
|
-
|
|
10
|
+
if (!cache) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
12
13
|
const reqs = await new Promise(res => {
|
|
13
14
|
const chunks = [];
|
|
14
15
|
let chunkLen = 0;
|
|
@@ -27,8 +28,9 @@ export const main = async (cache, input = process.stdin) => {
|
|
|
27
28
|
res(reqs);
|
|
28
29
|
});
|
|
29
30
|
});
|
|
30
|
-
if (!reqs.length)
|
|
31
|
-
|
|
31
|
+
if (!reqs.length) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
32
34
|
const rc = new RegistryClient({ cache });
|
|
33
35
|
await Promise.all(reqs.map(async ([method, url]) => {
|
|
34
36
|
await rc.request(url, {
|
|
@@ -36,6 +38,7 @@ export const main = async (cache, input = process.stdin) => {
|
|
|
36
38
|
staleWhileRevalidate: false,
|
|
37
39
|
});
|
|
38
40
|
}));
|
|
41
|
+
return true;
|
|
39
42
|
};
|
|
40
43
|
const g = globalThis;
|
|
41
44
|
if (isMain(g.__VLT_INTERNAL_MAIN ?? process.argv[1])) {
|
|
@@ -44,6 +47,9 @@ if (isMain(g.__VLT_INTERNAL_MAIN ?? process.argv[1])) {
|
|
|
44
47
|
// so always use the last arg unless there are only two which means
|
|
45
48
|
// no path was supplied.
|
|
46
49
|
const cacheFolder = process.argv.length === 2 ? undefined : process.argv.at(-1);
|
|
47
|
-
|
|
50
|
+
const res = await main(cacheFolder, process.stdin);
|
|
51
|
+
if (!res) {
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
48
54
|
}
|
|
49
55
|
//# sourceMappingURL=revalidate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"revalidate.js","sourceRoot":"","sources":["../../src/revalidate.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,4EAA4E;AAC5E,mEAAmE;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAE3C,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAA;AAE5D,MAAM,MAAM,GAAG,CAAC,IAAa,EAAE,EAAE,CAC/B,IAAI,KAAK,wBAAwB;IACjC,IAAI,KAAK,aAAa,CAAC,wBAAwB,CAAC,CAAC,QAAQ,EAAE,CAAA;AAE7D,MAAM,CAAC,MAAM,IAAI,GAAG,KAAK,EAAE,KAAc,EAAE,KAAK,GAAG,OAAO,CAAC,KAAK,EAAE,EAAE;IAClE,IAAI,CAAC,KAAK
|
|
1
|
+
{"version":3,"file":"revalidate.js","sourceRoot":"","sources":["../../src/revalidate.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,4EAA4E;AAC5E,mEAAmE;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAE3C,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC,IAA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n// otherwise we have a cyclical dependency cycle of dependencies in a cycle,\n// which is even more cyclical than this description describing it.\nimport { pathToFileURL } from 'node:url'\nimport { RegistryClient } from './index.ts'\n\nexport const __CODE_SPLIT_SCRIPT_NAME = import.meta.filename\n\nconst isMain = (path?: string) =>\n path === __CODE_SPLIT_SCRIPT_NAME ||\n path === pathToFileURL(__CODE_SPLIT_SCRIPT_NAME).toString()\n\nexport const main = async (cache?: string, input = process.stdin) => {\n if (!cache) {\n return false\n }\n const reqs = await new Promise<['GET' | 'HEAD', URL][]>(res => {\n const chunks: Buffer[] = []\n let chunkLen = 0\n input.on('data', chunk => {\n chunks.push(chunk)\n chunkLen += chunk.length\n })\n input.on('end', () => {\n const reqs: ['GET' | 'HEAD', URL][] = Buffer.concat(\n chunks,\n chunkLen,\n )\n .toString()\n .split('\\0')\n .filter(\n i => !!i && (i.startsWith('GET ') || i.startsWith('HEAD ')),\n )\n .map(i =>\n i.startsWith('GET ') ?\n ['GET', new URL(i.substring('GET '.length))]\n : ['HEAD', new URL(i.substring('HEAD '.length))],\n )\n\n res(reqs)\n })\n })\n\n if (!reqs.length) {\n return false\n }\n\n const rc = new RegistryClient({ cache })\n await Promise.all(\n reqs.map(async ([method, url]) => {\n await rc.request(url, {\n method,\n staleWhileRevalidate: false,\n })\n }),\n )\n\n return true\n}\n\nconst g = globalThis as typeof globalThis & {\n __VLT_INTERNAL_MAIN?: string\n}\n\nif (isMain(g.__VLT_INTERNAL_MAIN ?? process.argv[1])) {\n process.title = 'vlt-cache-revalidate'\n // When compiled there can be other leading args supplied by Deno\n // so always use the last arg unless there are only two which means\n // no path was supplied.\n const cacheFolder =\n process.argv.length === 2 ? undefined : process.argv.at(-1)\n const res = await main(cacheFolder, process.stdin)\n if (!res) {\n process.exit(1)\n }\n}\n"]}
|
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
* Given a rawHeaders array of [key, value, key2, value2, ...],
|
|
3
3
|
* overwrite the current value of a header, or if not found, append
|
|
4
4
|
*/
|
|
5
|
-
export declare const setRawHeader: (headers:
|
|
5
|
+
export declare const setRawHeader: (headers: Uint8Array[], key: string, value: Uint8Array | string) => Uint8Array[];
|
|
6
6
|
//# sourceMappingURL=set-raw-header.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"set-raw-header.d.ts","sourceRoot":"","sources":["../../src/set-raw-header.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"set-raw-header.d.ts","sourceRoot":"","sources":["../../src/set-raw-header.ts"],"names":[],"mappings":"AAKA;;;GAGG;AACH,eAAO,MAAM,YAAY,YACd,UAAU,EAAE,OAChB,MAAM,SACJ,UAAU,GAAG,MAAM,KACzB,UAAU,EAiBZ,CAAA"}
|
|
@@ -1,20 +1,22 @@
|
|
|
1
|
+
import { getDecodedValue, getEncondedValue, } from "./string-encoding.js";
|
|
1
2
|
/**
|
|
2
3
|
* Given a rawHeaders array of [key, value, key2, value2, ...],
|
|
3
4
|
* overwrite the current value of a header, or if not found, append
|
|
4
5
|
*/
|
|
5
6
|
export const setRawHeader = (headers, key, value) => {
|
|
6
7
|
key = key.toLowerCase();
|
|
7
|
-
const keyBuf =
|
|
8
|
-
const valBuf =
|
|
8
|
+
const keyBuf = getEncondedValue(key);
|
|
9
|
+
const valBuf = getEncondedValue(value);
|
|
9
10
|
for (let i = 0; i < headers.length; i += 2) {
|
|
10
11
|
const k = headers[i];
|
|
11
12
|
if (k &&
|
|
12
13
|
k.length === keyBuf.length &&
|
|
13
|
-
|
|
14
|
+
getDecodedValue(k).toLowerCase() === key) {
|
|
14
15
|
headers[i + 1] = valBuf;
|
|
15
|
-
return;
|
|
16
|
+
return headers;
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
headers.push(keyBuf, valBuf);
|
|
20
|
+
return headers;
|
|
19
21
|
};
|
|
20
22
|
//# sourceMappingURL=set-raw-header.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"set-raw-header.js","sourceRoot":"","sources":["../../src/set-raw-header.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,
|
|
1
|
+
{"version":3,"file":"set-raw-header.js","sourceRoot":"","sources":["../../src/set-raw-header.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,gBAAgB,GACjB,MAAM,sBAAsB,CAAA;AAE7B;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,OAAqB,EACrB,GAAW,EACX,KAA0B,EACZ,EAAE;IAChB,GAAG,GAAG,GAAG,CAAC,WAAW,EAAE,CAAA;IACvB,MAAM,MAAM,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAA;IACpC,MAAM,MAAM,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAA;IACtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3C,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;QACpB,IACE,CAAC;YACD,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM;YAC1B,eAAe,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,KAAK,GAAG,EACxC,CAAC;YACD,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAA;YACvB,OAAO,OAAO,CAAA;QAChB,CAAC;IACH,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC5B,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA","sourcesContent":["import {\n getDecodedValue,\n getEncondedValue,\n} from './string-encoding.ts'\n\n/**\n * Given a rawHeaders array of [key, value, key2, value2, ...],\n * overwrite the current value of a header, or if not found, append\n */\nexport const setRawHeader = (\n headers: Uint8Array[],\n key: string,\n value: Uint8Array | string,\n): Uint8Array[] => {\n key = key.toLowerCase()\n const keyBuf = getEncondedValue(key)\n const valBuf = getEncondedValue(value)\n for (let i = 0; i < headers.length; i += 2) {\n const k = headers[i]\n if (\n k &&\n k.length === keyBuf.length &&\n getDecodedValue(k).toLowerCase() === key\n ) {\n headers[i + 1] = valBuf\n return headers\n }\n }\n headers.push(keyBuf, valBuf)\n return headers\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decodes a string from a Uint8Array
|
|
3
|
+
*/
|
|
4
|
+
export declare const getDecodedValue: (value: string | Uint8Array | undefined) => string;
|
|
5
|
+
/**
|
|
6
|
+
* Encodes a string to a Uint8Array
|
|
7
|
+
*/
|
|
8
|
+
export declare const getEncondedValue: (value: Uint8Array | string | undefined) => Uint8Array;
|
|
9
|
+
//# sourceMappingURL=string-encoding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-encoding.d.ts","sourceRoot":"","sources":["../../src/string-encoding.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,eAAe,UACnB,MAAM,GAAG,UAAU,GAAG,SAAS,KACrC,MAKF,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB,UACpB,UAAU,GAAG,MAAM,GAAG,SAAS,KACrC,UAOF,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const decoder = new TextDecoder();
|
|
2
|
+
/**
|
|
3
|
+
* Decodes a string from a Uint8Array
|
|
4
|
+
*/
|
|
5
|
+
export const getDecodedValue = (value) => {
|
|
6
|
+
if (value == undefined)
|
|
7
|
+
return '';
|
|
8
|
+
if (typeof value === 'string')
|
|
9
|
+
return value;
|
|
10
|
+
const res = decoder.decode(value);
|
|
11
|
+
return res;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Encodes a string to a Uint8Array
|
|
15
|
+
*/
|
|
16
|
+
export const getEncondedValue = (value) => {
|
|
17
|
+
if (value == undefined)
|
|
18
|
+
return new Uint8Array(0);
|
|
19
|
+
if (typeof value === 'string') {
|
|
20
|
+
const res = Buffer.from(value);
|
|
21
|
+
return res;
|
|
22
|
+
}
|
|
23
|
+
return value;
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=string-encoding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-encoding.js","sourceRoot":"","sources":["../../src/string-encoding.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAA;AAEjC;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,KAAsC,EAC9B,EAAE;IACV,IAAI,KAAK,IAAI,SAAS;QAAE,OAAO,EAAE,CAAA;IACjC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAC3C,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IACjC,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,KAAsC,EAC1B,EAAE;IACd,IAAI,KAAK,IAAI,SAAS;QAAE,OAAO,IAAI,UAAU,CAAC,CAAC,CAAC,CAAA;IAChD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QAC9B,OAAO,GAAG,CAAA;IACZ,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["const decoder = new TextDecoder()\n\n/**\n * Decodes a string from a Uint8Array\n */\nexport const getDecodedValue = (\n value: string | Uint8Array | undefined,\n): string => {\n if (value == undefined) return ''\n if (typeof value === 'string') return value\n const res = decoder.decode(value)\n return res\n}\n\n/**\n * Encodes a string to a Uint8Array\n */\nexport const getEncondedValue = (\n value: Uint8Array | string | undefined,\n): Uint8Array => {\n if (value == undefined) return new Uint8Array(0)\n if (typeof value === 'string') {\n const res = Buffer.from(value)\n return res\n }\n return value\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token-response.d.ts","sourceRoot":"","sources":["../../src/token-response.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"token-response.d.ts","sourceRoot":"","sources":["../../src/token-response.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,eAAO,MAAM,gBAAgB,MACxB,OAAO,KACT,aAAa,GAAG,SASN,CAAA"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const getTokenResponse = (b) => (!!b &&
|
|
2
2
|
typeof b === 'object' &&
|
|
3
|
+
'token' in b &&
|
|
3
4
|
typeof b.token === 'string' &&
|
|
4
|
-
|
|
5
|
+
b.token) ?
|
|
6
|
+
{ token: b.token }
|
|
7
|
+
: undefined;
|
|
5
8
|
//# sourceMappingURL=token-response.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token-response.js","sourceRoot":"","sources":["../../src/token-response.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"token-response.js","sourceRoot":"","sources":["../../src/token-response.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,CAAU,EACiB,EAAE,CAC7B,CACE,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,KAAK,QAAQ;IACrB,OAAO,IAAI,CAAC;IACZ,OAAO,CAAC,CAAC,KAAK,KAAK,QAAQ;IAC3B,CAAC,CAAC,KAAK,CACR,CAAC,CAAC;IACD,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE;IACpB,CAAC,CAAC,SAAS,CAAA","sourcesContent":["export type TokenResponse = {\n token: string\n}\n\nexport const getTokenResponse = (\n b: unknown,\n): TokenResponse | undefined =>\n (\n !!b &&\n typeof b === 'object' &&\n 'token' in b &&\n typeof b.token === 'string' &&\n b.token\n ) ?\n { token: b.token }\n : undefined\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type WebAuthChallenge = {
|
|
2
2
|
doneUrl: string;
|
|
3
|
-
|
|
3
|
+
authUrl: string;
|
|
4
4
|
};
|
|
5
|
-
export declare const
|
|
5
|
+
export declare const getWebAuthChallenge: (o: unknown) => WebAuthChallenge | undefined;
|
|
6
6
|
//# sourceMappingURL=web-auth-challenge.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-auth-challenge.d.ts","sourceRoot":"","sources":["../../src/web-auth-challenge.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,MAAM,CAAA;IACf,
|
|
1
|
+
{"version":3,"file":"web-auth-challenge.d.ts","sourceRoot":"","sources":["../../src/web-auth-challenge.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,eAAO,MAAM,mBAAmB,MAC3B,OAAO,KACT,gBAAgB,GAAG,SAerB,CAAA"}
|
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
export const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
export const getWebAuthChallenge = (o) => {
|
|
2
|
+
if (!!o &&
|
|
3
|
+
typeof o === 'object' &&
|
|
4
|
+
'doneUrl' in o &&
|
|
5
|
+
typeof o.doneUrl === 'string' &&
|
|
6
|
+
o.doneUrl) {
|
|
7
|
+
// Publishes use authUrl, but login uses loginUrl
|
|
8
|
+
const authUrl = 'authUrl' in o && typeof o.authUrl === 'string' ? o.authUrl
|
|
9
|
+
: 'loginUrl' in o && typeof o.loginUrl === 'string' ? o.loginUrl
|
|
10
|
+
: undefined;
|
|
11
|
+
return authUrl ? { doneUrl: o.doneUrl, authUrl } : undefined;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
7
14
|
//# sourceMappingURL=web-auth-challenge.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-auth-challenge.js","sourceRoot":"","sources":["../../src/web-auth-challenge.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"web-auth-challenge.js","sourceRoot":"","sources":["../../src/web-auth-challenge.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,CAAU,EACoB,EAAE;IAChC,IACE,CAAC,CAAC,CAAC;QACH,OAAO,CAAC,KAAK,QAAQ;QACrB,SAAS,IAAI,CAAC;QACd,OAAO,CAAC,CAAC,OAAO,KAAK,QAAQ;QAC7B,CAAC,CAAC,OAAO,EACT,CAAC;QACD,iDAAiD;QACjD,MAAM,OAAO,GACX,SAAS,IAAI,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO;YAC3D,CAAC,CAAC,UAAU,IAAI,CAAC,IAAI,OAAO,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ;gBAChE,CAAC,CAAC,SAAS,CAAA;QACb,OAAO,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS,CAAA;IAC9D,CAAC;AACH,CAAC,CAAA","sourcesContent":["export type WebAuthChallenge = {\n doneUrl: string\n authUrl: string\n}\n\nexport const getWebAuthChallenge = (\n o: unknown,\n): WebAuthChallenge | undefined => {\n if (\n !!o &&\n typeof o === 'object' &&\n 'doneUrl' in o &&\n typeof o.doneUrl === 'string' &&\n o.doneUrl\n ) {\n // Publishes use authUrl, but login uses loginUrl\n const authUrl =\n 'authUrl' in o && typeof o.authUrl === 'string' ? o.authUrl\n : 'loginUrl' in o && typeof o.loginUrl === 'string' ? o.loginUrl\n : undefined\n return authUrl ? { doneUrl: o.doneUrl, authUrl } : undefined\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vltpkg/registry-client",
|
|
3
3
|
"description": "Fetch package artifacts and metadata from registries",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "1.0.0-rc.1",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/vltpkg/vltpkg.git",
|
|
8
8
|
"directory": "src/registry-client"
|
|
9
9
|
},
|
|
10
|
+
"author": "vlt technology inc. <support@vlt.sh> (http://vlt.sh)",
|
|
10
11
|
"tshy": {
|
|
11
12
|
"selfLink": false,
|
|
12
13
|
"liveDev": true,
|
|
@@ -20,29 +21,28 @@
|
|
|
20
21
|
}
|
|
21
22
|
},
|
|
22
23
|
"dependencies": {
|
|
23
|
-
"cache-control-parser": "^2.0.
|
|
24
|
-
"package-json-from-dist": "^1.0.
|
|
25
|
-
"undici": "^7.
|
|
26
|
-
"@vltpkg/cache": "
|
|
27
|
-
"@vltpkg/cache-unzip": "
|
|
28
|
-
"@vltpkg/
|
|
29
|
-
"@vltpkg/
|
|
30
|
-
"@vltpkg/output": "
|
|
31
|
-
"@vltpkg/types": "
|
|
32
|
-
"@vltpkg/url-open": "
|
|
33
|
-
"@vltpkg/xdg": "
|
|
24
|
+
"cache-control-parser": "^2.0.6",
|
|
25
|
+
"package-json-from-dist": "^1.0.1",
|
|
26
|
+
"undici": "^7.15.0",
|
|
27
|
+
"@vltpkg/cache": "1.0.0-rc.1",
|
|
28
|
+
"@vltpkg/cache-unzip": "1.0.0-rc.1",
|
|
29
|
+
"@vltpkg/keychain": "1.0.0-rc.1",
|
|
30
|
+
"@vltpkg/error-cause": "1.0.0-rc.1",
|
|
31
|
+
"@vltpkg/output": "1.0.0-rc.1",
|
|
32
|
+
"@vltpkg/types": "1.0.0-rc.1",
|
|
33
|
+
"@vltpkg/url-open": "1.0.0-rc.1",
|
|
34
|
+
"@vltpkg/xdg": "1.0.0-rc.1"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
|
-
"@eslint/js": "^9.
|
|
37
|
-
"@types/
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"prettier": "^3.4.2",
|
|
37
|
+
"@eslint/js": "^9.34.0",
|
|
38
|
+
"@types/node": "^22.17.2",
|
|
39
|
+
"eslint": "^9.34.0",
|
|
40
|
+
"prettier": "^3.6.2",
|
|
41
41
|
"tap": "^21.1.0",
|
|
42
42
|
"tshy": "^3.0.2",
|
|
43
|
-
"typedoc": "0.27.
|
|
43
|
+
"typedoc": "~0.27.9",
|
|
44
44
|
"typescript": "5.7.3",
|
|
45
|
-
"typescript-eslint": "^8.
|
|
45
|
+
"typescript-eslint": "^8.40.0"
|
|
46
46
|
},
|
|
47
47
|
"license": "BSD-2-Clause-Patent",
|
|
48
48
|
"engines": {
|
|
@@ -80,6 +80,7 @@
|
|
|
80
80
|
"snap": "tap",
|
|
81
81
|
"test": "tap",
|
|
82
82
|
"posttest": "tsc --noEmit",
|
|
83
|
+
"tshy": "tshy",
|
|
83
84
|
"typecheck": "tsc --noEmit"
|
|
84
85
|
}
|
|
85
86
|
}
|