function ping (args, silent, cb) { if (typeof cb !== 'function') { cb = silent silent = false } const opts = PingConfig(npmConfig()) const registry = opts.registry log.notice('PING', registry) const start = Date.now() return fetch('/-/ping?write=true', opts).then( res => res.json().catch(() => ({})) ).then(details => { if (silent) { } else { const time = Date.now() - start log.notice('PONG', `${time / 1000}ms`) if (npm.config.get('json')) { output(JSON.stringify({ registry, time, details }, null, 2)) } else if (Object.keys(details).length) { log.notice('PONG', `${JSON.stringify(details, null, 2)}`) } } }).nodeify(cb) }
return whoami([], true, () => {}).then(username => { if (username) { // first, get a list of remote packages this user owns. // once we have a user account, then don't complete anything. // get the list of packages by user return fetch( `/-/by-user/${encodeURIComponent(username)}`, DeprecateConfig() ).then(list => list[username]) } })
function createEntryUpdateStream (staleness, latest, opts) { log.verbose('all-package-metadata', 'creating remote entry stream') let partialUpdate = false let uri = '/-/all' if (latest && (Date.now() - latest < (staleness * 1000))) { // Skip the request altogether if our `latest` isn't stale. log.verbose('all-package-metadata', 'Local data up to date, skipping update') return BB.resolve({}) } else if (latest === 0) { log.warn('', 'Building the local index for the first time, please be patient') log.verbose('all-package-metadata', 'No cached data: requesting full metadata db') } else { log.verbose('all-package-metadata', 'Cached data present with timestamp:', latest, 'requesting partial index update') uri += '/since?stale=update_after&startkey=' + latest partialUpdate = true } return npmFetch(uri, opts).then(res => { log.silly('all-package-metadata', 'request stream opened, code:', res.statusCode) let entryStream = ms.pipeline.obj( res.body, JSONStream.parse('*', (pkg, key) => { if (key[0] === '_updated' || key[0][0] !== '_') { return pkg } }) ) if (partialUpdate) { // The `/all/since` endpoint doesn't return `_updated`, so we // just use the request's own timestamp. return { updateStream: entryStream, updatedLatest: Date.parse(res.headers.get('date')) } } else { return extractUpdated(entryStream, 'entry-update-stream', opts) } }) }
return otplease(reqOpts, reqOpts => regFetch(url, reqOpts)).then(() => {
return otplease(opts, opts => fetch(uri, opts.concat({ spec: p, method: 'PUT', body: packument, ignoreBody: true })))