gristlabs_grist-core/app/gen-server/migration
Alex Hall 3c4d71aeca (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
2021-09-23 14:35:39 +02:00
..
1536634251710-Initial.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1539031763952-Login.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1549313797109-PinDocs.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1549381727494-UserPicture.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1551805156919-LoginDisplayEmail.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1552416614755-LoginDisplayEmailNonNull.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1553016106336-Indexes.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1556726945436-Billing.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1557157922339-OrgDomainUnique.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1561589211752-Aliases.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1568238234987-TeamMembers.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1569593726320-FirstLogin.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1569946508569-FirstTimeUser.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1573569442552-CustomerIndex.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1579559983067-ExtraIndexes.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1591755411755-OrgHost.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1592261300044-DocRemovedAt.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1596456522124-Prefs.ts (core) add per-user per-org preferences to database 2020-08-04 15:20:13 -04:00
1623871765992-ExternalBilling.ts (core) add appsumo endpoints with stub implementations 2021-06-21 16:04:33 -04:00
1626369037484-DocOptions.ts (core) add docs.options column to home db to store doc description, icon, openMode 2021-07-15 21:51:05 -04:00
1631286208009-Secret.ts (core) Initial webhooks implementation 2021-09-23 14:35:39 +02:00