@gradual-so/cli 0.1.0 → 0.1.1

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 (2) hide show
  1. package/dist/index.js +28 -10
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -22189,11 +22189,11 @@ function sleep(ms) {
22189
22189
  return new Promise((resolve3) => setTimeout(resolve3, ms));
22190
22190
  }
22191
22191
  async function deviceLogin(dashboardUrl) {
22192
- const codeResponse = await fetch(`${dashboardUrl}/api/auth/device/authorize`, {
22192
+ const codeResponse = await fetch(`${dashboardUrl}/api/auth/device/code`, {
22193
22193
  method: "POST",
22194
22194
  headers: { "Content-Type": "application/json" },
22195
22195
  body: JSON.stringify({
22196
- clientId: "gradual-cli"
22196
+ client_id: "gradual-cli"
22197
22197
  })
22198
22198
  });
22199
22199
  if (!codeResponse.ok) {
@@ -22202,25 +22202,40 @@ async function deviceLogin(dashboardUrl) {
22202
22202
  }
22203
22203
  const codeData = await codeResponse.json();
22204
22204
  console.log();
22205
- console.log(` Your authorization code: ${source_default.bold.cyan(codeData.userCode)}`);
22205
+ console.log(` Your authorization code: ${source_default.bold.cyan(codeData.user_code)}`);
22206
22206
  console.log();
22207
22207
  console.log(` ${source_default.dim("Opening browser to verify...")}`);
22208
22208
  console.log();
22209
- await open_default(codeData.verificationUriComplete);
22209
+ await open_default(codeData.verification_uri_complete || codeData.verification_uri);
22210
22210
  let pollInterval = codeData.interval * 1000;
22211
- const deadline = Date.now() + codeData.expiresIn * 1000;
22211
+ const deadline = Date.now() + codeData.expires_in * 1000;
22212
22212
  while (Date.now() < deadline) {
22213
22213
  await sleep(pollInterval);
22214
- const tokenResponse = await fetch(`${dashboardUrl}/api/auth/device/verify`, {
22214
+ const tokenResponse = await fetch(`${dashboardUrl}/api/auth/device/token`, {
22215
22215
  method: "POST",
22216
22216
  headers: { "Content-Type": "application/json" },
22217
22217
  body: JSON.stringify({
22218
- deviceCode: codeData.deviceCode,
22219
- clientId: "gradual-cli"
22218
+ grant_type: "urn:ietf:params:oauth:grant-type:device_code",
22219
+ device_code: codeData.device_code,
22220
+ client_id: "gradual-cli"
22220
22221
  })
22221
22222
  });
22222
22223
  if (tokenResponse.ok) {
22223
- return await tokenResponse.json();
22224
+ const tokenData = await tokenResponse.json();
22225
+ const sessionResponse = await fetch(`${dashboardUrl}/api/auth/get-session`, {
22226
+ headers: {
22227
+ Authorization: `Bearer ${tokenData.access_token}`
22228
+ }
22229
+ });
22230
+ if (!sessionResponse.ok) {
22231
+ throw new Error("Failed to fetch session after authorization");
22232
+ }
22233
+ const session = await sessionResponse.json();
22234
+ return {
22235
+ token: tokenData.access_token,
22236
+ expiresAt: session.session.expiresAt,
22237
+ user: session.user
22238
+ };
22224
22239
  }
22225
22240
  const error2 = await tokenResponse.json();
22226
22241
  if (error2.error === "authorization_pending") {
@@ -22230,10 +22245,13 @@ async function deviceLogin(dashboardUrl) {
22230
22245
  pollInterval += 5000;
22231
22246
  continue;
22232
22247
  }
22248
+ if (error2.error === "access_denied") {
22249
+ throw new Error("Authorization was denied.");
22250
+ }
22233
22251
  if (error2.error === "expired_token") {
22234
22252
  throw new Error("Device code expired. Please try again.");
22235
22253
  }
22236
- throw new Error(error2.errorDescription ?? error2.error ?? "Device authorization failed");
22254
+ throw new Error(error2.error_description ?? error2.error ?? "Device authorization failed");
22237
22255
  }
22238
22256
  throw new Error("Device code expired. Please try again.");
22239
22257
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradual-so/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Gradual CLI for feature flag management",
5
5
  "type": "module",
6
6
  "bin": {