Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/smooth-peaches-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@team-plain/typescript-sdk': minor
---

Add support for creating attachment upload urls via the SDK
17 changes: 17 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import type { Context } from './context';
import type { PlainSDKError } from './error';
import {
AddCustomerToCustomerGroupsDocument,
type AttachmentUploadUrlPartsFragment,
CreateAttachmentUploadUrlDocument,
CreateIssueDocument,
CustomerByEmailDocument,
CustomerByIdDocument,
Expand Down Expand Up @@ -223,4 +225,19 @@ export class PlainClient {
return nonNullable(q.replyToEmail.email);
});
}

async createAttachmentUploadUrl(
input: VariablesOf<typeof CreateAttachmentUploadUrlDocument>['input']
): SDKResult<AttachmentUploadUrlPartsFragment> {
const res = await request(this.#ctx, {
query: CreateAttachmentUploadUrlDocument,
variables: {
input,
},
});

return unwrapData(res, (q) => {
return nonNullable(q.createAttachmentUploadUrl.attachmentUploadUrl);
});
}
}
17 changes: 8 additions & 9 deletions src/examples/upsertCustomer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,26 @@

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

export async function upsertCustomerExample() {
const client = new PlainClient({ apiKey: '' });
export async function createCustomer() {
const client = new PlainClient({ apiKey: 'XXX' });

const res = await client.upsertCustomer({
identifier: {
customerId: '',
emailAddress: 'jane@gmail.com',
},
onCreate: {
fullName: '',
fullName: 'Jane Fargate',
email: {
email: '',
isVerified: false,
email: 'jane@gmail.com',
isVerified: true,
},
},
onUpdate: {},
});

if (res.error) {
console.error(res.error);
throw new Error(res.error.message);
} else {
console.log(`Created customer with id=${res.data.customer.id}`);
}

console.log(`Created customer with id=${res.data.customer.id}`);
}
14 changes: 14 additions & 0 deletions src/graphql/fragments/attachmentUploadUrlParts.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
fragment AttachmentUploadUrlParts on AttachmentUploadUrl {
__typename
attachment {
...AttachmentParts
}
uploadFormUrl
uploadFormData {
key
value
}
expiresAt {
...DateTimeParts
}
}
10 changes: 10 additions & 0 deletions src/graphql/mutations/createAttachmentUploadUrl.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
mutation createAttachmentUploadUrl($input: CreateAttachmentUploadUrlInput!) {
createAttachmentUploadUrl(input: $input) {
attachmentUploadUrl {
...AttachmentUploadUrlParts
}
error {
...MutationErrorParts
}
}
}
Loading