({ positionalArgs, flags })
| 204 | } |
| 205 | |
| 206 | async createConfigCommand ({ positionalArgs, flags }) { |
| 207 | const { providerName, providerEntity, providerHostname } = this.constructor |
| 208 | const dryRun = this.config.get('dry-run') |
| 209 | const yes = this.config.get('yes') // deep-lore this allows for --no-yes |
| 210 | |
| 211 | const allowPublish = flags['allow-publish'] |
| 212 | const allowStagePublish = flags['allow-stage-publish'] |
| 213 | |
| 214 | if (!allowPublish && !allowStagePublish) { |
| 215 | throw new Error('At least one permission flag is required (--allow-publish, --allow-stage-publish)') |
| 216 | } |
| 217 | |
| 218 | const permissions = [] |
| 219 | if (allowPublish) { |
| 220 | permissions.push(PERMISSIONS.CREATE_PACKAGE) |
| 221 | } |
| 222 | if (allowStagePublish) { |
| 223 | permissions.push(PERMISSIONS.CREATE_STAGED_PACKAGE) |
| 224 | } |
| 225 | |
| 226 | const options = await this.flagsToOptions({ positionalArgs, flags, providerHostname }) |
| 227 | this.dialogue`Establishing trust between ${options.values.package} package and ${providerName}` |
| 228 | this.dialogue`Anyone with ${providerEntity} write access can publish to ${options.values.package}` |
| 229 | this.dialogue`Two-factor authentication is required for this operation` |
| 230 | if (!this.registryIsDefault) { |
| 231 | this.warn`Registry ${this.npm.config.get('registry')} may not support trusted publishing` |
| 232 | } |
| 233 | this.logOptions({ ...options, permissions }) |
| 234 | if (dryRun) { |
| 235 | return |
| 236 | } |
| 237 | await this.confirmOperation(yes) |
| 238 | const trustConfig = this.constructor.optionsToBody(options.values) |
| 239 | trustConfig.permissions = permissions |
| 240 | const response = await this.createConfig(options.values.package, [trustConfig]) |
| 241 | const body = await response.json() |
| 242 | this.dialogue`Trust configuration created successfully for ${options.values.package} with the following settings:` |
| 243 | this.displayResponseBody({ body, packageName: options.values.package }) |
| 244 | } |
| 245 | |
| 246 | async flagsToOptions ({ positionalArgs, flags, providerHostname }) { |
| 247 | const { entityKey, name, providerEntity, providerFile } = this.constructor |
no test coverage detected