@mastra/slack 1.6.4-alpha.0 → 1.7.0-alpha.0

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
@@ -37,11 +37,13 @@ var SlackManifestClient = class {
37
37
  #token;
38
38
  #refreshToken;
39
39
  #onTokenRotation;
40
+ #tokenResolver;
40
41
  #rotationPromise = null;
41
42
  constructor(config) {
42
- this.#token = config.token;
43
- this.#refreshToken = config.refreshToken;
43
+ this.#token = config.token ?? "";
44
+ this.#refreshToken = config.refreshToken ?? "";
44
45
  this.#onTokenRotation = config.onTokenRotation;
46
+ this.#tokenResolver = config.tokenResolver;
45
47
  }
46
48
  /**
47
49
  * Get current tokens (after potential rotation).
@@ -66,6 +68,9 @@ var SlackManifestClient = class {
66
68
  *
67
69
  * Concurrent callers share the same in-flight rotation to avoid burning
68
70
  * single-use refresh tokens.
71
+ *
72
+ * When a `tokenResolver` is configured, no rotation happens here — the
73
+ * resolver is asked for a fresh access token instead.
69
74
  */
70
75
  async rotateToken() {
71
76
  if (this.#rotationPromise) return this.#rotationPromise;
@@ -75,6 +80,11 @@ var SlackManifestClient = class {
75
80
  return this.#rotationPromise;
76
81
  }
77
82
  async #doRotateToken() {
83
+ if (this.#tokenResolver) {
84
+ this.#token = await this.#tokenResolver();
85
+ return;
86
+ }
87
+ if (!this.#refreshToken) throw new Error("SlackManifestClient has no refresh token or token resolver. Provide a refreshToken or a tokenResolver at construction.");
78
88
  const data = await (await fetch(`${SLACK_API_BASE}/tooling.tokens.rotate`, {
79
89
  method: "POST",
80
90
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
@@ -5296,7 +5306,8 @@ var SlackProvider = class {
5296
5306
  constructor(config = {}) {
5297
5307
  this.#channelConfig = config;
5298
5308
  this.#baseUrl = config.baseUrl;
5299
- if (config.refreshToken) this.#initManifestClient(config.token ?? "", config.refreshToken);
5309
+ if (config.tokenResolver) this.#manifestClient = new SlackManifestClient({ tokenResolver: config.tokenResolver });
5310
+ else if (config.refreshToken) this.#initManifestClient(config.token ?? "", config.refreshToken);
5300
5311
  }
5301
5312
  /**
5302
5313
  * Provide or clear Slack App Configuration credentials at runtime.
@@ -5316,6 +5327,7 @@ var SlackProvider = class {
5316
5327
  * ```
5317
5328
  */
5318
5329
  async configure(credentials) {
5330
+ if (this.#channelConfig.tokenResolver) throw new Error("SlackProvider was constructed with a tokenResolver — credentials are managed externally and cannot be configured manually.");
5319
5331
  if (credentials === null) {
5320
5332
  this.#manifestClient = void 0;
5321
5333
  return this.#deleteConfigTokens();
@@ -5674,7 +5686,7 @@ var SlackProvider = class {
5674
5686
  }
5675
5687
  }
5676
5688
  async #doInitialize() {
5677
- const storedTokensEncrypted = await this.#getConfigTokens();
5689
+ const storedTokensEncrypted = this.#channelConfig.tokenResolver ? null : await this.#getConfigTokens();
5678
5690
  if (storedTokensEncrypted) {
5679
5691
  const storedTokens = this.#decryptConfigTokens(storedTokensEncrypted);
5680
5692
  console.log(`[Slack] Using stored config tokens (updated ${storedTokens.updatedAt.toISOString()})`);