Skip to content

Commit cc7a63e

Browse files
authored
Merge pull request #288 from scientist-softserv/135-configure-emails
135 configure emails
2 parents 7bce499 + b8ff349 commit cc7a63e

File tree

5 files changed

+174
-1
lines changed

5 files changed

+174
-1
lines changed

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
NEXT_PUBLIC_PROVIDER_NAME=beachsidebiotech
55
NEXT_PUBLIC_PROVIDER_ID=5159
66
NEXT_PUBLIC_SCIENTIST_API_VERSION=v2
7+
NEXT_PUBLIC_WEBHOOK_URL=http://ss-mailer/webstore
8+
NEXT_PUBLIC_APP_BASE_URL=https://www.webstore-staging.vercel.app

pages/api/auth/[...nextauth].js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import NextAuth from 'next-auth'
22
import axios from 'axios'
33
// TODO(alishaevn): use the api value from https://github.com/assaydepot/rx/issues/21497 in the next phase
4-
import { EXPIRATION_DURATION } from '../../../utils'
4+
import { EXPIRATION_DURATION, getWebhookConfig, createWebhookConfig } from '../../../utils'
55

66
// For more information on each option (and a full list of options) go to: https://next-auth.js.org/configuration/options
77
const authOptions = {
@@ -32,6 +32,12 @@ const authOptions = {
3232
async jwt({ token, account, user }) {
3333
// Triggered on the initial sign in
3434
if (account && user) {
35+
// add the webstore webhook if it isn't there
36+
const data = await getWebhookConfig(accessToken)
37+
if(!data.id) {
38+
createWebhookConfig(account.access_token)
39+
}
40+
3541
return {
3642
accessToken: account.access_token,
3743
accessTokenExpires: Date.now() + EXPIRATION_DURATION,

utils/api/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from './base'
33
export * from './configurations'
44
export * from './requests'
55
export * from './services'
6+
export * from './webhooks'

utils/api/webhooks.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { fetcher, updating } from './base'
2+
import { WEBHOOK_EVENTS } from '../constants'
3+
4+
export const getWebhookConfig = async (accessToken) => {
5+
// TODO(alishaevn): update the url to "webhook_config/user.json" when
6+
// https://github.com/assaydepot/scientist_api_v2/pull/237 is available on api prod
7+
return fetcher('/webhook_config.json', accessToken)
8+
}
9+
10+
export const createWebhookConfig = (accessToken) => {
11+
const webhook_config = {
12+
'name': 'Webstore',
13+
'url': `${process.env.NEXT_PUBLIC_WEBHOOK_URL}`,
14+
'active': true,
15+
'params': {
16+
'base_url': `${process.env.NEXT_PUBLIC_APP_BASE_URL}`
17+
},
18+
'all_events': true,
19+
// TODO(alishaevn): attempt to use the below again when https://github.com/assaydepot/scientist_api_v2/pull/248
20+
// is available on api prod
21+
// 'all_events': false,
22+
// 'events': WEBHOOK_EVENTS,
23+
'send_own_action_items': false,
24+
}
25+
26+
// TODO(alishaevn): update the url to "webhook_config/user.json" when
27+
// https://github.com/assaydepot/scientist_api_v2/pull/237 is available on api prod
28+
updating('/webhook_config.json', webhook_config, accessToken)
29+
}

utils/constants.js

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,138 @@ export const FEATURED_SERVICE_PATH = '/requests/new'
108108
// this amount, listed in milliseconds, represents when the access token will expire
109109
// the default is 1 week
110110
export const EXPIRATION_DURATION = 604800000
111+
112+
export const WEBHOOK_EVENTS = {
113+
'signer': {
114+
'signature_voided': false,
115+
'signature_requested': false,
116+
},
117+
'vendor': {
118+
'new_request': false,
119+
'rfi_expired': false,
120+
'po_obsoleted': false,
121+
'work_started': false,
122+
'rfi_submitted': false,
123+
'sow_requested': false,
124+
'proposal_denied': false,
125+
'resource_shared': false,
126+
'invited_new_user': false,
127+
'proposal_expired': false,
128+
'signature_voided': false,
129+
'cancelled_request': false,
130+
'proposal_approved': false,
131+
'signature_requested': false,
132+
'timeline_post_added': false,
133+
'legal_document_signed': false,
134+
'share_token_generated': false,
135+
'legal_documents_updated': false,
136+
'rfi_expiration_reminder': false,
137+
'provider_credit_rejected': false,
138+
'request_updated_proposal': false,
139+
'provider_invoice_rejected': false,
140+
'supplier_approval_required': false,
141+
'request_description_updated': false,
142+
'signed_legal_document_revoked': false,
143+
'provider_credit_sent_to_customer': false,
144+
'provider_invoice_sent_to_customer': false,
145+
},
146+
'approver': {
147+
'approval_cancelled': false,
148+
'approval_requested': false,
149+
'user_legal_obligation_changed': false,
150+
'compliance_manifest_approved_by': false,
151+
},
152+
'customer': {
153+
'complete': true,
154+
'sow_submitted': true,
155+
'resource_shared': true,
156+
'signing_complete': true,
157+
'cancelled_request': true,
158+
'invoice_submitted': false,
159+
'estimate_submitted': true,
160+
'amendment_submitted': true,
161+
'timeline_post_added': true,
162+
'compliance_submitted': true,
163+
'share_token_generated': true,
164+
'unapproved_for_payment': false,
165+
'wip_timeline_post_added': true,
166+
'milestone_shipping_updated': true,
167+
'proposal_compliance_denied': true,
168+
'purchase_compliance_denied': true,
169+
'internal_timeline_post_added': true,
170+
'proposal_compliance_approved': true,
171+
'purchase_compliance_approved': true,
172+
'user_legal_obligation_changed': true,
173+
'sow_accepted_for_external_purchase': true,
174+
},
175+
'site_rep': {
176+
'rfi_badged': false,
177+
'new_request': false,
178+
'sow_accepted': false,
179+
'work_started': false,
180+
'sow_requested': false,
181+
'sow_submitted': false,
182+
'supplier_added': false,
183+
'signing_complete': false,
184+
'cancelled_request': false,
185+
'estimate_submitted': false,
186+
'amendment_submitted': false,
187+
'supplier_ad_created': false,
188+
'timeline_post_added': false,
189+
'legal_document_signed': false,
190+
'request_sent_to_vendors': false,
191+
'wip_timeline_post_added': false,
192+
'invoice_payment_rejected': false,
193+
'request_updated_proposal': false,
194+
'legal_documents_challenged': false,
195+
'proposal_compliance_denied': false,
196+
'purchase_compliance_denied': false,
197+
'request_compliance_approved': false,
198+
'request_description_updated': false,
199+
'internal_timeline_post_added': false,
200+
'proposal_compliance_approved': false,
201+
'purchase_compliance_approved': false,
202+
'signed_legal_document_revoked': false,
203+
'user_legal_obligation_changed': false,
204+
'sow_accepted_for_external_purchase': false,
205+
},
206+
'vendor_approver': {
207+
'proposal_approval_requested': false,
208+
},
209+
'vendor_follower': {
210+
'new_request': false,
211+
'rfi_expired': false,
212+
'work_started': false,
213+
'rfi_submitted': false,
214+
'sow_requested': false,
215+
'added_as_follower': false,
216+
'cancelled_request': false,
217+
'timeline_post_added': false,
218+
'rfi_expiration_reminder': false,
219+
'request_updated_proposal': false,
220+
'supplier_approval_required': false,
221+
'request_description_updated': false,
222+
},
223+
'approval_follower': {
224+
'approval_cancelled': false,
225+
'approval_requested': false,
226+
'user_legal_obligation_changed': false,
227+
'compliance_manifest_approved_by': false,
228+
},
229+
'customer_follower': {
230+
'added_as_follower': true,
231+
'internal_timeline_post_added': true,
232+
},
233+
'vendor_approval_follower': {
234+
'proposal_approval_requested': false,
235+
},
236+
'app_store_organization_approver': {
237+
'app_revoked': false,
238+
'app_approved': false,
239+
'app_requested': false,
240+
},
241+
'app_store_organization_follower': {
242+
'app_revoked': false,
243+
'app_approved': false,
244+
}
245+
}

0 commit comments

Comments
 (0)