@playdrop/playdrop-cli 0.10.12 → 0.10.14
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.
package/config/client-meta.json
CHANGED
package/dist/commands/login.d.ts
CHANGED
package/dist/commands/login.js
CHANGED
|
@@ -10,6 +10,7 @@ const environment_1 = require("../environment");
|
|
|
10
10
|
const browser_1 = require("../browser");
|
|
11
11
|
Object.defineProperty(exports, "resetOpenBrowserForTests", { enumerable: true, get: function () { return browser_1.resetOpenBrowserForTests; } });
|
|
12
12
|
Object.defineProperty(exports, "setOpenBrowserForTests", { enumerable: true, get: function () { return browser_1.setOpenBrowserForTests; } });
|
|
13
|
+
const output_1 = require("../output");
|
|
13
14
|
const messages_1 = require("../messages");
|
|
14
15
|
function sleep(ms) {
|
|
15
16
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -21,7 +22,7 @@ function extractAccessToken(data) {
|
|
|
21
22
|
function isLoginResponse(data) {
|
|
22
23
|
return typeof data === 'object' && data !== null && 'user' in data;
|
|
23
24
|
}
|
|
24
|
-
function storeLogin(env, data) {
|
|
25
|
+
function storeLogin(env, data, options = {}) {
|
|
25
26
|
const token = extractAccessToken(data);
|
|
26
27
|
if (!token) {
|
|
27
28
|
(0, messages_1.printErrorWithHelp)('Login succeeded but no access token was returned.', [
|
|
@@ -41,14 +42,22 @@ function storeLogin(env, data) {
|
|
|
41
42
|
return;
|
|
42
43
|
}
|
|
43
44
|
(0, config_1.saveAccountSession)({ username, env, token });
|
|
45
|
+
if (options.json) {
|
|
46
|
+
(0, output_1.printJson)({
|
|
47
|
+
status: 'authenticated',
|
|
48
|
+
username,
|
|
49
|
+
env,
|
|
50
|
+
});
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
44
53
|
console.log(`Logged in as ${username} on ${env}.`);
|
|
45
54
|
console.log('Next: run "playdrop auth whoami" to confirm your session.');
|
|
46
55
|
}
|
|
47
|
-
async function loginWithUsernamePassword(env, baseUrl, username, password) {
|
|
56
|
+
async function loginWithUsernamePassword(env, baseUrl, username, password, options = {}) {
|
|
48
57
|
const client = (0, apiClient_1.createCliApiClient)({ baseUrl });
|
|
49
58
|
try {
|
|
50
59
|
const data = await client.login({ username, password });
|
|
51
|
-
storeLogin(env, data);
|
|
60
|
+
storeLogin(env, data, options);
|
|
52
61
|
}
|
|
53
62
|
catch (unknownError) {
|
|
54
63
|
if (unknownError instanceof types_1.UnsupportedClientError) {
|
|
@@ -66,11 +75,11 @@ async function loginWithUsernamePassword(env, baseUrl, username, password) {
|
|
|
66
75
|
throw unknownError;
|
|
67
76
|
}
|
|
68
77
|
}
|
|
69
|
-
async function loginWithKey(env, baseUrl, apiKey) {
|
|
78
|
+
async function loginWithKey(env, baseUrl, apiKey, options = {}) {
|
|
70
79
|
const client = (0, apiClient_1.createCliApiClient)({ baseUrl });
|
|
71
80
|
try {
|
|
72
81
|
const data = await client.loginWithApiKey({ apiKey });
|
|
73
|
-
storeLogin(env, data);
|
|
82
|
+
storeLogin(env, data, options);
|
|
74
83
|
}
|
|
75
84
|
catch (unknownError) {
|
|
76
85
|
if (unknownError instanceof types_1.UnsupportedClientError) {
|
|
@@ -88,7 +97,29 @@ async function loginWithKey(env, baseUrl, apiKey) {
|
|
|
88
97
|
throw unknownError;
|
|
89
98
|
}
|
|
90
99
|
}
|
|
91
|
-
async function
|
|
100
|
+
async function loginWithHandoff(env, baseUrl, handoffToken, options = {}) {
|
|
101
|
+
const client = (0, apiClient_1.createCliApiClient)({ baseUrl });
|
|
102
|
+
try {
|
|
103
|
+
const data = await client.exchangeAppleOAuthHandoff({ token: handoffToken });
|
|
104
|
+
storeLogin(env, data, options);
|
|
105
|
+
}
|
|
106
|
+
catch (unknownError) {
|
|
107
|
+
if (unknownError instanceof types_1.UnsupportedClientError) {
|
|
108
|
+
(0, http_1.handleUnsupportedError)(unknownError, 'Login');
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (unknownError instanceof types_1.ApiError) {
|
|
112
|
+
(0, messages_1.printErrorWithHelp)(`Login handoff failed with status ${unknownError.status}.`, [
|
|
113
|
+
'Request a fresh handoff token from the PlayDrop app and retry.',
|
|
114
|
+
'Use "playdrop auth whoami" after logging in to confirm your status.',
|
|
115
|
+
], { command: 'login' });
|
|
116
|
+
process.exitCode = 1;
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
throw unknownError;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
async function loginInBrowser(env, baseUrl, options = {}) {
|
|
92
123
|
const client = (0, apiClient_1.createCliApiClient)({ baseUrl });
|
|
93
124
|
let flow;
|
|
94
125
|
try {
|
|
@@ -132,7 +163,7 @@ async function loginInBrowser(env, baseUrl) {
|
|
|
132
163
|
await sleep(intervalMs);
|
|
133
164
|
continue;
|
|
134
165
|
}
|
|
135
|
-
storeLogin(env, result);
|
|
166
|
+
storeLogin(env, result, options);
|
|
136
167
|
return;
|
|
137
168
|
}
|
|
138
169
|
catch (unknownError) {
|
|
@@ -176,11 +207,19 @@ async function login(env, options = {}) {
|
|
|
176
207
|
const username = options.username?.trim();
|
|
177
208
|
const password = options.password;
|
|
178
209
|
const apiKey = options.key?.trim();
|
|
179
|
-
|
|
210
|
+
const handoffToken = options.handoffToken?.trim();
|
|
211
|
+
const hasDirectCredentials = Boolean(username || password);
|
|
212
|
+
const explicitLoginMethods = [
|
|
213
|
+
apiKey ? 'key' : null,
|
|
214
|
+
hasDirectCredentials ? 'credentials' : null,
|
|
215
|
+
handoffToken ? 'handoff' : null,
|
|
216
|
+
].filter(Boolean);
|
|
217
|
+
if (explicitLoginMethods.length > 1) {
|
|
180
218
|
(0, messages_1.printErrorWithHelp)('Choose exactly one login method.', [
|
|
181
219
|
'Use "playdrop auth login" for browser login.',
|
|
182
220
|
'Use "--username" with "--password" for direct login.',
|
|
183
221
|
'Use "--key" by itself for API key login.',
|
|
222
|
+
'Use "--handoff-token" by itself for native app handoff login.',
|
|
184
223
|
], { command: 'login' });
|
|
185
224
|
process.exitCode = 1;
|
|
186
225
|
return;
|
|
@@ -195,14 +234,18 @@ async function login(env, options = {}) {
|
|
|
195
234
|
}
|
|
196
235
|
try {
|
|
197
236
|
if (apiKey) {
|
|
198
|
-
await loginWithKey(env, envConfig.apiBase, apiKey);
|
|
237
|
+
await loginWithKey(env, envConfig.apiBase, apiKey, { json: options.json });
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
if (handoffToken) {
|
|
241
|
+
await loginWithHandoff(env, envConfig.apiBase, handoffToken, { json: options.json });
|
|
199
242
|
return;
|
|
200
243
|
}
|
|
201
244
|
if (username && password) {
|
|
202
|
-
await loginWithUsernamePassword(env, envConfig.apiBase, username, password);
|
|
245
|
+
await loginWithUsernamePassword(env, envConfig.apiBase, username, password, { json: options.json });
|
|
203
246
|
return;
|
|
204
247
|
}
|
|
205
|
-
await loginInBrowser(env, envConfig.apiBase);
|
|
248
|
+
await loginInBrowser(env, envConfig.apiBase, { json: options.json });
|
|
206
249
|
}
|
|
207
250
|
catch (error) {
|
|
208
251
|
if (error instanceof http_1.CLIUnsupportedClientError) {
|
package/dist/index.js
CHANGED
|
@@ -120,11 +120,15 @@ function registerLoginCommand(parent) {
|
|
|
120
120
|
.option('--username <username>', 'Username for direct login')
|
|
121
121
|
.option('--password <password>', 'Password for direct login')
|
|
122
122
|
.option('--key <apiKey>', 'API key for direct login')
|
|
123
|
+
.option('--handoff-token <token>', 'Native app handoff token for direct login')
|
|
124
|
+
.option('--json', 'Output JSON')
|
|
123
125
|
.action(async (opts) => {
|
|
124
126
|
await (0, login_1.login)(opts.env, {
|
|
125
127
|
username: opts.username,
|
|
126
128
|
password: opts.password,
|
|
127
129
|
key: opts.key,
|
|
130
|
+
handoffToken: opts.handoffToken,
|
|
131
|
+
json: opts.json,
|
|
128
132
|
});
|
|
129
133
|
});
|
|
130
134
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@playdrop/playdrop-cli",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.14",
|
|
4
4
|
"description": "Official Playdrop CLI for publishing browser games, creator apps, and AI-generated game assets on playdrop.ai",
|
|
5
5
|
"homepage": "https://www.playdrop.ai",
|
|
6
6
|
"repository": {
|