Skip to content

Commit f55d303

Browse files
authored
Attachment upload support (#34)
* improve example * Add support for creating attachment upload urls via the SDK * Add changeset
1 parent 380ab9c commit f55d303

File tree

6 files changed

+69
-13
lines changed

6 files changed

+69
-13
lines changed

.changeset/smooth-peaches-tan.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 attachment upload urls via the SDK

src/client.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import type { Context } from './context';
44
import type { PlainSDKError } from './error';
55
import {
66
AddCustomerToCustomerGroupsDocument,
7+
type AttachmentUploadUrlPartsFragment,
8+
CreateAttachmentUploadUrlDocument,
79
CreateIssueDocument,
810
CustomerByEmailDocument,
911
CustomerByIdDocument,
@@ -223,4 +225,19 @@ export class PlainClient {
223225
return nonNullable(q.replyToEmail.email);
224226
});
225227
}
228+
229+
async createAttachmentUploadUrl(
230+
input: VariablesOf<typeof CreateAttachmentUploadUrlDocument>['input']
231+
): SDKResult<AttachmentUploadUrlPartsFragment> {
232+
const res = await request(this.#ctx, {
233+
query: CreateAttachmentUploadUrlDocument,
234+
variables: {
235+
input,
236+
},
237+
});
238+
239+
return unwrapData(res, (q) => {
240+
return nonNullable(q.createAttachmentUploadUrl.attachmentUploadUrl);
241+
});
242+
}
226243
}

src/examples/upsertCustomer.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,26 @@
55

66
import { PlainClient } from '../client';
77

8-
export async function upsertCustomerExample() {
9-
const client = new PlainClient({ apiKey: '' });
8+
export async function createCustomer() {
9+
const client = new PlainClient({ apiKey: 'XXX' });
1010

1111
const res = await client.upsertCustomer({
1212
identifier: {
13-
customerId: '',
13+
emailAddress: 'jane@gmail.com',
1414
},
1515
onCreate: {
16-
fullName: '',
16+
fullName: 'Jane Fargate',
1717
email: {
18-
email: '',
19-
isVerified: false,
18+
email: 'jane@gmail.com',
19+
isVerified: true,
2020
},
2121
},
2222
onUpdate: {},
2323
});
2424

2525
if (res.error) {
2626
console.error(res.error);
27-
throw new Error(res.error.message);
27+
} else {
28+
console.log(`Created customer with id=${res.data.customer.id}`);
2829
}
29-
30-
console.log(`Created customer with id=${res.data.customer.id}`);
3130
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
fragment AttachmentUploadUrlParts on AttachmentUploadUrl {
2+
__typename
3+
attachment {
4+
...AttachmentParts
5+
}
6+
uploadFormUrl
7+
uploadFormData {
8+
key
9+
value
10+
}
11+
expiresAt {
12+
...DateTimeParts
13+
}
14+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
mutation createAttachmentUploadUrl($input: CreateAttachmentUploadUrlInput!) {
2+
createAttachmentUploadUrl(input: $input) {
3+
attachmentUploadUrl {
4+
...AttachmentUploadUrlParts
5+
}
6+
error {
7+
...MutationErrorParts
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)