@dataflint/mcp-server 1.0.17 → 1.0.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 (55) hide show
  1. package/dist/auth/auth0-service.d.ts.map +1 -1
  2. package/dist/auth/auth0-service.js +27 -13
  3. package/dist/auth/auth0-service.js.map +1 -1
  4. package/dist/auth/errors.d.ts +86 -0
  5. package/dist/auth/errors.d.ts.map +1 -0
  6. package/dist/auth/errors.js +144 -0
  7. package/dist/auth/errors.js.map +1 -0
  8. package/dist/auth/index.d.ts +1 -0
  9. package/dist/auth/index.d.ts.map +1 -1
  10. package/dist/auth/index.js +10 -1
  11. package/dist/auth/index.js.map +1 -1
  12. package/dist/dataflint-server-service.d.ts +12 -4
  13. package/dist/dataflint-server-service.d.ts.map +1 -1
  14. package/dist/dataflint-server-service.js +219 -63
  15. package/dist/dataflint-server-service.js.map +1 -1
  16. package/dist/errors.d.ts +55 -0
  17. package/dist/errors.d.ts.map +1 -0
  18. package/dist/errors.js +185 -0
  19. package/dist/errors.js.map +1 -0
  20. package/dist/index.d.ts +3 -1
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +21 -5
  23. package/dist/index.js.map +1 -1
  24. package/dist/request-context.d.ts +20 -0
  25. package/dist/request-context.d.ts.map +1 -1
  26. package/dist/request-context.js +31 -1
  27. package/dist/request-context.js.map +1 -1
  28. package/dist/server.d.ts +2 -2
  29. package/dist/server.d.ts.map +1 -1
  30. package/dist/server.js +16 -14
  31. package/dist/server.js.map +1 -1
  32. package/dist/standalone/config.d.ts +13 -7
  33. package/dist/standalone/config.d.ts.map +1 -1
  34. package/dist/standalone/config.js +361 -81
  35. package/dist/standalone/config.js.map +4 -4
  36. package/dist/standalone/server.d.ts.map +1 -1
  37. package/dist/standalone/server.js +45 -25
  38. package/dist/standalone/server.js.map +1 -1
  39. package/dist/standalone/stdio-transport.d.ts +2 -1
  40. package/dist/standalone/stdio-transport.d.ts.map +1 -1
  41. package/dist/standalone/stdio-transport.js +3 -4
  42. package/dist/standalone/stdio-transport.js.map +1 -1
  43. package/dist/test-helpers.d.ts +27 -0
  44. package/dist/test-helpers.d.ts.map +1 -0
  45. package/dist/test-helpers.js +101 -0
  46. package/dist/test-helpers.js.map +1 -0
  47. package/dist/types.d.ts +5 -13
  48. package/dist/types.d.ts.map +1 -1
  49. package/dist/types.js +5 -0
  50. package/dist/types.js.map +1 -1
  51. package/package.json +1 -1
  52. package/dist/auth.d.ts +0 -47
  53. package/dist/auth.d.ts.map +0 -1
  54. package/dist/auth.js +0 -302
  55. package/dist/auth.js.map +0 -1
@@ -75,6 +75,127 @@ var require_types = __commonJS({
75
75
  }
76
76
  });
77
77
 
78
+ // dist/auth/errors.js
79
+ var require_errors = __commonJS({
80
+ "dist/auth/errors.js"(exports2) {
81
+ "use strict";
82
+ Object.defineProperty(exports2, "__esModule", { value: true });
83
+ exports2.NetworkError = exports2.ConfigError = exports2.AuthError = exports2.DataFlintError = exports2.ErrorCode = void 0;
84
+ var ErrorCode;
85
+ (function(ErrorCode2) {
86
+ ErrorCode2["AUTH_NOT_INITIALIZED"] = "AUTH_NOT_INITIALIZED";
87
+ ErrorCode2["AUTH_TOKEN_EXPIRED"] = "AUTH_TOKEN_EXPIRED";
88
+ ErrorCode2["AUTH_TOKEN_INVALID"] = "AUTH_TOKEN_INVALID";
89
+ ErrorCode2["AUTH_REFRESH_FAILED"] = "AUTH_REFRESH_FAILED";
90
+ ErrorCode2["AUTH_LOGIN_REQUIRED"] = "AUTH_LOGIN_REQUIRED";
91
+ ErrorCode2["AUTH_TIMEOUT"] = "AUTH_TIMEOUT";
92
+ ErrorCode2["CONFIG_MISSING"] = "CONFIG_MISSING";
93
+ ErrorCode2["CONFIG_INVALID"] = "CONFIG_INVALID";
94
+ ErrorCode2["CONFIG_DOMAIN_NOT_FOUND"] = "CONFIG_DOMAIN_NOT_FOUND";
95
+ ErrorCode2["NETWORK_UNAVAILABLE"] = "NETWORK_UNAVAILABLE";
96
+ ErrorCode2["NETWORK_TIMEOUT"] = "NETWORK_TIMEOUT";
97
+ ErrorCode2["NETWORK_DNS_FAILED"] = "NETWORK_DNS_FAILED";
98
+ ErrorCode2["API_UNAUTHORIZED"] = "API_UNAUTHORIZED";
99
+ ErrorCode2["API_FORBIDDEN"] = "API_FORBIDDEN";
100
+ ErrorCode2["API_NOT_FOUND"] = "API_NOT_FOUND";
101
+ ErrorCode2["API_RATE_LIMITED"] = "API_RATE_LIMITED";
102
+ ErrorCode2["API_SERVER_ERROR"] = "API_SERVER_ERROR";
103
+ ErrorCode2["API_BAD_REQUEST"] = "API_BAD_REQUEST";
104
+ ErrorCode2["SERVICE_NOT_STARTED"] = "SERVICE_NOT_STARTED";
105
+ ErrorCode2["SERVICE_UNAVAILABLE"] = "SERVICE_UNAVAILABLE";
106
+ ErrorCode2["UNKNOWN"] = "UNKNOWN";
107
+ })(ErrorCode || (exports2.ErrorCode = ErrorCode = {}));
108
+ var DataFlintError = class extends Error {
109
+ cause;
110
+ constructor(message, cause) {
111
+ super(message);
112
+ this.cause = cause;
113
+ this.name = this.constructor.name;
114
+ if (Error.captureStackTrace) {
115
+ Error.captureStackTrace(this, this.constructor);
116
+ }
117
+ }
118
+ /**
119
+ * Get a user-friendly error message with action
120
+ */
121
+ getUserMessage() {
122
+ return `${this.message}. ${this.userAction}`;
123
+ }
124
+ };
125
+ exports2.DataFlintError = DataFlintError;
126
+ var AuthError = class _AuthError extends DataFlintError {
127
+ code;
128
+ isRetryable;
129
+ userAction;
130
+ constructor(code, message, userAction, isRetryable = false, cause) {
131
+ super(message, cause);
132
+ this.code = code;
133
+ this.isRetryable = isRetryable;
134
+ this.userAction = userAction;
135
+ }
136
+ static tokenExpired(cause) {
137
+ return new _AuthError(ErrorCode.AUTH_TOKEN_EXPIRED, "Your session has expired", 'Please click "Login" to authenticate again.', false, cause);
138
+ }
139
+ static tokenInvalid(cause) {
140
+ return new _AuthError(ErrorCode.AUTH_TOKEN_INVALID, "Authentication token is invalid", 'Please click "Login" to authenticate again.', false, cause);
141
+ }
142
+ static refreshFailed(cause) {
143
+ return new _AuthError(ErrorCode.AUTH_REFRESH_FAILED, "Failed to refresh authentication", 'Please click "Login" to authenticate again.', false, cause);
144
+ }
145
+ static loginRequired() {
146
+ return new _AuthError(ErrorCode.AUTH_LOGIN_REQUIRED, "Authentication required", 'Please run "DataFlint: Login" from the command palette.', false);
147
+ }
148
+ static timeout(cause) {
149
+ return new _AuthError(ErrorCode.AUTH_TIMEOUT, "Authentication timed out", "Please check your internet connection and try again.", true, cause);
150
+ }
151
+ static notInitialized() {
152
+ return new _AuthError(ErrorCode.AUTH_NOT_INITIALIZED, "Authentication service not initialized", 'Please run "DataFlint: Restart Server" to reinitialize.', true);
153
+ }
154
+ };
155
+ exports2.AuthError = AuthError;
156
+ var ConfigError = class _ConfigError extends DataFlintError {
157
+ code;
158
+ isRetryable = false;
159
+ userAction;
160
+ constructor(code, message, userAction, cause) {
161
+ super(message, cause);
162
+ this.code = code;
163
+ this.userAction = userAction;
164
+ }
165
+ static missing(field) {
166
+ return new _ConfigError(ErrorCode.CONFIG_MISSING, `Missing required configuration: ${field}`, 'Please check your DataFlint settings. Run "DataFlint: Show Debug Information" for details.');
167
+ }
168
+ static invalid(field, value, expected) {
169
+ return new _ConfigError(ErrorCode.CONFIG_INVALID, `Invalid configuration for ${field}: "${value}"`, `Expected ${expected}. Please check your DataFlint settings.`);
170
+ }
171
+ static customerDomainNotFound(domain) {
172
+ return new _ConfigError(ErrorCode.CONFIG_DOMAIN_NOT_FOUND, `Customer domain "${domain}" is not configured`, "Please contact support to set up your organization's domain, or remove the customer domain setting.");
173
+ }
174
+ };
175
+ exports2.ConfigError = ConfigError;
176
+ var NetworkError = class _NetworkError extends DataFlintError {
177
+ code;
178
+ isRetryable = true;
179
+ userAction;
180
+ constructor(code, message, userAction, cause) {
181
+ super(message, cause);
182
+ this.code = code;
183
+ this.userAction = userAction;
184
+ }
185
+ static unavailable(cause) {
186
+ return new _NetworkError(ErrorCode.NETWORK_UNAVAILABLE, "Cannot connect to server", "Please check your internet connection and try again.", cause);
187
+ }
188
+ static timeout(cause) {
189
+ return new _NetworkError(ErrorCode.NETWORK_TIMEOUT, "Request timed out", "The server took too long to respond. Please check your connection and try again.", cause);
190
+ }
191
+ static dnsFailed(host, cause) {
192
+ return new _NetworkError(ErrorCode.NETWORK_DNS_FAILED, `Cannot resolve hostname: ${host}`, "Please check your internet connection and DNS settings.", cause);
193
+ }
194
+ };
195
+ exports2.NetworkError = NetworkError;
196
+ }
197
+ });
198
+
78
199
  // dist/auth/auth0-service.js
79
200
  var require_auth0_service = __commonJS({
80
201
  "dist/auth/auth0-service.js"(exports2) {
@@ -121,6 +242,7 @@ var require_auth0_service = __commonJS({
121
242
  var http = __importStar2(require("http"));
122
243
  var openid_client_1 = require("openid-client");
123
244
  var url_1 = require("url");
245
+ var errors_1 = require_errors();
124
246
  var AUTH_DISCOVERY_TIMEOUT_MS = 1e4;
125
247
  openid_client_1.custom.setHttpOptionsDefaults({
126
248
  timeout: AUTH_DISCOVERY_TIMEOUT_MS
@@ -184,13 +306,21 @@ var require_auth0_service = __commonJS({
184
306
  this.logger.error(`Client ID: ${this.config.clientId}`);
185
307
  this.logger.error(`Constructed issuer URL: ${this.config.domain.startsWith("http") ? this.config.domain : `https://${this.config.domain}`}`);
186
308
  if (error instanceof Error) {
187
- if (error.message.includes("404") || error.message.includes("Not Found")) {
188
- throw new Error(`Auth0 domain '${this.config.domain}' not found. Please verify your Auth0 domain configuration. The discovery endpoint ${this.config.domain} returned 404.`);
189
- } else if (error.message.includes("ENOTFOUND") || error.message.includes("getaddrinfo")) {
190
- throw new Error(`Cannot connect to Auth0 domain '${this.config.domain}'. Please check your internet connection and verify the domain is correct.`);
309
+ const message = error.message.toLowerCase();
310
+ if (message.includes("404") || message.includes("not found")) {
311
+ throw errors_1.ConfigError.invalid("Auth0 domain", this.config.domain, "a valid Auth0 domain (e.g., your-tenant.auth0.com)");
312
+ }
313
+ if (message.includes("enotfound") || message.includes("getaddrinfo")) {
314
+ throw errors_1.NetworkError.dnsFailed(this.config.domain, error);
315
+ }
316
+ if (message.includes("timeout") || message.includes("etimedout")) {
317
+ throw errors_1.AuthError.timeout(error);
318
+ }
319
+ if (message.includes("econnrefused") || message.includes("econnreset")) {
320
+ throw errors_1.NetworkError.unavailable(error);
191
321
  }
192
322
  }
193
- throw new Error(`Auth0 initialization failed: ${error}`);
323
+ throw new errors_1.AuthError("AUTH_NOT_INITIALIZED", `Auth0 initialization failed: ${error instanceof Error ? error.message : String(error)}`, "Please check your internet connection and Auth0 configuration.", false, error instanceof Error ? error : void 0);
194
324
  }
195
325
  }
196
326
  /**
@@ -201,7 +331,7 @@ var require_auth0_service = __commonJS({
201
331
  await this.initialize();
202
332
  }
203
333
  if (!this.client) {
204
- throw new Error("Auth0 client not initialized");
334
+ throw errors_1.AuthError.notInitialized();
205
335
  }
206
336
  const codeVerifier = openid_client_1.generators.codeVerifier();
207
337
  const codeChallenge = openid_client_1.generators.codeChallenge(codeVerifier);
@@ -270,7 +400,7 @@ var require_auth0_service = __commonJS({
270
400
  });
271
401
  setTimeout(() => {
272
402
  server.close();
273
- reject(new Error("Authentication timeout - no response received within 5 minutes"));
403
+ reject(errors_1.AuthError.timeout());
274
404
  }, 3e5);
275
405
  });
276
406
  }
@@ -279,7 +409,7 @@ var require_auth0_service = __commonJS({
279
409
  */
280
410
  async getUserInfo(accessToken) {
281
411
  if (!this.client) {
282
- throw new Error("Auth0 client not initialized");
412
+ throw errors_1.AuthError.notInitialized();
283
413
  }
284
414
  try {
285
415
  this.logger.info("Fetching user information...");
@@ -297,7 +427,7 @@ var require_auth0_service = __commonJS({
297
427
  */
298
428
  async refreshToken(refreshToken) {
299
429
  if (!this.client) {
300
- throw new Error("Auth0 client not initialized");
430
+ throw errors_1.AuthError.notInitialized();
301
431
  }
302
432
  try {
303
433
  this.logger.info("Refreshing access token...");
@@ -354,7 +484,7 @@ var require_auth0_service = __commonJS({
354
484
  */
355
485
  async logout(accessToken) {
356
486
  if (!this.client) {
357
- throw new Error("Auth0 client not initialized");
487
+ throw errors_1.AuthError.notInitialized();
358
488
  }
359
489
  try {
360
490
  await this.client.revoke(accessToken);
@@ -374,7 +504,7 @@ var require_auth0_m2m_service = __commonJS({
374
504
  "use strict";
375
505
  Object.defineProperty(exports2, "__esModule", { value: true });
376
506
  exports2.Auth0M2MService = void 0;
377
- var types_1 = require_types();
507
+ var types_12 = require_types();
378
508
  var noopLogger = {
379
509
  info: () => {
380
510
  },
@@ -407,7 +537,7 @@ var require_auth0_m2m_service = __commonJS({
407
537
  * Get the strategy type identifier
408
538
  */
409
539
  getType() {
410
- return types_1.AuthStrategyType.AUTH0_M2M;
540
+ return types_12.AuthStrategyType.AUTH0_M2M;
411
541
  }
412
542
  /**
413
543
  * Initialize the M2M service
@@ -578,7 +708,7 @@ var require_service_account_service = __commonJS({
578
708
  Object.defineProperty(exports2, "__esModule", { value: true });
579
709
  exports2.ServiceAccountService = void 0;
580
710
  var fs2 = __importStar2(require("fs"));
581
- var types_1 = require_types();
711
+ var types_12 = require_types();
582
712
  var noopLogger = {
583
713
  info: () => {
584
714
  },
@@ -603,7 +733,7 @@ var require_service_account_service = __commonJS({
603
733
  * Get the strategy type identifier
604
734
  */
605
735
  getType() {
606
- return types_1.AuthStrategyType.SERVICE_ACCOUNT;
736
+ return types_12.AuthStrategyType.SERVICE_ACCOUNT;
607
737
  }
608
738
  /**
609
739
  * Initialize the service account strategy
@@ -1071,7 +1201,7 @@ var require_auth_strategy_factory = __commonJS({
1071
1201
  "use strict";
1072
1202
  Object.defineProperty(exports2, "__esModule", { value: true });
1073
1203
  exports2.AuthStrategyFactory = void 0;
1074
- var types_1 = require_types();
1204
+ var types_12 = require_types();
1075
1205
  var service_account_service_1 = require_service_account_service();
1076
1206
  var auth0_m2m_service_1 = require_auth0_m2m_service();
1077
1207
  var secrets_1 = require_secrets();
@@ -1095,15 +1225,15 @@ var require_auth_strategy_factory = __commonJS({
1095
1225
  async createStrategy() {
1096
1226
  const m2mMode = this.configProvider.getM2MMode();
1097
1227
  switch (m2mMode.type) {
1098
- case types_1.M2MType.SERVICE_ACCOUNT:
1228
+ case types_12.M2MType.SERVICE_ACCOUNT:
1099
1229
  return this.buildServiceAccountStrategy(m2mMode);
1100
- case types_1.M2MType.AUTH0_M2M:
1230
+ case types_12.M2MType.AUTH0_M2M:
1101
1231
  return await this.buildAuth0M2MStrategy(m2mMode);
1102
1232
  default:
1103
1233
  this.logger.info("Using interactive OAuth flow");
1104
1234
  return {
1105
1235
  strategy: null,
1106
- strategyType: types_1.AuthStrategyType.AUTH0_USER
1236
+ strategyType: types_12.AuthStrategyType.AUTH0_USER
1107
1237
  };
1108
1238
  }
1109
1239
  }
@@ -1111,7 +1241,7 @@ var require_auth_strategy_factory = __commonJS({
1111
1241
  this.logger.info(`Service Account mode: ${mode.tokenPath}`);
1112
1242
  return {
1113
1243
  strategy: new service_account_service_1.ServiceAccountService(mode.tokenPath, mode.tenantId, this.logger),
1114
- strategyType: types_1.AuthStrategyType.SERVICE_ACCOUNT
1244
+ strategyType: types_12.AuthStrategyType.SERVICE_ACCOUNT
1115
1245
  };
1116
1246
  }
1117
1247
  async buildAuth0M2MStrategy(mode) {
@@ -1126,15 +1256,15 @@ var require_auth_strategy_factory = __commonJS({
1126
1256
  this.logger.info(`Auth0 M2M mode: ${mode.secretName}`);
1127
1257
  return {
1128
1258
  strategy: new auth0_m2m_service_1.Auth0M2MService(credentials, mode.tenantId, this.logger),
1129
- strategyType: types_1.AuthStrategyType.AUTH0_M2M
1259
+ strategyType: types_12.AuthStrategyType.AUTH0_M2M
1130
1260
  };
1131
1261
  }
1132
1262
  async isM2MAvailable() {
1133
1263
  const mode = this.configProvider.getM2MMode();
1134
- if (mode.type === types_1.M2MType.SERVICE_ACCOUNT) {
1264
+ if (mode.type === types_12.M2MType.SERVICE_ACCOUNT) {
1135
1265
  return true;
1136
1266
  }
1137
- if (mode.type === types_1.M2MType.AUTH0_M2M) {
1267
+ if (mode.type === types_12.M2MType.AUTH0_M2M) {
1138
1268
  const secretsProvider = new secrets_1.SecretsProvider(this.configProvider.getEnvironment(), this.logger);
1139
1269
  return secretsProvider.isAvailable();
1140
1270
  }
@@ -1187,7 +1317,7 @@ var require_auth = __commonJS({
1187
1317
  };
1188
1318
  })();
1189
1319
  Object.defineProperty(exports2, "__esModule", { value: true });
1190
- exports2.SecretsProvider = exports2.LocalFileSecretsProvider = exports2.AWSSecretsProvider = exports2.AuthStrategyFactory = exports2.ServiceAccountService = exports2.Auth0M2MService = exports2.Auth0Service = exports2.M2MType = exports2.AuthStrategyType = exports2.customerAuthConfigs = void 0;
1320
+ exports2.NetworkError = exports2.ConfigError = exports2.AuthError = exports2.DataFlintError = exports2.ErrorCode = exports2.SecretsProvider = exports2.LocalFileSecretsProvider = exports2.AWSSecretsProvider = exports2.AuthStrategyFactory = exports2.ServiceAccountService = exports2.Auth0M2MService = exports2.Auth0Service = exports2.M2MType = exports2.AuthStrategyType = exports2.customerAuthConfigs = void 0;
1191
1321
  exports2.getCustomerAuthConfig = getCustomerAuthConfig;
1192
1322
  var crypto2 = __importStar2(require("node:crypto"));
1193
1323
  var customer_auth_configs_1 = require_customer_auth_configs();
@@ -1212,12 +1342,12 @@ var require_auth = __commonJS({
1212
1342
  serverUrl: `https://api.${customerDomain}.dataflint.io`
1213
1343
  };
1214
1344
  }
1215
- var types_1 = require_types();
1345
+ var types_12 = require_types();
1216
1346
  Object.defineProperty(exports2, "AuthStrategyType", { enumerable: true, get: function() {
1217
- return types_1.AuthStrategyType;
1347
+ return types_12.AuthStrategyType;
1218
1348
  } });
1219
1349
  Object.defineProperty(exports2, "M2MType", { enumerable: true, get: function() {
1220
- return types_1.M2MType;
1350
+ return types_12.M2MType;
1221
1351
  } });
1222
1352
  var auth0_service_1 = require_auth0_service();
1223
1353
  Object.defineProperty(exports2, "Auth0Service", { enumerable: true, get: function() {
@@ -1245,6 +1375,64 @@ var require_auth = __commonJS({
1245
1375
  Object.defineProperty(exports2, "SecretsProvider", { enumerable: true, get: function() {
1246
1376
  return secrets_1.SecretsProvider;
1247
1377
  } });
1378
+ var errors_1 = require_errors();
1379
+ Object.defineProperty(exports2, "ErrorCode", { enumerable: true, get: function() {
1380
+ return errors_1.ErrorCode;
1381
+ } });
1382
+ Object.defineProperty(exports2, "DataFlintError", { enumerable: true, get: function() {
1383
+ return errors_1.DataFlintError;
1384
+ } });
1385
+ Object.defineProperty(exports2, "AuthError", { enumerable: true, get: function() {
1386
+ return errors_1.AuthError;
1387
+ } });
1388
+ Object.defineProperty(exports2, "ConfigError", { enumerable: true, get: function() {
1389
+ return errors_1.ConfigError;
1390
+ } });
1391
+ Object.defineProperty(exports2, "NetworkError", { enumerable: true, get: function() {
1392
+ return errors_1.NetworkError;
1393
+ } });
1394
+ }
1395
+ });
1396
+
1397
+ // dist/types.js
1398
+ var require_types2 = __commonJS({
1399
+ "dist/types.js"(exports2) {
1400
+ "use strict";
1401
+ Object.defineProperty(exports2, "__esModule", { value: true });
1402
+ exports2.M2MType = exports2.AuthStrategyType = void 0;
1403
+ var index_12 = require_auth();
1404
+ Object.defineProperty(exports2, "AuthStrategyType", { enumerable: true, get: function() {
1405
+ return index_12.AuthStrategyType;
1406
+ } });
1407
+ Object.defineProperty(exports2, "M2MType", { enumerable: true, get: function() {
1408
+ return index_12.M2MType;
1409
+ } });
1410
+ }
1411
+ });
1412
+
1413
+ // dist/logger.js
1414
+ var require_logger = __commonJS({
1415
+ "dist/logger.js"(exports2) {
1416
+ "use strict";
1417
+ Object.defineProperty(exports2, "__esModule", { value: true });
1418
+ exports2.Logger = void 0;
1419
+ var LOGGER_KEY = "__dataflint_mcp_logger__";
1420
+ var Logger = class {
1421
+ static setInstance(logger) {
1422
+ globalThis[LOGGER_KEY] = logger;
1423
+ }
1424
+ static getInstance() {
1425
+ const instance = globalThis[LOGGER_KEY];
1426
+ if (!instance) {
1427
+ throw new Error("Logger not initialized. Call Logger.setInstance() first.");
1428
+ }
1429
+ return instance;
1430
+ }
1431
+ static clear() {
1432
+ globalThis[LOGGER_KEY] = void 0;
1433
+ }
1434
+ };
1435
+ exports2.Logger = Logger;
1248
1436
  }
1249
1437
  });
1250
1438
 
@@ -1288,28 +1476,96 @@ var __importStar = exports && exports.__importStar || /* @__PURE__ */ (function(
1288
1476
  })();
1289
1477
  Object.defineProperty(exports, "__esModule", { value: true });
1290
1478
  exports.StandaloneConfigService = void 0;
1291
- var fs = __importStar(require("fs"));
1292
- var path = __importStar(require("path"));
1293
- var os = __importStar(require("os"));
1294
- var crypto = __importStar(require("crypto"));
1295
- var index_js_1 = require_auth();
1479
+ var fs = __importStar(require("node:fs"));
1480
+ var fsPromises = __importStar(require("node:fs/promises"));
1481
+ var path = __importStar(require("node:path"));
1482
+ var os = __importStar(require("node:os"));
1483
+ var crypto = __importStar(require("node:crypto"));
1484
+ var zod_1 = require("zod");
1485
+ var types_1 = require_types2();
1486
+ var index_1 = require_auth();
1487
+ var logger_1 = require_logger();
1488
+ var DEFAULT_CLIENT_ID_FOR_HASH = "default";
1489
+ var HASH_PREFIX_LENGTH = 8;
1490
+ var DEFAULT_ADMIN_COMPANY_DOMAIN = "none";
1491
+ var DEFAULT_SERVER_URL = "https://api.dataflint.io";
1492
+ var DEFAULT_AUTH_DOMAIN = "https://dataflint.us.auth0.com/";
1493
+ var DEFAULT_AUDIENCE = "https://api.dataflint.io";
1494
+ var DEFAULT_SCOPE = "openid profile email offline_access";
1495
+ var DEFAULT_PUBLIC_CLIENT_ID = "1NdbhkYoLyqQWtevBNal1BozB9pSZe3g";
1496
+ var CREDENTIALS_DIR_MODE = 448;
1497
+ var CREDENTIALS_FILE_MODE = 384;
1498
+ var StandaloneConfigSchema = zod_1.z.object({
1499
+ serverUrl: zod_1.z.string().url().optional(),
1500
+ authDomain: zod_1.z.string().optional(),
1501
+ clientId: zod_1.z.string().optional(),
1502
+ audience: zod_1.z.string().optional(),
1503
+ scope: zod_1.z.string().optional(),
1504
+ credentialsPath: zod_1.z.string().optional(),
1505
+ adminCompanyDomain: zod_1.z.string().optional(),
1506
+ customerDomain: zod_1.z.string().optional(),
1507
+ m2mTokenPath: zod_1.z.string().optional(),
1508
+ m2mSecretName: zod_1.z.string().optional(),
1509
+ tenantId: zod_1.z.string().optional()
1510
+ }).strict();
1296
1511
  var StandaloneConfigService = class {
1297
1512
  config;
1298
1513
  credentialsPath;
1514
+ m2mMode;
1299
1515
  constructor(config = {}) {
1300
1516
  this.config = this.mergeWithDefaults(config);
1301
- if (config.credentialsPath) {
1302
- this.credentialsPath = config.credentialsPath;
1303
- } else {
1304
- const clientIdHash = crypto.createHash("sha256").update(this.config.clientId).digest("hex").substring(0, 8);
1305
- this.credentialsPath = path.join(os.homedir(), ".dataflint", `credentials-${clientIdHash}.json`);
1306
- }
1517
+ this.m2mMode = this.detectM2MMode();
1518
+ this.validateM2MConfig();
1519
+ this.credentialsPath = config.credentialsPath || this.defaultCredentialsPath();
1307
1520
  this.ensureDataflintDirectory();
1308
1521
  }
1522
+ defaultCredentialsPath() {
1523
+ const hash = crypto.createHash("sha256").update(this.config.clientId || DEFAULT_CLIENT_ID_FOR_HASH).digest("hex").substring(0, HASH_PREFIX_LENGTH);
1524
+ return path.join(os.homedir(), ".dataflint", `credentials-${hash}.json`);
1525
+ }
1309
1526
  ensureDataflintDirectory() {
1310
- const dataflintDir = path.dirname(this.credentialsPath);
1311
- if (!fs.existsSync(dataflintDir)) {
1312
- fs.mkdirSync(dataflintDir, { recursive: true, mode: 448 });
1527
+ const dir = path.dirname(this.credentialsPath);
1528
+ if (!fs.existsSync(dir)) {
1529
+ fs.mkdirSync(dir, { recursive: true, mode: CREDENTIALS_DIR_MODE });
1530
+ }
1531
+ }
1532
+ detectM2MMode() {
1533
+ const tokenPath = this.config.m2mTokenPath;
1534
+ const secretName = this.config.m2mSecretName;
1535
+ const tenantId = this.config.tenantId;
1536
+ const logger = logger_1.Logger.getInstance();
1537
+ if (tokenPath) {
1538
+ logger.info("M2M mode: Service Account");
1539
+ return { type: types_1.M2MType.SERVICE_ACCOUNT, tokenPath, tenantId };
1540
+ }
1541
+ if (secretName) {
1542
+ logger.info("M2M mode: Auth0 M2M");
1543
+ return { type: types_1.M2MType.AUTH0_M2M, secretName, tenantId };
1544
+ }
1545
+ return { type: types_1.M2MType.NONE };
1546
+ }
1547
+ validateM2MConfig() {
1548
+ if (this.m2mMode.type !== types_1.M2MType.NONE && !this.config.serverUrl) {
1549
+ throw new Error("DATAFLINT_SERVER_URL is required in M2M mode");
1550
+ }
1551
+ }
1552
+ loadFileConfig() {
1553
+ const configFilePath = path.join(os.homedir(), ".dataflint", "config.json");
1554
+ if (!fs.existsSync(configFilePath)) {
1555
+ return {};
1556
+ }
1557
+ const logger = logger_1.Logger.getInstance();
1558
+ try {
1559
+ const rawContent = JSON.parse(fs.readFileSync(configFilePath, "utf8"));
1560
+ const result = StandaloneConfigSchema.safeParse(rawContent);
1561
+ if (!result.success) {
1562
+ logger.warn(`Invalid config file format at ${configFilePath}: ${result.error.issues.map((i) => i.message).join(", ")}`);
1563
+ return {};
1564
+ }
1565
+ return result.data;
1566
+ } catch (error) {
1567
+ logger.warn(`Failed to parse config file at ${configFilePath}: ${error instanceof Error ? error.message : String(error)}`);
1568
+ return {};
1313
1569
  }
1314
1570
  }
1315
1571
  mergeWithDefaults(config) {
@@ -1320,105 +1576,129 @@ var StandaloneConfigService = class {
1320
1576
  audience: process.env.DATAFLINT_AUDIENCE,
1321
1577
  scope: process.env.DATAFLINT_SCOPE,
1322
1578
  adminCompanyDomain: process.env.DATAFLINT_ADMIN_COMPANY_DOMAIN,
1323
- customerDomain: process.env.DATAFLINT_CUSTOMER_DOMAIN
1579
+ customerDomain: process.env.DATAFLINT_CUSTOMER_DOMAIN,
1580
+ m2mTokenPath: process.env.M2M_SA_TOKEN_PATH,
1581
+ m2mSecretName: process.env.M2M_AUTH0_SECRET_NAME,
1582
+ tenantId: process.env.TENANT_ID
1324
1583
  };
1325
- const configFilePath = path.join(os.homedir(), ".dataflint", "config.json");
1326
- let fileConfig = {};
1327
- if (fs.existsSync(configFilePath)) {
1328
- try {
1329
- const fileContent = fs.readFileSync(configFilePath, "utf8");
1330
- fileConfig = JSON.parse(fileContent);
1331
- } catch (error) {
1332
- }
1333
- }
1584
+ const fileConfig = this.loadFileConfig();
1585
+ const logger = logger_1.Logger.getInstance();
1334
1586
  const customerDomain = config.customerDomain || envConfig.customerDomain || fileConfig.customerDomain;
1335
1587
  if (customerDomain) {
1336
- console.error(`[CONFIG] Customer domain detected: ${customerDomain}`);
1337
- const customerConfig = (0, index_js_1.getCustomerAuthConfig)(customerDomain);
1588
+ logger.info(`Customer domain detected: ${customerDomain}`);
1589
+ const customerConfig = (0, index_1.getCustomerAuthConfig)(customerDomain);
1338
1590
  if (!customerConfig) {
1339
- console.error(`[CONFIG] ERROR: Unknown customer domain: ${customerDomain}`);
1591
+ logger.error(`Unknown customer domain: ${customerDomain}`);
1340
1592
  throw new Error(`Unknown customer domain: "${customerDomain}". This customer is not registered in the system. Please check the domain name or contact support.`);
1341
1593
  }
1342
- console.error(`[CONFIG] Using customer-specific configuration:`);
1343
- console.error(`[CONFIG] - Server URL: ${customerConfig.serverUrl}`);
1344
- console.error(`[CONFIG] - Auth0 Domain: ${customerConfig.domain}`);
1345
- console.error(`[CONFIG] - Client ID: ${customerConfig.clientId.substring(0, 8)}...`);
1594
+ logger.info(`Using customer-specific configuration:`);
1595
+ logger.info(`Server URL: ${customerConfig.serverUrl}`);
1596
+ logger.info(`Auth0 Domain: ${customerConfig.domain}`);
1597
+ logger.info(`Client ID: ${customerConfig.clientId.substring(0, 8)}...`);
1346
1598
  return {
1347
1599
  serverUrl: customerConfig.serverUrl,
1348
1600
  authDomain: customerConfig.domain,
1349
1601
  clientId: customerConfig.clientId,
1350
1602
  audience: customerConfig.audience,
1351
- scope: "openid profile email offline_access",
1603
+ scope: DEFAULT_SCOPE,
1352
1604
  // Credentials path only configurable via CLI argument for security
1353
1605
  credentialsPath: config.credentialsPath,
1354
- adminCompanyDomain: config.adminCompanyDomain || envConfig.adminCompanyDomain || fileConfig.adminCompanyDomain || "none",
1355
- customerDomain
1606
+ adminCompanyDomain: config.adminCompanyDomain || envConfig.adminCompanyDomain || fileConfig.adminCompanyDomain || DEFAULT_ADMIN_COMPANY_DOMAIN,
1607
+ customerDomain,
1608
+ m2mTokenPath: config.m2mTokenPath || envConfig.m2mTokenPath || fileConfig.m2mTokenPath,
1609
+ m2mSecretName: config.m2mSecretName || envConfig.m2mSecretName || fileConfig.m2mSecretName,
1610
+ tenantId: config.tenantId || envConfig.tenantId || fileConfig.tenantId
1356
1611
  };
1357
1612
  }
1358
- console.error(`[CONFIG] No customer domain - using default/explicit configuration`);
1613
+ logger.info(`No customer domain - using default/explicit configuration`);
1359
1614
  return {
1360
- serverUrl: config.serverUrl || envConfig.serverUrl || fileConfig.serverUrl || "https://api.dataflint.io",
1361
- authDomain: config.authDomain || envConfig.authDomain || fileConfig.authDomain || "https://dataflint.us.auth0.com/",
1362
- clientId: config.clientId || envConfig.clientId || fileConfig.clientId || "1NdbhkYoLyqQWtevBNal1BozB9pSZe3g",
1363
- audience: config.audience || envConfig.audience || fileConfig.audience || "https://api.dataflint.io",
1364
- scope: config.scope || envConfig.scope || fileConfig.scope || "openid profile email offline_access",
1365
- adminCompanyDomain: config.adminCompanyDomain || envConfig.adminCompanyDomain || fileConfig.adminCompanyDomain || "none",
1615
+ serverUrl: config.serverUrl || envConfig.serverUrl || fileConfig.serverUrl || DEFAULT_SERVER_URL,
1616
+ authDomain: config.authDomain || envConfig.authDomain || fileConfig.authDomain || DEFAULT_AUTH_DOMAIN,
1617
+ clientId: config.clientId || envConfig.clientId || fileConfig.clientId || DEFAULT_PUBLIC_CLIENT_ID,
1618
+ audience: config.audience || envConfig.audience || fileConfig.audience || DEFAULT_AUDIENCE,
1619
+ scope: config.scope || envConfig.scope || fileConfig.scope || DEFAULT_SCOPE,
1620
+ adminCompanyDomain: config.adminCompanyDomain || envConfig.adminCompanyDomain || fileConfig.adminCompanyDomain || DEFAULT_ADMIN_COMPANY_DOMAIN,
1366
1621
  // Credentials path only configurable via CLI argument for security
1367
1622
  credentialsPath: config.credentialsPath,
1368
- customerDomain: void 0
1623
+ customerDomain: void 0,
1624
+ m2mTokenPath: config.m2mTokenPath || envConfig.m2mTokenPath || fileConfig.m2mTokenPath,
1625
+ m2mSecretName: config.m2mSecretName || envConfig.m2mSecretName || fileConfig.m2mSecretName,
1626
+ tenantId: config.tenantId || envConfig.tenantId || fileConfig.tenantId
1369
1627
  };
1370
1628
  }
1371
1629
  // IConfigService interface implementation
1372
1630
  getServerUrl() {
1631
+ if (!this.config.serverUrl) {
1632
+ throw new Error("Server URL not configured. Set DATAFLINT_SERVER_URL environment variable or configure in ~/.dataflint/config.json");
1633
+ }
1373
1634
  return this.config.serverUrl;
1374
1635
  }
1375
1636
  getEnvironment() {
1376
1637
  return "prod";
1377
1638
  }
1378
1639
  getCustomerDomain() {
1379
- return this.config.customerDomain || null;
1640
+ return this.config.customerDomain ?? null;
1380
1641
  }
1381
1642
  getAdminCompanyDomain() {
1382
- return this.config.adminCompanyDomain || "none";
1643
+ return this.config.adminCompanyDomain ?? DEFAULT_ADMIN_COMPANY_DOMAIN;
1383
1644
  }
1384
1645
  getAuthConfig() {
1646
+ if (!this.config.authDomain) {
1647
+ throw new Error("Auth domain not configured. Set DATAFLINT_AUTH_DOMAIN environment variable or configure in ~/.dataflint/config.json");
1648
+ }
1649
+ if (!this.config.clientId) {
1650
+ throw new Error("Client ID not configured. Set DATAFLINT_CLIENT_ID environment variable or configure in ~/.dataflint/config.json");
1651
+ }
1652
+ if (!this.config.audience) {
1653
+ throw new Error("Audience not configured. Set DATAFLINT_AUDIENCE environment variable or configure in ~/.dataflint/config.json");
1654
+ }
1385
1655
  return {
1386
1656
  domain: this.config.authDomain,
1387
1657
  clientId: this.config.clientId,
1388
1658
  audience: this.config.audience,
1389
- scope: this.config.scope || "openid profile email offline_access"
1659
+ scope: this.config.scope ?? DEFAULT_SCOPE
1390
1660
  };
1391
1661
  }
1392
1662
  async getAuthSecret() {
1393
1663
  try {
1394
- if (fs.existsSync(this.credentialsPath)) {
1395
- const content = fs.readFileSync(this.credentialsPath, "utf8");
1396
- return content;
1397
- }
1398
- return void 0;
1664
+ return await fsPromises.readFile(this.credentialsPath, "utf8");
1399
1665
  } catch (error) {
1666
+ const nodeError = error;
1667
+ if (nodeError.code === "ENOENT") {
1668
+ return void 0;
1669
+ }
1670
+ logger_1.Logger.getInstance().warn(`Failed to read credentials from ${this.credentialsPath}: ${nodeError.message}`);
1400
1671
  return void 0;
1401
1672
  }
1402
1673
  }
1403
1674
  async setAuthSecret(value) {
1404
1675
  this.ensureDataflintDirectory();
1405
- fs.writeFileSync(this.credentialsPath, value, {
1406
- mode: 384,
1676
+ await fsPromises.writeFile(this.credentialsPath, value, {
1677
+ mode: CREDENTIALS_FILE_MODE,
1407
1678
  encoding: "utf8"
1408
1679
  });
1409
1680
  }
1410
1681
  async deleteAuthSecret() {
1411
1682
  try {
1412
- if (fs.existsSync(this.credentialsPath)) {
1413
- fs.unlinkSync(this.credentialsPath);
1414
- }
1683
+ await fsPromises.unlink(this.credentialsPath);
1415
1684
  } catch (error) {
1685
+ const nodeError = error;
1686
+ if (nodeError.code === "ENOENT") {
1687
+ return;
1688
+ }
1689
+ logger_1.Logger.getInstance().warn(`Failed to delete credentials at ${this.credentialsPath}: ${nodeError.message}`);
1416
1690
  }
1417
1691
  }
1418
1692
  getSendSourceCode() {
1419
1693
  const envValue = process.env.DATAFLINT_SEND_SOURCE_CODE;
1420
1694
  return (envValue == null ? void 0 : envValue.toLowerCase()) === "true";
1421
1695
  }
1696
+ getM2MMode() {
1697
+ return this.m2mMode;
1698
+ }
1699
+ getTenantId() {
1700
+ return this.config.tenantId;
1701
+ }
1422
1702
  };
1423
1703
  exports.StandaloneConfigService = StandaloneConfigService;
1424
1704
  //# sourceMappingURL=config.js.map