@wener/utils 1.1.25 → 1.1.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +9 -9
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/server.cjs +1 -1
- package/dist/cjs/server.cjs.map +1 -1
- package/dist/esm/index.js +11 -11
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/server.js +1 -1
- package/dist/esm/server.js.map +1 -1
- package/dist/system/index.js +8 -8
- package/dist/system/index.js.map +1 -1
- package/dist/system/server.js +1 -1
- package/dist/system/server.js.map +1 -1
- package/lib/crypto/hashing.js +1 -1
- package/lib/crypto/hashing.js.map +1 -1
- package/lib/fetch/createFetchWith.js.map +1 -1
- package/lib/{servers/fetch → fetch}/createFetchWithRetry.js +1 -1
- package/lib/fetch/createFetchWithRetry.js.map +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/server.js +0 -1
- package/lib/server.js.map +1 -1
- package/package.json +1 -1
- package/src/crypto/hashing.ts +1 -1
- package/src/fetch/createFetchWith.ts +1 -1
- package/src/{servers/fetch → fetch}/createFetchWithRetry.ts +3 -3
- package/src/fetch/index.ts +1 -0
- package/src/index.ts +9 -1
- package/src/server.ts +0 -1
- package/src/typedoc.ts +2 -1
- package/lib/servers/fetch/createFetchWithRetry.js.map +0 -1
package/dist/system/server.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
System.register(["./getGlobalThis-8951eb0e.js","node:crypto","node:fs","node:path","node:url"],function(
|
|
1
|
+
System.register(["./getGlobalThis-8951eb0e.js","node:crypto","node:fs","node:path","node:url"],function(f,o){"use strict";var y,l,h,i,d;return{setters:[function(e){y=e.g},function(e){l=e.createHash},function(e){h=e.default},function(e){i=e.default},function(e){d=e.fileURLToPath}],execute:function(){f({createFetchWithProxyByUndici:p,getPackageDir:k,md5:w,polyfillCrypto:e});async function e(){const t=y();return"crypto"in t?!1:(t.crypto=(await o.import("node:crypto")).webcrypto,!0)}function p({proxy:t,token:S,fetch:c,undici:g}={}){if(!t)return c||globalThis.fetch;let a;return async(...m)=>{const s=m[1]||={};{const r=s.body;typeof r=="object"&&r&&(r instanceof ReadableStream||Symbol.asyncIterator in r)&&(s.duplex||="half")}if(!a){let r=t,u=S;{let n;try{n=new URL(t)}catch{}!u&&n&&(n.username||n.password)&&(u=`Basic ${btoa(`${n.username||""}:${n.password}`)}`,n.username="",n.password="",r=n.toString())}g||=o.import("undici");const b=await g,T=b.ProxyAgent;c||=b.fetch,a=new T({uri:r,token:u})}return s.dispatcher=a,await c(...m)}}const U=f("createFetchWithProxy",p);function w(t){return l("md5").update(t).digest("hex")}const x=d(o.meta.url),P=i.dirname(x);function k(t=P){for(;!h.existsSync(i.join(t,"package.json"));)if(t=i.resolve(t,".."),t==="/")return;return t}}}});
|
|
2
2
|
//# sourceMappingURL=server.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sources":["../../src/servers/polyfill/polyfillCrypto.ts","../../src/servers/fetch/createFetchWithProxyByUndici.ts","../../src/servers/fetch/createFetchWithProxy.ts","../../src/servers/fetch/createFetchWithRetry.ts","../../src/servers/crypto/md5.ts","../../src/servers/getPackageDir.ts"],"sourcesContent":["import { getGlobalThis } from '../../isomorphics/getGlobalThis';\n\nexport async function polyfillCrypto() {\n const globalThis = getGlobalThis();\n if ('crypto' in globalThis) {\n return false;\n }\n (globalThis as any).crypto = (await import('node:crypto')).webcrypto as Crypto;\n return true;\n}\n","import { MaybePromise } from '../../asyncs/MaybePromise';\nimport { FetchLike } from '../../fetch';\n\nexport function createFetchWithProxyByUndici({\n proxy,\n token: _token,\n fetch,\n undici,\n}: {\n proxy?: string;\n token?: string;\n fetch?: FetchLike;\n undici?: MaybePromise<{ fetch: any; ProxyAgent: any }>;\n} = {}): FetchLike {\n if (!proxy) {\n return fetch || globalThis.fetch;\n }\n let agent: any;\n // https://github.com/nodejs/undici/blob/main/docs/best-practices/proxy.md\n return async (...args) => {\n const init = (args[1] ||= {}) as RequestInit & {\n duplex?: string;\n dispatcher?: any;\n };\n {\n const body = init.body;\n if (typeof body === 'object' && body && (body instanceof ReadableStream || Symbol.asyncIterator in body)) {\n // request.duplex must be set if request.body is ReadableStream or Async Iterables\n init.duplex ||= 'half';\n }\n }\n if (!agent) {\n let uri = proxy;\n let token = _token;\n {\n let u: URL | undefined;\n try {\n u = new URL(proxy);\n } catch (e) {}\n if (!token && u && (u.username || u.password)) {\n token = `Basic ${btoa(`${u.username || ''}:${u.password}`)}`;\n u.username = '';\n u.password = '';\n uri = u.toString();\n }\n }\n // if in next use 'next/dist/compiled/undici'\n undici ||= import('undici');\n const mod = await undici;\n const ProxyAgent = mod.ProxyAgent as new (_: any) => any;\n fetch ||= mod.fetch as FetchLike;\n // https://github.com/nodejs/undici/blob/main/docs/api/ProxyAgent.md\n agent = new ProxyAgent({\n uri,\n token,\n });\n // https://github.com/nodejs/node/issues/43187#issuecomment-1134634174\n // (global as any)[Symbol.for('undici.globalDispatcher.1')] = agent;\n // fixme should unwrap error https://github.com/nodejs/undici/issues/1248\n }\n init.dispatcher = agent;\n return await fetch!(...args);\n };\n}\n","import { createFetchWithProxyByUndici } from './createFetchWithProxyByUndici';\n\nexport const createFetchWithProxy = createFetchWithProxyByUndici;\n","import { FetchLike } from '../../fetch';\nimport { getGlobalThis } from '../../isomorphics/getGlobalThis';\n\ntype RequestDelayFunction = (attempt: number, error: Error | null, response: Response | null) => number;\ntype RequestRetryOnFunction = (\n attempt: number,\n error: Error | null,\n response: Response | null,\n) => boolean | Promise<boolean>;\n\nexport interface FetchWithRetryOptions {\n fetch?: FetchLike;\n retries?: number;\n retryDelay?: number | RequestDelayFunction;\n retryOn?: number[] | RequestRetryOnFunction;\n}\n\nexport function createFetchWithRetry({\n fetch = getGlobalThis().fetch,\n retries = 3,\n retryDelay = 1000,\n retryOn = [],\n}: FetchWithRetryOptions = {}): FetchLike {\n // https://github.com/jonbern/fetch-retry/blob/master/index.js\n\n return function fetchRetry(input: string | Request, init?: RequestInit) {\n return new Promise(function (resolve, reject) {\n var wrappedFetch = function (attempt: number) {\n // As of node 18, this is no longer needed since node comes with native support for fetch:\n /* istanbul ignore next */\n var _input = typeof Request !== 'undefined' && input instanceof Request ? input.clone() : input;\n fetch(_input, init)\n .then(function (response) {\n if (Array.isArray(retryOn) && retryOn.indexOf(response.status) === -1) {\n resolve(response);\n } else if (typeof retryOn === 'function') {\n try {\n return Promise.resolve(retryOn(attempt, null, response))\n .then(function (retryOnResponse) {\n if (retryOnResponse) {\n retry(attempt, null, response);\n } else {\n resolve(response);\n }\n })\n .catch(reject);\n } catch (error) {\n reject(error);\n }\n } else {\n if (attempt < retries) {\n retry(attempt, null, response);\n } else {\n resolve(response);\n }\n }\n return;\n })\n .catch(function (error) {\n if (typeof retryOn === 'function') {\n try {\n // eslint-disable-next-line no-undef\n Promise.resolve(retryOn(attempt, error, null))\n .then(function (retryOnResponse) {\n if (retryOnResponse) {\n retry(attempt, error, null);\n } else {\n reject(error);\n }\n })\n .catch(function (error) {\n reject(error);\n });\n } catch (error) {\n reject(error);\n }\n } else if (attempt < retries) {\n retry(attempt, error, null);\n } else {\n reject(error);\n }\n });\n };\n\n function retry(attempt: number, error: any, response: Response | null) {\n let delay = typeof retryDelay === 'function' ? retryDelay(attempt, error, response) : retryDelay;\n setTimeout(function () {\n wrappedFetch(++attempt);\n }, delay);\n }\n\n wrappedFetch(0);\n });\n };\n}\n","import { createHash } from 'node:crypto';\n\nexport function md5(input: Buffer | string) {\n return createHash('md5').update(input).digest('hex') as string;\n}\n","import fs from 'node:fs';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\nexport function getPackageDir(currentDir: string = __dirname) {\n while (!fs.existsSync(path.join(currentDir, 'package.json'))) {\n currentDir = path.resolve(currentDir, '..');\n if (currentDir === '/') {\n return undefined;\n }\n }\n return currentDir;\n}\n"],"names":["polyfillCrypto","globalThis","getGlobalThis","module","createFetchWithProxyByUndici","proxy","_token","fetch","undici","agent","args","init","body","uri","token","u","mod","ProxyAgent","createFetchWithProxy","createFetchWithRetry","retries","retryDelay","retryOn","input","resolve","reject","wrappedFetch","attempt","_input","response","retryOnResponse","retry","error","delay","md5","createHash","__filename","fileURLToPath","__dirname","path","getPackageDir","currentDir","fs"],"mappings":"6YAEA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAsBA,CAAiB,CAAA,CAAA,CACrC,CAAMC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAaC,CAAc,CAAA,CAAA,CACjC,CAAI,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAYD,CACP,CAAA,CAAA,CAAA,CAAA,CAERA,CAAmB,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAU,CAAaE,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAa,GAAG,CACpD,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CACT,CCNO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAASC,CAA6B,CAAA,CAC3C,CAAAC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CACA,CAAOC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CACP,CAAAC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CACA,CAAAC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA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AAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAU,CAElC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAASI,CAAcC,CAAAA,CAAAA,CAAqBH,CAAW,CAAA,CAC5D,CAAO,CAAA,CAAA,CAAA,CAAA,CAACI,CAAG,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAWH,CAAK,CAAA,CAAA,CAAA,CAAA,CAAA,CAAKE,CAAY,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAc,CAAC,CAAA,CAAA,CAEzD,CADAA,CAAAA,CAAAA,CAAAA,CAAaF,CAAK,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAQE,CAAY,CAAA,CAAA,CAAA,CAAA,CAAI,CACtCA,CAAAA,CAAAA,CAAAA,CAAAA,CAAe,CACjB,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAGJ,CAAOA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CACT;"}
|
|
1
|
+
{"version":3,"file":"server.js","sources":["../../src/servers/polyfill/polyfillCrypto.ts","../../src/servers/fetch/createFetchWithProxyByUndici.ts","../../src/servers/fetch/createFetchWithProxy.ts","../../src/servers/crypto/md5.ts","../../src/servers/getPackageDir.ts"],"sourcesContent":["import { getGlobalThis } from '../../isomorphics/getGlobalThis';\n\nexport async function polyfillCrypto() {\n const globalThis = getGlobalThis();\n if ('crypto' in globalThis) {\n return false;\n }\n (globalThis as any).crypto = (await import('node:crypto')).webcrypto as Crypto;\n return true;\n}\n","import { MaybePromise } from '../../asyncs/MaybePromise';\nimport { FetchLike } from '../../fetch';\n\nexport function createFetchWithProxyByUndici({\n proxy,\n token: _token,\n fetch,\n undici,\n}: {\n proxy?: string;\n token?: string;\n fetch?: FetchLike;\n undici?: MaybePromise<{ fetch: any; ProxyAgent: any }>;\n} = {}): FetchLike {\n if (!proxy) {\n return fetch || globalThis.fetch;\n }\n let agent: any;\n // https://github.com/nodejs/undici/blob/main/docs/best-practices/proxy.md\n return async (...args) => {\n const init = (args[1] ||= {}) as RequestInit & {\n duplex?: string;\n dispatcher?: any;\n };\n {\n const body = init.body;\n if (typeof body === 'object' && body && (body instanceof ReadableStream || Symbol.asyncIterator in body)) {\n // request.duplex must be set if request.body is ReadableStream or Async Iterables\n init.duplex ||= 'half';\n }\n }\n if (!agent) {\n let uri = proxy;\n let token = _token;\n {\n let u: URL | undefined;\n try {\n u = new URL(proxy);\n } catch (e) {}\n if (!token && u && (u.username || u.password)) {\n token = `Basic ${btoa(`${u.username || ''}:${u.password}`)}`;\n u.username = '';\n u.password = '';\n uri = u.toString();\n }\n }\n // if in next use 'next/dist/compiled/undici'\n undici ||= import('undici');\n const mod = await undici;\n const ProxyAgent = mod.ProxyAgent as new (_: any) => any;\n fetch ||= mod.fetch as FetchLike;\n // https://github.com/nodejs/undici/blob/main/docs/api/ProxyAgent.md\n agent = new ProxyAgent({\n uri,\n token,\n });\n // https://github.com/nodejs/node/issues/43187#issuecomment-1134634174\n // (global as any)[Symbol.for('undici.globalDispatcher.1')] = agent;\n // fixme should unwrap error https://github.com/nodejs/undici/issues/1248\n }\n init.dispatcher = agent;\n return await fetch!(...args);\n };\n}\n","import { createFetchWithProxyByUndici } from './createFetchWithProxyByUndici';\n\nexport const createFetchWithProxy = createFetchWithProxyByUndici;\n","import { createHash } from 'node:crypto';\n\nexport function md5(input: Buffer | string) {\n return createHash('md5').update(input).digest('hex') as string;\n}\n","import fs from 'node:fs';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\nexport function getPackageDir(currentDir: string = __dirname) {\n while (!fs.existsSync(path.join(currentDir, 'package.json'))) {\n currentDir = path.resolve(currentDir, '..');\n if (currentDir === '/') {\n return undefined;\n }\n }\n return currentDir;\n}\n"],"names":["polyfillCrypto","globalThis","getGlobalThis","module","createFetchWithProxyByUndici","proxy","_token","fetch","undici","agent","args","init","body","uri","token","u","mod","ProxyAgent","createFetchWithProxy","md5","input","createHash","__filename","fileURLToPath","__dirname","path","getPackageDir","currentDir","fs"],"mappings":"uXAEA,CAAsBA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAiB,CACrC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAMC,CAAaC,CAAAA,CAAAA,CAAc,EACjC,CAAI,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAYD,CACP,CAAA,CAAA,CAAA,CAAA,CAERA,EAAmB,CAAU,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAaE,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,aAAa,CAAG,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CACpD,CACT,CAAA,CAAA,CCNO,CAASC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAA6B,CAC3C,CAAA,CAAA,CAAA,CAAA,CAAA,CAAAC,EACA,CAAOC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CACP,CAAAC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CACA,OAAAC,CACF,CAAA,CAKI,CAAA,CAAA,CAAe,CACjB,CAAI,CAAA,CAAA,CAACH,CACH,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAOE,CAAS,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,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CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAWH,EAAK,CAAKE,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAY,CAAc,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAC,GAEzD,CADAA,CAAAA,CAAAA,CAAAA,CAAaF,CAAK,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAQE,EAAY,CAAI,CAAA,CAAA,CAAA,CAAA,CACtCA,CAAe,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CACjB,OAGJ,CAAOA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CACT;"}
|
package/lib/crypto/hashing.js
CHANGED
|
@@ -14,7 +14,7 @@ function sha512(s, o) {
|
|
|
14
14
|
}
|
|
15
15
|
function digestOf(a, s, o) {
|
|
16
16
|
let buffer = crypto.subtle.digest(a, binaryOf(s));
|
|
17
|
-
return o ? buffer.then((v) => encode(v, o)) :
|
|
17
|
+
return o ? buffer.then((v) => encode(v, o)) : buffer;
|
|
18
18
|
}
|
|
19
19
|
function binaryOf(s) {
|
|
20
20
|
if (typeof s === "string") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hashing.js","sources":["../../src/crypto/hashing.ts"],"sourcesContent":["import { ArrayBuffers } from '../io/ArrayBuffers';\n\nexport function sha1(s: BinaryLike, o?: undefined): Promise<Buffer>;\nexport function sha1(s: BinaryLike, o: 'hex' | 'base64'): Promise<string>;\n\nexport function sha1(s: BinaryLike, o?: DigestOptions) {\n return digestOf('SHA-1', s, o);\n}\n\nexport function sha256(s: BinaryLike, o?: undefined): Promise<Buffer>;\nexport function sha256(s: BinaryLike, o: 'hex' | 'base64'): Promise<string>;\n\nexport function sha256(s: BinaryLike, o?: DigestOptions) {\n return digestOf('SHA-256', s, o);\n}\n\nexport function sha384(s: BinaryLike, o?: undefined): Promise<Buffer>;\nexport function sha384(s: BinaryLike, o: 'hex' | 'base64'): Promise<string>;\n\nexport function sha384(s: BinaryLike, o?: DigestOptions) {\n return digestOf('SHA-384', s, o);\n}\n\nexport function sha512(s: BinaryLike, o?: undefined): Promise<Buffer>;\nexport function sha512(s: BinaryLike, o: 'hex' | 'base64'): Promise<string>;\n\nexport function sha512(s: BinaryLike, o?: DigestOptions) {\n return digestOf('SHA-512', s, o);\n}\n\nfunction digestOf(a: string, s: BinaryLike, o?: DigestOptions) {\n let buffer = crypto.subtle.digest(a, binaryOf(s));\n return o ? buffer.then((v) => encode(v, o)) :
|
|
1
|
+
{"version":3,"file":"hashing.js","sources":["../../src/crypto/hashing.ts"],"sourcesContent":["import { ArrayBuffers } from '../io/ArrayBuffers';\n\nexport function sha1(s: BinaryLike, o?: undefined): Promise<Buffer>;\nexport function sha1(s: BinaryLike, o: 'hex' | 'base64'): Promise<string>;\n\nexport function sha1(s: BinaryLike, o?: DigestOptions) {\n return digestOf('SHA-1', s, o);\n}\n\nexport function sha256(s: BinaryLike, o?: undefined): Promise<Buffer>;\nexport function sha256(s: BinaryLike, o: 'hex' | 'base64'): Promise<string>;\n\nexport function sha256(s: BinaryLike, o?: DigestOptions) {\n return digestOf('SHA-256', s, o);\n}\n\nexport function sha384(s: BinaryLike, o?: undefined): Promise<Buffer>;\nexport function sha384(s: BinaryLike, o: 'hex' | 'base64'): Promise<string>;\n\nexport function sha384(s: BinaryLike, o?: DigestOptions) {\n return digestOf('SHA-384', s, o);\n}\n\nexport function sha512(s: BinaryLike, o?: undefined): Promise<Buffer>;\nexport function sha512(s: BinaryLike, o: 'hex' | 'base64'): Promise<string>;\n\nexport function sha512(s: BinaryLike, o?: DigestOptions) {\n return digestOf('SHA-512', s, o);\n}\n\nfunction digestOf(a: string, s: BinaryLike, o?: DigestOptions) {\n let buffer = crypto.subtle.digest(a, binaryOf(s));\n return o ? buffer.then((v) => encode(v, o)) : buffer;\n}\n\nexport type DigestOptions =\n | 'hex'\n | 'base64'\n | {\n encoding: 'hex' | 'base64';\n };\n\ntype BinaryLike = string | BufferSource;\n\nfunction binaryOf(s: BinaryLike) {\n // ArrayBuffer, TypedArray, DataView\n if (typeof s === 'string') {\n return new TextEncoder().encode(s);\n }\n // ArrayBuffer, Buffer, TypedArray, DataView\n return s;\n}\n\nfunction encode(buf: BufferSource, o?: DigestOptions) {\n if (o) {\n switch (o) {\n case 'hex':\n case 'base64':\n return ArrayBuffers.toString(buf, o);\n }\n }\n return buf;\n}\n\ntype StringEncoding = 'hex' | 'base64';\ntype IsStringCoding<T> = T extends StringEncoding ? true : T extends { encoding: StringEncoding } ? true : false;\n\nexport function hmac<O extends DigestOptions>(\n hash: 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512' | 'sha1' | 'sha256' | 'sha384' | 'sha512',\n key: BinaryLike | CryptoKey,\n data: BinaryLike,\n o?: O,\n): Promise<IsStringCoding<O> extends true ? string : Buffer>;\n\nexport async function hmac(\n hash: 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512' | 'sha1' | 'sha256' | 'sha384' | 'sha512',\n key: BinaryLike | CryptoKey,\n data: BinaryLike,\n o?: DigestOptions,\n) {\n let ck =\n key instanceof CryptoKey\n ? key\n : await crypto.subtle.importKey(\n 'raw',\n binaryOf(key),\n {\n name: 'HMAC',\n hash: {\n name: normalizeHash(hash),\n },\n },\n false,\n ['sign'],\n );\n let buffer = await crypto.subtle.sign(\n {\n name: 'HMAC',\n hash: {\n name: hash,\n },\n },\n ck,\n binaryOf(data),\n );\n\n return encode(buffer, o);\n}\n\nfunction normalizeHash(hash: string) {\n return hash.replace(/^sha/i, 'SHA-');\n}\n"],"names":[],"mappings":";;AAKgB,SAAA,IAAA,CAAK,GAAe,CAAmB,EAAA;AACrD,EAAO,OAAA,QAAA,CAAS,OAAS,EAAA,CAAA,EAAG,CAAC,CAAA,CAAA;AAC/B,CAAA;AAKgB,SAAA,MAAA,CAAO,GAAe,CAAm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SAAA,GACX,GACA,GAAA,MAAM,OAAO,MAAO,CAAA,SAAA;AAAA,IAClB,KAAA;AAAA,IACA,SAAS,GAAG,CAAA;AAAA,IACZ;AAAA,MACE,IAAM,EAAA,MAAA;AAAA,MACN,IAAM,EAAA;AAAA,QACJ,IAAA,EAAM,cAAc,IAAI,CAAA;AAAA,OAC1B;AAAA,KACF;AAAA,IACA,KAAA;AAAA,IACA,CAAC,MAAM,CAAA;AAAA,GACT,CAAA;AACN,EAAI,IAAA,MAAA,GAAS,MAAM,MAAA,CAAO,MAAO,CAAA,IAAA;AAAA,IAC/B;AAAA,MACE,IAAM,EAAA,MAAA;AAAA,MACN,IAAM,EAAA;AAAA,QACJ,IAAM,EAAA,IAAA;AAAA,OACR;AAAA,KACF;AAAA,IACA,EAAA;AAAA,IACA,SAAS,IAAI,CAAA;AAAA,GACf,CAAA;AAEA,EAAO,OAAA,MAAA,CAAO,QAAQ,CAAC,CAAA,CAAA;AACzB,CAAA;AAEA,SAAS,cAAc,IAAc,EAAA;AACnC,EAAO,OAAA,IAAA,CAAK,OAAQ,CAAA,OAAA,EAAS,MAAM,CAAA,CAAA;AACrC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFetchWith.js","sources":["../../src/fetch/createFetchWith.ts"],"sourcesContent":["import { MaybePromise } from '../asyncs/MaybePromise';\nimport { getGlobalThis } from '../isomorphics/getGlobalThis';\nimport { type FetchLike } from './types';\n\nexport function createFetchWith({\n fetch = getGlobalThis().fetch,\n onRequest = (ctx) => ctx.next(ctx.url, ctx.req),\n onResponse = (ctx) => ctx.res,\n}: {\n fetch?: FetchLike;\n onRequest?: (ctx: {\n url: string;\n req: RequestInit;\n next: (url: string, req: RequestInit) => Promise<Response>;\n }) => MaybePromise<Response | void>;\n onResponse?: (ctx: { url: string; req: RequestInit; res: Response }) => MaybePromise<Response>;\n}) {\n return async (urlOrRequest: string | Request, init?: RequestInit & { fetch?: FetchLike }) => {\n const url = String(urlOrRequest);\n let req = init || {};\n const nextFetch = req.fetch || fetch;\n const res =\n (await onRequest({\n url,\n req,\n next: (url, init) => {\n req = init;\n return nextFetch(url, init);\n },\n })) ?? (await nextFetch(url, init));\n return onResponse({ url, req, res });\n };\n}\n"],"names":["url","init"],"mappings":";;AAIO,SAAS,eAAgB,CAAA;AAAA,EAC9B,KAAA,GAAQ,eAAgB,CAAA,KAAA;AAAA,EACxB,SAAA,GAAY,CAAC,GAAQ,KAAA,GAAA,CAAI,KAAK,GAAI,CAAA,GAAA,EAAK,IAAI,GAAG,CAAA;AAAA,EAC9C,UAAA,GAAa,CAAC,GAAA,KAAQ,GAAI,CAAA,GAAA;AAC5B,CAQG,EAAA;AACD,EAAO,OAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"createFetchWith.js","sources":["../../src/fetch/createFetchWith.ts"],"sourcesContent":["import { MaybePromise } from '../asyncs/MaybePromise';\nimport { getGlobalThis } from '../isomorphics/getGlobalThis';\nimport { type FetchLike } from './types';\n\nexport function createFetchWith({\n fetch = getGlobalThis().fetch,\n onRequest = (ctx) => ctx.next(ctx.url, ctx.req),\n onResponse = (ctx) => ctx.res,\n}: {\n fetch?: FetchLike;\n onRequest?: (ctx: {\n url: string;\n req: RequestInit;\n next: (url: string, req: RequestInit) => Promise<Response>;\n }) => MaybePromise<Response | void>;\n onResponse?: (ctx: { url: string; req: RequestInit; res: Response }) => MaybePromise<Response>;\n}) {\n return async (urlOrRequest: string | URL | Request, init?: RequestInit & { fetch?: FetchLike }) => {\n const url = String(urlOrRequest);\n let req = init || {};\n const nextFetch = req.fetch || fetch;\n const res =\n (await onRequest({\n url,\n req,\n next: (url, init) => {\n req = init;\n return nextFetch(url, init);\n },\n })) ?? (await nextFetch(url, init));\n return onResponse({ url, req, res });\n };\n}\n"],"names":["url","init"],"mappings":";;AAIO,SAAS,eAAgB,CAAA;AAAA,EAC9B,KAAA,GAAQ,eAAgB,CAAA,KAAA;AAAA,EACxB,SAAA,GAAY,CAAC,GAAQ,KAAA,GAAA,CAAI,KAAK,GAAI,CAAA,GAAA,EAAK,IAAI,GAAG,CAAA;AAAA,EAC9C,UAAA,GAAa,CAAC,GAAA,KAAQ,GAAI,CAAA,GAAA;AAC5B,CAQG,EAAA;AACD,EAAO,OAAA,OAAO,cAAsC,IAA+C,KAAA;AAjBrG,IAAA,IAAA,EAAA,CAAA;AAkBI,IAAM,MAAA,GAAA,GAAM,OAAO,YAAY,CAAA,CAAA;AAC/B,IAAI,IAAA,GAAA,GAAM,QAAQ,EAAC,CAAA;AACnB,IAAM,MAAA,SAAA,GAAY,IAAI,KAAS,IAAA,KAAA,CAAA;AAC/B,IAAM,MAAA,GAAA,GAAA,CACH,WAAM,SAAU,CAAA;AAAA,MACf,GAAA;AAAA,MACA,GAAA;AAAA,MACA,IAAA,EAAM,CAACA,IAAAA,EAAKC,KAAS,KAAA;AACnB,QAAMA,GAAAA,GAAAA,KAAAA,CAAAA;AACN,QAAO,OAAA,SAAA,CAAUD,MAAKC,KAAI,CAAA,CAAA;AAAA,OAC5B;AAAA,KACD,CAPA,KAAA,IAAA,GAAA,EAAA,GAOO,MAAM,SAAA,CAAU,KAAK,IAAI,CAAA,CAAA;AACnC,IAAA,OAAO,UAAW,CAAA,EAAE,GAAK,EAAA,GAAA,EAAK,KAAK,CAAA,CAAA;AAAA,GACrC,CAAA;AACF;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createFetchWithRetry.js","sources":["../../src/fetch/createFetchWithRetry.ts"],"sourcesContent":["import { getGlobalThis } from '../isomorphics/getGlobalThis';\nimport { FetchLike } from './types';\n\ntype RequestDelayFunction = (attempt: number, error: Error | null, response: Response | null) => number;\ntype RequestRetryOnFunction = (\n attempt: number,\n error: Error | null,\n response: Response | null,\n) => boolean | Promise<boolean>;\n\nexport interface FetchWithRetryOptions {\n fetch?: FetchLike;\n retries?: number;\n retryDelay?: number | RequestDelayFunction;\n retryOn?: number[] | RequestRetryOnFunction;\n}\n\nexport function createFetchWithRetry({\n fetch = getGlobalThis().fetch,\n retries = 3,\n retryDelay = 1000,\n retryOn = [],\n}: FetchWithRetryOptions = {}): FetchLike {\n // https://github.com/jonbern/fetch-retry/blob/master/index.js\n\n return function fetchRetry(input: string | URL | Request, init?: RequestInit) {\n return new Promise(function (resolve, reject) {\n var wrappedFetch = function (attempt: number) {\n // As of node 18, this is no longer needed since node comes with native support for fetch:\n /* istanbul ignore next */\n var _input = typeof Request !== 'undefined' && input instanceof Request ? input.clone() : input;\n fetch(_input, init)\n .then(function (response) {\n if (Array.isArray(retryOn) && retryOn.indexOf(response.status) === -1) {\n resolve(response);\n } else if (typeof retryOn === 'function') {\n try {\n return Promise.resolve(retryOn(attempt, null, response))\n .then(function (retryOnResponse) {\n if (retryOnResponse) {\n retry(attempt, null, response);\n } else {\n resolve(response);\n }\n })\n .catch(reject);\n } catch (error) {\n reject(error);\n }\n } else {\n if (attempt < retries) {\n retry(attempt, null, response);\n } else {\n resolve(response);\n }\n }\n return;\n })\n .catch(function (error) {\n if (typeof retryOn === 'function') {\n try {\n // eslint-disable-next-line no-undef\n Promise.resolve(retryOn(attempt, error, null))\n .then(function (retryOnResponse) {\n if (retryOnResponse) {\n retry(attempt, error, null);\n } else {\n reject(error);\n }\n })\n .catch(function (error) {\n reject(error);\n });\n } catch (error) {\n reject(error);\n }\n } else if (attempt < retries) {\n retry(attempt, error, null);\n } else {\n reject(error);\n }\n });\n };\n\n function retry(attempt: number, error: any, response: Response | null) {\n let delay = typeof retryDelay === 'function' ? retryDelay(attempt, error, response) : retryDelay;\n setTimeout(function () {\n wrappedFetch(++attempt);\n }, delay);\n }\n\n wrappedFetch(0);\n });\n };\n}\n"],"names":["error"],"mappings":";;AAiBO,SAAS,oBAAqB,CAAA;AAAA,EACnC,KAAA,GAAQ,eAAgB,CAAA,KAAA;AAAA,EACxB,OAAU,GAAA,CAAA;AAAA,EACV,UAAa,GAAA,GAAA;AAAA,EACb,UAAU,EAAC;AACb,CAAA,GAA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;AAAA,KACf,CAAA,CAAA;AAAA,GACH,CAAA;AACF;;;;"}
|
package/lib/index.js
CHANGED
|
@@ -57,6 +57,7 @@ export { createFetchWith } from './fetch/createFetchWith.js';
|
|
|
57
57
|
export { createFetchWithLogging } from './fetch/createFetchWithLogging.js';
|
|
58
58
|
export { dumpRequest } from './fetch/dumpRequest.js';
|
|
59
59
|
export { dumpResponse } from './fetch/dumpResponse.js';
|
|
60
|
+
export { createFetchWithRetry } from './fetch/createFetchWithRetry.js';
|
|
60
61
|
export { default as ms } from './libs/ms.js';
|
|
61
62
|
export { DetailError, Errors } from './errors/Errors.js';
|
|
62
63
|
export { getHttpStatusText, isRetryableHttpStatus } from './http/HttpStatus.js';
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/lib/server.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export { polyfillCrypto } from './servers/polyfill/polyfillCrypto.js';
|
|
2
2
|
export { createFetchWithProxyByUndici } from './servers/fetch/createFetchWithProxyByUndici.js';
|
|
3
3
|
export { createFetchWithProxy } from './servers/fetch/createFetchWithProxy.js';
|
|
4
|
-
export { createFetchWithRetry } from './servers/fetch/createFetchWithRetry.js';
|
|
5
4
|
export { md5 } from './servers/crypto/md5.js';
|
|
6
5
|
export { getPackageDir } from './servers/getPackageDir.js';
|
|
7
6
|
//# sourceMappingURL=server.js.map
|
package/lib/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"server.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
package/package.json
CHANGED
package/src/crypto/hashing.ts
CHANGED
|
@@ -30,7 +30,7 @@ export function sha512(s: BinaryLike, o?: DigestOptions) {
|
|
|
30
30
|
|
|
31
31
|
function digestOf(a: string, s: BinaryLike, o?: DigestOptions) {
|
|
32
32
|
let buffer = crypto.subtle.digest(a, binaryOf(s));
|
|
33
|
-
return o ? buffer.then((v) => encode(v, o)) :
|
|
33
|
+
return o ? buffer.then((v) => encode(v, o)) : buffer;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export type DigestOptions =
|
|
@@ -15,7 +15,7 @@ export function createFetchWith({
|
|
|
15
15
|
}) => MaybePromise<Response | void>;
|
|
16
16
|
onResponse?: (ctx: { url: string; req: RequestInit; res: Response }) => MaybePromise<Response>;
|
|
17
17
|
}) {
|
|
18
|
-
return async (urlOrRequest: string | Request, init?: RequestInit & { fetch?: FetchLike }) => {
|
|
18
|
+
return async (urlOrRequest: string | URL | Request, init?: RequestInit & { fetch?: FetchLike }) => {
|
|
19
19
|
const url = String(urlOrRequest);
|
|
20
20
|
let req = init || {};
|
|
21
21
|
const nextFetch = req.fetch || fetch;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { getGlobalThis } from '../isomorphics/getGlobalThis';
|
|
2
|
+
import { FetchLike } from './types';
|
|
3
3
|
|
|
4
4
|
type RequestDelayFunction = (attempt: number, error: Error | null, response: Response | null) => number;
|
|
5
5
|
type RequestRetryOnFunction = (
|
|
@@ -23,7 +23,7 @@ export function createFetchWithRetry({
|
|
|
23
23
|
}: FetchWithRetryOptions = {}): FetchLike {
|
|
24
24
|
// https://github.com/jonbern/fetch-retry/blob/master/index.js
|
|
25
25
|
|
|
26
|
-
return function fetchRetry(input: string | Request, init?: RequestInit) {
|
|
26
|
+
return function fetchRetry(input: string | URL | Request, init?: RequestInit) {
|
|
27
27
|
return new Promise(function (resolve, reject) {
|
|
28
28
|
var wrappedFetch = function (attempt: number) {
|
|
29
29
|
// As of node 18, this is no longer needed since node comes with native support for fetch:
|
package/src/fetch/index.ts
CHANGED
|
@@ -3,3 +3,4 @@ export { createFetchWith } from './createFetchWith';
|
|
|
3
3
|
export { createFetchWithLogging } from './createFetchWithLogging';
|
|
4
4
|
export { dumpRequest } from './dumpRequest';
|
|
5
5
|
export { dumpResponse } from './dumpResponse';
|
|
6
|
+
export { createFetchWithRetry, type FetchWithRetryOptions } from './createFetchWithRetry';
|
package/src/index.ts
CHANGED
|
@@ -95,7 +95,15 @@ export { PEM } from './crypto/pem/pem';
|
|
|
95
95
|
export { createRandom } from './maths/random';
|
|
96
96
|
|
|
97
97
|
// network
|
|
98
|
-
export {
|
|
98
|
+
export {
|
|
99
|
+
type FetchLike,
|
|
100
|
+
createFetchWith,
|
|
101
|
+
createFetchWithLogging,
|
|
102
|
+
dumpResponse,
|
|
103
|
+
dumpRequest,
|
|
104
|
+
createFetchWithRetry,
|
|
105
|
+
type FetchWithRetryOptions,
|
|
106
|
+
} from './fetch';
|
|
99
107
|
|
|
100
108
|
// bundled
|
|
101
109
|
export { default as ms } from './libs/ms';
|
package/src/server.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export { polyfillCrypto } from './servers/polyfill/polyfillCrypto';
|
|
2
2
|
export { createFetchWithProxyByUndici } from './servers/fetch/createFetchWithProxyByUndici';
|
|
3
3
|
export { createFetchWithProxy } from './servers/fetch/createFetchWithProxy';
|
|
4
|
-
export { createFetchWithRetry, type FetchWithRetryOptions } from './servers/fetch/createFetchWithRetry';
|
|
5
4
|
|
|
6
5
|
export { md5 } from './servers/crypto/md5';
|
|
7
6
|
export { getPackageDir } from './servers/getPackageDir';
|
package/src/typedoc.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createFetchWithRetry.js","sources":["../../../src/servers/fetch/createFetchWithRetry.ts"],"sourcesContent":["import { FetchLike } from '../../fetch';\nimport { getGlobalThis } from '../../isomorphics/getGlobalThis';\n\ntype RequestDelayFunction = (attempt: number, error: Error | null, response: Response | null) => number;\ntype RequestRetryOnFunction = (\n attempt: number,\n error: Error | null,\n response: Response | null,\n) => boolean | Promise<boolean>;\n\nexport interface FetchWithRetryOptions {\n fetch?: FetchLike;\n retries?: number;\n retryDelay?: number | RequestDelayFunction;\n retryOn?: number[] | RequestRetryOnFunction;\n}\n\nexport function createFetchWithRetry({\n fetch = getGlobalThis().fetch,\n retries = 3,\n retryDelay = 1000,\n retryOn = [],\n}: FetchWithRetryOptions = {}): FetchLike {\n // https://github.com/jonbern/fetch-retry/blob/master/index.js\n\n return function fetchRetry(input: string | Request, init?: RequestInit) {\n return new Promise(function (resolve, reject) {\n var wrappedFetch = function (attempt: number) {\n // As of node 18, this is no longer needed since node comes with native support for fetch:\n /* istanbul ignore next */\n var _input = typeof Request !== 'undefined' && input instanceof Request ? input.clone() : input;\n fetch(_input, init)\n .then(function (response) {\n if (Array.isArray(retryOn) && retryOn.indexOf(response.status) === -1) {\n resolve(response);\n } else if (typeof retryOn === 'function') {\n try {\n return Promise.resolve(retryOn(attempt, null, response))\n .then(function (retryOnResponse) {\n if (retryOnResponse) {\n retry(attempt, null, response);\n } else {\n resolve(response);\n }\n })\n .catch(reject);\n } catch (error) {\n reject(error);\n }\n } else {\n if (attempt < retries) {\n retry(attempt, null, response);\n } else {\n resolve(response);\n }\n }\n return;\n })\n .catch(function (error) {\n if (typeof retryOn === 'function') {\n try {\n // eslint-disable-next-line no-undef\n Promise.resolve(retryOn(attempt, error, null))\n .then(function (retryOnResponse) {\n if (retryOnResponse) {\n retry(attempt, error, null);\n } else {\n reject(error);\n }\n })\n .catch(function (error) {\n reject(error);\n });\n } catch (error) {\n reject(error);\n }\n } else if (attempt < retries) {\n retry(attempt, error, null);\n } else {\n reject(error);\n }\n });\n };\n\n function retry(attempt: number, error: any, response: Response | null) {\n let delay = typeof retryDelay === 'function' ? retryDelay(attempt, error, response) : retryDelay;\n setTimeout(function () {\n wrappedFetch(++attempt);\n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