Line data Source code
1 : import { isCloud, isNightly } from '@/platform/distribution/types'
2 :
3 : /**
4 : * Zendesk ticket form field IDs.
5 : */
6 2355 : const ZENDESK_FIELDS = {
7 : /** Distribution tag (cloud vs OSS) */
8 : DISTRIBUTION: 'tf_42243568391700',
9 : /** User email (anonymous requester) */
10 : ANONYMOUS_EMAIL: 'tf_anonymous_requester_email',
11 : /** User email (authenticated) */
12 : EMAIL: 'tf_40029135130388',
13 : /** User ID */
14 : USER_ID: 'tf_42515251051412'
15 : } as const
16 :
17 : /**
18 : * Gets the distribution identifier for tracking.
19 : * Helps distinguish feedback from different build types.
20 : */
21 4 : function getDistribution(): 'ccloud' | 'oss-nightly' | 'oss' {
22 : if (isCloud) return 'ccloud'
23 : if (isNightly) return 'oss-nightly'
24 4 : return 'oss'
25 : }
26 :
27 2355 : const SUPPORT_BASE_URL = 'https://support.comfy.org/hc/en-us/requests/new'
28 :
29 : export type FeedbackSource =
30 : | 'topbar'
31 : | 'action-bar'
32 : | 'help-center'
33 : | 'agent-panel'
34 : | 'agent-consent'
35 :
36 2355 : export const FEEDBACK_TYPEFORM_ID = 'q7azbWPi'
37 :
38 2355 : const FEEDBACK_TYPEFORM_BASE_URL = `https://form.typeform.com/to/${FEEDBACK_TYPEFORM_ID}`
39 :
40 : /** Shared by the URL and embed builders so their segmentation tags can't drift. */
41 0 : function getFeedbackTags(source: FeedbackSource): Record<string, string> {
42 0 : return { distribution: getDistribution(), source }
43 : }
44 :
45 : /**
46 : * Builds the feedback Typeform URL tagged with the current build distribution
47 : * and the UI source that opened it. Tags are passed via the URL fragment
48 : * (Typeform's hidden-field convention) so survey responses can be segmented
49 : * by distribution (cloud / oss-nightly / oss) and entry point.
50 : */
51 0 : export function buildFeedbackTypeformUrl(source: FeedbackSource): string {
52 : const params = new URLSearchParams(getFeedbackTags(source))
53 0 : return `${FEEDBACK_TYPEFORM_BASE_URL}#${params.toString()}`
54 : }
55 :
56 0 : export function buildFeedbackHiddenFields(
57 : source: FeedbackSource,
58 : extraTags: Record<string, string> = {}
59 : ): string {
60 : // Typeform's `data-tf-hidden` parser (transformRecord) splits on `,` and
61 : // unescapes `\,`, so a comma in a value is the only delimiter that needs escaping.
62 0 : return Object.entries({ ...getFeedbackTags(source), ...extraTags })
63 : .map(([key, value]) => `${key}=${value.replace(/,/g, '\\,')}`)
64 : .join(',')
65 : }
66 :
67 : /**
68 : * Builds the support URL with optional user information for pre-filling.
69 : * Users without login information will still get a valid support URL without pre-fill.
70 : *
71 : * @param params - User information to pre-fill in the support form
72 : * @returns Complete Zendesk support URL with query parameters
73 : */
74 4 : export function buildSupportUrl(params?: {
75 : userEmail?: string | null
76 : userId?: string | null
77 : }): string {
78 4 : const searchParams = new URLSearchParams({
79 : [ZENDESK_FIELDS.DISTRIBUTION]: getDistribution()
80 : })
81 :
82 4 : if (params?.userEmail) {
83 0 : searchParams.append(ZENDESK_FIELDS.ANONYMOUS_EMAIL, params.userEmail)
84 0 : searchParams.append(ZENDESK_FIELDS.EMAIL, params.userEmail)
85 : }
86 4 : if (params?.userId) {
87 0 : searchParams.append(ZENDESK_FIELDS.USER_ID, params.userId)
88 : }
89 :
90 4 : return `${SUPPORT_BASE_URL}?${searchParams.toString()}`
91 : }
|