@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.esm.js CHANGED
@@ -73,7 +73,7 @@ function SimpleHttpClient(baseUrl, apiKey, fetch, defaultTimeout, debug = false)
73
73
  }
74
74
 
75
75
  // Path: studiojs/src/resources/markets.ts
76
- function create$o(_) {
76
+ function create$q(_) {
77
77
  const actions = {
78
78
  /***
79
79
  * This is used to construct the action from the request body
@@ -103,7 +103,7 @@ function create$o(_) {
103
103
  return actions;
104
104
  }
105
105
 
106
- function create$n(httpClient) {
106
+ function create$p(httpClient) {
107
107
  let activity = {
108
108
  /**
109
109
  * List activity logs for a market with pagination and filtering
@@ -155,7 +155,7 @@ function create$n(httpClient) {
155
155
  return activity;
156
156
  }
157
157
 
158
- function create$m(httpClient) {
158
+ function create$o(httpClient) {
159
159
  return {
160
160
  list: async (marketId) => {
161
161
  return httpClient.get(`/${marketId}/adjustments`);
@@ -172,7 +172,7 @@ function create$m(httpClient) {
172
172
  };
173
173
  }
174
174
 
175
- function create$l(httpClient) {
175
+ function create$n(httpClient) {
176
176
  return {
177
177
  /**
178
178
  * Get the full cart for a customer including extras and uninvoiced lots
@@ -195,7 +195,7 @@ function create$l(httpClient) {
195
195
  };
196
196
  }
197
197
 
198
- function create$k(httpClient) {
198
+ function create$m(httpClient) {
199
199
  return {
200
200
  list: async (marketId) => {
201
201
  return httpClient.get(`/${marketId}/extras`);
@@ -215,7 +215,7 @@ function create$k(httpClient) {
215
215
  /***
216
216
  * Bidder applications
217
217
  */
218
- function create$j(httpClient) {
218
+ function create$l(httpClient) {
219
219
  let applications = {
220
220
  /**
221
221
  * List applications for a market with optional filtering
@@ -299,7 +299,7 @@ function create$j(httpClient) {
299
299
  }
300
300
 
301
301
  // Path: studiojs/src/resources/markets.ts
302
- function create$i(httpClient) {
302
+ function create$k(httpClient) {
303
303
  let customers = {
304
304
  list: async (marketId, lastId) => {
305
305
  let params = {};
@@ -346,6 +346,598 @@ function create$i(httpClient) {
346
346
  return customers;
347
347
  }
348
348
 
349
+ const DEFAULT_PAGE_SIZE = 100;
350
+ const MAX_MEMBER_BATCH_SIZE = 100;
351
+ function create$j(httpClient) {
352
+ const customerLists = {
353
+ list: async (marketId, options) => {
354
+ return httpClient.get(`/${marketId}/lists`, buildListQueryParams(options));
355
+ },
356
+ listAll: async (marketId, options) => {
357
+ var _a;
358
+ let lists = [];
359
+ let offset = 0;
360
+ let total = Number.POSITIVE_INFINITY;
361
+ let limit = (_a = options === null || options === void 0 ? void 0 : options.limit) !== null && _a !== void 0 ? _a : DEFAULT_PAGE_SIZE;
362
+ while (offset < total) {
363
+ let page = await customerLists.list(marketId, {
364
+ type: options === null || options === void 0 ? void 0 : options.type,
365
+ limit,
366
+ offset,
367
+ });
368
+ lists = lists.concat(page.lists);
369
+ total = page.total;
370
+ if (page.lists.length === 0) {
371
+ break;
372
+ }
373
+ offset += page.lists.length;
374
+ }
375
+ return lists;
376
+ },
377
+ get: async (marketId, listId) => {
378
+ return httpClient.get(`/${marketId}/lists/${listId}`);
379
+ },
380
+ getBySlug: async (marketId, slug) => {
381
+ return httpClient.get(`/${marketId}/lists/by-slug/${encodeURIComponent(slug)}`);
382
+ },
383
+ create: async (marketId, payload) => {
384
+ return httpClient.post(`/${marketId}/lists`, normalizeCreatePayload(payload));
385
+ },
386
+ update: async (marketId, listId, payload) => {
387
+ let body = await buildUpdatePayload(customerLists, marketId, listId, payload);
388
+ return httpClient.post(`/${marketId}/lists/${listId}`, body);
389
+ },
390
+ delete: async (marketId, listId) => {
391
+ return httpClient.delete(`/${marketId}/lists/${listId}`);
392
+ },
393
+ refresh: async (marketId, listId) => {
394
+ return httpClient.post(`/${marketId}/lists/${listId}/refresh`, {});
395
+ },
396
+ getMembers: async (marketId, listId, options) => {
397
+ return httpClient.get(`/${marketId}/lists/${listId}/members`, buildMembersQueryParams(options));
398
+ },
399
+ getAllMembers: async (marketId, listId, options) => {
400
+ var _a;
401
+ let members = [];
402
+ let offset = 0;
403
+ let limit = (_a = options === null || options === void 0 ? void 0 : options.limit) !== null && _a !== void 0 ? _a : DEFAULT_PAGE_SIZE;
404
+ let hasMore = true;
405
+ while (hasMore) {
406
+ let page = await customerLists.getMembers(marketId, listId, {
407
+ limit,
408
+ offset,
409
+ includeArchived: options === null || options === void 0 ? void 0 : options.includeArchived,
410
+ });
411
+ members = members.concat(page.members);
412
+ hasMore = page.hasMore;
413
+ if (page.members.length === 0) {
414
+ break;
415
+ }
416
+ offset += page.members.length;
417
+ }
418
+ return members;
419
+ },
420
+ addMembers: async (marketId, listId, customerIds) => {
421
+ if (customerIds.length === 0) {
422
+ return {
423
+ added: 0,
424
+ alreadyMembers: 0,
425
+ notFound: 0,
426
+ memberCount: 0,
427
+ };
428
+ }
429
+ let result = {
430
+ added: 0,
431
+ alreadyMembers: 0,
432
+ notFound: 0,
433
+ memberCount: 0,
434
+ };
435
+ for (let i = 0; i < customerIds.length; i += MAX_MEMBER_BATCH_SIZE) {
436
+ let chunk = customerIds.slice(i, i + MAX_MEMBER_BATCH_SIZE);
437
+ let response = await httpClient.post(`/${marketId}/lists/${listId}/members`, { customerIds: chunk });
438
+ result.added += response.added;
439
+ result.alreadyMembers += response.alreadyMembers;
440
+ result.notFound += response.notFound;
441
+ result.memberCount = response.memberCount;
442
+ }
443
+ return result;
444
+ },
445
+ removeMember: async (marketId, listId, customerId) => {
446
+ return httpClient.delete(`/${marketId}/lists/${listId}/members/${customerId}`);
447
+ },
448
+ preview: async (marketId, filters) => {
449
+ return httpClient.get(`/${marketId}/reports/customer-lists`, buildPreviewQueryParams(filters));
450
+ },
451
+ listProductCodes: async (marketId) => {
452
+ let response = await httpClient.get(`/${marketId}/reports/customer-lists`, { productCodesOnly: "true" });
453
+ return {
454
+ uniqueProductCodes: response.summary.uniqueProductCodes,
455
+ };
456
+ },
457
+ view: async (marketId, listIdOrSlug, options) => {
458
+ var _a;
459
+ let list = await resolveList(customerLists, marketId, listIdOrSlug, options);
460
+ if (list.type === "simple") {
461
+ 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);
462
+ if (shouldFetchAllMembers) {
463
+ let members = await customerLists.getAllMembers(marketId, list.id);
464
+ return {
465
+ mode: "simple",
466
+ list,
467
+ members,
468
+ total: members.length,
469
+ };
470
+ }
471
+ let response = await customerLists.getMembers(marketId, list.id, {
472
+ limit: options === null || options === void 0 ? void 0 : options.limit,
473
+ offset: options === null || options === void 0 ? void 0 : options.offset,
474
+ });
475
+ return {
476
+ mode: "simple",
477
+ list,
478
+ members: response.members,
479
+ total: response.total,
480
+ };
481
+ }
482
+ if (!list.query) {
483
+ throw new Error(`Smart list ${list.id} has no query defined`);
484
+ }
485
+ if ((options === null || options === void 0 ? void 0 : options.refresh) || hasRollingDates(list)) {
486
+ try {
487
+ await customerLists.refresh(marketId, list.id);
488
+ }
489
+ catch (error) {
490
+ if (!isRateLimitError(error)) {
491
+ throw error;
492
+ }
493
+ }
494
+ }
495
+ let effectiveQuery = applyRollingDatesToQuery(list);
496
+ let effectiveFilters = queryToFilters(effectiveQuery);
497
+ let preview = await customerLists.preview(marketId, effectiveFilters);
498
+ let excludedCustomerIds = new Set(list.excludedCustomerIds || []);
499
+ let rows = preview.rows.filter((row) => !excludedCustomerIds.has(row.customerId));
500
+ return {
501
+ mode: "smart",
502
+ list,
503
+ effectiveFilters,
504
+ rows,
505
+ summary: summariseRows(rows),
506
+ };
507
+ },
508
+ };
509
+ return customerLists;
510
+ }
511
+ async function buildUpdatePayload(customerLists, marketId, listId, payload) {
512
+ if (payload.query !== undefined && payload.filters !== undefined) {
513
+ throw new Error("Provide either query or filters when updating a customer list, not both");
514
+ }
515
+ let body = {};
516
+ if (payload.name !== undefined) {
517
+ body.name = payload.name;
518
+ }
519
+ if (payload.description !== undefined) {
520
+ body.description = payload.description;
521
+ }
522
+ if (payload.query !== undefined) {
523
+ body.query = payload.query;
524
+ }
525
+ if (payload.filters !== undefined) {
526
+ let existing = await customerLists.get(marketId, listId);
527
+ if (existing.type !== "smart") {
528
+ throw new Error("Cannot update filters on a simple list");
529
+ }
530
+ let existingFilters = queryToFilters(existing.query);
531
+ body.query = filtersToCustomerListQuery(mergeCustomerListFilters(existingFilters, payload.filters));
532
+ }
533
+ if (Object.keys(body).length === 0) {
534
+ throw new Error("No update fields provided");
535
+ }
536
+ return body;
537
+ }
538
+ function normalizeCreatePayload(payload) {
539
+ var _a;
540
+ if (payload.type === "simple") {
541
+ return {
542
+ name: payload.name,
543
+ description: payload.description,
544
+ type: payload.type,
545
+ };
546
+ }
547
+ if (payload.query !== undefined && payload.filters !== undefined) {
548
+ throw new Error("Provide either query or filters when creating a smart list, not both");
549
+ }
550
+ let query = (_a = payload.query) !== null && _a !== void 0 ? _a : filtersToCustomerListQuery(payload.filters || {});
551
+ return {
552
+ name: payload.name,
553
+ description: payload.description,
554
+ type: payload.type,
555
+ query,
556
+ };
557
+ }
558
+ function buildListQueryParams(options) {
559
+ let queryParams = {};
560
+ if (options === null || options === void 0 ? void 0 : options.type) {
561
+ queryParams.type = options.type;
562
+ }
563
+ if ((options === null || options === void 0 ? void 0 : options.limit) !== undefined) {
564
+ queryParams.limit = String(options.limit);
565
+ }
566
+ if ((options === null || options === void 0 ? void 0 : options.offset) !== undefined) {
567
+ queryParams.offset = String(options.offset);
568
+ }
569
+ return Object.keys(queryParams).length > 0 ? queryParams : undefined;
570
+ }
571
+ function buildMembersQueryParams(options) {
572
+ let queryParams = {};
573
+ if ((options === null || options === void 0 ? void 0 : options.limit) !== undefined) {
574
+ queryParams.limit = String(options.limit);
575
+ }
576
+ if ((options === null || options === void 0 ? void 0 : options.offset) !== undefined) {
577
+ queryParams.offset = String(options.offset);
578
+ }
579
+ if ((options === null || options === void 0 ? void 0 : options.includeArchived) !== undefined) {
580
+ queryParams.includeArchived = String(options.includeArchived);
581
+ }
582
+ return Object.keys(queryParams).length > 0 ? queryParams : undefined;
583
+ }
584
+ function buildPreviewQueryParams(filters) {
585
+ var _a;
586
+ let params = {};
587
+ let filter = buildFilterExpression(filters);
588
+ let excludeFilters = buildExcludeFilters(filters);
589
+ if (filter) {
590
+ params.filter = filter;
591
+ }
592
+ if (excludeFilters.length > 0) {
593
+ params.excludeFilters = JSON.stringify(excludeFilters);
594
+ }
595
+ params.role = (_a = filters.role) !== null && _a !== void 0 ? _a : "both";
596
+ if (filters.geoBounds) {
597
+ params.bounds = JSON.stringify(filters.geoBounds);
598
+ }
599
+ if (filters.secondaryFilter) {
600
+ params.secondaryFilter = JSON.stringify({
601
+ role: filters.secondaryFilter.role,
602
+ filter: buildFilterExpression(filters.secondaryFilter),
603
+ ...(filters.secondaryFilter.geoBounds
604
+ ? { bounds: filters.secondaryFilter.geoBounds }
605
+ : {}),
606
+ });
607
+ }
608
+ return params;
609
+ }
610
+ function filtersToCustomerListQuery(filters) {
611
+ var _a;
612
+ let excludeFilters = buildExcludeFilters(filters);
613
+ let query = {
614
+ role: (_a = filters.role) !== null && _a !== void 0 ? _a : "both",
615
+ };
616
+ let filter = buildFilterExpression(filters);
617
+ if (filter) {
618
+ query.filter = filter;
619
+ }
620
+ if (excludeFilters.length > 0) {
621
+ query.excludeFilters = excludeFilters;
622
+ }
623
+ if (filters.geoBounds) {
624
+ query.bounds = filters.geoBounds;
625
+ }
626
+ if (filters.rollingDateConfig) {
627
+ query.rollingDateConfig = filters.rollingDateConfig;
628
+ }
629
+ if (filters.secondaryFilter) {
630
+ query.secondaryFilter = {
631
+ role: filters.secondaryFilter.role,
632
+ filter: buildFilterExpression(filters.secondaryFilter),
633
+ ...(filters.secondaryFilter.geoBounds
634
+ ? { bounds: filters.secondaryFilter.geoBounds }
635
+ : {}),
636
+ ...(filters.secondaryFilter.rollingDateConfig
637
+ ? { rollingDateConfig: filters.secondaryFilter.rollingDateConfig }
638
+ : {}),
639
+ };
640
+ }
641
+ return query;
642
+ }
643
+ function queryToFilters(query) {
644
+ if (!query) {
645
+ return { role: "both", productCodes: [] };
646
+ }
647
+ let filters = {
648
+ role: query.role,
649
+ dateStart: extractDate(query.filter, ">="),
650
+ dateEnd: extractDate(query.filter, "<="),
651
+ productCodes: extractProductCodes(query.filter),
652
+ excludedProductCodes: [],
653
+ geoBounds: query.bounds || null,
654
+ boughtOnlineOnly: /@boughtOnline\s*=\s*true/.test(query.filter || ""),
655
+ cattleBreeds: extractAllMatches(query.filter, /@breedCodeOfCattle\s*=\s*"([^"]+)"/g),
656
+ sheepBreeds: extractAllMatches(query.filter, /breedOfSheep\s*=\s*"([^"]+)"/g),
657
+ rollingDateConfig: query.rollingDateConfig,
658
+ };
659
+ for (let excludeFilter of query.excludeFilters || []) {
660
+ if (filters.excludeDateStart == null) {
661
+ filters.excludeDateStart = extractDate(excludeFilter, ">=");
662
+ }
663
+ if (filters.excludeDateEnd == null) {
664
+ filters.excludeDateEnd = extractDate(excludeFilter, "<=");
665
+ }
666
+ filters.excludedProductCodes = uniqueStrings((filters.excludedProductCodes || []).concat(extractProductCodes(excludeFilter)));
667
+ }
668
+ if (query.secondaryFilter) {
669
+ filters.secondaryFilter = {
670
+ role: query.secondaryFilter.role,
671
+ dateStart: extractDate(query.secondaryFilter.filter, ">="),
672
+ dateEnd: extractDate(query.secondaryFilter.filter, "<="),
673
+ productCodes: extractProductCodes(query.secondaryFilter.filter),
674
+ geoBounds: query.secondaryFilter.bounds || null,
675
+ rollingDateConfig: query.secondaryFilter.rollingDateConfig,
676
+ };
677
+ }
678
+ return filters;
679
+ }
680
+ function mergeCustomerListFilters(base, updates) {
681
+ let merged = { ...base };
682
+ if (updates.role !== undefined)
683
+ merged.role = updates.role;
684
+ if (updates.dateStart !== undefined)
685
+ merged.dateStart = updates.dateStart;
686
+ if (updates.dateEnd !== undefined)
687
+ merged.dateEnd = updates.dateEnd;
688
+ if (updates.productCodes !== undefined)
689
+ merged.productCodes = [...updates.productCodes];
690
+ if (updates.excludeDateStart !== undefined) {
691
+ merged.excludeDateStart = updates.excludeDateStart;
692
+ }
693
+ if (updates.excludeDateEnd !== undefined) {
694
+ merged.excludeDateEnd = updates.excludeDateEnd;
695
+ }
696
+ if (updates.excludedProductCodes !== undefined) {
697
+ merged.excludedProductCodes = [...updates.excludedProductCodes];
698
+ }
699
+ if (updates.geoBounds !== undefined)
700
+ merged.geoBounds = updates.geoBounds;
701
+ if (updates.boughtOnlineOnly !== undefined) {
702
+ merged.boughtOnlineOnly = updates.boughtOnlineOnly;
703
+ }
704
+ if (updates.cattleBreeds !== undefined) {
705
+ merged.cattleBreeds = [...updates.cattleBreeds];
706
+ }
707
+ if (updates.sheepBreeds !== undefined) {
708
+ merged.sheepBreeds = [...updates.sheepBreeds];
709
+ }
710
+ if (updates.rollingDateConfig !== undefined) {
711
+ merged.rollingDateConfig = updates.rollingDateConfig;
712
+ }
713
+ if (updates.secondaryFilter !== undefined) {
714
+ if (updates.secondaryFilter === null) {
715
+ merged.secondaryFilter = null;
716
+ }
717
+ else {
718
+ let nextSecondary = merged.secondaryFilter
719
+ ? { ...merged.secondaryFilter }
720
+ : { role: updates.secondaryFilter.role || "both", productCodes: [] };
721
+ if (updates.secondaryFilter.role !== undefined) {
722
+ nextSecondary.role = updates.secondaryFilter.role;
723
+ }
724
+ if (updates.secondaryFilter.dateStart !== undefined) {
725
+ nextSecondary.dateStart = updates.secondaryFilter.dateStart;
726
+ }
727
+ if (updates.secondaryFilter.dateEnd !== undefined) {
728
+ nextSecondary.dateEnd = updates.secondaryFilter.dateEnd;
729
+ }
730
+ if (updates.secondaryFilter.productCodes !== undefined) {
731
+ nextSecondary.productCodes = [...updates.secondaryFilter.productCodes];
732
+ }
733
+ if (updates.secondaryFilter.geoBounds !== undefined) {
734
+ nextSecondary.geoBounds = updates.secondaryFilter.geoBounds;
735
+ }
736
+ if (updates.secondaryFilter.rollingDateConfig !== undefined) {
737
+ nextSecondary.rollingDateConfig =
738
+ updates.secondaryFilter.rollingDateConfig;
739
+ }
740
+ merged.secondaryFilter = nextSecondary;
741
+ }
742
+ }
743
+ return merged;
744
+ }
745
+ function buildExcludeFilters(filters) {
746
+ let excludeFilters = [];
747
+ if (filters.excludeDateStart || filters.excludeDateEnd) {
748
+ let clauses = [];
749
+ if (filters.excludeDateStart) {
750
+ clauses.push(`saleDate >= "${filters.excludeDateStart}"`);
751
+ }
752
+ if (filters.excludeDateEnd) {
753
+ clauses.push(`saleDate <= "${filters.excludeDateEnd}"`);
754
+ }
755
+ if (clauses.length > 0) {
756
+ excludeFilters.push(clauses.join(" AND "));
757
+ }
758
+ }
759
+ if (filters.excludedProductCodes && filters.excludedProductCodes.length > 0) {
760
+ if (filters.excludedProductCodes.length === 1) {
761
+ excludeFilters.push(`productCode = "${filters.excludedProductCodes[0]}"`);
762
+ }
763
+ else {
764
+ excludeFilters.push(filters.excludedProductCodes
765
+ .map((code) => `productCode = "${code}"`)
766
+ .join(" OR "));
767
+ }
768
+ }
769
+ return excludeFilters;
770
+ }
771
+ function buildFilterExpression(filters) {
772
+ let fixedClauses = [];
773
+ let alternativeGroups = [];
774
+ if (filters.dateStart)
775
+ fixedClauses.push(`saleDate >= "${filters.dateStart}"`);
776
+ if (filters.dateEnd)
777
+ fixedClauses.push(`saleDate <= "${filters.dateEnd}"`);
778
+ if (filters.productCodes && filters.productCodes.length > 0) {
779
+ alternativeGroups.push(filters.productCodes.map((code) => `productCode = "${code}"`));
780
+ }
781
+ if (filters.boughtOnlineOnly) {
782
+ fixedClauses.push(`@boughtOnline = true`);
783
+ }
784
+ let breedClauses = [];
785
+ for (let breed of filters.cattleBreeds || []) {
786
+ breedClauses.push(`@breedCodeOfCattle = "${breed}"`);
787
+ }
788
+ for (let breed of filters.sheepBreeds || []) {
789
+ breedClauses.push(`breedOfSheep = "${breed}"`);
790
+ }
791
+ if (breedClauses.length > 0) {
792
+ alternativeGroups.push(breedClauses);
793
+ }
794
+ let expandedBranches = alternativeGroups.reduce((branches, alternatives) => branches.flatMap((branch) => alternatives.map((alternative) => [...branch, alternative])), [[]]);
795
+ let expressions = expandedBranches
796
+ .map((branch) => [...fixedClauses, ...branch].filter(Boolean))
797
+ .filter((branch) => branch.length > 0)
798
+ .map((branch) => branch.join(" AND "));
799
+ if (expressions.length === 0) {
800
+ return undefined;
801
+ }
802
+ return expressions.join(" OR ");
803
+ }
804
+ async function resolveList(customerLists, marketId, listIdOrSlug, options) {
805
+ let identifierType = (options === null || options === void 0 ? void 0 : options.identifierType) || "auto";
806
+ if (identifierType === "id") {
807
+ return customerLists.get(marketId, listIdOrSlug);
808
+ }
809
+ if (identifierType === "slug") {
810
+ return customerLists.getBySlug(marketId, listIdOrSlug);
811
+ }
812
+ let firstLookup = listIdOrSlug.startsWith("list_") ? "id" : "slug";
813
+ try {
814
+ return firstLookup === "id"
815
+ ? await customerLists.get(marketId, listIdOrSlug)
816
+ : await customerLists.getBySlug(marketId, listIdOrSlug);
817
+ }
818
+ catch (error) {
819
+ if (!isNotFoundError(error)) {
820
+ throw error;
821
+ }
822
+ }
823
+ return firstLookup === "id"
824
+ ? customerLists.getBySlug(marketId, listIdOrSlug)
825
+ : customerLists.get(marketId, listIdOrSlug);
826
+ }
827
+ function applyRollingDatesToQuery(list) {
828
+ var _a;
829
+ if (!list.query) {
830
+ throw new Error(`Smart list ${list.id} has no query defined`);
831
+ }
832
+ let query = {
833
+ ...list.query,
834
+ ...(list.query.secondaryFilter
835
+ ? { secondaryFilter: { ...list.query.secondaryFilter } }
836
+ : {}),
837
+ };
838
+ let topLevelRollingConfig = list.query.rollingDateConfig || list.rollingDateConfig;
839
+ if (topLevelRollingConfig) {
840
+ query.filter = applyRollingDatesToFilter(query.filter, topLevelRollingConfig, list.createdAt);
841
+ }
842
+ if ((_a = query.secondaryFilter) === null || _a === void 0 ? void 0 : _a.rollingDateConfig) {
843
+ query.secondaryFilter.filter = applyRollingDatesToFilter(query.secondaryFilter.filter, query.secondaryFilter.rollingDateConfig, list.createdAt);
844
+ }
845
+ return query;
846
+ }
847
+ function applyRollingDatesToFilter(filter, rollingDateConfig, createdAt) {
848
+ if (!filter) {
849
+ return filter;
850
+ }
851
+ let createdAtDate = new Date(createdAt);
852
+ if (Number.isNaN(createdAtDate.getTime())) {
853
+ return filter;
854
+ }
855
+ let originalStart = new Date(rollingDateConfig.originalStart);
856
+ let originalEnd = new Date(rollingDateConfig.originalEnd);
857
+ if (Number.isNaN(originalStart.getTime()) ||
858
+ Number.isNaN(originalEnd.getTime())) {
859
+ return filter;
860
+ }
861
+ let now = new Date();
862
+ let daysElapsed = Math.floor((now.getTime() - createdAtDate.getTime()) / (24 * 60 * 60 * 1000));
863
+ let nextStart = new Date(originalStart.getTime() + daysElapsed * 24 * 60 * 60 * 1000);
864
+ let nextEnd = new Date(originalEnd.getTime() + daysElapsed * 24 * 60 * 60 * 1000);
865
+ return filter
866
+ .replace(/saleDate\s*>=\s*"[^"]+"/g, `saleDate >= "${formatDate(nextStart)}"`)
867
+ .replace(/saleDate\s*<=\s*"[^"]+"/g, `saleDate <= "${formatDate(nextEnd)}"`);
868
+ }
869
+ function hasRollingDates(list) {
870
+ var _a, _b, _c;
871
+ return Boolean(((_a = list.query) === null || _a === void 0 ? void 0 : _a.rollingDateConfig) ||
872
+ list.rollingDateConfig ||
873
+ ((_c = (_b = list.query) === null || _b === void 0 ? void 0 : _b.secondaryFilter) === null || _c === void 0 ? void 0 : _c.rollingDateConfig));
874
+ }
875
+ function summariseRows(rows) {
876
+ let uniqueProductCodes = new Set();
877
+ let totalSoldValueInCents = 0;
878
+ let totalPurchasedValueInCents = 0;
879
+ let customersWithLocation = 0;
880
+ for (let row of rows) {
881
+ totalSoldValueInCents += Number(row.totalSoldValueInCents || 0);
882
+ totalPurchasedValueInCents += Number(row.totalPurchasedValueInCents || 0);
883
+ if (row.latitude != null && row.longitude != null) {
884
+ customersWithLocation += 1;
885
+ }
886
+ for (let productCode of row.productCodesSold || []) {
887
+ uniqueProductCodes.add(productCode);
888
+ }
889
+ for (let productCode of row.productCodesBought || []) {
890
+ uniqueProductCodes.add(productCode);
891
+ }
892
+ }
893
+ return {
894
+ totalCustomers: rows.length,
895
+ totalSoldValueInCents,
896
+ totalPurchasedValueInCents,
897
+ customersWithLocation,
898
+ uniqueProductCodes: Array.from(uniqueProductCodes),
899
+ };
900
+ }
901
+ function extractDate(filter, operator) {
902
+ if (!filter) {
903
+ return null;
904
+ }
905
+ let escapedOperator = operator.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
906
+ let match = filter.match(new RegExp(`saleDate\\s*${escapedOperator}\\s*"([^"]+)"`));
907
+ return match ? match[1] : null;
908
+ }
909
+ function extractProductCodes(filter) {
910
+ if (!filter) {
911
+ return [];
912
+ }
913
+ let inMatch = filter.match(/productCode\s+IN\s*\(([^)]+)\)/);
914
+ if (inMatch) {
915
+ return uniqueStrings(inMatch[1]
916
+ .split(",")
917
+ .map((value) => value.trim().replace(/^"|"$/g, ""))
918
+ .filter(Boolean));
919
+ }
920
+ return uniqueStrings(extractAllMatches(filter, /productCode\s*=\s*"([^"]+)"/g));
921
+ }
922
+ function extractAllMatches(filter, regex) {
923
+ if (!filter) {
924
+ return [];
925
+ }
926
+ return [...filter.matchAll(regex)].map((match) => match[1]).filter(Boolean);
927
+ }
928
+ function uniqueStrings(values) {
929
+ return Array.from(new Set(values));
930
+ }
931
+ function formatDate(date) {
932
+ return date.toISOString().split("T")[0];
933
+ }
934
+ function isNotFoundError(error) {
935
+ return error instanceof Error && error.message.includes(" not found");
936
+ }
937
+ function isRateLimitError(error) {
938
+ return error instanceof Error && error.message.includes("status 429");
939
+ }
940
+
349
941
  var util;
350
942
  (function (util) {
351
943
  util.assertEqual = (val) => val;
@@ -5136,7 +5728,7 @@ const uploadSingleFile = async (input, token) => {
5136
5728
  };
5137
5729
 
5138
5730
  // Multipart Upload for Media to the MARTEYE Media Service
5139
- function create$h() {
5731
+ function create$i() {
5140
5732
  const files = {
5141
5733
  uploadSingleFile: async (input, token) => {
5142
5734
  return await uploadSingleFile(input, token);
@@ -5151,7 +5743,7 @@ function create$h() {
5151
5743
  return files;
5152
5744
  }
5153
5745
 
5154
- function create$g(httpClient) {
5746
+ function create$h(httpClient) {
5155
5747
  const invoices = {
5156
5748
  /**
5157
5749
  * List all invoices for a market with pagination
@@ -5179,7 +5771,7 @@ function create$g(httpClient) {
5179
5771
  return invoices;
5180
5772
  }
5181
5773
 
5182
- function create$f(httpClient) {
5774
+ function create$g(httpClient) {
5183
5775
  return {
5184
5776
  create: async (marketId, saleId, lotId, data) => {
5185
5777
  return httpClient.post(`/${marketId}/sales/${saleId}/lots/${lotId}/items`, data);
@@ -5196,7 +5788,7 @@ function create$f(httpClient) {
5196
5788
  /**
5197
5789
  * Defines the possible status values for a lot in a sale
5198
5790
  */
5199
- function create$e(httpClient) {
5791
+ function create$f(httpClient) {
5200
5792
  return {
5201
5793
  get: async (marketId, saleId, lotId, options) => {
5202
5794
  return httpClient.get(`/${marketId}/sales/${saleId}/lots/${lotId}`, (options === null || options === void 0 ? void 0 : options.at) ? { at: options.at } : undefined);
@@ -5213,10 +5805,19 @@ function create$e(httpClient) {
5213
5805
  delete: async (marketId, saleId, lotId) => {
5214
5806
  return httpClient.delete(`/${marketId}/sales/${saleId}/lots/${lotId}`);
5215
5807
  },
5808
+ deletePreflight: async (marketId, saleId, lotId) => {
5809
+ return httpClient.get(`/${marketId}/sales/${saleId}/lots/${lotId}/delete-preflight`);
5810
+ },
5811
+ deletePreflightBatch: async (marketId, saleId, lotIds) => {
5812
+ return httpClient.post(`/${marketId}/sales/${saleId}/lots/delete-preflight`, { lotIds });
5813
+ },
5814
+ deleteBatch: async (marketId, saleId, lotIds, confirmedLotIds) => {
5815
+ return httpClient.post(`/${marketId}/sales/${saleId}/lots/delete`, { lotIds, confirmedLotIds });
5816
+ },
5216
5817
  };
5217
5818
  }
5218
5819
 
5219
- function create$d(httpClient) {
5820
+ function create$e(httpClient) {
5220
5821
  const markets = {
5221
5822
  get: async (marketId, options) => {
5222
5823
  return httpClient.get(`/${marketId}`, (options === null || options === void 0 ? void 0 : options.at) ? { at: options.at } : undefined);
@@ -5238,7 +5839,7 @@ function create$d(httpClient) {
5238
5839
  return markets;
5239
5840
  }
5240
5841
 
5241
- function create$c(httpClient) {
5842
+ function create$d(httpClient) {
5242
5843
  let members = {
5243
5844
  /**
5244
5845
  * List members (staff accounts) for a market with pagination
@@ -5269,7 +5870,7 @@ function create$c(httpClient) {
5269
5870
  return members;
5270
5871
  }
5271
5872
 
5272
- function create$b(httpClient) {
5873
+ function create$c(httpClient) {
5273
5874
  const payments = {
5274
5875
  /**
5275
5876
  * List all payments for a market with pagination
@@ -5297,7 +5898,7 @@ function create$b(httpClient) {
5297
5898
  return payments;
5298
5899
  }
5299
5900
 
5300
- function create$a(httpClient) {
5901
+ function create$b(httpClient) {
5301
5902
  const payouts = {
5302
5903
  /**
5303
5904
  * List all payouts for a market with pagination
@@ -5336,7 +5937,7 @@ function create$a(httpClient) {
5336
5937
  return payouts;
5337
5938
  }
5338
5939
 
5339
- function create$9(httpClient) {
5940
+ function create$a(httpClient) {
5340
5941
  return {
5341
5942
  list: async (marketId) => {
5342
5943
  return httpClient.get(`/${marketId}/product-codes`);
@@ -5353,7 +5954,7 @@ function create$9(httpClient) {
5353
5954
  };
5354
5955
  }
5355
5956
 
5356
- function create$8(httpClient) {
5957
+ function create$9(httpClient) {
5357
5958
  return {
5358
5959
  get: async (marketId, saleId, options) => {
5359
5960
  return httpClient.get(`/${marketId}/sales/${saleId}`, (options === null || options === void 0 ? void 0 : options.at) ? { at: options.at } : undefined);
@@ -5370,7 +5971,7 @@ function create$8(httpClient) {
5370
5971
  };
5371
5972
  }
5372
5973
 
5373
- function create$7(httpClient) {
5974
+ function create$8(httpClient) {
5374
5975
  return {
5375
5976
  list: async (marketId) => {
5376
5977
  return httpClient.get(`/${marketId}/sale-templates`);
@@ -5390,7 +5991,7 @@ function create$7(httpClient) {
5390
5991
  };
5391
5992
  }
5392
5993
 
5393
- function create$6(httpClient) {
5994
+ function create$7(httpClient) {
5394
5995
  let search = {
5395
5996
  /**
5396
5997
  * Search for documents within a market
@@ -5405,7 +6006,7 @@ function create$6(httpClient) {
5405
6006
  return search;
5406
6007
  }
5407
6008
 
5408
- function create$5(httpClient) {
6009
+ function create$6(httpClient) {
5409
6010
  return {
5410
6011
  get: async (marketId, options) => {
5411
6012
  return httpClient.get(`/${marketId}/settings`, (options === null || options === void 0 ? void 0 : options.at) ? { at: options.at } : undefined);
@@ -5413,7 +6014,7 @@ function create$5(httpClient) {
5413
6014
  };
5414
6015
  }
5415
6016
 
5416
- function create$4(httpClient) {
6017
+ function create$5(httpClient) {
5417
6018
  return {
5418
6019
  list: async (marketId) => {
5419
6020
  return httpClient.get(`/${marketId}/tax_rates`);
@@ -5425,7 +6026,7 @@ function create$4(httpClient) {
5425
6026
  }
5426
6027
 
5427
6028
  // Path: studiojs/src/resources/markets.ts
5428
- function create$3(_) {
6029
+ function create$4(_) {
5429
6030
  const webhooks = {
5430
6031
  /***
5431
6032
  * This is used to construct the webhook event from the request body
@@ -5460,13 +6061,13 @@ function create$3(_) {
5460
6061
  return webhooks;
5461
6062
  }
5462
6063
 
5463
- function create$2(httpClient) {
6064
+ function create$3(httpClient) {
5464
6065
  return {
5465
6066
  lookup: async (marketId, cph) => httpClient.get(`/${marketId}/cph`, { cph }),
5466
6067
  };
5467
6068
  }
5468
6069
 
5469
- function create$1(httpClient) {
6070
+ function create$2(httpClient) {
5470
6071
  return {
5471
6072
  list: async (marketId, customerId, params) => {
5472
6073
  const query = {};
@@ -5491,7 +6092,7 @@ function create$1(httpClient) {
5491
6092
  };
5492
6093
  }
5493
6094
 
5494
- function create(httpClient) {
6095
+ function create$1(httpClient) {
5495
6096
  let ledger = {
5496
6097
  /**
5497
6098
  * Get the current balance for a ledger account
@@ -5552,33 +6153,42 @@ function create(httpClient) {
5552
6153
  return ledger;
5553
6154
  }
5554
6155
 
6156
+ function create(httpClient) {
6157
+ return {
6158
+ sendSMS: async (marketId, data) => httpClient.post(`/${marketId}/sms/send`, data),
6159
+ getSMS: async (marketId, smsId) => httpClient.get(`/${marketId}/sms/${smsId}`),
6160
+ };
6161
+ }
6162
+
5555
6163
  function resources(httpClient) {
5556
6164
  return {
5557
- activity: create$n(httpClient),
5558
- markets: create$d(httpClient),
5559
- members: create$c(httpClient),
5560
- sales: create$8(httpClient),
5561
- lots: create$e(httpClient),
5562
- lotitems: create$f(httpClient),
5563
- carts: create$l(httpClient),
5564
- cph: create$2(httpClient),
5565
- webhooks: create$3(),
5566
- actions: create$o(),
5567
- bidderApplications: create$j(httpClient),
5568
- settings: create$5(httpClient),
5569
- adjustments: create$m(httpClient),
5570
- extras: create$k(httpClient),
5571
- productCodes: create$9(httpClient),
5572
- saleTemplates: create$7(httpClient),
5573
- taxRates: create$4(httpClient),
5574
- customers: create$i(httpClient),
5575
- invoices: create$g(httpClient),
5576
- payments: create$b(httpClient),
5577
- payouts: create$a(httpClient),
5578
- search: create$6(httpClient),
5579
- files: create$h(),
5580
- contacts: create$1(httpClient),
5581
- ledger: create(httpClient),
6165
+ activity: create$p(httpClient),
6166
+ markets: create$e(httpClient),
6167
+ members: create$d(httpClient),
6168
+ sales: create$9(httpClient),
6169
+ lots: create$f(httpClient),
6170
+ lotitems: create$g(httpClient),
6171
+ carts: create$n(httpClient),
6172
+ cph: create$3(httpClient),
6173
+ webhooks: create$4(),
6174
+ actions: create$q(),
6175
+ bidderApplications: create$l(httpClient),
6176
+ settings: create$6(httpClient),
6177
+ adjustments: create$o(httpClient),
6178
+ extras: create$m(httpClient),
6179
+ productCodes: create$a(httpClient),
6180
+ saleTemplates: create$8(httpClient),
6181
+ taxRates: create$5(httpClient),
6182
+ customers: create$k(httpClient),
6183
+ customerLists: create$j(httpClient),
6184
+ invoices: create$h(httpClient),
6185
+ payments: create$c(httpClient),
6186
+ payouts: create$b(httpClient),
6187
+ search: create$7(httpClient),
6188
+ files: create$i(),
6189
+ contacts: create$2(httpClient),
6190
+ ledger: create$1(httpClient),
6191
+ sms: create(httpClient),
5582
6192
  };
5583
6193
  }
5584
6194
 
@@ -5668,6 +6278,10 @@ const supportedWebhookEvents = [
5668
6278
  "member.created",
5669
6279
  "member.updated",
5670
6280
  "member.deleted",
6281
+ // sms tasks
6282
+ "sms-task.created",
6283
+ "sms-task.updated",
6284
+ "sms-task.deleted",
5671
6285
  ];
5672
6286
 
5673
6287
  var types = /*#__PURE__*/Object.freeze({