@terreno/ui 57.3.0 → 57.4.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.
Files changed (212) hide show
  1. package/dist/AnnouncementBanner.d.ts +12 -0
  2. package/dist/AnnouncementBanner.js +61 -0
  3. package/dist/AnnouncementBanner.js.map +1 -0
  4. package/dist/AnnouncementNavigator.d.ts +11 -0
  5. package/dist/AnnouncementNavigator.js +189 -0
  6. package/dist/AnnouncementNavigator.js.map +1 -0
  7. package/dist/AnnouncementScreen.d.ts +12 -0
  8. package/dist/AnnouncementScreen.js +28 -0
  9. package/dist/AnnouncementScreen.js.map +1 -0
  10. package/dist/AreaChart.d.ts +5 -0
  11. package/dist/AreaChart.js +69 -0
  12. package/dist/AreaChart.js.map +1 -0
  13. package/dist/BarChart.d.ts +5 -0
  14. package/dist/BarChart.js +89 -0
  15. package/dist/BarChart.js.map +1 -0
  16. package/dist/Button.js +17 -3
  17. package/dist/Button.js.map +1 -1
  18. package/dist/Common.d.ts +96 -0
  19. package/dist/Common.js.map +1 -1
  20. package/dist/DashboardGrid.d.ts +4 -0
  21. package/dist/DashboardGrid.js +38 -0
  22. package/dist/DashboardGrid.js.map +1 -0
  23. package/dist/DataTable.js +83 -11
  24. package/dist/DataTable.js.map +1 -1
  25. package/dist/DonutChart.d.ts +5 -0
  26. package/dist/DonutChart.js +84 -0
  27. package/dist/DonutChart.js.map +1 -0
  28. package/dist/Filter.js +12 -2
  29. package/dist/Filter.js.map +1 -1
  30. package/dist/GPTChat.d.ts +7 -1
  31. package/dist/GPTChat.js +28 -15
  32. package/dist/GPTChat.js.map +1 -1
  33. package/dist/LineChart.d.ts +5 -0
  34. package/dist/LineChart.js +68 -0
  35. package/dist/LineChart.js.map +1 -0
  36. package/dist/MarkdownEmbed.d.ts +6 -0
  37. package/dist/MarkdownEmbed.js +17 -0
  38. package/dist/MarkdownEmbed.js.map +1 -0
  39. package/dist/MarkdownView.js +38 -3
  40. package/dist/MarkdownView.js.map +1 -1
  41. package/dist/Modal.js +12 -10
  42. package/dist/Modal.js.map +1 -1
  43. package/dist/ModalSheet.d.ts +5 -1
  44. package/dist/ModalSheet.js +31 -13
  45. package/dist/ModalSheet.js.map +1 -1
  46. package/dist/MultiselectField.js +4 -9
  47. package/dist/MultiselectField.js.map +1 -1
  48. package/dist/NotificationBell.d.ts +16 -0
  49. package/dist/NotificationBell.js +15 -0
  50. package/dist/NotificationBell.js.map +1 -0
  51. package/dist/NotificationInbox.d.ts +21 -0
  52. package/dist/NotificationInbox.js +41 -0
  53. package/dist/NotificationInbox.js.map +1 -0
  54. package/dist/NotificationPreferences.d.ts +14 -0
  55. package/dist/NotificationPreferences.js +32 -0
  56. package/dist/NotificationPreferences.js.map +1 -0
  57. package/dist/TextField.js +83 -6
  58. package/dist/TextField.js.map +1 -1
  59. package/dist/announcementBuildVersion.d.ts +6 -0
  60. package/dist/announcementBuildVersion.js +21 -0
  61. package/dist/announcementBuildVersion.js.map +1 -0
  62. package/dist/announcementFrequency.d.ts +42 -0
  63. package/dist/announcementFrequency.js +163 -0
  64. package/dist/announcementFrequency.js.map +1 -0
  65. package/dist/announcementPlatform.d.ts +2 -0
  66. package/dist/announcementPlatform.js +11 -0
  67. package/dist/announcementPlatform.js.map +1 -0
  68. package/dist/charts/ChartFrame.d.ts +12 -0
  69. package/dist/charts/ChartFrame.js +13 -0
  70. package/dist/charts/ChartFrame.js.map +1 -0
  71. package/dist/charts/bars.d.ts +18 -0
  72. package/dist/charts/bars.js +29 -0
  73. package/dist/charts/bars.js.map +1 -0
  74. package/dist/charts/layout.d.ts +47 -0
  75. package/dist/charts/layout.js +56 -0
  76. package/dist/charts/layout.js.map +1 -0
  77. package/dist/charts/paths.d.ts +31 -0
  78. package/dist/charts/paths.js +52 -0
  79. package/dist/charts/paths.js.map +1 -0
  80. package/dist/charts/scales.d.ts +6 -0
  81. package/dist/charts/scales.js +43 -0
  82. package/dist/charts/scales.js.map +1 -0
  83. package/dist/charts/theme.d.ts +9 -0
  84. package/dist/charts/theme.js +15 -0
  85. package/dist/charts/theme.js.map +1 -0
  86. package/dist/charts/types/chartTypes.d.ts +17 -0
  87. package/dist/charts/types/chartTypes.js +2 -0
  88. package/dist/charts/types/chartTypes.js.map +1 -0
  89. package/dist/dashboardGridLayout.d.ts +22 -0
  90. package/dist/dashboardGridLayout.js +33 -0
  91. package/dist/dashboardGridLayout.js.map +1 -0
  92. package/dist/dataTableFilters.d.ts +33 -0
  93. package/dist/dataTableFilters.js +221 -0
  94. package/dist/dataTableFilters.js.map +1 -0
  95. package/dist/dataTableListQuery.d.ts +42 -0
  96. package/dist/dataTableListQuery.js +161 -0
  97. package/dist/dataTableListQuery.js.map +1 -0
  98. package/dist/index.d.ts +18 -1
  99. package/dist/index.js +11 -1
  100. package/dist/index.js.map +1 -1
  101. package/dist/lazyBoundaries/heavyOptionalExports.d.ts +12 -0
  102. package/dist/lazyBoundaries/heavyOptionalExports.js +8 -0
  103. package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -1
  104. package/dist/markdownEmbeds.d.ts +6 -0
  105. package/dist/markdownEmbeds.js +59 -0
  106. package/dist/markdownEmbeds.js.map +1 -0
  107. package/dist/testing/resolveTestId.js +2 -1
  108. package/dist/testing/resolveTestId.js.map +1 -1
  109. package/dist/testing/types.d.ts +3 -0
  110. package/dist/textFieldOscillationGuard.d.ts +25 -0
  111. package/dist/textFieldOscillationGuard.js +41 -0
  112. package/dist/textFieldOscillationGuard.js.map +1 -0
  113. package/dist/useAcknowledgeAnnouncement.d.ts +71 -0
  114. package/dist/useAcknowledgeAnnouncement.js +94 -0
  115. package/dist/useAcknowledgeAnnouncement.js.map +1 -0
  116. package/dist/useAnnouncements.d.ts +73 -0
  117. package/dist/useAnnouncements.js +66 -0
  118. package/dist/useAnnouncements.js.map +1 -0
  119. package/package.json +7 -18
  120. package/src/AnnouncementBanner.test.tsx +267 -0
  121. package/src/AnnouncementBanner.tsx +128 -0
  122. package/src/AnnouncementNavigator.test.tsx +759 -0
  123. package/src/AnnouncementNavigator.tsx +287 -0
  124. package/src/AnnouncementScreen.test.tsx +97 -0
  125. package/src/AnnouncementScreen.tsx +70 -0
  126. package/src/AreaChart.test.tsx +68 -0
  127. package/src/AreaChart.tsx +194 -0
  128. package/src/BarChart.test.tsx +96 -0
  129. package/src/BarChart.tsx +208 -0
  130. package/src/Button.test.tsx +66 -0
  131. package/src/Button.tsx +17 -2
  132. package/src/Common.ts +95 -0
  133. package/src/ConsentNavigator.test.tsx +55 -0
  134. package/src/DashboardGrid.test.tsx +75 -0
  135. package/src/DashboardGrid.tsx +69 -0
  136. package/src/DataTable.test.tsx +296 -1
  137. package/src/DataTable.tsx +210 -18
  138. package/src/DonutChart.test.tsx +121 -0
  139. package/src/DonutChart.tsx +160 -0
  140. package/src/EmojiSelector.test.tsx +51 -0
  141. package/src/Field.test.tsx +18 -0
  142. package/src/Filter.test.tsx +25 -0
  143. package/src/Filter.tsx +38 -7
  144. package/src/GPTChat.test.tsx +107 -0
  145. package/src/GPTChat.tsx +176 -86
  146. package/src/LineChart.test.tsx +166 -0
  147. package/src/LineChart.tsx +190 -0
  148. package/src/MarkdownEmbed.test.tsx +34 -0
  149. package/src/MarkdownEmbed.tsx +43 -0
  150. package/src/MarkdownView.test.tsx +59 -2
  151. package/src/MarkdownView.tsx +51 -3
  152. package/src/Modal.test.tsx +107 -14
  153. package/src/Modal.tsx +20 -8
  154. package/src/ModalSheet.test.tsx +121 -9
  155. package/src/ModalSheet.tsx +46 -11
  156. package/src/MultiselectField.test.tsx +21 -0
  157. package/src/MultiselectField.tsx +11 -13
  158. package/src/NotificationBell.test.tsx +91 -0
  159. package/src/NotificationBell.tsx +77 -0
  160. package/src/NotificationInbox.test.tsx +130 -0
  161. package/src/NotificationInbox.tsx +144 -0
  162. package/src/NotificationPreferences.test.tsx +25 -0
  163. package/src/NotificationPreferences.tsx +75 -0
  164. package/src/RootImportRegression.test.tsx +20 -0
  165. package/src/TextField.test.tsx +421 -0
  166. package/src/TextField.tsx +121 -4
  167. package/src/__snapshots__/Field.test.tsx.snap +22 -0
  168. package/src/__snapshots__/ModalSheet.test.tsx.snap +4 -1
  169. package/src/__snapshots__/TextArea.test.tsx.snap +5 -5
  170. package/src/__snapshots__/TextField.test.tsx.snap +5 -5
  171. package/src/announcementBuildVersion.test.ts +43 -0
  172. package/src/announcementBuildVersion.ts +21 -0
  173. package/src/announcementFrequency.test.ts +245 -0
  174. package/src/announcementFrequency.ts +246 -0
  175. package/src/announcementPlatform.test.ts +27 -0
  176. package/src/announcementPlatform.ts +13 -0
  177. package/src/charts/ChartFrame.tsx +67 -0
  178. package/src/charts/bars.test.ts +56 -0
  179. package/src/charts/bars.ts +53 -0
  180. package/src/charts/layout.test.ts +80 -0
  181. package/src/charts/layout.ts +99 -0
  182. package/src/charts/paths.test.ts +79 -0
  183. package/src/charts/paths.ts +100 -0
  184. package/src/charts/scales.test.ts +59 -0
  185. package/src/charts/scales.ts +60 -0
  186. package/src/charts/theme.test.ts +22 -0
  187. package/src/charts/theme.ts +24 -0
  188. package/src/charts/types/chartTypes.ts +19 -0
  189. package/src/dashboardGridLayout.test.ts +90 -0
  190. package/src/dashboardGridLayout.ts +60 -0
  191. package/src/dataTableFilters.test.tsx +552 -0
  192. package/src/dataTableFilters.tsx +441 -0
  193. package/src/dataTableListQuery.test.ts +220 -0
  194. package/src/dataTableListQuery.ts +201 -0
  195. package/src/index.tsx +21 -1
  196. package/src/lazyBoundaries/heavyOptionalExports.tsx +28 -0
  197. package/src/login/__snapshots__/LoginScreen.test.tsx.snap +22 -0
  198. package/src/markdownEmbeds.test.ts +53 -0
  199. package/src/markdownEmbeds.ts +62 -0
  200. package/src/pdfHtmlTemplate.test.ts +119 -0
  201. package/src/signUp/__snapshots__/SignUpScreen.test.tsx.snap +22 -0
  202. package/src/testing/resolveTestId.test.ts +3 -0
  203. package/src/testing/resolveTestId.ts +1 -0
  204. package/src/testing/types.ts +3 -0
  205. package/src/textFieldOscillationGuard.test.ts +63 -0
  206. package/src/textFieldOscillationGuard.ts +89 -0
  207. package/src/types/react-native-markdown-display.d.ts +6 -0
  208. package/src/types/react-native-swiper-flatlist.d.ts +5 -5
  209. package/src/useAcknowledgeAnnouncement.test.ts +223 -0
  210. package/src/useAcknowledgeAnnouncement.ts +166 -0
  211. package/src/useAnnouncements.test.ts +226 -0
  212. package/src/useAnnouncements.ts +150 -0
@@ -28,7 +28,7 @@ exports[`TextArea snapshots should match snapshot with default props 1`] = `
28
28
  "nativeID": undefined,
29
29
  "numberOfLines": 1,
30
30
  "onBlur": [Function],
31
- "onChangeText": [class Function],
31
+ "onChangeText": [Function],
32
32
  "onContentSizeChange": [Function],
33
33
  "onFocus": [Function],
34
34
  "onSubmitEditing": [Function],
@@ -136,7 +136,7 @@ exports[`TextArea snapshots should match snapshot with all props 1`] = `
136
136
  "nativeID": undefined,
137
137
  "numberOfLines": 5,
138
138
  "onBlur": [Function],
139
- "onChangeText": [class Function],
139
+ "onChangeText": [Function],
140
140
  "onContentSizeChange": [Function],
141
141
  "onFocus": [Function],
142
142
  "onSubmitEditing": [Function],
@@ -273,7 +273,7 @@ exports[`TextArea snapshots should match snapshot when disabled 1`] = `
273
273
  "nativeID": undefined,
274
274
  "numberOfLines": 1,
275
275
  "onBlur": [Function],
276
- "onChangeText": [class Function],
276
+ "onChangeText": [Function],
277
277
  "onContentSizeChange": [Function],
278
278
  "onFocus": [Function],
279
279
  "onSubmitEditing": [Function],
@@ -420,7 +420,7 @@ exports[`TextArea snapshots should match snapshot with error state 1`] = `
420
420
  "nativeID": undefined,
421
421
  "numberOfLines": 1,
422
422
  "onBlur": [Function],
423
- "onChangeText": [class Function],
423
+ "onChangeText": [Function],
424
424
  "onContentSizeChange": [Function],
425
425
  "onFocus": [Function],
426
426
  "onSubmitEditing": [Function],
@@ -528,7 +528,7 @@ exports[`TextArea snapshots should match snapshot with multiline content 1`] = `
528
528
  "nativeID": undefined,
529
529
  "numberOfLines": 4,
530
530
  "onBlur": [Function],
531
- "onChangeText": [class Function],
531
+ "onChangeText": [Function],
532
532
  "onContentSizeChange": [Function],
533
533
  "onFocus": [Function],
534
534
  "onSubmitEditing": [Function],
@@ -28,7 +28,7 @@ exports[`TextField snapshots should match snapshot with default props 1`] = `
28
28
  "nativeID": undefined,
29
29
  "numberOfLines": 1,
30
30
  "onBlur": [Function],
31
- "onChangeText": [class Function],
31
+ "onChangeText": [Function],
32
32
  "onContentSizeChange": [Function],
33
33
  "onFocus": [Function],
34
34
  "onSubmitEditing": [Function],
@@ -175,7 +175,7 @@ exports[`TextField snapshots should match snapshot with all props 1`] = `
175
175
  "nativeID": undefined,
176
176
  "numberOfLines": 1,
177
177
  "onBlur": [Function],
178
- "onChangeText": [class Function],
178
+ "onChangeText": [Function],
179
179
  "onContentSizeChange": [Function],
180
180
  "onFocus": [Function],
181
181
  "onSubmitEditing": [Function],
@@ -321,7 +321,7 @@ exports[`TextField snapshots should match snapshot when disabled 1`] = `
321
321
  "nativeID": undefined,
322
322
  "numberOfLines": 1,
323
323
  "onBlur": [Function],
324
- "onChangeText": [class Function],
324
+ "onChangeText": [Function],
325
325
  "onContentSizeChange": [Function],
326
326
  "onFocus": [Function],
327
327
  "onSubmitEditing": [Function],
@@ -429,7 +429,7 @@ exports[`TextField snapshots should match snapshot with multiline 1`] = `
429
429
  "nativeID": undefined,
430
430
  "numberOfLines": 3,
431
431
  "onBlur": [Function],
432
- "onChangeText": [class Function],
432
+ "onChangeText": [Function],
433
433
  "onContentSizeChange": [Function],
434
434
  "onFocus": [Function],
435
435
  "onSubmitEditing": [Function],
@@ -576,7 +576,7 @@ exports[`TextField snapshots should match snapshot with error state 1`] = `
576
576
  "nativeID": undefined,
577
577
  "numberOfLines": 1,
578
578
  "onBlur": [Function],
579
- "onChangeText": [class Function],
579
+ "onChangeText": [Function],
580
580
  "onContentSizeChange": [Function],
581
581
  "onFocus": [Function],
582
582
  "onSubmitEditing": [Function],
@@ -0,0 +1,43 @@
1
+ import {afterEach, describe, it, mock} from "bun:test";
2
+ import {assert} from "chai";
3
+
4
+ const constantsState = {
5
+ expoConfig: {
6
+ extra: {
7
+ buildNumber: undefined as number | string | undefined,
8
+ },
9
+ },
10
+ };
11
+
12
+ mock.module("expo-constants", () => ({
13
+ default: constantsState,
14
+ }));
15
+
16
+ const {getAnnouncementBuildVersion} = await import("./announcementBuildVersion");
17
+
18
+ describe("getAnnouncementBuildVersion", () => {
19
+ afterEach(() => {
20
+ constantsState.expoConfig.extra.buildNumber = undefined;
21
+ });
22
+
23
+ it("returns a finite integer build number from Expo config", () => {
24
+ constantsState.expoConfig.extra.buildNumber = 42;
25
+ assert.strictEqual(getAnnouncementBuildVersion(), 42);
26
+ });
27
+
28
+ it("coerces string build numbers to integers", () => {
29
+ constantsState.expoConfig.extra.buildNumber = "17";
30
+ assert.strictEqual(getAnnouncementBuildVersion(), 17);
31
+ });
32
+
33
+ it("omits invalid or missing build numbers", () => {
34
+ constantsState.expoConfig.extra.buildNumber = undefined;
35
+ assert.isUndefined(getAnnouncementBuildVersion());
36
+
37
+ constantsState.expoConfig.extra.buildNumber = "not-a-number";
38
+ assert.isUndefined(getAnnouncementBuildVersion());
39
+
40
+ constantsState.expoConfig.extra.buildNumber = Number.NaN;
41
+ assert.isUndefined(getAnnouncementBuildVersion());
42
+ });
43
+ });
@@ -0,0 +1,21 @@
1
+ import Constants from "expo-constants";
2
+
3
+ const coerceBuildNumber = (value: unknown): number | undefined => {
4
+ if (value === undefined || value === null) {
5
+ return undefined;
6
+ }
7
+ const parsed = typeof value === "number" ? value : Number.parseInt(String(value), 10);
8
+ if (!Number.isFinite(parsed) || !Number.isInteger(parsed)) {
9
+ return undefined;
10
+ }
11
+ return parsed;
12
+ };
13
+
14
+ /**
15
+ * Returns the running app's build number from Expo config, matching
16
+ * `useUpgradeCheck` / `Constants.expoConfig.extra.buildNumber`.
17
+ * Omits the value when missing or not a finite integer.
18
+ */
19
+ export const getAnnouncementBuildVersion = (): number | undefined => {
20
+ return coerceBuildNumber(Constants.expoConfig?.extra?.buildNumber);
21
+ };
@@ -0,0 +1,245 @@
1
+ import {beforeEach, describe, it} from "bun:test";
2
+ import {assert} from "chai";
3
+ import {DateTime} from "luxon";
4
+
5
+ import {
6
+ type AnnouncementFrequencyDeps,
7
+ buildFrequencyStorageKey,
8
+ createFrequencySessionState,
9
+ type FrequencyStorage,
10
+ getFrequencyStorageNamespace,
11
+ recordInterruptShown,
12
+ resetFrequencySessionStateForTests,
13
+ resolveFrequencyConfig,
14
+ shouldSuppressInterrupt,
15
+ } from "./announcementFrequency";
16
+
17
+ const createMemoryStorage = (initial: Record<string, string> = {}): FrequencyStorage => {
18
+ const store = new Map<string, string>(Object.entries(initial));
19
+ return {
20
+ getItem: async (key: string): Promise<string | null> => {
21
+ return store.get(key) ?? null;
22
+ },
23
+ setItem: async (key: string, value: string): Promise<void> => {
24
+ store.set(key, value);
25
+ },
26
+ };
27
+ };
28
+
29
+ const createDeps = (
30
+ overrides: Partial<AnnouncementFrequencyDeps> & {storage?: FrequencyStorage} = {}
31
+ ): AnnouncementFrequencyDeps => {
32
+ const session = overrides.session ?? createFrequencySessionState();
33
+ const storage = overrides.storage ?? createMemoryStorage();
34
+ const clock = overrides.clock ?? {
35
+ now: (): DateTime => DateTime.fromISO("2026-09-15T12:00:00.000Z", {zone: "utc"}),
36
+ };
37
+ const warnings: Array<{message: string; details?: unknown}> = [];
38
+ const warn =
39
+ overrides.warn ??
40
+ ((message: string, details?: unknown): void => {
41
+ warnings.push({details, message});
42
+ });
43
+ return {clock, session, storage, warn, ...overrides};
44
+ };
45
+
46
+ describe("announcementFrequency", () => {
47
+ beforeEach(() => {
48
+ resetFrequencySessionStateForTests();
49
+ });
50
+
51
+ describe("resolveFrequencyConfig", () => {
52
+ it("defaults maxInterruptionsPerSession to 1, cooldown off, and skipFirstLaunch false", () => {
53
+ const resolved = resolveFrequencyConfig();
54
+ assert.strictEqual(resolved.maxInterruptionsPerSession, 1);
55
+ assert.isUndefined(resolved.cooldownHours);
56
+ assert.strictEqual(resolved.skipFirstLaunch, false);
57
+ assert.isUndefined(resolved.userId);
58
+ });
59
+ });
60
+
61
+ describe("getFrequencyStorageNamespace", () => {
62
+ it("uses anon when userId is omitted", () => {
63
+ assert.strictEqual(getFrequencyStorageNamespace(), "anon");
64
+ assert.strictEqual(getFrequencyStorageNamespace(undefined), "anon");
65
+ });
66
+
67
+ it("uses the provided userId for namespacing", () => {
68
+ assert.strictEqual(getFrequencyStorageNamespace("user-123"), "user-123");
69
+ });
70
+ });
71
+
72
+ describe("shouldSuppressInterrupt", () => {
73
+ it("suppresses when the session cap is reached", async () => {
74
+ const deps = createDeps();
75
+ const config = {maxInterruptionsPerSession: 1};
76
+
77
+ await recordInterruptShown(config, "announcement-1:1", deps);
78
+ const suppress = await shouldSuppressInterrupt(config, "announcement-2:1", deps);
79
+
80
+ assert.strictEqual(suppress, true);
81
+ });
82
+
83
+ it("allows another interrupt when maxInterruptionsPerSession is higher", async () => {
84
+ const deps = createDeps();
85
+ const config = {maxInterruptionsPerSession: 2};
86
+
87
+ await recordInterruptShown(config, "announcement-1:1", deps);
88
+ const suppress = await shouldSuppressInterrupt(config, "announcement-2:1", deps);
89
+
90
+ assert.strictEqual(suppress, false);
91
+ });
92
+
93
+ it("skips interrupts on first launch when skipFirstLaunch is true", async () => {
94
+ const deps = createDeps();
95
+ const config = {skipFirstLaunch: true, userId: "user-a"};
96
+
97
+ const suppress = await shouldSuppressInterrupt(config, "announcement-1:1", deps);
98
+
99
+ assert.strictEqual(suppress, true);
100
+ const hasLaunchedKey = buildFrequencyStorageKey("user-a", "hasLaunched");
101
+ assert.strictEqual(await deps.storage?.getItem(hasLaunchedKey), "true");
102
+ });
103
+
104
+ it("shows interrupts on subsequent launches after skipFirstLaunch stored hasLaunched", async () => {
105
+ const deps = createDeps({
106
+ storage: createMemoryStorage({
107
+ [buildFrequencyStorageKey("user-a", "hasLaunched")]: "true",
108
+ }),
109
+ });
110
+ const config = {skipFirstLaunch: true, userId: "user-a"};
111
+
112
+ const suppress = await shouldSuppressInterrupt(config, "announcement-1:1", deps);
113
+
114
+ assert.strictEqual(suppress, false);
115
+ });
116
+
117
+ it("keeps skipping for the rest of the session after first-launch skip", async () => {
118
+ const deps = createDeps();
119
+ const config = {skipFirstLaunch: true};
120
+
121
+ const firstCheck = await shouldSuppressInterrupt(config, "announcement-1:1", deps);
122
+ const secondCheck = await shouldSuppressInterrupt(config, "announcement-2:1", deps);
123
+
124
+ assert.strictEqual(firstCheck, true);
125
+ assert.strictEqual(secondCheck, true);
126
+ });
127
+
128
+ it("suppresses when last interrupt is inside the cooldown window", async () => {
129
+ const deps = createDeps({
130
+ storage: createMemoryStorage({
131
+ [buildFrequencyStorageKey("anon", "lastInterruptAt")]: "2026-09-15T10:00:00.000Z",
132
+ }),
133
+ });
134
+ const config = {cooldownHours: 24};
135
+
136
+ const suppress = await shouldSuppressInterrupt(config, "announcement-1:1", deps);
137
+
138
+ assert.strictEqual(suppress, true);
139
+ });
140
+
141
+ it("allows interrupts after the cooldown window elapses", async () => {
142
+ const deps = createDeps({
143
+ storage: createMemoryStorage({
144
+ [buildFrequencyStorageKey("anon", "lastInterruptAt")]: "2026-09-14T11:00:00.000Z",
145
+ }),
146
+ });
147
+ const config = {cooldownHours: 24};
148
+
149
+ const suppress = await shouldSuppressInterrupt(config, "announcement-1:1", deps);
150
+
151
+ assert.strictEqual(suppress, false);
152
+ });
153
+
154
+ it("fails open when hasLaunched setItem is rejected without activating session skip", async () => {
155
+ const session = createFrequencySessionState();
156
+ const warnings: Array<{message: string; details?: unknown}> = [];
157
+ const deps = createDeps({
158
+ session,
159
+ storage: {
160
+ getItem: async (): Promise<string | null> => null,
161
+ setItem: async (): Promise<void> => {
162
+ throw new Error("storage write failed");
163
+ },
164
+ },
165
+ warn: (message: string, details?: unknown): void => {
166
+ warnings.push({details, message});
167
+ },
168
+ });
169
+ const config = {skipFirstLaunch: true, userId: "user-a"};
170
+
171
+ const suppress = await shouldSuppressInterrupt(config, "announcement-1:1", deps);
172
+ const secondSuppress = await shouldSuppressInterrupt(config, "announcement-2:1", deps);
173
+
174
+ assert.strictEqual(suppress, false);
175
+ assert.strictEqual(secondSuppress, false);
176
+ assert.strictEqual(session.isFirstLaunchSkipActive(), false);
177
+ assert.isTrue(warnings.some((entry) => entry.message.includes("hasLaunched")));
178
+ });
179
+
180
+ it("fails open when storage reads fail", async () => {
181
+ const warnings: Array<{message: string; details?: unknown}> = [];
182
+ const deps = createDeps({
183
+ storage: {
184
+ getItem: async (): Promise<string | null> => {
185
+ throw new Error("storage read failed");
186
+ },
187
+ setItem: async (): Promise<void> => {
188
+ throw new Error("storage write failed");
189
+ },
190
+ },
191
+ warn: (message: string, details?: unknown): void => {
192
+ warnings.push({details, message});
193
+ },
194
+ });
195
+ const config = {cooldownHours: 24, skipFirstLaunch: true};
196
+
197
+ const suppress = await shouldSuppressInterrupt(config, "announcement-1:1", deps);
198
+
199
+ assert.strictEqual(suppress, false);
200
+ assert.isAtLeast(warnings.length, 1);
201
+ });
202
+ });
203
+
204
+ describe("recordInterruptShown", () => {
205
+ it("increments the session counter exactly once per announcement id:version", async () => {
206
+ const deps = createDeps();
207
+ const config = {maxInterruptionsPerSession: 2};
208
+
209
+ await recordInterruptShown(config, "announcement-1:1", deps);
210
+ await recordInterruptShown(config, "announcement-1:1", deps);
211
+
212
+ assert.strictEqual(deps.session?.getInterruptionCount(), 1);
213
+ });
214
+
215
+ it("persists lastInterruptAt when an interrupt becomes visible", async () => {
216
+ const deps = createDeps();
217
+ const config = {userId: "user-b"};
218
+
219
+ await recordInterruptShown(config, "announcement-1:2", deps);
220
+
221
+ const lastKey = buildFrequencyStorageKey("user-b", "lastInterruptAt");
222
+ assert.strictEqual(await deps.storage?.getItem(lastKey), "2026-09-15T12:00:00.000Z");
223
+ });
224
+
225
+ it("warns but does not throw when storage writes fail", async () => {
226
+ const warnings: Array<{message: string; details?: unknown}> = [];
227
+ const deps = createDeps({
228
+ storage: {
229
+ getItem: async (): Promise<string | null> => null,
230
+ setItem: async (): Promise<void> => {
231
+ throw new Error("storage write failed");
232
+ },
233
+ },
234
+ warn: (message: string, details?: unknown): void => {
235
+ warnings.push({details, message});
236
+ },
237
+ });
238
+
239
+ await recordInterruptShown({}, "announcement-1:1", deps);
240
+
241
+ assert.strictEqual(deps.session?.getInterruptionCount(), 1);
242
+ assert.isTrue(warnings.some((entry) => entry.message.includes("lastInterruptAt")));
243
+ });
244
+ });
245
+ });
@@ -0,0 +1,246 @@
1
+ import {DateTime} from "luxon";
2
+
3
+ import {Unifier} from "./Unifier";
4
+
5
+ export interface AnnouncementFrequencyConfig {
6
+ cooldownHours?: number;
7
+ maxInterruptionsPerSession?: number;
8
+ skipFirstLaunch?: boolean;
9
+ userId?: string;
10
+ }
11
+
12
+ export interface ResolvedAnnouncementFrequencyConfig {
13
+ cooldownHours?: number;
14
+ maxInterruptionsPerSession: number;
15
+ skipFirstLaunch: boolean;
16
+ userId?: string;
17
+ }
18
+
19
+ export interface FrequencyStorage {
20
+ getItem: (key: string) => Promise<string | null>;
21
+ setItem: (key: string, value: string) => Promise<void>;
22
+ }
23
+
24
+ export interface FrequencyClock {
25
+ now: () => DateTime;
26
+ }
27
+
28
+ export interface FrequencySessionState {
29
+ getInterruptionCount: () => number;
30
+ hasRecordedInterruptKey: (key: string) => boolean;
31
+ incrementInterruptionCount: () => void;
32
+ isFirstLaunchSkipActive: () => boolean;
33
+ markRecordedInterruptKey: (key: string) => void;
34
+ setFirstLaunchSkipActive: (active: boolean) => void;
35
+ }
36
+
37
+ export interface AnnouncementFrequencyDeps {
38
+ clock?: FrequencyClock;
39
+ session?: FrequencySessionState;
40
+ storage?: FrequencyStorage;
41
+ warn?: (message: string, details?: unknown) => void;
42
+ }
43
+
44
+ const STORAGE_KEY_PREFIX = "terreno:announcements:frequency";
45
+
46
+ export const getFrequencyStorageNamespace = (userId?: string): string => {
47
+ return userId ?? "anon";
48
+ };
49
+
50
+ export const buildFrequencyStorageKey = (
51
+ namespace: string,
52
+ suffix: "hasLaunched" | "lastInterruptAt"
53
+ ): string => {
54
+ return `${STORAGE_KEY_PREFIX}:${namespace}:${suffix}`;
55
+ };
56
+
57
+ export const resolveFrequencyConfig = (
58
+ config?: AnnouncementFrequencyConfig
59
+ ): ResolvedAnnouncementFrequencyConfig => ({
60
+ cooldownHours: config?.cooldownHours,
61
+ maxInterruptionsPerSession: config?.maxInterruptionsPerSession ?? 1,
62
+ skipFirstLaunch: config?.skipFirstLaunch ?? false,
63
+ userId: config?.userId,
64
+ });
65
+
66
+ export const createFrequencySessionState = (): FrequencySessionState => {
67
+ let interruptionCount = 0;
68
+ let firstLaunchSkipActive = false;
69
+ const recordedInterruptKeys = new Set<string>();
70
+
71
+ return {
72
+ getInterruptionCount: (): number => interruptionCount,
73
+ hasRecordedInterruptKey: (key: string): boolean => recordedInterruptKeys.has(key),
74
+ incrementInterruptionCount: (): void => {
75
+ interruptionCount += 1;
76
+ },
77
+ isFirstLaunchSkipActive: (): boolean => firstLaunchSkipActive,
78
+ markRecordedInterruptKey: (key: string): void => {
79
+ recordedInterruptKeys.add(key);
80
+ },
81
+ setFirstLaunchSkipActive: (active: boolean): void => {
82
+ firstLaunchSkipActive = active;
83
+ },
84
+ };
85
+ };
86
+
87
+ let moduleSessionState: FrequencySessionState | undefined;
88
+
89
+ export const getFrequencySessionState = (
90
+ override?: FrequencySessionState
91
+ ): FrequencySessionState => {
92
+ if (override) {
93
+ return override;
94
+ }
95
+ if (!moduleSessionState) {
96
+ moduleSessionState = createFrequencySessionState();
97
+ }
98
+ return moduleSessionState;
99
+ };
100
+
101
+ export const resetFrequencySessionStateForTests = (): void => {
102
+ moduleSessionState = undefined;
103
+ };
104
+
105
+ const defaultWarn = (message: string, details?: unknown): void => {
106
+ console.warn(message, details);
107
+ };
108
+
109
+ const defaultClock = (): FrequencyClock => ({
110
+ now: (): DateTime => DateTime.now(),
111
+ });
112
+
113
+ const createAsyncStorageAdapter = (): FrequencyStorage => ({
114
+ getItem: async (key: string): Promise<string | null> => {
115
+ const value = await Unifier.storage.getItem(key);
116
+ if (value === null || value === undefined) {
117
+ return null;
118
+ }
119
+ return typeof value === "string" ? value : String(value);
120
+ },
121
+ setItem: async (key: string, value: string): Promise<void> => {
122
+ await Unifier.storage.setItem(key, value);
123
+ },
124
+ });
125
+
126
+ const readHasLaunched = async (
127
+ storage: FrequencyStorage,
128
+ namespace: string,
129
+ warn: (message: string, details?: unknown) => void
130
+ ): Promise<boolean | null> => {
131
+ const key = buildFrequencyStorageKey(namespace, "hasLaunched");
132
+ try {
133
+ const value = await storage.getItem(key);
134
+ return value !== null;
135
+ } catch (error) {
136
+ warn("[announcementFrequency] Failed to read hasLaunched; allowing interrupt", {error});
137
+ return null;
138
+ }
139
+ };
140
+
141
+ const writeHasLaunched = async (
142
+ storage: FrequencyStorage,
143
+ namespace: string,
144
+ warn: (message: string, details?: unknown) => void
145
+ ): Promise<boolean> => {
146
+ const key = buildFrequencyStorageKey(namespace, "hasLaunched");
147
+ try {
148
+ await storage.setItem(key, "true");
149
+ return true;
150
+ } catch (error) {
151
+ warn("[announcementFrequency] Failed to persist hasLaunched", {error});
152
+ return false;
153
+ }
154
+ };
155
+
156
+ const isInsideCooldown = (
157
+ lastInterruptAt: string,
158
+ cooldownHours: number,
159
+ clock: FrequencyClock
160
+ ): boolean => {
161
+ const lastShown = DateTime.fromISO(lastInterruptAt);
162
+ if (!lastShown.isValid) {
163
+ return false;
164
+ }
165
+ const hoursSince = clock.now().diff(lastShown, "hours").hours;
166
+ return hoursSince < cooldownHours;
167
+ };
168
+
169
+ export const shouldSuppressInterrupt = async (
170
+ config: AnnouncementFrequencyConfig | undefined,
171
+ _announcementKey: string,
172
+ deps?: AnnouncementFrequencyDeps
173
+ ): Promise<boolean> => {
174
+ const resolved = resolveFrequencyConfig(config);
175
+ const session = getFrequencySessionState(deps?.session);
176
+ const warn = deps?.warn ?? defaultWarn;
177
+ const storage = deps?.storage ?? createAsyncStorageAdapter();
178
+ const clock = deps?.clock ?? defaultClock();
179
+ const namespace = getFrequencyStorageNamespace(resolved.userId);
180
+
181
+ if (session.getInterruptionCount() >= resolved.maxInterruptionsPerSession) {
182
+ return true;
183
+ }
184
+
185
+ if (resolved.skipFirstLaunch) {
186
+ if (session.isFirstLaunchSkipActive()) {
187
+ return true;
188
+ }
189
+
190
+ const hasLaunched = await readHasLaunched(storage, namespace, warn);
191
+ if (hasLaunched === false) {
192
+ const persisted = await writeHasLaunched(storage, namespace, warn);
193
+ if (persisted) {
194
+ session.setFirstLaunchSkipActive(true);
195
+ return true;
196
+ }
197
+ }
198
+ }
199
+
200
+ if (resolved.cooldownHours !== undefined && resolved.cooldownHours > 0) {
201
+ const lastKey = buildFrequencyStorageKey(namespace, "lastInterruptAt");
202
+ try {
203
+ const lastInterruptAt = await storage.getItem(lastKey);
204
+ if (lastInterruptAt && isInsideCooldown(lastInterruptAt, resolved.cooldownHours, clock)) {
205
+ return true;
206
+ }
207
+ } catch (error) {
208
+ warn("[announcementFrequency] Failed to read lastInterruptAt; allowing interrupt", {error});
209
+ }
210
+ }
211
+
212
+ return false;
213
+ };
214
+
215
+ export const recordInterruptShown = async (
216
+ config: AnnouncementFrequencyConfig | undefined,
217
+ announcementKey: string,
218
+ deps?: AnnouncementFrequencyDeps
219
+ ): Promise<void> => {
220
+ const resolved = resolveFrequencyConfig(config);
221
+ const session = getFrequencySessionState(deps?.session);
222
+ const warn = deps?.warn ?? defaultWarn;
223
+ const storage = deps?.storage ?? createAsyncStorageAdapter();
224
+ const clock = deps?.clock ?? defaultClock();
225
+ const namespace = getFrequencyStorageNamespace(resolved.userId);
226
+
227
+ if (session.hasRecordedInterruptKey(announcementKey)) {
228
+ return;
229
+ }
230
+
231
+ session.markRecordedInterruptKey(announcementKey);
232
+ session.incrementInterruptionCount();
233
+
234
+ const iso = clock.now().toISO();
235
+ if (!iso) {
236
+ warn("[announcementFrequency] Failed to serialize interrupt timestamp");
237
+ return;
238
+ }
239
+
240
+ const lastKey = buildFrequencyStorageKey(namespace, "lastInterruptAt");
241
+ try {
242
+ await storage.setItem(lastKey, iso);
243
+ } catch (error) {
244
+ warn("[announcementFrequency] Failed to persist lastInterruptAt", {error});
245
+ }
246
+ };
@@ -0,0 +1,27 @@
1
+ import {afterEach, describe, expect, it} from "bun:test";
2
+ import {Platform} from "react-native";
3
+
4
+ import {getAnnouncementPlatform} from "./announcementPlatform";
5
+
6
+ describe("getAnnouncementPlatform", () => {
7
+ const originalOS = Platform.OS;
8
+
9
+ afterEach(() => {
10
+ Platform.OS = originalOS;
11
+ });
12
+
13
+ it("returns ios on iOS clients", () => {
14
+ Platform.OS = "ios";
15
+ expect(getAnnouncementPlatform()).toBe("ios");
16
+ });
17
+
18
+ it("returns android on Android clients", () => {
19
+ Platform.OS = "android";
20
+ expect(getAnnouncementPlatform()).toBe("android");
21
+ });
22
+
23
+ it("returns web on other platforms", () => {
24
+ Platform.OS = "web";
25
+ expect(getAnnouncementPlatform()).toBe("web");
26
+ });
27
+ });
@@ -0,0 +1,13 @@
1
+ import {Platform} from "react-native";
2
+
3
+ export type AnnouncementPlatform = "android" | "ios" | "web";
4
+
5
+ export const getAnnouncementPlatform = (): AnnouncementPlatform => {
6
+ if (Platform.OS === "ios") {
7
+ return "ios";
8
+ }
9
+ if (Platform.OS === "android") {
10
+ return "android";
11
+ }
12
+ return "web";
13
+ };