@@ -15,6 +15,8 @@ import {
1515import { deleteTranslations , findSpaceById , findTranslations , findTranslationsHistory , spaceTranslationCachePath } from './services' ;
1616import { translateCloud , translateWithGoogle } from './services/translate.service' ;
1717import { canPerform } from './utils/user-auth-utils' ;
18+ import { triggerWebHooksForEvent } from './utils/webhook-utils' ;
19+ import { WebHookEvent , WebHookPayload } from './models/webhook.model' ;
1820
1921// Publish
2022const publish = onCall < PublishTranslationsData > ( async request => {
@@ -59,6 +61,13 @@ const publish = onCall<PublishTranslationsData>(async request => {
5961 createdAt : FieldValue . serverTimestamp ( ) ,
6062 } ;
6163 await findTranslationsHistory ( spaceId ) . add ( addHistory ) ;
64+ const webhookPayload : WebHookPayload = {
65+ event : WebHookEvent . TRANSLATION_PUBLISHED ,
66+ spaceId,
67+ timestamp : new Date ( ) . toISOString ( ) ,
68+ data : { } ,
69+ } ;
70+ await triggerWebHooksForEvent ( spaceId , webhookPayload ) ;
6271 return ;
6372 } else {
6473 logger . info ( `[translationsPublish] Space ${ spaceId } does not exist or no translations.` ) ;
@@ -257,6 +266,26 @@ const onWriteToHistory = onDocumentWritten('spaces/{spaceId}/translations/{trans
257266 addHistory . name = afterData . updatedBy . name ;
258267 }
259268 await findTranslationsHistory ( spaceId ) . add ( addHistory ) ;
269+
270+ // Trigger webhook based on operation type
271+ let webhookEvent : WebHookEvent | undefined ;
272+ if ( beforeData && afterData ) {
273+ webhookEvent = WebHookEvent . TRANSLATION_UPDATED ;
274+ } else if ( beforeData ) {
275+ webhookEvent = WebHookEvent . TRANSLATION_DELETED ;
276+ } else if ( afterData ) {
277+ webhookEvent = WebHookEvent . TRANSLATION_ADDED ;
278+ }
279+ if ( webhookEvent ) {
280+ const webhookPayload : WebHookPayload = {
281+ event : webhookEvent ,
282+ spaceId,
283+ timestamp : new Date ( ) . toISOString ( ) ,
284+ data : { translationId } ,
285+ } ;
286+ await triggerWebHooksForEvent ( spaceId , webhookPayload ) ;
287+ }
288+
260289 const countSnapshot = await findTranslationsHistory ( spaceId ) . count ( ) . get ( ) ;
261290 const { count } = countSnapshot . data ( ) ;
262291 if ( count > 30 ) {
0 commit comments