@hasna/connectors 1.3.27 → 1.3.29

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/bin/index.js CHANGED
@@ -1909,7 +1909,7 @@ var package_default;
1909
1909
  var init_package = __esm(() => {
1910
1910
  package_default = {
1911
1911
  name: "@hasna/connectors",
1912
- version: "1.3.27",
1912
+ version: "1.3.29",
1913
1913
  description: "Open source connector library - Install API connectors with a single command",
1914
1914
  type: "module",
1915
1915
  bin: {
@@ -7463,6 +7463,35 @@ function listProfiles2() {
7463
7463
  }
7464
7464
  return Array.from(profiles).sort((a, b) => a.localeCompare(b));
7465
7465
  }
7466
+ function listProfileStatuses(profile) {
7467
+ const profiles = profile ? [profile] : listProfiles2();
7468
+ const uniqueProfiles = profiles.length ? profiles : ["default"];
7469
+ const now = Date.now();
7470
+ return uniqueProfiles.map((name) => {
7471
+ const tokens = loadTokens2(name);
7472
+ const credentials = loadCredentials2(name);
7473
+ const hasAccessToken = Boolean(tokens?.accessToken || process.env.GOOGLE_ACCESS_TOKEN);
7474
+ const hasRefreshToken = Boolean(tokens?.refreshToken);
7475
+ const hasOAuthCredentials = Boolean(credentials.clientId && credentials.clientSecret);
7476
+ const expiresAt = tokens?.expiresAt ?? null;
7477
+ const expired = Boolean(expiresAt && now >= expiresAt - REFRESH_BUFFER_MS2);
7478
+ const authenticated = Boolean(process.env.GOOGLE_ACCESS_TOKEN || hasRefreshToken || hasAccessToken && !expired);
7479
+ const configured = authenticated || hasOAuthCredentials;
7480
+ const authRequired = !authenticated || expired && !hasRefreshToken;
7481
+ return {
7482
+ profile: name,
7483
+ configured,
7484
+ authenticated,
7485
+ expired,
7486
+ expiresAt,
7487
+ hasAccessToken,
7488
+ hasRefreshToken,
7489
+ hasOAuthCredentials,
7490
+ authRequired,
7491
+ message: authRequired ? `Google Drive profile "${name}" needs authentication. Run: connectors auth googledrive` : expired ? `Google Drive profile "${name}" access token is expired but can refresh.` : `Google Drive profile "${name}" is authenticated.`
7492
+ };
7493
+ });
7494
+ }
7466
7495
  function loadCredentials2(profile) {
7467
7496
  const envClientId = process.env.GOOGLE_CLIENT_ID;
7468
7497
  const envClientSecret = process.env.GOOGLE_CLIENT_SECRET;
@@ -7535,7 +7564,7 @@ function extractGoogleError(body) {
7535
7564
  return body;
7536
7565
  }
7537
7566
  }
7538
- var DRIVE_API_BASE = "https://www.googleapis.com/drive/v3", TOKEN_URL2 = "https://oauth2.googleapis.com/token", REFRESH_BUFFER_MS2, DEFAULT_FILE_FIELDS, DEFAULT_EXPORT_FORMATS, EXPORT_EXTENSIONS, listFilesSchema, listDrivesSchema, fileIdSchema, downloadSchema, googleDriveConnector;
7567
+ var DRIVE_API_BASE = "https://www.googleapis.com/drive/v3", TOKEN_URL2 = "https://oauth2.googleapis.com/token", REFRESH_BUFFER_MS2, DEFAULT_FILE_FIELDS, DEFAULT_EXPORT_FORMATS, EXPORT_EXTENSIONS, listFilesSchema, listDrivesSchema, fileIdSchema, downloadSchema, profilesStatusSchema, googleDriveConnector;
7539
7568
  var init_googledrive = __esm(() => {
7540
7569
  init_zod();
7541
7570
  init_connector();
@@ -7600,6 +7629,9 @@ var init_googledrive = __esm(() => {
7600
7629
  }).optional(),
7601
7630
  exportMimeType: exports_external.string().optional()
7602
7631
  });
7632
+ profilesStatusSchema = exports_external.object({
7633
+ profile: exports_external.string().optional()
7634
+ });
7603
7635
  googleDriveConnector = defineConnector({
7604
7636
  meta: {
7605
7637
  name: "googledrive",
@@ -7622,6 +7654,11 @@ var init_googledrive = __esm(() => {
7622
7654
  summary: "List configured Google Drive profiles.",
7623
7655
  execute: () => ({ profiles: listProfiles2() })
7624
7656
  },
7657
+ "profiles.status": {
7658
+ summary: "List Google Drive profile authentication status.",
7659
+ inputSchema: profilesStatusSchema,
7660
+ execute: (_ctx, input) => ({ profiles: listProfileStatuses(input.profile) })
7661
+ },
7625
7662
  "files.list": {
7626
7663
  summary: "List Google Drive files.",
7627
7664
  inputSchema: listFilesSchema,
@@ -34245,6 +34282,27 @@ function getOAuthTokenState(name) {
34245
34282
  })();
34246
34283
  return { hasTokens: true, expired: isExpired, expiresIn };
34247
34284
  }
34285
+ function getCurrentOAuthProfile(name, connectorsHome = getConnectorsHome()) {
34286
+ for (const dir of getConnectorConfigReadDirs(name, connectorsHome)) {
34287
+ const currentProfilePath = join20(dir, "current_profile");
34288
+ if (!existsSync20(currentProfilePath))
34289
+ continue;
34290
+ const profile = readFileSync11(currentProfilePath, "utf8").trim();
34291
+ if (profile)
34292
+ return profile;
34293
+ }
34294
+ return "default";
34295
+ }
34296
+ function getOAuthTokenPathsForProfile(name, connectorsHome = getConnectorsHome(), profile = getCurrentOAuthProfile(name, connectorsHome)) {
34297
+ return getConnectorConfigReadDirs(name, connectorsHome).map((dir) => join20(dir, "profiles", profile, "tokens.json"));
34298
+ }
34299
+ function hasOAuthTokenFileUpdatedSince(tokenPaths, sinceMs) {
34300
+ return tokenPaths.some((tokensPath) => {
34301
+ if (!existsSync20(tokensPath))
34302
+ return false;
34303
+ return statSync8(tokensPath).mtimeMs >= sinceMs;
34304
+ });
34305
+ }
34248
34306
  function registerCommands4(program2) {
34249
34307
  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).option("--refresh", "Refresh expired OAuth tokens", false).option("--port <port>", "OAuth server port (default: 9876)", "9876").description("Configure authentication for a connector").action(async (connector, options) => {
34250
34308
  const meta = getConnector(connector);
@@ -34370,10 +34428,11 @@ ${meta.displayName} \u2014 Auth Configuration
34370
34428
  console.log(chalk5.dim(`Starting OAuth server on port ${port}...`));
34371
34429
  const { spawn: spawn3 } = await import("child_process");
34372
34430
  const scriptPath = process.argv[1];
34373
- const serverProc = spawn3("node", [scriptPath, "serve", "--port", String(port)], {
34431
+ const serverProc = spawn3(process.execPath, [scriptPath, "serve", "--port", String(port)], {
34374
34432
  detached: true,
34375
34433
  stdio: "ignore"
34376
34434
  });
34435
+ const startedAt = Date.now();
34377
34436
  serverProc.unref();
34378
34437
  await new Promise((resolve) => setTimeout(resolve, 2000));
34379
34438
  try {
@@ -34390,12 +34449,13 @@ ${meta.displayName} \u2014 Auth Configuration
34390
34449
  `);
34391
34450
  console.log(chalk5.dim("Waiting for authentication to complete..."));
34392
34451
  const connectorsHome = getConnectorsHome();
34393
- const tokenPaths = getConnectorConfigReadDirs(connector, connectorsHome).map((dir) => join20(dir, "profiles", "default", "tokens.json"));
34452
+ const activeProfile = getCurrentOAuthProfile(connector, connectorsHome);
34453
+ const tokenPaths = getOAuthTokenPathsForProfile(connector, connectorsHome, activeProfile);
34394
34454
  let attempts = 0;
34395
34455
  const maxAttempts = 360;
34396
34456
  while (attempts < maxAttempts) {
34397
34457
  await new Promise((resolve) => setTimeout(resolve, 500));
34398
- if (tokenPaths.some((tokensPath) => existsSync20(tokensPath))) {
34458
+ if (hasOAuthTokenFileUpdatedSince(tokenPaths, startedAt)) {
34399
34459
  break;
34400
34460
  }
34401
34461
  attempts++;
@@ -35549,7 +35609,6 @@ Testing connector credentials...
35549
35609
  init_registry2();
35550
35610
  init_auth();
35551
35611
  init_runner();
35552
- init_connector_resolver();
35553
35612
  import chalk7 from "chalk";
35554
35613
  function registerCommands6(program2) {
35555
35614
  program2.command("ops").description("List available API operations for a connector").argument("<name>", "Connector name (e.g. stripe, gmail)").argument("[command]", "Get detailed help for a specific subcommand").option("--json", "Output as JSON").action(async (name, command, options) => {
@@ -35713,13 +35772,12 @@ Setting up ${meta.displayName}...
35713
35772
  `);
35714
35773
  const { spawn: spawn3 } = await import("child_process");
35715
35774
  const { getConnectorsHome: getConnectorsHome2 } = await Promise.resolve().then(() => (init_database(), exports_database));
35716
- const { existsSync: existsSync8 } = await import("fs");
35717
- const { join: join8 } = await import("path");
35718
35775
  const scriptPath = process.argv[1];
35719
- const serverProc = spawn3("node", [scriptPath, "serve", "--port", String(port)], {
35776
+ const serverProc = spawn3(process.execPath, [scriptPath, "serve", "--port", String(port)], {
35720
35777
  detached: true,
35721
35778
  stdio: "ignore"
35722
35779
  });
35780
+ const startedAt = Date.now();
35723
35781
  serverProc.unref();
35724
35782
  await new Promise((resolve) => setTimeout(resolve, 2000));
35725
35783
  try {
@@ -35731,12 +35789,13 @@ Setting up ${meta.displayName}...
35731
35789
  }
35732
35790
  console.log(chalk7.dim(" Waiting for authentication to complete..."));
35733
35791
  const connectorsHome = getConnectorsHome2();
35734
- const tokenPaths = getConnectorConfigReadDirs(name, connectorsHome).map((dir) => join8(dir, "profiles", "default", "tokens.json"));
35792
+ const activeProfile = getCurrentOAuthProfile(name, connectorsHome);
35793
+ const tokenPaths = getOAuthTokenPathsForProfile(name, connectorsHome, activeProfile);
35735
35794
  let attempts = 0;
35736
35795
  const maxAttempts = 360;
35737
35796
  while (attempts < maxAttempts) {
35738
35797
  await new Promise((resolve) => setTimeout(resolve, 500));
35739
- if (tokenPaths.some((tokensPath) => existsSync8(tokensPath)))
35798
+ if (hasOAuthTokenFileUpdatedSince(tokenPaths, startedAt))
35740
35799
  break;
35741
35800
  attempts++;
35742
35801
  if (attempts % 6 === 0)
package/bin/mcp.js CHANGED
@@ -11988,6 +11988,35 @@ function listProfiles2() {
11988
11988
  }
11989
11989
  return Array.from(profiles).sort((a, b) => a.localeCompare(b));
11990
11990
  }
11991
+ function listProfileStatuses(profile) {
11992
+ const profiles = profile ? [profile] : listProfiles2();
11993
+ const uniqueProfiles = profiles.length ? profiles : ["default"];
11994
+ const now = Date.now();
11995
+ return uniqueProfiles.map((name) => {
11996
+ const tokens = loadTokens2(name);
11997
+ const credentials = loadCredentials2(name);
11998
+ const hasAccessToken = Boolean(tokens?.accessToken || process.env.GOOGLE_ACCESS_TOKEN);
11999
+ const hasRefreshToken = Boolean(tokens?.refreshToken);
12000
+ const hasOAuthCredentials = Boolean(credentials.clientId && credentials.clientSecret);
12001
+ const expiresAt = tokens?.expiresAt ?? null;
12002
+ const expired = Boolean(expiresAt && now >= expiresAt - REFRESH_BUFFER_MS2);
12003
+ const authenticated = Boolean(process.env.GOOGLE_ACCESS_TOKEN || hasRefreshToken || hasAccessToken && !expired);
12004
+ const configured = authenticated || hasOAuthCredentials;
12005
+ const authRequired = !authenticated || expired && !hasRefreshToken;
12006
+ return {
12007
+ profile: name,
12008
+ configured,
12009
+ authenticated,
12010
+ expired,
12011
+ expiresAt,
12012
+ hasAccessToken,
12013
+ hasRefreshToken,
12014
+ hasOAuthCredentials,
12015
+ authRequired,
12016
+ message: authRequired ? `Google Drive profile "${name}" needs authentication. Run: connectors auth googledrive` : expired ? `Google Drive profile "${name}" access token is expired but can refresh.` : `Google Drive profile "${name}" is authenticated.`
12017
+ };
12018
+ });
12019
+ }
11991
12020
  function loadCredentials2(profile) {
11992
12021
  const envClientId = process.env.GOOGLE_CLIENT_ID;
11993
12022
  const envClientSecret = process.env.GOOGLE_CLIENT_SECRET;
@@ -12060,7 +12089,7 @@ function extractGoogleError(body) {
12060
12089
  return body;
12061
12090
  }
12062
12091
  }
12063
- var DRIVE_API_BASE = "https://www.googleapis.com/drive/v3", TOKEN_URL2 = "https://oauth2.googleapis.com/token", REFRESH_BUFFER_MS2, DEFAULT_FILE_FIELDS, DEFAULT_EXPORT_FORMATS, EXPORT_EXTENSIONS, listFilesSchema, listDrivesSchema, fileIdSchema, downloadSchema, googleDriveConnector;
12092
+ var DRIVE_API_BASE = "https://www.googleapis.com/drive/v3", TOKEN_URL2 = "https://oauth2.googleapis.com/token", REFRESH_BUFFER_MS2, DEFAULT_FILE_FIELDS, DEFAULT_EXPORT_FORMATS, EXPORT_EXTENSIONS, listFilesSchema, listDrivesSchema, fileIdSchema, downloadSchema, profilesStatusSchema, googleDriveConnector;
12064
12093
  var init_googledrive = __esm(() => {
12065
12094
  init_zod();
12066
12095
  init_connector();
@@ -12125,6 +12154,9 @@ var init_googledrive = __esm(() => {
12125
12154
  }).optional(),
12126
12155
  exportMimeType: exports_external.string().optional()
12127
12156
  });
12157
+ profilesStatusSchema = exports_external.object({
12158
+ profile: exports_external.string().optional()
12159
+ });
12128
12160
  googleDriveConnector = defineConnector({
12129
12161
  meta: {
12130
12162
  name: "googledrive",
@@ -12147,6 +12179,11 @@ var init_googledrive = __esm(() => {
12147
12179
  summary: "List configured Google Drive profiles.",
12148
12180
  execute: () => ({ profiles: listProfiles2() })
12149
12181
  },
12182
+ "profiles.status": {
12183
+ summary: "List Google Drive profile authentication status.",
12184
+ inputSchema: profilesStatusSchema,
12185
+ execute: (_ctx, input) => ({ profiles: listProfileStatuses(input.profile) })
12186
+ },
12150
12187
  "files.list": {
12151
12188
  summary: "List Google Drive files.",
12152
12189
  inputSchema: listFilesSchema,
@@ -12203,7 +12240,7 @@ var package_default;
12203
12240
  var init_package = __esm(() => {
12204
12241
  package_default = {
12205
12242
  name: "@hasna/connectors",
12206
- version: "1.3.27",
12243
+ version: "1.3.29",
12207
12244
  description: "Open source connector library - Install API connectors with a single command",
12208
12245
  type: "module",
12209
12246
  bin: {
package/bin/serve.js CHANGED
@@ -15691,6 +15691,9 @@ var downloadSchema = exports_external2.object({
15691
15691
  }).optional(),
15692
15692
  exportMimeType: exports_external2.string().optional()
15693
15693
  });
15694
+ var profilesStatusSchema = exports_external2.object({
15695
+ profile: exports_external2.string().optional()
15696
+ });
15694
15697
  var googleDriveConnector = defineConnector({
15695
15698
  meta: {
15696
15699
  name: "googledrive",
@@ -15713,6 +15716,11 @@ var googleDriveConnector = defineConnector({
15713
15716
  summary: "List configured Google Drive profiles.",
15714
15717
  execute: () => ({ profiles: listProfiles2() })
15715
15718
  },
15719
+ "profiles.status": {
15720
+ summary: "List Google Drive profile authentication status.",
15721
+ inputSchema: profilesStatusSchema,
15722
+ execute: (_ctx, input) => ({ profiles: listProfileStatuses(input.profile) })
15723
+ },
15716
15724
  "files.list": {
15717
15725
  summary: "List Google Drive files.",
15718
15726
  inputSchema: listFilesSchema,
@@ -15841,6 +15849,35 @@ function listProfiles2() {
15841
15849
  }
15842
15850
  return Array.from(profiles).sort((a, b) => a.localeCompare(b));
15843
15851
  }
15852
+ function listProfileStatuses(profile) {
15853
+ const profiles = profile ? [profile] : listProfiles2();
15854
+ const uniqueProfiles = profiles.length ? profiles : ["default"];
15855
+ const now3 = Date.now();
15856
+ return uniqueProfiles.map((name) => {
15857
+ const tokens = loadTokens2(name);
15858
+ const credentials = loadCredentials2(name);
15859
+ const hasAccessToken = Boolean(tokens?.accessToken || process.env.GOOGLE_ACCESS_TOKEN);
15860
+ const hasRefreshToken = Boolean(tokens?.refreshToken);
15861
+ const hasOAuthCredentials = Boolean(credentials.clientId && credentials.clientSecret);
15862
+ const expiresAt = tokens?.expiresAt ?? null;
15863
+ const expired = Boolean(expiresAt && now3 >= expiresAt - REFRESH_BUFFER_MS2);
15864
+ const authenticated = Boolean(process.env.GOOGLE_ACCESS_TOKEN || hasRefreshToken || hasAccessToken && !expired);
15865
+ const configured = authenticated || hasOAuthCredentials;
15866
+ const authRequired = !authenticated || expired && !hasRefreshToken;
15867
+ return {
15868
+ profile: name,
15869
+ configured,
15870
+ authenticated,
15871
+ expired,
15872
+ expiresAt,
15873
+ hasAccessToken,
15874
+ hasRefreshToken,
15875
+ hasOAuthCredentials,
15876
+ authRequired,
15877
+ message: authRequired ? `Google Drive profile "${name}" needs authentication. Run: connectors auth googledrive` : expired ? `Google Drive profile "${name}" access token is expired but can refresh.` : `Google Drive profile "${name}" is authenticated.`
15878
+ };
15879
+ });
15880
+ }
15844
15881
  function loadCredentials2(profile) {
15845
15882
  const envClientId = process.env.GOOGLE_CLIENT_ID;
15846
15883
  const envClientSecret = process.env.GOOGLE_CLIENT_SECRET;
@@ -15916,7 +15953,7 @@ function extractGoogleError(body) {
15916
15953
  // package.json
15917
15954
  var package_default = {
15918
15955
  name: "@hasna/connectors",
15919
- version: "1.3.27",
15956
+ version: "1.3.29",
15920
15957
  description: "Open source connector library - Install API connectors with a single command",
15921
15958
  type: "module",
15922
15959
  bin: {
@@ -0,0 +1 @@
1
+ export {};
@@ -1,2 +1,5 @@
1
1
  import { Command } from "commander";
2
+ export declare function getCurrentOAuthProfile(name: string, connectorsHome?: string): string;
3
+ export declare function getOAuthTokenPathsForProfile(name: string, connectorsHome?: string, profile?: string): string[];
4
+ export declare function hasOAuthTokenFileUpdatedSince(tokenPaths: string[], sinceMs: number): boolean;
2
5
  export declare function registerCommands(program: Command): void;
package/dist/index.js CHANGED
@@ -5465,6 +5465,9 @@ var downloadSchema = exports_external.object({
5465
5465
  }).optional(),
5466
5466
  exportMimeType: exports_external.string().optional()
5467
5467
  });
5468
+ var profilesStatusSchema = exports_external.object({
5469
+ profile: exports_external.string().optional()
5470
+ });
5468
5471
  var googleDriveConnector = defineConnector({
5469
5472
  meta: {
5470
5473
  name: "googledrive",
@@ -5487,6 +5490,11 @@ var googleDriveConnector = defineConnector({
5487
5490
  summary: "List configured Google Drive profiles.",
5488
5491
  execute: () => ({ profiles: listProfiles2() })
5489
5492
  },
5493
+ "profiles.status": {
5494
+ summary: "List Google Drive profile authentication status.",
5495
+ inputSchema: profilesStatusSchema,
5496
+ execute: (_ctx, input) => ({ profiles: listProfileStatuses(input.profile) })
5497
+ },
5490
5498
  "files.list": {
5491
5499
  summary: "List Google Drive files.",
5492
5500
  inputSchema: listFilesSchema,
@@ -5615,6 +5623,35 @@ function listProfiles2() {
5615
5623
  }
5616
5624
  return Array.from(profiles).sort((a, b) => a.localeCompare(b));
5617
5625
  }
5626
+ function listProfileStatuses(profile) {
5627
+ const profiles = profile ? [profile] : listProfiles2();
5628
+ const uniqueProfiles = profiles.length ? profiles : ["default"];
5629
+ const now = Date.now();
5630
+ return uniqueProfiles.map((name) => {
5631
+ const tokens = loadTokens2(name);
5632
+ const credentials = loadCredentials2(name);
5633
+ const hasAccessToken = Boolean(tokens?.accessToken || process.env.GOOGLE_ACCESS_TOKEN);
5634
+ const hasRefreshToken = Boolean(tokens?.refreshToken);
5635
+ const hasOAuthCredentials = Boolean(credentials.clientId && credentials.clientSecret);
5636
+ const expiresAt = tokens?.expiresAt ?? null;
5637
+ const expired = Boolean(expiresAt && now >= expiresAt - REFRESH_BUFFER_MS2);
5638
+ const authenticated = Boolean(process.env.GOOGLE_ACCESS_TOKEN || hasRefreshToken || hasAccessToken && !expired);
5639
+ const configured = authenticated || hasOAuthCredentials;
5640
+ const authRequired = !authenticated || expired && !hasRefreshToken;
5641
+ return {
5642
+ profile: name,
5643
+ configured,
5644
+ authenticated,
5645
+ expired,
5646
+ expiresAt,
5647
+ hasAccessToken,
5648
+ hasRefreshToken,
5649
+ hasOAuthCredentials,
5650
+ authRequired,
5651
+ message: authRequired ? `Google Drive profile "${name}" needs authentication. Run: connectors auth googledrive` : expired ? `Google Drive profile "${name}" access token is expired but can refresh.` : `Google Drive profile "${name}" is authenticated.`
5652
+ };
5653
+ });
5654
+ }
5618
5655
  function loadCredentials2(profile) {
5619
5656
  const envClientId = process.env.GOOGLE_CLIENT_ID;
5620
5657
  const envClientSecret = process.env.GOOGLE_CLIENT_SECRET;
@@ -5690,7 +5727,7 @@ function extractGoogleError(body) {
5690
5727
  // package.json
5691
5728
  var package_default = {
5692
5729
  name: "@hasna/connectors",
5693
- version: "1.3.27",
5730
+ version: "1.3.29",
5694
5731
  description: "Open source connector library - Install API connectors with a single command",
5695
5732
  type: "module",
5696
5733
  bin: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasna/connectors",
3
- "version": "1.3.27",
3
+ "version": "1.3.29",
4
4
  "description": "Open source connector library - Install API connectors with a single command",
5
5
  "type": "module",
6
6
  "bin": {