Skip to content

Commit

Permalink
Merge branch 'activepieces:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
obenazouz-wedof authored Aug 13, 2024
2 parents 9a45c1d + 99c1e18 commit d6f8240
Show file tree
Hide file tree
Showing 21 changed files with 292 additions and 289 deletions.
9 changes: 4 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "activepieces",
"version": "0.29.1",
"rcVersion": "0.30.0-rc.4",
"rcVersion": "0.30.0-rc.5",
"scripts": {
"prepare": "husky install",
"serve:frontend": "nx serve ui-core",
Expand Down Expand Up @@ -71,7 +71,7 @@
"@segment/analytics-node": "2.1.0",
"@sendgrid/mail": "8.0.0",
"@sentry/node": "7.64.0",
"@sinclair/typebox": "0.31.28",
"@sinclair/typebox": "0.32.35",
"@slack/web-api": "7.0.4",
"@socket.io/redis-adapter": "8.2.1",
"@supabase/supabase-js": "2.33.1",
Expand Down
1 change: 1 addition & 0 deletions packages/ee/shared/src/lib/audit-events/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const BaseAuditEventProps = {
...BaseModelSchema,
platformId: Type.String(),
projectId: Type.Optional(Type.String()),
projectDisplayName: Type.Optional(Type.String()),
userId: Type.Optional(Type.String()),
userEmail: Type.Optional(Type.String()),
ip: Type.Optional(Type.String()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import { JobType, LATEST_JOB_DATA_SCHEMA_VERSION, logger, rejectedPromiseHandler
import {
ActivepiecesError, ALL_PRINCIPAL_TYPES,
apId,
assertNotNullOrUndefined,
ErrorCode,
isNil,
} from '@activepieces/shared'
import { FastifyPluginAsyncTypebox } from '@fastify/type-provider-typebox'
import { FastifyRequest } from 'fastify'
import { flowQueue } from '../workers/queue'
import { StatusCodes } from 'http-status-codes'
import { DEFAULT_PRIORITY } from '../workers/queue/queue-manager'
import { appEventRoutingService } from './app-event-routing.service'

Expand All @@ -22,7 +23,6 @@ const appWebhooks: Record<string, Piece> = {
'facebook-leads': facebookLeads,
intercom,
}

const pieceNames: Record<string, string> = {
slack: '@activepieces/piece-slack',
square: '@activepieces/piece-square',
Expand All @@ -44,7 +44,6 @@ export const appEventRoutingController: FastifyPluginAsyncTypebox = async (
rawBody: true,
allowedPrincipals: ALL_PRINCIPAL_TYPES,
},
logLevel: 'silent',
},
async (
request: FastifyRequest<{
Expand All @@ -56,7 +55,7 @@ export const appEventRoutingController: FastifyPluginAsyncTypebox = async (
requestReply,
) => {
const pieceUrl = request.params.pieceUrl
const eventPayload = {
const payload = {
headers: request.headers as Record<string, string>,
body: request.body,
rawBody: request.rawBody,
Expand All @@ -74,42 +73,46 @@ export const appEventRoutingController: FastifyPluginAsyncTypebox = async (
},
})
}
const pieceName = pieceNames[pieceUrl]
const { reply, event, identifierValue } = piece.events!.parseAndReply({
payload: eventPayload,
})

logger.debug(
`Received event ${event} with identifier ${identifierValue} in app ${pieceName}`,
)
if (event && identifierValue) {
const listeners = await appEventRoutingService.listListeners({
appName: pieceName,
event,
identifierValue,
})
rejectedPromiseHandler(Promise.all(listeners.map(async (listener) => {
const requestId = apId()
await flowQueue.add({
id: requestId,
type: JobType.WEBHOOK,
data: {
projectId: listener.projectId,
schemaVersion: LATEST_JOB_DATA_SCHEMA_VERSION,
requestId,
synchronousHandlerId: null,
payload: eventPayload,
flowId: listener.flowId,
simulate: false,
},
priority: DEFAULT_PRIORITY,
})
})))
const appName = pieceNames[pieceUrl]
assertNotNullOrUndefined(piece.events, 'Event is possible in this piece')
const { reply, event, identifierValue } = piece.events.parseAndReply({ payload })
if (!isNil(reply)) {
logger.info({
reply,
piece: pieceUrl,
}, '[AppEventRoutingController#event] reply')
return requestReply.status(StatusCodes.OK).headers(reply?.headers ?? {}).send(reply?.body ?? {})
}
return requestReply
.status(200)
.headers(reply?.headers ?? {})
.send(reply?.body ?? {})
},
)
logger.info({
event,
identifierValue,
}, '[AppEventRoutingController#event] event')
if (isNil(event) || isNil(identifierValue)) {
return requestReply.status(StatusCodes.BAD_REQUEST).send({})
}
const listeners = await appEventRoutingService.listListeners({
appName,
event,
identifierValue,
})
const eventsQueue = listeners.map(async (listener) => {
const requestId = apId()
return {
id: requestId,
type: JobType.WEBHOOK,
data: {
projectId: listener.projectId,
schemaVersion: LATEST_JOB_DATA_SCHEMA_VERSION,
requestId,
synchronousHandlerId: null,
payload,
flowId: listener.flowId,
simulate: false,
},
priority: DEFAULT_PRIORITY,
}
})
rejectedPromiseHandler(Promise.all(eventsQueue))
return requestReply.status(StatusCodes.OK).send({})
})
}
5 changes: 1 addition & 4 deletions packages/server/api/src/app/copilot/copilot.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ export const copilotModule: FastifyPluginAsyncTypebox = async () => {
websocketService.addListener(WebsocketServerEvent.GENERATE_CODE, (socket) => {
return async (data: GenerateCodeRequest) => {
const { prompt, previousContext } = data
const result = await copilotService.generateCode({ prompt, previousContext })
const response: GenerateCodeResponse = {
result,
}
const response: GenerateCodeResponse = await copilotService.generateCode({ prompt, previousContext })
socket.emit(WebsocketClientEvent.GENERATE_CODE_FINISHED, response)
}
})
Expand Down
Loading

0 comments on commit d6f8240

Please sign in to comment.