@heroku/skynet 1.6.16 → 1.6.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,7 @@ const cli = require('heroku-cli-util')
2
2
  const command = require('../../lib/command')
3
3
  const sudo = require('../../lib/sudo')
4
4
  const SkynetAPI = require('../../lib/skynet')
5
+ const HerokuAPI = require('../../lib/heroku')
5
6
 
6
7
  function readlines (file) {
7
8
  return new Promise(function (resolve, reject) {
@@ -26,15 +27,22 @@ function readlines (file) {
26
27
  })
27
28
  }
28
29
 
30
+ async function unverifyUser (api, user) {
31
+ const resMsg = await api.unverifyUser(user)
32
+ cli.log('Unverify ' + user + ': ' + resMsg)
33
+ }
34
+
29
35
  async function run (context) {
30
36
  sudo()
31
37
  const skynet = new SkynetAPI(context.auth.password)
38
+ const api = new HerokuAPI(context.auth.password)
32
39
  const user = context.flags.user || process.env.HEROKU_USER
33
40
  const file = context.flags.infile
34
41
  const notes = context.flags.notes
35
42
  const category = context.flags.category
36
43
  const force = context.flags.bypass
37
44
  const notify = !context.flags['no-notify']
45
+ const unverify = context.flags.unverify
38
46
 
39
47
  if (user && file) {
40
48
  throw new Error('Either --user USER or --infile must be passed, but not both')
@@ -44,6 +52,10 @@ async function run (context) {
44
52
  const users = await readlines(file)
45
53
  const response = await skynet.bulkSuspendUsers(users.join(), notes, category, notify, force)
46
54
  cli.log(response)
55
+
56
+ if (unverify) {
57
+ users.forEach(item => unverifyUser(api, item))
58
+ }
47
59
  } else {
48
60
  if (!user) {
49
61
  throw new Error('Required flag: --user USER or --infile FILE')
@@ -52,6 +64,10 @@ async function run (context) {
52
64
  let response = await skynet.suspendUser(user, notes, category, notify, force)
53
65
  response = JSON.parse(response)
54
66
  cli.log(`${response.status}. ${response.message}`)
67
+
68
+ if (unverify) {
69
+ unverifyUser(api, user)
70
+ }
55
71
  }
56
72
  }
57
73
 
@@ -67,7 +83,8 @@ module.exports = {
67
83
  { name: 'category', char: 'c', description: 'suspension category', hasValue: true, required: true },
68
84
  { name: 'notes', char: 'n', description: 'suspend notes', hasValue: true, required: true },
69
85
  { name: 'bypass', description: 'bypass the whitelist', hasValue: false, required: false },
70
- { name: 'no-notify', description: 'skip user suspension email notification', hasValue: false, required: false }
86
+ { name: 'no-notify', description: 'skip user suspension email notification', hasValue: false, required: false },
87
+ { name: 'unverify', description: 'unverifies a user account, removes all billing info', hasValue: false, required: false }
71
88
  ],
72
89
  run: command(run)
73
90
  }
package/lib/heroku.js ADDED
@@ -0,0 +1,30 @@
1
+ 'use restrict'
2
+
3
+ const got = require('got')
4
+ const apiHost = 'https://api.heroku.com'
5
+ const qs = require('querystring')
6
+
7
+ module.exports = class HerokuAPI {
8
+ constructor (token) {
9
+ this.token = token
10
+ }
11
+
12
+ request (url, options = {}) {
13
+ options.headers = Object.assign({
14
+ Authorization: `Bearer ${this.token}`,
15
+ Accept: 'application/json',
16
+ 'Content-type': 'application/x-www-form-urlencoded',
17
+ 'X-Heroku-Sudo': 'true'
18
+ })
19
+
20
+ return got(apiHost + url, options).then(res => 'done').catch(exception => 'failed')
21
+ }
22
+
23
+ unverifyUser (user) {
24
+ return this.request(`/admin/users/payment-method?${user}`, {
25
+ method: 'delete',
26
+ body: qs.stringify({ user }),
27
+ json: false
28
+ })
29
+ }
30
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heroku/skynet",
3
- "version": "1.6.16",
3
+ "version": "1.6.17",
4
4
  "description": "use Skynet from Heroku CLI",
5
5
  "main": "index.js",
6
6
  "author": "Bob Argenbright @byt3smith",