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:
parent
ce5377d729
commit
af02321ba2
5 changed files with 15 additions and 3 deletions
|
@ -39,6 +39,10 @@ export const webhookDetailsParser = {
|
||||||
config: {
|
config: {
|
||||||
url,
|
url,
|
||||||
headers: headersObject,
|
headers: headersObject,
|
||||||
|
/**
|
||||||
|
* This is for backward compatibility.
|
||||||
|
*/
|
||||||
|
retries: 3,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
|
@ -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,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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) => {
|
||||||
|
|
|
@ -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,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -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>;
|
||||||
|
|
Loading…
Reference in a new issue