@adtrackify/at-service-common 5.0.0 → 5.0.3
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.
- package/dist/cjs/__tests__/clients/acuity-client.spec.d.ts +1 -1
- package/dist/cjs/__tests__/clients/acuity-client.spec.js +43 -43
- package/dist/cjs/__tests__/clients/cross-platform-compression.spec.d.ts +1 -1
- package/dist/cjs/__tests__/clients/cross-platform-compression.spec.js +354 -354
- package/dist/cjs/__tests__/clients/dynamodb-client.spec.d.ts +1 -1
- package/dist/cjs/__tests__/clients/dynamodb-client.spec.js +194 -194
- package/dist/cjs/__tests__/clients/event-collector-client.spec.d.ts +1 -1
- package/dist/cjs/__tests__/clients/event-collector-client.spec.js +227 -227
- package/dist/cjs/__tests__/clients/open-exchange-rates-client.spec.d.ts +1 -1
- package/dist/cjs/__tests__/clients/open-exchange-rates-client.spec.js +55 -55
- package/dist/cjs/__tests__/clients/sqs-bundled-client.spec.d.ts +1 -1
- package/dist/cjs/__tests__/clients/sqs-bundled-client.spec.js +931 -931
- package/dist/cjs/__tests__/clients/sqs-bundling-contracts.spec.d.ts +1 -1
- package/dist/cjs/__tests__/clients/sqs-bundling-contracts.spec.js +563 -563
- package/dist/cjs/__tests__/clients/sqs-client.spec.d.ts +1 -1
- package/dist/cjs/__tests__/clients/sqs-client.spec.js +191 -191
- package/dist/cjs/__tests__/clients/sqs-unbundle.spec.d.ts +1 -1
- package/dist/cjs/__tests__/clients/sqs-unbundle.spec.js +1357 -1357
- package/dist/cjs/__tests__/db/contact-enrichments-db-service.spec.d.ts +1 -1
- package/dist/cjs/__tests__/db/contact-enrichments-db-service.spec.js +68 -68
- package/dist/cjs/__tests__/db/destinations-db-service.spec.d.ts +1 -1
- package/dist/cjs/__tests__/db/destinations-db-service.spec.js +125 -125
- package/dist/cjs/__tests__/db/products-db-service.spec.d.ts +1 -1
- package/dist/cjs/__tests__/db/products-db-service.spec.js +89 -89
- package/dist/cjs/__tests__/db/shared-read-db-services.spec.d.ts +1 -1
- package/dist/cjs/__tests__/db/shared-read-db-services.spec.js +89 -89
- package/dist/cjs/__tests__/db/shopify-app-installs-db-service.spec.d.ts +1 -1
- package/dist/cjs/__tests__/db/shopify-app-installs-db-service.spec.js +104 -104
- package/dist/cjs/__tests__/db/subscriptions-db-service.spec.d.ts +1 -1
- package/dist/cjs/__tests__/db/subscriptions-db-service.spec.js +95 -95
- package/dist/cjs/__tests__/db/user-accounts-db-service.spec.d.ts +1 -1
- package/dist/cjs/__tests__/db/user-accounts-db-service.spec.js +76 -76
- package/dist/cjs/__tests__/helpers/account-users-helper.spec.d.ts +1 -1
- package/dist/cjs/__tests__/helpers/account-users-helper.spec.js +220 -220
- package/dist/cjs/__tests__/helpers/acuity-helper.spec.d.ts +1 -1
- package/dist/cjs/__tests__/helpers/acuity-helper.spec.js +69 -69
- package/dist/cjs/__tests__/helpers/api-key-auth-helper.spec.d.ts +1 -1
- package/dist/cjs/__tests__/helpers/api-key-auth-helper.spec.js +82 -82
- package/dist/cjs/__tests__/helpers/cognito-auth-helper.spec.d.ts +1 -1
- package/dist/cjs/__tests__/helpers/cognito-auth-helper.spec.js +46 -46
- package/dist/cjs/__tests__/helpers/order-calculation-helper.spec.d.ts +1 -1
- package/dist/cjs/__tests__/helpers/order-calculation-helper.spec.js +152 -152
- package/dist/cjs/__tests__/helpers/public-api-response-helper.spec.d.ts +1 -1
- package/dist/cjs/__tests__/helpers/public-api-response-helper.spec.js +60 -60
- package/dist/cjs/__tests__/identity-cache/helpers.spec.d.ts +1 -1
- package/dist/cjs/__tests__/identity-cache/helpers.spec.js +592 -592
- package/dist/cjs/__tests__/identity-cache/identity-cache-db-service.spec.d.ts +1 -1
- package/dist/cjs/__tests__/identity-cache/identity-cache-db-service.spec.js +676 -676
- package/dist/cjs/__tests__/identity-cache/identity-cache-dynamodb-db-service.spec.d.ts +1 -1
- package/dist/cjs/__tests__/identity-cache/identity-cache-dynamodb-db-service.spec.js +727 -555
- package/dist/cjs/__tests__/identity-cache/identity-cache-dynamodb-db-service.spec.js.map +1 -1
- package/dist/cjs/__tests__/identity-cache/identity-cache-tier-routing.spec.d.ts +1 -1
- package/dist/cjs/__tests__/identity-cache/identity-cache-tier-routing.spec.js +631 -631
- package/dist/cjs/__tests__/identity-cache/identity-client.spec.d.ts +1 -1
- package/dist/cjs/__tests__/identity-cache/identity-client.spec.js +359 -359
- package/dist/cjs/__tests__/identity-cache/identity-gateway-cache-hit.spec.d.ts +1 -1
- package/dist/cjs/__tests__/identity-cache/identity-gateway-cache-hit.spec.js +137 -137
- package/dist/cjs/__tests__/identity-cache/identity-gateway-cache-miss.spec.d.ts +1 -1
- package/dist/cjs/__tests__/identity-cache/identity-gateway-cache-miss.spec.js +152 -152
- package/dist/cjs/__tests__/identity-cache/identity-gateway-constructor.spec.d.ts +1 -1
- package/dist/cjs/__tests__/identity-cache/identity-gateway-constructor.spec.js +71 -71
- package/dist/cjs/__tests__/identity-cache/identity-gateway-edge-cases.spec.d.ts +1 -1
- package/dist/cjs/__tests__/identity-cache/identity-gateway-edge-cases.spec.js +88 -88
- package/dist/cjs/__tests__/identity-cache/identity-gateway-enqueue-async.spec.d.ts +1 -1
- package/dist/cjs/__tests__/identity-cache/identity-gateway-enqueue-async.spec.js +135 -135
- package/dist/cjs/__tests__/identity-cache/identity-gateway-stale-cache.spec.d.ts +1 -1
- package/dist/cjs/__tests__/identity-cache/identity-gateway-stale-cache.spec.js +223 -223
- package/dist/cjs/__tests__/identity-cache/identity-gateway-test-setup.d.ts +28 -28
- package/dist/cjs/__tests__/identity-cache/identity-gateway-test-setup.js +89 -89
- package/dist/cjs/__tests__/identity-cache/trait-merging-and-staleness.spec.d.ts +1 -1
- package/dist/cjs/__tests__/identity-cache/trait-merging-and-staleness.spec.js +1770 -1770
- package/dist/cjs/__tests__/identity-cache/volatile-traits-optimization.spec.d.ts +1 -1
- package/dist/cjs/__tests__/identity-cache/volatile-traits-optimization.spec.js +818 -818
- package/dist/cjs/__tests__/integration/sqs-bundling-roundtrip.spec.d.ts +1 -1
- package/dist/cjs/__tests__/integration/sqs-bundling-roundtrip.spec.js +584 -584
- package/dist/cjs/__tests__/libs/compress-decompress.spec.d.ts +1 -1
- package/dist/cjs/__tests__/libs/compress-decompress.spec.js +16 -16
- package/dist/cjs/__tests__/libs/contacts.spec.d.ts +1 -1
- package/dist/cjs/__tests__/libs/contacts.spec.js +294 -294
- package/dist/cjs/__tests__/libs/currency.spec.d.ts +1 -1
- package/dist/cjs/__tests__/libs/currency.spec.js +220 -220
- package/dist/cjs/__tests__/libs/dates.spec.d.ts +1 -1
- package/dist/cjs/__tests__/libs/dates.spec.js +130 -130
- package/dist/cjs/__tests__/libs/domain.spec.d.ts +1 -1
- package/dist/cjs/__tests__/libs/domain.spec.js +107 -107
- package/dist/cjs/__tests__/libs/numbers.spec.d.ts +1 -1
- package/dist/cjs/__tests__/libs/numbers.spec.js +261 -261
- package/dist/cjs/__tests__/s3-client/s3-client.spec.d.ts +1 -1
- package/dist/cjs/__tests__/s3-client/s3-client.spec.js +33 -33
- package/dist/cjs/__tests__/services/acuity-api-service.spec.d.ts +1 -1
- package/dist/cjs/__tests__/services/acuity-api-service.spec.js +71 -71
- package/dist/cjs/__tests__/services/cost/cost-calculation-types.spec.d.ts +1 -1
- package/dist/cjs/__tests__/services/cost/cost-calculation-types.spec.js +23 -23
- package/dist/cjs/__tests__/services/cost/cost-calculator-service.spec.d.ts +1 -1
- package/dist/cjs/__tests__/services/cost/cost-calculator-service.spec.js +3361 -3361
- package/dist/cjs/__tests__/services/cost/cost-currency-service.spec.d.ts +1 -1
- package/dist/cjs/__tests__/services/cost/cost-currency-service.spec.js +114 -114
- package/dist/cjs/__tests__/services/cost/cost-filter-service.spec.d.ts +1 -1
- package/dist/cjs/__tests__/services/cost/cost-filter-service.spec.js +468 -468
- package/dist/cjs/__tests__/services/cost/order-cost/order-cost-resolution-service.spec.d.ts +1 -1
- package/dist/cjs/__tests__/services/cost/order-cost/order-cost-resolution-service.spec.js +360 -360
- package/dist/cjs/__tests__/services/currency-exchange-rate-lookup-service.spec.d.ts +1 -1
- package/dist/cjs/__tests__/services/currency-exchange-rate-lookup-service.spec.js +34 -34
- package/dist/cjs/__tests__/services/email-verification/contact-email-verification-service.spec.d.ts +1 -1
- package/dist/cjs/__tests__/services/email-verification/contact-email-verification-service.spec.js +93 -93
- package/dist/cjs/__tests__/services/email-verification/email-verification-service.spec.d.ts +1 -1
- package/dist/cjs/__tests__/services/email-verification/email-verification-service.spec.js +57 -57
- package/dist/cjs/__tests__/services/events/collect-queue-tracking-service.spec.d.ts +1 -1
- package/dist/cjs/__tests__/services/events/collect-queue-tracking-service.spec.js +229 -229
- package/dist/cjs/__tests__/services/events/tracking-event-sqs-service.spec.d.ts +1 -1
- package/dist/cjs/__tests__/services/events/tracking-event-sqs-service.spec.js +191 -191
- package/dist/cjs/__tests__/shopify/shopify-graphql-transformer.spec.d.ts +1 -1
- package/dist/cjs/__tests__/shopify/shopify-graphql-transformer.spec.js +35 -35
- package/dist/cjs/__tests__/unit/libs/api-router/public-api-router.spec.d.ts +1 -1
- package/dist/cjs/__tests__/unit/libs/api-router/public-api-router.spec.js +181 -181
- package/dist/cjs/__tests__/unit/libs/api-router/route-matcher.spec.d.ts +1 -1
- package/dist/cjs/__tests__/unit/libs/api-router/route-matcher.spec.js +69 -69
- package/dist/cjs/__tests__/utils/custom-measure-formula-utils.spec.d.ts +1 -1
- package/dist/cjs/__tests__/utils/custom-measure-formula-utils.spec.js +146 -146
- package/dist/cjs/clients/generic/cognito-client.d.ts +23 -23
- package/dist/cjs/clients/generic/cognito-client.js +209 -209
- package/dist/cjs/clients/generic/dynamodb-client.d.ts +20 -20
- package/dist/cjs/clients/generic/dynamodb-client.js +235 -235
- package/dist/cjs/clients/generic/eventbridge-client.d.ts +14 -14
- package/dist/cjs/clients/generic/eventbridge-client.js +51 -51
- package/dist/cjs/clients/generic/http-client.d.ts +14 -14
- package/dist/cjs/clients/generic/http-client.js +61 -61
- package/dist/cjs/clients/generic/index.d.ts +13 -13
- package/dist/cjs/clients/generic/index.js +29 -29
- package/dist/cjs/clients/generic/lambda-invoke-client.d.ts +10 -10
- package/dist/cjs/clients/generic/lambda-invoke-client.js +39 -39
- package/dist/cjs/clients/generic/location-client.d.ts +8 -8
- package/dist/cjs/clients/generic/location-client.js +31 -31
- package/dist/cjs/clients/generic/redis-client.d.ts +33 -33
- package/dist/cjs/clients/generic/redis-client.js +191 -191
- package/dist/cjs/clients/generic/s3-client.d.ts +23 -23
- package/dist/cjs/clients/generic/s3-client.js +216 -216
- package/dist/cjs/clients/generic/singlestore-db-client.d.ts +21 -14
- package/dist/cjs/clients/generic/singlestore-db-client.js +92 -67
- package/dist/cjs/clients/generic/singlestore-db-client.js.map +1 -1
- package/dist/cjs/clients/generic/sqs-bundled-client.d.ts +15 -15
- package/dist/cjs/clients/generic/sqs-bundled-client.js +311 -311
- package/dist/cjs/clients/generic/sqs-bundled-client.types.d.ts +53 -53
- package/dist/cjs/clients/generic/sqs-bundled-client.types.js +17 -17
- package/dist/cjs/clients/generic/sqs-client.d.ts +53 -53
- package/dist/cjs/clients/generic/sqs-client.js +285 -285
- package/dist/cjs/clients/generic/sqs-unbundle.d.ts +32 -32
- package/dist/cjs/clients/generic/sqs-unbundle.js +144 -144
- package/dist/cjs/clients/index.d.ts +3 -3
- package/dist/cjs/clients/index.js +19 -19
- package/dist/cjs/clients/internal-api/accounts-client.d.ts +91 -91
- package/dist/cjs/clients/internal-api/accounts-client.js +129 -129
- package/dist/cjs/clients/internal-api/cache-lambda-client.d.ts +26 -26
- package/dist/cjs/clients/internal-api/cache-lambda-client.js +89 -89
- package/dist/cjs/clients/internal-api/db-management-client.d.ts +18 -18
- package/dist/cjs/clients/internal-api/db-management-client.js +36 -36
- package/dist/cjs/clients/internal-api/destinations-client.d.ts +34 -34
- package/dist/cjs/clients/internal-api/destinations-client.js +79 -79
- package/dist/cjs/clients/internal-api/event-collector-client.d.ts +122 -122
- package/dist/cjs/clients/internal-api/event-collector-client.js +78 -78
- package/dist/cjs/clients/internal-api/identity-client.d.ts +41 -41
- package/dist/cjs/clients/internal-api/identity-client.js +137 -137
- package/dist/cjs/clients/internal-api/index.d.ts +9 -9
- package/dist/cjs/clients/internal-api/index.js +25 -25
- package/dist/cjs/clients/internal-api/shopify-app-install-client.d.ts +37 -37
- package/dist/cjs/clients/internal-api/shopify-app-install-client.js +81 -81
- package/dist/cjs/clients/internal-api/subscriptions-client.d.ts +26 -26
- package/dist/cjs/clients/internal-api/subscriptions-client.js +77 -77
- package/dist/cjs/clients/internal-api/users-auth-client.d.ts +35 -35
- package/dist/cjs/clients/internal-api/users-auth-client.js +110 -110
- package/dist/cjs/clients/third-party/acuity-client.d.ts +10 -10
- package/dist/cjs/clients/third-party/acuity-client.js +40 -40
- package/dist/cjs/clients/third-party/emailable-client.d.ts +7 -7
- package/dist/cjs/clients/third-party/emailable-client.js +25 -25
- package/dist/cjs/clients/third-party/exchange-rate-api-client.d.ts +17 -17
- package/dist/cjs/clients/third-party/exchange-rate-api-client.js +19 -19
- package/dist/cjs/clients/third-party/index.d.ts +6 -6
- package/dist/cjs/clients/third-party/index.js +22 -22
- package/dist/cjs/clients/third-party/loops-client.d.ts +10 -10
- package/dist/cjs/clients/third-party/loops-client.js +30 -30
- package/dist/cjs/clients/third-party/open-exchange-rates-client.d.ts +8 -8
- package/dist/cjs/clients/third-party/open-exchange-rates-client.js +27 -27
- package/dist/cjs/clients/third-party/shopify/graphql-analytics-queries.d.ts +18 -18
- package/dist/cjs/clients/third-party/shopify/graphql-analytics-queries.js +22 -22
- package/dist/cjs/clients/third-party/shopify/graphql-order-queries.d.ts +25 -25
- package/dist/cjs/clients/third-party/shopify/graphql-order-queries.js +4 -4
- package/dist/cjs/clients/third-party/shopify/graphql-product-queries.d.ts +2 -2
- package/dist/cjs/clients/third-party/shopify/graphql-product-queries.js +5 -5
- package/dist/cjs/clients/third-party/shopify/shopify-graphql-client.d.ts +42 -42
- package/dist/cjs/clients/third-party/shopify/shopify-graphql-client.js +352 -352
- package/dist/cjs/clients/third-party/shopify-client.d.ts +29 -29
- package/dist/cjs/clients/third-party/shopify-client.js +146 -146
- package/dist/cjs/constants/index.d.ts +1 -1
- package/dist/cjs/constants/index.js +17 -17
- package/dist/cjs/constants/sqs.d.ts +20 -20
- package/dist/cjs/constants/sqs.js +26 -26
- package/dist/cjs/helpers/account-users-helper.d.ts +2 -2
- package/dist/cjs/helpers/account-users-helper.js +22 -22
- package/dist/cjs/helpers/acuity-helper.d.ts +4 -4
- package/dist/cjs/helpers/acuity-helper.js +56 -56
- package/dist/cjs/helpers/api-key-auth-helper.d.ts +9 -9
- package/dist/cjs/helpers/api-key-auth-helper.js +40 -40
- package/dist/cjs/helpers/api-key-authorizer-helper.d.ts +36 -36
- package/dist/cjs/helpers/api-key-authorizer-helper.js +87 -87
- package/dist/cjs/helpers/cognito-auth-helper.d.ts +5 -5
- package/dist/cjs/helpers/cognito-auth-helper.js +14 -14
- package/dist/cjs/helpers/index.d.ts +12 -12
- package/dist/cjs/helpers/index.js +28 -28
- package/dist/cjs/helpers/input-validation-helper.d.ts +3 -3
- package/dist/cjs/helpers/input-validation-helper.js +22 -22
- package/dist/cjs/helpers/logging-helper.d.ts +16 -16
- package/dist/cjs/helpers/logging-helper.js +84 -84
- package/dist/cjs/helpers/order-calculation-helper.d.ts +13 -13
- package/dist/cjs/helpers/order-calculation-helper.js +117 -117
- package/dist/cjs/helpers/public-api-response-helper.d.ts +21 -21
- package/dist/cjs/helpers/public-api-response-helper.js +45 -45
- package/dist/cjs/helpers/response-helper.d.ts +18 -18
- package/dist/cjs/helpers/response-helper.js +43 -43
- package/dist/cjs/helpers/shopify-helper.d.ts +9 -9
- package/dist/cjs/helpers/shopify-helper.js +26 -26
- package/dist/cjs/helpers/sqs-utils.d.ts +6 -6
- package/dist/cjs/helpers/sqs-utils.js +14 -14
- package/dist/cjs/index.d.ts +7 -7
- package/dist/cjs/index.js +23 -23
- package/dist/cjs/libs/api-router/index.d.ts +2 -2
- package/dist/cjs/libs/api-router/index.js +18 -18
- package/dist/cjs/libs/api-router/public-api-router.d.ts +3 -3
- package/dist/cjs/libs/api-router/public-api-router.js +36 -36
- package/dist/cjs/libs/api-router/route-matcher.d.ts +21 -21
- package/dist/cjs/libs/api-router/route-matcher.js +36 -36
- package/dist/cjs/libs/click-id-parser.d.ts +23 -23
- package/dist/cjs/libs/click-id-parser.js +49 -49
- package/dist/cjs/libs/compression.d.ts +2 -2
- package/dist/cjs/libs/compression.js +33 -33
- package/dist/cjs/libs/contacts.d.ts +7 -7
- package/dist/cjs/libs/contacts.js +152 -152
- package/dist/cjs/libs/cookie.d.ts +17 -17
- package/dist/cjs/libs/cookie.js +76 -76
- package/dist/cjs/libs/crypto.d.ts +4 -4
- package/dist/cjs/libs/crypto.js +25 -25
- package/dist/cjs/libs/csv.d.ts +2 -2
- package/dist/cjs/libs/csv.js +35 -35
- package/dist/cjs/libs/currency.d.ts +1 -1
- package/dist/cjs/libs/currency.js +29 -29
- package/dist/cjs/libs/dates.d.ts +12 -12
- package/dist/cjs/libs/dates.js +96 -96
- package/dist/cjs/libs/domain.d.ts +2 -2
- package/dist/cjs/libs/domain.js +38 -38
- package/dist/cjs/libs/emails.d.ts +8 -8
- package/dist/cjs/libs/emails.js +154 -154
- package/dist/cjs/libs/http-error.d.ts +21 -21
- package/dist/cjs/libs/http-error.js +63 -63
- package/dist/cjs/libs/http-status-codes.d.ts +58 -58
- package/dist/cjs/libs/http-status-codes.js +62 -62
- package/dist/cjs/libs/index.d.ts +19 -19
- package/dist/cjs/libs/index.js +35 -35
- package/dist/cjs/libs/numbers.d.ts +1 -1
- package/dist/cjs/libs/numbers.js +15 -15
- package/dist/cjs/libs/referrer-parser/index.d.ts +2 -2
- package/dist/cjs/libs/referrer-parser/index.js +18 -18
- package/dist/cjs/libs/referrer-parser/referrer-data.d.ts +9 -9
- package/dist/cjs/libs/referrer-parser/referrer-data.js +3307 -3307
- package/dist/cjs/libs/referrer-parser/referrer-parser-util.d.ts +20 -20
- package/dist/cjs/libs/referrer-parser/referrer-parser-util.js +131 -131
- package/dist/cjs/libs/strings.d.ts +3 -3
- package/dist/cjs/libs/strings.js +46 -46
- package/dist/cjs/libs/traits.d.ts +6 -6
- package/dist/cjs/libs/traits.js +65 -65
- package/dist/cjs/libs/url.d.ts +1 -1
- package/dist/cjs/libs/url.js +13 -13
- package/dist/cjs/services/acuity-api-service.d.ts +9 -9
- package/dist/cjs/services/acuity-api-service.js +73 -73
- package/dist/cjs/services/cache/generic-cached-object.d.ts +5 -5
- package/dist/cjs/services/cache/generic-cached-object.js +2 -2
- package/dist/cjs/services/cache/index.d.ts +1 -1
- package/dist/cjs/services/cache/index.js +17 -17
- package/dist/cjs/services/cache/product-cache-service.d.ts +21 -21
- package/dist/cjs/services/cache/product-cache-service.js +76 -76
- package/dist/cjs/services/cost/cost-calculation-types.d.ts +69 -69
- package/dist/cjs/services/cost/cost-calculation-types.js +19 -19
- package/dist/cjs/services/cost/cost-calculator-service.d.ts +24 -24
- package/dist/cjs/services/cost/cost-calculator-service.js +462 -462
- package/dist/cjs/services/cost/cost-currency-service.d.ts +6 -6
- package/dist/cjs/services/cost/cost-currency-service.js +87 -87
- package/dist/cjs/services/cost/cost-filter-service.d.ts +10 -10
- package/dist/cjs/services/cost/cost-filter-service.js +121 -121
- package/dist/cjs/services/cost/index.d.ts +5 -5
- package/dist/cjs/services/cost/index.js +21 -21
- package/dist/cjs/services/cost/order-cost/index.d.ts +2 -2
- package/dist/cjs/services/cost/order-cost/index.js +18 -18
- package/dist/cjs/services/cost/order-cost/order-cost-resolution-service.d.ts +23 -23
- package/dist/cjs/services/cost/order-cost/order-cost-resolution-service.js +293 -293
- package/dist/cjs/services/cost/order-cost/order-cost-resolution-types.d.ts +31 -31
- package/dist/cjs/services/cost/order-cost/order-cost-resolution-types.js +2 -2
- package/dist/cjs/services/currency-exchange-rate-lookup-service.d.ts +12 -12
- package/dist/cjs/services/currency-exchange-rate-lookup-service.js +94 -94
- package/dist/cjs/services/db/accounts-db-service.d.ts +9 -9
- package/dist/cjs/services/db/accounts-db-service.js +33 -33
- package/dist/cjs/services/db/api-keys-db-service.d.ts +10 -10
- package/dist/cjs/services/db/api-keys-db-service.js +36 -36
- package/dist/cjs/services/db/contact-enrichments-db-service.d.ts +15 -15
- package/dist/cjs/services/db/contact-enrichments-db-service.js +94 -94
- package/dist/cjs/services/db/currency-exchange-rates-db-service.d.ts +21 -21
- package/dist/cjs/services/db/currency-exchange-rates-db-service.js +39 -39
- package/dist/cjs/services/db/custom-measures-db-service.d.ts +14 -14
- package/dist/cjs/services/db/custom-measures-db-service.js +48 -48
- package/dist/cjs/services/db/destinations-db-service.d.ts +13 -13
- package/dist/cjs/services/db/destinations-db-service.js +74 -74
- package/dist/cjs/services/db/identity-cache-db-service.d.ts +28 -28
- package/dist/cjs/services/db/identity-cache-db-service.js +320 -320
- package/dist/cjs/services/db/identity-cache-dynamodb-service/constants.d.ts +3 -3
- package/dist/cjs/services/db/identity-cache-dynamodb-service/constants.js +6 -6
- package/dist/cjs/services/db/identity-cache-dynamodb-service/identity-cache-dynamodb-db-service.d.ts +25 -20
- package/dist/cjs/services/db/identity-cache-dynamodb-service/identity-cache-dynamodb-db-service.js +507 -362
- package/dist/cjs/services/db/identity-cache-dynamodb-service/identity-cache-dynamodb-db-service.js.map +1 -1
- package/dist/cjs/services/db/identity-cache-dynamodb-service/identity-gateway-service.d.ts +23 -23
- package/dist/cjs/services/db/identity-cache-dynamodb-service/identity-gateway-service.js +222 -222
- package/dist/cjs/services/db/identity-cache-dynamodb-service/index.d.ts +4 -4
- package/dist/cjs/services/db/identity-cache-dynamodb-service/index.js +20 -20
- package/dist/cjs/services/db/identity-cache-dynamodb-service/key-builders.d.ts +12 -12
- package/dist/cjs/services/db/identity-cache-dynamodb-service/key-builders.js +31 -31
- package/dist/cjs/services/db/identity-cache-dynamodb-service/types.d.ts +82 -71
- package/dist/cjs/services/db/identity-cache-dynamodb-service/types.js +28 -28
- package/dist/cjs/services/db/identity-cache-dynamodb-service/types.js.map +1 -1
- package/dist/cjs/services/db/index.d.ts +22 -22
- package/dist/cjs/services/db/index.js +38 -38
- package/dist/cjs/services/db/log-events-db-service.d.ts +11 -11
- package/dist/cjs/services/db/log-events-db-service.js +181 -181
- package/dist/cjs/services/db/pixels-db-service.d.ts +8 -8
- package/dist/cjs/services/db/pixels-db-service.js +35 -35
- package/dist/cjs/services/db/products-db-service-types.d.ts +10 -10
- package/dist/cjs/services/db/products-db-service-types.js +2 -2
- package/dist/cjs/services/db/products-db-service.d.ts +19 -19
- package/dist/cjs/services/db/products-db-service.js +281 -281
- package/dist/cjs/services/db/purchasable-contacts-db-service.d.ts +9 -9
- package/dist/cjs/services/db/purchasable-contacts-db-service.js +43 -43
- package/dist/cjs/services/db/purchased-contacts/index.d.ts +2 -2
- package/dist/cjs/services/db/purchased-contacts/index.js +18 -18
- package/dist/cjs/services/db/purchased-contacts/purchased-contacts-db-service.d.ts +18 -18
- package/dist/cjs/services/db/purchased-contacts/purchased-contacts-db-service.js +152 -152
- package/dist/cjs/services/db/purchased-contacts/types.d.ts +11 -11
- package/dist/cjs/services/db/purchased-contacts/types.js +2 -2
- package/dist/cjs/services/db/shopify-app-installs-db-service.d.ts +10 -10
- package/dist/cjs/services/db/shopify-app-installs-db-service.js +52 -52
- package/dist/cjs/services/db/shopify-products-cache-db-service.d.ts +16 -16
- package/dist/cjs/services/db/shopify-products-cache-db-service.js +73 -73
- package/dist/cjs/services/db/subscriptions-db-service.d.ts +11 -11
- package/dist/cjs/services/db/subscriptions-db-service.js +38 -38
- package/dist/cjs/services/db/tracking-events-db-service.d.ts +21 -21
- package/dist/cjs/services/db/tracking-events-db-service.js +188 -188
- package/dist/cjs/services/db/user-accounts-db-service.d.ts +7 -7
- package/dist/cjs/services/db/user-accounts-db-service.js +17 -17
- package/dist/cjs/services/email-verification/contact-email-verification-service.d.ts +7 -7
- package/dist/cjs/services/email-verification/contact-email-verification-service.js +101 -101
- package/dist/cjs/services/email-verification/email-verification-service.d.ts +19 -19
- package/dist/cjs/services/email-verification/email-verification-service.js +131 -131
- package/dist/cjs/services/email-verification/index.d.ts +2 -2
- package/dist/cjs/services/email-verification/index.js +18 -18
- package/dist/cjs/services/eventbridge-integration-service.d.ts +9 -9
- package/dist/cjs/services/eventbridge-integration-service.js +28 -28
- package/dist/cjs/services/events/build-collect-queue-tracking-event.d.ts +11 -11
- package/dist/cjs/services/events/build-collect-queue-tracking-event.js +23 -23
- package/dist/cjs/services/events/collect-queue-tracking-service.d.ts +12 -12
- package/dist/cjs/services/events/collect-queue-tracking-service.js +22 -22
- package/dist/cjs/services/events/index.d.ts +5 -5
- package/dist/cjs/services/events/index.js +21 -21
- package/dist/cjs/services/events/log-event-service.d.ts +19 -19
- package/dist/cjs/services/events/log-event-service.js +77 -77
- package/dist/cjs/services/events/metric-event-service.d.ts +9 -9
- package/dist/cjs/services/events/metric-event-service.js +49 -49
- package/dist/cjs/services/events/tracking-event-sqs-service.d.ts +8 -8
- package/dist/cjs/services/events/tracking-event-sqs-service.js +36 -36
- package/dist/cjs/services/generic-cache-service.d.ts +7 -7
- package/dist/cjs/services/generic-cache-service.js +33 -33
- package/dist/cjs/services/index.d.ts +11 -11
- package/dist/cjs/services/index.js +27 -27
- package/dist/cjs/services/ipdata-lookup-service.d.ts +20 -20
- package/dist/cjs/services/ipdata-lookup-service.js +112 -112
- package/dist/cjs/services/shopify/index.d.ts +2 -2
- package/dist/cjs/services/shopify/index.js +18 -18
- package/dist/cjs/services/shopify/products/index.d.ts +1 -1
- package/dist/cjs/services/shopify/products/index.js +17 -17
- package/dist/cjs/services/shopify/products/shopify-products-serviceV2.d.ts +17 -17
- package/dist/cjs/services/shopify/products/shopify-products-serviceV2.js +112 -112
- package/dist/cjs/services/shopify/shopify-graphql-transformer.d.ts +8 -8
- package/dist/cjs/services/shopify/shopify-graphql-transformer.js +141 -141
- package/dist/cjs/types/acuity-types.d.ts +74 -74
- package/dist/cjs/types/acuity-types.js +2 -2
- package/dist/cjs/types/api-response.d.ts +6 -6
- package/dist/cjs/types/api-response.js +2 -2
- package/dist/cjs/types/index.d.ts +6 -6
- package/dist/cjs/types/index.js +35 -35
- package/dist/cjs/types/internal-events/event-detail-types.d.ts +20 -20
- package/dist/cjs/types/internal-events/event-detail-types.js +27 -27
- package/dist/cjs/types/internal-events/index.d.ts +1 -1
- package/dist/cjs/types/internal-events/index.js +17 -17
- package/dist/cjs/types/open-exchange-rates-types.d.ts +10 -10
- package/dist/cjs/types/open-exchange-rates-types.js +2 -2
- package/dist/cjs/types/public-api-types.d.ts +24 -24
- package/dist/cjs/types/public-api-types.js +13 -13
- package/dist/cjs/types/shopify-graphql-types/admin.generated.d.ts +123 -123
- package/dist/cjs/types/shopify-graphql-types/admin.generated.js +2 -2
- package/dist/cjs/types/shopify-graphql-types/admin.types.d.ts +26289 -26289
- package/dist/cjs/types/shopify-graphql-types/admin.types.js +5311 -5311
- package/dist/cjs/types/shopify-graphql-types/index.d.ts +2 -2
- package/dist/cjs/types/shopify-graphql-types/index.js +18 -18
- package/dist/cjs/types/shopify-rest-types.d.ts +767 -767
- package/dist/cjs/types/shopify-rest-types.js +2 -2
- package/dist/cjs/utils/compression.d.ts +36 -36
- package/dist/cjs/utils/compression.js +198 -198
- package/dist/cjs/utils/custom-measure-formula-utils.d.ts +6 -6
- package/dist/cjs/utils/custom-measure-formula-utils.js +209 -209
- package/dist/cjs/utils/index.d.ts +4 -4
- package/dist/cjs/utils/index.js +20 -20
- package/dist/cjs/utils/retry-envelope.d.ts +12 -12
- package/dist/cjs/utils/retry-envelope.js +28 -28
- package/dist/cjs/utils/size.d.ts +2 -2
- package/dist/cjs/utils/size.js +49 -49
- package/dist/esm/__tests__/clients/acuity-client.spec.d.ts +1 -1
- package/dist/esm/__tests__/clients/acuity-client.spec.js +41 -41
- package/dist/esm/__tests__/clients/cross-platform-compression.spec.d.ts +1 -1
- package/dist/esm/__tests__/clients/cross-platform-compression.spec.js +329 -329
- package/dist/esm/__tests__/clients/dynamodb-client.spec.d.ts +1 -1
- package/dist/esm/__tests__/clients/dynamodb-client.spec.js +192 -192
- package/dist/esm/__tests__/clients/event-collector-client.spec.d.ts +1 -1
- package/dist/esm/__tests__/clients/event-collector-client.spec.js +225 -225
- package/dist/esm/__tests__/clients/open-exchange-rates-client.spec.d.ts +1 -1
- package/dist/esm/__tests__/clients/open-exchange-rates-client.spec.js +53 -53
- package/dist/esm/__tests__/clients/sqs-bundled-client.spec.d.ts +1 -1
- package/dist/esm/__tests__/clients/sqs-bundled-client.spec.js +906 -906
- package/dist/esm/__tests__/clients/sqs-bundling-contracts.spec.d.ts +1 -1
- package/dist/esm/__tests__/clients/sqs-bundling-contracts.spec.js +538 -538
- package/dist/esm/__tests__/clients/sqs-client.spec.d.ts +1 -1
- package/dist/esm/__tests__/clients/sqs-client.spec.js +189 -189
- package/dist/esm/__tests__/clients/sqs-unbundle.spec.d.ts +1 -1
- package/dist/esm/__tests__/clients/sqs-unbundle.spec.js +1355 -1355
- package/dist/esm/__tests__/db/contact-enrichments-db-service.spec.d.ts +1 -1
- package/dist/esm/__tests__/db/contact-enrichments-db-service.spec.js +66 -66
- package/dist/esm/__tests__/db/destinations-db-service.spec.d.ts +1 -1
- package/dist/esm/__tests__/db/destinations-db-service.spec.js +123 -123
- package/dist/esm/__tests__/db/products-db-service.spec.d.ts +1 -1
- package/dist/esm/__tests__/db/products-db-service.spec.js +87 -87
- package/dist/esm/__tests__/db/shared-read-db-services.spec.d.ts +1 -1
- package/dist/esm/__tests__/db/shared-read-db-services.spec.js +87 -87
- package/dist/esm/__tests__/db/shopify-app-installs-db-service.spec.d.ts +1 -1
- package/dist/esm/__tests__/db/shopify-app-installs-db-service.spec.js +102 -102
- package/dist/esm/__tests__/db/subscriptions-db-service.spec.d.ts +1 -1
- package/dist/esm/__tests__/db/subscriptions-db-service.spec.js +93 -93
- package/dist/esm/__tests__/db/user-accounts-db-service.spec.d.ts +1 -1
- package/dist/esm/__tests__/db/user-accounts-db-service.spec.js +74 -74
- package/dist/esm/__tests__/helpers/account-users-helper.spec.d.ts +1 -1
- package/dist/esm/__tests__/helpers/account-users-helper.spec.js +218 -218
- package/dist/esm/__tests__/helpers/acuity-helper.spec.d.ts +1 -1
- package/dist/esm/__tests__/helpers/acuity-helper.spec.js +67 -67
- package/dist/esm/__tests__/helpers/api-key-auth-helper.spec.d.ts +1 -1
- package/dist/esm/__tests__/helpers/api-key-auth-helper.spec.js +80 -80
- package/dist/esm/__tests__/helpers/cognito-auth-helper.spec.d.ts +1 -1
- package/dist/esm/__tests__/helpers/cognito-auth-helper.spec.js +44 -44
- package/dist/esm/__tests__/helpers/order-calculation-helper.spec.d.ts +1 -1
- package/dist/esm/__tests__/helpers/order-calculation-helper.spec.js +150 -150
- package/dist/esm/__tests__/helpers/public-api-response-helper.spec.d.ts +1 -1
- package/dist/esm/__tests__/helpers/public-api-response-helper.spec.js +55 -55
- package/dist/esm/__tests__/identity-cache/helpers.spec.d.ts +1 -1
- package/dist/esm/__tests__/identity-cache/helpers.spec.js +590 -590
- package/dist/esm/__tests__/identity-cache/identity-cache-db-service.spec.d.ts +1 -1
- package/dist/esm/__tests__/identity-cache/identity-cache-db-service.spec.js +674 -674
- package/dist/esm/__tests__/identity-cache/identity-cache-dynamodb-db-service.spec.d.ts +1 -1
- package/dist/esm/__tests__/identity-cache/identity-cache-dynamodb-db-service.spec.js +725 -553
- package/dist/esm/__tests__/identity-cache/identity-cache-dynamodb-db-service.spec.js.map +1 -1
- package/dist/esm/__tests__/identity-cache/identity-cache-tier-routing.spec.d.ts +1 -1
- package/dist/esm/__tests__/identity-cache/identity-cache-tier-routing.spec.js +629 -629
- package/dist/esm/__tests__/identity-cache/identity-client.spec.d.ts +1 -1
- package/dist/esm/__tests__/identity-cache/identity-client.spec.js +357 -357
- package/dist/esm/__tests__/identity-cache/identity-gateway-cache-hit.spec.d.ts +1 -1
- package/dist/esm/__tests__/identity-cache/identity-gateway-cache-hit.spec.js +135 -135
- package/dist/esm/__tests__/identity-cache/identity-gateway-cache-miss.spec.d.ts +1 -1
- package/dist/esm/__tests__/identity-cache/identity-gateway-cache-miss.spec.js +150 -150
- package/dist/esm/__tests__/identity-cache/identity-gateway-constructor.spec.d.ts +1 -1
- package/dist/esm/__tests__/identity-cache/identity-gateway-constructor.spec.js +69 -69
- package/dist/esm/__tests__/identity-cache/identity-gateway-edge-cases.spec.d.ts +1 -1
- package/dist/esm/__tests__/identity-cache/identity-gateway-edge-cases.spec.js +86 -86
- package/dist/esm/__tests__/identity-cache/identity-gateway-enqueue-async.spec.d.ts +1 -1
- package/dist/esm/__tests__/identity-cache/identity-gateway-enqueue-async.spec.js +133 -133
- package/dist/esm/__tests__/identity-cache/identity-gateway-stale-cache.spec.d.ts +1 -1
- package/dist/esm/__tests__/identity-cache/identity-gateway-stale-cache.spec.js +221 -221
- package/dist/esm/__tests__/identity-cache/identity-gateway-test-setup.d.ts +28 -28
- package/dist/esm/__tests__/identity-cache/identity-gateway-test-setup.js +82 -82
- package/dist/esm/__tests__/identity-cache/trait-merging-and-staleness.spec.d.ts +1 -1
- package/dist/esm/__tests__/identity-cache/trait-merging-and-staleness.spec.js +1768 -1768
- package/dist/esm/__tests__/identity-cache/volatile-traits-optimization.spec.d.ts +1 -1
- package/dist/esm/__tests__/identity-cache/volatile-traits-optimization.spec.js +816 -816
- package/dist/esm/__tests__/integration/sqs-bundling-roundtrip.spec.d.ts +1 -1
- package/dist/esm/__tests__/integration/sqs-bundling-roundtrip.spec.js +582 -582
- package/dist/esm/__tests__/libs/compress-decompress.spec.d.ts +1 -1
- package/dist/esm/__tests__/libs/compress-decompress.spec.js +14 -14
- package/dist/esm/__tests__/libs/contacts.spec.d.ts +1 -1
- package/dist/esm/__tests__/libs/contacts.spec.js +292 -292
- package/dist/esm/__tests__/libs/currency.spec.d.ts +1 -1
- package/dist/esm/__tests__/libs/currency.spec.js +218 -218
- package/dist/esm/__tests__/libs/dates.spec.d.ts +1 -1
- package/dist/esm/__tests__/libs/dates.spec.js +128 -128
- package/dist/esm/__tests__/libs/domain.spec.d.ts +1 -1
- package/dist/esm/__tests__/libs/domain.spec.js +105 -105
- package/dist/esm/__tests__/libs/numbers.spec.d.ts +1 -1
- package/dist/esm/__tests__/libs/numbers.spec.js +259 -259
- package/dist/esm/__tests__/s3-client/s3-client.spec.d.ts +1 -1
- package/dist/esm/__tests__/s3-client/s3-client.spec.js +31 -31
- package/dist/esm/__tests__/services/acuity-api-service.spec.d.ts +1 -1
- package/dist/esm/__tests__/services/acuity-api-service.spec.js +69 -69
- package/dist/esm/__tests__/services/cost/cost-calculation-types.spec.d.ts +1 -1
- package/dist/esm/__tests__/services/cost/cost-calculation-types.spec.js +21 -21
- package/dist/esm/__tests__/services/cost/cost-calculator-service.spec.d.ts +1 -1
- package/dist/esm/__tests__/services/cost/cost-calculator-service.spec.js +3359 -3359
- package/dist/esm/__tests__/services/cost/cost-currency-service.spec.d.ts +1 -1
- package/dist/esm/__tests__/services/cost/cost-currency-service.spec.js +112 -112
- package/dist/esm/__tests__/services/cost/cost-filter-service.spec.d.ts +1 -1
- package/dist/esm/__tests__/services/cost/cost-filter-service.spec.js +466 -466
- package/dist/esm/__tests__/services/cost/order-cost/order-cost-resolution-service.spec.d.ts +1 -1
- package/dist/esm/__tests__/services/cost/order-cost/order-cost-resolution-service.spec.js +358 -358
- package/dist/esm/__tests__/services/currency-exchange-rate-lookup-service.spec.d.ts +1 -1
- package/dist/esm/__tests__/services/currency-exchange-rate-lookup-service.spec.js +32 -32
- package/dist/esm/__tests__/services/email-verification/contact-email-verification-service.spec.d.ts +1 -1
- package/dist/esm/__tests__/services/email-verification/contact-email-verification-service.spec.js +91 -91
- package/dist/esm/__tests__/services/email-verification/email-verification-service.spec.d.ts +1 -1
- package/dist/esm/__tests__/services/email-verification/email-verification-service.spec.js +55 -55
- package/dist/esm/__tests__/services/events/collect-queue-tracking-service.spec.d.ts +1 -1
- package/dist/esm/__tests__/services/events/collect-queue-tracking-service.spec.js +227 -227
- package/dist/esm/__tests__/services/events/tracking-event-sqs-service.spec.d.ts +1 -1
- package/dist/esm/__tests__/services/events/tracking-event-sqs-service.spec.js +189 -189
- package/dist/esm/__tests__/shopify/shopify-graphql-transformer.spec.d.ts +1 -1
- package/dist/esm/__tests__/shopify/shopify-graphql-transformer.spec.js +33 -33
- package/dist/esm/__tests__/unit/libs/api-router/public-api-router.spec.d.ts +1 -1
- package/dist/esm/__tests__/unit/libs/api-router/public-api-router.spec.js +156 -156
- package/dist/esm/__tests__/unit/libs/api-router/route-matcher.spec.d.ts +1 -1
- package/dist/esm/__tests__/unit/libs/api-router/route-matcher.spec.js +67 -67
- package/dist/esm/__tests__/utils/custom-measure-formula-utils.spec.d.ts +1 -1
- package/dist/esm/__tests__/utils/custom-measure-formula-utils.spec.js +144 -144
- package/dist/esm/clients/generic/cognito-client.d.ts +23 -23
- package/dist/esm/clients/generic/cognito-client.js +204 -204
- package/dist/esm/clients/generic/dynamodb-client.d.ts +20 -20
- package/dist/esm/clients/generic/dynamodb-client.js +231 -231
- package/dist/esm/clients/generic/eventbridge-client.d.ts +14 -14
- package/dist/esm/clients/generic/eventbridge-client.js +47 -47
- package/dist/esm/clients/generic/http-client.d.ts +14 -14
- package/dist/esm/clients/generic/http-client.js +53 -53
- package/dist/esm/clients/generic/index.d.ts +13 -13
- package/dist/esm/clients/generic/index.js +13 -13
- package/dist/esm/clients/generic/lambda-invoke-client.d.ts +10 -10
- package/dist/esm/clients/generic/lambda-invoke-client.js +35 -35
- package/dist/esm/clients/generic/location-client.d.ts +8 -8
- package/dist/esm/clients/generic/location-client.js +27 -27
- package/dist/esm/clients/generic/redis-client.d.ts +33 -33
- package/dist/esm/clients/generic/redis-client.js +184 -184
- package/dist/esm/clients/generic/s3-client.d.ts +23 -23
- package/dist/esm/clients/generic/s3-client.js +209 -209
- package/dist/esm/clients/generic/singlestore-db-client.d.ts +21 -14
- package/dist/esm/clients/generic/singlestore-db-client.js +65 -40
- package/dist/esm/clients/generic/singlestore-db-client.js.map +1 -1
- package/dist/esm/clients/generic/sqs-bundled-client.d.ts +15 -15
- package/dist/esm/clients/generic/sqs-bundled-client.js +307 -307
- package/dist/esm/clients/generic/sqs-bundled-client.types.d.ts +53 -53
- package/dist/esm/clients/generic/sqs-bundled-client.types.js +14 -14
- package/dist/esm/clients/generic/sqs-client.d.ts +53 -53
- package/dist/esm/clients/generic/sqs-client.js +281 -281
- package/dist/esm/clients/generic/sqs-unbundle.d.ts +32 -32
- package/dist/esm/clients/generic/sqs-unbundle.js +137 -137
- package/dist/esm/clients/index.d.ts +3 -3
- package/dist/esm/clients/index.js +3 -3
- package/dist/esm/clients/internal-api/accounts-client.d.ts +91 -91
- package/dist/esm/clients/internal-api/accounts-client.js +125 -125
- package/dist/esm/clients/internal-api/cache-lambda-client.d.ts +26 -26
- package/dist/esm/clients/internal-api/cache-lambda-client.js +85 -85
- package/dist/esm/clients/internal-api/db-management-client.d.ts +18 -18
- package/dist/esm/clients/internal-api/db-management-client.js +32 -32
- package/dist/esm/clients/internal-api/destinations-client.d.ts +34 -34
- package/dist/esm/clients/internal-api/destinations-client.js +75 -75
- package/dist/esm/clients/internal-api/event-collector-client.d.ts +122 -122
- package/dist/esm/clients/internal-api/event-collector-client.js +74 -74
- package/dist/esm/clients/internal-api/identity-client.d.ts +41 -41
- package/dist/esm/clients/internal-api/identity-client.js +133 -133
- package/dist/esm/clients/internal-api/index.d.ts +9 -9
- package/dist/esm/clients/internal-api/index.js +9 -9
- package/dist/esm/clients/internal-api/shopify-app-install-client.d.ts +37 -37
- package/dist/esm/clients/internal-api/shopify-app-install-client.js +77 -77
- package/dist/esm/clients/internal-api/subscriptions-client.d.ts +26 -26
- package/dist/esm/clients/internal-api/subscriptions-client.js +73 -73
- package/dist/esm/clients/internal-api/users-auth-client.d.ts +35 -35
- package/dist/esm/clients/internal-api/users-auth-client.js +106 -106
- package/dist/esm/clients/third-party/acuity-client.d.ts +10 -10
- package/dist/esm/clients/third-party/acuity-client.js +36 -36
- package/dist/esm/clients/third-party/emailable-client.d.ts +7 -7
- package/dist/esm/clients/third-party/emailable-client.js +21 -21
- package/dist/esm/clients/third-party/exchange-rate-api-client.d.ts +17 -17
- package/dist/esm/clients/third-party/exchange-rate-api-client.js +15 -15
- package/dist/esm/clients/third-party/index.d.ts +6 -6
- package/dist/esm/clients/third-party/index.js +6 -6
- package/dist/esm/clients/third-party/loops-client.d.ts +10 -10
- package/dist/esm/clients/third-party/loops-client.js +26 -26
- package/dist/esm/clients/third-party/open-exchange-rates-client.d.ts +8 -8
- package/dist/esm/clients/third-party/open-exchange-rates-client.js +23 -23
- package/dist/esm/clients/third-party/shopify/graphql-analytics-queries.d.ts +18 -18
- package/dist/esm/clients/third-party/shopify/graphql-analytics-queries.js +19 -19
- package/dist/esm/clients/third-party/shopify/graphql-order-queries.d.ts +25 -25
- package/dist/esm/clients/third-party/shopify/graphql-order-queries.js +1 -1
- package/dist/esm/clients/third-party/shopify/graphql-product-queries.d.ts +2 -2
- package/dist/esm/clients/third-party/shopify/graphql-product-queries.js +2 -2
- package/dist/esm/clients/third-party/shopify/shopify-graphql-client.d.ts +42 -42
- package/dist/esm/clients/third-party/shopify/shopify-graphql-client.js +348 -348
- package/dist/esm/clients/third-party/shopify-client.d.ts +29 -29
- package/dist/esm/clients/third-party/shopify-client.js +142 -142
- package/dist/esm/constants/index.d.ts +1 -1
- package/dist/esm/constants/index.js +1 -1
- package/dist/esm/constants/sqs.d.ts +20 -20
- package/dist/esm/constants/sqs.js +22 -22
- package/dist/esm/helpers/account-users-helper.d.ts +2 -2
- package/dist/esm/helpers/account-users-helper.js +18 -18
- package/dist/esm/helpers/acuity-helper.d.ts +4 -4
- package/dist/esm/helpers/acuity-helper.js +51 -51
- package/dist/esm/helpers/api-key-auth-helper.d.ts +9 -9
- package/dist/esm/helpers/api-key-auth-helper.js +35 -35
- package/dist/esm/helpers/api-key-authorizer-helper.d.ts +36 -36
- package/dist/esm/helpers/api-key-authorizer-helper.js +83 -83
- package/dist/esm/helpers/cognito-auth-helper.d.ts +5 -5
- package/dist/esm/helpers/cognito-auth-helper.js +10 -10
- package/dist/esm/helpers/index.d.ts +12 -12
- package/dist/esm/helpers/index.js +12 -12
- package/dist/esm/helpers/input-validation-helper.d.ts +3 -3
- package/dist/esm/helpers/input-validation-helper.js +18 -18
- package/dist/esm/helpers/logging-helper.d.ts +16 -16
- package/dist/esm/helpers/logging-helper.js +56 -56
- package/dist/esm/helpers/order-calculation-helper.d.ts +13 -13
- package/dist/esm/helpers/order-calculation-helper.js +111 -111
- package/dist/esm/helpers/public-api-response-helper.d.ts +21 -21
- package/dist/esm/helpers/public-api-response-helper.js +38 -38
- package/dist/esm/helpers/response-helper.d.ts +18 -18
- package/dist/esm/helpers/response-helper.js +37 -37
- package/dist/esm/helpers/shopify-helper.d.ts +9 -9
- package/dist/esm/helpers/shopify-helper.js +21 -21
- package/dist/esm/helpers/sqs-utils.d.ts +6 -6
- package/dist/esm/helpers/sqs-utils.js +9 -9
- package/dist/esm/index.d.ts +7 -7
- package/dist/esm/index.js +7 -7
- package/dist/esm/libs/api-router/index.d.ts +2 -2
- package/dist/esm/libs/api-router/index.js +2 -2
- package/dist/esm/libs/api-router/public-api-router.d.ts +3 -3
- package/dist/esm/libs/api-router/public-api-router.js +32 -32
- package/dist/esm/libs/api-router/route-matcher.d.ts +21 -21
- package/dist/esm/libs/api-router/route-matcher.js +30 -30
- package/dist/esm/libs/click-id-parser.d.ts +23 -23
- package/dist/esm/libs/click-id-parser.js +45 -45
- package/dist/esm/libs/compression.d.ts +2 -2
- package/dist/esm/libs/compression.js +25 -25
- package/dist/esm/libs/contacts.d.ts +7 -7
- package/dist/esm/libs/contacts.js +143 -143
- package/dist/esm/libs/cookie.d.ts +17 -17
- package/dist/esm/libs/cookie.js +70 -70
- package/dist/esm/libs/crypto.d.ts +4 -4
- package/dist/esm/libs/crypto.js +15 -15
- package/dist/esm/libs/csv.d.ts +2 -2
- package/dist/esm/libs/csv.js +30 -30
- package/dist/esm/libs/currency.d.ts +1 -1
- package/dist/esm/libs/currency.js +22 -22
- package/dist/esm/libs/dates.d.ts +12 -12
- package/dist/esm/libs/dates.js +83 -83
- package/dist/esm/libs/domain.d.ts +2 -2
- package/dist/esm/libs/domain.js +33 -33
- package/dist/esm/libs/emails.d.ts +8 -8
- package/dist/esm/libs/emails.js +146 -146
- package/dist/esm/libs/http-error.d.ts +21 -21
- package/dist/esm/libs/http-error.js +59 -59
- package/dist/esm/libs/http-status-codes.d.ts +58 -58
- package/dist/esm/libs/http-status-codes.js +59 -59
- package/dist/esm/libs/index.d.ts +19 -19
- package/dist/esm/libs/index.js +19 -19
- package/dist/esm/libs/numbers.d.ts +1 -1
- package/dist/esm/libs/numbers.js +11 -11
- package/dist/esm/libs/referrer-parser/index.d.ts +2 -2
- package/dist/esm/libs/referrer-parser/index.js +2 -2
- package/dist/esm/libs/referrer-parser/referrer-data.d.ts +9 -9
- package/dist/esm/libs/referrer-parser/referrer-data.js +3304 -3304
- package/dist/esm/libs/referrer-parser/referrer-parser-util.d.ts +20 -20
- package/dist/esm/libs/referrer-parser/referrer-parser-util.js +124 -124
- package/dist/esm/libs/strings.d.ts +3 -3
- package/dist/esm/libs/strings.js +40 -40
- package/dist/esm/libs/traits.d.ts +6 -6
- package/dist/esm/libs/traits.js +54 -54
- package/dist/esm/libs/url.d.ts +1 -1
- package/dist/esm/libs/url.js +9 -9
- package/dist/esm/services/acuity-api-service.d.ts +9 -9
- package/dist/esm/services/acuity-api-service.js +69 -69
- package/dist/esm/services/cache/generic-cached-object.d.ts +5 -5
- package/dist/esm/services/cache/generic-cached-object.js +1 -1
- package/dist/esm/services/cache/index.d.ts +1 -1
- package/dist/esm/services/cache/index.js +1 -1
- package/dist/esm/services/cache/product-cache-service.d.ts +21 -21
- package/dist/esm/services/cache/product-cache-service.js +68 -68
- package/dist/esm/services/cost/cost-calculation-types.d.ts +69 -69
- package/dist/esm/services/cost/cost-calculation-types.js +15 -15
- package/dist/esm/services/cost/cost-calculator-service.d.ts +24 -24
- package/dist/esm/services/cost/cost-calculator-service.js +456 -456
- package/dist/esm/services/cost/cost-currency-service.d.ts +6 -6
- package/dist/esm/services/cost/cost-currency-service.js +84 -84
- package/dist/esm/services/cost/cost-filter-service.d.ts +10 -10
- package/dist/esm/services/cost/cost-filter-service.js +118 -118
- package/dist/esm/services/cost/index.d.ts +5 -5
- package/dist/esm/services/cost/index.js +5 -5
- package/dist/esm/services/cost/order-cost/index.d.ts +2 -2
- package/dist/esm/services/cost/order-cost/index.js +2 -2
- package/dist/esm/services/cost/order-cost/order-cost-resolution-service.d.ts +23 -23
- package/dist/esm/services/cost/order-cost/order-cost-resolution-service.js +287 -287
- package/dist/esm/services/cost/order-cost/order-cost-resolution-types.d.ts +31 -31
- package/dist/esm/services/cost/order-cost/order-cost-resolution-types.js +1 -1
- package/dist/esm/services/currency-exchange-rate-lookup-service.d.ts +12 -12
- package/dist/esm/services/currency-exchange-rate-lookup-service.js +90 -90
- package/dist/esm/services/db/accounts-db-service.d.ts +9 -9
- package/dist/esm/services/db/accounts-db-service.js +29 -29
- package/dist/esm/services/db/api-keys-db-service.d.ts +10 -10
- package/dist/esm/services/db/api-keys-db-service.js +32 -32
- package/dist/esm/services/db/contact-enrichments-db-service.d.ts +15 -15
- package/dist/esm/services/db/contact-enrichments-db-service.js +90 -90
- package/dist/esm/services/db/currency-exchange-rates-db-service.d.ts +21 -21
- package/dist/esm/services/db/currency-exchange-rates-db-service.js +35 -35
- package/dist/esm/services/db/custom-measures-db-service.d.ts +14 -14
- package/dist/esm/services/db/custom-measures-db-service.js +44 -44
- package/dist/esm/services/db/destinations-db-service.d.ts +13 -13
- package/dist/esm/services/db/destinations-db-service.js +70 -70
- package/dist/esm/services/db/identity-cache-db-service.d.ts +28 -28
- package/dist/esm/services/db/identity-cache-db-service.js +313 -313
- package/dist/esm/services/db/identity-cache-dynamodb-service/constants.d.ts +3 -3
- package/dist/esm/services/db/identity-cache-dynamodb-service/constants.js +3 -3
- package/dist/esm/services/db/identity-cache-dynamodb-service/identity-cache-dynamodb-db-service.d.ts +25 -20
- package/dist/esm/services/db/identity-cache-dynamodb-service/identity-cache-dynamodb-db-service.js +503 -358
- package/dist/esm/services/db/identity-cache-dynamodb-service/identity-cache-dynamodb-db-service.js.map +1 -1
- package/dist/esm/services/db/identity-cache-dynamodb-service/identity-gateway-service.d.ts +23 -23
- package/dist/esm/services/db/identity-cache-dynamodb-service/identity-gateway-service.js +218 -218
- package/dist/esm/services/db/identity-cache-dynamodb-service/index.d.ts +4 -4
- package/dist/esm/services/db/identity-cache-dynamodb-service/index.js +4 -4
- package/dist/esm/services/db/identity-cache-dynamodb-service/key-builders.d.ts +12 -12
- package/dist/esm/services/db/identity-cache-dynamodb-service/key-builders.js +23 -23
- package/dist/esm/services/db/identity-cache-dynamodb-service/types.d.ts +82 -71
- package/dist/esm/services/db/identity-cache-dynamodb-service/types.js +25 -25
- package/dist/esm/services/db/identity-cache-dynamodb-service/types.js.map +1 -1
- package/dist/esm/services/db/index.d.ts +22 -22
- package/dist/esm/services/db/index.js +22 -22
- package/dist/esm/services/db/log-events-db-service.d.ts +11 -11
- package/dist/esm/services/db/log-events-db-service.js +177 -177
- package/dist/esm/services/db/pixels-db-service.d.ts +8 -8
- package/dist/esm/services/db/pixels-db-service.js +31 -31
- package/dist/esm/services/db/products-db-service-types.d.ts +10 -10
- package/dist/esm/services/db/products-db-service-types.js +1 -1
- package/dist/esm/services/db/products-db-service.d.ts +19 -19
- package/dist/esm/services/db/products-db-service.js +277 -277
- package/dist/esm/services/db/purchasable-contacts-db-service.d.ts +9 -9
- package/dist/esm/services/db/purchasable-contacts-db-service.js +39 -39
- package/dist/esm/services/db/purchased-contacts/index.d.ts +2 -2
- package/dist/esm/services/db/purchased-contacts/index.js +2 -2
- package/dist/esm/services/db/purchased-contacts/purchased-contacts-db-service.d.ts +18 -18
- package/dist/esm/services/db/purchased-contacts/purchased-contacts-db-service.js +148 -148
- package/dist/esm/services/db/purchased-contacts/types.d.ts +11 -11
- package/dist/esm/services/db/purchased-contacts/types.js +1 -1
- package/dist/esm/services/db/shopify-app-installs-db-service.d.ts +10 -10
- package/dist/esm/services/db/shopify-app-installs-db-service.js +48 -48
- package/dist/esm/services/db/shopify-products-cache-db-service.d.ts +16 -16
- package/dist/esm/services/db/shopify-products-cache-db-service.js +66 -66
- package/dist/esm/services/db/subscriptions-db-service.d.ts +11 -11
- package/dist/esm/services/db/subscriptions-db-service.js +34 -34
- package/dist/esm/services/db/tracking-events-db-service.d.ts +21 -21
- package/dist/esm/services/db/tracking-events-db-service.js +184 -184
- package/dist/esm/services/db/user-accounts-db-service.d.ts +7 -7
- package/dist/esm/services/db/user-accounts-db-service.js +13 -13
- package/dist/esm/services/email-verification/contact-email-verification-service.d.ts +7 -7
- package/dist/esm/services/email-verification/contact-email-verification-service.js +97 -97
- package/dist/esm/services/email-verification/email-verification-service.d.ts +19 -19
- package/dist/esm/services/email-verification/email-verification-service.js +127 -127
- package/dist/esm/services/email-verification/index.d.ts +2 -2
- package/dist/esm/services/email-verification/index.js +2 -2
- package/dist/esm/services/eventbridge-integration-service.d.ts +9 -9
- package/dist/esm/services/eventbridge-integration-service.js +24 -24
- package/dist/esm/services/events/build-collect-queue-tracking-event.d.ts +11 -11
- package/dist/esm/services/events/build-collect-queue-tracking-event.js +19 -19
- package/dist/esm/services/events/collect-queue-tracking-service.d.ts +12 -12
- package/dist/esm/services/events/collect-queue-tracking-service.js +18 -18
- package/dist/esm/services/events/index.d.ts +5 -5
- package/dist/esm/services/events/index.js +5 -5
- package/dist/esm/services/events/log-event-service.d.ts +19 -19
- package/dist/esm/services/events/log-event-service.js +73 -73
- package/dist/esm/services/events/metric-event-service.d.ts +9 -9
- package/dist/esm/services/events/metric-event-service.js +45 -45
- package/dist/esm/services/events/tracking-event-sqs-service.d.ts +8 -8
- package/dist/esm/services/events/tracking-event-sqs-service.js +32 -32
- package/dist/esm/services/generic-cache-service.d.ts +7 -7
- package/dist/esm/services/generic-cache-service.js +29 -29
- package/dist/esm/services/index.d.ts +11 -11
- package/dist/esm/services/index.js +11 -11
- package/dist/esm/services/ipdata-lookup-service.d.ts +20 -20
- package/dist/esm/services/ipdata-lookup-service.js +108 -108
- package/dist/esm/services/shopify/index.d.ts +2 -2
- package/dist/esm/services/shopify/index.js +2 -2
- package/dist/esm/services/shopify/products/index.d.ts +1 -1
- package/dist/esm/services/shopify/products/index.js +1 -1
- package/dist/esm/services/shopify/products/shopify-products-serviceV2.d.ts +17 -17
- package/dist/esm/services/shopify/products/shopify-products-serviceV2.js +108 -108
- package/dist/esm/services/shopify/shopify-graphql-transformer.d.ts +8 -8
- package/dist/esm/services/shopify/shopify-graphql-transformer.js +138 -138
- package/dist/esm/types/acuity-types.d.ts +74 -74
- package/dist/esm/types/acuity-types.js +1 -1
- package/dist/esm/types/api-response.d.ts +6 -6
- package/dist/esm/types/api-response.js +1 -1
- package/dist/esm/types/index.d.ts +6 -6
- package/dist/esm/types/index.js +6 -6
- package/dist/esm/types/internal-events/event-detail-types.d.ts +20 -20
- package/dist/esm/types/internal-events/event-detail-types.js +24 -24
- package/dist/esm/types/internal-events/index.d.ts +1 -1
- package/dist/esm/types/internal-events/index.js +1 -1
- package/dist/esm/types/open-exchange-rates-types.d.ts +10 -10
- package/dist/esm/types/open-exchange-rates-types.js +1 -1
- package/dist/esm/types/public-api-types.d.ts +24 -24
- package/dist/esm/types/public-api-types.js +10 -10
- package/dist/esm/types/shopify-graphql-types/admin.generated.d.ts +123 -123
- package/dist/esm/types/shopify-graphql-types/admin.generated.js +1 -1
- package/dist/esm/types/shopify-graphql-types/admin.types.d.ts +26289 -26289
- package/dist/esm/types/shopify-graphql-types/admin.types.js +5299 -5299
- package/dist/esm/types/shopify-graphql-types/index.d.ts +2 -2
- package/dist/esm/types/shopify-graphql-types/index.js +2 -2
- package/dist/esm/types/shopify-rest-types.d.ts +767 -767
- package/dist/esm/types/shopify-rest-types.js +1 -1
- package/dist/esm/utils/compression.d.ts +36 -36
- package/dist/esm/utils/compression.js +187 -187
- package/dist/esm/utils/custom-measure-formula-utils.d.ts +6 -6
- package/dist/esm/utils/custom-measure-formula-utils.js +201 -201
- package/dist/esm/utils/index.d.ts +4 -4
- package/dist/esm/utils/index.js +4 -4
- package/dist/esm/utils/retry-envelope.d.ts +12 -12
- package/dist/esm/utils/retry-envelope.js +22 -22
- package/dist/esm/utils/size.d.ts +2 -2
- package/dist/esm/utils/size.js +44 -44
- package/package.json +136 -136
|
@@ -1,1771 +1,1771 @@
|
|
|
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
|
-
describe('Identity Trait Merging Tests', () => {
|
|
6
|
-
afterEach(() => {
|
|
7
|
-
jest.resetModules();
|
|
8
|
-
});
|
|
9
|
-
describe('mergeIdentityTraits function', () => {
|
|
10
|
-
it('should merge simple string arrays correctly', () => {
|
|
11
|
-
const incomingTraits = {
|
|
12
|
-
emails: ['new@email.com'],
|
|
13
|
-
userIds: ['user1', 'user2'],
|
|
14
|
-
};
|
|
15
|
-
const cachedTraits = {
|
|
16
|
-
emails: ['existing@email.com'],
|
|
17
|
-
userIds: ['user2', 'user3'],
|
|
18
|
-
phones: ['+1234567890'],
|
|
19
|
-
};
|
|
20
|
-
const merged = (0, at_shared_utils_1.mergeIdentityTraits)(incomingTraits, cachedTraits);
|
|
21
|
-
expect(merged.emails).toEqual(['new@email.com', 'existing@email.com']);
|
|
22
|
-
expect(merged.userIds).toEqual(['user1', 'user2', 'user3']);
|
|
23
|
-
expect(merged.phones).toEqual(['+1234567890']);
|
|
24
|
-
});
|
|
25
|
-
it('should handle null and undefined values in arrays', () => {
|
|
26
|
-
const incomingTraits = {
|
|
27
|
-
emails: ['test@email.com', null, undefined],
|
|
28
|
-
userIds: ['user1'],
|
|
29
|
-
};
|
|
30
|
-
const cachedTraits = {
|
|
31
|
-
emails: [null, 'cached@email.com', undefined],
|
|
32
|
-
userIds: null,
|
|
33
|
-
};
|
|
34
|
-
const merged = (0, at_shared_utils_1.mergeIdentityTraits)(incomingTraits, cachedTraits);
|
|
35
|
-
expect(merged.emails).toContain('test@email.com');
|
|
36
|
-
expect(merged.emails).toContain('cached@email.com');
|
|
37
|
-
expect(merged.userIds).toEqual(['user1']);
|
|
38
|
-
});
|
|
39
|
-
it('should merge addresses correctly', () => {
|
|
40
|
-
const incomingTraits = {
|
|
41
|
-
addresses: [
|
|
42
|
-
{
|
|
43
|
-
city: 'New York',
|
|
44
|
-
country: 'USA',
|
|
45
|
-
countryCode: 'US',
|
|
46
|
-
province: 'NY',
|
|
47
|
-
provinceCode: '10001',
|
|
48
|
-
},
|
|
49
|
-
],
|
|
50
|
-
};
|
|
51
|
-
const cachedTraits = {
|
|
52
|
-
addresses: [
|
|
53
|
-
{
|
|
54
|
-
city: 'Los Angeles',
|
|
55
|
-
country: 'USA',
|
|
56
|
-
countryCode: 'US',
|
|
57
|
-
province: 'CA',
|
|
58
|
-
provinceCode: '90210',
|
|
59
|
-
},
|
|
60
|
-
],
|
|
61
|
-
};
|
|
62
|
-
const merged = (0, at_shared_utils_1.mergeIdentityTraits)(incomingTraits, cachedTraits);
|
|
63
|
-
expect(merged.addresses).toHaveLength(2);
|
|
64
|
-
expect(merged.addresses).toEqual(expect.arrayContaining([
|
|
65
|
-
expect.objectContaining({ city: 'New York' }),
|
|
66
|
-
expect.objectContaining({ city: 'Los Angeles' }),
|
|
67
|
-
]));
|
|
68
|
-
});
|
|
69
|
-
it('should merge click information correctly', () => {
|
|
70
|
-
const incomingTraits = {
|
|
71
|
-
click: {
|
|
72
|
-
fbp: 'fb.new.123',
|
|
73
|
-
fbpCollectedAt: '2024-01-01T00:00:00.000Z',
|
|
74
|
-
gclid: 'new_gclid',
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
const cachedTraits = {
|
|
78
|
-
click: {
|
|
79
|
-
fbp: 'fb.old.456',
|
|
80
|
-
fbpCollectedAt: '2023-12-01T00:00:00.000Z',
|
|
81
|
-
fbclid: 'cached_fbclid',
|
|
82
|
-
},
|
|
83
|
-
};
|
|
84
|
-
const merged = (0, at_shared_utils_1.mergeIdentityTraits)(incomingTraits, cachedTraits);
|
|
85
|
-
expect(merged.click?.fbp).toBe('fb.new.123');
|
|
86
|
-
expect(merged.click?.gclid).toBe('new_gclid');
|
|
87
|
-
expect(merged.click?.fbpCollectedAt).toBe('2024-01-01T00:00:00.000Z');
|
|
88
|
-
expect(merged.click?.fbclid).toBeUndefined();
|
|
89
|
-
});
|
|
90
|
-
it('should handle empty traits correctly', () => {
|
|
91
|
-
const incomingTraits = {};
|
|
92
|
-
const cachedTraits = {
|
|
93
|
-
emails: ['cached@email.com'],
|
|
94
|
-
userIds: ['user1'],
|
|
95
|
-
};
|
|
96
|
-
const merged = (0, at_shared_utils_1.mergeIdentityTraits)(incomingTraits, cachedTraits);
|
|
97
|
-
expect(merged.emails).toEqual(['cached@email.com']);
|
|
98
|
-
expect(merged.userIds).toEqual(['user1']);
|
|
99
|
-
});
|
|
100
|
-
it('should handle undefined traits correctly', () => {
|
|
101
|
-
const merged1 = (0, at_shared_utils_1.mergeIdentityTraits)(undefined, { emails: ['test@email.com'] });
|
|
102
|
-
expect(merged1.emails).toEqual(['test@email.com']);
|
|
103
|
-
const merged2 = (0, at_shared_utils_1.mergeIdentityTraits)({ emails: ['test@email.com'] }, undefined);
|
|
104
|
-
expect(merged2.emails).toEqual(['test@email.com']);
|
|
105
|
-
const merged3 = (0, at_shared_utils_1.mergeIdentityTraits)(undefined, undefined);
|
|
106
|
-
expect(merged3).toEqual({});
|
|
107
|
-
});
|
|
108
|
-
it('should preserve version information', () => {
|
|
109
|
-
const incomingTraits = {
|
|
110
|
-
version: '3',
|
|
111
|
-
emails: ['new@email.com'],
|
|
112
|
-
};
|
|
113
|
-
const cachedTraits = {
|
|
114
|
-
version: '2',
|
|
115
|
-
emails: ['old@email.com'],
|
|
116
|
-
};
|
|
117
|
-
const merged = (0, at_shared_utils_1.mergeIdentityTraits)(incomingTraits, cachedTraits);
|
|
118
|
-
expect(merged.version).toBe('3');
|
|
119
|
-
expect(merged.emails).toEqual(['new@email.com', 'old@email.com']);
|
|
120
|
-
});
|
|
121
|
-
it('should handle complex nested objects', () => {
|
|
122
|
-
const incomingTraits = {
|
|
123
|
-
click: {
|
|
124
|
-
googleClientInfos: [{ id: 'new1', clickId: 'click1', sessionId: 'session1' }],
|
|
125
|
-
},
|
|
126
|
-
};
|
|
127
|
-
const cachedTraits = {
|
|
128
|
-
click: {
|
|
129
|
-
googleClientInfos: [{ id: 'cached1', clickId: 'click2', sessionId: 'session2' }],
|
|
130
|
-
},
|
|
131
|
-
};
|
|
132
|
-
const merged = (0, at_shared_utils_1.mergeIdentityTraits)(incomingTraits, cachedTraits);
|
|
133
|
-
expect(merged.click?.googleClientInfos).toBeDefined();
|
|
134
|
-
expect(Array.isArray(merged.click?.googleClientInfos)).toBe(true);
|
|
135
|
-
expect(merged.click?.googleClientInfos).toEqual([{ id: 'cached1', clickId: 'click2', sessionId: 'session2' }]);
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
describe('Integration: Merging + Staleness Checking', () => {
|
|
139
|
-
it('should not be stale when merged identity matches cached identity', () => {
|
|
140
|
-
const cachedIdentity = {
|
|
141
|
-
identityId: 'test-id-123',
|
|
142
|
-
traits: {
|
|
143
|
-
emails: ['cached@email.com', 'shared@email.com'],
|
|
144
|
-
userIds: ['user1', 'user2'],
|
|
145
|
-
addresses: [
|
|
146
|
-
{
|
|
147
|
-
city: 'New York',
|
|
148
|
-
country: 'USA',
|
|
149
|
-
countryCode: 'US',
|
|
150
|
-
},
|
|
151
|
-
],
|
|
152
|
-
version: '2',
|
|
153
|
-
},
|
|
154
|
-
};
|
|
155
|
-
const incomingIdentity = {
|
|
156
|
-
identityId: 'test-id-123',
|
|
157
|
-
traits: {
|
|
158
|
-
emails: ['shared@email.com'],
|
|
159
|
-
userIds: ['user1'],
|
|
160
|
-
version: '2',
|
|
161
|
-
},
|
|
162
|
-
};
|
|
163
|
-
const mergedTraits = (0, at_shared_utils_1.mergeIdentityTraits)(incomingIdentity.traits, cachedIdentity.traits);
|
|
164
|
-
const mergedIdentity = { ...incomingIdentity, traits: mergedTraits };
|
|
165
|
-
const staleTracker = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, mergedIdentity);
|
|
166
|
-
expect(staleTracker.isCacheStale).toBe(false);
|
|
167
|
-
expect(mergedIdentity.traits?.emails).toEqual(['shared@email.com', 'cached@email.com']);
|
|
168
|
-
});
|
|
169
|
-
it('should be stale when merged identity has new traits', () => {
|
|
170
|
-
const cachedIdentity = {
|
|
171
|
-
identityId: 'test-id-123',
|
|
172
|
-
traits: {
|
|
173
|
-
emails: ['cached@email.com'],
|
|
174
|
-
version: '2',
|
|
175
|
-
},
|
|
176
|
-
};
|
|
177
|
-
const incomingIdentity = {
|
|
178
|
-
identityId: 'test-id-123',
|
|
179
|
-
traits: {
|
|
180
|
-
emails: ['cached@email.com', 'new@email.com'],
|
|
181
|
-
version: '2',
|
|
182
|
-
},
|
|
183
|
-
};
|
|
184
|
-
const mergedTraits = (0, at_shared_utils_1.mergeIdentityTraits)(incomingIdentity.traits, cachedIdentity.traits);
|
|
185
|
-
const mergedIdentity = { ...incomingIdentity, traits: mergedTraits };
|
|
186
|
-
const staleTracker = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, mergedIdentity);
|
|
187
|
-
expect(staleTracker.isCacheStale).toBe(true);
|
|
188
|
-
expect(staleTracker.isEmailsStale).toBe(true);
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
describe('Identity Cache Staleness Tests', () => {
|
|
193
|
-
afterEach(() => {
|
|
194
|
-
jest.resetModules();
|
|
195
|
-
});
|
|
196
|
-
describe('isIdentityCacheStale function', () => {
|
|
197
|
-
it('should detect identity ID changes', () => {
|
|
198
|
-
const cachedIdentity = {
|
|
199
|
-
identityId: 'old-id',
|
|
200
|
-
traits: { emails: ['test@email.com'] },
|
|
201
|
-
};
|
|
202
|
-
const incomingIdentity = {
|
|
203
|
-
identityId: 'new-id',
|
|
204
|
-
traits: { emails: ['test@email.com'] },
|
|
205
|
-
};
|
|
206
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
207
|
-
expect(result.isCacheStale).toBe(true);
|
|
208
|
-
expect(result.isIdentityIdStale).toBe(true);
|
|
209
|
-
});
|
|
210
|
-
it('should detect new emails', () => {
|
|
211
|
-
const cachedIdentity = {
|
|
212
|
-
identityId: 'test-id',
|
|
213
|
-
traits: { emails: ['old@email.com'] },
|
|
214
|
-
};
|
|
215
|
-
const incomingIdentity = {
|
|
216
|
-
identityId: 'test-id',
|
|
217
|
-
traits: { emails: ['old@email.com', 'new@email.com'] },
|
|
218
|
-
};
|
|
219
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
220
|
-
expect(result.isCacheStale).toBe(true);
|
|
221
|
-
expect(result.isEmailsStale).toBe(true);
|
|
222
|
-
});
|
|
223
|
-
it('should detect new user IDs', () => {
|
|
224
|
-
const cachedIdentity = {
|
|
225
|
-
identityId: 'test-id',
|
|
226
|
-
traits: { userIds: ['user1'] },
|
|
227
|
-
};
|
|
228
|
-
const incomingIdentity = {
|
|
229
|
-
identityId: 'test-id',
|
|
230
|
-
traits: { userIds: ['user1', 'user2'] },
|
|
231
|
-
};
|
|
232
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
233
|
-
expect(result.isCacheStale).toBe(true);
|
|
234
|
-
expect(result.isUserIdsStale).toBe(true);
|
|
235
|
-
});
|
|
236
|
-
it('should detect new phones', () => {
|
|
237
|
-
const cachedIdentity = {
|
|
238
|
-
identityId: 'test-id',
|
|
239
|
-
traits: { phones: ['+1234567890'] },
|
|
240
|
-
};
|
|
241
|
-
const incomingIdentity = {
|
|
242
|
-
identityId: 'test-id',
|
|
243
|
-
traits: { phones: ['+1234567890', '+9876543210'] },
|
|
244
|
-
};
|
|
245
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
246
|
-
expect(result.isCacheStale).toBe(true);
|
|
247
|
-
expect(result.isPhonesStale).toBe(true);
|
|
248
|
-
});
|
|
249
|
-
it('should detect new addresses (non-IP sourced)', () => {
|
|
250
|
-
const cachedIdentity = {
|
|
251
|
-
identityId: 'test-id',
|
|
252
|
-
traits: {
|
|
253
|
-
addresses: [
|
|
254
|
-
{
|
|
255
|
-
city: 'New York',
|
|
256
|
-
country: 'USA',
|
|
257
|
-
s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT,
|
|
258
|
-
},
|
|
259
|
-
],
|
|
260
|
-
},
|
|
261
|
-
};
|
|
262
|
-
const incomingIdentity = {
|
|
263
|
-
identityId: 'test-id',
|
|
264
|
-
traits: {
|
|
265
|
-
addresses: [
|
|
266
|
-
{ city: 'New York', country: 'USA', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT },
|
|
267
|
-
{ city: 'Los Angeles', country: 'USA', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT },
|
|
268
|
-
],
|
|
269
|
-
},
|
|
270
|
-
};
|
|
271
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
272
|
-
expect(result.isCacheStale).toBe(true);
|
|
273
|
-
expect(result.isAddressesStale).toBe(true);
|
|
274
|
-
expect(result.isNonIpAddressesStale).toBe(true);
|
|
275
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
|
|
276
|
-
});
|
|
277
|
-
it('should detect IP address changes but NOT mark cache stale (volatile trait)', () => {
|
|
278
|
-
const cachedIdentity = {
|
|
279
|
-
identityId: 'test-id',
|
|
280
|
-
traits: { ipAddress: '192.168.1.1' },
|
|
281
|
-
};
|
|
282
|
-
const incomingIdentity = {
|
|
283
|
-
identityId: 'test-id',
|
|
284
|
-
traits: { ipAddress: '10.0.0.1' },
|
|
285
|
-
};
|
|
286
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
287
|
-
expect(result.isCacheStale).toBe(false);
|
|
288
|
-
expect(result.isIpAddressStale).toBe(true);
|
|
289
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
|
|
290
|
-
});
|
|
291
|
-
it('should detect user agent changes but NOT mark cache stale (volatile trait)', () => {
|
|
292
|
-
const cachedIdentity = {
|
|
293
|
-
identityId: 'test-id',
|
|
294
|
-
traits: { userAgent: 'Mozilla/5.0 (old browser)' },
|
|
295
|
-
};
|
|
296
|
-
const incomingIdentity = {
|
|
297
|
-
identityId: 'test-id',
|
|
298
|
-
traits: { userAgent: 'Mozilla/5.0 (new browser)' },
|
|
299
|
-
};
|
|
300
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
301
|
-
expect(result.isCacheStale).toBe(false);
|
|
302
|
-
expect(result.isUserAgentStale).toBe(true);
|
|
303
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
|
|
304
|
-
});
|
|
305
|
-
it('should not be stale when no new information is provided', () => {
|
|
306
|
-
const cachedIdentity = {
|
|
307
|
-
identityId: 'test-id',
|
|
308
|
-
traits: {
|
|
309
|
-
emails: ['test@email.com'],
|
|
310
|
-
userIds: ['user1'],
|
|
311
|
-
phones: ['+1234567890'],
|
|
312
|
-
},
|
|
313
|
-
};
|
|
314
|
-
const incomingIdentity = {
|
|
315
|
-
identityId: 'test-id',
|
|
316
|
-
traits: {
|
|
317
|
-
emails: ['test@email.com'],
|
|
318
|
-
userIds: ['user1'],
|
|
319
|
-
},
|
|
320
|
-
};
|
|
321
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
322
|
-
expect(result.isCacheStale).toBe(false);
|
|
323
|
-
});
|
|
324
|
-
it('should handle empty traits gracefully', () => {
|
|
325
|
-
const cachedIdentity = {
|
|
326
|
-
identityId: 'test-id',
|
|
327
|
-
traits: {},
|
|
328
|
-
};
|
|
329
|
-
const incomingIdentity = {
|
|
330
|
-
identityId: 'test-id',
|
|
331
|
-
traits: {},
|
|
332
|
-
};
|
|
333
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
334
|
-
expect(result.isCacheStale).toBe(false);
|
|
335
|
-
});
|
|
336
|
-
it('should handle undefined traits gracefully', () => {
|
|
337
|
-
const cachedIdentity = {
|
|
338
|
-
identityId: 'test-id',
|
|
339
|
-
};
|
|
340
|
-
const incomingIdentity = {
|
|
341
|
-
identityId: 'test-id',
|
|
342
|
-
};
|
|
343
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
344
|
-
expect(result.isCacheStale).toBe(false);
|
|
345
|
-
});
|
|
346
|
-
it('should detect multiple stale conditions (identity traits take priority over volatile)', () => {
|
|
347
|
-
const cachedIdentity = {
|
|
348
|
-
identityId: 'test-id',
|
|
349
|
-
traits: {
|
|
350
|
-
emails: ['old@email.com'],
|
|
351
|
-
userIds: ['user1'],
|
|
352
|
-
ipAddress: '192.168.1.1',
|
|
353
|
-
},
|
|
354
|
-
};
|
|
355
|
-
const incomingIdentity = {
|
|
356
|
-
identityId: 'test-id',
|
|
357
|
-
traits: {
|
|
358
|
-
emails: ['old@email.com', 'new@email.com'],
|
|
359
|
-
userIds: ['user1', 'user2'],
|
|
360
|
-
ipAddress: '10.0.0.1',
|
|
361
|
-
},
|
|
362
|
-
};
|
|
363
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
364
|
-
expect(result.isCacheStale).toBe(true);
|
|
365
|
-
expect(result.isEmailsStale).toBe(true);
|
|
366
|
-
expect(result.isUserIdsStale).toBe(true);
|
|
367
|
-
expect(result.isIpAddressStale).toBe(true);
|
|
368
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
369
|
-
});
|
|
370
|
-
});
|
|
371
|
-
describe('isClickInfosStale function', () => {
|
|
372
|
-
it('should detect new FBC values', () => {
|
|
373
|
-
const cachedClick = {
|
|
374
|
-
fbc: 'fb.1.123.old_fbclid',
|
|
375
|
-
};
|
|
376
|
-
const incomingClick = {
|
|
377
|
-
fbc: 'fb.1.123.new_fbclid',
|
|
378
|
-
};
|
|
379
|
-
const result = (0, at_shared_utils_1.isClickInfosStale)(cachedClick, incomingClick);
|
|
380
|
-
expect(result).toBe(true);
|
|
381
|
-
});
|
|
382
|
-
it('should detect new click IDs', () => {
|
|
383
|
-
const cachedClick = {
|
|
384
|
-
gclid: 'old_gclid',
|
|
385
|
-
};
|
|
386
|
-
const incomingClick = {
|
|
387
|
-
gclid: 'new_gclid',
|
|
388
|
-
};
|
|
389
|
-
const result = (0, at_shared_utils_1.isClickInfosStale)(cachedClick, incomingClick);
|
|
390
|
-
expect(result).toBe(true);
|
|
391
|
-
});
|
|
392
|
-
it('should ignore collection timestamps', () => {
|
|
393
|
-
const cachedClick = {
|
|
394
|
-
fbp: 'fb.2.123.456',
|
|
395
|
-
fbpCollectedAt: '2023-01-01T00:00:00.000Z',
|
|
396
|
-
};
|
|
397
|
-
const incomingClick = {
|
|
398
|
-
fbp: 'fb.2.123.456',
|
|
399
|
-
fbpCollectedAt: '2024-01-01T00:00:00.000Z',
|
|
400
|
-
};
|
|
401
|
-
const result = (0, at_shared_utils_1.isClickInfosStale)(cachedClick, incomingClick);
|
|
402
|
-
expect(result).toBe(false);
|
|
403
|
-
});
|
|
404
|
-
it('should ignore googleClientInfos', () => {
|
|
405
|
-
const cachedClick = {
|
|
406
|
-
googleClientInfos: [{ id: 'old', clickId: 'old_click' }],
|
|
407
|
-
};
|
|
408
|
-
const incomingClick = {
|
|
409
|
-
googleClientInfos: [{ id: 'new', clickId: 'new_click' }],
|
|
410
|
-
};
|
|
411
|
-
const result = (0, at_shared_utils_1.isClickInfosStale)(cachedClick, incomingClick);
|
|
412
|
-
expect(result).toBe(false);
|
|
413
|
-
});
|
|
414
|
-
it('should handle empty click info', () => {
|
|
415
|
-
const result = (0, at_shared_utils_1.isClickInfosStale)({}, {});
|
|
416
|
-
expect(result).toBe(false);
|
|
417
|
-
});
|
|
418
|
-
it('should detect when incoming has new click info but cached is empty', () => {
|
|
419
|
-
const cachedClick = {};
|
|
420
|
-
const incomingClick = {
|
|
421
|
-
fbp: 'fb.2.123.456',
|
|
422
|
-
};
|
|
423
|
-
const result = (0, at_shared_utils_1.isClickInfosStale)(cachedClick, incomingClick);
|
|
424
|
-
expect(result).toBe(true);
|
|
425
|
-
});
|
|
426
|
-
});
|
|
427
|
-
describe('Edge Cases and Error Handling', () => {
|
|
428
|
-
it('should handle malformed FBC values gracefully', () => {
|
|
429
|
-
const cachedClick = {
|
|
430
|
-
fbc: 'malformed_fbc',
|
|
431
|
-
};
|
|
432
|
-
const incomingClick = {
|
|
433
|
-
fbc: 'also_malformed',
|
|
434
|
-
};
|
|
435
|
-
const result = (0, at_shared_utils_1.isClickInfosStale)(cachedClick, incomingClick);
|
|
436
|
-
expect(result).toBe(true);
|
|
437
|
-
});
|
|
438
|
-
it('should handle null/undefined arrays in traits', () => {
|
|
439
|
-
const cachedIdentity = {
|
|
440
|
-
identityId: 'test-id',
|
|
441
|
-
traits: {
|
|
442
|
-
emails: null,
|
|
443
|
-
userIds: undefined,
|
|
444
|
-
},
|
|
445
|
-
};
|
|
446
|
-
const incomingIdentity = {
|
|
447
|
-
identityId: 'test-id',
|
|
448
|
-
traits: {
|
|
449
|
-
emails: ['new@email.com'],
|
|
450
|
-
userIds: ['user1'],
|
|
451
|
-
},
|
|
452
|
-
};
|
|
453
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
454
|
-
expect(result.isCacheStale).toBe(true);
|
|
455
|
-
expect(result.isEmailsStale).toBe(true);
|
|
456
|
-
expect(result.isUserIdsStale).toBe(true);
|
|
457
|
-
});
|
|
458
|
-
it('should handle arrays with null/undefined elements', () => {
|
|
459
|
-
const cachedIdentity = {
|
|
460
|
-
identityId: 'test-id',
|
|
461
|
-
traits: {
|
|
462
|
-
emails: ['valid@email.com', null, undefined],
|
|
463
|
-
},
|
|
464
|
-
};
|
|
465
|
-
const incomingIdentity = {
|
|
466
|
-
identityId: 'test-id',
|
|
467
|
-
traits: {
|
|
468
|
-
emails: ['valid@email.com', null, undefined, 'new@email.com'],
|
|
469
|
-
},
|
|
470
|
-
};
|
|
471
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
472
|
-
expect(result.isCacheStale).toBe(true);
|
|
473
|
-
expect(result.isEmailsStale).toBe(true);
|
|
474
|
-
});
|
|
475
|
-
it('should handle error conditions gracefully', () => {
|
|
476
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(null, undefined);
|
|
477
|
-
expect(result.isCacheStale).toBe(false);
|
|
478
|
-
});
|
|
479
|
-
});
|
|
480
|
-
describe('Comprehensive Scenario Tests', () => {
|
|
481
|
-
it('should handle complex real-world scenario', () => {
|
|
482
|
-
const cachedIdentity = {
|
|
483
|
-
identityId: '01HXRZ27H4TXWBBTRK09Q7APDP',
|
|
484
|
-
traits: {
|
|
485
|
-
emails: ['user@domain.com'],
|
|
486
|
-
userIds: ['shopify_123'],
|
|
487
|
-
addresses: [
|
|
488
|
-
{
|
|
489
|
-
city: 'New York',
|
|
490
|
-
country: 'USA',
|
|
491
|
-
countryCode: 'US',
|
|
492
|
-
province: 'NY',
|
|
493
|
-
provinceCode: '10001',
|
|
494
|
-
},
|
|
495
|
-
],
|
|
496
|
-
click: {
|
|
497
|
-
fbp: 'fb.2.1715603578424.5068754021',
|
|
498
|
-
fbpCollectedAt: '2024-05-13T12:32:58.424Z',
|
|
499
|
-
gclid: 'original_gclid',
|
|
500
|
-
},
|
|
501
|
-
ipAddress: '192.168.1.100',
|
|
502
|
-
version: '2',
|
|
503
|
-
},
|
|
504
|
-
};
|
|
505
|
-
const incomingIdentity = {
|
|
506
|
-
identityId: '01HXRZ27H4TXWBBTRK09Q7APDP',
|
|
507
|
-
traits: {
|
|
508
|
-
emails: ['user@domain.com', 'user.secondary@domain.com'],
|
|
509
|
-
phones: ['+1234567890'],
|
|
510
|
-
addresses: [
|
|
511
|
-
{
|
|
512
|
-
city: 'New York',
|
|
513
|
-
country: 'USA',
|
|
514
|
-
countryCode: 'US',
|
|
515
|
-
province: 'NY',
|
|
516
|
-
provinceCode: '10001',
|
|
517
|
-
},
|
|
518
|
-
],
|
|
519
|
-
click: {
|
|
520
|
-
fbp: 'fb.2.1715603578424.5068754021',
|
|
521
|
-
fbpCollectedAt: '2024-05-13T15:30:00.000Z',
|
|
522
|
-
gclid: 'updated_gclid',
|
|
523
|
-
},
|
|
524
|
-
ipAddress: '192.168.1.100',
|
|
525
|
-
version: '2',
|
|
526
|
-
},
|
|
527
|
-
};
|
|
528
|
-
const mergedTraits = (0, at_shared_utils_1.mergeIdentityTraits)(cachedIdentity.traits, incomingIdentity.traits);
|
|
529
|
-
const mergedIdentity = { ...incomingIdentity, traits: mergedTraits };
|
|
530
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, mergedIdentity);
|
|
531
|
-
expect(result.isCacheStale).toBe(true);
|
|
532
|
-
expect(result.isEmailsStale).toBe(true);
|
|
533
|
-
expect(result.isPhonesStale).toBe(true);
|
|
534
|
-
expect(result.isClickInfosStale).toBe(true);
|
|
535
|
-
expect(result.isAddressesStale).toBe(false);
|
|
536
|
-
expect(result.isIpAddressStale).toBe(false);
|
|
537
|
-
expect(mergedIdentity.traits?.emails).toEqual(['user@domain.com', 'user.secondary@domain.com']);
|
|
538
|
-
expect(mergedIdentity.traits?.phones).toEqual(['+1234567890']);
|
|
539
|
-
expect(mergedIdentity.traits?.userIds).toEqual(['shopify_123']);
|
|
540
|
-
expect(mergedIdentity.traits?.click?.gclid).toEqual('updated_gclid');
|
|
541
|
-
});
|
|
542
|
-
it('should properly detect click staleness when click info actually differs', () => {
|
|
543
|
-
const cachedIdentity = {
|
|
544
|
-
identityId: 'test-id',
|
|
545
|
-
traits: {
|
|
546
|
-
click: {
|
|
547
|
-
gclid: 'original_gclid',
|
|
548
|
-
gclidCollectedAt: '2024-05-15T12:32:58.424Z',
|
|
549
|
-
},
|
|
550
|
-
},
|
|
551
|
-
};
|
|
552
|
-
const incomingIdentity = {
|
|
553
|
-
identityId: 'test-id',
|
|
554
|
-
traits: {
|
|
555
|
-
click: {
|
|
556
|
-
gclid: 'completely_different_gclid',
|
|
557
|
-
gclidCollectedAt: '2024-05-13T12:32:58.424Z',
|
|
558
|
-
},
|
|
559
|
-
},
|
|
560
|
-
};
|
|
561
|
-
const mergedTraits = (0, at_shared_utils_1.mergeIdentityTraits)(cachedIdentity.traits, incomingIdentity.traits);
|
|
562
|
-
const mergedIdentity = { ...incomingIdentity, traits: mergedTraits };
|
|
563
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, mergedIdentity);
|
|
564
|
-
expect(mergedTraits?.click?.gclid).toEqual('original_gclid');
|
|
565
|
-
expect(result.isCacheStale).toBe(false);
|
|
566
|
-
});
|
|
567
|
-
it('should handle scenario where cache is fresh', () => {
|
|
568
|
-
const cachedIdentity = {
|
|
569
|
-
identityId: 'test-id',
|
|
570
|
-
traits: {
|
|
571
|
-
emails: ['user@domain.com', 'secondary@domain.com'],
|
|
572
|
-
userIds: ['user1', 'user2'],
|
|
573
|
-
phones: ['+1234567890'],
|
|
574
|
-
version: '2',
|
|
575
|
-
},
|
|
576
|
-
};
|
|
577
|
-
const incomingIdentity = {
|
|
578
|
-
identityId: 'test-id',
|
|
579
|
-
traits: {
|
|
580
|
-
emails: ['user@domain.com'],
|
|
581
|
-
userIds: ['user1'],
|
|
582
|
-
version: '2',
|
|
583
|
-
},
|
|
584
|
-
};
|
|
585
|
-
const mergedTraits = (0, at_shared_utils_1.mergeIdentityTraits)(cachedIdentity.traits, incomingIdentity.traits);
|
|
586
|
-
const mergedIdentity = { ...incomingIdentity, traits: mergedTraits };
|
|
587
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, mergedIdentity);
|
|
588
|
-
expect(result.isCacheStale).toBe(false);
|
|
589
|
-
expect(mergedIdentity.traits?.emails).toEqual(['user@domain.com', 'secondary@domain.com']);
|
|
590
|
-
expect(mergedIdentity.traits?.userIds).toEqual(['user1', 'user2']);
|
|
591
|
-
expect(mergedIdentity.traits?.phones).toEqual(['+1234567890']);
|
|
592
|
-
});
|
|
593
|
-
});
|
|
594
|
-
});
|
|
595
|
-
describe('Three-Tier Staleness Model Tests', () => {
|
|
596
|
-
afterEach(() => {
|
|
597
|
-
jest.resetModules();
|
|
598
|
-
});
|
|
599
|
-
describe('TIER 1: VOLATILE_ONLY (no action needed)', () => {
|
|
600
|
-
it('should return VOLATILE_ONLY tier when only ipAddress is stale', () => {
|
|
601
|
-
const cachedIdentity = {
|
|
602
|
-
identityId: 'test-id',
|
|
603
|
-
traits: {
|
|
604
|
-
emails: ['test@email.com'],
|
|
605
|
-
ipAddress: '192.168.1.1',
|
|
606
|
-
},
|
|
607
|
-
};
|
|
608
|
-
const incomingIdentity = {
|
|
609
|
-
identityId: 'test-id',
|
|
610
|
-
traits: {
|
|
611
|
-
emails: ['test@email.com'],
|
|
612
|
-
ipAddress: '10.0.0.1',
|
|
613
|
-
},
|
|
614
|
-
};
|
|
615
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
616
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
|
|
617
|
-
expect(result.isCacheStale).toBe(false);
|
|
618
|
-
expect(result.isIpAddressStale).toBe(true);
|
|
619
|
-
});
|
|
620
|
-
it('should return VOLATILE_ONLY tier when only userAgent is stale', () => {
|
|
621
|
-
const cachedIdentity = {
|
|
622
|
-
identityId: 'test-id',
|
|
623
|
-
traits: {
|
|
624
|
-
emails: ['test@email.com'],
|
|
625
|
-
userAgent: 'Mozilla/5.0 (old)',
|
|
626
|
-
},
|
|
627
|
-
};
|
|
628
|
-
const incomingIdentity = {
|
|
629
|
-
identityId: 'test-id',
|
|
630
|
-
traits: {
|
|
631
|
-
emails: ['test@email.com'],
|
|
632
|
-
userAgent: 'Mozilla/5.0 (new)',
|
|
633
|
-
},
|
|
634
|
-
};
|
|
635
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
636
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
|
|
637
|
-
expect(result.isCacheStale).toBe(false);
|
|
638
|
-
expect(result.isUserAgentStale).toBe(true);
|
|
639
|
-
});
|
|
640
|
-
it('should return VOLATILE_ONLY tier when only IP-sourced addresses are stale', () => {
|
|
641
|
-
const cachedIdentity = {
|
|
642
|
-
identityId: 'test-id',
|
|
643
|
-
traits: {
|
|
644
|
-
emails: ['test@email.com'],
|
|
645
|
-
addresses: [
|
|
646
|
-
{ city: 'New York', country: 'USA', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.IP_ADDRESS },
|
|
647
|
-
],
|
|
648
|
-
},
|
|
649
|
-
};
|
|
650
|
-
const incomingIdentity = {
|
|
651
|
-
identityId: 'test-id',
|
|
652
|
-
traits: {
|
|
653
|
-
emails: ['test@email.com'],
|
|
654
|
-
addresses: [
|
|
655
|
-
{ city: 'Los Angeles', country: 'USA', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.IP_ADDRESS },
|
|
656
|
-
],
|
|
657
|
-
},
|
|
658
|
-
};
|
|
659
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
660
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
|
|
661
|
-
expect(result.isCacheStale).toBe(false);
|
|
662
|
-
expect(result.isIpAddressesStale).toBe(true);
|
|
663
|
-
expect(result.isNonIpAddressesStale).toBe(false);
|
|
664
|
-
});
|
|
665
|
-
it('should return VOLATILE_ONLY tier when multiple volatile traits are stale', () => {
|
|
666
|
-
const cachedIdentity = {
|
|
667
|
-
identityId: 'test-id',
|
|
668
|
-
traits: {
|
|
669
|
-
emails: ['test@email.com'],
|
|
670
|
-
ipAddress: '192.168.1.1',
|
|
671
|
-
userAgent: 'Mozilla/5.0 (old)',
|
|
672
|
-
addresses: [
|
|
673
|
-
{ city: 'New York', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.IP_ADDRESS },
|
|
674
|
-
],
|
|
675
|
-
},
|
|
676
|
-
};
|
|
677
|
-
const incomingIdentity = {
|
|
678
|
-
identityId: 'test-id',
|
|
679
|
-
traits: {
|
|
680
|
-
emails: ['test@email.com'],
|
|
681
|
-
ipAddress: '10.0.0.1',
|
|
682
|
-
userAgent: 'Mozilla/5.0 (new)',
|
|
683
|
-
addresses: [
|
|
684
|
-
{ city: 'Chicago', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.IP_ADDRESS },
|
|
685
|
-
],
|
|
686
|
-
},
|
|
687
|
-
};
|
|
688
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
689
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
|
|
690
|
-
expect(result.isCacheStale).toBe(false);
|
|
691
|
-
expect(result.isIpAddressStale).toBe(true);
|
|
692
|
-
expect(result.isUserAgentStale).toBe(true);
|
|
693
|
-
expect(result.isIpAddressesStale).toBe(true);
|
|
694
|
-
});
|
|
695
|
-
});
|
|
696
|
-
describe('TIER 2: ADDRESS_UPDATE (cache write only, skip Neptune)', () => {
|
|
697
|
-
it('should return ADDRESS_UPDATE tier when non-IP address is new', () => {
|
|
698
|
-
const cachedIdentity = {
|
|
699
|
-
identityId: 'test-id',
|
|
700
|
-
traits: {
|
|
701
|
-
emails: ['test@email.com'],
|
|
702
|
-
addresses: [],
|
|
703
|
-
},
|
|
704
|
-
};
|
|
705
|
-
const incomingIdentity = {
|
|
706
|
-
identityId: 'test-id',
|
|
707
|
-
traits: {
|
|
708
|
-
emails: ['test@email.com'],
|
|
709
|
-
addresses: [
|
|
710
|
-
{ city: 'Boston', province: 'MA', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT },
|
|
711
|
-
],
|
|
712
|
-
},
|
|
713
|
-
};
|
|
714
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
715
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
|
|
716
|
-
expect(result.isCacheStale).toBe(true);
|
|
717
|
-
expect(result.isNonIpAddressesStale).toBe(true);
|
|
718
|
-
});
|
|
719
|
-
it('should return ADDRESS_UPDATE tier when new input address added', () => {
|
|
720
|
-
const cachedIdentity = {
|
|
721
|
-
identityId: 'test-id',
|
|
722
|
-
traits: {
|
|
723
|
-
emails: ['test@email.com'],
|
|
724
|
-
addresses: [
|
|
725
|
-
{ city: 'New York', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT },
|
|
726
|
-
],
|
|
727
|
-
},
|
|
728
|
-
};
|
|
729
|
-
const incomingIdentity = {
|
|
730
|
-
identityId: 'test-id',
|
|
731
|
-
traits: {
|
|
732
|
-
emails: ['test@email.com'],
|
|
733
|
-
addresses: [
|
|
734
|
-
{ city: 'New York', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT },
|
|
735
|
-
{ city: 'Boston', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT },
|
|
736
|
-
],
|
|
737
|
-
},
|
|
738
|
-
};
|
|
739
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
740
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
|
|
741
|
-
expect(result.isCacheStale).toBe(true);
|
|
742
|
-
expect(result.isNonIpAddressesStale).toBe(true);
|
|
743
|
-
});
|
|
744
|
-
it('should return ADDRESS_UPDATE tier even when volatile traits are also stale', () => {
|
|
745
|
-
const cachedIdentity = {
|
|
746
|
-
identityId: 'test-id',
|
|
747
|
-
traits: {
|
|
748
|
-
emails: ['test@email.com'],
|
|
749
|
-
ipAddress: '192.168.1.1',
|
|
750
|
-
addresses: [],
|
|
751
|
-
},
|
|
752
|
-
};
|
|
753
|
-
const incomingIdentity = {
|
|
754
|
-
identityId: 'test-id',
|
|
755
|
-
traits: {
|
|
756
|
-
emails: ['test@email.com'],
|
|
757
|
-
ipAddress: '10.0.0.1',
|
|
758
|
-
addresses: [
|
|
759
|
-
{ city: 'Boston', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT },
|
|
760
|
-
],
|
|
761
|
-
},
|
|
762
|
-
};
|
|
763
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
764
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
|
|
765
|
-
expect(result.isCacheStale).toBe(true);
|
|
766
|
-
expect(result.isIpAddressStale).toBe(true);
|
|
767
|
-
expect(result.isNonIpAddressesStale).toBe(true);
|
|
768
|
-
});
|
|
769
|
-
});
|
|
770
|
-
describe('TIER 3: IDENTITY_STALE (full Neptune resolution)', () => {
|
|
771
|
-
it('should return IDENTITY_STALE tier when email is new', () => {
|
|
772
|
-
const cachedIdentity = {
|
|
773
|
-
identityId: 'test-id',
|
|
774
|
-
traits: {
|
|
775
|
-
emails: ['old@email.com'],
|
|
776
|
-
},
|
|
777
|
-
};
|
|
778
|
-
const incomingIdentity = {
|
|
779
|
-
identityId: 'test-id',
|
|
780
|
-
traits: {
|
|
781
|
-
emails: ['old@email.com', 'new@email.com'],
|
|
782
|
-
},
|
|
783
|
-
};
|
|
784
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
785
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
786
|
-
expect(result.isCacheStale).toBe(true);
|
|
787
|
-
expect(result.isEmailsStale).toBe(true);
|
|
788
|
-
});
|
|
789
|
-
it('should return IDENTITY_STALE tier when identityId changes', () => {
|
|
790
|
-
const cachedIdentity = {
|
|
791
|
-
identityId: 'old-id',
|
|
792
|
-
traits: { emails: ['test@email.com'] },
|
|
793
|
-
};
|
|
794
|
-
const incomingIdentity = {
|
|
795
|
-
identityId: 'new-id',
|
|
796
|
-
traits: { emails: ['test@email.com'] },
|
|
797
|
-
};
|
|
798
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
799
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
800
|
-
expect(result.isCacheStale).toBe(true);
|
|
801
|
-
expect(result.isIdentityIdStale).toBe(true);
|
|
802
|
-
});
|
|
803
|
-
it('should return IDENTITY_STALE tier when phone is new', () => {
|
|
804
|
-
const cachedIdentity = {
|
|
805
|
-
identityId: 'test-id',
|
|
806
|
-
traits: { phones: ['+1234567890'] },
|
|
807
|
-
};
|
|
808
|
-
const incomingIdentity = {
|
|
809
|
-
identityId: 'test-id',
|
|
810
|
-
traits: { phones: ['+1234567890', '+9876543210'] },
|
|
811
|
-
};
|
|
812
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
813
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
814
|
-
expect(result.isCacheStale).toBe(true);
|
|
815
|
-
expect(result.isPhonesStale).toBe(true);
|
|
816
|
-
});
|
|
817
|
-
it('should return IDENTITY_STALE tier when click info changes', () => {
|
|
818
|
-
const cachedIdentity = {
|
|
819
|
-
identityId: 'test-id',
|
|
820
|
-
traits: {
|
|
821
|
-
click: { gclid: 'old_gclid' },
|
|
822
|
-
},
|
|
823
|
-
};
|
|
824
|
-
const incomingIdentity = {
|
|
825
|
-
identityId: 'test-id',
|
|
826
|
-
traits: {
|
|
827
|
-
click: { gclid: 'new_gclid' },
|
|
828
|
-
},
|
|
829
|
-
};
|
|
830
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
831
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
832
|
-
expect(result.isCacheStale).toBe(true);
|
|
833
|
-
expect(result.isClickInfosStale).toBe(true);
|
|
834
|
-
});
|
|
835
|
-
it('should return IDENTITY_STALE tier when identity trait is stale even with ADDRESS_UPDATE', () => {
|
|
836
|
-
const cachedIdentity = {
|
|
837
|
-
identityId: 'test-id',
|
|
838
|
-
traits: {
|
|
839
|
-
emails: ['old@email.com'],
|
|
840
|
-
addresses: [],
|
|
841
|
-
},
|
|
842
|
-
};
|
|
843
|
-
const incomingIdentity = {
|
|
844
|
-
identityId: 'test-id',
|
|
845
|
-
traits: {
|
|
846
|
-
emails: ['old@email.com', 'new@email.com'],
|
|
847
|
-
addresses: [
|
|
848
|
-
{ city: 'Boston', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT },
|
|
849
|
-
],
|
|
850
|
-
},
|
|
851
|
-
};
|
|
852
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
853
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
854
|
-
expect(result.isCacheStale).toBe(true);
|
|
855
|
-
expect(result.isEmailsStale).toBe(true);
|
|
856
|
-
expect(result.isNonIpAddressesStale).toBe(true);
|
|
857
|
-
});
|
|
858
|
-
it('should return IDENTITY_STALE tier when identity trait is stale even with VOLATILE_ONLY', () => {
|
|
859
|
-
const cachedIdentity = {
|
|
860
|
-
identityId: 'test-id',
|
|
861
|
-
traits: {
|
|
862
|
-
emails: ['old@email.com'],
|
|
863
|
-
ipAddress: '192.168.1.1',
|
|
864
|
-
},
|
|
865
|
-
};
|
|
866
|
-
const incomingIdentity = {
|
|
867
|
-
identityId: 'test-id',
|
|
868
|
-
traits: {
|
|
869
|
-
emails: ['old@email.com', 'new@email.com'],
|
|
870
|
-
ipAddress: '10.0.0.1',
|
|
871
|
-
},
|
|
872
|
-
};
|
|
873
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
874
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
875
|
-
expect(result.isCacheStale).toBe(true);
|
|
876
|
-
expect(result.isEmailsStale).toBe(true);
|
|
877
|
-
expect(result.isIpAddressStale).toBe(true);
|
|
878
|
-
});
|
|
879
|
-
});
|
|
880
|
-
describe('TIER NONE: No staleness', () => {
|
|
881
|
-
it('should return NONE tier when nothing is stale', () => {
|
|
882
|
-
const cachedIdentity = {
|
|
883
|
-
identityId: 'test-id',
|
|
884
|
-
traits: {
|
|
885
|
-
emails: ['test@email.com'],
|
|
886
|
-
phones: ['+1234567890'],
|
|
887
|
-
ipAddress: '192.168.1.1',
|
|
888
|
-
},
|
|
889
|
-
};
|
|
890
|
-
const incomingIdentity = {
|
|
891
|
-
identityId: 'test-id',
|
|
892
|
-
traits: {
|
|
893
|
-
emails: ['test@email.com'],
|
|
894
|
-
phones: ['+1234567890'],
|
|
895
|
-
ipAddress: '192.168.1.1',
|
|
896
|
-
},
|
|
897
|
-
};
|
|
898
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
899
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.NONE);
|
|
900
|
-
expect(result.isCacheStale).toBe(false);
|
|
901
|
-
});
|
|
902
|
-
it('should return NONE tier when incoming is subset of cached', () => {
|
|
903
|
-
const cachedIdentity = {
|
|
904
|
-
identityId: 'test-id',
|
|
905
|
-
traits: {
|
|
906
|
-
emails: ['a@email.com', 'b@email.com'],
|
|
907
|
-
phones: ['+1234567890', '+9876543210'],
|
|
908
|
-
},
|
|
909
|
-
};
|
|
910
|
-
const incomingIdentity = {
|
|
911
|
-
identityId: 'test-id',
|
|
912
|
-
traits: {
|
|
913
|
-
emails: ['a@email.com'],
|
|
914
|
-
},
|
|
915
|
-
};
|
|
916
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
917
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.NONE);
|
|
918
|
-
expect(result.isCacheStale).toBe(false);
|
|
919
|
-
});
|
|
920
|
-
});
|
|
921
|
-
describe('Address source filtering', () => {
|
|
922
|
-
it('should correctly identify IP-sourced addresses', () => {
|
|
923
|
-
const cachedIdentity = {
|
|
924
|
-
identityId: 'test-id',
|
|
925
|
-
traits: {
|
|
926
|
-
addresses: [
|
|
927
|
-
{ city: 'CachedCity', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.IP_ADDRESS },
|
|
928
|
-
],
|
|
929
|
-
},
|
|
930
|
-
};
|
|
931
|
-
const incomingIdentity = {
|
|
932
|
-
identityId: 'test-id',
|
|
933
|
-
traits: {
|
|
934
|
-
addresses: [
|
|
935
|
-
{ city: 'NewCity', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.IP_ADDRESS },
|
|
936
|
-
],
|
|
937
|
-
},
|
|
938
|
-
};
|
|
939
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
940
|
-
expect(result.isIpAddressesStale).toBe(true);
|
|
941
|
-
expect(result.isNonIpAddressesStale).toBe(false);
|
|
942
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
|
|
943
|
-
});
|
|
944
|
-
it('should correctly identify INPUT-sourced addresses', () => {
|
|
945
|
-
const cachedIdentity = {
|
|
946
|
-
identityId: 'test-id',
|
|
947
|
-
traits: {
|
|
948
|
-
addresses: [
|
|
949
|
-
{ city: 'CachedCity', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT },
|
|
950
|
-
],
|
|
951
|
-
},
|
|
952
|
-
};
|
|
953
|
-
const incomingIdentity = {
|
|
954
|
-
identityId: 'test-id',
|
|
955
|
-
traits: {
|
|
956
|
-
addresses: [
|
|
957
|
-
{ city: 'CachedCity', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT },
|
|
958
|
-
{ city: 'NewCity', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT },
|
|
959
|
-
],
|
|
960
|
-
},
|
|
961
|
-
};
|
|
962
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
963
|
-
expect(result.isIpAddressesStale).toBe(false);
|
|
964
|
-
expect(result.isNonIpAddressesStale).toBe(true);
|
|
965
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
|
|
966
|
-
});
|
|
967
|
-
it('should handle mixed address sources correctly', () => {
|
|
968
|
-
const cachedIdentity = {
|
|
969
|
-
identityId: 'test-id',
|
|
970
|
-
traits: {
|
|
971
|
-
addresses: [
|
|
972
|
-
{ city: 'IPCity', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.IP_ADDRESS },
|
|
973
|
-
{ city: 'InputCity', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT },
|
|
974
|
-
],
|
|
975
|
-
},
|
|
976
|
-
};
|
|
977
|
-
const incomingIdentity = {
|
|
978
|
-
identityId: 'test-id',
|
|
979
|
-
traits: {
|
|
980
|
-
addresses: [
|
|
981
|
-
{ city: 'NewIPCity', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.IP_ADDRESS },
|
|
982
|
-
{ city: 'InputCity', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT },
|
|
983
|
-
{ city: 'NewInputCity', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT },
|
|
984
|
-
],
|
|
985
|
-
},
|
|
986
|
-
};
|
|
987
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
988
|
-
expect(result.isIpAddressesStale).toBe(true);
|
|
989
|
-
expect(result.isNonIpAddressesStale).toBe(true);
|
|
990
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
|
|
991
|
-
expect(result.isCacheStale).toBe(true);
|
|
992
|
-
});
|
|
993
|
-
it('should handle addresses without source field (default to IP based on PII)', () => {
|
|
994
|
-
const cachedIdentity = {
|
|
995
|
-
identityId: 'test-id',
|
|
996
|
-
traits: {
|
|
997
|
-
addresses: [],
|
|
998
|
-
},
|
|
999
|
-
};
|
|
1000
|
-
const incomingIdentity = {
|
|
1001
|
-
identityId: 'test-id',
|
|
1002
|
-
traits: {
|
|
1003
|
-
addresses: [
|
|
1004
|
-
{ city: 'NoSourceCity' },
|
|
1005
|
-
],
|
|
1006
|
-
},
|
|
1007
|
-
};
|
|
1008
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
1009
|
-
expect(result.isIpAddressesStale).toBe(true);
|
|
1010
|
-
expect(result.isNonIpAddressesStale).toBe(false);
|
|
1011
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
|
|
1012
|
-
expect(result.isCacheStale).toBe(false);
|
|
1013
|
-
});
|
|
1014
|
-
it('should treat addresses without source but with PII as non-IP', () => {
|
|
1015
|
-
const cachedIdentity = {
|
|
1016
|
-
identityId: 'test-id',
|
|
1017
|
-
traits: {
|
|
1018
|
-
addresses: [],
|
|
1019
|
-
},
|
|
1020
|
-
};
|
|
1021
|
-
const incomingIdentity = {
|
|
1022
|
-
identityId: 'test-id',
|
|
1023
|
-
traits: {
|
|
1024
|
-
addresses: [
|
|
1025
|
-
{ city: 'InputCity', firstName: 'John' },
|
|
1026
|
-
],
|
|
1027
|
-
},
|
|
1028
|
-
};
|
|
1029
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
1030
|
-
expect(result.isNonIpAddressesStale).toBe(true);
|
|
1031
|
-
expect(result.isIpAddressesStale).toBe(false);
|
|
1032
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
|
|
1033
|
-
expect(result.isCacheStale).toBe(true);
|
|
1034
|
-
});
|
|
1035
|
-
});
|
|
1036
|
-
describe('Backward compatibility', () => {
|
|
1037
|
-
it('should maintain isAddressesStale for any address change', () => {
|
|
1038
|
-
const cachedIdentity = {
|
|
1039
|
-
identityId: 'test-id',
|
|
1040
|
-
traits: {
|
|
1041
|
-
addresses: [
|
|
1042
|
-
{ city: 'OldCity', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.IP_ADDRESS },
|
|
1043
|
-
],
|
|
1044
|
-
},
|
|
1045
|
-
};
|
|
1046
|
-
const incomingIdentity = {
|
|
1047
|
-
identityId: 'test-id',
|
|
1048
|
-
traits: {
|
|
1049
|
-
addresses: [
|
|
1050
|
-
{ city: 'NewCity', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.IP_ADDRESS },
|
|
1051
|
-
],
|
|
1052
|
-
},
|
|
1053
|
-
};
|
|
1054
|
-
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
1055
|
-
expect(result.isAddressesStale).toBe(true);
|
|
1056
|
-
expect(result.isCacheStale).toBe(false);
|
|
1057
|
-
});
|
|
1058
|
-
});
|
|
1059
|
-
});
|
|
1060
|
-
describe('extractStaleTraitNames function', () => {
|
|
1061
|
-
it('should return empty array when nothing is stale', () => {
|
|
1062
|
-
const cachedIdentity = {
|
|
1063
|
-
identityId: 'test-id',
|
|
1064
|
-
traits: { emails: ['test@email.com'] },
|
|
1065
|
-
};
|
|
1066
|
-
const incomingIdentity = {
|
|
1067
|
-
identityId: 'test-id',
|
|
1068
|
-
traits: { emails: ['test@email.com'] },
|
|
1069
|
-
};
|
|
1070
|
-
const tracker = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
1071
|
-
const staleTraits = (0, at_shared_utils_1.extractStaleTraitNames)(tracker);
|
|
1072
|
-
expect(staleTraits).toEqual([]);
|
|
1073
|
-
});
|
|
1074
|
-
it('should return identity-defining trait names when stale', () => {
|
|
1075
|
-
const cachedIdentity = {
|
|
1076
|
-
identityId: 'test-id',
|
|
1077
|
-
traits: { emails: ['old@email.com'] },
|
|
1078
|
-
};
|
|
1079
|
-
const incomingIdentity = {
|
|
1080
|
-
identityId: 'test-id',
|
|
1081
|
-
traits: { emails: ['old@email.com', 'new@email.com'] },
|
|
1082
|
-
};
|
|
1083
|
-
const tracker = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
1084
|
-
const staleTraits = (0, at_shared_utils_1.extractStaleTraitNames)(tracker);
|
|
1085
|
-
expect(staleTraits).toContain('emails');
|
|
1086
|
-
});
|
|
1087
|
-
it('should return multiple stale trait names', () => {
|
|
1088
|
-
const cachedIdentity = {
|
|
1089
|
-
identityId: 'test-id',
|
|
1090
|
-
traits: {
|
|
1091
|
-
emails: ['old@email.com'],
|
|
1092
|
-
phones: ['+1234567890'],
|
|
1093
|
-
},
|
|
1094
|
-
};
|
|
1095
|
-
const incomingIdentity = {
|
|
1096
|
-
identityId: 'test-id',
|
|
1097
|
-
traits: {
|
|
1098
|
-
emails: ['old@email.com', 'new@email.com'],
|
|
1099
|
-
phones: ['+1234567890', '+9876543210'],
|
|
1100
|
-
},
|
|
1101
|
-
};
|
|
1102
|
-
const tracker = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
1103
|
-
const staleTraits = (0, at_shared_utils_1.extractStaleTraitNames)(tracker);
|
|
1104
|
-
expect(staleTraits).toContain('emails');
|
|
1105
|
-
expect(staleTraits).toContain('phones');
|
|
1106
|
-
});
|
|
1107
|
-
it('should return volatile trait names when stale', () => {
|
|
1108
|
-
const cachedIdentity = {
|
|
1109
|
-
identityId: 'test-id',
|
|
1110
|
-
traits: {
|
|
1111
|
-
ipAddress: '192.168.1.1',
|
|
1112
|
-
userAgent: 'old-agent',
|
|
1113
|
-
},
|
|
1114
|
-
};
|
|
1115
|
-
const incomingIdentity = {
|
|
1116
|
-
identityId: 'test-id',
|
|
1117
|
-
traits: {
|
|
1118
|
-
ipAddress: '10.0.0.1',
|
|
1119
|
-
userAgent: 'new-agent',
|
|
1120
|
-
},
|
|
1121
|
-
};
|
|
1122
|
-
const tracker = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
1123
|
-
const staleTraits = (0, at_shared_utils_1.extractStaleTraitNames)(tracker);
|
|
1124
|
-
expect(staleTraits).toContain('ipAddress');
|
|
1125
|
-
expect(staleTraits).toContain('userAgent');
|
|
1126
|
-
});
|
|
1127
|
-
});
|
|
1128
|
-
describe('mergeAndComputeIdentityStaleness function', () => {
|
|
1129
|
-
describe('NONE tier - cache is fresh', () => {
|
|
1130
|
-
it('should return NONE tier when incoming is subset of cached', () => {
|
|
1131
|
-
const incomingIdentity = {
|
|
1132
|
-
identityId: 'test-id',
|
|
1133
|
-
traits: { emails: ['shared@email.com'] },
|
|
1134
|
-
};
|
|
1135
|
-
const cachedIdentity = {
|
|
1136
|
-
identityId: 'test-id',
|
|
1137
|
-
traits: {
|
|
1138
|
-
emails: ['shared@email.com', 'other@email.com'],
|
|
1139
|
-
phones: ['+1234567890'],
|
|
1140
|
-
},
|
|
1141
|
-
};
|
|
1142
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1143
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.NONE);
|
|
1144
|
-
expect(result.isCacheStale).toBe(false);
|
|
1145
|
-
expect(result.staleTraits).toEqual([]);
|
|
1146
|
-
expect(result.mergedIdentity.traits?.emails).toEqual(['shared@email.com', 'other@email.com']);
|
|
1147
|
-
expect(result.mergedIdentity.traits?.phones).toEqual(['+1234567890']);
|
|
1148
|
-
});
|
|
1149
|
-
it('should return NONE tier when identities are identical', () => {
|
|
1150
|
-
const incomingIdentity = {
|
|
1151
|
-
identityId: 'test-id',
|
|
1152
|
-
traits: {
|
|
1153
|
-
emails: ['test@email.com'],
|
|
1154
|
-
phones: ['+1234567890'],
|
|
1155
|
-
},
|
|
1156
|
-
};
|
|
1157
|
-
const cachedIdentity = {
|
|
1158
|
-
identityId: 'test-id',
|
|
1159
|
-
traits: {
|
|
1160
|
-
emails: ['test@email.com'],
|
|
1161
|
-
phones: ['+1234567890'],
|
|
1162
|
-
},
|
|
1163
|
-
};
|
|
1164
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1165
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.NONE);
|
|
1166
|
-
expect(result.isCacheStale).toBe(false);
|
|
1167
|
-
expect(result.staleTraits).toEqual([]);
|
|
1168
|
-
});
|
|
1169
|
-
it('should return NONE tier with identical click info', () => {
|
|
1170
|
-
const incomingIdentity = {
|
|
1171
|
-
identityId: 'test-id',
|
|
1172
|
-
traits: {
|
|
1173
|
-
emails: ['test@email.com'],
|
|
1174
|
-
click: { gclid: 'same_gclid', fbp: 'fb.1.123.456' },
|
|
1175
|
-
},
|
|
1176
|
-
};
|
|
1177
|
-
const cachedIdentity = {
|
|
1178
|
-
identityId: 'test-id',
|
|
1179
|
-
traits: {
|
|
1180
|
-
emails: ['test@email.com'],
|
|
1181
|
-
click: { gclid: 'same_gclid', fbp: 'fb.1.123.456' },
|
|
1182
|
-
},
|
|
1183
|
-
};
|
|
1184
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1185
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.NONE);
|
|
1186
|
-
expect(result.isCacheStale).toBe(false);
|
|
1187
|
-
});
|
|
1188
|
-
});
|
|
1189
|
-
describe('VOLATILE_ONLY tier - treat as cache hit', () => {
|
|
1190
|
-
it('should return VOLATILE_ONLY tier when only ipAddress is new', () => {
|
|
1191
|
-
const incomingIdentity = {
|
|
1192
|
-
identityId: 'test-id',
|
|
1193
|
-
traits: {
|
|
1194
|
-
emails: ['test@email.com'],
|
|
1195
|
-
ipAddress: '10.0.0.1',
|
|
1196
|
-
},
|
|
1197
|
-
};
|
|
1198
|
-
const cachedIdentity = {
|
|
1199
|
-
identityId: 'test-id',
|
|
1200
|
-
traits: {
|
|
1201
|
-
emails: ['test@email.com'],
|
|
1202
|
-
},
|
|
1203
|
-
};
|
|
1204
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1205
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
|
|
1206
|
-
expect(result.isCacheStale).toBe(false);
|
|
1207
|
-
expect(result.staleTraits).toContain('ipAddress');
|
|
1208
|
-
});
|
|
1209
|
-
it('should return VOLATILE_ONLY tier when only userAgent is new', () => {
|
|
1210
|
-
const incomingIdentity = {
|
|
1211
|
-
identityId: 'test-id',
|
|
1212
|
-
traits: {
|
|
1213
|
-
emails: ['test@email.com'],
|
|
1214
|
-
userAgent: 'new-agent',
|
|
1215
|
-
},
|
|
1216
|
-
};
|
|
1217
|
-
const cachedIdentity = {
|
|
1218
|
-
identityId: 'test-id',
|
|
1219
|
-
traits: {
|
|
1220
|
-
emails: ['test@email.com'],
|
|
1221
|
-
},
|
|
1222
|
-
};
|
|
1223
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1224
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
|
|
1225
|
-
expect(result.isCacheStale).toBe(false);
|
|
1226
|
-
expect(result.staleTraits).toContain('userAgent');
|
|
1227
|
-
});
|
|
1228
|
-
it('should return VOLATILE_ONLY tier when only IP-sourced address is new', () => {
|
|
1229
|
-
const incomingIdentity = {
|
|
1230
|
-
identityId: 'test-id',
|
|
1231
|
-
traits: {
|
|
1232
|
-
emails: ['test@email.com'],
|
|
1233
|
-
addresses: [{ city: 'NewIPCity', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.IP_ADDRESS }],
|
|
1234
|
-
},
|
|
1235
|
-
};
|
|
1236
|
-
const cachedIdentity = {
|
|
1237
|
-
identityId: 'test-id',
|
|
1238
|
-
traits: {
|
|
1239
|
-
emails: ['test@email.com'],
|
|
1240
|
-
addresses: [],
|
|
1241
|
-
},
|
|
1242
|
-
};
|
|
1243
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1244
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
|
|
1245
|
-
expect(result.isCacheStale).toBe(false);
|
|
1246
|
-
});
|
|
1247
|
-
});
|
|
1248
|
-
describe('ADDRESS_UPDATE tier - cache write only, skip Neptune', () => {
|
|
1249
|
-
it('should return ADDRESS_UPDATE tier when non-IP address is new', () => {
|
|
1250
|
-
const incomingIdentity = {
|
|
1251
|
-
identityId: 'test-id',
|
|
1252
|
-
traits: {
|
|
1253
|
-
emails: ['test@email.com'],
|
|
1254
|
-
addresses: [{ city: 'Boston', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT }],
|
|
1255
|
-
},
|
|
1256
|
-
};
|
|
1257
|
-
const cachedIdentity = {
|
|
1258
|
-
identityId: 'test-id',
|
|
1259
|
-
traits: {
|
|
1260
|
-
emails: ['test@email.com'],
|
|
1261
|
-
addresses: [],
|
|
1262
|
-
},
|
|
1263
|
-
};
|
|
1264
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1265
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
|
|
1266
|
-
expect(result.isCacheStale).toBe(true);
|
|
1267
|
-
expect(result.staleTraits).toContain('addresses');
|
|
1268
|
-
});
|
|
1269
|
-
it('should return ADDRESS_UPDATE even with volatile traits stale', () => {
|
|
1270
|
-
const incomingIdentity = {
|
|
1271
|
-
identityId: 'test-id',
|
|
1272
|
-
traits: {
|
|
1273
|
-
emails: ['test@email.com'],
|
|
1274
|
-
ipAddress: '10.0.0.1',
|
|
1275
|
-
addresses: [{ city: 'Boston', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT }],
|
|
1276
|
-
},
|
|
1277
|
-
};
|
|
1278
|
-
const cachedIdentity = {
|
|
1279
|
-
identityId: 'test-id',
|
|
1280
|
-
traits: {
|
|
1281
|
-
emails: ['test@email.com'],
|
|
1282
|
-
ipAddress: '192.168.1.1',
|
|
1283
|
-
addresses: [],
|
|
1284
|
-
},
|
|
1285
|
-
};
|
|
1286
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1287
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
|
|
1288
|
-
expect(result.isCacheStale).toBe(true);
|
|
1289
|
-
});
|
|
1290
|
-
});
|
|
1291
|
-
describe('IDENTITY_STALE tier - full Neptune resolution', () => {
|
|
1292
|
-
it('should return IDENTITY_STALE tier when email is new', () => {
|
|
1293
|
-
const incomingIdentity = {
|
|
1294
|
-
identityId: 'test-id',
|
|
1295
|
-
traits: { emails: ['old@email.com', 'new@email.com'] },
|
|
1296
|
-
};
|
|
1297
|
-
const cachedIdentity = {
|
|
1298
|
-
identityId: 'test-id',
|
|
1299
|
-
traits: { emails: ['old@email.com'] },
|
|
1300
|
-
};
|
|
1301
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1302
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
1303
|
-
expect(result.isCacheStale).toBe(true);
|
|
1304
|
-
expect(result.staleTraits).toContain('emails');
|
|
1305
|
-
});
|
|
1306
|
-
it('should return IDENTITY_STALE tier when phone is new', () => {
|
|
1307
|
-
const incomingIdentity = {
|
|
1308
|
-
identityId: 'test-id',
|
|
1309
|
-
traits: { phones: ['+1234567890', '+9876543210'] },
|
|
1310
|
-
};
|
|
1311
|
-
const cachedIdentity = {
|
|
1312
|
-
identityId: 'test-id',
|
|
1313
|
-
traits: { phones: ['+1234567890'] },
|
|
1314
|
-
};
|
|
1315
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1316
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
1317
|
-
expect(result.isCacheStale).toBe(true);
|
|
1318
|
-
expect(result.staleTraits).toContain('phones');
|
|
1319
|
-
});
|
|
1320
|
-
it('should return IDENTITY_STALE tier when identityId changes', () => {
|
|
1321
|
-
const incomingIdentity = {
|
|
1322
|
-
identityId: 'new-id',
|
|
1323
|
-
traits: { emails: ['test@email.com'] },
|
|
1324
|
-
};
|
|
1325
|
-
const cachedIdentity = {
|
|
1326
|
-
identityId: 'old-id',
|
|
1327
|
-
traits: { emails: ['test@email.com'] },
|
|
1328
|
-
};
|
|
1329
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1330
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
1331
|
-
expect(result.isCacheStale).toBe(true);
|
|
1332
|
-
expect(result.staleTraits).toContain('identityId');
|
|
1333
|
-
});
|
|
1334
|
-
it('should return IDENTITY_STALE tier when click info is new', () => {
|
|
1335
|
-
const incomingIdentity = {
|
|
1336
|
-
identityId: 'test-id',
|
|
1337
|
-
traits: { click: { gclid: 'new_gclid' } },
|
|
1338
|
-
};
|
|
1339
|
-
const cachedIdentity = {
|
|
1340
|
-
identityId: 'test-id',
|
|
1341
|
-
traits: {},
|
|
1342
|
-
};
|
|
1343
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1344
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
1345
|
-
expect(result.isCacheStale).toBe(true);
|
|
1346
|
-
expect(result.staleTraits).toContain('clickInfos');
|
|
1347
|
-
});
|
|
1348
|
-
it('should return IDENTITY_STALE even with ADDRESS_UPDATE also present', () => {
|
|
1349
|
-
const incomingIdentity = {
|
|
1350
|
-
identityId: 'test-id',
|
|
1351
|
-
traits: {
|
|
1352
|
-
emails: ['old@email.com', 'new@email.com'],
|
|
1353
|
-
addresses: [{ city: 'Boston', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT }],
|
|
1354
|
-
},
|
|
1355
|
-
};
|
|
1356
|
-
const cachedIdentity = {
|
|
1357
|
-
identityId: 'test-id',
|
|
1358
|
-
traits: {
|
|
1359
|
-
emails: ['old@email.com'],
|
|
1360
|
-
addresses: [],
|
|
1361
|
-
},
|
|
1362
|
-
};
|
|
1363
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1364
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
1365
|
-
expect(result.isCacheStale).toBe(true);
|
|
1366
|
-
expect(result.staleTraits).toContain('emails');
|
|
1367
|
-
expect(result.staleTraits).toContain('addresses');
|
|
1368
|
-
});
|
|
1369
|
-
});
|
|
1370
|
-
describe('Merged identity structure', () => {
|
|
1371
|
-
it('should preserve incoming identityId in merged identity', () => {
|
|
1372
|
-
const incomingIdentity = {
|
|
1373
|
-
identityId: 'incoming-id',
|
|
1374
|
-
traits: { emails: ['test@email.com'] },
|
|
1375
|
-
};
|
|
1376
|
-
const cachedIdentity = {
|
|
1377
|
-
identityId: 'cached-id',
|
|
1378
|
-
traits: { phones: ['+1234567890'] },
|
|
1379
|
-
};
|
|
1380
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1381
|
-
expect(result.mergedIdentity.identityId).toBe('incoming-id');
|
|
1382
|
-
});
|
|
1383
|
-
it('should merge traits from both incoming and cached', () => {
|
|
1384
|
-
const incomingIdentity = {
|
|
1385
|
-
identityId: 'test-id',
|
|
1386
|
-
traits: {
|
|
1387
|
-
emails: ['incoming@email.com'],
|
|
1388
|
-
userIds: ['user1'],
|
|
1389
|
-
},
|
|
1390
|
-
};
|
|
1391
|
-
const cachedIdentity = {
|
|
1392
|
-
identityId: 'test-id',
|
|
1393
|
-
traits: {
|
|
1394
|
-
emails: ['cached@email.com'],
|
|
1395
|
-
phones: ['+1234567890'],
|
|
1396
|
-
},
|
|
1397
|
-
};
|
|
1398
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1399
|
-
expect(result.mergedIdentity.traits?.emails).toContain('incoming@email.com');
|
|
1400
|
-
expect(result.mergedIdentity.traits?.emails).toContain('cached@email.com');
|
|
1401
|
-
expect(result.mergedIdentity.traits?.userIds).toEqual(['user1']);
|
|
1402
|
-
expect(result.mergedIdentity.traits?.phones).toEqual(['+1234567890']);
|
|
1403
|
-
});
|
|
1404
|
-
});
|
|
1405
|
-
describe('staleTracker output', () => {
|
|
1406
|
-
it('should include full staleTracker with all flags', () => {
|
|
1407
|
-
const incomingIdentity = {
|
|
1408
|
-
identityId: 'test-id',
|
|
1409
|
-
traits: {
|
|
1410
|
-
emails: ['old@email.com', 'new@email.com'],
|
|
1411
|
-
ipAddress: '10.0.0.1',
|
|
1412
|
-
},
|
|
1413
|
-
};
|
|
1414
|
-
const cachedIdentity = {
|
|
1415
|
-
identityId: 'test-id',
|
|
1416
|
-
traits: {
|
|
1417
|
-
emails: ['old@email.com'],
|
|
1418
|
-
},
|
|
1419
|
-
};
|
|
1420
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1421
|
-
expect(result.staleTracker).toBeDefined();
|
|
1422
|
-
expect(result.staleTracker.isEmailsStale).toBe(true);
|
|
1423
|
-
expect(result.staleTracker.isIpAddressStale).toBe(true);
|
|
1424
|
-
expect(result.staleTracker.isPhonesStale).toBe(false);
|
|
1425
|
-
});
|
|
1426
|
-
});
|
|
1427
|
-
describe('Edge cases - empty traits', () => {
|
|
1428
|
-
it('should handle empty traits on incoming identity', () => {
|
|
1429
|
-
const incomingIdentity = {
|
|
1430
|
-
identityId: 'test-id',
|
|
1431
|
-
traits: {},
|
|
1432
|
-
};
|
|
1433
|
-
const cachedIdentity = {
|
|
1434
|
-
identityId: 'test-id',
|
|
1435
|
-
traits: {
|
|
1436
|
-
emails: ['cached@email.com'],
|
|
1437
|
-
phones: ['+1234567890'],
|
|
1438
|
-
userIds: ['user1'],
|
|
1439
|
-
},
|
|
1440
|
-
};
|
|
1441
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1442
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.NONE);
|
|
1443
|
-
expect(result.isCacheStale).toBe(false);
|
|
1444
|
-
expect(result.staleTraits).toEqual([]);
|
|
1445
|
-
expect(result.mergedIdentity.traits?.emails).toEqual(['cached@email.com']);
|
|
1446
|
-
expect(result.mergedIdentity.traits?.phones).toEqual(['+1234567890']);
|
|
1447
|
-
expect(result.mergedIdentity.traits?.userIds).toEqual(['user1']);
|
|
1448
|
-
});
|
|
1449
|
-
it('should handle empty traits on cached identity', () => {
|
|
1450
|
-
const incomingIdentity = {
|
|
1451
|
-
identityId: 'test-id',
|
|
1452
|
-
traits: {
|
|
1453
|
-
emails: ['new@email.com'],
|
|
1454
|
-
phones: ['+1234567890'],
|
|
1455
|
-
},
|
|
1456
|
-
};
|
|
1457
|
-
const cachedIdentity = {
|
|
1458
|
-
identityId: 'test-id',
|
|
1459
|
-
traits: {},
|
|
1460
|
-
};
|
|
1461
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1462
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
1463
|
-
expect(result.isCacheStale).toBe(true);
|
|
1464
|
-
expect(result.staleTraits).toContain('emails');
|
|
1465
|
-
expect(result.staleTraits).toContain('phones');
|
|
1466
|
-
expect(result.mergedIdentity.traits?.emails).toEqual(['new@email.com']);
|
|
1467
|
-
expect(result.mergedIdentity.traits?.phones).toEqual(['+1234567890']);
|
|
1468
|
-
});
|
|
1469
|
-
it('should handle both identities with empty traits', () => {
|
|
1470
|
-
const incomingIdentity = {
|
|
1471
|
-
identityId: 'test-id',
|
|
1472
|
-
traits: {},
|
|
1473
|
-
};
|
|
1474
|
-
const cachedIdentity = {
|
|
1475
|
-
identityId: 'test-id',
|
|
1476
|
-
traits: {},
|
|
1477
|
-
};
|
|
1478
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1479
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.NONE);
|
|
1480
|
-
expect(result.isCacheStale).toBe(false);
|
|
1481
|
-
expect(result.staleTraits).toEqual([]);
|
|
1482
|
-
});
|
|
1483
|
-
});
|
|
1484
|
-
describe('Edge cases - null/undefined handling', () => {
|
|
1485
|
-
it('should handle undefined traits on incoming identity', () => {
|
|
1486
|
-
const incomingIdentity = {
|
|
1487
|
-
identityId: 'test-id',
|
|
1488
|
-
};
|
|
1489
|
-
const cachedIdentity = {
|
|
1490
|
-
identityId: 'test-id',
|
|
1491
|
-
traits: {
|
|
1492
|
-
emails: ['cached@email.com'],
|
|
1493
|
-
},
|
|
1494
|
-
};
|
|
1495
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1496
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.NONE);
|
|
1497
|
-
expect(result.isCacheStale).toBe(false);
|
|
1498
|
-
});
|
|
1499
|
-
it('should handle undefined traits on cached identity', () => {
|
|
1500
|
-
const incomingIdentity = {
|
|
1501
|
-
identityId: 'test-id',
|
|
1502
|
-
traits: {
|
|
1503
|
-
emails: ['new@email.com'],
|
|
1504
|
-
},
|
|
1505
|
-
};
|
|
1506
|
-
const cachedIdentity = {
|
|
1507
|
-
identityId: 'test-id',
|
|
1508
|
-
};
|
|
1509
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1510
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
1511
|
-
expect(result.isCacheStale).toBe(true);
|
|
1512
|
-
expect(result.staleTraits).toContain('emails');
|
|
1513
|
-
});
|
|
1514
|
-
it('should handle both identities with undefined traits', () => {
|
|
1515
|
-
const incomingIdentity = {
|
|
1516
|
-
identityId: 'test-id',
|
|
1517
|
-
};
|
|
1518
|
-
const cachedIdentity = {
|
|
1519
|
-
identityId: 'test-id',
|
|
1520
|
-
};
|
|
1521
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1522
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.NONE);
|
|
1523
|
-
expect(result.isCacheStale).toBe(false);
|
|
1524
|
-
expect(result.staleTraits).toEqual([]);
|
|
1525
|
-
});
|
|
1526
|
-
it('should handle null values in array traits gracefully', () => {
|
|
1527
|
-
const incomingIdentity = {
|
|
1528
|
-
identityId: 'test-id',
|
|
1529
|
-
traits: {
|
|
1530
|
-
emails: ['valid@email.com', null, 'new@email.com'],
|
|
1531
|
-
},
|
|
1532
|
-
};
|
|
1533
|
-
const cachedIdentity = {
|
|
1534
|
-
identityId: 'test-id',
|
|
1535
|
-
traits: {
|
|
1536
|
-
emails: ['valid@email.com'],
|
|
1537
|
-
},
|
|
1538
|
-
};
|
|
1539
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1540
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
1541
|
-
expect(result.isCacheStale).toBe(true);
|
|
1542
|
-
});
|
|
1543
|
-
});
|
|
1544
|
-
describe('Edge cases - click trait merging', () => {
|
|
1545
|
-
it('should detect staleness when incoming has new click info', () => {
|
|
1546
|
-
const incomingIdentity = {
|
|
1547
|
-
identityId: 'test-id',
|
|
1548
|
-
traits: {
|
|
1549
|
-
click: {
|
|
1550
|
-
gclid: 'new_gclid',
|
|
1551
|
-
fbp: 'fb.1.new.123',
|
|
1552
|
-
},
|
|
1553
|
-
},
|
|
1554
|
-
};
|
|
1555
|
-
const cachedIdentity = {
|
|
1556
|
-
identityId: 'test-id',
|
|
1557
|
-
traits: {},
|
|
1558
|
-
};
|
|
1559
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1560
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
1561
|
-
expect(result.isCacheStale).toBe(true);
|
|
1562
|
-
expect(result.staleTraits).toContain('clickInfos');
|
|
1563
|
-
});
|
|
1564
|
-
it('should preserve cached click info when merging', () => {
|
|
1565
|
-
const incomingIdentity = {
|
|
1566
|
-
identityId: 'test-id',
|
|
1567
|
-
traits: {
|
|
1568
|
-
click: {
|
|
1569
|
-
gclid: 'incoming_gclid',
|
|
1570
|
-
},
|
|
1571
|
-
},
|
|
1572
|
-
};
|
|
1573
|
-
const cachedIdentity = {
|
|
1574
|
-
identityId: 'test-id',
|
|
1575
|
-
traits: {
|
|
1576
|
-
click: {
|
|
1577
|
-
gclid: 'cached_gclid',
|
|
1578
|
-
fbp: 'fb.1.cached.456',
|
|
1579
|
-
},
|
|
1580
|
-
},
|
|
1581
|
-
};
|
|
1582
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1583
|
-
expect(result.mergedIdentity.traits?.click?.gclid).toBe('cached_gclid');
|
|
1584
|
-
expect(result.mergedIdentity.traits?.click?.fbp).toBe('fb.1.cached.456');
|
|
1585
|
-
});
|
|
1586
|
-
it('should not be stale when click timestamps differ but values are same', () => {
|
|
1587
|
-
const incomingIdentity = {
|
|
1588
|
-
identityId: 'test-id',
|
|
1589
|
-
traits: {
|
|
1590
|
-
click: {
|
|
1591
|
-
fbp: 'fb.1.same.123',
|
|
1592
|
-
fbpCollectedAt: '2024-06-01T00:00:00Z',
|
|
1593
|
-
},
|
|
1594
|
-
},
|
|
1595
|
-
};
|
|
1596
|
-
const cachedIdentity = {
|
|
1597
|
-
identityId: 'test-id',
|
|
1598
|
-
traits: {
|
|
1599
|
-
click: {
|
|
1600
|
-
fbp: 'fb.1.same.123',
|
|
1601
|
-
fbpCollectedAt: '2024-01-01T00:00:00Z',
|
|
1602
|
-
},
|
|
1603
|
-
},
|
|
1604
|
-
};
|
|
1605
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1606
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.NONE);
|
|
1607
|
-
expect(result.isCacheStale).toBe(false);
|
|
1608
|
-
});
|
|
1609
|
-
it('should detect staleness when fbc changes (incoming has new fbc, cached has none)', () => {
|
|
1610
|
-
const incomingIdentity = {
|
|
1611
|
-
identityId: 'test-id',
|
|
1612
|
-
traits: {
|
|
1613
|
-
click: {
|
|
1614
|
-
fbc: 'fb.1.1234.new_fbclid',
|
|
1615
|
-
},
|
|
1616
|
-
},
|
|
1617
|
-
};
|
|
1618
|
-
const cachedIdentity = {
|
|
1619
|
-
identityId: 'test-id',
|
|
1620
|
-
traits: {
|
|
1621
|
-
click: {},
|
|
1622
|
-
},
|
|
1623
|
-
};
|
|
1624
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1625
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
1626
|
-
expect(result.isCacheStale).toBe(true);
|
|
1627
|
-
expect(result.staleTraits).toContain('clickInfos');
|
|
1628
|
-
});
|
|
1629
|
-
});
|
|
1630
|
-
describe('staleTraits extraction comprehensive tests', () => {
|
|
1631
|
-
it('should return empty array when NONE tier', () => {
|
|
1632
|
-
const incomingIdentity = {
|
|
1633
|
-
identityId: 'test-id',
|
|
1634
|
-
traits: { emails: ['test@email.com'] },
|
|
1635
|
-
};
|
|
1636
|
-
const cachedIdentity = {
|
|
1637
|
-
identityId: 'test-id',
|
|
1638
|
-
traits: { emails: ['test@email.com', 'other@email.com'] },
|
|
1639
|
-
};
|
|
1640
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1641
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.NONE);
|
|
1642
|
-
expect(result.staleTraits).toEqual([]);
|
|
1643
|
-
});
|
|
1644
|
-
it('should return volatile trait names for VOLATILE_ONLY tier', () => {
|
|
1645
|
-
const incomingIdentity = {
|
|
1646
|
-
identityId: 'test-id',
|
|
1647
|
-
traits: {
|
|
1648
|
-
emails: ['test@email.com'],
|
|
1649
|
-
ipAddress: '10.0.0.1',
|
|
1650
|
-
userAgent: 'new-agent',
|
|
1651
|
-
},
|
|
1652
|
-
};
|
|
1653
|
-
const cachedIdentity = {
|
|
1654
|
-
identityId: 'test-id',
|
|
1655
|
-
traits: {
|
|
1656
|
-
emails: ['test@email.com'],
|
|
1657
|
-
},
|
|
1658
|
-
};
|
|
1659
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1660
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
|
|
1661
|
-
expect(result.staleTraits).toContain('ipAddress');
|
|
1662
|
-
expect(result.staleTraits).toContain('userAgent');
|
|
1663
|
-
expect(result.staleTraits).not.toContain('emails');
|
|
1664
|
-
});
|
|
1665
|
-
it('should return address trait name for ADDRESS_UPDATE tier', () => {
|
|
1666
|
-
const incomingIdentity = {
|
|
1667
|
-
identityId: 'test-id',
|
|
1668
|
-
traits: {
|
|
1669
|
-
emails: ['test@email.com'],
|
|
1670
|
-
addresses: [{ city: 'Boston', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT }],
|
|
1671
|
-
},
|
|
1672
|
-
};
|
|
1673
|
-
const cachedIdentity = {
|
|
1674
|
-
identityId: 'test-id',
|
|
1675
|
-
traits: {
|
|
1676
|
-
emails: ['test@email.com'],
|
|
1677
|
-
addresses: [],
|
|
1678
|
-
},
|
|
1679
|
-
};
|
|
1680
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1681
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
|
|
1682
|
-
expect(result.staleTraits).toContain('addresses');
|
|
1683
|
-
});
|
|
1684
|
-
it('should return all stale identity trait names for IDENTITY_STALE tier', () => {
|
|
1685
|
-
const incomingIdentity = {
|
|
1686
|
-
identityId: 'test-id',
|
|
1687
|
-
traits: {
|
|
1688
|
-
emails: ['old@email.com', 'new@email.com'],
|
|
1689
|
-
phones: ['+1234567890', '+9876543210'],
|
|
1690
|
-
userIds: ['user1', 'user2'],
|
|
1691
|
-
},
|
|
1692
|
-
};
|
|
1693
|
-
const cachedIdentity = {
|
|
1694
|
-
identityId: 'test-id',
|
|
1695
|
-
traits: {
|
|
1696
|
-
emails: ['old@email.com'],
|
|
1697
|
-
phones: ['+1234567890'],
|
|
1698
|
-
userIds: ['user1'],
|
|
1699
|
-
},
|
|
1700
|
-
};
|
|
1701
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1702
|
-
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
1703
|
-
expect(result.staleTraits).toContain('emails');
|
|
1704
|
-
expect(result.staleTraits).toContain('phones');
|
|
1705
|
-
expect(result.staleTraits).toContain('userIds');
|
|
1706
|
-
});
|
|
1707
|
-
});
|
|
1708
|
-
describe('Merge behavior verification', () => {
|
|
1709
|
-
it('should merge incoming and cached array traits (emails, phones, userIds)', () => {
|
|
1710
|
-
const incomingIdentity = {
|
|
1711
|
-
identityId: 'incoming-id',
|
|
1712
|
-
traits: {
|
|
1713
|
-
emails: ['incoming@email.com', 'shared@email.com'],
|
|
1714
|
-
userIds: ['incominguser'],
|
|
1715
|
-
},
|
|
1716
|
-
};
|
|
1717
|
-
const cachedIdentity = {
|
|
1718
|
-
identityId: 'cached-id',
|
|
1719
|
-
traits: {
|
|
1720
|
-
emails: ['cached@email.com', 'shared@email.com'],
|
|
1721
|
-
phones: ['+1234567890'],
|
|
1722
|
-
userIds: ['cacheduser'],
|
|
1723
|
-
},
|
|
1724
|
-
};
|
|
1725
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1726
|
-
expect(result.mergedIdentity.traits?.emails).toContain('incoming@email.com');
|
|
1727
|
-
expect(result.mergedIdentity.traits?.emails).toContain('cached@email.com');
|
|
1728
|
-
expect(result.mergedIdentity.traits?.emails).toContain('shared@email.com');
|
|
1729
|
-
expect(result.mergedIdentity.traits?.phones).toEqual(['+1234567890']);
|
|
1730
|
-
expect(result.mergedIdentity.traits?.userIds).toContain('incominguser');
|
|
1731
|
-
expect(result.mergedIdentity.traits?.userIds).toContain('cacheduser');
|
|
1732
|
-
});
|
|
1733
|
-
it('should preserve identityId from incoming identity', () => {
|
|
1734
|
-
const incomingIdentity = {
|
|
1735
|
-
identityId: 'incoming-id-123',
|
|
1736
|
-
traits: { emails: ['test@email.com'] },
|
|
1737
|
-
};
|
|
1738
|
-
const cachedIdentity = {
|
|
1739
|
-
identityId: 'cached-id-456',
|
|
1740
|
-
traits: { phones: ['+1234567890'] },
|
|
1741
|
-
};
|
|
1742
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1743
|
-
expect(result.mergedIdentity.identityId).toBe('incoming-id-123');
|
|
1744
|
-
});
|
|
1745
|
-
it('should merge addresses from both identities', () => {
|
|
1746
|
-
const incomingIdentity = {
|
|
1747
|
-
identityId: 'test-id',
|
|
1748
|
-
traits: {
|
|
1749
|
-
addresses: [
|
|
1750
|
-
{ city: 'IncomingCity', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT },
|
|
1751
|
-
],
|
|
1752
|
-
},
|
|
1753
|
-
};
|
|
1754
|
-
const cachedIdentity = {
|
|
1755
|
-
identityId: 'test-id',
|
|
1756
|
-
traits: {
|
|
1757
|
-
addresses: [
|
|
1758
|
-
{ city: 'CachedCity', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT },
|
|
1759
|
-
],
|
|
1760
|
-
},
|
|
1761
|
-
};
|
|
1762
|
-
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1763
|
-
expect(result.mergedIdentity.traits?.addresses).toHaveLength(2);
|
|
1764
|
-
expect(result.mergedIdentity.traits?.addresses).toEqual(expect.arrayContaining([
|
|
1765
|
-
expect.objectContaining({ city: 'IncomingCity' }),
|
|
1766
|
-
expect.objectContaining({ city: 'CachedCity' }),
|
|
1767
|
-
]));
|
|
1768
|
-
});
|
|
1769
|
-
});
|
|
1770
|
-
});
|
|
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
|
+
describe('Identity Trait Merging Tests', () => {
|
|
6
|
+
afterEach(() => {
|
|
7
|
+
jest.resetModules();
|
|
8
|
+
});
|
|
9
|
+
describe('mergeIdentityTraits function', () => {
|
|
10
|
+
it('should merge simple string arrays correctly', () => {
|
|
11
|
+
const incomingTraits = {
|
|
12
|
+
emails: ['new@email.com'],
|
|
13
|
+
userIds: ['user1', 'user2'],
|
|
14
|
+
};
|
|
15
|
+
const cachedTraits = {
|
|
16
|
+
emails: ['existing@email.com'],
|
|
17
|
+
userIds: ['user2', 'user3'],
|
|
18
|
+
phones: ['+1234567890'],
|
|
19
|
+
};
|
|
20
|
+
const merged = (0, at_shared_utils_1.mergeIdentityTraits)(incomingTraits, cachedTraits);
|
|
21
|
+
expect(merged.emails).toEqual(['new@email.com', 'existing@email.com']);
|
|
22
|
+
expect(merged.userIds).toEqual(['user1', 'user2', 'user3']);
|
|
23
|
+
expect(merged.phones).toEqual(['+1234567890']);
|
|
24
|
+
});
|
|
25
|
+
it('should handle null and undefined values in arrays', () => {
|
|
26
|
+
const incomingTraits = {
|
|
27
|
+
emails: ['test@email.com', null, undefined],
|
|
28
|
+
userIds: ['user1'],
|
|
29
|
+
};
|
|
30
|
+
const cachedTraits = {
|
|
31
|
+
emails: [null, 'cached@email.com', undefined],
|
|
32
|
+
userIds: null,
|
|
33
|
+
};
|
|
34
|
+
const merged = (0, at_shared_utils_1.mergeIdentityTraits)(incomingTraits, cachedTraits);
|
|
35
|
+
expect(merged.emails).toContain('test@email.com');
|
|
36
|
+
expect(merged.emails).toContain('cached@email.com');
|
|
37
|
+
expect(merged.userIds).toEqual(['user1']);
|
|
38
|
+
});
|
|
39
|
+
it('should merge addresses correctly', () => {
|
|
40
|
+
const incomingTraits = {
|
|
41
|
+
addresses: [
|
|
42
|
+
{
|
|
43
|
+
city: 'New York',
|
|
44
|
+
country: 'USA',
|
|
45
|
+
countryCode: 'US',
|
|
46
|
+
province: 'NY',
|
|
47
|
+
provinceCode: '10001',
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
};
|
|
51
|
+
const cachedTraits = {
|
|
52
|
+
addresses: [
|
|
53
|
+
{
|
|
54
|
+
city: 'Los Angeles',
|
|
55
|
+
country: 'USA',
|
|
56
|
+
countryCode: 'US',
|
|
57
|
+
province: 'CA',
|
|
58
|
+
provinceCode: '90210',
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
};
|
|
62
|
+
const merged = (0, at_shared_utils_1.mergeIdentityTraits)(incomingTraits, cachedTraits);
|
|
63
|
+
expect(merged.addresses).toHaveLength(2);
|
|
64
|
+
expect(merged.addresses).toEqual(expect.arrayContaining([
|
|
65
|
+
expect.objectContaining({ city: 'New York' }),
|
|
66
|
+
expect.objectContaining({ city: 'Los Angeles' }),
|
|
67
|
+
]));
|
|
68
|
+
});
|
|
69
|
+
it('should merge click information correctly', () => {
|
|
70
|
+
const incomingTraits = {
|
|
71
|
+
click: {
|
|
72
|
+
fbp: 'fb.new.123',
|
|
73
|
+
fbpCollectedAt: '2024-01-01T00:00:00.000Z',
|
|
74
|
+
gclid: 'new_gclid',
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
const cachedTraits = {
|
|
78
|
+
click: {
|
|
79
|
+
fbp: 'fb.old.456',
|
|
80
|
+
fbpCollectedAt: '2023-12-01T00:00:00.000Z',
|
|
81
|
+
fbclid: 'cached_fbclid',
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
const merged = (0, at_shared_utils_1.mergeIdentityTraits)(incomingTraits, cachedTraits);
|
|
85
|
+
expect(merged.click?.fbp).toBe('fb.new.123');
|
|
86
|
+
expect(merged.click?.gclid).toBe('new_gclid');
|
|
87
|
+
expect(merged.click?.fbpCollectedAt).toBe('2024-01-01T00:00:00.000Z');
|
|
88
|
+
expect(merged.click?.fbclid).toBeUndefined();
|
|
89
|
+
});
|
|
90
|
+
it('should handle empty traits correctly', () => {
|
|
91
|
+
const incomingTraits = {};
|
|
92
|
+
const cachedTraits = {
|
|
93
|
+
emails: ['cached@email.com'],
|
|
94
|
+
userIds: ['user1'],
|
|
95
|
+
};
|
|
96
|
+
const merged = (0, at_shared_utils_1.mergeIdentityTraits)(incomingTraits, cachedTraits);
|
|
97
|
+
expect(merged.emails).toEqual(['cached@email.com']);
|
|
98
|
+
expect(merged.userIds).toEqual(['user1']);
|
|
99
|
+
});
|
|
100
|
+
it('should handle undefined traits correctly', () => {
|
|
101
|
+
const merged1 = (0, at_shared_utils_1.mergeIdentityTraits)(undefined, { emails: ['test@email.com'] });
|
|
102
|
+
expect(merged1.emails).toEqual(['test@email.com']);
|
|
103
|
+
const merged2 = (0, at_shared_utils_1.mergeIdentityTraits)({ emails: ['test@email.com'] }, undefined);
|
|
104
|
+
expect(merged2.emails).toEqual(['test@email.com']);
|
|
105
|
+
const merged3 = (0, at_shared_utils_1.mergeIdentityTraits)(undefined, undefined);
|
|
106
|
+
expect(merged3).toEqual({});
|
|
107
|
+
});
|
|
108
|
+
it('should preserve version information', () => {
|
|
109
|
+
const incomingTraits = {
|
|
110
|
+
version: '3',
|
|
111
|
+
emails: ['new@email.com'],
|
|
112
|
+
};
|
|
113
|
+
const cachedTraits = {
|
|
114
|
+
version: '2',
|
|
115
|
+
emails: ['old@email.com'],
|
|
116
|
+
};
|
|
117
|
+
const merged = (0, at_shared_utils_1.mergeIdentityTraits)(incomingTraits, cachedTraits);
|
|
118
|
+
expect(merged.version).toBe('3');
|
|
119
|
+
expect(merged.emails).toEqual(['new@email.com', 'old@email.com']);
|
|
120
|
+
});
|
|
121
|
+
it('should handle complex nested objects', () => {
|
|
122
|
+
const incomingTraits = {
|
|
123
|
+
click: {
|
|
124
|
+
googleClientInfos: [{ id: 'new1', clickId: 'click1', sessionId: 'session1' }],
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
const cachedTraits = {
|
|
128
|
+
click: {
|
|
129
|
+
googleClientInfos: [{ id: 'cached1', clickId: 'click2', sessionId: 'session2' }],
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
const merged = (0, at_shared_utils_1.mergeIdentityTraits)(incomingTraits, cachedTraits);
|
|
133
|
+
expect(merged.click?.googleClientInfos).toBeDefined();
|
|
134
|
+
expect(Array.isArray(merged.click?.googleClientInfos)).toBe(true);
|
|
135
|
+
expect(merged.click?.googleClientInfos).toEqual([{ id: 'cached1', clickId: 'click2', sessionId: 'session2' }]);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
describe('Integration: Merging + Staleness Checking', () => {
|
|
139
|
+
it('should not be stale when merged identity matches cached identity', () => {
|
|
140
|
+
const cachedIdentity = {
|
|
141
|
+
identityId: 'test-id-123',
|
|
142
|
+
traits: {
|
|
143
|
+
emails: ['cached@email.com', 'shared@email.com'],
|
|
144
|
+
userIds: ['user1', 'user2'],
|
|
145
|
+
addresses: [
|
|
146
|
+
{
|
|
147
|
+
city: 'New York',
|
|
148
|
+
country: 'USA',
|
|
149
|
+
countryCode: 'US',
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
version: '2',
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
const incomingIdentity = {
|
|
156
|
+
identityId: 'test-id-123',
|
|
157
|
+
traits: {
|
|
158
|
+
emails: ['shared@email.com'],
|
|
159
|
+
userIds: ['user1'],
|
|
160
|
+
version: '2',
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
const mergedTraits = (0, at_shared_utils_1.mergeIdentityTraits)(incomingIdentity.traits, cachedIdentity.traits);
|
|
164
|
+
const mergedIdentity = { ...incomingIdentity, traits: mergedTraits };
|
|
165
|
+
const staleTracker = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, mergedIdentity);
|
|
166
|
+
expect(staleTracker.isCacheStale).toBe(false);
|
|
167
|
+
expect(mergedIdentity.traits?.emails).toEqual(['shared@email.com', 'cached@email.com']);
|
|
168
|
+
});
|
|
169
|
+
it('should be stale when merged identity has new traits', () => {
|
|
170
|
+
const cachedIdentity = {
|
|
171
|
+
identityId: 'test-id-123',
|
|
172
|
+
traits: {
|
|
173
|
+
emails: ['cached@email.com'],
|
|
174
|
+
version: '2',
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
const incomingIdentity = {
|
|
178
|
+
identityId: 'test-id-123',
|
|
179
|
+
traits: {
|
|
180
|
+
emails: ['cached@email.com', 'new@email.com'],
|
|
181
|
+
version: '2',
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
const mergedTraits = (0, at_shared_utils_1.mergeIdentityTraits)(incomingIdentity.traits, cachedIdentity.traits);
|
|
185
|
+
const mergedIdentity = { ...incomingIdentity, traits: mergedTraits };
|
|
186
|
+
const staleTracker = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, mergedIdentity);
|
|
187
|
+
expect(staleTracker.isCacheStale).toBe(true);
|
|
188
|
+
expect(staleTracker.isEmailsStale).toBe(true);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
describe('Identity Cache Staleness Tests', () => {
|
|
193
|
+
afterEach(() => {
|
|
194
|
+
jest.resetModules();
|
|
195
|
+
});
|
|
196
|
+
describe('isIdentityCacheStale function', () => {
|
|
197
|
+
it('should detect identity ID changes', () => {
|
|
198
|
+
const cachedIdentity = {
|
|
199
|
+
identityId: 'old-id',
|
|
200
|
+
traits: { emails: ['test@email.com'] },
|
|
201
|
+
};
|
|
202
|
+
const incomingIdentity = {
|
|
203
|
+
identityId: 'new-id',
|
|
204
|
+
traits: { emails: ['test@email.com'] },
|
|
205
|
+
};
|
|
206
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
207
|
+
expect(result.isCacheStale).toBe(true);
|
|
208
|
+
expect(result.isIdentityIdStale).toBe(true);
|
|
209
|
+
});
|
|
210
|
+
it('should detect new emails', () => {
|
|
211
|
+
const cachedIdentity = {
|
|
212
|
+
identityId: 'test-id',
|
|
213
|
+
traits: { emails: ['old@email.com'] },
|
|
214
|
+
};
|
|
215
|
+
const incomingIdentity = {
|
|
216
|
+
identityId: 'test-id',
|
|
217
|
+
traits: { emails: ['old@email.com', 'new@email.com'] },
|
|
218
|
+
};
|
|
219
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
220
|
+
expect(result.isCacheStale).toBe(true);
|
|
221
|
+
expect(result.isEmailsStale).toBe(true);
|
|
222
|
+
});
|
|
223
|
+
it('should detect new user IDs', () => {
|
|
224
|
+
const cachedIdentity = {
|
|
225
|
+
identityId: 'test-id',
|
|
226
|
+
traits: { userIds: ['user1'] },
|
|
227
|
+
};
|
|
228
|
+
const incomingIdentity = {
|
|
229
|
+
identityId: 'test-id',
|
|
230
|
+
traits: { userIds: ['user1', 'user2'] },
|
|
231
|
+
};
|
|
232
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
233
|
+
expect(result.isCacheStale).toBe(true);
|
|
234
|
+
expect(result.isUserIdsStale).toBe(true);
|
|
235
|
+
});
|
|
236
|
+
it('should detect new phones', () => {
|
|
237
|
+
const cachedIdentity = {
|
|
238
|
+
identityId: 'test-id',
|
|
239
|
+
traits: { phones: ['+1234567890'] },
|
|
240
|
+
};
|
|
241
|
+
const incomingIdentity = {
|
|
242
|
+
identityId: 'test-id',
|
|
243
|
+
traits: { phones: ['+1234567890', '+9876543210'] },
|
|
244
|
+
};
|
|
245
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
246
|
+
expect(result.isCacheStale).toBe(true);
|
|
247
|
+
expect(result.isPhonesStale).toBe(true);
|
|
248
|
+
});
|
|
249
|
+
it('should detect new addresses (non-IP sourced)', () => {
|
|
250
|
+
const cachedIdentity = {
|
|
251
|
+
identityId: 'test-id',
|
|
252
|
+
traits: {
|
|
253
|
+
addresses: [
|
|
254
|
+
{
|
|
255
|
+
city: 'New York',
|
|
256
|
+
country: 'USA',
|
|
257
|
+
s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT,
|
|
258
|
+
},
|
|
259
|
+
],
|
|
260
|
+
},
|
|
261
|
+
};
|
|
262
|
+
const incomingIdentity = {
|
|
263
|
+
identityId: 'test-id',
|
|
264
|
+
traits: {
|
|
265
|
+
addresses: [
|
|
266
|
+
{ city: 'New York', country: 'USA', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT },
|
|
267
|
+
{ city: 'Los Angeles', country: 'USA', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT },
|
|
268
|
+
],
|
|
269
|
+
},
|
|
270
|
+
};
|
|
271
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
272
|
+
expect(result.isCacheStale).toBe(true);
|
|
273
|
+
expect(result.isAddressesStale).toBe(true);
|
|
274
|
+
expect(result.isNonIpAddressesStale).toBe(true);
|
|
275
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
|
|
276
|
+
});
|
|
277
|
+
it('should detect IP address changes but NOT mark cache stale (volatile trait)', () => {
|
|
278
|
+
const cachedIdentity = {
|
|
279
|
+
identityId: 'test-id',
|
|
280
|
+
traits: { ipAddress: '192.168.1.1' },
|
|
281
|
+
};
|
|
282
|
+
const incomingIdentity = {
|
|
283
|
+
identityId: 'test-id',
|
|
284
|
+
traits: { ipAddress: '10.0.0.1' },
|
|
285
|
+
};
|
|
286
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
287
|
+
expect(result.isCacheStale).toBe(false);
|
|
288
|
+
expect(result.isIpAddressStale).toBe(true);
|
|
289
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
|
|
290
|
+
});
|
|
291
|
+
it('should detect user agent changes but NOT mark cache stale (volatile trait)', () => {
|
|
292
|
+
const cachedIdentity = {
|
|
293
|
+
identityId: 'test-id',
|
|
294
|
+
traits: { userAgent: 'Mozilla/5.0 (old browser)' },
|
|
295
|
+
};
|
|
296
|
+
const incomingIdentity = {
|
|
297
|
+
identityId: 'test-id',
|
|
298
|
+
traits: { userAgent: 'Mozilla/5.0 (new browser)' },
|
|
299
|
+
};
|
|
300
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
301
|
+
expect(result.isCacheStale).toBe(false);
|
|
302
|
+
expect(result.isUserAgentStale).toBe(true);
|
|
303
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
|
|
304
|
+
});
|
|
305
|
+
it('should not be stale when no new information is provided', () => {
|
|
306
|
+
const cachedIdentity = {
|
|
307
|
+
identityId: 'test-id',
|
|
308
|
+
traits: {
|
|
309
|
+
emails: ['test@email.com'],
|
|
310
|
+
userIds: ['user1'],
|
|
311
|
+
phones: ['+1234567890'],
|
|
312
|
+
},
|
|
313
|
+
};
|
|
314
|
+
const incomingIdentity = {
|
|
315
|
+
identityId: 'test-id',
|
|
316
|
+
traits: {
|
|
317
|
+
emails: ['test@email.com'],
|
|
318
|
+
userIds: ['user1'],
|
|
319
|
+
},
|
|
320
|
+
};
|
|
321
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
322
|
+
expect(result.isCacheStale).toBe(false);
|
|
323
|
+
});
|
|
324
|
+
it('should handle empty traits gracefully', () => {
|
|
325
|
+
const cachedIdentity = {
|
|
326
|
+
identityId: 'test-id',
|
|
327
|
+
traits: {},
|
|
328
|
+
};
|
|
329
|
+
const incomingIdentity = {
|
|
330
|
+
identityId: 'test-id',
|
|
331
|
+
traits: {},
|
|
332
|
+
};
|
|
333
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
334
|
+
expect(result.isCacheStale).toBe(false);
|
|
335
|
+
});
|
|
336
|
+
it('should handle undefined traits gracefully', () => {
|
|
337
|
+
const cachedIdentity = {
|
|
338
|
+
identityId: 'test-id',
|
|
339
|
+
};
|
|
340
|
+
const incomingIdentity = {
|
|
341
|
+
identityId: 'test-id',
|
|
342
|
+
};
|
|
343
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
344
|
+
expect(result.isCacheStale).toBe(false);
|
|
345
|
+
});
|
|
346
|
+
it('should detect multiple stale conditions (identity traits take priority over volatile)', () => {
|
|
347
|
+
const cachedIdentity = {
|
|
348
|
+
identityId: 'test-id',
|
|
349
|
+
traits: {
|
|
350
|
+
emails: ['old@email.com'],
|
|
351
|
+
userIds: ['user1'],
|
|
352
|
+
ipAddress: '192.168.1.1',
|
|
353
|
+
},
|
|
354
|
+
};
|
|
355
|
+
const incomingIdentity = {
|
|
356
|
+
identityId: 'test-id',
|
|
357
|
+
traits: {
|
|
358
|
+
emails: ['old@email.com', 'new@email.com'],
|
|
359
|
+
userIds: ['user1', 'user2'],
|
|
360
|
+
ipAddress: '10.0.0.1',
|
|
361
|
+
},
|
|
362
|
+
};
|
|
363
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
364
|
+
expect(result.isCacheStale).toBe(true);
|
|
365
|
+
expect(result.isEmailsStale).toBe(true);
|
|
366
|
+
expect(result.isUserIdsStale).toBe(true);
|
|
367
|
+
expect(result.isIpAddressStale).toBe(true);
|
|
368
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
describe('isClickInfosStale function', () => {
|
|
372
|
+
it('should detect new FBC values', () => {
|
|
373
|
+
const cachedClick = {
|
|
374
|
+
fbc: 'fb.1.123.old_fbclid',
|
|
375
|
+
};
|
|
376
|
+
const incomingClick = {
|
|
377
|
+
fbc: 'fb.1.123.new_fbclid',
|
|
378
|
+
};
|
|
379
|
+
const result = (0, at_shared_utils_1.isClickInfosStale)(cachedClick, incomingClick);
|
|
380
|
+
expect(result).toBe(true);
|
|
381
|
+
});
|
|
382
|
+
it('should detect new click IDs', () => {
|
|
383
|
+
const cachedClick = {
|
|
384
|
+
gclid: 'old_gclid',
|
|
385
|
+
};
|
|
386
|
+
const incomingClick = {
|
|
387
|
+
gclid: 'new_gclid',
|
|
388
|
+
};
|
|
389
|
+
const result = (0, at_shared_utils_1.isClickInfosStale)(cachedClick, incomingClick);
|
|
390
|
+
expect(result).toBe(true);
|
|
391
|
+
});
|
|
392
|
+
it('should ignore collection timestamps', () => {
|
|
393
|
+
const cachedClick = {
|
|
394
|
+
fbp: 'fb.2.123.456',
|
|
395
|
+
fbpCollectedAt: '2023-01-01T00:00:00.000Z',
|
|
396
|
+
};
|
|
397
|
+
const incomingClick = {
|
|
398
|
+
fbp: 'fb.2.123.456',
|
|
399
|
+
fbpCollectedAt: '2024-01-01T00:00:00.000Z',
|
|
400
|
+
};
|
|
401
|
+
const result = (0, at_shared_utils_1.isClickInfosStale)(cachedClick, incomingClick);
|
|
402
|
+
expect(result).toBe(false);
|
|
403
|
+
});
|
|
404
|
+
it('should ignore googleClientInfos', () => {
|
|
405
|
+
const cachedClick = {
|
|
406
|
+
googleClientInfos: [{ id: 'old', clickId: 'old_click' }],
|
|
407
|
+
};
|
|
408
|
+
const incomingClick = {
|
|
409
|
+
googleClientInfos: [{ id: 'new', clickId: 'new_click' }],
|
|
410
|
+
};
|
|
411
|
+
const result = (0, at_shared_utils_1.isClickInfosStale)(cachedClick, incomingClick);
|
|
412
|
+
expect(result).toBe(false);
|
|
413
|
+
});
|
|
414
|
+
it('should handle empty click info', () => {
|
|
415
|
+
const result = (0, at_shared_utils_1.isClickInfosStale)({}, {});
|
|
416
|
+
expect(result).toBe(false);
|
|
417
|
+
});
|
|
418
|
+
it('should detect when incoming has new click info but cached is empty', () => {
|
|
419
|
+
const cachedClick = {};
|
|
420
|
+
const incomingClick = {
|
|
421
|
+
fbp: 'fb.2.123.456',
|
|
422
|
+
};
|
|
423
|
+
const result = (0, at_shared_utils_1.isClickInfosStale)(cachedClick, incomingClick);
|
|
424
|
+
expect(result).toBe(true);
|
|
425
|
+
});
|
|
426
|
+
});
|
|
427
|
+
describe('Edge Cases and Error Handling', () => {
|
|
428
|
+
it('should handle malformed FBC values gracefully', () => {
|
|
429
|
+
const cachedClick = {
|
|
430
|
+
fbc: 'malformed_fbc',
|
|
431
|
+
};
|
|
432
|
+
const incomingClick = {
|
|
433
|
+
fbc: 'also_malformed',
|
|
434
|
+
};
|
|
435
|
+
const result = (0, at_shared_utils_1.isClickInfosStale)(cachedClick, incomingClick);
|
|
436
|
+
expect(result).toBe(true);
|
|
437
|
+
});
|
|
438
|
+
it('should handle null/undefined arrays in traits', () => {
|
|
439
|
+
const cachedIdentity = {
|
|
440
|
+
identityId: 'test-id',
|
|
441
|
+
traits: {
|
|
442
|
+
emails: null,
|
|
443
|
+
userIds: undefined,
|
|
444
|
+
},
|
|
445
|
+
};
|
|
446
|
+
const incomingIdentity = {
|
|
447
|
+
identityId: 'test-id',
|
|
448
|
+
traits: {
|
|
449
|
+
emails: ['new@email.com'],
|
|
450
|
+
userIds: ['user1'],
|
|
451
|
+
},
|
|
452
|
+
};
|
|
453
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
454
|
+
expect(result.isCacheStale).toBe(true);
|
|
455
|
+
expect(result.isEmailsStale).toBe(true);
|
|
456
|
+
expect(result.isUserIdsStale).toBe(true);
|
|
457
|
+
});
|
|
458
|
+
it('should handle arrays with null/undefined elements', () => {
|
|
459
|
+
const cachedIdentity = {
|
|
460
|
+
identityId: 'test-id',
|
|
461
|
+
traits: {
|
|
462
|
+
emails: ['valid@email.com', null, undefined],
|
|
463
|
+
},
|
|
464
|
+
};
|
|
465
|
+
const incomingIdentity = {
|
|
466
|
+
identityId: 'test-id',
|
|
467
|
+
traits: {
|
|
468
|
+
emails: ['valid@email.com', null, undefined, 'new@email.com'],
|
|
469
|
+
},
|
|
470
|
+
};
|
|
471
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
472
|
+
expect(result.isCacheStale).toBe(true);
|
|
473
|
+
expect(result.isEmailsStale).toBe(true);
|
|
474
|
+
});
|
|
475
|
+
it('should handle error conditions gracefully', () => {
|
|
476
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(null, undefined);
|
|
477
|
+
expect(result.isCacheStale).toBe(false);
|
|
478
|
+
});
|
|
479
|
+
});
|
|
480
|
+
describe('Comprehensive Scenario Tests', () => {
|
|
481
|
+
it('should handle complex real-world scenario', () => {
|
|
482
|
+
const cachedIdentity = {
|
|
483
|
+
identityId: '01HXRZ27H4TXWBBTRK09Q7APDP',
|
|
484
|
+
traits: {
|
|
485
|
+
emails: ['user@domain.com'],
|
|
486
|
+
userIds: ['shopify_123'],
|
|
487
|
+
addresses: [
|
|
488
|
+
{
|
|
489
|
+
city: 'New York',
|
|
490
|
+
country: 'USA',
|
|
491
|
+
countryCode: 'US',
|
|
492
|
+
province: 'NY',
|
|
493
|
+
provinceCode: '10001',
|
|
494
|
+
},
|
|
495
|
+
],
|
|
496
|
+
click: {
|
|
497
|
+
fbp: 'fb.2.1715603578424.5068754021',
|
|
498
|
+
fbpCollectedAt: '2024-05-13T12:32:58.424Z',
|
|
499
|
+
gclid: 'original_gclid',
|
|
500
|
+
},
|
|
501
|
+
ipAddress: '192.168.1.100',
|
|
502
|
+
version: '2',
|
|
503
|
+
},
|
|
504
|
+
};
|
|
505
|
+
const incomingIdentity = {
|
|
506
|
+
identityId: '01HXRZ27H4TXWBBTRK09Q7APDP',
|
|
507
|
+
traits: {
|
|
508
|
+
emails: ['user@domain.com', 'user.secondary@domain.com'],
|
|
509
|
+
phones: ['+1234567890'],
|
|
510
|
+
addresses: [
|
|
511
|
+
{
|
|
512
|
+
city: 'New York',
|
|
513
|
+
country: 'USA',
|
|
514
|
+
countryCode: 'US',
|
|
515
|
+
province: 'NY',
|
|
516
|
+
provinceCode: '10001',
|
|
517
|
+
},
|
|
518
|
+
],
|
|
519
|
+
click: {
|
|
520
|
+
fbp: 'fb.2.1715603578424.5068754021',
|
|
521
|
+
fbpCollectedAt: '2024-05-13T15:30:00.000Z',
|
|
522
|
+
gclid: 'updated_gclid',
|
|
523
|
+
},
|
|
524
|
+
ipAddress: '192.168.1.100',
|
|
525
|
+
version: '2',
|
|
526
|
+
},
|
|
527
|
+
};
|
|
528
|
+
const mergedTraits = (0, at_shared_utils_1.mergeIdentityTraits)(cachedIdentity.traits, incomingIdentity.traits);
|
|
529
|
+
const mergedIdentity = { ...incomingIdentity, traits: mergedTraits };
|
|
530
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, mergedIdentity);
|
|
531
|
+
expect(result.isCacheStale).toBe(true);
|
|
532
|
+
expect(result.isEmailsStale).toBe(true);
|
|
533
|
+
expect(result.isPhonesStale).toBe(true);
|
|
534
|
+
expect(result.isClickInfosStale).toBe(true);
|
|
535
|
+
expect(result.isAddressesStale).toBe(false);
|
|
536
|
+
expect(result.isIpAddressStale).toBe(false);
|
|
537
|
+
expect(mergedIdentity.traits?.emails).toEqual(['user@domain.com', 'user.secondary@domain.com']);
|
|
538
|
+
expect(mergedIdentity.traits?.phones).toEqual(['+1234567890']);
|
|
539
|
+
expect(mergedIdentity.traits?.userIds).toEqual(['shopify_123']);
|
|
540
|
+
expect(mergedIdentity.traits?.click?.gclid).toEqual('updated_gclid');
|
|
541
|
+
});
|
|
542
|
+
it('should properly detect click staleness when click info actually differs', () => {
|
|
543
|
+
const cachedIdentity = {
|
|
544
|
+
identityId: 'test-id',
|
|
545
|
+
traits: {
|
|
546
|
+
click: {
|
|
547
|
+
gclid: 'original_gclid',
|
|
548
|
+
gclidCollectedAt: '2024-05-15T12:32:58.424Z',
|
|
549
|
+
},
|
|
550
|
+
},
|
|
551
|
+
};
|
|
552
|
+
const incomingIdentity = {
|
|
553
|
+
identityId: 'test-id',
|
|
554
|
+
traits: {
|
|
555
|
+
click: {
|
|
556
|
+
gclid: 'completely_different_gclid',
|
|
557
|
+
gclidCollectedAt: '2024-05-13T12:32:58.424Z',
|
|
558
|
+
},
|
|
559
|
+
},
|
|
560
|
+
};
|
|
561
|
+
const mergedTraits = (0, at_shared_utils_1.mergeIdentityTraits)(cachedIdentity.traits, incomingIdentity.traits);
|
|
562
|
+
const mergedIdentity = { ...incomingIdentity, traits: mergedTraits };
|
|
563
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, mergedIdentity);
|
|
564
|
+
expect(mergedTraits?.click?.gclid).toEqual('original_gclid');
|
|
565
|
+
expect(result.isCacheStale).toBe(false);
|
|
566
|
+
});
|
|
567
|
+
it('should handle scenario where cache is fresh', () => {
|
|
568
|
+
const cachedIdentity = {
|
|
569
|
+
identityId: 'test-id',
|
|
570
|
+
traits: {
|
|
571
|
+
emails: ['user@domain.com', 'secondary@domain.com'],
|
|
572
|
+
userIds: ['user1', 'user2'],
|
|
573
|
+
phones: ['+1234567890'],
|
|
574
|
+
version: '2',
|
|
575
|
+
},
|
|
576
|
+
};
|
|
577
|
+
const incomingIdentity = {
|
|
578
|
+
identityId: 'test-id',
|
|
579
|
+
traits: {
|
|
580
|
+
emails: ['user@domain.com'],
|
|
581
|
+
userIds: ['user1'],
|
|
582
|
+
version: '2',
|
|
583
|
+
},
|
|
584
|
+
};
|
|
585
|
+
const mergedTraits = (0, at_shared_utils_1.mergeIdentityTraits)(cachedIdentity.traits, incomingIdentity.traits);
|
|
586
|
+
const mergedIdentity = { ...incomingIdentity, traits: mergedTraits };
|
|
587
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, mergedIdentity);
|
|
588
|
+
expect(result.isCacheStale).toBe(false);
|
|
589
|
+
expect(mergedIdentity.traits?.emails).toEqual(['user@domain.com', 'secondary@domain.com']);
|
|
590
|
+
expect(mergedIdentity.traits?.userIds).toEqual(['user1', 'user2']);
|
|
591
|
+
expect(mergedIdentity.traits?.phones).toEqual(['+1234567890']);
|
|
592
|
+
});
|
|
593
|
+
});
|
|
594
|
+
});
|
|
595
|
+
describe('Three-Tier Staleness Model Tests', () => {
|
|
596
|
+
afterEach(() => {
|
|
597
|
+
jest.resetModules();
|
|
598
|
+
});
|
|
599
|
+
describe('TIER 1: VOLATILE_ONLY (no action needed)', () => {
|
|
600
|
+
it('should return VOLATILE_ONLY tier when only ipAddress is stale', () => {
|
|
601
|
+
const cachedIdentity = {
|
|
602
|
+
identityId: 'test-id',
|
|
603
|
+
traits: {
|
|
604
|
+
emails: ['test@email.com'],
|
|
605
|
+
ipAddress: '192.168.1.1',
|
|
606
|
+
},
|
|
607
|
+
};
|
|
608
|
+
const incomingIdentity = {
|
|
609
|
+
identityId: 'test-id',
|
|
610
|
+
traits: {
|
|
611
|
+
emails: ['test@email.com'],
|
|
612
|
+
ipAddress: '10.0.0.1',
|
|
613
|
+
},
|
|
614
|
+
};
|
|
615
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
616
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
|
|
617
|
+
expect(result.isCacheStale).toBe(false);
|
|
618
|
+
expect(result.isIpAddressStale).toBe(true);
|
|
619
|
+
});
|
|
620
|
+
it('should return VOLATILE_ONLY tier when only userAgent is stale', () => {
|
|
621
|
+
const cachedIdentity = {
|
|
622
|
+
identityId: 'test-id',
|
|
623
|
+
traits: {
|
|
624
|
+
emails: ['test@email.com'],
|
|
625
|
+
userAgent: 'Mozilla/5.0 (old)',
|
|
626
|
+
},
|
|
627
|
+
};
|
|
628
|
+
const incomingIdentity = {
|
|
629
|
+
identityId: 'test-id',
|
|
630
|
+
traits: {
|
|
631
|
+
emails: ['test@email.com'],
|
|
632
|
+
userAgent: 'Mozilla/5.0 (new)',
|
|
633
|
+
},
|
|
634
|
+
};
|
|
635
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
636
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
|
|
637
|
+
expect(result.isCacheStale).toBe(false);
|
|
638
|
+
expect(result.isUserAgentStale).toBe(true);
|
|
639
|
+
});
|
|
640
|
+
it('should return VOLATILE_ONLY tier when only IP-sourced addresses are stale', () => {
|
|
641
|
+
const cachedIdentity = {
|
|
642
|
+
identityId: 'test-id',
|
|
643
|
+
traits: {
|
|
644
|
+
emails: ['test@email.com'],
|
|
645
|
+
addresses: [
|
|
646
|
+
{ city: 'New York', country: 'USA', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.IP_ADDRESS },
|
|
647
|
+
],
|
|
648
|
+
},
|
|
649
|
+
};
|
|
650
|
+
const incomingIdentity = {
|
|
651
|
+
identityId: 'test-id',
|
|
652
|
+
traits: {
|
|
653
|
+
emails: ['test@email.com'],
|
|
654
|
+
addresses: [
|
|
655
|
+
{ city: 'Los Angeles', country: 'USA', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.IP_ADDRESS },
|
|
656
|
+
],
|
|
657
|
+
},
|
|
658
|
+
};
|
|
659
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
660
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
|
|
661
|
+
expect(result.isCacheStale).toBe(false);
|
|
662
|
+
expect(result.isIpAddressesStale).toBe(true);
|
|
663
|
+
expect(result.isNonIpAddressesStale).toBe(false);
|
|
664
|
+
});
|
|
665
|
+
it('should return VOLATILE_ONLY tier when multiple volatile traits are stale', () => {
|
|
666
|
+
const cachedIdentity = {
|
|
667
|
+
identityId: 'test-id',
|
|
668
|
+
traits: {
|
|
669
|
+
emails: ['test@email.com'],
|
|
670
|
+
ipAddress: '192.168.1.1',
|
|
671
|
+
userAgent: 'Mozilla/5.0 (old)',
|
|
672
|
+
addresses: [
|
|
673
|
+
{ city: 'New York', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.IP_ADDRESS },
|
|
674
|
+
],
|
|
675
|
+
},
|
|
676
|
+
};
|
|
677
|
+
const incomingIdentity = {
|
|
678
|
+
identityId: 'test-id',
|
|
679
|
+
traits: {
|
|
680
|
+
emails: ['test@email.com'],
|
|
681
|
+
ipAddress: '10.0.0.1',
|
|
682
|
+
userAgent: 'Mozilla/5.0 (new)',
|
|
683
|
+
addresses: [
|
|
684
|
+
{ city: 'Chicago', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.IP_ADDRESS },
|
|
685
|
+
],
|
|
686
|
+
},
|
|
687
|
+
};
|
|
688
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
689
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
|
|
690
|
+
expect(result.isCacheStale).toBe(false);
|
|
691
|
+
expect(result.isIpAddressStale).toBe(true);
|
|
692
|
+
expect(result.isUserAgentStale).toBe(true);
|
|
693
|
+
expect(result.isIpAddressesStale).toBe(true);
|
|
694
|
+
});
|
|
695
|
+
});
|
|
696
|
+
describe('TIER 2: ADDRESS_UPDATE (cache write only, skip Neptune)', () => {
|
|
697
|
+
it('should return ADDRESS_UPDATE tier when non-IP address is new', () => {
|
|
698
|
+
const cachedIdentity = {
|
|
699
|
+
identityId: 'test-id',
|
|
700
|
+
traits: {
|
|
701
|
+
emails: ['test@email.com'],
|
|
702
|
+
addresses: [],
|
|
703
|
+
},
|
|
704
|
+
};
|
|
705
|
+
const incomingIdentity = {
|
|
706
|
+
identityId: 'test-id',
|
|
707
|
+
traits: {
|
|
708
|
+
emails: ['test@email.com'],
|
|
709
|
+
addresses: [
|
|
710
|
+
{ city: 'Boston', province: 'MA', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT },
|
|
711
|
+
],
|
|
712
|
+
},
|
|
713
|
+
};
|
|
714
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
715
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
|
|
716
|
+
expect(result.isCacheStale).toBe(true);
|
|
717
|
+
expect(result.isNonIpAddressesStale).toBe(true);
|
|
718
|
+
});
|
|
719
|
+
it('should return ADDRESS_UPDATE tier when new input address added', () => {
|
|
720
|
+
const cachedIdentity = {
|
|
721
|
+
identityId: 'test-id',
|
|
722
|
+
traits: {
|
|
723
|
+
emails: ['test@email.com'],
|
|
724
|
+
addresses: [
|
|
725
|
+
{ city: 'New York', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT },
|
|
726
|
+
],
|
|
727
|
+
},
|
|
728
|
+
};
|
|
729
|
+
const incomingIdentity = {
|
|
730
|
+
identityId: 'test-id',
|
|
731
|
+
traits: {
|
|
732
|
+
emails: ['test@email.com'],
|
|
733
|
+
addresses: [
|
|
734
|
+
{ city: 'New York', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT },
|
|
735
|
+
{ city: 'Boston', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT },
|
|
736
|
+
],
|
|
737
|
+
},
|
|
738
|
+
};
|
|
739
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
740
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
|
|
741
|
+
expect(result.isCacheStale).toBe(true);
|
|
742
|
+
expect(result.isNonIpAddressesStale).toBe(true);
|
|
743
|
+
});
|
|
744
|
+
it('should return ADDRESS_UPDATE tier even when volatile traits are also stale', () => {
|
|
745
|
+
const cachedIdentity = {
|
|
746
|
+
identityId: 'test-id',
|
|
747
|
+
traits: {
|
|
748
|
+
emails: ['test@email.com'],
|
|
749
|
+
ipAddress: '192.168.1.1',
|
|
750
|
+
addresses: [],
|
|
751
|
+
},
|
|
752
|
+
};
|
|
753
|
+
const incomingIdentity = {
|
|
754
|
+
identityId: 'test-id',
|
|
755
|
+
traits: {
|
|
756
|
+
emails: ['test@email.com'],
|
|
757
|
+
ipAddress: '10.0.0.1',
|
|
758
|
+
addresses: [
|
|
759
|
+
{ city: 'Boston', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT },
|
|
760
|
+
],
|
|
761
|
+
},
|
|
762
|
+
};
|
|
763
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
764
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
|
|
765
|
+
expect(result.isCacheStale).toBe(true);
|
|
766
|
+
expect(result.isIpAddressStale).toBe(true);
|
|
767
|
+
expect(result.isNonIpAddressesStale).toBe(true);
|
|
768
|
+
});
|
|
769
|
+
});
|
|
770
|
+
describe('TIER 3: IDENTITY_STALE (full Neptune resolution)', () => {
|
|
771
|
+
it('should return IDENTITY_STALE tier when email is new', () => {
|
|
772
|
+
const cachedIdentity = {
|
|
773
|
+
identityId: 'test-id',
|
|
774
|
+
traits: {
|
|
775
|
+
emails: ['old@email.com'],
|
|
776
|
+
},
|
|
777
|
+
};
|
|
778
|
+
const incomingIdentity = {
|
|
779
|
+
identityId: 'test-id',
|
|
780
|
+
traits: {
|
|
781
|
+
emails: ['old@email.com', 'new@email.com'],
|
|
782
|
+
},
|
|
783
|
+
};
|
|
784
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
785
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
786
|
+
expect(result.isCacheStale).toBe(true);
|
|
787
|
+
expect(result.isEmailsStale).toBe(true);
|
|
788
|
+
});
|
|
789
|
+
it('should return IDENTITY_STALE tier when identityId changes', () => {
|
|
790
|
+
const cachedIdentity = {
|
|
791
|
+
identityId: 'old-id',
|
|
792
|
+
traits: { emails: ['test@email.com'] },
|
|
793
|
+
};
|
|
794
|
+
const incomingIdentity = {
|
|
795
|
+
identityId: 'new-id',
|
|
796
|
+
traits: { emails: ['test@email.com'] },
|
|
797
|
+
};
|
|
798
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
799
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
800
|
+
expect(result.isCacheStale).toBe(true);
|
|
801
|
+
expect(result.isIdentityIdStale).toBe(true);
|
|
802
|
+
});
|
|
803
|
+
it('should return IDENTITY_STALE tier when phone is new', () => {
|
|
804
|
+
const cachedIdentity = {
|
|
805
|
+
identityId: 'test-id',
|
|
806
|
+
traits: { phones: ['+1234567890'] },
|
|
807
|
+
};
|
|
808
|
+
const incomingIdentity = {
|
|
809
|
+
identityId: 'test-id',
|
|
810
|
+
traits: { phones: ['+1234567890', '+9876543210'] },
|
|
811
|
+
};
|
|
812
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
813
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
814
|
+
expect(result.isCacheStale).toBe(true);
|
|
815
|
+
expect(result.isPhonesStale).toBe(true);
|
|
816
|
+
});
|
|
817
|
+
it('should return IDENTITY_STALE tier when click info changes', () => {
|
|
818
|
+
const cachedIdentity = {
|
|
819
|
+
identityId: 'test-id',
|
|
820
|
+
traits: {
|
|
821
|
+
click: { gclid: 'old_gclid' },
|
|
822
|
+
},
|
|
823
|
+
};
|
|
824
|
+
const incomingIdentity = {
|
|
825
|
+
identityId: 'test-id',
|
|
826
|
+
traits: {
|
|
827
|
+
click: { gclid: 'new_gclid' },
|
|
828
|
+
},
|
|
829
|
+
};
|
|
830
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
831
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
832
|
+
expect(result.isCacheStale).toBe(true);
|
|
833
|
+
expect(result.isClickInfosStale).toBe(true);
|
|
834
|
+
});
|
|
835
|
+
it('should return IDENTITY_STALE tier when identity trait is stale even with ADDRESS_UPDATE', () => {
|
|
836
|
+
const cachedIdentity = {
|
|
837
|
+
identityId: 'test-id',
|
|
838
|
+
traits: {
|
|
839
|
+
emails: ['old@email.com'],
|
|
840
|
+
addresses: [],
|
|
841
|
+
},
|
|
842
|
+
};
|
|
843
|
+
const incomingIdentity = {
|
|
844
|
+
identityId: 'test-id',
|
|
845
|
+
traits: {
|
|
846
|
+
emails: ['old@email.com', 'new@email.com'],
|
|
847
|
+
addresses: [
|
|
848
|
+
{ city: 'Boston', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT },
|
|
849
|
+
],
|
|
850
|
+
},
|
|
851
|
+
};
|
|
852
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
853
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
854
|
+
expect(result.isCacheStale).toBe(true);
|
|
855
|
+
expect(result.isEmailsStale).toBe(true);
|
|
856
|
+
expect(result.isNonIpAddressesStale).toBe(true);
|
|
857
|
+
});
|
|
858
|
+
it('should return IDENTITY_STALE tier when identity trait is stale even with VOLATILE_ONLY', () => {
|
|
859
|
+
const cachedIdentity = {
|
|
860
|
+
identityId: 'test-id',
|
|
861
|
+
traits: {
|
|
862
|
+
emails: ['old@email.com'],
|
|
863
|
+
ipAddress: '192.168.1.1',
|
|
864
|
+
},
|
|
865
|
+
};
|
|
866
|
+
const incomingIdentity = {
|
|
867
|
+
identityId: 'test-id',
|
|
868
|
+
traits: {
|
|
869
|
+
emails: ['old@email.com', 'new@email.com'],
|
|
870
|
+
ipAddress: '10.0.0.1',
|
|
871
|
+
},
|
|
872
|
+
};
|
|
873
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
874
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
875
|
+
expect(result.isCacheStale).toBe(true);
|
|
876
|
+
expect(result.isEmailsStale).toBe(true);
|
|
877
|
+
expect(result.isIpAddressStale).toBe(true);
|
|
878
|
+
});
|
|
879
|
+
});
|
|
880
|
+
describe('TIER NONE: No staleness', () => {
|
|
881
|
+
it('should return NONE tier when nothing is stale', () => {
|
|
882
|
+
const cachedIdentity = {
|
|
883
|
+
identityId: 'test-id',
|
|
884
|
+
traits: {
|
|
885
|
+
emails: ['test@email.com'],
|
|
886
|
+
phones: ['+1234567890'],
|
|
887
|
+
ipAddress: '192.168.1.1',
|
|
888
|
+
},
|
|
889
|
+
};
|
|
890
|
+
const incomingIdentity = {
|
|
891
|
+
identityId: 'test-id',
|
|
892
|
+
traits: {
|
|
893
|
+
emails: ['test@email.com'],
|
|
894
|
+
phones: ['+1234567890'],
|
|
895
|
+
ipAddress: '192.168.1.1',
|
|
896
|
+
},
|
|
897
|
+
};
|
|
898
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
899
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.NONE);
|
|
900
|
+
expect(result.isCacheStale).toBe(false);
|
|
901
|
+
});
|
|
902
|
+
it('should return NONE tier when incoming is subset of cached', () => {
|
|
903
|
+
const cachedIdentity = {
|
|
904
|
+
identityId: 'test-id',
|
|
905
|
+
traits: {
|
|
906
|
+
emails: ['a@email.com', 'b@email.com'],
|
|
907
|
+
phones: ['+1234567890', '+9876543210'],
|
|
908
|
+
},
|
|
909
|
+
};
|
|
910
|
+
const incomingIdentity = {
|
|
911
|
+
identityId: 'test-id',
|
|
912
|
+
traits: {
|
|
913
|
+
emails: ['a@email.com'],
|
|
914
|
+
},
|
|
915
|
+
};
|
|
916
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
917
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.NONE);
|
|
918
|
+
expect(result.isCacheStale).toBe(false);
|
|
919
|
+
});
|
|
920
|
+
});
|
|
921
|
+
describe('Address source filtering', () => {
|
|
922
|
+
it('should correctly identify IP-sourced addresses', () => {
|
|
923
|
+
const cachedIdentity = {
|
|
924
|
+
identityId: 'test-id',
|
|
925
|
+
traits: {
|
|
926
|
+
addresses: [
|
|
927
|
+
{ city: 'CachedCity', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.IP_ADDRESS },
|
|
928
|
+
],
|
|
929
|
+
},
|
|
930
|
+
};
|
|
931
|
+
const incomingIdentity = {
|
|
932
|
+
identityId: 'test-id',
|
|
933
|
+
traits: {
|
|
934
|
+
addresses: [
|
|
935
|
+
{ city: 'NewCity', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.IP_ADDRESS },
|
|
936
|
+
],
|
|
937
|
+
},
|
|
938
|
+
};
|
|
939
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
940
|
+
expect(result.isIpAddressesStale).toBe(true);
|
|
941
|
+
expect(result.isNonIpAddressesStale).toBe(false);
|
|
942
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
|
|
943
|
+
});
|
|
944
|
+
it('should correctly identify INPUT-sourced addresses', () => {
|
|
945
|
+
const cachedIdentity = {
|
|
946
|
+
identityId: 'test-id',
|
|
947
|
+
traits: {
|
|
948
|
+
addresses: [
|
|
949
|
+
{ city: 'CachedCity', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT },
|
|
950
|
+
],
|
|
951
|
+
},
|
|
952
|
+
};
|
|
953
|
+
const incomingIdentity = {
|
|
954
|
+
identityId: 'test-id',
|
|
955
|
+
traits: {
|
|
956
|
+
addresses: [
|
|
957
|
+
{ city: 'CachedCity', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT },
|
|
958
|
+
{ city: 'NewCity', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT },
|
|
959
|
+
],
|
|
960
|
+
},
|
|
961
|
+
};
|
|
962
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
963
|
+
expect(result.isIpAddressesStale).toBe(false);
|
|
964
|
+
expect(result.isNonIpAddressesStale).toBe(true);
|
|
965
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
|
|
966
|
+
});
|
|
967
|
+
it('should handle mixed address sources correctly', () => {
|
|
968
|
+
const cachedIdentity = {
|
|
969
|
+
identityId: 'test-id',
|
|
970
|
+
traits: {
|
|
971
|
+
addresses: [
|
|
972
|
+
{ city: 'IPCity', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.IP_ADDRESS },
|
|
973
|
+
{ city: 'InputCity', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT },
|
|
974
|
+
],
|
|
975
|
+
},
|
|
976
|
+
};
|
|
977
|
+
const incomingIdentity = {
|
|
978
|
+
identityId: 'test-id',
|
|
979
|
+
traits: {
|
|
980
|
+
addresses: [
|
|
981
|
+
{ city: 'NewIPCity', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.IP_ADDRESS },
|
|
982
|
+
{ city: 'InputCity', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT },
|
|
983
|
+
{ city: 'NewInputCity', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT },
|
|
984
|
+
],
|
|
985
|
+
},
|
|
986
|
+
};
|
|
987
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
988
|
+
expect(result.isIpAddressesStale).toBe(true);
|
|
989
|
+
expect(result.isNonIpAddressesStale).toBe(true);
|
|
990
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
|
|
991
|
+
expect(result.isCacheStale).toBe(true);
|
|
992
|
+
});
|
|
993
|
+
it('should handle addresses without source field (default to IP based on PII)', () => {
|
|
994
|
+
const cachedIdentity = {
|
|
995
|
+
identityId: 'test-id',
|
|
996
|
+
traits: {
|
|
997
|
+
addresses: [],
|
|
998
|
+
},
|
|
999
|
+
};
|
|
1000
|
+
const incomingIdentity = {
|
|
1001
|
+
identityId: 'test-id',
|
|
1002
|
+
traits: {
|
|
1003
|
+
addresses: [
|
|
1004
|
+
{ city: 'NoSourceCity' },
|
|
1005
|
+
],
|
|
1006
|
+
},
|
|
1007
|
+
};
|
|
1008
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
1009
|
+
expect(result.isIpAddressesStale).toBe(true);
|
|
1010
|
+
expect(result.isNonIpAddressesStale).toBe(false);
|
|
1011
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
|
|
1012
|
+
expect(result.isCacheStale).toBe(false);
|
|
1013
|
+
});
|
|
1014
|
+
it('should treat addresses without source but with PII as non-IP', () => {
|
|
1015
|
+
const cachedIdentity = {
|
|
1016
|
+
identityId: 'test-id',
|
|
1017
|
+
traits: {
|
|
1018
|
+
addresses: [],
|
|
1019
|
+
},
|
|
1020
|
+
};
|
|
1021
|
+
const incomingIdentity = {
|
|
1022
|
+
identityId: 'test-id',
|
|
1023
|
+
traits: {
|
|
1024
|
+
addresses: [
|
|
1025
|
+
{ city: 'InputCity', firstName: 'John' },
|
|
1026
|
+
],
|
|
1027
|
+
},
|
|
1028
|
+
};
|
|
1029
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
1030
|
+
expect(result.isNonIpAddressesStale).toBe(true);
|
|
1031
|
+
expect(result.isIpAddressesStale).toBe(false);
|
|
1032
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
|
|
1033
|
+
expect(result.isCacheStale).toBe(true);
|
|
1034
|
+
});
|
|
1035
|
+
});
|
|
1036
|
+
describe('Backward compatibility', () => {
|
|
1037
|
+
it('should maintain isAddressesStale for any address change', () => {
|
|
1038
|
+
const cachedIdentity = {
|
|
1039
|
+
identityId: 'test-id',
|
|
1040
|
+
traits: {
|
|
1041
|
+
addresses: [
|
|
1042
|
+
{ city: 'OldCity', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.IP_ADDRESS },
|
|
1043
|
+
],
|
|
1044
|
+
},
|
|
1045
|
+
};
|
|
1046
|
+
const incomingIdentity = {
|
|
1047
|
+
identityId: 'test-id',
|
|
1048
|
+
traits: {
|
|
1049
|
+
addresses: [
|
|
1050
|
+
{ city: 'NewCity', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.IP_ADDRESS },
|
|
1051
|
+
],
|
|
1052
|
+
},
|
|
1053
|
+
};
|
|
1054
|
+
const result = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
1055
|
+
expect(result.isAddressesStale).toBe(true);
|
|
1056
|
+
expect(result.isCacheStale).toBe(false);
|
|
1057
|
+
});
|
|
1058
|
+
});
|
|
1059
|
+
});
|
|
1060
|
+
describe('extractStaleTraitNames function', () => {
|
|
1061
|
+
it('should return empty array when nothing is stale', () => {
|
|
1062
|
+
const cachedIdentity = {
|
|
1063
|
+
identityId: 'test-id',
|
|
1064
|
+
traits: { emails: ['test@email.com'] },
|
|
1065
|
+
};
|
|
1066
|
+
const incomingIdentity = {
|
|
1067
|
+
identityId: 'test-id',
|
|
1068
|
+
traits: { emails: ['test@email.com'] },
|
|
1069
|
+
};
|
|
1070
|
+
const tracker = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
1071
|
+
const staleTraits = (0, at_shared_utils_1.extractStaleTraitNames)(tracker);
|
|
1072
|
+
expect(staleTraits).toEqual([]);
|
|
1073
|
+
});
|
|
1074
|
+
it('should return identity-defining trait names when stale', () => {
|
|
1075
|
+
const cachedIdentity = {
|
|
1076
|
+
identityId: 'test-id',
|
|
1077
|
+
traits: { emails: ['old@email.com'] },
|
|
1078
|
+
};
|
|
1079
|
+
const incomingIdentity = {
|
|
1080
|
+
identityId: 'test-id',
|
|
1081
|
+
traits: { emails: ['old@email.com', 'new@email.com'] },
|
|
1082
|
+
};
|
|
1083
|
+
const tracker = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
1084
|
+
const staleTraits = (0, at_shared_utils_1.extractStaleTraitNames)(tracker);
|
|
1085
|
+
expect(staleTraits).toContain('emails');
|
|
1086
|
+
});
|
|
1087
|
+
it('should return multiple stale trait names', () => {
|
|
1088
|
+
const cachedIdentity = {
|
|
1089
|
+
identityId: 'test-id',
|
|
1090
|
+
traits: {
|
|
1091
|
+
emails: ['old@email.com'],
|
|
1092
|
+
phones: ['+1234567890'],
|
|
1093
|
+
},
|
|
1094
|
+
};
|
|
1095
|
+
const incomingIdentity = {
|
|
1096
|
+
identityId: 'test-id',
|
|
1097
|
+
traits: {
|
|
1098
|
+
emails: ['old@email.com', 'new@email.com'],
|
|
1099
|
+
phones: ['+1234567890', '+9876543210'],
|
|
1100
|
+
},
|
|
1101
|
+
};
|
|
1102
|
+
const tracker = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
1103
|
+
const staleTraits = (0, at_shared_utils_1.extractStaleTraitNames)(tracker);
|
|
1104
|
+
expect(staleTraits).toContain('emails');
|
|
1105
|
+
expect(staleTraits).toContain('phones');
|
|
1106
|
+
});
|
|
1107
|
+
it('should return volatile trait names when stale', () => {
|
|
1108
|
+
const cachedIdentity = {
|
|
1109
|
+
identityId: 'test-id',
|
|
1110
|
+
traits: {
|
|
1111
|
+
ipAddress: '192.168.1.1',
|
|
1112
|
+
userAgent: 'old-agent',
|
|
1113
|
+
},
|
|
1114
|
+
};
|
|
1115
|
+
const incomingIdentity = {
|
|
1116
|
+
identityId: 'test-id',
|
|
1117
|
+
traits: {
|
|
1118
|
+
ipAddress: '10.0.0.1',
|
|
1119
|
+
userAgent: 'new-agent',
|
|
1120
|
+
},
|
|
1121
|
+
};
|
|
1122
|
+
const tracker = (0, at_shared_utils_1.isIdentityCacheStale)(cachedIdentity, incomingIdentity);
|
|
1123
|
+
const staleTraits = (0, at_shared_utils_1.extractStaleTraitNames)(tracker);
|
|
1124
|
+
expect(staleTraits).toContain('ipAddress');
|
|
1125
|
+
expect(staleTraits).toContain('userAgent');
|
|
1126
|
+
});
|
|
1127
|
+
});
|
|
1128
|
+
describe('mergeAndComputeIdentityStaleness function', () => {
|
|
1129
|
+
describe('NONE tier - cache is fresh', () => {
|
|
1130
|
+
it('should return NONE tier when incoming is subset of cached', () => {
|
|
1131
|
+
const incomingIdentity = {
|
|
1132
|
+
identityId: 'test-id',
|
|
1133
|
+
traits: { emails: ['shared@email.com'] },
|
|
1134
|
+
};
|
|
1135
|
+
const cachedIdentity = {
|
|
1136
|
+
identityId: 'test-id',
|
|
1137
|
+
traits: {
|
|
1138
|
+
emails: ['shared@email.com', 'other@email.com'],
|
|
1139
|
+
phones: ['+1234567890'],
|
|
1140
|
+
},
|
|
1141
|
+
};
|
|
1142
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1143
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.NONE);
|
|
1144
|
+
expect(result.isCacheStale).toBe(false);
|
|
1145
|
+
expect(result.staleTraits).toEqual([]);
|
|
1146
|
+
expect(result.mergedIdentity.traits?.emails).toEqual(['shared@email.com', 'other@email.com']);
|
|
1147
|
+
expect(result.mergedIdentity.traits?.phones).toEqual(['+1234567890']);
|
|
1148
|
+
});
|
|
1149
|
+
it('should return NONE tier when identities are identical', () => {
|
|
1150
|
+
const incomingIdentity = {
|
|
1151
|
+
identityId: 'test-id',
|
|
1152
|
+
traits: {
|
|
1153
|
+
emails: ['test@email.com'],
|
|
1154
|
+
phones: ['+1234567890'],
|
|
1155
|
+
},
|
|
1156
|
+
};
|
|
1157
|
+
const cachedIdentity = {
|
|
1158
|
+
identityId: 'test-id',
|
|
1159
|
+
traits: {
|
|
1160
|
+
emails: ['test@email.com'],
|
|
1161
|
+
phones: ['+1234567890'],
|
|
1162
|
+
},
|
|
1163
|
+
};
|
|
1164
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1165
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.NONE);
|
|
1166
|
+
expect(result.isCacheStale).toBe(false);
|
|
1167
|
+
expect(result.staleTraits).toEqual([]);
|
|
1168
|
+
});
|
|
1169
|
+
it('should return NONE tier with identical click info', () => {
|
|
1170
|
+
const incomingIdentity = {
|
|
1171
|
+
identityId: 'test-id',
|
|
1172
|
+
traits: {
|
|
1173
|
+
emails: ['test@email.com'],
|
|
1174
|
+
click: { gclid: 'same_gclid', fbp: 'fb.1.123.456' },
|
|
1175
|
+
},
|
|
1176
|
+
};
|
|
1177
|
+
const cachedIdentity = {
|
|
1178
|
+
identityId: 'test-id',
|
|
1179
|
+
traits: {
|
|
1180
|
+
emails: ['test@email.com'],
|
|
1181
|
+
click: { gclid: 'same_gclid', fbp: 'fb.1.123.456' },
|
|
1182
|
+
},
|
|
1183
|
+
};
|
|
1184
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1185
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.NONE);
|
|
1186
|
+
expect(result.isCacheStale).toBe(false);
|
|
1187
|
+
});
|
|
1188
|
+
});
|
|
1189
|
+
describe('VOLATILE_ONLY tier - treat as cache hit', () => {
|
|
1190
|
+
it('should return VOLATILE_ONLY tier when only ipAddress is new', () => {
|
|
1191
|
+
const incomingIdentity = {
|
|
1192
|
+
identityId: 'test-id',
|
|
1193
|
+
traits: {
|
|
1194
|
+
emails: ['test@email.com'],
|
|
1195
|
+
ipAddress: '10.0.0.1',
|
|
1196
|
+
},
|
|
1197
|
+
};
|
|
1198
|
+
const cachedIdentity = {
|
|
1199
|
+
identityId: 'test-id',
|
|
1200
|
+
traits: {
|
|
1201
|
+
emails: ['test@email.com'],
|
|
1202
|
+
},
|
|
1203
|
+
};
|
|
1204
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1205
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
|
|
1206
|
+
expect(result.isCacheStale).toBe(false);
|
|
1207
|
+
expect(result.staleTraits).toContain('ipAddress');
|
|
1208
|
+
});
|
|
1209
|
+
it('should return VOLATILE_ONLY tier when only userAgent is new', () => {
|
|
1210
|
+
const incomingIdentity = {
|
|
1211
|
+
identityId: 'test-id',
|
|
1212
|
+
traits: {
|
|
1213
|
+
emails: ['test@email.com'],
|
|
1214
|
+
userAgent: 'new-agent',
|
|
1215
|
+
},
|
|
1216
|
+
};
|
|
1217
|
+
const cachedIdentity = {
|
|
1218
|
+
identityId: 'test-id',
|
|
1219
|
+
traits: {
|
|
1220
|
+
emails: ['test@email.com'],
|
|
1221
|
+
},
|
|
1222
|
+
};
|
|
1223
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1224
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
|
|
1225
|
+
expect(result.isCacheStale).toBe(false);
|
|
1226
|
+
expect(result.staleTraits).toContain('userAgent');
|
|
1227
|
+
});
|
|
1228
|
+
it('should return VOLATILE_ONLY tier when only IP-sourced address is new', () => {
|
|
1229
|
+
const incomingIdentity = {
|
|
1230
|
+
identityId: 'test-id',
|
|
1231
|
+
traits: {
|
|
1232
|
+
emails: ['test@email.com'],
|
|
1233
|
+
addresses: [{ city: 'NewIPCity', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.IP_ADDRESS }],
|
|
1234
|
+
},
|
|
1235
|
+
};
|
|
1236
|
+
const cachedIdentity = {
|
|
1237
|
+
identityId: 'test-id',
|
|
1238
|
+
traits: {
|
|
1239
|
+
emails: ['test@email.com'],
|
|
1240
|
+
addresses: [],
|
|
1241
|
+
},
|
|
1242
|
+
};
|
|
1243
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1244
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
|
|
1245
|
+
expect(result.isCacheStale).toBe(false);
|
|
1246
|
+
});
|
|
1247
|
+
});
|
|
1248
|
+
describe('ADDRESS_UPDATE tier - cache write only, skip Neptune', () => {
|
|
1249
|
+
it('should return ADDRESS_UPDATE tier when non-IP address is new', () => {
|
|
1250
|
+
const incomingIdentity = {
|
|
1251
|
+
identityId: 'test-id',
|
|
1252
|
+
traits: {
|
|
1253
|
+
emails: ['test@email.com'],
|
|
1254
|
+
addresses: [{ city: 'Boston', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT }],
|
|
1255
|
+
},
|
|
1256
|
+
};
|
|
1257
|
+
const cachedIdentity = {
|
|
1258
|
+
identityId: 'test-id',
|
|
1259
|
+
traits: {
|
|
1260
|
+
emails: ['test@email.com'],
|
|
1261
|
+
addresses: [],
|
|
1262
|
+
},
|
|
1263
|
+
};
|
|
1264
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1265
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
|
|
1266
|
+
expect(result.isCacheStale).toBe(true);
|
|
1267
|
+
expect(result.staleTraits).toContain('addresses');
|
|
1268
|
+
});
|
|
1269
|
+
it('should return ADDRESS_UPDATE even with volatile traits stale', () => {
|
|
1270
|
+
const incomingIdentity = {
|
|
1271
|
+
identityId: 'test-id',
|
|
1272
|
+
traits: {
|
|
1273
|
+
emails: ['test@email.com'],
|
|
1274
|
+
ipAddress: '10.0.0.1',
|
|
1275
|
+
addresses: [{ city: 'Boston', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT }],
|
|
1276
|
+
},
|
|
1277
|
+
};
|
|
1278
|
+
const cachedIdentity = {
|
|
1279
|
+
identityId: 'test-id',
|
|
1280
|
+
traits: {
|
|
1281
|
+
emails: ['test@email.com'],
|
|
1282
|
+
ipAddress: '192.168.1.1',
|
|
1283
|
+
addresses: [],
|
|
1284
|
+
},
|
|
1285
|
+
};
|
|
1286
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1287
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
|
|
1288
|
+
expect(result.isCacheStale).toBe(true);
|
|
1289
|
+
});
|
|
1290
|
+
});
|
|
1291
|
+
describe('IDENTITY_STALE tier - full Neptune resolution', () => {
|
|
1292
|
+
it('should return IDENTITY_STALE tier when email is new', () => {
|
|
1293
|
+
const incomingIdentity = {
|
|
1294
|
+
identityId: 'test-id',
|
|
1295
|
+
traits: { emails: ['old@email.com', 'new@email.com'] },
|
|
1296
|
+
};
|
|
1297
|
+
const cachedIdentity = {
|
|
1298
|
+
identityId: 'test-id',
|
|
1299
|
+
traits: { emails: ['old@email.com'] },
|
|
1300
|
+
};
|
|
1301
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1302
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
1303
|
+
expect(result.isCacheStale).toBe(true);
|
|
1304
|
+
expect(result.staleTraits).toContain('emails');
|
|
1305
|
+
});
|
|
1306
|
+
it('should return IDENTITY_STALE tier when phone is new', () => {
|
|
1307
|
+
const incomingIdentity = {
|
|
1308
|
+
identityId: 'test-id',
|
|
1309
|
+
traits: { phones: ['+1234567890', '+9876543210'] },
|
|
1310
|
+
};
|
|
1311
|
+
const cachedIdentity = {
|
|
1312
|
+
identityId: 'test-id',
|
|
1313
|
+
traits: { phones: ['+1234567890'] },
|
|
1314
|
+
};
|
|
1315
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1316
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
1317
|
+
expect(result.isCacheStale).toBe(true);
|
|
1318
|
+
expect(result.staleTraits).toContain('phones');
|
|
1319
|
+
});
|
|
1320
|
+
it('should return IDENTITY_STALE tier when identityId changes', () => {
|
|
1321
|
+
const incomingIdentity = {
|
|
1322
|
+
identityId: 'new-id',
|
|
1323
|
+
traits: { emails: ['test@email.com'] },
|
|
1324
|
+
};
|
|
1325
|
+
const cachedIdentity = {
|
|
1326
|
+
identityId: 'old-id',
|
|
1327
|
+
traits: { emails: ['test@email.com'] },
|
|
1328
|
+
};
|
|
1329
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1330
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
1331
|
+
expect(result.isCacheStale).toBe(true);
|
|
1332
|
+
expect(result.staleTraits).toContain('identityId');
|
|
1333
|
+
});
|
|
1334
|
+
it('should return IDENTITY_STALE tier when click info is new', () => {
|
|
1335
|
+
const incomingIdentity = {
|
|
1336
|
+
identityId: 'test-id',
|
|
1337
|
+
traits: { click: { gclid: 'new_gclid' } },
|
|
1338
|
+
};
|
|
1339
|
+
const cachedIdentity = {
|
|
1340
|
+
identityId: 'test-id',
|
|
1341
|
+
traits: {},
|
|
1342
|
+
};
|
|
1343
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1344
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
1345
|
+
expect(result.isCacheStale).toBe(true);
|
|
1346
|
+
expect(result.staleTraits).toContain('clickInfos');
|
|
1347
|
+
});
|
|
1348
|
+
it('should return IDENTITY_STALE even with ADDRESS_UPDATE also present', () => {
|
|
1349
|
+
const incomingIdentity = {
|
|
1350
|
+
identityId: 'test-id',
|
|
1351
|
+
traits: {
|
|
1352
|
+
emails: ['old@email.com', 'new@email.com'],
|
|
1353
|
+
addresses: [{ city: 'Boston', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT }],
|
|
1354
|
+
},
|
|
1355
|
+
};
|
|
1356
|
+
const cachedIdentity = {
|
|
1357
|
+
identityId: 'test-id',
|
|
1358
|
+
traits: {
|
|
1359
|
+
emails: ['old@email.com'],
|
|
1360
|
+
addresses: [],
|
|
1361
|
+
},
|
|
1362
|
+
};
|
|
1363
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1364
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
1365
|
+
expect(result.isCacheStale).toBe(true);
|
|
1366
|
+
expect(result.staleTraits).toContain('emails');
|
|
1367
|
+
expect(result.staleTraits).toContain('addresses');
|
|
1368
|
+
});
|
|
1369
|
+
});
|
|
1370
|
+
describe('Merged identity structure', () => {
|
|
1371
|
+
it('should preserve incoming identityId in merged identity', () => {
|
|
1372
|
+
const incomingIdentity = {
|
|
1373
|
+
identityId: 'incoming-id',
|
|
1374
|
+
traits: { emails: ['test@email.com'] },
|
|
1375
|
+
};
|
|
1376
|
+
const cachedIdentity = {
|
|
1377
|
+
identityId: 'cached-id',
|
|
1378
|
+
traits: { phones: ['+1234567890'] },
|
|
1379
|
+
};
|
|
1380
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1381
|
+
expect(result.mergedIdentity.identityId).toBe('incoming-id');
|
|
1382
|
+
});
|
|
1383
|
+
it('should merge traits from both incoming and cached', () => {
|
|
1384
|
+
const incomingIdentity = {
|
|
1385
|
+
identityId: 'test-id',
|
|
1386
|
+
traits: {
|
|
1387
|
+
emails: ['incoming@email.com'],
|
|
1388
|
+
userIds: ['user1'],
|
|
1389
|
+
},
|
|
1390
|
+
};
|
|
1391
|
+
const cachedIdentity = {
|
|
1392
|
+
identityId: 'test-id',
|
|
1393
|
+
traits: {
|
|
1394
|
+
emails: ['cached@email.com'],
|
|
1395
|
+
phones: ['+1234567890'],
|
|
1396
|
+
},
|
|
1397
|
+
};
|
|
1398
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1399
|
+
expect(result.mergedIdentity.traits?.emails).toContain('incoming@email.com');
|
|
1400
|
+
expect(result.mergedIdentity.traits?.emails).toContain('cached@email.com');
|
|
1401
|
+
expect(result.mergedIdentity.traits?.userIds).toEqual(['user1']);
|
|
1402
|
+
expect(result.mergedIdentity.traits?.phones).toEqual(['+1234567890']);
|
|
1403
|
+
});
|
|
1404
|
+
});
|
|
1405
|
+
describe('staleTracker output', () => {
|
|
1406
|
+
it('should include full staleTracker with all flags', () => {
|
|
1407
|
+
const incomingIdentity = {
|
|
1408
|
+
identityId: 'test-id',
|
|
1409
|
+
traits: {
|
|
1410
|
+
emails: ['old@email.com', 'new@email.com'],
|
|
1411
|
+
ipAddress: '10.0.0.1',
|
|
1412
|
+
},
|
|
1413
|
+
};
|
|
1414
|
+
const cachedIdentity = {
|
|
1415
|
+
identityId: 'test-id',
|
|
1416
|
+
traits: {
|
|
1417
|
+
emails: ['old@email.com'],
|
|
1418
|
+
},
|
|
1419
|
+
};
|
|
1420
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1421
|
+
expect(result.staleTracker).toBeDefined();
|
|
1422
|
+
expect(result.staleTracker.isEmailsStale).toBe(true);
|
|
1423
|
+
expect(result.staleTracker.isIpAddressStale).toBe(true);
|
|
1424
|
+
expect(result.staleTracker.isPhonesStale).toBe(false);
|
|
1425
|
+
});
|
|
1426
|
+
});
|
|
1427
|
+
describe('Edge cases - empty traits', () => {
|
|
1428
|
+
it('should handle empty traits on incoming identity', () => {
|
|
1429
|
+
const incomingIdentity = {
|
|
1430
|
+
identityId: 'test-id',
|
|
1431
|
+
traits: {},
|
|
1432
|
+
};
|
|
1433
|
+
const cachedIdentity = {
|
|
1434
|
+
identityId: 'test-id',
|
|
1435
|
+
traits: {
|
|
1436
|
+
emails: ['cached@email.com'],
|
|
1437
|
+
phones: ['+1234567890'],
|
|
1438
|
+
userIds: ['user1'],
|
|
1439
|
+
},
|
|
1440
|
+
};
|
|
1441
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1442
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.NONE);
|
|
1443
|
+
expect(result.isCacheStale).toBe(false);
|
|
1444
|
+
expect(result.staleTraits).toEqual([]);
|
|
1445
|
+
expect(result.mergedIdentity.traits?.emails).toEqual(['cached@email.com']);
|
|
1446
|
+
expect(result.mergedIdentity.traits?.phones).toEqual(['+1234567890']);
|
|
1447
|
+
expect(result.mergedIdentity.traits?.userIds).toEqual(['user1']);
|
|
1448
|
+
});
|
|
1449
|
+
it('should handle empty traits on cached identity', () => {
|
|
1450
|
+
const incomingIdentity = {
|
|
1451
|
+
identityId: 'test-id',
|
|
1452
|
+
traits: {
|
|
1453
|
+
emails: ['new@email.com'],
|
|
1454
|
+
phones: ['+1234567890'],
|
|
1455
|
+
},
|
|
1456
|
+
};
|
|
1457
|
+
const cachedIdentity = {
|
|
1458
|
+
identityId: 'test-id',
|
|
1459
|
+
traits: {},
|
|
1460
|
+
};
|
|
1461
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1462
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
1463
|
+
expect(result.isCacheStale).toBe(true);
|
|
1464
|
+
expect(result.staleTraits).toContain('emails');
|
|
1465
|
+
expect(result.staleTraits).toContain('phones');
|
|
1466
|
+
expect(result.mergedIdentity.traits?.emails).toEqual(['new@email.com']);
|
|
1467
|
+
expect(result.mergedIdentity.traits?.phones).toEqual(['+1234567890']);
|
|
1468
|
+
});
|
|
1469
|
+
it('should handle both identities with empty traits', () => {
|
|
1470
|
+
const incomingIdentity = {
|
|
1471
|
+
identityId: 'test-id',
|
|
1472
|
+
traits: {},
|
|
1473
|
+
};
|
|
1474
|
+
const cachedIdentity = {
|
|
1475
|
+
identityId: 'test-id',
|
|
1476
|
+
traits: {},
|
|
1477
|
+
};
|
|
1478
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1479
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.NONE);
|
|
1480
|
+
expect(result.isCacheStale).toBe(false);
|
|
1481
|
+
expect(result.staleTraits).toEqual([]);
|
|
1482
|
+
});
|
|
1483
|
+
});
|
|
1484
|
+
describe('Edge cases - null/undefined handling', () => {
|
|
1485
|
+
it('should handle undefined traits on incoming identity', () => {
|
|
1486
|
+
const incomingIdentity = {
|
|
1487
|
+
identityId: 'test-id',
|
|
1488
|
+
};
|
|
1489
|
+
const cachedIdentity = {
|
|
1490
|
+
identityId: 'test-id',
|
|
1491
|
+
traits: {
|
|
1492
|
+
emails: ['cached@email.com'],
|
|
1493
|
+
},
|
|
1494
|
+
};
|
|
1495
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1496
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.NONE);
|
|
1497
|
+
expect(result.isCacheStale).toBe(false);
|
|
1498
|
+
});
|
|
1499
|
+
it('should handle undefined traits on cached identity', () => {
|
|
1500
|
+
const incomingIdentity = {
|
|
1501
|
+
identityId: 'test-id',
|
|
1502
|
+
traits: {
|
|
1503
|
+
emails: ['new@email.com'],
|
|
1504
|
+
},
|
|
1505
|
+
};
|
|
1506
|
+
const cachedIdentity = {
|
|
1507
|
+
identityId: 'test-id',
|
|
1508
|
+
};
|
|
1509
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1510
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
1511
|
+
expect(result.isCacheStale).toBe(true);
|
|
1512
|
+
expect(result.staleTraits).toContain('emails');
|
|
1513
|
+
});
|
|
1514
|
+
it('should handle both identities with undefined traits', () => {
|
|
1515
|
+
const incomingIdentity = {
|
|
1516
|
+
identityId: 'test-id',
|
|
1517
|
+
};
|
|
1518
|
+
const cachedIdentity = {
|
|
1519
|
+
identityId: 'test-id',
|
|
1520
|
+
};
|
|
1521
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1522
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.NONE);
|
|
1523
|
+
expect(result.isCacheStale).toBe(false);
|
|
1524
|
+
expect(result.staleTraits).toEqual([]);
|
|
1525
|
+
});
|
|
1526
|
+
it('should handle null values in array traits gracefully', () => {
|
|
1527
|
+
const incomingIdentity = {
|
|
1528
|
+
identityId: 'test-id',
|
|
1529
|
+
traits: {
|
|
1530
|
+
emails: ['valid@email.com', null, 'new@email.com'],
|
|
1531
|
+
},
|
|
1532
|
+
};
|
|
1533
|
+
const cachedIdentity = {
|
|
1534
|
+
identityId: 'test-id',
|
|
1535
|
+
traits: {
|
|
1536
|
+
emails: ['valid@email.com'],
|
|
1537
|
+
},
|
|
1538
|
+
};
|
|
1539
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1540
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
1541
|
+
expect(result.isCacheStale).toBe(true);
|
|
1542
|
+
});
|
|
1543
|
+
});
|
|
1544
|
+
describe('Edge cases - click trait merging', () => {
|
|
1545
|
+
it('should detect staleness when incoming has new click info', () => {
|
|
1546
|
+
const incomingIdentity = {
|
|
1547
|
+
identityId: 'test-id',
|
|
1548
|
+
traits: {
|
|
1549
|
+
click: {
|
|
1550
|
+
gclid: 'new_gclid',
|
|
1551
|
+
fbp: 'fb.1.new.123',
|
|
1552
|
+
},
|
|
1553
|
+
},
|
|
1554
|
+
};
|
|
1555
|
+
const cachedIdentity = {
|
|
1556
|
+
identityId: 'test-id',
|
|
1557
|
+
traits: {},
|
|
1558
|
+
};
|
|
1559
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1560
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
1561
|
+
expect(result.isCacheStale).toBe(true);
|
|
1562
|
+
expect(result.staleTraits).toContain('clickInfos');
|
|
1563
|
+
});
|
|
1564
|
+
it('should preserve cached click info when merging', () => {
|
|
1565
|
+
const incomingIdentity = {
|
|
1566
|
+
identityId: 'test-id',
|
|
1567
|
+
traits: {
|
|
1568
|
+
click: {
|
|
1569
|
+
gclid: 'incoming_gclid',
|
|
1570
|
+
},
|
|
1571
|
+
},
|
|
1572
|
+
};
|
|
1573
|
+
const cachedIdentity = {
|
|
1574
|
+
identityId: 'test-id',
|
|
1575
|
+
traits: {
|
|
1576
|
+
click: {
|
|
1577
|
+
gclid: 'cached_gclid',
|
|
1578
|
+
fbp: 'fb.1.cached.456',
|
|
1579
|
+
},
|
|
1580
|
+
},
|
|
1581
|
+
};
|
|
1582
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1583
|
+
expect(result.mergedIdentity.traits?.click?.gclid).toBe('cached_gclid');
|
|
1584
|
+
expect(result.mergedIdentity.traits?.click?.fbp).toBe('fb.1.cached.456');
|
|
1585
|
+
});
|
|
1586
|
+
it('should not be stale when click timestamps differ but values are same', () => {
|
|
1587
|
+
const incomingIdentity = {
|
|
1588
|
+
identityId: 'test-id',
|
|
1589
|
+
traits: {
|
|
1590
|
+
click: {
|
|
1591
|
+
fbp: 'fb.1.same.123',
|
|
1592
|
+
fbpCollectedAt: '2024-06-01T00:00:00Z',
|
|
1593
|
+
},
|
|
1594
|
+
},
|
|
1595
|
+
};
|
|
1596
|
+
const cachedIdentity = {
|
|
1597
|
+
identityId: 'test-id',
|
|
1598
|
+
traits: {
|
|
1599
|
+
click: {
|
|
1600
|
+
fbp: 'fb.1.same.123',
|
|
1601
|
+
fbpCollectedAt: '2024-01-01T00:00:00Z',
|
|
1602
|
+
},
|
|
1603
|
+
},
|
|
1604
|
+
};
|
|
1605
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1606
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.NONE);
|
|
1607
|
+
expect(result.isCacheStale).toBe(false);
|
|
1608
|
+
});
|
|
1609
|
+
it('should detect staleness when fbc changes (incoming has new fbc, cached has none)', () => {
|
|
1610
|
+
const incomingIdentity = {
|
|
1611
|
+
identityId: 'test-id',
|
|
1612
|
+
traits: {
|
|
1613
|
+
click: {
|
|
1614
|
+
fbc: 'fb.1.1234.new_fbclid',
|
|
1615
|
+
},
|
|
1616
|
+
},
|
|
1617
|
+
};
|
|
1618
|
+
const cachedIdentity = {
|
|
1619
|
+
identityId: 'test-id',
|
|
1620
|
+
traits: {
|
|
1621
|
+
click: {},
|
|
1622
|
+
},
|
|
1623
|
+
};
|
|
1624
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1625
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
1626
|
+
expect(result.isCacheStale).toBe(true);
|
|
1627
|
+
expect(result.staleTraits).toContain('clickInfos');
|
|
1628
|
+
});
|
|
1629
|
+
});
|
|
1630
|
+
describe('staleTraits extraction comprehensive tests', () => {
|
|
1631
|
+
it('should return empty array when NONE tier', () => {
|
|
1632
|
+
const incomingIdentity = {
|
|
1633
|
+
identityId: 'test-id',
|
|
1634
|
+
traits: { emails: ['test@email.com'] },
|
|
1635
|
+
};
|
|
1636
|
+
const cachedIdentity = {
|
|
1637
|
+
identityId: 'test-id',
|
|
1638
|
+
traits: { emails: ['test@email.com', 'other@email.com'] },
|
|
1639
|
+
};
|
|
1640
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1641
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.NONE);
|
|
1642
|
+
expect(result.staleTraits).toEqual([]);
|
|
1643
|
+
});
|
|
1644
|
+
it('should return volatile trait names for VOLATILE_ONLY tier', () => {
|
|
1645
|
+
const incomingIdentity = {
|
|
1646
|
+
identityId: 'test-id',
|
|
1647
|
+
traits: {
|
|
1648
|
+
emails: ['test@email.com'],
|
|
1649
|
+
ipAddress: '10.0.0.1',
|
|
1650
|
+
userAgent: 'new-agent',
|
|
1651
|
+
},
|
|
1652
|
+
};
|
|
1653
|
+
const cachedIdentity = {
|
|
1654
|
+
identityId: 'test-id',
|
|
1655
|
+
traits: {
|
|
1656
|
+
emails: ['test@email.com'],
|
|
1657
|
+
},
|
|
1658
|
+
};
|
|
1659
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1660
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.VOLATILE_ONLY);
|
|
1661
|
+
expect(result.staleTraits).toContain('ipAddress');
|
|
1662
|
+
expect(result.staleTraits).toContain('userAgent');
|
|
1663
|
+
expect(result.staleTraits).not.toContain('emails');
|
|
1664
|
+
});
|
|
1665
|
+
it('should return address trait name for ADDRESS_UPDATE tier', () => {
|
|
1666
|
+
const incomingIdentity = {
|
|
1667
|
+
identityId: 'test-id',
|
|
1668
|
+
traits: {
|
|
1669
|
+
emails: ['test@email.com'],
|
|
1670
|
+
addresses: [{ city: 'Boston', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT }],
|
|
1671
|
+
},
|
|
1672
|
+
};
|
|
1673
|
+
const cachedIdentity = {
|
|
1674
|
+
identityId: 'test-id',
|
|
1675
|
+
traits: {
|
|
1676
|
+
emails: ['test@email.com'],
|
|
1677
|
+
addresses: [],
|
|
1678
|
+
},
|
|
1679
|
+
};
|
|
1680
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1681
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.ADDRESS_UPDATE);
|
|
1682
|
+
expect(result.staleTraits).toContain('addresses');
|
|
1683
|
+
});
|
|
1684
|
+
it('should return all stale identity trait names for IDENTITY_STALE tier', () => {
|
|
1685
|
+
const incomingIdentity = {
|
|
1686
|
+
identityId: 'test-id',
|
|
1687
|
+
traits: {
|
|
1688
|
+
emails: ['old@email.com', 'new@email.com'],
|
|
1689
|
+
phones: ['+1234567890', '+9876543210'],
|
|
1690
|
+
userIds: ['user1', 'user2'],
|
|
1691
|
+
},
|
|
1692
|
+
};
|
|
1693
|
+
const cachedIdentity = {
|
|
1694
|
+
identityId: 'test-id',
|
|
1695
|
+
traits: {
|
|
1696
|
+
emails: ['old@email.com'],
|
|
1697
|
+
phones: ['+1234567890'],
|
|
1698
|
+
userIds: ['user1'],
|
|
1699
|
+
},
|
|
1700
|
+
};
|
|
1701
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1702
|
+
expect(result.staleTier).toBe(at_shared_utils_1.IDENTITY_CACHE_STALENESS_TIER.IDENTITY_STALE);
|
|
1703
|
+
expect(result.staleTraits).toContain('emails');
|
|
1704
|
+
expect(result.staleTraits).toContain('phones');
|
|
1705
|
+
expect(result.staleTraits).toContain('userIds');
|
|
1706
|
+
});
|
|
1707
|
+
});
|
|
1708
|
+
describe('Merge behavior verification', () => {
|
|
1709
|
+
it('should merge incoming and cached array traits (emails, phones, userIds)', () => {
|
|
1710
|
+
const incomingIdentity = {
|
|
1711
|
+
identityId: 'incoming-id',
|
|
1712
|
+
traits: {
|
|
1713
|
+
emails: ['incoming@email.com', 'shared@email.com'],
|
|
1714
|
+
userIds: ['incominguser'],
|
|
1715
|
+
},
|
|
1716
|
+
};
|
|
1717
|
+
const cachedIdentity = {
|
|
1718
|
+
identityId: 'cached-id',
|
|
1719
|
+
traits: {
|
|
1720
|
+
emails: ['cached@email.com', 'shared@email.com'],
|
|
1721
|
+
phones: ['+1234567890'],
|
|
1722
|
+
userIds: ['cacheduser'],
|
|
1723
|
+
},
|
|
1724
|
+
};
|
|
1725
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1726
|
+
expect(result.mergedIdentity.traits?.emails).toContain('incoming@email.com');
|
|
1727
|
+
expect(result.mergedIdentity.traits?.emails).toContain('cached@email.com');
|
|
1728
|
+
expect(result.mergedIdentity.traits?.emails).toContain('shared@email.com');
|
|
1729
|
+
expect(result.mergedIdentity.traits?.phones).toEqual(['+1234567890']);
|
|
1730
|
+
expect(result.mergedIdentity.traits?.userIds).toContain('incominguser');
|
|
1731
|
+
expect(result.mergedIdentity.traits?.userIds).toContain('cacheduser');
|
|
1732
|
+
});
|
|
1733
|
+
it('should preserve identityId from incoming identity', () => {
|
|
1734
|
+
const incomingIdentity = {
|
|
1735
|
+
identityId: 'incoming-id-123',
|
|
1736
|
+
traits: { emails: ['test@email.com'] },
|
|
1737
|
+
};
|
|
1738
|
+
const cachedIdentity = {
|
|
1739
|
+
identityId: 'cached-id-456',
|
|
1740
|
+
traits: { phones: ['+1234567890'] },
|
|
1741
|
+
};
|
|
1742
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1743
|
+
expect(result.mergedIdentity.identityId).toBe('incoming-id-123');
|
|
1744
|
+
});
|
|
1745
|
+
it('should merge addresses from both identities', () => {
|
|
1746
|
+
const incomingIdentity = {
|
|
1747
|
+
identityId: 'test-id',
|
|
1748
|
+
traits: {
|
|
1749
|
+
addresses: [
|
|
1750
|
+
{ city: 'IncomingCity', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT },
|
|
1751
|
+
],
|
|
1752
|
+
},
|
|
1753
|
+
};
|
|
1754
|
+
const cachedIdentity = {
|
|
1755
|
+
identityId: 'test-id',
|
|
1756
|
+
traits: {
|
|
1757
|
+
addresses: [
|
|
1758
|
+
{ city: 'CachedCity', s: at_tracking_event_types_1.ADDRESS_INFO_SOURCE.INPUT },
|
|
1759
|
+
],
|
|
1760
|
+
},
|
|
1761
|
+
};
|
|
1762
|
+
const result = (0, at_shared_utils_1.mergeAndComputeIdentityStaleness)(incomingIdentity, cachedIdentity);
|
|
1763
|
+
expect(result.mergedIdentity.traits?.addresses).toHaveLength(2);
|
|
1764
|
+
expect(result.mergedIdentity.traits?.addresses).toEqual(expect.arrayContaining([
|
|
1765
|
+
expect.objectContaining({ city: 'IncomingCity' }),
|
|
1766
|
+
expect.objectContaining({ city: 'CachedCity' }),
|
|
1767
|
+
]));
|
|
1768
|
+
});
|
|
1769
|
+
});
|
|
1770
|
+
});
|
|
1771
1771
|
//# sourceMappingURL=trait-merging-and-staleness.spec.js.map
|