Skip to content

Commit 695f962

Browse files
authored
Add support for getting a customer by external id (#168)
1 parent 4e8c5e5 commit 695f962

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed
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 getCustomerByExternalId

src/client.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
CreateThreadEventDocument,
2424
CreateWebhookTargetDocument,
2525
CustomerByEmailDocument,
26+
CustomerByExternalIdDocument,
2627
CustomerByIdDocument,
2728
type CustomerCardConfigPartsFragment,
2829
CustomerCustomerGroupsDocument,
@@ -221,6 +222,25 @@ export class PlainClient {
221222
});
222223
}
223224

225+
/**
226+
* If the customer is not found this will return null.
227+
*/
228+
async getCustomerByExternalId(
229+
variables: VariablesOf<typeof CustomerByExternalIdDocument>
230+
): SDKResult<CustomerPartsFragment | null> {
231+
const res = await request(this.#ctx, {
232+
query: CustomerByExternalIdDocument,
233+
variables,
234+
});
235+
236+
return unwrapData(res, (q) => {
237+
if (!q.customerByExternalId) {
238+
return null;
239+
}
240+
return q.customerByExternalId;
241+
});
242+
}
243+
224244
/**
225245
* If the customer is not found this will return null.
226246
*/
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
query customerByExternalId($externalId: ID!) {
2+
customerByExternalId(externalId: $externalId) {
3+
...CustomerParts
4+
}
5+
}

0 commit comments

Comments
 (0)