@sixtyninecommerce/admin 0.8.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. package/README.md +2739 -17
  2. package/dist/api-tokens/index.d.ts +15 -5
  3. package/dist/api-tokens/index.js +1 -0
  4. package/dist/apps/event-subscription.d.ts +59 -0
  5. package/dist/apps/event-subscription.js +32 -0
  6. package/dist/apps/hook-secret.d.ts +22 -0
  7. package/dist/apps/hook-secret.js +36 -0
  8. package/dist/apps/index.d.ts +54 -3
  9. package/dist/apps/index.js +17 -0
  10. package/dist/audit/index.d.ts +7 -0
  11. package/dist/auth/queries.d.ts +5 -1
  12. package/dist/auth/queries.js +6 -0
  13. package/dist/bulk/index.d.ts +323 -0
  14. package/dist/bulk/index.js +162 -0
  15. package/dist/catalog/assets.d.ts +147 -0
  16. package/dist/catalog/assets.js +164 -0
  17. package/dist/catalog/collections.d.ts +109 -0
  18. package/dist/catalog/collections.js +91 -0
  19. package/dist/catalog/facets.d.ts +103 -0
  20. package/dist/catalog/facets.js +100 -0
  21. package/dist/catalog/index.d.ts +115 -0
  22. package/dist/catalog/index.js +21 -0
  23. package/dist/catalog/options.d.ts +89 -0
  24. package/dist/catalog/options.js +88 -0
  25. package/dist/catalog/products-bulk.d.ts +21 -0
  26. package/dist/catalog/products-bulk.js +58 -0
  27. package/dist/catalog/products.d.ts +650 -0
  28. package/dist/catalog/products.js +458 -0
  29. package/dist/catalog/properties.d.ts +234 -0
  30. package/dist/catalog/properties.js +158 -0
  31. package/dist/catalog/types.d.ts +174 -0
  32. package/dist/catalog/types.js +141 -0
  33. package/dist/catalog/variants.d.ts +324 -0
  34. package/dist/catalog/variants.js +288 -0
  35. package/dist/catalog/visibility.d.ts +57 -0
  36. package/dist/catalog/visibility.js +59 -0
  37. package/dist/client.d.ts +192 -3
  38. package/dist/client.js +87 -12
  39. package/dist/compliance/index.d.ts +88 -0
  40. package/dist/compliance/index.js +88 -0
  41. package/dist/customer-data-redaction.d.ts +14 -0
  42. package/dist/customer-data-redaction.js +22 -0
  43. package/dist/customers/index.d.ts +428 -17
  44. package/dist/customers/index.js +322 -15
  45. package/dist/documents/index.d.ts +513 -16
  46. package/dist/documents/index.js +229 -3
  47. package/dist/events/index.d.ts +259 -0
  48. package/dist/events/index.js +147 -0
  49. package/dist/feeds/ai.d.ts +46 -0
  50. package/dist/feeds/ai.js +43 -0
  51. package/dist/feeds/categories.d.ts +50 -0
  52. package/dist/feeds/categories.js +56 -0
  53. package/dist/feeds/configs.d.ts +54 -0
  54. package/dist/feeds/configs.js +85 -0
  55. package/dist/feeds/identifier-fields.d.ts +25 -0
  56. package/dist/feeds/identifier-fields.js +29 -0
  57. package/dist/feeds/index.d.ts +54 -0
  58. package/dist/feeds/index.js +46 -0
  59. package/dist/feeds/preserve.d.ts +38 -0
  60. package/dist/feeds/preserve.js +74 -0
  61. package/dist/feeds/rules.d.ts +42 -0
  62. package/dist/feeds/rules.js +56 -0
  63. package/dist/feeds/types.d.ts +654 -0
  64. package/dist/feeds/types.js +135 -0
  65. package/dist/fulfillments/index.d.ts +437 -0
  66. package/dist/fulfillments/index.js +534 -0
  67. package/dist/heads/index.d.ts +60 -0
  68. package/dist/heads/index.js +45 -0
  69. package/dist/hooks/assignments.d.ts +90 -0
  70. package/dist/hooks/assignments.js +53 -0
  71. package/dist/hooks/index.d.ts +97 -0
  72. package/dist/hooks/index.js +76 -0
  73. package/dist/index.d.ts +95 -9
  74. package/dist/index.js +21 -1
  75. package/dist/integrations/index.d.ts +14 -0
  76. package/dist/integrations/index.js +9 -0
  77. package/dist/integrations/pipelines.d.ts +113 -0
  78. package/dist/integrations/pipelines.js +62 -0
  79. package/dist/integrations/types.d.ts +176 -0
  80. package/dist/integrations/types.js +8 -0
  81. package/dist/jobs/bulk-action-run.d.ts +74 -0
  82. package/dist/jobs/bulk-action-run.js +69 -0
  83. package/dist/locations/index.d.ts +6 -2
  84. package/dist/meta/index.d.ts +32 -0
  85. package/dist/orders/bulk.d.ts +75 -0
  86. package/dist/orders/bulk.js +150 -0
  87. package/dist/orders/commit-edit.d.ts +123 -0
  88. package/dist/orders/commit-edit.js +142 -0
  89. package/dist/orders/deposit-policy.d.ts +103 -0
  90. package/dist/orders/deposit-policy.js +202 -0
  91. package/dist/orders/get.d.ts +722 -0
  92. package/dist/orders/get.js +530 -0
  93. package/dist/orders/index.d.ts +186 -21
  94. package/dist/orders/index.js +57 -0
  95. package/dist/orders/line-price-preview.d.ts +297 -0
  96. package/dist/orders/line-price-preview.js +50 -0
  97. package/dist/orders/manual-discounts.d.ts +141 -0
  98. package/dist/orders/manual-discounts.js +97 -0
  99. package/dist/orders/manual-pricing.d.ts +192 -0
  100. package/dist/orders/manual-pricing.js +72 -0
  101. package/dist/orders/order-entry.d.ts +566 -0
  102. package/dist/orders/order-entry.js +129 -0
  103. package/dist/orders/parcel-charge.d.ts +45 -0
  104. package/dist/orders/parcel-charge.js +55 -0
  105. package/dist/orders/plan-edit.d.ts +489 -0
  106. package/dist/orders/plan-edit.js +93 -0
  107. package/dist/orders/status.d.ts +235 -0
  108. package/dist/orders/status.js +96 -0
  109. package/dist/orders/surcharges.d.ts +75 -2
  110. package/dist/orders/surcharges.js +110 -4
  111. package/dist/payments/account-credit.d.ts +171 -0
  112. package/dist/payments/account-credit.js +107 -0
  113. package/dist/payments/index.d.ts +241 -9
  114. package/dist/payments/index.js +92 -0
  115. package/dist/payments/methods.d.ts +37 -0
  116. package/dist/payments/methods.js +33 -0
  117. package/dist/platform/catalog.d.ts +148 -0
  118. package/dist/platform/catalog.js +74 -0
  119. package/dist/platform/entitlements.d.ts +111 -0
  120. package/dist/platform/entitlements.js +86 -0
  121. package/dist/platform/legal-entities.d.ts +139 -0
  122. package/dist/platform/legal-entities.js +126 -0
  123. package/dist/platform/legal-entity-numbering.d.ts +103 -0
  124. package/dist/platform/legal-entity-numbering.js +101 -0
  125. package/dist/platform/organization-membership.d.ts +80 -0
  126. package/dist/platform/organization-membership.js +71 -0
  127. package/dist/platform/organization-settings.d.ts +33 -0
  128. package/dist/platform/organization-settings.js +42 -0
  129. package/dist/platform/organization-sharing.d.ts +172 -0
  130. package/dist/platform/organization-sharing.js +120 -0
  131. package/dist/platform/organizations.d.ts +205 -0
  132. package/dist/platform/organizations.js +180 -0
  133. package/dist/platform/provision-store.d.ts +88 -8
  134. package/dist/platform/provision-store.js +12 -0
  135. package/dist/platform/reports.d.ts +46 -0
  136. package/dist/platform/reports.js +31 -0
  137. package/dist/platform/server-metrics.d.ts +58 -0
  138. package/dist/platform/server-metrics.js +11 -0
  139. package/dist/pos/index.d.ts +567 -0
  140. package/dist/pos/index.js +205 -0
  141. package/dist/pricing/index.d.ts +408 -0
  142. package/dist/pricing/index.js +353 -0
  143. package/dist/pricing/vouchers.d.ts +103 -0
  144. package/dist/pricing/vouchers.js +69 -0
  145. package/dist/provenance/index.d.ts +93 -0
  146. package/dist/provenance/index.js +53 -0
  147. package/dist/reports/index.d.ts +199 -0
  148. package/dist/reports/index.js +154 -0
  149. package/dist/returns/index.d.ts +225 -0
  150. package/dist/returns/index.js +160 -0
  151. package/dist/search/index.d.ts +99 -0
  152. package/dist/search/index.js +62 -0
  153. package/dist/shipping/parcel-count-suggestion.d.ts +52 -0
  154. package/dist/shipping/parcel-count-suggestion.js +73 -0
  155. package/dist/shipping/parcel-rule.d.ts +48 -0
  156. package/dist/shipping/parcel-rule.js +91 -0
  157. package/dist/stock/index.d.ts +166 -0
  158. package/dist/stock/index.js +115 -0
  159. package/dist/stock/transfers.d.ts +520 -0
  160. package/dist/stock/transfers.js +437 -0
  161. package/dist/stored-value/index.d.ts +154 -0
  162. package/dist/stored-value/index.js +130 -0
  163. package/dist/tenant/capabilities.d.ts +10 -0
  164. package/dist/tenant/entitlements.d.ts +35 -0
  165. package/dist/tenant/entitlements.js +15 -0
  166. package/dist/tenant/field-groups.d.ts +64 -0
  167. package/dist/tenant/field-groups.js +34 -0
  168. package/dist/tenant/legal-entity.d.ts +32 -0
  169. package/dist/tenant/legal-entity.js +41 -0
  170. package/dist/tenant/notifications.d.ts +148 -0
  171. package/dist/tenant/notifications.js +79 -0
  172. package/dist/tenant/retention.d.ts +10 -4
  173. package/dist/tenant/settings-sources.d.ts +103 -0
  174. package/dist/tenant/settings-sources.js +92 -0
  175. package/dist/types.d.ts +86 -11
  176. package/dist/uploads/index.d.ts +11 -7
  177. package/dist/users/index.d.ts +104 -0
  178. package/dist/users/index.js +80 -0
  179. package/package.json +3 -2
@@ -1,4 +1,7 @@
1
1
  import { errorFromErrorResult, isErrorResult, pageFromVendureList, readOffsetCursor, } from '@sixtyninecommerce/core';
2
+ import { CATALOGUE_OWNERSHIP_FIELDS } from '../catalog/types.js';
3
+ import { COMPLIANCE_REQUEST_FIELDS } from '../compliance/index.js';
4
+ import { redactionWatcher } from '../customer-data-redaction.js';
2
5
  /**
3
6
  * Customers — the commerce master record (headless spec §6.5).
4
7
  *
@@ -15,6 +18,31 @@ import { errorFromErrorResult, isErrorResult, pageFromVendureList, readOffsetCur
15
18
  * 2. **`erase` is a scrub, not a delete.** It removes the person and keeps the
16
19
  * record, the orders and the documents. It is the only destructive customer
17
20
  * operation the platform has.
21
+ *
22
+ * ## Acting inside a customer's cart: `actAs`
23
+ *
24
+ * `actAs(customerId, { reason })` answers a trusted-agent session: a Shop API
25
+ * bearer for that customer, valid 15 minutes and never renewed. It is usable
26
+ * in exactly ONE way — as the customer token of a storefront client for the
27
+ * same store:
28
+ *
29
+ * ```ts
30
+ * const session = await admin.customers.actAs(customerId, { reason: 'Phone order' });
31
+ * const shop = await createStorefrontClient({
32
+ * storeCode: 'my-store',
33
+ * cdnUrl,
34
+ * customerToken: session.token, // @sixtyninecommerce/client
35
+ * });
36
+ * await shop.commerce.addToCart(variantId, 2); // the customer's own cart
37
+ * await admin.customers.endAgentSession(session.id);
38
+ * ```
39
+ *
40
+ * The Admin API, the CMS and the plugins service all refuse it. On the Shop
41
+ * API it may run cart and checkout only; an address-book edit, a password or
42
+ * email change, order history beyond the active order, or anything else is
43
+ * refused with `PermissionDeniedError` `AGENT_SESSION_SCOPE`. Every order row
44
+ * it writes records the caller as `on_behalf_of`; the customer sees the order
45
+ * as their own.
18
46
  */
19
47
  export const CUSTOMER_FIELDS = /* GraphQL */ `
20
48
  id
@@ -71,10 +99,14 @@ export const ADDRESSES_QUERY = /* GraphQL */ `
71
99
  /**
72
100
  * The CHANNEL-SCOPED creation mutation. See the module docblock — core
73
101
  * `createCustomer` is not an option, and this SDK exposes no path to it.
102
+ *
103
+ * No `password` argument: the server ignores one (and a later release refuses
104
+ * it with `CUSTOMER_PASSWORD_NOT_ALLOWED`), because staff and API tokens never
105
+ * set a customer's password. `invite` is how a customer gets one.
74
106
  */
75
107
  export const CREATE_MUTATION = /* GraphQL */ `
76
- mutation CreateChannelCustomer($input: CreateCustomerInput!, $password: String) {
77
- createChannelCustomer(input: $input, password: $password) {
108
+ mutation CreateChannelCustomer($input: CreateCustomerInput!) {
109
+ createChannelCustomer(input: $input) {
78
110
  id
79
111
  emailAddress
80
112
  createdNew
@@ -109,6 +141,24 @@ export const RESEND_INVITE_MUTATION = /* GraphQL */ `
109
141
  }
110
142
  }
111
143
  `;
144
+ /**
145
+ * "Invite all trade customers" — the whole channel's B2B-group members in one
146
+ * call. Counts always come back; unless `dryRun`, a background job sends the
147
+ * invitations and `jobId` names it.
148
+ */
149
+ export const INVITE_B2B_MUTATION = /* GraphQL */ `
150
+ mutation InviteB2BCustomers($input: InviteB2BCustomersInput) {
151
+ inviteB2BCustomers(input: $input) {
152
+ dryRun
153
+ total
154
+ eligible
155
+ skippedHasPassword
156
+ skippedPending
157
+ skippedUnreachable
158
+ jobId
159
+ }
160
+ }
161
+ `;
112
162
  export const ERASE_MUTATION = /* GraphQL */ `
113
163
  mutation EraseCustomer(
114
164
  $customerId: ID!
@@ -143,6 +193,32 @@ export const ERASURE_QUERY = /* GraphQL */ `
143
193
  }
144
194
  }
145
195
  `;
196
+ export const ACT_AS_MUTATION = /* GraphQL */ `
197
+ mutation ActAsCustomer($customerId: ID!, $reason: String!) {
198
+ actAsCustomer(customerId: $customerId, reason: $reason) {
199
+ id
200
+ customerId
201
+ token
202
+ expiresAt
203
+ }
204
+ }
205
+ `;
206
+ export const REQUEST_DATA_MUTATION = /* GraphQL */ `
207
+ mutation RequestCustomerData($customerId: ID!, $reason: String!, $idempotencyKey: String) {
208
+ requestCustomerData(customerId: $customerId, reason: $reason, idempotencyKey: $idempotencyKey) {
209
+ ${COMPLIANCE_REQUEST_FIELDS}
210
+ }
211
+ }
212
+ `;
213
+ export const END_AGENT_SESSION_MUTATION = /* GraphQL */ `
214
+ mutation EndCustomerAgentSession($sessionId: ID!) {
215
+ endCustomerAgentSession(sessionId: $sessionId) {
216
+ id
217
+ customerId
218
+ revokedAt
219
+ }
220
+ }
221
+ `;
146
222
  export const ADD_TO_GROUP_MUTATION = /* GraphQL */ `
147
223
  mutation AddCustomersToGroup($customerGroupId: ID!, $customerIds: [ID!]!) {
148
224
  addCustomersToGroup(customerGroupId: $customerGroupId, customerIds: $customerIds) {
@@ -159,6 +235,111 @@ export const REMOVE_FROM_GROUP_MUTATION = /* GraphQL */ `
159
235
  }
160
236
  }
161
237
  `;
238
+ /**
239
+ * External keys (incentives program decision 7): when another system is the customer master it
240
+ * addresses this store's customers and segments by its own keys. Every key is this store's: another
241
+ * store's key reads as one nobody filed. Each document is its own request, so a client ahead of the
242
+ * engine fails only that call, never the customer page.
243
+ */
244
+ export const CUSTOMER_EXTERNAL_REF_FIELDS = /* GraphQL */ `
245
+ id
246
+ createdAt
247
+ updatedAt
248
+ system
249
+ ref
250
+ `;
251
+ export const EXTERNAL_KEYED_GROUP_FIELDS = /* GraphQL */ `
252
+ id
253
+ name
254
+ externalKey
255
+ ${CATALOGUE_OWNERSHIP_FIELDS}
256
+ `;
257
+ export const BY_EXTERNAL_REF_QUERY = /* GraphQL */ `
258
+ query CustomerByExternalRef($system: String!, $ref: String!) {
259
+ customerByExternalRef(system: $system, ref: $ref) { ${CUSTOMER_FIELDS} }
260
+ }
261
+ `;
262
+ export const EXTERNAL_REFS_QUERY = /* GraphQL */ `
263
+ query CustomerExternalRefs($id: ID!) {
264
+ customer(id: $id) {
265
+ id
266
+ externalRefs { ${CUSTOMER_EXTERNAL_REF_FIELDS} }
267
+ }
268
+ }
269
+ `;
270
+ export const UPSERT_BY_EXTERNAL_REF_MUTATION = /* GraphQL */ `
271
+ mutation UpsertCustomerByExternalRef(
272
+ $input: UpsertCustomerByExternalRefInput!
273
+ $idempotencyKey: String
274
+ ) {
275
+ upsertCustomerByExternalRef(input: $input, idempotencyKey: $idempotencyKey) {
276
+ customer { ${CUSTOMER_FIELDS} }
277
+ created
278
+ matchedByEmail
279
+ updated
280
+ }
281
+ }
282
+ `;
283
+ export const GROUP_BY_EXTERNAL_KEY_QUERY = /* GraphQL */ `
284
+ query CustomerGroupByExternalKey($key: String!) {
285
+ customerGroupByExternalKey(key: $key) { ${EXTERNAL_KEYED_GROUP_FIELDS} }
286
+ }
287
+ `;
288
+ /** A customer group as {@link CustomerGroupsModule.get} reads it. */
289
+ export const CUSTOMER_GROUP_FIELDS = /* GraphQL */ `
290
+ id
291
+ createdAt
292
+ updatedAt
293
+ name
294
+ externalKey
295
+ ${CATALOGUE_OWNERSHIP_FIELDS}
296
+ `;
297
+ export const CUSTOMER_GROUP_QUERY = /* GraphQL */ `
298
+ query CustomerGroup($id: ID!) {
299
+ customerGroup(id: $id) { ${CUSTOMER_GROUP_FIELDS} }
300
+ }
301
+ `;
302
+ export const GROUP_EXTERNAL_KEY_QUERY = /* GraphQL */ `
303
+ query CustomerGroupExternalKey($id: ID!) {
304
+ customerGroup(id: $id) {
305
+ id
306
+ externalKey
307
+ }
308
+ }
309
+ `;
310
+ export const UPSERT_GROUP_BY_EXTERNAL_KEY_MUTATION = /* GraphQL */ `
311
+ mutation UpsertCustomerGroupByExternalKey($key: String!, $name: String!) {
312
+ upsertCustomerGroupByExternalKey(key: $key, name: $name) {
313
+ customerGroup { ${EXTERNAL_KEYED_GROUP_FIELDS} }
314
+ created
315
+ renamed
316
+ }
317
+ }
318
+ `;
319
+ export const REPLACE_GROUP_MEMBERS_MUTATION = /* GraphQL */ `
320
+ mutation ReplaceCustomerGroupMembers(
321
+ $key: String!
322
+ $customerExternalRefs: [CustomerExternalRefInput!]!
323
+ $idempotencyKey: String
324
+ ) {
325
+ replaceCustomerGroupMembers(
326
+ key: $key
327
+ customerExternalRefs: $customerExternalRefs
328
+ idempotencyKey: $idempotencyKey
329
+ ) {
330
+ customerGroup { ${EXTERNAL_KEYED_GROUP_FIELDS} }
331
+ memberCount
332
+ added
333
+ removed
334
+ unknownRefs {
335
+ system
336
+ ref
337
+ }
338
+ }
339
+ }
340
+ `;
341
+ /** The most member keys one `customers.groups.replaceMembers` call takes. */
342
+ export const MAX_REPLACE_GROUP_MEMBERS = 5000;
162
343
  export const CREATE_ADDRESS_MUTATION = /* GraphQL */ `
163
344
  mutation CreateCustomerAddress($customerId: ID!, $input: CreateAddressInput!) {
164
345
  createCustomerAddress(customerId: $customerId, input: $input) {
@@ -179,7 +360,14 @@ export const DELETE_ADDRESS_MUTATION = /* GraphQL */ `
179
360
  const DEFAULT_PAGE_SIZE = 25;
180
361
  export function createCustomersModule(transport) {
181
362
  const listPage = async (skip, take, options) => {
182
- const data = await transport.graphql({ api: 'admin', query: LIST_QUERY, variables: { options: { skip, take } } }, options);
363
+ const redaction = redactionWatcher();
364
+ const data = await transport.graphql({
365
+ api: 'admin',
366
+ query: LIST_QUERY,
367
+ variables: { options: { skip, take } },
368
+ onExtensions: redaction.onExtensions,
369
+ }, options);
370
+ data.customers.items.forEach(redaction.mark);
183
371
  return pageFromVendureList(data.customers, skip, take, (cursor) => listPage(readOffsetCursor(cursor), take, options));
184
372
  };
185
373
  return {
@@ -191,19 +379,28 @@ export function createCustomersModule(transport) {
191
379
  return listPage(skip, take, options);
192
380
  },
193
381
  async get(id, options) {
194
- const data = await transport.graphql({ api: 'admin', query: GET_QUERY, variables: { id } }, options);
195
- return data.customer;
382
+ const redaction = redactionWatcher();
383
+ const data = await transport.graphql({ api: 'admin', query: GET_QUERY, variables: { id }, onExtensions: redaction.onExtensions }, options);
384
+ return redaction.mark(data.customer);
196
385
  },
197
386
  async create(input, options) {
387
+ const redaction = redactionWatcher();
198
388
  const data = await transport.graphql({
199
389
  api: 'admin',
200
390
  query: CREATE_MUTATION,
201
- variables: { input, password: options?.password ?? null },
391
+ variables: { input },
392
+ onExtensions: redaction.onExtensions,
202
393
  }, options);
203
- return data.createChannelCustomer;
394
+ return redaction.mark(data.createChannelCustomer);
204
395
  },
205
396
  async update(id, input, options) {
206
- const data = await transport.graphql({ api: 'admin', query: UPDATE_MUTATION, variables: { input: { id, ...input } } }, options);
397
+ const redaction = redactionWatcher();
398
+ const data = await transport.graphql({
399
+ api: 'admin',
400
+ query: UPDATE_MUTATION,
401
+ variables: { input: { id, ...input } },
402
+ onExtensions: redaction.onExtensions,
403
+ }, options);
207
404
  // `updateCustomer` is a UNION — `Customer | EmailAddressConflictError` —
208
405
  // delivered at HTTP 200, so the transport never throws for it. Returned
209
406
  // unchecked, a rename onto an address already taken on the channel
@@ -211,7 +408,8 @@ export function createCustomersModule(transport) {
211
408
  // `Customer` whose `id` was undefined.
212
409
  if (isErrorResult(data.updateCustomer))
213
410
  throw errorFromErrorResult(data.updateCustomer);
214
- return data.updateCustomer;
411
+ // The Admin API redacts a mutation's answer like a read's.
412
+ return redaction.mark(data.updateCustomer);
215
413
  },
216
414
  async invite(id, options) {
217
415
  // `resend` picks the SEPARATE mutation rather than a flag on one: the two
@@ -223,6 +421,19 @@ export function createCustomersModule(transport) {
223
421
  const data = await transport.graphql({ api: 'admin', query, variables: { customerId: id, mode: options?.mode ?? null } }, options);
224
422
  return (data.inviteCustomer ?? data.resendCustomerInvitation);
225
423
  },
424
+ async inviteB2B(options) {
425
+ const data = await transport.graphql({
426
+ api: 'admin',
427
+ query: INVITE_B2B_MUTATION,
428
+ variables: {
429
+ input: {
430
+ dryRun: options?.dryRun ?? null,
431
+ includePending: options?.includePending ?? null,
432
+ },
433
+ },
434
+ }, options);
435
+ return data.inviteB2BCustomers;
436
+ },
226
437
  async erase(id, options) {
227
438
  const data = await transport.graphql({
228
439
  api: 'admin',
@@ -240,7 +451,85 @@ export function createCustomersModule(transport) {
240
451
  const data = await transport.graphql({ api: 'admin', query: ERASURE_QUERY, variables: { customerId: id } }, options);
241
452
  return data.customerErasure;
242
453
  },
454
+ async requestData(id, options) {
455
+ const data = await transport.graphql({
456
+ api: 'admin',
457
+ query: REQUEST_DATA_MUTATION,
458
+ variables: {
459
+ customerId: id,
460
+ reason: options.reason,
461
+ idempotencyKey: options.idempotencyKey ?? null,
462
+ },
463
+ }, options);
464
+ return data.requestCustomerData;
465
+ },
466
+ async actAs(customerId, options) {
467
+ const data = await transport.graphql({ api: 'admin', query: ACT_AS_MUTATION, variables: { customerId, reason: options.reason } }, options);
468
+ return data.actAsCustomer;
469
+ },
470
+ async endAgentSession(sessionId, options) {
471
+ const data = await transport.graphql({ api: 'admin', query: END_AGENT_SESSION_MUTATION, variables: { sessionId } }, options);
472
+ return data.endCustomerAgentSession;
473
+ },
474
+ async byExternalRef(system, ref, options) {
475
+ const redaction = redactionWatcher();
476
+ const data = await transport.graphql({
477
+ api: 'admin',
478
+ query: BY_EXTERNAL_REF_QUERY,
479
+ variables: { system, ref },
480
+ onExtensions: redaction.onExtensions,
481
+ }, options);
482
+ return redaction.mark(data.customerByExternalRef);
483
+ },
484
+ async externalRefs(customerId, options) {
485
+ const data = await transport.graphql({ api: 'admin', query: EXTERNAL_REFS_QUERY, variables: { id: customerId } }, options);
486
+ return data.customer?.externalRefs ?? [];
487
+ },
488
+ async upsertByExternalRef(input, options) {
489
+ const redaction = redactionWatcher();
490
+ const data = await transport.graphql({
491
+ api: 'admin',
492
+ query: UPSERT_BY_EXTERNAL_REF_MUTATION,
493
+ variables: { input, idempotencyKey: options?.idempotencyKey ?? null },
494
+ onExtensions: redaction.onExtensions,
495
+ }, options);
496
+ const result = data.upsertCustomerByExternalRef;
497
+ redaction.mark(result.customer);
498
+ return result;
499
+ },
243
500
  groups: {
501
+ async get(id, options) {
502
+ const data = await transport.graphql({ api: 'admin', query: CUSTOMER_GROUP_QUERY, variables: { id } }, options);
503
+ return data.customerGroup;
504
+ },
505
+ async byExternalKey(key, options) {
506
+ const data = await transport.graphql({ api: 'admin', query: GROUP_BY_EXTERNAL_KEY_QUERY, variables: { key } }, options);
507
+ return data.customerGroupByExternalKey;
508
+ },
509
+ async externalKey(groupId, options) {
510
+ const data = await transport.graphql({ api: 'admin', query: GROUP_EXTERNAL_KEY_QUERY, variables: { id: groupId } }, options);
511
+ return data.customerGroup?.externalKey ?? null;
512
+ },
513
+ async upsertByExternalKey(key, name, options) {
514
+ const data = await transport.graphql({ api: 'admin', query: UPSERT_GROUP_BY_EXTERNAL_KEY_MUTATION, variables: { key, name } }, options);
515
+ return data.upsertCustomerGroupByExternalKey;
516
+ },
517
+ async replaceMembers(key, customerExternalRefs, options) {
518
+ const data = await transport.graphql({
519
+ api: 'admin',
520
+ query: REPLACE_GROUP_MEMBERS_MUTATION,
521
+ variables: {
522
+ key,
523
+ // Only the two fields the input type declares: an extra one fails validation.
524
+ customerExternalRefs: customerExternalRefs.map(({ system, ref }) => ({
525
+ system,
526
+ ref,
527
+ })),
528
+ idempotencyKey: options?.idempotencyKey ?? null,
529
+ },
530
+ }, options);
531
+ return data.replaceCustomerGroupMembers;
532
+ },
244
533
  async add(groupId, customerIds, options) {
245
534
  const data = await transport.graphql({
246
535
  api: 'admin',
@@ -260,16 +549,34 @@ export function createCustomersModule(transport) {
260
549
  },
261
550
  addresses: {
262
551
  async list(customerId, options) {
263
- const data = await transport.graphql({ api: 'admin', query: ADDRESSES_QUERY, variables: { id: customerId } }, options);
264
- return data.customer?.addresses ?? [];
552
+ const redaction = redactionWatcher();
553
+ const data = await transport.graphql({
554
+ api: 'admin',
555
+ query: ADDRESSES_QUERY,
556
+ variables: { id: customerId },
557
+ onExtensions: redaction.onExtensions,
558
+ }, options);
559
+ return (data.customer?.addresses ?? []).map(redaction.mark);
265
560
  },
266
561
  async create(customerId, input, options) {
267
- const data = await transport.graphql({ api: 'admin', query: CREATE_ADDRESS_MUTATION, variables: { customerId, input } }, options);
268
- return data.createCustomerAddress;
562
+ const redaction = redactionWatcher();
563
+ const data = await transport.graphql({
564
+ api: 'admin',
565
+ query: CREATE_ADDRESS_MUTATION,
566
+ variables: { customerId, input },
567
+ onExtensions: redaction.onExtensions,
568
+ }, options);
569
+ return redaction.mark(data.createCustomerAddress);
269
570
  },
270
571
  async update(input, options) {
271
- const data = await transport.graphql({ api: 'admin', query: UPDATE_ADDRESS_MUTATION, variables: { input } }, options);
272
- return data.updateCustomerAddress;
572
+ const redaction = redactionWatcher();
573
+ const data = await transport.graphql({
574
+ api: 'admin',
575
+ query: UPDATE_ADDRESS_MUTATION,
576
+ variables: { input },
577
+ onExtensions: redaction.onExtensions,
578
+ }, options);
579
+ return redaction.mark(data.updateCustomerAddress);
273
580
  },
274
581
  async delete(id, options) {
275
582
  await transport.graphql({ api: 'admin', query: DELETE_ADDRESS_MUTATION, variables: { id } }, options);