Skip to content
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

feat: Make webhook creation optional #570

Merged
merged 48 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
87305c7
init webhooks
Nabhag8848 May 15, 2024
78e5498
temp
Nabhag8848 May 15, 2024
5099fa6
refactor: created AccountProvider and useEnvironment
Nabhag8848 May 15, 2024
323953e
fix: remove props and useEnvironment
Nabhag8848 May 15, 2024
5b9f19c
feat: have link navigation for tabs
Nabhag8848 May 15, 2024
767355c
fix: change in Environment by creating EnvironmentProvider
Nabhag8848 May 16, 2024
a27b4c0
feat: init webhooks
Nabhag8848 May 16, 2024
3ebeab1
feat(wip): create and get svix application
Nabhag8848 May 17, 2024
ce5d07d
fix: Main layout
Nabhag8848 May 17, 2024
ef51fec
feat(wip): createMagicLink
Nabhag8848 May 17, 2024
6fcc0e8
fix: onEnable Webhooks rerender with magic link
Nabhag8848 May 19, 2024
5783b34
fix: createSvix per account environment
Nabhag8848 May 19, 2024
bda3e5b
fix: fetch res which returns void
Nabhag8848 May 19, 2024
3bf275c
refactor(home): onboarding page
Nabhag8848 May 19, 2024
99ae297
refactor(Integrations): including fixed some errors
Nabhag8848 May 19, 2024
5c94a68
refactor(apiKey): dashboard to support env specific keys without fetc…
Nabhag8848 May 19, 2024
015d602
refactor(bar): Navbar
Nabhag8848 May 19, 2024
e46ff28
refactor(apiKeys): including keyContainers to handle overFlow
Nabhag8848 May 19, 2024
8408e7d
fix(spinner): to center the vh
Nabhag8848 May 19, 2024
2d650d2
refactor(analytics): dashboard
Nabhag8848 May 19, 2024
35f5d3c
fix: SvixProvider to get Current Env account
Nabhag8848 May 20, 2024
1c2a27f
fix(webhook): dashboard to generate links of specific env
Nabhag8848 May 20, 2024
9ead6ec
feat(webhooks): create and configure webhooks dashboard including spi…
Nabhag8848 May 20, 2024
4fab476
chore: remove unneccasry code
Nabhag8848 May 20, 2024
2490829
feat: success toast on Enabling Webhooks and Creating App
Nabhag8848 May 20, 2024
251b9a6
fix(toast): to position top-center
Nabhag8848 May 20, 2024
fa3f6b0
refactor(editcredentials): wip todo
Nabhag8848 May 21, 2024
a3cfd0f
fix: don't copy key to clipboard when visiblity is changed
Nabhag8848 May 21, 2024
1c14b71
fix: svixAppId to be environmentId
Nabhag8848 May 21, 2024
15f5222
fix: change svixAppId to envId - breaking changes
Nabhag8848 May 21, 2024
258cea0
fix: connection.created and deleted events to only fire when svixacco…
Nabhag8848 May 21, 2024
2972fae
fix: delete svixAccount on user.deleted
Nabhag8848 May 21, 2024
f7054f8
fix: deleting svix account to handle only delete which is existing
Nabhag8848 May 21, 2024
61874ad
fix: createSvix to have within service
Nabhag8848 May 21, 2024
e05e8f4
fix: getSvixAccount and createMagicLink to have under SvixService
Nabhag8848 May 21, 2024
1efd76e
fix: don't logError for svixAccountService which are mean App doesn't…
Nabhag8848 May 21, 2024
44fd7fd
fix: to have switch instead of button
Nabhag8848 May 22, 2024
562100a
fix: multiple calls for getMagicLink
Nabhag8848 May 22, 2024
4c0b099
fix: key error uuid
Nabhag8848 May 22, 2024
bde43bc
feat: to have CustomSwitch on center
Nabhag8848 May 22, 2024
9af61b6
chore: remove intercom appId
Nabhag8848 May 22, 2024
a048cb8
chore: improving dx by providing Intercom App Id provided by Intercom…
Nabhag8848 May 22, 2024
a215116
fix: switch to use mui
Nabhag8848 May 22, 2024
13414d1
Merge branch 'main' into feat/create-webhooks
Nabhag8848 Jun 6, 2024
51c2ebf
fix: svix account to not load on loading
Nabhag8848 Jun 6, 2024
c03e72e
Merge branch 'main' into feat/create-webhooks
Nabhag8848 Aug 6, 2024
7ea947f
fix: to include new integration dropdown
Nabhag8848 Aug 6, 2024
37a46c7
fix: svixAppId to use environmentId for new introduced categories int…
Nabhag8848 Aug 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion fern/definition/common/types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,11 @@ types:
AppConfig:
properties:
bot_token: optional<string>
org_url: optional<string>
org_url: optional<string>

SvixAccount:
properties:
uid: optional<string>
name: string
rateLimit: optional<integer>
id: string
60 changes: 55 additions & 5 deletions fern/definition/internal/account.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ types:
GetAccountDetailsResponse:
properties:
account: types.Account
SvixAccountResponse:
properties:
account: optional<types.SvixAccount>
exist: boolean
environment: optional<string>
SvixMagicLinkResponse:
properties:
key: string
environment: string

service:
base-path: /internal/account
Expand Down Expand Up @@ -54,16 +63,57 @@ service:
docs: create Revert App for Account
method: POST
path: /apps
request:
request:
name: CreateRevertAppForAccount
body:
properties:
body:
properties:
userId: string
tpId: types.TPID
environment: string
response: GetAccountDetailsResponse
errors:
errors:
- errors.UnAuthorizedError
- errors.InternalServerError
getSvixAccount:
docs: Get Svix Account
method: GET
path: /svix/{id}
path-parameters:
id: string
request:
name: getSvixAccount
query-parameters:
environment: string
response: SvixAccountResponse
errors:
- errors.UnAuthorizedError
- errors.InternalServerError
- errors.NotFoundError

createSvixAccount:
docs: Create Svix Account
method: POST
path: /svix
request:
name: createSvixAccount
body:
properties:
environment: string
accountId: string
response: SvixAccountResponse
errors:
- errors.UnAuthorizedError
- errors.InternalServerError
createSvixAccountMagicLink:
docs: Create Svix Account Consumer Panel MagicLink
method: POST
path: /svix/panel/link
request:
name: createSvixAccountPanelMagicLink
body:
properties:
appId: string
response: SvixMagicLinkResponse
errors:
- errors.UnAuthorizedError
- errors.InternalServerError
6 changes: 3 additions & 3 deletions packages/backend/helpers/crm/hubspot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const getAssociationObjects = async (
thirdPartyId: any,
connection: any,
account: any,
invalidAssociations: any
invalidAssociations: any,
) => {
const associatedData: any = {};

Expand Down Expand Up @@ -189,8 +189,8 @@ export const getAssociationObjects = async (
objType: associatedObjectType,
tenantSchemaMappingId: connection.schema_mapping_id,
accountFieldMappingConfig: account.accountFieldMappingConfig,
})
)
}),
),
));
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/backend/helpers/crm/transform/preprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export const preprocessUnifyObject = <T extends Record<string, any>>({
}: {
obj: T;
tpId: CRM_TP_ID | TICKET_TP_ID;
objType:StandardObjects
objType:
| StandardObjects
| ChatStandardObjects
| TicketStandardObjects
| AtsStandardObjects
Expand Down
10 changes: 6 additions & 4 deletions packages/backend/helpers/crm/transform/transformSchemaMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export const transformFieldMappingToModel = async ({
}: {
obj: any;
tpId: TP_ID;
objType: StandardObjects
objType:
| StandardObjects
| ChatStandardObjects
| TicketStandardObjects
| AtsStandardObjects
Expand Down Expand Up @@ -64,7 +65,7 @@ export const transformFieldMappingToModel = async ({
.filter((a: any) => a.objectName === objType)
.map((a: any) => a.fieldName)
.includes(field)
: accountFieldMappingConfig?.allow_connection_override_custom_fields))
: accountFieldMappingConfig?.allow_connection_override_custom_fields)),
) || rootSchema?.fieldMappings?.find((r) => r?.target_field_name === field);

const transformedKey = fieldMapping?.source_field_name;
Expand Down Expand Up @@ -93,7 +94,8 @@ export const transformModelToFieldMapping = async ({
}: {
unifiedObj: any;
tpId: TP_ID;
objType:StandardObjects
objType:
| StandardObjects
| ChatStandardObjects
| TicketStandardObjects
| AtsStandardObjects
Expand Down Expand Up @@ -123,7 +125,7 @@ export const transformModelToFieldMapping = async ({
.filter((a: any) => a.objectName === objType)
.map((a: any) => a.fieldName)
.includes(key)
: accountFieldMappingConfig?.allow_connection_override_custom_fields))
: accountFieldMappingConfig?.allow_connection_override_custom_fields)),
);
const rootFieldMapping = rootSchema?.fieldMappings?.filter((r) => r?.target_field_name === key);
const crmKey = tenantFieldMapping?.source_field_name;
Expand Down
3 changes: 2 additions & 1 deletion packages/backend/helpers/crm/transform/unify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export async function unifyObject<T extends Record<string, any>, K>({
}: {
obj: T;
tpId: CRM_TP_ID;
objType:StandardObjects
objType:
| StandardObjects
| ChatStandardObjects
| TicketStandardObjects
| AtsStandardObjects
Expand Down
24 changes: 22 additions & 2 deletions packages/backend/helpers/webhooks/connection.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import config from '../../config';

export default function sendConnectionAddedEvent(
// Warn: svixAppId is now including env that is environmentId -> ie: accoundId_environment (accountId_production)
export default async function sendConnectionAddedEvent(
svixAppId: string,
tenantId: string,
tp_id: string,
tp_access_token: string,
tp_customer_id: string
) {
try {
const isSvixAppExist = await getSvixAccount(svixAppId);
if (!isSvixAppExist) {
return;
}

config.svix?.message.create(svixAppId, {
eventType: 'connection.added',
payload: {
Expand All @@ -26,8 +32,12 @@ export default function sendConnectionAddedEvent(
}
}

export function sendConnectionDeletedEvent(svixAppId: string, connection: any) {
export async function sendConnectionDeletedEvent(svixAppId: string, connection: any) {
try {
const isSvixAppExist = await getSvixAccount(svixAppId);
if (!isSvixAppExist) {
return;
}
config.svix?.message.create(svixAppId, {
eventType: 'connection.deleted',
payload: {
Expand All @@ -40,3 +50,13 @@ export function sendConnectionDeletedEvent(svixAppId: string, connection: any) {
console.error('Error sending webhook event:', error);
}
}

export async function getSvixAccount(svixAppId: string) {
try {
const svixAccount = await config.svix?.application.get(svixAppId);
return svixAccount;
} catch (error) {
// probably svixAccount doesn't exist
return undefined;
}
}
6 changes: 3 additions & 3 deletions packages/backend/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ app.use(
skip: (req, _) => {
return req.originalUrl.startsWith('/health-check');
},
})
}),
);

app.use(versionMiddleware());
Expand Down Expand Up @@ -121,14 +121,14 @@ app.use(
manageRouterVersioning({
v1: indexRouter,
v2: testv2Router,
})
}),
);
app.use(
'/v1',
manageRouterVersioning({
v1: indexRouter,
v2: testv2Router,
})
}),
);
app.use(endpointLogger());
// The error handler must be before any other error middleware and after all controllers
Expand Down
Loading
Loading