@canopy-io/node 0.3.5 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/README.md +26 -0
- package/dist/index.cjs +6 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +828 -3
- package/dist/index.d.ts +828 -3
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @canopy-io/node
|
|
2
2
|
|
|
3
|
+
## 0.3.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 703377c: `organization.deleted` and `organization.deleted_all` webhook deliveries now type `domains_released`, `sso_bindings_removed` and `sso_connections_removed`: deleting an organization releases its email-domain claims, its SSO binding and any connection it owned.
|
|
8
|
+
|
|
9
|
+
## 0.3.6
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 0708712: Typed webhook deliveries.
|
|
14
|
+
|
|
15
|
+
- Canopy now publishes a schema per webhook event, and the types are regenerated from it: 37 `Webhook…Event` schemas on the shared envelope, plus `payload_schema` and `resource_types` on `GET /api/v1/webhooks/event-types`. No operation was added or removed.
|
|
16
|
+
- New `WebhookDelivery`, `WebhookEventName`, `WebhookEvent<Name>` and `WebhookEventData<Name>` types, and an `isWebhookEvent(delivery, name)` guard, so a handler reads one event's `metadata` without a cast.
|
|
17
|
+
- `metadata` is now always an object on every delivery.
|
|
18
|
+
|
|
3
19
|
## 0.3.5
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -169,6 +169,32 @@ const { token, base_url } = await canopy.organizations.mintDirectoryToken(
|
|
|
169
169
|
);
|
|
170
170
|
```
|
|
171
171
|
|
|
172
|
+
### Handling webhooks
|
|
173
|
+
|
|
174
|
+
Every webhook event has a published schema, and the SDK types deliveries from
|
|
175
|
+
it. Narrow by event name and read that event's `metadata` without a cast; a
|
|
176
|
+
field the API adds arrives with the next `npm run generate`.
|
|
177
|
+
|
|
178
|
+
```ts
|
|
179
|
+
import { isWebhookEvent, type WebhookDelivery } from "@canopy-io/node";
|
|
180
|
+
|
|
181
|
+
app.post("/webhooks/canopy", (req, res) => {
|
|
182
|
+
const delivery = req.body as WebhookDelivery;
|
|
183
|
+
|
|
184
|
+
if (isWebhookEvent(delivery, "organization.member.added")) {
|
|
185
|
+
const { identity_id, role_id } = delivery.data.metadata;
|
|
186
|
+
// ...
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
res.sendStatus(204);
|
|
190
|
+
});
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
`WebhookEvent<"assignment.updated">` is the delivery of one event, and
|
|
194
|
+
`WebhookEventName` is every event a subscription can receive. The API's
|
|
195
|
+
`GET /api/v1/webhooks/event-types` names each event's schema in
|
|
196
|
+
`payload_schema`.
|
|
197
|
+
|
|
172
198
|
### Authorizing without a call per request
|
|
173
199
|
|
|
174
200
|
Asking "may this identity act _here_" on every request puts Canopy in your
|
package/dist/index.cjs
CHANGED
|
@@ -1606,6 +1606,11 @@ var TokenVerifier = class {
|
|
|
1606
1606
|
}
|
|
1607
1607
|
};
|
|
1608
1608
|
|
|
1609
|
+
// src/webhooks.ts
|
|
1610
|
+
function isWebhookEvent(delivery, name) {
|
|
1611
|
+
return delivery.event === name;
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1609
1614
|
exports.Assignments = Assignments;
|
|
1610
1615
|
exports.Canopy = Canopy;
|
|
1611
1616
|
exports.CanopyAuthorizerError = CanopyAuthorizerError;
|
|
@@ -1625,6 +1630,7 @@ exports.isCanopyConnectionError = isCanopyConnectionError;
|
|
|
1625
1630
|
exports.isCanopyError = isCanopyError;
|
|
1626
1631
|
exports.isCanopyTokenError = isCanopyTokenError;
|
|
1627
1632
|
exports.isCursorPagination = isCursorPagination;
|
|
1633
|
+
exports.isWebhookEvent = isWebhookEvent;
|
|
1628
1634
|
exports.orgContext = orgContext;
|
|
1629
1635
|
exports.paginate = paginate;
|
|
1630
1636
|
exports.withConcurrency = withConcurrency;
|