@sentry/junior 0.32.0 → 0.33.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.
Files changed (2) hide show
  1. package/dist/app.js +63 -26
  2. package/package.json +1 -1
package/dist/app.js CHANGED
@@ -1131,7 +1131,6 @@ async function postSlackMessage(input) {
1131
1131
  () => getSlackClient().chat.postMessage({
1132
1132
  channel: channelId,
1133
1133
  text,
1134
- mrkdwn: true,
1135
1134
  ...input.blocks?.length ? {
1136
1135
  blocks: input.blocks
1137
1136
  } : {},
@@ -3134,11 +3133,11 @@ function buildBehaviorSection() {
3134
3133
  ].join("\n\n");
3135
3134
  }
3136
3135
  function buildOutputSection() {
3137
- const openTag = `<output format="slack-mrkdwn" max_inline_chars="${slackOutputPolicy.maxInlineChars}" max_inline_lines="${slackOutputPolicy.maxInlineLines}">`;
3136
+ const openTag = `<output format="slack-markdown" max_inline_chars="${slackOutputPolicy.maxInlineChars}" max_inline_lines="${slackOutputPolicy.maxInlineLines}">`;
3138
3137
  return [
3139
3138
  openTag,
3140
3139
  "- Start with the answer or result, not internal process narration.",
3141
- "- Use Slack-friendly mrkdwn: bolded section labels instead of headings, no markdown tables or markdown links, and plain URLs.",
3140
+ "- Use Slack-flavored Markdown: **bold** section labels, `code`, [text](url) links, bullet lists, and fenced code blocks. No tables.",
3142
3141
  "- Keep replies brief and scannable; use bullets or short code blocks when helpful, and one compact thread reply when it fits.",
3143
3142
  "- When a research or document-style answer would benefit from continuation, multiple sections, or future reference value, create a Slack canvas and keep the thread reply to one or two short sentences plus the link; do not recap the canvas contents.",
3144
3143
  "- Unless a successful Slack side-effect tool intentionally satisfied the request by itself, end every turn with a final user-facing markdown response.",
@@ -11230,25 +11229,25 @@ function buildSlackReplyFooter(args) {
11230
11229
  return items.length > 0 ? { items } : void 0;
11231
11230
  }
11232
11231
  function buildSlackReplyBlocks(text, footer) {
11233
- if (!text.trim() || !footer?.items.length) {
11232
+ if (!text.trim()) {
11234
11233
  return void 0;
11235
11234
  }
11236
- return [
11237
- {
11238
- type: "section",
11239
- text: {
11240
- type: "mrkdwn",
11241
- text
11242
- }
11243
- },
11235
+ const blocks = [
11244
11236
  {
11237
+ type: "markdown",
11238
+ text
11239
+ }
11240
+ ];
11241
+ if (footer?.items.length) {
11242
+ blocks.push({
11245
11243
  type: "context",
11246
11244
  elements: footer.items.map((item) => ({
11247
11245
  type: "mrkdwn",
11248
11246
  text: `*${escapeSlackMrkdwn(item.label)}:* ${escapeSlackMrkdwn(item.value)}`
11249
11247
  }))
11250
- }
11251
- ];
11248
+ });
11249
+ }
11250
+ return blocks;
11252
11251
  }
11253
11252
 
11254
11253
  // src/chat/slack/reply.ts
@@ -11372,11 +11371,13 @@ async function postSlackApiReplyPosts(args) {
11372
11371
  let messageTs;
11373
11372
  try {
11374
11373
  if (post.text.trim().length > 0) {
11374
+ const footer = index === lastTextPostIndex ? args.footer : void 0;
11375
+ const blocks = buildSlackReplyBlocks(post.text, footer);
11375
11376
  const response = await postSlackMessage({
11376
11377
  channelId: args.channelId,
11377
11378
  threadTs: args.threadTs,
11378
11379
  text: post.text,
11379
- ...index === lastTextPostIndex && args.footer ? { blocks: buildSlackReplyBlocks(post.text, args.footer) } : {}
11380
+ ...blocks ? { blocks } : {}
11380
11381
  });
11381
11382
  messageTs = response.ts;
11382
11383
  lastPostedMessageTs = response.ts;
@@ -15317,6 +15318,24 @@ function nonEmptyString(value) {
15317
15318
  return trimmed || void 0;
15318
15319
  }
15319
15320
 
15321
+ // src/chat/ingress/workspace-membership.ts
15322
+ import { AsyncLocalStorage } from "async_hooks";
15323
+ var workspaceTeamIdStorage = new AsyncLocalStorage();
15324
+ function runWithWorkspaceTeamId(teamId, fn) {
15325
+ if (!teamId) return fn();
15326
+ return workspaceTeamIdStorage.run(teamId, fn);
15327
+ }
15328
+ function isExternalSlackUser(raw) {
15329
+ if (!raw) return false;
15330
+ const workspaceTeamId = workspaceTeamIdStorage.getStore();
15331
+ if (!workspaceTeamId) return false;
15332
+ const userTeam = typeof raw.user_team === "string" ? raw.user_team : void 0;
15333
+ if (userTeam) return userTeam !== workspaceTeamId;
15334
+ const sourceTeam = typeof raw.source_team === "string" ? raw.source_team : void 0;
15335
+ if (sourceTeam) return sourceTeam !== workspaceTeamId;
15336
+ return false;
15337
+ }
15338
+
15320
15339
  // src/chat/ingress/junior-chat.ts
15321
15340
  function enqueueBackgroundTask(options, task) {
15322
15341
  if (!options?.waitUntil) {
@@ -15355,6 +15374,9 @@ var JuniorChat = class extends Chat {
15355
15374
  (async () => {
15356
15375
  try {
15357
15376
  const message = await messageOrFactory();
15377
+ if (isExternalSlackUser(message.raw)) {
15378
+ return;
15379
+ }
15358
15380
  const normalized = normalizeIncomingSlackThreadId(
15359
15381
  threadId,
15360
15382
  message
@@ -15373,6 +15395,9 @@ var JuniorChat = class extends Chat {
15373
15395
  );
15374
15396
  return;
15375
15397
  }
15398
+ if (isExternalSlackUser(messageOrFactory.raw)) {
15399
+ return;
15400
+ }
15376
15401
  enqueueBackgroundTask(
15377
15402
  options,
15378
15403
  (async () => {
@@ -15824,12 +15849,16 @@ function extractMessageChangedMention(body, botUserId, adapter) {
15824
15849
  const userId = event.message.user ?? "unknown";
15825
15850
  const threadId = `slack:${channelId}:${threadTs}`;
15826
15851
  const teamId = typeof body.team_id === "string" ? body.team_id : void 0;
15852
+ const userTeam = typeof event.message.user_team === "string" ? event.message.user_team : void 0;
15853
+ const sourceTeam = typeof event.message.source_team === "string" ? event.message.source_team : void 0;
15827
15854
  const raw = {
15828
15855
  channel: channelId,
15829
15856
  ts: messageTs,
15830
15857
  thread_ts: threadTs,
15831
15858
  user: userId,
15832
- ...teamId ? { team_id: teamId } : {}
15859
+ ...teamId ? { team_id: teamId } : {},
15860
+ ...userTeam ? { user_team: userTeam } : {},
15861
+ ...sourceTeam ? { source_team: sourceTeam } : {}
15833
15862
  };
15834
15863
  const message = new Message({
15835
15864
  id: getEditedMentionMessageId(messageTs),
@@ -15931,6 +15960,7 @@ async function handlePlatformWebhook(request, platform, waitUntil, bot = getProd
15931
15960
  return new Response(`Unknown platform: ${platform}`, { status: 404 });
15932
15961
  }
15933
15962
  let rebuiltRequest = request;
15963
+ let slackWorkspaceTeamId;
15934
15964
  if (platform === "slack") {
15935
15965
  const rawBody = await request.text();
15936
15966
  let parsedBody;
@@ -15939,15 +15969,19 @@ async function handlePlatformWebhook(request, platform, waitUntil, bot = getProd
15939
15969
  } catch {
15940
15970
  parsedBody = void 0;
15941
15971
  }
15972
+ slackWorkspaceTeamId = getSlackPayloadTeamId(parsedBody);
15942
15973
  if (parsedBody && isMessageChangedEnvelope(parsedBody)) {
15943
15974
  try {
15944
- await handleAuthenticatedSlackMessageChangedMention({
15945
- body: parsedBody,
15946
- bot,
15947
- rawBody,
15948
- request,
15949
- waitUntil
15950
- });
15975
+ await runWithWorkspaceTeamId(
15976
+ slackWorkspaceTeamId,
15977
+ () => handleAuthenticatedSlackMessageChangedMention({
15978
+ body: parsedBody,
15979
+ bot,
15980
+ rawBody,
15981
+ request,
15982
+ waitUntil
15983
+ })
15984
+ );
15951
15985
  } catch (error) {
15952
15986
  logException(error, "slack_message_changed_side_channel_failed");
15953
15987
  }
@@ -15965,9 +15999,12 @@ async function handlePlatformWebhook(request, platform, waitUntil, bot = getProd
15965
15999
  requestContext,
15966
16000
  async () => {
15967
16001
  try {
15968
- const response = await handler(rebuiltRequest, {
15969
- waitUntil: (task) => waitUntil(task)
15970
- });
16002
+ const response = await runWithWorkspaceTeamId(
16003
+ slackWorkspaceTeamId,
16004
+ () => handler(rebuiltRequest, {
16005
+ waitUntil: (task) => waitUntil(task)
16006
+ })
16007
+ );
15971
16008
  if (response.status >= 400) {
15972
16009
  let responseBodySnippet;
15973
16010
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/junior",
3
- "version": "0.32.0",
3
+ "version": "0.33.0",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"