diff --git a/packages/console/src/pages/WebhookDetails/utils.ts b/packages/console/src/pages/WebhookDetails/utils.ts index 49fc3225c..84a134e55 100644 --- a/packages/console/src/pages/WebhookDetails/utils.ts +++ b/packages/console/src/pages/WebhookDetails/utils.ts @@ -39,6 +39,10 @@ export const webhookDetailsParser = { config: { url, headers: headersObject, + /** + * This is for backward compatibility. + */ + retries: 3, }, }; }, diff --git a/packages/core/src/libraries/hook.test.ts b/packages/core/src/libraries/hook.test.ts index 723dde4c7..5657e87a7 100644 --- a/packages/core/src/libraries/hook.test.ts +++ b/packages/core/src/libraries/hook.test.ts @@ -26,7 +26,7 @@ const hook: Hook = { events: [HookEvent.PostSignIn], signingKey: 'signing_key', enabled: true, - config: { headers: { bar: 'baz' }, url }, + config: { headers: { bar: 'baz' }, url, retries: 3 }, createdAt: Date.now() / 1000, }; diff --git a/packages/core/src/libraries/hook.ts b/packages/core/src/libraries/hook.ts index fbee0cf53..27d5d5248 100644 --- a/packages/core/src/libraries/hook.ts +++ b/packages/core/src/libraries/hook.ts @@ -78,7 +78,7 @@ export const createHookLibrary = (queries: Queries) => { } satisfies Omit; await Promise.all( - rows.map(async ({ config: { url, headers }, id }) => { + rows.map(async ({ config: { url, headers, retries }, id }) => { consoleLog.info(`\tTriggering hook ${id} due to ${hookEvent} event`); const json: HookEventPayload = { hookId: id, ...payload }; const logEntry = new LogEntry(`TriggerHook.${hookEvent}`); @@ -90,7 +90,7 @@ export const createHookLibrary = (queries: Queries) => { .post(url, { headers: { 'user-agent': 'Logto (https://logto.io)', ...headers }, json, - retry: { limit: 3 }, + retry: { limit: retries }, timeout: { request: 10_000 }, }) .then(async (response) => { diff --git a/packages/integration-tests/src/tests/api/hooks.test.ts b/packages/integration-tests/src/tests/api/hooks.test.ts index 0b00e7a92..5e0981fbd 100644 --- a/packages/integration-tests/src/tests/api/hooks.test.ts +++ b/packages/integration-tests/src/tests/api/hooks.test.ts @@ -13,6 +13,7 @@ const createPayload = (event: HookEvent, url = 'not_work_url'): Partial => config: { url, headers: { foo: 'bar' }, + retries: 3, }, }); diff --git a/packages/schemas/src/foundations/jsonb-types.ts b/packages/schemas/src/foundations/jsonb-types.ts index 109756d3d..f16e014c9 100644 --- a/packages/schemas/src/foundations/jsonb-types.ts +++ b/packages/schemas/src/foundations/jsonb-types.ts @@ -211,6 +211,13 @@ export const hookConfigGuard = z.object({ url: z.string(), /** Additional headers that attach to the request */ headers: z.record(z.string()).optional(), + /** + * @deprecated + * Retry times when hook response status >= 500. + * Now the retry times is fixed to 3. + * Keep for backward compatibility. + */ + retries: z.number().gte(0).lte(3), }); export type HookConfig = z.infer;