@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.
@@ -5,11 +5,11 @@ export interface AiProviderModule extends Environments, ModuleKey {
5
5
  /**
6
6
  * module name
7
7
  */
8
- name: string;
8
+ name?: string;
9
9
  /**
10
10
  * module description
11
11
  */
12
- description: string;
12
+ description?: string;
13
13
  /**
14
14
  * Settings UI module
15
15
  */
@@ -64,22 +64,37 @@ function webhookHandler(config, webhooks) {
64
64
  res.status(403).send({ error: 'Invalid signature' });
65
65
  return;
66
66
  }
67
- res.status(200).send();
68
- const { client } = yield (0, connection_1.prepareCrowdinClient)({ config, credentials, autoRenew: true });
69
- const json = JSON.parse(req.body.toString());
70
- for (const webhook of webhooks) {
71
- if (webhook.key === moduleKey) {
72
- yield webhook.callback({
73
- events: json.events,
74
- client,
75
- webhookContext: {
76
- domain: credentials.domain,
77
- organizationId: credentials.organizationId,
78
- userId: credentials.userId,
79
- agentId: credentials.agentId,
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdin/app-project-module",
3
- "version": "0.98.0-cf-7",
3
+ "version": "0.98.0-cf-9",
4
4
  "description": "Module that generates for you all common endpoints for serving standalone Crowdin App",
5
5
  "main": "out/index.js",
6
6
  "types": "out/index.d.ts",