@adtrackify/at-service-common 4.0.3 → 4.0.4

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 (753) hide show
  1. package/dist/cjs/__tests__/clients/acuity-client.spec.d.ts +1 -1
  2. package/dist/cjs/__tests__/clients/acuity-client.spec.js +43 -43
  3. package/dist/cjs/__tests__/clients/cross-platform-compression.spec.d.ts +1 -1
  4. package/dist/cjs/__tests__/clients/cross-platform-compression.spec.js +354 -354
  5. package/dist/cjs/__tests__/clients/dynamodb-client.spec.d.ts +1 -1
  6. package/dist/cjs/__tests__/clients/dynamodb-client.spec.js +194 -194
  7. package/dist/cjs/__tests__/clients/sqs-bundled-client.spec.d.ts +1 -1
  8. package/dist/cjs/__tests__/clients/sqs-bundled-client.spec.js +931 -931
  9. package/dist/cjs/__tests__/clients/sqs-bundling-contracts.spec.d.ts +1 -1
  10. package/dist/cjs/__tests__/clients/sqs-bundling-contracts.spec.js +563 -563
  11. package/dist/cjs/__tests__/clients/sqs-client.spec.d.ts +1 -1
  12. package/dist/cjs/__tests__/clients/sqs-client.spec.js +191 -191
  13. package/dist/cjs/__tests__/clients/sqs-unbundle.spec.d.ts +1 -1
  14. package/dist/cjs/__tests__/clients/sqs-unbundle.spec.js +1357 -1357
  15. package/dist/cjs/__tests__/db/contact-enrichments-db-service.spec.d.ts +1 -1
  16. package/dist/cjs/__tests__/db/contact-enrichments-db-service.spec.js +68 -68
  17. package/dist/cjs/__tests__/db/destinations-db-service.spec.d.ts +1 -1
  18. package/dist/cjs/__tests__/db/destinations-db-service.spec.js +125 -125
  19. package/dist/cjs/__tests__/db/products-db-service.spec.d.ts +1 -0
  20. package/dist/cjs/__tests__/db/products-db-service.spec.js +90 -0
  21. package/dist/cjs/__tests__/db/products-db-service.spec.js.map +1 -0
  22. package/dist/cjs/__tests__/db/shared-read-db-services.spec.d.ts +1 -1
  23. package/dist/cjs/__tests__/db/shared-read-db-services.spec.js +89 -89
  24. package/dist/cjs/__tests__/db/shopify-app-installs-db-service.spec.d.ts +1 -1
  25. package/dist/cjs/__tests__/db/shopify-app-installs-db-service.spec.js +104 -104
  26. package/dist/cjs/__tests__/db/subscriptions-db-service.spec.d.ts +1 -1
  27. package/dist/cjs/__tests__/db/subscriptions-db-service.spec.js +95 -95
  28. package/dist/cjs/__tests__/db/user-accounts-db-service.spec.d.ts +1 -1
  29. package/dist/cjs/__tests__/db/user-accounts-db-service.spec.js +76 -76
  30. package/dist/cjs/__tests__/helpers/account-users-helper.spec.d.ts +1 -1
  31. package/dist/cjs/__tests__/helpers/account-users-helper.spec.js +220 -220
  32. package/dist/cjs/__tests__/helpers/acuity-helper.spec.d.ts +1 -1
  33. package/dist/cjs/__tests__/helpers/acuity-helper.spec.js +69 -69
  34. package/dist/cjs/__tests__/helpers/api-key-auth-helper.spec.d.ts +1 -1
  35. package/dist/cjs/__tests__/helpers/api-key-auth-helper.spec.js +82 -82
  36. package/dist/cjs/__tests__/identity-cache/identity-cache-db-service.spec.d.ts +1 -1
  37. package/dist/cjs/__tests__/identity-cache/identity-cache-db-service.spec.js +676 -676
  38. package/dist/cjs/__tests__/identity-cache/identity-cache-dynamodb-service.spec.d.ts +1 -1
  39. package/dist/cjs/__tests__/identity-cache/identity-cache-dynamodb-service.spec.js +1140 -1140
  40. package/dist/cjs/__tests__/identity-cache/identity-cache-tier-routing.spec.d.ts +1 -1
  41. package/dist/cjs/__tests__/identity-cache/identity-cache-tier-routing.spec.js +851 -851
  42. package/dist/cjs/__tests__/identity-cache/trait-merging-and-staleness.spec.d.ts +1 -1
  43. package/dist/cjs/__tests__/identity-cache/trait-merging-and-staleness.spec.js +1060 -1060
  44. package/dist/cjs/__tests__/identity-cache/volatile-traits-optimization.spec.d.ts +1 -1
  45. package/dist/cjs/__tests__/identity-cache/volatile-traits-optimization.spec.js +818 -818
  46. package/dist/cjs/__tests__/integration/sqs-bundling-roundtrip.spec.d.ts +1 -1
  47. package/dist/cjs/__tests__/integration/sqs-bundling-roundtrip.spec.js +584 -584
  48. package/dist/cjs/__tests__/libs/compress-decompress.spec.d.ts +1 -1
  49. package/dist/cjs/__tests__/libs/compress-decompress.spec.js +16 -16
  50. package/dist/cjs/__tests__/libs/contacts.spec.d.ts +1 -1
  51. package/dist/cjs/__tests__/libs/contacts.spec.js +294 -294
  52. package/dist/cjs/__tests__/libs/currency.spec.d.ts +1 -1
  53. package/dist/cjs/__tests__/libs/currency.spec.js +220 -220
  54. package/dist/cjs/__tests__/libs/dates.spec.d.ts +1 -1
  55. package/dist/cjs/__tests__/libs/dates.spec.js +130 -130
  56. package/dist/cjs/__tests__/libs/domain.spec.d.ts +1 -1
  57. package/dist/cjs/__tests__/libs/domain.spec.js +107 -107
  58. package/dist/cjs/__tests__/libs/numbers.spec.d.ts +1 -1
  59. package/dist/cjs/__tests__/libs/numbers.spec.js +261 -261
  60. package/dist/cjs/__tests__/s3-client/s3-client.spec.d.ts +1 -1
  61. package/dist/cjs/__tests__/s3-client/s3-client.spec.js +33 -33
  62. package/dist/cjs/__tests__/services/acuity-api-service.spec.d.ts +1 -1
  63. package/dist/cjs/__tests__/services/acuity-api-service.spec.js +71 -71
  64. package/dist/cjs/__tests__/services/cost/cost-calculation-types.spec.d.ts +1 -0
  65. package/dist/cjs/__tests__/services/cost/cost-calculation-types.spec.js +24 -0
  66. package/dist/cjs/__tests__/services/cost/cost-calculation-types.spec.js.map +1 -0
  67. package/dist/cjs/__tests__/services/cost/cost-calculator-service.spec.d.ts +1 -0
  68. package/dist/cjs/__tests__/services/cost/cost-calculator-service.spec.js +3320 -0
  69. package/dist/cjs/__tests__/services/cost/cost-calculator-service.spec.js.map +1 -0
  70. package/dist/cjs/__tests__/services/cost/cost-currency-service.spec.d.ts +1 -0
  71. package/dist/cjs/__tests__/services/cost/cost-currency-service.spec.js +115 -0
  72. package/dist/cjs/__tests__/services/cost/cost-currency-service.spec.js.map +1 -0
  73. package/dist/cjs/__tests__/services/cost/cost-filter-service.spec.d.ts +1 -0
  74. package/dist/cjs/__tests__/services/cost/cost-filter-service.spec.js +469 -0
  75. package/dist/cjs/__tests__/services/cost/cost-filter-service.spec.js.map +1 -0
  76. package/dist/cjs/__tests__/services/cost/order-cost/order-cost-resolution-service.spec.d.ts +1 -0
  77. package/dist/cjs/__tests__/services/cost/order-cost/order-cost-resolution-service.spec.js +207 -0
  78. package/dist/cjs/__tests__/services/cost/order-cost/order-cost-resolution-service.spec.js.map +1 -0
  79. package/dist/cjs/__tests__/services/currency-exchange-rate-lookup-service.spec.d.ts +1 -0
  80. package/dist/cjs/__tests__/services/currency-exchange-rate-lookup-service.spec.js +35 -0
  81. package/dist/cjs/__tests__/services/currency-exchange-rate-lookup-service.spec.js.map +1 -0
  82. package/dist/cjs/__tests__/services/email-verification/contact-email-verification-service.spec.d.ts +1 -1
  83. package/dist/cjs/__tests__/services/email-verification/contact-email-verification-service.spec.js +93 -93
  84. package/dist/cjs/__tests__/services/email-verification/email-verification-service.spec.d.ts +1 -1
  85. package/dist/cjs/__tests__/services/email-verification/email-verification-service.spec.js +57 -57
  86. package/dist/cjs/__tests__/shopify/shopify-graphql-transformer.spec.d.ts +1 -1
  87. package/dist/cjs/__tests__/shopify/shopify-graphql-transformer.spec.js +35 -35
  88. package/dist/cjs/__tests__/unit/libs/api-router/public-api-router.spec.d.ts +1 -1
  89. package/dist/cjs/__tests__/unit/libs/api-router/public-api-router.spec.js +181 -181
  90. package/dist/cjs/__tests__/unit/libs/api-router/route-matcher.spec.d.ts +1 -1
  91. package/dist/cjs/__tests__/unit/libs/api-router/route-matcher.spec.js +69 -69
  92. package/dist/cjs/__tests__/utils/custom-measure-formula-utils.spec.d.ts +1 -1
  93. package/dist/cjs/__tests__/utils/custom-measure-formula-utils.spec.js +139 -139
  94. package/dist/cjs/clients/generic/cognito-client.d.ts +23 -23
  95. package/dist/cjs/clients/generic/cognito-client.js +209 -209
  96. package/dist/cjs/clients/generic/dynamodb-client.d.ts +20 -20
  97. package/dist/cjs/clients/generic/dynamodb-client.js +235 -235
  98. package/dist/cjs/clients/generic/eventbridge-client.d.ts +14 -14
  99. package/dist/cjs/clients/generic/eventbridge-client.js +51 -51
  100. package/dist/cjs/clients/generic/http-client.d.ts +14 -14
  101. package/dist/cjs/clients/generic/http-client.js +61 -61
  102. package/dist/cjs/clients/generic/index.d.ts +13 -13
  103. package/dist/cjs/clients/generic/index.js +29 -29
  104. package/dist/cjs/clients/generic/lambda-invoke-client.d.ts +10 -10
  105. package/dist/cjs/clients/generic/lambda-invoke-client.js +39 -39
  106. package/dist/cjs/clients/generic/location-client.d.ts +8 -8
  107. package/dist/cjs/clients/generic/location-client.js +31 -31
  108. package/dist/cjs/clients/generic/redis-client.d.ts +33 -33
  109. package/dist/cjs/clients/generic/redis-client.js +191 -191
  110. package/dist/cjs/clients/generic/s3-client.d.ts +23 -23
  111. package/dist/cjs/clients/generic/s3-client.js +216 -216
  112. package/dist/cjs/clients/generic/singlestore-db-client.d.ts +14 -14
  113. package/dist/cjs/clients/generic/singlestore-db-client.js +67 -67
  114. package/dist/cjs/clients/generic/sqs-bundled-client.d.ts +15 -15
  115. package/dist/cjs/clients/generic/sqs-bundled-client.js +311 -311
  116. package/dist/cjs/clients/generic/sqs-bundled-client.types.d.ts +53 -53
  117. package/dist/cjs/clients/generic/sqs-bundled-client.types.js +17 -17
  118. package/dist/cjs/clients/generic/sqs-client.d.ts +53 -53
  119. package/dist/cjs/clients/generic/sqs-client.js +285 -285
  120. package/dist/cjs/clients/generic/sqs-unbundle.d.ts +32 -32
  121. package/dist/cjs/clients/generic/sqs-unbundle.js +144 -144
  122. package/dist/cjs/clients/index.d.ts +3 -3
  123. package/dist/cjs/clients/index.js +19 -19
  124. package/dist/cjs/clients/internal-api/accounts-client.d.ts +91 -91
  125. package/dist/cjs/clients/internal-api/accounts-client.js +129 -129
  126. package/dist/cjs/clients/internal-api/cache-lambda-client.d.ts +26 -26
  127. package/dist/cjs/clients/internal-api/cache-lambda-client.js +89 -89
  128. package/dist/cjs/clients/internal-api/db-management-client.d.ts +18 -18
  129. package/dist/cjs/clients/internal-api/db-management-client.js +36 -36
  130. package/dist/cjs/clients/internal-api/destinations-client.d.ts +34 -34
  131. package/dist/cjs/clients/internal-api/destinations-client.js +79 -79
  132. package/dist/cjs/clients/internal-api/event-collector-client.d.ts +20 -20
  133. package/dist/cjs/clients/internal-api/event-collector-client.js +36 -36
  134. package/dist/cjs/clients/internal-api/identity-client.d.ts +31 -31
  135. package/dist/cjs/clients/internal-api/identity-client.js +91 -91
  136. package/dist/cjs/clients/internal-api/index.d.ts +9 -9
  137. package/dist/cjs/clients/internal-api/index.js +25 -25
  138. package/dist/cjs/clients/internal-api/shopify-app-install-client.d.ts +37 -37
  139. package/dist/cjs/clients/internal-api/shopify-app-install-client.js +81 -81
  140. package/dist/cjs/clients/internal-api/subscriptions-client.d.ts +26 -26
  141. package/dist/cjs/clients/internal-api/subscriptions-client.js +77 -77
  142. package/dist/cjs/clients/internal-api/users-auth-client.d.ts +35 -35
  143. package/dist/cjs/clients/internal-api/users-auth-client.js +110 -110
  144. package/dist/cjs/clients/third-party/acuity-client.d.ts +10 -10
  145. package/dist/cjs/clients/third-party/acuity-client.js +40 -40
  146. package/dist/cjs/clients/third-party/emailable-client.d.ts +7 -7
  147. package/dist/cjs/clients/third-party/emailable-client.js +25 -25
  148. package/dist/cjs/clients/third-party/exchange-rate-api-client.d.ts +17 -17
  149. package/dist/cjs/clients/third-party/exchange-rate-api-client.js +19 -19
  150. package/dist/cjs/clients/third-party/index.d.ts +5 -5
  151. package/dist/cjs/clients/third-party/index.js +21 -21
  152. package/dist/cjs/clients/third-party/loops-client.d.ts +10 -10
  153. package/dist/cjs/clients/third-party/loops-client.js +30 -30
  154. package/dist/cjs/clients/third-party/shopify/graphql-order-queries.d.ts +25 -25
  155. package/dist/cjs/clients/third-party/shopify/graphql-order-queries.js +4 -4
  156. package/dist/cjs/clients/third-party/shopify/graphql-product-queries.d.ts +2 -2
  157. package/dist/cjs/clients/third-party/shopify/graphql-product-queries.js +5 -5
  158. package/dist/cjs/clients/third-party/shopify/shopify-graphql-client.d.ts +10 -10
  159. package/dist/cjs/clients/third-party/shopify/shopify-graphql-client.js +161 -161
  160. package/dist/cjs/clients/third-party/shopify-client.d.ts +29 -29
  161. package/dist/cjs/clients/third-party/shopify-client.js +146 -146
  162. package/dist/cjs/constants/index.d.ts +1 -1
  163. package/dist/cjs/constants/index.js +17 -17
  164. package/dist/cjs/constants/sqs.d.ts +20 -20
  165. package/dist/cjs/constants/sqs.js +26 -26
  166. package/dist/cjs/helpers/account-users-helper.d.ts +2 -2
  167. package/dist/cjs/helpers/account-users-helper.js +22 -22
  168. package/dist/cjs/helpers/acuity-helper.d.ts +4 -4
  169. package/dist/cjs/helpers/acuity-helper.js +56 -56
  170. package/dist/cjs/helpers/api-key-auth-helper.d.ts +9 -9
  171. package/dist/cjs/helpers/api-key-auth-helper.js +40 -40
  172. package/dist/cjs/helpers/api-key-authorizer-helper.d.ts +36 -36
  173. package/dist/cjs/helpers/api-key-authorizer-helper.js +87 -87
  174. package/dist/cjs/helpers/identity-cache-helper.d.ts +30 -30
  175. package/dist/cjs/helpers/identity-cache-helper.js +253 -253
  176. package/dist/cjs/helpers/index.d.ts +10 -10
  177. package/dist/cjs/helpers/index.js +26 -26
  178. package/dist/cjs/helpers/input-validation-helper.d.ts +3 -3
  179. package/dist/cjs/helpers/input-validation-helper.js +22 -22
  180. package/dist/cjs/helpers/logging-helper.d.ts +16 -16
  181. package/dist/cjs/helpers/logging-helper.js +84 -84
  182. package/dist/cjs/helpers/response-helper.d.ts +18 -18
  183. package/dist/cjs/helpers/response-helper.js +43 -43
  184. package/dist/cjs/helpers/shopify-helper.d.ts +9 -9
  185. package/dist/cjs/helpers/shopify-helper.js +26 -26
  186. package/dist/cjs/helpers/sqs-utils.d.ts +6 -6
  187. package/dist/cjs/helpers/sqs-utils.js +14 -14
  188. package/dist/cjs/index.d.ts +7 -7
  189. package/dist/cjs/index.js +23 -23
  190. package/dist/cjs/libs/api-router/index.d.ts +2 -2
  191. package/dist/cjs/libs/api-router/index.js +18 -18
  192. package/dist/cjs/libs/api-router/public-api-router.d.ts +3 -3
  193. package/dist/cjs/libs/api-router/public-api-router.js +36 -36
  194. package/dist/cjs/libs/api-router/route-matcher.d.ts +21 -21
  195. package/dist/cjs/libs/api-router/route-matcher.js +36 -36
  196. package/dist/cjs/libs/click-id-parser.d.ts +23 -23
  197. package/dist/cjs/libs/click-id-parser.js +49 -49
  198. package/dist/cjs/libs/compression.d.ts +2 -2
  199. package/dist/cjs/libs/compression.js +33 -33
  200. package/dist/cjs/libs/contacts.d.ts +7 -7
  201. package/dist/cjs/libs/contacts.js +152 -152
  202. package/dist/cjs/libs/cookie.d.ts +17 -17
  203. package/dist/cjs/libs/cookie.js +76 -76
  204. package/dist/cjs/libs/crypto.d.ts +4 -4
  205. package/dist/cjs/libs/crypto.js +25 -25
  206. package/dist/cjs/libs/csv.d.ts +2 -2
  207. package/dist/cjs/libs/csv.js +35 -35
  208. package/dist/cjs/libs/currency.d.ts +1 -1
  209. package/dist/cjs/libs/currency.js +29 -29
  210. package/dist/cjs/libs/dates.d.ts +12 -12
  211. package/dist/cjs/libs/dates.js +96 -96
  212. package/dist/cjs/libs/domain.d.ts +2 -2
  213. package/dist/cjs/libs/domain.js +38 -38
  214. package/dist/cjs/libs/emails.d.ts +8 -8
  215. package/dist/cjs/libs/emails.js +154 -154
  216. package/dist/cjs/libs/http-error.d.ts +21 -21
  217. package/dist/cjs/libs/http-error.js +63 -63
  218. package/dist/cjs/libs/http-status-codes.d.ts +58 -58
  219. package/dist/cjs/libs/http-status-codes.js +62 -62
  220. package/dist/cjs/libs/index.d.ts +19 -19
  221. package/dist/cjs/libs/index.js +35 -35
  222. package/dist/cjs/libs/numbers.d.ts +1 -1
  223. package/dist/cjs/libs/numbers.js +15 -15
  224. package/dist/cjs/libs/referrer-parser/index.d.ts +2 -2
  225. package/dist/cjs/libs/referrer-parser/index.js +18 -18
  226. package/dist/cjs/libs/referrer-parser/referrer-data.d.ts +9 -9
  227. package/dist/cjs/libs/referrer-parser/referrer-data.js +3307 -3307
  228. package/dist/cjs/libs/referrer-parser/referrer-parser-util.d.ts +20 -20
  229. package/dist/cjs/libs/referrer-parser/referrer-parser-util.js +131 -131
  230. package/dist/cjs/libs/strings.d.ts +3 -3
  231. package/dist/cjs/libs/strings.js +46 -46
  232. package/dist/cjs/libs/traits.d.ts +6 -6
  233. package/dist/cjs/libs/traits.js +65 -65
  234. package/dist/cjs/libs/url.d.ts +1 -1
  235. package/dist/cjs/libs/url.js +13 -13
  236. package/dist/cjs/services/acuity-api-service.d.ts +9 -9
  237. package/dist/cjs/services/acuity-api-service.js +73 -73
  238. package/dist/cjs/services/cache/generic-cached-object.d.ts +5 -5
  239. package/dist/cjs/services/cache/generic-cached-object.js +2 -2
  240. package/dist/cjs/services/cache/index.d.ts +1 -1
  241. package/dist/cjs/services/cache/index.js +17 -17
  242. package/dist/cjs/services/cache/product-cache-service.d.ts +21 -21
  243. package/dist/cjs/services/cache/product-cache-service.js +76 -76
  244. package/dist/cjs/services/cost/cost-calculation-types.d.ts +69 -0
  245. package/dist/cjs/services/cost/cost-calculation-types.js +20 -0
  246. package/dist/cjs/services/cost/cost-calculation-types.js.map +1 -0
  247. package/dist/cjs/services/cost/cost-calculator-service.d.ts +24 -0
  248. package/dist/cjs/services/cost/cost-calculator-service.js +457 -0
  249. package/dist/cjs/services/cost/cost-calculator-service.js.map +1 -0
  250. package/dist/cjs/services/cost/cost-currency-service.d.ts +6 -0
  251. package/dist/cjs/services/cost/cost-currency-service.js +88 -0
  252. package/dist/cjs/services/cost/cost-currency-service.js.map +1 -0
  253. package/dist/cjs/services/cost/cost-filter-service.d.ts +10 -0
  254. package/dist/cjs/services/cost/cost-filter-service.js +122 -0
  255. package/dist/cjs/services/cost/cost-filter-service.js.map +1 -0
  256. package/dist/cjs/services/cost/index.d.ts +5 -0
  257. package/dist/cjs/services/cost/index.js +22 -0
  258. package/dist/cjs/services/cost/index.js.map +1 -0
  259. package/dist/cjs/services/cost/order-cost/index.d.ts +2 -0
  260. package/dist/cjs/services/cost/order-cost/index.js +19 -0
  261. package/dist/cjs/services/cost/order-cost/index.js.map +1 -0
  262. package/dist/cjs/services/cost/order-cost/order-cost-resolution-service.d.ts +23 -0
  263. package/dist/cjs/services/cost/order-cost/order-cost-resolution-service.js +362 -0
  264. package/dist/cjs/services/cost/order-cost/order-cost-resolution-service.js.map +1 -0
  265. package/dist/cjs/services/cost/order-cost/order-cost-resolution-types.d.ts +37 -0
  266. package/dist/cjs/services/cost/order-cost/order-cost-resolution-types.js +3 -0
  267. package/dist/cjs/services/cost/order-cost/order-cost-resolution-types.js.map +1 -0
  268. package/dist/cjs/services/currency-exchange-rate-lookup-service.d.ts +12 -11
  269. package/dist/cjs/services/currency-exchange-rate-lookup-service.js +94 -66
  270. package/dist/cjs/services/currency-exchange-rate-lookup-service.js.map +1 -1
  271. package/dist/cjs/services/db/accounts-db-service.d.ts +9 -9
  272. package/dist/cjs/services/db/accounts-db-service.js +33 -33
  273. package/dist/cjs/services/db/api-keys-db-service.d.ts +10 -10
  274. package/dist/cjs/services/db/api-keys-db-service.js +36 -36
  275. package/dist/cjs/services/db/contact-enrichments-db-service.d.ts +15 -15
  276. package/dist/cjs/services/db/contact-enrichments-db-service.js +94 -94
  277. package/dist/cjs/services/db/currency-exchange-rates-db-service.d.ts +21 -21
  278. package/dist/cjs/services/db/currency-exchange-rates-db-service.js +39 -39
  279. package/dist/cjs/services/db/custom-measures-db-service.d.ts +14 -14
  280. package/dist/cjs/services/db/custom-measures-db-service.js +48 -48
  281. package/dist/cjs/services/db/destinations-db-service.d.ts +13 -13
  282. package/dist/cjs/services/db/destinations-db-service.js +74 -74
  283. package/dist/cjs/services/db/identity-cache-db-service.d.ts +28 -28
  284. package/dist/cjs/services/db/identity-cache-db-service.js +320 -320
  285. package/dist/cjs/services/db/identity-cache-dynamodb-service.d.ts +44 -44
  286. package/dist/cjs/services/db/identity-cache-dynamodb-service.js +734 -734
  287. package/dist/cjs/services/db/index.d.ts +19 -17
  288. package/dist/cjs/services/db/index.js +35 -33
  289. package/dist/cjs/services/db/index.js.map +1 -1
  290. package/dist/cjs/services/db/log-events-db-service.d.ts +11 -11
  291. package/dist/cjs/services/db/log-events-db-service.js +181 -181
  292. package/dist/cjs/services/db/pixels-db-service.d.ts +8 -8
  293. package/dist/cjs/services/db/pixels-db-service.js +35 -35
  294. package/dist/cjs/services/db/products-db-service-types.d.ts +10 -0
  295. package/dist/cjs/services/db/products-db-service-types.js +3 -0
  296. package/dist/cjs/services/db/products-db-service-types.js.map +1 -0
  297. package/dist/cjs/services/db/products-db-service.d.ts +19 -0
  298. package/dist/cjs/services/db/products-db-service.js +282 -0
  299. package/dist/cjs/services/db/products-db-service.js.map +1 -0
  300. package/dist/cjs/services/db/purchasable-contacts-db-service.d.ts +9 -9
  301. package/dist/cjs/services/db/purchasable-contacts-db-service.js +43 -43
  302. package/dist/cjs/services/db/purchased-contacts/index.d.ts +2 -2
  303. package/dist/cjs/services/db/purchased-contacts/index.js +18 -18
  304. package/dist/cjs/services/db/purchased-contacts/purchased-contacts-db-service.d.ts +18 -18
  305. package/dist/cjs/services/db/purchased-contacts/purchased-contacts-db-service.js +152 -152
  306. package/dist/cjs/services/db/purchased-contacts/types.d.ts +11 -11
  307. package/dist/cjs/services/db/purchased-contacts/types.js +2 -2
  308. package/dist/cjs/services/db/shopify-app-installs-db-service.d.ts +10 -10
  309. package/dist/cjs/services/db/shopify-app-installs-db-service.js +52 -52
  310. package/dist/cjs/services/db/shopify-products-cache-db-service.d.ts +16 -16
  311. package/dist/cjs/services/db/shopify-products-cache-db-service.js +73 -73
  312. package/dist/cjs/services/db/subscriptions-db-service.d.ts +11 -11
  313. package/dist/cjs/services/db/subscriptions-db-service.js +38 -38
  314. package/dist/cjs/services/db/tracking-events-db-service.d.ts +21 -21
  315. package/dist/cjs/services/db/tracking-events-db-service.js +188 -188
  316. package/dist/cjs/services/db/user-accounts-db-service.d.ts +7 -7
  317. package/dist/cjs/services/db/user-accounts-db-service.js +17 -17
  318. package/dist/cjs/services/email-verification/contact-email-verification-service.d.ts +7 -7
  319. package/dist/cjs/services/email-verification/contact-email-verification-service.js +101 -101
  320. package/dist/cjs/services/email-verification/email-verification-service.d.ts +19 -19
  321. package/dist/cjs/services/email-verification/email-verification-service.js +131 -131
  322. package/dist/cjs/services/email-verification/index.d.ts +2 -2
  323. package/dist/cjs/services/email-verification/index.js +18 -18
  324. package/dist/cjs/services/eventbridge-integration-service.d.ts +9 -9
  325. package/dist/cjs/services/eventbridge-integration-service.js +28 -28
  326. package/dist/cjs/services/events/index.d.ts +3 -3
  327. package/dist/cjs/services/events/index.js +19 -19
  328. package/dist/cjs/services/events/log-event-service.d.ts +19 -19
  329. package/dist/cjs/services/events/log-event-service.js +77 -77
  330. package/dist/cjs/services/events/metric-event-service.d.ts +9 -9
  331. package/dist/cjs/services/events/metric-event-service.js +49 -49
  332. package/dist/cjs/services/events/tracking-event-sqs-service.d.ts +8 -8
  333. package/dist/cjs/services/events/tracking-event-sqs-service.js +34 -34
  334. package/dist/cjs/services/generic-cache-service.d.ts +7 -7
  335. package/dist/cjs/services/generic-cache-service.js +33 -33
  336. package/dist/cjs/services/index.d.ts +11 -10
  337. package/dist/cjs/services/index.js +27 -26
  338. package/dist/cjs/services/index.js.map +1 -1
  339. package/dist/cjs/services/ipdata-lookup-service.d.ts +20 -20
  340. package/dist/cjs/services/ipdata-lookup-service.js +112 -112
  341. package/dist/cjs/services/shopify/index.d.ts +2 -2
  342. package/dist/cjs/services/shopify/index.js +18 -18
  343. package/dist/cjs/services/shopify/products/index.d.ts +1 -1
  344. package/dist/cjs/services/shopify/products/index.js +17 -17
  345. package/dist/cjs/services/shopify/products/shopify-products-serviceV2.d.ts +17 -17
  346. package/dist/cjs/services/shopify/products/shopify-products-serviceV2.js +112 -112
  347. package/dist/cjs/services/shopify/shopify-graphql-transformer.d.ts +8 -8
  348. package/dist/cjs/services/shopify/shopify-graphql-transformer.js +141 -141
  349. package/dist/cjs/types/acuity-types.d.ts +74 -74
  350. package/dist/cjs/types/acuity-types.js +2 -2
  351. package/dist/cjs/types/api-response.d.ts +6 -6
  352. package/dist/cjs/types/api-response.js +2 -2
  353. package/dist/cjs/types/index.d.ts +4 -4
  354. package/dist/cjs/types/index.js +33 -33
  355. package/dist/cjs/types/internal-events/event-detail-types.d.ts +20 -20
  356. package/dist/cjs/types/internal-events/event-detail-types.js +27 -27
  357. package/dist/cjs/types/internal-events/index.d.ts +1 -1
  358. package/dist/cjs/types/internal-events/index.js +17 -17
  359. package/dist/cjs/types/shopify-graphql-types/admin.generated.d.ts +123 -123
  360. package/dist/cjs/types/shopify-graphql-types/admin.generated.js +2 -2
  361. package/dist/cjs/types/shopify-graphql-types/admin.types.d.ts +26289 -26289
  362. package/dist/cjs/types/shopify-graphql-types/admin.types.js +5311 -5311
  363. package/dist/cjs/types/shopify-graphql-types/index.d.ts +2 -2
  364. package/dist/cjs/types/shopify-graphql-types/index.js +18 -18
  365. package/dist/cjs/types/shopify-rest-types.d.ts +767 -767
  366. package/dist/cjs/types/shopify-rest-types.js +2 -2
  367. package/dist/cjs/utils/compression.d.ts +36 -36
  368. package/dist/cjs/utils/compression.js +198 -198
  369. package/dist/cjs/utils/custom-measure-formula-utils.d.ts +6 -6
  370. package/dist/cjs/utils/custom-measure-formula-utils.js +209 -209
  371. package/dist/cjs/utils/index.d.ts +4 -4
  372. package/dist/cjs/utils/index.js +20 -20
  373. package/dist/cjs/utils/retry-envelope.d.ts +12 -12
  374. package/dist/cjs/utils/retry-envelope.js +28 -28
  375. package/dist/cjs/utils/size.d.ts +2 -2
  376. package/dist/cjs/utils/size.js +49 -49
  377. package/dist/esm/__tests__/clients/acuity-client.spec.d.ts +1 -1
  378. package/dist/esm/__tests__/clients/acuity-client.spec.js +41 -41
  379. package/dist/esm/__tests__/clients/cross-platform-compression.spec.d.ts +1 -1
  380. package/dist/esm/__tests__/clients/cross-platform-compression.spec.js +329 -329
  381. package/dist/esm/__tests__/clients/dynamodb-client.spec.d.ts +1 -1
  382. package/dist/esm/__tests__/clients/dynamodb-client.spec.js +192 -192
  383. package/dist/esm/__tests__/clients/sqs-bundled-client.spec.d.ts +1 -1
  384. package/dist/esm/__tests__/clients/sqs-bundled-client.spec.js +906 -906
  385. package/dist/esm/__tests__/clients/sqs-bundling-contracts.spec.d.ts +1 -1
  386. package/dist/esm/__tests__/clients/sqs-bundling-contracts.spec.js +538 -538
  387. package/dist/esm/__tests__/clients/sqs-client.spec.d.ts +1 -1
  388. package/dist/esm/__tests__/clients/sqs-client.spec.js +189 -189
  389. package/dist/esm/__tests__/clients/sqs-unbundle.spec.d.ts +1 -1
  390. package/dist/esm/__tests__/clients/sqs-unbundle.spec.js +1355 -1355
  391. package/dist/esm/__tests__/db/contact-enrichments-db-service.spec.d.ts +1 -1
  392. package/dist/esm/__tests__/db/contact-enrichments-db-service.spec.js +66 -66
  393. package/dist/esm/__tests__/db/destinations-db-service.spec.d.ts +1 -1
  394. package/dist/esm/__tests__/db/destinations-db-service.spec.js +123 -123
  395. package/dist/esm/__tests__/db/products-db-service.spec.d.ts +1 -0
  396. package/dist/esm/__tests__/db/products-db-service.spec.js +88 -0
  397. package/dist/esm/__tests__/db/products-db-service.spec.js.map +1 -0
  398. package/dist/esm/__tests__/db/shared-read-db-services.spec.d.ts +1 -1
  399. package/dist/esm/__tests__/db/shared-read-db-services.spec.js +87 -87
  400. package/dist/esm/__tests__/db/shopify-app-installs-db-service.spec.d.ts +1 -1
  401. package/dist/esm/__tests__/db/shopify-app-installs-db-service.spec.js +102 -102
  402. package/dist/esm/__tests__/db/subscriptions-db-service.spec.d.ts +1 -1
  403. package/dist/esm/__tests__/db/subscriptions-db-service.spec.js +93 -93
  404. package/dist/esm/__tests__/db/user-accounts-db-service.spec.d.ts +1 -1
  405. package/dist/esm/__tests__/db/user-accounts-db-service.spec.js +74 -74
  406. package/dist/esm/__tests__/helpers/account-users-helper.spec.d.ts +1 -1
  407. package/dist/esm/__tests__/helpers/account-users-helper.spec.js +218 -218
  408. package/dist/esm/__tests__/helpers/acuity-helper.spec.d.ts +1 -1
  409. package/dist/esm/__tests__/helpers/acuity-helper.spec.js +67 -67
  410. package/dist/esm/__tests__/helpers/api-key-auth-helper.spec.d.ts +1 -1
  411. package/dist/esm/__tests__/helpers/api-key-auth-helper.spec.js +80 -80
  412. package/dist/esm/__tests__/identity-cache/identity-cache-db-service.spec.d.ts +1 -1
  413. package/dist/esm/__tests__/identity-cache/identity-cache-db-service.spec.js +674 -674
  414. package/dist/esm/__tests__/identity-cache/identity-cache-dynamodb-service.spec.d.ts +1 -1
  415. package/dist/esm/__tests__/identity-cache/identity-cache-dynamodb-service.spec.js +1138 -1138
  416. package/dist/esm/__tests__/identity-cache/identity-cache-tier-routing.spec.d.ts +1 -1
  417. package/dist/esm/__tests__/identity-cache/identity-cache-tier-routing.spec.js +849 -849
  418. package/dist/esm/__tests__/identity-cache/trait-merging-and-staleness.spec.d.ts +1 -1
  419. package/dist/esm/__tests__/identity-cache/trait-merging-and-staleness.spec.js +1058 -1058
  420. package/dist/esm/__tests__/identity-cache/volatile-traits-optimization.spec.d.ts +1 -1
  421. package/dist/esm/__tests__/identity-cache/volatile-traits-optimization.spec.js +816 -816
  422. package/dist/esm/__tests__/integration/sqs-bundling-roundtrip.spec.d.ts +1 -1
  423. package/dist/esm/__tests__/integration/sqs-bundling-roundtrip.spec.js +582 -582
  424. package/dist/esm/__tests__/libs/compress-decompress.spec.d.ts +1 -1
  425. package/dist/esm/__tests__/libs/compress-decompress.spec.js +14 -14
  426. package/dist/esm/__tests__/libs/contacts.spec.d.ts +1 -1
  427. package/dist/esm/__tests__/libs/contacts.spec.js +292 -292
  428. package/dist/esm/__tests__/libs/currency.spec.d.ts +1 -1
  429. package/dist/esm/__tests__/libs/currency.spec.js +218 -218
  430. package/dist/esm/__tests__/libs/dates.spec.d.ts +1 -1
  431. package/dist/esm/__tests__/libs/dates.spec.js +128 -128
  432. package/dist/esm/__tests__/libs/domain.spec.d.ts +1 -1
  433. package/dist/esm/__tests__/libs/domain.spec.js +105 -105
  434. package/dist/esm/__tests__/libs/numbers.spec.d.ts +1 -1
  435. package/dist/esm/__tests__/libs/numbers.spec.js +259 -259
  436. package/dist/esm/__tests__/s3-client/s3-client.spec.d.ts +1 -1
  437. package/dist/esm/__tests__/s3-client/s3-client.spec.js +31 -31
  438. package/dist/esm/__tests__/services/acuity-api-service.spec.d.ts +1 -1
  439. package/dist/esm/__tests__/services/acuity-api-service.spec.js +69 -69
  440. package/dist/esm/__tests__/services/cost/cost-calculation-types.spec.d.ts +1 -0
  441. package/dist/esm/__tests__/services/cost/cost-calculation-types.spec.js +22 -0
  442. package/dist/esm/__tests__/services/cost/cost-calculation-types.spec.js.map +1 -0
  443. package/dist/esm/__tests__/services/cost/cost-calculator-service.spec.d.ts +1 -0
  444. package/dist/esm/__tests__/services/cost/cost-calculator-service.spec.js +3318 -0
  445. package/dist/esm/__tests__/services/cost/cost-calculator-service.spec.js.map +1 -0
  446. package/dist/esm/__tests__/services/cost/cost-currency-service.spec.d.ts +1 -0
  447. package/dist/esm/__tests__/services/cost/cost-currency-service.spec.js +113 -0
  448. package/dist/esm/__tests__/services/cost/cost-currency-service.spec.js.map +1 -0
  449. package/dist/esm/__tests__/services/cost/cost-filter-service.spec.d.ts +1 -0
  450. package/dist/esm/__tests__/services/cost/cost-filter-service.spec.js +467 -0
  451. package/dist/esm/__tests__/services/cost/cost-filter-service.spec.js.map +1 -0
  452. package/dist/esm/__tests__/services/cost/order-cost/order-cost-resolution-service.spec.d.ts +1 -0
  453. package/dist/esm/__tests__/services/cost/order-cost/order-cost-resolution-service.spec.js +205 -0
  454. package/dist/esm/__tests__/services/cost/order-cost/order-cost-resolution-service.spec.js.map +1 -0
  455. package/dist/esm/__tests__/services/currency-exchange-rate-lookup-service.spec.d.ts +1 -0
  456. package/dist/esm/__tests__/services/currency-exchange-rate-lookup-service.spec.js +33 -0
  457. package/dist/esm/__tests__/services/currency-exchange-rate-lookup-service.spec.js.map +1 -0
  458. package/dist/esm/__tests__/services/email-verification/contact-email-verification-service.spec.d.ts +1 -1
  459. package/dist/esm/__tests__/services/email-verification/contact-email-verification-service.spec.js +91 -91
  460. package/dist/esm/__tests__/services/email-verification/email-verification-service.spec.d.ts +1 -1
  461. package/dist/esm/__tests__/services/email-verification/email-verification-service.spec.js +55 -55
  462. package/dist/esm/__tests__/shopify/shopify-graphql-transformer.spec.d.ts +1 -1
  463. package/dist/esm/__tests__/shopify/shopify-graphql-transformer.spec.js +33 -33
  464. package/dist/esm/__tests__/unit/libs/api-router/public-api-router.spec.d.ts +1 -1
  465. package/dist/esm/__tests__/unit/libs/api-router/public-api-router.spec.js +156 -156
  466. package/dist/esm/__tests__/unit/libs/api-router/route-matcher.spec.d.ts +1 -1
  467. package/dist/esm/__tests__/unit/libs/api-router/route-matcher.spec.js +67 -67
  468. package/dist/esm/__tests__/utils/custom-measure-formula-utils.spec.d.ts +1 -1
  469. package/dist/esm/__tests__/utils/custom-measure-formula-utils.spec.js +137 -137
  470. package/dist/esm/clients/generic/cognito-client.d.ts +23 -23
  471. package/dist/esm/clients/generic/cognito-client.js +204 -204
  472. package/dist/esm/clients/generic/dynamodb-client.d.ts +20 -20
  473. package/dist/esm/clients/generic/dynamodb-client.js +231 -231
  474. package/dist/esm/clients/generic/eventbridge-client.d.ts +14 -14
  475. package/dist/esm/clients/generic/eventbridge-client.js +47 -47
  476. package/dist/esm/clients/generic/http-client.d.ts +14 -14
  477. package/dist/esm/clients/generic/http-client.js +53 -53
  478. package/dist/esm/clients/generic/index.d.ts +13 -13
  479. package/dist/esm/clients/generic/index.js +13 -13
  480. package/dist/esm/clients/generic/lambda-invoke-client.d.ts +10 -10
  481. package/dist/esm/clients/generic/lambda-invoke-client.js +35 -35
  482. package/dist/esm/clients/generic/location-client.d.ts +8 -8
  483. package/dist/esm/clients/generic/location-client.js +27 -27
  484. package/dist/esm/clients/generic/redis-client.d.ts +33 -33
  485. package/dist/esm/clients/generic/redis-client.js +184 -184
  486. package/dist/esm/clients/generic/s3-client.d.ts +23 -23
  487. package/dist/esm/clients/generic/s3-client.js +209 -209
  488. package/dist/esm/clients/generic/singlestore-db-client.d.ts +14 -14
  489. package/dist/esm/clients/generic/singlestore-db-client.js +40 -40
  490. package/dist/esm/clients/generic/sqs-bundled-client.d.ts +15 -15
  491. package/dist/esm/clients/generic/sqs-bundled-client.js +307 -307
  492. package/dist/esm/clients/generic/sqs-bundled-client.types.d.ts +53 -53
  493. package/dist/esm/clients/generic/sqs-bundled-client.types.js +14 -14
  494. package/dist/esm/clients/generic/sqs-client.d.ts +53 -53
  495. package/dist/esm/clients/generic/sqs-client.js +281 -281
  496. package/dist/esm/clients/generic/sqs-unbundle.d.ts +32 -32
  497. package/dist/esm/clients/generic/sqs-unbundle.js +137 -137
  498. package/dist/esm/clients/index.d.ts +3 -3
  499. package/dist/esm/clients/index.js +3 -3
  500. package/dist/esm/clients/internal-api/accounts-client.d.ts +91 -91
  501. package/dist/esm/clients/internal-api/accounts-client.js +125 -125
  502. package/dist/esm/clients/internal-api/cache-lambda-client.d.ts +26 -26
  503. package/dist/esm/clients/internal-api/cache-lambda-client.js +85 -85
  504. package/dist/esm/clients/internal-api/db-management-client.d.ts +18 -18
  505. package/dist/esm/clients/internal-api/db-management-client.js +32 -32
  506. package/dist/esm/clients/internal-api/destinations-client.d.ts +34 -34
  507. package/dist/esm/clients/internal-api/destinations-client.js +75 -75
  508. package/dist/esm/clients/internal-api/event-collector-client.d.ts +20 -20
  509. package/dist/esm/clients/internal-api/event-collector-client.js +32 -32
  510. package/dist/esm/clients/internal-api/identity-client.d.ts +31 -31
  511. package/dist/esm/clients/internal-api/identity-client.js +87 -87
  512. package/dist/esm/clients/internal-api/index.d.ts +9 -9
  513. package/dist/esm/clients/internal-api/index.js +9 -9
  514. package/dist/esm/clients/internal-api/shopify-app-install-client.d.ts +37 -37
  515. package/dist/esm/clients/internal-api/shopify-app-install-client.js +77 -77
  516. package/dist/esm/clients/internal-api/subscriptions-client.d.ts +26 -26
  517. package/dist/esm/clients/internal-api/subscriptions-client.js +73 -73
  518. package/dist/esm/clients/internal-api/users-auth-client.d.ts +35 -35
  519. package/dist/esm/clients/internal-api/users-auth-client.js +106 -106
  520. package/dist/esm/clients/third-party/acuity-client.d.ts +10 -10
  521. package/dist/esm/clients/third-party/acuity-client.js +36 -36
  522. package/dist/esm/clients/third-party/emailable-client.d.ts +7 -7
  523. package/dist/esm/clients/third-party/emailable-client.js +21 -21
  524. package/dist/esm/clients/third-party/exchange-rate-api-client.d.ts +17 -17
  525. package/dist/esm/clients/third-party/exchange-rate-api-client.js +15 -15
  526. package/dist/esm/clients/third-party/index.d.ts +5 -5
  527. package/dist/esm/clients/third-party/index.js +5 -5
  528. package/dist/esm/clients/third-party/loops-client.d.ts +10 -10
  529. package/dist/esm/clients/third-party/loops-client.js +26 -26
  530. package/dist/esm/clients/third-party/shopify/graphql-order-queries.d.ts +25 -25
  531. package/dist/esm/clients/third-party/shopify/graphql-order-queries.js +1 -1
  532. package/dist/esm/clients/third-party/shopify/graphql-product-queries.d.ts +2 -2
  533. package/dist/esm/clients/third-party/shopify/graphql-product-queries.js +2 -2
  534. package/dist/esm/clients/third-party/shopify/shopify-graphql-client.d.ts +10 -10
  535. package/dist/esm/clients/third-party/shopify/shopify-graphql-client.js +157 -157
  536. package/dist/esm/clients/third-party/shopify-client.d.ts +29 -29
  537. package/dist/esm/clients/third-party/shopify-client.js +142 -142
  538. package/dist/esm/constants/index.d.ts +1 -1
  539. package/dist/esm/constants/index.js +1 -1
  540. package/dist/esm/constants/sqs.d.ts +20 -20
  541. package/dist/esm/constants/sqs.js +22 -22
  542. package/dist/esm/helpers/account-users-helper.d.ts +2 -2
  543. package/dist/esm/helpers/account-users-helper.js +18 -18
  544. package/dist/esm/helpers/acuity-helper.d.ts +4 -4
  545. package/dist/esm/helpers/acuity-helper.js +51 -51
  546. package/dist/esm/helpers/api-key-auth-helper.d.ts +9 -9
  547. package/dist/esm/helpers/api-key-auth-helper.js +35 -35
  548. package/dist/esm/helpers/api-key-authorizer-helper.d.ts +36 -36
  549. package/dist/esm/helpers/api-key-authorizer-helper.js +83 -83
  550. package/dist/esm/helpers/identity-cache-helper.d.ts +30 -30
  551. package/dist/esm/helpers/identity-cache-helper.js +248 -248
  552. package/dist/esm/helpers/index.d.ts +10 -10
  553. package/dist/esm/helpers/index.js +10 -10
  554. package/dist/esm/helpers/input-validation-helper.d.ts +3 -3
  555. package/dist/esm/helpers/input-validation-helper.js +18 -18
  556. package/dist/esm/helpers/logging-helper.d.ts +16 -16
  557. package/dist/esm/helpers/logging-helper.js +56 -56
  558. package/dist/esm/helpers/response-helper.d.ts +18 -18
  559. package/dist/esm/helpers/response-helper.js +37 -37
  560. package/dist/esm/helpers/shopify-helper.d.ts +9 -9
  561. package/dist/esm/helpers/shopify-helper.js +21 -21
  562. package/dist/esm/helpers/sqs-utils.d.ts +6 -6
  563. package/dist/esm/helpers/sqs-utils.js +9 -9
  564. package/dist/esm/index.d.ts +7 -7
  565. package/dist/esm/index.js +7 -7
  566. package/dist/esm/libs/api-router/index.d.ts +2 -2
  567. package/dist/esm/libs/api-router/index.js +2 -2
  568. package/dist/esm/libs/api-router/public-api-router.d.ts +3 -3
  569. package/dist/esm/libs/api-router/public-api-router.js +32 -32
  570. package/dist/esm/libs/api-router/route-matcher.d.ts +21 -21
  571. package/dist/esm/libs/api-router/route-matcher.js +30 -30
  572. package/dist/esm/libs/click-id-parser.d.ts +23 -23
  573. package/dist/esm/libs/click-id-parser.js +45 -45
  574. package/dist/esm/libs/compression.d.ts +2 -2
  575. package/dist/esm/libs/compression.js +25 -25
  576. package/dist/esm/libs/contacts.d.ts +7 -7
  577. package/dist/esm/libs/contacts.js +143 -143
  578. package/dist/esm/libs/cookie.d.ts +17 -17
  579. package/dist/esm/libs/cookie.js +70 -70
  580. package/dist/esm/libs/crypto.d.ts +4 -4
  581. package/dist/esm/libs/crypto.js +15 -15
  582. package/dist/esm/libs/csv.d.ts +2 -2
  583. package/dist/esm/libs/csv.js +30 -30
  584. package/dist/esm/libs/currency.d.ts +1 -1
  585. package/dist/esm/libs/currency.js +22 -22
  586. package/dist/esm/libs/dates.d.ts +12 -12
  587. package/dist/esm/libs/dates.js +83 -83
  588. package/dist/esm/libs/domain.d.ts +2 -2
  589. package/dist/esm/libs/domain.js +33 -33
  590. package/dist/esm/libs/emails.d.ts +8 -8
  591. package/dist/esm/libs/emails.js +146 -146
  592. package/dist/esm/libs/http-error.d.ts +21 -21
  593. package/dist/esm/libs/http-error.js +59 -59
  594. package/dist/esm/libs/http-status-codes.d.ts +58 -58
  595. package/dist/esm/libs/http-status-codes.js +59 -59
  596. package/dist/esm/libs/index.d.ts +19 -19
  597. package/dist/esm/libs/index.js +19 -19
  598. package/dist/esm/libs/numbers.d.ts +1 -1
  599. package/dist/esm/libs/numbers.js +11 -11
  600. package/dist/esm/libs/referrer-parser/index.d.ts +2 -2
  601. package/dist/esm/libs/referrer-parser/index.js +2 -2
  602. package/dist/esm/libs/referrer-parser/referrer-data.d.ts +9 -9
  603. package/dist/esm/libs/referrer-parser/referrer-data.js +3304 -3304
  604. package/dist/esm/libs/referrer-parser/referrer-parser-util.d.ts +20 -20
  605. package/dist/esm/libs/referrer-parser/referrer-parser-util.js +124 -124
  606. package/dist/esm/libs/strings.d.ts +3 -3
  607. package/dist/esm/libs/strings.js +40 -40
  608. package/dist/esm/libs/traits.d.ts +6 -6
  609. package/dist/esm/libs/traits.js +54 -54
  610. package/dist/esm/libs/url.d.ts +1 -1
  611. package/dist/esm/libs/url.js +9 -9
  612. package/dist/esm/services/acuity-api-service.d.ts +9 -9
  613. package/dist/esm/services/acuity-api-service.js +69 -69
  614. package/dist/esm/services/cache/generic-cached-object.d.ts +5 -5
  615. package/dist/esm/services/cache/generic-cached-object.js +1 -1
  616. package/dist/esm/services/cache/index.d.ts +1 -1
  617. package/dist/esm/services/cache/index.js +1 -1
  618. package/dist/esm/services/cache/product-cache-service.d.ts +21 -21
  619. package/dist/esm/services/cache/product-cache-service.js +68 -68
  620. package/dist/esm/services/cost/cost-calculation-types.d.ts +69 -0
  621. package/dist/esm/services/cost/cost-calculation-types.js +16 -0
  622. package/dist/esm/services/cost/cost-calculation-types.js.map +1 -0
  623. package/dist/esm/services/cost/cost-calculator-service.d.ts +24 -0
  624. package/dist/esm/services/cost/cost-calculator-service.js +451 -0
  625. package/dist/esm/services/cost/cost-calculator-service.js.map +1 -0
  626. package/dist/esm/services/cost/cost-currency-service.d.ts +6 -0
  627. package/dist/esm/services/cost/cost-currency-service.js +85 -0
  628. package/dist/esm/services/cost/cost-currency-service.js.map +1 -0
  629. package/dist/esm/services/cost/cost-filter-service.d.ts +10 -0
  630. package/dist/esm/services/cost/cost-filter-service.js +119 -0
  631. package/dist/esm/services/cost/cost-filter-service.js.map +1 -0
  632. package/dist/esm/services/cost/index.d.ts +5 -0
  633. package/dist/esm/services/cost/index.js +6 -0
  634. package/dist/esm/services/cost/index.js.map +1 -0
  635. package/dist/esm/services/cost/order-cost/index.d.ts +2 -0
  636. package/dist/esm/services/cost/order-cost/index.js +3 -0
  637. package/dist/esm/services/cost/order-cost/index.js.map +1 -0
  638. package/dist/esm/services/cost/order-cost/order-cost-resolution-service.d.ts +23 -0
  639. package/dist/esm/services/cost/order-cost/order-cost-resolution-service.js +356 -0
  640. package/dist/esm/services/cost/order-cost/order-cost-resolution-service.js.map +1 -0
  641. package/dist/esm/services/cost/order-cost/order-cost-resolution-types.d.ts +37 -0
  642. package/dist/esm/services/cost/order-cost/order-cost-resolution-types.js +2 -0
  643. package/dist/esm/services/cost/order-cost/order-cost-resolution-types.js.map +1 -0
  644. package/dist/esm/services/currency-exchange-rate-lookup-service.d.ts +12 -11
  645. package/dist/esm/services/currency-exchange-rate-lookup-service.js +90 -62
  646. package/dist/esm/services/currency-exchange-rate-lookup-service.js.map +1 -1
  647. package/dist/esm/services/db/accounts-db-service.d.ts +9 -9
  648. package/dist/esm/services/db/accounts-db-service.js +29 -29
  649. package/dist/esm/services/db/api-keys-db-service.d.ts +10 -10
  650. package/dist/esm/services/db/api-keys-db-service.js +32 -32
  651. package/dist/esm/services/db/contact-enrichments-db-service.d.ts +15 -15
  652. package/dist/esm/services/db/contact-enrichments-db-service.js +90 -90
  653. package/dist/esm/services/db/currency-exchange-rates-db-service.d.ts +21 -21
  654. package/dist/esm/services/db/currency-exchange-rates-db-service.js +35 -35
  655. package/dist/esm/services/db/custom-measures-db-service.d.ts +14 -14
  656. package/dist/esm/services/db/custom-measures-db-service.js +44 -44
  657. package/dist/esm/services/db/destinations-db-service.d.ts +13 -13
  658. package/dist/esm/services/db/destinations-db-service.js +70 -70
  659. package/dist/esm/services/db/identity-cache-db-service.d.ts +28 -28
  660. package/dist/esm/services/db/identity-cache-db-service.js +313 -313
  661. package/dist/esm/services/db/identity-cache-dynamodb-service.d.ts +44 -44
  662. package/dist/esm/services/db/identity-cache-dynamodb-service.js +727 -727
  663. package/dist/esm/services/db/index.d.ts +19 -17
  664. package/dist/esm/services/db/index.js +19 -17
  665. package/dist/esm/services/db/index.js.map +1 -1
  666. package/dist/esm/services/db/log-events-db-service.d.ts +11 -11
  667. package/dist/esm/services/db/log-events-db-service.js +177 -177
  668. package/dist/esm/services/db/pixels-db-service.d.ts +8 -8
  669. package/dist/esm/services/db/pixels-db-service.js +31 -31
  670. package/dist/esm/services/db/products-db-service-types.d.ts +10 -0
  671. package/dist/esm/services/db/products-db-service-types.js +2 -0
  672. package/dist/esm/services/db/products-db-service-types.js.map +1 -0
  673. package/dist/esm/services/db/products-db-service.d.ts +19 -0
  674. package/dist/esm/services/db/products-db-service.js +278 -0
  675. package/dist/esm/services/db/products-db-service.js.map +1 -0
  676. package/dist/esm/services/db/purchasable-contacts-db-service.d.ts +9 -9
  677. package/dist/esm/services/db/purchasable-contacts-db-service.js +39 -39
  678. package/dist/esm/services/db/purchased-contacts/index.d.ts +2 -2
  679. package/dist/esm/services/db/purchased-contacts/index.js +2 -2
  680. package/dist/esm/services/db/purchased-contacts/purchased-contacts-db-service.d.ts +18 -18
  681. package/dist/esm/services/db/purchased-contacts/purchased-contacts-db-service.js +148 -148
  682. package/dist/esm/services/db/purchased-contacts/types.d.ts +11 -11
  683. package/dist/esm/services/db/purchased-contacts/types.js +1 -1
  684. package/dist/esm/services/db/shopify-app-installs-db-service.d.ts +10 -10
  685. package/dist/esm/services/db/shopify-app-installs-db-service.js +48 -48
  686. package/dist/esm/services/db/shopify-products-cache-db-service.d.ts +16 -16
  687. package/dist/esm/services/db/shopify-products-cache-db-service.js +66 -66
  688. package/dist/esm/services/db/subscriptions-db-service.d.ts +11 -11
  689. package/dist/esm/services/db/subscriptions-db-service.js +34 -34
  690. package/dist/esm/services/db/tracking-events-db-service.d.ts +21 -21
  691. package/dist/esm/services/db/tracking-events-db-service.js +184 -184
  692. package/dist/esm/services/db/user-accounts-db-service.d.ts +7 -7
  693. package/dist/esm/services/db/user-accounts-db-service.js +13 -13
  694. package/dist/esm/services/email-verification/contact-email-verification-service.d.ts +7 -7
  695. package/dist/esm/services/email-verification/contact-email-verification-service.js +97 -97
  696. package/dist/esm/services/email-verification/email-verification-service.d.ts +19 -19
  697. package/dist/esm/services/email-verification/email-verification-service.js +127 -127
  698. package/dist/esm/services/email-verification/index.d.ts +2 -2
  699. package/dist/esm/services/email-verification/index.js +2 -2
  700. package/dist/esm/services/eventbridge-integration-service.d.ts +9 -9
  701. package/dist/esm/services/eventbridge-integration-service.js +24 -24
  702. package/dist/esm/services/events/index.d.ts +3 -3
  703. package/dist/esm/services/events/index.js +3 -3
  704. package/dist/esm/services/events/log-event-service.d.ts +19 -19
  705. package/dist/esm/services/events/log-event-service.js +73 -73
  706. package/dist/esm/services/events/metric-event-service.d.ts +9 -9
  707. package/dist/esm/services/events/metric-event-service.js +45 -45
  708. package/dist/esm/services/events/tracking-event-sqs-service.d.ts +8 -8
  709. package/dist/esm/services/events/tracking-event-sqs-service.js +30 -30
  710. package/dist/esm/services/generic-cache-service.d.ts +7 -7
  711. package/dist/esm/services/generic-cache-service.js +29 -29
  712. package/dist/esm/services/index.d.ts +11 -10
  713. package/dist/esm/services/index.js +11 -10
  714. package/dist/esm/services/index.js.map +1 -1
  715. package/dist/esm/services/ipdata-lookup-service.d.ts +20 -20
  716. package/dist/esm/services/ipdata-lookup-service.js +108 -108
  717. package/dist/esm/services/shopify/index.d.ts +2 -2
  718. package/dist/esm/services/shopify/index.js +2 -2
  719. package/dist/esm/services/shopify/products/index.d.ts +1 -1
  720. package/dist/esm/services/shopify/products/index.js +1 -1
  721. package/dist/esm/services/shopify/products/shopify-products-serviceV2.d.ts +17 -17
  722. package/dist/esm/services/shopify/products/shopify-products-serviceV2.js +108 -108
  723. package/dist/esm/services/shopify/shopify-graphql-transformer.d.ts +8 -8
  724. package/dist/esm/services/shopify/shopify-graphql-transformer.js +138 -138
  725. package/dist/esm/types/acuity-types.d.ts +74 -74
  726. package/dist/esm/types/acuity-types.js +1 -1
  727. package/dist/esm/types/api-response.d.ts +6 -6
  728. package/dist/esm/types/api-response.js +1 -1
  729. package/dist/esm/types/index.d.ts +4 -4
  730. package/dist/esm/types/index.js +4 -4
  731. package/dist/esm/types/internal-events/event-detail-types.d.ts +20 -20
  732. package/dist/esm/types/internal-events/event-detail-types.js +24 -24
  733. package/dist/esm/types/internal-events/index.d.ts +1 -1
  734. package/dist/esm/types/internal-events/index.js +1 -1
  735. package/dist/esm/types/shopify-graphql-types/admin.generated.d.ts +123 -123
  736. package/dist/esm/types/shopify-graphql-types/admin.generated.js +1 -1
  737. package/dist/esm/types/shopify-graphql-types/admin.types.d.ts +26289 -26289
  738. package/dist/esm/types/shopify-graphql-types/admin.types.js +5299 -5299
  739. package/dist/esm/types/shopify-graphql-types/index.d.ts +2 -2
  740. package/dist/esm/types/shopify-graphql-types/index.js +2 -2
  741. package/dist/esm/types/shopify-rest-types.d.ts +767 -767
  742. package/dist/esm/types/shopify-rest-types.js +1 -1
  743. package/dist/esm/utils/compression.d.ts +36 -36
  744. package/dist/esm/utils/compression.js +187 -187
  745. package/dist/esm/utils/custom-measure-formula-utils.d.ts +6 -6
  746. package/dist/esm/utils/custom-measure-formula-utils.js +201 -201
  747. package/dist/esm/utils/index.d.ts +4 -4
  748. package/dist/esm/utils/index.js +4 -4
  749. package/dist/esm/utils/retry-envelope.d.ts +12 -12
  750. package/dist/esm/utils/retry-envelope.js +22 -22
  751. package/dist/esm/utils/size.d.ts +2 -2
  752. package/dist/esm/utils/size.js +44 -44
  753. package/package.json +134 -134
@@ -1,1059 +1,1059 @@
1
- import { ADDRESS_INFO_SOURCE } from '@adtrackify/at-tracking-event-types';
2
- import { mergeIdentityTraits } from '@adtrackify/at-shared-utils';
3
- import { isIdentityCacheStale, isClickInfosStale, IDENTITY_CACHE_STALENESS_TIER, } from '../../helpers/identity-cache-helper';
4
- describe('Identity Trait Merging Tests', () => {
5
- afterEach(() => {
6
- jest.resetModules();
7
- });
8
- describe('mergeIdentityTraits function', () => {
9
- it('should merge simple string arrays correctly', () => {
10
- const incomingTraits = {
11
- emails: ['new@email.com'],
12
- userIds: ['user1', 'user2'],
13
- };
14
- const cachedTraits = {
15
- emails: ['existing@email.com'],
16
- userIds: ['user2', 'user3'],
17
- phones: ['+1234567890'],
18
- };
19
- const merged = mergeIdentityTraits(incomingTraits, cachedTraits);
20
- expect(merged.emails).toEqual(['new@email.com', 'existing@email.com']);
21
- expect(merged.userIds).toEqual(['user1', 'user2', 'user3']);
22
- expect(merged.phones).toEqual(['+1234567890']);
23
- });
24
- it('should handle null and undefined values in arrays', () => {
25
- const incomingTraits = {
26
- emails: ['test@email.com', null, undefined],
27
- userIds: ['user1'],
28
- };
29
- const cachedTraits = {
30
- emails: [null, 'cached@email.com', undefined],
31
- userIds: null,
32
- };
33
- const merged = mergeIdentityTraits(incomingTraits, cachedTraits);
34
- expect(merged.emails).toContain('test@email.com');
35
- expect(merged.emails).toContain('cached@email.com');
36
- expect(merged.userIds).toEqual(['user1']);
37
- });
38
- it('should merge addresses correctly', () => {
39
- const incomingTraits = {
40
- addresses: [
41
- {
42
- city: 'New York',
43
- country: 'USA',
44
- countryCode: 'US',
45
- province: 'NY',
46
- provinceCode: '10001',
47
- },
48
- ],
49
- };
50
- const cachedTraits = {
51
- addresses: [
52
- {
53
- city: 'Los Angeles',
54
- country: 'USA',
55
- countryCode: 'US',
56
- province: 'CA',
57
- provinceCode: '90210',
58
- },
59
- ],
60
- };
61
- const merged = mergeIdentityTraits(incomingTraits, cachedTraits);
62
- expect(merged.addresses).toHaveLength(2);
63
- expect(merged.addresses).toEqual(expect.arrayContaining([
64
- expect.objectContaining({ city: 'New York' }),
65
- expect.objectContaining({ city: 'Los Angeles' }),
66
- ]));
67
- });
68
- it('should merge click information correctly', () => {
69
- const incomingTraits = {
70
- click: {
71
- fbp: 'fb.new.123',
72
- fbpCollectedAt: '2024-01-01T00:00:00.000Z',
73
- gclid: 'new_gclid',
74
- },
75
- };
76
- const cachedTraits = {
77
- click: {
78
- fbp: 'fb.old.456',
79
- fbpCollectedAt: '2023-12-01T00:00:00.000Z',
80
- fbclid: 'cached_fbclid',
81
- },
82
- };
83
- const merged = mergeIdentityTraits(incomingTraits, cachedTraits);
84
- expect(merged.click?.fbp).toBe('fb.new.123');
85
- expect(merged.click?.gclid).toBe('new_gclid');
86
- expect(merged.click?.fbpCollectedAt).toBe('2024-01-01T00:00:00.000Z');
87
- expect(merged.click?.fbclid).toBeUndefined();
88
- });
89
- it('should handle empty traits correctly', () => {
90
- const incomingTraits = {};
91
- const cachedTraits = {
92
- emails: ['cached@email.com'],
93
- userIds: ['user1'],
94
- };
95
- const merged = mergeIdentityTraits(incomingTraits, cachedTraits);
96
- expect(merged.emails).toEqual(['cached@email.com']);
97
- expect(merged.userIds).toEqual(['user1']);
98
- });
99
- it('should handle undefined traits correctly', () => {
100
- const merged1 = mergeIdentityTraits(undefined, { emails: ['test@email.com'] });
101
- expect(merged1.emails).toEqual(['test@email.com']);
102
- const merged2 = mergeIdentityTraits({ emails: ['test@email.com'] }, undefined);
103
- expect(merged2.emails).toEqual(['test@email.com']);
104
- const merged3 = mergeIdentityTraits(undefined, undefined);
105
- expect(merged3).toEqual({});
106
- });
107
- it('should preserve version information', () => {
108
- const incomingTraits = {
109
- version: '3',
110
- emails: ['new@email.com'],
111
- };
112
- const cachedTraits = {
113
- version: '2',
114
- emails: ['old@email.com'],
115
- };
116
- const merged = mergeIdentityTraits(incomingTraits, cachedTraits);
117
- expect(merged.version).toBe('3');
118
- expect(merged.emails).toEqual(['new@email.com', 'old@email.com']);
119
- });
120
- it('should handle complex nested objects', () => {
121
- const incomingTraits = {
122
- click: {
123
- googleClientInfos: [{ id: 'new1', clickId: 'click1', sessionId: 'session1' }],
124
- },
125
- };
126
- const cachedTraits = {
127
- click: {
128
- googleClientInfos: [{ id: 'cached1', clickId: 'click2', sessionId: 'session2' }],
129
- },
130
- };
131
- const merged = mergeIdentityTraits(incomingTraits, cachedTraits);
132
- expect(merged.click?.googleClientInfos).toBeDefined();
133
- expect(Array.isArray(merged.click?.googleClientInfos)).toBe(true);
134
- expect(merged.click?.googleClientInfos).toEqual([{ id: 'cached1', clickId: 'click2', sessionId: 'session2' }]);
135
- });
136
- });
137
- describe('Integration: Merging + Staleness Checking', () => {
138
- it('should not be stale when merged identity matches cached identity', () => {
139
- const cachedIdentity = {
140
- identityId: 'test-id-123',
141
- traits: {
142
- emails: ['cached@email.com', 'shared@email.com'],
143
- userIds: ['user1', 'user2'],
144
- addresses: [
145
- {
146
- city: 'New York',
147
- country: 'USA',
148
- countryCode: 'US',
149
- },
150
- ],
151
- version: '2',
152
- },
153
- };
154
- const incomingIdentity = {
155
- identityId: 'test-id-123',
156
- traits: {
157
- emails: ['shared@email.com'],
158
- userIds: ['user1'],
159
- version: '2',
160
- },
161
- };
162
- const mergedTraits = mergeIdentityTraits(incomingIdentity.traits, cachedIdentity.traits);
163
- const mergedIdentity = { ...incomingIdentity, traits: mergedTraits };
164
- const staleTracker = isIdentityCacheStale(cachedIdentity, mergedIdentity);
165
- expect(staleTracker.isCacheStale).toBe(false);
166
- expect(mergedIdentity.traits?.emails).toEqual(['shared@email.com', 'cached@email.com']);
167
- });
168
- it('should be stale when merged identity has new traits', () => {
169
- const cachedIdentity = {
170
- identityId: 'test-id-123',
171
- traits: {
172
- emails: ['cached@email.com'],
173
- version: '2',
174
- },
175
- };
176
- const incomingIdentity = {
177
- identityId: 'test-id-123',
178
- traits: {
179
- emails: ['cached@email.com', 'new@email.com'],
180
- version: '2',
181
- },
182
- };
183
- const mergedTraits = mergeIdentityTraits(incomingIdentity.traits, cachedIdentity.traits);
184
- const mergedIdentity = { ...incomingIdentity, traits: mergedTraits };
185
- const staleTracker = isIdentityCacheStale(cachedIdentity, mergedIdentity);
186
- expect(staleTracker.isCacheStale).toBe(true);
187
- expect(staleTracker.isEmailsStale).toBe(true);
188
- });
189
- });
190
- });
191
- describe('Identity Cache Staleness Tests', () => {
192
- afterEach(() => {
193
- jest.resetModules();
194
- });
195
- describe('isIdentityCacheStale function', () => {
196
- it('should detect identity ID changes', () => {
197
- const cachedIdentity = {
198
- identityId: 'old-id',
199
- traits: { emails: ['test@email.com'] },
200
- };
201
- const incomingIdentity = {
202
- identityId: 'new-id',
203
- traits: { emails: ['test@email.com'] },
204
- };
205
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
206
- expect(result.isCacheStale).toBe(true);
207
- expect(result.isIdentityIdStale).toBe(true);
208
- });
209
- it('should detect new emails', () => {
210
- const cachedIdentity = {
211
- identityId: 'test-id',
212
- traits: { emails: ['old@email.com'] },
213
- };
214
- const incomingIdentity = {
215
- identityId: 'test-id',
216
- traits: { emails: ['old@email.com', 'new@email.com'] },
217
- };
218
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
219
- expect(result.isCacheStale).toBe(true);
220
- expect(result.isEmailsStale).toBe(true);
221
- });
222
- it('should detect new user IDs', () => {
223
- const cachedIdentity = {
224
- identityId: 'test-id',
225
- traits: { userIds: ['user1'] },
226
- };
227
- const incomingIdentity = {
228
- identityId: 'test-id',
229
- traits: { userIds: ['user1', 'user2'] },
230
- };
231
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
232
- expect(result.isCacheStale).toBe(true);
233
- expect(result.isUserIdsStale).toBe(true);
234
- });
235
- it('should detect new phones', () => {
236
- const cachedIdentity = {
237
- identityId: 'test-id',
238
- traits: { phones: ['+1234567890'] },
239
- };
240
- const incomingIdentity = {
241
- identityId: 'test-id',
242
- traits: { phones: ['+1234567890', '+9876543210'] },
243
- };
244
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
245
- expect(result.isCacheStale).toBe(true);
246
- expect(result.isPhonesStale).toBe(true);
247
- });
248
- it('should detect new addresses (non-IP sourced)', () => {
249
- const cachedIdentity = {
250
- identityId: 'test-id',
251
- traits: {
252
- addresses: [
253
- {
254
- city: 'New York',
255
- country: 'USA',
256
- s: ADDRESS_INFO_SOURCE.INPUT,
257
- },
258
- ],
259
- },
260
- };
261
- const incomingIdentity = {
262
- identityId: 'test-id',
263
- traits: {
264
- addresses: [
265
- { city: 'New York', country: 'USA', s: ADDRESS_INFO_SOURCE.INPUT },
266
- { city: 'Los Angeles', country: 'USA', s: ADDRESS_INFO_SOURCE.INPUT },
267
- ],
268
- },
269
- };
270
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
271
- expect(result.isCacheStale).toBe(true);
272
- expect(result.isAddressesStale).toBe(true);
273
- expect(result.isNonIpAddressesStale).toBe(true);
274
- expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
275
- });
276
- it('should detect IP address changes but NOT mark cache stale (volatile trait)', () => {
277
- const cachedIdentity = {
278
- identityId: 'test-id',
279
- traits: { ipAddress: '192.168.1.1' },
280
- };
281
- const incomingIdentity = {
282
- identityId: 'test-id',
283
- traits: { ipAddress: '10.0.0.1' },
284
- };
285
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
286
- expect(result.isCacheStale).toBe(false);
287
- expect(result.isIpAddressStale).toBe(true);
288
- expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
289
- });
290
- it('should detect user agent changes but NOT mark cache stale (volatile trait)', () => {
291
- const cachedIdentity = {
292
- identityId: 'test-id',
293
- traits: { userAgent: 'Mozilla/5.0 (old browser)' },
294
- };
295
- const incomingIdentity = {
296
- identityId: 'test-id',
297
- traits: { userAgent: 'Mozilla/5.0 (new browser)' },
298
- };
299
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
300
- expect(result.isCacheStale).toBe(false);
301
- expect(result.isUserAgentStale).toBe(true);
302
- expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
303
- });
304
- it('should not be stale when no new information is provided', () => {
305
- const cachedIdentity = {
306
- identityId: 'test-id',
307
- traits: {
308
- emails: ['test@email.com'],
309
- userIds: ['user1'],
310
- phones: ['+1234567890'],
311
- },
312
- };
313
- const incomingIdentity = {
314
- identityId: 'test-id',
315
- traits: {
316
- emails: ['test@email.com'],
317
- userIds: ['user1'],
318
- },
319
- };
320
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
321
- expect(result.isCacheStale).toBe(false);
322
- });
323
- it('should handle empty traits gracefully', () => {
324
- const cachedIdentity = {
325
- identityId: 'test-id',
326
- traits: {},
327
- };
328
- const incomingIdentity = {
329
- identityId: 'test-id',
330
- traits: {},
331
- };
332
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
333
- expect(result.isCacheStale).toBe(false);
334
- });
335
- it('should handle undefined traits gracefully', () => {
336
- const cachedIdentity = {
337
- identityId: 'test-id',
338
- };
339
- const incomingIdentity = {
340
- identityId: 'test-id',
341
- };
342
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
343
- expect(result.isCacheStale).toBe(false);
344
- });
345
- it('should detect multiple stale conditions (identity traits take priority over volatile)', () => {
346
- const cachedIdentity = {
347
- identityId: 'test-id',
348
- traits: {
349
- emails: ['old@email.com'],
350
- userIds: ['user1'],
351
- ipAddress: '192.168.1.1',
352
- },
353
- };
354
- const incomingIdentity = {
355
- identityId: 'test-id',
356
- traits: {
357
- emails: ['old@email.com', 'new@email.com'],
358
- userIds: ['user1', 'user2'],
359
- ipAddress: '10.0.0.1',
360
- },
361
- };
362
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
363
- expect(result.isCacheStale).toBe(true);
364
- expect(result.isEmailsStale).toBe(true);
365
- expect(result.isUserIdsStale).toBe(true);
366
- expect(result.isIpAddressStale).toBe(true);
367
- expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
368
- });
369
- });
370
- describe('isClickInfosStale function', () => {
371
- it('should detect new FBC values', () => {
372
- const cachedClick = {
373
- fbc: 'fb.1.123.old_fbclid',
374
- };
375
- const incomingClick = {
376
- fbc: 'fb.1.123.new_fbclid',
377
- };
378
- const result = isClickInfosStale(cachedClick, incomingClick);
379
- expect(result).toBe(true);
380
- });
381
- it('should detect new click IDs', () => {
382
- const cachedClick = {
383
- gclid: 'old_gclid',
384
- };
385
- const incomingClick = {
386
- gclid: 'new_gclid',
387
- };
388
- const result = isClickInfosStale(cachedClick, incomingClick);
389
- expect(result).toBe(true);
390
- });
391
- it('should ignore collection timestamps', () => {
392
- const cachedClick = {
393
- fbp: 'fb.2.123.456',
394
- fbpCollectedAt: '2023-01-01T00:00:00.000Z',
395
- };
396
- const incomingClick = {
397
- fbp: 'fb.2.123.456',
398
- fbpCollectedAt: '2024-01-01T00:00:00.000Z',
399
- };
400
- const result = isClickInfosStale(cachedClick, incomingClick);
401
- expect(result).toBe(false);
402
- });
403
- it('should ignore googleClientInfos', () => {
404
- const cachedClick = {
405
- googleClientInfos: [{ id: 'old', clickId: 'old_click' }],
406
- };
407
- const incomingClick = {
408
- googleClientInfos: [{ id: 'new', clickId: 'new_click' }],
409
- };
410
- const result = isClickInfosStale(cachedClick, incomingClick);
411
- expect(result).toBe(false);
412
- });
413
- it('should handle empty click info', () => {
414
- const result = isClickInfosStale({}, {});
415
- expect(result).toBe(false);
416
- });
417
- it('should detect when incoming has new click info but cached is empty', () => {
418
- const cachedClick = {};
419
- const incomingClick = {
420
- fbp: 'fb.2.123.456',
421
- };
422
- const result = isClickInfosStale(cachedClick, incomingClick);
423
- expect(result).toBe(true);
424
- });
425
- });
426
- describe('Edge Cases and Error Handling', () => {
427
- it('should handle malformed FBC values gracefully', () => {
428
- const cachedClick = {
429
- fbc: 'malformed_fbc',
430
- };
431
- const incomingClick = {
432
- fbc: 'also_malformed',
433
- };
434
- const result = isClickInfosStale(cachedClick, incomingClick);
435
- expect(result).toBe(true);
436
- });
437
- it('should handle null/undefined arrays in traits', () => {
438
- const cachedIdentity = {
439
- identityId: 'test-id',
440
- traits: {
441
- emails: null,
442
- userIds: undefined,
443
- },
444
- };
445
- const incomingIdentity = {
446
- identityId: 'test-id',
447
- traits: {
448
- emails: ['new@email.com'],
449
- userIds: ['user1'],
450
- },
451
- };
452
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
453
- expect(result.isCacheStale).toBe(true);
454
- expect(result.isEmailsStale).toBe(true);
455
- expect(result.isUserIdsStale).toBe(true);
456
- });
457
- it('should handle arrays with null/undefined elements', () => {
458
- const cachedIdentity = {
459
- identityId: 'test-id',
460
- traits: {
461
- emails: ['valid@email.com', null, undefined],
462
- },
463
- };
464
- const incomingIdentity = {
465
- identityId: 'test-id',
466
- traits: {
467
- emails: ['valid@email.com', null, undefined, 'new@email.com'],
468
- },
469
- };
470
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
471
- expect(result.isCacheStale).toBe(true);
472
- expect(result.isEmailsStale).toBe(true);
473
- });
474
- it('should handle error conditions gracefully', () => {
475
- const result = isIdentityCacheStale(null, undefined);
476
- expect(result.isCacheStale).toBe(false);
477
- });
478
- });
479
- describe('Comprehensive Scenario Tests', () => {
480
- it('should handle complex real-world scenario', () => {
481
- const cachedIdentity = {
482
- identityId: '01HXRZ27H4TXWBBTRK09Q7APDP',
483
- traits: {
484
- emails: ['user@domain.com'],
485
- userIds: ['shopify_123'],
486
- addresses: [
487
- {
488
- city: 'New York',
489
- country: 'USA',
490
- countryCode: 'US',
491
- province: 'NY',
492
- provinceCode: '10001',
493
- },
494
- ],
495
- click: {
496
- fbp: 'fb.2.1715603578424.5068754021',
497
- fbpCollectedAt: '2024-05-13T12:32:58.424Z',
498
- gclid: 'original_gclid',
499
- },
500
- ipAddress: '192.168.1.100',
501
- version: '2',
502
- },
503
- };
504
- const incomingIdentity = {
505
- identityId: '01HXRZ27H4TXWBBTRK09Q7APDP',
506
- traits: {
507
- emails: ['user@domain.com', 'user.secondary@domain.com'],
508
- phones: ['+1234567890'],
509
- addresses: [
510
- {
511
- city: 'New York',
512
- country: 'USA',
513
- countryCode: 'US',
514
- province: 'NY',
515
- provinceCode: '10001',
516
- },
517
- ],
518
- click: {
519
- fbp: 'fb.2.1715603578424.5068754021',
520
- fbpCollectedAt: '2024-05-13T15:30:00.000Z',
521
- gclid: 'updated_gclid',
522
- },
523
- ipAddress: '192.168.1.100',
524
- version: '2',
525
- },
526
- };
527
- const mergedTraits = mergeIdentityTraits(cachedIdentity.traits, incomingIdentity.traits);
528
- const mergedIdentity = { ...incomingIdentity, traits: mergedTraits };
529
- const result = isIdentityCacheStale(cachedIdentity, mergedIdentity);
530
- expect(result.isCacheStale).toBe(true);
531
- expect(result.isEmailsStale).toBe(true);
532
- expect(result.isPhonesStale).toBe(true);
533
- expect(result.isClickInfosStale).toBe(true);
534
- expect(result.isAddressesStale).toBe(false);
535
- expect(result.isIpAddressStale).toBe(false);
536
- expect(mergedIdentity.traits?.emails).toEqual(['user@domain.com', 'user.secondary@domain.com']);
537
- expect(mergedIdentity.traits?.phones).toEqual(['+1234567890']);
538
- expect(mergedIdentity.traits?.userIds).toEqual(['shopify_123']);
539
- expect(mergedIdentity.traits?.click?.gclid).toEqual('updated_gclid');
540
- });
541
- it('should properly detect click staleness when click info actually differs', () => {
542
- const cachedIdentity = {
543
- identityId: 'test-id',
544
- traits: {
545
- click: {
546
- gclid: 'original_gclid',
547
- gclidCollectedAt: '2024-05-15T12:32:58.424Z',
548
- },
549
- },
550
- };
551
- const incomingIdentity = {
552
- identityId: 'test-id',
553
- traits: {
554
- click: {
555
- gclid: 'completely_different_gclid',
556
- gclidCollectedAt: '2024-05-13T12:32:58.424Z',
557
- },
558
- },
559
- };
560
- const mergedTraits = mergeIdentityTraits(cachedIdentity.traits, incomingIdentity.traits);
561
- const mergedIdentity = { ...incomingIdentity, traits: mergedTraits };
562
- const result = isIdentityCacheStale(cachedIdentity, mergedIdentity);
563
- expect(mergedTraits?.click?.gclid).toEqual('original_gclid');
564
- expect(result.isCacheStale).toBe(false);
565
- });
566
- it('should handle scenario where cache is fresh', () => {
567
- const cachedIdentity = {
568
- identityId: 'test-id',
569
- traits: {
570
- emails: ['user@domain.com', 'secondary@domain.com'],
571
- userIds: ['user1', 'user2'],
572
- phones: ['+1234567890'],
573
- version: '2',
574
- },
575
- };
576
- const incomingIdentity = {
577
- identityId: 'test-id',
578
- traits: {
579
- emails: ['user@domain.com'],
580
- userIds: ['user1'],
581
- version: '2',
582
- },
583
- };
584
- const mergedTraits = mergeIdentityTraits(cachedIdentity.traits, incomingIdentity.traits);
585
- const mergedIdentity = { ...incomingIdentity, traits: mergedTraits };
586
- const result = isIdentityCacheStale(cachedIdentity, mergedIdentity);
587
- expect(result.isCacheStale).toBe(false);
588
- expect(mergedIdentity.traits?.emails).toEqual(['user@domain.com', 'secondary@domain.com']);
589
- expect(mergedIdentity.traits?.userIds).toEqual(['user1', 'user2']);
590
- expect(mergedIdentity.traits?.phones).toEqual(['+1234567890']);
591
- });
592
- });
593
- });
594
- describe('Three-Tier Staleness Model Tests', () => {
595
- afterEach(() => {
596
- jest.resetModules();
597
- });
598
- describe('TIER 1: VOLATILE_ONLY (no action needed)', () => {
599
- it('should return VOLATILE_ONLY tier when only ipAddress is stale', () => {
600
- const cachedIdentity = {
601
- identityId: 'test-id',
602
- traits: {
603
- emails: ['test@email.com'],
604
- ipAddress: '192.168.1.1',
605
- },
606
- };
607
- const incomingIdentity = {
608
- identityId: 'test-id',
609
- traits: {
610
- emails: ['test@email.com'],
611
- ipAddress: '10.0.0.1',
612
- },
613
- };
614
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
615
- expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
616
- expect(result.isCacheStale).toBe(false);
617
- expect(result.isIpAddressStale).toBe(true);
618
- });
619
- it('should return VOLATILE_ONLY tier when only userAgent is stale', () => {
620
- const cachedIdentity = {
621
- identityId: 'test-id',
622
- traits: {
623
- emails: ['test@email.com'],
624
- userAgent: 'Mozilla/5.0 (old)',
625
- },
626
- };
627
- const incomingIdentity = {
628
- identityId: 'test-id',
629
- traits: {
630
- emails: ['test@email.com'],
631
- userAgent: 'Mozilla/5.0 (new)',
632
- },
633
- };
634
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
635
- expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
636
- expect(result.isCacheStale).toBe(false);
637
- expect(result.isUserAgentStale).toBe(true);
638
- });
639
- it('should return VOLATILE_ONLY tier when only IP-sourced addresses are stale', () => {
640
- const cachedIdentity = {
641
- identityId: 'test-id',
642
- traits: {
643
- emails: ['test@email.com'],
644
- addresses: [
645
- { city: 'New York', country: 'USA', s: ADDRESS_INFO_SOURCE.IP_ADDRESS },
646
- ],
647
- },
648
- };
649
- const incomingIdentity = {
650
- identityId: 'test-id',
651
- traits: {
652
- emails: ['test@email.com'],
653
- addresses: [
654
- { city: 'Los Angeles', country: 'USA', s: ADDRESS_INFO_SOURCE.IP_ADDRESS },
655
- ],
656
- },
657
- };
658
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
659
- expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
660
- expect(result.isCacheStale).toBe(false);
661
- expect(result.isIpAddressesStale).toBe(true);
662
- expect(result.isNonIpAddressesStale).toBe(false);
663
- });
664
- it('should return VOLATILE_ONLY tier when multiple volatile traits are stale', () => {
665
- const cachedIdentity = {
666
- identityId: 'test-id',
667
- traits: {
668
- emails: ['test@email.com'],
669
- ipAddress: '192.168.1.1',
670
- userAgent: 'Mozilla/5.0 (old)',
671
- addresses: [
672
- { city: 'New York', s: ADDRESS_INFO_SOURCE.IP_ADDRESS },
673
- ],
674
- },
675
- };
676
- const incomingIdentity = {
677
- identityId: 'test-id',
678
- traits: {
679
- emails: ['test@email.com'],
680
- ipAddress: '10.0.0.1',
681
- userAgent: 'Mozilla/5.0 (new)',
682
- addresses: [
683
- { city: 'Chicago', s: ADDRESS_INFO_SOURCE.IP_ADDRESS },
684
- ],
685
- },
686
- };
687
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
688
- expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
689
- expect(result.isCacheStale).toBe(false);
690
- expect(result.isIpAddressStale).toBe(true);
691
- expect(result.isUserAgentStale).toBe(true);
692
- expect(result.isIpAddressesStale).toBe(true);
693
- });
694
- });
695
- describe('TIER 2: ADDRESS_UPDATE (cache write only, skip Neptune)', () => {
696
- it('should return ADDRESS_UPDATE tier when non-IP address is new', () => {
697
- const cachedIdentity = {
698
- identityId: 'test-id',
699
- traits: {
700
- emails: ['test@email.com'],
701
- addresses: [],
702
- },
703
- };
704
- const incomingIdentity = {
705
- identityId: 'test-id',
706
- traits: {
707
- emails: ['test@email.com'],
708
- addresses: [
709
- { city: 'Boston', province: 'MA', s: ADDRESS_INFO_SOURCE.INPUT },
710
- ],
711
- },
712
- };
713
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
714
- expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
715
- expect(result.isCacheStale).toBe(true);
716
- expect(result.isNonIpAddressesStale).toBe(true);
717
- });
718
- it('should return ADDRESS_UPDATE tier when new input address added', () => {
719
- const cachedIdentity = {
720
- identityId: 'test-id',
721
- traits: {
722
- emails: ['test@email.com'],
723
- addresses: [
724
- { city: 'New York', s: ADDRESS_INFO_SOURCE.INPUT },
725
- ],
726
- },
727
- };
728
- const incomingIdentity = {
729
- identityId: 'test-id',
730
- traits: {
731
- emails: ['test@email.com'],
732
- addresses: [
733
- { city: 'New York', s: ADDRESS_INFO_SOURCE.INPUT },
734
- { city: 'Boston', s: ADDRESS_INFO_SOURCE.INPUT },
735
- ],
736
- },
737
- };
738
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
739
- expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
740
- expect(result.isCacheStale).toBe(true);
741
- expect(result.isNonIpAddressesStale).toBe(true);
742
- });
743
- it('should return ADDRESS_UPDATE tier even when volatile traits are also stale', () => {
744
- const cachedIdentity = {
745
- identityId: 'test-id',
746
- traits: {
747
- emails: ['test@email.com'],
748
- ipAddress: '192.168.1.1',
749
- addresses: [],
750
- },
751
- };
752
- const incomingIdentity = {
753
- identityId: 'test-id',
754
- traits: {
755
- emails: ['test@email.com'],
756
- ipAddress: '10.0.0.1',
757
- addresses: [
758
- { city: 'Boston', s: ADDRESS_INFO_SOURCE.INPUT },
759
- ],
760
- },
761
- };
762
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
763
- expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
764
- expect(result.isCacheStale).toBe(true);
765
- expect(result.isIpAddressStale).toBe(true);
766
- expect(result.isNonIpAddressesStale).toBe(true);
767
- });
768
- });
769
- describe('TIER 3: IDENTITY_STALE (full Neptune resolution)', () => {
770
- it('should return IDENTITY_STALE tier when email is new', () => {
771
- const cachedIdentity = {
772
- identityId: 'test-id',
773
- traits: {
774
- emails: ['old@email.com'],
775
- },
776
- };
777
- const incomingIdentity = {
778
- identityId: 'test-id',
779
- traits: {
780
- emails: ['old@email.com', 'new@email.com'],
781
- },
782
- };
783
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
784
- expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
785
- expect(result.isCacheStale).toBe(true);
786
- expect(result.isEmailsStale).toBe(true);
787
- });
788
- it('should return IDENTITY_STALE tier when identityId changes', () => {
789
- const cachedIdentity = {
790
- identityId: 'old-id',
791
- traits: { emails: ['test@email.com'] },
792
- };
793
- const incomingIdentity = {
794
- identityId: 'new-id',
795
- traits: { emails: ['test@email.com'] },
796
- };
797
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
798
- expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
799
- expect(result.isCacheStale).toBe(true);
800
- expect(result.isIdentityIdStale).toBe(true);
801
- });
802
- it('should return IDENTITY_STALE tier when phone is new', () => {
803
- const cachedIdentity = {
804
- identityId: 'test-id',
805
- traits: { phones: ['+1234567890'] },
806
- };
807
- const incomingIdentity = {
808
- identityId: 'test-id',
809
- traits: { phones: ['+1234567890', '+9876543210'] },
810
- };
811
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
812
- expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
813
- expect(result.isCacheStale).toBe(true);
814
- expect(result.isPhonesStale).toBe(true);
815
- });
816
- it('should return IDENTITY_STALE tier when click info changes', () => {
817
- const cachedIdentity = {
818
- identityId: 'test-id',
819
- traits: {
820
- click: { gclid: 'old_gclid' },
821
- },
822
- };
823
- const incomingIdentity = {
824
- identityId: 'test-id',
825
- traits: {
826
- click: { gclid: 'new_gclid' },
827
- },
828
- };
829
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
830
- expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
831
- expect(result.isCacheStale).toBe(true);
832
- expect(result.isClickInfosStale).toBe(true);
833
- });
834
- it('should return IDENTITY_STALE tier when identity trait is stale even with ADDRESS_UPDATE', () => {
835
- const cachedIdentity = {
836
- identityId: 'test-id',
837
- traits: {
838
- emails: ['old@email.com'],
839
- addresses: [],
840
- },
841
- };
842
- const incomingIdentity = {
843
- identityId: 'test-id',
844
- traits: {
845
- emails: ['old@email.com', 'new@email.com'],
846
- addresses: [
847
- { city: 'Boston', s: ADDRESS_INFO_SOURCE.INPUT },
848
- ],
849
- },
850
- };
851
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
852
- expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
853
- expect(result.isCacheStale).toBe(true);
854
- expect(result.isEmailsStale).toBe(true);
855
- expect(result.isNonIpAddressesStale).toBe(true);
856
- });
857
- it('should return IDENTITY_STALE tier when identity trait is stale even with VOLATILE_ONLY', () => {
858
- const cachedIdentity = {
859
- identityId: 'test-id',
860
- traits: {
861
- emails: ['old@email.com'],
862
- ipAddress: '192.168.1.1',
863
- },
864
- };
865
- const incomingIdentity = {
866
- identityId: 'test-id',
867
- traits: {
868
- emails: ['old@email.com', 'new@email.com'],
869
- ipAddress: '10.0.0.1',
870
- },
871
- };
872
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
873
- expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
874
- expect(result.isCacheStale).toBe(true);
875
- expect(result.isEmailsStale).toBe(true);
876
- expect(result.isIpAddressStale).toBe(true);
877
- });
878
- });
879
- describe('TIER NONE: No staleness', () => {
880
- it('should return NONE tier when nothing is stale', () => {
881
- const cachedIdentity = {
882
- identityId: 'test-id',
883
- traits: {
884
- emails: ['test@email.com'],
885
- phones: ['+1234567890'],
886
- ipAddress: '192.168.1.1',
887
- },
888
- };
889
- const incomingIdentity = {
890
- identityId: 'test-id',
891
- traits: {
892
- emails: ['test@email.com'],
893
- phones: ['+1234567890'],
894
- ipAddress: '192.168.1.1',
895
- },
896
- };
897
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
898
- expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.NONE);
899
- expect(result.isCacheStale).toBe(false);
900
- });
901
- it('should return NONE tier when incoming is subset of cached', () => {
902
- const cachedIdentity = {
903
- identityId: 'test-id',
904
- traits: {
905
- emails: ['a@email.com', 'b@email.com'],
906
- phones: ['+1234567890', '+9876543210'],
907
- },
908
- };
909
- const incomingIdentity = {
910
- identityId: 'test-id',
911
- traits: {
912
- emails: ['a@email.com'],
913
- },
914
- };
915
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
916
- expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.NONE);
917
- expect(result.isCacheStale).toBe(false);
918
- });
919
- });
920
- describe('Address source filtering', () => {
921
- it('should correctly identify IP-sourced addresses', () => {
922
- const cachedIdentity = {
923
- identityId: 'test-id',
924
- traits: {
925
- addresses: [
926
- { city: 'CachedCity', s: ADDRESS_INFO_SOURCE.IP_ADDRESS },
927
- ],
928
- },
929
- };
930
- const incomingIdentity = {
931
- identityId: 'test-id',
932
- traits: {
933
- addresses: [
934
- { city: 'NewCity', s: ADDRESS_INFO_SOURCE.IP_ADDRESS },
935
- ],
936
- },
937
- };
938
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
939
- expect(result.isIpAddressesStale).toBe(true);
940
- expect(result.isNonIpAddressesStale).toBe(false);
941
- expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
942
- });
943
- it('should correctly identify INPUT-sourced addresses', () => {
944
- const cachedIdentity = {
945
- identityId: 'test-id',
946
- traits: {
947
- addresses: [
948
- { city: 'CachedCity', s: ADDRESS_INFO_SOURCE.INPUT },
949
- ],
950
- },
951
- };
952
- const incomingIdentity = {
953
- identityId: 'test-id',
954
- traits: {
955
- addresses: [
956
- { city: 'CachedCity', s: ADDRESS_INFO_SOURCE.INPUT },
957
- { city: 'NewCity', s: ADDRESS_INFO_SOURCE.INPUT },
958
- ],
959
- },
960
- };
961
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
962
- expect(result.isIpAddressesStale).toBe(false);
963
- expect(result.isNonIpAddressesStale).toBe(true);
964
- expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
965
- });
966
- it('should handle mixed address sources correctly', () => {
967
- const cachedIdentity = {
968
- identityId: 'test-id',
969
- traits: {
970
- addresses: [
971
- { city: 'IPCity', s: ADDRESS_INFO_SOURCE.IP_ADDRESS },
972
- { city: 'InputCity', s: ADDRESS_INFO_SOURCE.INPUT },
973
- ],
974
- },
975
- };
976
- const incomingIdentity = {
977
- identityId: 'test-id',
978
- traits: {
979
- addresses: [
980
- { city: 'NewIPCity', s: ADDRESS_INFO_SOURCE.IP_ADDRESS },
981
- { city: 'InputCity', s: ADDRESS_INFO_SOURCE.INPUT },
982
- { city: 'NewInputCity', s: ADDRESS_INFO_SOURCE.INPUT },
983
- ],
984
- },
985
- };
986
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
987
- expect(result.isIpAddressesStale).toBe(true);
988
- expect(result.isNonIpAddressesStale).toBe(true);
989
- expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
990
- expect(result.isCacheStale).toBe(true);
991
- });
992
- it('should handle addresses without source field (default to IP based on PII)', () => {
993
- const cachedIdentity = {
994
- identityId: 'test-id',
995
- traits: {
996
- addresses: [],
997
- },
998
- };
999
- const incomingIdentity = {
1000
- identityId: 'test-id',
1001
- traits: {
1002
- addresses: [
1003
- { city: 'NoSourceCity' },
1004
- ],
1005
- },
1006
- };
1007
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
1008
- expect(result.isIpAddressesStale).toBe(true);
1009
- expect(result.isNonIpAddressesStale).toBe(false);
1010
- expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
1011
- expect(result.isCacheStale).toBe(false);
1012
- });
1013
- it('should treat addresses without source but with PII as non-IP', () => {
1014
- const cachedIdentity = {
1015
- identityId: 'test-id',
1016
- traits: {
1017
- addresses: [],
1018
- },
1019
- };
1020
- const incomingIdentity = {
1021
- identityId: 'test-id',
1022
- traits: {
1023
- addresses: [
1024
- { city: 'InputCity', firstName: 'John' },
1025
- ],
1026
- },
1027
- };
1028
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
1029
- expect(result.isNonIpAddressesStale).toBe(true);
1030
- expect(result.isIpAddressesStale).toBe(false);
1031
- expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
1032
- expect(result.isCacheStale).toBe(true);
1033
- });
1034
- });
1035
- describe('Backward compatibility', () => {
1036
- it('should maintain isAddressesStale for any address change', () => {
1037
- const cachedIdentity = {
1038
- identityId: 'test-id',
1039
- traits: {
1040
- addresses: [
1041
- { city: 'OldCity', s: ADDRESS_INFO_SOURCE.IP_ADDRESS },
1042
- ],
1043
- },
1044
- };
1045
- const incomingIdentity = {
1046
- identityId: 'test-id',
1047
- traits: {
1048
- addresses: [
1049
- { city: 'NewCity', s: ADDRESS_INFO_SOURCE.IP_ADDRESS },
1050
- ],
1051
- },
1052
- };
1053
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
1054
- expect(result.isAddressesStale).toBe(true);
1055
- expect(result.isCacheStale).toBe(false);
1056
- });
1057
- });
1058
- });
1
+ import { ADDRESS_INFO_SOURCE } from '@adtrackify/at-tracking-event-types';
2
+ import { mergeIdentityTraits } from '@adtrackify/at-shared-utils';
3
+ import { isIdentityCacheStale, isClickInfosStale, IDENTITY_CACHE_STALENESS_TIER, } from '../../helpers/identity-cache-helper';
4
+ describe('Identity Trait Merging Tests', () => {
5
+ afterEach(() => {
6
+ jest.resetModules();
7
+ });
8
+ describe('mergeIdentityTraits function', () => {
9
+ it('should merge simple string arrays correctly', () => {
10
+ const incomingTraits = {
11
+ emails: ['new@email.com'],
12
+ userIds: ['user1', 'user2'],
13
+ };
14
+ const cachedTraits = {
15
+ emails: ['existing@email.com'],
16
+ userIds: ['user2', 'user3'],
17
+ phones: ['+1234567890'],
18
+ };
19
+ const merged = mergeIdentityTraits(incomingTraits, cachedTraits);
20
+ expect(merged.emails).toEqual(['new@email.com', 'existing@email.com']);
21
+ expect(merged.userIds).toEqual(['user1', 'user2', 'user3']);
22
+ expect(merged.phones).toEqual(['+1234567890']);
23
+ });
24
+ it('should handle null and undefined values in arrays', () => {
25
+ const incomingTraits = {
26
+ emails: ['test@email.com', null, undefined],
27
+ userIds: ['user1'],
28
+ };
29
+ const cachedTraits = {
30
+ emails: [null, 'cached@email.com', undefined],
31
+ userIds: null,
32
+ };
33
+ const merged = mergeIdentityTraits(incomingTraits, cachedTraits);
34
+ expect(merged.emails).toContain('test@email.com');
35
+ expect(merged.emails).toContain('cached@email.com');
36
+ expect(merged.userIds).toEqual(['user1']);
37
+ });
38
+ it('should merge addresses correctly', () => {
39
+ const incomingTraits = {
40
+ addresses: [
41
+ {
42
+ city: 'New York',
43
+ country: 'USA',
44
+ countryCode: 'US',
45
+ province: 'NY',
46
+ provinceCode: '10001',
47
+ },
48
+ ],
49
+ };
50
+ const cachedTraits = {
51
+ addresses: [
52
+ {
53
+ city: 'Los Angeles',
54
+ country: 'USA',
55
+ countryCode: 'US',
56
+ province: 'CA',
57
+ provinceCode: '90210',
58
+ },
59
+ ],
60
+ };
61
+ const merged = mergeIdentityTraits(incomingTraits, cachedTraits);
62
+ expect(merged.addresses).toHaveLength(2);
63
+ expect(merged.addresses).toEqual(expect.arrayContaining([
64
+ expect.objectContaining({ city: 'New York' }),
65
+ expect.objectContaining({ city: 'Los Angeles' }),
66
+ ]));
67
+ });
68
+ it('should merge click information correctly', () => {
69
+ const incomingTraits = {
70
+ click: {
71
+ fbp: 'fb.new.123',
72
+ fbpCollectedAt: '2024-01-01T00:00:00.000Z',
73
+ gclid: 'new_gclid',
74
+ },
75
+ };
76
+ const cachedTraits = {
77
+ click: {
78
+ fbp: 'fb.old.456',
79
+ fbpCollectedAt: '2023-12-01T00:00:00.000Z',
80
+ fbclid: 'cached_fbclid',
81
+ },
82
+ };
83
+ const merged = mergeIdentityTraits(incomingTraits, cachedTraits);
84
+ expect(merged.click?.fbp).toBe('fb.new.123');
85
+ expect(merged.click?.gclid).toBe('new_gclid');
86
+ expect(merged.click?.fbpCollectedAt).toBe('2024-01-01T00:00:00.000Z');
87
+ expect(merged.click?.fbclid).toBeUndefined();
88
+ });
89
+ it('should handle empty traits correctly', () => {
90
+ const incomingTraits = {};
91
+ const cachedTraits = {
92
+ emails: ['cached@email.com'],
93
+ userIds: ['user1'],
94
+ };
95
+ const merged = mergeIdentityTraits(incomingTraits, cachedTraits);
96
+ expect(merged.emails).toEqual(['cached@email.com']);
97
+ expect(merged.userIds).toEqual(['user1']);
98
+ });
99
+ it('should handle undefined traits correctly', () => {
100
+ const merged1 = mergeIdentityTraits(undefined, { emails: ['test@email.com'] });
101
+ expect(merged1.emails).toEqual(['test@email.com']);
102
+ const merged2 = mergeIdentityTraits({ emails: ['test@email.com'] }, undefined);
103
+ expect(merged2.emails).toEqual(['test@email.com']);
104
+ const merged3 = mergeIdentityTraits(undefined, undefined);
105
+ expect(merged3).toEqual({});
106
+ });
107
+ it('should preserve version information', () => {
108
+ const incomingTraits = {
109
+ version: '3',
110
+ emails: ['new@email.com'],
111
+ };
112
+ const cachedTraits = {
113
+ version: '2',
114
+ emails: ['old@email.com'],
115
+ };
116
+ const merged = mergeIdentityTraits(incomingTraits, cachedTraits);
117
+ expect(merged.version).toBe('3');
118
+ expect(merged.emails).toEqual(['new@email.com', 'old@email.com']);
119
+ });
120
+ it('should handle complex nested objects', () => {
121
+ const incomingTraits = {
122
+ click: {
123
+ googleClientInfos: [{ id: 'new1', clickId: 'click1', sessionId: 'session1' }],
124
+ },
125
+ };
126
+ const cachedTraits = {
127
+ click: {
128
+ googleClientInfos: [{ id: 'cached1', clickId: 'click2', sessionId: 'session2' }],
129
+ },
130
+ };
131
+ const merged = mergeIdentityTraits(incomingTraits, cachedTraits);
132
+ expect(merged.click?.googleClientInfos).toBeDefined();
133
+ expect(Array.isArray(merged.click?.googleClientInfos)).toBe(true);
134
+ expect(merged.click?.googleClientInfos).toEqual([{ id: 'cached1', clickId: 'click2', sessionId: 'session2' }]);
135
+ });
136
+ });
137
+ describe('Integration: Merging + Staleness Checking', () => {
138
+ it('should not be stale when merged identity matches cached identity', () => {
139
+ const cachedIdentity = {
140
+ identityId: 'test-id-123',
141
+ traits: {
142
+ emails: ['cached@email.com', 'shared@email.com'],
143
+ userIds: ['user1', 'user2'],
144
+ addresses: [
145
+ {
146
+ city: 'New York',
147
+ country: 'USA',
148
+ countryCode: 'US',
149
+ },
150
+ ],
151
+ version: '2',
152
+ },
153
+ };
154
+ const incomingIdentity = {
155
+ identityId: 'test-id-123',
156
+ traits: {
157
+ emails: ['shared@email.com'],
158
+ userIds: ['user1'],
159
+ version: '2',
160
+ },
161
+ };
162
+ const mergedTraits = mergeIdentityTraits(incomingIdentity.traits, cachedIdentity.traits);
163
+ const mergedIdentity = { ...incomingIdentity, traits: mergedTraits };
164
+ const staleTracker = isIdentityCacheStale(cachedIdentity, mergedIdentity);
165
+ expect(staleTracker.isCacheStale).toBe(false);
166
+ expect(mergedIdentity.traits?.emails).toEqual(['shared@email.com', 'cached@email.com']);
167
+ });
168
+ it('should be stale when merged identity has new traits', () => {
169
+ const cachedIdentity = {
170
+ identityId: 'test-id-123',
171
+ traits: {
172
+ emails: ['cached@email.com'],
173
+ version: '2',
174
+ },
175
+ };
176
+ const incomingIdentity = {
177
+ identityId: 'test-id-123',
178
+ traits: {
179
+ emails: ['cached@email.com', 'new@email.com'],
180
+ version: '2',
181
+ },
182
+ };
183
+ const mergedTraits = mergeIdentityTraits(incomingIdentity.traits, cachedIdentity.traits);
184
+ const mergedIdentity = { ...incomingIdentity, traits: mergedTraits };
185
+ const staleTracker = isIdentityCacheStale(cachedIdentity, mergedIdentity);
186
+ expect(staleTracker.isCacheStale).toBe(true);
187
+ expect(staleTracker.isEmailsStale).toBe(true);
188
+ });
189
+ });
190
+ });
191
+ describe('Identity Cache Staleness Tests', () => {
192
+ afterEach(() => {
193
+ jest.resetModules();
194
+ });
195
+ describe('isIdentityCacheStale function', () => {
196
+ it('should detect identity ID changes', () => {
197
+ const cachedIdentity = {
198
+ identityId: 'old-id',
199
+ traits: { emails: ['test@email.com'] },
200
+ };
201
+ const incomingIdentity = {
202
+ identityId: 'new-id',
203
+ traits: { emails: ['test@email.com'] },
204
+ };
205
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
206
+ expect(result.isCacheStale).toBe(true);
207
+ expect(result.isIdentityIdStale).toBe(true);
208
+ });
209
+ it('should detect new emails', () => {
210
+ const cachedIdentity = {
211
+ identityId: 'test-id',
212
+ traits: { emails: ['old@email.com'] },
213
+ };
214
+ const incomingIdentity = {
215
+ identityId: 'test-id',
216
+ traits: { emails: ['old@email.com', 'new@email.com'] },
217
+ };
218
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
219
+ expect(result.isCacheStale).toBe(true);
220
+ expect(result.isEmailsStale).toBe(true);
221
+ });
222
+ it('should detect new user IDs', () => {
223
+ const cachedIdentity = {
224
+ identityId: 'test-id',
225
+ traits: { userIds: ['user1'] },
226
+ };
227
+ const incomingIdentity = {
228
+ identityId: 'test-id',
229
+ traits: { userIds: ['user1', 'user2'] },
230
+ };
231
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
232
+ expect(result.isCacheStale).toBe(true);
233
+ expect(result.isUserIdsStale).toBe(true);
234
+ });
235
+ it('should detect new phones', () => {
236
+ const cachedIdentity = {
237
+ identityId: 'test-id',
238
+ traits: { phones: ['+1234567890'] },
239
+ };
240
+ const incomingIdentity = {
241
+ identityId: 'test-id',
242
+ traits: { phones: ['+1234567890', '+9876543210'] },
243
+ };
244
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
245
+ expect(result.isCacheStale).toBe(true);
246
+ expect(result.isPhonesStale).toBe(true);
247
+ });
248
+ it('should detect new addresses (non-IP sourced)', () => {
249
+ const cachedIdentity = {
250
+ identityId: 'test-id',
251
+ traits: {
252
+ addresses: [
253
+ {
254
+ city: 'New York',
255
+ country: 'USA',
256
+ s: ADDRESS_INFO_SOURCE.INPUT,
257
+ },
258
+ ],
259
+ },
260
+ };
261
+ const incomingIdentity = {
262
+ identityId: 'test-id',
263
+ traits: {
264
+ addresses: [
265
+ { city: 'New York', country: 'USA', s: ADDRESS_INFO_SOURCE.INPUT },
266
+ { city: 'Los Angeles', country: 'USA', s: ADDRESS_INFO_SOURCE.INPUT },
267
+ ],
268
+ },
269
+ };
270
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
271
+ expect(result.isCacheStale).toBe(true);
272
+ expect(result.isAddressesStale).toBe(true);
273
+ expect(result.isNonIpAddressesStale).toBe(true);
274
+ expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
275
+ });
276
+ it('should detect IP address changes but NOT mark cache stale (volatile trait)', () => {
277
+ const cachedIdentity = {
278
+ identityId: 'test-id',
279
+ traits: { ipAddress: '192.168.1.1' },
280
+ };
281
+ const incomingIdentity = {
282
+ identityId: 'test-id',
283
+ traits: { ipAddress: '10.0.0.1' },
284
+ };
285
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
286
+ expect(result.isCacheStale).toBe(false);
287
+ expect(result.isIpAddressStale).toBe(true);
288
+ expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
289
+ });
290
+ it('should detect user agent changes but NOT mark cache stale (volatile trait)', () => {
291
+ const cachedIdentity = {
292
+ identityId: 'test-id',
293
+ traits: { userAgent: 'Mozilla/5.0 (old browser)' },
294
+ };
295
+ const incomingIdentity = {
296
+ identityId: 'test-id',
297
+ traits: { userAgent: 'Mozilla/5.0 (new browser)' },
298
+ };
299
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
300
+ expect(result.isCacheStale).toBe(false);
301
+ expect(result.isUserAgentStale).toBe(true);
302
+ expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
303
+ });
304
+ it('should not be stale when no new information is provided', () => {
305
+ const cachedIdentity = {
306
+ identityId: 'test-id',
307
+ traits: {
308
+ emails: ['test@email.com'],
309
+ userIds: ['user1'],
310
+ phones: ['+1234567890'],
311
+ },
312
+ };
313
+ const incomingIdentity = {
314
+ identityId: 'test-id',
315
+ traits: {
316
+ emails: ['test@email.com'],
317
+ userIds: ['user1'],
318
+ },
319
+ };
320
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
321
+ expect(result.isCacheStale).toBe(false);
322
+ });
323
+ it('should handle empty traits gracefully', () => {
324
+ const cachedIdentity = {
325
+ identityId: 'test-id',
326
+ traits: {},
327
+ };
328
+ const incomingIdentity = {
329
+ identityId: 'test-id',
330
+ traits: {},
331
+ };
332
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
333
+ expect(result.isCacheStale).toBe(false);
334
+ });
335
+ it('should handle undefined traits gracefully', () => {
336
+ const cachedIdentity = {
337
+ identityId: 'test-id',
338
+ };
339
+ const incomingIdentity = {
340
+ identityId: 'test-id',
341
+ };
342
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
343
+ expect(result.isCacheStale).toBe(false);
344
+ });
345
+ it('should detect multiple stale conditions (identity traits take priority over volatile)', () => {
346
+ const cachedIdentity = {
347
+ identityId: 'test-id',
348
+ traits: {
349
+ emails: ['old@email.com'],
350
+ userIds: ['user1'],
351
+ ipAddress: '192.168.1.1',
352
+ },
353
+ };
354
+ const incomingIdentity = {
355
+ identityId: 'test-id',
356
+ traits: {
357
+ emails: ['old@email.com', 'new@email.com'],
358
+ userIds: ['user1', 'user2'],
359
+ ipAddress: '10.0.0.1',
360
+ },
361
+ };
362
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
363
+ expect(result.isCacheStale).toBe(true);
364
+ expect(result.isEmailsStale).toBe(true);
365
+ expect(result.isUserIdsStale).toBe(true);
366
+ expect(result.isIpAddressStale).toBe(true);
367
+ expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
368
+ });
369
+ });
370
+ describe('isClickInfosStale function', () => {
371
+ it('should detect new FBC values', () => {
372
+ const cachedClick = {
373
+ fbc: 'fb.1.123.old_fbclid',
374
+ };
375
+ const incomingClick = {
376
+ fbc: 'fb.1.123.new_fbclid',
377
+ };
378
+ const result = isClickInfosStale(cachedClick, incomingClick);
379
+ expect(result).toBe(true);
380
+ });
381
+ it('should detect new click IDs', () => {
382
+ const cachedClick = {
383
+ gclid: 'old_gclid',
384
+ };
385
+ const incomingClick = {
386
+ gclid: 'new_gclid',
387
+ };
388
+ const result = isClickInfosStale(cachedClick, incomingClick);
389
+ expect(result).toBe(true);
390
+ });
391
+ it('should ignore collection timestamps', () => {
392
+ const cachedClick = {
393
+ fbp: 'fb.2.123.456',
394
+ fbpCollectedAt: '2023-01-01T00:00:00.000Z',
395
+ };
396
+ const incomingClick = {
397
+ fbp: 'fb.2.123.456',
398
+ fbpCollectedAt: '2024-01-01T00:00:00.000Z',
399
+ };
400
+ const result = isClickInfosStale(cachedClick, incomingClick);
401
+ expect(result).toBe(false);
402
+ });
403
+ it('should ignore googleClientInfos', () => {
404
+ const cachedClick = {
405
+ googleClientInfos: [{ id: 'old', clickId: 'old_click' }],
406
+ };
407
+ const incomingClick = {
408
+ googleClientInfos: [{ id: 'new', clickId: 'new_click' }],
409
+ };
410
+ const result = isClickInfosStale(cachedClick, incomingClick);
411
+ expect(result).toBe(false);
412
+ });
413
+ it('should handle empty click info', () => {
414
+ const result = isClickInfosStale({}, {});
415
+ expect(result).toBe(false);
416
+ });
417
+ it('should detect when incoming has new click info but cached is empty', () => {
418
+ const cachedClick = {};
419
+ const incomingClick = {
420
+ fbp: 'fb.2.123.456',
421
+ };
422
+ const result = isClickInfosStale(cachedClick, incomingClick);
423
+ expect(result).toBe(true);
424
+ });
425
+ });
426
+ describe('Edge Cases and Error Handling', () => {
427
+ it('should handle malformed FBC values gracefully', () => {
428
+ const cachedClick = {
429
+ fbc: 'malformed_fbc',
430
+ };
431
+ const incomingClick = {
432
+ fbc: 'also_malformed',
433
+ };
434
+ const result = isClickInfosStale(cachedClick, incomingClick);
435
+ expect(result).toBe(true);
436
+ });
437
+ it('should handle null/undefined arrays in traits', () => {
438
+ const cachedIdentity = {
439
+ identityId: 'test-id',
440
+ traits: {
441
+ emails: null,
442
+ userIds: undefined,
443
+ },
444
+ };
445
+ const incomingIdentity = {
446
+ identityId: 'test-id',
447
+ traits: {
448
+ emails: ['new@email.com'],
449
+ userIds: ['user1'],
450
+ },
451
+ };
452
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
453
+ expect(result.isCacheStale).toBe(true);
454
+ expect(result.isEmailsStale).toBe(true);
455
+ expect(result.isUserIdsStale).toBe(true);
456
+ });
457
+ it('should handle arrays with null/undefined elements', () => {
458
+ const cachedIdentity = {
459
+ identityId: 'test-id',
460
+ traits: {
461
+ emails: ['valid@email.com', null, undefined],
462
+ },
463
+ };
464
+ const incomingIdentity = {
465
+ identityId: 'test-id',
466
+ traits: {
467
+ emails: ['valid@email.com', null, undefined, 'new@email.com'],
468
+ },
469
+ };
470
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
471
+ expect(result.isCacheStale).toBe(true);
472
+ expect(result.isEmailsStale).toBe(true);
473
+ });
474
+ it('should handle error conditions gracefully', () => {
475
+ const result = isIdentityCacheStale(null, undefined);
476
+ expect(result.isCacheStale).toBe(false);
477
+ });
478
+ });
479
+ describe('Comprehensive Scenario Tests', () => {
480
+ it('should handle complex real-world scenario', () => {
481
+ const cachedIdentity = {
482
+ identityId: '01HXRZ27H4TXWBBTRK09Q7APDP',
483
+ traits: {
484
+ emails: ['user@domain.com'],
485
+ userIds: ['shopify_123'],
486
+ addresses: [
487
+ {
488
+ city: 'New York',
489
+ country: 'USA',
490
+ countryCode: 'US',
491
+ province: 'NY',
492
+ provinceCode: '10001',
493
+ },
494
+ ],
495
+ click: {
496
+ fbp: 'fb.2.1715603578424.5068754021',
497
+ fbpCollectedAt: '2024-05-13T12:32:58.424Z',
498
+ gclid: 'original_gclid',
499
+ },
500
+ ipAddress: '192.168.1.100',
501
+ version: '2',
502
+ },
503
+ };
504
+ const incomingIdentity = {
505
+ identityId: '01HXRZ27H4TXWBBTRK09Q7APDP',
506
+ traits: {
507
+ emails: ['user@domain.com', 'user.secondary@domain.com'],
508
+ phones: ['+1234567890'],
509
+ addresses: [
510
+ {
511
+ city: 'New York',
512
+ country: 'USA',
513
+ countryCode: 'US',
514
+ province: 'NY',
515
+ provinceCode: '10001',
516
+ },
517
+ ],
518
+ click: {
519
+ fbp: 'fb.2.1715603578424.5068754021',
520
+ fbpCollectedAt: '2024-05-13T15:30:00.000Z',
521
+ gclid: 'updated_gclid',
522
+ },
523
+ ipAddress: '192.168.1.100',
524
+ version: '2',
525
+ },
526
+ };
527
+ const mergedTraits = mergeIdentityTraits(cachedIdentity.traits, incomingIdentity.traits);
528
+ const mergedIdentity = { ...incomingIdentity, traits: mergedTraits };
529
+ const result = isIdentityCacheStale(cachedIdentity, mergedIdentity);
530
+ expect(result.isCacheStale).toBe(true);
531
+ expect(result.isEmailsStale).toBe(true);
532
+ expect(result.isPhonesStale).toBe(true);
533
+ expect(result.isClickInfosStale).toBe(true);
534
+ expect(result.isAddressesStale).toBe(false);
535
+ expect(result.isIpAddressStale).toBe(false);
536
+ expect(mergedIdentity.traits?.emails).toEqual(['user@domain.com', 'user.secondary@domain.com']);
537
+ expect(mergedIdentity.traits?.phones).toEqual(['+1234567890']);
538
+ expect(mergedIdentity.traits?.userIds).toEqual(['shopify_123']);
539
+ expect(mergedIdentity.traits?.click?.gclid).toEqual('updated_gclid');
540
+ });
541
+ it('should properly detect click staleness when click info actually differs', () => {
542
+ const cachedIdentity = {
543
+ identityId: 'test-id',
544
+ traits: {
545
+ click: {
546
+ gclid: 'original_gclid',
547
+ gclidCollectedAt: '2024-05-15T12:32:58.424Z',
548
+ },
549
+ },
550
+ };
551
+ const incomingIdentity = {
552
+ identityId: 'test-id',
553
+ traits: {
554
+ click: {
555
+ gclid: 'completely_different_gclid',
556
+ gclidCollectedAt: '2024-05-13T12:32:58.424Z',
557
+ },
558
+ },
559
+ };
560
+ const mergedTraits = mergeIdentityTraits(cachedIdentity.traits, incomingIdentity.traits);
561
+ const mergedIdentity = { ...incomingIdentity, traits: mergedTraits };
562
+ const result = isIdentityCacheStale(cachedIdentity, mergedIdentity);
563
+ expect(mergedTraits?.click?.gclid).toEqual('original_gclid');
564
+ expect(result.isCacheStale).toBe(false);
565
+ });
566
+ it('should handle scenario where cache is fresh', () => {
567
+ const cachedIdentity = {
568
+ identityId: 'test-id',
569
+ traits: {
570
+ emails: ['user@domain.com', 'secondary@domain.com'],
571
+ userIds: ['user1', 'user2'],
572
+ phones: ['+1234567890'],
573
+ version: '2',
574
+ },
575
+ };
576
+ const incomingIdentity = {
577
+ identityId: 'test-id',
578
+ traits: {
579
+ emails: ['user@domain.com'],
580
+ userIds: ['user1'],
581
+ version: '2',
582
+ },
583
+ };
584
+ const mergedTraits = mergeIdentityTraits(cachedIdentity.traits, incomingIdentity.traits);
585
+ const mergedIdentity = { ...incomingIdentity, traits: mergedTraits };
586
+ const result = isIdentityCacheStale(cachedIdentity, mergedIdentity);
587
+ expect(result.isCacheStale).toBe(false);
588
+ expect(mergedIdentity.traits?.emails).toEqual(['user@domain.com', 'secondary@domain.com']);
589
+ expect(mergedIdentity.traits?.userIds).toEqual(['user1', 'user2']);
590
+ expect(mergedIdentity.traits?.phones).toEqual(['+1234567890']);
591
+ });
592
+ });
593
+ });
594
+ describe('Three-Tier Staleness Model Tests', () => {
595
+ afterEach(() => {
596
+ jest.resetModules();
597
+ });
598
+ describe('TIER 1: VOLATILE_ONLY (no action needed)', () => {
599
+ it('should return VOLATILE_ONLY tier when only ipAddress is stale', () => {
600
+ const cachedIdentity = {
601
+ identityId: 'test-id',
602
+ traits: {
603
+ emails: ['test@email.com'],
604
+ ipAddress: '192.168.1.1',
605
+ },
606
+ };
607
+ const incomingIdentity = {
608
+ identityId: 'test-id',
609
+ traits: {
610
+ emails: ['test@email.com'],
611
+ ipAddress: '10.0.0.1',
612
+ },
613
+ };
614
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
615
+ expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
616
+ expect(result.isCacheStale).toBe(false);
617
+ expect(result.isIpAddressStale).toBe(true);
618
+ });
619
+ it('should return VOLATILE_ONLY tier when only userAgent is stale', () => {
620
+ const cachedIdentity = {
621
+ identityId: 'test-id',
622
+ traits: {
623
+ emails: ['test@email.com'],
624
+ userAgent: 'Mozilla/5.0 (old)',
625
+ },
626
+ };
627
+ const incomingIdentity = {
628
+ identityId: 'test-id',
629
+ traits: {
630
+ emails: ['test@email.com'],
631
+ userAgent: 'Mozilla/5.0 (new)',
632
+ },
633
+ };
634
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
635
+ expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
636
+ expect(result.isCacheStale).toBe(false);
637
+ expect(result.isUserAgentStale).toBe(true);
638
+ });
639
+ it('should return VOLATILE_ONLY tier when only IP-sourced addresses are stale', () => {
640
+ const cachedIdentity = {
641
+ identityId: 'test-id',
642
+ traits: {
643
+ emails: ['test@email.com'],
644
+ addresses: [
645
+ { city: 'New York', country: 'USA', s: ADDRESS_INFO_SOURCE.IP_ADDRESS },
646
+ ],
647
+ },
648
+ };
649
+ const incomingIdentity = {
650
+ identityId: 'test-id',
651
+ traits: {
652
+ emails: ['test@email.com'],
653
+ addresses: [
654
+ { city: 'Los Angeles', country: 'USA', s: ADDRESS_INFO_SOURCE.IP_ADDRESS },
655
+ ],
656
+ },
657
+ };
658
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
659
+ expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
660
+ expect(result.isCacheStale).toBe(false);
661
+ expect(result.isIpAddressesStale).toBe(true);
662
+ expect(result.isNonIpAddressesStale).toBe(false);
663
+ });
664
+ it('should return VOLATILE_ONLY tier when multiple volatile traits are stale', () => {
665
+ const cachedIdentity = {
666
+ identityId: 'test-id',
667
+ traits: {
668
+ emails: ['test@email.com'],
669
+ ipAddress: '192.168.1.1',
670
+ userAgent: 'Mozilla/5.0 (old)',
671
+ addresses: [
672
+ { city: 'New York', s: ADDRESS_INFO_SOURCE.IP_ADDRESS },
673
+ ],
674
+ },
675
+ };
676
+ const incomingIdentity = {
677
+ identityId: 'test-id',
678
+ traits: {
679
+ emails: ['test@email.com'],
680
+ ipAddress: '10.0.0.1',
681
+ userAgent: 'Mozilla/5.0 (new)',
682
+ addresses: [
683
+ { city: 'Chicago', s: ADDRESS_INFO_SOURCE.IP_ADDRESS },
684
+ ],
685
+ },
686
+ };
687
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
688
+ expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
689
+ expect(result.isCacheStale).toBe(false);
690
+ expect(result.isIpAddressStale).toBe(true);
691
+ expect(result.isUserAgentStale).toBe(true);
692
+ expect(result.isIpAddressesStale).toBe(true);
693
+ });
694
+ });
695
+ describe('TIER 2: ADDRESS_UPDATE (cache write only, skip Neptune)', () => {
696
+ it('should return ADDRESS_UPDATE tier when non-IP address is new', () => {
697
+ const cachedIdentity = {
698
+ identityId: 'test-id',
699
+ traits: {
700
+ emails: ['test@email.com'],
701
+ addresses: [],
702
+ },
703
+ };
704
+ const incomingIdentity = {
705
+ identityId: 'test-id',
706
+ traits: {
707
+ emails: ['test@email.com'],
708
+ addresses: [
709
+ { city: 'Boston', province: 'MA', s: ADDRESS_INFO_SOURCE.INPUT },
710
+ ],
711
+ },
712
+ };
713
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
714
+ expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
715
+ expect(result.isCacheStale).toBe(true);
716
+ expect(result.isNonIpAddressesStale).toBe(true);
717
+ });
718
+ it('should return ADDRESS_UPDATE tier when new input address added', () => {
719
+ const cachedIdentity = {
720
+ identityId: 'test-id',
721
+ traits: {
722
+ emails: ['test@email.com'],
723
+ addresses: [
724
+ { city: 'New York', s: ADDRESS_INFO_SOURCE.INPUT },
725
+ ],
726
+ },
727
+ };
728
+ const incomingIdentity = {
729
+ identityId: 'test-id',
730
+ traits: {
731
+ emails: ['test@email.com'],
732
+ addresses: [
733
+ { city: 'New York', s: ADDRESS_INFO_SOURCE.INPUT },
734
+ { city: 'Boston', s: ADDRESS_INFO_SOURCE.INPUT },
735
+ ],
736
+ },
737
+ };
738
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
739
+ expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
740
+ expect(result.isCacheStale).toBe(true);
741
+ expect(result.isNonIpAddressesStale).toBe(true);
742
+ });
743
+ it('should return ADDRESS_UPDATE tier even when volatile traits are also stale', () => {
744
+ const cachedIdentity = {
745
+ identityId: 'test-id',
746
+ traits: {
747
+ emails: ['test@email.com'],
748
+ ipAddress: '192.168.1.1',
749
+ addresses: [],
750
+ },
751
+ };
752
+ const incomingIdentity = {
753
+ identityId: 'test-id',
754
+ traits: {
755
+ emails: ['test@email.com'],
756
+ ipAddress: '10.0.0.1',
757
+ addresses: [
758
+ { city: 'Boston', s: ADDRESS_INFO_SOURCE.INPUT },
759
+ ],
760
+ },
761
+ };
762
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
763
+ expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
764
+ expect(result.isCacheStale).toBe(true);
765
+ expect(result.isIpAddressStale).toBe(true);
766
+ expect(result.isNonIpAddressesStale).toBe(true);
767
+ });
768
+ });
769
+ describe('TIER 3: IDENTITY_STALE (full Neptune resolution)', () => {
770
+ it('should return IDENTITY_STALE tier when email is new', () => {
771
+ const cachedIdentity = {
772
+ identityId: 'test-id',
773
+ traits: {
774
+ emails: ['old@email.com'],
775
+ },
776
+ };
777
+ const incomingIdentity = {
778
+ identityId: 'test-id',
779
+ traits: {
780
+ emails: ['old@email.com', 'new@email.com'],
781
+ },
782
+ };
783
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
784
+ expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
785
+ expect(result.isCacheStale).toBe(true);
786
+ expect(result.isEmailsStale).toBe(true);
787
+ });
788
+ it('should return IDENTITY_STALE tier when identityId changes', () => {
789
+ const cachedIdentity = {
790
+ identityId: 'old-id',
791
+ traits: { emails: ['test@email.com'] },
792
+ };
793
+ const incomingIdentity = {
794
+ identityId: 'new-id',
795
+ traits: { emails: ['test@email.com'] },
796
+ };
797
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
798
+ expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
799
+ expect(result.isCacheStale).toBe(true);
800
+ expect(result.isIdentityIdStale).toBe(true);
801
+ });
802
+ it('should return IDENTITY_STALE tier when phone is new', () => {
803
+ const cachedIdentity = {
804
+ identityId: 'test-id',
805
+ traits: { phones: ['+1234567890'] },
806
+ };
807
+ const incomingIdentity = {
808
+ identityId: 'test-id',
809
+ traits: { phones: ['+1234567890', '+9876543210'] },
810
+ };
811
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
812
+ expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
813
+ expect(result.isCacheStale).toBe(true);
814
+ expect(result.isPhonesStale).toBe(true);
815
+ });
816
+ it('should return IDENTITY_STALE tier when click info changes', () => {
817
+ const cachedIdentity = {
818
+ identityId: 'test-id',
819
+ traits: {
820
+ click: { gclid: 'old_gclid' },
821
+ },
822
+ };
823
+ const incomingIdentity = {
824
+ identityId: 'test-id',
825
+ traits: {
826
+ click: { gclid: 'new_gclid' },
827
+ },
828
+ };
829
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
830
+ expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
831
+ expect(result.isCacheStale).toBe(true);
832
+ expect(result.isClickInfosStale).toBe(true);
833
+ });
834
+ it('should return IDENTITY_STALE tier when identity trait is stale even with ADDRESS_UPDATE', () => {
835
+ const cachedIdentity = {
836
+ identityId: 'test-id',
837
+ traits: {
838
+ emails: ['old@email.com'],
839
+ addresses: [],
840
+ },
841
+ };
842
+ const incomingIdentity = {
843
+ identityId: 'test-id',
844
+ traits: {
845
+ emails: ['old@email.com', 'new@email.com'],
846
+ addresses: [
847
+ { city: 'Boston', s: ADDRESS_INFO_SOURCE.INPUT },
848
+ ],
849
+ },
850
+ };
851
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
852
+ expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
853
+ expect(result.isCacheStale).toBe(true);
854
+ expect(result.isEmailsStale).toBe(true);
855
+ expect(result.isNonIpAddressesStale).toBe(true);
856
+ });
857
+ it('should return IDENTITY_STALE tier when identity trait is stale even with VOLATILE_ONLY', () => {
858
+ const cachedIdentity = {
859
+ identityId: 'test-id',
860
+ traits: {
861
+ emails: ['old@email.com'],
862
+ ipAddress: '192.168.1.1',
863
+ },
864
+ };
865
+ const incomingIdentity = {
866
+ identityId: 'test-id',
867
+ traits: {
868
+ emails: ['old@email.com', 'new@email.com'],
869
+ ipAddress: '10.0.0.1',
870
+ },
871
+ };
872
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
873
+ expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
874
+ expect(result.isCacheStale).toBe(true);
875
+ expect(result.isEmailsStale).toBe(true);
876
+ expect(result.isIpAddressStale).toBe(true);
877
+ });
878
+ });
879
+ describe('TIER NONE: No staleness', () => {
880
+ it('should return NONE tier when nothing is stale', () => {
881
+ const cachedIdentity = {
882
+ identityId: 'test-id',
883
+ traits: {
884
+ emails: ['test@email.com'],
885
+ phones: ['+1234567890'],
886
+ ipAddress: '192.168.1.1',
887
+ },
888
+ };
889
+ const incomingIdentity = {
890
+ identityId: 'test-id',
891
+ traits: {
892
+ emails: ['test@email.com'],
893
+ phones: ['+1234567890'],
894
+ ipAddress: '192.168.1.1',
895
+ },
896
+ };
897
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
898
+ expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.NONE);
899
+ expect(result.isCacheStale).toBe(false);
900
+ });
901
+ it('should return NONE tier when incoming is subset of cached', () => {
902
+ const cachedIdentity = {
903
+ identityId: 'test-id',
904
+ traits: {
905
+ emails: ['a@email.com', 'b@email.com'],
906
+ phones: ['+1234567890', '+9876543210'],
907
+ },
908
+ };
909
+ const incomingIdentity = {
910
+ identityId: 'test-id',
911
+ traits: {
912
+ emails: ['a@email.com'],
913
+ },
914
+ };
915
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
916
+ expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.NONE);
917
+ expect(result.isCacheStale).toBe(false);
918
+ });
919
+ });
920
+ describe('Address source filtering', () => {
921
+ it('should correctly identify IP-sourced addresses', () => {
922
+ const cachedIdentity = {
923
+ identityId: 'test-id',
924
+ traits: {
925
+ addresses: [
926
+ { city: 'CachedCity', s: ADDRESS_INFO_SOURCE.IP_ADDRESS },
927
+ ],
928
+ },
929
+ };
930
+ const incomingIdentity = {
931
+ identityId: 'test-id',
932
+ traits: {
933
+ addresses: [
934
+ { city: 'NewCity', s: ADDRESS_INFO_SOURCE.IP_ADDRESS },
935
+ ],
936
+ },
937
+ };
938
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
939
+ expect(result.isIpAddressesStale).toBe(true);
940
+ expect(result.isNonIpAddressesStale).toBe(false);
941
+ expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
942
+ });
943
+ it('should correctly identify INPUT-sourced addresses', () => {
944
+ const cachedIdentity = {
945
+ identityId: 'test-id',
946
+ traits: {
947
+ addresses: [
948
+ { city: 'CachedCity', s: ADDRESS_INFO_SOURCE.INPUT },
949
+ ],
950
+ },
951
+ };
952
+ const incomingIdentity = {
953
+ identityId: 'test-id',
954
+ traits: {
955
+ addresses: [
956
+ { city: 'CachedCity', s: ADDRESS_INFO_SOURCE.INPUT },
957
+ { city: 'NewCity', s: ADDRESS_INFO_SOURCE.INPUT },
958
+ ],
959
+ },
960
+ };
961
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
962
+ expect(result.isIpAddressesStale).toBe(false);
963
+ expect(result.isNonIpAddressesStale).toBe(true);
964
+ expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
965
+ });
966
+ it('should handle mixed address sources correctly', () => {
967
+ const cachedIdentity = {
968
+ identityId: 'test-id',
969
+ traits: {
970
+ addresses: [
971
+ { city: 'IPCity', s: ADDRESS_INFO_SOURCE.IP_ADDRESS },
972
+ { city: 'InputCity', s: ADDRESS_INFO_SOURCE.INPUT },
973
+ ],
974
+ },
975
+ };
976
+ const incomingIdentity = {
977
+ identityId: 'test-id',
978
+ traits: {
979
+ addresses: [
980
+ { city: 'NewIPCity', s: ADDRESS_INFO_SOURCE.IP_ADDRESS },
981
+ { city: 'InputCity', s: ADDRESS_INFO_SOURCE.INPUT },
982
+ { city: 'NewInputCity', s: ADDRESS_INFO_SOURCE.INPUT },
983
+ ],
984
+ },
985
+ };
986
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
987
+ expect(result.isIpAddressesStale).toBe(true);
988
+ expect(result.isNonIpAddressesStale).toBe(true);
989
+ expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
990
+ expect(result.isCacheStale).toBe(true);
991
+ });
992
+ it('should handle addresses without source field (default to IP based on PII)', () => {
993
+ const cachedIdentity = {
994
+ identityId: 'test-id',
995
+ traits: {
996
+ addresses: [],
997
+ },
998
+ };
999
+ const incomingIdentity = {
1000
+ identityId: 'test-id',
1001
+ traits: {
1002
+ addresses: [
1003
+ { city: 'NoSourceCity' },
1004
+ ],
1005
+ },
1006
+ };
1007
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
1008
+ expect(result.isIpAddressesStale).toBe(true);
1009
+ expect(result.isNonIpAddressesStale).toBe(false);
1010
+ expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
1011
+ expect(result.isCacheStale).toBe(false);
1012
+ });
1013
+ it('should treat addresses without source but with PII as non-IP', () => {
1014
+ const cachedIdentity = {
1015
+ identityId: 'test-id',
1016
+ traits: {
1017
+ addresses: [],
1018
+ },
1019
+ };
1020
+ const incomingIdentity = {
1021
+ identityId: 'test-id',
1022
+ traits: {
1023
+ addresses: [
1024
+ { city: 'InputCity', firstName: 'John' },
1025
+ ],
1026
+ },
1027
+ };
1028
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
1029
+ expect(result.isNonIpAddressesStale).toBe(true);
1030
+ expect(result.isIpAddressesStale).toBe(false);
1031
+ expect(result.staleTier).toBe(IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
1032
+ expect(result.isCacheStale).toBe(true);
1033
+ });
1034
+ });
1035
+ describe('Backward compatibility', () => {
1036
+ it('should maintain isAddressesStale for any address change', () => {
1037
+ const cachedIdentity = {
1038
+ identityId: 'test-id',
1039
+ traits: {
1040
+ addresses: [
1041
+ { city: 'OldCity', s: ADDRESS_INFO_SOURCE.IP_ADDRESS },
1042
+ ],
1043
+ },
1044
+ };
1045
+ const incomingIdentity = {
1046
+ identityId: 'test-id',
1047
+ traits: {
1048
+ addresses: [
1049
+ { city: 'NewCity', s: ADDRESS_INFO_SOURCE.IP_ADDRESS },
1050
+ ],
1051
+ },
1052
+ };
1053
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
1054
+ expect(result.isAddressesStale).toBe(true);
1055
+ expect(result.isCacheStale).toBe(false);
1056
+ });
1057
+ });
1058
+ });
1059
1059
  //# sourceMappingURL=trait-merging-and-staleness.spec.js.map