@wener/utils 1.1.15 → 1.1.17

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 (43) hide show
  1. package/dist/cjs/index.cjs +5 -5
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs/server.cjs +1 -1
  4. package/dist/cjs/server.cjs.map +1 -1
  5. package/dist/esm/index.js +5 -5
  6. package/dist/esm/index.js.map +1 -1
  7. package/dist/esm/server.js +1 -1
  8. package/dist/esm/server.js.map +1 -1
  9. package/dist/system/index.js +5 -5
  10. package/dist/system/index.js.map +1 -1
  11. package/dist/system/server.js +1 -1
  12. package/dist/system/server.js.map +1 -1
  13. package/lib/crypto/ulid.js +1 -1
  14. package/lib/crypto/ulid.js.map +1 -1
  15. package/lib/fetch/createFetchWith.js +3 -2
  16. package/lib/fetch/createFetchWith.js.map +1 -1
  17. package/lib/fetch/createFetchWithLogging.js +1 -1
  18. package/lib/fetch/createFetchWithLogging.js.map +1 -1
  19. package/lib/server.js +2 -2
  20. package/lib/servers/createFetchWithProxy.js +1 -7
  21. package/lib/servers/createFetchWithProxy.js.map +1 -1
  22. package/lib/servers/createFetchWithProxyByUndici.js +25 -3
  23. package/lib/servers/createFetchWithProxyByUndici.js.map +1 -1
  24. package/lib/servers/createFetchWithRetry.js +70 -0
  25. package/lib/servers/createFetchWithRetry.js.map +1 -0
  26. package/lib/servers/md5.js +8 -0
  27. package/lib/servers/md5.js.map +1 -0
  28. package/package.json +4 -9
  29. package/src/crypto/md5.d.ts +1 -0
  30. package/src/crypto/md5.js +44 -0
  31. package/src/crypto/ulid.ts +1 -1
  32. package/src/fetch/createFetchWith.ts +7 -6
  33. package/src/fetch/createFetchWithLogging.ts +3 -1
  34. package/src/fetch/index.ts +1 -1
  35. package/src/fetch/types.ts +1 -0
  36. package/src/maths/clamp.ts +1 -0
  37. package/src/server.ts +3 -2
  38. package/src/servers/createFetchWithProxy.ts +1 -10
  39. package/src/servers/createFetchWithProxyByUndici.ts +36 -8
  40. package/src/servers/createFetchWithRetry.ts +95 -0
  41. package/src/servers/md5.ts +5 -0
  42. package/lib/servers/createFetchWithProxyByNodeFetch.js +0 -38
  43. package/lib/servers/createFetchWithProxyByNodeFetch.js.map +0 -1
@@ -1,2 +1,2 @@
1
- System.register(["./getGlobalThis-8951eb0e.js"],function(x,y){"use strict";var h;return{setters:[function(p){h=p.g}],execute:function(){x({createFetchWithProxy:m,createFetchWithProxyByNodeFetch:g,createFetchWithProxyByUndici:b,polyfillBrowser:F,polyfillCrypto:p,polyfillFetch:w,polyfillJsDom:d});async function p(){const e=h();return"crypto"in e?!1:(e.crypto=(await y.import("node:crypto")).webcrypto,!0)}function w(e){if("fetch"in globalThis)return!1;if(e){const{default:t,Response:s,Headers:n,Request:c,AbortError:i,FetchError:a,FormData:r,Blob:f,File:l}=e;return Object.assign(globalThis,{fetch:t,Response:s,Headers:n,Request:c,AbortError:i,FetchError:a,FormData:r,Blob:f,File:l}),!0}return y.import("node-fetch").then(t=>w(t))}async function d(){if(typeof window<"u")return!1;const e=h(),{ResourceLoader:t,JSDOM:s}=await y.import("jsdom");class n{constructor(f={}){const{proxy:l,strictSSL:u,userAgent:o,...O}=f,P=new t({proxy:l,strictSSL:u,userAgent:o});return new s("",Object.assign(O,{resources:P})).window}}const c={},i=(()=>Object.getOwnPropertyNames(new n(c)).filter(r=>typeof e[r]<"u"))();function a(...r){const f=r.filter(o=>Array.isArray(o))[0],l=r.filter(o=>!Array.isArray(o))[0],u=new n(Object.assign({},l,c));return Object.getOwnPropertyNames(u).filter(o=>!i.includes(o)).filter(o=>!(f&&f.indexOf(o)===-1)).filter(o=>{switch(o){case"undefined":return!1}return!0}).forEach(o=>{Object.defineProperty(e,o,{configurable:!0,get:()=>u[o]})}),u}return a({url:"http://localhost"}),!0}async function F(){await p(),await w(),await d()}function g({proxy:e,fetch:t}={}){const s=h();if(!e)return t||s.fetch;let n;const c=s.Request;let i,a;return async(r,f)=>{if(!n){const{default:l}=await y.import("https-proxy-agent");n=l(e)}return i||({Request:i,default:a}=await y.import("node-fetch")),t||=a,r instanceof c?t(new c(r,{agent:n})):r instanceof i?t(new i(r,{agent:n})):t(r,{...f,agent:n})}}function b({proxy:e,fetch:t,undici:s}={}){if(!e)return t||globalThis.fetch;let n;return async(...c)=>{const i=c[1]||={};if(i.body instanceof ReadableStream&&(i.duplex||="half"),!n){s||=y.import("undici");const a=await s,r=a.ProxyAgent;t||=a.fetch,n=new r(e)}return i.dispatcher=n,await t(...c)}}function m({proxy:e,fetch:t}){return e?parseInt(process.versions.node)>=18?b({proxy:e,fetch:t}):g({proxy:e,fetch:t}):t||globalThis.fetch}}}});
1
+ System.register(["./getGlobalThis-8951eb0e.js","node:crypto"],function(b,d){"use strict";var w,m;return{setters:[function(p){w=p.g},function(p){m=p.createHash}],execute:function(){b({createFetchWithProxyByUndici:x,createFetchWithRetry:A,md5:P,polyfillBrowser:O,polyfillCrypto:p,polyfillJsDom:g});async function p(){const o=w();return"crypto"in o?!1:(o.crypto=(await d.import("node:crypto")).webcrypto,!0)}async function g(){if(typeof window<"u")return!1;const o=w(),{ResourceLoader:y,JSDOM:l}=await d.import("jsdom");class c{constructor(i={}){const{proxy:s,strictSSL:r,userAgent:t,...n}=i,a=new y({proxy:s,strictSSL:r,userAgent:t});return new l("",Object.assign(n,{resources:a})).window}}const f={},h=(()=>Object.getOwnPropertyNames(new c(f)).filter(e=>typeof o[e]<"u"))();function u(...e){const i=e.filter(t=>Array.isArray(t))[0],s=e.filter(t=>!Array.isArray(t))[0],r=new c(Object.assign({},s,f));return Object.getOwnPropertyNames(r).filter(t=>!h.includes(t)).filter(t=>!(i&&i.indexOf(t)===-1)).filter(t=>{switch(t){case"undefined":return!1}return!0}).forEach(t=>{Object.defineProperty(o,t,{configurable:!0,get:()=>r[t]})}),r}return u({url:"http://localhost"}),!0}function F(o){if("fetch"in globalThis)return!1;if(o){const{default:y,Response:l,Headers:c,Request:f,AbortError:h,FetchError:u,FormData:e,Blob:i,File:s}=o;return Object.assign(globalThis,{fetch:y,Response:l,Headers:c,Request:f,AbortError:h,FetchError:u,FormData:e,Blob:i,File:s}),!0}return d.import("node-fetch").then(y=>F(y))}async function O(){await p(),await F(),await g()}function x({proxy:o,token:y,fetch:l,undici:c}={}){if(!o)return l||globalThis.fetch;let f;return async(...h)=>{const u=h[1]||={};{const e=u.body;typeof e=="object"&&e&&(e instanceof ReadableStream||Symbol.asyncIterator in e)&&(u.duplex||="half")}if(!f){let e=o,i=y;{let t;try{t=new URL(o)}catch{}!i&&t&&(t.username||t.password)&&(i=`Basic ${btoa(`${t.username||""}:${t.password}`)}`,t.username="",t.password="",e=t.toString())}c||=d.import("undici");const s=await c,r=s.ProxyAgent;l||=s.fetch,f=new r({uri:e,token:i})}return u.dispatcher=f,await l(...h)}}const R=b("createFetchWithProxy",x);function A({fetch:o=w().fetch,retries:y=3,retryDelay:l=1e3,retryOn:c=[]}={}){return function(f,h){return new Promise(function(u,e){var i=function(r){var t=typeof Request<"u"&&f instanceof Request?f.clone():f;o(t,h).then(function(n){if(Array.isArray(c)&&c.indexOf(n.status)===-1)u(n);else if(typeof c=="function")try{return Promise.resolve(c(r,null,n)).then(function(a){a?s(r,null,n):u(n)}).catch(e)}catch(a){e(a)}else r<y?s(r,null,n):u(n)}).catch(function(n){if(typeof c=="function")try{Promise.resolve(c(r,n,null)).then(function(a){a?s(r,n,null):e(n)}).catch(function(a){e(a)})}catch(a){e(a)}else r<y?s(r,n,null):e(n)})};function s(r,t,n){let a=typeof l=="function"?l(r,t,n):l;setTimeout(function(){i(++r)},a)}i(0)})}}function P(o){return m("md5").update(o).digest("hex")}}}});
2
2
  //# sourceMappingURL=server.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","sources":["../../src/servers/polyfillCrypto.ts","../../src/servers/polyfillFetch.ts","../../src/servers/polyfillJsDom.ts","../../src/servers/polyfillBrowser.ts","../../src/servers/createFetchWithProxyByNodeFetch.ts","../../src/servers/createFetchWithProxyByUndici.ts","../../src/servers/createFetchWithProxy.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 type { MaybePromise } from '../asyncs/MaybePromise';\n\nexport function polyfillFetch(nodeFetch: typeof import('node-fetch')): boolean;\nexport function polyfillFetch(nodeFetch?: undefined): Promise<boolean>;\nexport function polyfillFetch(nodeFetch?: typeof import('node-fetch')): MaybePromise<boolean> {\n if ('fetch' in globalThis) {\n return false;\n }\n // sync mode\n if (nodeFetch) {\n const { default: fetch, Response, Headers, Request, AbortError, FetchError, FormData, Blob, File } = nodeFetch;\n Object.assign(globalThis, {\n fetch,\n Response,\n Headers,\n Request,\n AbortError,\n FetchError,\n FormData,\n Blob,\n File,\n });\n // abort controller\n return true;\n }\n return import('node-fetch').then((v) => polyfillFetch(v));\n}\n","import type { ConstructorOptions, ResourceLoaderConstructorOptions } from 'jsdom';\nimport { getGlobalThis } from '../isomorphics/getGlobalThis';\n\nexport async function polyfillJsDom() {\n if (typeof window !== 'undefined') {\n return false;\n }\n\n const globalThis = getGlobalThis();\n\n const { ResourceLoader, JSDOM } = await import('jsdom');\n\n // https://github.com/lukechilds/window/blob/master/src/index.js\n // eslint-disable-next-line @typescript-eslint/no-extraneous-class\n class Window {\n constructor(opts: ResourceLoaderConstructorOptions & ConstructorOptions = {}) {\n const { proxy, strictSSL, userAgent, ...jsdomOpts } = opts;\n const resources = new ResourceLoader({\n proxy,\n strictSSL,\n userAgent,\n });\n return new JSDOM(\n '',\n Object.assign(jsdomOpts, {\n resources,\n }),\n ).window;\n }\n }\n\n // https://github.com/lukechilds/browser-env/blob/master/src/index.js\n // Default jsdom config.\n // These settings must override any custom settings to make sure we can iterate\n // over the window object.\n const defaultJsdomConfig = {\n // features: {\n // FetchExternalResources: false,\n // ProcessExternalResources: false,\n // },\n };\n // IIFE executed on import to return an array of global Node.js properties that\n // conflict with global browser properties.\n const protectedProperties = (() =>\n Object.getOwnPropertyNames(new Window(defaultJsdomConfig)).filter(\n (prop) => typeof globalThis[prop as keyof typeof globalThis] !== 'undefined',\n ))();\n\n function installEnv(...args: any[]) {\n // Sets up global browser environment\n // Extract options from args\n const properties = args.filter((arg: any) => Array.isArray(arg))[0];\n const userJsdomConfig = args.filter((arg: any) => !Array.isArray(arg))[0];\n\n // Create window object\n const window = new Window(Object.assign({}, userJsdomConfig, defaultJsdomConfig));\n\n // Get all global browser properties\n Object.getOwnPropertyNames(window)\n\n // Remove protected properties\n .filter((prop) => !protectedProperties.includes(prop))\n\n // If we're only applying specific required properties remove everything else\n .filter((prop) => !(properties && properties.indexOf(prop) === -1))\n .filter((prop) => {\n switch (prop) {\n case 'undefined':\n return false;\n }\n return true;\n })\n\n // Copy what's left to the Node.js global scope\n .forEach((prop) => {\n // console.debug(`define globalThis.${prop}`);\n Object.defineProperty(globalThis, prop, {\n configurable: true,\n get: () => window[prop as keyof Window] as any,\n });\n });\n\n return window;\n }\n\n installEnv({ url: 'http://localhost' });\n return true;\n}\n","import { polyfillCrypto } from './polyfillCrypto';\nimport { polyfillFetch } from './polyfillFetch';\nimport { polyfillJsDom } from './polyfillJsDom';\n\n/**\n * Polyfills the browser environment with the necessary APIs for the server.\n * Currently, this includes:\n * - `window`\n * - `document`\n * - `fetch`\n * - `crypto`\n */\nexport async function polyfillBrowser() {\n await polyfillCrypto();\n await polyfillFetch();\n await polyfillJsDom();\n}\n","import { type FetchLike } from '../fetch';\nimport { getGlobalThis } from '../isomorphics/getGlobalThis';\n\nexport function createFetchWithProxyByNodeFetch({\n proxy,\n fetch,\n}: { proxy?: string; fetch?: FetchLike } = {}): FetchLike {\n const globalThis = getGlobalThis();\n if (!proxy) {\n return fetch || globalThis.fetch;\n }\n\n let agent: any;\n const Request = globalThis.Request;\n let NodeRequest: any;\n let NodeFetch: any;\n return async (url, init?: RequestInit) => {\n if (!agent) {\n const { default: createHttpsProxyAgent } = await import('https-proxy-agent');\n agent = (createHttpsProxyAgent as any)(proxy);\n }\n\n // node-fetch 才可以,node v18 fetch 不支持\n if (!NodeRequest) {\n ({ Request: NodeRequest, default: NodeFetch } = await import('node-fetch'));\n }\n\n fetch ||= NodeFetch;\n\n if (url instanceof Request) {\n return (fetch as any)(new Request(url, { agent } as any));\n }\n if ((url as any) instanceof NodeRequest) {\n return (fetch as any)(new NodeRequest(url, { agent } as any));\n }\n return (fetch as any)(url, {\n ...init,\n agent,\n } as any);\n };\n}\n","import { MaybePromise } from 'rollup';\nimport { FetchLike } from '../fetch';\n\nexport function createFetchWithProxyByUndici({\n proxy,\n fetch,\n undici,\n}: {\n proxy?: 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 return async (...args) => {\n const init: RequestInit & { duplex?: string; dispatcher?: any } = (args[1] ||= {});\n if (init.body instanceof ReadableStream) {\n // https://github.com/nodejs/node/issues/46221\n init.duplex ||= 'half';\n }\n if (!agent) {\n // if in next use 'next/dist/compiled/undici'\n undici ||= import('undici');\n const mod = await undici;\n const ProxyAgent = mod.ProxyAgent;\n fetch ||= mod.fetch;\n agent = new ProxyAgent(proxy);\n // https://github.com/nodejs/node/issues/43187#issuecomment-1134634174\n // (global as any)[Symbol.for('undici.globalDispatcher.1')] = agent;\n }\n init.dispatcher = agent;\n return await fetch!(...args);\n };\n}\n","import { FetchLike } from '../fetch';\nimport { createFetchWithProxyByNodeFetch } from '../server';\nimport { createFetchWithProxyByUndici } from './createFetchWithProxyByUndici';\n\nexport function createFetchWithProxy({ proxy, fetch }: { proxy?: string; fetch?: FetchLike }): FetchLike {\n if (!proxy) {\n return fetch || globalThis.fetch;\n }\n return parseInt(process.versions.node) >= 18\n ? createFetchWithProxyByUndici({ proxy, fetch })\n : createFetchWithProxyByNodeFetch({ proxy, fetch });\n}\n"],"names":["polyfillCrypto","globalThis","getGlobalThis","module","polyfillFetch","nodeFetch","fetch","Response","Headers","Request","AbortError","FetchError","FormData","Blob","File","v","polyfillJsDom","ResourceLoader","JSDOM","Window","opts","proxy","strictSSL","userAgent","jsdomOpts","resources","defaultJsdomConfig","protectedProperties","prop","installEnv","args","properties","arg","userJsdomConfig","window","polyfillBrowser","createFetchWithProxyByNodeFetch","agent","NodeRequest","NodeFetch","url","init","createHttpsProxyAgent","createFetchWithProxyByUndici","undici","mod","ProxyAgent","createFetchWithProxy"],"mappings":"wSAEA,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,EAAaC,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,MAAaE,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAa,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAG,CACpD,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CACT,CCLO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAASC,EAAcC,CAAgE,CAAA,CAC5F,CAAI,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAW,CACb,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,C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,CAAW,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAK/B;"}
1
+ {"version":3,"file":"server.js","sources":["../../src/servers/polyfillCrypto.ts","../../src/servers/polyfillJsDom.ts","../../src/servers/polyfillFetch.ts","../../src/servers/polyfillBrowser.ts","../../src/servers/createFetchWithProxyByUndici.ts","../../src/servers/createFetchWithProxy.ts","../../src/servers/createFetchWithRetry.ts","../../src/servers/md5.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 type { ConstructorOptions, ResourceLoaderConstructorOptions } from 'jsdom';\nimport { getGlobalThis } from '../isomorphics/getGlobalThis';\n\nexport async function polyfillJsDom() {\n if (typeof window !== 'undefined') {\n return false;\n }\n\n const globalThis = getGlobalThis();\n\n const { ResourceLoader, JSDOM } = await import('jsdom');\n\n // https://github.com/lukechilds/window/blob/master/src/index.js\n // eslint-disable-next-line @typescript-eslint/no-extraneous-class\n class Window {\n constructor(opts: ResourceLoaderConstructorOptions & ConstructorOptions = {}) {\n const { proxy, strictSSL, userAgent, ...jsdomOpts } = opts;\n const resources = new ResourceLoader({\n proxy,\n strictSSL,\n userAgent,\n });\n return new JSDOM(\n '',\n Object.assign(jsdomOpts, {\n resources,\n }),\n ).window;\n }\n }\n\n // https://github.com/lukechilds/browser-env/blob/master/src/index.js\n // Default jsdom config.\n // These settings must override any custom settings to make sure we can iterate\n // over the window object.\n const defaultJsdomConfig = {\n // features: {\n // FetchExternalResources: false,\n // ProcessExternalResources: false,\n // },\n };\n // IIFE executed on import to return an array of global Node.js properties that\n // conflict with global browser properties.\n const protectedProperties = (() =>\n Object.getOwnPropertyNames(new Window(defaultJsdomConfig)).filter(\n (prop) => typeof globalThis[prop as keyof typeof globalThis] !== 'undefined',\n ))();\n\n function installEnv(...args: any[]) {\n // Sets up global browser environment\n // Extract options from args\n const properties = args.filter((arg: any) => Array.isArray(arg))[0];\n const userJsdomConfig = args.filter((arg: any) => !Array.isArray(arg))[0];\n\n // Create window object\n const window = new Window(Object.assign({}, userJsdomConfig, defaultJsdomConfig));\n\n // Get all global browser properties\n Object.getOwnPropertyNames(window)\n\n // Remove protected properties\n .filter((prop) => !protectedProperties.includes(prop))\n\n // If we're only applying specific required properties remove everything else\n .filter((prop) => !(properties && properties.indexOf(prop) === -1))\n .filter((prop) => {\n switch (prop) {\n case 'undefined':\n return false;\n }\n return true;\n })\n\n // Copy what's left to the Node.js global scope\n .forEach((prop) => {\n // console.debug(`define globalThis.${prop}`);\n Object.defineProperty(globalThis, prop, {\n configurable: true,\n get: () => window[prop as keyof Window] as any,\n });\n });\n\n return window;\n }\n\n installEnv({ url: 'http://localhost' });\n return true;\n}\n","import type { MaybePromise } from '../asyncs/MaybePromise';\n\nexport function polyfillFetch(nodeFetch: typeof import('node-fetch')): boolean;\nexport function polyfillFetch(nodeFetch?: undefined): Promise<boolean>;\nexport function polyfillFetch(nodeFetch?: typeof import('node-fetch')): MaybePromise<boolean> {\n if ('fetch' in globalThis) {\n return false;\n }\n // sync mode\n if (nodeFetch) {\n const { default: fetch, Response, Headers, Request, AbortError, FetchError, FormData, Blob, File } = nodeFetch;\n Object.assign(globalThis, {\n fetch,\n Response,\n Headers,\n Request,\n AbortError,\n FetchError,\n FormData,\n Blob,\n File,\n });\n // abort controller\n return true;\n }\n return import('node-fetch').then((v) => polyfillFetch(v));\n}\n","import { polyfillCrypto } from './polyfillCrypto';\nimport { polyfillFetch } from './polyfillFetch';\nimport { polyfillJsDom } from './polyfillJsDom';\n\n/**\n * Polyfills the browser environment with the necessary APIs for the server.\n * Currently, this includes:\n * - `window`\n * - `document`\n * - `fetch`\n * - `crypto`\n */\nexport async function polyfillBrowser() {\n await polyfillCrypto();\n await polyfillFetch();\n await polyfillJsDom();\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"],"names":["polyfillCrypto","globalThis","getGlobalThis","module","polyfillJsDom","ResourceLoader","JSDOM","Window","opts","proxy","strictSSL","userAgent","jsdomOpts","resources","defaultJsdomConfig","protectedProperties","prop","installEnv","args","properties","arg","userJsdomConfig","window","polyfillFetch","nodeFetch","fetch","Response","Headers","Request","AbortError","FetchError","FormData","Blob","File","v","polyfillBrowser","createFetchWithProxyByUndici","_token","undici","agent","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"],"mappings":"uSAEA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAsBA,GAAiB,CACrC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAMC,EAAaC,CAAc,CAAA,CAAA,CACjC,MAAI,CAAYD,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CACP,IAERA,CAAmB,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAU,MAAaE,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,aAAa,CAAG,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CACpD,GACT,CCNA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAsBC,GAAgB,CACpC,CAAA,CAAA,CAAI,OAAO,CAAW,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CACpB,MAAO,CAGT,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAMH,EAAaC,CAAc,CAAA,CA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A,CAAA,CAAA,CAAW,UAAY,CACrBK,CAAAA,CAAa,EAAEC,CAAO,CACxB,EAAGM,CAAK,CACV,CAEAP,CAAa,CAAA,CAAC,CAChB,CAAC,CACH,CACF,CC5FgB,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAAQ,EAAIX,CAAwB,CAAA,CAC1C,OAAOY,CAAW,CAAA,CAAA,CAAA,CAAA,CAAA,CAAK,EAAE,CAAOZ,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAK,EAAE,CAAO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAK,CACrD;"}
@@ -11,7 +11,7 @@ const TIME_MAX = Math.pow(2, 48) - 1;
11
11
  const TIME_LEN = 10;
12
12
  const RANDOM_LEN = 16;
13
13
  function isULID(str) {
14
- return (str == null ? void 0 : str.length) === 26 && /^[0-9A-HJKMNP-TV-Z]{26}$/i.test(str);
14
+ return (str == null ? void 0 : str.length) === 26 && /^[0-9]{10}[0-9A-HJKMNP-TV-Z]{16}$/i.test(str);
15
15
  }
16
16
  function replaceCharAt(str, index, char) {
17
17
  if (index > str.length - 1) {
@@ -1 +1 @@
1
- {"version":3,"file":"ulid.js","sources":["../../src/crypto/ulid.ts"],"sourcesContent":["import { getRandomValues } from './getRandomValues';\n\ntype PRNG = () => number;\n\n/**\n * Universally Unique Lexicographically Sortable Identifier\n *\n * @see https://github.com/ulid/spec ulid/spec\n */\nexport type ULID = (seedTime?: number) => string;\n\nexport interface ULIDError extends Error {\n source: string;\n}\n\nfunction createError(message: string): ULIDError {\n const err = new Error(message) as ULIDError;\n err.source = 'ulid';\n return err;\n}\n\n// These values should NEVER change. If\n// they do, we're no longer making ulids!\nconst ENCODING = '0123456789ABCDEFGHJKMNPQRSTVWXYZ'; // Crockford's Base32\nconst ENCODING_LEN = ENCODING.length;\nconst TIME_MAX = Math.pow(2, 48) - 1;\nconst TIME_LEN = 10;\nconst RANDOM_LEN = 16;\n\n/**\n * check give {@link str} is a valid ulid\n */\nexport function isULID(str: string): boolean {\n // ttttttttttrrrrrrrrrrrrrrrr\n return str?.length === 26 && /^[0-9A-HJKMNP-TV-Z]{26}$/i.test(str);\n}\n\nfunction replaceCharAt(str: string, index: number, char: string) {\n if (index > str.length - 1) {\n return str;\n }\n return str.substr(0, index) + char + str.substr(index + 1);\n}\n\nfunction incrementBase32(str: string): string {\n let done;\n let index = str.length;\n let char;\n let charIndex;\n const maxCharIndex = ENCODING_LEN - 1;\n while (!done && index-- >= 0) {\n char = str[index];\n charIndex = ENCODING.indexOf(char);\n if (charIndex === -1) {\n throw createError('incorrectly encoded string');\n }\n if (charIndex === maxCharIndex) {\n str = replaceCharAt(str, index, ENCODING[0]);\n continue;\n }\n done = replaceCharAt(str, index, ENCODING[charIndex + 1]);\n }\n if (typeof done === 'string') {\n return done;\n }\n throw createError('cannot increment this string');\n}\n\nfunction randomChar(prng: PRNG): string {\n let rand = Math.floor(prng() * ENCODING_LEN);\n if (rand === ENCODING_LEN) {\n rand = ENCODING_LEN - 1;\n }\n return ENCODING.charAt(rand);\n}\n\nfunction encodeTime(now: number, len: number): string {\n if (isNaN(now)) {\n throw new Error(`${now} must be a number`);\n }\n if (now > TIME_MAX) {\n throw createError(`cannot encode time greater than ${TIME_MAX}`);\n }\n if (now < 0) {\n throw createError('time must be positive');\n }\n if (!Number.isInteger(now)) {\n throw createError('time must be an integer');\n }\n let mod;\n let str = '';\n for (; len > 0; len--) {\n mod = now % ENCODING_LEN;\n str = ENCODING.charAt(mod) + str;\n now = (now - mod) / ENCODING_LEN;\n }\n return str;\n}\n\nfunction encodeRandom(len: number, prng: PRNG): string {\n let str = '';\n for (; len > 0; len--) {\n str = randomChar(prng) + str;\n }\n return str;\n}\n\n/**\n * extract time & random from ulid\n *\n * @throws ULIDError\n */\nexport function parseULID(id: string): { timestamp: number; random: string } {\n if (id.length !== TIME_LEN + RANDOM_LEN) {\n throw createError('malformed ulid');\n }\n const time = id\n .substr(0, TIME_LEN)\n .split('')\n .reverse()\n .reduce((carry, char, index) => {\n const encodingIndex = ENCODING.indexOf(char);\n if (encodingIndex === -1) {\n throw createError('invalid character found: ' + char);\n }\n return (carry += encodingIndex * Math.pow(ENCODING_LEN, index));\n }, 0);\n if (time > TIME_MAX) {\n throw createError('malformed ulid, timestamp too large');\n }\n return { timestamp: time, random: id.substring(TIME_LEN) };\n}\n\nfunction createPrng(): PRNG {\n return () => {\n const buffer = new Uint8Array(1);\n getRandomValues(buffer);\n return buffer[0] / 0xff;\n };\n}\n\n/**\n * create a ulid generator\n */\nexport function createULID({\n monotonic = true,\n random = createPrng(),\n now = Date.now,\n}: { monotonic?: boolean; now?: () => number; random?: () => number } = {}) {\n if (!monotonic) {\n return function ulid(seedTime?: number): string {\n seedTime ||= now();\n return encodeTime(seedTime, TIME_LEN) + encodeRandom(RANDOM_LEN, random);\n };\n }\n\n let lastTime: number = 0;\n let lastRandom: string;\n return function ulid(seedTime?: number): string {\n seedTime ||= now();\n if (seedTime <= lastTime && lastRandom) {\n const incrementedRandom = (lastRandom = incrementBase32(lastRandom));\n return encodeTime(lastTime, TIME_LEN) + incrementedRandom;\n }\n lastTime = seedTime;\n const newRandom = (lastRandom = encodeRandom(RANDOM_LEN, random));\n return encodeTime(seedTime, TIME_LEN) + newRandom;\n };\n}\n\n/**\n * default monotonic ulid generator\n */\nexport let ulid: ULID = (...args) => {\n if (_real) {\n return _real(...args);\n }\n // delay initialize crypto\n _real = createULID();\n ulid = _real;\n return _real(...args);\n};\nlet _real: ULID;\n"],"names":["ulid"],"mappings":";;AAeA,SAAS,YAAY,OAA4B,EAAA;AAC/C,EAAM,MAAA,GAAA,GAAM,IAAI,KAAA,CAAM,OAAO,CAAA,CAAA;AAC7B,EAAA,GAAA,CAAI,MAAS,GAAA,MAAA,CAAA;AACb,EAAO,OAAA,GAAA,CAAA;AACT,CAAA;AAIA,MAAM,QAAW,GAAA,kCAAA,CAAA;AACjB,MAAM,e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AAW,QAAA,GAAA,QAAA,CAAA;AACX,IAAA,MAAM,SAAa,GAAA,UAAA,GAAa,YAAa,CAAA,UAAA,EAAY,MAAM,CAAA,CAAA;AAC/D,IAAO,OAAA,UAAA,CAAW,QAAU,EAAA,QAAQ,CAAI,GAAA,SAAA,CAAA;AAAA,GAC1C,CAAA;AACF,CAAA;AAKW,IAAA,IAAA,GAAa,IAAI,IAAS,KAAA;AACnC,EAAA,IAAI,KAAO,EAAA;AACT,IAAO,OAAA,KAAA,CAAM,GAAG,IAAI,CAAA,CAAA;AAAA,GACtB;AAEA,EAAA,KAAA,GAAQ,UAAW,EAAA,CAAA;AACnB,EAAO,IAAA,GAAA,KAAA,CAAA;AACP,EAAO,OAAA,KAAA,CAAM,GAAG,IAAI,CAAA,CAAA;AACtB,EAAA;AACA,IAAI,KAAA;;;;"}
1
+ {"version":3,"file":"ulid.js","sources":["../../src/crypto/ulid.ts"],"sourcesContent":["import { getRandomValues } from './getRandomValues';\n\ntype PRNG = () => number;\n\n/**\n * Universally Unique Lexicographically Sortable Identifier\n *\n * @see https://github.com/ulid/spec ulid/spec\n */\nexport type ULID = (seedTime?: number) => string;\n\nexport interface ULIDError extends Error {\n source: string;\n}\n\nfunction createError(message: string): ULIDError {\n const err = new Error(message) as ULIDError;\n err.source = 'ulid';\n return err;\n}\n\n// These values should NEVER change. If\n// they do, we're no longer making ulids!\nconst ENCODING = '0123456789ABCDEFGHJKMNPQRSTVWXYZ'; // Crockford's Base32\nconst ENCODING_LEN = ENCODING.length;\nconst TIME_MAX = Math.pow(2, 48) - 1;\nconst TIME_LEN = 10;\nconst RANDOM_LEN = 16;\n\n/**\n * check give {@link str} is a valid ulid\n */\nexport function isULID(str: string): boolean {\n // ttttttttttrrrrrrrrrrrrrrrr\n return str?.length === 26 && /^[0-9]{10}[0-9A-HJKMNP-TV-Z]{16}$/i.test(str);\n}\n\nfunction replaceCharAt(str: string, index: number, char: string) {\n if (index > str.length - 1) {\n return str;\n }\n return str.substr(0, index) + char + str.substr(index + 1);\n}\n\nfunction incrementBase32(str: string): string {\n let done;\n let index = str.length;\n let char;\n let charIndex;\n const maxCharIndex = ENCODING_LEN - 1;\n while (!done && index-- >= 0) {\n char = str[index];\n charIndex = ENCODING.indexOf(char);\n if (charIndex === -1) {\n throw createError('incorrectly encoded string');\n }\n if (charIndex === maxCharIndex) {\n str = replaceCharAt(str, index, ENCODING[0]);\n continue;\n }\n done = replaceCharAt(str, index, ENCODING[charIndex + 1]);\n }\n if (typeof done === 'string') {\n return done;\n }\n throw createError('cannot increment this string');\n}\n\nfunction randomChar(prng: PRNG): string {\n let rand = Math.floor(prng() * ENCODING_LEN);\n if (rand === ENCODING_LEN) {\n rand = ENCODING_LEN - 1;\n }\n return ENCODING.charAt(rand);\n}\n\nfunction encodeTime(now: number, len: number): string {\n if (isNaN(now)) {\n throw new Error(`${now} must be a number`);\n }\n if (now > TIME_MAX) {\n throw createError(`cannot encode time greater than ${TIME_MAX}`);\n }\n if (now < 0) {\n throw createError('time must be positive');\n }\n if (!Number.isInteger(now)) {\n throw createError('time must be an integer');\n }\n let mod;\n let str = '';\n for (; len > 0; len--) {\n mod = now % ENCODING_LEN;\n str = ENCODING.charAt(mod) + str;\n now = (now - mod) / ENCODING_LEN;\n }\n return str;\n}\n\nfunction encodeRandom(len: number, prng: PRNG): string {\n let str = '';\n for (; len > 0; len--) {\n str = randomChar(prng) + str;\n }\n return str;\n}\n\n/**\n * extract time & random from ulid\n *\n * @throws ULIDError\n */\nexport function parseULID(id: string): { timestamp: number; random: string } {\n if (id.length !== TIME_LEN + RANDOM_LEN) {\n throw createError('malformed ulid');\n }\n const time = id\n .substr(0, TIME_LEN)\n .split('')\n .reverse()\n .reduce((carry, char, index) => {\n const encodingIndex = ENCODING.indexOf(char);\n if (encodingIndex === -1) {\n throw createError('invalid character found: ' + char);\n }\n return (carry += encodingIndex * Math.pow(ENCODING_LEN, index));\n }, 0);\n if (time > TIME_MAX) {\n throw createError('malformed ulid, timestamp too large');\n }\n return { timestamp: time, random: id.substring(TIME_LEN) };\n}\n\nfunction createPrng(): PRNG {\n return () => {\n const buffer = new Uint8Array(1);\n getRandomValues(buffer);\n return buffer[0] / 0xff;\n };\n}\n\n/**\n * create a ulid generator\n */\nexport function createULID({\n monotonic = true,\n random = createPrng(),\n now = Date.now,\n}: { monotonic?: boolean; now?: () => number; random?: () => number } = {}) {\n if (!monotonic) {\n return function ulid(seedTime?: number): string {\n seedTime ||= now();\n return encodeTime(seedTime, TIME_LEN) + encodeRandom(RANDOM_LEN, random);\n };\n }\n\n let lastTime: number = 0;\n let lastRandom: string;\n return function ulid(seedTime?: number): string {\n seedTime ||= now();\n if (seedTime <= lastTime && lastRandom) {\n const incrementedRandom = (lastRandom = incrementBase32(lastRandom));\n return encodeTime(lastTime, TIME_LEN) + incrementedRandom;\n }\n lastTime = seedTime;\n const newRandom = (lastRandom = encodeRandom(RANDOM_LEN, random));\n return encodeTime(seedTime, TIME_LEN) + newRandom;\n };\n}\n\n/**\n * default monotonic ulid generator\n */\nexport let ulid: ULID = (...args) => {\n if (_real) {\n return _real(...args);\n }\n // delay initialize crypto\n _real = createULID();\n ulid = _real;\n return _real(...args);\n};\nlet _real: ULID;\n"],"names":["ulid"],"mappings":";;AAeA,SAAS,YAAY,OAA4B,EAAA;AAC/C,EAAM,MAAA,GAAA,GAAM,IAAI,KAAA,CAAM,OAAO,CAAA,CAAA;AAC7B,EAAA,GAAA,CAAI,MAAS,GAAA,MAAA,CAAA;AACb,EAAO,OAAA,GAAA,CAAA;AACT,CAAA;AAIA,MAAM,QAAW,GAAA,kCAAA,CAAA;AACjB,MAAM,eAAe,QAAS,CAAA,MAAA,CAAA;AAC9B,MAAM,QAAW,GAAA,IAAA,CAAK,GAAI,CAAA,CAAA,EAAG,EAAE,CAAI,GAAA,CAAA,CAAA;AACnC,MAAM,QAAW,GAAA,EAAA,CAAA;AACjB,MAAM,UAAa,GAAA,EAAA,CAAA;AAKZ,SAAS,OAAO,GAAsB,EAA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,IAAA,IAAA,GAAa,IAAI,IAAS,KAAA;AACnC,EAAA,IAAI,KAAO,EAAA;AACT,IAAO,OAAA,KAAA,CAAM,GAAG,IAAI,CAAA,CAAA;AAAA,GACtB;AAEA,EAAA,KAAA,GAAQ,UAAW,EAAA,CAAA;AACnB,EAAO,IAAA,GAAA,KAAA,CAAA;AACP,EAAO,OAAA,KAAA,CAAM,GAAG,IAAI,CAAA,CAAA;AACtB,EAAA;AACA,IAAI,KAAA;;;;"}
@@ -9,14 +9,15 @@ function createFetchWith({
9
9
  var _a;
10
10
  const url = String(urlOrRequest);
11
11
  let req = init || {};
12
+ const nextFetch = req.fetch || fetch;
12
13
  const res = (_a = await onRequest({
13
14
  url,
14
15
  req,
15
16
  next: (url2, init2) => {
16
17
  req = init2;
17
- return fetch(url2, init2);
18
+ return nextFetch(url2, init2);
18
19
  }
19
- })) != null ? _a : await fetch(url, init);
20
+ })) != null ? _a : await nextFetch(url, init);
20
21
  return onResponse({ url, req, res });
21
22
  };
22
23
  }
@@ -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 { FetchLike } from './index';\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}): FetchLike {\n return async (urlOrRequest, init) => {\n const url = String(urlOrRequest);\n let req: RequestInit = init || {};\n const res =\n (await onRequest({\n url,\n req,\n next: (url, init) => {\n req = init;\n return fetch(url, init);\n },\n })) ?? (await fetch(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,CAQc,EAAA;AACZ,EAAO,OAAA,OAAO,cAAc,IAAS,KAAA;AAjBvC,IAAA,IAAA,EAAA,CAAA;AAkBI,IAAM,MAAA,GAAA,GAAM,OAAO,YAAY,CAAA,CAAA;AAC/B,IAAI,IAAA,GAAA,GAAmB,QAAQ,EAAC,CAAA;AAChC,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,KAAA,CAAMD,MAAKC,KAAI,CAAA,CAAA;AAAA,OACxB;AAAA,KACD,CAPA,KAAA,IAAA,GAAA,EAAA,GAOO,MAAM,KAAA,CAAM,KAAK,IAAI,CAAA,CAAA;AAC/B,IAAA,OAAO,UAAW,CAAA,EAAE,GAAK,EAAA,GAAA,EAAK,KAAK,CAAA,CAAA;AAAA,GACrC,CAAA;AACF;;;;"}
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,cAAgC,IAA+C,KAAA;AAjB/F,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;;;;"}
@@ -1,5 +1,5 @@
1
- import { dumpRequest } from './dumpRequest.js';
2
1
  import { createFetchWith } from './createFetchWith.js';
2
+ import { dumpRequest } from './dumpRequest.js';
3
3
  import { dumpResponse } from './dumpResponse.js';
4
4
 
5
5
  function createFetchWithLogging({
@@ -1 +1 @@
1
- {"version":3,"file":"createFetchWithLogging.js","sources":["../../src/fetch/createFetchWithLogging.ts"],"sourcesContent":["import { dumpRequest } from './dumpRequest';\nimport { createFetchWith, dumpResponse, FetchLike } from './index';\n\nexport function createFetchWithLogging({\n fetch,\n log = console.log,\n}: {\n fetch?: FetchLike;\n log?: (s: string) => void;\n} = {}): FetchLike {\n return createFetchWith({\n fetch,\n onRequest: ({ url, req }) => {\n void dumpRequest({ url, req, log });\n },\n onResponse: ({ url, req, res }) => {\n return dumpResponse({ url, req, res, log });\n },\n });\n}\n"],"names":[],"mappings":";;;;AAGO,SAAS,sBAAuB,CAAA;AAAA,EACrC,KAAA;AAAA,EACA,MAAM,OAAQ,CAAA,GAAA;AAChB,CAAA,GAGI,EAAe,EAAA;AACjB,EAAA,OAAO,eAAgB,CAAA;AAAA,IACrB,KAAA;AAAA,IACA,SAAW,EAAA,CAAC,EAAE,GAAA,EAAK,KAAU,KAAA;AAC3B,MAAA,KAAK,WAAY,CAAA,EAAE,GAAK,EAAA,GAAA,EAAK,KAAK,CAAA,CAAA;AAAA,KACpC;AAAA,IACA,YAAY,CAAC,EAAE,GAAK,EAAA,GAAA,EAAK,KAAU,KAAA;AACjC,MAAA,OAAO,aAAa,EAAE,GAAA,EAAK,GAAK,EAAA,GAAA,EAAK,KAAK,CAAA,CAAA;AAAA,KAC5C;AAAA,GACD,CAAA,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"createFetchWithLogging.js","sources":["../../src/fetch/createFetchWithLogging.ts"],"sourcesContent":["import { createFetchWith } from './createFetchWith';\nimport { dumpRequest } from './dumpRequest';\nimport { dumpResponse } from './dumpResponse';\nimport { type FetchLike } from './types';\n\nexport function createFetchWithLogging({\n fetch,\n log = console.log,\n}: {\n fetch?: FetchLike;\n log?: (s: string) => void;\n} = {}): FetchLike {\n return createFetchWith({\n fetch,\n onRequest: ({ url, req }) => {\n void dumpRequest({ url, req, log });\n },\n onResponse: ({ url, req, res }) => {\n return dumpResponse({ url, req, res, log });\n },\n });\n}\n"],"names":[],"mappings":";;;;AAKO,SAAS,sBAAuB,CAAA;AAAA,EACrC,KAAA;AAAA,EACA,MAAM,OAAQ,CAAA,GAAA;AAChB,CAAA,GAGI,EAAe,EAAA;AACjB,EAAA,OAAO,eAAgB,CAAA;AAAA,IACrB,KAAA;AAAA,IACA,SAAW,EAAA,CAAC,EAAE,GAAA,EAAK,KAAU,KAAA;AAC3B,MAAA,KAAK,WAAY,CAAA,EAAE,GAAK,EAAA,GAAA,EAAK,KAAK,CAAA,CAAA;AAAA,KACpC;AAAA,IACA,YAAY,CAAC,EAAE,GAAK,EAAA,GAAA,EAAK,KAAU,KAAA;AACjC,MAAA,OAAO,aAAa,EAAE,GAAA,EAAK,GAAK,EAAA,GAAA,EAAK,KAAK,CAAA,CAAA;AAAA,KAC5C;AAAA,GACD,CAAA,CAAA;AACH;;;;"}
package/lib/server.js CHANGED
@@ -1,8 +1,8 @@
1
1
  export { polyfillCrypto } from './servers/polyfillCrypto.js';
2
- export { polyfillFetch } from './servers/polyfillFetch.js';
3
2
  export { polyfillJsDom } from './servers/polyfillJsDom.js';
4
3
  export { polyfillBrowser } from './servers/polyfillBrowser.js';
5
- export { createFetchWithProxyByNodeFetch } from './servers/createFetchWithProxyByNodeFetch.js';
6
4
  export { createFetchWithProxyByUndici } from './servers/createFetchWithProxyByUndici.js';
7
5
  export { createFetchWithProxy } from './servers/createFetchWithProxy.js';
6
+ export { createFetchWithRetry } from './servers/createFetchWithRetry.js';
7
+ export { md5 } from './servers/md5.js';
8
8
  //# sourceMappingURL=server.js.map
@@ -1,12 +1,6 @@
1
- import { createFetchWithProxyByNodeFetch } from './createFetchWithProxyByNodeFetch.js';
2
1
  import { createFetchWithProxyByUndici } from './createFetchWithProxyByUndici.js';
3
2
 
4
- function createFetchWithProxy({ proxy, fetch }) {
5
- if (!proxy) {
6
- return fetch || globalThis.fetch;
7
- }
8
- return parseInt(process.versions.node) >= 18 ? createFetchWithProxyByUndici({ proxy, fetch }) : createFetchWithProxyByNodeFetch({ proxy, fetch });
9
- }
3
+ const createFetchWithProxy = createFetchWithProxyByUndici;
10
4
 
11
5
  export { createFetchWithProxy };
12
6
  //# sourceMappingURL=createFetchWithProxy.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"createFetchWithProxy.js","sources":["../../src/servers/createFetchWithProxy.ts"],"sourcesContent":["import { FetchLike } from '../fetch';\nimport { createFetchWithProxyByNodeFetch } from '../server';\nimport { createFetchWithProxyByUndici } from './createFetchWithProxyByUndici';\n\nexport function createFetchWithProxy({ proxy, fetch }: { proxy?: string; fetch?: FetchLike }): FetchLike {\n if (!proxy) {\n return fetch || globalThis.fetch;\n }\n return parseInt(process.versions.node) >= 18\n ? createFetchWithProxyByUndici({ proxy, fetch })\n : createFetchWithProxyByNodeFetch({ proxy, fetch });\n}\n"],"names":[],"mappings":";;;AAIO,SAAS,oBAAqB,CAAA,EAAE,KAAO,EAAA,KAAA,EAA2D,EAAA;AACvG,EAAA,IAAI,CAAC,KAAO,EAAA;AACV,IAAA,OAAO,SAAS,UAAW,CAAA,KAAA,CAAA;AAAA,GAC7B;AACA,EAAA,OAAO,SAAS,OAAQ,CAAA,QAAA,CAAS,IAAI,CAAA,IAAK,KACtC,4BAA6B,CAAA,EAAE,KAAO,EAAA,KAAA,EAAO,CAC7C,GAAA,+BAAA,CAAgC,EAAE,KAAA,EAAO,OAAO,CAAA,CAAA;AACtD;;;;"}
1
+ {"version":3,"file":"createFetchWithProxy.js","sources":["../../src/servers/createFetchWithProxy.ts"],"sourcesContent":["import { createFetchWithProxyByUndici } from './createFetchWithProxyByUndici';\n\nexport const createFetchWithProxy = createFetchWithProxyByUndici;\n"],"names":[],"mappings":";;AAEO,MAAM,oBAAuB,GAAA;;;;"}
@@ -1,5 +1,6 @@
1
1
  function createFetchWithProxyByUndici({
2
2
  proxy,
3
+ token: _token,
3
4
  fetch,
4
5
  undici
5
6
  } = {}) {
@@ -9,15 +10,36 @@ function createFetchWithProxyByUndici({
9
10
  let agent;
10
11
  return async (...args) => {
11
12
  const init = args[1] || (args[1] = {});
12
- if (init.body instanceof ReadableStream) {
13
- init.duplex || (init.duplex = "half");
13
+ {
14
+ const body = init.body;
15
+ if (typeof body === "object" && body && (body instanceof ReadableStream || Symbol.asyncIterator in body)) {
16
+ init.duplex || (init.duplex = "half");
17
+ }
14
18
  }
15
19
  if (!agent) {
20
+ let uri = proxy;
21
+ let token = _token;
22
+ {
23
+ let u;
24
+ try {
25
+ u = new URL(proxy);
26
+ } catch (e) {
27
+ }
28
+ if (!token && u && (u.username || u.password)) {
29
+ token = `Basic ${btoa(`${u.username || ""}:${u.password}`)}`;
30
+ u.username = "";
31
+ u.password = "";
32
+ uri = u.toString();
33
+ }
34
+ }
16
35
  undici || (undici = import('undici'));
17
36
  const mod = await undici;
18
37
  const ProxyAgent = mod.ProxyAgent;
19
38
  fetch || (fetch = mod.fetch);
20
- agent = new ProxyAgent(proxy);
39
+ agent = new ProxyAgent({
40
+ uri,
41
+ token
42
+ });
21
43
  }
22
44
  init.dispatcher = agent;
23
45
  return await fetch(...args);
@@ -1 +1 @@
1
- {"version":3,"file":"createFetchWithProxyByUndici.js","sources":["../../src/servers/createFetchWithProxyByUndici.ts"],"sourcesContent":["import { MaybePromise } from 'rollup';\nimport { FetchLike } from '../fetch';\n\nexport function createFetchWithProxyByUndici({\n proxy,\n fetch,\n undici,\n}: {\n proxy?: 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 return async (...args) => {\n const init: RequestInit & { duplex?: string; dispatcher?: any } = (args[1] ||= {});\n if (init.body instanceof ReadableStream) {\n // https://github.com/nodejs/node/issues/46221\n init.duplex ||= 'half';\n }\n if (!agent) {\n // if in next use 'next/dist/compiled/undici'\n undici ||= import('undici');\n const mod = await undici;\n const ProxyAgent = mod.ProxyAgent;\n fetch ||= mod.fetch;\n agent = new ProxyAgent(proxy);\n // https://github.com/nodejs/node/issues/43187#issuecomment-1134634174\n // (global as any)[Symbol.for('undici.globalDispatcher.1')] = agent;\n }\n init.dispatcher = agent;\n return await fetch!(...args);\n };\n}\n"],"names":[],"mappings":"AAGO,SAAS,4BAA6B,CAAA;AAAA,EAC3C,KAAA;AAAA,EACA,KAAA;AAAA,EACA,MAAA;AACF,CAAA,GAII,EAAe,EAAA;AACjB,EAAA,IAAI,CAAC,KAAO,EAAA;AACV,IAAA,OAAO,SAAS,UAAW,CAAA,KAAA,CAAA;AAAA,GAC7B;AACA,EAAI,IAAA,KAAA,CAAA;AACJ,EAAA,OAAO,UAAU,IAAS,KAAA;AACxB,IAAM,MAAA,IAAA,GAA6D,sBAAY,EAAC,CAAA,CAAA;AAChF,IAAI,IAAA,IAAA,CAAK,gBAAgB,cAAgB,EAAA;AAEvC,MAAK,IAAA,CAAA,MAAA,KAAL,KAAK,MAAW,GAAA,MAAA,CAAA,CAAA;AAAA,KAClB;AACA,IAAA,IAAI,CAAC,KAAO,EAAA;AAEV,MAAA,MAAA,KAAA,MAAA,GAAW,OAAO,QAAQ,CAAA,CAAA,CAAA;AAC1B,MAAA,MAAM,MAAM,MAAM,MAAA,CAAA;AAClB,MAAA,MAAM,aAAa,GAAI,CAAA,UAAA,CAAA;AACvB,MAAA,KAAA,KAAA,KAAA,GAAU,GAAI,CAAA,KAAA,CAAA,CAAA;AACd,MAAQ,KAAA,GAAA,IAAI,WAAW,KAAK,CAAA,CAAA;AAAA,KAG9B;AACA,IAAA,IAAA,CAAK,UAAa,GAAA,KAAA,CAAA;AAClB,IAAO,OAAA,MAAM,KAAO,CAAA,GAAG,IAAI,CAAA,CAAA;AAAA,GAC7B,CAAA;AACF;;;;"}
1
+ {"version":3,"file":"createFetchWithProxyByUndici.js","sources":["../../src/servers/createFetchWithProxyByUndici.ts"],"sourcesContent":["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"],"names":[],"mappings":"AAGO,SAAS,4BAA6B,CAAA;AAAA,E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AA,CAAA;AAAA,SACnB;AAAA,OACF;AAEA,MAAA,MAAA,KAAA,MAAA,GAAW,OAAO,QAAQ,CAAA,CAAA,CAAA;AAC1B,MAAA,MAAM,MAAM,MAAM,MAAA,CAAA;AAClB,MAAA,MAAM,aAAa,GAAI,CAAA,UAAA,CAAA;AACvB,MAAA,KAAA,KAAA,KAAA,GAAU,GAAI,CAAA,KAAA,CAAA,CAAA;AAEd,MAAA,KAAA,GAAQ,IAAI,UAAW,CAAA;AAAA,QACrB,GAAA;AAAA,QACA,KAAA;AAAA,OACD,CAAA,CAAA;AAAA,KAIH;AACA,IAAA,IAAA,CAAK,UAAa,GAAA,KAAA,CAAA;AAClB,IAAO,OAAA,MAAM,KAAO,CAAA,GAAG,IAAI,CAAA,CAAA;AAAA,GAC7B,CAAA;AACF;;;;"}
@@ -0,0 +1,70 @@
1
+ import { getGlobalThis } from '../isomorphics/getGlobalThis.js';
2
+
3
+ function createFetchWithRetry({
4
+ fetch = getGlobalThis().fetch,
5
+ retries = 3,
6
+ retryDelay = 1e3,
7
+ retryOn = []
8
+ } = {}) {
9
+ return function fetchRetry(input, init) {
10
+ return new Promise(function(resolve, reject) {
11
+ var wrappedFetch = function(attempt) {
12
+ var _input = typeof Request !== "undefined" && input instanceof Request ? input.clone() : input;
13
+ fetch(_input, init).then(function(response) {
14
+ if (Array.isArray(retryOn) && retryOn.indexOf(response.status) === -1) {
15
+ resolve(response);
16
+ } else if (typeof retryOn === "function") {
17
+ try {
18
+ return Promise.resolve(retryOn(attempt, null, response)).then(function(retryOnResponse) {
19
+ if (retryOnResponse) {
20
+ retry(attempt, null, response);
21
+ } else {
22
+ resolve(response);
23
+ }
24
+ }).catch(reject);
25
+ } catch (error) {
26
+ reject(error);
27
+ }
28
+ } else {
29
+ if (attempt < retries) {
30
+ retry(attempt, null, response);
31
+ } else {
32
+ resolve(response);
33
+ }
34
+ }
35
+ return;
36
+ }).catch(function(error) {
37
+ if (typeof retryOn === "function") {
38
+ try {
39
+ Promise.resolve(retryOn(attempt, error, null)).then(function(retryOnResponse) {
40
+ if (retryOnResponse) {
41
+ retry(attempt, error, null);
42
+ } else {
43
+ reject(error);
44
+ }
45
+ }).catch(function(error2) {
46
+ reject(error2);
47
+ });
48
+ } catch (error2) {
49
+ reject(error2);
50
+ }
51
+ } else if (attempt < retries) {
52
+ retry(attempt, error, null);
53
+ } else {
54
+ reject(error);
55
+ }
56
+ });
57
+ };
58
+ function retry(attempt, error, response) {
59
+ let delay = typeof retryDelay === "function" ? retryDelay(attempt, error, response) : retryDelay;
60
+ setTimeout(function() {
61
+ wrappedFetch(++attempt);
62
+ }, delay);
63
+ }
64
+ wrappedFetch(0);
65
+ });
66
+ };
67
+ }
68
+
69
+ export { createFetchWithRetry };
70
+ //# sourceMappingURL=createFetchWithRetry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createFetchWithRetry.js","sources":["../../src/servers/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 }, 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,GAA2B,EAAe,EAAA;AAGxC,EAAO,OAAA,SAAS,UAAW,CAAA,KAAA,EAAyB,IAAoB,EAAA;AACtE,IAAA,OAAO,IAAI,OAAA,CAAQ,SAAU,OAAA,EAAS,MAAQ,EAAA;AAC5C,MAAI,IAAA,YAAA,GAAe,SAAU,OAAiB,EAAA;AAG5C,QAAI,IAAA,MAAA,GAAS,OAAO,OAAY,KAAA,WAAA,IAAe,iBAAiB,OAAU,GAAA,KAAA,CAAM,OAAU,GAAA,KAAA,CAAA;AAC1F,QAAA,KAAA,CAAM,MAAQ,EAAA,IAA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,OAAA,EAAS,OAAO,IAAI,CAAA,CAAA;AAAA,iBACrB,MAAA;AACL,kBAAA,MAAA,CAAO,KAAK,CAAA,CAAA;AAAA,iBACd;AAAA,eACD,CAAA,CACA,KAAM,CAAA,SAAUA,MAAO,EAAA;AACtB,gBAAA,MAAA,CAAOA,MAAK,CAAA,CAAA;AAAA,eACb,CAAA,CAAA;AAAA,qBACIA,MAAP,EAAA;AACA,cAAA,MAAA,CAAOA,MAAK,CAAA,CAAA;AAAA,aACd;AAAA,WACF,MAAA,IAAW,UAAU,OAAS,EAAA;AAC5B,YAAM,KAAA,CAAA,OAAA,EAAS,OAAO,IAAI,CAAA,CAAA;AAAA,WACrB,MAAA;AACL,YAAA,MAAA,CAAO,KAAK,CAAA,CAAA;AAAA,WACd;AAAA,SACD,CAAA,CAAA;AAAA,OACL,CAAA;AAEA,MAAS,SAAA,KAAA,CAAM,OAAiB,EAAA,KAAA,EAAY,QAA2B,EAAA;AACrE,QAAI,IAAA,KAAA,GAAQ,OAAO,UAAe,KAAA,UAAA,GAAa,WAAW,OAAS,EAAA,KAAA,EAAO,QAAQ,CAAI,GAAA,UAAA,CAAA;AACtF,QAAA,UAAA,CAAW,WAAY;AACrB,UAAA,YAAA,CAAa,EAAE,OAAO,CAAA,CAAA;AAAA,WACrB,KAAK,CAAA,CAAA;AAAA,OACV;AAEA,MAAA,YAAA,CAAa,CAAC,CAAA,CAAA;AAAA,KACf,CAAA,CAAA;AAAA,GACH,CAAA;AACF;;;;"}
@@ -0,0 +1,8 @@
1
+ import { createHash } from 'node:crypto';
2
+
3
+ function md5(input) {
4
+ return createHash("md5").update(input).digest("hex");
5
+ }
6
+
7
+ export { md5 };
8
+ //# sourceMappingURL=md5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"md5.js","sources":["../../src/servers/md5.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\n\nexport function md5(input: Buffer | string) {\n return createHash('md5').update(input).digest('hex') as string;\n}\n"],"names":[],"mappings":";;AAEO,SAAS,IAAI,KAAwB,EAAA;AAC1C,EAAA,OAAO,WAAW,KAAK,CAAA,CAAE,OAAO,KAAK,CAAA,CAAE,OAAO,KAAK,CAAA,CAAA;AACrD;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wener/utils",
3
- "version": "1.1.15",
3
+ "version": "1.1.17",
4
4
  "type": "module",
5
5
  "description": "Utils for daily use",
6
6
  "repository": {
@@ -32,16 +32,9 @@
32
32
  "lodash"
33
33
  ],
34
34
  "peerDependencies": {
35
- "https-proxy-agent": "*",
36
35
  "undici": "*"
37
36
  },
38
37
  "peerDependenciesMeta": {
39
- "https-proxy-agent": {
40
- "optional": true
41
- },
42
- "node-fetch": {
43
- "optional": true
44
- },
45
38
  "undici": {
46
39
  "optional": true
47
40
  }
@@ -65,8 +58,10 @@
65
58
  "./src/server.ts"
66
59
  ],
67
60
  "external": [
61
+ "crypto",
68
62
  "jsdom",
69
- "node-fetch"
63
+ "node-fetch",
64
+ "undici"
70
65
  ]
71
66
  },
72
67
  "scripts": {
@@ -0,0 +1 @@
1
+ export function md5(s: string): string;
@@ -0,0 +1,44 @@
1
+ // prettier-ignore
2
+ export function md5(inputString) {
3
+ // https://stackoverflow.com/a/60467595/1870054
4
+ var hc="0123456789abcdef";
5
+ function rh(n) {var j,s="";for(j=0;j<=3;j++) s+=hc.charAt((n>>(j*8+4))&0x0F)+hc.charAt((n>>(j*8))&0x0F);return s;}
6
+ function ad(x,y) {var l=(x&0xFFFF)+(y&0xFFFF);var m=(x>>16)+(y>>16)+(l>>16);return (m<<16)|(l&0xFFFF);}
7
+ function rl(n,c) {return (n<<c)|(n>>>(32-c));}
8
+ function cm(q,a,b,x,s,t) {return ad(rl(ad(ad(a,q),ad(x,t)),s),b);}
9
+ function ff(a,b,c,d,x,s,t) {return cm((b&c)|((~b)&d),a,b,x,s,t);}
10
+ function gg(a,b,c,d,x,s,t) {return cm((b&d)|(c&(~d)),a,b,x,s,t);}
11
+ function hh(a,b,c,d,x,s,t) {return cm(b^c^d,a,b,x,s,t);}
12
+ function ii(a,b,c,d,x,s,t) {return cm(c^(b|(~d)),a,b,x,s,t);}
13
+ function sb(x) {
14
+ var i;var nblk=((x.length+8)>>6)+1;var blks=new Array(nblk*16);for(i=0;i<nblk*16;i++) blks[i]=0;
15
+ for(i=0;i<x.length;i++) blks[i>>2]|=x.charCodeAt(i)<<((i%4)*8);
16
+ blks[i>>2]|=0x80<<((i%4)*8);blks[nblk*16-2]=x.length*8;return blks;
17
+ }
18
+ var i,x=sb(""+inputString),a=1732584193,b=-271733879,c=-1732584194,d=271733878,olda,oldb,oldc,oldd;
19
+ for(i=0;i<x.length;i+=16) {olda=a;oldb=b;oldc=c;oldd=d;
20
+ a=ff(a,b,c,d,x[i+ 0], 7, -680876936);d=ff(d,a,b,c,x[i+ 1],12, -389564586);c=ff(c,d,a,b,x[i+ 2],17, 606105819);
21
+ b=ff(b,c,d,a,x[i+ 3],22,-1044525330);a=ff(a,b,c,d,x[i+ 4], 7, -176418897);d=ff(d,a,b,c,x[i+ 5],12, 1200080426);
22
+ c=ff(c,d,a,b,x[i+ 6],17,-1473231341);b=ff(b,c,d,a,x[i+ 7],22, -45705983);a=ff(a,b,c,d,x[i+ 8], 7, 1770035416);
23
+ d=ff(d,a,b,c,x[i+ 9],12,-1958414417);c=ff(c,d,a,b,x[i+10],17, -42063);b=ff(b,c,d,a,x[i+11],22,-1990404162);
24
+ a=ff(a,b,c,d,x[i+12], 7, 1804603682);d=ff(d,a,b,c,x[i+13],12, -40341101);c=ff(c,d,a,b,x[i+14],17,-1502002290);
25
+ b=ff(b,c,d,a,x[i+15],22, 1236535329);a=gg(a,b,c,d,x[i+ 1], 5, -165796510);d=gg(d,a,b,c,x[i+ 6], 9,-1069501632);
26
+ c=gg(c,d,a,b,x[i+11],14, 643717713);b=gg(b,c,d,a,x[i+ 0],20, -373897302);a=gg(a,b,c,d,x[i+ 5], 5, -701558691);
27
+ d=gg(d,a,b,c,x[i+10], 9, 38016083);c=gg(c,d,a,b,x[i+15],14, -660478335);b=gg(b,c,d,a,x[i+ 4],20, -405537848);
28
+ a=gg(a,b,c,d,x[i+ 9], 5, 568446438);d=gg(d,a,b,c,x[i+14], 9,-1019803690);c=gg(c,d,a,b,x[i+ 3],14, -187363961);
29
+ b=gg(b,c,d,a,x[i+ 8],20, 1163531501);a=gg(a,b,c,d,x[i+13], 5,-1444681467);d=gg(d,a,b,c,x[i+ 2], 9, -51403784);
30
+ c=gg(c,d,a,b,x[i+ 7],14, 1735328473);b=gg(b,c,d,a,x[i+12],20,-1926607734);a=hh(a,b,c,d,x[i+ 5], 4, -378558);
31
+ d=hh(d,a,b,c,x[i+ 8],11,-2022574463);c=hh(c,d,a,b,x[i+11],16, 1839030562);b=hh(b,c,d,a,x[i+14],23, -35309556);
32
+ a=hh(a,b,c,d,x[i+ 1], 4,-1530992060);d=hh(d,a,b,c,x[i+ 4],11, 1272893353);c=hh(c,d,a,b,x[i+ 7],16, -155497632);
33
+ b=hh(b,c,d,a,x[i+10],23,-1094730640);a=hh(a,b,c,d,x[i+13], 4, 681279174);d=hh(d,a,b,c,x[i+ 0],11, -358537222);
34
+ c=hh(c,d,a,b,x[i+ 3],16, -722521979);b=hh(b,c,d,a,x[i+ 6],23, 76029189);a=hh(a,b,c,d,x[i+ 9], 4, -640364487);
35
+ d=hh(d,a,b,c,x[i+12],11, -421815835);c=hh(c,d,a,b,x[i+15],16, 530742520);b=hh(b,c,d,a,x[i+ 2],23, -995338651);
36
+ a=ii(a,b,c,d,x[i+ 0], 6, -198630844);d=ii(d,a,b,c,x[i+ 7],10, 1126891415);c=ii(c,d,a,b,x[i+14],15,-1416354905);
37
+ b=ii(b,c,d,a,x[i+ 5],21, -57434055);a=ii(a,b,c,d,x[i+12], 6, 1700485571);d=ii(d,a,b,c,x[i+ 3],10,-1894986606);
38
+ c=ii(c,d,a,b,x[i+10],15, -1051523);b=ii(b,c,d,a,x[i+ 1],21,-2054922799);a=ii(a,b,c,d,x[i+ 8], 6, 1873313359);
39
+ d=ii(d,a,b,c,x[i+15],10, -30611744);c=ii(c,d,a,b,x[i+ 6],15,-1560198380);b=ii(b,c,d,a,x[i+13],21, 1309151649);
40
+ a=ii(a,b,c,d,x[i+ 4], 6, -145523070);d=ii(d,a,b,c,x[i+11],10,-1120210379);c=ii(c,d,a,b,x[i+ 2],15, 718787259);
41
+ b=ii(b,c,d,a,x[i+ 9],21, -343485551);a=ad(a,olda);b=ad(b,oldb);c=ad(c,oldc);d=ad(d,oldd);
42
+ }
43
+ return rh(a)+rh(b)+rh(c)+rh(d);
44
+ }
@@ -32,7 +32,7 @@ const RANDOM_LEN = 16;
32
32
  */
33
33
  export function isULID(str: string): boolean {
34
34
  // ttttttttttrrrrrrrrrrrrrrrr
35
- return str?.length === 26 && /^[0-9A-HJKMNP-TV-Z]{26}$/i.test(str);
35
+ return str?.length === 26 && /^[0-9]{10}[0-9A-HJKMNP-TV-Z]{16}$/i.test(str);
36
36
  }
37
37
 
38
38
  function replaceCharAt(str: string, index: number, char: string) {
@@ -1,6 +1,6 @@
1
1
  import { MaybePromise } from '../asyncs/MaybePromise';
2
2
  import { getGlobalThis } from '../isomorphics/getGlobalThis';
3
- import { FetchLike } from './index';
3
+ import { type FetchLike } from './types';
4
4
 
5
5
  export function createFetchWith({
6
6
  fetch = getGlobalThis().fetch,
@@ -14,19 +14,20 @@ export function createFetchWith({
14
14
  next: (url: string, req: RequestInit) => Promise<Response>;
15
15
  }) => MaybePromise<Response | void>;
16
16
  onResponse?: (ctx: { url: string; req: RequestInit; res: Response }) => MaybePromise<Response>;
17
- }): FetchLike {
18
- return async (urlOrRequest, init) => {
17
+ }) {
18
+ return async (urlOrRequest: string | Request, init?: RequestInit & { fetch?: FetchLike }) => {
19
19
  const url = String(urlOrRequest);
20
- let req: RequestInit = init || {};
20
+ let req = init || {};
21
+ const nextFetch = req.fetch || fetch;
21
22
  const res =
22
23
  (await onRequest({
23
24
  url,
24
25
  req,
25
26
  next: (url, init) => {
26
27
  req = init;
27
- return fetch(url, init);
28
+ return nextFetch(url, init);
28
29
  },
29
- })) ?? (await fetch(url, init));
30
+ })) ?? (await nextFetch(url, init));
30
31
  return onResponse({ url, req, res });
31
32
  };
32
33
  }
@@ -1,5 +1,7 @@
1
+ import { createFetchWith } from './createFetchWith';
1
2
  import { dumpRequest } from './dumpRequest';
2
- import { createFetchWith, dumpResponse, FetchLike } from './index';
3
+ import { dumpResponse } from './dumpResponse';
4
+ import { type FetchLike } from './types';
3
5
 
4
6
  export function createFetchWithLogging({
5
7
  fetch,
@@ -1,4 +1,4 @@
1
- export type FetchLike = (url: string | Request, init?: RequestInit) => Promise<Response>;
1
+ export type * from './types';
2
2
  export { createFetchWith } from './createFetchWith';
3
3
  export { createFetchWithLogging } from './createFetchWithLogging';
4
4
  export { dumpRequest } from './dumpRequest';
@@ -0,0 +1 @@
1
+ export type FetchLike<R extends RequestInit = RequestInit> = (url: string | Request, init?: R) => Promise<Response>;
@@ -0,0 +1 @@
1
+ export function clamp() {}
package/src/server.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  export { polyfillCrypto } from './servers/polyfillCrypto';
2
- export { polyfillFetch } from './servers/polyfillFetch';
3
2
  export { polyfillJsDom } from './servers/polyfillJsDom';
4
3
  export { polyfillBrowser } from './servers/polyfillBrowser';
5
- export { createFetchWithProxyByNodeFetch } from './servers/createFetchWithProxyByNodeFetch';
6
4
  export { createFetchWithProxyByUndici } from './servers/createFetchWithProxyByUndici';
7
5
  export { createFetchWithProxy } from './servers/createFetchWithProxy';
6
+ export { createFetchWithRetry, type FetchWithRetryOptions } from './servers/createFetchWithRetry';
7
+
8
+ export { md5 } from './servers/md5';