@timardex/cluemart-shared 2.5.0 → 2.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) 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-L4NHGGT7.mjs → chunk-H6HM2FOZ.mjs} +2 -2
  4. package/dist/{chunk-DEK7NF3O.mjs → chunk-NEOBS55J.mjs} +1 -1
  5. package/dist/{chunk-2RHUGVV3.mjs → chunk-WOBG6I4T.mjs} +175 -12
  6. package/dist/chunk-WOBG6I4T.mjs.map +1 -0
  7. package/dist/chunk-YCUKTVVA.mjs +69 -0
  8. package/dist/chunk-YCUKTVVA.mjs.map +1 -0
  9. package/dist/formFields/index.mjs +3 -3
  10. package/dist/graphql/index.cjs +193 -13
  11. package/dist/graphql/index.cjs.map +1 -1
  12. package/dist/graphql/index.d.mts +46 -3
  13. package/dist/graphql/index.d.ts +46 -3
  14. package/dist/graphql/index.mjs +8 -2
  15. package/dist/hooks/index.cjs +23 -13
  16. package/dist/hooks/index.cjs.map +1 -1
  17. package/dist/hooks/index.d.mts +1 -1
  18. package/dist/hooks/index.d.ts +1 -1
  19. package/dist/hooks/index.mjs +4 -4
  20. package/dist/index.cjs +209 -13
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.mts +61 -2
  23. package/dist/index.d.ts +61 -2
  24. package/dist/index.mjs +196 -9
  25. package/dist/index.mjs.map +1 -1
  26. package/dist/types/index.d.mts +1 -1
  27. package/dist/types/index.d.ts +1 -1
  28. package/dist/utils/index.cjs +34 -0
  29. package/dist/utils/index.cjs.map +1 -1
  30. package/dist/utils/index.d.mts +17 -1
  31. package/dist/utils/index.d.ts +17 -1
  32. package/dist/utils/index.mjs +15 -3
  33. package/package.json +1 -1
  34. package/dist/chunk-2RHUGVV3.mjs.map +0 -1
  35. package/dist/chunk-7DQBUZXY.mjs +0 -41
  36. package/dist/chunk-7DQBUZXY.mjs.map +0 -1
  37. /package/dist/{chunk-L4NHGGT7.mjs.map → chunk-H6HM2FOZ.mjs.map} +0 -0
  38. /package/dist/{chunk-DEK7NF3O.mjs.map → chunk-NEOBS55J.mjs.map} +0 -0
@@ -42,17 +42,17 @@ import {
42
42
  vendorStallSize,
43
43
  vendorStartDateFields,
44
44
  vendorTable
45
- } from "../chunk-L4NHGGT7.mjs";
45
+ } from "../chunk-H6HM2FOZ.mjs";
46
46
  import {
47
47
  availableCategories,
48
48
  categoryColors
49
- } from "../chunk-DEK7NF3O.mjs";
49
+ } from "../chunk-NEOBS55J.mjs";
50
50
  import "../chunk-RE4NZPYY.mjs";
51
51
  import "../chunk-4CQLKIQ6.mjs";
52
52
  import "../chunk-WWAHS5R2.mjs";
53
53
  import "../chunk-RAYUJODN.mjs";
54
54
  import "../chunk-DQ7ZHIXW.mjs";
55
- import "../chunk-7DQBUZXY.mjs";
55
+ import "../chunk-YCUKTVVA.mjs";
56
56
  import "../chunk-A52C6JDT.mjs";
57
57
  export {
58
58
  availableCategories,
@@ -26,6 +26,7 @@ __export(graphql_exports, {
26
26
  CREATE_AD_CHECKOUT_MUTATION: () => CREATE_AD_CHECKOUT_MUTATION,
27
27
  GET_AD_BOOKING: () => GET_AD_BOOKING,
28
28
  GET_AD_DAILY_PRICES: () => GET_AD_DAILY_PRICES,
29
+ GET_AD_METRIC_TOTALS: () => GET_AD_METRIC_TOTALS,
29
30
  GET_AD_SETTINGS: () => GET_AD_SETTINGS,
30
31
  GET_EVENT: () => GET_EVENT,
31
32
  GET_EVENTS: () => GET_EVENTS,
@@ -54,6 +55,7 @@ __export(graphql_exports, {
54
55
  UPDATE_AD_SETTINGS_MUTATION: () => UPDATE_AD_SETTINGS_MUTATION,
55
56
  toGraphqlQueryString: () => toGraphqlQueryString,
56
57
  useActivateVendorClaim: () => useActivateVendorClaim,
58
+ useAdMetricsReporter: () => useAdMetricsReporter,
57
59
  useAddParticipantToChat: () => useAddParticipantToChat,
58
60
  useAddUserFavouriteResource: () => useAddUserFavouriteResource,
59
61
  useAddUserGoingResource: () => useAddUserGoingResource,
@@ -104,6 +106,7 @@ __export(graphql_exports, {
104
106
  useDeleteVendor: () => useDeleteVendor,
105
107
  useEndImpersonation: () => useEndImpersonation,
106
108
  useGetAd: () => useGetAd,
109
+ useGetAdMetricTotals: () => useGetAdMetricTotals,
107
110
  useGetAds: () => useGetAds,
108
111
  useGetAdsByRegion: () => useGetAdsByRegion,
109
112
  useGetAffiliate: () => useGetAffiliate,
@@ -3645,6 +3648,7 @@ var useGetUsersByPromoCode = (promoCode, options) => {
3645
3648
 
3646
3649
  // src/graphql/hooks/ad/hooksMutation.ts
3647
3650
  var import_client48 = require("@apollo/client");
3651
+ var import_react = require("react");
3648
3652
 
3649
3653
  // src/graphql/mutations/ad.ts
3650
3654
  var import_client45 = require("@apollo/client");
@@ -3810,6 +3814,15 @@ var GET_AD_SETTINGS = import_client46.gql`
3810
3814
  }
3811
3815
  }
3812
3816
  `;
3817
+ var GET_AD_METRIC_TOTALS = import_client46.gql`
3818
+ query getAdMetricTotals($filter: AdMetricTotalsFilterInputGraphQLType) {
3819
+ adMetricTotals(filter: $filter) {
3820
+ adId
3821
+ clicks
3822
+ impressions
3823
+ }
3824
+ }
3825
+ `;
3813
3826
 
3814
3827
  // src/graphql/mutations/adBooking.ts
3815
3828
  var CREATE_AD_CHECKOUT_MUTATION = import_client47.gql`
@@ -3876,6 +3889,24 @@ var RECORD_AD_CLICK_MUTATION = import_client47.gql`
3876
3889
  }
3877
3890
  `;
3878
3891
 
3892
+ // src/utils/adMetrics.ts
3893
+ var AD_METRIC_ROTATION_INTERVAL_MS = 8e3;
3894
+ var AD_METRIC_IMPRESSION_RETRY_DELAY_MS = 1e3;
3895
+ function getAdMetricRotationSlot(epochMilliseconds) {
3896
+ return Math.floor(epochMilliseconds / AD_METRIC_ROTATION_INTERVAL_MS);
3897
+ }
3898
+ function buildAdMetricSlotKey(adId, placement, slot) {
3899
+ return `${adId}:${placement}:${slot}`;
3900
+ }
3901
+ function generateAdClickId() {
3902
+ const cryptoApi = globalThis.crypto;
3903
+ if (typeof cryptoApi?.randomUUID === "function") {
3904
+ return cryptoApi.randomUUID();
3905
+ }
3906
+ const randomPart = Math.random().toString(36).slice(2) || "0";
3907
+ return `click-${Date.now()}-${randomPart}`;
3908
+ }
3909
+
3879
3910
  // src/graphql/hooks/ad/hooksMutation.ts
3880
3911
  var useCreateAd = () => {
3881
3912
  const [createAd, { loading, error }] = (0, import_client48.useMutation)(CREATE_AD_MUTATION, {
@@ -3926,14 +3957,147 @@ var useRecordAdClick = () => {
3926
3957
  recordAdClick
3927
3958
  };
3928
3959
  };
3960
+ var defaultAdMetricErrorHandler = (message, error) => {
3961
+ console.error(message, error);
3962
+ };
3963
+ var useAdMetricsReporter = (input, onError = defaultAdMetricErrorHandler) => {
3964
+ const { recordAdImpression } = useRecordAdImpression();
3965
+ const { recordAdClick } = useRecordAdClick();
3966
+ const reportedSlotRef = (0, import_react.useRef)({
3967
+ keys: /* @__PURE__ */ new Set(),
3968
+ slot: -1
3969
+ });
3970
+ const inFlightRef = (0, import_react.useRef)(false);
3971
+ const disposedRef = (0, import_react.useRef)(false);
3972
+ const safeOnError = (0, import_react.useCallback)(
3973
+ (message, error) => {
3974
+ try {
3975
+ onError(message, error);
3976
+ } catch {
3977
+ }
3978
+ },
3979
+ [onError]
3980
+ );
3981
+ (0, import_react.useEffect)(() => {
3982
+ disposedRef.current = false;
3983
+ return () => {
3984
+ disposedRef.current = true;
3985
+ };
3986
+ }, []);
3987
+ const reportImpression = (0, import_react.useCallback)(
3988
+ async (opts) => {
3989
+ if (inFlightRef.current || disposedRef.current) return false;
3990
+ const now = opts?.nowMs ?? Date.now();
3991
+ const slot = getAdMetricRotationSlot(now);
3992
+ const key = buildAdMetricSlotKey(input.adId, input.placement, slot);
3993
+ const reported = reportedSlotRef.current;
3994
+ if (reported.slot !== slot) {
3995
+ reported.slot = slot;
3996
+ reported.keys.clear();
3997
+ }
3998
+ if (reported.keys.has(key)) return false;
3999
+ inFlightRef.current = true;
4000
+ try {
4001
+ const result = await recordAdImpression({
4002
+ variables: {
4003
+ input: {
4004
+ adId: input.adId,
4005
+ placement: input.placement,
4006
+ platform: input.platform,
4007
+ region: input.region
4008
+ }
4009
+ }
4010
+ });
4011
+ if (result.data?.recordAdImpression?.data !== true) {
4012
+ return false;
4013
+ }
4014
+ reported.keys.add(key);
4015
+ return true;
4016
+ } catch (error) {
4017
+ safeOnError(
4018
+ "Ad impression report failed; retrying within the rotation.",
4019
+ error
4020
+ );
4021
+ if (!disposedRef.current && getAdMetricRotationSlot(Date.now()) === slot) {
4022
+ await new Promise(
4023
+ (resolve) => setTimeout(resolve, AD_METRIC_IMPRESSION_RETRY_DELAY_MS)
4024
+ );
4025
+ if (!disposedRef.current && getAdMetricRotationSlot(Date.now()) === slot) {
4026
+ try {
4027
+ const retryResult = await recordAdImpression({
4028
+ variables: {
4029
+ input: {
4030
+ adId: input.adId,
4031
+ placement: input.placement,
4032
+ platform: input.platform,
4033
+ region: input.region
4034
+ }
4035
+ }
4036
+ });
4037
+ if (retryResult.data?.recordAdImpression?.data !== true) {
4038
+ return false;
4039
+ }
4040
+ reported.keys.add(key);
4041
+ return true;
4042
+ } catch (retryError) {
4043
+ safeOnError("Ad impression retry failed.", retryError);
4044
+ }
4045
+ }
4046
+ }
4047
+ return false;
4048
+ } finally {
4049
+ inFlightRef.current = false;
4050
+ }
4051
+ },
4052
+ [
4053
+ input.adId,
4054
+ input.placement,
4055
+ input.platform,
4056
+ input.region,
4057
+ safeOnError,
4058
+ recordAdImpression
4059
+ ]
4060
+ );
4061
+ const reportClick = (0, import_react.useCallback)(
4062
+ (adIdOverride) => {
4063
+ try {
4064
+ void recordAdClick({
4065
+ variables: {
4066
+ input: {
4067
+ adId: adIdOverride ?? input.adId,
4068
+ clickId: generateAdClickId(),
4069
+ placement: input.placement,
4070
+ platform: input.platform,
4071
+ region: input.region
4072
+ }
4073
+ }
4074
+ }).catch((error) => {
4075
+ safeOnError("Ad click report failed.", error);
4076
+ });
4077
+ } catch (error) {
4078
+ safeOnError("Ad click report failed.", error);
4079
+ }
4080
+ },
4081
+ [
4082
+ input.adId,
4083
+ input.placement,
4084
+ input.platform,
4085
+ input.region,
4086
+ safeOnError,
4087
+ recordAdClick
4088
+ ]
4089
+ );
4090
+ return { reportClick, reportImpression };
4091
+ };
3929
4092
 
3930
4093
  // src/graphql/hooks/ad/hooksQuery.ts
3931
4094
  var import_client49 = require("@apollo/client");
3932
- var useGetAds = () => {
4095
+ var useGetAds = (skip = false) => {
3933
4096
  const { data, loading, error, refetch } = (0, import_client49.useQuery)(
3934
4097
  GET_ADS,
3935
4098
  {
3936
- fetchPolicy: "no-cache"
4099
+ fetchPolicy: "no-cache",
4100
+ skip
3937
4101
  }
3938
4102
  );
3939
4103
  return {
@@ -3969,6 +4133,19 @@ var useGetAdsByRegion = (region, platform, showOn) => {
3969
4133
  refetch
3970
4134
  };
3971
4135
  };
4136
+ var useGetAdMetricTotals = (filter, skip = false) => {
4137
+ const { data, loading, error, refetch } = (0, import_client49.useQuery)(GET_AD_METRIC_TOTALS, {
4138
+ fetchPolicy: "no-cache",
4139
+ skip,
4140
+ variables: filter ? { filter } : void 0
4141
+ });
4142
+ return {
4143
+ adMetricTotals: data?.adMetricTotals || [],
4144
+ error,
4145
+ loading,
4146
+ refetch
4147
+ };
4148
+ };
3972
4149
 
3973
4150
  // src/graphql/hooks/resourceActivities/hooksMutation.ts
3974
4151
  var import_client51 = require("@apollo/client");
@@ -5583,7 +5760,7 @@ var useGetCoupon = (_id) => {
5583
5760
 
5584
5761
  // src/graphql/hooks/usePaginatedList.ts
5585
5762
  var import_client88 = require("@apollo/client");
5586
- var import_react = require("react");
5763
+ var import_react2 = require("react");
5587
5764
 
5588
5765
  // src/utils/pagination.ts
5589
5766
  var DEFAULT_PAGE_SIZE = 50;
@@ -5630,12 +5807,12 @@ function usePaginatedList({
5630
5807
  `usePaginatedList: pageSize must be a positive integer, received ${String(pageSize)}.`
5631
5808
  );
5632
5809
  }
5633
- const [offset, setOffset] = (0, import_react.useState)(0);
5634
- const [items, setItems] = (0, import_react.useState)([]);
5635
- const [hasMore, setHasMore] = (0, import_react.useState)(!skip);
5636
- const [hasSettled, setHasSettled] = (0, import_react.useState)(false);
5810
+ const [offset, setOffset] = (0, import_react2.useState)(0);
5811
+ const [items, setItems] = (0, import_react2.useState)([]);
5812
+ const [hasMore, setHasMore] = (0, import_react2.useState)(!skip);
5813
+ const [hasSettled, setHasSettled] = (0, import_react2.useState)(false);
5637
5814
  const variablesKey = JSON.stringify(variables ?? null);
5638
- (0, import_react.useEffect)(() => {
5815
+ (0, import_react2.useEffect)(() => {
5639
5816
  setItems([]);
5640
5817
  setHasMore(!skip);
5641
5818
  setHasSettled(false);
@@ -5646,14 +5823,14 @@ function usePaginatedList({
5646
5823
  skip,
5647
5824
  variables: { ...variables, options: { limit: pageSize + 1, offset } }
5648
5825
  });
5649
- const refetchRef = (0, import_react.useRef)(refetch);
5826
+ const refetchRef = (0, import_react2.useRef)(refetch);
5650
5827
  refetchRef.current = refetch;
5651
- const variablesRef = (0, import_react.useRef)(variables);
5828
+ const variablesRef = (0, import_react2.useRef)(variables);
5652
5829
  variablesRef.current = variables;
5653
5830
  const rawPage = getItems(data);
5654
5831
  const page = rawPage.length > pageSize ? rawPage.slice(0, pageSize) : rawPage;
5655
5832
  const hasMorePage = rawPage.length > pageSize;
5656
- (0, import_react.useEffect)(() => {
5833
+ (0, import_react2.useEffect)(() => {
5657
5834
  if (loading || skip || error) {
5658
5835
  return;
5659
5836
  }
@@ -5669,7 +5846,7 @@ function usePaginatedList({
5669
5846
  setHasSettled(true);
5670
5847
  setHasMore(hasMorePage);
5671
5848
  }, [loading, skip, error, page, hasMorePage, hasSettled, pageSize, getId]);
5672
- const loadMore = (0, import_react.useCallback)(() => {
5849
+ const loadMore = (0, import_react2.useCallback)(() => {
5673
5850
  if (loading || skip) {
5674
5851
  return;
5675
5852
  }
@@ -5685,7 +5862,7 @@ function usePaginatedList({
5685
5862
  }
5686
5863
  setOffset(offset + pageSize);
5687
5864
  }, [loading, skip, error, hasSettled, hasMore, offset, pageSize]);
5688
- const refresh = (0, import_react.useCallback)(() => {
5865
+ const refresh = (0, import_react2.useCallback)(() => {
5689
5866
  setItems([]);
5690
5867
  setHasMore(!skip);
5691
5868
  setHasSettled(false);
@@ -5716,6 +5893,7 @@ function usePaginatedList({
5716
5893
  CREATE_AD_CHECKOUT_MUTATION,
5717
5894
  GET_AD_BOOKING,
5718
5895
  GET_AD_DAILY_PRICES,
5896
+ GET_AD_METRIC_TOTALS,
5719
5897
  GET_AD_SETTINGS,
5720
5898
  GET_EVENT,
5721
5899
  GET_EVENTS,
@@ -5744,6 +5922,7 @@ function usePaginatedList({
5744
5922
  UPDATE_AD_SETTINGS_MUTATION,
5745
5923
  toGraphqlQueryString,
5746
5924
  useActivateVendorClaim,
5925
+ useAdMetricsReporter,
5747
5926
  useAddParticipantToChat,
5748
5927
  useAddUserFavouriteResource,
5749
5928
  useAddUserGoingResource,
@@ -5794,6 +5973,7 @@ function usePaginatedList({
5794
5973
  useDeleteVendor,
5795
5974
  useEndImpersonation,
5796
5975
  useGetAd,
5976
+ useGetAdMetricTotals,
5797
5977
  useGetAds,
5798
5978
  useGetAdsByRegion,
5799
5979
  useGetAffiliate,