@vltpkg/registry-client 1.0.0-rc.2 → 1.0.0-rc.22

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.
Files changed (82) hide show
  1. package/package.json +36 -48
  2. package/dist/esm/add-header.d.ts +0 -2
  3. package/dist/esm/add-header.d.ts.map +0 -1
  4. package/dist/esm/add-header.js +0 -27
  5. package/dist/esm/add-header.js.map +0 -1
  6. package/dist/esm/auth.d.ts +0 -9
  7. package/dist/esm/auth.d.ts.map +0 -1
  8. package/dist/esm/auth.js +0 -39
  9. package/dist/esm/auth.js.map +0 -1
  10. package/dist/esm/cache-entry.d.ts +0 -141
  11. package/dist/esm/cache-entry.d.ts.map +0 -1
  12. package/dist/esm/cache-entry.js +0 -518
  13. package/dist/esm/cache-entry.js.map +0 -1
  14. package/dist/esm/cache-revalidate.d.ts +0 -2
  15. package/dist/esm/cache-revalidate.d.ts.map +0 -1
  16. package/dist/esm/cache-revalidate.js +0 -66
  17. package/dist/esm/cache-revalidate.js.map +0 -1
  18. package/dist/esm/delete-header.d.ts +0 -2
  19. package/dist/esm/delete-header.d.ts.map +0 -1
  20. package/dist/esm/delete-header.js +0 -32
  21. package/dist/esm/delete-header.js.map +0 -1
  22. package/dist/esm/env.d.ts +0 -7
  23. package/dist/esm/env.d.ts.map +0 -1
  24. package/dist/esm/env.js +0 -13
  25. package/dist/esm/env.js.map +0 -1
  26. package/dist/esm/get-header.d.ts +0 -2
  27. package/dist/esm/get-header.d.ts.map +0 -1
  28. package/dist/esm/get-header.js +0 -37
  29. package/dist/esm/get-header.js.map +0 -1
  30. package/dist/esm/handle-304-response.d.ts +0 -4
  31. package/dist/esm/handle-304-response.d.ts.map +0 -1
  32. package/dist/esm/handle-304-response.js +0 -10
  33. package/dist/esm/handle-304-response.js.map +0 -1
  34. package/dist/esm/index.d.ts +0 -144
  35. package/dist/esm/index.d.ts.map +0 -1
  36. package/dist/esm/index.js +0 -325
  37. package/dist/esm/index.js.map +0 -1
  38. package/dist/esm/is-cacheable.d.ts +0 -5
  39. package/dist/esm/is-cacheable.d.ts.map +0 -1
  40. package/dist/esm/is-cacheable.js +0 -10
  41. package/dist/esm/is-cacheable.js.map +0 -1
  42. package/dist/esm/is-iterable.d.ts +0 -2
  43. package/dist/esm/is-iterable.d.ts.map +0 -1
  44. package/dist/esm/is-iterable.js +0 -2
  45. package/dist/esm/is-iterable.js.map +0 -1
  46. package/dist/esm/otplease.d.ts +0 -4
  47. package/dist/esm/otplease.d.ts.map +0 -1
  48. package/dist/esm/otplease.js +0 -63
  49. package/dist/esm/otplease.js.map +0 -1
  50. package/dist/esm/package.json +0 -3
  51. package/dist/esm/raw-header.d.ts +0 -9
  52. package/dist/esm/raw-header.d.ts.map +0 -1
  53. package/dist/esm/raw-header.js +0 -36
  54. package/dist/esm/raw-header.js.map +0 -1
  55. package/dist/esm/redirect.d.ts +0 -23
  56. package/dist/esm/redirect.d.ts.map +0 -1
  57. package/dist/esm/redirect.js +0 -65
  58. package/dist/esm/redirect.js.map +0 -1
  59. package/dist/esm/revalidate.d.ts +0 -5
  60. package/dist/esm/revalidate.d.ts.map +0 -1
  61. package/dist/esm/revalidate.js +0 -55
  62. package/dist/esm/revalidate.js.map +0 -1
  63. package/dist/esm/set-cache-headers.d.ts +0 -4
  64. package/dist/esm/set-cache-headers.d.ts.map +0 -1
  65. package/dist/esm/set-cache-headers.js +0 -17
  66. package/dist/esm/set-cache-headers.js.map +0 -1
  67. package/dist/esm/set-raw-header.d.ts +0 -6
  68. package/dist/esm/set-raw-header.d.ts.map +0 -1
  69. package/dist/esm/set-raw-header.js +0 -22
  70. package/dist/esm/set-raw-header.js.map +0 -1
  71. package/dist/esm/string-encoding.d.ts +0 -9
  72. package/dist/esm/string-encoding.d.ts.map +0 -1
  73. package/dist/esm/string-encoding.js +0 -25
  74. package/dist/esm/string-encoding.js.map +0 -1
  75. package/dist/esm/token-response.d.ts +0 -5
  76. package/dist/esm/token-response.d.ts.map +0 -1
  77. package/dist/esm/token-response.js +0 -8
  78. package/dist/esm/token-response.js.map +0 -1
  79. package/dist/esm/web-auth-challenge.d.ts +0 -6
  80. package/dist/esm/web-auth-challenge.d.ts.map +0 -1
  81. package/dist/esm/web-auth-challenge.js +0 -14
  82. package/dist/esm/web-auth-challenge.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"cache-revalidate.js","sourceRoot":"","sources":["../../src/cache-revalidate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC1C,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAA;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,MAAM,MAAM,GACT,UAAiD,CAAC,IAAI,IAAI,SAAS,CAAA;AAEtE,IAAI,wBAAwB,GAAG,KAAK,CAAA;AACpC,MAAM,UAAU,GAAG,IAAI,GAAG,EAAuB,CAAA;AAEjD,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,IAAY,EACZ,MAAsB,EACtB,GAAiB,EACX,EAAE;IACR,MAAM,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,EAAU,CAAA;IACnD,MAAM,GAAG,GAAG,GAAG,MAAM,IAAI,GAAG,EAAE,CAAA;IAC9B,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IACV,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;IACvB,IAAI,CAAC,wBAAwB,EAAE,CAAC;QAC9B,wBAAwB,GAAG,IAAI,CAAA;QAC/B,OAAO,CAAC,EAAE,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAA;IAC5C,CAAC;AACH,CAAC,CAAA;AAED,MAAM,gBAAgB,GAAG,GAAG,EAAE;IAC5B,KAAK,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,UAAU,EAAE,CAAC;QACnC,oBAAoB;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/E,0EAA0E;QAC1E,oDAAoD;QACpD,gDAAgD;QAChD,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,CAAC,KAAK,EAAE,CAAA;QACd,CAAC;IACH,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { spawn } from 'node:child_process'\nimport { __CODE_SPLIT_SCRIPT_NAME } from './revalidate.ts'\nimport { pathToFileURL } from 'node:url'\n\nconst isDeno =\n (globalThis as typeof globalThis & { Deno?: any }).Deno != undefined\n\nlet didProcessBeforeExitHook = false\nconst registered = new Map<string, Set<string>>()\n\nexport const register = (\n path: string,\n method: 'HEAD' | 'GET',\n url: string | URL,\n): void => {\n const r = registered.get(path) ?? new Set<string>()\n const key = `${method} ${url}`\n r.add(key)\n registered.set(path, r)\n if (!didProcessBeforeExitHook) {\n didProcessBeforeExitHook = true\n process.on('beforeExit', handleBeforeExit)\n }\n}\n\nconst handleBeforeExit = () => {\n for (const [path, r] of registered) {\n /* c8 ignore next */\n if (!r.size) return\n const env = { ...process.env }\n const args = []\n /* c8 ignore start */\n // When compiled the script to be run is passed as an\n // environment variable and then routed by the main entry point\n if (process.env.__VLT_INTERNAL_COMPILED) {\n env.__VLT_INTERNAL_MAIN = pathToFileURL(\n __CODE_SPLIT_SCRIPT_NAME,\n ).toString()\n args.push(path)\n } else {\n // If we are running deno from source we need to add the\n // unstable flags we need. The '-A' flag does not need\n // to be passed in as Deno supplies that automatically.\n if (isDeno) {\n args.push(\n '--unstable-node-globals',\n '--unstable-bare-node-builtins',\n )\n }\n /* c8 ignore stop */\n args.push(__CODE_SPLIT_SCRIPT_NAME, path)\n }\n registered.delete(path)\n // Deno on Windows does not support detached processes\n // https://github.com/denoland/deno/issues/25867\n // TODO: figure out something better to do here?\n /* c8 ignore next */\n const detached = !(isDeno && process.platform === 'win32')\n const proc = spawn(process.execPath, args, {\n detached,\n stdio: ['pipe', 'ignore', 'ignore'],\n env,\n })\n for (const key of r) {\n proc.stdin.write(`${key}\\0`)\n }\n proc.stdin.end()\n // Another Deno oddity. Calling unref on a spawned process will kill the\n // process unless it is detached. https://github.com/denoland/deno/issues/21446\n // So in this case Deno on Windows will be slower to exit the main process\n // since it will wait for the child process to exit.\n // TODO: figure out something better to do here?\n if (detached) {\n proc.unref()\n }\n }\n}\n"]}
@@ -1,2 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,32 +0,0 @@
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
@@ -1 +0,0 @@
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 DELETED
@@ -1,7 +0,0 @@
1
- export declare const isDeno: boolean;
2
- export declare const isBun: boolean;
3
- export declare const isNode: boolean;
4
- export declare const bun: string | undefined;
5
- export declare const deno: string | undefined;
6
- export declare const node: string | undefined;
7
- //# sourceMappingURL=env.d.ts.map
@@ -1 +0,0 @@
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 DELETED
@@ -1,13 +0,0 @@
1
- import proc from 'node:process';
2
- const { Deno, Bun } = globalThis;
3
- const isObj = (v) => typeof v === 'object' && !!v;
4
- export const isDeno = isObj(Deno);
5
- export const isBun = !isDeno && isObj(Bun);
6
- // bun and deno also report 'node' in process.versions so its only
7
- // node if it is not bun or deno
8
- export const isNode = !isDeno && !isBun && 'node' in proc.versions;
9
- // All the runtimes put their versions into process.versions
10
- export const bun = isBun ? proc.versions.bun : undefined;
11
- export const deno = isDeno ? proc.versions.deno : undefined;
12
- export const node = isNode ? proc.versions.node : undefined;
13
- //# sourceMappingURL=env.js.map
@@ -1 +0,0 @@
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,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAA;AAC1C,kEAAkE;AAClE,gCAAgC;AAChC,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,KAAK,IAAI,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAA;AAElE,4DAA4D;AAC5D,MAAM,CAAC,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,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,2 +0,0 @@
1
- export declare const getHeader: (headers: Iterable<[string, string[] | string | undefined]> | Record<string, string[] | string | undefined> | string[] | null | undefined, key: string) => string[] | string | undefined;
2
- //# sourceMappingURL=get-header.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-header.d.ts","sourceRoot":"","sources":["../../src/get-header.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,SAAS,YAEhB,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,GACR,IAAI,GACJ,SAAS,OACR,MAAM,KACV,MAAM,EAAE,GAAG,MAAM,GAAG,SA8BtB,CAAA"}
@@ -1,37 +0,0 @@
1
- const isIterable = (o) => !!o && typeof o === 'object' && Symbol.iterator in o;
2
- export const getHeader = (headers, key) => {
3
- if (!headers)
4
- return undefined;
5
- key = key.toLowerCase();
6
- if (Array.isArray(headers)) {
7
- if (!headers.length)
8
- return undefined;
9
- if (Array.isArray(headers[0])) {
10
- // [string,HeaderValue][]
11
- for (const [k, v] of headers) {
12
- if (k.toLowerCase() === key)
13
- return v;
14
- }
15
- }
16
- else if (headers.length % 2 === 0) {
17
- // [k, v, k2, v2, ...]
18
- for (let i = 0; i < headers.length; i += 2) {
19
- if (headers[i]?.toLowerCase() === key)
20
- return headers[i + 1];
21
- }
22
- }
23
- }
24
- else if (isIterable(headers)) {
25
- for (const [k, v] of headers) {
26
- if (k.toLowerCase() === key)
27
- return v;
28
- }
29
- }
30
- else {
31
- for (const [k, v] of Object.entries(headers)) {
32
- if (k.toLowerCase() === key)
33
- return v;
34
- }
35
- }
36
- };
37
- //# sourceMappingURL=get-header.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-header.js","sourceRoot":"","sources":["../../src/get-header.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,GAAG,CAAI,CAAU,EAAoB,EAAE,CACrD,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,IAAI,CAAC,CAAA;AAEtD,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,OAKa,EACb,GAAW,EACoB,EAAE;IACjC,IAAI,CAAC,OAAO;QAAE,OAAO,SAAS,CAAA;IAC9B,GAAG,GAAG,GAAG,CAAC,WAAW,EAAE,CAAA;IACvB,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3B,IAAI,CAAC,OAAO,CAAC,MAAM;YAAE,OAAO,SAAS,CAAA;QACrC,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAC9B,yBAAyB;YACzB,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,OAGlB,EAAE,CAAC;gBACJ,IAAI,CAAC,CAAC,WAAW,EAAE,KAAK,GAAG;oBAAE,OAAO,CAAC,CAAA;YACvC,CAAC;QACH,CAAC;aAAM,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YACpC,sBAAsB;YACtB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC3C,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,KAAK,GAAG;oBAAE,OAAO,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;YAC9D,CAAC;QACH,CAAC;IACH,CAAC;SAAM,IACL,UAAU,CAA0C,OAAO,CAAC,EAC5D,CAAC;QACD,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,OAAO,EAAE,CAAC;YAC7B,IAAI,CAAC,CAAC,WAAW,EAAE,KAAK,GAAG;gBAAE,OAAO,CAAC,CAAA;QACvC,CAAC;IACH,CAAC;SAAM,CAAC;QACN,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7C,IAAI,CAAC,CAAC,WAAW,EAAE,KAAK,GAAG;gBAAE,OAAO,CAAC,CAAA;QACvC,CAAC;IACH,CAAC;AACH,CAAC,CAAA","sourcesContent":["const isIterable = <T>(o: unknown): o is Iterable<T> =>\n !!o && typeof o === 'object' && Symbol.iterator in o\n\nexport const getHeader = (\n headers:\n | Iterable<[string, string[] | string | undefined]>\n | Record<string, string[] | string | undefined>\n | string[]\n | null\n | undefined,\n key: string,\n): string[] | string | undefined => {\n if (!headers) return undefined\n key = key.toLowerCase()\n if (Array.isArray(headers)) {\n if (!headers.length) return undefined\n if (Array.isArray(headers[0])) {\n // [string,HeaderValue][]\n for (const [k, v] of headers as unknown as [\n string,\n string[] | string,\n ][]) {\n if (k.toLowerCase() === key) return v\n }\n } else if (headers.length % 2 === 0) {\n // [k, v, k2, v2, ...]\n for (let i = 0; i < headers.length; i += 2) {\n if (headers[i]?.toLowerCase() === key) return headers[i + 1]\n }\n }\n } else if (\n isIterable<[string, string[] | string | undefined]>(headers)\n ) {\n for (const [k, v] of headers) {\n if (k.toLowerCase() === key) return v\n }\n } else {\n for (const [k, v] of Object.entries(headers)) {\n if (k.toLowerCase() === key) return v\n }\n }\n}\n"]}
@@ -1,4 +0,0 @@
1
- import type { Dispatcher } from 'undici';
2
- import type { CacheEntry } from './cache-entry.ts';
3
- export declare const handle304Response: (resp: Dispatcher.ResponseData, entry?: CacheEntry) => entry is CacheEntry;
4
- //# sourceMappingURL=handle-304-response.d.ts.map
@@ -1 +0,0 @@
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,10 +0,0 @@
1
- export const handle304Response = (resp, entry) => {
2
- if (resp.statusCode !== 304 || !entry)
3
- return false;
4
- const d = String(resp.headers.date ?? '') || new Date().toUTCString();
5
- entry.setHeader('date', d);
6
- // shouldn't have a body, but just in case.
7
- resp.body.resume();
8
- return true;
9
- };
10
- //# sourceMappingURL=handle-304-response.js.map
@@ -1 +0,0 @@
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,CAAC,CAAC,CAAA;IAC1B,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', d)\n // shouldn't have a body, but just in case.\n resp.body.resume()\n return true\n}\n"]}
@@ -1,144 +0,0 @@
1
- import { Cache } from '@vltpkg/cache';
2
- import type { Integrity } from '@vltpkg/types';
3
- import type { Dispatcher } from 'undici';
4
- import { RetryAgent } from 'undici';
5
- import type { Token } from './auth.ts';
6
- import { deleteToken, getKC, isToken, keychains, setToken } from './auth.ts';
7
- import type { JSONObj } from './cache-entry.ts';
8
- import { CacheEntry } from './cache-entry.ts';
9
- import type { TokenResponse } from './token-response.ts';
10
- import type { WebAuthChallenge } from './web-auth-challenge.ts';
11
- export { CacheEntry, deleteToken, getKC, isToken, keychains, setToken, type JSONObj, type Token, type TokenResponse, type WebAuthChallenge, };
12
- export type CacheableMethod = 'GET' | 'HEAD';
13
- export declare const isCacheableMethod: (m: unknown) => m is CacheableMethod;
14
- export type RegistryClientOptions = {
15
- /**
16
- * Path on disk where the cache should be stored
17
- *
18
- * Defaults to the XDG cache folder for `vlt/registry-client`
19
- */
20
- cache?: string;
21
- /**
22
- * Number of retries to perform when encountering network errors or
23
- * likely-transient errors from git hosts.
24
- */
25
- 'fetch-retries'?: number;
26
- /** The exponential backoff factor to use when retrying git hosts */
27
- 'fetch-retry-factor'?: number;
28
- /** Number of milliseconds before starting first retry */
29
- 'fetch-retry-mintimeout'?: number;
30
- /** Maximum number of milliseconds between two retries */
31
- 'fetch-retry-maxtimeout'?: number;
32
- /** the identity to use for storing auth tokens */
33
- identity?: string;
34
- /**
35
- * If the server does not serve a `stale-while-revalidate` value in the
36
- * `cache-control` header, then this multiplier is applied to the `max-age`
37
- * or `s-maxage` values.
38
- *
39
- * By default, this is `60`, so for example a response that is cacheable for
40
- * 5 minutes will allow a stale response while revalidating for up to 5
41
- * hours.
42
- *
43
- * If the server *does* provide a `stale-while-revalidate` value, then that
44
- * is always used.
45
- *
46
- * Set to 0 to prevent any `stale-while-revalidate` behavior unless
47
- * explicitly allowed by the server's `cache-control` header.
48
- */
49
- 'stale-while-revalidate-factor'?: number;
50
- };
51
- export type RegistryClientRequestOptions = Omit<Dispatcher.RequestOptions, 'method' | 'path'> & {
52
- /**
53
- * `path` should not be set when using the RegistryClient.
54
- * It will be overwritten with the path on the URL being requested.
55
- * This only here for compliance with the DispatchOptions base type.
56
- * @deprecated
57
- */
58
- path?: string;
59
- /**
60
- * Method is optional, defaults to 'GET'
61
- */
62
- method?: Dispatcher.DispatchOptions['method'];
63
- /**
64
- * Provide an SRI string to verify integrity of the item being fetched.
65
- *
66
- * This is only relevant when it must make a request to the registry. Once in
67
- * the local disk cache, items are assumed to be trustworthy.
68
- */
69
- integrity?: Integrity;
70
- /**
71
- * Set to true if the integrity should be trusted implicitly without
72
- * a recalculation, for example if it comes from a trusted registry that
73
- * also serves the tarball itself.
74
- */
75
- trustIntegrity?: boolean;
76
- /**
77
- * Follow up to 10 redirections by default. Set this to 0 to just return
78
- * the 3xx response. If the max redirections are expired, and we still get
79
- * a redirection response, then fail the request. Redirection cycles are
80
- * always treated as an error.
81
- */
82
- maxRedirections?: number;
83
- /**
84
- * the number of redirections that have already been seen. This is used
85
- * internally, and should always start at 0.
86
- * @internal
87
- */
88
- redirections?: Set<string>;
89
- /**
90
- * Set to `false` to suppress ANY lookups from cache. This will also
91
- * prevent storing the result to the cache.
92
- */
93
- useCache?: false;
94
- /**
95
- * Set to pass an `npm-otp` header on the request.
96
- *
97
- * This should not be set except by the RegistryClient itself, when
98
- * we receive a 401 response with an OTP challenge.
99
- * @internal
100
- */
101
- otp?: string;
102
- /**
103
- * Set to false to explicitly prevent `stale-while-revalidate` behavior,
104
- * for use in revalidating while stale.
105
- * @internal
106
- */
107
- staleWhileRevalidate?: false;
108
- };
109
- export declare const userAgent: string;
110
- export declare class RegistryClient {
111
- #private;
112
- agent: RetryAgent;
113
- cache: Cache;
114
- identity: string;
115
- staleWhileRevalidateFactor: number;
116
- constructor(options: RegistryClientOptions);
117
- /**
118
- * Fetch the entire set of a paginated list of objects
119
- */
120
- scroll<T>(url: URL | string, options?: RegistryClientRequestOptions, seek?: (obj: T) => boolean): Promise<T[]>;
121
- /**
122
- * find a given item in a paginated set
123
- */
124
- seek<T>(url: URL | string, seek: (obj: T) => boolean, options?: RegistryClientRequestOptions): Promise<T | undefined>;
125
- /**
126
- * Log out from the registry specified, attempting to destroy the
127
- * token if the registry supports that endpoint.
128
- */
129
- logout(registry: string): Promise<void>;
130
- /**
131
- * Log into the registry specified
132
- *
133
- * Does not return the token or expose it, just saves to the auth keychain
134
- * and returns void if it worked. Otherwise, error is raised.
135
- */
136
- login(registry: string): Promise<void>;
137
- /**
138
- * Given a {@link WebAuthChallenge}, open the `authUrl` in a browser and
139
- * hang on the `doneUrl` until it returns a {@link TokenResponse} object.
140
- */
141
- webAuthOpener({ doneUrl, authUrl }: WebAuthChallenge): Promise<TokenResponse>;
142
- request(url: URL | string, options?: RegistryClientRequestOptions): Promise<CacheEntry>;
143
- }
144
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAKrC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAM9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACxC,OAAO,EAAS,UAAU,EAAE,MAAM,QAAQ,CAAA;AAE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EAAE,OAAO,EAAE,EAAE,gBAAgB;IA6CpD,OAAO,CACX,GAAG,EAAE,GAAG,GAAG,MAAM,EACjB,OAAO,GAAE,4BAAiC,GACzC,OAAO,CAAC,UAAU,CAAC;CA6LvB"}
package/dist/esm/index.js DELETED
@@ -1,325 +0,0 @@
1
- import { Cache } from '@vltpkg/cache';
2
- import { register as cacheUnzipRegister } from '@vltpkg/cache-unzip';
3
- import { error } from '@vltpkg/error-cause';
4
- import { asError } from '@vltpkg/types';
5
- import { logRequest } from '@vltpkg/output';
6
- import { urlOpen } from '@vltpkg/url-open';
7
- import { XDG } from '@vltpkg/xdg';
8
- import { dirname, resolve } from 'node:path';
9
- import { setTimeout } from 'node:timers/promises';
10
- import { loadPackageJson } from 'package-json-from-dist';
11
- import { Agent, RetryAgent } from 'undici';
12
- import { addHeader } from "./add-header.js";
13
- import { deleteToken, getKC, getToken, isToken, keychains, setToken, } from "./auth.js";
14
- import { CacheEntry } from "./cache-entry.js";
15
- import { register } from "./cache-revalidate.js";
16
- import { bun, deno, node } from "./env.js";
17
- import { handle304Response } from "./handle-304-response.js";
18
- import { otplease } from "./otplease.js";
19
- import { isRedirect, redirect } from "./redirect.js";
20
- import { setCacheHeaders } from "./set-cache-headers.js";
21
- import { getTokenResponse } from "./token-response.js";
22
- import { getWebAuthChallenge } from "./web-auth-challenge.js";
23
- import { getEncondedValue } from "./string-encoding.js";
24
- export { CacheEntry, deleteToken, getKC, isToken, keychains, setToken, };
25
- export const isCacheableMethod = (m) => m === 'GET' || m === 'HEAD';
26
- const { version } = loadPackageJson(import.meta.filename, process.env.__VLT_INTERNAL_REGISTRY_CLIENT_PACKAGE_JSON);
27
- const nua = globalThis.navigator?.userAgent ??
28
- (bun ? `Bun/${bun}`
29
- : deno ? `Deno/${deno}`
30
- : node ? `Node.js/${node}`
31
- : '(unknown platform)');
32
- export const userAgent = `@vltpkg/registry-client/${version} ${nua}`;
33
- const agentOptions = {
34
- bodyTimeout: 600_000,
35
- headersTimeout: 600_000,
36
- keepAliveMaxTimeout: 1_200_000,
37
- keepAliveTimeout: 600_000,
38
- keepAliveTimeoutThreshold: 30_000,
39
- connect: {
40
- timeout: 600_000,
41
- keepAlive: true,
42
- keepAliveInitialDelay: 30_000,
43
- sessionTimeout: 600,
44
- },
45
- connections: 128,
46
- pipelining: 10,
47
- };
48
- const xdg = new XDG('vlt');
49
- export class RegistryClient {
50
- agent;
51
- cache;
52
- identity;
53
- staleWhileRevalidateFactor;
54
- constructor(options) {
55
- const { cache = xdg.cache(), 'fetch-retry-factor': timeoutFactor = 2, 'fetch-retry-mintimeout': minTimeout = 0, 'fetch-retry-maxtimeout': maxTimeout = 30_000, 'fetch-retries': maxRetries = 3, identity = '', 'stale-while-revalidate-factor': staleWhileRevalidateFactor = 60, } = options;
56
- this.identity = identity;
57
- this.staleWhileRevalidateFactor = staleWhileRevalidateFactor;
58
- const path = resolve(cache, 'registry-client');
59
- this.cache = new Cache({
60
- path,
61
- onDiskWrite(_path, key, data) {
62
- if (CacheEntry.isGzipEntry(data)) {
63
- cacheUnzipRegister(path, key);
64
- }
65
- },
66
- });
67
- const dispatch = new Agent(agentOptions);
68
- this.agent = new RetryAgent(dispatch, {
69
- maxRetries,
70
- timeoutFactor,
71
- minTimeout,
72
- maxTimeout,
73
- retryAfter: true,
74
- errorCodes: [
75
- 'ECONNREFUSED',
76
- 'ECONNRESET',
77
- 'EHOSTDOWN',
78
- 'ENETDOWN',
79
- 'ENETUNREACH',
80
- 'ENOTFOUND',
81
- 'EPIPE',
82
- 'UND_ERR_SOCKET',
83
- ],
84
- });
85
- }
86
- /**
87
- * Fetch the entire set of a paginated list of objects
88
- */
89
- async scroll(url, options = {}, seek) {
90
- const resp = await this.request(url, options);
91
- const { objects, urls } = resp.json();
92
- // if we have more, and haven't found our target, fetch more
93
- return urls.next && !(seek && objects.some(seek)) ?
94
- objects.concat(await this.scroll(urls.next, options, seek))
95
- : objects;
96
- }
97
- /**
98
- * find a given item in a paginated set
99
- */
100
- async seek(url, seek, options = {}) {
101
- return (await this.scroll(url, options, seek)).find(seek);
102
- }
103
- /**
104
- * Log out from the registry specified, attempting to destroy the
105
- * token if the registry supports that endpoint.
106
- */
107
- async logout(registry) {
108
- // if we have no token for that registry, nothing to do
109
- const tok = await getToken(registry, this.identity);
110
- if (!tok)
111
- return;
112
- const s = tok.replace(/^(Bearer|Basic) /i, '');
113
- const tokensUrl = new URL('-/npm/v1/tokens', registry);
114
- const record = await this.seek(tokensUrl, ({ token }) => s.startsWith(token), {
115
- useCache: false,
116
- }).catch(() => undefined);
117
- if (record) {
118
- const { key } = record;
119
- await this.request(new URL(`-/npm/v1/tokens/token/${key}`, registry), { useCache: false, method: 'DELETE' });
120
- }
121
- await deleteToken(registry, this.identity);
122
- }
123
- /**
124
- * Log into the registry specified
125
- *
126
- * Does not return the token or expose it, just saves to the auth keychain
127
- * and returns void if it worked. Otherwise, error is raised.
128
- */
129
- async login(registry) {
130
- // - make POST to '/-/v1/login'
131
- // - include a body of {} and npm-auth-type:web
132
- // - get a {doneUrl, authUrl}
133
- // - open the authUrl
134
- // - hang on the doneUrl until done
135
- //
136
- // if that fails: fall back to couchdb login
137
- const webLoginURL = new URL('-/v1/login', registry);
138
- const response = await this.request(webLoginURL, {
139
- method: 'POST',
140
- useCache: false,
141
- headers: {
142
- 'content-type': 'application/json',
143
- 'npm-auth-type': 'web',
144
- },
145
- body: '{}',
146
- });
147
- if (response.statusCode === 200) {
148
- const challenge = getWebAuthChallenge(response.json());
149
- if (challenge) {
150
- const result = await this.webAuthOpener(challenge);
151
- await setToken(registry, `Bearer ${result.token}`, this.identity);
152
- return;
153
- }
154
- }
155
- /* c8 ignore start */
156
- // TODO: fall back to username/password login, and/or couchdb PUT login
157
- throw error('Failed to perform web login', { response });
158
- }
159
- /* c8 ignore stop */
160
- /**
161
- * Given a {@link WebAuthChallenge}, open the `authUrl` in a browser and
162
- * hang on the `doneUrl` until it returns a {@link TokenResponse} object.
163
- */
164
- async webAuthOpener({ doneUrl, authUrl }) {
165
- const ac = new AbortController();
166
- const { signal } = ac;
167
- /* c8 ignore start - race condition */
168
- const [result] = await Promise.all([
169
- this.#checkLogin(doneUrl, { signal }).then(result => {
170
- ac.abort();
171
- return result;
172
- }),
173
- urlOpen(authUrl, { signal }).catch((er) => {
174
- if (asError(er).name === 'AbortError')
175
- return;
176
- ac.abort();
177
- throw er;
178
- }),
179
- ]);
180
- /* c8 ignore stop */
181
- return result;
182
- }
183
- async #checkLogin(url, options = {}) {
184
- const response = await this.request(url, {
185
- ...options,
186
- useCache: false,
187
- });
188
- const { signal } = options;
189
- if (response.statusCode === 202) {
190
- const rt = response.getHeaderString('retry-after');
191
- const retryAfter = rt ? Number(rt) : -1;
192
- if (retryAfter > 0) {
193
- await setTimeout(retryAfter * 1000, null, { signal });
194
- }
195
- return await this.#checkLogin(url, options);
196
- }
197
- if (response.statusCode === 200) {
198
- const token = getTokenResponse(response.json());
199
- if (token)
200
- return token;
201
- }
202
- throw error('Invalid response from web login endpoint', {
203
- response,
204
- });
205
- }
206
- async request(url, options = {}) {
207
- const u = typeof url === 'string' ? new URL(url) : url;
208
- const { method = 'GET', integrity, redirections = new Set(), signal, otp = (process.env.VLT_OTP ?? '').trim(), staleWhileRevalidate = true, } = options;
209
- let { trustIntegrity } = options;
210
- const m = isCacheableMethod(method) ? method : undefined;
211
- const { useCache = !!m } = options;
212
- signal?.throwIfAborted();
213
- // first, try to get from the cache before making any request.
214
- const { origin } = u;
215
- const key = `${method !== 'GET' ? method + ' ' : ''}${u}`;
216
- const buffer = useCache ?
217
- await this.cache.fetch(key, { context: { integrity } })
218
- : undefined;
219
- const entry = buffer ? CacheEntry.decode(buffer) : undefined;
220
- if (entry?.valid) {
221
- logRequest(url, 'cache');
222
- return entry;
223
- }
224
- if (staleWhileRevalidate && entry?.staleWhileRevalidate && m) {
225
- // revalidate while returning the stale entry
226
- register(dirname(this.cache.path()), m, url);
227
- logRequest(url, 'stale');
228
- return entry;
229
- }
230
- logRequest(url, 'start');
231
- // either no cache entry, or need to revalidate before use.
232
- setCacheHeaders(options, entry);
233
- redirections.add(String(url));
234
- Object.assign(options, {
235
- path: u.pathname.replace(/\/+$/, '') + u.search,
236
- ...agentOptions,
237
- });
238
- options.origin = u.origin;
239
- options.headers = addHeader(addHeader(options.headers, 'accept-encoding', 'gzip;q=1.0, identity;q=0.5'), 'user-agent', userAgent);
240
- if (otp) {
241
- options.headers = addHeader(options.headers, 'npm-otp', otp);
242
- }
243
- if (integrity) {
244
- options.headers = addHeader(options.headers, 'accept-integrity', integrity);
245
- }
246
- options.method = options.method ?? 'GET';
247
- // will remove if we don't have a token.
248
- options.headers = addHeader(options.headers, 'authorization', await getToken(origin, this.identity));
249
- let response = null;
250
- try {
251
- response = await this.agent.request(options);
252
- /* c8 ignore start */
253
- }
254
- catch (er) {
255
- // Rethrow so we get a better stack trace
256
- throw error('Request failed', {
257
- code: 'EREQUEST',
258
- cause: er,
259
- url,
260
- method,
261
- });
262
- }
263
- /* c8 ignore stop */
264
- const result = await this.#handleResponse(u, options, response, entry);
265
- if (result.getHeader('integrity')) {
266
- trustIntegrity = true;
267
- }
268
- if (result.isGzip && !trustIntegrity) {
269
- result.checkIntegrity({ url });
270
- }
271
- if (useCache) {
272
- // Get the encoded buffer from the cache entry
273
- const buffer = result.encode();
274
- this.cache.set(key, Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength), {
275
- integrity: result.integrity,
276
- });
277
- }
278
- return result;
279
- }
280
- async #handleResponse(url, options, response, entry) {
281
- if (handle304Response(response, entry))
282
- return entry;
283
- if (response.statusCode === 401) {
284
- const repeatRequest = await otplease(this, options, response);
285
- if (repeatRequest)
286
- return await this.request(url, repeatRequest);
287
- }
288
- const h = [];
289
- for (const [key, value] of Object.entries(response.headers)) {
290
- /* c8 ignore start - theoretical */
291
- if (Array.isArray(value)) {
292
- h.push(getEncondedValue(key), getEncondedValue(value.join(', ')));
293
- /* c8 ignore stop */
294
- }
295
- else if (typeof value === 'string') {
296
- h.push(getEncondedValue(key), getEncondedValue(value));
297
- }
298
- }
299
- const { integrity, trustIntegrity } = options;
300
- const result = new CacheEntry(
301
- /* c8 ignore next - should always have a status code */
302
- response.statusCode || 200, h, {
303
- integrity,
304
- trustIntegrity,
305
- 'stale-while-revalidate-factor': this.staleWhileRevalidateFactor,
306
- contentLength: response.headers['content-length'] ?
307
- Number(response.headers['content-length'])
308
- : /* c8 ignore next */ undefined,
309
- });
310
- if (isRedirect(result)) {
311
- response.body.resume();
312
- const [nextURL, nextOptions] = redirect(options, result, url);
313
- if (nextOptions && nextURL) {
314
- return await this.request(nextURL, nextOptions);
315
- }
316
- return result;
317
- }
318
- response.body.on('data', (chunk) => result.addBody(chunk));
319
- return await new Promise((res, rej) => {
320
- response.body.on('error', rej);
321
- response.body.on('end', () => res(result));
322
- });
323
- }
324
- }
325
- //# sourceMappingURL=index.js.map