0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

fix(core): compatibility for retries field in HookConfig (#3834)

This commit is contained in:
Xiao Yijun 2023-05-15 11:41:46 +08:00 committed by GitHub
parent ce5377d729
commit af02321ba2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 3 deletions

View file

@ -39,6 +39,10 @@ export const webhookDetailsParser = {
config: { config: {
url, url,
headers: headersObject, headers: headersObject,
/**
* This is for backward compatibility.
*/
retries: 3,
}, },
}; };
}, },

View file

@ -26,7 +26,7 @@ const hook: Hook = {
events: [HookEvent.PostSignIn], events: [HookEvent.PostSignIn],
signingKey: 'signing_key', signingKey: 'signing_key',
enabled: true, enabled: true,
config: { headers: { bar: 'baz' }, url }, config: { headers: { bar: 'baz' }, url, retries: 3 },
createdAt: Date.now() / 1000, createdAt: Date.now() / 1000,
}; };

View file

@ -78,7 +78,7 @@ export const createHookLibrary = (queries: Queries) => {
} satisfies Omit<HookEventPayload, 'hookId'>; } satisfies Omit<HookEventPayload, 'hookId'>;
await Promise.all( 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`); consoleLog.info(`\tTriggering hook ${id} due to ${hookEvent} event`);
const json: HookEventPayload = { hookId: id, ...payload }; const json: HookEventPayload = { hookId: id, ...payload };
const logEntry = new LogEntry(`TriggerHook.${hookEvent}`); const logEntry = new LogEntry(`TriggerHook.${hookEvent}`);
@ -90,7 +90,7 @@ export const createHookLibrary = (queries: Queries) => {
.post(url, { .post(url, {
headers: { 'user-agent': 'Logto (https://logto.io)', ...headers }, headers: { 'user-agent': 'Logto (https://logto.io)', ...headers },
json, json,
retry: { limit: 3 }, retry: { limit: retries },
timeout: { request: 10_000 }, timeout: { request: 10_000 },
}) })
.then(async (response) => { .then(async (response) => {

View file

@ -13,6 +13,7 @@ const createPayload = (event: HookEvent, url = 'not_work_url'): Partial<Hook> =>
config: { config: {
url, url,
headers: { foo: 'bar' }, headers: { foo: 'bar' },
retries: 3,
}, },
}); });

View file

@ -211,6 +211,13 @@ export const hookConfigGuard = z.object({
url: z.string(), url: z.string(),
/** Additional headers that attach to the request */ /** Additional headers that attach to the request */
headers: z.record(z.string()).optional(), 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<typeof hookConfigGuard>; export type HookConfig = z.infer<typeof hookConfigGuard>;