@mastra/slack 1.6.4 → 1.7.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.js CHANGED
@@ -14,11 +14,13 @@ var SlackManifestClient = class {
14
14
  #token;
15
15
  #refreshToken;
16
16
  #onTokenRotation;
17
+ #tokenResolver;
17
18
  #rotationPromise = null;
18
19
  constructor(config) {
19
- this.#token = config.token;
20
- this.#refreshToken = config.refreshToken;
20
+ this.#token = config.token ?? "";
21
+ this.#refreshToken = config.refreshToken ?? "";
21
22
  this.#onTokenRotation = config.onTokenRotation;
23
+ this.#tokenResolver = config.tokenResolver;
22
24
  }
23
25
  /**
24
26
  * Get current tokens (after potential rotation).
@@ -43,6 +45,9 @@ var SlackManifestClient = class {
43
45
  *
44
46
  * Concurrent callers share the same in-flight rotation to avoid burning
45
47
  * single-use refresh tokens.
48
+ *
49
+ * When a `tokenResolver` is configured, no rotation happens here — the
50
+ * resolver is asked for a fresh access token instead.
46
51
  */
47
52
  async rotateToken() {
48
53
  if (this.#rotationPromise) return this.#rotationPromise;
@@ -52,6 +57,11 @@ var SlackManifestClient = class {
52
57
  return this.#rotationPromise;
53
58
  }
54
59
  async #doRotateToken() {
60
+ if (this.#tokenResolver) {
61
+ this.#token = await this.#tokenResolver();
62
+ return;
63
+ }
64
+ if (!this.#refreshToken) throw new Error("SlackManifestClient has no refresh token or token resolver. Provide a refreshToken or a tokenResolver at construction.");
55
65
  const data = await (await fetch(`${SLACK_API_BASE}/tooling.tokens.rotate`, {
56
66
  method: "POST",
57
67
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
@@ -5273,7 +5283,8 @@ var SlackProvider = class {
5273
5283
  constructor(config = {}) {
5274
5284
  this.#channelConfig = config;
5275
5285
  this.#baseUrl = config.baseUrl;
5276
- if (config.refreshToken) this.#initManifestClient(config.token ?? "", config.refreshToken);
5286
+ if (config.tokenResolver) this.#manifestClient = new SlackManifestClient({ tokenResolver: config.tokenResolver });
5287
+ else if (config.refreshToken) this.#initManifestClient(config.token ?? "", config.refreshToken);
5277
5288
  }
5278
5289
  /**
5279
5290
  * Provide or clear Slack App Configuration credentials at runtime.
@@ -5293,6 +5304,7 @@ var SlackProvider = class {
5293
5304
  * ```
5294
5305
  */
5295
5306
  async configure(credentials) {
5307
+ if (this.#channelConfig.tokenResolver) throw new Error("SlackProvider was constructed with a tokenResolver — credentials are managed externally and cannot be configured manually.");
5296
5308
  if (credentials === null) {
5297
5309
  this.#manifestClient = void 0;
5298
5310
  return this.#deleteConfigTokens();
@@ -5651,7 +5663,7 @@ var SlackProvider = class {
5651
5663
  }
5652
5664
  }
5653
5665
  async #doInitialize() {
5654
- const storedTokensEncrypted = await this.#getConfigTokens();
5666
+ const storedTokensEncrypted = this.#channelConfig.tokenResolver ? null : await this.#getConfigTokens();
5655
5667
  if (storedTokensEncrypted) {
5656
5668
  const storedTokens = this.#decryptConfigTokens(storedTokensEncrypted);
5657
5669
  console.log(`[Slack] Using stored config tokens (updated ${storedTokens.updatedAt.toISOString()})`);