Skip to content

Commit 772d0c6

Browse files
mattvagnijordrake
andauthored
Webhook target support (#104)
* Add support for webhook targets * Add changeset * Fix type error * fix * Fix EOF lines --------- Co-authored-by: Jordan Drake <jordan@plain.com>
1 parent 2ebf671 commit 772d0c6

File tree

11 files changed

+399
-831
lines changed

11 files changed

+399
-831
lines changed

.changeset/hot-bags-boil.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@team-plain/typescript-sdk': minor
3+
---
4+
5+
Add support for creating, updating, deleting and fetcing webhook targets.

src/client.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
CreateCustomerEventDocument,
1515
CreateThreadDocument,
1616
CreateThreadEventDocument,
17+
CreateWebhookTargetDocument,
1718
CustomerByEmailDocument,
1819
CustomerByIdDocument,
1920
type CustomerCardConfigPartsFragment,
@@ -26,6 +27,7 @@ import {
2627
CustomersDocument,
2728
DeleteCustomerCardConfigDocument,
2829
DeleteCustomerDocument,
30+
DeleteWebhookTargetDocument,
2931
type EmailPartsFragment,
3032
type LabelPartsFragment,
3133
LabelTypeDocument,
@@ -49,10 +51,14 @@ import {
4951
ThreadsDocument,
5052
UnassignThreadDocument,
5153
UpdateCustomerCardConfigDocument,
54+
UpdateWebhookTargetDocument,
5255
UpsertCustomerDocument,
5356
type UpsertResult,
5457
UserByEmailDocument,
5558
type UserPartsFragment,
59+
WebhookTargetDocument,
60+
type WebhookTargetPartsFragment,
61+
WebhookTargetsDocument,
5662
type WorkspacePartsFragment,
5763
} from './graphql/types';
5864
import { request } from './request';
@@ -729,4 +735,74 @@ export class PlainClient {
729735

730736
return unwrapData(res, (q) => nonNullable(q.createThreadEvent.threadEvent));
731737
}
738+
739+
async createWebhookTarget(
740+
input: VariablesOf<typeof CreateWebhookTargetDocument>['input']
741+
): SDKResult<WebhookTargetPartsFragment> {
742+
const res = await request(this.#ctx, {
743+
query: CreateWebhookTargetDocument,
744+
variables: {
745+
input,
746+
},
747+
});
748+
749+
return unwrapData(res, (q) => nonNullable(q.createWebhookTarget.webhookTarget));
750+
}
751+
752+
async updateWebhookTarget(
753+
input: VariablesOf<typeof UpdateWebhookTargetDocument>['input']
754+
): SDKResult<WebhookTargetPartsFragment> {
755+
const res = await request(this.#ctx, {
756+
query: UpdateWebhookTargetDocument,
757+
variables: {
758+
input,
759+
},
760+
});
761+
762+
return unwrapData(res, (q) => nonNullable(q.updateWebhookTarget.webhookTarget));
763+
}
764+
765+
async deleteWebhookTarget(
766+
input: VariablesOf<typeof DeleteWebhookTargetDocument>['input']
767+
): SDKResult<null> {
768+
const res = await request(this.#ctx, {
769+
query: DeleteWebhookTargetDocument,
770+
variables: {
771+
input,
772+
},
773+
});
774+
775+
return unwrapData(res, () => null);
776+
}
777+
778+
async getWebhookTargets(variables: VariablesOf<typeof WebhookTargetsDocument>): SDKResult<{
779+
webhookTargets: WebhookTargetPartsFragment[];
780+
pageInfo: PageInfoPartsFragment;
781+
}> {
782+
const res = await request(this.#ctx, {
783+
query: WebhookTargetsDocument,
784+
variables,
785+
});
786+
787+
return unwrapData(res, (q) => ({
788+
pageInfo: q.webhookTargets.pageInfo,
789+
webhookTargets: q.webhookTargets.edges.map((edge) => edge.node),
790+
}));
791+
}
792+
793+
/**
794+
* If the webhook target is not found it will return null
795+
*/
796+
async getWebhookTargetById(
797+
variables: VariablesOf<typeof WebhookTargetDocument>
798+
): SDKResult<WebhookTargetPartsFragment | null> {
799+
const res = await request(this.#ctx, {
800+
query: WebhookTargetDocument,
801+
variables,
802+
});
803+
804+
return unwrapData(res, (q) => {
805+
return q.webhookTarget;
806+
});
807+
}
732808
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fragment WebhookTargetEventSubscriptionParts on WebhookTargetEventSubscription {
2+
__typename
3+
eventType
4+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
fragment WebhookTargetParts on WebhookTarget {
2+
id
3+
url
4+
isEnabled
5+
description
6+
createdAt {
7+
...DateTimeParts
8+
}
9+
createdBy {
10+
...ActorParts
11+
}
12+
updatedAt {
13+
...DateTimeParts
14+
}
15+
updatedBy {
16+
...ActorParts
17+
}
18+
eventSubscriptions {
19+
...WebhookTargetEventSubscriptionParts
20+
}
21+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
mutation createWebhookTarget($input: CreateWebhookTargetInput!) {
2+
createWebhookTarget(input: $input) {
3+
webhookTarget {
4+
...WebhookTargetParts
5+
}
6+
error {
7+
...MutationErrorParts
8+
}
9+
}
10+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
mutation deleteWebhookTarget($input: DeleteWebhookTargetInput!) {
2+
deleteWebhookTarget(input: $input) {
3+
error {
4+
...MutationErrorParts
5+
}
6+
}
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
mutation updateWebhookTarget($input: UpdateWebhookTargetInput!) {
2+
updateWebhookTarget(input: $input) {
3+
webhookTarget {
4+
...WebhookTargetParts
5+
}
6+
error {
7+
...MutationErrorParts
8+
}
9+
}
10+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
query webhookTarget($id: ID!) {
2+
webhookTarget(webhookTargetId: $id) {
3+
...WebhookTargetParts
4+
}
5+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
query webhookTargets($first: Int, $after: String, $last: Int, $before: String) {
2+
webhookTargets(first: $first, after: $after, last: $last, before: $before) {
3+
edges {
4+
cursor
5+
node {
6+
...WebhookTargetParts
7+
}
8+
}
9+
pageInfo {
10+
...PageInfoParts
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)