mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
f7fdfab6bf
Summary: Rework of endpoint GET for webhooks to make it coherent with other endpoints. Now data should be return in {webhooks:[{id:"...",fields:{"..."}]} format ``` { "webhooks": [ { "id": ... "fields": { "url": ... "unsubscribeKey": ... "eventTypes": [ "add", "update" ], "isReadyColumn": null, "tableId": "...", "enabled": false, "name": "...", "memo": "..." }, "usage": { "status": "idle", "numWaiting": 0, "lastEventBatch": null } }, { "id": "...", "fields": { "url": "...", "unsubscribeKey": "...", "eventTypes": [ "add", "update" ], "isReadyColumn": null, "tableId": "...", "enabled": true, "name": "...", "memo": "..." }, "usage": { "status": "error", "numWaiting": 0, "updatedTime": 1689076978098, "lastEventBatch": { "status": "rejected", "httpStatus": 404, "errorMessage": "{\"success\":false,\"error\":{\"message\":\"Alias 5a9bf6a8-4865-403a-bec6-b4ko not found\",\"id\":null}}", "size": 49, "attempts": 5 }, "lastSuccessTime": null, "lastFailureTime": 1689076978097, "lastErrorMessage": "{\"success\":false,\"error\":{\"message\":\"Alias 5a9bf6a8-4865-403a-bec6-b4ko not found\",\"id\":null}}", "lastHttpStatus": 404 } } ] } ``` Test Plan: new test added to check if GET data fromat is correct. Other tests fixed to handle changed endpoint. Reviewers: paulfitz Reviewed By: paulfitz Differential Revision: https://phab.getgrist.com/D3966
94 lines
2.2 KiB
TypeScript
94 lines
2.2 KiB
TypeScript
export interface WebhookSubscribeCollection{
|
|
webhooks: Array<Webhook>
|
|
}
|
|
|
|
export interface Webhook {
|
|
fields: WebhookFields;
|
|
}
|
|
|
|
export interface WebhookFields {
|
|
url: string;
|
|
eventTypes: Array<"add"|"update">;
|
|
tableId: string;
|
|
enabled?: boolean;
|
|
isReadyColumn?: string|null;
|
|
name?: string;
|
|
memo?: string;
|
|
}
|
|
|
|
// Union discriminated by type
|
|
export type WebhookBatchStatus = 'success'|'failure'|'rejected';
|
|
export type WebhookStatus = 'idle'|'sending'|'retrying'|'postponed'|'error'|'invalid';
|
|
|
|
|
|
// WebhookSubscribe should be `Omit<WebhookFields, 'tableId'>` (because subscribe endpoint read
|
|
// tableId from the url) but generics are not yet supported by ts-interface-builder
|
|
export interface WebhookSubscribe {
|
|
url: string;
|
|
eventTypes: Array<"add"|"update">;
|
|
enabled?: boolean;
|
|
isReadyColumn?: string|null;
|
|
name?: string;
|
|
memo?: string;
|
|
}
|
|
|
|
|
|
export interface WebhookSummaryCollection {
|
|
webhooks: Array<WebhookSummary>;
|
|
}
|
|
export interface WebhookSummary {
|
|
id: string;
|
|
fields: {
|
|
url: string;
|
|
unsubscribeKey: string;
|
|
eventTypes: string[];
|
|
isReadyColumn: string|null;
|
|
tableId: string;
|
|
enabled: boolean;
|
|
name: string;
|
|
memo: string;
|
|
},
|
|
usage: WebhookUsage|null,
|
|
}
|
|
|
|
// Describes fields to update a webhook
|
|
export interface WebhookUpdate {
|
|
id: string;
|
|
fields: WebhookPatch;
|
|
}
|
|
|
|
// WebhookPatch should be `Partial<WebhookFields>` but generics are not yet supported by
|
|
// ts-interface-builder
|
|
export interface WebhookPatch {
|
|
url?: string;
|
|
eventTypes?: Array<"add"|"update">;
|
|
tableId?: string;
|
|
enabled?: boolean;
|
|
isReadyColumn?: string|null;
|
|
name?: string;
|
|
memo?: string;
|
|
}
|
|
|
|
|
|
export interface WebhookUsage {
|
|
// As minimum we need number of waiting events and status (by default pending).
|
|
numWaiting: number,
|
|
status: WebhookStatus;
|
|
updatedTime?: number|null;
|
|
lastSuccessTime?: number|null;
|
|
lastFailureTime?: number|null;
|
|
lastErrorMessage?: string|null;
|
|
lastHttpStatus?: number|null;
|
|
lastEventBatch?: null | {
|
|
size: number;
|
|
errorMessage: string|null;
|
|
httpStatus: number|null;
|
|
status: WebhookBatchStatus;
|
|
attempts: number;
|
|
},
|
|
numSuccess?: {
|
|
pastHour: number;
|
|
past24Hours: number;
|
|
},
|
|
}
|