Skip to content

Commit d4d46d1

Browse files
authored
add threadByRef support in typescript SDK (#194)
* add threadByRef support in typescript SDK * remove wrong example * typecheck * revert changes to pnpm lock
1 parent 68e7f95 commit d4d46d1

File tree

7 files changed

+1248
-45
lines changed

7 files changed

+1248
-45
lines changed

src/client.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ import {
7171
type TenantTierMembershipPartsFragment,
7272
TenantsDocument,
7373
ThreadByExternalIdDocument,
74+
ThreadByRefDocument,
7475
ThreadDocument,
7576
type ThreadEventPartsFragment,
7677
type ThreadFieldPartsFragment,
@@ -576,6 +577,20 @@ export class PlainClient {
576577
return unwrapData(res, (q) => q.thread);
577578
}
578579

580+
/**
581+
* Get a single thread by its ref (eg T-12345)
582+
*/
583+
async getThreadByRef(
584+
variables: VariablesOf<typeof ThreadByRefDocument>
585+
): SDKResult<ThreadPartsFragment | null> {
586+
const res = await request(this.#ctx, {
587+
query: ThreadByRefDocument,
588+
variables,
589+
});
590+
591+
return unwrapData(res, (q) => q.threadByRef);
592+
}
593+
579594
/**
580595
* Get a single thread by external id. A thread's external id is unique per customer,
581596
* hence why the customer id is also required.

src/examples/getThreadByRef.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { PlainClient } from '../index';
2+
3+
export async function getThreadByRef() {
4+
const client = new PlainClient({ apiKey: process.env.API_KEY || '' });
5+
6+
const ref = 'T-12345';
7+
const res = await client.getThreadByRef({
8+
ref,
9+
});
10+
if (res.error) {
11+
console.error(res.error);
12+
} else if (res.data === null) {
13+
console.log(`Thread with ref=${ref} not found`);
14+
} else {
15+
console.log(`Thread with id=${res.data.id} and ref=${res.data.ref} found`);
16+
}
17+
}

src/examples/threadFields.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ export async function upsertThreadField() {
2525

2626
export async function deleteThreadField() {
2727
const res = await client.deleteThreadField({
28-
threadFieldId: 'tf_01HVTN2VTNYP91P5XGDQ57M2ZX',
28+
identifier: {
29+
key: 'product_area',
30+
threadId: 'th_01HVNWFJS395XVPPBJNE6A8BHP',
31+
},
2932
});
3033

3134
if (res.error) {

src/graphql/fragments/threadParts.gql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
fragment ThreadParts on Thread {
22
__typename
33
id
4+
ref
45
externalId
56
customer {
67
id
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
query threadByRef($ref: String!) {
2+
threadByRef(ref: $ref) {
3+
...ThreadParts
4+
}
5+
}

0 commit comments

Comments
 (0)