@cuemath/web-utils 2.0.0-beta.0 → 2.1.11-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (274) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc.json +9 -0
  3. package/.husky/pre-commit +5 -0
  4. package/.huskyrc +5 -0
  5. package/.lintstagedrc.yml +5 -0
  6. package/.nvmrc +1 -0
  7. package/.prettierrc.json +1 -0
  8. package/.vscode/settings.json +1 -0
  9. package/README.md +1 -334
  10. package/dist/constants/country/index.d.ts +2 -0
  11. package/dist/constants/country/index.js +7 -0
  12. package/dist/constants/country/index.js.map +1 -0
  13. package/dist/constants/country/iso-country-code.d.ts +248 -0
  14. package/dist/constants/country/iso-country-code.js +252 -0
  15. package/dist/constants/country/iso-country-code.js.map +1 -0
  16. package/dist/constants/date-time/index.d.ts +17 -0
  17. package/dist/constants/date-time/index.js +42 -0
  18. package/dist/constants/date-time/index.js.map +1 -0
  19. package/dist/constants/date-time/international-timezones.d.ts +7 -0
  20. package/dist/constants/date-time/international-timezones.js +155 -0
  21. package/dist/constants/date-time/international-timezones.js.map +1 -0
  22. package/dist/constants/e-cna/index.d.ts +41 -0
  23. package/dist/constants/e-cna/index.js +45 -0
  24. package/dist/constants/e-cna/index.js.map +1 -0
  25. package/dist/constants/index.d.ts +2 -0
  26. package/dist/constants/index.js +19 -0
  27. package/dist/constants/index.js.map +1 -0
  28. package/dist/cookie/index.d.ts +4 -0
  29. package/dist/cookie/index.js +46 -0
  30. package/dist/cookie/index.js.map +1 -0
  31. package/dist/country/index.d.ts +1 -0
  32. package/dist/country/index.js +13 -0
  33. package/dist/country/index.js.map +1 -0
  34. package/dist/date-time-helper/e-cna.d.ts +32 -0
  35. package/dist/date-time-helper/e-cna.js +153 -0
  36. package/dist/date-time-helper/e-cna.js.map +1 -0
  37. package/dist/date-time-helper/index.d.ts +54 -0
  38. package/dist/date-time-helper/index.js +290 -0
  39. package/dist/date-time-helper/index.js.map +1 -0
  40. package/dist/e-cna/flow/aggregator.d.ts +473 -0
  41. package/dist/e-cna/flow/aggregator.js +17 -0
  42. package/dist/e-cna/flow/aggregator.js.map +1 -0
  43. package/dist/e-cna/flow/index.d.ts +1 -0
  44. package/dist/e-cna/flow/index.js +18 -0
  45. package/dist/e-cna/flow/index.js.map +1 -0
  46. package/dist/e-cna/flow/variants/default.d.ts +734 -0
  47. package/dist/e-cna/flow/variants/default.js +94 -0
  48. package/dist/e-cna/flow/variants/default.js.map +1 -0
  49. package/dist/e-cna/flow/variants/index.d.ts +1 -0
  50. package/dist/e-cna/flow/variants/index.js +18 -0
  51. package/dist/e-cna/flow/variants/index.js.map +1 -0
  52. package/dist/e-cna/index.d.ts +43 -0
  53. package/dist/e-cna/index.js +221 -0
  54. package/dist/e-cna/index.js.map +1 -0
  55. package/dist/e-cna/slides/child_hobbies/index.d.ts +1 -0
  56. package/dist/e-cna/slides/child_hobbies/index.js +18 -0
  57. package/dist/e-cna/slides/child_hobbies/index.js.map +1 -0
  58. package/dist/e-cna/slides/child_hobbies/variants.d.ts +22 -0
  59. package/dist/e-cna/slides/child_hobbies/variants.js +26 -0
  60. package/dist/e-cna/slides/child_hobbies/variants.js.map +1 -0
  61. package/dist/e-cna/slides/child_info/index.d.ts +1 -0
  62. package/dist/e-cna/slides/child_info/index.js +18 -0
  63. package/dist/e-cna/slides/child_info/index.js.map +1 -0
  64. package/dist/e-cna/slides/child_info/variants.d.ts +17 -0
  65. package/dist/e-cna/slides/child_info/variants.js +22 -0
  66. package/dist/e-cna/slides/child_info/variants.js.map +1 -0
  67. package/dist/e-cna/slides/child_personality/index.d.ts +1 -0
  68. package/dist/e-cna/slides/child_personality/index.js +18 -0
  69. package/dist/e-cna/slides/child_personality/index.js.map +1 -0
  70. package/dist/e-cna/slides/child_personality/variants.d.ts +12 -0
  71. package/dist/e-cna/slides/child_personality/variants.js +16 -0
  72. package/dist/e-cna/slides/child_personality/variants.js.map +1 -0
  73. package/dist/e-cna/slides/curriculum/index.d.ts +1 -0
  74. package/dist/e-cna/slides/curriculum/index.js +18 -0
  75. package/dist/e-cna/slides/curriculum/index.js.map +1 -0
  76. package/dist/e-cna/slides/curriculum/variants.d.ts +12 -0
  77. package/dist/e-cna/slides/curriculum/variants.js +17 -0
  78. package/dist/e-cna/slides/curriculum/variants.js.map +1 -0
  79. package/dist/e-cna/slides/grade/index.d.ts +1 -0
  80. package/dist/e-cna/slides/grade/index.js +18 -0
  81. package/dist/e-cna/slides/grade/index.js.map +1 -0
  82. package/dist/e-cna/slides/grade/variants.d.ts +25 -0
  83. package/dist/e-cna/slides/grade/variants.js +54 -0
  84. package/dist/e-cna/slides/grade/variants.js.map +1 -0
  85. package/dist/e-cna/slides/index.d.ts +19 -0
  86. package/dist/e-cna/slides/index.js +36 -0
  87. package/dist/e-cna/slides/index.js.map +1 -0
  88. package/dist/e-cna/slides/intro/index.d.ts +1 -0
  89. package/dist/e-cna/slides/intro/index.js +18 -0
  90. package/dist/e-cna/slides/intro/index.js.map +1 -0
  91. package/dist/e-cna/slides/intro/variants.d.ts +7 -0
  92. package/dist/e-cna/slides/intro/variants.js +11 -0
  93. package/dist/e-cna/slides/intro/variants.js.map +1 -0
  94. package/dist/e-cna/slides/key_need_l1/index.d.ts +1 -0
  95. package/dist/e-cna/slides/key_need_l1/index.js +18 -0
  96. package/dist/e-cna/slides/key_need_l1/index.js.map +1 -0
  97. package/dist/e-cna/slides/key_need_l1/variants.d.ts +26 -0
  98. package/dist/e-cna/slides/key_need_l1/variants.js +57 -0
  99. package/dist/e-cna/slides/key_need_l1/variants.js.map +1 -0
  100. package/dist/e-cna/slides/key_need_l2/index.d.ts +1 -0
  101. package/dist/e-cna/slides/key_need_l2/index.js +18 -0
  102. package/dist/e-cna/slides/key_need_l2/index.js.map +1 -0
  103. package/dist/e-cna/slides/key_need_l2/variants.d.ts +67 -0
  104. package/dist/e-cna/slides/key_need_l2/variants.js +139 -0
  105. package/dist/e-cna/slides/key_need_l2/variants.js.map +1 -0
  106. package/dist/e-cna/slides/key_need_l3/index.d.ts +1 -0
  107. package/dist/e-cna/slides/key_need_l3/index.js +18 -0
  108. package/dist/e-cna/slides/key_need_l3/index.js.map +1 -0
  109. package/dist/e-cna/slides/key_need_l3/variants.d.ts +11 -0
  110. package/dist/e-cna/slides/key_need_l3/variants.js +15 -0
  111. package/dist/e-cna/slides/key_need_l3/variants.js.map +1 -0
  112. package/dist/e-cna/slides/math-perception/index.d.ts +1 -0
  113. package/dist/e-cna/slides/math-perception/index.js +18 -0
  114. package/dist/e-cna/slides/math-perception/index.js.map +1 -0
  115. package/dist/e-cna/slides/math-perception/variants.d.ts +15 -0
  116. package/dist/e-cna/slides/math-perception/variants.js +32 -0
  117. package/dist/e-cna/slides/math-perception/variants.js.map +1 -0
  118. package/dist/e-cna/slides/other_curriculum/index.d.ts +1 -0
  119. package/dist/e-cna/slides/other_curriculum/index.js +18 -0
  120. package/dist/e-cna/slides/other_curriculum/index.js.map +1 -0
  121. package/dist/e-cna/slides/other_curriculum/variants.d.ts +12 -0
  122. package/dist/e-cna/slides/other_curriculum/variants.js +17 -0
  123. package/dist/e-cna/slides/other_curriculum/variants.js.map +1 -0
  124. package/dist/e-cna/slides/school_performance_5_12/index.d.ts +1 -0
  125. package/dist/e-cna/slides/school_performance_5_12/index.js +18 -0
  126. package/dist/e-cna/slides/school_performance_5_12/index.js.map +1 -0
  127. package/dist/e-cna/slides/school_performance_5_12/variants.d.ts +15 -0
  128. package/dist/e-cna/slides/school_performance_5_12/variants.js +26 -0
  129. package/dist/e-cna/slides/school_performance_5_12/variants.js.map +1 -0
  130. package/dist/e-cna/slides/school_performance_kg_4/index.d.ts +1 -0
  131. package/dist/e-cna/slides/school_performance_kg_4/index.js +18 -0
  132. package/dist/e-cna/slides/school_performance_kg_4/index.js.map +1 -0
  133. package/dist/e-cna/slides/school_performance_kg_4/variants.d.ts +14 -0
  134. package/dist/e-cna/slides/school_performance_kg_4/variants.js +28 -0
  135. package/dist/e-cna/slides/school_performance_kg_4/variants.js.map +1 -0
  136. package/dist/e-cna/slides/secondary_needs/index.d.ts +1 -0
  137. package/dist/e-cna/slides/secondary_needs/index.js +18 -0
  138. package/dist/e-cna/slides/secondary_needs/index.js.map +1 -0
  139. package/dist/e-cna/slides/secondary_needs/variants.d.ts +14 -0
  140. package/dist/e-cna/slides/secondary_needs/variants.js +28 -0
  141. package/dist/e-cna/slides/secondary_needs/variants.js.map +1 -0
  142. package/dist/e-cna/slides/signup/index.d.ts +1 -0
  143. package/dist/e-cna/slides/signup/index.js +18 -0
  144. package/dist/e-cna/slides/signup/index.js.map +1 -0
  145. package/dist/e-cna/slides/signup/variants.d.ts +7 -0
  146. package/dist/e-cna/slides/signup/variants.js +11 -0
  147. package/dist/e-cna/slides/signup/variants.js.map +1 -0
  148. package/dist/e-cna/slides/signup_refer/index.d.ts +1 -0
  149. package/dist/e-cna/slides/signup_refer/index.js +18 -0
  150. package/dist/e-cna/slides/signup_refer/index.js.map +1 -0
  151. package/dist/e-cna/slides/signup_refer/variants.d.ts +22 -0
  152. package/dist/e-cna/slides/signup_refer/variants.js +34 -0
  153. package/dist/e-cna/slides/signup_refer/variants.js.map +1 -0
  154. package/dist/e-cna/slides/slot_pick/index.d.ts +1 -0
  155. package/dist/e-cna/slides/slot_pick/index.js +18 -0
  156. package/dist/e-cna/slides/slot_pick/index.js.map +1 -0
  157. package/dist/e-cna/slides/slot_pick/variants.d.ts +12 -0
  158. package/dist/e-cna/slides/slot_pick/variants.js +16 -0
  159. package/dist/e-cna/slides/slot_pick/variants.js.map +1 -0
  160. package/dist/e-cna/slides/teacher_intro/index.d.ts +1 -0
  161. package/dist/e-cna/slides/teacher_intro/index.js +18 -0
  162. package/dist/e-cna/slides/teacher_intro/index.js.map +1 -0
  163. package/dist/e-cna/slides/teacher_intro/variants.d.ts +78 -0
  164. package/dist/e-cna/slides/teacher_intro/variants.js +114 -0
  165. package/dist/e-cna/slides/teacher_intro/variants.js.map +1 -0
  166. package/dist/e-cna/utils/index.d.ts +4 -0
  167. package/dist/e-cna/utils/index.js +28 -0
  168. package/dist/e-cna/utils/index.js.map +1 -0
  169. package/dist/index.d.ts +7 -313
  170. package/dist/index.js +23 -3
  171. package/dist/index.js.map +1 -1
  172. package/dist/local-storage/index.d.ts +13 -0
  173. package/dist/local-storage/index.js +172 -0
  174. package/dist/local-storage/index.js.map +1 -0
  175. package/dist/object/index.d.ts +6 -0
  176. package/dist/object/index.js +24 -0
  177. package/dist/object/index.js.map +1 -0
  178. package/package.json +11 -52
  179. package/src/constants/country/index.ts +2 -0
  180. package/src/constants/country/iso-country-code.ts +248 -0
  181. package/src/constants/date-time/index.ts +43 -0
  182. package/src/constants/date-time/international-timezones.ts +157 -0
  183. package/src/constants/e-cna/index.ts +55 -0
  184. package/src/constants/index.ts +2 -0
  185. package/src/cookie/index.ts +51 -0
  186. package/src/country/index.ts +9 -0
  187. package/src/date-time-helper/e-cna.ts +205 -0
  188. package/src/date-time-helper/index.ts +365 -0
  189. package/src/e-cna/flow/aggregator.ts +12 -0
  190. package/src/e-cna/flow/index.ts +1 -0
  191. package/src/e-cna/flow/variants/default.ts +112 -0
  192. package/src/e-cna/flow/variants/index.ts +1 -0
  193. package/src/e-cna/index.ts +249 -0
  194. package/src/e-cna/slides/child_hobbies/index.ts +1 -0
  195. package/src/e-cna/slides/child_hobbies/variants.ts +24 -0
  196. package/src/e-cna/slides/child_info/index.ts +1 -0
  197. package/src/e-cna/slides/child_info/variants.ts +18 -0
  198. package/src/e-cna/slides/child_personality/index.ts +1 -0
  199. package/src/e-cna/slides/child_personality/variants.ts +12 -0
  200. package/src/e-cna/slides/curriculum/index.ts +1 -0
  201. package/src/e-cna/slides/curriculum/variants.ts +14 -0
  202. package/src/e-cna/slides/grade/index.ts +1 -0
  203. package/src/e-cna/slides/grade/variants.ts +53 -0
  204. package/src/e-cna/slides/index.ts +19 -0
  205. package/src/e-cna/slides/intro/index.ts +1 -0
  206. package/src/e-cna/slides/intro/variants.ts +7 -0
  207. package/src/e-cna/slides/key_need_l1/index.ts +1 -0
  208. package/src/e-cna/slides/key_need_l1/variants.ts +57 -0
  209. package/src/e-cna/slides/key_need_l2/index.ts +1 -0
  210. package/src/e-cna/slides/key_need_l2/variants.ts +143 -0
  211. package/src/e-cna/slides/key_need_l3/index.ts +1 -0
  212. package/src/e-cna/slides/key_need_l3/variants.ts +13 -0
  213. package/src/e-cna/slides/math-perception/index.ts +1 -0
  214. package/src/e-cna/slides/math-perception/variants.ts +30 -0
  215. package/src/e-cna/slides/other_curriculum/index.ts +1 -0
  216. package/src/e-cna/slides/other_curriculum/variants.ts +14 -0
  217. package/src/e-cna/slides/school_performance_5_12/index.ts +1 -0
  218. package/src/e-cna/slides/school_performance_5_12/variants.ts +23 -0
  219. package/src/e-cna/slides/school_performance_kg_4/index.ts +1 -0
  220. package/src/e-cna/slides/school_performance_kg_4/variants.ts +25 -0
  221. package/src/e-cna/slides/secondary_needs/index.ts +1 -0
  222. package/src/e-cna/slides/secondary_needs/variants.ts +26 -0
  223. package/src/e-cna/slides/signup/index.ts +1 -0
  224. package/src/e-cna/slides/signup/variants.ts +7 -0
  225. package/src/e-cna/slides/signup_refer/index.ts +1 -0
  226. package/src/e-cna/slides/signup_refer/variants.ts +30 -0
  227. package/src/e-cna/slides/slot_pick/index.ts +1 -0
  228. package/src/e-cna/slides/slot_pick/variants.ts +12 -0
  229. package/src/e-cna/slides/teacher_intro/index.ts +1 -0
  230. package/src/e-cna/slides/teacher_intro/variants.ts +112 -0
  231. package/src/e-cna/utils/index.ts +32 -0
  232. package/src/index.ts +7 -0
  233. package/src/local-storage/index.ts +186 -0
  234. package/src/object/index.ts +26 -0
  235. package/tsconfig.json +8 -0
  236. package/dist/browser.d.mts +0 -15
  237. package/dist/browser.d.ts +0 -15
  238. package/dist/browser.js +0 -2
  239. package/dist/browser.js.map +0 -1
  240. package/dist/browser.mjs +0 -2
  241. package/dist/browser.mjs.map +0 -1
  242. package/dist/chunk-5X4UT2UI.js +0 -3
  243. package/dist/chunk-5X4UT2UI.js.map +0 -1
  244. package/dist/chunk-CVZIO6BX.mjs +0 -4
  245. package/dist/chunk-CVZIO6BX.mjs.map +0 -1
  246. package/dist/chunk-LUUB665J.mjs +0 -3
  247. package/dist/chunk-LUUB665J.mjs.map +0 -1
  248. package/dist/chunk-OBXSX4MO.js +0 -3
  249. package/dist/chunk-OBXSX4MO.js.map +0 -1
  250. package/dist/chunk-SMWXEBQ2.js +0 -4
  251. package/dist/chunk-SMWXEBQ2.js.map +0 -1
  252. package/dist/chunk-TG7DRTM7.mjs +0 -3
  253. package/dist/chunk-TG7DRTM7.mjs.map +0 -1
  254. package/dist/cloudfront-DRTOCXPV.d.mts +0 -758
  255. package/dist/cloudfront-DRTOCXPV.d.ts +0 -758
  256. package/dist/cloudfront.d.mts +0 -2
  257. package/dist/cloudfront.d.ts +0 -2
  258. package/dist/cloudfront.js +0 -2
  259. package/dist/cloudfront.js.map +0 -1
  260. package/dist/cloudfront.mjs +0 -2
  261. package/dist/cloudfront.mjs.map +0 -1
  262. package/dist/data-props-RvZdA60G.d.mts +0 -157
  263. package/dist/data-props-RvZdA60G.d.ts +0 -157
  264. package/dist/date-time-helper/timezone.d.mts +0 -61
  265. package/dist/date-time-helper/timezone.d.ts +0 -61
  266. package/dist/date-time-helper/timezone.js +0 -2
  267. package/dist/date-time-helper/timezone.js.map +0 -1
  268. package/dist/date-time-helper/timezone.mjs +0 -2
  269. package/dist/date-time-helper/timezone.mjs.map +0 -1
  270. package/dist/index.d.mts +0 -313
  271. package/dist/index.mjs +0 -4
  272. package/dist/index.mjs.map +0 -1
  273. package/dist/metafile-cjs.json +0 -1
  274. package/dist/metafile-esm.json +0 -1
package/.eslintignore ADDED
@@ -0,0 +1,2 @@
1
+ .next
2
+ /dist
package/.eslintrc.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "root": true,
3
+ "extends": ["@cuemath"],
4
+ "settings": {
5
+ "react": {
6
+ "version": "16.13.1"
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env sh
2
+ . "$(dirname -- "$0")/_/husky.sh"
3
+
4
+ yarn lint
5
+ npx lint-staged
package/.huskyrc ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "hooks": {
3
+ "pre-commit": "lint-staged"
4
+ }
5
+ }
@@ -0,0 +1,5 @@
1
+ linters:
2
+ ./**/*.ts:
3
+ - prettier --write
4
+ - eslint
5
+ - git add
package/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ v18.12.1
@@ -0,0 +1 @@
1
+ "@cuemath/prettier-config"
@@ -0,0 +1 @@
1
+ {}
package/README.md CHANGED
@@ -1,334 +1 @@
1
- # @cuemath/web-utils v2.0.0
2
-
3
- Shared web utilities package optimized for Lambda@Edge, CloudFront, and browser environments.
4
-
5
- ## Features
6
-
7
- - 🚀 **Lambda@Edge Ready** - Optimized bundles for AWS CloudFront edge computing
8
- - 📦 **Tree-Shakeable** - Import only what you need with ESM
9
- - ⚡ **Tiny Bundles** - CloudFront entry: 18KB gzipped (800KB limit)
10
- - 🔧 **Dual Formats** - ESM (primary) + CJS (legacy) support
11
- - 🎯 **TypeScript** - Full type definitions included
12
- - 🌐 **Universal** - Works in Node.js, browsers, and edge runtimes
13
-
14
- ## Installation
15
-
16
- ```bash
17
- yarn add @cuemath/web-utils
18
- # or
19
- npm install @cuemath/web-utils
20
- ```
21
-
22
- ## Entry Points
23
-
24
- ### Main Entry (Universal)
25
- ```typescript
26
- import { formatDateTime, getCurrentTimestamp } from '@cuemath/web-utils';
27
- ```
28
-
29
- ### CloudFront/Lambda@Edge (Server-Optimized)
30
- ```typescript
31
- import {
32
- parseCloudFrontCookies,
33
- getABVariantFromCookies,
34
- getABExperimentCacheKey
35
- } from '@cuemath/web-utils/cloudfront';
36
- ```
37
-
38
- ### Browser (DOM APIs)
39
- ```typescript
40
- import {
41
- getABVariant,
42
- localStorageSet,
43
- getAttributes
44
- } from '@cuemath/web-utils/browser';
45
- ```
46
-
47
- ### Timezone Functions (Optional)
48
- ```typescript
49
- import {
50
- dateByTimezone,
51
- getTimezone
52
- } from '@cuemath/web-utils/date-time-helper/timezone';
53
- ```
54
-
55
- ## CloudFront Lambda@Edge Usage
56
-
57
- ### Origin Request Handler Example
58
-
59
- ```typescript
60
- import {
61
- parseCloudFrontCookies,
62
- getABVariantFromCookies,
63
- getABExperimentCacheKey,
64
- ISO_COUNTRY_CODE,
65
- EXPERIMENT_KEYS,
66
- VARIANTS,
67
- AB_IDENTIFIER_KEY
68
- } from '@cuemath/web-utils/cloudfront';
69
-
70
- export const handler = async (event) => {
71
- const request = event.Records[0].cf.request;
72
- const headers = request.headers;
73
-
74
- // Parse CloudFront cookies (handles multiple Cookie headers)
75
- const cookies = parseCloudFrontCookies(headers.cookie || []);
76
-
77
- // Get country from CloudFront-Viewer-Country header
78
- const country = headers['cloudfront-viewer-country']?.[0]?.value || 'US';
79
-
80
- // Parse current A/B variants from cookie
81
- const currentVariants = cookies[AB_IDENTIFIER_KEY]
82
- ? JSON.parse(decodeURIComponent(cookies[AB_IDENTIFIER_KEY]))
83
- : {};
84
-
85
- // Parse last landing page cookie
86
- const lastLandingPage = cookies['lastLandingPage']
87
- ? JSON.parse(cookies['lastLandingPage'])
88
- : { value: '', createdAt: '' };
89
-
90
- // Get A/B variant assignments (Lambda@Edge optimized)
91
- const { isABExperimentsUpdated, abExperiment } = getABVariantFromCookies(
92
- request.uri,
93
- country,
94
- currentVariants,
95
- lastLandingPage,
96
- cookies, // Pre-parsed cookies
97
- 'debug_ab' // Debug cookie name
98
- );
99
-
100
- // Generate cache key for CloudFront
101
- const cacheKey = getABExperimentCacheKey(abExperiment);
102
-
103
- // Add cache key to custom header for CloudFront caching
104
- request.headers['x-ab-experiments'] = [{
105
- key: 'X-AB-Experiments',
106
- value: cacheKey
107
- }];
108
-
109
- // Set cookie if experiments were updated
110
- if (isABExperimentsUpdated) {
111
- const cookieValue = encodeURIComponent(JSON.stringify(abExperiment));
112
- request.headers['cookie'] = request.headers['cookie'] || [];
113
- request.headers['cookie'].push({
114
- key: 'Cookie',
115
- value: `${AB_IDENTIFIER_KEY}=${cookieValue}`
116
- });
117
- }
118
-
119
- return request;
120
- };
121
- ```
122
-
123
- ### Viewer Response Handler (Set Cookies)
124
-
125
- ```typescript
126
- export const handler = async (event) => {
127
- const response = event.Records[0].cf.response;
128
- const request = event.Records[0].cf.request;
129
-
130
- // Get A/B experiments from request header
131
- const abHeader = request.headers['x-ab-experiments']?.[0]?.value;
132
-
133
- if (abHeader) {
134
- // Set cookie with A/B variants
135
- response.headers['set-cookie'] = [{
136
- key: 'Set-Cookie',
137
- value: `${AB_IDENTIFIER_KEY}=${abHeader}; Path=/; Max-Age=31536000; Secure; SameSite=Lax`
138
- }];
139
- }
140
-
141
- return response;
142
- };
143
- ```
144
-
145
- ## Migration from Cloudflare Workers
146
-
147
- ### Before (Cloudflare Workers)
148
- ```typescript
149
- import { getABVariant } from '@cuemath/web-utils';
150
-
151
- const result = getABVariant(
152
- request.url,
153
- 'US',
154
- currentVariants,
155
- lastLanding,
156
- 'debug_ab',
157
- request.headers.get('Cookie') // String
158
- );
159
- ```
160
-
161
- ### After (CloudFront Lambda@Edge)
162
- ```typescript
163
- import {
164
- parseCloudFrontCookies,
165
- getABVariantFromCookies
166
- } from '@cuemath/web-utils/cloudfront';
167
-
168
- // CloudFront provides cookies as header array
169
- const cookies = parseCloudFrontCookies(
170
- event.Records[0].cf.request.headers.cookie
171
- );
172
-
173
- const result = getABVariantFromCookies(
174
- request.uri,
175
- 'US',
176
- currentVariants,
177
- lastLanding,
178
- cookies, // Object
179
- 'debug_ab'
180
- );
181
- ```
182
-
183
- **Key Differences:**
184
- 1. CloudFront cookies are header arrays, not strings
185
- 2. Use `parseCloudFrontCookies()` to convert to object
186
- 3. Use `getABVariantFromCookies()` instead of `getABVariant()`
187
- 4. CloudFront request URI instead of full URL
188
- 5. Country from `cloudfront-viewer-country` header
189
-
190
- ## Bundle Sizes
191
-
192
- | Entry Point | Gzipped | Uncompressed | Lambda@Edge Limit |
193
- |-------------|---------|--------------|-------------------|
194
- | CloudFront | 18 KB | ~60 KB | 1 MB (1.8% used) |
195
- | Browser | 22 KB | ~90 KB | N/A |
196
- | Main | 24 KB | ~95 KB | N/A |
197
- | Timezone | 4 KB | ~12 KB | N/A |
198
-
199
- All entry points are **well within Lambda@Edge limits** for origin-request handlers!
200
-
201
- ## Breaking Changes (v2.0.0)
202
-
203
- ### 1. Node.js 18+ Required
204
- ```json
205
- {
206
- "engines": {
207
- "node": ">=18.0.0"
208
- }
209
- }
210
- ```
211
-
212
- ### 2. Timezone Functions Separated
213
- ```typescript
214
- // ❌ Old (v1.x)
215
- import { dateByTimezone } from '@cuemath/web-utils';
216
-
217
- // ✅ New (v2.x)
218
- import { dateByTimezone } from '@cuemath/web-utils/date-time-helper/timezone';
219
- ```
220
-
221
- ### 3. New CloudFront Entry Point
222
- ```typescript
223
- // ✅ New in v2.0
224
- import { parseCloudFrontCookies, getABVariantFromCookies } from '@cuemath/web-utils/cloudfront';
225
- ```
226
-
227
- ### 4. Export Paths Changed
228
- ```typescript
229
- // ❌ Old (v1.x)
230
- import utils from '@cuemath/web-utils';
231
-
232
- // ✅ New (v2.x) - Named imports only
233
- import { formatDateTime } from '@cuemath/web-utils';
234
- ```
235
-
236
- ## API Reference
237
-
238
- ### Cookie Utilities
239
-
240
- #### `parseCookieString(cookieString: string): Record<string, string>`
241
- Parse a cookie string into key-value object. Works with Cloudflare Workers and browser `document.cookie`.
242
-
243
- #### `parseCloudFrontCookies(headers: Array<{key: string, value: string}>): Record<string, string>`
244
- Parse CloudFront cookie headers (handles multiple Cookie headers). **First occurrence takes priority.**
245
-
246
- #### `getCookie(name: string, cookie?: string): string`
247
- Get a specific cookie value. Works in both browser and server contexts.
248
-
249
- ### A/B Testing
250
-
251
- #### `getABVariantFromCookies(...): { isABExperimentsUpdated: boolean, abExperiment: Record<string, string> }`
252
- Lambda@Edge optimized A/B variant assignment. Accepts pre-parsed cookies.
253
-
254
- **Parameters:**
255
- - `url: string` - Request URL/path
256
- - `countryCode: string` - ISO country code
257
- - `currentABVariant: Record<string, string>` - Current assignments
258
- - `lastLandingPageCookies: { value: string, createdAt: string }` - Landing page data
259
- - `parsedCookies: Record<string, string>` - Pre-parsed cookie object
260
- - `debugABCookieName: string` - Debug cookie name
261
-
262
- #### `getABExperimentCacheKey(experiments: Record<string, string>): string`
263
- Generate CloudFront cache key from A/B experiments. Returns sorted `key=value&key=value` string.
264
-
265
- ### Date/Time Helpers (Core)
266
-
267
- #### `formatDateTime(dateTime, format): string`
268
- Format dates using dayjs format strings.
269
-
270
- #### `getCurrentTimestamp(): number`
271
- Get current Unix timestamp in seconds.
272
-
273
- #### `convertTimeStampToSeconds(timestamp): number`
274
- Normalize millisecond timestamps to seconds.
275
-
276
- ### Date/Time Helpers (Timezone - Optional)
277
-
278
- #### `dateByTimezone(timestamp, timezone, format): string`
279
- Format timestamp with IANA timezone support.
280
-
281
- #### `getTimezone(): string`
282
- Get browser's IANA timezone identifier.
283
-
284
- ## Performance Tips
285
-
286
- ### 1. Import from Specific Entry Points
287
- ```typescript
288
- // ✅ Good - Only CloudFront bundle (18KB)
289
- import { parseCloudFrontCookies } from '@cuemath/web-utils/cloudfront';
290
-
291
- // ❌ Avoid - Pulls in entire package
292
- import { parseCloudFrontCookies } from '@cuemath/web-utils';
293
- ```
294
-
295
- ### 2. Avoid Timezone Functions in Lambda@Edge
296
- ```typescript
297
- // ✅ Good - No timezone dependencies (saves ~7KB)
298
- import { formatDateTime } from '@cuemath/web-utils/cloudfront';
299
-
300
- // ❌ Avoid - Adds timezone data bundle
301
- import { dateByTimezone } from '@cuemath/web-utils/date-time-helper/timezone';
302
- ```
303
-
304
- ### 3. Use Tree-Shaking
305
- ```typescript
306
- // ✅ Good - Only imports what you use
307
- import { ISO_COUNTRY_CODE } from '@cuemath/web-utils/cloudfront';
308
-
309
- // ❌ Avoid - Imports everything
310
- import * as utils from '@cuemath/web-utils';
311
- ```
312
-
313
- ## Development
314
-
315
- ```bash
316
- # Install dependencies
317
- yarn install
318
-
319
- # Build all entry points
320
- yarn build
321
-
322
- # Watch mode
323
- yarn build:watch
324
-
325
- # Check bundle sizes
326
- yarn size
327
-
328
- # Analyze bundles
329
- yarn build:analyze
330
- ```
331
-
332
- ## License
333
-
334
- ISC
1
+ ### Shared UI utils package
@@ -0,0 +1,2 @@
1
+ export { COUNTRY_NAME_COUNTRY_CODE_MAP as ISO_COUNTRY_CODE } from './iso-country-code';
2
+ export declare const CUE_COUNTRY_CODE_KEY = "cue_country_code";
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CUE_COUNTRY_CODE_KEY = exports.ISO_COUNTRY_CODE = void 0;
4
+ var iso_country_code_1 = require("./iso-country-code");
5
+ Object.defineProperty(exports, "ISO_COUNTRY_CODE", { enumerable: true, get: function () { return iso_country_code_1.COUNTRY_NAME_COUNTRY_CODE_MAP; } });
6
+ exports.CUE_COUNTRY_CODE_KEY = 'cue_country_code';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/constants/country/index.ts"],"names":[],"mappings":";;;AAAA,uDAAuF;AAA9E,oHAAA,6BAA6B,OAAoB;AAC7C,QAAA,oBAAoB,GAAG,kBAAkB,CAAC"}
@@ -0,0 +1,248 @@
1
+ export declare const COUNTRY_NAME_COUNTRY_CODE_MAP: {
2
+ AFGHANISTAN: string;
3
+ 'ALAND ISLANDS': string;
4
+ ALBANIA: string;
5
+ ALGERIA: string;
6
+ 'AMERICAN SAMOA': string;
7
+ ANDORRA: string;
8
+ ANGOLA: string;
9
+ ANGUILLA: string;
10
+ ANTARCTICA: string;
11
+ 'ANTIGUA AND BARBUDA': string;
12
+ ARGENTINA: string;
13
+ ARMENIA: string;
14
+ ARUBA: string;
15
+ AUSTRALIA: string;
16
+ AUSTRIA: string;
17
+ AZERBAIJAN: string;
18
+ BAHAMAS: string;
19
+ BAHRAIN: string;
20
+ BANGLADESH: string;
21
+ BARBADOS: string;
22
+ BELARUS: string;
23
+ BELGIUM: string;
24
+ BELIZE: string;
25
+ BENIN: string;
26
+ BERMUDA: string;
27
+ BHUTAN: string;
28
+ BOLIVIA: string;
29
+ 'BOSNIA AND HERZEGOVINA': string;
30
+ BOTSWANA: string;
31
+ 'BOUVET ISLAND': string;
32
+ BRAZIL: string;
33
+ 'BRITISH INDIAN OCEAN TERRITORY': string;
34
+ 'BRUNEI DARUSSALAM': string;
35
+ BULGARIA: string;
36
+ 'BURKINA FASO': string;
37
+ BURUNDI: string;
38
+ CAMBODIA: string;
39
+ CAMEROON: string;
40
+ CANADA: string;
41
+ 'CAPE VERDE': string;
42
+ 'CAYMAN ISLANDS': string;
43
+ 'CENTRAL AFRICAN REPUBLIC': string;
44
+ CHAD: string;
45
+ CHILE: string;
46
+ CHINA: string;
47
+ 'CHRISTMAS ISLAND': string;
48
+ 'COCOS (KEELING) ISLANDS': string;
49
+ COLOMBIA: string;
50
+ COMOROS: string;
51
+ CONGO: string;
52
+ 'CONGO, DEMOCRATIC REPUBLIC': string;
53
+ 'COOK ISLANDS': string;
54
+ 'COSTA RICA': string;
55
+ 'COTE D"IVOIRE': string;
56
+ CROATIA: string;
57
+ CUBA: string;
58
+ CYPRUS: string;
59
+ 'CZECH REPUBLIC': string;
60
+ DENMARK: string;
61
+ DJIBOUTI: string;
62
+ DOMINICA: string;
63
+ 'DOMINICAN REPUBLIC': string;
64
+ ECUADOR: string;
65
+ EGYPT: string;
66
+ 'EL SALVADOR': string;
67
+ 'EQUATORIAL GUINEA': string;
68
+ ERITREA: string;
69
+ ESTONIA: string;
70
+ ETHIOPIA: string;
71
+ 'FALKLAND ISLANDS (MALVINAS)': string;
72
+ 'FAROE ISLANDS': string;
73
+ FIJI: string;
74
+ FINLAND: string;
75
+ FRANCE: string;
76
+ 'FRENCH GUIANA': string;
77
+ 'FRENCH POLYNESIA': string;
78
+ 'FRENCH SOUTHERN TERRITORIES': string;
79
+ GABON: string;
80
+ GAMBIA: string;
81
+ GEORGIA: string;
82
+ GERMANY: string;
83
+ GHANA: string;
84
+ GIBRALTAR: string;
85
+ GREECE: string;
86
+ GREENLAND: string;
87
+ GRENADA: string;
88
+ GUADELOUPE: string;
89
+ GUAM: string;
90
+ GUATEMALA: string;
91
+ GUERNSEY: string;
92
+ GUINEA: string;
93
+ 'GUINEA-BISSAU': string;
94
+ GUYANA: string;
95
+ HAITI: string;
96
+ 'HEARD ISLAND & MCDONALD ISLANDS': string;
97
+ 'HOLY SEE (VATICAN CITY STATE)': string;
98
+ HONDURAS: string;
99
+ 'HONG KONG': string;
100
+ HUNGARY: string;
101
+ ICELAND: string;
102
+ INDIA: string;
103
+ INDONESIA: string;
104
+ 'IRAN, ISLAMIC REPUBLIC OF': string;
105
+ IRAQ: string;
106
+ IRELAND: string;
107
+ 'ISLE OF MAN': string;
108
+ ISRAEL: string;
109
+ ITALY: string;
110
+ JAMAICA: string;
111
+ JAPAN: string;
112
+ JERSEY: string;
113
+ JORDAN: string;
114
+ KAZAKHSTAN: string;
115
+ KENYA: string;
116
+ KIRIBATI: string;
117
+ KOREA: string;
118
+ 'NORTH KOREA': string;
119
+ KUWAIT: string;
120
+ KYRGYZSTAN: string;
121
+ 'LAO PEOPLE"S DEMOCRATIC REPUBLIC': string;
122
+ LATVIA: string;
123
+ LEBANON: string;
124
+ LESOTHO: string;
125
+ LIBERIA: string;
126
+ 'LIBYAN ARAB JAMAHIRIYA': string;
127
+ LIECHTENSTEIN: string;
128
+ LITHUANIA: string;
129
+ LUXEMBOURG: string;
130
+ MACAO: string;
131
+ MACEDONIA: string;
132
+ MADAGASCAR: string;
133
+ MALAWI: string;
134
+ MALAYSIA: string;
135
+ MALDIVES: string;
136
+ MALI: string;
137
+ MALTA: string;
138
+ 'MARSHALL ISLANDS': string;
139
+ MARTINIQUE: string;
140
+ MAURITANIA: string;
141
+ MAURITIUS: string;
142
+ MAYOTTE: string;
143
+ MEXICO: string;
144
+ 'MICRONESIA, FEDERATED STATES OF': string;
145
+ MOLDOVA: string;
146
+ MONACO: string;
147
+ MONGOLIA: string;
148
+ MONTENEGRO: string;
149
+ MONTSERRAT: string;
150
+ MOROCCO: string;
151
+ MOZAMBIQUE: string;
152
+ MYANMAR: string;
153
+ NAMIBIA: string;
154
+ NAURU: string;
155
+ NEPAL: string;
156
+ NETHERLANDS: string;
157
+ 'NETHERLANDS ANTILLES': string;
158
+ 'NEW CALEDONIA': string;
159
+ 'NEW ZEALAND': string;
160
+ NICARAGUA: string;
161
+ NIGER: string;
162
+ NIGERIA: string;
163
+ NIUE: string;
164
+ 'NORFOLK ISLAND': string;
165
+ 'NORTHERN MARIANA ISLANDS': string;
166
+ NORWAY: string;
167
+ OMAN: string;
168
+ PAKISTAN: string;
169
+ PALAU: string;
170
+ 'PALESTINIAN TERRITORY, OCCUPIED': string;
171
+ PANAMA: string;
172
+ 'PAPUA NEW GUINEA': string;
173
+ PARAGUAY: string;
174
+ PERU: string;
175
+ PHILIPPINES: string;
176
+ PITCAIRN: string;
177
+ POLAND: string;
178
+ PORTUGAL: string;
179
+ 'PUERTO RICO': string;
180
+ QATAR: string;
181
+ REUNION: string;
182
+ ROMANIA: string;
183
+ 'RUSSIAN FEDERATION': string;
184
+ RWANDA: string;
185
+ 'SAINT BARTHELEMY': string;
186
+ 'SAINT HELENA': string;
187
+ 'SAINT KITTS AND NEVIS': string;
188
+ 'SAINT LUCIA': string;
189
+ 'SAINT MARTIN': string;
190
+ 'SAINT PIERRE AND MIQUELON': string;
191
+ 'SAINT VINCENT AND GRENADINES': string;
192
+ SAMOA: string;
193
+ 'SAN MARINO': string;
194
+ 'SAO TOME AND PRINCIPE': string;
195
+ 'SAUDI ARABIA': string;
196
+ SENEGAL: string;
197
+ SERBIA: string;
198
+ SEYCHELLES: string;
199
+ 'SIERRA LEONE': string;
200
+ SINGAPORE: string;
201
+ SLOVAKIA: string;
202
+ SLOVENIA: string;
203
+ 'SOLOMON ISLANDS': string;
204
+ SOMALIA: string;
205
+ 'SOUTH AFRICA': string;
206
+ 'SOUTH GEORGIA AND SANDWICH ISL.': string;
207
+ SPAIN: string;
208
+ 'SRI LANKA': string;
209
+ SUDAN: string;
210
+ SURINAME: string;
211
+ 'SVALBARD AND JAN MAYEN': string;
212
+ SWAZILAND: string;
213
+ SWEDEN: string;
214
+ SWITZERLAND: string;
215
+ 'SYRIAN ARAB REPUBLIC': string;
216
+ TAIWAN: string;
217
+ TAJIKISTAN: string;
218
+ TANZANIA: string;
219
+ THAILAND: string;
220
+ 'TIMOR-LESTE': string;
221
+ TOGO: string;
222
+ TOKELAU: string;
223
+ TONGA: string;
224
+ 'TRINIDAD AND TOBAGO': string;
225
+ TUNISIA: string;
226
+ TURKEY: string;
227
+ TURKMENISTAN: string;
228
+ 'TURKS AND CAICOS ISLANDS': string;
229
+ TUVALU: string;
230
+ UGANDA: string;
231
+ UKRAINE: string;
232
+ 'UNITED ARAB EMIRATES': string;
233
+ 'UNITED KINGDOM': string;
234
+ 'UNITED STATES': string;
235
+ 'UNITED STATES OUTLYING ISLANDS': string;
236
+ URUGUAY: string;
237
+ UZBEKISTAN: string;
238
+ VANUATU: string;
239
+ VENEZUELA: string;
240
+ VIETNAM: string;
241
+ 'VIRGIN ISLANDS, BRITISH': string;
242
+ 'VIRGIN ISLANDS, U.S.': string;
243
+ 'WALLIS AND FUTUNA': string;
244
+ 'WESTERN SAHARA': string;
245
+ YEMEN: string;
246
+ ZAMBIA: string;
247
+ ZIMBABWE: string;
248
+ };