@timardex/cluemart-shared 2.5.0 → 2.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/{ad-DRI2CIzV.d.ts → ad-C7GbDyUi.d.ts} +1 -1
  2. package/dist/{ad-BSyVGv8q.d.mts → ad-DB9gvcJW.d.mts} +1 -1
  3. package/dist/{chunk-DEK7NF3O.mjs → chunk-T736WX7J.mjs} +5 -5
  4. package/dist/{chunk-DEK7NF3O.mjs.map → chunk-T736WX7J.mjs.map} +1 -1
  5. package/dist/{chunk-4CQLKIQ6.mjs → chunk-TGEYOSSX.mjs} +24 -2
  6. package/dist/chunk-TGEYOSSX.mjs.map +1 -0
  7. package/dist/{chunk-2RHUGVV3.mjs → chunk-WOBG6I4T.mjs} +175 -12
  8. package/dist/chunk-WOBG6I4T.mjs.map +1 -0
  9. package/dist/{chunk-L4NHGGT7.mjs → chunk-WRYRBSRZ.mjs} +2 -2
  10. package/dist/chunk-YCUKTVVA.mjs +69 -0
  11. package/dist/chunk-YCUKTVVA.mjs.map +1 -0
  12. package/dist/{chunk-CQ26N3W6.mjs → chunk-YJJUTHBX.mjs} +2 -2
  13. package/dist/formFields/index.cjs.map +1 -1
  14. package/dist/formFields/index.mjs +4 -4
  15. package/dist/graphql/index.cjs +193 -13
  16. package/dist/graphql/index.cjs.map +1 -1
  17. package/dist/graphql/index.d.mts +46 -3
  18. package/dist/graphql/index.d.ts +46 -3
  19. package/dist/graphql/index.mjs +8 -2
  20. package/dist/hooks/index.cjs +23 -13
  21. package/dist/hooks/index.cjs.map +1 -1
  22. package/dist/hooks/index.d.mts +1 -1
  23. package/dist/hooks/index.d.ts +1 -1
  24. package/dist/hooks/index.mjs +6 -6
  25. package/dist/index.cjs +236 -16
  26. package/dist/index.cjs.map +1 -1
  27. package/dist/index.d.mts +77 -2
  28. package/dist/index.d.ts +77 -2
  29. package/dist/index.mjs +221 -12
  30. package/dist/index.mjs.map +1 -1
  31. package/dist/sharing/index.cjs +2 -1
  32. package/dist/sharing/index.cjs.map +1 -1
  33. package/dist/sharing/index.mjs +2 -2
  34. package/dist/types/index.d.mts +1 -1
  35. package/dist/types/index.d.ts +1 -1
  36. package/dist/utils/index.cjs +61 -3
  37. package/dist/utils/index.cjs.map +1 -1
  38. package/dist/utils/index.d.mts +33 -1
  39. package/dist/utils/index.d.ts +33 -1
  40. package/dist/utils/index.mjs +20 -4
  41. package/package.json +1 -1
  42. package/dist/chunk-2RHUGVV3.mjs.map +0 -1
  43. package/dist/chunk-4CQLKIQ6.mjs.map +0 -1
  44. package/dist/chunk-7DQBUZXY.mjs +0 -41
  45. package/dist/chunk-7DQBUZXY.mjs.map +0 -1
  46. /package/dist/{chunk-L4NHGGT7.mjs.map → chunk-WRYRBSRZ.mjs.map} +0 -0
  47. /package/dist/{chunk-CQ26N3W6.mjs.map → chunk-YJJUTHBX.mjs.map} +0 -0
package/dist/index.mjs CHANGED
@@ -761,10 +761,11 @@ function nzDayKey(input) {
761
761
  function isUtcMidnight(value) {
762
762
  return value instanceof Date && !Number.isNaN(value.getTime()) && value.getUTCHours() === 0 && value.getUTCMinutes() === 0 && value.getUTCSeconds() === 0 && value.getUTCMilliseconds() === 0;
763
763
  }
764
+ var DATE_DISPLAY_FORMAT = "dddd, D MMMM, YYYY";
764
765
  var formatDate = (dateStr, display = "datetime", timeStr) => {
765
766
  const dateTimeStr = timeStr ? `${dateStr} ${timeStr}` : dateStr;
766
767
  const dateTime = timeStr ? dayjs2(dateTimeStr, `${dateFormat} ${timeFormat}`) : dayjs2(dateStr, dateFormat);
767
- const formattedDate = dateTime.format("dddd, D MMMM, YYYY");
768
+ const formattedDate = dateTime.format(DATE_DISPLAY_FORMAT);
768
769
  const formattedTime = dateTime.format("h:mm a");
769
770
  switch (display) {
770
771
  case "date":
@@ -777,6 +778,25 @@ var formatDate = (dateStr, display = "datetime", timeStr) => {
777
778
  return formattedDate;
778
779
  }
779
780
  };
781
+ function parseStrictDate(dateStr) {
782
+ return dayjs2(dateStr, dateFormat, true);
783
+ }
784
+ function isDayBeforeNzToday(parsed) {
785
+ const dayKey = /* @__PURE__ */ new Date(`${parsed.format(isoDateFormat)}T00:00:00Z`);
786
+ return dayKey.getTime() < nzDayKey().getTime();
787
+ }
788
+ function isPastDate(dateStr) {
789
+ const parsed = parseStrictDate(dateStr);
790
+ return parsed.isValid() && isDayBeforeNzToday(parsed);
791
+ }
792
+ function formatDateOptionLabel(dateStr) {
793
+ const parsed = parseStrictDate(dateStr);
794
+ if (!parsed.isValid()) {
795
+ return dateStr;
796
+ }
797
+ const label = parsed.format(DATE_DISPLAY_FORMAT);
798
+ return isDayBeforeNzToday(parsed) ? `${label} (Past)` : label;
799
+ }
780
800
  var SLOT_FORMATS = [
781
801
  `${dateFormat} ${timeFormat}`,
782
802
  `${dateFormat} H:mm`,
@@ -2874,6 +2894,28 @@ function isTransientNetworkError(err) {
2874
2894
  return TRANSIENT_NETWORK_PATTERNS.some((pattern) => pattern.test(message));
2875
2895
  }
2876
2896
 
2897
+ // src/utils/adMetrics.ts
2898
+ var AD_METRIC_ROTATION_INTERVAL_MS = 8e3;
2899
+ var AD_METRIC_IMPRESSION_RETRY_DELAY_MS = 1e3;
2900
+ function getAdMetricRotationSlot(epochMilliseconds) {
2901
+ return Math.floor(epochMilliseconds / AD_METRIC_ROTATION_INTERVAL_MS);
2902
+ }
2903
+ function getAdMetricRotationIndex(epochMilliseconds, count) {
2904
+ if (count <= 0) return 0;
2905
+ return getAdMetricRotationSlot(epochMilliseconds) % count;
2906
+ }
2907
+ function buildAdMetricSlotKey(adId, placement, slot) {
2908
+ return `${adId}:${placement}:${slot}`;
2909
+ }
2910
+ function generateAdClickId() {
2911
+ const cryptoApi = globalThis.crypto;
2912
+ if (typeof cryptoApi?.randomUUID === "function") {
2913
+ return cryptoApi.randomUUID();
2914
+ }
2915
+ const randomPart = Math.random().toString(36).slice(2) || "0";
2916
+ return `click-${Date.now()}-${randomPart}`;
2917
+ }
2918
+
2877
2919
  // src/utils/billingCatalog/index.ts
2878
2920
  var BILLING_CATALOG_KEYS = [
2879
2921
  "pro_vendor_monthly",
@@ -3001,7 +3043,7 @@ function getEventStallholdersData({
3001
3043
  registeredForEvent,
3002
3044
  unregisteredForEvent
3003
3045
  ).map((startDate) => ({
3004
- label: formatDate(startDate, "date"),
3046
+ label: formatDateOptionLabel(startDate),
3005
3047
  value: startDate
3006
3048
  }));
3007
3049
  const hasDatePills = futureEventStartDates.length > 0;
@@ -3029,7 +3071,7 @@ function getVendorEventsData({
3029
3071
  const eventDateOptions = getVendorEventRelationDateOptions(events).map(
3030
3072
  (option) => ({
3031
3073
  ...option,
3032
- label: formatDate(option.value, "date")
3074
+ label: formatDateOptionLabel(option.value)
3033
3075
  })
3034
3076
  );
3035
3077
  return {
@@ -7239,6 +7281,7 @@ var useGetUsersByPromoCode = (promoCode, options) => {
7239
7281
 
7240
7282
  // src/graphql/hooks/ad/hooksMutation.ts
7241
7283
  import { useMutation as useMutation12 } from "@apollo/client";
7284
+ import { useCallback, useEffect, useRef } from "react";
7242
7285
 
7243
7286
  // src/graphql/mutations/ad.ts
7244
7287
  import { gql as gql27 } from "@apollo/client";
@@ -7404,6 +7447,15 @@ var GET_AD_SETTINGS = gql28`
7404
7447
  }
7405
7448
  }
7406
7449
  `;
7450
+ var GET_AD_METRIC_TOTALS = gql28`
7451
+ query getAdMetricTotals($filter: AdMetricTotalsFilterInputGraphQLType) {
7452
+ adMetricTotals(filter: $filter) {
7453
+ adId
7454
+ clicks
7455
+ impressions
7456
+ }
7457
+ }
7458
+ `;
7407
7459
 
7408
7460
  // src/graphql/mutations/adBooking.ts
7409
7461
  var CREATE_AD_CHECKOUT_MUTATION = gql29`
@@ -7520,14 +7572,147 @@ var useRecordAdClick = () => {
7520
7572
  recordAdClick
7521
7573
  };
7522
7574
  };
7575
+ var defaultAdMetricErrorHandler = (message, error) => {
7576
+ console.error(message, error);
7577
+ };
7578
+ var useAdMetricsReporter = (input, onError = defaultAdMetricErrorHandler) => {
7579
+ const { recordAdImpression } = useRecordAdImpression();
7580
+ const { recordAdClick } = useRecordAdClick();
7581
+ const reportedSlotRef = useRef({
7582
+ keys: /* @__PURE__ */ new Set(),
7583
+ slot: -1
7584
+ });
7585
+ const inFlightRef = useRef(false);
7586
+ const disposedRef = useRef(false);
7587
+ const safeOnError = useCallback(
7588
+ (message, error) => {
7589
+ try {
7590
+ onError(message, error);
7591
+ } catch {
7592
+ }
7593
+ },
7594
+ [onError]
7595
+ );
7596
+ useEffect(() => {
7597
+ disposedRef.current = false;
7598
+ return () => {
7599
+ disposedRef.current = true;
7600
+ };
7601
+ }, []);
7602
+ const reportImpression = useCallback(
7603
+ async (opts) => {
7604
+ if (inFlightRef.current || disposedRef.current) return false;
7605
+ const now = opts?.nowMs ?? Date.now();
7606
+ const slot = getAdMetricRotationSlot(now);
7607
+ const key = buildAdMetricSlotKey(input.adId, input.placement, slot);
7608
+ const reported = reportedSlotRef.current;
7609
+ if (reported.slot !== slot) {
7610
+ reported.slot = slot;
7611
+ reported.keys.clear();
7612
+ }
7613
+ if (reported.keys.has(key)) return false;
7614
+ inFlightRef.current = true;
7615
+ try {
7616
+ const result = await recordAdImpression({
7617
+ variables: {
7618
+ input: {
7619
+ adId: input.adId,
7620
+ placement: input.placement,
7621
+ platform: input.platform,
7622
+ region: input.region
7623
+ }
7624
+ }
7625
+ });
7626
+ if (result.data?.recordAdImpression?.data !== true) {
7627
+ return false;
7628
+ }
7629
+ reported.keys.add(key);
7630
+ return true;
7631
+ } catch (error) {
7632
+ safeOnError(
7633
+ "Ad impression report failed; retrying within the rotation.",
7634
+ error
7635
+ );
7636
+ if (!disposedRef.current && getAdMetricRotationSlot(Date.now()) === slot) {
7637
+ await new Promise(
7638
+ (resolve) => setTimeout(resolve, AD_METRIC_IMPRESSION_RETRY_DELAY_MS)
7639
+ );
7640
+ if (!disposedRef.current && getAdMetricRotationSlot(Date.now()) === slot) {
7641
+ try {
7642
+ const retryResult = await recordAdImpression({
7643
+ variables: {
7644
+ input: {
7645
+ adId: input.adId,
7646
+ placement: input.placement,
7647
+ platform: input.platform,
7648
+ region: input.region
7649
+ }
7650
+ }
7651
+ });
7652
+ if (retryResult.data?.recordAdImpression?.data !== true) {
7653
+ return false;
7654
+ }
7655
+ reported.keys.add(key);
7656
+ return true;
7657
+ } catch (retryError) {
7658
+ safeOnError("Ad impression retry failed.", retryError);
7659
+ }
7660
+ }
7661
+ }
7662
+ return false;
7663
+ } finally {
7664
+ inFlightRef.current = false;
7665
+ }
7666
+ },
7667
+ [
7668
+ input.adId,
7669
+ input.placement,
7670
+ input.platform,
7671
+ input.region,
7672
+ safeOnError,
7673
+ recordAdImpression
7674
+ ]
7675
+ );
7676
+ const reportClick = useCallback(
7677
+ (adIdOverride) => {
7678
+ try {
7679
+ void recordAdClick({
7680
+ variables: {
7681
+ input: {
7682
+ adId: adIdOverride ?? input.adId,
7683
+ clickId: generateAdClickId(),
7684
+ placement: input.placement,
7685
+ platform: input.platform,
7686
+ region: input.region
7687
+ }
7688
+ }
7689
+ }).catch((error) => {
7690
+ safeOnError("Ad click report failed.", error);
7691
+ });
7692
+ } catch (error) {
7693
+ safeOnError("Ad click report failed.", error);
7694
+ }
7695
+ },
7696
+ [
7697
+ input.adId,
7698
+ input.placement,
7699
+ input.platform,
7700
+ input.region,
7701
+ safeOnError,
7702
+ recordAdClick
7703
+ ]
7704
+ );
7705
+ return { reportClick, reportImpression };
7706
+ };
7523
7707
 
7524
7708
  // src/graphql/hooks/ad/hooksQuery.ts
7525
7709
  import { useQuery as useQuery7 } from "@apollo/client";
7526
- var useGetAds = () => {
7710
+ var useGetAds = (skip = false) => {
7527
7711
  const { data, loading, error, refetch } = useQuery7(
7528
7712
  GET_ADS,
7529
7713
  {
7530
- fetchPolicy: "no-cache"
7714
+ fetchPolicy: "no-cache",
7715
+ skip
7531
7716
  }
7532
7717
  );
7533
7718
  return {
@@ -7563,6 +7748,19 @@ var useGetAdsByRegion = (region, platform, showOn) => {
7563
7748
  refetch
7564
7749
  };
7565
7750
  };
7751
+ var useGetAdMetricTotals = (filter, skip = false) => {
7752
+ const { data, loading, error, refetch } = useQuery7(GET_AD_METRIC_TOTALS, {
7753
+ fetchPolicy: "no-cache",
7754
+ skip,
7755
+ variables: filter ? { filter } : void 0
7756
+ });
7757
+ return {
7758
+ adMetricTotals: data?.adMetricTotals || [],
7759
+ error,
7760
+ loading,
7761
+ refetch
7762
+ };
7763
+ };
7566
7764
 
7567
7765
  // src/graphql/hooks/resourceActivities/hooksMutation.ts
7568
7766
  import { useMutation as useMutation13 } from "@apollo/client";
@@ -9177,7 +9375,7 @@ var useGetCoupon = (_id) => {
9177
9375
 
9178
9376
  // src/graphql/hooks/usePaginatedList.ts
9179
9377
  import { useQuery as useQuery18 } from "@apollo/client";
9180
- import { useCallback, useEffect, useRef, useState } from "react";
9378
+ import { useCallback as useCallback2, useEffect as useEffect2, useRef as useRef2, useState } from "react";
9181
9379
  function usePaginatedList({
9182
9380
  document,
9183
9381
  getItems,
@@ -9196,7 +9394,7 @@ function usePaginatedList({
9196
9394
  const [hasMore, setHasMore] = useState(!skip);
9197
9395
  const [hasSettled, setHasSettled] = useState(false);
9198
9396
  const variablesKey = JSON.stringify(variables ?? null);
9199
- useEffect(() => {
9397
+ useEffect2(() => {
9200
9398
  setItems([]);
9201
9399
  setHasMore(!skip);
9202
9400
  setHasSettled(false);
@@ -9207,14 +9405,14 @@ function usePaginatedList({
9207
9405
  skip,
9208
9406
  variables: { ...variables, options: { limit: pageSize + 1, offset } }
9209
9407
  });
9210
- const refetchRef = useRef(refetch);
9408
+ const refetchRef = useRef2(refetch);
9211
9409
  refetchRef.current = refetch;
9212
- const variablesRef = useRef(variables);
9410
+ const variablesRef = useRef2(variables);
9213
9411
  variablesRef.current = variables;
9214
9412
  const rawPage = getItems(data);
9215
9413
  const page = rawPage.length > pageSize ? rawPage.slice(0, pageSize) : rawPage;
9216
9414
  const hasMorePage = rawPage.length > pageSize;
9217
- useEffect(() => {
9415
+ useEffect2(() => {
9218
9416
  if (loading || skip || error) {
9219
9417
  return;
9220
9418
  }
@@ -9230,7 +9428,7 @@ function usePaginatedList({
9230
9428
  setHasSettled(true);
9231
9429
  setHasMore(hasMorePage);
9232
9430
  }, [loading, skip, error, page, hasMorePage, hasSettled, pageSize, getId]);
9233
- const loadMore = useCallback(() => {
9431
+ const loadMore = useCallback2(() => {
9234
9432
  if (loading || skip) {
9235
9433
  return;
9236
9434
  }
@@ -9246,7 +9444,7 @@ function usePaginatedList({
9246
9444
  }
9247
9445
  setOffset(offset + pageSize);
9248
9446
  }, [loading, skip, error, hasSettled, hasMore, offset, pageSize]);
9249
- const refresh = useCallback(() => {
9447
+ const refresh = useCallback2(() => {
9250
9448
  setItems([]);
9251
9449
  setHasMore(!skip);
9252
9450
  setHasSettled(false);
@@ -9828,6 +10026,8 @@ export {
9828
10026
  ADMIN_APP_ROLES,
9829
10027
  ADMIN_DASHBOARD_CONTEXTS,
9830
10028
  AD_BOOKING_FIELDS_FRAGMENT,
10029
+ AD_METRIC_IMPRESSION_RETRY_DELAY_MS,
10030
+ AD_METRIC_ROTATION_INTERVAL_MS,
9831
10031
  AFFILIATE_PARTICIPANT_TYPE_LABELS,
9832
10032
  AFFILIATE_REWARDS,
9833
10033
  ANDROID_URL,
@@ -9891,6 +10091,7 @@ export {
9891
10091
  FUTURE_EVENT_DATE_STATUSES,
9892
10092
  GET_AD_BOOKING,
9893
10093
  GET_AD_DAILY_PRICES,
10094
+ GET_AD_METRIC_TOTALS,
9894
10095
  GET_AD_SETTINGS,
9895
10096
  GET_EVENT,
9896
10097
  GET_EVENTS,
@@ -9984,6 +10185,7 @@ export {
9984
10185
  badges,
9985
10186
  bankAccountDetailsFields,
9986
10187
  billingCatalogDefinitionMatches,
10188
+ buildAdMetricSlotKey,
9987
10189
  buildApplicationShareDescription,
9988
10190
  buildCalendarSheetContentData,
9989
10191
  buildInvitationShareDescription,
@@ -10035,6 +10237,7 @@ export {
10035
10237
  foodFlavourOptions,
10036
10238
  formatCategoryLabel,
10037
10239
  formatDate,
10240
+ formatDateOptionLabel,
10038
10241
  formatDistance,
10039
10242
  formatIrdNumber,
10040
10243
  formatNZBankAccount,
@@ -10056,6 +10259,9 @@ export {
10056
10259
  futureTimePeriods,
10057
10260
  gameScreenIdentifierList,
10058
10261
  gameTypeToDisplayName,
10262
+ generateAdClickId,
10263
+ getAdMetricRotationIndex,
10264
+ getAdMetricRotationSlot,
10059
10265
  getAllowedEventDateStatuses,
10060
10266
  getBillingCatalogKeyForSelection,
10061
10267
  getCurrentAndFutureDates,
@@ -10100,6 +10306,7 @@ export {
10100
10306
  isInternalErrorMessage,
10101
10307
  isIsoDateString,
10102
10308
  isNonVisitorResourceType,
10309
+ isPastDate,
10103
10310
  isPostShareResourceType,
10104
10311
  isRelationShareResourceType,
10105
10312
  isResourceImageActive,
@@ -10170,6 +10377,7 @@ export {
10170
10377
  truncateText,
10171
10378
  updateSingleDateTimeStatus,
10172
10379
  useActivateVendorClaim,
10380
+ useAdMetricsReporter,
10173
10381
  useAddParticipantToChat,
10174
10382
  useAddUserFavouriteResource,
10175
10383
  useAddUserGoingResource,
@@ -10220,6 +10428,7 @@ export {
10220
10428
  useDeleteVendor,
10221
10429
  useEndImpersonation,
10222
10430
  useGetAd,
10431
+ useGetAdMetricTotals,
10223
10432
  useGetAds,
10224
10433
  useGetAdsByRegion,
10225
10434
  useGetAffiliate,