statelyai 0.7.3 → 0.7.4

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/dist/bin.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { _ as run } from "./cli-DR7_Qkzm.mjs";
2
+ import { _ as run } from "./cli-CrVHYzeo.mjs";
3
3
 
4
4
  //#region src/bin.ts
5
5
  run();
@@ -1,7 +1,6 @@
1
1
  import * as crypto from "node:crypto";
2
2
  import fs, { promises, watch } from "node:fs";
3
3
  import fsPromises from "node:fs/promises";
4
- import * as http from "node:http";
5
4
  import { execFile, execFileSync, spawn } from "node:child_process";
6
5
  import * as path$1 from "node:path";
7
6
  import path from "node:path";
@@ -10,6 +9,7 @@ import { Writable } from "node:stream";
10
9
  import { fileURLToPath, pathToFileURL } from "node:url";
11
10
  import { promisify } from "node:util";
12
11
  import { Args, Command, Flags, flush, handle, run } from "@oclif/core";
12
+ import * as http from "node:http";
13
13
  import os from "node:os";
14
14
  import { StudioApiError, buildAuthorizeUrl, createPkcePair, createStatelyClient, discoverAuthorizationServer, discoverProtectedResource, exchangeCodeForToken, getStatelyPragma, registerOAuthClient } from "@statelyai/sdk";
15
15
  import { planSync, pullSync, pushLocalMachineLinks } from "@statelyai/sdk/sync";
@@ -698,6 +698,51 @@ function escapeAttribute(value) {
698
698
  return value.replaceAll("&", "&amp;").replaceAll("\"", "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
699
699
  }
700
700
 
701
+ //#endregion
702
+ //#region src/oauthCallbackServer.ts
703
+ async function createLocalOAuthCallbackServer(options) {
704
+ let resolveCode;
705
+ let rejectCode;
706
+ const codePromise = new Promise((resolve, reject) => {
707
+ resolveCode = resolve;
708
+ rejectCode = reject;
709
+ });
710
+ const server = http.createServer((req, res) => {
711
+ const requestUrl = new URL(req.url ?? "/", "http://127.0.0.1");
712
+ const code = requestUrl.searchParams.get("code");
713
+ const state = requestUrl.searchParams.get("state");
714
+ const error = requestUrl.searchParams.get("error");
715
+ res.setHeader("Content-Type", "text/html; charset=utf-8");
716
+ res.setHeader("Connection", "close");
717
+ if (error) {
718
+ res.statusCode = 400;
719
+ res.end("<!doctype html><title>Sign in failed</title><p>Sign in failed. Return to the terminal.</p>");
720
+ rejectCode(new Error(error));
721
+ return;
722
+ }
723
+ if (!code || state !== options.state) {
724
+ res.statusCode = 400;
725
+ res.end("<!doctype html><title>Sign in failed</title><p>Invalid sign-in callback. Return to the terminal.</p>");
726
+ rejectCode(/* @__PURE__ */ new Error("Invalid OAuth callback."));
727
+ return;
728
+ }
729
+ res.end("<!doctype html><title>Signed in</title><p>Signed in. You can close this window.</p>");
730
+ resolveCode(code);
731
+ });
732
+ await new Promise((resolve) => {
733
+ server.listen(0, "127.0.0.1", resolve);
734
+ });
735
+ const address = server.address();
736
+ if (!address || typeof address === "string") throw new Error("Could not start OAuth callback server.");
737
+ return {
738
+ redirectUri: `http://127.0.0.1:${address.port}/callback`,
739
+ waitForCode: () => codePromise,
740
+ close: () => new Promise((resolve) => {
741
+ server.close(() => resolve());
742
+ })
743
+ };
744
+ }
745
+
701
746
  //#endregion
702
747
  //#region src/credentials.ts
703
748
  const execFile$1 = promisify(execFile);
@@ -1511,47 +1556,6 @@ function createOAuthCredential(tokenResponse, now = Date.now()) {
1511
1556
  ...expiresAt ? { expiresAt } : {}
1512
1557
  };
1513
1558
  }
1514
- async function createLocalOAuthCallbackServer(options) {
1515
- let resolveCode;
1516
- let rejectCode;
1517
- const codePromise = new Promise((resolve, reject) => {
1518
- resolveCode = resolve;
1519
- rejectCode = reject;
1520
- });
1521
- const server = http.createServer((req, res) => {
1522
- const requestUrl = new URL(req.url ?? "/", "http://127.0.0.1");
1523
- const code = requestUrl.searchParams.get("code");
1524
- const state = requestUrl.searchParams.get("state");
1525
- const error = requestUrl.searchParams.get("error");
1526
- res.setHeader("Content-Type", "text/html; charset=utf-8");
1527
- if (error) {
1528
- res.statusCode = 400;
1529
- res.end("<!doctype html><title>Sign in failed</title><p>Sign in failed. Return to the terminal.</p>");
1530
- rejectCode(new Error(error));
1531
- return;
1532
- }
1533
- if (!code || state !== options.state) {
1534
- res.statusCode = 400;
1535
- res.end("<!doctype html><title>Sign in failed</title><p>Invalid sign-in callback. Return to the terminal.</p>");
1536
- rejectCode(/* @__PURE__ */ new Error("Invalid OAuth callback."));
1537
- return;
1538
- }
1539
- res.end("<!doctype html><title>Signed in</title><p>Signed in. You can close this window.</p>");
1540
- resolveCode(code);
1541
- });
1542
- await new Promise((resolve) => {
1543
- server.listen(0, "127.0.0.1", resolve);
1544
- });
1545
- const address = server.address();
1546
- if (!address || typeof address === "string") throw new Error("Could not start OAuth callback server.");
1547
- return {
1548
- redirectUri: `http://127.0.0.1:${address.port}/callback`,
1549
- waitForCode: () => codePromise,
1550
- close: () => new Promise((resolve) => {
1551
- server.close(() => resolve());
1552
- })
1553
- };
1554
- }
1555
1559
  async function buildOAuthLoginStart(options) {
1556
1560
  const [discovery, pkce] = await Promise.all([discoverOAuthLogin({
1557
1561
  baseUrl: options.baseUrl,
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { _ as run, a as discoverOAuthLogin, c as formatPlanSummary, d as getEnvCredential, f as inferInitProjectName, g as resolveConfiguredPullTargets, h as resolveApiKey, i as discoverLinkedPullTargets, l as formatStoredCredentialSource, m as isFileGitDirty, n as buildOAuthLoginStart, o as discoverRemoteProjectMachineTargets, p as initProject, r as classifyPushCandidates, s as formatMissingNewMachineDirMessage, t as COMMANDS, u as getEnvApiKey, v as scanProjectSources, y as createStatelyProjectConfig } from "./cli-DR7_Qkzm.mjs";
1
+ import { _ as run, a as discoverOAuthLogin, c as formatPlanSummary, d as getEnvCredential, f as inferInitProjectName, g as resolveConfiguredPullTargets, h as resolveApiKey, i as discoverLinkedPullTargets, l as formatStoredCredentialSource, m as isFileGitDirty, n as buildOAuthLoginStart, o as discoverRemoteProjectMachineTargets, p as initProject, r as classifyPushCandidates, s as formatMissingNewMachineDirMessage, t as COMMANDS, u as getEnvApiKey, v as scanProjectSources, y as createStatelyProjectConfig } from "./cli-CrVHYzeo.mjs";
2
2
 
3
3
  export { COMMANDS, buildOAuthLoginStart, classifyPushCandidates, createStatelyProjectConfig, discoverLinkedPullTargets, discoverOAuthLogin, discoverRemoteProjectMachineTargets, formatMissingNewMachineDirMessage, formatPlanSummary, formatStoredCredentialSource, getEnvApiKey, getEnvCredential, inferInitProjectName, initProject, isFileGitDirty, resolveApiKey, resolveConfiguredPullTargets, run, scanProjectSources };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "statelyai",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
4
4
  "description": "Command-line tools for Stately",
5
5
  "license": "MIT",
6
6
  "type": "module",