|
1 | 1 | import { Context } from './context'; |
2 | 2 | import { PlainSDKError } from './error'; |
| 3 | +import { |
| 4 | + CustomerGroupMembershipPartsFragment, |
| 5 | + RemoveCustomerFromCustomerGroupsDocument, |
| 6 | + RemoveCustomerFromCustomerGroupsInput, |
| 7 | +} from './graphql/types'; |
| 8 | +import { AddCustomerToCustomerGroupsDocument } from './graphql/types'; |
| 9 | +import { AddCustomerToCustomerGroupsInput } from './graphql/types'; |
3 | 10 | import { |
4 | 11 | CreateIssueDocument, |
5 | 12 | CreateIssueInput, |
6 | 13 | CustomerByIdDocument, |
7 | 14 | CustomerByIdQueryVariables, |
8 | 15 | CustomerPartsFragment, |
9 | 16 | IssuePartsFragment, |
| 17 | + TimelineEntryPartsFragment, |
| 18 | + UpsertCustomTimelineEntryDocument, |
| 19 | + UpsertCustomTimelineEntryInput, |
10 | 20 | UpsertCustomerDocument, |
11 | 21 | UpsertCustomerInput, |
| 22 | + UpsertResult, |
12 | 23 | } from './graphql/types'; |
13 | 24 | import { request } from './request'; |
14 | 25 | import { Result } from './result'; |
@@ -103,4 +114,61 @@ export class PlainSDKClient { |
103 | 114 |
|
104 | 115 | return unwrapData(res, (q) => nonNullable(q.createIssue.issue)); |
105 | 116 | } |
| 117 | + |
| 118 | + /** |
| 119 | + * Adds a customer to a customer groups. |
| 120 | + */ |
| 121 | + async addCustomerToCustomerGroups( |
| 122 | + input: AddCustomerToCustomerGroupsInput |
| 123 | + ): SDKResult<CustomerGroupMembershipPartsFragment[]> { |
| 124 | + const res = await request(this.#ctx, { |
| 125 | + query: AddCustomerToCustomerGroupsDocument, |
| 126 | + variables: { |
| 127 | + input, |
| 128 | + }, |
| 129 | + }); |
| 130 | + |
| 131 | + return unwrapData(res, (q) => |
| 132 | + nonNullable(q.addCustomerToCustomerGroups.customerGroupMemberships) |
| 133 | + ); |
| 134 | + } |
| 135 | + |
| 136 | + /** |
| 137 | + * Remove a customer from customer groups. |
| 138 | + */ |
| 139 | + async removeCustomerFromCustomerGroups( |
| 140 | + input: RemoveCustomerFromCustomerGroupsInput |
| 141 | + ): SDKResult<null> { |
| 142 | + const res = await request(this.#ctx, { |
| 143 | + query: RemoveCustomerFromCustomerGroupsDocument, |
| 144 | + variables: { |
| 145 | + input, |
| 146 | + }, |
| 147 | + }); |
| 148 | + |
| 149 | + return unwrapData(res, () => null); |
| 150 | + } |
| 151 | + |
| 152 | + /** |
| 153 | + * Add a custom timeline entry to a customer's timeline. |
| 154 | + * |
| 155 | + * This can be used to power custom contact forms, log events from your own systems and much more. |
| 156 | + */ |
| 157 | + async upsertCustomTimelineEntry( |
| 158 | + input: UpsertCustomTimelineEntryInput |
| 159 | + ): SDKResult<{ result: UpsertResult; timelineEntry: TimelineEntryPartsFragment }> { |
| 160 | + const res = await request(this.#ctx, { |
| 161 | + query: UpsertCustomTimelineEntryDocument, |
| 162 | + variables: { |
| 163 | + input, |
| 164 | + }, |
| 165 | + }); |
| 166 | + |
| 167 | + return unwrapData(res, (q) => { |
| 168 | + return { |
| 169 | + result: nonNullable(q.upsertCustomTimelineEntry.result), |
| 170 | + timelineEntry: nonNullable(q.upsertCustomTimelineEntry.timelineEntry), |
| 171 | + }; |
| 172 | + }); |
| 173 | + } |
106 | 174 | } |
0 commit comments