@adtrackify/at-service-common 3.16.1 → 3.16.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (415) hide show
  1. package/dist/cjs/__tests__/clients/sqs-client.spec.d.ts +1 -1
  2. package/dist/cjs/__tests__/clients/sqs-client.spec.js +121 -121
  3. package/dist/cjs/__tests__/helpers/account-users-helper.spec.d.ts +1 -1
  4. package/dist/cjs/__tests__/helpers/account-users-helper.spec.js +220 -220
  5. package/dist/cjs/__tests__/identity-cache/identity-cache-db-service.spec.d.ts +1 -1
  6. package/dist/cjs/__tests__/identity-cache/identity-cache-db-service.spec.js +674 -674
  7. package/dist/cjs/__tests__/identity-cache/trait-merging-and-staleness.spec.d.ts +1 -1
  8. package/dist/cjs/__tests__/identity-cache/trait-merging-and-staleness.spec.js +588 -588
  9. package/dist/cjs/__tests__/libs/compress-decompress.spec.d.ts +1 -1
  10. package/dist/cjs/__tests__/libs/compress-decompress.spec.js +16 -16
  11. package/dist/cjs/__tests__/libs/currency.spec.d.ts +1 -1
  12. package/dist/cjs/__tests__/libs/currency.spec.js +220 -220
  13. package/dist/cjs/__tests__/libs/dates.spec.d.ts +1 -1
  14. package/dist/cjs/__tests__/libs/dates.spec.js +130 -130
  15. package/dist/cjs/__tests__/libs/domain.spec.d.ts +1 -1
  16. package/dist/cjs/__tests__/libs/domain.spec.js +107 -107
  17. package/dist/cjs/__tests__/libs/numbers.spec.d.ts +1 -1
  18. package/dist/cjs/__tests__/libs/numbers.spec.js +261 -261
  19. package/dist/cjs/__tests__/s3-client/s3-client.spec.d.ts +1 -1
  20. package/dist/cjs/__tests__/s3-client/s3-client.spec.js +33 -33
  21. package/dist/cjs/__tests__/shopify/shopify-graphql-transformer.spec.d.ts +1 -1
  22. package/dist/cjs/__tests__/shopify/shopify-graphql-transformer.spec.js +35 -35
  23. package/dist/cjs/clients/generic/cognito-client.d.ts +23 -23
  24. package/dist/cjs/clients/generic/cognito-client.js +209 -209
  25. package/dist/cjs/clients/generic/dynamodb-client.d.ts +18 -18
  26. package/dist/cjs/clients/generic/dynamodb-client.js +171 -171
  27. package/dist/cjs/clients/generic/eventbridge-client.d.ts +14 -14
  28. package/dist/cjs/clients/generic/eventbridge-client.js +51 -51
  29. package/dist/cjs/clients/generic/http-client.d.ts +14 -14
  30. package/dist/cjs/clients/generic/http-client.js +61 -61
  31. package/dist/cjs/clients/generic/index.d.ts +10 -10
  32. package/dist/cjs/clients/generic/index.js +26 -26
  33. package/dist/cjs/clients/generic/lambda-invoke-client.d.ts +10 -10
  34. package/dist/cjs/clients/generic/lambda-invoke-client.js +39 -39
  35. package/dist/cjs/clients/generic/location-client.d.ts +8 -8
  36. package/dist/cjs/clients/generic/location-client.js +31 -31
  37. package/dist/cjs/clients/generic/redis-client.d.ts +33 -33
  38. package/dist/cjs/clients/generic/redis-client.js +191 -191
  39. package/dist/cjs/clients/generic/s3-client.d.ts +23 -23
  40. package/dist/cjs/clients/generic/s3-client.js +216 -216
  41. package/dist/cjs/clients/generic/singlestore-db-client.d.ts +14 -14
  42. package/dist/cjs/clients/generic/singlestore-db-client.js +67 -67
  43. package/dist/cjs/clients/generic/sqs-client.d.ts +33 -33
  44. package/dist/cjs/clients/generic/sqs-client.js +111 -111
  45. package/dist/cjs/clients/index.d.ts +3 -3
  46. package/dist/cjs/clients/index.js +19 -19
  47. package/dist/cjs/clients/internal-api/accounts-client.d.ts +85 -85
  48. package/dist/cjs/clients/internal-api/accounts-client.js +129 -129
  49. package/dist/cjs/clients/internal-api/cache-lambda-client.d.ts +26 -26
  50. package/dist/cjs/clients/internal-api/cache-lambda-client.js +89 -89
  51. package/dist/cjs/clients/internal-api/db-management-client.d.ts +18 -18
  52. package/dist/cjs/clients/internal-api/db-management-client.js +36 -36
  53. package/dist/cjs/clients/internal-api/destinations-client.d.ts +34 -34
  54. package/dist/cjs/clients/internal-api/destinations-client.js +79 -79
  55. package/dist/cjs/clients/internal-api/event-collector-client.d.ts +20 -20
  56. package/dist/cjs/clients/internal-api/event-collector-client.js +36 -36
  57. package/dist/cjs/clients/internal-api/identity-client.d.ts +31 -31
  58. package/dist/cjs/clients/internal-api/identity-client.js +91 -91
  59. package/dist/cjs/clients/internal-api/index.d.ts +9 -9
  60. package/dist/cjs/clients/internal-api/index.js +25 -25
  61. package/dist/cjs/clients/internal-api/shopify-app-install-client.d.ts +37 -37
  62. package/dist/cjs/clients/internal-api/shopify-app-install-client.js +81 -81
  63. package/dist/cjs/clients/internal-api/subscriptions-client.d.ts +26 -26
  64. package/dist/cjs/clients/internal-api/subscriptions-client.js +77 -77
  65. package/dist/cjs/clients/internal-api/users-auth-client.d.ts +35 -35
  66. package/dist/cjs/clients/internal-api/users-auth-client.js +110 -110
  67. package/dist/cjs/clients/third-party/emailable-client.d.ts +7 -7
  68. package/dist/cjs/clients/third-party/emailable-client.js +25 -25
  69. package/dist/cjs/clients/third-party/exchange-rate-api-client.d.ts +17 -17
  70. package/dist/cjs/clients/third-party/exchange-rate-api-client.js +19 -19
  71. package/dist/cjs/clients/third-party/index.d.ts +4 -4
  72. package/dist/cjs/clients/third-party/index.js +20 -20
  73. package/dist/cjs/clients/third-party/loops-client.d.ts +10 -10
  74. package/dist/cjs/clients/third-party/loops-client.js +30 -30
  75. package/dist/cjs/clients/third-party/shopify/graphql-order-queries.d.ts +25 -25
  76. package/dist/cjs/clients/third-party/shopify/graphql-order-queries.js +30 -30
  77. package/dist/cjs/clients/third-party/shopify/graphql-product-queries.d.ts +2 -2
  78. package/dist/cjs/clients/third-party/shopify/graphql-product-queries.js +180 -180
  79. package/dist/cjs/clients/third-party/shopify/shopify-graphql-client.d.ts +10 -10
  80. package/dist/cjs/clients/third-party/shopify/shopify-graphql-client.js +161 -161
  81. package/dist/cjs/clients/third-party/shopify-client.d.ts +29 -29
  82. package/dist/cjs/clients/third-party/shopify-client.js +146 -146
  83. package/dist/cjs/helpers/account-users-helper.d.ts +2 -2
  84. package/dist/cjs/helpers/account-users-helper.js +22 -22
  85. package/dist/cjs/helpers/identity-cache-helper.d.ts +21 -21
  86. package/dist/cjs/helpers/identity-cache-helper.js +156 -156
  87. package/dist/cjs/helpers/index.d.ts +7 -7
  88. package/dist/cjs/helpers/index.js +23 -23
  89. package/dist/cjs/helpers/input-validation-helper.d.ts +3 -3
  90. package/dist/cjs/helpers/input-validation-helper.js +22 -22
  91. package/dist/cjs/helpers/logging-helper.d.ts +16 -16
  92. package/dist/cjs/helpers/logging-helper.js +84 -84
  93. package/dist/cjs/helpers/response-helper.d.ts +18 -18
  94. package/dist/cjs/helpers/response-helper.js +43 -43
  95. package/dist/cjs/helpers/shopify-helper.d.ts +9 -9
  96. package/dist/cjs/helpers/shopify-helper.js +26 -26
  97. package/dist/cjs/helpers/sqs-utils.d.ts +6 -6
  98. package/dist/cjs/helpers/sqs-utils.js +14 -14
  99. package/dist/cjs/index.d.ts +5 -5
  100. package/dist/cjs/index.js +21 -21
  101. package/dist/cjs/libs/click-id-parser.d.ts +23 -23
  102. package/dist/cjs/libs/click-id-parser.js +49 -49
  103. package/dist/cjs/libs/compression.d.ts +2 -2
  104. package/dist/cjs/libs/compression.js +33 -33
  105. package/dist/cjs/libs/cookie.d.ts +17 -17
  106. package/dist/cjs/libs/cookie.js +76 -76
  107. package/dist/cjs/libs/crypto.d.ts +4 -3
  108. package/dist/cjs/libs/crypto.js +25 -20
  109. package/dist/cjs/libs/crypto.js.map +1 -1
  110. package/dist/cjs/libs/csv.d.ts +2 -2
  111. package/dist/cjs/libs/csv.js +35 -35
  112. package/dist/cjs/libs/currency.d.ts +1 -1
  113. package/dist/cjs/libs/currency.js +29 -29
  114. package/dist/cjs/libs/dates.d.ts +12 -12
  115. package/dist/cjs/libs/dates.js +96 -96
  116. package/dist/cjs/libs/domain.d.ts +2 -2
  117. package/dist/cjs/libs/domain.js +38 -38
  118. package/dist/cjs/libs/emails.d.ts +6 -6
  119. package/dist/cjs/libs/emails.js +122 -122
  120. package/dist/cjs/libs/http-error.d.ts +21 -21
  121. package/dist/cjs/libs/http-error.js +63 -63
  122. package/dist/cjs/libs/http-status-codes.d.ts +58 -58
  123. package/dist/cjs/libs/http-status-codes.js +62 -62
  124. package/dist/cjs/libs/index.d.ts +17 -17
  125. package/dist/cjs/libs/index.js +33 -33
  126. package/dist/cjs/libs/numbers.d.ts +1 -1
  127. package/dist/cjs/libs/numbers.js +15 -15
  128. package/dist/cjs/libs/referrer-parser/index.d.ts +2 -2
  129. package/dist/cjs/libs/referrer-parser/index.js +18 -18
  130. package/dist/cjs/libs/referrer-parser/referrer-data.d.ts +9 -9
  131. package/dist/cjs/libs/referrer-parser/referrer-data.js +3307 -3307
  132. package/dist/cjs/libs/referrer-parser/referrer-parser-util.d.ts +20 -20
  133. package/dist/cjs/libs/referrer-parser/referrer-parser-util.js +131 -131
  134. package/dist/cjs/libs/strings.d.ts +3 -3
  135. package/dist/cjs/libs/strings.js +46 -46
  136. package/dist/cjs/libs/traits.d.ts +6 -6
  137. package/dist/cjs/libs/traits.js +65 -65
  138. package/dist/cjs/libs/url.d.ts +1 -1
  139. package/dist/cjs/libs/url.js +13 -13
  140. package/dist/cjs/services/cache/generic-cached-object.d.ts +5 -5
  141. package/dist/cjs/services/cache/generic-cached-object.js +2 -2
  142. package/dist/cjs/services/cache/index.d.ts +1 -1
  143. package/dist/cjs/services/cache/index.js +17 -17
  144. package/dist/cjs/services/cache/product-cache-service.d.ts +21 -21
  145. package/dist/cjs/services/cache/product-cache-service.js +76 -76
  146. package/dist/cjs/services/currency-exchange-rate-lookup-service.d.ts +11 -11
  147. package/dist/cjs/services/currency-exchange-rate-lookup-service.js +66 -66
  148. package/dist/cjs/services/db/currency-exchange-rates-db-service.d.ts +21 -21
  149. package/dist/cjs/services/db/currency-exchange-rates-db-service.js +39 -39
  150. package/dist/cjs/services/db/destinations-db-service.d.ts +12 -12
  151. package/dist/cjs/services/db/destinations-db-service.js +76 -76
  152. package/dist/cjs/services/db/identity-cache-db-service.d.ts +28 -28
  153. package/dist/cjs/services/db/identity-cache-db-service.js +320 -320
  154. package/dist/cjs/services/db/index.d.ts +10 -10
  155. package/dist/cjs/services/db/index.js +26 -26
  156. package/dist/cjs/services/db/log-events-db-service.d.ts +11 -11
  157. package/dist/cjs/services/db/log-events-db-service.js +181 -181
  158. package/dist/cjs/services/db/pixels-db-service.d.ts +8 -8
  159. package/dist/cjs/services/db/pixels-db-service.js +35 -35
  160. package/dist/cjs/services/db/purchasable-contacts-db-service.d.ts +9 -9
  161. package/dist/cjs/services/db/purchasable-contacts-db-service.js +43 -43
  162. package/dist/cjs/services/db/purchased-contacts-db-service.d.ts +17 -17
  163. package/dist/cjs/services/db/purchased-contacts-db-service.js +143 -143
  164. package/dist/cjs/services/db/shopify-app-installs-db-service.d.ts +7 -7
  165. package/dist/cjs/services/db/shopify-app-installs-db-service.js +47 -47
  166. package/dist/cjs/services/db/shopify-products-cache-db-service.d.ts +16 -16
  167. package/dist/cjs/services/db/shopify-products-cache-db-service.js +73 -73
  168. package/dist/cjs/services/db/tracking-events-db-service.d.ts +20 -20
  169. package/dist/cjs/services/db/tracking-events-db-service.js +165 -165
  170. package/dist/cjs/services/eventbridge-integration-service.d.ts +9 -9
  171. package/dist/cjs/services/eventbridge-integration-service.js +28 -28
  172. package/dist/cjs/services/events/index.d.ts +3 -3
  173. package/dist/cjs/services/events/index.js +19 -19
  174. package/dist/cjs/services/events/log-event-service.d.ts +9 -9
  175. package/dist/cjs/services/events/log-event-service.js +56 -56
  176. package/dist/cjs/services/events/metric-event-service.d.ts +9 -9
  177. package/dist/cjs/services/events/metric-event-service.js +49 -49
  178. package/dist/cjs/services/events/tracking-event-sqs-service.d.ts +8 -8
  179. package/dist/cjs/services/events/tracking-event-sqs-service.js +34 -34
  180. package/dist/cjs/services/generic-cache-service.d.ts +7 -7
  181. package/dist/cjs/services/generic-cache-service.js +33 -33
  182. package/dist/cjs/services/index.d.ts +8 -8
  183. package/dist/cjs/services/index.js +24 -24
  184. package/dist/cjs/services/ipdata-lookup-service.d.ts +20 -20
  185. package/dist/cjs/services/ipdata-lookup-service.js +112 -112
  186. package/dist/cjs/services/shopify/index.d.ts +2 -2
  187. package/dist/cjs/services/shopify/index.js +18 -18
  188. package/dist/cjs/services/shopify/products/index.d.ts +1 -1
  189. package/dist/cjs/services/shopify/products/index.js +17 -17
  190. package/dist/cjs/services/shopify/products/shopify-products-serviceV2.d.ts +17 -17
  191. package/dist/cjs/services/shopify/products/shopify-products-serviceV2.js +112 -112
  192. package/dist/cjs/services/shopify/shopify-graphql-transformer.d.ts +8 -8
  193. package/dist/cjs/services/shopify/shopify-graphql-transformer.js +141 -141
  194. package/dist/cjs/types/api-response.d.ts +6 -6
  195. package/dist/cjs/types/api-response.js +2 -2
  196. package/dist/cjs/types/index.d.ts +1 -1
  197. package/dist/cjs/types/index.js +17 -17
  198. package/dist/cjs/types/internal-events/event-detail-types.d.ts +20 -20
  199. package/dist/cjs/types/internal-events/event-detail-types.js +27 -27
  200. package/dist/cjs/types/internal-events/index.d.ts +1 -1
  201. package/dist/cjs/types/internal-events/index.js +17 -17
  202. package/dist/cjs/types/shopify-graphql-types/admin.generated.d.ts +123 -123
  203. package/dist/cjs/types/shopify-graphql-types/admin.generated.js +2 -2
  204. package/dist/cjs/types/shopify-graphql-types/admin.types.d.ts +26289 -26289
  205. package/dist/cjs/types/shopify-graphql-types/admin.types.js +5311 -5311
  206. package/dist/cjs/types/shopify-graphql-types/index.d.ts +2 -2
  207. package/dist/cjs/types/shopify-graphql-types/index.js +18 -18
  208. package/dist/esm/__tests__/clients/sqs-client.spec.d.ts +1 -1
  209. package/dist/esm/__tests__/clients/sqs-client.spec.js +119 -119
  210. package/dist/esm/__tests__/helpers/account-users-helper.spec.d.ts +1 -1
  211. package/dist/esm/__tests__/helpers/account-users-helper.spec.js +218 -218
  212. package/dist/esm/__tests__/identity-cache/identity-cache-db-service.spec.d.ts +1 -1
  213. package/dist/esm/__tests__/identity-cache/identity-cache-db-service.spec.js +672 -672
  214. package/dist/esm/__tests__/identity-cache/trait-merging-and-staleness.spec.d.ts +1 -1
  215. package/dist/esm/__tests__/identity-cache/trait-merging-and-staleness.spec.js +586 -586
  216. package/dist/esm/__tests__/libs/compress-decompress.spec.d.ts +1 -1
  217. package/dist/esm/__tests__/libs/compress-decompress.spec.js +14 -14
  218. package/dist/esm/__tests__/libs/currency.spec.d.ts +1 -1
  219. package/dist/esm/__tests__/libs/currency.spec.js +218 -218
  220. package/dist/esm/__tests__/libs/dates.spec.d.ts +1 -1
  221. package/dist/esm/__tests__/libs/dates.spec.js +128 -128
  222. package/dist/esm/__tests__/libs/domain.spec.d.ts +1 -1
  223. package/dist/esm/__tests__/libs/domain.spec.js +105 -105
  224. package/dist/esm/__tests__/libs/numbers.spec.d.ts +1 -1
  225. package/dist/esm/__tests__/libs/numbers.spec.js +259 -259
  226. package/dist/esm/__tests__/s3-client/s3-client.spec.d.ts +1 -1
  227. package/dist/esm/__tests__/s3-client/s3-client.spec.js +31 -31
  228. package/dist/esm/__tests__/shopify/shopify-graphql-transformer.spec.d.ts +1 -1
  229. package/dist/esm/__tests__/shopify/shopify-graphql-transformer.spec.js +33 -33
  230. package/dist/esm/clients/generic/cognito-client.d.ts +23 -23
  231. package/dist/esm/clients/generic/cognito-client.js +204 -204
  232. package/dist/esm/clients/generic/dynamodb-client.d.ts +18 -18
  233. package/dist/esm/clients/generic/dynamodb-client.js +167 -167
  234. package/dist/esm/clients/generic/eventbridge-client.d.ts +14 -14
  235. package/dist/esm/clients/generic/eventbridge-client.js +47 -47
  236. package/dist/esm/clients/generic/http-client.d.ts +14 -14
  237. package/dist/esm/clients/generic/http-client.js +53 -53
  238. package/dist/esm/clients/generic/index.d.ts +10 -10
  239. package/dist/esm/clients/generic/index.js +10 -10
  240. package/dist/esm/clients/generic/lambda-invoke-client.d.ts +10 -10
  241. package/dist/esm/clients/generic/lambda-invoke-client.js +35 -35
  242. package/dist/esm/clients/generic/location-client.d.ts +8 -8
  243. package/dist/esm/clients/generic/location-client.js +27 -27
  244. package/dist/esm/clients/generic/redis-client.d.ts +33 -33
  245. package/dist/esm/clients/generic/redis-client.js +184 -184
  246. package/dist/esm/clients/generic/s3-client.d.ts +23 -23
  247. package/dist/esm/clients/generic/s3-client.js +209 -209
  248. package/dist/esm/clients/generic/singlestore-db-client.d.ts +14 -14
  249. package/dist/esm/clients/generic/singlestore-db-client.js +40 -40
  250. package/dist/esm/clients/generic/sqs-client.d.ts +33 -33
  251. package/dist/esm/clients/generic/sqs-client.js +107 -107
  252. package/dist/esm/clients/index.d.ts +3 -3
  253. package/dist/esm/clients/index.js +3 -3
  254. package/dist/esm/clients/internal-api/accounts-client.d.ts +85 -85
  255. package/dist/esm/clients/internal-api/accounts-client.js +125 -125
  256. package/dist/esm/clients/internal-api/cache-lambda-client.d.ts +26 -26
  257. package/dist/esm/clients/internal-api/cache-lambda-client.js +85 -85
  258. package/dist/esm/clients/internal-api/db-management-client.d.ts +18 -18
  259. package/dist/esm/clients/internal-api/db-management-client.js +32 -32
  260. package/dist/esm/clients/internal-api/destinations-client.d.ts +34 -34
  261. package/dist/esm/clients/internal-api/destinations-client.js +75 -75
  262. package/dist/esm/clients/internal-api/event-collector-client.d.ts +20 -20
  263. package/dist/esm/clients/internal-api/event-collector-client.js +32 -32
  264. package/dist/esm/clients/internal-api/identity-client.d.ts +31 -31
  265. package/dist/esm/clients/internal-api/identity-client.js +87 -87
  266. package/dist/esm/clients/internal-api/index.d.ts +9 -9
  267. package/dist/esm/clients/internal-api/index.js +9 -9
  268. package/dist/esm/clients/internal-api/shopify-app-install-client.d.ts +37 -37
  269. package/dist/esm/clients/internal-api/shopify-app-install-client.js +77 -77
  270. package/dist/esm/clients/internal-api/subscriptions-client.d.ts +26 -26
  271. package/dist/esm/clients/internal-api/subscriptions-client.js +73 -73
  272. package/dist/esm/clients/internal-api/users-auth-client.d.ts +35 -35
  273. package/dist/esm/clients/internal-api/users-auth-client.js +106 -106
  274. package/dist/esm/clients/third-party/emailable-client.d.ts +7 -7
  275. package/dist/esm/clients/third-party/emailable-client.js +21 -21
  276. package/dist/esm/clients/third-party/exchange-rate-api-client.d.ts +17 -17
  277. package/dist/esm/clients/third-party/exchange-rate-api-client.js +15 -15
  278. package/dist/esm/clients/third-party/index.d.ts +4 -4
  279. package/dist/esm/clients/third-party/index.js +4 -4
  280. package/dist/esm/clients/third-party/loops-client.d.ts +10 -10
  281. package/dist/esm/clients/third-party/loops-client.js +26 -26
  282. package/dist/esm/clients/third-party/shopify/graphql-order-queries.d.ts +25 -25
  283. package/dist/esm/clients/third-party/shopify/graphql-order-queries.js +27 -27
  284. package/dist/esm/clients/third-party/shopify/graphql-product-queries.d.ts +2 -2
  285. package/dist/esm/clients/third-party/shopify/graphql-product-queries.js +177 -177
  286. package/dist/esm/clients/third-party/shopify/shopify-graphql-client.d.ts +10 -10
  287. package/dist/esm/clients/third-party/shopify/shopify-graphql-client.js +157 -157
  288. package/dist/esm/clients/third-party/shopify-client.d.ts +29 -29
  289. package/dist/esm/clients/third-party/shopify-client.js +142 -142
  290. package/dist/esm/helpers/account-users-helper.d.ts +2 -2
  291. package/dist/esm/helpers/account-users-helper.js +18 -18
  292. package/dist/esm/helpers/identity-cache-helper.d.ts +21 -21
  293. package/dist/esm/helpers/identity-cache-helper.js +151 -151
  294. package/dist/esm/helpers/index.d.ts +7 -7
  295. package/dist/esm/helpers/index.js +7 -7
  296. package/dist/esm/helpers/input-validation-helper.d.ts +3 -3
  297. package/dist/esm/helpers/input-validation-helper.js +18 -18
  298. package/dist/esm/helpers/logging-helper.d.ts +16 -16
  299. package/dist/esm/helpers/logging-helper.js +56 -56
  300. package/dist/esm/helpers/response-helper.d.ts +18 -18
  301. package/dist/esm/helpers/response-helper.js +37 -37
  302. package/dist/esm/helpers/shopify-helper.d.ts +9 -9
  303. package/dist/esm/helpers/shopify-helper.js +21 -21
  304. package/dist/esm/helpers/sqs-utils.d.ts +6 -6
  305. package/dist/esm/helpers/sqs-utils.js +9 -9
  306. package/dist/esm/index.d.ts +5 -5
  307. package/dist/esm/index.js +5 -5
  308. package/dist/esm/libs/click-id-parser.d.ts +23 -23
  309. package/dist/esm/libs/click-id-parser.js +45 -45
  310. package/dist/esm/libs/compression.d.ts +2 -2
  311. package/dist/esm/libs/compression.js +25 -25
  312. package/dist/esm/libs/cookie.d.ts +17 -17
  313. package/dist/esm/libs/cookie.js +70 -70
  314. package/dist/esm/libs/crypto.d.ts +4 -3
  315. package/dist/esm/libs/crypto.js +15 -11
  316. package/dist/esm/libs/crypto.js.map +1 -1
  317. package/dist/esm/libs/csv.d.ts +2 -2
  318. package/dist/esm/libs/csv.js +30 -30
  319. package/dist/esm/libs/currency.d.ts +1 -1
  320. package/dist/esm/libs/currency.js +22 -22
  321. package/dist/esm/libs/dates.d.ts +12 -12
  322. package/dist/esm/libs/dates.js +83 -83
  323. package/dist/esm/libs/domain.d.ts +2 -2
  324. package/dist/esm/libs/domain.js +33 -33
  325. package/dist/esm/libs/emails.d.ts +6 -6
  326. package/dist/esm/libs/emails.js +115 -115
  327. package/dist/esm/libs/http-error.d.ts +21 -21
  328. package/dist/esm/libs/http-error.js +59 -59
  329. package/dist/esm/libs/http-status-codes.d.ts +58 -58
  330. package/dist/esm/libs/http-status-codes.js +59 -59
  331. package/dist/esm/libs/index.d.ts +17 -17
  332. package/dist/esm/libs/index.js +17 -17
  333. package/dist/esm/libs/numbers.d.ts +1 -1
  334. package/dist/esm/libs/numbers.js +11 -11
  335. package/dist/esm/libs/referrer-parser/index.d.ts +2 -2
  336. package/dist/esm/libs/referrer-parser/index.js +2 -2
  337. package/dist/esm/libs/referrer-parser/referrer-data.d.ts +9 -9
  338. package/dist/esm/libs/referrer-parser/referrer-data.js +3304 -3304
  339. package/dist/esm/libs/referrer-parser/referrer-parser-util.d.ts +20 -20
  340. package/dist/esm/libs/referrer-parser/referrer-parser-util.js +124 -124
  341. package/dist/esm/libs/strings.d.ts +3 -3
  342. package/dist/esm/libs/strings.js +40 -40
  343. package/dist/esm/libs/traits.d.ts +6 -6
  344. package/dist/esm/libs/traits.js +54 -54
  345. package/dist/esm/libs/url.d.ts +1 -1
  346. package/dist/esm/libs/url.js +9 -9
  347. package/dist/esm/services/cache/generic-cached-object.d.ts +5 -5
  348. package/dist/esm/services/cache/generic-cached-object.js +1 -1
  349. package/dist/esm/services/cache/index.d.ts +1 -1
  350. package/dist/esm/services/cache/index.js +1 -1
  351. package/dist/esm/services/cache/product-cache-service.d.ts +21 -21
  352. package/dist/esm/services/cache/product-cache-service.js +68 -68
  353. package/dist/esm/services/currency-exchange-rate-lookup-service.d.ts +11 -11
  354. package/dist/esm/services/currency-exchange-rate-lookup-service.js +62 -62
  355. package/dist/esm/services/db/currency-exchange-rates-db-service.d.ts +21 -21
  356. package/dist/esm/services/db/currency-exchange-rates-db-service.js +35 -35
  357. package/dist/esm/services/db/destinations-db-service.d.ts +12 -12
  358. package/dist/esm/services/db/destinations-db-service.js +72 -72
  359. package/dist/esm/services/db/identity-cache-db-service.d.ts +28 -28
  360. package/dist/esm/services/db/identity-cache-db-service.js +313 -313
  361. package/dist/esm/services/db/index.d.ts +10 -10
  362. package/dist/esm/services/db/index.js +10 -10
  363. package/dist/esm/services/db/log-events-db-service.d.ts +11 -11
  364. package/dist/esm/services/db/log-events-db-service.js +177 -177
  365. package/dist/esm/services/db/pixels-db-service.d.ts +8 -8
  366. package/dist/esm/services/db/pixels-db-service.js +31 -31
  367. package/dist/esm/services/db/purchasable-contacts-db-service.d.ts +9 -9
  368. package/dist/esm/services/db/purchasable-contacts-db-service.js +39 -39
  369. package/dist/esm/services/db/purchased-contacts-db-service.d.ts +17 -17
  370. package/dist/esm/services/db/purchased-contacts-db-service.js +139 -139
  371. package/dist/esm/services/db/shopify-app-installs-db-service.d.ts +7 -7
  372. package/dist/esm/services/db/shopify-app-installs-db-service.js +43 -43
  373. package/dist/esm/services/db/shopify-products-cache-db-service.d.ts +16 -16
  374. package/dist/esm/services/db/shopify-products-cache-db-service.js +66 -66
  375. package/dist/esm/services/db/tracking-events-db-service.d.ts +20 -20
  376. package/dist/esm/services/db/tracking-events-db-service.js +161 -161
  377. package/dist/esm/services/eventbridge-integration-service.d.ts +9 -9
  378. package/dist/esm/services/eventbridge-integration-service.js +24 -24
  379. package/dist/esm/services/events/index.d.ts +3 -3
  380. package/dist/esm/services/events/index.js +3 -3
  381. package/dist/esm/services/events/log-event-service.d.ts +9 -9
  382. package/dist/esm/services/events/log-event-service.js +52 -52
  383. package/dist/esm/services/events/metric-event-service.d.ts +9 -9
  384. package/dist/esm/services/events/metric-event-service.js +45 -45
  385. package/dist/esm/services/events/tracking-event-sqs-service.d.ts +8 -8
  386. package/dist/esm/services/events/tracking-event-sqs-service.js +30 -30
  387. package/dist/esm/services/generic-cache-service.d.ts +7 -7
  388. package/dist/esm/services/generic-cache-service.js +29 -29
  389. package/dist/esm/services/index.d.ts +8 -8
  390. package/dist/esm/services/index.js +8 -8
  391. package/dist/esm/services/ipdata-lookup-service.d.ts +20 -20
  392. package/dist/esm/services/ipdata-lookup-service.js +108 -108
  393. package/dist/esm/services/shopify/index.d.ts +2 -2
  394. package/dist/esm/services/shopify/index.js +2 -2
  395. package/dist/esm/services/shopify/products/index.d.ts +1 -1
  396. package/dist/esm/services/shopify/products/index.js +1 -1
  397. package/dist/esm/services/shopify/products/shopify-products-serviceV2.d.ts +17 -17
  398. package/dist/esm/services/shopify/products/shopify-products-serviceV2.js +108 -108
  399. package/dist/esm/services/shopify/shopify-graphql-transformer.d.ts +8 -8
  400. package/dist/esm/services/shopify/shopify-graphql-transformer.js +138 -138
  401. package/dist/esm/types/api-response.d.ts +6 -6
  402. package/dist/esm/types/api-response.js +1 -1
  403. package/dist/esm/types/index.d.ts +1 -1
  404. package/dist/esm/types/index.js +1 -1
  405. package/dist/esm/types/internal-events/event-detail-types.d.ts +20 -20
  406. package/dist/esm/types/internal-events/event-detail-types.js +24 -24
  407. package/dist/esm/types/internal-events/index.d.ts +1 -1
  408. package/dist/esm/types/internal-events/index.js +1 -1
  409. package/dist/esm/types/shopify-graphql-types/admin.generated.d.ts +123 -123
  410. package/dist/esm/types/shopify-graphql-types/admin.generated.js +1 -1
  411. package/dist/esm/types/shopify-graphql-types/admin.types.d.ts +26289 -26289
  412. package/dist/esm/types/shopify-graphql-types/admin.types.js +5299 -5299
  413. package/dist/esm/types/shopify-graphql-types/index.d.ts +2 -2
  414. package/dist/esm/types/shopify-graphql-types/index.js +2 -2
  415. package/package.json +135 -135
@@ -1,587 +1,587 @@
1
- import { mergeIdentityTraits } from '@adtrackify/at-shared-utils';
2
- import { isIdentityCacheStale, isClickInfosStale } from '../../helpers/identity-cache-helper';
3
- describe('Identity Trait Merging Tests', () => {
4
- afterEach(() => {
5
- jest.resetModules();
6
- });
7
- describe('mergeIdentityTraits function', () => {
8
- it('should merge simple string arrays correctly', () => {
9
- const incomingTraits = {
10
- emails: ['new@email.com'],
11
- userIds: ['user1', 'user2'],
12
- };
13
- const cachedTraits = {
14
- emails: ['existing@email.com'],
15
- userIds: ['user2', 'user3'],
16
- phones: ['+1234567890'],
17
- };
18
- const merged = mergeIdentityTraits(incomingTraits, cachedTraits);
19
- expect(merged.emails).toEqual(['new@email.com', 'existing@email.com']);
20
- expect(merged.userIds).toEqual(['user1', 'user2', 'user3']);
21
- expect(merged.phones).toEqual(['+1234567890']);
22
- });
23
- it('should handle null and undefined values in arrays', () => {
24
- const incomingTraits = {
25
- emails: ['test@email.com', null, undefined],
26
- userIds: ['user1'],
27
- };
28
- const cachedTraits = {
29
- emails: [null, 'cached@email.com', undefined],
30
- userIds: null,
31
- };
32
- const merged = mergeIdentityTraits(incomingTraits, cachedTraits);
33
- expect(merged.emails).toContain('test@email.com');
34
- expect(merged.emails).toContain('cached@email.com');
35
- expect(merged.userIds).toEqual(['user1']);
36
- });
37
- it('should merge addresses correctly', () => {
38
- const incomingTraits = {
39
- addresses: [
40
- {
41
- city: 'New York',
42
- country: 'USA',
43
- countryCode: 'US',
44
- province: 'NY',
45
- provinceCode: '10001',
46
- },
47
- ],
48
- };
49
- const cachedTraits = {
50
- addresses: [
51
- {
52
- city: 'Los Angeles',
53
- country: 'USA',
54
- countryCode: 'US',
55
- province: 'CA',
56
- provinceCode: '90210',
57
- },
58
- ],
59
- };
60
- const merged = mergeIdentityTraits(incomingTraits, cachedTraits);
61
- expect(merged.addresses).toHaveLength(2);
62
- expect(merged.addresses).toEqual(expect.arrayContaining([
63
- expect.objectContaining({ city: 'New York' }),
64
- expect.objectContaining({ city: 'Los Angeles' }),
65
- ]));
66
- });
67
- it('should merge click information correctly', () => {
68
- const incomingTraits = {
69
- click: {
70
- fbp: 'fb.new.123',
71
- fbpCollectedAt: '2024-01-01T00:00:00.000Z',
72
- gclid: 'new_gclid',
73
- },
74
- };
75
- const cachedTraits = {
76
- click: {
77
- fbp: 'fb.old.456',
78
- fbpCollectedAt: '2023-12-01T00:00:00.000Z',
79
- fbclid: 'cached_fbclid',
80
- },
81
- };
82
- const merged = mergeIdentityTraits(incomingTraits, cachedTraits);
83
- expect(merged.click?.fbp).toBe('fb.new.123');
84
- expect(merged.click?.gclid).toBe('new_gclid');
85
- expect(merged.click?.fbpCollectedAt).toBe('2024-01-01T00:00:00.000Z');
86
- expect(merged.click?.fbclid).toBeUndefined();
87
- });
88
- it('should handle empty traits correctly', () => {
89
- const incomingTraits = {};
90
- const cachedTraits = {
91
- emails: ['cached@email.com'],
92
- userIds: ['user1'],
93
- };
94
- const merged = mergeIdentityTraits(incomingTraits, cachedTraits);
95
- expect(merged.emails).toEqual(['cached@email.com']);
96
- expect(merged.userIds).toEqual(['user1']);
97
- });
98
- it('should handle undefined traits correctly', () => {
99
- const merged1 = mergeIdentityTraits(undefined, { emails: ['test@email.com'] });
100
- expect(merged1.emails).toEqual(['test@email.com']);
101
- const merged2 = mergeIdentityTraits({ emails: ['test@email.com'] }, undefined);
102
- expect(merged2.emails).toEqual(['test@email.com']);
103
- const merged3 = mergeIdentityTraits(undefined, undefined);
104
- expect(merged3).toEqual({});
105
- });
106
- it('should preserve version information', () => {
107
- const incomingTraits = {
108
- version: '3',
109
- emails: ['new@email.com'],
110
- };
111
- const cachedTraits = {
112
- version: '2',
113
- emails: ['old@email.com'],
114
- };
115
- const merged = mergeIdentityTraits(incomingTraits, cachedTraits);
116
- expect(merged.version).toBe('3');
117
- expect(merged.emails).toEqual(['new@email.com', 'old@email.com']);
118
- });
119
- it('should handle complex nested objects', () => {
120
- const incomingTraits = {
121
- click: {
122
- googleClientInfos: [{ id: 'new1', clickId: 'click1', sessionId: 'session1' }],
123
- },
124
- };
125
- const cachedTraits = {
126
- click: {
127
- googleClientInfos: [{ id: 'cached1', clickId: 'click2', sessionId: 'session2' }],
128
- },
129
- };
130
- const merged = mergeIdentityTraits(incomingTraits, cachedTraits);
131
- expect(merged.click?.googleClientInfos).toBeDefined();
132
- expect(Array.isArray(merged.click?.googleClientInfos)).toBe(true);
133
- expect(merged.click?.googleClientInfos).toEqual([{ id: 'cached1', clickId: 'click2', sessionId: 'session2' }]);
134
- });
135
- });
136
- describe('Integration: Merging + Staleness Checking', () => {
137
- it('should not be stale when merged identity matches cached identity', () => {
138
- const cachedIdentity = {
139
- identityId: 'test-id-123',
140
- traits: {
141
- emails: ['cached@email.com', 'shared@email.com'],
142
- userIds: ['user1', 'user2'],
143
- addresses: [
144
- {
145
- city: 'New York',
146
- country: 'USA',
147
- countryCode: 'US',
148
- },
149
- ],
150
- version: '2',
151
- },
152
- };
153
- const incomingIdentity = {
154
- identityId: 'test-id-123',
155
- traits: {
156
- emails: ['shared@email.com'],
157
- userIds: ['user1'],
158
- version: '2',
159
- },
160
- };
161
- const mergedTraits = mergeIdentityTraits(incomingIdentity.traits, cachedIdentity.traits);
162
- const mergedIdentity = { ...incomingIdentity, traits: mergedTraits };
163
- const staleTracker = isIdentityCacheStale(cachedIdentity, mergedIdentity);
164
- expect(staleTracker.isCacheStale).toBe(false);
165
- expect(mergedIdentity.traits?.emails).toEqual(['shared@email.com', 'cached@email.com']);
166
- });
167
- it('should be stale when merged identity has new traits', () => {
168
- const cachedIdentity = {
169
- identityId: 'test-id-123',
170
- traits: {
171
- emails: ['cached@email.com'],
172
- version: '2',
173
- },
174
- };
175
- const incomingIdentity = {
176
- identityId: 'test-id-123',
177
- traits: {
178
- emails: ['cached@email.com', 'new@email.com'],
179
- version: '2',
180
- },
181
- };
182
- const mergedTraits = mergeIdentityTraits(incomingIdentity.traits, cachedIdentity.traits);
183
- const mergedIdentity = { ...incomingIdentity, traits: mergedTraits };
184
- const staleTracker = isIdentityCacheStale(cachedIdentity, mergedIdentity);
185
- expect(staleTracker.isCacheStale).toBe(true);
186
- expect(staleTracker.isEmailsStale).toBe(true);
187
- });
188
- });
189
- });
190
- describe('Identity Cache Staleness Tests', () => {
191
- afterEach(() => {
192
- jest.resetModules();
193
- });
194
- describe('isIdentityCacheStale function', () => {
195
- it('should detect identity ID changes', () => {
196
- const cachedIdentity = {
197
- identityId: 'old-id',
198
- traits: { emails: ['test@email.com'] },
199
- };
200
- const incomingIdentity = {
201
- identityId: 'new-id',
202
- traits: { emails: ['test@email.com'] },
203
- };
204
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
205
- expect(result.isCacheStale).toBe(true);
206
- expect(result.isIdentityIdStale).toBe(true);
207
- });
208
- it('should detect new emails', () => {
209
- const cachedIdentity = {
210
- identityId: 'test-id',
211
- traits: { emails: ['old@email.com'] },
212
- };
213
- const incomingIdentity = {
214
- identityId: 'test-id',
215
- traits: { emails: ['old@email.com', 'new@email.com'] },
216
- };
217
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
218
- expect(result.isCacheStale).toBe(true);
219
- expect(result.isEmailsStale).toBe(true);
220
- });
221
- it('should detect new user IDs', () => {
222
- const cachedIdentity = {
223
- identityId: 'test-id',
224
- traits: { userIds: ['user1'] },
225
- };
226
- const incomingIdentity = {
227
- identityId: 'test-id',
228
- traits: { userIds: ['user1', 'user2'] },
229
- };
230
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
231
- expect(result.isCacheStale).toBe(true);
232
- expect(result.isUserIdsStale).toBe(true);
233
- });
234
- it('should detect new phones', () => {
235
- const cachedIdentity = {
236
- identityId: 'test-id',
237
- traits: { phones: ['+1234567890'] },
238
- };
239
- const incomingIdentity = {
240
- identityId: 'test-id',
241
- traits: { phones: ['+1234567890', '+9876543210'] },
242
- };
243
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
244
- expect(result.isCacheStale).toBe(true);
245
- expect(result.isPhonesStale).toBe(true);
246
- });
247
- it('should detect new addresses', () => {
248
- const cachedIdentity = {
249
- identityId: 'test-id',
250
- traits: {
251
- addresses: [
252
- {
253
- city: 'New York',
254
- country: 'USA',
255
- },
256
- ],
257
- },
258
- };
259
- const incomingIdentity = {
260
- identityId: 'test-id',
261
- traits: {
262
- addresses: [
263
- { city: 'New York', country: 'USA' },
264
- { city: 'Los Angeles', country: 'USA' },
265
- ],
266
- },
267
- };
268
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
269
- expect(result.isCacheStale).toBe(true);
270
- expect(result.isAddressesStale).toBe(true);
271
- });
272
- it('should detect IP address changes', () => {
273
- const cachedIdentity = {
274
- identityId: 'test-id',
275
- traits: { ipAddress: '192.168.1.1' },
276
- };
277
- const incomingIdentity = {
278
- identityId: 'test-id',
279
- traits: { ipAddress: '10.0.0.1' },
280
- };
281
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
282
- expect(result.isCacheStale).toBe(true);
283
- expect(result.isIpAddressStale).toBe(true);
284
- });
285
- it('should detect user agent changes', () => {
286
- const cachedIdentity = {
287
- identityId: 'test-id',
288
- traits: { userAgent: 'Mozilla/5.0 (old browser)' },
289
- };
290
- const incomingIdentity = {
291
- identityId: 'test-id',
292
- traits: { userAgent: 'Mozilla/5.0 (new browser)' },
293
- };
294
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
295
- expect(result.isCacheStale).toBe(true);
296
- expect(result.isUserAgentStale).toBe(true);
297
- });
298
- it('should not be stale when no new information is provided', () => {
299
- const cachedIdentity = {
300
- identityId: 'test-id',
301
- traits: {
302
- emails: ['test@email.com'],
303
- userIds: ['user1'],
304
- phones: ['+1234567890'],
305
- },
306
- };
307
- const incomingIdentity = {
308
- identityId: 'test-id',
309
- traits: {
310
- emails: ['test@email.com'],
311
- userIds: ['user1'],
312
- },
313
- };
314
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
315
- expect(result.isCacheStale).toBe(false);
316
- });
317
- it('should handle empty traits gracefully', () => {
318
- const cachedIdentity = {
319
- identityId: 'test-id',
320
- traits: {},
321
- };
322
- const incomingIdentity = {
323
- identityId: 'test-id',
324
- traits: {},
325
- };
326
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
327
- expect(result.isCacheStale).toBe(false);
328
- });
329
- it('should handle undefined traits gracefully', () => {
330
- const cachedIdentity = {
331
- identityId: 'test-id',
332
- };
333
- const incomingIdentity = {
334
- identityId: 'test-id',
335
- };
336
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
337
- expect(result.isCacheStale).toBe(false);
338
- });
339
- it('should detect multiple stale conditions', () => {
340
- const cachedIdentity = {
341
- identityId: 'test-id',
342
- traits: {
343
- emails: ['old@email.com'],
344
- userIds: ['user1'],
345
- ipAddress: '192.168.1.1',
346
- },
347
- };
348
- const incomingIdentity = {
349
- identityId: 'test-id',
350
- traits: {
351
- emails: ['old@email.com', 'new@email.com'],
352
- userIds: ['user1', 'user2'],
353
- ipAddress: '10.0.0.1',
354
- },
355
- };
356
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
357
- expect(result.isCacheStale).toBe(true);
358
- expect(result.isEmailsStale).toBe(true);
359
- expect(result.isUserIdsStale).toBe(true);
360
- expect(result.isIpAddressStale).toBe(true);
361
- });
362
- });
363
- describe('isClickInfosStale function', () => {
364
- it('should detect new FBC values', () => {
365
- const cachedClick = {
366
- fbc: 'fb.1.123.old_fbclid',
367
- };
368
- const incomingClick = {
369
- fbc: 'fb.1.123.new_fbclid',
370
- };
371
- const result = isClickInfosStale(cachedClick, incomingClick);
372
- expect(result).toBe(true);
373
- });
374
- it('should detect new click IDs', () => {
375
- const cachedClick = {
376
- gclid: 'old_gclid',
377
- };
378
- const incomingClick = {
379
- gclid: 'new_gclid',
380
- };
381
- const result = isClickInfosStale(cachedClick, incomingClick);
382
- expect(result).toBe(true);
383
- });
384
- it('should ignore collection timestamps', () => {
385
- const cachedClick = {
386
- fbp: 'fb.2.123.456',
387
- fbpCollectedAt: '2023-01-01T00:00:00.000Z',
388
- };
389
- const incomingClick = {
390
- fbp: 'fb.2.123.456',
391
- fbpCollectedAt: '2024-01-01T00:00:00.000Z',
392
- };
393
- const result = isClickInfosStale(cachedClick, incomingClick);
394
- expect(result).toBe(false);
395
- });
396
- it('should ignore googleClientInfos', () => {
397
- const cachedClick = {
398
- googleClientInfos: [{ id: 'old', clickId: 'old_click' }],
399
- };
400
- const incomingClick = {
401
- googleClientInfos: [{ id: 'new', clickId: 'new_click' }],
402
- };
403
- const result = isClickInfosStale(cachedClick, incomingClick);
404
- expect(result).toBe(false);
405
- });
406
- it('should handle empty click info', () => {
407
- const result = isClickInfosStale({}, {});
408
- expect(result).toBe(false);
409
- });
410
- it('should detect when incoming has new click info but cached is empty', () => {
411
- const cachedClick = {};
412
- const incomingClick = {
413
- fbp: 'fb.2.123.456',
414
- };
415
- const result = isClickInfosStale(cachedClick, incomingClick);
416
- expect(result).toBe(true);
417
- });
418
- });
419
- describe('Edge Cases and Error Handling', () => {
420
- it('should handle malformed FBC values gracefully', () => {
421
- const cachedClick = {
422
- fbc: 'malformed_fbc',
423
- };
424
- const incomingClick = {
425
- fbc: 'also_malformed',
426
- };
427
- const result = isClickInfosStale(cachedClick, incomingClick);
428
- expect(result).toBe(true);
429
- });
430
- it('should handle null/undefined arrays in traits', () => {
431
- const cachedIdentity = {
432
- identityId: 'test-id',
433
- traits: {
434
- emails: null,
435
- userIds: undefined,
436
- },
437
- };
438
- const incomingIdentity = {
439
- identityId: 'test-id',
440
- traits: {
441
- emails: ['new@email.com'],
442
- userIds: ['user1'],
443
- },
444
- };
445
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
446
- expect(result.isCacheStale).toBe(true);
447
- expect(result.isEmailsStale).toBe(true);
448
- expect(result.isUserIdsStale).toBe(true);
449
- });
450
- it('should handle arrays with null/undefined elements', () => {
451
- const cachedIdentity = {
452
- identityId: 'test-id',
453
- traits: {
454
- emails: ['valid@email.com', null, undefined],
455
- },
456
- };
457
- const incomingIdentity = {
458
- identityId: 'test-id',
459
- traits: {
460
- emails: ['valid@email.com', null, undefined, 'new@email.com'],
461
- },
462
- };
463
- const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
464
- expect(result.isCacheStale).toBe(true);
465
- expect(result.isEmailsStale).toBe(true);
466
- });
467
- it('should handle error conditions gracefully', () => {
468
- const result = isIdentityCacheStale(null, undefined);
469
- expect(result.isCacheStale).toBe(false);
470
- });
471
- });
472
- describe('Comprehensive Scenario Tests', () => {
473
- it('should handle complex real-world scenario', () => {
474
- const cachedIdentity = {
475
- identityId: '01HXRZ27H4TXWBBTRK09Q7APDP',
476
- traits: {
477
- emails: ['user@domain.com'],
478
- userIds: ['shopify_123'],
479
- addresses: [
480
- {
481
- city: 'New York',
482
- country: 'USA',
483
- countryCode: 'US',
484
- province: 'NY',
485
- provinceCode: '10001',
486
- },
487
- ],
488
- click: {
489
- fbp: 'fb.2.1715603578424.5068754021',
490
- fbpCollectedAt: '2024-05-13T12:32:58.424Z',
491
- gclid: 'original_gclid',
492
- },
493
- ipAddress: '192.168.1.100',
494
- version: '2',
495
- },
496
- };
497
- const incomingIdentity = {
498
- identityId: '01HXRZ27H4TXWBBTRK09Q7APDP',
499
- traits: {
500
- emails: ['user@domain.com', 'user.secondary@domain.com'],
501
- phones: ['+1234567890'],
502
- addresses: [
503
- {
504
- city: 'New York',
505
- country: 'USA',
506
- countryCode: 'US',
507
- province: 'NY',
508
- provinceCode: '10001',
509
- },
510
- ],
511
- click: {
512
- fbp: 'fb.2.1715603578424.5068754021',
513
- fbpCollectedAt: '2024-05-13T15:30:00.000Z',
514
- gclid: 'updated_gclid',
515
- },
516
- ipAddress: '192.168.1.100',
517
- version: '2',
518
- },
519
- };
520
- const mergedTraits = mergeIdentityTraits(cachedIdentity.traits, incomingIdentity.traits);
521
- const mergedIdentity = { ...incomingIdentity, traits: mergedTraits };
522
- const result = isIdentityCacheStale(cachedIdentity, mergedIdentity);
523
- expect(result.isCacheStale).toBe(true);
524
- expect(result.isEmailsStale).toBe(true);
525
- expect(result.isPhonesStale).toBe(true);
526
- expect(result.isClickInfosStale).toBe(true);
527
- expect(result.isAddressesStale).toBe(false);
528
- expect(result.isIpAddressStale).toBe(false);
529
- expect(mergedIdentity.traits?.emails).toEqual(['user@domain.com', 'user.secondary@domain.com']);
530
- expect(mergedIdentity.traits?.phones).toEqual(['+1234567890']);
531
- expect(mergedIdentity.traits?.userIds).toEqual(['shopify_123']);
532
- expect(mergedIdentity.traits?.click?.gclid).toEqual('updated_gclid');
533
- });
534
- it('should properly detect click staleness when click info actually differs', () => {
535
- const cachedIdentity = {
536
- identityId: 'test-id',
537
- traits: {
538
- click: {
539
- gclid: 'original_gclid',
540
- gclidCollectedAt: '2024-05-15T12:32:58.424Z',
541
- },
542
- },
543
- };
544
- const incomingIdentity = {
545
- identityId: 'test-id',
546
- traits: {
547
- click: {
548
- gclid: 'completely_different_gclid',
549
- gclidCollectedAt: '2024-05-13T12:32:58.424Z',
550
- },
551
- },
552
- };
553
- const mergedTraits = mergeIdentityTraits(cachedIdentity.traits, incomingIdentity.traits);
554
- const mergedIdentity = { ...incomingIdentity, traits: mergedTraits };
555
- const result = isIdentityCacheStale(cachedIdentity, mergedIdentity);
556
- expect(mergedTraits?.click?.gclid).toEqual('original_gclid');
557
- expect(result.isCacheStale).toBe(false);
558
- });
559
- it('should handle scenario where cache is fresh', () => {
560
- const cachedIdentity = {
561
- identityId: 'test-id',
562
- traits: {
563
- emails: ['user@domain.com', 'secondary@domain.com'],
564
- userIds: ['user1', 'user2'],
565
- phones: ['+1234567890'],
566
- version: '2',
567
- },
568
- };
569
- const incomingIdentity = {
570
- identityId: 'test-id',
571
- traits: {
572
- emails: ['user@domain.com'],
573
- userIds: ['user1'],
574
- version: '2',
575
- },
576
- };
577
- const mergedTraits = mergeIdentityTraits(cachedIdentity.traits, incomingIdentity.traits);
578
- const mergedIdentity = { ...incomingIdentity, traits: mergedTraits };
579
- const result = isIdentityCacheStale(cachedIdentity, mergedIdentity);
580
- expect(result.isCacheStale).toBe(false);
581
- expect(mergedIdentity.traits?.emails).toEqual(['user@domain.com', 'secondary@domain.com']);
582
- expect(mergedIdentity.traits?.userIds).toEqual(['user1', 'user2']);
583
- expect(mergedIdentity.traits?.phones).toEqual(['+1234567890']);
584
- });
585
- });
586
- });
1
+ import { mergeIdentityTraits } from '@adtrackify/at-shared-utils';
2
+ import { isIdentityCacheStale, isClickInfosStale } from '../../helpers/identity-cache-helper';
3
+ describe('Identity Trait Merging Tests', () => {
4
+ afterEach(() => {
5
+ jest.resetModules();
6
+ });
7
+ describe('mergeIdentityTraits function', () => {
8
+ it('should merge simple string arrays correctly', () => {
9
+ const incomingTraits = {
10
+ emails: ['new@email.com'],
11
+ userIds: ['user1', 'user2'],
12
+ };
13
+ const cachedTraits = {
14
+ emails: ['existing@email.com'],
15
+ userIds: ['user2', 'user3'],
16
+ phones: ['+1234567890'],
17
+ };
18
+ const merged = mergeIdentityTraits(incomingTraits, cachedTraits);
19
+ expect(merged.emails).toEqual(['new@email.com', 'existing@email.com']);
20
+ expect(merged.userIds).toEqual(['user1', 'user2', 'user3']);
21
+ expect(merged.phones).toEqual(['+1234567890']);
22
+ });
23
+ it('should handle null and undefined values in arrays', () => {
24
+ const incomingTraits = {
25
+ emails: ['test@email.com', null, undefined],
26
+ userIds: ['user1'],
27
+ };
28
+ const cachedTraits = {
29
+ emails: [null, 'cached@email.com', undefined],
30
+ userIds: null,
31
+ };
32
+ const merged = mergeIdentityTraits(incomingTraits, cachedTraits);
33
+ expect(merged.emails).toContain('test@email.com');
34
+ expect(merged.emails).toContain('cached@email.com');
35
+ expect(merged.userIds).toEqual(['user1']);
36
+ });
37
+ it('should merge addresses correctly', () => {
38
+ const incomingTraits = {
39
+ addresses: [
40
+ {
41
+ city: 'New York',
42
+ country: 'USA',
43
+ countryCode: 'US',
44
+ province: 'NY',
45
+ provinceCode: '10001',
46
+ },
47
+ ],
48
+ };
49
+ const cachedTraits = {
50
+ addresses: [
51
+ {
52
+ city: 'Los Angeles',
53
+ country: 'USA',
54
+ countryCode: 'US',
55
+ province: 'CA',
56
+ provinceCode: '90210',
57
+ },
58
+ ],
59
+ };
60
+ const merged = mergeIdentityTraits(incomingTraits, cachedTraits);
61
+ expect(merged.addresses).toHaveLength(2);
62
+ expect(merged.addresses).toEqual(expect.arrayContaining([
63
+ expect.objectContaining({ city: 'New York' }),
64
+ expect.objectContaining({ city: 'Los Angeles' }),
65
+ ]));
66
+ });
67
+ it('should merge click information correctly', () => {
68
+ const incomingTraits = {
69
+ click: {
70
+ fbp: 'fb.new.123',
71
+ fbpCollectedAt: '2024-01-01T00:00:00.000Z',
72
+ gclid: 'new_gclid',
73
+ },
74
+ };
75
+ const cachedTraits = {
76
+ click: {
77
+ fbp: 'fb.old.456',
78
+ fbpCollectedAt: '2023-12-01T00:00:00.000Z',
79
+ fbclid: 'cached_fbclid',
80
+ },
81
+ };
82
+ const merged = mergeIdentityTraits(incomingTraits, cachedTraits);
83
+ expect(merged.click?.fbp).toBe('fb.new.123');
84
+ expect(merged.click?.gclid).toBe('new_gclid');
85
+ expect(merged.click?.fbpCollectedAt).toBe('2024-01-01T00:00:00.000Z');
86
+ expect(merged.click?.fbclid).toBeUndefined();
87
+ });
88
+ it('should handle empty traits correctly', () => {
89
+ const incomingTraits = {};
90
+ const cachedTraits = {
91
+ emails: ['cached@email.com'],
92
+ userIds: ['user1'],
93
+ };
94
+ const merged = mergeIdentityTraits(incomingTraits, cachedTraits);
95
+ expect(merged.emails).toEqual(['cached@email.com']);
96
+ expect(merged.userIds).toEqual(['user1']);
97
+ });
98
+ it('should handle undefined traits correctly', () => {
99
+ const merged1 = mergeIdentityTraits(undefined, { emails: ['test@email.com'] });
100
+ expect(merged1.emails).toEqual(['test@email.com']);
101
+ const merged2 = mergeIdentityTraits({ emails: ['test@email.com'] }, undefined);
102
+ expect(merged2.emails).toEqual(['test@email.com']);
103
+ const merged3 = mergeIdentityTraits(undefined, undefined);
104
+ expect(merged3).toEqual({});
105
+ });
106
+ it('should preserve version information', () => {
107
+ const incomingTraits = {
108
+ version: '3',
109
+ emails: ['new@email.com'],
110
+ };
111
+ const cachedTraits = {
112
+ version: '2',
113
+ emails: ['old@email.com'],
114
+ };
115
+ const merged = mergeIdentityTraits(incomingTraits, cachedTraits);
116
+ expect(merged.version).toBe('3');
117
+ expect(merged.emails).toEqual(['new@email.com', 'old@email.com']);
118
+ });
119
+ it('should handle complex nested objects', () => {
120
+ const incomingTraits = {
121
+ click: {
122
+ googleClientInfos: [{ id: 'new1', clickId: 'click1', sessionId: 'session1' }],
123
+ },
124
+ };
125
+ const cachedTraits = {
126
+ click: {
127
+ googleClientInfos: [{ id: 'cached1', clickId: 'click2', sessionId: 'session2' }],
128
+ },
129
+ };
130
+ const merged = mergeIdentityTraits(incomingTraits, cachedTraits);
131
+ expect(merged.click?.googleClientInfos).toBeDefined();
132
+ expect(Array.isArray(merged.click?.googleClientInfos)).toBe(true);
133
+ expect(merged.click?.googleClientInfos).toEqual([{ id: 'cached1', clickId: 'click2', sessionId: 'session2' }]);
134
+ });
135
+ });
136
+ describe('Integration: Merging + Staleness Checking', () => {
137
+ it('should not be stale when merged identity matches cached identity', () => {
138
+ const cachedIdentity = {
139
+ identityId: 'test-id-123',
140
+ traits: {
141
+ emails: ['cached@email.com', 'shared@email.com'],
142
+ userIds: ['user1', 'user2'],
143
+ addresses: [
144
+ {
145
+ city: 'New York',
146
+ country: 'USA',
147
+ countryCode: 'US',
148
+ },
149
+ ],
150
+ version: '2',
151
+ },
152
+ };
153
+ const incomingIdentity = {
154
+ identityId: 'test-id-123',
155
+ traits: {
156
+ emails: ['shared@email.com'],
157
+ userIds: ['user1'],
158
+ version: '2',
159
+ },
160
+ };
161
+ const mergedTraits = mergeIdentityTraits(incomingIdentity.traits, cachedIdentity.traits);
162
+ const mergedIdentity = { ...incomingIdentity, traits: mergedTraits };
163
+ const staleTracker = isIdentityCacheStale(cachedIdentity, mergedIdentity);
164
+ expect(staleTracker.isCacheStale).toBe(false);
165
+ expect(mergedIdentity.traits?.emails).toEqual(['shared@email.com', 'cached@email.com']);
166
+ });
167
+ it('should be stale when merged identity has new traits', () => {
168
+ const cachedIdentity = {
169
+ identityId: 'test-id-123',
170
+ traits: {
171
+ emails: ['cached@email.com'],
172
+ version: '2',
173
+ },
174
+ };
175
+ const incomingIdentity = {
176
+ identityId: 'test-id-123',
177
+ traits: {
178
+ emails: ['cached@email.com', 'new@email.com'],
179
+ version: '2',
180
+ },
181
+ };
182
+ const mergedTraits = mergeIdentityTraits(incomingIdentity.traits, cachedIdentity.traits);
183
+ const mergedIdentity = { ...incomingIdentity, traits: mergedTraits };
184
+ const staleTracker = isIdentityCacheStale(cachedIdentity, mergedIdentity);
185
+ expect(staleTracker.isCacheStale).toBe(true);
186
+ expect(staleTracker.isEmailsStale).toBe(true);
187
+ });
188
+ });
189
+ });
190
+ describe('Identity Cache Staleness Tests', () => {
191
+ afterEach(() => {
192
+ jest.resetModules();
193
+ });
194
+ describe('isIdentityCacheStale function', () => {
195
+ it('should detect identity ID changes', () => {
196
+ const cachedIdentity = {
197
+ identityId: 'old-id',
198
+ traits: { emails: ['test@email.com'] },
199
+ };
200
+ const incomingIdentity = {
201
+ identityId: 'new-id',
202
+ traits: { emails: ['test@email.com'] },
203
+ };
204
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
205
+ expect(result.isCacheStale).toBe(true);
206
+ expect(result.isIdentityIdStale).toBe(true);
207
+ });
208
+ it('should detect new emails', () => {
209
+ const cachedIdentity = {
210
+ identityId: 'test-id',
211
+ traits: { emails: ['old@email.com'] },
212
+ };
213
+ const incomingIdentity = {
214
+ identityId: 'test-id',
215
+ traits: { emails: ['old@email.com', 'new@email.com'] },
216
+ };
217
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
218
+ expect(result.isCacheStale).toBe(true);
219
+ expect(result.isEmailsStale).toBe(true);
220
+ });
221
+ it('should detect new user IDs', () => {
222
+ const cachedIdentity = {
223
+ identityId: 'test-id',
224
+ traits: { userIds: ['user1'] },
225
+ };
226
+ const incomingIdentity = {
227
+ identityId: 'test-id',
228
+ traits: { userIds: ['user1', 'user2'] },
229
+ };
230
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
231
+ expect(result.isCacheStale).toBe(true);
232
+ expect(result.isUserIdsStale).toBe(true);
233
+ });
234
+ it('should detect new phones', () => {
235
+ const cachedIdentity = {
236
+ identityId: 'test-id',
237
+ traits: { phones: ['+1234567890'] },
238
+ };
239
+ const incomingIdentity = {
240
+ identityId: 'test-id',
241
+ traits: { phones: ['+1234567890', '+9876543210'] },
242
+ };
243
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
244
+ expect(result.isCacheStale).toBe(true);
245
+ expect(result.isPhonesStale).toBe(true);
246
+ });
247
+ it('should detect new addresses', () => {
248
+ const cachedIdentity = {
249
+ identityId: 'test-id',
250
+ traits: {
251
+ addresses: [
252
+ {
253
+ city: 'New York',
254
+ country: 'USA',
255
+ },
256
+ ],
257
+ },
258
+ };
259
+ const incomingIdentity = {
260
+ identityId: 'test-id',
261
+ traits: {
262
+ addresses: [
263
+ { city: 'New York', country: 'USA' },
264
+ { city: 'Los Angeles', country: 'USA' },
265
+ ],
266
+ },
267
+ };
268
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
269
+ expect(result.isCacheStale).toBe(true);
270
+ expect(result.isAddressesStale).toBe(true);
271
+ });
272
+ it('should detect IP address changes', () => {
273
+ const cachedIdentity = {
274
+ identityId: 'test-id',
275
+ traits: { ipAddress: '192.168.1.1' },
276
+ };
277
+ const incomingIdentity = {
278
+ identityId: 'test-id',
279
+ traits: { ipAddress: '10.0.0.1' },
280
+ };
281
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
282
+ expect(result.isCacheStale).toBe(true);
283
+ expect(result.isIpAddressStale).toBe(true);
284
+ });
285
+ it('should detect user agent changes', () => {
286
+ const cachedIdentity = {
287
+ identityId: 'test-id',
288
+ traits: { userAgent: 'Mozilla/5.0 (old browser)' },
289
+ };
290
+ const incomingIdentity = {
291
+ identityId: 'test-id',
292
+ traits: { userAgent: 'Mozilla/5.0 (new browser)' },
293
+ };
294
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
295
+ expect(result.isCacheStale).toBe(true);
296
+ expect(result.isUserAgentStale).toBe(true);
297
+ });
298
+ it('should not be stale when no new information is provided', () => {
299
+ const cachedIdentity = {
300
+ identityId: 'test-id',
301
+ traits: {
302
+ emails: ['test@email.com'],
303
+ userIds: ['user1'],
304
+ phones: ['+1234567890'],
305
+ },
306
+ };
307
+ const incomingIdentity = {
308
+ identityId: 'test-id',
309
+ traits: {
310
+ emails: ['test@email.com'],
311
+ userIds: ['user1'],
312
+ },
313
+ };
314
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
315
+ expect(result.isCacheStale).toBe(false);
316
+ });
317
+ it('should handle empty traits gracefully', () => {
318
+ const cachedIdentity = {
319
+ identityId: 'test-id',
320
+ traits: {},
321
+ };
322
+ const incomingIdentity = {
323
+ identityId: 'test-id',
324
+ traits: {},
325
+ };
326
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
327
+ expect(result.isCacheStale).toBe(false);
328
+ });
329
+ it('should handle undefined traits gracefully', () => {
330
+ const cachedIdentity = {
331
+ identityId: 'test-id',
332
+ };
333
+ const incomingIdentity = {
334
+ identityId: 'test-id',
335
+ };
336
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
337
+ expect(result.isCacheStale).toBe(false);
338
+ });
339
+ it('should detect multiple stale conditions', () => {
340
+ const cachedIdentity = {
341
+ identityId: 'test-id',
342
+ traits: {
343
+ emails: ['old@email.com'],
344
+ userIds: ['user1'],
345
+ ipAddress: '192.168.1.1',
346
+ },
347
+ };
348
+ const incomingIdentity = {
349
+ identityId: 'test-id',
350
+ traits: {
351
+ emails: ['old@email.com', 'new@email.com'],
352
+ userIds: ['user1', 'user2'],
353
+ ipAddress: '10.0.0.1',
354
+ },
355
+ };
356
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
357
+ expect(result.isCacheStale).toBe(true);
358
+ expect(result.isEmailsStale).toBe(true);
359
+ expect(result.isUserIdsStale).toBe(true);
360
+ expect(result.isIpAddressStale).toBe(true);
361
+ });
362
+ });
363
+ describe('isClickInfosStale function', () => {
364
+ it('should detect new FBC values', () => {
365
+ const cachedClick = {
366
+ fbc: 'fb.1.123.old_fbclid',
367
+ };
368
+ const incomingClick = {
369
+ fbc: 'fb.1.123.new_fbclid',
370
+ };
371
+ const result = isClickInfosStale(cachedClick, incomingClick);
372
+ expect(result).toBe(true);
373
+ });
374
+ it('should detect new click IDs', () => {
375
+ const cachedClick = {
376
+ gclid: 'old_gclid',
377
+ };
378
+ const incomingClick = {
379
+ gclid: 'new_gclid',
380
+ };
381
+ const result = isClickInfosStale(cachedClick, incomingClick);
382
+ expect(result).toBe(true);
383
+ });
384
+ it('should ignore collection timestamps', () => {
385
+ const cachedClick = {
386
+ fbp: 'fb.2.123.456',
387
+ fbpCollectedAt: '2023-01-01T00:00:00.000Z',
388
+ };
389
+ const incomingClick = {
390
+ fbp: 'fb.2.123.456',
391
+ fbpCollectedAt: '2024-01-01T00:00:00.000Z',
392
+ };
393
+ const result = isClickInfosStale(cachedClick, incomingClick);
394
+ expect(result).toBe(false);
395
+ });
396
+ it('should ignore googleClientInfos', () => {
397
+ const cachedClick = {
398
+ googleClientInfos: [{ id: 'old', clickId: 'old_click' }],
399
+ };
400
+ const incomingClick = {
401
+ googleClientInfos: [{ id: 'new', clickId: 'new_click' }],
402
+ };
403
+ const result = isClickInfosStale(cachedClick, incomingClick);
404
+ expect(result).toBe(false);
405
+ });
406
+ it('should handle empty click info', () => {
407
+ const result = isClickInfosStale({}, {});
408
+ expect(result).toBe(false);
409
+ });
410
+ it('should detect when incoming has new click info but cached is empty', () => {
411
+ const cachedClick = {};
412
+ const incomingClick = {
413
+ fbp: 'fb.2.123.456',
414
+ };
415
+ const result = isClickInfosStale(cachedClick, incomingClick);
416
+ expect(result).toBe(true);
417
+ });
418
+ });
419
+ describe('Edge Cases and Error Handling', () => {
420
+ it('should handle malformed FBC values gracefully', () => {
421
+ const cachedClick = {
422
+ fbc: 'malformed_fbc',
423
+ };
424
+ const incomingClick = {
425
+ fbc: 'also_malformed',
426
+ };
427
+ const result = isClickInfosStale(cachedClick, incomingClick);
428
+ expect(result).toBe(true);
429
+ });
430
+ it('should handle null/undefined arrays in traits', () => {
431
+ const cachedIdentity = {
432
+ identityId: 'test-id',
433
+ traits: {
434
+ emails: null,
435
+ userIds: undefined,
436
+ },
437
+ };
438
+ const incomingIdentity = {
439
+ identityId: 'test-id',
440
+ traits: {
441
+ emails: ['new@email.com'],
442
+ userIds: ['user1'],
443
+ },
444
+ };
445
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
446
+ expect(result.isCacheStale).toBe(true);
447
+ expect(result.isEmailsStale).toBe(true);
448
+ expect(result.isUserIdsStale).toBe(true);
449
+ });
450
+ it('should handle arrays with null/undefined elements', () => {
451
+ const cachedIdentity = {
452
+ identityId: 'test-id',
453
+ traits: {
454
+ emails: ['valid@email.com', null, undefined],
455
+ },
456
+ };
457
+ const incomingIdentity = {
458
+ identityId: 'test-id',
459
+ traits: {
460
+ emails: ['valid@email.com', null, undefined, 'new@email.com'],
461
+ },
462
+ };
463
+ const result = isIdentityCacheStale(cachedIdentity, incomingIdentity);
464
+ expect(result.isCacheStale).toBe(true);
465
+ expect(result.isEmailsStale).toBe(true);
466
+ });
467
+ it('should handle error conditions gracefully', () => {
468
+ const result = isIdentityCacheStale(null, undefined);
469
+ expect(result.isCacheStale).toBe(false);
470
+ });
471
+ });
472
+ describe('Comprehensive Scenario Tests', () => {
473
+ it('should handle complex real-world scenario', () => {
474
+ const cachedIdentity = {
475
+ identityId: '01HXRZ27H4TXWBBTRK09Q7APDP',
476
+ traits: {
477
+ emails: ['user@domain.com'],
478
+ userIds: ['shopify_123'],
479
+ addresses: [
480
+ {
481
+ city: 'New York',
482
+ country: 'USA',
483
+ countryCode: 'US',
484
+ province: 'NY',
485
+ provinceCode: '10001',
486
+ },
487
+ ],
488
+ click: {
489
+ fbp: 'fb.2.1715603578424.5068754021',
490
+ fbpCollectedAt: '2024-05-13T12:32:58.424Z',
491
+ gclid: 'original_gclid',
492
+ },
493
+ ipAddress: '192.168.1.100',
494
+ version: '2',
495
+ },
496
+ };
497
+ const incomingIdentity = {
498
+ identityId: '01HXRZ27H4TXWBBTRK09Q7APDP',
499
+ traits: {
500
+ emails: ['user@domain.com', 'user.secondary@domain.com'],
501
+ phones: ['+1234567890'],
502
+ addresses: [
503
+ {
504
+ city: 'New York',
505
+ country: 'USA',
506
+ countryCode: 'US',
507
+ province: 'NY',
508
+ provinceCode: '10001',
509
+ },
510
+ ],
511
+ click: {
512
+ fbp: 'fb.2.1715603578424.5068754021',
513
+ fbpCollectedAt: '2024-05-13T15:30:00.000Z',
514
+ gclid: 'updated_gclid',
515
+ },
516
+ ipAddress: '192.168.1.100',
517
+ version: '2',
518
+ },
519
+ };
520
+ const mergedTraits = mergeIdentityTraits(cachedIdentity.traits, incomingIdentity.traits);
521
+ const mergedIdentity = { ...incomingIdentity, traits: mergedTraits };
522
+ const result = isIdentityCacheStale(cachedIdentity, mergedIdentity);
523
+ expect(result.isCacheStale).toBe(true);
524
+ expect(result.isEmailsStale).toBe(true);
525
+ expect(result.isPhonesStale).toBe(true);
526
+ expect(result.isClickInfosStale).toBe(true);
527
+ expect(result.isAddressesStale).toBe(false);
528
+ expect(result.isIpAddressStale).toBe(false);
529
+ expect(mergedIdentity.traits?.emails).toEqual(['user@domain.com', 'user.secondary@domain.com']);
530
+ expect(mergedIdentity.traits?.phones).toEqual(['+1234567890']);
531
+ expect(mergedIdentity.traits?.userIds).toEqual(['shopify_123']);
532
+ expect(mergedIdentity.traits?.click?.gclid).toEqual('updated_gclid');
533
+ });
534
+ it('should properly detect click staleness when click info actually differs', () => {
535
+ const cachedIdentity = {
536
+ identityId: 'test-id',
537
+ traits: {
538
+ click: {
539
+ gclid: 'original_gclid',
540
+ gclidCollectedAt: '2024-05-15T12:32:58.424Z',
541
+ },
542
+ },
543
+ };
544
+ const incomingIdentity = {
545
+ identityId: 'test-id',
546
+ traits: {
547
+ click: {
548
+ gclid: 'completely_different_gclid',
549
+ gclidCollectedAt: '2024-05-13T12:32:58.424Z',
550
+ },
551
+ },
552
+ };
553
+ const mergedTraits = mergeIdentityTraits(cachedIdentity.traits, incomingIdentity.traits);
554
+ const mergedIdentity = { ...incomingIdentity, traits: mergedTraits };
555
+ const result = isIdentityCacheStale(cachedIdentity, mergedIdentity);
556
+ expect(mergedTraits?.click?.gclid).toEqual('original_gclid');
557
+ expect(result.isCacheStale).toBe(false);
558
+ });
559
+ it('should handle scenario where cache is fresh', () => {
560
+ const cachedIdentity = {
561
+ identityId: 'test-id',
562
+ traits: {
563
+ emails: ['user@domain.com', 'secondary@domain.com'],
564
+ userIds: ['user1', 'user2'],
565
+ phones: ['+1234567890'],
566
+ version: '2',
567
+ },
568
+ };
569
+ const incomingIdentity = {
570
+ identityId: 'test-id',
571
+ traits: {
572
+ emails: ['user@domain.com'],
573
+ userIds: ['user1'],
574
+ version: '2',
575
+ },
576
+ };
577
+ const mergedTraits = mergeIdentityTraits(cachedIdentity.traits, incomingIdentity.traits);
578
+ const mergedIdentity = { ...incomingIdentity, traits: mergedTraits };
579
+ const result = isIdentityCacheStale(cachedIdentity, mergedIdentity);
580
+ expect(result.isCacheStale).toBe(false);
581
+ expect(mergedIdentity.traits?.emails).toEqual(['user@domain.com', 'secondary@domain.com']);
582
+ expect(mergedIdentity.traits?.userIds).toEqual(['user1', 'user2']);
583
+ expect(mergedIdentity.traits?.phones).toEqual(['+1234567890']);
584
+ });
585
+ });
586
+ });
587
587
  //# sourceMappingURL=trait-merging-and-staleness.spec.js.map