Skip to content

Commit

Permalink
Feature/hubspot integration (#1123)
Browse files Browse the repository at this point in the history
Co-authored-by: Uroš Marolt <[email protected]>
Co-authored-by: garrrikkotua <[email protected]>
Co-authored-by: Gašper Grom <[email protected]>
  • Loading branch information
4 people authored Jul 26, 2023
1 parent afa3487 commit 76ccc3b
Show file tree
Hide file tree
Showing 152 changed files with 14,581 additions and 1,863 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/production-deploy-new.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ on:
description: Deploy search-sync-worker service?
required: true
type: boolean
deploy_integration_sync_worker:
description: Deploy integration-sync-worker service?
required: true
type: boolean

env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
Expand Down Expand Up @@ -41,6 +45,27 @@ jobs:
id: image
run: echo "IMAGE=${{ steps.image-builder.outputs.image }}" >> $GITHUB_OUTPUT

build-and-push-integration-sync-worker:
runs-on: ubuntu-latest
if: ${{ inputs.deploy_integration_sync_worker }}
outputs:
image: ${{ steps.image.outputs.IMAGE }}
defaults:
run:
shell: bash
steps:
- name: Check out repository code
uses: actions/checkout@v2

- uses: ./.github/actions/build-docker-image
id: image-builder
with:
image: integration-sync-worker

- name: Set docker image output
id: image
run: echo "IMAGE=${{ steps.image-builder.outputs.image }}" >> $GITHUB_OUTPUT

deploy-search-sync-worker:
needs: build-and-push-search-sync-worker
runs-on: ubuntu-latest
Expand All @@ -58,3 +83,21 @@ jobs:
service: search-sync-worker
image: ${{ needs.build-and-push-search-sync-worker.outputs.image }}
cluster: ${{ env.CROWD_CLUSTER }}

deploy-integration-sync-worker:
needs: build-and-push-integration-sync-worker
runs-on: ubuntu-latest
if: ${{ inputs.deploy_integration_sync_worker }}
defaults:
run:
shell: bash

steps:
- name: Check out repository code
uses: actions/checkout@v2

- uses: ./.github/actions/deploy-service
with:
service: integration-sync-worker
image: ${{ needs.build-and-push-integration-sync-worker.outputs.image }}
cluster: ${{ env.CROWD_CLUSTER }}
60 changes: 60 additions & 0 deletions .github/workflows/staging-deploy-integration-sync-worker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Staging Deploy Integration Sync Worker

on:
push:
branches:
- 'staging/**'
- 'staging-**'
paths:
- 'services/libs/**'
- 'services/apps/integration_sync_worker/**'

env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
CROWD_CLUSTER: ${{ secrets.STAGING_CLUSTER_NAME }}
CROWD_ROLE_ARN: ${{ secrets.STAGING_CLUSTER_ROLE_ARN }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
SLACK_CHANNEL: deploys-staging
SLACK_WEBHOOK: ${{ secrets.STAGING_SLACK_CHANNEL_HOOK }}

jobs:
build-and-push:
runs-on: ubuntu-latest
outputs:
image: ${{ steps.image.outputs.IMAGE }}
defaults:
run:
shell: bash

steps:
- name: Check out repository code
uses: actions/checkout@v2

- uses: ./.github/actions/build-docker-image
id: image-builder
with:
image: integration-sync-worker

- name: Set docker image output
id: image
run: echo "IMAGE=${{ steps.image-builder.outputs.image }}" >> $GITHUB_OUTPUT

deploy-integration-sync-worker:
needs: build-and-push
runs-on: ubuntu-latest
defaults:
run:
shell: bash

steps:
- name: Check out repository code
uses: actions/checkout@v2

- uses: ./.github/actions/deploy-service
with:
service: integration-sync-worker
image: ${{ needs.build-and-push.outputs.image }}
cluster: ${{ env.CROWD_CLUSTER }}
2 changes: 1 addition & 1 deletion backend/.env.dist.local
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ CROWD_STACKEXCHANGE_KEY=
# Nango settings
CROWD_NANGO_URL=http://localhost:3003
CROWD_NANGO_SECRET_KEY=424242
CROWD_NANGO_INTEGRATIONS=reddit,linkedin,stackexchange
CROWD_NANGO_INTEGRATIONS=reddit,linkedin,stackexchange,hubspot

# Cohere settings
CROWD_COHERE_API_KEY=
Expand Down
5 changes: 5 additions & 0 deletions backend/config/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@
"stackexchange": {
"key": "CROWD_STACKEXCHANGE_KEY"
},
"hubspot": {
"appId": "CROWD_HUBSPOT_APP_ID",
"clientId": "CROWD_HUBSPOT_CLIENT_ID",
"clientSecret": "CROWD_HUBSPOT_CLIENT_SECRET"
},
"nango": {
"url": "CROWD_NANGO_URL",
"secretKey": "CROWD_NANGO_SECRET_KEY"
Expand Down
9 changes: 9 additions & 0 deletions backend/src/api/integration/helpers/hubspotConnect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Permissions from '../../../security/permissions'
import IntegrationService from '../../../services/integrationService'
import PermissionChecker from '../../../services/user/permissionChecker'

export default async (req, res) => {
new PermissionChecker(req).validateHas(Permissions.values.tenantEdit)
const payload = await new IntegrationService(req).hubspotConnect()
await req.responseHandler.success(req, res, payload)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Permissions from '../../../security/permissions'
import IntegrationService from '../../../services/integrationService'
import PermissionChecker from '../../../services/user/permissionChecker'

export default async (req, res) => {
new PermissionChecker(req).validateHas(Permissions.values.tenantEdit)
const payload = await new IntegrationService(req).hubspotGetMappableFields()
await req.responseHandler.success(req, res, payload)
}
9 changes: 9 additions & 0 deletions backend/src/api/integration/helpers/hubspotOnboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Permissions from '../../../security/permissions'
import IntegrationService from '../../../services/integrationService'
import PermissionChecker from '../../../services/user/permissionChecker'

export default async (req, res) => {
new PermissionChecker(req).validateHas(Permissions.values.tenantEdit)
const payload = await new IntegrationService(req).hubspotOnboard(req.body)
await req.responseHandler.success(req, res, payload)
}
9 changes: 9 additions & 0 deletions backend/src/api/integration/helpers/hubspotStopSyncMember.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Permissions from '../../../security/permissions'
import IntegrationService from '../../../services/integrationService'
import PermissionChecker from '../../../services/user/permissionChecker'

export default async (req, res) => {
new PermissionChecker(req).validateHas(Permissions.values.integrationEdit)
const payload = await new IntegrationService(req).hubspotStopSyncMember(req.body)
await req.responseHandler.success(req, res, payload)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Permissions from '../../../security/permissions'
import IntegrationService from '../../../services/integrationService'
import PermissionChecker from '../../../services/user/permissionChecker'

export default async (req, res) => {
new PermissionChecker(req).validateHas(Permissions.values.integrationEdit)
const payload = await new IntegrationService(req).hubspotStopSyncOrganization(req.body)
await req.responseHandler.success(req, res, payload)
}
9 changes: 9 additions & 0 deletions backend/src/api/integration/helpers/hubspotSyncMember.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Permissions from '../../../security/permissions'
import IntegrationService from '../../../services/integrationService'
import PermissionChecker from '../../../services/user/permissionChecker'

export default async (req, res) => {
new PermissionChecker(req).validateHas(Permissions.values.integrationEdit)
const payload = await new IntegrationService(req).hubspotSyncMember(req.body)
await req.responseHandler.success(req, res, payload)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Permissions from '../../../security/permissions'
import IntegrationService from '../../../services/integrationService'
import PermissionChecker from '../../../services/user/permissionChecker'

export default async (req, res) => {
new PermissionChecker(req).validateHas(Permissions.values.integrationEdit)
const payload = await new IntegrationService(req).hubspotSyncOrganization(req.body)
await req.responseHandler.success(req, res, payload)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Permissions from '../../../security/permissions'
import IntegrationService from '../../../services/integrationService'
import PermissionChecker from '../../../services/user/permissionChecker'

export default async (req, res) => {
new PermissionChecker(req).validateHas(Permissions.values.tenantEdit)
const payload = await new IntegrationService(req).hubspotUpdateProperties()
await req.responseHandler.success(req, res, payload)
}
50 changes: 50 additions & 0 deletions backend/src/api/integration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import SegmentRepository from '../../database/repositories/segmentRepository'
import { authMiddleware } from '../../middlewares/authMiddleware'
import { safeWrap } from '../../middlewares/errorMiddleware'
import TenantService from '../../services/tenantService'
import { FeatureFlag } from '@/types/common'
import { featureFlagMiddleware } from '@/middlewares/featureFlagMiddleware'

export default (app) => {
app.post(`/tenant/:tenantId/integration/query`, safeWrap(require('./integrationQuery').default))
Expand Down Expand Up @@ -76,6 +78,54 @@ export default (app) => {
safeWrap(require('./helpers/discourseTestWebhook').default),
)

app.post(
'/tenant/:tenantId/hubspot-connect',
featureFlagMiddleware(FeatureFlag.HUBSPOT, 'hubspot.errors.notInPlan'),
safeWrap(require('./helpers/hubspotConnect').default),
)

app.post(
'/tenant/:tenantId/hubspot-onboard',
featureFlagMiddleware(FeatureFlag.HUBSPOT, 'hubspot.errors.notInPlan'),
safeWrap(require('./helpers/hubspotOnboard').default),
)

app.post(
'/tenant/:tenantId/hubspot-update-properties',
featureFlagMiddleware(FeatureFlag.HUBSPOT, 'hubspot.errors.notInPlan'),
safeWrap(require('./helpers/hubspotUpdateProperties').default),
)

app.get(
'/tenant/:tenantId/hubspot-mappable-fields',
featureFlagMiddleware(FeatureFlag.HUBSPOT, 'hubspot.errors.notInPlan'),
safeWrap(require('./helpers/hubspotGetMappableFields').default),
)

app.post(
'/tenant/:tenantId/hubspot-sync-member',
featureFlagMiddleware(FeatureFlag.HUBSPOT, 'hubspot.errors.notInPlan'),
safeWrap(require('./helpers/hubspotSyncMember').default),
)

app.post(
'/tenant/:tenantId/hubspot-stop-sync-member',
featureFlagMiddleware(FeatureFlag.HUBSPOT, 'hubspot.errors.notInPlan'),
safeWrap(require('./helpers/hubspotStopSyncMember').default),
)

app.post(
'/tenant/:tenantId/hubspot-sync-organization',
featureFlagMiddleware(FeatureFlag.HUBSPOT, 'hubspot.errors.notInPlan'),
safeWrap(require('./helpers/hubspotSyncOrganization').default),
)

app.post(
'/tenant/:tenantId/hubspot-stop-sync-organization',
featureFlagMiddleware(FeatureFlag.HUBSPOT, 'hubspot.errors.notInPlan'),
safeWrap(require('./helpers/hubspotStopSyncOrganization').default),
)

// if (TWITTER_CONFIG.clientId) {
// /**
// * Using the passport.authenticate this endpoint forces a
Expand Down
2 changes: 1 addition & 1 deletion backend/src/bin/jobs/downgradeExpiredPlans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const job: CrowdJob = {
log.info('Downgrading expired non-trial plans')
const expiredNonTrialTenants = await dbOptions.database.sequelize.query(
`select t.id, t.name from tenants t
where (t.plan = ${Plans.values.growth} or t.plan = ${Plans.values.eagleEye}) and t."planSubscriptionEndsAt" is not null and t."planSubscriptionEndsAt" + interval '3 days' < now()`,
where (t.plan = ${Plans.values.growth} or t.plan = ${Plans.values.eagleEye} or t.plan = ${Plans.values.scale}) and t."planSubscriptionEndsAt" is not null and t."planSubscriptionEndsAt" + interval '3 days' < now()`,
)

for (const tenant of expiredNonTrialTenants[0]) {
Expand Down
Loading

0 comments on commit 76ccc3b

Please sign in to comment.