@marteye/studiojs 1.1.46 → 1.1.47

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.
package/dist/index.js CHANGED
@@ -77,7 +77,7 @@ function SimpleHttpClient(baseUrl, apiKey, fetch, defaultTimeout, debug = false)
77
77
  }
78
78
 
79
79
  // Path: studiojs/src/resources/markets.ts
80
- function create$o(_) {
80
+ function create$q(_) {
81
81
  const actions = {
82
82
  /***
83
83
  * This is used to construct the action from the request body
@@ -107,7 +107,7 @@ function create$o(_) {
107
107
  return actions;
108
108
  }
109
109
 
110
- function create$n(httpClient) {
110
+ function create$p(httpClient) {
111
111
  let activity = {
112
112
  /**
113
113
  * List activity logs for a market with pagination and filtering
@@ -159,7 +159,7 @@ function create$n(httpClient) {
159
159
  return activity;
160
160
  }
161
161
 
162
- function create$m(httpClient) {
162
+ function create$o(httpClient) {
163
163
  return {
164
164
  list: async (marketId) => {
165
165
  return httpClient.get(`/${marketId}/adjustments`);
@@ -176,7 +176,7 @@ function create$m(httpClient) {
176
176
  };
177
177
  }
178
178
 
179
- function create$l(httpClient) {
179
+ function create$n(httpClient) {
180
180
  return {
181
181
  /**
182
182
  * Get the full cart for a customer including extras and uninvoiced lots
@@ -199,7 +199,7 @@ function create$l(httpClient) {
199
199
  };
200
200
  }
201
201
 
202
- function create$k(httpClient) {
202
+ function create$m(httpClient) {
203
203
  return {
204
204
  list: async (marketId) => {
205
205
  return httpClient.get(`/${marketId}/extras`);
@@ -219,7 +219,7 @@ function create$k(httpClient) {
219
219
  /***
220
220
  * Bidder applications
221
221
  */
222
- function create$j(httpClient) {
222
+ function create$l(httpClient) {
223
223
  let applications = {
224
224
  /**
225
225
  * List applications for a market with optional filtering
@@ -303,7 +303,7 @@ function create$j(httpClient) {
303
303
  }
304
304
 
305
305
  // Path: studiojs/src/resources/markets.ts
306
- function create$i(httpClient) {
306
+ function create$k(httpClient) {
307
307
  let customers = {
308
308
  list: async (marketId, lastId) => {
309
309
  let params = {};
@@ -350,6 +350,598 @@ function create$i(httpClient) {
350
350
  return customers;
351
351
  }
352
352
 
353
+ const DEFAULT_PAGE_SIZE = 100;
354
+ const MAX_MEMBER_BATCH_SIZE = 100;
355
+ function create$j(httpClient) {
356
+ const customerLists = {
357
+ list: async (marketId, options) => {
358
+ return httpClient.get(`/${marketId}/lists`, buildListQueryParams(options));
359
+ },
360
+ listAll: async (marketId, options) => {
361
+ var _a;
362
+ let lists = [];
363
+ let offset = 0;
364
+ let total = Number.POSITIVE_INFINITY;
365
+ let limit = (_a = options === null || options === void 0 ? void 0 : options.limit) !== null && _a !== void 0 ? _a : DEFAULT_PAGE_SIZE;
366
+ while (offset < total) {
367
+ let page = await customerLists.list(marketId, {
368
+ type: options === null || options === void 0 ? void 0 : options.type,
369
+ limit,
370
+ offset,
371
+ });
372
+ lists = lists.concat(page.lists);
373
+ total = page.total;
374
+ if (page.lists.length === 0) {
375
+ break;
376
+ }
377
+ offset += page.lists.length;
378
+ }
379
+ return lists;
380
+ },
381
+ get: async (marketId, listId) => {
382
+ return httpClient.get(`/${marketId}/lists/${listId}`);
383
+ },
384
+ getBySlug: async (marketId, slug) => {
385
+ return httpClient.get(`/${marketId}/lists/by-slug/${encodeURIComponent(slug)}`);
386
+ },
387
+ create: async (marketId, payload) => {
388
+ return httpClient.post(`/${marketId}/lists`, normalizeCreatePayload(payload));
389
+ },
390
+ update: async (marketId, listId, payload) => {
391
+ let body = await buildUpdatePayload(customerLists, marketId, listId, payload);
392
+ return httpClient.post(`/${marketId}/lists/${listId}`, body);
393
+ },
394
+ delete: async (marketId, listId) => {
395
+ return httpClient.delete(`/${marketId}/lists/${listId}`);
396
+ },
397
+ refresh: async (marketId, listId) => {
398
+ return httpClient.post(`/${marketId}/lists/${listId}/refresh`, {});
399
+ },
400
+ getMembers: async (marketId, listId, options) => {
401
+ return httpClient.get(`/${marketId}/lists/${listId}/members`, buildMembersQueryParams(options));
402
+ },
403
+ getAllMembers: async (marketId, listId, options) => {
404
+ var _a;
405
+ let members = [];
406
+ let offset = 0;
407
+ let limit = (_a = options === null || options === void 0 ? void 0 : options.limit) !== null && _a !== void 0 ? _a : DEFAULT_PAGE_SIZE;
408
+ let hasMore = true;
409
+ while (hasMore) {
410
+ let page = await customerLists.getMembers(marketId, listId, {
411
+ limit,
412
+ offset,
413
+ includeArchived: options === null || options === void 0 ? void 0 : options.includeArchived,
414
+ });
415
+ members = members.concat(page.members);
416
+ hasMore = page.hasMore;
417
+ if (page.members.length === 0) {
418
+ break;
419
+ }
420
+ offset += page.members.length;
421
+ }
422
+ return members;
423
+ },
424
+ addMembers: async (marketId, listId, customerIds) => {
425
+ if (customerIds.length === 0) {
426
+ return {
427
+ added: 0,
428
+ alreadyMembers: 0,
429
+ notFound: 0,
430
+ memberCount: 0,
431
+ };
432
+ }
433
+ let result = {
434
+ added: 0,
435
+ alreadyMembers: 0,
436
+ notFound: 0,
437
+ memberCount: 0,
438
+ };
439
+ for (let i = 0; i < customerIds.length; i += MAX_MEMBER_BATCH_SIZE) {
440
+ let chunk = customerIds.slice(i, i + MAX_MEMBER_BATCH_SIZE);
441
+ let response = await httpClient.post(`/${marketId}/lists/${listId}/members`, { customerIds: chunk });
442
+ result.added += response.added;
443
+ result.alreadyMembers += response.alreadyMembers;
444
+ result.notFound += response.notFound;
445
+ result.memberCount = response.memberCount;
446
+ }
447
+ return result;
448
+ },
449
+ removeMember: async (marketId, listId, customerId) => {
450
+ return httpClient.delete(`/${marketId}/lists/${listId}/members/${customerId}`);
451
+ },
452
+ preview: async (marketId, filters) => {
453
+ return httpClient.get(`/${marketId}/reports/customer-lists`, buildPreviewQueryParams(filters));
454
+ },
455
+ listProductCodes: async (marketId) => {
456
+ let response = await httpClient.get(`/${marketId}/reports/customer-lists`, { productCodesOnly: "true" });
457
+ return {
458
+ uniqueProductCodes: response.summary.uniqueProductCodes,
459
+ };
460
+ },
461
+ view: async (marketId, listIdOrSlug, options) => {
462
+ var _a;
463
+ let list = await resolveList(customerLists, marketId, listIdOrSlug, options);
464
+ if (list.type === "simple") {
465
+ let shouldFetchAllMembers = (_a = options === null || options === void 0 ? void 0 : options.allMembers) !== null && _a !== void 0 ? _a : ((options === null || options === void 0 ? void 0 : options.limit) === undefined && (options === null || options === void 0 ? void 0 : options.offset) === undefined);
466
+ if (shouldFetchAllMembers) {
467
+ let members = await customerLists.getAllMembers(marketId, list.id);
468
+ return {
469
+ mode: "simple",
470
+ list,
471
+ members,
472
+ total: members.length,
473
+ };
474
+ }
475
+ let response = await customerLists.getMembers(marketId, list.id, {
476
+ limit: options === null || options === void 0 ? void 0 : options.limit,
477
+ offset: options === null || options === void 0 ? void 0 : options.offset,
478
+ });
479
+ return {
480
+ mode: "simple",
481
+ list,
482
+ members: response.members,
483
+ total: response.total,
484
+ };
485
+ }
486
+ if (!list.query) {
487
+ throw new Error(`Smart list ${list.id} has no query defined`);
488
+ }
489
+ if ((options === null || options === void 0 ? void 0 : options.refresh) || hasRollingDates(list)) {
490
+ try {
491
+ await customerLists.refresh(marketId, list.id);
492
+ }
493
+ catch (error) {
494
+ if (!isRateLimitError(error)) {
495
+ throw error;
496
+ }
497
+ }
498
+ }
499
+ let effectiveQuery = applyRollingDatesToQuery(list);
500
+ let effectiveFilters = queryToFilters(effectiveQuery);
501
+ let preview = await customerLists.preview(marketId, effectiveFilters);
502
+ let excludedCustomerIds = new Set(list.excludedCustomerIds || []);
503
+ let rows = preview.rows.filter((row) => !excludedCustomerIds.has(row.customerId));
504
+ return {
505
+ mode: "smart",
506
+ list,
507
+ effectiveFilters,
508
+ rows,
509
+ summary: summariseRows(rows),
510
+ };
511
+ },
512
+ };
513
+ return customerLists;
514
+ }
515
+ async function buildUpdatePayload(customerLists, marketId, listId, payload) {
516
+ if (payload.query !== undefined && payload.filters !== undefined) {
517
+ throw new Error("Provide either query or filters when updating a customer list, not both");
518
+ }
519
+ let body = {};
520
+ if (payload.name !== undefined) {
521
+ body.name = payload.name;
522
+ }
523
+ if (payload.description !== undefined) {
524
+ body.description = payload.description;
525
+ }
526
+ if (payload.query !== undefined) {
527
+ body.query = payload.query;
528
+ }
529
+ if (payload.filters !== undefined) {
530
+ let existing = await customerLists.get(marketId, listId);
531
+ if (existing.type !== "smart") {
532
+ throw new Error("Cannot update filters on a simple list");
533
+ }
534
+ let existingFilters = queryToFilters(existing.query);
535
+ body.query = filtersToCustomerListQuery(mergeCustomerListFilters(existingFilters, payload.filters));
536
+ }
537
+ if (Object.keys(body).length === 0) {
538
+ throw new Error("No update fields provided");
539
+ }
540
+ return body;
541
+ }
542
+ function normalizeCreatePayload(payload) {
543
+ var _a;
544
+ if (payload.type === "simple") {
545
+ return {
546
+ name: payload.name,
547
+ description: payload.description,
548
+ type: payload.type,
549
+ };
550
+ }
551
+ if (payload.query !== undefined && payload.filters !== undefined) {
552
+ throw new Error("Provide either query or filters when creating a smart list, not both");
553
+ }
554
+ let query = (_a = payload.query) !== null && _a !== void 0 ? _a : filtersToCustomerListQuery(payload.filters || {});
555
+ return {
556
+ name: payload.name,
557
+ description: payload.description,
558
+ type: payload.type,
559
+ query,
560
+ };
561
+ }
562
+ function buildListQueryParams(options) {
563
+ let queryParams = {};
564
+ if (options === null || options === void 0 ? void 0 : options.type) {
565
+ queryParams.type = options.type;
566
+ }
567
+ if ((options === null || options === void 0 ? void 0 : options.limit) !== undefined) {
568
+ queryParams.limit = String(options.limit);
569
+ }
570
+ if ((options === null || options === void 0 ? void 0 : options.offset) !== undefined) {
571
+ queryParams.offset = String(options.offset);
572
+ }
573
+ return Object.keys(queryParams).length > 0 ? queryParams : undefined;
574
+ }
575
+ function buildMembersQueryParams(options) {
576
+ let queryParams = {};
577
+ if ((options === null || options === void 0 ? void 0 : options.limit) !== undefined) {
578
+ queryParams.limit = String(options.limit);
579
+ }
580
+ if ((options === null || options === void 0 ? void 0 : options.offset) !== undefined) {
581
+ queryParams.offset = String(options.offset);
582
+ }
583
+ if ((options === null || options === void 0 ? void 0 : options.includeArchived) !== undefined) {
584
+ queryParams.includeArchived = String(options.includeArchived);
585
+ }
586
+ return Object.keys(queryParams).length > 0 ? queryParams : undefined;
587
+ }
588
+ function buildPreviewQueryParams(filters) {
589
+ var _a;
590
+ let params = {};
591
+ let filter = buildFilterExpression(filters);
592
+ let excludeFilters = buildExcludeFilters(filters);
593
+ if (filter) {
594
+ params.filter = filter;
595
+ }
596
+ if (excludeFilters.length > 0) {
597
+ params.excludeFilters = JSON.stringify(excludeFilters);
598
+ }
599
+ params.role = (_a = filters.role) !== null && _a !== void 0 ? _a : "both";
600
+ if (filters.geoBounds) {
601
+ params.bounds = JSON.stringify(filters.geoBounds);
602
+ }
603
+ if (filters.secondaryFilter) {
604
+ params.secondaryFilter = JSON.stringify({
605
+ role: filters.secondaryFilter.role,
606
+ filter: buildFilterExpression(filters.secondaryFilter),
607
+ ...(filters.secondaryFilter.geoBounds
608
+ ? { bounds: filters.secondaryFilter.geoBounds }
609
+ : {}),
610
+ });
611
+ }
612
+ return params;
613
+ }
614
+ function filtersToCustomerListQuery(filters) {
615
+ var _a;
616
+ let excludeFilters = buildExcludeFilters(filters);
617
+ let query = {
618
+ role: (_a = filters.role) !== null && _a !== void 0 ? _a : "both",
619
+ };
620
+ let filter = buildFilterExpression(filters);
621
+ if (filter) {
622
+ query.filter = filter;
623
+ }
624
+ if (excludeFilters.length > 0) {
625
+ query.excludeFilters = excludeFilters;
626
+ }
627
+ if (filters.geoBounds) {
628
+ query.bounds = filters.geoBounds;
629
+ }
630
+ if (filters.rollingDateConfig) {
631
+ query.rollingDateConfig = filters.rollingDateConfig;
632
+ }
633
+ if (filters.secondaryFilter) {
634
+ query.secondaryFilter = {
635
+ role: filters.secondaryFilter.role,
636
+ filter: buildFilterExpression(filters.secondaryFilter),
637
+ ...(filters.secondaryFilter.geoBounds
638
+ ? { bounds: filters.secondaryFilter.geoBounds }
639
+ : {}),
640
+ ...(filters.secondaryFilter.rollingDateConfig
641
+ ? { rollingDateConfig: filters.secondaryFilter.rollingDateConfig }
642
+ : {}),
643
+ };
644
+ }
645
+ return query;
646
+ }
647
+ function queryToFilters(query) {
648
+ if (!query) {
649
+ return { role: "both", productCodes: [] };
650
+ }
651
+ let filters = {
652
+ role: query.role,
653
+ dateStart: extractDate(query.filter, ">="),
654
+ dateEnd: extractDate(query.filter, "<="),
655
+ productCodes: extractProductCodes(query.filter),
656
+ excludedProductCodes: [],
657
+ geoBounds: query.bounds || null,
658
+ boughtOnlineOnly: /@boughtOnline\s*=\s*true/.test(query.filter || ""),
659
+ cattleBreeds: extractAllMatches(query.filter, /@breedCodeOfCattle\s*=\s*"([^"]+)"/g),
660
+ sheepBreeds: extractAllMatches(query.filter, /breedOfSheep\s*=\s*"([^"]+)"/g),
661
+ rollingDateConfig: query.rollingDateConfig,
662
+ };
663
+ for (let excludeFilter of query.excludeFilters || []) {
664
+ if (filters.excludeDateStart == null) {
665
+ filters.excludeDateStart = extractDate(excludeFilter, ">=");
666
+ }
667
+ if (filters.excludeDateEnd == null) {
668
+ filters.excludeDateEnd = extractDate(excludeFilter, "<=");
669
+ }
670
+ filters.excludedProductCodes = uniqueStrings((filters.excludedProductCodes || []).concat(extractProductCodes(excludeFilter)));
671
+ }
672
+ if (query.secondaryFilter) {
673
+ filters.secondaryFilter = {
674
+ role: query.secondaryFilter.role,
675
+ dateStart: extractDate(query.secondaryFilter.filter, ">="),
676
+ dateEnd: extractDate(query.secondaryFilter.filter, "<="),
677
+ productCodes: extractProductCodes(query.secondaryFilter.filter),
678
+ geoBounds: query.secondaryFilter.bounds || null,
679
+ rollingDateConfig: query.secondaryFilter.rollingDateConfig,
680
+ };
681
+ }
682
+ return filters;
683
+ }
684
+ function mergeCustomerListFilters(base, updates) {
685
+ let merged = { ...base };
686
+ if (updates.role !== undefined)
687
+ merged.role = updates.role;
688
+ if (updates.dateStart !== undefined)
689
+ merged.dateStart = updates.dateStart;
690
+ if (updates.dateEnd !== undefined)
691
+ merged.dateEnd = updates.dateEnd;
692
+ if (updates.productCodes !== undefined)
693
+ merged.productCodes = [...updates.productCodes];
694
+ if (updates.excludeDateStart !== undefined) {
695
+ merged.excludeDateStart = updates.excludeDateStart;
696
+ }
697
+ if (updates.excludeDateEnd !== undefined) {
698
+ merged.excludeDateEnd = updates.excludeDateEnd;
699
+ }
700
+ if (updates.excludedProductCodes !== undefined) {
701
+ merged.excludedProductCodes = [...updates.excludedProductCodes];
702
+ }
703
+ if (updates.geoBounds !== undefined)
704
+ merged.geoBounds = updates.geoBounds;
705
+ if (updates.boughtOnlineOnly !== undefined) {
706
+ merged.boughtOnlineOnly = updates.boughtOnlineOnly;
707
+ }
708
+ if (updates.cattleBreeds !== undefined) {
709
+ merged.cattleBreeds = [...updates.cattleBreeds];
710
+ }
711
+ if (updates.sheepBreeds !== undefined) {
712
+ merged.sheepBreeds = [...updates.sheepBreeds];
713
+ }
714
+ if (updates.rollingDateConfig !== undefined) {
715
+ merged.rollingDateConfig = updates.rollingDateConfig;
716
+ }
717
+ if (updates.secondaryFilter !== undefined) {
718
+ if (updates.secondaryFilter === null) {
719
+ merged.secondaryFilter = null;
720
+ }
721
+ else {
722
+ let nextSecondary = merged.secondaryFilter
723
+ ? { ...merged.secondaryFilter }
724
+ : { role: updates.secondaryFilter.role || "both", productCodes: [] };
725
+ if (updates.secondaryFilter.role !== undefined) {
726
+ nextSecondary.role = updates.secondaryFilter.role;
727
+ }
728
+ if (updates.secondaryFilter.dateStart !== undefined) {
729
+ nextSecondary.dateStart = updates.secondaryFilter.dateStart;
730
+ }
731
+ if (updates.secondaryFilter.dateEnd !== undefined) {
732
+ nextSecondary.dateEnd = updates.secondaryFilter.dateEnd;
733
+ }
734
+ if (updates.secondaryFilter.productCodes !== undefined) {
735
+ nextSecondary.productCodes = [...updates.secondaryFilter.productCodes];
736
+ }
737
+ if (updates.secondaryFilter.geoBounds !== undefined) {
738
+ nextSecondary.geoBounds = updates.secondaryFilter.geoBounds;
739
+ }
740
+ if (updates.secondaryFilter.rollingDateConfig !== undefined) {
741
+ nextSecondary.rollingDateConfig =
742
+ updates.secondaryFilter.rollingDateConfig;
743
+ }
744
+ merged.secondaryFilter = nextSecondary;
745
+ }
746
+ }
747
+ return merged;
748
+ }
749
+ function buildExcludeFilters(filters) {
750
+ let excludeFilters = [];
751
+ if (filters.excludeDateStart || filters.excludeDateEnd) {
752
+ let clauses = [];
753
+ if (filters.excludeDateStart) {
754
+ clauses.push(`saleDate >= "${filters.excludeDateStart}"`);
755
+ }
756
+ if (filters.excludeDateEnd) {
757
+ clauses.push(`saleDate <= "${filters.excludeDateEnd}"`);
758
+ }
759
+ if (clauses.length > 0) {
760
+ excludeFilters.push(clauses.join(" AND "));
761
+ }
762
+ }
763
+ if (filters.excludedProductCodes && filters.excludedProductCodes.length > 0) {
764
+ if (filters.excludedProductCodes.length === 1) {
765
+ excludeFilters.push(`productCode = "${filters.excludedProductCodes[0]}"`);
766
+ }
767
+ else {
768
+ excludeFilters.push(filters.excludedProductCodes
769
+ .map((code) => `productCode = "${code}"`)
770
+ .join(" OR "));
771
+ }
772
+ }
773
+ return excludeFilters;
774
+ }
775
+ function buildFilterExpression(filters) {
776
+ let fixedClauses = [];
777
+ let alternativeGroups = [];
778
+ if (filters.dateStart)
779
+ fixedClauses.push(`saleDate >= "${filters.dateStart}"`);
780
+ if (filters.dateEnd)
781
+ fixedClauses.push(`saleDate <= "${filters.dateEnd}"`);
782
+ if (filters.productCodes && filters.productCodes.length > 0) {
783
+ alternativeGroups.push(filters.productCodes.map((code) => `productCode = "${code}"`));
784
+ }
785
+ if (filters.boughtOnlineOnly) {
786
+ fixedClauses.push(`@boughtOnline = true`);
787
+ }
788
+ let breedClauses = [];
789
+ for (let breed of filters.cattleBreeds || []) {
790
+ breedClauses.push(`@breedCodeOfCattle = "${breed}"`);
791
+ }
792
+ for (let breed of filters.sheepBreeds || []) {
793
+ breedClauses.push(`breedOfSheep = "${breed}"`);
794
+ }
795
+ if (breedClauses.length > 0) {
796
+ alternativeGroups.push(breedClauses);
797
+ }
798
+ let expandedBranches = alternativeGroups.reduce((branches, alternatives) => branches.flatMap((branch) => alternatives.map((alternative) => [...branch, alternative])), [[]]);
799
+ let expressions = expandedBranches
800
+ .map((branch) => [...fixedClauses, ...branch].filter(Boolean))
801
+ .filter((branch) => branch.length > 0)
802
+ .map((branch) => branch.join(" AND "));
803
+ if (expressions.length === 0) {
804
+ return undefined;
805
+ }
806
+ return expressions.join(" OR ");
807
+ }
808
+ async function resolveList(customerLists, marketId, listIdOrSlug, options) {
809
+ let identifierType = (options === null || options === void 0 ? void 0 : options.identifierType) || "auto";
810
+ if (identifierType === "id") {
811
+ return customerLists.get(marketId, listIdOrSlug);
812
+ }
813
+ if (identifierType === "slug") {
814
+ return customerLists.getBySlug(marketId, listIdOrSlug);
815
+ }
816
+ let firstLookup = listIdOrSlug.startsWith("list_") ? "id" : "slug";
817
+ try {
818
+ return firstLookup === "id"
819
+ ? await customerLists.get(marketId, listIdOrSlug)
820
+ : await customerLists.getBySlug(marketId, listIdOrSlug);
821
+ }
822
+ catch (error) {
823
+ if (!isNotFoundError(error)) {
824
+ throw error;
825
+ }
826
+ }
827
+ return firstLookup === "id"
828
+ ? customerLists.getBySlug(marketId, listIdOrSlug)
829
+ : customerLists.get(marketId, listIdOrSlug);
830
+ }
831
+ function applyRollingDatesToQuery(list) {
832
+ var _a;
833
+ if (!list.query) {
834
+ throw new Error(`Smart list ${list.id} has no query defined`);
835
+ }
836
+ let query = {
837
+ ...list.query,
838
+ ...(list.query.secondaryFilter
839
+ ? { secondaryFilter: { ...list.query.secondaryFilter } }
840
+ : {}),
841
+ };
842
+ let topLevelRollingConfig = list.query.rollingDateConfig || list.rollingDateConfig;
843
+ if (topLevelRollingConfig) {
844
+ query.filter = applyRollingDatesToFilter(query.filter, topLevelRollingConfig, list.createdAt);
845
+ }
846
+ if ((_a = query.secondaryFilter) === null || _a === void 0 ? void 0 : _a.rollingDateConfig) {
847
+ query.secondaryFilter.filter = applyRollingDatesToFilter(query.secondaryFilter.filter, query.secondaryFilter.rollingDateConfig, list.createdAt);
848
+ }
849
+ return query;
850
+ }
851
+ function applyRollingDatesToFilter(filter, rollingDateConfig, createdAt) {
852
+ if (!filter) {
853
+ return filter;
854
+ }
855
+ let createdAtDate = new Date(createdAt);
856
+ if (Number.isNaN(createdAtDate.getTime())) {
857
+ return filter;
858
+ }
859
+ let originalStart = new Date(rollingDateConfig.originalStart);
860
+ let originalEnd = new Date(rollingDateConfig.originalEnd);
861
+ if (Number.isNaN(originalStart.getTime()) ||
862
+ Number.isNaN(originalEnd.getTime())) {
863
+ return filter;
864
+ }
865
+ let now = new Date();
866
+ let daysElapsed = Math.floor((now.getTime() - createdAtDate.getTime()) / (24 * 60 * 60 * 1000));
867
+ let nextStart = new Date(originalStart.getTime() + daysElapsed * 24 * 60 * 60 * 1000);
868
+ let nextEnd = new Date(originalEnd.getTime() + daysElapsed * 24 * 60 * 60 * 1000);
869
+ return filter
870
+ .replace(/saleDate\s*>=\s*"[^"]+"/g, `saleDate >= "${formatDate(nextStart)}"`)
871
+ .replace(/saleDate\s*<=\s*"[^"]+"/g, `saleDate <= "${formatDate(nextEnd)}"`);
872
+ }
873
+ function hasRollingDates(list) {
874
+ var _a, _b, _c;
875
+ return Boolean(((_a = list.query) === null || _a === void 0 ? void 0 : _a.rollingDateConfig) ||
876
+ list.rollingDateConfig ||
877
+ ((_c = (_b = list.query) === null || _b === void 0 ? void 0 : _b.secondaryFilter) === null || _c === void 0 ? void 0 : _c.rollingDateConfig));
878
+ }
879
+ function summariseRows(rows) {
880
+ let uniqueProductCodes = new Set();
881
+ let totalSoldValueInCents = 0;
882
+ let totalPurchasedValueInCents = 0;
883
+ let customersWithLocation = 0;
884
+ for (let row of rows) {
885
+ totalSoldValueInCents += Number(row.totalSoldValueInCents || 0);
886
+ totalPurchasedValueInCents += Number(row.totalPurchasedValueInCents || 0);
887
+ if (row.latitude != null && row.longitude != null) {
888
+ customersWithLocation += 1;
889
+ }
890
+ for (let productCode of row.productCodesSold || []) {
891
+ uniqueProductCodes.add(productCode);
892
+ }
893
+ for (let productCode of row.productCodesBought || []) {
894
+ uniqueProductCodes.add(productCode);
895
+ }
896
+ }
897
+ return {
898
+ totalCustomers: rows.length,
899
+ totalSoldValueInCents,
900
+ totalPurchasedValueInCents,
901
+ customersWithLocation,
902
+ uniqueProductCodes: Array.from(uniqueProductCodes),
903
+ };
904
+ }
905
+ function extractDate(filter, operator) {
906
+ if (!filter) {
907
+ return null;
908
+ }
909
+ let escapedOperator = operator.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
910
+ let match = filter.match(new RegExp(`saleDate\\s*${escapedOperator}\\s*"([^"]+)"`));
911
+ return match ? match[1] : null;
912
+ }
913
+ function extractProductCodes(filter) {
914
+ if (!filter) {
915
+ return [];
916
+ }
917
+ let inMatch = filter.match(/productCode\s+IN\s*\(([^)]+)\)/);
918
+ if (inMatch) {
919
+ return uniqueStrings(inMatch[1]
920
+ .split(",")
921
+ .map((value) => value.trim().replace(/^"|"$/g, ""))
922
+ .filter(Boolean));
923
+ }
924
+ return uniqueStrings(extractAllMatches(filter, /productCode\s*=\s*"([^"]+)"/g));
925
+ }
926
+ function extractAllMatches(filter, regex) {
927
+ if (!filter) {
928
+ return [];
929
+ }
930
+ return [...filter.matchAll(regex)].map((match) => match[1]).filter(Boolean);
931
+ }
932
+ function uniqueStrings(values) {
933
+ return Array.from(new Set(values));
934
+ }
935
+ function formatDate(date) {
936
+ return date.toISOString().split("T")[0];
937
+ }
938
+ function isNotFoundError(error) {
939
+ return error instanceof Error && error.message.includes(" not found");
940
+ }
941
+ function isRateLimitError(error) {
942
+ return error instanceof Error && error.message.includes("status 429");
943
+ }
944
+
353
945
  var util;
354
946
  (function (util) {
355
947
  util.assertEqual = (val) => val;
@@ -5140,7 +5732,7 @@ const uploadSingleFile = async (input, token) => {
5140
5732
  };
5141
5733
 
5142
5734
  // Multipart Upload for Media to the MARTEYE Media Service
5143
- function create$h() {
5735
+ function create$i() {
5144
5736
  const files = {
5145
5737
  uploadSingleFile: async (input, token) => {
5146
5738
  return await uploadSingleFile(input, token);
@@ -5155,7 +5747,7 @@ function create$h() {
5155
5747
  return files;
5156
5748
  }
5157
5749
 
5158
- function create$g(httpClient) {
5750
+ function create$h(httpClient) {
5159
5751
  const invoices = {
5160
5752
  /**
5161
5753
  * List all invoices for a market with pagination
@@ -5183,7 +5775,7 @@ function create$g(httpClient) {
5183
5775
  return invoices;
5184
5776
  }
5185
5777
 
5186
- function create$f(httpClient) {
5778
+ function create$g(httpClient) {
5187
5779
  return {
5188
5780
  create: async (marketId, saleId, lotId, data) => {
5189
5781
  return httpClient.post(`/${marketId}/sales/${saleId}/lots/${lotId}/items`, data);
@@ -5200,7 +5792,7 @@ function create$f(httpClient) {
5200
5792
  /**
5201
5793
  * Defines the possible status values for a lot in a sale
5202
5794
  */
5203
- function create$e(httpClient) {
5795
+ function create$f(httpClient) {
5204
5796
  return {
5205
5797
  get: async (marketId, saleId, lotId, options) => {
5206
5798
  return httpClient.get(`/${marketId}/sales/${saleId}/lots/${lotId}`, (options === null || options === void 0 ? void 0 : options.at) ? { at: options.at } : undefined);
@@ -5217,10 +5809,19 @@ function create$e(httpClient) {
5217
5809
  delete: async (marketId, saleId, lotId) => {
5218
5810
  return httpClient.delete(`/${marketId}/sales/${saleId}/lots/${lotId}`);
5219
5811
  },
5812
+ deletePreflight: async (marketId, saleId, lotId) => {
5813
+ return httpClient.get(`/${marketId}/sales/${saleId}/lots/${lotId}/delete-preflight`);
5814
+ },
5815
+ deletePreflightBatch: async (marketId, saleId, lotIds) => {
5816
+ return httpClient.post(`/${marketId}/sales/${saleId}/lots/delete-preflight`, { lotIds });
5817
+ },
5818
+ deleteBatch: async (marketId, saleId, lotIds, confirmedLotIds) => {
5819
+ return httpClient.post(`/${marketId}/sales/${saleId}/lots/delete`, { lotIds, confirmedLotIds });
5820
+ },
5220
5821
  };
5221
5822
  }
5222
5823
 
5223
- function create$d(httpClient) {
5824
+ function create$e(httpClient) {
5224
5825
  const markets = {
5225
5826
  get: async (marketId, options) => {
5226
5827
  return httpClient.get(`/${marketId}`, (options === null || options === void 0 ? void 0 : options.at) ? { at: options.at } : undefined);
@@ -5242,7 +5843,7 @@ function create$d(httpClient) {
5242
5843
  return markets;
5243
5844
  }
5244
5845
 
5245
- function create$c(httpClient) {
5846
+ function create$d(httpClient) {
5246
5847
  let members = {
5247
5848
  /**
5248
5849
  * List members (staff accounts) for a market with pagination
@@ -5273,7 +5874,7 @@ function create$c(httpClient) {
5273
5874
  return members;
5274
5875
  }
5275
5876
 
5276
- function create$b(httpClient) {
5877
+ function create$c(httpClient) {
5277
5878
  const payments = {
5278
5879
  /**
5279
5880
  * List all payments for a market with pagination
@@ -5301,7 +5902,7 @@ function create$b(httpClient) {
5301
5902
  return payments;
5302
5903
  }
5303
5904
 
5304
- function create$a(httpClient) {
5905
+ function create$b(httpClient) {
5305
5906
  const payouts = {
5306
5907
  /**
5307
5908
  * List all payouts for a market with pagination
@@ -5340,7 +5941,7 @@ function create$a(httpClient) {
5340
5941
  return payouts;
5341
5942
  }
5342
5943
 
5343
- function create$9(httpClient) {
5944
+ function create$a(httpClient) {
5344
5945
  return {
5345
5946
  list: async (marketId) => {
5346
5947
  return httpClient.get(`/${marketId}/product-codes`);
@@ -5357,7 +5958,7 @@ function create$9(httpClient) {
5357
5958
  };
5358
5959
  }
5359
5960
 
5360
- function create$8(httpClient) {
5961
+ function create$9(httpClient) {
5361
5962
  return {
5362
5963
  get: async (marketId, saleId, options) => {
5363
5964
  return httpClient.get(`/${marketId}/sales/${saleId}`, (options === null || options === void 0 ? void 0 : options.at) ? { at: options.at } : undefined);
@@ -5374,7 +5975,7 @@ function create$8(httpClient) {
5374
5975
  };
5375
5976
  }
5376
5977
 
5377
- function create$7(httpClient) {
5978
+ function create$8(httpClient) {
5378
5979
  return {
5379
5980
  list: async (marketId) => {
5380
5981
  return httpClient.get(`/${marketId}/sale-templates`);
@@ -5394,7 +5995,7 @@ function create$7(httpClient) {
5394
5995
  };
5395
5996
  }
5396
5997
 
5397
- function create$6(httpClient) {
5998
+ function create$7(httpClient) {
5398
5999
  let search = {
5399
6000
  /**
5400
6001
  * Search for documents within a market
@@ -5409,7 +6010,7 @@ function create$6(httpClient) {
5409
6010
  return search;
5410
6011
  }
5411
6012
 
5412
- function create$5(httpClient) {
6013
+ function create$6(httpClient) {
5413
6014
  return {
5414
6015
  get: async (marketId, options) => {
5415
6016
  return httpClient.get(`/${marketId}/settings`, (options === null || options === void 0 ? void 0 : options.at) ? { at: options.at } : undefined);
@@ -5417,7 +6018,7 @@ function create$5(httpClient) {
5417
6018
  };
5418
6019
  }
5419
6020
 
5420
- function create$4(httpClient) {
6021
+ function create$5(httpClient) {
5421
6022
  return {
5422
6023
  list: async (marketId) => {
5423
6024
  return httpClient.get(`/${marketId}/tax_rates`);
@@ -5429,7 +6030,7 @@ function create$4(httpClient) {
5429
6030
  }
5430
6031
 
5431
6032
  // Path: studiojs/src/resources/markets.ts
5432
- function create$3(_) {
6033
+ function create$4(_) {
5433
6034
  const webhooks = {
5434
6035
  /***
5435
6036
  * This is used to construct the webhook event from the request body
@@ -5464,13 +6065,13 @@ function create$3(_) {
5464
6065
  return webhooks;
5465
6066
  }
5466
6067
 
5467
- function create$2(httpClient) {
6068
+ function create$3(httpClient) {
5468
6069
  return {
5469
6070
  lookup: async (marketId, cph) => httpClient.get(`/${marketId}/cph`, { cph }),
5470
6071
  };
5471
6072
  }
5472
6073
 
5473
- function create$1(httpClient) {
6074
+ function create$2(httpClient) {
5474
6075
  return {
5475
6076
  list: async (marketId, customerId, params) => {
5476
6077
  const query = {};
@@ -5495,7 +6096,7 @@ function create$1(httpClient) {
5495
6096
  };
5496
6097
  }
5497
6098
 
5498
- function create(httpClient) {
6099
+ function create$1(httpClient) {
5499
6100
  let ledger = {
5500
6101
  /**
5501
6102
  * Get the current balance for a ledger account
@@ -5556,33 +6157,42 @@ function create(httpClient) {
5556
6157
  return ledger;
5557
6158
  }
5558
6159
 
6160
+ function create(httpClient) {
6161
+ return {
6162
+ sendSMS: async (marketId, data) => httpClient.post(`/${marketId}/sms/send`, data),
6163
+ getSMS: async (marketId, smsId) => httpClient.get(`/${marketId}/sms/${smsId}`),
6164
+ };
6165
+ }
6166
+
5559
6167
  function resources(httpClient) {
5560
6168
  return {
5561
- activity: create$n(httpClient),
5562
- markets: create$d(httpClient),
5563
- members: create$c(httpClient),
5564
- sales: create$8(httpClient),
5565
- lots: create$e(httpClient),
5566
- lotitems: create$f(httpClient),
5567
- carts: create$l(httpClient),
5568
- cph: create$2(httpClient),
5569
- webhooks: create$3(),
5570
- actions: create$o(),
5571
- bidderApplications: create$j(httpClient),
5572
- settings: create$5(httpClient),
5573
- adjustments: create$m(httpClient),
5574
- extras: create$k(httpClient),
5575
- productCodes: create$9(httpClient),
5576
- saleTemplates: create$7(httpClient),
5577
- taxRates: create$4(httpClient),
5578
- customers: create$i(httpClient),
5579
- invoices: create$g(httpClient),
5580
- payments: create$b(httpClient),
5581
- payouts: create$a(httpClient),
5582
- search: create$6(httpClient),
5583
- files: create$h(),
5584
- contacts: create$1(httpClient),
5585
- ledger: create(httpClient),
6169
+ activity: create$p(httpClient),
6170
+ markets: create$e(httpClient),
6171
+ members: create$d(httpClient),
6172
+ sales: create$9(httpClient),
6173
+ lots: create$f(httpClient),
6174
+ lotitems: create$g(httpClient),
6175
+ carts: create$n(httpClient),
6176
+ cph: create$3(httpClient),
6177
+ webhooks: create$4(),
6178
+ actions: create$q(),
6179
+ bidderApplications: create$l(httpClient),
6180
+ settings: create$6(httpClient),
6181
+ adjustments: create$o(httpClient),
6182
+ extras: create$m(httpClient),
6183
+ productCodes: create$a(httpClient),
6184
+ saleTemplates: create$8(httpClient),
6185
+ taxRates: create$5(httpClient),
6186
+ customers: create$k(httpClient),
6187
+ customerLists: create$j(httpClient),
6188
+ invoices: create$h(httpClient),
6189
+ payments: create$c(httpClient),
6190
+ payouts: create$b(httpClient),
6191
+ search: create$7(httpClient),
6192
+ files: create$i(),
6193
+ contacts: create$2(httpClient),
6194
+ ledger: create$1(httpClient),
6195
+ sms: create(httpClient),
5586
6196
  };
5587
6197
  }
5588
6198
 
@@ -5672,6 +6282,10 @@ const supportedWebhookEvents = [
5672
6282
  "member.created",
5673
6283
  "member.updated",
5674
6284
  "member.deleted",
6285
+ // sms tasks
6286
+ "sms-task.created",
6287
+ "sms-task.updated",
6288
+ "sms-task.deleted",
5675
6289
  ];
5676
6290
 
5677
6291
  var types = /*#__PURE__*/Object.freeze({