|
1 | 1 | 'use strict' |
2 | 2 |
|
3 | | -const promisify = require('promisify-es6') |
| 3 | +const callbackify = require('callbackify') |
| 4 | +const configure = require('../../lib/configure') |
4 | 5 |
|
5 | | -const toObject = function (res, callback) { |
6 | | - if (Buffer.isBuffer(res)) { |
7 | | - callback(null, JSON.parse(res.toString())) |
8 | | - } else { |
9 | | - callback(null, res) |
10 | | - } |
11 | | -} |
| 6 | +module.exports = configure(({ ky }) => { |
| 7 | + return callbackify.variadic(async (profile, options) => { |
| 8 | + options = options || {} |
12 | 9 |
|
13 | | -module.exports = (send) => { |
14 | | - return promisify((profile, opts, callback) => { |
15 | | - if (typeof opts === 'function') { |
16 | | - callback = opts |
17 | | - opts = {} |
18 | | - } |
19 | | - |
20 | | - opts = normalizeOpts(opts) |
21 | | - |
22 | | - send.andTransform({ |
23 | | - path: 'config/profile/apply', |
24 | | - args: profile, |
25 | | - qs: opts |
26 | | - }, toObject, (err, response) => { |
27 | | - if (err) { |
28 | | - return callback(err) |
| 10 | + const res = await ky.post('config/profile/apply', { |
| 11 | + timeout: options.timeout, |
| 12 | + signal: options.signal, |
| 13 | + headers: options.headers, |
| 14 | + searchParams: { |
| 15 | + arg: profile, |
| 16 | + // can only pass strings or numbers as values https://github.com/sindresorhus/ky/issues/182 |
| 17 | + 'dry-run': options.dryRun ? 'true' : 'false' |
29 | 18 | } |
30 | | - callback(null, { old: response.OldCfg, new: response.NewCfg }) |
31 | 19 | }) |
32 | | - }) |
33 | | -} |
34 | 20 |
|
35 | | -function normalizeOpts (opts) { |
36 | | - opts = opts || {} |
37 | | - if (typeof opts.dryRun !== 'undefined') { |
38 | | - opts['dry-run'] = opts.dryRun |
39 | | - } |
40 | | - return opts |
41 | | -} |
| 21 | + const parsed = await res.json() |
| 22 | + |
| 23 | + return { |
| 24 | + original: parsed.OldCfg, updated: parsed.NewCfg |
| 25 | + } |
| 26 | + }) |
| 27 | +}) |
0 commit comments