@hasna/connectors 1.4.4 → 1.4.5

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/index.js CHANGED
@@ -15,8 +15,8 @@ var __export = (target, all) => {
15
15
  };
16
16
 
17
17
  // src/lib/registry.ts
18
- import { existsSync as existsSync8, readFileSync as readFileSync4 } from "fs";
19
- import { join as join8, dirname as dirname4 } from "path";
18
+ import { existsSync as existsSync9, readFileSync as readFileSync4 } from "fs";
19
+ import { join as join10, dirname as dirname4 } from "path";
20
20
  import { fileURLToPath as fileURLToPath3 } from "url";
21
21
 
22
22
  // src/core/errors.ts
@@ -4968,9 +4968,115 @@ var githubConnector = defineConnector({
4968
4968
  });
4969
4969
 
4970
4970
  // src/core/connectors/gmail.ts
4971
- import { existsSync as existsSync2, mkdirSync, readFileSync, readdirSync, writeFileSync } from "fs";
4971
+ import { existsSync as existsSync3, mkdirSync, readFileSync, readdirSync, writeFileSync } from "fs";
4972
+ import { basename, join as join4 } from "path";
4973
+
4974
+ // src/lib/paths.ts
4975
+ import { existsSync as existsSync2 } from "fs";
4976
+ import { homedir as homedir2 } from "os";
4977
+ import { join as join3, resolve } from "path";
4978
+
4979
+ // ../../node_modules/.bun/@hasna+paths@0.1.0/node_modules/@hasna/paths/dist/index.js
4972
4980
  import { homedir } from "os";
4973
- import { basename, join as join2 } from "path";
4981
+ import { join as join2 } from "path";
4982
+ var KIND_ENV = {
4983
+ config: "HASNA_CONFIG_HOME",
4984
+ data: "HASNA_DATA_HOME",
4985
+ state: "HASNA_STATE_HOME",
4986
+ cache: "HASNA_CACHE_HOME"
4987
+ };
4988
+ var APP_SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
4989
+ function assertApp(app) {
4990
+ if (typeof app !== "string" || app.length === 0) {
4991
+ throw new TypeError("paths: app must be a non-empty string");
4992
+ }
4993
+ if (!APP_SLUG_RE.test(app)) {
4994
+ throw new TypeError(`paths: invalid app slug "${app}" \u2014 expected lowercase kebab-case ([a-z0-9]+(-[a-z0-9]+)*)`);
4995
+ }
4996
+ }
4997
+ function envOf(options) {
4998
+ return options.env ?? process.env;
4999
+ }
5000
+ function envValue(options, kind) {
5001
+ const value = envOf(options)[KIND_ENV[kind]];
5002
+ return typeof value === "string" && value.length > 0 ? value : undefined;
5003
+ }
5004
+ function isMacOS(platform) {
5005
+ return platform === "darwin";
5006
+ }
5007
+ function baseDir(kind, options) {
5008
+ const override = envValue(options, kind);
5009
+ if (override)
5010
+ return override;
5011
+ const home = options.home ?? homedir();
5012
+ const platform = options.platform ?? process.platform;
5013
+ if (isMacOS(platform)) {
5014
+ switch (kind) {
5015
+ case "config":
5016
+ case "data":
5017
+ return join2(home, "Library", "Application Support", "Hasna");
5018
+ case "cache":
5019
+ return join2(home, "Library", "Caches", "Hasna");
5020
+ case "state":
5021
+ return join2(home, "Library", "Logs", "Hasna");
5022
+ }
5023
+ }
5024
+ switch (kind) {
5025
+ case "config":
5026
+ return join2(home, ".config", "hasna");
5027
+ case "data":
5028
+ return join2(home, ".local", "share", "hasna");
5029
+ case "state":
5030
+ return join2(home, ".local", "state", "hasna");
5031
+ case "cache":
5032
+ return join2(home, ".cache", "hasna");
5033
+ }
5034
+ }
5035
+ function resolvePath(kind, options) {
5036
+ assertApp(options.app);
5037
+ const appSegment = options.internal === true ? join2("internal", options.app) : options.app;
5038
+ return join2(baseDir(kind, options), appSegment);
5039
+ }
5040
+ function dataDir(options) {
5041
+ return resolvePath("data", options);
5042
+ }
5043
+
5044
+ // src/lib/paths.ts
5045
+ function envOr(name, fallback) {
5046
+ const value = process.env[name]?.trim();
5047
+ return value ? value : fallback;
5048
+ }
5049
+ function effectiveHome() {
5050
+ return process.env["HOME"] || process.env["USERPROFILE"] || homedir2();
5051
+ }
5052
+ function legacyHomeDir() {
5053
+ return join3(effectiveHome(), ".hasna", "connectors");
5054
+ }
5055
+ function resolverHome() {
5056
+ return dataDir({
5057
+ app: "connectors",
5058
+ home: process.env["HOME"] || process.env["USERPROFILE"] || undefined
5059
+ });
5060
+ }
5061
+ function adoptResolverHome(resolved, env = process.env) {
5062
+ const dataOverride = env.HASNA_DATA_HOME;
5063
+ if (typeof dataOverride === "string" && dataOverride.trim().length > 0)
5064
+ return true;
5065
+ return existsSync2(join3(resolved, "connectors.db"));
5066
+ }
5067
+ function exactConnectorsHome() {
5068
+ const home = envOr("HASNA_CONNECTORS_DIR", "");
5069
+ return home ? home : undefined;
5070
+ }
5071
+ function connectorsHome() {
5072
+ const exact = exactConnectorsHome();
5073
+ if (exact)
5074
+ return resolve(exact);
5075
+ const resolved = resolverHome();
5076
+ return adoptResolverHome(resolved) ? resolve(resolved) : resolve(legacyHomeDir());
5077
+ }
5078
+
5079
+ // src/core/connectors/gmail.ts
4974
5080
  var GMAIL_API_BASE = "https://gmail.googleapis.com/gmail/v1";
4975
5081
  var TOKEN_URL = "https://oauth2.googleapis.com/token";
4976
5082
  var REFRESH_BUFFER_MS = 5 * 60 * 1000;
@@ -5174,7 +5280,7 @@ async function replyToMessage(profile, messageId, input) {
5174
5280
  }
5175
5281
  async function downloadAttachments(profile, input) {
5176
5282
  const messageId = getMessageId(input);
5177
- const outputDir = input.dir ?? input.outputDir ?? join2(configDirs()[0], "attachments", messageId);
5283
+ const outputDir = input.dir ?? input.outputDir ?? join4(configDirs()[0], "attachments", messageId);
5178
5284
  mkdirSync(outputDir, { recursive: true });
5179
5285
  const attachments = input.attachmentId && input.filename ? [{
5180
5286
  attachmentId: input.attachmentId,
@@ -5186,7 +5292,7 @@ async function downloadAttachments(profile, input) {
5186
5292
  for (const attachment of attachments) {
5187
5293
  const data = await requestJson(profile, `/users/me/messages/${encodeURIComponent(messageId)}/attachments/${encodeURIComponent(attachment.attachmentId)}`, {});
5188
5294
  const filename = safeFilename(attachment.filename);
5189
- const path = join2(outputDir, filename);
5295
+ const path = join4(outputDir, filename);
5190
5296
  const buffer = Buffer.from(data.data, "base64url");
5191
5297
  writeFileSync(path, buffer);
5192
5298
  downloaded.push({
@@ -5256,7 +5362,7 @@ function gmailBackoffDelayMs(attempt, retryAfter = null) {
5256
5362
  return Math.min(2 ** attempt * baseMs + jitterMs, 64000);
5257
5363
  }
5258
5364
  function sleep(ms) {
5259
- return new Promise((resolve) => setTimeout(resolve, ms));
5365
+ return new Promise((resolve2) => setTimeout(resolve2, ms));
5260
5366
  }
5261
5367
  async function getValidAccessToken(profile) {
5262
5368
  if (process.env.GMAIL_ACCESS_TOKEN)
@@ -5302,9 +5408,9 @@ async function refreshAccessToken(profile, currentTokens) {
5302
5408
  }
5303
5409
  function listProfiles() {
5304
5410
  const profiles = new Set;
5305
- for (const baseDir of configDirs()) {
5306
- const profilesDir = join2(baseDir, "profiles");
5307
- if (!existsSync2(profilesDir))
5411
+ for (const baseDir2 of configDirs()) {
5412
+ const profilesDir = join4(baseDir2, "profiles");
5413
+ if (!existsSync3(profilesDir))
5308
5414
  continue;
5309
5415
  for (const entry of readdirSync(profilesDir, { withFileTypes: true })) {
5310
5416
  if (entry.isDirectory())
@@ -5320,10 +5426,10 @@ function loadCredentials(profile) {
5320
5426
  const envClientSecret = process.env.GMAIL_CLIENT_SECRET ?? process.env.GOOGLE_CLIENT_SECRET;
5321
5427
  if (envClientId && envClientSecret)
5322
5428
  return { clientId: envClientId, clientSecret: envClientSecret };
5323
- for (const baseDir of configDirs()) {
5429
+ for (const baseDir2 of configDirs()) {
5324
5430
  const credentials = {
5325
- ...readJson(join2(baseDir, "credentials.json")),
5326
- ...readJson(join2(baseDir, "profiles", profile, "config.json"))
5431
+ ...readJson(join4(baseDir2, "credentials.json")),
5432
+ ...readJson(join4(baseDir2, "profiles", profile, "config.json"))
5327
5433
  };
5328
5434
  if (credentials.clientId || credentials.clientSecret)
5329
5435
  return credentials;
@@ -5331,31 +5437,31 @@ function loadCredentials(profile) {
5331
5437
  return {};
5332
5438
  }
5333
5439
  function loadTokens(profile) {
5334
- for (const baseDir of configDirs()) {
5335
- const fromProfile = readJson(join2(baseDir, "profiles", profile, "tokens.json"));
5440
+ for (const baseDir2 of configDirs()) {
5441
+ const fromProfile = readJson(join4(baseDir2, "profiles", profile, "tokens.json"));
5336
5442
  if (fromProfile)
5337
5443
  return fromProfile;
5338
- const flat = readJson(join2(baseDir, "profiles", `${profile}.json`));
5444
+ const flat = readJson(join4(baseDir2, "profiles", `${profile}.json`));
5339
5445
  if (flat)
5340
5446
  return flat.tokens ?? (flat.accessToken || flat.refreshToken ? flat : null);
5341
5447
  }
5342
5448
  return null;
5343
5449
  }
5344
5450
  function saveTokens(profile, tokens) {
5345
- const baseDir = configDirs().find((dir) => existsSync2(dir)) ?? configDirs()[0];
5346
- const profileDir = join2(baseDir, "profiles", profile);
5451
+ const baseDir2 = configDirs().find((dir) => existsSync3(dir)) ?? configDirs()[0];
5452
+ const profileDir = join4(baseDir2, "profiles", profile);
5347
5453
  mkdirSync(profileDir, { recursive: true });
5348
- writeFileSync(join2(profileDir, "tokens.json"), JSON.stringify(tokens, null, 2), { mode: 384 });
5454
+ writeFileSync(join4(profileDir, "tokens.json"), JSON.stringify(tokens, null, 2), { mode: 384 });
5349
5455
  }
5350
5456
  function configDirs() {
5351
5457
  const explicit = process.env.HASNA_GMAIL_CONNECTOR_DIR ?? process.env.GMAIL_CONNECTOR_DIR;
5352
5458
  if (explicit)
5353
5459
  return [explicit];
5354
- const baseDir = process.env.HASNA_CONNECTORS_DIR ?? join2(homedir(), ".hasna", "connectors");
5355
- return [join2(baseDir, "gmail"), join2(baseDir, "connect-gmail")];
5460
+ const baseDir2 = connectorsHome();
5461
+ return [join4(baseDir2, "gmail"), join4(baseDir2, "connect-gmail")];
5356
5462
  }
5357
5463
  function readJson(path) {
5358
- if (!existsSync2(path))
5464
+ if (!existsSync3(path))
5359
5465
  return null;
5360
5466
  try {
5361
5467
  return JSON.parse(readFileSync(path, "utf8"));
@@ -5436,9 +5542,8 @@ function safeFilename(filename) {
5436
5542
  }
5437
5543
 
5438
5544
  // src/core/connectors/googledrive.ts
5439
- import { existsSync as existsSync3, mkdirSync as mkdirSync2, readFileSync as readFileSync2, readdirSync as readdirSync2, writeFileSync as writeFileSync2 } from "fs";
5440
- import { homedir as homedir2 } from "os";
5441
- import { basename as basename2, join as join3 } from "path";
5545
+ import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync2, readdirSync as readdirSync2, writeFileSync as writeFileSync2 } from "fs";
5546
+ import { basename as basename2, join as join5 } from "path";
5442
5547
  var DRIVE_API_BASE = "https://www.googleapis.com/drive/v3";
5443
5548
  var TOKEN_URL2 = "https://oauth2.googleapis.com/token";
5444
5549
  var REFRESH_BUFFER_MS2 = 5 * 60 * 1000;
@@ -5647,9 +5752,9 @@ async function refreshAccessToken2(profile, currentTokens) {
5647
5752
  }
5648
5753
  function listProfiles2() {
5649
5754
  const profiles = new Set;
5650
- for (const baseDir of configDirs2()) {
5651
- const profilesDir = join3(baseDir, "profiles");
5652
- if (!existsSync3(profilesDir))
5755
+ for (const baseDir2 of configDirs2()) {
5756
+ const profilesDir = join5(baseDir2, "profiles");
5757
+ if (!existsSync4(profilesDir))
5653
5758
  continue;
5654
5759
  for (const entry of readdirSync2(profilesDir, { withFileTypes: true })) {
5655
5760
  if (entry.isDirectory())
@@ -5694,10 +5799,10 @@ function loadCredentials2(profile) {
5694
5799
  const envClientSecret = process.env.GOOGLE_CLIENT_SECRET;
5695
5800
  if (envClientId && envClientSecret)
5696
5801
  return { clientId: envClientId, clientSecret: envClientSecret };
5697
- for (const baseDir of configDirs2()) {
5802
+ for (const baseDir2 of configDirs2()) {
5698
5803
  const credentials = {
5699
- ...readJson2(join3(baseDir, "credentials.json")),
5700
- ...readJson2(join3(baseDir, "profiles", profile, "config.json"))
5804
+ ...readJson2(join5(baseDir2, "credentials.json")),
5805
+ ...readJson2(join5(baseDir2, "profiles", profile, "config.json"))
5701
5806
  };
5702
5807
  if (credentials.clientId || credentials.clientSecret)
5703
5808
  return credentials;
@@ -5705,31 +5810,31 @@ function loadCredentials2(profile) {
5705
5810
  return {};
5706
5811
  }
5707
5812
  function loadTokens2(profile) {
5708
- for (const baseDir of configDirs2()) {
5709
- const fromProfile = readJson2(join3(baseDir, "profiles", profile, "tokens.json"));
5813
+ for (const baseDir2 of configDirs2()) {
5814
+ const fromProfile = readJson2(join5(baseDir2, "profiles", profile, "tokens.json"));
5710
5815
  if (fromProfile)
5711
5816
  return fromProfile;
5712
- const flat = readJson2(join3(baseDir, "profiles", `${profile}.json`));
5817
+ const flat = readJson2(join5(baseDir2, "profiles", `${profile}.json`));
5713
5818
  if (flat)
5714
5819
  return flat.tokens ?? (flat.accessToken || flat.refreshToken ? flat : null);
5715
5820
  }
5716
5821
  return null;
5717
5822
  }
5718
5823
  function saveTokens2(profile, tokens) {
5719
- const baseDir = configDirs2().find((dir) => existsSync3(dir)) ?? configDirs2()[0];
5720
- const profileDir = join3(baseDir, "profiles", profile);
5824
+ const baseDir2 = configDirs2().find((dir) => existsSync4(dir)) ?? configDirs2()[0];
5825
+ const profileDir = join5(baseDir2, "profiles", profile);
5721
5826
  mkdirSync2(profileDir, { recursive: true });
5722
- writeFileSync2(join3(profileDir, "tokens.json"), JSON.stringify(tokens, null, 2), { mode: 384 });
5827
+ writeFileSync2(join5(profileDir, "tokens.json"), JSON.stringify(tokens, null, 2), { mode: 384 });
5723
5828
  }
5724
5829
  function configDirs2() {
5725
5830
  const explicit = process.env.HASNA_GOOGLE_DRIVE_CONNECTOR_DIR ?? process.env.GOOGLE_DRIVE_CONNECTOR_DIR;
5726
5831
  if (explicit)
5727
5832
  return [explicit];
5728
- const baseDir = process.env.HASNA_CONNECTORS_DIR ?? join3(homedir2(), ".hasna", "connectors");
5729
- return [join3(baseDir, "googledrive"), join3(baseDir, "connect-googledrive")];
5833
+ const baseDir2 = connectorsHome();
5834
+ return [join5(baseDir2, "googledrive"), join5(baseDir2, "connect-googledrive")];
5730
5835
  }
5731
5836
  function readJson2(path) {
5732
- if (!existsSync3(path))
5837
+ if (!existsSync4(path))
5733
5838
  return null;
5734
5839
  try {
5735
5840
  return JSON.parse(readFileSync2(path, "utf8"));
@@ -5764,7 +5869,7 @@ function extractGoogleError(body) {
5764
5869
  // package.json
5765
5870
  var package_default = {
5766
5871
  name: "@hasna/connectors",
5767
- version: "1.4.4",
5872
+ version: "1.4.5",
5768
5873
  description: "Open source connector library - Install API connectors with a single command",
5769
5874
  type: "module",
5770
5875
  bin: {
@@ -5836,6 +5941,7 @@ var package_default = {
5836
5941
  },
5837
5942
  dependencies: {
5838
5943
  "@hasna/events": "0.1.8",
5944
+ "@hasna/paths": "0.1.0",
5839
5945
  "@modelcontextprotocol/sdk": "^1.26.0",
5840
5946
  chalk: "^5.3.0",
5841
5947
  commander: "^12.1.0",
@@ -5868,7 +5974,7 @@ var package_default = {
5868
5974
 
5869
5975
  // src/core/connectors/imessage.ts
5870
5976
  import {
5871
- existsSync as existsSync6,
5977
+ existsSync as existsSync7,
5872
5978
  mkdirSync as mkdirSync4,
5873
5979
  readFileSync as readFileSync3,
5874
5980
  readdirSync as readdirSync5,
@@ -5876,40 +5982,39 @@ import {
5876
5982
  statSync as statSync3,
5877
5983
  writeFileSync as writeFileSync3
5878
5984
  } from "fs";
5879
- import { join as join6 } from "path";
5985
+ import { join as join8 } from "path";
5880
5986
 
5881
5987
  // src/lib/connector-resolver.ts
5882
- import { existsSync as existsSync5, readdirSync as readdirSync4, statSync as statSync2 } from "fs";
5883
- import { join as join5 } from "path";
5988
+ import { existsSync as existsSync6, readdirSync as readdirSync4, statSync as statSync2 } from "fs";
5989
+ import { join as join7 } from "path";
5884
5990
 
5885
5991
  // src/db/database.ts
5886
- import { dirname as dirname2, join as join4 } from "path";
5887
- import { homedir as homedir3 } from "os";
5888
- import { mkdirSync as mkdirSync3, existsSync as existsSync4, readdirSync as readdirSync3, copyFileSync, statSync } from "fs";
5992
+ import { dirname as dirname2, join as join6 } from "path";
5993
+ import { mkdirSync as mkdirSync3, existsSync as existsSync5, readdirSync as readdirSync3, copyFileSync, statSync } from "fs";
5889
5994
  function mergeDirectoryContents(sourceDir, targetDir) {
5890
- if (!existsSync4(sourceDir)) {
5995
+ if (!existsSync5(sourceDir)) {
5891
5996
  return;
5892
5997
  }
5893
5998
  mkdirSync3(targetDir, { recursive: true });
5894
5999
  for (const entry of readdirSync3(sourceDir)) {
5895
- const sourcePath = join4(sourceDir, entry);
5896
- const targetPath = join4(targetDir, entry);
6000
+ const sourcePath = join6(sourceDir, entry);
6001
+ const targetPath = join6(targetDir, entry);
5897
6002
  try {
5898
6003
  const sourceStat = statSync(sourcePath);
5899
6004
  if (sourceStat.isDirectory()) {
5900
6005
  mergeDirectoryContents(sourcePath, targetPath);
5901
6006
  continue;
5902
6007
  }
5903
- if (!existsSync4(targetPath)) {
6008
+ if (!existsSync5(targetPath)) {
5904
6009
  copyFileSync(sourcePath, targetPath);
5905
6010
  }
5906
6011
  } catch {}
5907
6012
  }
5908
6013
  }
5909
6014
  function getConnectorsHome() {
5910
- const home = process.env["HOME"] || process.env["USERPROFILE"] || homedir3();
5911
- const newDir = join4(home, ".hasna", "connectors");
5912
- const legacyDirs = [join4(home, ".connectors"), join4(home, ".connect")];
6015
+ const newDir = connectorsHome();
6016
+ const home = effectiveHome();
6017
+ const legacyDirs = [join6(home, ".connectors"), join6(home, ".connect")];
5913
6018
  mkdirSync3(newDir, { recursive: true });
5914
6019
  for (const legacyDir of legacyDirs) {
5915
6020
  try {
@@ -5919,7 +6024,7 @@ function getConnectorsHome() {
5919
6024
  return newDir;
5920
6025
  }
5921
6026
  var DB_DIR = getConnectorsHome();
5922
- var DB_PATH = join4(DB_DIR, "connectors.db");
6027
+ var DB_PATH = join6(DB_DIR, "connectors.db");
5923
6028
 
5924
6029
  // src/lib/connector-resolver.ts
5925
6030
  var LEGACY_CONNECTOR_PREFIX = "connect-";
@@ -5970,8 +6075,8 @@ function connectorPackageDirNames(name) {
5970
6075
  function resolveConnectorPackagePath(connectorsDir, name) {
5971
6076
  const resolution = resolveConnectorName(name);
5972
6077
  const dirNames = connectorPackageDirNames(name);
5973
- const checkedPaths = dirNames.map((dirName) => join5(connectorsDir, dirName));
5974
- const existingPath = checkedPaths.find((path) => existsSync5(path)) ?? null;
6078
+ const checkedPaths = dirNames.map((dirName) => join7(connectorsDir, dirName));
6079
+ const existingPath = checkedPaths.find((path) => existsSync6(path)) ?? null;
5975
6080
  const existingDirName = existingPath ? dirNames[checkedPaths.indexOf(existingPath)] : null;
5976
6081
  return {
5977
6082
  ...resolution,
@@ -5987,16 +6092,16 @@ function getConnectorPackagePath(connectorsDir, name) {
5987
6092
  const resolved = resolveConnectorPackagePath(connectorsDir, name);
5988
6093
  return resolved.existingPath ?? resolved.preferredPath;
5989
6094
  }
5990
- function resolveConnectorConfigPaths(name, connectorsHome = getConnectorsHome()) {
6095
+ function resolveConnectorConfigPaths(name, connectorsHome2 = getConnectorsHome()) {
5991
6096
  const resolution = resolveConnectorName(name);
5992
6097
  const preferredDirName = resolution.canonicalName || resolution.legacyName;
5993
- const preferredPath = join5(connectorsHome, preferredDirName);
5994
- const legacyPath = join5(connectorsHome, resolution.legacyName);
6098
+ const preferredPath = join7(connectorsHome2, preferredDirName);
6099
+ const legacyPath = join7(connectorsHome2, resolution.legacyName);
5995
6100
  const paths = preferredPath === legacyPath ? [preferredPath] : [preferredPath, legacyPath];
5996
- const existingPaths = paths.filter((path) => existsSync5(path));
6101
+ const existingPaths = paths.filter((path) => existsSync6(path));
5997
6102
  return {
5998
6103
  ...resolution,
5999
- connectorsHome,
6104
+ connectorsHome: connectorsHome2,
6000
6105
  preferredDirName,
6001
6106
  preferredPath,
6002
6107
  legacyPath,
@@ -6004,11 +6109,11 @@ function resolveConnectorConfigPaths(name, connectorsHome = getConnectorsHome())
6004
6109
  readPaths: paths
6005
6110
  };
6006
6111
  }
6007
- function getConnectorConfigDir(name, connectorsHome = getConnectorsHome()) {
6008
- return resolveConnectorConfigPaths(name, connectorsHome).preferredPath;
6112
+ function getConnectorConfigDir(name, connectorsHome2 = getConnectorsHome()) {
6113
+ return resolveConnectorConfigPaths(name, connectorsHome2).preferredPath;
6009
6114
  }
6010
- function getConnectorConfigReadDirs(name, connectorsHome = getConnectorsHome()) {
6011
- return resolveConnectorConfigPaths(name, connectorsHome).readPaths;
6115
+ function getConnectorConfigReadDirs(name, connectorsHome2 = getConnectorsHome()) {
6116
+ return resolveConnectorConfigPaths(name, connectorsHome2).readPaths;
6012
6117
  }
6013
6118
 
6014
6119
  // src/core/connectors/imessage.ts
@@ -6178,12 +6283,12 @@ function getConfigReadDirs() {
6178
6283
  return getConnectorConfigReadDirs(CONNECTOR_NAME);
6179
6284
  }
6180
6285
  function getProfilesDir() {
6181
- return join6(getConfigDir(), "profiles");
6286
+ return join8(getConfigDir(), "profiles");
6182
6287
  }
6183
6288
  function getCurrentProfile() {
6184
6289
  for (const configDir of getConfigReadDirs()) {
6185
- const currentProfileFile = join6(configDir, "current_profile");
6186
- if (!existsSync6(currentProfileFile))
6290
+ const currentProfileFile = join8(configDir, "current_profile");
6291
+ if (!existsSync7(currentProfileFile))
6187
6292
  continue;
6188
6293
  try {
6189
6294
  return readFileSync3(currentProfileFile, "utf-8").trim() || "default";
@@ -6196,16 +6301,16 @@ function getCurrentProfile() {
6196
6301
  function setCurrentProfile(profile) {
6197
6302
  const configDir = getConfigDir();
6198
6303
  mkdirSync4(configDir, { recursive: true });
6199
- writeFileSync3(join6(configDir, "current_profile"), profile);
6304
+ writeFileSync3(join8(configDir, "current_profile"), profile);
6200
6305
  }
6201
6306
  function getFlatProfilePath(profile) {
6202
- return join6(getProfilesDir(), `${profile}.json`);
6307
+ return join8(getProfilesDir(), `${profile}.json`);
6203
6308
  }
6204
6309
  function getFlatProfileReadPaths(profile) {
6205
- return getConfigReadDirs().map((dir) => join6(dir, "profiles", `${profile}.json`));
6310
+ return getConfigReadDirs().map((dir) => join8(dir, "profiles", `${profile}.json`));
6206
6311
  }
6207
6312
  function getDirectoryProfileReadPaths(profile) {
6208
- return getConfigReadDirs().map((dir) => join6(dir, "profiles", profile, "config.json"));
6313
+ return getConfigReadDirs().map((dir) => join8(dir, "profiles", profile, "config.json"));
6209
6314
  }
6210
6315
  function loadJsonFile(path) {
6211
6316
  try {
@@ -6225,8 +6330,8 @@ function sanitizeProfileConfig(config) {
6225
6330
  };
6226
6331
  }
6227
6332
  function loadProfile(profile = getCurrentProfile()) {
6228
- const flatConfig = getFlatProfileReadPaths(profile).reverse().reduce((config, path) => ({ ...config, ...existsSync6(path) ? loadJsonFile(path) : {} }), {});
6229
- const directoryConfig = getDirectoryProfileReadPaths(profile).reverse().reduce((config, path) => ({ ...config, ...existsSync6(path) ? loadJsonFile(path) : {} }), {});
6333
+ const flatConfig = getFlatProfileReadPaths(profile).reverse().reduce((config, path) => ({ ...config, ...existsSync7(path) ? loadJsonFile(path) : {} }), {});
6334
+ const directoryConfig = getDirectoryProfileReadPaths(profile).reverse().reduce((config, path) => ({ ...config, ...existsSync7(path) ? loadJsonFile(path) : {} }), {});
6230
6335
  return sanitizeProfileConfig({
6231
6336
  ...flatConfig,
6232
6337
  ...directoryConfig
@@ -6242,17 +6347,17 @@ function profileExists(profile) {
6242
6347
  if (profile === "default") {
6243
6348
  return true;
6244
6349
  }
6245
- return getFlatProfileReadPaths(profile).some((path) => existsSync6(path)) || getConfigReadDirs().some((dir) => existsSync6(join6(dir, "profiles", profile)));
6350
+ return getFlatProfileReadPaths(profile).some((path) => existsSync7(path)) || getConfigReadDirs().some((dir) => existsSync7(join8(dir, "profiles", profile)));
6246
6351
  }
6247
6352
  function listProfiles3() {
6248
6353
  const seen = new Set(["default"]);
6249
6354
  for (const configDir of getConfigReadDirs()) {
6250
- const profilesDir = join6(configDir, "profiles");
6251
- if (!existsSync6(profilesDir))
6355
+ const profilesDir = join8(configDir, "profiles");
6356
+ if (!existsSync7(profilesDir))
6252
6357
  continue;
6253
6358
  try {
6254
6359
  for (const entry of readdirSync5(profilesDir)) {
6255
- const fullPath = join6(profilesDir, entry);
6360
+ const fullPath = join8(profilesDir, entry);
6256
6361
  const stat = statSync3(fullPath);
6257
6362
  if (stat.isDirectory()) {
6258
6363
  seen.add(entry);
@@ -6274,11 +6379,11 @@ function createProfile(profile, config = {}) {
6274
6379
  }
6275
6380
  function clearProfile(profile = getCurrentProfile()) {
6276
6381
  const flatPath = getFlatProfilePath(profile);
6277
- const directoryPath = join6(getProfilesDir(), profile);
6278
- if (existsSync6(flatPath)) {
6382
+ const directoryPath = join8(getProfilesDir(), profile);
6383
+ if (existsSync7(flatPath)) {
6279
6384
  rmSync(flatPath);
6280
6385
  }
6281
- if (existsSync6(directoryPath)) {
6386
+ if (existsSync7(directoryPath)) {
6282
6387
  rmSync(directoryPath, { recursive: true, force: true });
6283
6388
  }
6284
6389
  }
@@ -7083,19 +7188,19 @@ var imessageConnector = defineConnector({
7083
7188
  });
7084
7189
 
7085
7190
  // src/core/connectors/stripe.ts
7086
- import { existsSync as existsSync7 } from "fs";
7087
- import { dirname as dirname3, join as join7 } from "path";
7191
+ import { existsSync as existsSync8 } from "fs";
7192
+ import { dirname as dirname3, join as join9 } from "path";
7088
7193
  import { fileURLToPath as fileURLToPath2, pathToFileURL as pathToFileURL2 } from "url";
7089
7194
  var __dirname3 = dirname3(fileURLToPath2(import.meta.url));
7090
7195
  function resolveStripeConnectorDir() {
7091
7196
  const candidates = [
7092
- join7(__dirname3, "..", "..", "..", "connectors", "stripe"),
7093
- join7(__dirname3, "..", "..", "connectors", "stripe"),
7094
- join7(__dirname3, "..", "connectors", "stripe"),
7095
- join7(process.cwd(), "connectors", "stripe")
7197
+ join9(__dirname3, "..", "..", "..", "connectors", "stripe"),
7198
+ join9(__dirname3, "..", "..", "connectors", "stripe"),
7199
+ join9(__dirname3, "..", "connectors", "stripe"),
7200
+ join9(process.cwd(), "connectors", "stripe")
7096
7201
  ];
7097
7202
  for (const candidate of candidates) {
7098
- if (existsSync7(candidate)) {
7203
+ if (existsSync8(candidate)) {
7099
7204
  return candidate;
7100
7205
  }
7101
7206
  }
@@ -7334,10 +7439,10 @@ function buildCommandHelp2(spec) {
7334
7439
  var ROOT_HELP3 = buildRootHelp2(COMMAND_SPECS2);
7335
7440
  var COMMAND_HELP3 = Object.fromEntries(COMMAND_SPECS2.map((spec) => [spec.name, buildCommandHelp2(spec)]));
7336
7441
  async function loadStripeApiModule() {
7337
- return await import(pathToFileURL2(join7(CONNECTOR_DIR2, "src", "api", "index.ts")).href);
7442
+ return await import(pathToFileURL2(join9(CONNECTOR_DIR2, "src", "api", "index.ts")).href);
7338
7443
  }
7339
7444
  async function loadStripeConfigModule() {
7340
- return await import(pathToFileURL2(join7(CONNECTOR_DIR2, "src", "utils", "config.ts")).href);
7445
+ return await import(pathToFileURL2(join9(CONNECTOR_DIR2, "src", "utils", "config.ts")).href);
7341
7446
  }
7342
7447
  function extractGlobalArgs3(args) {
7343
7448
  const remaining = [];
@@ -16393,16 +16498,16 @@ function loadConnectorVersions() {
16393
16498
  versionsLoaded = true;
16394
16499
  const thisDir = dirname4(fileURLToPath3(import.meta.url));
16395
16500
  const candidates = [
16396
- join8(thisDir, "..", "connectors"),
16397
- join8(thisDir, "..", "..", "connectors")
16501
+ join10(thisDir, "..", "connectors"),
16502
+ join10(thisDir, "..", "..", "connectors")
16398
16503
  ];
16399
- const connectorsDir = candidates.find((d) => existsSync8(d));
16504
+ const connectorsDir = candidates.find((d) => existsSync9(d));
16400
16505
  if (!connectorsDir)
16401
16506
  return;
16402
16507
  for (const connector of CONNECTORS) {
16403
16508
  try {
16404
- const pkgPath = join8(getConnectorPackagePath(connectorsDir, connector.name), "package.json");
16405
- if (existsSync8(pkgPath)) {
16509
+ const pkgPath = join10(getConnectorPackagePath(connectorsDir, connector.name), "package.json");
16510
+ if (existsSync9(pkgPath)) {
16406
16511
  const pkg = JSON.parse(readFileSync4(pkgPath, "utf-8"));
16407
16512
  connector.version = pkg.version || "0.0.0";
16408
16513
  continue;
@@ -16415,16 +16520,16 @@ function loadConnectorVersions() {
16415
16520
  }
16416
16521
  }
16417
16522
  // src/lib/installer.ts
16418
- import { existsSync as existsSync9, mkdirSync as mkdirSync5, readFileSync as readFileSync5, writeFileSync as writeFileSync4, readdirSync as readdirSync6, statSync as statSync4, rmSync as rmSync2 } from "fs";
16419
- import { join as join9, dirname as dirname5 } from "path";
16523
+ import { existsSync as existsSync10, mkdirSync as mkdirSync5, readFileSync as readFileSync5, writeFileSync as writeFileSync4, readdirSync as readdirSync6, statSync as statSync4, rmSync as rmSync2 } from "fs";
16524
+ import { join as join11, dirname as dirname5 } from "path";
16420
16525
  import { fileURLToPath as fileURLToPath4 } from "url";
16421
16526
  var __dirname4 = dirname5(fileURLToPath4(import.meta.url));
16422
16527
  function resolveConnectorsDir() {
16423
- const fromBin = join9(__dirname4, "..", "connectors");
16424
- if (existsSync9(fromBin))
16528
+ const fromBin = join11(__dirname4, "..", "connectors");
16529
+ if (existsSync10(fromBin))
16425
16530
  return fromBin;
16426
- const fromSrc = join9(__dirname4, "..", "..", "connectors");
16427
- if (existsSync9(fromSrc))
16531
+ const fromSrc = join11(__dirname4, "..", "..", "connectors");
16532
+ if (existsSync10(fromSrc))
16428
16533
  return fromSrc;
16429
16534
  return fromBin;
16430
16535
  }
@@ -16433,17 +16538,17 @@ var PROJECT_CONNECTORS_DIRNAME = ".connectors";
16433
16538
  var ENABLEMENT_MANIFEST_FILENAME = "manifest.json";
16434
16539
  var ENABLEMENT_INDEX_FILENAME = "index.ts";
16435
16540
  function getProjectConnectorsDir(targetDir) {
16436
- return join9(targetDir, PROJECT_CONNECTORS_DIRNAME);
16541
+ return join11(targetDir, PROJECT_CONNECTORS_DIRNAME);
16437
16542
  }
16438
16543
  function getEnablementManifestPath(targetDir) {
16439
- return join9(getProjectConnectorsDir(targetDir), ENABLEMENT_MANIFEST_FILENAME);
16544
+ return join11(getProjectConnectorsDir(targetDir), ENABLEMENT_MANIFEST_FILENAME);
16440
16545
  }
16441
16546
  function getLegacyInstallPath(targetDir, name) {
16442
- return join9(getProjectConnectorsDir(targetDir), legacyConnectorName(name));
16547
+ return join11(getProjectConnectorsDir(targetDir), legacyConnectorName(name));
16443
16548
  }
16444
16549
  function loadEnablementManifest(targetDir) {
16445
16550
  const manifestPath = getEnablementManifestPath(targetDir);
16446
- if (!existsSync9(manifestPath)) {
16551
+ if (!existsSync10(manifestPath)) {
16447
16552
  return null;
16448
16553
  }
16449
16554
  try {
@@ -16463,11 +16568,11 @@ function loadEnablementManifest(targetDir) {
16463
16568
  }
16464
16569
  function getLegacyInstalledConnectors(targetDir) {
16465
16570
  const connectorsDir = getProjectConnectorsDir(targetDir);
16466
- if (!existsSync9(connectorsDir)) {
16571
+ if (!existsSync10(connectorsDir)) {
16467
16572
  return [];
16468
16573
  }
16469
16574
  return readdirSync6(connectorsDir).filter((entry) => {
16470
- const fullPath = join9(connectorsDir, entry);
16575
+ const fullPath = join11(connectorsDir, entry);
16471
16576
  return entry.startsWith("connect-") && statSync4(fullPath).isDirectory();
16472
16577
  }).map((entry) => entry.replace("connect-", "")).sort();
16473
16578
  }
@@ -16476,7 +16581,7 @@ function getEnabledConnectors(targetDir) {
16476
16581
  return [...new Set([...manifestConnectors, ...getLegacyInstalledConnectors(targetDir)])].sort();
16477
16582
  }
16478
16583
  function updateConnectorsIndex(connectorsDir, connectors18) {
16479
- const indexPath = join9(connectorsDir, ENABLEMENT_INDEX_FILENAME);
16584
+ const indexPath = join11(connectorsDir, ENABLEMENT_INDEX_FILENAME);
16480
16585
  const connectorList = connectors18.map((connector) => ` "${connector}",`).join(`
16481
16586
  `);
16482
16587
  const content = `/**
@@ -16512,7 +16617,7 @@ function getConnectorPath(name) {
16512
16617
  }
16513
16618
  function connectorExists(name) {
16514
16619
  const normalizedName = normalizeConnectorName(name);
16515
- return hasInternalConnectorDefinition(normalizedName) || existsSync9(getConnectorPath(normalizedName));
16620
+ return hasInternalConnectorDefinition(normalizedName) || existsSync10(getConnectorPath(normalizedName));
16516
16621
  }
16517
16622
  function installConnector(name, options = {}) {
16518
16623
  const { targetDir = process.cwd(), overwrite = false } = options;
@@ -16545,7 +16650,7 @@ function installConnector(name, options = {}) {
16545
16650
  try {
16546
16651
  const nextEnabled = [...new Set([...installed, normalizedName])].sort();
16547
16652
  writeEnablementManifest(targetDir, nextEnabled);
16548
- if (overwrite && existsSync9(legacyInstallPath)) {
16653
+ if (overwrite && existsSync10(legacyInstallPath)) {
16549
16654
  rmSync2(legacyInstallPath, { recursive: true });
16550
16655
  }
16551
16656
  return {
@@ -16580,8 +16685,8 @@ function parseConnectorDocs(raw) {
16580
16685
  function getConnectorDocs(name) {
16581
16686
  const normalizedName = normalizeConnectorName(name);
16582
16687
  const connectorPath = getConnectorPath(normalizedName);
16583
- const claudeMdPath = join9(connectorPath, "CLAUDE.md");
16584
- if (existsSync9(claudeMdPath)) {
16688
+ const claudeMdPath = join11(connectorPath, "CLAUDE.md");
16689
+ if (existsSync10(claudeMdPath)) {
16585
16690
  return parseConnectorDocs(readFileSync5(claudeMdPath, "utf-8"));
16586
16691
  }
16587
16692
  const internalDocs = getInternalConnectorDefinition(normalizedName)?.docsMarkdown;
@@ -16626,20 +16731,20 @@ function removeConnector(name, targetDir = process.cwd()) {
16626
16731
  const nextEnabled = installed.filter((connector) => connector !== normalizedName);
16627
16732
  writeEnablementManifest(targetDir, nextEnabled);
16628
16733
  const legacyInstallPath = getLegacyInstallPath(targetDir, normalizedName);
16629
- if (existsSync9(legacyInstallPath)) {
16734
+ if (existsSync10(legacyInstallPath)) {
16630
16735
  rmSync2(legacyInstallPath, { recursive: true });
16631
16736
  }
16632
16737
  return true;
16633
16738
  }
16634
16739
  // src/lib/runner.ts
16635
- import { existsSync as existsSync11, readdirSync as readdirSync8 } from "fs";
16636
- import { join as join11, dirname as dirname6 } from "path";
16740
+ import { existsSync as existsSync12, readdirSync as readdirSync8 } from "fs";
16741
+ import { join as join13, dirname as dirname6 } from "path";
16637
16742
  import { fileURLToPath as fileURLToPath5 } from "url";
16638
16743
  import { spawn } from "child_process";
16639
16744
 
16640
16745
  // src/server/auth.ts
16641
- import { chmodSync, existsSync as existsSync10, readFileSync as readFileSync6, writeFileSync as writeFileSync5, mkdirSync as mkdirSync6, readdirSync as readdirSync7, rmSync as rmSync3, statSync as statSync5 } from "fs";
16642
- import { join as join10 } from "path";
16746
+ import { chmodSync, existsSync as existsSync11, readFileSync as readFileSync6, writeFileSync as writeFileSync5, mkdirSync as mkdirSync6, readdirSync as readdirSync7, rmSync as rmSync3, statSync as statSync5 } from "fs";
16747
+ import { join as join12 } from "path";
16643
16748
  var oauthStateStore = new Map;
16644
16749
  var GOOGLE_SCOPES = {
16645
16750
  gmail: [
@@ -16703,8 +16808,8 @@ function getConnectorConfigReadDirs2(name) {
16703
16808
  function getCurrentProfile2(name) {
16704
16809
  name = normalizeConnectorName(name);
16705
16810
  for (const configDir of getConnectorConfigReadDirs2(name)) {
16706
- const currentProfileFile = join10(configDir, "current_profile");
16707
- if (existsSync10(currentProfileFile)) {
16811
+ const currentProfileFile = join12(configDir, "current_profile");
16812
+ if (existsSync11(currentProfileFile)) {
16708
16813
  try {
16709
16814
  return readFileSync6(currentProfileFile, "utf-8").trim() || "default";
16710
16815
  } catch {
@@ -16717,14 +16822,14 @@ function getCurrentProfile2(name) {
16717
16822
  function loadProfileConfigFromDir(configDir, profile) {
16718
16823
  let flatConfig = {};
16719
16824
  let dirConfig = {};
16720
- const profileFile = join10(configDir, "profiles", `${profile}.json`);
16721
- if (existsSync10(profileFile)) {
16825
+ const profileFile = join12(configDir, "profiles", `${profile}.json`);
16826
+ if (existsSync11(profileFile)) {
16722
16827
  try {
16723
16828
  flatConfig = JSON.parse(readFileSync6(profileFile, "utf-8"));
16724
16829
  } catch {}
16725
16830
  }
16726
- const profileDirConfig = join10(configDir, "profiles", profile, "config.json");
16727
- if (existsSync10(profileDirConfig)) {
16831
+ const profileDirConfig = join12(configDir, "profiles", profile, "config.json");
16832
+ if (existsSync11(profileDirConfig)) {
16728
16833
  try {
16729
16834
  dirConfig = JSON.parse(readFileSync6(profileDirConfig, "utf-8"));
16730
16835
  } catch {}
@@ -16744,8 +16849,8 @@ function loadTokens3(name) {
16744
16849
  name = normalizeConnectorName(name);
16745
16850
  const profile = getCurrentProfile2(name);
16746
16851
  for (const configDir of getConnectorConfigReadDirs2(name)) {
16747
- const tokensFile = join10(configDir, "profiles", profile, "tokens.json");
16748
- if (existsSync10(tokensFile)) {
16852
+ const tokensFile = join12(configDir, "profiles", profile, "tokens.json");
16853
+ if (existsSync11(tokensFile)) {
16749
16854
  try {
16750
16855
  return JSON.parse(readFileSync6(tokensFile, "utf-8"));
16751
16856
  } catch {
@@ -16773,8 +16878,8 @@ function getEnvVars(name) {
16773
16878
  function getOAuthConfig(name) {
16774
16879
  name = normalizeConnectorName(name);
16775
16880
  for (const configDir of getConnectorConfigReadDirs2(name)) {
16776
- const credentialsFile = join10(configDir, "credentials.json");
16777
- if (existsSync10(credentialsFile)) {
16881
+ const credentialsFile = join12(configDir, "credentials.json");
16882
+ if (existsSync11(credentialsFile)) {
16778
16883
  try {
16779
16884
  const creds = JSON.parse(readFileSync6(credentialsFile, "utf-8"));
16780
16885
  return { clientId: creds.clientId, clientSecret: creds.clientSecret };
@@ -16791,11 +16896,11 @@ function getOAuthConfig(name) {
16791
16896
  // src/lib/runner.ts
16792
16897
  var __dirname5 = dirname6(fileURLToPath5(import.meta.url));
16793
16898
  function resolveConnectorsDir2() {
16794
- const fromBin = join11(__dirname5, "..", "connectors");
16795
- if (existsSync11(fromBin))
16899
+ const fromBin = join13(__dirname5, "..", "connectors");
16900
+ if (existsSync12(fromBin))
16796
16901
  return fromBin;
16797
- const fromSrc = join11(__dirname5, "..", "..", "connectors");
16798
- if (existsSync11(fromSrc))
16902
+ const fromSrc = join13(__dirname5, "..", "..", "connectors");
16903
+ if (existsSync12(fromSrc))
16799
16904
  return fromSrc;
16800
16905
  return fromBin;
16801
16906
  }
@@ -16871,8 +16976,8 @@ function buildEnvWithCredentials(connectorName, baseEnv) {
16871
16976
  function getConnectorCliPath(name) {
16872
16977
  const safeName = normalizeConnectorName(name).replace(/[^a-z0-9-]/g, "");
16873
16978
  const connectorDir = getConnectorPackagePath(CONNECTORS_DIR2, safeName);
16874
- const cliPath = join11(connectorDir, "src", "cli", "index.ts");
16875
- if (existsSync11(cliPath))
16979
+ const cliPath = join13(connectorDir, "src", "cli", "index.ts");
16980
+ if (existsSync12(cliPath))
16876
16981
  return cliPath;
16877
16982
  return null;
16878
16983
  }
@@ -17066,7 +17171,7 @@ function runLegacyConnectorCommand(name, args, timeoutMs = 30000) {
17066
17171
  success: false
17067
17172
  });
17068
17173
  }
17069
- return new Promise((resolve) => {
17174
+ return new Promise((resolve2) => {
17070
17175
  const proc = spawn("bun", ["run", cliPath, ...args], {
17071
17176
  timeout: timeoutMs,
17072
17177
  env: buildEnvWithCredentials(connectorName, process.env),
@@ -17081,7 +17186,7 @@ function runLegacyConnectorCommand(name, args, timeoutMs = 30000) {
17081
17186
  stderr += data.toString();
17082
17187
  });
17083
17188
  proc.on("close", (code) => {
17084
- resolve({
17189
+ resolve2({
17085
17190
  stdout: stdout.trim(),
17086
17191
  stderr: stderr.trim(),
17087
17192
  exitCode: code ?? 1,
@@ -17089,7 +17194,7 @@ function runLegacyConnectorCommand(name, args, timeoutMs = 30000) {
17089
17194
  });
17090
17195
  });
17091
17196
  proc.on("error", (err) => {
17092
- resolve({
17197
+ resolve2({
17093
17198
  stdout: "",
17094
17199
  stderr: err.message,
17095
17200
  exitCode: 1,