UNPKG

1.73 kBJavaScriptView Raw
1'use strict'
2
3let cli = require('heroku-cli-util')
4
5class AppTransfer {
6 /**
7 * @param {Object} options
8 * @param {Object} options.heroku - instance of heroku-client
9 * @param {string} options.appName - application that is being transferred
10 * @param {string} options.recipient - recipient of the transfer
11 * @param {boolean} options.personalToPersonal - determines if it is a transfer between individual accounts
12 */
13 constructor (opts) {
14 this.opts = opts
15 this.heroku = this.opts.heroku
16 this.appName = this.opts.appName
17 this.recipient = this.opts.recipient
18 this.personalToPersonal = this.opts.personalToPersonal
19
20 if (this.personalToPersonal === undefined) this.personalToPersonal = true
21
22 if (this.personalToPersonal) {
23 this.body = { app: this.appName, recipient: this.recipient }
24 this.transferMsg = `Initiating transfer of ${cli.color.app(this.appName)}`
25 if (!this.opts.bulk) this.transferMsg += ` to ${cli.color.magenta(this.recipient)}`
26 this.path = '/account/app-transfers'
27 this.method = 'POST'
28 } else {
29 this.body = { owner: this.recipient }
30 this.transferMsg = `Transferring ${cli.color.app(this.appName)}`
31 if (!this.opts.bulk) this.transferMsg += ` to ${cli.color.magenta(this.recipient)}`
32 this.path = `/organizations/apps/${this.appName}`
33 this.method = 'PATCH'
34 }
35 }
36
37 start () {
38 let request = this.init().then(request => {
39 if (request.state === 'pending') cli.action.done('email sent')
40 })
41 return cli.action(this.transferMsg, request)
42 }
43
44 init () {
45 return this.heroku.request({
46 path: this.path,
47 method: this.method,
48 body: this.body
49 })
50 }
51}
52
53module.exports = AppTransfer