Skip to content

Commit 910fe46

Browse files
authored
Add support for creating and updating customer card configs (#48)
* Add support for creating and updating customer card configs * copy change * add update method
1 parent efa2749 commit 910fe46

File tree

7 files changed

+126
-4
lines changed

7 files changed

+126
-4
lines changed

.changeset/eight-grapes-decide.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 and updating Customer Card configurations. Useful if you want to programatically set up Customer Cards.

src/client.ts

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import {
66
AddCustomerToCustomerGroupsDocument,
77
type AttachmentUploadUrlPartsFragment,
88
CreateAttachmentUploadUrlDocument,
9+
CreateCustomerCardConfigDocument,
910
CreateIssueDocument,
1011
CustomerByEmailDocument,
1112
CustomerByIdDocument,
13+
type CustomerCardConfigPartsFragment,
1214
CustomerGroupByIdDocument,
1315
type CustomerGroupMembershipPartsFragment,
1416
type CustomerGroupPartsFragment,
@@ -23,10 +25,11 @@ import {
2325
ReplyToEmailDocument,
2426
SendNewEmailDocument,
2527
type TimelineEntryPartsFragment,
28+
UpdateCustomerCardConfigDocument,
2629
UpsertCustomerDocument,
2730
UpsertCustomTimelineEntryDocument,
2831
type UpsertResult,
29-
type WorkspacePartsFragment
32+
type WorkspacePartsFragment,
3033
} from './graphql/types';
3134
import { request } from './request';
3235
import type { Result } from './result';
@@ -84,7 +87,7 @@ export class PlainClient {
8487
*/
8588
async getCustomers(
8689
variables: VariablesOf<typeof CustomersDocument>
87-
): SDKResult<{ customers: CustomerPartsFragment[], pageInfo: PageInfo, totalCount: number }> {
90+
): SDKResult<{ customers: CustomerPartsFragment[]; pageInfo: PageInfo; totalCount: number }> {
8891
const res = await request(this.#ctx, {
8992
query: CustomersDocument,
9093
variables,
@@ -97,7 +100,6 @@ export class PlainClient {
97100
}));
98101
}
99102

100-
101103
/**
102104
* If the customer is not found this will return null.
103105
*/
@@ -184,7 +186,7 @@ export class PlainClient {
184186
*/
185187
async getCustomerGroups(
186188
variables: VariablesOf<typeof CustomerGroupsDocument>
187-
): SDKResult<{ customerGroups: CustomerGroupPartsFragment[], pageInfo: PageInfo }> {
189+
): SDKResult<{ customerGroups: CustomerGroupPartsFragment[]; pageInfo: PageInfo }> {
188190
const res = await request(this.#ctx, {
189191
query: CustomerGroupsDocument,
190192
variables,
@@ -310,4 +312,41 @@ export class PlainClient {
310312
return nonNullable(q.myWorkspace);
311313
});
312314
}
315+
316+
/**
317+
* Creates the configuration for a Customer Card. Useful if you want
318+
* to programatically set up a customer card vs using the settings UI
319+
*/
320+
async createCustomerCardConfig(
321+
input: VariablesOf<typeof CreateCustomerCardConfigDocument>['input']
322+
): SDKResult<CustomerCardConfigPartsFragment> {
323+
const res = await request(this.#ctx, {
324+
query: CreateCustomerCardConfigDocument,
325+
variables: {
326+
input,
327+
},
328+
});
329+
330+
return unwrapData(res, (q) => {
331+
return nonNullable(q.createCustomerCardConfig.customerCardConfig);
332+
});
333+
}
334+
335+
/**
336+
* Updates the configuration for a Customer Card.
337+
*/
338+
async updateCustomerCardConfig(
339+
input: VariablesOf<typeof UpdateCustomerCardConfigDocument>['input']
340+
): SDKResult<CustomerCardConfigPartsFragment> {
341+
const res = await request(this.#ctx, {
342+
query: UpdateCustomerCardConfigDocument,
343+
variables: {
344+
input,
345+
},
346+
});
347+
348+
return unwrapData(res, (q) => {
349+
return nonNullable(q.updateCustomerCardConfig.customerCardConfig);
350+
});
351+
}
313352
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
fragment CustomerCardConfigParts on CustomerCardConfig {
2+
id
3+
title
4+
key
5+
defaultTimeToLiveSeconds
6+
apiUrl
7+
order
8+
apiHeaders {
9+
name
10+
value
11+
}
12+
isEnabled
13+
createdAt {
14+
...DateTimeParts
15+
}
16+
updatedAt {
17+
...DateTimeParts
18+
}
19+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
mutation createCustomerCardConfig($input: CreateCustomerCardConfigInput!) {
2+
createCustomerCardConfig(input: $input) {
3+
customerCardConfig {
4+
...CustomerCardConfigParts
5+
}
6+
error {
7+
...MutationErrorParts
8+
}
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
mutation updateCustomerCardConfig($input: UpdateCustomerCardConfigInput!) {
2+
updateCustomerCardConfig(input: $input) {
3+
customerCardConfig {
4+
...CustomerCardConfigParts
5+
}
6+
error {
7+
...MutationErrorParts
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)