@hasna/connectors 1.3.20 → 1.3.21

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/bin/index.js +56 -3
  2. package/package.json +1 -1
package/bin/index.js CHANGED
@@ -33030,7 +33030,7 @@ function redactSecrets(obj) {
33030
33030
  return obj;
33031
33031
  }
33032
33032
  function registerCommands4(program2) {
33033
- program2.command("auth").argument("<connector>", "Connector name to configure auth for").option("-k, --key <value>", "API key or bearer token value (non-interactive)").option("-f, --field <field>", "Which field to set (for multi-field connectors)").option("--json", "Output as JSON", false).description("Configure authentication for a connector").action(async (connector, options) => {
33033
+ program2.command("auth").argument("<connector>", "Connector name to configure auth for").option("-k, --key <value>", "API key or bearer token value (non-interactive)").option("-f, --field <field>", "Which field to set (for multi-field connectors)").option("--json", "Output as JSON", false).option("--no-browser", "Print OAuth URL without opening a browser (agent-friendly)", false).description("Configure authentication for a connector").action(async (connector, options) => {
33034
33034
  const meta = getConnector(connector);
33035
33035
  if (!meta) {
33036
33036
  if (options.json) {
@@ -33069,12 +33069,65 @@ ${meta.displayName} \u2014 Auth Configuration
33069
33069
  }
33070
33070
  console.log(chalk5.yellow("OAuth connectors require browser-based authentication."));
33071
33071
  console.log();
33072
+ const port = 9876;
33073
+ const oauthUrl = `http://localhost:${port}/oauth/${connector}/start`;
33072
33074
  try {
33073
- const port = 9876;
33075
+ if (!options.browser) {
33076
+ console.log(chalk5.dim(`Starting OAuth server on port ${port}...`));
33077
+ const { spawn: spawn4 } = await import("child_process");
33078
+ const scriptPath = process.argv[1];
33079
+ const serverProc = spawn4("node", [scriptPath, "serve", "--port", String(port)], {
33080
+ detached: true,
33081
+ stdio: "ignore"
33082
+ });
33083
+ serverProc.unref();
33084
+ await new Promise((resolve) => setTimeout(resolve, 2000));
33085
+ try {
33086
+ await fetch(`http://localhost:${port}/api/connectors`);
33087
+ } catch {
33088
+ console.log(chalk5.red(`OAuth server failed to start on port ${port}. Is the port already in use?`));
33089
+ console.log(chalk5.dim("Free the port and try again, or use 'connectors serve' for the full dashboard."));
33090
+ process.exit(1);
33091
+ return;
33092
+ }
33093
+ console.log(chalk5.bold(`Open this URL to authenticate:
33094
+ `));
33095
+ console.log(` ${chalk5.cyan(oauthUrl)}
33096
+ `);
33097
+ console.log(chalk5.dim(`Waiting for authentication to complete...
33098
+ `));
33099
+ const { join: join8 } = await import("path");
33100
+ const { getConnectorsHome: getConnectorsHome2 } = await Promise.resolve().then(() => (init_database(), exports_database));
33101
+ const connectorsHome = getConnectorsHome2();
33102
+ const connectorDirName = connector.startsWith("connect-") ? connector : `connect-${connector}`;
33103
+ const tokensPath = join8(connectorsHome, connectorDirName, "profiles", "default", "tokens.json");
33104
+ let attempts = 0;
33105
+ const maxAttempts = 360;
33106
+ while (attempts < maxAttempts) {
33107
+ await new Promise((resolve) => setTimeout(resolve, 500));
33108
+ if (existsSync19(tokensPath)) {
33109
+ break;
33110
+ }
33111
+ attempts++;
33112
+ }
33113
+ try {
33114
+ serverProc.kill("SIGTERM");
33115
+ } catch {}
33116
+ if (attempts >= maxAttempts) {
33117
+ console.log(chalk5.yellow("Timed out waiting for OAuth callback. The auth may still be in progress."));
33118
+ console.log(chalk5.dim(`Check ${tokensPath} for tokens.`));
33119
+ console.log(chalk5.dim("You can stop the server manually: lsof -ti :${port} | xargs kill"));
33120
+ process.exit(1);
33121
+ return;
33122
+ }
33123
+ console.log(chalk5.green(`
33124
+ \u2713 Connected! ${meta.displayName} is now authenticated.`));
33125
+ process.exit(0);
33126
+ return;
33127
+ }
33074
33128
  const { startServer: startServer2 } = await Promise.resolve().then(() => (init_serve(), exports_serve));
33075
33129
  console.log(chalk5.dim(`Starting temporary server on port ${port}...`));
33076
33130
  await startServer2(port, { open: false, strict: true });
33077
- const oauthUrl = `http://localhost:${port}/oauth/${connector}/start`;
33078
33131
  console.log(chalk5.bold(`
33079
33132
  Open this URL to authenticate:
33080
33133
  `));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasna/connectors",
3
- "version": "1.3.20",
3
+ "version": "1.3.21",
4
4
  "description": "Open source connector library - Install API connectors with a single command",
5
5
  "type": "module",
6
6
  "bin": {