@joytreesite/joytree 1.0.1 → 1.0.3

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.
Files changed (3) hide show
  1. package/bin/joytree.js +132 -209
  2. package/lib/api.js +22 -22
  3. package/package.json +1 -1
package/bin/joytree.js CHANGED
@@ -4,7 +4,6 @@
4
4
  const { program } = require('commander');
5
5
  const pkg = require('../package.json');
6
6
 
7
- // Commands
8
7
  const auth = require('../commands/auth');
9
8
  const deploy = require('../commands/deploy');
10
9
  const projects= require('../commands/projects');
@@ -19,117 +18,91 @@ const ssh = require('../commands/ssh');
19
18
  const extras = require('../commands/extras');
20
19
  const ui = require('../lib/ui');
21
20
 
22
- // ── Custom help screen ────────────────────────────────────────────────
23
21
  function showHelp() {
24
22
  const c = ui.c;
25
23
  ui.logo();
26
24
 
27
- console.log(`${c.bold}USAGE${c.reset}`);
28
- console.log(` joytree ${c.cyan}<command>${c.reset} ${c.dim}[options]${c.reset}\n`);
29
-
30
- const section = (title, icon) => {
31
- console.log(`${c.bold}${c.white}${icon} ${title}${c.reset}`);
25
+ // two-column row: left = cyan command, right = dim description
26
+ const row = (left, right) => {
27
+ const padded = left.padEnd(38);
28
+ console.log(` ${c.cyan}${padded}${c.reset}${c.dim}${right}${c.reset}`);
32
29
  };
33
30
 
34
- const cmd = (name, args, desc) => {
35
- const nameCol = `${c.cyan} joytree ${c.bold}${name}${c.reset}`;
36
- const argsCol = args ? ` ${c.dim}${args}${c.reset}` : '';
37
- const pad = Math.max(0, 42 - name.length - (args ? args.length + 1 : 0));
38
- console.log(`${nameCol}${argsCol}${' '.repeat(pad)}${c.dim}${desc}${c.reset}`);
31
+ const section = (title) => {
32
+ console.log(`\n${c.bold}${title}${c.reset}`);
39
33
  };
40
34
 
41
- // ── ACCOUNT ──
42
- section('Account', '◆');
43
- cmd('login', '--api-key <key>', 'Validate and save your Joytree API key');
44
- cmd('logout', '', 'Remove local credentials');
45
- cmd('whoami', '', 'Show the active account and API key scope');
46
- cmd('status', '', 'Show account status and project overview');
47
- console.log();
48
-
49
- // ── API KEY ──
50
- section('API Key', '◆');
51
- cmd('apikey show', '', 'View your current API key and usage stats');
52
- cmd('apikey rotate', '', 'Revoke old key and generate a new one');
53
- console.log();
54
-
55
- // ── DEPLOY ──
56
- section('Deploy', '◆');
57
- cmd('deploy', '-r <repo> -n <name>', 'Deploy a GitHub repo to Joytree');
58
- cmd('redeploy', '<project-id>', 'Trigger a fresh redeployment');
59
- cmd('stop', '<deploy-id>', 'Cancel a currently running deployment');
60
- cmd('autodeploy', '<project-id> --enable', 'Toggle GitHub push auto-deploy on/off');
61
- cmd('deployments', '[project-id]', 'Show recent deployment history');
62
- cmd('open', '<project-id>', 'Open the live URL in your browser');
63
- console.log();
64
-
65
- // ── PROJECTS ──
66
- section('Projects', '◆');
67
- cmd('projects', '', 'List all your projects');
68
- cmd('inspect', '<project-id>', 'Show full project details');
69
- cmd('delete', '<project-id>', 'Delete a project (irreversible)');
70
- console.log();
71
-
72
- // ── LOGS ──
73
- section('Logs', '◆');
74
- cmd('logs', '<project-id>', 'Fetch recent runtime logs');
75
- cmd('logs', '<project-id> --follow', 'Stream live logs in real time');
76
- console.log();
77
-
78
- // ── ENV VARS ──
79
- section('Environment Variables', '◆');
80
- cmd('env list', '<project-id>', 'List all env var keys');
81
- cmd('env set', '<project-id> KEY=VALUE', 'Set one or more env vars');
82
- cmd('env delete', '<project-id> <KEY>', 'Delete an env var');
83
- cmd('env push', '<project-id>', 'Push a local .env file to a project');
84
- console.log();
85
-
86
- // ── GITHUB ──
87
- section('GitHub', '◆');
88
- cmd('pull repos', '', 'List your linked GitHub repositories');
89
- cmd('pull branches', '<repo-url>', 'List branches for a repository');
90
- console.log();
91
-
92
- // ── DOMAINS ──
93
- section('Domains', '◆');
94
- cmd('domains list', '', 'List your custom domains');
95
- cmd('domains attach', '<domain> <project-id>', 'Attach a domain to a project');
96
- cmd('domains verify', '<domain>', 'Trigger DNS verification');
97
- cmd('domains remove', '<domain>', 'Remove a custom domain');
98
- cmd('domains check', '<domain>', 'Check domain availability');
99
- console.log();
100
-
101
- // ── DATABASES ──
102
- section('Databases', '◆');
103
- cmd('db list', '', 'List all databases');
104
- cmd('db create', '--type', 'Create a new database (postgres/mysql/redis/mongo)');
105
- cmd('db start', '<db-id>', 'Start a stopped database');
106
- cmd('db stop', '<db-id>', 'Stop a running database');
107
- cmd('db restart', '<db-id>', 'Restart a database');
108
- cmd('db logs', '<db-id>', 'Fetch recent database logs');
109
- cmd('db delete', '<db-id>', 'Delete a database (irreversible)');
110
- console.log();
111
-
112
- // ── WEBHOOK ──
113
- section('Webhooks', '◆');
114
- cmd('webhook secret', '', 'Show your global webhook secret');
115
- cmd('webhook rotate', '', 'Regenerate your webhook secret');
116
- console.log();
117
-
118
- // ── SSH ──
119
- section('SSH Keys', '◆');
120
- cmd('ssh list', '', 'List all SSH keys');
121
- cmd('ssh generate', '--name', 'Generate a new SSH key pair');
122
- cmd('ssh delete', '<key-id>', 'Delete an SSH key');
123
- console.log();
35
+ section('Account');
36
+ row('joytree login --api-key <key>', 'Validate and save a Joytree API key');
37
+ row('joytree logout', 'Remove local credentials');
38
+ row('joytree whoami', 'Show the active account and API key scope');
39
+ row('joytree status', 'Show account status and project overview');
40
+
41
+ section('API Key');
42
+ row('joytree apikey show', 'View your current API key and usage stats');
43
+ row('joytree apikey rotate', 'Revoke old key and generate a new one');
44
+
45
+ section('Deploy');
46
+ row('joytree deploy -r <repo>', 'Deploy a GitHub repo to Joytree');
47
+ row('joytree deploy -m "message"', 'Deploy with a custom commit message');
48
+ row('joytree redeploy <project-id>', 'Trigger a fresh redeployment');
49
+ row('joytree stop <deploy-id>', 'Cancel a currently running deployment');
50
+ row('joytree autodeploy <id> --enable', 'Enable GitHub push auto-deploy');
51
+ row('joytree autodeploy <id> --disable', 'Disable GitHub push auto-deploy');
52
+ row('joytree deployments [project-id]', 'Show recent deployments');
53
+ row('joytree open <project-id>', 'Open the live URL in your browser');
54
+
55
+ section('Projects');
56
+ row('joytree projects', 'List all your projects');
57
+ row('joytree inspect <project-id>', 'Show full project details');
58
+ row('joytree delete <project-id>', 'Delete a project (irreversible)');
59
+
60
+ section('Logs');
61
+ row('joytree logs <project-id>', 'Fetch recent runtime logs');
62
+ row('joytree logs <id> --follow', 'Stream live project logs');
63
+ row('joytree logs <id> --lines 100', 'Fetch logs by line count');
64
+
65
+ section('Project Config');
66
+ row('joytree env list <project-id>', 'List project env var keys');
67
+ row('joytree env set <id> KEY=VALUE', 'Set one or more env vars');
68
+ row('joytree env delete <id> <KEY>', 'Delete an env var');
69
+ row('joytree env push <project-id>', 'Push a local .env file to a project');
70
+ row('joytree env push <id> --force', 'Replace all existing env vars');
71
+
72
+ section('GitHub');
73
+ row('joytree pull repos', 'List your linked GitHub repositories');
74
+ row('joytree pull branches <repo-url>', 'List branches for a repository');
75
+
76
+ section('Domains');
77
+ row('joytree domains list', 'List your custom domains');
78
+ row('joytree domains attach <d> <id>', 'Attach a domain to a project');
79
+ row('joytree domains verify <domain>', 'Trigger DNS verification');
80
+ row('joytree domains remove <domain>', 'Remove a custom domain');
81
+ row('joytree domains check <domain>', 'Check domain availability');
82
+
83
+ section('Databases');
84
+ row('joytree db list', 'List all databases');
85
+ row('joytree db create --type <type>', 'Create a database (postgres/mysql/redis/mongo)');
86
+ row('joytree db start <db-id>', 'Start a stopped database');
87
+ row('joytree db stop <db-id>', 'Stop a running database');
88
+ row('joytree db restart <db-id>', 'Restart a database');
89
+ row('joytree db logs <db-id>', 'Fetch recent database logs');
90
+ row('joytree db delete <db-id>', 'Delete a database (irreversible)');
91
+
92
+ section('Webhooks');
93
+ row('joytree webhook secret', 'Show your global webhook secret');
94
+ row('joytree webhook rotate', 'Regenerate your webhook secret');
95
+
96
+ section('SSH Keys');
97
+ row('joytree ssh list', 'List all SSH keys');
98
+ row('joytree ssh generate --name <n>', 'Generate a new SSH key pair');
99
+ row('joytree ssh delete <key-id>', 'Delete an SSH key');
100
+
101
+ section('Activity');
102
+ row('joytree activity', 'Show recent platform activity feed');
103
+ row('joytree activity --limit <n>', 'Limit number of events shown');
124
104
 
125
- // ── ACTIVITY ──
126
- section('Activity', '◆');
127
- cmd('activity', '--limit <n>', 'Show recent platform activity feed');
128
105
  console.log();
129
-
130
- // ── FOOTER ──
131
- console.log(`${c.dim} Run ${c.cyan}joytree <command> --help${c.dim} for detailed options on any command.${c.reset}`);
132
- console.log(`${c.dim} Docs: ${c.cyan}https://docs.joytree.site${c.reset}\n`);
133
106
  }
134
107
 
135
108
  program
@@ -137,139 +110,89 @@ program
137
110
  .description('Joytree CLI — deploy and manage your projects from the terminal')
138
111
  .version(pkg.version)
139
112
  .helpOption(false)
140
- .addHelpCommand(false)
141
- .option('-h, --help', 'Show this help screen')
142
- .hook('preAction', (thisCommand) => {
143
- if (thisCommand.opts().help) { showHelp(); process.exit(0); }
144
- });
145
-
146
- // Override default --help
147
- program.on('--help', showHelp);
148
-
149
- // Show custom help when no args given
150
- if (process.argv.length === 2) {
151
- showHelp();
152
- process.exit(0);
153
- }
113
+ .addHelpCommand(false);
154
114
 
155
- // ── Auth ──────────────────────────────────────────────────────────────
156
- program
157
- .command('login')
158
- .description('Authenticate with your Joytree API key')
159
- .option('--api-key <key>', 'Provide API key directly (skips prompt)')
160
- .action(auth.login);
115
+ if (process.argv.length === 2) { showHelp(); process.exit(0); }
161
116
 
162
- program
163
- .command('logout')
164
- .description('Remove saved credentials')
165
- .action(auth.logout);
166
-
167
- program
168
- .command('whoami')
169
- .description('Show the active account and API key scope')
170
- .action(auth.whoami);
171
-
172
- program
173
- .command('status')
174
- .description('Show account status, plan, and project count')
175
- .action(account.status);
117
+ // ── Auth ──────────────────────────────────────────────────────────────
118
+ program.command('login').option('--api-key <key>').action(auth.login);
119
+ program.command('logout').action(auth.logout);
120
+ program.command('whoami').action(auth.whoami);
121
+ program.command('status').action(account.status);
176
122
 
177
123
  // ── API Key ───────────────────────────────────────────────────────────
178
- const apikeyGroup = program
179
- .command('apikey')
180
- .description('Manage your Joytree API key');
181
-
182
- apikeyGroup.command('show').description('Show your current API key and usage info').action(extras.apiKey);
183
- apikeyGroup.command('rotate').description('Generate a new API key and revoke the old one').action(extras.rotateApiKey);
124
+ const apikeyGroup = program.command('apikey');
125
+ apikeyGroup.command('show').action(extras.apiKey);
126
+ apikeyGroup.command('rotate').action(extras.rotateApiKey);
184
127
 
185
128
  // ── Activity ──────────────────────────────────────────────────────────
186
- program
187
- .command('activity')
188
- .description('Show recent platform activity')
189
- .option('--limit <n>', 'Number of events to show', '20')
190
- .action(extras.activity);
129
+ program.command('activity').option('--limit <n>', '', '20').action(extras.activity);
191
130
 
192
131
  // ── GitHub ────────────────────────────────────────────────────────────
193
- const pullGroup = program.command('pull').description('Browse connected GitHub repos and branches');
194
- pullGroup.command('repos').description('List your linked GitHub repositories').action(github.repos);
195
- pullGroup.command('branches <repo-url>').description('List branches for a repository').action(github.branches);
132
+ const pullGroup = program.command('pull');
133
+ pullGroup.command('repos').action(github.repos);
134
+ pullGroup.command('branches <repo-url>').action(github.branches);
196
135
 
197
136
  // ── Deploy ────────────────────────────────────────────────────────────
198
- program
199
- .command('deploy')
200
- .description('Deploy a GitHub repository to Joytree')
201
- .option('-r, --repo <url>', 'GitHub repository URL')
202
- .option('-b, --branch <branch>', 'Branch to deploy', 'main')
203
- .option('-n, --name <name>', 'Project name / subdomain')
204
- .option('--build <cmd>', 'Build command')
205
- .option('--start <cmd>', 'Start command')
206
- .option('--static', 'Mark as a static site')
207
- .option('-m, --message <msg>', 'Deployment message')
137
+ program.command('deploy')
138
+ .option('-r, --repo <url>')
139
+ .option('-b, --branch <branch>', '', 'main')
140
+ .option('-n, --name <name>')
141
+ .option('--build <cmd>')
142
+ .option('--start <cmd>')
143
+ .option('--static')
144
+ .option('-m, --message <msg>')
208
145
  .action(deploy.deployGit);
209
146
 
210
- program.command('redeploy <project-id>').description('Trigger a fresh deployment').action(deploy.redeploy);
211
- program.command('stop <deploy-id>').description('Stop a currently running deployment').action(extras.stopDeploy);
212
- program
213
- .command('autodeploy <project-id>')
214
- .description('Toggle GitHub push auto-deploy')
215
- .option('--enable', 'Enable auto-deploy')
216
- .option('--disable', 'Disable auto-deploy')
217
- .action(extras.autodeploy);
218
- program.command('open [project-id]').description('Open the live URL in your browser').action(deploy.open);
219
- program
220
- .command('deployments [project-id]')
221
- .description('Show recent deployments')
222
- .option('--limit <n>', 'Number to show', '10')
223
- .action(deploy.listDeployments);
147
+ program.command('redeploy <project-id>').action(deploy.redeploy);
148
+ program.command('stop <deploy-id>').action(extras.stopDeploy);
149
+ program.command('autodeploy <project-id>').option('--enable').option('--disable').action(extras.autodeploy);
150
+ program.command('open [project-id]').action(deploy.open);
151
+ program.command('deployments [project-id]').option('--limit <n>', '', '10').action(deploy.listDeployments);
224
152
 
225
153
  // ── Projects ──────────────────────────────────────────────────────────
226
- program.command('projects').description('List all your projects').option('--json', 'Output raw JSON').action(projects.list);
227
- program.command('inspect <project-id>').description('Show full project details').action(projects.inspect);
228
- program.command('delete <project-id>').description('Delete a project (irreversible)').option('-y, --yes', 'Skip confirmation').action(projects.deleteProject);
154
+ program.command('projects').option('--json').action(projects.list);
155
+ program.command('inspect <project-id>').action(projects.inspect);
156
+ program.command('delete <project-id>').option('-y, --yes').action(projects.deleteProject);
229
157
 
230
158
  // ── Logs ──────────────────────────────────────────────────────────────
231
- program
232
- .command('logs <project-id>')
233
- .description('Fetch runtime logs for a project')
234
- .option('--lines <n>', 'Number of lines', '50')
235
- .option('-f, --follow', 'Stream live logs')
236
- .action(logs.fetchLogs);
159
+ program.command('logs <project-id>').option('--lines <n>', '', '50').option('-f, --follow').action(logs.fetchLogs);
237
160
 
238
161
  // ── Env ───────────────────────────────────────────────────────────────
239
- const envGroup = program.command('env').description('Manage environment variables');
240
- envGroup.command('list <project-id>').description('List all env var keys').action(envCmd.list);
241
- envGroup.command('set <project-id> <KEY=VALUE...>').description('Set one or more env vars').action(envCmd.set);
242
- envGroup.command('delete <project-id> <KEY>').description('Delete an env var').action(envCmd.del);
243
- envGroup.command('push <project-id>').description('Push a .env file').option('--file <path>', 'Path to .env file', '.env').option('--force', 'Overwrite all existing vars').action(envCmd.push);
162
+ const envGroup = program.command('env');
163
+ envGroup.command('list <project-id>').action(envCmd.list);
164
+ envGroup.command('set <project-id> <KEY=VALUE...>').action(envCmd.set);
165
+ envGroup.command('delete <project-id> <KEY>').action(envCmd.del);
166
+ envGroup.command('push <project-id>').option('--file <path>', '', '.env').option('--force').action(envCmd.push);
244
167
 
245
168
  // ── Domains ───────────────────────────────────────────────────────────
246
- const domainGroup = program.command('domains').description('Manage custom domains');
247
- domainGroup.command('list').description('List your custom domains').action(domains.list);
248
- domainGroup.command('attach <domain> <project-id>').description('Attach a domain to a project').action(domains.attach);
249
- domainGroup.command('verify <domain>').description('Trigger DNS verification').action(domains.verify);
250
- domainGroup.command('remove <domain>').description('Remove a custom domain').action(domains.remove);
251
- domainGroup.command('check <domain>').description('Check domain availability').action(domains.check);
169
+ const domainGroup = program.command('domains');
170
+ domainGroup.command('list').action(domains.list);
171
+ domainGroup.command('attach <domain> <project-id>').action(domains.attach);
172
+ domainGroup.command('verify <domain>').action(domains.verify);
173
+ domainGroup.command('remove <domain>').action(domains.remove);
174
+ domainGroup.command('check <domain>').action(domains.check);
252
175
 
253
176
  // ── Databases ─────────────────────────────────────────────────────────
254
- const dbGroup = program.command('db').description('Manage databases');
255
- dbGroup.command('list').description('List all databases').action(db.list);
256
- dbGroup.command('create').description('Create a new database').option('--type <type>', 'Database type', 'postgres').option('--name <name>', 'Database name').action(db.create);
257
- dbGroup.command('start <db-id>').description('Start a stopped database').action(db.start);
258
- dbGroup.command('stop <db-id>').description('Stop a running database').action(db.stop);
259
- dbGroup.command('restart <db-id>').description('Restart a database').action(db.restart);
260
- dbGroup.command('logs <db-id>').description('Fetch database logs').action(db.fetchLogs);
261
- dbGroup.command('delete <db-id>').description('Delete a database').option('-y, --yes', 'Skip confirmation').action(db.del);
177
+ const dbGroup = program.command('db');
178
+ dbGroup.command('list').action(db.list);
179
+ dbGroup.command('create').option('--type <type>', '', 'postgres').option('--name <name>').action(db.create);
180
+ dbGroup.command('start <db-id>').action(db.start);
181
+ dbGroup.command('stop <db-id>').action(db.stop);
182
+ dbGroup.command('restart <db-id>').action(db.restart);
183
+ dbGroup.command('logs <db-id>').action(db.fetchLogs);
184
+ dbGroup.command('delete <db-id>').option('-y, --yes').action(db.del);
262
185
 
263
186
  // ── Webhook ───────────────────────────────────────────────────────────
264
- const webhookGroup = program.command('webhook').description('Manage GitHub webhook secrets');
265
- webhookGroup.command('secret').description('Show your global webhook secret').action(webhook.getSecret);
266
- webhookGroup.command('rotate').description('Regenerate your webhook secret').action(webhook.rotateSecret);
187
+ const webhookGroup = program.command('webhook');
188
+ webhookGroup.command('secret').action(webhook.getSecret);
189
+ webhookGroup.command('rotate').action(webhook.rotateSecret);
267
190
 
268
191
  // ── SSH ───────────────────────────────────────────────────────────────
269
- const sshGroup = program.command('ssh').description('Manage SSH keys');
270
- sshGroup.command('list').description('List all SSH keys').action(ssh.list);
271
- sshGroup.command('generate').description('Generate a new SSH key pair').option('--name <name>', 'Key name/label').action(ssh.generate);
272
- sshGroup.command('delete <key-id>').description('Delete an SSH key').option('-y, --yes', 'Skip confirmation').action(ssh.del);
192
+ const sshGroup = program.command('ssh');
193
+ sshGroup.command('list').action(ssh.list);
194
+ sshGroup.command('generate').option('--name <name>').action(ssh.generate);
195
+ sshGroup.command('delete <key-id>').option('-y, --yes').action(ssh.del);
273
196
 
274
197
  program.parseAsync(process.argv).catch(err => {
275
198
  console.error('Error:', err.message);
package/lib/api.js CHANGED
@@ -1,15 +1,10 @@
1
1
  'use strict';
2
2
 
3
- const https = require('https');
4
- const http = require('http');
3
+ const https = require('https');
4
+ const http = require('http');
5
5
  const { URL } = require('url');
6
- const config = require('./config');
6
+ const config = require('./config');
7
7
 
8
- /**
9
- * Make an authenticated request to the Joytree API.
10
- * Auth is done via ?api_key=jtk_... (same pattern as /api/v1/transfer).
11
- * For session-based endpoints we pass token as Bearer header.
12
- */
13
8
  async function request(method, endpoint, body = null, opts = {}) {
14
9
  const apiKey = config.getApiKey();
15
10
  const baseUrl = config.getBaseUrl();
@@ -18,9 +13,7 @@ async function request(method, endpoint, body = null, opts = {}) {
18
13
  throw new Error('Not authenticated. Run: joytree login');
19
14
  }
20
15
 
21
- const separator = endpoint.includes('?') ? '&' : '?';
22
- const url = new URL(`${baseUrl}${endpoint}${apiKey ? `${separator}api_key=${encodeURIComponent(apiKey)}` : ''}`);
23
-
16
+ const url = new URL(`${baseUrl}${endpoint}`);
24
17
  const payload = body ? JSON.stringify(body) : null;
25
18
 
26
19
  return new Promise((resolve, reject) => {
@@ -33,6 +26,8 @@ async function request(method, endpoint, body = null, opts = {}) {
33
26
  headers: {
34
27
  'Content-Type': 'application/json',
35
28
  'User-Agent': `joytree-cli/${require('../package.json').version}`,
29
+ // Send API key as Bearer token — this is what requireAuth on the server reads
30
+ ...(apiKey ? { 'Authorization': `Bearer ${apiKey}` } : {}),
36
31
  ...(payload ? { 'Content-Length': Buffer.byteLength(payload) } : {}),
37
32
  ...(opts.headers || {}),
38
33
  },
@@ -63,7 +58,6 @@ async function request(method, endpoint, body = null, opts = {}) {
63
58
  });
64
59
  }
65
60
 
66
- // Convenience wrappers
67
61
  const api = {
68
62
  get: (path, opts) => request('GET', path, null, opts),
69
63
  post: (path, body, opts) => request('POST', path, body, opts),
@@ -72,19 +66,24 @@ const api = {
72
66
  delete: (path, opts) => request('DELETE', path, null, opts),
73
67
  };
74
68
 
75
- /**
76
- * Validate an API key by calling /api/v1/transfer and reading the response.
77
- * Returns { ok, email, projectCount } or throws.
78
- */
69
+ // Validate API key via /api/v1/transfer
79
70
  async function validateApiKey(apiKey, baseUrl) {
80
- const url = `${baseUrl}/api/v1/transfer?api_key=${encodeURIComponent(apiKey)}`;
81
- const parsed = new URL(url);
82
- const mod = parsed.protocol === 'https:' ? require('https') : require('http');
71
+ const url = new URL(`${baseUrl}/api/v1/transfer`);
72
+ const mod = url.protocol === 'https:' ? require('https') : require('http');
83
73
 
84
74
  return new Promise((resolve, reject) => {
85
- const req = mod.get(url, {
86
- headers: { 'User-Agent': `joytree-cli/${require('../package.json').version}` }
87
- }, (res) => {
75
+ const reqOpts = {
76
+ hostname: url.hostname,
77
+ port: url.port || (url.protocol === 'https:' ? 443 : 80),
78
+ path: url.pathname,
79
+ method: 'GET',
80
+ headers: {
81
+ 'Authorization': `Bearer ${apiKey}`,
82
+ 'User-Agent': `joytree-cli/${require('../package.json').version}`,
83
+ },
84
+ };
85
+
86
+ const req = mod.request(reqOpts, (res) => {
88
87
  let raw = '';
89
88
  res.on('data', c => raw += c);
90
89
  res.on('end', () => {
@@ -98,6 +97,7 @@ async function validateApiKey(apiKey, baseUrl) {
98
97
  });
99
98
  });
100
99
  req.on('error', reject);
100
+ req.end();
101
101
  });
102
102
  }
103
103
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joytreesite/joytree",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Joytree CLI — deploy and manage your sites from the terminal",
5
5
  "main": "bin/joytree.js",
6
6
  "bin": {