Repository navigation
feat(core): in-app previews (Slack, HubSpot, HTML) and workflow dry runs #697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
seanspeaks
wants to merge
6
commits into
claude/shared-conversation-8hgmbr-stack-5-definitions-as-types
Choose a base branch
from
claude/shared-conversation-8hgmbr-stack-6-previews
base: claude/shared-conversation-8hgmbr-stack-5-definitions-as-types
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ef39425
feat(core): previews for data-defined integrations (Slack, HubSpot, H…
claude 3bb0e23
Merge renderers: in-app previews (Slack, HubSpot, HTML) and workflow …
claude 2348cde
fix(core): escape record data inside Slack messages (mrkdwn filter)
claude cea7ddd
docs(adr): ADR-063 previews are preview renderers, not deployed host …
claude b3ed0e8
Merge fix branches into stack 6: updated stack-5 (adr-text-5, id-take…
claude 20e3e54
Merge fix branches into stack 6: adr-text-6
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
packages/core/integrations/data-defined/renderers/common.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /** | ||
| * What every renderer shares: coercion of view props (they come from record data, so any type can arrive), the one | ||
| * URL rule, truncation that never leaves half an entity behind, and the button <-> Slack round trip. | ||
| */ | ||
|
|
||
| /** A view prop as text. Objects are JSON, null/undefined are empty: a renderer never prints "[object Object]" or "undefined". */ | ||
| function str(v) { | ||
| if (v == null) return ''; | ||
| if (typeof v === 'string') return v; | ||
| if (typeof v === 'object') { try { return JSON.stringify(v); } catch (_) { return ''; } } | ||
| return String(v); | ||
| } | ||
|
|
||
| /** | ||
| * Only http(s) links leave a preview or a card. Record data decides these URLs ("{{data.proposal.recording}}"), and a | ||
| * `javascript:` or `data:` URL in a vendor field must not become a clickable thing in someone's HubSpot or Slack. | ||
| * @returns {string|null} | ||
| */ | ||
| function safeUrl(u) { | ||
| const s = str(u).trim(); | ||
| if (!/^https?:\/\/[^\s<>"']+$/i.test(s)) return null; | ||
| try { new URL(s); } catch (_) { return null; } | ||
| return s; | ||
| } | ||
|
|
||
| /** | ||
| * Cut to at most `max` characters, ending in the marker. Never leaves a dangling half of a Slack entity ("&am"), which | ||
| * would render as literal junk instead of the character it stood for. | ||
| */ | ||
| function truncate(s, max, marker = '…') { | ||
| s = String(s); | ||
| if (s.length <= max) return s; | ||
| let cut = s.slice(0, Math.max(0, max - marker.length)); | ||
| cut = cut.replace(/&(?:[a-z]{1,4}|#\d{0,6}|#x[0-9a-f]{0,5})?$/i, ''); | ||
| return cut + marker; | ||
| } | ||
|
|
||
| /** Badge tone (`neutral`, or a Jira statusCategory key like `done`) -> one of four. Unknown is neutral, never an error. */ | ||
| function toneOf(tone) { | ||
| const t = str(tone).toLowerCase(); | ||
| if (['positive', 'success', 'good', 'done', 'green', 'complete', 'completed'].includes(t)) return 'positive'; | ||
| if (['warning', 'caution', 'indeterminate', 'yellow', 'in_progress', 'pending'].includes(t)) return 'warning'; | ||
| if (['critical', 'danger', 'error', 'bad', 'red', 'failed'].includes(t)) return 'critical'; | ||
| return 'neutral'; | ||
| } | ||
|
|
||
| const ACTION_VALUE_MAX = 2000; // Slack's cap on a button's value | ||
|
|
||
| /** | ||
| * A userAction button's identity as a Slack button value: which installation, which workflow, which surface it was on. | ||
| * `needsInput` marks a button whose workflow asks for values first (a Slack button cannot, so the handler opens a form). | ||
| */ | ||
| function encodeAction({ integrationId, workflow, surface, needsInput }) { | ||
| const value = JSON.stringify({ ...(integrationId ? { integrationId: String(integrationId) } : {}), workflow, surface, ...(needsInput ? { needsInput: true } : {}) }); | ||
| return value.length <= ACTION_VALUE_MAX ? value : null; | ||
| } | ||
|
|
||
| /** The inverse, for the handler that receives a click. null for anything that is not one of ours. */ | ||
| function decodeAction(value) { | ||
| let v; | ||
| try { v = JSON.parse(value); } catch (_) { return null; } | ||
| if (!v || typeof v !== 'object' || typeof v.workflow !== 'string' || !v.workflow || typeof v.surface !== 'string') return null; | ||
| if (v.integrationId !== undefined && typeof v.integrationId !== 'string') return null; | ||
| return { ...(v.integrationId ? { integrationId: v.integrationId } : {}), workflow: v.workflow, surface: v.surface, ...(v.needsInput ? { needsInput: true } : {}) }; | ||
| } | ||
|
|
||
| module.exports = { str, safeUrl, truncate, toneOf, encodeAction, decodeAction, ACTION_VALUE_MAX }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[should-fix]
mrkdwnescape is opt-in. Authors who omit| mrkdwnon record-driven Slack templates can still format/ping in production posts (*…*,<!channel>in deal/task titles). Prefer default-escape for outgoing Slack text, or ensure examples always pipe through this filter.