@marteye/studiojs 1.1.46 → 1.1.47-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,599 @@ 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 clauses = [];
777
+ if (filters.dateStart)
778
+ clauses.push(`saleDate >= "${filters.dateStart}"`);
779
+ if (filters.dateEnd)
780
+ clauses.push(`saleDate <= "${filters.dateEnd}"`);
781
+ if (filters.productCodes && filters.productCodes.length > 0) {
782
+ if (filters.productCodes.length === 1) {
783
+ clauses.push(`productCode = "${filters.productCodes[0]}"`);
784
+ }
785
+ else {
786
+ clauses.push(`(${filters.productCodes
787
+ .map((code) => `productCode = "${code}"`)
788
+ .join(" OR ")})`);
789
+ }
790
+ }
791
+ if (filters.boughtOnlineOnly) {
792
+ clauses.push(`@boughtOnline = true`);
793
+ }
794
+ let breedClauses = [];
795
+ for (let breed of filters.cattleBreeds || []) {
796
+ breedClauses.push(`@breedCodeOfCattle = "${breed}"`);
797
+ }
798
+ for (let breed of filters.sheepBreeds || []) {
799
+ breedClauses.push(`breedOfSheep = "${breed}"`);
800
+ }
801
+ if (breedClauses.length === 1) {
802
+ clauses.push(breedClauses[0]);
803
+ }
804
+ else if (breedClauses.length > 1) {
805
+ clauses.push(`(${breedClauses.join(" OR ")})`);
806
+ }
807
+ return clauses.length > 0 ? clauses.join(" AND ") : undefined;
808
+ }
809
+ async function resolveList(customerLists, marketId, listIdOrSlug, options) {
810
+ let identifierType = (options === null || options === void 0 ? void 0 : options.identifierType) || "auto";
811
+ if (identifierType === "id") {
812
+ return customerLists.get(marketId, listIdOrSlug);
813
+ }
814
+ if (identifierType === "slug") {
815
+ return customerLists.getBySlug(marketId, listIdOrSlug);
816
+ }
817
+ let firstLookup = listIdOrSlug.startsWith("list_") ? "id" : "slug";
818
+ try {
819
+ return firstLookup === "id"
820
+ ? await customerLists.get(marketId, listIdOrSlug)
821
+ : await customerLists.getBySlug(marketId, listIdOrSlug);
822
+ }
823
+ catch (error) {
824
+ if (!isNotFoundError(error)) {
825
+ throw error;
826
+ }
827
+ }
828
+ return firstLookup === "id"
829
+ ? customerLists.getBySlug(marketId, listIdOrSlug)
830
+ : customerLists.get(marketId, listIdOrSlug);
831
+ }
832
+ function applyRollingDatesToQuery(list) {
833
+ var _a;
834
+ if (!list.query) {
835
+ throw new Error(`Smart list ${list.id} has no query defined`);
836
+ }
837
+ let query = {
838
+ ...list.query,
839
+ ...(list.query.secondaryFilter
840
+ ? { secondaryFilter: { ...list.query.secondaryFilter } }
841
+ : {}),
842
+ };
843
+ let topLevelRollingConfig = list.query.rollingDateConfig || list.rollingDateConfig;
844
+ if (topLevelRollingConfig) {
845
+ query.filter = applyRollingDatesToFilter(query.filter, topLevelRollingConfig, list.createdAt);
846
+ }
847
+ if ((_a = query.secondaryFilter) === null || _a === void 0 ? void 0 : _a.rollingDateConfig) {
848
+ query.secondaryFilter.filter = applyRollingDatesToFilter(query.secondaryFilter.filter, query.secondaryFilter.rollingDateConfig, list.createdAt);
849
+ }
850
+ return query;
851
+ }
852
+ function applyRollingDatesToFilter(filter, rollingDateConfig, createdAt) {
853
+ if (!filter) {
854
+ return filter;
855
+ }
856
+ let createdAtDate = new Date(createdAt);
857
+ if (Number.isNaN(createdAtDate.getTime())) {
858
+ return filter;
859
+ }
860
+ let originalStart = new Date(rollingDateConfig.originalStart);
861
+ let originalEnd = new Date(rollingDateConfig.originalEnd);
862
+ if (Number.isNaN(originalStart.getTime()) ||
863
+ Number.isNaN(originalEnd.getTime())) {
864
+ return filter;
865
+ }
866
+ let now = new Date();
867
+ let daysElapsed = Math.floor((now.getTime() - createdAtDate.getTime()) / (24 * 60 * 60 * 1000));
868
+ let nextStart = new Date(originalStart.getTime() + daysElapsed * 24 * 60 * 60 * 1000);
869
+ let nextEnd = new Date(originalEnd.getTime() + daysElapsed * 24 * 60 * 60 * 1000);
870
+ return filter
871
+ .replace(/saleDate\s*>=\s*"[^"]+"/g, `saleDate >= "${formatDate(nextStart)}"`)
872
+ .replace(/saleDate\s*<=\s*"[^"]+"/g, `saleDate <= "${formatDate(nextEnd)}"`);
873
+ }
874
+ function hasRollingDates(list) {
875
+ var _a, _b, _c;
876
+ return Boolean(((_a = list.query) === null || _a === void 0 ? void 0 : _a.rollingDateConfig) ||
877
+ list.rollingDateConfig ||
878
+ ((_c = (_b = list.query) === null || _b === void 0 ? void 0 : _b.secondaryFilter) === null || _c === void 0 ? void 0 : _c.rollingDateConfig));
879
+ }
880
+ function summariseRows(rows) {
881
+ let uniqueProductCodes = new Set();
882
+ let totalSoldValueInCents = 0;
883
+ let totalPurchasedValueInCents = 0;
884
+ let customersWithLocation = 0;
885
+ for (let row of rows) {
886
+ totalSoldValueInCents += Number(row.totalSoldValueInCents || 0);
887
+ totalPurchasedValueInCents += Number(row.totalPurchasedValueInCents || 0);
888
+ if (row.latitude != null && row.longitude != null) {
889
+ customersWithLocation += 1;
890
+ }
891
+ for (let productCode of row.productCodesSold || []) {
892
+ uniqueProductCodes.add(productCode);
893
+ }
894
+ for (let productCode of row.productCodesBought || []) {
895
+ uniqueProductCodes.add(productCode);
896
+ }
897
+ }
898
+ return {
899
+ totalCustomers: rows.length,
900
+ totalSoldValueInCents,
901
+ totalPurchasedValueInCents,
902
+ customersWithLocation,
903
+ uniqueProductCodes: Array.from(uniqueProductCodes),
904
+ };
905
+ }
906
+ function extractDate(filter, operator) {
907
+ if (!filter) {
908
+ return null;
909
+ }
910
+ let escapedOperator = operator.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
911
+ let match = filter.match(new RegExp(`saleDate\\s*${escapedOperator}\\s*"([^"]+)"`));
912
+ return match ? match[1] : null;
913
+ }
914
+ function extractProductCodes(filter) {
915
+ if (!filter) {
916
+ return [];
917
+ }
918
+ let inMatch = filter.match(/productCode\s+IN\s*\(([^)]+)\)/);
919
+ if (inMatch) {
920
+ return uniqueStrings(inMatch[1]
921
+ .split(",")
922
+ .map((value) => value.trim().replace(/^"|"$/g, ""))
923
+ .filter(Boolean));
924
+ }
925
+ return uniqueStrings(extractAllMatches(filter, /productCode\s*=\s*"([^"]+)"/g));
926
+ }
927
+ function extractAllMatches(filter, regex) {
928
+ if (!filter) {
929
+ return [];
930
+ }
931
+ return [...filter.matchAll(regex)].map((match) => match[1]).filter(Boolean);
932
+ }
933
+ function uniqueStrings(values) {
934
+ return Array.from(new Set(values));
935
+ }
936
+ function formatDate(date) {
937
+ return date.toISOString().split("T")[0];
938
+ }
939
+ function isNotFoundError(error) {
940
+ return error instanceof Error && error.message.includes(" not found");
941
+ }
942
+ function isRateLimitError(error) {
943
+ return error instanceof Error && error.message.includes("status 429");
944
+ }
945
+
353
946
  var util;
354
947
  (function (util) {
355
948
  util.assertEqual = (val) => val;
@@ -5140,7 +5733,7 @@ const uploadSingleFile = async (input, token) => {
5140
5733
  };
5141
5734
 
5142
5735
  // Multipart Upload for Media to the MARTEYE Media Service
5143
- function create$h() {
5736
+ function create$i() {
5144
5737
  const files = {
5145
5738
  uploadSingleFile: async (input, token) => {
5146
5739
  return await uploadSingleFile(input, token);
@@ -5155,7 +5748,7 @@ function create$h() {
5155
5748
  return files;
5156
5749
  }
5157
5750
 
5158
- function create$g(httpClient) {
5751
+ function create$h(httpClient) {
5159
5752
  const invoices = {
5160
5753
  /**
5161
5754
  * List all invoices for a market with pagination
@@ -5183,7 +5776,7 @@ function create$g(httpClient) {
5183
5776
  return invoices;
5184
5777
  }
5185
5778
 
5186
- function create$f(httpClient) {
5779
+ function create$g(httpClient) {
5187
5780
  return {
5188
5781
  create: async (marketId, saleId, lotId, data) => {
5189
5782
  return httpClient.post(`/${marketId}/sales/${saleId}/lots/${lotId}/items`, data);
@@ -5200,7 +5793,7 @@ function create$f(httpClient) {
5200
5793
  /**
5201
5794
  * Defines the possible status values for a lot in a sale
5202
5795
  */
5203
- function create$e(httpClient) {
5796
+ function create$f(httpClient) {
5204
5797
  return {
5205
5798
  get: async (marketId, saleId, lotId, options) => {
5206
5799
  return httpClient.get(`/${marketId}/sales/${saleId}/lots/${lotId}`, (options === null || options === void 0 ? void 0 : options.at) ? { at: options.at } : undefined);
@@ -5217,10 +5810,19 @@ function create$e(httpClient) {
5217
5810
  delete: async (marketId, saleId, lotId) => {
5218
5811
  return httpClient.delete(`/${marketId}/sales/${saleId}/lots/${lotId}`);
5219
5812
  },
5813
+ deletePreflight: async (marketId, saleId, lotId) => {
5814
+ return httpClient.get(`/${marketId}/sales/${saleId}/lots/${lotId}/delete-preflight`);
5815
+ },
5816
+ deletePreflightBatch: async (marketId, saleId, lotIds) => {
5817
+ return httpClient.post(`/${marketId}/sales/${saleId}/lots/delete-preflight`, { lotIds });
5818
+ },
5819
+ deleteBatch: async (marketId, saleId, lotIds, confirmedLotIds) => {
5820
+ return httpClient.post(`/${marketId}/sales/${saleId}/lots/delete`, { lotIds, confirmedLotIds });
5821
+ },
5220
5822
  };
5221
5823
  }
5222
5824
 
5223
- function create$d(httpClient) {
5825
+ function create$e(httpClient) {
5224
5826
  const markets = {
5225
5827
  get: async (marketId, options) => {
5226
5828
  return httpClient.get(`/${marketId}`, (options === null || options === void 0 ? void 0 : options.at) ? { at: options.at } : undefined);
@@ -5242,7 +5844,7 @@ function create$d(httpClient) {
5242
5844
  return markets;
5243
5845
  }
5244
5846
 
5245
- function create$c(httpClient) {
5847
+ function create$d(httpClient) {
5246
5848
  let members = {
5247
5849
  /**
5248
5850
  * List members (staff accounts) for a market with pagination
@@ -5273,7 +5875,7 @@ function create$c(httpClient) {
5273
5875
  return members;
5274
5876
  }
5275
5877
 
5276
- function create$b(httpClient) {
5878
+ function create$c(httpClient) {
5277
5879
  const payments = {
5278
5880
  /**
5279
5881
  * List all payments for a market with pagination
@@ -5301,7 +5903,7 @@ function create$b(httpClient) {
5301
5903
  return payments;
5302
5904
  }
5303
5905
 
5304
- function create$a(httpClient) {
5906
+ function create$b(httpClient) {
5305
5907
  const payouts = {
5306
5908
  /**
5307
5909
  * List all payouts for a market with pagination
@@ -5340,7 +5942,7 @@ function create$a(httpClient) {
5340
5942
  return payouts;
5341
5943
  }
5342
5944
 
5343
- function create$9(httpClient) {
5945
+ function create$a(httpClient) {
5344
5946
  return {
5345
5947
  list: async (marketId) => {
5346
5948
  return httpClient.get(`/${marketId}/product-codes`);
@@ -5357,7 +5959,7 @@ function create$9(httpClient) {
5357
5959
  };
5358
5960
  }
5359
5961
 
5360
- function create$8(httpClient) {
5962
+ function create$9(httpClient) {
5361
5963
  return {
5362
5964
  get: async (marketId, saleId, options) => {
5363
5965
  return httpClient.get(`/${marketId}/sales/${saleId}`, (options === null || options === void 0 ? void 0 : options.at) ? { at: options.at } : undefined);
@@ -5374,7 +5976,7 @@ function create$8(httpClient) {
5374
5976
  };
5375
5977
  }
5376
5978
 
5377
- function create$7(httpClient) {
5979
+ function create$8(httpClient) {
5378
5980
  return {
5379
5981
  list: async (marketId) => {
5380
5982
  return httpClient.get(`/${marketId}/sale-templates`);
@@ -5394,7 +5996,7 @@ function create$7(httpClient) {
5394
5996
  };
5395
5997
  }
5396
5998
 
5397
- function create$6(httpClient) {
5999
+ function create$7(httpClient) {
5398
6000
  let search = {
5399
6001
  /**
5400
6002
  * Search for documents within a market
@@ -5409,7 +6011,7 @@ function create$6(httpClient) {
5409
6011
  return search;
5410
6012
  }
5411
6013
 
5412
- function create$5(httpClient) {
6014
+ function create$6(httpClient) {
5413
6015
  return {
5414
6016
  get: async (marketId, options) => {
5415
6017
  return httpClient.get(`/${marketId}/settings`, (options === null || options === void 0 ? void 0 : options.at) ? { at: options.at } : undefined);
@@ -5417,7 +6019,7 @@ function create$5(httpClient) {
5417
6019
  };
5418
6020
  }
5419
6021
 
5420
- function create$4(httpClient) {
6022
+ function create$5(httpClient) {
5421
6023
  return {
5422
6024
  list: async (marketId) => {
5423
6025
  return httpClient.get(`/${marketId}/tax_rates`);
@@ -5429,7 +6031,7 @@ function create$4(httpClient) {
5429
6031
  }
5430
6032
 
5431
6033
  // Path: studiojs/src/resources/markets.ts
5432
- function create$3(_) {
6034
+ function create$4(_) {
5433
6035
  const webhooks = {
5434
6036
  /***
5435
6037
  * This is used to construct the webhook event from the request body
@@ -5464,13 +6066,13 @@ function create$3(_) {
5464
6066
  return webhooks;
5465
6067
  }
5466
6068
 
5467
- function create$2(httpClient) {
6069
+ function create$3(httpClient) {
5468
6070
  return {
5469
6071
  lookup: async (marketId, cph) => httpClient.get(`/${marketId}/cph`, { cph }),
5470
6072
  };
5471
6073
  }
5472
6074
 
5473
- function create$1(httpClient) {
6075
+ function create$2(httpClient) {
5474
6076
  return {
5475
6077
  list: async (marketId, customerId, params) => {
5476
6078
  const query = {};
@@ -5495,7 +6097,7 @@ function create$1(httpClient) {
5495
6097
  };
5496
6098
  }
5497
6099
 
5498
- function create(httpClient) {
6100
+ function create$1(httpClient) {
5499
6101
  let ledger = {
5500
6102
  /**
5501
6103
  * Get the current balance for a ledger account
@@ -5556,33 +6158,42 @@ function create(httpClient) {
5556
6158
  return ledger;
5557
6159
  }
5558
6160
 
6161
+ function create(httpClient) {
6162
+ return {
6163
+ sendSMS: async (marketId, data) => httpClient.post(`/${marketId}/sms/send`, data),
6164
+ getSMS: async (marketId, smsId) => httpClient.get(`/${marketId}/sms/${smsId}`),
6165
+ };
6166
+ }
6167
+
5559
6168
  function resources(httpClient) {
5560
6169
  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),
6170
+ activity: create$p(httpClient),
6171
+ markets: create$e(httpClient),
6172
+ members: create$d(httpClient),
6173
+ sales: create$9(httpClient),
6174
+ lots: create$f(httpClient),
6175
+ lotitems: create$g(httpClient),
6176
+ carts: create$n(httpClient),
6177
+ cph: create$3(httpClient),
6178
+ webhooks: create$4(),
6179
+ actions: create$q(),
6180
+ bidderApplications: create$l(httpClient),
6181
+ settings: create$6(httpClient),
6182
+ adjustments: create$o(httpClient),
6183
+ extras: create$m(httpClient),
6184
+ productCodes: create$a(httpClient),
6185
+ saleTemplates: create$8(httpClient),
6186
+ taxRates: create$5(httpClient),
6187
+ customers: create$k(httpClient),
6188
+ customerLists: create$j(httpClient),
6189
+ invoices: create$h(httpClient),
6190
+ payments: create$c(httpClient),
6191
+ payouts: create$b(httpClient),
6192
+ search: create$7(httpClient),
6193
+ files: create$i(),
6194
+ contacts: create$2(httpClient),
6195
+ ledger: create$1(httpClient),
6196
+ sms: create(httpClient),
5586
6197
  };
5587
6198
  }
5588
6199
 
@@ -5672,6 +6283,10 @@ const supportedWebhookEvents = [
5672
6283
  "member.created",
5673
6284
  "member.updated",
5674
6285
  "member.deleted",
6286
+ // sms tasks
6287
+ "sms-task.created",
6288
+ "sms-task.updated",
6289
+ "sms-task.deleted",
5675
6290
  ];
5676
6291
 
5677
6292
  var types = /*#__PURE__*/Object.freeze({