flowgrid-sdk 1.2.1 → 1.4.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 (312) hide show
  1. package/README.md +221 -250
  2. package/dist/237.flowgrid.min.js +2 -0
  3. package/dist/237.flowgrid.min.js.map +1 -0
  4. package/dist/546.flowgrid.min.js +3 -0
  5. package/dist/546.flowgrid.min.js.LICENSE.txt +14 -0
  6. package/dist/546.flowgrid.min.js.map +1 -0
  7. package/dist/EXAMPLE.d.ts +1 -0
  8. package/dist/EXAMPLE.js +55 -0
  9. package/dist/EXAMPLE.js.map +1 -0
  10. package/dist/browser.d.ts +46 -103
  11. package/dist/browser.js +102 -0
  12. package/dist/browser.js.map +1 -0
  13. package/dist/flowgrid.min.js +1 -1
  14. package/dist/flowgrid.min.js.map +1 -1
  15. package/dist/index.d.ts +7 -8
  16. package/dist/index.js +64 -1
  17. package/dist/index.js.map +1 -1
  18. package/dist/lib/client/transport.d.ts +14 -4
  19. package/dist/lib/client/transport.js +432 -0
  20. package/dist/lib/client/transport.js.map +1 -0
  21. package/dist/lib/consent/index.d.ts +0 -5
  22. package/dist/lib/consent/index.js +32 -0
  23. package/dist/lib/consent/index.js.map +1 -0
  24. package/dist/lib/consent/manager.js +336 -0
  25. package/dist/lib/consent/manager.js.map +1 -0
  26. package/dist/lib/consent/types.d.ts +3 -20
  27. package/dist/lib/consent/types.js +10 -0
  28. package/dist/lib/consent/types.js.map +1 -0
  29. package/dist/lib/features/analytics/attribution.d.ts +6 -47
  30. package/dist/lib/features/analytics/attribution.js +181 -0
  31. package/dist/lib/features/analytics/attribution.js.map +1 -0
  32. package/dist/lib/features/analytics/events.d.ts +1 -28
  33. package/dist/lib/features/analytics/events.js +256 -0
  34. package/dist/lib/features/analytics/events.js.map +1 -0
  35. package/dist/lib/features/analytics/funnels.js +260 -0
  36. package/dist/lib/features/analytics/funnels.js.map +1 -0
  37. package/dist/lib/features/analytics/heatmaps.d.ts +12 -19
  38. package/dist/lib/features/analytics/heatmaps.js +258 -0
  39. package/dist/lib/features/analytics/heatmaps.js.map +1 -0
  40. package/dist/lib/features/analytics/identify.d.ts +1 -21
  41. package/dist/lib/features/analytics/identify.js +213 -0
  42. package/dist/lib/features/analytics/identify.js.map +1 -0
  43. package/dist/lib/features/analytics/index.d.ts +2 -0
  44. package/dist/lib/features/analytics/index.js +15 -0
  45. package/dist/lib/features/analytics/index.js.map +1 -0
  46. package/dist/lib/features/analytics/page-views.d.ts +13 -30
  47. package/dist/lib/features/analytics/page-views.js +268 -0
  48. package/dist/lib/features/analytics/page-views.js.map +1 -0
  49. package/dist/lib/features/analytics/performance.d.ts +18 -24
  50. package/dist/lib/features/analytics/performance.js +232 -0
  51. package/dist/lib/features/analytics/performance.js.map +1 -0
  52. package/dist/lib/features/analytics/replay.d.ts +170 -0
  53. package/dist/lib/features/analytics/replay.js +381 -0
  54. package/dist/lib/features/analytics/replay.js.map +1 -0
  55. package/dist/lib/features/analytics/retention.d.ts +1 -76
  56. package/dist/lib/features/analytics/retention.js +135 -0
  57. package/dist/lib/features/analytics/retention.js.map +1 -0
  58. package/dist/lib/features/analytics/sessions.d.ts +12 -37
  59. package/dist/lib/features/analytics/sessions.js +213 -0
  60. package/dist/lib/features/analytics/sessions.js.map +1 -0
  61. package/dist/lib/features/core/activation.d.ts +1 -24
  62. package/dist/lib/features/core/activation.js +175 -0
  63. package/dist/lib/features/core/activation.js.map +1 -0
  64. package/dist/lib/features/core/experiment.d.ts +53 -21
  65. package/dist/lib/features/core/experiment.js +554 -0
  66. package/dist/lib/features/core/experiment.js.map +1 -0
  67. package/dist/lib/features/core/index.js +9 -0
  68. package/dist/lib/features/core/index.js.map +1 -0
  69. package/dist/lib/features/core/track-feature.d.ts +1 -8
  70. package/dist/lib/features/core/track-feature.js +119 -0
  71. package/dist/lib/features/core/track-feature.js.map +1 -0
  72. package/dist/lib/features/core/track-prompt.d.ts +5 -8
  73. package/dist/lib/features/core/track-prompt.js +181 -0
  74. package/dist/lib/features/core/track-prompt.js.map +1 -0
  75. package/dist/lib/features/ecommerce/cart.d.ts +1 -24
  76. package/dist/lib/features/ecommerce/cart.js +244 -0
  77. package/dist/lib/features/ecommerce/cart.js.map +1 -0
  78. package/dist/lib/features/ecommerce/checkout.d.ts +1 -28
  79. package/dist/lib/features/ecommerce/checkout.js +254 -0
  80. package/dist/lib/features/ecommerce/checkout.js.map +1 -0
  81. package/dist/lib/features/ecommerce/index.d.ts +0 -2
  82. package/dist/lib/features/ecommerce/index.js +15 -0
  83. package/dist/lib/features/ecommerce/index.js.map +1 -0
  84. package/dist/lib/features/ecommerce/ltv.d.ts +1 -69
  85. package/dist/lib/features/ecommerce/ltv.js +114 -0
  86. package/dist/lib/features/ecommerce/ltv.js.map +1 -0
  87. package/dist/lib/features/ecommerce/products.d.ts +1 -33
  88. package/dist/lib/features/ecommerce/products.js +223 -0
  89. package/dist/lib/features/ecommerce/products.js.map +1 -0
  90. package/dist/lib/features/ecommerce/promotions.d.ts +1 -30
  91. package/dist/lib/features/ecommerce/promotions.js +197 -0
  92. package/dist/lib/features/ecommerce/promotions.js.map +1 -0
  93. package/dist/lib/features/ecommerce/purchases.d.ts +1 -48
  94. package/dist/lib/features/ecommerce/purchases.js +193 -0
  95. package/dist/lib/features/ecommerce/purchases.js.map +1 -0
  96. package/dist/lib/features/ecommerce/refunds.d.ts +1 -27
  97. package/dist/lib/features/ecommerce/refunds.js +195 -0
  98. package/dist/lib/features/ecommerce/refunds.js.map +1 -0
  99. package/dist/lib/features/ecommerce/search.d.ts +1 -24
  100. package/dist/lib/features/ecommerce/search.js +156 -0
  101. package/dist/lib/features/ecommerce/search.js.map +1 -0
  102. package/dist/lib/features/ecommerce/subscriptions.d.ts +1 -28
  103. package/dist/lib/features/ecommerce/subscriptions.js +207 -0
  104. package/dist/lib/features/ecommerce/subscriptions.js.map +1 -0
  105. package/dist/lib/features/ecommerce/wishlist.d.ts +1 -28
  106. package/dist/lib/features/ecommerce/wishlist.js +186 -0
  107. package/dist/lib/features/ecommerce/wishlist.js.map +1 -0
  108. package/dist/lib/features/enterprise/acquisition.d.ts +2 -57
  109. package/dist/lib/features/enterprise/acquisition.js +166 -0
  110. package/dist/lib/features/enterprise/acquisition.js.map +1 -0
  111. package/dist/lib/features/enterprise/alerts.d.ts +1 -37
  112. package/dist/lib/features/enterprise/alerts.js +246 -0
  113. package/dist/lib/features/enterprise/alerts.js.map +1 -0
  114. package/dist/lib/features/enterprise/churn.d.ts +1 -42
  115. package/dist/lib/features/enterprise/churn.js +175 -0
  116. package/dist/lib/features/enterprise/churn.js.map +1 -0
  117. package/dist/lib/features/enterprise/cohorts.d.ts +1 -37
  118. package/dist/lib/features/enterprise/cohorts.js +201 -0
  119. package/dist/lib/features/enterprise/cohorts.js.map +1 -0
  120. package/dist/lib/features/enterprise/engagement.d.ts +40 -46
  121. package/dist/lib/features/enterprise/engagement.js +335 -0
  122. package/dist/lib/features/enterprise/engagement.js.map +1 -0
  123. package/dist/lib/features/enterprise/forecasting.d.ts +0 -50
  124. package/dist/lib/features/enterprise/forecasting.js +232 -0
  125. package/dist/lib/features/enterprise/forecasting.js.map +1 -0
  126. package/dist/lib/features/enterprise/index.d.ts +1 -1
  127. package/dist/lib/features/enterprise/index.js +76 -0
  128. package/dist/lib/features/enterprise/index.js.map +1 -0
  129. package/dist/lib/features/enterprise/monetization.d.ts +1 -60
  130. package/dist/lib/features/enterprise/monetization.js +146 -0
  131. package/dist/lib/features/enterprise/monetization.js.map +1 -0
  132. package/dist/lib/features/enterprise/multi-path-funnels.d.ts +1 -17
  133. package/dist/lib/features/enterprise/multi-path-funnels.js +205 -0
  134. package/dist/lib/features/enterprise/multi-path-funnels.js.map +1 -0
  135. package/dist/lib/features/enterprise/paths.d.ts +1 -56
  136. package/dist/lib/features/enterprise/paths.js +149 -0
  137. package/dist/lib/features/enterprise/paths.js.map +1 -0
  138. package/dist/lib/features/enterprise/security.d.ts +8 -57
  139. package/dist/lib/features/enterprise/security.js +202 -0
  140. package/dist/lib/features/enterprise/security.js.map +1 -0
  141. package/dist/lib/features/enterprise/support.d.ts +3 -42
  142. package/dist/lib/features/enterprise/support.js +162 -0
  143. package/dist/lib/features/enterprise/support.js.map +1 -0
  144. package/dist/lib/flowgrid.d.ts +278 -0
  145. package/dist/lib/flowgrid.js +323 -0
  146. package/dist/lib/flowgrid.js.map +1 -0
  147. package/dist/lib/frameworks/index.d.ts +13 -6
  148. package/dist/lib/frameworks/index.js +18 -0
  149. package/dist/lib/frameworks/index.js.map +1 -0
  150. package/dist/lib/frameworks/nextjs/client.js +355 -0
  151. package/dist/lib/frameworks/nextjs/client.js.map +1 -0
  152. package/dist/lib/frameworks/nextjs/index.js +31 -0
  153. package/dist/lib/frameworks/nextjs/index.js.map +1 -0
  154. package/dist/lib/frameworks/nextjs/server.js +259 -0
  155. package/dist/lib/frameworks/nextjs/server.js.map +1 -0
  156. package/dist/lib/frameworks/node/index.js +391 -0
  157. package/dist/lib/frameworks/node/index.js.map +1 -0
  158. package/dist/lib/frameworks/nuxt/index.js +288 -0
  159. package/dist/lib/frameworks/nuxt/index.js.map +1 -0
  160. package/dist/lib/frameworks/react/CookieBanner.js +166 -0
  161. package/dist/lib/frameworks/react/CookieBanner.js.map +1 -0
  162. package/dist/lib/frameworks/react/index.js +271 -0
  163. package/dist/lib/frameworks/react/index.js.map +1 -0
  164. package/dist/lib/frameworks/vue/CookieBanner.js +165 -0
  165. package/dist/lib/frameworks/vue/CookieBanner.js.map +1 -0
  166. package/dist/lib/frameworks/vue/index.js +390 -0
  167. package/dist/lib/frameworks/vue/index.js.map +1 -0
  168. package/dist/lib/tracking/analytics/attribution.d.ts +14 -0
  169. package/dist/lib/tracking/analytics/attribution.js +18 -0
  170. package/dist/lib/tracking/analytics/attribution.js.map +1 -0
  171. package/dist/lib/tracking/analytics/events.d.ts +26 -0
  172. package/dist/lib/tracking/analytics/events.js +30 -0
  173. package/dist/lib/tracking/analytics/events.js.map +1 -0
  174. package/dist/lib/tracking/analytics/funnels.d.ts +16 -0
  175. package/dist/lib/tracking/analytics/funnels.js +22 -0
  176. package/dist/lib/tracking/analytics/funnels.js.map +1 -0
  177. package/dist/lib/tracking/analytics/heatmaps.d.ts +27 -0
  178. package/dist/lib/tracking/analytics/heatmaps.js +22 -0
  179. package/dist/lib/tracking/analytics/heatmaps.js.map +1 -0
  180. package/dist/lib/tracking/analytics/identify.d.ts +16 -0
  181. package/dist/lib/tracking/analytics/identify.js +22 -0
  182. package/dist/lib/tracking/analytics/identify.js.map +1 -0
  183. package/dist/lib/tracking/analytics/index.d.ts +10 -0
  184. package/dist/lib/tracking/analytics/index.js +11 -0
  185. package/dist/lib/tracking/analytics/index.js.map +1 -0
  186. package/dist/lib/tracking/analytics/page-views.d.ts +29 -0
  187. package/dist/lib/tracking/analytics/page-views.js +50 -0
  188. package/dist/lib/tracking/analytics/page-views.js.map +1 -0
  189. package/dist/lib/tracking/analytics/performance.d.ts +22 -0
  190. package/dist/lib/tracking/analytics/performance.js +22 -0
  191. package/dist/lib/tracking/analytics/performance.js.map +1 -0
  192. package/dist/lib/tracking/analytics/replay.d.ts +34 -0
  193. package/dist/lib/tracking/analytics/replay.js +46 -0
  194. package/dist/lib/tracking/analytics/replay.js.map +1 -0
  195. package/dist/lib/tracking/analytics/retention.d.ts +10 -0
  196. package/dist/lib/tracking/analytics/retention.js +10 -0
  197. package/dist/lib/tracking/analytics/retention.js.map +1 -0
  198. package/dist/lib/tracking/analytics/sessions.d.ts +20 -0
  199. package/dist/lib/tracking/analytics/sessions.js +26 -0
  200. package/dist/lib/tracking/analytics/sessions.js.map +1 -0
  201. package/dist/lib/tracking/core/activation.d.ts +23 -0
  202. package/dist/lib/tracking/core/activation.js +33 -0
  203. package/dist/lib/tracking/core/activation.js.map +1 -0
  204. package/dist/lib/tracking/core/experiment.d.ts +122 -0
  205. package/dist/lib/tracking/core/experiment.js +150 -0
  206. package/dist/lib/tracking/core/experiment.js.map +1 -0
  207. package/dist/lib/tracking/core/feature.d.ts +13 -0
  208. package/dist/lib/tracking/core/feature.js +14 -0
  209. package/dist/lib/tracking/core/feature.js.map +1 -0
  210. package/dist/lib/tracking/core/index.d.ts +4 -0
  211. package/dist/lib/tracking/core/index.js +5 -0
  212. package/dist/lib/tracking/core/index.js.map +1 -0
  213. package/dist/lib/tracking/core/prompt.d.ts +18 -0
  214. package/dist/lib/tracking/core/prompt.js +26 -0
  215. package/dist/lib/tracking/core/prompt.js.map +1 -0
  216. package/dist/lib/tracking/ecommerce/cart.d.ts +17 -0
  217. package/dist/lib/tracking/ecommerce/cart.js +22 -0
  218. package/dist/lib/tracking/ecommerce/cart.js.map +1 -0
  219. package/dist/lib/tracking/ecommerce/checkout.d.ts +17 -0
  220. package/dist/lib/tracking/ecommerce/checkout.js +22 -0
  221. package/dist/lib/tracking/ecommerce/checkout.js.map +1 -0
  222. package/dist/lib/tracking/ecommerce/index.d.ts +10 -0
  223. package/dist/lib/tracking/ecommerce/index.js +11 -0
  224. package/dist/lib/tracking/ecommerce/index.js.map +1 -0
  225. package/dist/lib/tracking/ecommerce/ltv.d.ts +15 -0
  226. package/dist/lib/tracking/ecommerce/ltv.js +14 -0
  227. package/dist/lib/tracking/ecommerce/ltv.js.map +1 -0
  228. package/dist/lib/tracking/ecommerce/products.d.ts +15 -0
  229. package/dist/lib/tracking/ecommerce/products.js +18 -0
  230. package/dist/lib/tracking/ecommerce/products.js.map +1 -0
  231. package/dist/lib/tracking/ecommerce/promotions.d.ts +14 -0
  232. package/dist/lib/tracking/ecommerce/promotions.js +25 -0
  233. package/dist/lib/tracking/ecommerce/promotions.js.map +1 -0
  234. package/dist/lib/tracking/ecommerce/purchases.d.ts +11 -0
  235. package/dist/lib/tracking/ecommerce/purchases.js +10 -0
  236. package/dist/lib/tracking/ecommerce/purchases.js.map +1 -0
  237. package/dist/lib/tracking/ecommerce/refunds.d.ts +17 -0
  238. package/dist/lib/tracking/ecommerce/refunds.js +22 -0
  239. package/dist/lib/tracking/ecommerce/refunds.js.map +1 -0
  240. package/dist/lib/tracking/ecommerce/search.d.ts +24 -0
  241. package/dist/lib/tracking/ecommerce/search.js +22 -0
  242. package/dist/lib/tracking/ecommerce/search.js.map +1 -0
  243. package/dist/lib/tracking/ecommerce/subscriptions.d.ts +21 -0
  244. package/dist/lib/tracking/ecommerce/subscriptions.js +38 -0
  245. package/dist/lib/tracking/ecommerce/subscriptions.js.map +1 -0
  246. package/dist/lib/tracking/ecommerce/wishlist.d.ts +19 -0
  247. package/dist/lib/tracking/ecommerce/wishlist.js +26 -0
  248. package/dist/lib/tracking/ecommerce/wishlist.js.map +1 -0
  249. package/dist/lib/tracking/enterprise/acquisition.d.ts +25 -0
  250. package/dist/lib/tracking/enterprise/acquisition.js +22 -0
  251. package/dist/lib/tracking/enterprise/acquisition.js.map +1 -0
  252. package/dist/lib/tracking/enterprise/alerts.d.ts +32 -0
  253. package/dist/lib/tracking/enterprise/alerts.js +30 -0
  254. package/dist/lib/tracking/enterprise/alerts.js.map +1 -0
  255. package/dist/lib/tracking/enterprise/churn.d.ts +23 -0
  256. package/dist/lib/tracking/enterprise/churn.js +22 -0
  257. package/dist/lib/tracking/enterprise/churn.js.map +1 -0
  258. package/dist/lib/tracking/enterprise/cohorts.d.ts +18 -0
  259. package/dist/lib/tracking/enterprise/cohorts.js +18 -0
  260. package/dist/lib/tracking/enterprise/cohorts.js.map +1 -0
  261. package/dist/lib/tracking/enterprise/engagement.d.ts +31 -0
  262. package/dist/lib/tracking/enterprise/engagement.js +44 -0
  263. package/dist/lib/tracking/enterprise/engagement.js.map +1 -0
  264. package/dist/lib/tracking/enterprise/forecasting.d.ts +18 -0
  265. package/dist/lib/tracking/enterprise/forecasting.js +22 -0
  266. package/dist/lib/tracking/enterprise/forecasting.js.map +1 -0
  267. package/dist/lib/tracking/enterprise/index.d.ts +11 -0
  268. package/dist/lib/tracking/enterprise/index.js +12 -0
  269. package/dist/lib/tracking/enterprise/index.js.map +1 -0
  270. package/dist/lib/tracking/enterprise/monetization.d.ts +14 -0
  271. package/dist/lib/tracking/enterprise/monetization.js +10 -0
  272. package/dist/lib/tracking/enterprise/monetization.js.map +1 -0
  273. package/dist/lib/tracking/enterprise/multi-path-funnels.d.ts +20 -0
  274. package/dist/lib/tracking/enterprise/multi-path-funnels.js +18 -0
  275. package/dist/lib/tracking/enterprise/multi-path-funnels.js.map +1 -0
  276. package/dist/lib/tracking/enterprise/paths.d.ts +20 -0
  277. package/dist/lib/tracking/enterprise/paths.js +18 -0
  278. package/dist/lib/tracking/enterprise/paths.js.map +1 -0
  279. package/dist/lib/tracking/enterprise/security.d.ts +28 -0
  280. package/dist/lib/tracking/enterprise/security.js +26 -0
  281. package/dist/lib/tracking/enterprise/security.js.map +1 -0
  282. package/dist/lib/tracking/enterprise/support.d.ts +25 -0
  283. package/dist/lib/tracking/enterprise/support.js +22 -0
  284. package/dist/lib/tracking/enterprise/support.js.map +1 -0
  285. package/dist/lib/tracking/index.d.ts +4 -0
  286. package/dist/lib/tracking/index.js +5 -0
  287. package/dist/lib/tracking/index.js.map +1 -0
  288. package/dist/lib/types/analytics.d.ts +10 -2
  289. package/dist/lib/types/analytics.js +6 -0
  290. package/dist/lib/types/analytics.js.map +1 -0
  291. package/dist/lib/types/common.js +6 -0
  292. package/dist/lib/types/common.js.map +1 -0
  293. package/dist/lib/types/ecommerce.js +6 -0
  294. package/dist/lib/types/ecommerce.js.map +1 -0
  295. package/dist/lib/types/index.js +8 -0
  296. package/dist/lib/types/index.js.map +1 -0
  297. package/dist/lib/utils/browser.d.ts +16 -0
  298. package/dist/lib/utils/browser.js +32 -0
  299. package/dist/lib/utils/browser.js.map +1 -0
  300. package/dist/lib/utils/identity.js +346 -0
  301. package/dist/lib/utils/identity.js.map +1 -0
  302. package/dist/lib/utils/storage.js +105 -0
  303. package/dist/lib/utils/storage.js.map +1 -0
  304. package/dist/umd/237.index.js +2 -0
  305. package/dist/umd/237.index.js.map +1 -0
  306. package/dist/umd/546.index.js +3 -0
  307. package/dist/umd/546.index.js.LICENSE.txt +14 -0
  308. package/dist/umd/546.index.js.map +1 -0
  309. package/dist/umd/index.js +2 -0
  310. package/dist/umd/index.js.map +1 -0
  311. package/package.json +27 -80
  312. package/dist/lib/features/ecommerce/inventory.d.ts +0 -219
@@ -0,0 +1,336 @@
1
+ /**
2
+ * @fileoverview FlowGrid Consent Manager
3
+ * @module consent/manager
4
+ *
5
+ * @description
6
+ * Framework-agnostic consent manager that stores user cookie preferences,
7
+ * integrates with the FlowGrid transport layer's consent gates, and
8
+ * respects DNT / GPC signals.
9
+ *
10
+ * The consent manager uses a single cookie (`fg_consent` by default) to
11
+ * persist the user's per-category choices. It exposes a simple API that
12
+ * framework-specific cookie banner components can wrap.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import { ConsentManager } from 'flowgrid-sdk';
17
+ * import { FlowGridTransport } from 'flowgrid-sdk';
18
+ *
19
+ * const consent = new ConsentManager({
20
+ * onChange: (prefs) => {
21
+ * // Sync with FlowGrid transport consent gates
22
+ * FlowGridTransport.setConsent({
23
+ * analytics: prefs.analytics,
24
+ * marketing: prefs.marketing,
25
+ * });
26
+ * },
27
+ * });
28
+ *
29
+ * // Check if user has already consented
30
+ * if (!consent.hasConsented()) {
31
+ * showCookieBanner();
32
+ * }
33
+ *
34
+ * // Accept all
35
+ * consent.acceptAll();
36
+ *
37
+ * // Or reject non-essential
38
+ * consent.rejectNonEssential();
39
+ *
40
+ * // Or update individual categories
41
+ * consent.update({ analytics: true, marketing: false, preferences: true });
42
+ *
43
+ * // Read current state
44
+ * const prefs = consent.getPreferences();
45
+ * console.log(prefs.analytics); // true
46
+ * ```
47
+ */
48
+ // ============================================================================
49
+ // DEFAULTS
50
+ // ============================================================================
51
+ const DEFAULT_COOKIE_NAME = 'fg_consent';
52
+ const DEFAULT_TRACKING_COOKIE_NAME = 'fg_tracking_consent';
53
+ const DEFAULT_COOKIE_DAYS = 365;
54
+ const DEFAULT_PREFERENCES = {
55
+ necessary: true,
56
+ analytics: false,
57
+ marketing: false,
58
+ preferences: true,
59
+ };
60
+ // ============================================================================
61
+ // CONSENT MANAGER
62
+ // ============================================================================
63
+ /**
64
+ * Manages cookie consent state for GDPR/CCPA compliance.
65
+ *
66
+ * Stores the user's per-category consent choices in a single cookie and
67
+ * provides methods to accept, reject, or customise preferences. Integrates
68
+ * with the FlowGrid transport layer via the `onChange` callback.
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * import { ConsentManager, FlowGridTransport } from 'flowgrid-sdk';
73
+ *
74
+ * const consent = new ConsentManager({
75
+ * onChange: (prefs) => {
76
+ * FlowGridTransport.setConsent({
77
+ * analytics: prefs.analytics,
78
+ * marketing: prefs.marketing,
79
+ * });
80
+ * },
81
+ * });
82
+ *
83
+ * // In your cookie banner "Accept All" handler:
84
+ * consent.acceptAll();
85
+ *
86
+ * // In your "Reject All" handler:
87
+ * consent.rejectNonEssential();
88
+ *
89
+ * // In your "Save Preferences" handler:
90
+ * consent.update({ analytics: true, marketing: false, preferences: true });
91
+ * ```
92
+ */
93
+ export class ConsentManager {
94
+ /**
95
+ * Create a new ConsentManager.
96
+ *
97
+ * @param config - Consent configuration options.
98
+ *
99
+ * @example
100
+ * ```ts
101
+ * const consent = new ConsentManager({
102
+ * cookieName: 'my_app_consent',
103
+ * cookieDays: 180,
104
+ * respectDNT: true,
105
+ * requireExplicitConsent: true,
106
+ * onChange: (prefs) => {
107
+ * console.log('Consent changed:', prefs);
108
+ * },
109
+ * });
110
+ * ```
111
+ */
112
+ constructor(config) {
113
+ this.config = {
114
+ cookieName: config?.cookieName ?? DEFAULT_COOKIE_NAME,
115
+ cookieDays: config?.cookieDays ?? DEFAULT_COOKIE_DAYS,
116
+ cookieDomain: config?.cookieDomain,
117
+ respectDNT: config?.respectDNT ?? true,
118
+ requireExplicitConsent: config?.requireExplicitConsent ?? true,
119
+ onChange: config?.onChange,
120
+ defaultPreferences: {
121
+ ...DEFAULT_PREFERENCES,
122
+ ...config?.defaultPreferences,
123
+ necessary: true, // always true
124
+ },
125
+ };
126
+ // Load saved preferences or use defaults
127
+ const saved = this.loadFromCookie();
128
+ if (saved) {
129
+ this.preferences = saved;
130
+ }
131
+ else if (this.isDNTEnabled() && this.config.respectDNT) {
132
+ // DNT/GPC: default to rejecting non-essential
133
+ this.preferences = {
134
+ necessary: true,
135
+ analytics: false,
136
+ marketing: false,
137
+ preferences: false,
138
+ };
139
+ }
140
+ else if (this.config.requireExplicitConsent) {
141
+ this.preferences = { ...this.config.defaultPreferences };
142
+ }
143
+ else {
144
+ // Implied consent mode: all enabled by default
145
+ this.preferences = {
146
+ necessary: true,
147
+ analytics: true,
148
+ marketing: true,
149
+ preferences: true,
150
+ };
151
+ }
152
+ }
153
+ // ---------------------------------------------------------------------------
154
+ // PUBLIC API
155
+ // ---------------------------------------------------------------------------
156
+ /**
157
+ * Check if the user has previously given consent (cookie exists).
158
+ *
159
+ * @returns `true` if the consent cookie exists, `false` otherwise.
160
+ *
161
+ * @example
162
+ * ```ts
163
+ * if (!consent.hasConsented()) {
164
+ * showCookieBanner();
165
+ * }
166
+ * ```
167
+ */
168
+ hasConsented() {
169
+ return this.loadFromCookie() !== null;
170
+ }
171
+ /**
172
+ * Get the current consent preferences.
173
+ *
174
+ * @returns A copy of the current {@link ConsentPreferences}.
175
+ *
176
+ * @example
177
+ * ```ts
178
+ * const prefs = consent.getPreferences();
179
+ * if (prefs.analytics) {
180
+ * initAnalytics();
181
+ * }
182
+ * ```
183
+ */
184
+ getPreferences() {
185
+ return { ...this.preferences };
186
+ }
187
+ /**
188
+ * Check if a specific consent category is enabled.
189
+ *
190
+ * @param category - The category to check.
191
+ * @returns `true` if the category is consented to.
192
+ *
193
+ * @example
194
+ * ```ts
195
+ * if (consent.hasCategory('marketing')) {
196
+ * loadMarketingPixels();
197
+ * }
198
+ * ```
199
+ */
200
+ hasCategory(category) {
201
+ return this.preferences[category] ?? false;
202
+ }
203
+ /**
204
+ * Accept all consent categories.
205
+ *
206
+ * @example
207
+ * ```ts
208
+ * // "Accept All" button handler
209
+ * document.getElementById('accept-all')?.addEventListener('click', () => {
210
+ * consent.acceptAll();
211
+ * });
212
+ * ```
213
+ */
214
+ acceptAll() {
215
+ this.setPreferences({
216
+ necessary: true,
217
+ analytics: true,
218
+ marketing: true,
219
+ preferences: true,
220
+ });
221
+ }
222
+ /**
223
+ * Reject all non-essential categories.
224
+ * Only `necessary` remains enabled.
225
+ *
226
+ * @example
227
+ * ```ts
228
+ * // "Reject All" button handler
229
+ * consent.rejectNonEssential();
230
+ * ```
231
+ */
232
+ rejectNonEssential() {
233
+ this.setPreferences({
234
+ necessary: true,
235
+ analytics: false,
236
+ marketing: false,
237
+ preferences: false,
238
+ });
239
+ }
240
+ /**
241
+ * Update individual consent categories.
242
+ *
243
+ * @param updates - Partial preferences to merge.
244
+ *
245
+ * @example
246
+ * ```ts
247
+ * // "Save Preferences" handler
248
+ * consent.update({
249
+ * analytics: true,
250
+ * marketing: false,
251
+ * preferences: true,
252
+ * });
253
+ * ```
254
+ */
255
+ update(updates) {
256
+ this.setPreferences({
257
+ ...this.preferences,
258
+ ...updates,
259
+ necessary: true,
260
+ });
261
+ }
262
+ /**
263
+ * Reset consent — removes the cookie and restores defaults.
264
+ * The cookie banner should be shown again after this.
265
+ *
266
+ * @example
267
+ * ```ts
268
+ * // "Reset Cookies" link
269
+ * consent.reset();
270
+ * ```
271
+ */
272
+ reset() {
273
+ this.deleteCookie();
274
+ this.preferences = { ...this.config.defaultPreferences };
275
+ }
276
+ // ---------------------------------------------------------------------------
277
+ // PRIVATE
278
+ // ---------------------------------------------------------------------------
279
+ setPreferences(prefs) {
280
+ const previous = { ...this.preferences };
281
+ this.preferences = { ...prefs, necessary: true };
282
+ this.saveToCookie();
283
+ if (this.config.onChange) {
284
+ this.config.onChange(this.preferences);
285
+ }
286
+ }
287
+ isDNTEnabled() {
288
+ if (typeof navigator === 'undefined')
289
+ return false;
290
+ if (navigator.globalPrivacyControl)
291
+ return true;
292
+ if (navigator.doNotTrack === '1')
293
+ return true;
294
+ return false;
295
+ }
296
+ // ---------------------------------------------------------------------------
297
+ // COOKIE I/O
298
+ // ---------------------------------------------------------------------------
299
+ loadFromCookie() {
300
+ if (typeof document === 'undefined')
301
+ return null;
302
+ const match = document.cookie.match(new RegExp('(^| )' + this.config.cookieName + '=([^;]+)'));
303
+ if (!match)
304
+ return null;
305
+ try {
306
+ const parsed = JSON.parse(decodeURIComponent(match[2]));
307
+ if (typeof parsed === 'object' && parsed !== null && typeof parsed.necessary === 'boolean') {
308
+ return { ...DEFAULT_PREFERENCES, ...parsed, necessary: true };
309
+ }
310
+ return null;
311
+ }
312
+ catch {
313
+ return null;
314
+ }
315
+ }
316
+ saveToCookie() {
317
+ if (typeof document === 'undefined')
318
+ return;
319
+ const value = encodeURIComponent(JSON.stringify(this.preferences));
320
+ const maxAge = this.config.cookieDays * 24 * 60 * 60;
321
+ const domain = this.config.cookieDomain ? `; Domain=${this.config.cookieDomain}` : '';
322
+ const secure = typeof location !== 'undefined' && location.protocol === 'https:' ? '; Secure' : '';
323
+ document.cookie = `${this.config.cookieName}=${value}; Path=/; Max-Age=${maxAge}; SameSite=Lax${secure}${domain}`;
324
+ // Simple boolean cookie for track.js compatibility
325
+ const trackingAllowed = this.preferences.analytics ? 'true' : 'false';
326
+ document.cookie = `${DEFAULT_TRACKING_COOKIE_NAME}=${trackingAllowed}; Path=/; Max-Age=${maxAge}; SameSite=Lax${secure}${domain}`;
327
+ }
328
+ deleteCookie() {
329
+ if (typeof document === 'undefined')
330
+ return;
331
+ const domain = this.config.cookieDomain ? `; Domain=${this.config.cookieDomain}` : '';
332
+ document.cookie = `${this.config.cookieName}=; Path=/; Max-Age=0${domain}`;
333
+ document.cookie = `${DEFAULT_TRACKING_COOKIE_NAME}=; Path=/; Max-Age=0${domain}`;
334
+ }
335
+ }
336
+ //# sourceMappingURL=manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manager.js","sourceRoot":"","sources":["../../../src/lib/consent/manager.ts"],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AAG,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;QACtE,QAAQ,CAAC,MAAM,GAAG,GAAG,4BAA4B,IAAI,eAAe,qBAAqB,MAAM,iBAAiB,MAAM,GAAG,MAAM,EAAE,CAAC;IACpI,CAAC;IAEO,YAAY;QAClB,IAAI,OAAO,QAAQ,KAAK,WAAW;YAAE,OAAO;QAC5C,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,YAAY,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACtF,QAAQ,CAAC,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,uBAAuB,MAAM,EAAE,CAAC;QAC3E,QAAQ,CAAC,MAAM,GAAG,GAAG,4BAA4B,uBAAuB,MAAM,EAAE,CAAC;IACnF,CAAC;CACF"}
@@ -117,26 +117,9 @@ export interface CookieBannerTheme {
117
117
  /**
118
118
  * Full configuration for a cookie banner component.
119
119
  *
120
- * @example
121
- * ```tsx
122
- * // React
123
- * import { CookieBanner } from 'flowgrid-sdk/react';
124
- *
125
- * <CookieBanner
126
- * config={{
127
- * title: 'We use cookies',
128
- * description: 'We use cookies to improve your experience.',
129
- * acceptAllLabel: 'Accept All',
130
- * rejectAllLabel: 'Reject All',
131
- * customizeLabel: 'Customize',
132
- * privacyPolicyUrl: '/privacy',
133
- * theme: { position: 'bottom', primaryColor: '#4F46E5' },
134
- * }}
135
- * onAcceptAll={() => consent.acceptAll()}
136
- * onRejectAll={() => consent.rejectNonEssential()}
137
- * onCustomize={(prefs) => consent.update(prefs)}
138
- * />
139
- * ```
120
+ * Pass this to your own UI implementation — `ConsentManager` handles the
121
+ * persistence; rendering is left to consumer code so the SDK stays
122
+ * framework-agnostic.
140
123
  */
141
124
  export interface CookieBannerConfig {
142
125
  /** Banner title. Defaults to `"Cookie Preferences"`. */
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @fileoverview FlowGrid Consent Management — Types
3
+ * @module consent/types
4
+ *
5
+ * @description
6
+ * Types for cookie consent management, GDPR/CCPA compliance,
7
+ * and customizable cookie banner configuration.
8
+ */
9
+ export {};
10
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/lib/consent/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
@@ -37,13 +37,10 @@
37
37
  * campaign: 'brand_terms',
38
38
  * medium: 'cpc'
39
39
  * });
40
- *
41
- * // Get attribution report
42
- * const report = await attribution.getReport({ range: 'last30days' });
43
40
  * ```
44
41
  */
45
42
  import { FlowGridTransport } from "../../client/transport";
46
- import { MoneyValue, DateRangeFilter } from "../../types";
43
+ import { MoneyValue } from "../../types";
47
44
  /**
48
45
  * Attribution model types.
49
46
  */
@@ -85,6 +82,8 @@ export interface ConversionEvent {
85
82
  value?: MoneyValue;
86
83
  /** Conversion identifier (e.g., order ID) */
87
84
  conversionId?: string;
85
+ /** Custom properties */
86
+ properties?: Record<string, unknown>;
88
87
  }
89
88
  /**
90
89
  * Touchpoint response from API.
@@ -170,11 +169,6 @@ export interface AttributionReportData {
170
169
  * value: { amount: 9999, currency: 'USD' },
171
170
  * conversionId: 'ORD-12345'
172
171
  * });
173
- *
174
- * // Get attribution report
175
- * const report = await attribution.getReport({
176
- * model: 'linear'
177
- * });
178
172
  * ```
179
173
  */
180
174
  export declare class Attribution extends FlowGridTransport {
@@ -214,44 +208,9 @@ export declare class Attribution extends FlowGridTransport {
214
208
  */
215
209
  recordConversion(event: ConversionEvent): Promise<TouchpointResponse>;
216
210
  /**
217
- * Gets attribution report with specified model.
218
- *
219
- * @param options - Report options
220
- * @returns Promise resolving to attribution report
221
- *
222
- * @example
223
- * ```typescript
224
- * const report = await attribution.getReport({
225
- * model: 'position_based',
226
- * filter: { range: 'last30days' }
227
- * });
228
- *
229
- * // Bar chart - revenue by channel
230
- * const channelChart = report.byChannel.map(c => ({
231
- * name: c.channel,
232
- * value: c.attributedRevenue.amount
233
- * }));
234
- *
235
- * // Sankey - top conversion paths
236
- * const pathData = report.topPaths;
237
- * ```
211
+ * Auto-capture a touchpoint from `utm_*` query params and `document.referrer`.
212
+ * Browser-only; returns null on the server or when no UTM/referrer data is present.
238
213
  */
239
- getReport(options?: {
240
- model?: AttributionModel;
241
- filter?: DateRangeFilter;
242
- }): Promise<AttributionReportData>;
243
- /**
244
- * Gets user journey/path for a specific user.
245
- *
246
- * @param userId - User identifier
247
- * @returns Promise resolving to user journey data
248
- */
249
- getUserJourney(userId: string): Promise<{
250
- touchpoints: Array<TouchpointConfig & {
251
- timestamp: string;
252
- }>;
253
- conversions: ConversionEvent[];
254
- totalValue: MoneyValue;
255
- }>;
214
+ captureFromUrl(userId: string): TouchpointConfig | null;
256
215
  }
257
216
  export default Attribution;
@@ -0,0 +1,181 @@
1
+ /**
2
+ * @fileoverview Product Analytics - Revenue Attribution
3
+ * @module features/analytics/attribution
4
+ *
5
+ * @description
6
+ * Multi-touch attribution modeling to understand which marketing
7
+ * channels and touchpoints drive conversions and revenue.
8
+ *
9
+ * @useCases
10
+ * - Track marketing touchpoints across customer journey
11
+ * - Calculate attribution for conversions
12
+ * - Compare attribution models (first-touch, last-touch, linear)
13
+ * - Optimize marketing spend allocation
14
+ * - Understand channel effectiveness
15
+ *
16
+ * @metrics
17
+ * - Attributed revenue by channel
18
+ * - Conversion paths
19
+ * - Assisted conversions
20
+ * - Time to conversion
21
+ * - Channel influence score
22
+ *
23
+ * @chartData
24
+ * - Sankey diagram: Customer journey paths
25
+ * - Bar chart: Revenue by channel
26
+ * - Table: Attribution comparison by model
27
+ * - Pie chart: Channel contribution
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * const attribution = new Attribution(webId, endpoint, apiKey);
32
+ *
33
+ * // Track touchpoint
34
+ * await attribution.trackTouchpoint({
35
+ * userId: 'user_123',
36
+ * channel: 'google_ads',
37
+ * campaign: 'brand_terms',
38
+ * medium: 'cpc'
39
+ * });
40
+ * ```
41
+ */
42
+ import { FlowGridTransport } from "../../client/transport";
43
+ import { getWindow, getDocument, isBrowser } from "../../utils/browser";
44
+ // ============================================================================
45
+ // ATTRIBUTION CLASS
46
+ // ============================================================================
47
+ /**
48
+ * Attribution - Multi-touch attribution tracking.
49
+ *
50
+ * @extends FlowGridTransport
51
+ *
52
+ * @description
53
+ * Provides attribution capabilities including:
54
+ * - Touchpoint tracking
55
+ * - Conversion attribution
56
+ * - Multiple attribution models
57
+ * - Path analysis
58
+ * - Channel effectiveness
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const attribution = new Attribution(webId, endpoint, apiKey);
63
+ *
64
+ * // Track touchpoints throughout customer journey
65
+ * await attribution.trackTouchpoint({
66
+ * userId: 'user_123',
67
+ * channel: 'email',
68
+ * campaign: 'welcome_series',
69
+ * medium: 'email'
70
+ * });
71
+ *
72
+ * // Record conversion
73
+ * await attribution.recordConversion({
74
+ * userId: 'user_123',
75
+ * conversionType: 'purchase',
76
+ * value: { amount: 9999, currency: 'USD' },
77
+ * conversionId: 'ORD-12345'
78
+ * });
79
+ * ```
80
+ */
81
+ export class Attribution extends FlowGridTransport {
82
+ /**
83
+ * Tracks a marketing touchpoint.
84
+ *
85
+ * @param config - Touchpoint configuration
86
+ * @returns Promise resolving to touchpoint response
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * await attribution.trackTouchpoint({
91
+ * userId: 'user_123',
92
+ * channel: 'facebook_ads',
93
+ * campaign: 'retargeting_cart',
94
+ * medium: 'paid_social',
95
+ * landingPage: '/products/special-offer'
96
+ * });
97
+ * ```
98
+ */
99
+ async trackTouchpoint(config) {
100
+ return await this.init("attribution_touchpoint", {
101
+ type: "attribution_touchpoint",
102
+ userId: config.userId,
103
+ channel: config.channel,
104
+ campaign: config.campaign,
105
+ medium: config.medium,
106
+ source: config.source,
107
+ content: config.content,
108
+ term: config.term,
109
+ referrer: config.referrer,
110
+ landingPage: config.landingPage,
111
+ ...config.properties,
112
+ timestamp: new Date().toISOString()
113
+ });
114
+ }
115
+ /**
116
+ * Records a conversion for attribution.
117
+ *
118
+ * @param event - Conversion event
119
+ * @returns Promise resolving to conversion response
120
+ *
121
+ * @example
122
+ * ```typescript
123
+ * await attribution.recordConversion({
124
+ * userId: 'user_123',
125
+ * conversionType: 'purchase',
126
+ * value: { amount: 14999, currency: 'USD' },
127
+ * conversionId: 'ORD-98765'
128
+ * });
129
+ * ```
130
+ */
131
+ async recordConversion(event) {
132
+ return await this.init("attribution_conversion", {
133
+ type: "attribution_conversion",
134
+ userId: event.userId,
135
+ conversionType: event.conversionType,
136
+ value: event.value,
137
+ conversionId: event.conversionId,
138
+ ...event.properties,
139
+ timestamp: new Date().toISOString()
140
+ });
141
+ }
142
+ /**
143
+ * Auto-capture a touchpoint from `utm_*` query params and `document.referrer`.
144
+ * Browser-only; returns null on the server or when no UTM/referrer data is present.
145
+ */
146
+ captureFromUrl(userId) {
147
+ if (!isBrowser())
148
+ return null;
149
+ const win = getWindow();
150
+ const doc = getDocument();
151
+ if (!win || !doc)
152
+ return null;
153
+ const params = new URLSearchParams(win.location.search);
154
+ const utm = {
155
+ utmSource: params.get("utm_source") ?? undefined,
156
+ utmMedium: params.get("utm_medium") ?? undefined,
157
+ utmCampaign: params.get("utm_campaign") ?? undefined,
158
+ utmTerm: params.get("utm_term") ?? undefined,
159
+ utmContent: params.get("utm_content") ?? undefined,
160
+ };
161
+ const referrer = doc.referrer || undefined;
162
+ if (!utm.utmSource && !utm.utmMedium && !utm.utmCampaign && !referrer) {
163
+ return null;
164
+ }
165
+ const config = {
166
+ userId,
167
+ channel: utm.utmSource || (referrer ? "referral" : "direct"),
168
+ campaign: utm.utmCampaign,
169
+ medium: utm.utmMedium,
170
+ source: utm.utmSource,
171
+ content: utm.utmContent,
172
+ term: utm.utmTerm,
173
+ referrer,
174
+ landingPage: win.location.pathname,
175
+ };
176
+ void this.trackTouchpoint(config);
177
+ return config;
178
+ }
179
+ }
180
+ export default Attribution;
181
+ //# sourceMappingURL=attribution.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attribution.js","sourceRoot":"","sources":["../../../../src/lib/features/analytics/attribution.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAO3D,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAiHxE,+EAA+E;AAC/E,oBAAoB;AACpB,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,OAAO,WAAY,SAAQ,iBAAiB;IAChD;;;;;;;;;;;;;;;;OAgBG;IACH,KAAK,CAAC,eAAe,CAAC,MAAwB;QAC5C,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,wBAAwB,EAAE;YAC/C,IAAI,EAAE,wBAAwB;YAC9B,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,GAAG,MAAM,CAAC,UAAU;YACpB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACpC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,KAAK,CAAC,gBAAgB,CAAC,KAAsB;QAC3C,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,wBAAwB,EAAE;YAC/C,I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