@crowdin/app-project-module 0.98.0-cf-7 → 0.98.0-cf-9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -64,22 +64,37 @@ function webhookHandler(config, webhooks) {
|
|
|
64
64
|
res.status(403).send({ error: 'Invalid signature' });
|
|
65
65
|
return;
|
|
66
66
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
67
|
+
const shouldDeferResponse = webhooks.some((webhook) => webhook.key === moduleKey && webhook.deferResponse);
|
|
68
|
+
if (!shouldDeferResponse) {
|
|
69
|
+
res.status(200).send();
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
const { client } = yield (0, connection_1.prepareCrowdinClient)({ config, credentials, autoRenew: true });
|
|
73
|
+
const json = JSON.parse(req.body.toString());
|
|
74
|
+
for (const webhook of webhooks) {
|
|
75
|
+
if (webhook.key === moduleKey) {
|
|
76
|
+
yield webhook.callback({
|
|
77
|
+
events: json.events,
|
|
78
|
+
client,
|
|
79
|
+
webhookContext: {
|
|
80
|
+
domain: credentials.domain,
|
|
81
|
+
organizationId: credentials.organizationId,
|
|
82
|
+
userId: credentials.userId,
|
|
83
|
+
agentId: credentials.agentId,
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (!shouldDeferResponse) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
res.status(200).send();
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
if (!shouldDeferResponse) {
|
|
95
|
+
throw error;
|
|
82
96
|
}
|
|
97
|
+
res.status(500).send({ error: 'Webhook processing failed' });
|
|
83
98
|
}
|
|
84
99
|
}));
|
|
85
100
|
}
|
|
@@ -13,6 +13,13 @@ export interface Webhook extends ModuleKey {
|
|
|
13
13
|
events: Event[];
|
|
14
14
|
client: Crowdin;
|
|
15
15
|
}) => Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* If true, response will be sent after webhook processing is complete.
|
|
18
|
+
* This is required for Cloudflare Workers where the execution context
|
|
19
|
+
* terminates after the response is sent.
|
|
20
|
+
* Default: false (response is sent immediately after signature verification)
|
|
21
|
+
*/
|
|
22
|
+
deferResponse?: boolean;
|
|
16
23
|
}
|
|
17
24
|
interface WebhookContext {
|
|
18
25
|
domain?: string;
|
package/package.json
CHANGED