MCPcopy Index your code
hub / github.com/nodejs/node / rm

Method rm

deps/npm/lib/commands/token.js:107–150  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

105 }
106
107 async rm (args) {
108 if (args.length === 0) {
109 throw this.usageError('`<tokenKey>` argument is required.')
110 }
111
112 const json = this.npm.config.get('json')
113 const parseable = this.npm.config.get('parseable')
114 const toRemove = []
115 log.info('token', `removing ${toRemove.length} tokens`)
116 const tokens = await paginate('/-/npm/v1/tokens', this.npm.flatOptions)
117 for (const id of args) {
118 const matches = tokens.filter(token => token.key.indexOf(id) === 0)
119 if (matches.length === 1) {
120 toRemove.push(matches[0].key)
121 } else if (matches.length > 1) {
122 throw new Error(
123 `Token ID "${id}" was ambiguous, a new token may have been created since you last ran \`npm token list\`.`
124 )
125 } else {
126 const tokenMatches = tokens.some(t => id.indexOf(t.token) === 0)
127 if (!tokenMatches) {
128 throw new Error(`Unknown token id or value "${id}".`)
129 }
130
131 toRemove.push(id)
132 }
133 }
134 for (const tokenKey of toRemove) {
135 await otplease(this.npm, this.npm.flatOptions, opts =>
136 fetch(`/-/npm/v1/tokens/token/${tokenKey}`, {
137 ...opts,
138 method: 'DELETE',
139 ignoreBody: true,
140 })
141 )
142 }
143 if (json) {
144 output.buffer(toRemove)
145 } else if (parseable) {
146 output.standard(toRemove.join('\t'))
147 } else {
148 output.standard('Removed ' + toRemove.length + ' token' + (toRemove.length !== 1 ? 's' : ''))
149 }
150 }
151
152 async create () {
153 const json = this.npm.config.get('json')

Callers 1

execMethod · 0.95

Calls 12

paginateFunction · 0.85
otpleaseFunction · 0.85
fetchFunction · 0.85
usageErrorMethod · 0.80
infoMethod · 0.80
someMethod · 0.80
getMethod · 0.65
filterMethod · 0.65
indexOfMethod · 0.45
pushMethod · 0.45
bufferMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected