@umituz/react-native-subscription 2.27.114 → 2.27.116

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 (44) hide show
  1. package/package.json +1 -1
  2. package/src/domains/credits/infrastructure/CreditsRepository.ts +16 -19
  3. package/src/domains/credits/utils/creditCalculations.ts +6 -11
  4. package/src/domains/subscription/application/SubscriptionSyncService.ts +3 -0
  5. package/src/domains/subscription/infrastructure/services/CustomerInfoListenerManager.ts +3 -0
  6. package/src/domains/subscription/infrastructure/services/RevenueCatInitializer.ts +1 -0
  7. package/src/domains/subscription/infrastructure/services/RevenueCatService.ts +1 -0
  8. package/src/domains/subscription/infrastructure/utils/PremiumStatusSyncer.ts +3 -0
  9. package/src/domains/subscription/presentation/useAuthAwarePurchase.ts +4 -8
  10. package/src/domains/wallet/infrastructure/repositories/TransactionRepository.ts +18 -42
  11. package/src/domains/wallet/infrastructure/services/ProductMetadataService.ts +2 -6
  12. package/src/shared/infrastructure/SubscriptionEventBus.ts +1 -0
  13. package/src/shared/infrastructure/firestore/collectionUtils.ts +67 -0
  14. package/src/shared/infrastructure/firestore/index.ts +6 -0
  15. package/src/shared/infrastructure/firestore/resultUtils.ts +68 -0
  16. package/src/shared/infrastructure/index.ts +6 -0
  17. package/src/shared/presentation/hooks/index.ts +6 -0
  18. package/src/shared/presentation/hooks/useAsyncState.ts +72 -0
  19. package/src/shared/presentation/hooks/useServiceCall.ts +66 -0
  20. package/src/shared/types/CommonTypes.ts +6 -1
  21. package/src/shared/types/ReactTypes.ts +80 -0
  22. package/src/shared/utils/Result.ts +0 -16
  23. package/src/shared/utils/arrayUtils.core.ts +81 -0
  24. package/src/shared/utils/arrayUtils.query.ts +118 -0
  25. package/src/shared/utils/arrayUtils.transforms.ts +116 -0
  26. package/src/shared/utils/arrayUtils.ts +19 -0
  27. package/src/shared/utils/index.ts +14 -0
  28. package/src/shared/utils/numberUtils.aggregate.ts +35 -0
  29. package/src/shared/utils/numberUtils.core.ts +73 -0
  30. package/src/shared/utils/numberUtils.format.ts +42 -0
  31. package/src/shared/utils/numberUtils.math.ts +48 -0
  32. package/src/shared/utils/numberUtils.ts +9 -0
  33. package/src/shared/utils/stringUtils.case.ts +64 -0
  34. package/src/shared/utils/stringUtils.check.ts +65 -0
  35. package/src/shared/utils/stringUtils.format.ts +84 -0
  36. package/src/shared/utils/stringUtils.generate.ts +47 -0
  37. package/src/shared/utils/stringUtils.modify.ts +67 -0
  38. package/src/shared/utils/stringUtils.ts +10 -0
  39. package/src/shared/utils/validators.ts +187 -0
  40. package/src/utils/dateUtils.compare.ts +65 -0
  41. package/src/utils/dateUtils.core.ts +67 -0
  42. package/src/utils/dateUtils.format.ts +138 -0
  43. package/src/utils/dateUtils.math.ts +112 -0
  44. package/src/utils/dateUtils.ts +6 -28
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Date Utilities - Formatting
3
+ * Date display and formatting functions
4
+ */
5
+
6
+ import type { DateLike } from "./dateUtils.core";
7
+
8
+ /**
9
+ * Format date to locale string
10
+ */
11
+ export function formatLocale(
12
+ date: DateLike,
13
+ options?: Intl.DateTimeFormatOptions,
14
+ locale: string = "en-US"
15
+ ): string {
16
+ const d = new Date(date);
17
+ if (isNaN(d.getTime())) {
18
+ return "";
19
+ }
20
+ return d.toLocaleDateString(locale, options);
21
+ }
22
+
23
+ /**
24
+ * Format date to relative time (e.g., "2 days ago", "in 3 hours")
25
+ */
26
+ export function formatRelative(date: DateLike, now: Date = new Date()): string {
27
+ const target = new Date(date);
28
+ if (isNaN(target.getTime())) {
29
+ return "";
30
+ }
31
+
32
+ const diffMs = target.getTime() - now.getTime();
33
+ const diffSecs = Math.floor(diffMs / 1000);
34
+ const diffMins = Math.floor(diffSecs / 60);
35
+ const diffHours = Math.floor(diffMins / 60);
36
+ const diffDays = Math.floor(diffHours / 24);
37
+
38
+ const rtf = new Intl.RelativeTimeFormat("en", { numeric: "auto" });
39
+
40
+ if (Math.abs(diffDays) > 0) {
41
+ return rtf.format(diffDays, "day");
42
+ }
43
+ if (Math.abs(diffHours) > 0) {
44
+ return rtf.format(diffHours, "hour");
45
+ }
46
+ if (Math.abs(diffMins) > 0) {
47
+ return rtf.format(diffMins, "minute");
48
+ }
49
+ return rtf.format(diffSecs, "second");
50
+ }
51
+
52
+ /**
53
+ * Format date to short date string (e.g., "1/1/2024")
54
+ */
55
+ export function formatShort(date: DateLike, locale: string = "en-US"): string {
56
+ return formatLocale(date, { month: "numeric", day: "numeric", year: "numeric" }, locale);
57
+ }
58
+
59
+ /**
60
+ * Format date to medium date string (e.g., "Jan 1, 2024")
61
+ */
62
+ export function formatMedium(date: DateLike, locale: string = "en-US"): string {
63
+ return formatLocale(date, { month: "short", day: "numeric", year: "numeric" }, locale);
64
+ }
65
+
66
+ /**
67
+ * Format date to long date string (e.g., "January 1, 2024")
68
+ */
69
+ export function formatLong(date: DateLike, locale: string = "en-US"): string {
70
+ return formatLocale(date, { month: "long", day: "numeric", year: "numeric" }, locale);
71
+ }
72
+
73
+ /**
74
+ * Format date to time string
75
+ */
76
+ export function formatTime(date: DateLike, locale: string = "en-US"): string {
77
+ return formatLocale(date, { hour: "numeric", minute: "numeric" }, locale);
78
+ }
79
+
80
+ /**
81
+ * Format date to date and time string
82
+ */
83
+ export function formatDateTime(date: DateLike, locale: string = "en-US"): string {
84
+ return formatLocale(
85
+ date,
86
+ { month: "short", day: "numeric", year: "numeric", hour: "numeric", minute: "numeric" },
87
+ locale
88
+ );
89
+ }
90
+
91
+ /**
92
+ * Convert milliseconds to human-readable duration
93
+ */
94
+ export function formatDuration(ms: number): string {
95
+ const seconds = Math.floor(ms / 1000);
96
+ const minutes = Math.floor(seconds / 60);
97
+ const hours = Math.floor(minutes / 60);
98
+ const days = Math.floor(hours / 24);
99
+
100
+ if (days > 0) {
101
+ return `${days}d ${hours % 24}h`;
102
+ }
103
+ if (hours > 0) {
104
+ return `${hours}h ${minutes % 60}m`;
105
+ }
106
+ if (minutes > 0) {
107
+ return `${minutes}m ${seconds % 60}s`;
108
+ }
109
+ return `${seconds}s`;
110
+ }
111
+
112
+ /**
113
+ * Format date to weekday name (e.g., "Monday")
114
+ */
115
+ export function formatWeekday(date: DateLike, locale: string = "en-US"): string {
116
+ return formatLocale(date, { weekday: "long" }, locale);
117
+ }
118
+
119
+ /**
120
+ * Format date to short weekday name (e.g., "Mon")
121
+ */
122
+ export function formatWeekdayShort(date: DateLike, locale: string = "en-US"): string {
123
+ return formatLocale(date, { weekday: "short" }, locale);
124
+ }
125
+
126
+ /**
127
+ * Format date to month name (e.g., "January")
128
+ */
129
+ export function formatMonth(date: DateLike, locale: string = "en-US"): string {
130
+ return formatLocale(date, { month: "long" }, locale);
131
+ }
132
+
133
+ /**
134
+ * Format date to short month name (e.g., "Jan")
135
+ */
136
+ export function formatMonthShort(date: DateLike, locale: string = "en-US"): string {
137
+ return formatLocale(date, { month: "short" }, locale);
138
+ }
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Date Utilities - Math Operations
3
+ * Date arithmetic and manipulation functions
4
+ */
5
+
6
+ import type { DateLike } from "./dateUtils.core";
7
+
8
+ /**
9
+ * Add days to a date
10
+ */
11
+ export function addDays(date: DateLike, days: number): Date {
12
+ const result = new Date(date);
13
+ result.setDate(result.getDate() + days);
14
+ return result;
15
+ }
16
+
17
+ /**
18
+ * Add hours to a date
19
+ */
20
+ export function addHours(date: DateLike, hours: number): Date {
21
+ const result = new Date(date);
22
+ result.setHours(result.getHours() + hours);
23
+ return result;
24
+ }
25
+
26
+ /**
27
+ * Add minutes to a date
28
+ */
29
+ export function addMinutes(date: DateLike, minutes: number): Date {
30
+ const result = new Date(date);
31
+ result.setMinutes(result.getMinutes() + minutes);
32
+ return result;
33
+ }
34
+
35
+ /**
36
+ * Add months to a date
37
+ */
38
+ export function addMonths(date: DateLike, months: number): Date {
39
+ const result = new Date(date);
40
+ result.setMonth(result.getMonth() + months);
41
+ return result;
42
+ }
43
+
44
+ /**
45
+ * Add years to a date
46
+ */
47
+ export function addYears(date: DateLike, years: number): Date {
48
+ const result = new Date(date);
49
+ result.setFullYear(result.getFullYear() + years);
50
+ return result;
51
+ }
52
+
53
+ /**
54
+ * Subtract days from a date
55
+ */
56
+ export function subtractDays(date: DateLike, days: number): Date {
57
+ return addDays(date, -days);
58
+ }
59
+
60
+ /**
61
+ * Get start of day (midnight)
62
+ */
63
+ export function startOfDay(date: DateLike): Date {
64
+ const d = new Date(date);
65
+ d.setHours(0, 0, 0, 0);
66
+ return d;
67
+ }
68
+
69
+ /**
70
+ * Get end of day (23:59:59.999)
71
+ */
72
+ export function endOfDay(date: DateLike): Date {
73
+ const d = new Date(date);
74
+ d.setHours(23, 59, 59, 999);
75
+ return d;
76
+ }
77
+
78
+ /**
79
+ * Get start of week (Sunday)
80
+ */
81
+ export function startOfWeek(date: DateLike): Date {
82
+ const d = new Date(date);
83
+ const day = d.getDay();
84
+ const diff = d.getDate() - day;
85
+ return new Date(d.setDate(diff));
86
+ }
87
+
88
+ /**
89
+ * Get end of week (Saturday)
90
+ */
91
+ export function endOfWeek(date: DateLike): Date {
92
+ const d = new Date(date);
93
+ const day = d.getDay();
94
+ const diff = d.getDate() - day + 6;
95
+ return new Date(d.setDate(diff));
96
+ }
97
+
98
+ /**
99
+ * Get start of month
100
+ */
101
+ export function startOfMonth(date: DateLike): Date {
102
+ const d = new Date(date);
103
+ return new Date(d.getFullYear(), d.getMonth(), 1);
104
+ }
105
+
106
+ /**
107
+ * Get end of month
108
+ */
109
+ export function endOfMonth(date: DateLike): Date {
110
+ const d = new Date(date);
111
+ return new Date(d.getFullYear(), d.getMonth() + 1, 0);
112
+ }
@@ -1,32 +1,10 @@
1
1
  /**
2
2
  * Date Utilities
3
+ * Re-exports all date utility modules
3
4
  */
4
5
 
5
- /**
6
- * Checks if a date is in the past
7
- */
8
- export function isPast(date: Date | string | number): boolean {
9
- const d = new Date(date);
10
- return d.getTime() < Date.now();
11
- }
12
-
13
- /**
14
- * Converts various timestamp formats to a safe Date object
15
- */
16
- export function toSafeDate(ts: any): Date | null {
17
- if (!ts) return null;
18
- if (typeof ts.toDate === "function") return ts.toDate();
19
- if (ts instanceof Date) return ts;
20
- if (typeof ts === "string" || typeof ts === "number") {
21
- const d = new Date(ts);
22
- return isNaN(d.getTime()) ? null : d;
23
- }
24
- return null;
25
- }
26
-
27
- /**
28
- * Formats a date to ISO string safely
29
- */
30
- export function formatISO(date: Date | null): string | null {
31
- return date ? date.toISOString() : null;
32
- }
6
+ export type { DateLike } from "./dateUtils.core";
7
+ export * from "./dateUtils.core";
8
+ export * from "./dateUtils.compare";
9
+ export * from "./dateUtils.format";
10
+ export * from "./dateUtils.math";