@sideboard-ai/core 0.1.335 → 0.1.336

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
@@ -41729,18 +41729,25 @@ async function connectSlackToken(rawToken) {
41729
41729
  if (!teamId) throw new Error("Slack auth.test did not return a team_id");
41730
41730
  const existing = getSlackWorkspace(teamId);
41731
41731
  const kind = tokenKind(token);
41732
+ const authUserId = auth.user_id?.trim();
41733
+ const userId = kind === "bot" ? existing?.user_id || authUserId : authUserId || existing?.user_id;
41732
41734
  const next = {
41733
41735
  team_id: teamId,
41734
41736
  team_name: auth.team?.trim() || existing?.team_name || teamId,
41735
- user_id: auth.user_id?.trim() || existing?.user_id,
41737
+ user_id: userId,
41736
41738
  bot_token: kind === "bot" ? token : existing?.bot_token,
41737
41739
  user_token: kind === "user" || kind === "unknown" ? token : existing?.user_token,
41740
+ listen_grant: existing?.user_id && userId && existing.user_id !== userId ? void 0 : existing?.listen_grant,
41738
41741
  scopes: existing?.scopes,
41739
41742
  connected_at: existing?.connected_at || (/* @__PURE__ */ new Date()).toISOString()
41740
41743
  };
41741
41744
  if (kind === "unknown" && auth.bot_id) {
41742
41745
  next.bot_token = token;
41743
41746
  next.user_token = existing?.user_token;
41747
+ next.user_id = existing?.user_id || authUserId;
41748
+ if (existing?.user_id && next.user_id && existing.user_id !== next.user_id) {
41749
+ next.listen_grant = void 0;
41750
+ }
41744
41751
  }
41745
41752
  return upsertSlackWorkspace(next);
41746
41753
  }
@@ -42071,7 +42078,7 @@ async function handleEvents(ctx, registrationId) {
42071
42078
  }
42072
42079
  const life = lifecycleFromEventsBody(body);
42073
42080
  if (life?.kind === "app_uninstalled") {
42074
- ctx.apps.deleteByTeam(life.teamId);
42081
+ ctx.apps.clearInstall(life.teamId);
42075
42082
  ctx.grants.revokeTeam(life.teamId);
42076
42083
  ctx.hub.uninstallTeam(life.teamId);
42077
42084
  return;
@@ -42365,10 +42372,19 @@ var SlackAppStore = class {
42365
42372
  botToken: openSecret(this.key, row2.bot_token_enc)
42366
42373
  }));
42367
42374
  }
42368
- deleteByTeam(teamId) {
42375
+ /**
42376
+ * Slack removed the install. Drop the bot token and team so a reinstall can
42377
+ * record again. Keep the client id, secrets, and registration id — the events
42378
+ * URL in the Slack app is that registration id.
42379
+ */
42380
+ clearInstall(teamId) {
42369
42381
  const id = teamId.trim();
42370
42382
  if (!id) return;
42371
- this.db.prepare("DELETE FROM slack_apps WHERE team_id = ?").run(id);
42383
+ this.db.prepare(
42384
+ `UPDATE slack_apps
42385
+ SET team_id = NULL, bot_token_enc = NULL, bot_user_id = NULL
42386
+ WHERE team_id = ?`
42387
+ ).run(id);
42372
42388
  }
42373
42389
  row(registrationId) {
42374
42390
  const id = registrationId.trim();
package/dist/index.js CHANGED
@@ -5822,18 +5822,25 @@ async function connectSlackToken(rawToken) {
5822
5822
  if (!teamId) throw new Error("Slack auth.test did not return a team_id");
5823
5823
  const existing = getSlackWorkspace(teamId);
5824
5824
  const kind = tokenKind(token);
5825
+ const authUserId = auth.user_id?.trim();
5826
+ const userId = kind === "bot" ? existing?.user_id || authUserId : authUserId || existing?.user_id;
5825
5827
  const next = {
5826
5828
  team_id: teamId,
5827
5829
  team_name: auth.team?.trim() || existing?.team_name || teamId,
5828
- user_id: auth.user_id?.trim() || existing?.user_id,
5830
+ user_id: userId,
5829
5831
  bot_token: kind === "bot" ? token : existing?.bot_token,
5830
5832
  user_token: kind === "user" || kind === "unknown" ? token : existing?.user_token,
5833
+ listen_grant: existing?.user_id && userId && existing.user_id !== userId ? void 0 : existing?.listen_grant,
5831
5834
  scopes: existing?.scopes,
5832
5835
  connected_at: existing?.connected_at || (/* @__PURE__ */ new Date()).toISOString()
5833
5836
  };
5834
5837
  if (kind === "unknown" && auth.bot_id) {
5835
5838
  next.bot_token = token;
5836
5839
  next.user_token = existing?.user_token;
5840
+ next.user_id = existing?.user_id || authUserId;
5841
+ if (existing?.user_id && next.user_id && existing.user_id !== next.user_id) {
5842
+ next.listen_grant = void 0;
5843
+ }
5837
5844
  }
5838
5845
  return upsertSlackWorkspace(next);
5839
5846
  }
@@ -6164,7 +6171,7 @@ async function handleEvents(ctx, registrationId) {
6164
6171
  }
6165
6172
  const life = lifecycleFromEventsBody(body);
6166
6173
  if (life?.kind === "app_uninstalled") {
6167
- ctx.apps.deleteByTeam(life.teamId);
6174
+ ctx.apps.clearInstall(life.teamId);
6168
6175
  ctx.grants.revokeTeam(life.teamId);
6169
6176
  ctx.hub.uninstallTeam(life.teamId);
6170
6177
  return;
@@ -6458,10 +6465,19 @@ var SlackAppStore = class {
6458
6465
  botToken: openSecret(this.key, row2.bot_token_enc)
6459
6466
  }));
6460
6467
  }
6461
- deleteByTeam(teamId) {
6468
+ /**
6469
+ * Slack removed the install. Drop the bot token and team so a reinstall can
6470
+ * record again. Keep the client id, secrets, and registration id — the events
6471
+ * URL in the Slack app is that registration id.
6472
+ */
6473
+ clearInstall(teamId) {
6462
6474
  const id = teamId.trim();
6463
6475
  if (!id) return;
6464
- this.db.prepare("DELETE FROM slack_apps WHERE team_id = ?").run(id);
6476
+ this.db.prepare(
6477
+ `UPDATE slack_apps
6478
+ SET team_id = NULL, bot_token_enc = NULL, bot_user_id = NULL
6479
+ WHERE team_id = ?`
6480
+ ).run(id);
6465
6481
  }
6466
6482
  row(registrationId) {
6467
6483
  const id = registrationId.trim();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sideboard-ai/core",
3
- "version": "0.1.335",
3
+ "version": "0.1.336",
4
4
  "description": "Sideboard core — orchestration, agents, git worktrees, MCP server",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",