@edgebound/bigcommerce 0.1.3 → 0.2.1

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 (61) hide show
  1. package/dist/addresses.d.mts +27 -0
  2. package/dist/addresses.d.ts +27 -0
  3. package/dist/addresses.js +69 -0
  4. package/dist/addresses.js.map +1 -0
  5. package/dist/addresses.mjs +9 -0
  6. package/dist/addresses.mjs.map +1 -0
  7. package/dist/{bigcommerce.fetcher-D1TyK4y4.d.mts → bigcommerce.fetcher-Ujztbs8P.d.mts} +2 -2
  8. package/dist/{bigcommerce.fetcher-D1TyK4y4.d.ts → bigcommerce.fetcher-Ujztbs8P.d.ts} +2 -2
  9. package/dist/{chunk-V2AKD2LM.mjs → chunk-2VMEIQCL.mjs} +63 -27
  10. package/dist/chunk-2VMEIQCL.mjs.map +1 -0
  11. package/dist/chunk-BWLQCNNX.mjs +30 -0
  12. package/dist/chunk-BWLQCNNX.mjs.map +1 -0
  13. package/dist/companies.d.mts +230 -1
  14. package/dist/companies.d.ts +230 -1
  15. package/dist/companies.js +723 -0
  16. package/dist/companies.js.map +1 -1
  17. package/dist/companies.mjs +367 -0
  18. package/dist/companies.mjs.map +1 -1
  19. package/dist/customers.d.mts +95 -2
  20. package/dist/customers.d.ts +95 -2
  21. package/dist/customers.js +245 -63
  22. package/dist/customers.js.map +1 -1
  23. package/dist/customers.mjs +172 -46
  24. package/dist/customers.mjs.map +1 -1
  25. package/dist/index.d.mts +2 -2
  26. package/dist/index.d.ts +2 -2
  27. package/dist/index.js +61 -17
  28. package/dist/index.js.map +1 -1
  29. package/dist/index.mjs +1 -1
  30. package/dist/orders.d.mts +1323 -2
  31. package/dist/orders.d.ts +1323 -2
  32. package/dist/orders.js +283 -181
  33. package/dist/orders.js.map +1 -1
  34. package/dist/orders.mjs +193 -166
  35. package/dist/orders.mjs.map +1 -1
  36. package/dist/payments.d.mts +28 -0
  37. package/dist/payments.d.ts +28 -0
  38. package/dist/payments.js +365 -0
  39. package/dist/payments.js.map +1 -0
  40. package/dist/payments.mjs +43 -0
  41. package/dist/payments.mjs.map +1 -0
  42. package/dist/priceLists.d.mts +81 -0
  43. package/dist/priceLists.d.ts +81 -0
  44. package/dist/priceLists.js +458 -0
  45. package/dist/priceLists.js.map +1 -0
  46. package/dist/priceLists.mjs +118 -0
  47. package/dist/priceLists.mjs.map +1 -0
  48. package/dist/products.d.mts +29 -7
  49. package/dist/products.d.ts +29 -7
  50. package/dist/products.js +114 -60
  51. package/dist/products.js.map +1 -1
  52. package/dist/products.mjs +26 -25
  53. package/dist/products.mjs.map +1 -1
  54. package/dist/salesStaff.d.mts +64 -0
  55. package/dist/salesStaff.d.ts +64 -0
  56. package/dist/salesStaff.js +419 -0
  57. package/dist/salesStaff.js.map +1 -0
  58. package/dist/salesStaff.mjs +82 -0
  59. package/dist/salesStaff.mjs.map +1 -0
  60. package/package.json +35 -15
  61. package/dist/chunk-V2AKD2LM.mjs.map +0 -1
@@ -1,10 +1,48 @@
1
1
  import { I as InputValidationError } from './validation.error-CHLpPYC_.js';
2
- import { S as SomeBigCommerceError, B as BigCommerceFetcher } from './bigcommerce.fetcher-D1TyK4y4.js';
2
+ import { S as SomeBigCommerceError, B as BigCommerceFetcher } from './bigcommerce.fetcher-Ujztbs8P.js';
3
3
  import { Effect } from 'effect';
4
4
  import * as z from 'zod';
5
5
  import 'effect/Cause';
6
6
  import 'effect/Types';
7
7
 
8
+ declare const CreateCustomerGroupSchema: z.ZodObject<{
9
+ name: z.ZodString;
10
+ discount_rules: z.ZodArray<z.ZodObject<{
11
+ type: z.ZodLiteral<"price_list">;
12
+ price_list_id: z.ZodInt;
13
+ }, z.core.$strip>>;
14
+ }, z.core.$strip>;
15
+ declare const CreateCustomerGroupResponseSchema: z.ZodObject<{
16
+ id: z.ZodInt;
17
+ }, z.core.$strip>;
18
+ declare const CustomerGroupSchema: z.ZodObject<{
19
+ id: z.ZodInt;
20
+ name: z.ZodString;
21
+ is_default: z.ZodBoolean;
22
+ is_group_for_guests: z.ZodBoolean;
23
+ }, z.core.$strip>;
24
+ declare const FindCustomerGroupsCriteriaSchema: z.ZodObject<{
25
+ limit: z.ZodOptional<z.ZodInt>;
26
+ page: z.ZodOptional<z.ZodInt>;
27
+ }, z.core.$strip>;
28
+ declare const SetCustomerGroupPriceListSchema: z.ZodObject<{
29
+ data: z.ZodObject<{
30
+ discount_rules: z.ZodArray<z.ZodObject<{
31
+ type: z.ZodLiteral<"price_list">;
32
+ price_list_id: z.ZodInt;
33
+ }, z.core.$strip>>;
34
+ }, z.core.$strip>;
35
+ customerGroupId: z.ZodInt;
36
+ }, z.core.$strip>;
37
+ declare const SetCustomerGroupPriceListResponseSchema: z.ZodObject<{
38
+ id: z.ZodInt;
39
+ name: z.ZodString;
40
+ }, z.core.$strip>;
41
+
42
+ declare const createCustomerGroup: (data: z.input<typeof CreateCustomerGroupSchema>) => Effect.Effect<{
43
+ id: number;
44
+ }, SomeBigCommerceError | InputValidationError, BigCommerceFetcher>;
45
+
8
46
  declare const FindCustomersCriteriaSchema: z.ZodObject<{
9
47
  'id:in': z.ZodOptional<z.ZodPipe<z.ZodArray<z.ZodInt>, z.ZodTransform<string, number[]>>>;
10
48
  page: z.ZodOptional<z.ZodInt>;
@@ -50,6 +88,19 @@ declare const getAllCustomersBy: (criteria: Omit<z.input<typeof FindCustomersCri
50
88
  company?: string | undefined;
51
89
  }[], SomeBigCommerceError | InputValidationError, BigCommerceFetcher>;
52
90
 
91
+ declare const findCustomersGroups: (criteria?: z.input<typeof FindCustomerGroupsCriteriaSchema>) => Effect.Effect<{
92
+ id: number;
93
+ name: string;
94
+ is_default: boolean;
95
+ is_group_for_guests: boolean;
96
+ }[], SomeBigCommerceError | InputValidationError, BigCommerceFetcher>;
97
+ declare const getAllCustomerGroupsBy: (criteria?: Omit<z.input<typeof FindCustomerGroupsCriteriaSchema>, "page" | "limit">) => Effect.Effect<{
98
+ id: number;
99
+ name: string;
100
+ is_default: boolean;
101
+ is_group_for_guests: boolean;
102
+ }[], SomeBigCommerceError | InputValidationError, BigCommerceFetcher>;
103
+
53
104
  declare const getCustomer: (customerId: number) => Effect.Effect<{
54
105
  email: string;
55
106
  first_name: string;
@@ -61,4 +112,46 @@ declare const getCustomer: (customerId: number) => Effect.Effect<{
61
112
  company?: string | undefined;
62
113
  } | undefined, SomeBigCommerceError | InputValidationError, BigCommerceFetcher>;
63
114
 
64
- export { findCustomers, getAllCustomersBy, getCustomer };
115
+ declare const CustomerSchema: z.ZodObject<{
116
+ email: z.ZodEmail;
117
+ first_name: z.ZodString;
118
+ last_name: z.ZodString;
119
+ company: z.ZodOptional<z.ZodString>;
120
+ phone: z.ZodString;
121
+ customer_group_id: z.ZodInt;
122
+ id: z.ZodInt;
123
+ channel_ids: z.ZodArray<z.ZodInt>;
124
+ }, z.core.$strip>;
125
+ declare const FindCustomerResponse: z.ZodObject<{
126
+ data: z.ZodArray<z.ZodObject<{
127
+ email: z.ZodEmail;
128
+ first_name: z.ZodString;
129
+ last_name: z.ZodString;
130
+ company: z.ZodOptional<z.ZodString>;
131
+ phone: z.ZodString;
132
+ customer_group_id: z.ZodInt;
133
+ id: z.ZodInt;
134
+ channel_ids: z.ZodArray<z.ZodInt>;
135
+ }, z.core.$strip>>;
136
+ meta: z.ZodObject<{
137
+ pagination: z.ZodObject<{
138
+ total: z.ZodInt;
139
+ count: z.ZodInt;
140
+ per_page: z.ZodInt;
141
+ current_page: z.ZodInt;
142
+ total_pages: z.ZodInt;
143
+ links: z.ZodObject<{
144
+ previous: z.ZodNullable<z.ZodOptional<z.ZodString>>;
145
+ current: z.ZodString;
146
+ next: z.ZodNullable<z.ZodOptional<z.ZodString>>;
147
+ }, z.core.$strip>;
148
+ }, z.core.$strip>;
149
+ }, z.core.$strip>;
150
+ }, z.core.$strip>;
151
+
152
+ declare const setCustomerGroupPriceList: (input: z.input<typeof SetCustomerGroupPriceListSchema>) => Effect.Effect<{
153
+ id: number;
154
+ name: string;
155
+ }, SomeBigCommerceError | InputValidationError, BigCommerceFetcher>;
156
+
157
+ export { CreateCustomerGroupResponseSchema, CreateCustomerGroupSchema, CustomerGroupSchema, CustomerSchema, FindCustomerGroupsCriteriaSchema, FindCustomerResponse, FindCustomersCriteriaSchema, SetCustomerGroupPriceListResponseSchema, SetCustomerGroupPriceListSchema, createCustomerGroup, findCustomers, findCustomersGroups, getAllCustomerGroupsBy, getAllCustomersBy, getCustomer, setCustomerGroupPriceList };
package/dist/customers.js CHANGED
@@ -30,30 +30,82 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/bigcommerce-entities/customers/index.ts
31
31
  var customers_exports = {};
32
32
  __export(customers_exports, {
33
+ CreateCustomerGroupResponseSchema: () => CreateCustomerGroupResponseSchema,
34
+ CreateCustomerGroupSchema: () => CreateCustomerGroupSchema,
35
+ CustomerGroupSchema: () => CustomerGroupSchema,
36
+ CustomerSchema: () => CustomerSchema,
37
+ FindCustomerGroupsCriteriaSchema: () => FindCustomerGroupsCriteriaSchema,
38
+ FindCustomerResponse: () => FindCustomerResponse,
39
+ FindCustomersCriteriaSchema: () => FindCustomersCriteriaSchema,
40
+ SetCustomerGroupPriceListResponseSchema: () => SetCustomerGroupPriceListResponseSchema,
41
+ SetCustomerGroupPriceListSchema: () => SetCustomerGroupPriceListSchema,
42
+ createCustomerGroup: () => createCustomerGroup,
33
43
  findCustomers: () => findCustomers,
44
+ findCustomersGroups: () => findCustomersGroups,
45
+ getAllCustomerGroupsBy: () => getAllCustomerGroupsBy,
34
46
  getAllCustomersBy: () => getAllCustomersBy,
35
- getCustomer: () => getCustomer
47
+ getCustomer: () => getCustomer,
48
+ setCustomerGroupPriceList: () => setCustomerGroupPriceList
36
49
  });
37
50
  module.exports = __toCommonJS(customers_exports);
38
51
 
39
- // src/bigcommerce-entities/customers/find-customers.ts
52
+ // src/bigcommerce-entities/customers/create-customer-group.ts
40
53
  var import_effect8 = require("effect");
41
54
 
42
55
  // src/constants.ts
43
56
  var import_effect = require("effect");
44
- var DEFAULT_TIMEOUT_MS = 3e4;
45
- var API_BASE_URLS = {
46
- B2B: "https://api-b2b.bigcommerce.com/api",
47
- REGULAR: "https://api.bigcommerce.com/stores"
57
+ var DEFAULTS = {
58
+ retry: {
59
+ policy: import_effect.Schedule.exponential(import_effect.Duration.millis(200), 2).pipe(
60
+ import_effect.Schedule.intersect(import_effect.Schedule.recurs(3))
61
+ )
62
+ },
63
+ timeout: {
64
+ ms: 3e4
65
+ },
66
+ bigcommerceUrls: {
67
+ b2b: "https://api-b2b.bigcommerce.com/api",
68
+ regular: "https://api.bigcommerce.com/stores"
69
+ },
70
+ customers: {
71
+ getBatchSize: 250
72
+ },
73
+ salesStaff: {
74
+ getBatchSize: 250
75
+ },
76
+ companies: {
77
+ salesStaffAssignments: {
78
+ assignBatchSize: 10,
79
+ concurrency: 2
80
+ },
81
+ extraFields: {
82
+ getBatchSize: 250
83
+ },
84
+ roles: {
85
+ getBatchSize: 250
86
+ }
87
+ },
88
+ products: {
89
+ updateBatchSize: 5,
90
+ updateConcurrency: 2,
91
+ inventory: {
92
+ updateBatchSize: 2e3,
93
+ updateConcurrency: 2
94
+ }
95
+ },
96
+ orders: {
97
+ getAllBatchSize: 250,
98
+ shippingAddresses: {
99
+ getAllBatchSize: 250
100
+ },
101
+ products: {
102
+ getAllBatchSize: 250
103
+ }
104
+ },
105
+ priceLists: {
106
+ getAllBatchSize: 250
107
+ }
48
108
  };
49
- var DEFAULT_RETRY_TIMES = 2;
50
- var DEFAULT_RETRY_WAIT = 200;
51
- var DEFAULT_RETRY_SCHEDULE = import_effect.Schedule.exponential(import_effect.Duration.millis(DEFAULT_RETRY_WAIT));
52
- var RETRY_POLICY_WITH_BACKOFF = import_effect.Schedule.exponential(
53
- import_effect.Duration.millis(DEFAULT_RETRY_WAIT),
54
- 2
55
- ).pipe(import_effect.Schedule.intersect(import_effect.Schedule.recurs(DEFAULT_RETRY_TIMES)));
56
- var GET_CUSTOMERS_BATCH_SIZE = 100;
57
109
 
58
110
  // src/core/bigcommerce.error.ts
59
111
  var import_effect2 = require("effect");
@@ -111,7 +163,7 @@ var getBigCommerceTimeout = () => {
111
163
  return import_effect4.Config.nested(import_effect4.Config.number("TIMEOUT"), "BIGCOMMERCE").pipe(
112
164
  import_effect4.Effect.mapError(() => new NoBigCommerceConfigError({ key: "TIMEOUT" })),
113
165
  // Default to 30 seconds if not configured
114
- import_effect4.Effect.orElse(() => import_effect4.Effect.succeed(DEFAULT_TIMEOUT_MS))
166
+ import_effect4.Effect.orElse(() => import_effect4.Effect.succeed(DEFAULTS.timeout.ms))
115
167
  );
116
168
  };
117
169
  var BigCommerceConfigLive = import_effect4.Layer.effect(
@@ -138,7 +190,7 @@ var BigCommerceConfigTest = import_effect4.Layer.succeed(BigCommerceConfig, {
138
190
  getClientId: import_effect4.Effect.succeed("test"),
139
191
  getClientSecret: import_effect4.Effect.succeed("test"),
140
192
  getStoreHash: import_effect4.Effect.succeed("test"),
141
- getTimeout: import_effect4.Effect.succeed(DEFAULT_TIMEOUT_MS)
193
+ getTimeout: import_effect4.Effect.succeed(DEFAULTS.timeout.ms)
142
194
  });
143
195
 
144
196
  // src/core/bigcommerce.fetcher.live.ts
@@ -210,8 +262,12 @@ var applyParams = (url, params) => {
210
262
  if (!params) {
211
263
  return base;
212
264
  }
213
- for (const [key, value] of Object.entries(params)) {
214
- base.searchParams.append(key, `${value}`);
265
+ if (typeof params === "string") {
266
+ base.search = params;
267
+ } else {
268
+ for (const [key, value] of Object.entries(params)) {
269
+ base.searchParams.append(key, `${value}`);
270
+ }
215
271
  }
216
272
  return base;
217
273
  };
@@ -221,9 +277,9 @@ var getBase = ({
221
277
  version
222
278
  }) => {
223
279
  if (isB2B) {
224
- return `${API_BASE_URLS.B2B}/${version}/io/${path}`;
280
+ return `${DEFAULTS.bigcommerceUrls.b2b}/${version}/io/${path}`;
225
281
  }
226
- return `${API_BASE_URLS.REGULAR}/[storeHash]/${version}/${path}`;
282
+ return `${DEFAULTS.bigcommerceUrls.regular}/[storeHash]/${version}/${path}`;
227
283
  };
228
284
  function processSuccessResponse(response, schema) {
229
285
  return import_effect5.Effect.tryPromise({
@@ -300,69 +356,122 @@ var validateInput = (schema, data) => {
300
356
  });
301
357
  };
302
358
 
303
- // src/bigcommerce-entities/customers/schemas/customer.schema.ts
359
+ // src/bigcommerce-entities/customers/schemas/customer-group.schema.ts
304
360
  var z = __toESM(require("zod"));
305
- var CustomerSchema = z.object({
306
- email: z.email(),
307
- first_name: z.string(),
308
- last_name: z.string(),
309
- company: z.string().optional(),
310
- phone: z.string(),
311
- customer_group_id: z.int(),
361
+ var CreateCustomerGroupSchema = z.object({
362
+ name: z.string(),
363
+ discount_rules: z.array(
364
+ z.object({
365
+ type: z.literal("price_list"),
366
+ price_list_id: z.int()
367
+ })
368
+ )
369
+ });
370
+ var CreateCustomerGroupResponseSchema = z.object({
371
+ id: z.int()
372
+ });
373
+ var CustomerGroupSchema = z.object({
312
374
  id: z.int(),
313
- channel_ids: z.array(z.int())
375
+ name: z.string(),
376
+ is_default: z.boolean(),
377
+ is_group_for_guests: z.boolean()
314
378
  });
315
- var FindCustomerResponse = z.object({
316
- data: z.array(CustomerSchema),
317
- meta: z.object({
318
- pagination: z.object({
319
- total: z.int(),
320
- count: z.int(),
321
- per_page: z.int(),
322
- current_page: z.int(),
323
- total_pages: z.int(),
324
- links: z.object({
325
- previous: z.string().optional().nullable(),
326
- current: z.string(),
327
- next: z.string().optional().nullable()
379
+ var FindCustomerGroupsCriteriaSchema = z.object({
380
+ limit: z.int().max(DEFAULTS.customers.getBatchSize).optional(),
381
+ page: z.int().positive().optional()
382
+ });
383
+ var SetCustomerGroupPriceListSchema = z.object({
384
+ data: z.object({
385
+ discount_rules: z.object({
386
+ type: z.literal("price_list"),
387
+ price_list_id: z.int()
388
+ }).array()
389
+ }),
390
+ customerGroupId: z.int()
391
+ });
392
+ var SetCustomerGroupPriceListResponseSchema = z.object({
393
+ id: z.int(),
394
+ name: z.string()
395
+ });
396
+
397
+ // src/bigcommerce-entities/customers/create-customer-group.ts
398
+ var createCustomerGroup = (data) => import_effect8.Effect.gen(function* () {
399
+ const fetcher = yield* BigCommerceFetcher;
400
+ const validatedBody = yield* validateInput(CreateCustomerGroupSchema, data);
401
+ return yield* import_effect8.Effect.retry(
402
+ fetcher.fetch({
403
+ body: validatedBody,
404
+ isB2B: false,
405
+ method: "POST",
406
+ path: "customer_groups",
407
+ resultSchema: CreateCustomerGroupResponseSchema,
408
+ version: "v2"
409
+ }),
410
+ DEFAULTS.retry.policy
411
+ );
412
+ });
413
+
414
+ // src/bigcommerce-entities/customers/find-customers.ts
415
+ var import_effect9 = require("effect");
416
+ var import_node_querystring = require("querystring");
417
+
418
+ // src/bigcommerce-entities/customers/schemas/customer.schema.ts
419
+ var z2 = __toESM(require("zod"));
420
+ var CustomerSchema = z2.object({
421
+ email: z2.email(),
422
+ first_name: z2.string(),
423
+ last_name: z2.string(),
424
+ company: z2.string().optional(),
425
+ phone: z2.string(),
426
+ customer_group_id: z2.int(),
427
+ id: z2.int(),
428
+ channel_ids: z2.array(z2.int())
429
+ });
430
+ var FindCustomerResponse = z2.object({
431
+ data: z2.array(CustomerSchema),
432
+ meta: z2.object({
433
+ pagination: z2.object({
434
+ total: z2.int(),
435
+ count: z2.int(),
436
+ per_page: z2.int(),
437
+ current_page: z2.int(),
438
+ total_pages: z2.int(),
439
+ links: z2.object({
440
+ previous: z2.string().optional().nullable(),
441
+ current: z2.string(),
442
+ next: z2.string().optional().nullable()
328
443
  })
329
444
  })
330
445
  })
331
446
  });
332
447
 
333
448
  // src/bigcommerce-entities/customers/schemas/find-customer.criteria.ts
334
- var z2 = __toESM(require("zod"));
335
- var FindCustomersCriteriaSchema = z2.object({
336
- "id:in": z2.array(z2.int()).transform((ids) => ids.join(",")).optional(),
337
- page: z2.int().optional(),
338
- limit: z2.int().optional(),
339
- "company:in": z2.array(z2.string()).transform((companies) => companies.join(",")).optional(),
340
- "customer_group_id:in": z2.array(z2.int()).transform((ids) => ids.join(",")).optional()
449
+ var z3 = __toESM(require("zod"));
450
+ var FindCustomersCriteriaSchema = z3.object({
451
+ "id:in": z3.array(z3.int()).transform((ids) => ids.join(",")).optional(),
452
+ page: z3.int().optional(),
453
+ limit: z3.int().optional(),
454
+ "company:in": z3.array(z3.string()).transform((companies) => companies.join(",")).optional(),
455
+ "customer_group_id:in": z3.array(z3.int()).transform((ids) => ids.join(",")).optional()
341
456
  });
342
457
 
343
458
  // src/bigcommerce-entities/customers/find-customers.ts
344
459
  var findCustomers = (criteria) => {
345
- return import_effect8.Effect.gen(function* () {
460
+ return import_effect9.Effect.gen(function* () {
346
461
  const fetcher = yield* BigCommerceFetcher;
347
- const validatedResponse = yield* validateInput(FindCustomersCriteriaSchema, criteria ?? {});
348
- const query = {};
349
- for (const [key, value] of Object.entries(validatedResponse)) {
350
- if (value !== void 0) {
351
- query[key] = `${value}`;
352
- }
353
- }
462
+ const validatedQuery = yield* validateInput(FindCustomersCriteriaSchema, criteria ?? {});
354
463
  return yield* fetcher.fetch({
355
464
  method: "GET",
356
465
  path: `customers`,
357
466
  isB2B: false,
358
467
  version: "v3",
359
468
  resultSchema: FindCustomerResponse,
360
- query
469
+ query: (0, import_node_querystring.stringify)(validatedQuery)
361
470
  });
362
471
  });
363
472
  };
364
473
  var getAllCustomersBy = (criteria) => {
365
- return import_effect8.Effect.gen(function* () {
474
+ return import_effect9.Effect.gen(function* () {
366
475
  const allCustomers = [];
367
476
  let page = 1;
368
477
  let hasMoreCustomers = true;
@@ -370,7 +479,7 @@ var getAllCustomersBy = (criteria) => {
370
479
  const customers = yield* findCustomers({
371
480
  ...criteria,
372
481
  page,
373
- limit: GET_CUSTOMERS_BATCH_SIZE
482
+ limit: DEFAULTS.customers.getBatchSize
374
483
  });
375
484
  if (customers.meta.pagination.links.next) {
376
485
  allCustomers.push(...customers.data);
@@ -383,17 +492,90 @@ var getAllCustomersBy = (criteria) => {
383
492
  });
384
493
  };
385
494
 
495
+ // src/bigcommerce-entities/customers/get-all-customer-groups.ts
496
+ var import_effect10 = require("effect");
497
+ var import_node_querystring2 = require("querystring");
498
+ var z4 = __toESM(require("zod"));
499
+ var FindCustomerResponse2 = z4.union([
500
+ z4.array(CustomerGroupSchema),
501
+ z4.literal(""),
502
+ z4.literal(null)
503
+ ]);
504
+ var findCustomersGroups = (criteria) => import_effect10.Effect.gen(function* () {
505
+ const fetcher = yield* BigCommerceFetcher;
506
+ const validatedQuery = yield* validateInput(FindCustomerGroupsCriteriaSchema, criteria ?? {});
507
+ const response = yield* fetcher.fetch({
508
+ method: "GET",
509
+ path: `customers`,
510
+ isB2B: false,
511
+ version: "v3",
512
+ resultSchema: FindCustomerResponse2,
513
+ query: (0, import_node_querystring2.stringify)(validatedQuery)
514
+ });
515
+ return response || [];
516
+ });
517
+ var getAllCustomerGroupsBy = (criteria) => import_effect10.Effect.gen(function* () {
518
+ const all = [];
519
+ let page = 1;
520
+ let hasMore = true;
521
+ while (hasMore) {
522
+ const groups = yield* findCustomersGroups({
523
+ ...criteria,
524
+ page,
525
+ limit: DEFAULTS.customers.getBatchSize
526
+ });
527
+ if (groups.length) {
528
+ all.push(...groups);
529
+ page++;
530
+ } else {
531
+ hasMore = false;
532
+ }
533
+ }
534
+ return all;
535
+ });
536
+
386
537
  // src/bigcommerce-entities/customers/get-customer.ts
387
- var import_effect9 = require("effect");
538
+ var import_effect11 = require("effect");
388
539
  var getCustomer = (customerId) => {
389
540
  return findCustomers({
390
541
  "id:in": [customerId]
391
- }).pipe(import_effect9.Effect.map((response) => response.data[0]));
542
+ }).pipe(import_effect11.Effect.map((response) => response.data[0]));
392
543
  };
544
+
545
+ // src/bigcommerce-entities/customers/set-customer-group-price-list.ts
546
+ var import_effect12 = require("effect");
547
+ var setCustomerGroupPriceList = (input) => import_effect12.Effect.gen(function* () {
548
+ const { customerGroupId, data } = yield* validateInput(SetCustomerGroupPriceListSchema, input);
549
+ const fetcher = yield* BigCommerceFetcher;
550
+ return yield* import_effect12.Effect.retry(
551
+ fetcher.fetch({
552
+ body: data,
553
+ isB2B: false,
554
+ method: "PUT",
555
+ path: `customer_groups/${customerGroupId}`,
556
+ resultSchema: SetCustomerGroupPriceListResponseSchema,
557
+ version: "v2"
558
+ }),
559
+ DEFAULTS.retry.policy
560
+ );
561
+ });
393
562
  // Annotate the CommonJS export names for ESM import in node:
394
563
  0 && (module.exports = {
564
+ CreateCustomerGroupResponseSchema,
565
+ CreateCustomerGroupSchema,
566
+ CustomerGroupSchema,
567
+ CustomerSchema,
568
+ FindCustomerGroupsCriteriaSchema,
569
+ FindCustomerResponse,
570
+ FindCustomersCriteriaSchema,
571
+ SetCustomerGroupPriceListResponseSchema,
572
+ SetCustomerGroupPriceListSchema,
573
+ createCustomerGroup,
395
574
  findCustomers,
575
+ findCustomersGroups,
576
+ getAllCustomerGroupsBy,
396
577
  getAllCustomersBy,
397
- getCustomer
578
+ getCustomer,
579
+ setCustomerGroupPriceList
398
580
  });
399
581
  //# sourceMappingURL=customers.js.map