query-registry
Advanced tools
Comparing version 2.1.0-0 to 2.2.0-0
@@ -36,2 +36,16 @@ /** | ||
* @example | ||
* Get the abbreviated packument for package `query-registry` from the npm registry: | ||
* | ||
* ```typescript | ||
* import { getAbbreviatedPackument } from 'query-registry'; | ||
* | ||
* (async () => { | ||
* const packument = await getAbbreviatedPackument({ name: 'query-registry' }); | ||
* | ||
* // Output: 'query-registry' | ||
* console.log(manifest.name); | ||
* })(); | ||
* ``` | ||
* | ||
* @example | ||
* Get the weekly downloads for package `query-registry` from the npm registry: | ||
@@ -69,3 +83,4 @@ * | ||
* Enable {@link https://www.npmjs.com/package/debug | debug messages} | ||
* by setting the `DEBUG` environment variable to `query-registry`: | ||
* by setting the `DEBUG` environment variable to `query-registry` | ||
* (available only in non production environments): | ||
* | ||
@@ -79,2 +94,3 @@ * ```bash | ||
export * from './data/registries'; | ||
export * from './endpoints/get-abbreviated-packument'; | ||
export * from './endpoints/get-daily-package-downloads'; | ||
@@ -85,2 +101,3 @@ export * from './endpoints/get-daily-registry-downloads'; | ||
export * from './endpoints/get-packument'; | ||
export * from './endpoints/get-raw-abbreviated-packument'; | ||
export * from './endpoints/get-raw-package-manifest'; | ||
@@ -91,2 +108,3 @@ export * from './endpoints/get-raw-packument'; | ||
export * from './endpoints/search-packages'; | ||
export * from './types/abbreviated-packument'; | ||
export * from './types/bug-tracker'; | ||
@@ -103,2 +121,3 @@ export * from './types/dist-info'; | ||
export * from './types/person'; | ||
export * from './types/raw-abbreviated-packument'; | ||
export * from './types/raw-package-manifest'; | ||
@@ -105,0 +124,0 @@ export * from './types/raw-packument'; |
export { cloudflareRegistry, npmRegistry, npmRegistryDownloadsAPI, npmRegistryMirrors, yarnRegistry } from './data/registries.esm.js'; | ||
export { getAbbreviatedPackument } from './endpoints/get-abbreviated-packument.esm.js'; | ||
export { getDailyPackageDownloads } from './endpoints/get-daily-package-downloads.esm.js'; | ||
@@ -7,2 +8,3 @@ export { getDailyRegistryDownloads } from './endpoints/get-daily-registry-downloads.esm.js'; | ||
export { getPackument } from './endpoints/get-packument.esm.js'; | ||
export { getRawAbbreviatedPackument } from './endpoints/get-raw-abbreviated-packument.esm.js'; | ||
export { getRawPackageManifest } from './endpoints/get-raw-package-manifest.esm.js'; | ||
@@ -9,0 +11,0 @@ export { getRawPackument } from './endpoints/get-raw-packument.esm.js'; |
@@ -78,2 +78,17 @@ 'use strict'; | ||
function normalizeRawAbbreviatedPackument({ | ||
rawAbbreviatedPackument | ||
}) { | ||
const { | ||
'dist-tags': distTags, | ||
name: id, | ||
modified: modifiedAt | ||
} = rawAbbreviatedPackument; | ||
return { ...rawAbbreviatedPackument, | ||
id, | ||
distTags, | ||
modifiedAt | ||
}; | ||
} | ||
/** | ||
@@ -151,2 +166,3 @@ * `FetchError` represents an error that happened when fetching a URL. | ||
url, | ||
headers, | ||
cached = true | ||
@@ -164,3 +180,5 @@ }) { | ||
const response = await unfetch__default["default"](url); | ||
const response = await unfetch__default["default"](url, { | ||
headers | ||
}); | ||
@@ -170,2 +188,3 @@ if (!response.ok) { | ||
url, | ||
headers, | ||
status: response.statusText, | ||
@@ -192,2 +211,3 @@ response | ||
endpoint, | ||
headers, | ||
query, | ||
@@ -209,2 +229,3 @@ registry = npmRegistry, | ||
url, | ||
headers, | ||
cached | ||
@@ -221,2 +242,3 @@ }); | ||
endpoint, | ||
headers, | ||
query, | ||
@@ -230,2 +252,103 @@ registry, | ||
/** | ||
* `getRawAbbreviatedPackument` returns the abbreviated packument (package document) | ||
* containing only the metadata necessary to install a package present on the registry. | ||
* | ||
* Note: the abbreviated packument is returned as retrieved from the registry. | ||
* | ||
* @param name - package name | ||
* @param registry - URL of the registry (default: npm registry) | ||
* @param mirrors - URLs of the registry mirrors (default: npm registry mirrors) | ||
* @param cached - accept cached responses (default: `true`) | ||
* | ||
* @example | ||
* Get the abbreviated packument for package `query-registry` from the npm registry: | ||
* | ||
* ```typescript | ||
* import { getRawAbbreviatedPackument } from 'query-registry'; | ||
* | ||
* (async () => { | ||
* const packument = await getRawAbbreviatedPackument({ name: 'query-registry' }); | ||
* | ||
* // Output: 'query-registry' | ||
* console.log(packument.name); | ||
* })(); | ||
* ``` | ||
* | ||
* @see {@link RawAbbreviatedPackument} | ||
* @see {@link npmRegistry} | ||
* @see {@link npmRegistryMirrors} | ||
*/ | ||
async function getRawAbbreviatedPackument({ | ||
name, | ||
registry, | ||
mirrors, | ||
cached | ||
}) { | ||
assertValidPackageName({ | ||
name | ||
}); | ||
const endpoint = `/${name}`; | ||
const headers = { | ||
Accept: 'application/vnd.npm.install-v1+json' | ||
}; | ||
return fetchFromRegistry({ | ||
endpoint, | ||
headers, | ||
registry, | ||
mirrors, | ||
cached | ||
}); | ||
} | ||
/** | ||
* `getAbbreviatedPackument` returns the abbreviated packument (package document) | ||
* containing only the metadata necessary to install a package present on the registry. | ||
* | ||
* @remarks | ||
* To get all the metadata (full packument) about a package see {@link getPackument}. | ||
* | ||
* @param name - package name | ||
* @param registry - URL of the registry (default: npm registry) | ||
* @param mirrors - URLs of the registry mirrors (default: npm registry mirrors) | ||
* @param cached - accept cached responses (default: `true`) | ||
* | ||
* @example | ||
* Get the abbreviated packument for package `query-registry` from the npm registry: | ||
* | ||
* ```typescript | ||
* import { getAbbreviatedPackument } from 'query-registry'; | ||
* | ||
* (async () => { | ||
* const packument = await getAbbreviatedPackument({ name: 'query-registry' }); | ||
* | ||
* // Output: 'query-registry' | ||
* console.log(packument.name); | ||
* })(); | ||
* ``` | ||
* | ||
* @see {@link AbbreviatedPackument} | ||
* @see {@link RawAbbreviatedPackument} | ||
* @see {@link npmRegistry} | ||
* @see {@link npmRegistryMirrors} | ||
*/ | ||
async function getAbbreviatedPackument({ | ||
name, | ||
registry, | ||
mirrors, | ||
cached | ||
}) { | ||
const rawAbbreviatedPackument = await getRawAbbreviatedPackument({ | ||
name, | ||
registry, | ||
mirrors, | ||
cached | ||
}); | ||
return normalizeRawAbbreviatedPackument({ | ||
rawAbbreviatedPackument | ||
}); | ||
} | ||
async function fetchDownloadsFromRegistry({ | ||
@@ -1101,2 +1224,3 @@ endpoint, | ||
exports.cloudflareRegistry = cloudflareRegistry; | ||
exports.getAbbreviatedPackument = getAbbreviatedPackument; | ||
exports.getDailyPackageDownloads = getDailyPackageDownloads; | ||
@@ -1107,2 +1231,3 @@ exports.getDailyRegistryDownloads = getDailyRegistryDownloads; | ||
exports.getPackument = getPackument; | ||
exports.getRawAbbreviatedPackument = getRawAbbreviatedPackument; | ||
exports.getRawPackageManifest = getRawPackageManifest; | ||
@@ -1109,0 +1234,0 @@ exports.getRawPackument = getRawPackument; |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("validate-npm-package-name"),e=require("make-error"),t=require("isomorphic-unfetch"),n=require("tiny-lru"),a=require("git-url-parse");function i(r){return r&&"object"==typeof r&&"default"in r?r:{default:r}}var s=i(r),o=i(e),c=i(t),d=i(n),u=i(a);const p=["https://registry.npmjs.cf","https://registry.yarnpkg.com"];class y extends e.BaseError{constructor(r,e){super(`fetch: request to ${r} failed with status ${e.statusText}`),this.url=void 0,this.response=void 0,this.url=r,this.response=e}}const g=o.default("InvalidPackageNameError"),l=o.default("InvalidPackageVersionError");async function f(r,...e){}function m({name:r}){const{validForOldPackages:e,validForNewPackages:t}=s.default(r);if(!e&&!t)throw f(),new g(`invalid package name: '${r}'`)}const w=d.default(250,3e5);async function h({url:r,cached:e=!0}){const t=w.get(r);if(e&&t)return f(),t;const n=await c.default(r);if(!n.ok)throw f(),new y(r,n);const a=await n.json();return e&&w.set(r,a),f(),a}async function P({endpoint:r,query:e,registry:t="https://registry.npmjs.org",mirrors:n=p,cached:a}){const i=[t,...n].map((t=>{const n=new URL(r,t);return n.search=null!=e?e:"",n.href}));let s;for(const r of i)try{return await h({url:r,cached:a})}catch(r){s=r}throw f(),s}async function k({endpoint:r,registryDownloadsAPI:e="https://api.npmjs.org",cached:t}){return P({endpoint:r,registry:e,mirrors:[],cached:t})}function v({rawDownloadPeriod:r="last-week"}){if("string"==typeof r)return r;if(r instanceof Date)return $(r);const{start:e,end:t}=r;return`${$(e)}:${$(t)}`}function $(r){return r.toISOString().split("T")[0]}function D({rawPackument:r,version:e="latest"}){var t;const{name:n,"dist-tags":a,versions:i}=r,s=i[null!=(t=a[e])?t:e];if(!s)throw f(),new l(`invalid package version: '${n}@${e}'`);return s}async function x({name:r,registry:e,mirrors:t,cached:n}){return m({name:r}),P({endpoint:`/${r}`,registry:e,mirrors:t,cached:n})}async function R({name:r,version:e,registry:t,mirrors:n,cached:a}){return D({rawPackument:await x({name:r,registry:t,mirrors:n,cached:a}),version:e})}function b({rawLicense:r}){if(r&&"string"==typeof r)return r}function I({rawRepository:r}){return function(r){return r&&"object"==typeof r&&"string"==typeof r.url&&["string","undefined"].includes(typeof r.type)&&["string","undefined"].includes(typeof r.directory)}(r)?j({rawRepository:r}):"string"==typeof r?j({rawRepository:{url:r}}):void 0}function j({rawRepository:r}){const{url:e,directory:t}=r,n=function({url:r}){let e;try{e=u.default(r)}catch{}return e}({url:e});if(!n)return;const{source:a,full_name:i,filepath:s}=n;return{type:"git",url:`https://${a.replace(/^$/,"github.com").replace(/^github$/,"github.com").replace(/^gitlab$/,"gitlab.com").replace(/^bitbucket$/,"bitbucket.org")}/${i}`,directory:null!=t?t:""!==s?s:void 0}}exports.FetchError=y,exports.InvalidPackageNameError=g,exports.InvalidPackageVersionError=l,exports.cloudflareRegistry="https://registry.npmjs.cf",exports.getDailyPackageDownloads=async function({name:r,period:e,registryDownloadsAPI:t,cached:n}){return m({name:r}),k({endpoint:`/downloads/range/${v({rawDownloadPeriod:e})}/${r}`,registryDownloadsAPI:t,cached:n})},exports.getDailyRegistryDownloads=async function({period:r,registryDownloadsAPI:e,cached:t}={}){return k({endpoint:`/downloads/range/${v({rawDownloadPeriod:r})}`,registryDownloadsAPI:e,cached:t})},exports.getPackageDownloads=async function({name:r,period:e,registryDownloadsAPI:t,cached:n}){return m({name:r}),k({endpoint:`/downloads/point/${v({rawDownloadPeriod:e})}/${r}`,registryDownloadsAPI:t,cached:n})},exports.getPackageManifest=async function({name:r,version:e,registry:t,mirrors:n,cached:a}){const i=await x({name:r,registry:t,mirrors:n,cached:a}),s=D({rawPackument:i,version:e});return await async function({rawPackageManifest:r,rawPackument:e,registry:t,mirrors:n,cached:a}){const{_id:i,name:s,version:o,license:c,repository:d,_npmUser:u}=r,p=e.time[o],y=b({rawLicense:c}),g=I({rawRepository:d}),l=await async function({rawPackageManifest:r,registry:e,mirrors:t,cached:n}){const{name:a,types:i,typings:s}=r,o=function({name:r}){return r.startsWith("@types/")?r:`@types/${r.replace("@","").replace("/","__")}`}({name:a});if(a===o||i||s)return;let c=!1;try{const{deprecated:r}=await R({name:o,registry:e,mirrors:t,cached:n});c=void 0===r}catch{}return c?o:void 0}({rawPackageManifest:r,registry:t,mirrors:n,cached:a}),f=function({name:r}){if(!r.startsWith("@types/"))return;const[e,t]=r.replace("@types/","").split("__");return t?`@${e}/${t}`:e}({name:s});return{...r,id:i,createdAt:p,publisher:u,license:y,gitRepository:g,definitelyTypedName:l,untypedName:f}}({rawPackageManifest:s,rawPackument:i,registry:t,mirrors:n,cached:a})},exports.getPackument=async function({name:r,registry:e,mirrors:t,cached:n}){return function({rawPackument:r}){const{_id:e,"dist-tags":t,time:n,license:a,repository:i}=r,s=b({rawLicense:a}),o=I({rawRepository:i}),c=Object.fromEntries(Object.entries(n).filter((([r])=>!["created","modified"].includes(r))));return{...r,id:e,distTags:t,versionsToTimestamps:c,license:s,gitRepository:o}}({rawPackument:await x({name:r,registry:e,mirrors:t,cached:n})})},exports.getRawPackageManifest=R,exports.getRawPackument=x,exports.getRegistryDownloads=async function({period:r,registryDownloadsAPI:e,cached:t}={}){return k({endpoint:`/downloads/point/${v({rawDownloadPeriod:r})}`,registryDownloadsAPI:e,cached:t})},exports.getRegistryMetadata=async function({registry:r,cached:e}={}){return P({registry:r,mirrors:[],endpoint:"/",cached:e})},exports.npmRegistry="https://registry.npmjs.org",exports.npmRegistryDownloadsAPI="https://api.npmjs.org",exports.npmRegistryMirrors=p,exports.searchPackages=async function({query:r,registry:e,mirrors:t,cached:n}){const a=function({rawSearchCriteria:r}){return Object.entries(r).filter((([,r])=>["string","number"].includes(typeof r))).map((([r,e])=>`${r}=${e}`)).join("&")}({rawSearchCriteria:r});return P({endpoint:"/-/v1/search",query:a,registry:e,mirrors:t,cached:n})},exports.yarnRegistry="https://registry.yarnpkg.com"; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("validate-npm-package-name"),r=require("make-error"),t=require("isomorphic-unfetch"),n=require("tiny-lru"),a=require("git-url-parse");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=i(e),o=i(r),c=i(t),d=i(n),u=i(a);const p=["https://registry.npmjs.cf","https://registry.yarnpkg.com"];class y extends r.BaseError{constructor(e,r){super(`fetch: request to ${e} failed with status ${r.statusText}`),this.url=void 0,this.response=void 0,this.url=e,this.response=r}}const g=o.default("InvalidPackageNameError"),l=o.default("InvalidPackageVersionError");async function m(e,...r){}function f({name:e}){const{validForOldPackages:r,validForNewPackages:t}=s.default(e);if(!r&&!t)throw m(),new g(`invalid package name: '${e}'`)}const h=d.default(250,3e5);async function w({url:e,headers:r,cached:t=!0}){const n=h.get(e);if(t&&n)return m(),n;const a=await c.default(e,{headers:r});if(!a.ok)throw m(),new y(e,a);const i=await a.json();return t&&h.set(e,i),m(),i}async function P({endpoint:e,headers:r,query:t,registry:n="https://registry.npmjs.org",mirrors:a=p,cached:i}){const s=[n,...a].map((r=>{const n=new URL(e,r);return n.search=null!=t?t:"",n.href}));let o;for(const e of s)try{return await w({url:e,headers:r,cached:i})}catch(e){o=e}throw m(),o}async function k({name:e,registry:r,mirrors:t,cached:n}){return f({name:e}),P({endpoint:`/${e}`,headers:{Accept:"application/vnd.npm.install-v1+json"},registry:r,mirrors:t,cached:n})}async function v({endpoint:e,registryDownloadsAPI:r="https://api.npmjs.org",cached:t}){return P({endpoint:e,registry:r,mirrors:[],cached:t})}function $({rawDownloadPeriod:e="last-week"}){if("string"==typeof e)return e;if(e instanceof Date)return b(e);const{start:r,end:t}=e;return`${b(r)}:${b(t)}`}function b(e){return e.toISOString().split("T")[0]}function x({rawPackument:e,version:r="latest"}){var t;const{name:n,"dist-tags":a,versions:i}=e,s=i[null!=(t=a[r])?t:r];if(!s)throw m(),new l(`invalid package version: '${n}@${r}'`);return s}async function D({name:e,registry:r,mirrors:t,cached:n}){return f({name:e}),P({endpoint:`/${e}`,registry:r,mirrors:t,cached:n})}async function R({name:e,version:r,registry:t,mirrors:n,cached:a}){return x({rawPackument:await D({name:e,registry:t,mirrors:n,cached:a}),version:r})}function A({rawLicense:e}){if(e&&"string"==typeof e)return e}function j({rawRepository:e}){return function(e){return e&&"object"==typeof e&&"string"==typeof e.url&&["string","undefined"].includes(typeof e.type)&&["string","undefined"].includes(typeof e.directory)}(e)?I({rawRepository:e}):"string"==typeof e?I({rawRepository:{url:e}}):void 0}function I({rawRepository:e}){const{url:r,directory:t}=e,n=function({url:e}){let r;try{r=u.default(e)}catch{}return r}({url:r});if(!n)return;const{source:a,full_name:i,filepath:s}=n;return{type:"git",url:`https://${a.replace(/^$/,"github.com").replace(/^github$/,"github.com").replace(/^gitlab$/,"gitlab.com").replace(/^bitbucket$/,"bitbucket.org")}/${i}`,directory:null!=t?t:""!==s?s:void 0}}exports.FetchError=y,exports.InvalidPackageNameError=g,exports.InvalidPackageVersionError=l,exports.cloudflareRegistry="https://registry.npmjs.cf",exports.getAbbreviatedPackument=async function({name:e,registry:r,mirrors:t,cached:n}){return function({rawAbbreviatedPackument:e}){const{"dist-tags":r,name:t,modified:n}=e;return{...e,id:t,distTags:r,modifiedAt:n}}({rawAbbreviatedPackument:await k({name:e,registry:r,mirrors:t,cached:n})})},exports.getDailyPackageDownloads=async function({name:e,period:r,registryDownloadsAPI:t,cached:n}){return f({name:e}),v({endpoint:`/downloads/range/${$({rawDownloadPeriod:r})}/${e}`,registryDownloadsAPI:t,cached:n})},exports.getDailyRegistryDownloads=async function({period:e,registryDownloadsAPI:r,cached:t}={}){return v({endpoint:`/downloads/range/${$({rawDownloadPeriod:e})}`,registryDownloadsAPI:r,cached:t})},exports.getPackageDownloads=async function({name:e,period:r,registryDownloadsAPI:t,cached:n}){return f({name:e}),v({endpoint:`/downloads/point/${$({rawDownloadPeriod:r})}/${e}`,registryDownloadsAPI:t,cached:n})},exports.getPackageManifest=async function({name:e,version:r,registry:t,mirrors:n,cached:a}){const i=await D({name:e,registry:t,mirrors:n,cached:a}),s=x({rawPackument:i,version:r});return await async function({rawPackageManifest:e,rawPackument:r,registry:t,mirrors:n,cached:a}){const{_id:i,name:s,version:o,license:c,repository:d,_npmUser:u}=e,p=r.time[o],y=A({rawLicense:c}),g=j({rawRepository:d}),l=await async function({rawPackageManifest:e,registry:r,mirrors:t,cached:n}){const{name:a,types:i,typings:s}=e,o=function({name:e}){return e.startsWith("@types/")?e:`@types/${e.replace("@","").replace("/","__")}`}({name:a});if(a===o||i||s)return;let c=!1;try{const{deprecated:e}=await R({name:o,registry:r,mirrors:t,cached:n});c=void 0===e}catch{}return c?o:void 0}({rawPackageManifest:e,registry:t,mirrors:n,cached:a}),m=function({name:e}){if(!e.startsWith("@types/"))return;const[r,t]=e.replace("@types/","").split("__");return t?`@${r}/${t}`:r}({name:s});return{...e,id:i,createdAt:p,publisher:u,license:y,gitRepository:g,definitelyTypedName:l,untypedName:m}}({rawPackageManifest:s,rawPackument:i,registry:t,mirrors:n,cached:a})},exports.getPackument=async function({name:e,registry:r,mirrors:t,cached:n}){return function({rawPackument:e}){const{_id:r,"dist-tags":t,time:n,license:a,repository:i}=e,s=A({rawLicense:a}),o=j({rawRepository:i}),c=Object.fromEntries(Object.entries(n).filter((([e])=>!["created","modified"].includes(e))));return{...e,id:r,distTags:t,versionsToTimestamps:c,license:s,gitRepository:o}}({rawPackument:await D({name:e,registry:r,mirrors:t,cached:n})})},exports.getRawAbbreviatedPackument=k,exports.getRawPackageManifest=R,exports.getRawPackument=D,exports.getRegistryDownloads=async function({period:e,registryDownloadsAPI:r,cached:t}={}){return v({endpoint:`/downloads/point/${$({rawDownloadPeriod:e})}`,registryDownloadsAPI:r,cached:t})},exports.getRegistryMetadata=async function({registry:e,cached:r}={}){return P({registry:e,mirrors:[],endpoint:"/",cached:r})},exports.npmRegistry="https://registry.npmjs.org",exports.npmRegistryDownloadsAPI="https://api.npmjs.org",exports.npmRegistryMirrors=p,exports.searchPackages=async function({query:e,registry:r,mirrors:t,cached:n}){const a=function({rawSearchCriteria:e}){return Object.entries(e).filter((([,e])=>["string","number"].includes(typeof e))).map((([e,r])=>`${e}=${r}`)).join("&")}({rawSearchCriteria:e});return P({endpoint:"/-/v1/search",query:a,registry:r,mirrors:t,cached:n})},exports.yarnRegistry="https://registry.yarnpkg.com"; | ||
//# sourceMappingURL=query-registry.cjs.production.min.js.map |
@@ -1,3 +0,4 @@ | ||
export declare function fetchFromRegistry<T>({ endpoint, query, registry, mirrors, cached, }: { | ||
export declare function fetchFromRegistry<T>({ endpoint, headers, query, registry, mirrors, cached, }: { | ||
endpoint: string; | ||
headers?: Record<string, string>; | ||
query?: string; | ||
@@ -4,0 +5,0 @@ registry?: string; |
@@ -7,2 +7,3 @@ import { npmRegistry, npmRegistryMirrors } from '../data/registries.esm.js'; | ||
endpoint, | ||
headers, | ||
query, | ||
@@ -24,2 +25,3 @@ registry = npmRegistry, | ||
url, | ||
headers, | ||
cached | ||
@@ -36,2 +38,3 @@ }); | ||
endpoint, | ||
headers, | ||
query, | ||
@@ -38,0 +41,0 @@ registry, |
@@ -1,5 +0,6 @@ | ||
export declare function fetch({ url, cached, }: { | ||
export declare function fetch({ url, headers, cached, }: { | ||
url: string; | ||
headers?: Record<string, string>; | ||
cached?: boolean; | ||
}): Promise<any>; | ||
//# sourceMappingURL=fetch.d.ts.map |
@@ -11,2 +11,3 @@ import unfetch from 'isomorphic-unfetch'; | ||
url, | ||
headers, | ||
cached = true | ||
@@ -24,3 +25,5 @@ }) { | ||
const response = await unfetch(url); | ||
const response = await unfetch(url, { | ||
headers | ||
}); | ||
@@ -30,2 +33,3 @@ if (!response.ok) { | ||
url, | ||
headers, | ||
status: response.statusText, | ||
@@ -32,0 +36,0 @@ response |
{ | ||
"name": "query-registry", | ||
"description": "Query the npm registry for packuments, manifests, packages and download counts", | ||
"version": "2.1.0-0", | ||
"version": "2.2.0-0", | ||
"author": "Edoardo Scibona (velut)", | ||
@@ -87,3 +87,3 @@ "license": "MIT", | ||
"np": "7.6.0", | ||
"prettier": "2.4.1", | ||
"prettier": "2.5.0", | ||
"setup-polly-jest": "0.10.0", | ||
@@ -90,0 +90,0 @@ "tslib": "2.3.1", |
@@ -17,3 +17,3 @@ # query-registry | ||
- Get registry metadata | ||
- Get packuments (package documents) | ||
- Get packuments (package documents) and their abbreviated form | ||
- Get package manifests | ||
@@ -77,2 +77,15 @@ - Get download counts (packages and registry) | ||
Get the abbreviated packument for package `query-registry` from the npm registry: | ||
```typescript | ||
import { getAbbreviatedPackument } from 'query-registry'; | ||
(async () => { | ||
const packument = await getAbbreviatedPackument({ name: 'query-registry' }); | ||
// Output: 'query-registry' | ||
console.log(packument.name); | ||
})(); | ||
``` | ||
Get the weekly downloads for package `query-registry` from the npm registry: | ||
@@ -111,3 +124,3 @@ | ||
Debug messages are available when the `DEBUG` environment variable is set to `query-registry`: | ||
Debug messages are available in non production environments when the `DEBUG` environment variable is set to `query-registry`: | ||
@@ -114,0 +127,0 @@ ```bash |
@@ -36,2 +36,16 @@ /** | ||
* @example | ||
* Get the abbreviated packument for package `query-registry` from the npm registry: | ||
* | ||
* ```typescript | ||
* import { getAbbreviatedPackument } from 'query-registry'; | ||
* | ||
* (async () => { | ||
* const packument = await getAbbreviatedPackument({ name: 'query-registry' }); | ||
* | ||
* // Output: 'query-registry' | ||
* console.log(manifest.name); | ||
* })(); | ||
* ``` | ||
* | ||
* @example | ||
* Get the weekly downloads for package `query-registry` from the npm registry: | ||
@@ -69,3 +83,4 @@ * | ||
* Enable {@link https://www.npmjs.com/package/debug | debug messages} | ||
* by setting the `DEBUG` environment variable to `query-registry`: | ||
* by setting the `DEBUG` environment variable to `query-registry` | ||
* (available only in non production environments): | ||
* | ||
@@ -80,2 +95,3 @@ * ```bash | ||
export * from './data/registries'; | ||
export * from './endpoints/get-abbreviated-packument'; | ||
export * from './endpoints/get-daily-package-downloads'; | ||
@@ -86,2 +102,3 @@ export * from './endpoints/get-daily-registry-downloads'; | ||
export * from './endpoints/get-packument'; | ||
export * from './endpoints/get-raw-abbreviated-packument'; | ||
export * from './endpoints/get-raw-package-manifest'; | ||
@@ -92,2 +109,3 @@ export * from './endpoints/get-raw-packument'; | ||
export * from './endpoints/search-packages'; | ||
export * from './types/abbreviated-packument'; | ||
export * from './types/bug-tracker'; | ||
@@ -104,2 +122,3 @@ export * from './types/dist-info'; | ||
export * from './types/person'; | ||
export * from './types/raw-abbreviated-packument'; | ||
export * from './types/raw-package-manifest'; | ||
@@ -106,0 +125,0 @@ export * from './types/raw-packument'; |
@@ -8,2 +8,3 @@ import { npmRegistry, npmRegistryMirrors } from '../data/registries'; | ||
endpoint, | ||
headers, | ||
query, | ||
@@ -15,2 +16,3 @@ registry = npmRegistry, | ||
endpoint: string; | ||
headers?: Record<string, string>; | ||
query?: string; | ||
@@ -30,3 +32,3 @@ registry?: string; | ||
try { | ||
const json = await fetch({ url, cached }); | ||
const json = await fetch({ url, headers, cached }); | ||
return json as T; | ||
@@ -43,2 +45,3 @@ } catch (err) { | ||
endpoint, | ||
headers, | ||
query, | ||
@@ -45,0 +48,0 @@ registry, |
@@ -12,5 +12,7 @@ import unfetch from 'isomorphic-unfetch'; | ||
url, | ||
headers, | ||
cached = true, | ||
}: { | ||
url: string; | ||
headers?: Record<string, string>; | ||
cached?: boolean; | ||
@@ -24,6 +26,7 @@ }): Promise<any> { | ||
const response = await unfetch(url); | ||
const response = await unfetch(url, { headers }); | ||
if (!response.ok) { | ||
log('fetch: request failed: %O', { | ||
url, | ||
headers, | ||
status: response.statusText, | ||
@@ -30,0 +33,0 @@ response, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
392672
219
6090
137