mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Initial webhooks implementation
Summary: See https://grist.quip.com/VKd3ASF99ezD/Outgoing-Webhooks - 2 new DocApi endpoints: _subscribe and _unsubscribe, not meant to be user friendly or publicly documented. _unsubscribe should be given the response from _subscribe in the body, e.g: ``` $ curl -X POST -H "Authorization: Bearer 8fd4dc59ecb05ab29ae5a183c03101319b8e6ca9" "http://localhost:8080/api/docs/6WYa23FqWxGNe3AR6DLjCJ/tables/Table2/_subscribe" -H "Content-type: application/json" -d '{"url": "https://webhook.site/a916b526-8afc-46e6-aa8f-a625d0d83ec3", "eventTypes": ["add"], "isReadyColumn": "C"}' {"unsubscribeKey":"3246f158-55b5-4fc7-baa5-093b75ffa86c","triggerId":2,"webhookId":"853b4bfa-9d39-4639-aa33-7d45354903c0"} $ curl -X POST -H "Authorization: Bearer 8fd4dc59ecb05ab29ae5a183c03101319b8e6ca9" "http://localhost:8080/api/docs/6WYa23FqWxGNe3AR6DLjCJ/tables/Table2/_unsubscribe" -H "Content-type: application/json" -d '{"unsubscribeKey":"3246f158-55b5-4fc7-baa5-093b75ffa86c","triggerId":2,"webhookId":"853b4bfa-9d39-4639-aa33-7d45354903c0"}' {"success":true} ``` - New DB entity Secret to hold the webhook URL and unsubscribe key - New document metatable _grist_Triggers subscribes to table changes and points to a secret to use for a webhook - New file Triggers.ts processes action summaries and uses the two new tables to send webhooks. - Also went on a bit of a diversion and made a typesafe subclass of TableData for metatables. I think this is essentially good enough for a first diff, to keep the diffs manageable and to talk about the overall structure. Future diffs can add tests and more robustness using redis etc. After this diff I can also start building the Zapier integration privately. Test Plan: Tested manually: see curl commands in summary for an example. Payloads can be seen in https://webhook.site/#!/a916b526-8afc-46e6-aa8f-a625d0d83ec3/0b9fe335-33f7-49fe-b90b-2db5ba53382d/1 . Great site for testing webhooks btw. Reviewers: dsagal, paulfitz Reviewed By: paulfitz Differential Revision: https://phab.getgrist.com/D3019
This commit is contained in:
@@ -13,6 +13,7 @@ _ts_types = {
|
||||
"PositionNumber": "number",
|
||||
"Ref": "number",
|
||||
"RefList": "['L', ...number[]]|null", # Non-primitive values are encoded
|
||||
"ChoiceList": "['L', ...string[]]|null",
|
||||
"Text": "string",
|
||||
}
|
||||
|
||||
|
||||
@@ -795,3 +795,15 @@ def migration23(tdset):
|
||||
add_column('_grist_DocInfo', 'documentSettings', 'Text'),
|
||||
actions.UpdateRecord('_grist_DocInfo', 1, {'documentSettings': '{"locale":"en-US"}'})
|
||||
])
|
||||
|
||||
|
||||
@migration(schema_version=24)
|
||||
def migration24(tdset):
|
||||
return tdset.apply_doc_actions([
|
||||
actions.AddTable('_grist_Triggers', [
|
||||
schema.make_column("tableRef", "Ref:_grist_Tables"),
|
||||
schema.make_column("eventTypes", "ChoiceList"),
|
||||
schema.make_column("isReadyColRef", "Ref:_grist_Tables_column"),
|
||||
schema.make_column("actions", "Text"), # JSON
|
||||
]),
|
||||
])
|
||||
|
||||
@@ -15,7 +15,7 @@ import six
|
||||
|
||||
import actions
|
||||
|
||||
SCHEMA_VERSION = 23
|
||||
SCHEMA_VERSION = 24
|
||||
|
||||
def make_column(col_id, col_type, formula='', isFormula=False):
|
||||
return {
|
||||
@@ -236,6 +236,14 @@ def schema_create_actions():
|
||||
]),
|
||||
|
||||
|
||||
# Triggers subscribing to changes in tables
|
||||
actions.AddTable("_grist_Triggers", [
|
||||
make_column("tableRef", "Ref:_grist_Tables"),
|
||||
make_column("eventTypes", "ChoiceList"),
|
||||
make_column("isReadyColRef", "Ref:_grist_Tables_column"),
|
||||
make_column("actions", "Text"), # JSON
|
||||
]),
|
||||
|
||||
# All of the ACL rules.
|
||||
actions.AddTable('_grist_ACLRules', [
|
||||
make_column('resource', 'Ref:_grist_ACLResources'),
|
||||
|
||||
Reference in New Issue
Block a user