@adtrackify/at-service-common 4.0.4 → 4.0.6

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