@flutchai/flutch-sdk 0.2.10 → 0.2.11

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.cjs CHANGED
@@ -2848,8 +2848,8 @@ exports.IdempotencyManager = __decorateClass([
2848
2848
 
2849
2849
  // src/callbacks/smart-callback.router.ts
2850
2850
  exports.SmartCallbackRouter = class SmartCallbackRouter {
2851
- constructor(registry, store, acl, auditor, metrics, rateLimiter, idempotencyManager, patchService) {
2852
- this.registry = registry;
2851
+ constructor(registry2, store, acl, auditor, metrics, rateLimiter, idempotencyManager, patchService) {
2852
+ this.registry = registry2;
2853
2853
  this.store = store;
2854
2854
  this.acl = acl;
2855
2855
  this.auditor = auditor;
@@ -3128,8 +3128,8 @@ var UniversalCallbackService = class {
3128
3128
  };
3129
3129
 
3130
3130
  // src/callbacks/example.callback.ts
3131
- function registerFinanceExampleCallback(registry) {
3132
- registry.register(
3131
+ function registerFinanceExampleCallback(registry2) {
3132
+ registry2.register(
3133
3133
  "example",
3134
3134
  async () => ({
3135
3135
  success: true,
@@ -3654,8 +3654,8 @@ exports.CallbackMetrics = class CallbackMetrics {
3654
3654
  activeCallbacks;
3655
3655
  pendingCallbacks;
3656
3656
  queueSize;
3657
- constructor(registry) {
3658
- this.registry = registry ?? new promClient.Registry();
3657
+ constructor(registry2) {
3658
+ this.registry = registry2 ?? new promClient.Registry();
3659
3659
  promClient.collectDefaultMetrics({ register: this.registry });
3660
3660
  this.callbacksTotal = new promClient.Counter({
3661
3661
  name: "graph_callbacks_total",
@@ -5658,7 +5658,7 @@ exports.UniversalGraphModule = class UniversalGraphModule {
5658
5658
  },
5659
5659
  {
5660
5660
  provide: exports.CallbackMetrics,
5661
- useFactory: (registry) => new exports.CallbackMetrics(registry),
5661
+ useFactory: (registry2) => new exports.CallbackMetrics(registry2),
5662
5662
  inject: ["PROMETHEUS_REGISTRY"]
5663
5663
  },
5664
5664
  {
@@ -5686,8 +5686,8 @@ exports.UniversalGraphModule = class UniversalGraphModule {
5686
5686
  },
5687
5687
  {
5688
5688
  provide: exports.SmartCallbackRouter,
5689
- useFactory: (registry, store, acl, auditor, metrics, rateLimiter, idempotencyManager, patchService) => new exports.SmartCallbackRouter(
5690
- registry,
5689
+ useFactory: (registry2, store, acl, auditor, metrics, rateLimiter, idempotencyManager, patchService) => new exports.SmartCallbackRouter(
5690
+ registry2,
5691
5691
  store,
5692
5692
  acl,
5693
5693
  auditor,
@@ -5719,8 +5719,8 @@ exports.UniversalGraphModule = class UniversalGraphModule {
5719
5719
  },
5720
5720
  {
5721
5721
  provide: "CALLBACK_EXAMPLE_REGISTRATION",
5722
- useFactory: (registry) => {
5723
- registerFinanceExampleCallback(registry);
5722
+ useFactory: (registry2) => {
5723
+ registerFinanceExampleCallback(registry2);
5724
5724
  },
5725
5725
  inject: [CallbackRegistry]
5726
5726
  },
@@ -5783,8 +5783,8 @@ exports.UniversalGraphModule = class UniversalGraphModule {
5783
5783
  },
5784
5784
  {
5785
5785
  provide: "GRAPH_BUILDERS",
5786
- useFactory: (registry) => {
5787
- return registry.getBuilders();
5786
+ useFactory: (registry2) => {
5787
+ return registry2.getBuilders();
5788
5788
  },
5789
5789
  inject: [exports.BuilderRegistryService]
5790
5790
  },
@@ -7330,11 +7330,7 @@ var ALGORITHM = "aes-256-cbc";
7330
7330
  var IV_LENGTH = 16;
7331
7331
  function encryptTokens(tokens, key) {
7332
7332
  const iv = crypto__namespace.randomBytes(IV_LENGTH);
7333
- const cipher = crypto__namespace.createCipheriv(
7334
- ALGORITHM,
7335
- Buffer.from(key),
7336
- iv
7337
- );
7333
+ const cipher = crypto__namespace.createCipheriv(ALGORITHM, Buffer.from(key), iv);
7338
7334
  const json = JSON.stringify(tokens);
7339
7335
  let encrypted = cipher.update(json, "utf8", "hex");
7340
7336
  encrypted += cipher.final("hex");
@@ -7348,11 +7344,7 @@ function decryptTokens(encrypted, key) {
7348
7344
  const ivHex = encrypted.substring(0, separatorIndex);
7349
7345
  const encryptedData = encrypted.substring(separatorIndex + 1);
7350
7346
  const iv = Buffer.from(ivHex, "hex");
7351
- const decipher = crypto__namespace.createDecipheriv(
7352
- ALGORITHM,
7353
- Buffer.from(key),
7354
- iv
7355
- );
7347
+ const decipher = crypto__namespace.createDecipheriv(ALGORITHM, Buffer.from(key), iv);
7356
7348
  let decrypted = decipher.update(encryptedData, "hex", "utf8");
7357
7349
  decrypted += decipher.final("utf8");
7358
7350
  return JSON.parse(decrypted);
@@ -7393,7 +7385,10 @@ var OAuthTokenManager = class {
7393
7385
  this.setCache(config.provider, tokens.accessToken, tokens.expiresAt);
7394
7386
  return tokens.accessToken;
7395
7387
  }
7396
- const refreshed = await this.refreshAccessToken(config, tokens.refreshToken);
7388
+ const refreshed = await this.refreshAccessToken(
7389
+ config,
7390
+ tokens.refreshToken
7391
+ );
7397
7392
  await this.persistTokens(config.provider, refreshed);
7398
7393
  return refreshed.accessToken;
7399
7394
  }
@@ -7457,6 +7452,56 @@ var OAuthTokenManager = class {
7457
7452
  this.cache.set(provider, { token, expiresAt });
7458
7453
  }
7459
7454
  };
7455
+
7456
+ // src/oauth/oauth-provider.registry.ts
7457
+ var registry = {};
7458
+ function loadOAuthProviders(providers) {
7459
+ registry = { ...providers };
7460
+ }
7461
+ function getOAuthProvider(provider) {
7462
+ const def = registry[provider];
7463
+ if (!def) {
7464
+ throw new Error(`Unknown OAuth provider: ${provider}`);
7465
+ }
7466
+ return def;
7467
+ }
7468
+ function getOAuthProviderNames() {
7469
+ return Object.keys(registry);
7470
+ }
7471
+ function resolveOAuthProviderConfig(provider) {
7472
+ const def = getOAuthProvider(provider);
7473
+ const clientId = process.env[def.clientIdEnvVar];
7474
+ const clientSecret = process.env[def.clientSecretEnvVar];
7475
+ if (!clientId) {
7476
+ throw new Error(`Missing env var: ${def.clientIdEnvVar}`);
7477
+ }
7478
+ if (!clientSecret) {
7479
+ throw new Error(`Missing env var: ${def.clientSecretEnvVar}`);
7480
+ }
7481
+ return {
7482
+ provider: def.name,
7483
+ tokenUrl: def.tokenUrl,
7484
+ clientId,
7485
+ clientSecret
7486
+ };
7487
+ }
7488
+ function buildOAuthAuthorizationUrl(provider, params) {
7489
+ const def = getOAuthProvider(provider);
7490
+ const clientId = process.env[def.clientIdEnvVar];
7491
+ if (!clientId) {
7492
+ throw new Error(`Missing env var: ${def.clientIdEnvVar}`);
7493
+ }
7494
+ const query = new URLSearchParams({
7495
+ client_id: clientId,
7496
+ redirect_uri: params.redirectUri,
7497
+ response_type: "code",
7498
+ state: params.state
7499
+ });
7500
+ if (def.scopes.length > 0) {
7501
+ query.set("scope", def.scopes.join(" "));
7502
+ }
7503
+ return `${def.authorizationUrl}?${query.toString()}`;
7504
+ }
7460
7505
  var FileTokenStore = class {
7461
7506
  constructor(filePath) {
7462
7507
  this.filePath = filePath;
@@ -7560,6 +7605,7 @@ exports.WithEndpoints = WithEndpoints;
7560
7605
  exports.WithUIEndpoints = WithUIEndpoints;
7561
7606
  exports._internals = _internals;
7562
7607
  exports.bootstrap = bootstrap;
7608
+ exports.buildOAuthAuthorizationUrl = buildOAuthAuthorizationUrl;
7563
7609
  exports.clearAttachmentDataStore = clearAttachmentDataStore;
7564
7610
  exports.createEndpointDescriptors = createEndpointDescriptors;
7565
7611
  exports.createGraphAttachment = createGraphAttachment;
@@ -7575,12 +7621,16 @@ exports.generateAttachmentSummary = generateAttachmentSummary;
7575
7621
  exports.getAttachmentData = getAttachmentData;
7576
7622
  exports.getCallbackMetadata = getCallbackMetadata;
7577
7623
  exports.getEndpointMetadata = getEndpointMetadata;
7624
+ exports.getOAuthProvider = getOAuthProvider;
7625
+ exports.getOAuthProviderNames = getOAuthProviderNames;
7578
7626
  exports.getUIEndpointClassMetadata = getUIEndpointClassMetadata;
7579
7627
  exports.getUIEndpointMethodsMetadata = getUIEndpointMethodsMetadata;
7580
7628
  exports.hasCallbacks = hasCallbacks;
7581
7629
  exports.hasUIEndpoints = hasUIEndpoints;
7630
+ exports.loadOAuthProviders = loadOAuthProviders;
7582
7631
  exports.registerFinanceExampleCallback = registerFinanceExampleCallback;
7583
7632
  exports.registerUIEndpointsFromClass = registerUIEndpointsFromClass;
7633
+ exports.resolveOAuthProviderConfig = resolveOAuthProviderConfig;
7584
7634
  exports.sanitizeTraceData = sanitizeTraceData;
7585
7635
  exports.storeAttachmentData = storeAttachmentData;
7586
7636
  exports.traceApiCall = traceApiCall;