From 5af09756d8a7b8ffe16c70f4db50bb142d3fdabe Mon Sep 17 00:00:00 2001 From: Sander Bruens Date: Fri, 6 Oct 2023 16:06:19 -0400 Subject: [PATCH 1/2] Add new contact form fields to the sentry webhook. --- .../post_sentry_event_to_salesforce.spec.ts | 12 ++++-- .../post_sentry_event_to_salesforce.ts | 40 +++++++++---------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/sentry_webhook/post_sentry_event_to_salesforce.spec.ts b/src/sentry_webhook/post_sentry_event_to_salesforce.spec.ts index 60f791ff5..51d155ebc 100644 --- a/src/sentry_webhook/post_sentry_event_to_salesforce.spec.ts +++ b/src/sentry_webhook/post_sentry_event_to_salesforce.spec.ts @@ -79,7 +79,7 @@ describe('postSentryEventToSalesforce', () => { 'orgid=00D750000004dFg' + '&recordType=0123F000000MWTS' + '&email=foo%40bar.com' + - '&00N3F000002Rqhq=' + + '&00N0b00000BqOA4=' + '&description=my%20message' + '&type=Outline%20client' ); @@ -108,9 +108,13 @@ describe('postSentryEventToSalesforce', () => { '&00N0b00000BqOA4=' + '&description=my%20message' + '&type=Outline%20client' + - '&00N5a00000DXy19=test%20category' + - '&00N5a00000DXxmo=test%20os' + - '&00N5a00000DXxmq=test%20version' + '&OC_Outline_Issue_v2__c=test%20category' + + '&subject=' + + '&OC_Operating_System__c=test%20os' + + '&OC_Outline_Manager_Client_Version__c=test%20version' + + '&Build__c=' + + '&Updated_App_Contact_Form__c=' + + '&OC_Where_did_you_get_your_access_key__c=' ); expect(mockRequest.end).toHaveBeenCalled(); }); diff --git a/src/sentry_webhook/post_sentry_event_to_salesforce.ts b/src/sentry_webhook/post_sentry_event_to_salesforce.ts index d7d325cd4..eac6e5926 100644 --- a/src/sentry_webhook/post_sentry_event_to_salesforce.ts +++ b/src/sentry_webhook/post_sentry_event_to_salesforce.ts @@ -20,13 +20,17 @@ interface SalesforceFormFields { orgId: string; recordType: string; email: string; + subject: string; description: string; category: string; + accessKeySource: string; cloudProvider: string; sentryEventUrl: string; os: string; version: string; + build: string; type: string; + isUpdatedForm: string; } // Defines the Salesforce form values. @@ -38,29 +42,21 @@ interface SalesforceFormValues { const SALESFORCE_DEV_HOST = 'google-jigsaw--jigsawuat.sandbox.my.salesforce.com'; const SALESFORCE_PROD_HOST = 'webto.salesforce.com'; const SALESFORCE_PATH = '/servlet/servlet.WebToCase'; -const SALESFORCE_FORM_FIELDS_DEV: SalesforceFormFields = { +const SALESFORCE_FORM_FIELDS: SalesforceFormFields = { orgId: 'orgid', recordType: 'recordType', email: 'email', + subject: 'subject', description: 'description', - category: '00N3F000002Rqho', - cloudProvider: '00N3F000002Rqhs', - sentryEventUrl: '00N3F000002Rqhq', - os: '00N3F000002cLcN', - version: '00N3F000002cLcI', - type: 'type', -}; -const SALESFORCE_FORM_FIELDS_PROD: SalesforceFormFields = { - orgId: 'orgid', - recordType: 'recordType', - email: 'email', - description: 'description', - category: '00N5a00000DXy19', - cloudProvider: '00N5a00000DXxmn', + category: 'OC_Outline_Issue_v2__c', + accessKeySource: 'OC_Where_did_you_get_your_access_key__c', + cloudProvider: 'OC_Cloud_Provider__c', sentryEventUrl: '00N0b00000BqOA4', - os: '00N5a00000DXxmo', - version: '00N5a00000DXxmq', + os: 'OC_Operating_System__c', + version: 'OC_Outline_Manager_Client_Version__c', + build: 'Build__c', type: 'type', + isUpdatedForm: 'Updated_App_Contact_Form__c', }; const SALESFORCE_FORM_VALUES_DEV: SalesforceFormValues = { orgId: '00D750000004dFg', @@ -84,11 +80,10 @@ export function postSentryEventToSalesforce(event: SentryEvent, project: string) // Sentry development projects are marked with 'dev', i.e. outline-client-dev. const isProd = project.indexOf('-dev') === -1; const salesforceHost = isProd ? SALESFORCE_PROD_HOST : SALESFORCE_DEV_HOST; - const formFields = isProd ? SALESFORCE_FORM_FIELDS_PROD : SALESFORCE_FORM_FIELDS_DEV; const formValues = isProd ? SALESFORCE_FORM_VALUES_PROD : SALESFORCE_FORM_VALUES_DEV; const isClient = project.indexOf('client') !== -1; const formData = getSalesforceFormData( - formFields, + SALESFORCE_FORM_FIELDS, formValues, event, event.user!.email!, @@ -141,9 +136,14 @@ function getSalesforceFormData( if (event.tags) { const tags = new Map(event.tags); form.push(encodeFormData(formFields.category, tags.get('category'))); + form.push(encodeFormData(formFields.subject, tags.get('subject'))); form.push(encodeFormData(formFields.os, tags.get('os.name'))); form.push(encodeFormData(formFields.version, tags.get('sentry:release'))); - if (!isClient) { + form.push(encodeFormData(formFields.build, tags.get('build.number'))); + form.push(encodeFormData(formFields.isUpdatedForm, tags.get('isUpdatedForm'))); + if (isClient) { + form.push(encodeFormData(formFields.accessKeySource, tags.get('accessKeySource'))); + } else { form.push(encodeFormData(formFields.cloudProvider, tags.get('cloudProvider'))); } } From f046d49abca2aeb37d598559ac3c005dfbcb49eb Mon Sep 17 00:00:00 2001 From: Sander Bruens Date: Mon, 9 Oct 2023 12:08:30 -0400 Subject: [PATCH 2/2] Set `isUpdatedForm` based on form version. --- .../post_sentry_event_to_salesforce.spec.ts | 19 ++++++++++++++++--- .../post_sentry_event_to_salesforce.ts | 5 ++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/sentry_webhook/post_sentry_event_to_salesforce.spec.ts b/src/sentry_webhook/post_sentry_event_to_salesforce.spec.ts index 51d155ebc..069c4ed8a 100644 --- a/src/sentry_webhook/post_sentry_event_to_salesforce.spec.ts +++ b/src/sentry_webhook/post_sentry_event_to_salesforce.spec.ts @@ -92,8 +92,10 @@ describe('postSentryEventToSalesforce', () => { message: 'my message', tags: [ ['category', 'test category'], + ['subject', 'test subject'], ['os.name', 'test os'], ['sentry:release', 'test version'], + ['build.number', 'test build'], ['unknown:tag', 'foo'], ], }; @@ -109,13 +111,24 @@ describe('postSentryEventToSalesforce', () => { '&description=my%20message' + '&type=Outline%20client' + '&OC_Outline_Issue_v2__c=test%20category' + - '&subject=' + + '&subject=test%20subject' + '&OC_Operating_System__c=test%20os' + '&OC_Outline_Manager_Client_Version__c=test%20version' + - '&Build__c=' + - '&Updated_App_Contact_Form__c=' + + '&Build__c=test%20build' + '&OC_Where_did_you_get_your_access_key__c=' ); expect(mockRequest.end).toHaveBeenCalled(); }); + + it('sets the correct form version tag', () => { + const event: SentryEvent = { + user: {email: 'foo@bar.com'}, + message: 'my message', + tags: [['formVersion', '2']], + }; + + postSentryEventToSalesforce(event, 'outline-clients'); + + expect(mockRequest.write.calls.argsFor(0)[0]).toContain('&Updated_App_Contact_Form__c=true'); + }); }); diff --git a/src/sentry_webhook/post_sentry_event_to_salesforce.ts b/src/sentry_webhook/post_sentry_event_to_salesforce.ts index eac6e5926..455b6bac9 100644 --- a/src/sentry_webhook/post_sentry_event_to_salesforce.ts +++ b/src/sentry_webhook/post_sentry_event_to_salesforce.ts @@ -140,7 +140,10 @@ function getSalesforceFormData( form.push(encodeFormData(formFields.os, tags.get('os.name'))); form.push(encodeFormData(formFields.version, tags.get('sentry:release'))); form.push(encodeFormData(formFields.build, tags.get('build.number'))); - form.push(encodeFormData(formFields.isUpdatedForm, tags.get('isUpdatedForm'))); + const formVersion = Number(tags.get('formVersion') ?? 1); + if (formVersion === 2) { + form.push(encodeFormData(formFields.isUpdatedForm, 'true')); + } if (isClient) { form.push(encodeFormData(formFields.accessKeySource, tags.get('accessKeySource'))); } else {