mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Adds endpoint to update webhook
Summary: Adds a new endpoint to update webhook. Perform some refactoring to allow code reuse from endpoint allowing to _subscribe and _unsubscribe webhooks. One aspect of webhook is that url are stored in the home db while the rest of the fields (tableRef, isReadyColRef, ...) are stored in sqlite. So care must be taken when updating fields, to properly rollback if anything should fail. Follow up diff will bring UI to edit webhook list Test Plan: Updated doc api server tests Reviewers: jarek Reviewed By: jarek Subscribers: paulfitz Differential Revision: https://phab.getgrist.com/D3821
This commit is contained in:
41
app/common/Triggers-ti.ts
Normal file
41
app/common/Triggers-ti.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* This module was automatically generated by `ts-interface-builder`
|
||||
*/
|
||||
import * as t from "ts-interface-checker";
|
||||
// tslint:disable:object-literal-key-quotes
|
||||
|
||||
export const WebhookFields = t.iface([], {
|
||||
"url": "string",
|
||||
"eventTypes": t.array(t.union(t.lit("add"), t.lit("update"))),
|
||||
"tableId": "string",
|
||||
"enabled": t.opt("boolean"),
|
||||
"isReadyColumn": t.opt(t.union("string", "null")),
|
||||
});
|
||||
|
||||
export const WebhookSubscribe = t.iface([], {
|
||||
"url": "string",
|
||||
"eventTypes": t.array(t.union(t.lit("add"), t.lit("update"))),
|
||||
"enabled": t.opt("boolean"),
|
||||
"isReadyColumn": t.opt(t.union("string", "null")),
|
||||
});
|
||||
|
||||
export const WebhookUpdate = t.iface([], {
|
||||
"id": "string",
|
||||
"fields": "WebhookPatch",
|
||||
});
|
||||
|
||||
export const WebhookPatch = t.iface([], {
|
||||
"url": t.opt("string"),
|
||||
"eventTypes": t.opt(t.array(t.union(t.lit("add"), t.lit("update")))),
|
||||
"tableId": t.opt("string"),
|
||||
"enabled": t.opt("boolean"),
|
||||
"isReadyColumn": t.opt(t.union("string", "null")),
|
||||
});
|
||||
|
||||
const exportedTypeSuite: t.ITypeSuite = {
|
||||
WebhookFields,
|
||||
WebhookSubscribe,
|
||||
WebhookUpdate,
|
||||
WebhookPatch,
|
||||
};
|
||||
export default exportedTypeSuite;
|
||||
32
app/common/Triggers.ts
Normal file
32
app/common/Triggers.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
export interface WebhookFields {
|
||||
url: string;
|
||||
eventTypes: Array<"add"|"update">;
|
||||
tableId: string;
|
||||
enabled?: boolean;
|
||||
isReadyColumn?: string|null;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import {OrgPrefs, UserOrgPrefs, UserPrefs} from 'app/common/Prefs';
|
||||
import * as roles from 'app/common/roles';
|
||||
import {addCurrentOrgToPath} from 'app/common/urlUtils';
|
||||
import {encodeQueryParams} from 'app/common/gutil';
|
||||
import {WebhookUpdate} from 'app/common/Triggers';
|
||||
|
||||
export type {FullUser, UserProfile};
|
||||
|
||||
@@ -451,6 +452,9 @@ export interface DocAPI {
|
||||
|
||||
// Get users that are worth proposing to "View As" for access control purposes.
|
||||
getUsersForViewAs(): Promise<PermissionDataWithExtraUsers>;
|
||||
|
||||
// Update webhook
|
||||
updateWebhook(webhook: WebhookUpdate): Promise<void>;
|
||||
}
|
||||
|
||||
// Operations that are supported by a doc worker.
|
||||
@@ -900,6 +904,13 @@ export class DocAPIImpl extends BaseAPI implements DocAPI {
|
||||
return this.requestJson(`${this._url}/usersForViewAs`);
|
||||
}
|
||||
|
||||
public async updateWebhook(webhook: WebhookUpdate): Promise<void> {
|
||||
return this.requestJson(`${this._url}/webhooks/${webhook.id}`, {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify(webhook.fields),
|
||||
});
|
||||
}
|
||||
|
||||
public async forceReload(): Promise<void> {
|
||||
await this.request(`${this._url}/force-reload`, {
|
||||
method: 'POST'
|
||||
|
||||
Reference in New Issue
Block a user