@adtrackify/at-service-common 3.1.48 → 3.1.49
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__/identity-cache/identity-cache-db-service.spec.d.ts +1 -1
- package/dist/cjs/__tests__/identity-cache/identity-cache-db-service.spec.js +527 -527
- 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__/s3-client/s3-client.spec.d.ts +1 -1
- package/dist/cjs/__tests__/s3-client/s3-client.spec.js +26 -26
- package/dist/cjs/clients/generic/cognito-client.d.ts +22 -22
- package/dist/cjs/clients/generic/cognito-client.js +175 -175
- package/dist/cjs/clients/generic/dynamodb-client.d.ts +17 -17
- package/dist/cjs/clients/generic/dynamodb-client.js +167 -167
- package/dist/cjs/clients/generic/eventbridge-client.d.ts +14 -14
- package/dist/cjs/clients/generic/eventbridge-client.js +49 -49
- package/dist/cjs/clients/generic/http-client.d.ts +88 -88
- package/dist/cjs/clients/generic/http-client.js +60 -60
- package/dist/cjs/clients/generic/index.d.ts +10 -10
- package/dist/cjs/clients/generic/index.js +26 -26
- package/dist/cjs/clients/generic/lambda-invoke-client.d.ts +10 -10
- package/dist/cjs/clients/generic/lambda-invoke-client.js +35 -35
- 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 +18 -18
- package/dist/cjs/clients/generic/redis-client.js +128 -128
- package/dist/cjs/clients/generic/s3-client.d.ts +16 -16
- package/dist/cjs/clients/generic/s3-client.js +110 -110
- package/dist/cjs/clients/generic/singlestore-db-client.d.ts +14 -14
- package/dist/cjs/clients/generic/singlestore-db-client.js +67 -67
- package/dist/cjs/clients/generic/sqs-client.d.ts +20 -20
- package/dist/cjs/clients/generic/sqs-client.js +36 -36
- 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 +112 -112
- package/dist/cjs/clients/internal-api/accounts-client.js +117 -117
- package/dist/cjs/clients/internal-api/cache-lambda-client.d.ts +25 -25
- package/dist/cjs/clients/internal-api/cache-lambda-client.js +79 -79
- package/dist/cjs/clients/internal-api/db-management-client.d.ts +18 -18
- package/dist/cjs/clients/internal-api/db-management-client.js +39 -39
- package/dist/cjs/clients/internal-api/destinations-client.d.ts +29 -29
- package/dist/cjs/clients/internal-api/destinations-client.js +54 -54
- package/dist/cjs/clients/internal-api/event-collector-client.d.ts +20 -20
- package/dist/cjs/clients/internal-api/event-collector-client.js +39 -39
- package/dist/cjs/clients/internal-api/identity-client.d.ts +25 -25
- package/dist/cjs/clients/internal-api/identity-client.js +92 -92
- package/dist/cjs/clients/internal-api/identity-client.js.map +1 -1
- package/dist/cjs/clients/internal-api/index.d.ts +8 -8
- package/dist/cjs/clients/internal-api/index.js +24 -24
- package/dist/cjs/clients/internal-api/shopify-app-install-client.d.ts +34 -34
- package/dist/cjs/clients/internal-api/shopify-app-install-client.js +63 -63
- 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/index.d.ts +1 -1
- package/dist/cjs/clients/third-party/index.js +17 -17
- 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 +180 -180
- package/dist/cjs/clients/third-party/shopify/shopify-graphql-client.d.ts +9 -9
- package/dist/cjs/clients/third-party/shopify/shopify-graphql-client.js +95 -95
- package/dist/cjs/clients/third-party/shopify-client.d.ts +198 -198
- package/dist/cjs/clients/third-party/shopify-client.js +150 -150
- package/dist/cjs/helpers/identity-cache-helper.d.ts +4 -4
- package/dist/cjs/helpers/identity-cache-helper.js +150 -150
- package/dist/cjs/helpers/index.d.ts +5 -5
- package/dist/cjs/helpers/index.js +21 -21
- 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/response-helper.d.ts +15 -15
- package/dist/cjs/helpers/response-helper.js +42 -42
- package/dist/cjs/helpers/shopify-helper.d.ts +9 -9
- package/dist/cjs/helpers/shopify-helper.js +28 -28
- package/dist/cjs/index.d.ts +5 -5
- package/dist/cjs/index.js +21 -21
- package/dist/cjs/libs/clickId-parser.d.ts +23 -23
- package/dist/cjs/libs/clickId-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/crypto.d.ts +1 -1
- package/dist/cjs/libs/crypto.js +12 -12
- package/dist/cjs/libs/dates.d.ts +6 -6
- package/dist/cjs/libs/dates.js +31 -31
- package/dist/cjs/libs/http-error.d.ts +21 -21
- package/dist/cjs/libs/http-error.js +59 -59
- 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 +9 -9
- package/dist/cjs/libs/index.js +25 -25
- 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 +4712 -4712
- package/dist/cjs/libs/referrer-parser/referrer-parser-util.d.ts +20 -20
- package/dist/cjs/libs/referrer-parser/referrer-parser-util.js +128 -128
- package/dist/cjs/libs/url.d.ts +1 -1
- package/dist/cjs/libs/url.js +13 -13
- 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 +68 -68
- package/dist/cjs/services/db/destinations-db-service.d.ts +9 -9
- package/dist/cjs/services/db/destinations-db-service.js +57 -57
- package/dist/cjs/services/db/identity-cache-db-service.d.ts +24 -24
- package/dist/cjs/services/db/identity-cache-db-service.js +233 -233
- package/dist/cjs/services/db/index.d.ts +7 -7
- package/dist/cjs/services/db/index.js +23 -23
- package/dist/cjs/services/db/log-events-db-service.d.ts +11 -11
- package/dist/cjs/services/db/log-events-db-service.js +172 -172
- package/dist/cjs/services/db/purchased-contacts-db-service.d.ts +9 -9
- package/dist/cjs/services/db/purchased-contacts-db-service.js +38 -38
- package/dist/cjs/services/db/shopify-app-installs-db-service.d.ts +7 -7
- package/dist/cjs/services/db/shopify-app-installs-db-service.js +47 -47
- 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 +65 -65
- package/dist/cjs/services/db/tracking-events-db-service.d.ts +20 -20
- package/dist/cjs/services/db/tracking-events-db-service.js +162 -162
- 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/generic-cache-service.d.ts +7 -7
- package/dist/cjs/services/generic-cache-service.js +33 -33
- package/dist/cjs/services/index.d.ts +8 -8
- package/dist/cjs/services/index.js +24 -24
- package/dist/cjs/services/ipdata-lookup-service.d.ts +19 -19
- package/dist/cjs/services/ipdata-lookup-service.js +77 -77
- package/dist/cjs/services/log-event-service.d.ts +9 -9
- package/dist/cjs/services/log-event-service.js +56 -56
- package/dist/cjs/services/metric-event-service.d.ts +9 -9
- package/dist/cjs/services/metric-event-service.js +49 -49
- package/dist/cjs/services/shopify/index.d.ts +3 -3
- package/dist/cjs/services/shopify/index.js +19 -19
- 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 +103 -103
- package/dist/cjs/services/shopify/products/shopify-products-serviceV2.js.map +1 -1
- package/dist/cjs/services/shopify/shopify-graphql-transformer.d.ts +9 -9
- package/dist/cjs/services/shopify/shopify-graphql-transformer.js +130 -130
- package/dist/cjs/services/shopify/types/index.d.ts +1 -1
- package/dist/cjs/services/shopify/types/index.js +17 -17
- package/dist/cjs/services/shopify/types/product.d.ts +115 -115
- package/dist/cjs/services/shopify/types/product.js +9 -9
- 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 +2 -2
- package/dist/cjs/types/index.js +18 -18
- 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/shopify-graphql-types/admin.generated.d.ts +105 -105
- 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/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 +525 -525
- 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__/s3-client/s3-client.spec.d.ts +1 -1
- package/dist/esm/__tests__/s3-client/s3-client.spec.js +24 -24
- package/dist/esm/clients/generic/cognito-client.d.ts +22 -22
- package/dist/esm/clients/generic/cognito-client.js +170 -170
- package/dist/esm/clients/generic/dynamodb-client.d.ts +17 -17
- package/dist/esm/clients/generic/dynamodb-client.js +163 -163
- package/dist/esm/clients/generic/eventbridge-client.d.ts +14 -14
- package/dist/esm/clients/generic/eventbridge-client.js +45 -45
- package/dist/esm/clients/generic/http-client.d.ts +88 -88
- package/dist/esm/clients/generic/http-client.js +52 -52
- package/dist/esm/clients/generic/index.d.ts +10 -10
- package/dist/esm/clients/generic/index.js +10 -10
- package/dist/esm/clients/generic/lambda-invoke-client.d.ts +10 -10
- package/dist/esm/clients/generic/lambda-invoke-client.js +31 -31
- 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 +18 -18
- package/dist/esm/clients/generic/redis-client.js +121 -121
- package/dist/esm/clients/generic/s3-client.d.ts +16 -16
- package/dist/esm/clients/generic/s3-client.js +106 -106
- package/dist/esm/clients/generic/singlestore-db-client.d.ts +14 -14
- package/dist/esm/clients/generic/singlestore-db-client.js +40 -40
- package/dist/esm/clients/generic/sqs-client.d.ts +20 -20
- package/dist/esm/clients/generic/sqs-client.js +32 -32
- 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 +112 -112
- package/dist/esm/clients/internal-api/accounts-client.js +113 -113
- package/dist/esm/clients/internal-api/cache-lambda-client.d.ts +25 -25
- package/dist/esm/clients/internal-api/cache-lambda-client.js +75 -75
- 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 +29 -29
- package/dist/esm/clients/internal-api/destinations-client.js +50 -50
- package/dist/esm/clients/internal-api/event-collector-client.d.ts +20 -20
- package/dist/esm/clients/internal-api/event-collector-client.js +32 -32
- package/dist/esm/clients/internal-api/identity-client.d.ts +25 -25
- package/dist/esm/clients/internal-api/identity-client.js +88 -88
- package/dist/esm/clients/internal-api/identity-client.js.map +1 -1
- package/dist/esm/clients/internal-api/index.d.ts +8 -8
- package/dist/esm/clients/internal-api/index.js +8 -8
- package/dist/esm/clients/internal-api/shopify-app-install-client.d.ts +34 -34
- package/dist/esm/clients/internal-api/shopify-app-install-client.js +56 -56
- 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/index.d.ts +1 -1
- package/dist/esm/clients/third-party/index.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 +177 -177
- package/dist/esm/clients/third-party/shopify/shopify-graphql-client.d.ts +9 -9
- package/dist/esm/clients/third-party/shopify/shopify-graphql-client.js +91 -91
- package/dist/esm/clients/third-party/shopify-client.d.ts +198 -198
- package/dist/esm/clients/third-party/shopify-client.js +146 -146
- package/dist/esm/helpers/identity-cache-helper.d.ts +4 -4
- package/dist/esm/helpers/identity-cache-helper.js +145 -145
- package/dist/esm/helpers/index.d.ts +5 -5
- package/dist/esm/helpers/index.js +5 -5
- 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/response-helper.d.ts +15 -15
- package/dist/esm/helpers/response-helper.js +36 -36
- package/dist/esm/helpers/shopify-helper.d.ts +9 -9
- package/dist/esm/helpers/shopify-helper.js +23 -23
- package/dist/esm/index.d.ts +5 -5
- package/dist/esm/index.js +5 -5
- package/dist/esm/libs/clickId-parser.d.ts +23 -23
- package/dist/esm/libs/clickId-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/crypto.d.ts +1 -1
- package/dist/esm/libs/crypto.js +5 -5
- package/dist/esm/libs/dates.d.ts +6 -6
- package/dist/esm/libs/dates.js +22 -22
- package/dist/esm/libs/http-error.d.ts +21 -21
- package/dist/esm/libs/http-error.js +55 -55
- 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 +9 -9
- package/dist/esm/libs/index.js +9 -9
- 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 +4709 -4709
- package/dist/esm/libs/referrer-parser/referrer-parser-util.d.ts +20 -20
- package/dist/esm/libs/referrer-parser/referrer-parser-util.js +121 -121
- package/dist/esm/libs/url.d.ts +1 -1
- package/dist/esm/libs/url.js +9 -9
- 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 +60 -60
- package/dist/esm/services/db/destinations-db-service.d.ts +9 -9
- package/dist/esm/services/db/destinations-db-service.js +53 -53
- package/dist/esm/services/db/identity-cache-db-service.d.ts +24 -24
- package/dist/esm/services/db/identity-cache-db-service.js +229 -229
- package/dist/esm/services/db/index.d.ts +7 -7
- package/dist/esm/services/db/index.js +7 -7
- package/dist/esm/services/db/log-events-db-service.d.ts +11 -11
- package/dist/esm/services/db/log-events-db-service.js +168 -168
- package/dist/esm/services/db/purchased-contacts-db-service.d.ts +9 -9
- package/dist/esm/services/db/purchased-contacts-db-service.js +34 -34
- package/dist/esm/services/db/shopify-app-installs-db-service.d.ts +7 -7
- package/dist/esm/services/db/shopify-app-installs-db-service.js +43 -43
- 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 +58 -58
- package/dist/esm/services/db/tracking-events-db-service.d.ts +20 -20
- package/dist/esm/services/db/tracking-events-db-service.js +158 -158
- 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/generic-cache-service.d.ts +7 -7
- package/dist/esm/services/generic-cache-service.js +29 -29
- package/dist/esm/services/index.d.ts +8 -8
- package/dist/esm/services/index.js +8 -8
- package/dist/esm/services/ipdata-lookup-service.d.ts +19 -19
- package/dist/esm/services/ipdata-lookup-service.js +73 -73
- package/dist/esm/services/log-event-service.d.ts +9 -9
- package/dist/esm/services/log-event-service.js +52 -52
- package/dist/esm/services/metric-event-service.d.ts +9 -9
- package/dist/esm/services/metric-event-service.js +45 -45
- package/dist/esm/services/shopify/index.d.ts +3 -3
- package/dist/esm/services/shopify/index.js +3 -3
- 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 +99 -99
- package/dist/esm/services/shopify/products/shopify-products-serviceV2.js.map +1 -1
- package/dist/esm/services/shopify/shopify-graphql-transformer.d.ts +9 -9
- package/dist/esm/services/shopify/shopify-graphql-transformer.js +127 -127
- package/dist/esm/services/shopify/types/index.d.ts +1 -1
- package/dist/esm/services/shopify/types/index.js +1 -1
- package/dist/esm/services/shopify/types/product.d.ts +115 -115
- package/dist/esm/services/shopify/types/product.js +6 -6
- 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 +2 -2
- package/dist/esm/types/index.js +2 -2
- 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/shopify-graphql-types/admin.generated.d.ts +105 -105
- 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/package.json +123 -123
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
import { DynamoDbClient } from '../../clients';
|
|
2
|
-
import { compressJSON, decompressJSON, getCurrentTimestamp } from '../../libs';
|
|
3
|
-
import { DateTime } from 'luxon';
|
|
4
|
-
import { Logger } from '../../helpers';
|
|
5
|
-
import crypto from 'crypto';
|
|
6
|
-
const DEFAULT_TTL_IN_SECONDS = 7 * 24 * 3600;
|
|
7
|
-
export class ShopifyProductsCacheDbService {
|
|
8
|
-
TABLE_NAME;
|
|
9
|
-
KEY_NAME;
|
|
10
|
-
dynamoDbCacheTtlInSeconds;
|
|
11
|
-
constructor(tableName, keyName, dynamoDbCacheTtlInSeconds) {
|
|
12
|
-
this.TABLE_NAME = tableName;
|
|
13
|
-
this.KEY_NAME = keyName;
|
|
14
|
-
this.dynamoDbCacheTtlInSeconds = dynamoDbCacheTtlInSeconds || DEFAULT_TTL_IN_SECONDS;
|
|
15
|
-
}
|
|
16
|
-
getProductFromDynamoDBCache = async (pixelId, productId) => {
|
|
17
|
-
try {
|
|
18
|
-
const cachedProduct = await DynamoDbClient.safeGet(this.TABLE_NAME, this.KEY_NAME, `${pixelId}_${productId}`);
|
|
19
|
-
if (cachedProduct && !this.isProductCacheStale(cachedProduct)) {
|
|
20
|
-
const product = decompressJSON(cachedProduct.productCompressed);
|
|
21
|
-
return product;
|
|
22
|
-
}
|
|
23
|
-
return undefined;
|
|
24
|
-
}
|
|
25
|
-
catch (error) {
|
|
26
|
-
Logger.error('Failed getShopifyProductCacheREST', { keyName: this.KEY_NAME, pixelId, productId, error });
|
|
27
|
-
return undefined;
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
putProductInDynamoDBCache = async (pixelId, productId, product, ttlInSeconds) => {
|
|
31
|
-
const ttl = ttlInSeconds || this.dynamoDbCacheTtlInSeconds;
|
|
32
|
-
const expiresAt = DateTime.utc().plus({ seconds: ttl }).toSeconds();
|
|
33
|
-
const cachedAt = getCurrentTimestamp();
|
|
34
|
-
const cachedAtEpoch = DateTime.utc().toSeconds();
|
|
35
|
-
const fullSha256 = crypto.createHash('sha256').update(JSON.stringify(product)).digest('hex');
|
|
36
|
-
const noInventoryProduct = { ...product, totalInventory: undefined, variants: product?.variants?.map(variant => ({ ...variant, inventoryQuantity: undefined, inventoryItem: undefined })) };
|
|
37
|
-
const noInventorySha256 = crypto.createHash('sha256').update(JSON.stringify(noInventoryProduct)).digest('hex');
|
|
38
|
-
const productCompressed = compressJSON(product);
|
|
39
|
-
const shopifyProductCache = {
|
|
40
|
-
pixelId_productId: `${pixelId}_${productId}`,
|
|
41
|
-
pixelId,
|
|
42
|
-
productId,
|
|
43
|
-
productCompressed,
|
|
44
|
-
fullSha256,
|
|
45
|
-
noInventorySha256,
|
|
46
|
-
cachedAt,
|
|
47
|
-
cachedAtEpoch,
|
|
48
|
-
expiresAt
|
|
49
|
-
};
|
|
50
|
-
return await DynamoDbClient.safePut(this.TABLE_NAME, shopifyProductCache);
|
|
51
|
-
};
|
|
52
|
-
isProductCacheStale = (cachedData) => {
|
|
53
|
-
if (cachedData?.expiresAt && cachedData.expiresAt < DateTime.utc().toSeconds()) {
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
return false;
|
|
57
|
-
};
|
|
58
|
-
}
|
|
1
|
+
import { DynamoDbClient } from '../../clients';
|
|
2
|
+
import { compressJSON, decompressJSON, getCurrentTimestamp } from '../../libs';
|
|
3
|
+
import { DateTime } from 'luxon';
|
|
4
|
+
import { Logger } from '../../helpers';
|
|
5
|
+
import crypto from 'crypto';
|
|
6
|
+
const DEFAULT_TTL_IN_SECONDS = 7 * 24 * 3600;
|
|
7
|
+
export class ShopifyProductsCacheDbService {
|
|
8
|
+
TABLE_NAME;
|
|
9
|
+
KEY_NAME;
|
|
10
|
+
dynamoDbCacheTtlInSeconds;
|
|
11
|
+
constructor(tableName, keyName, dynamoDbCacheTtlInSeconds) {
|
|
12
|
+
this.TABLE_NAME = tableName;
|
|
13
|
+
this.KEY_NAME = keyName;
|
|
14
|
+
this.dynamoDbCacheTtlInSeconds = dynamoDbCacheTtlInSeconds || DEFAULT_TTL_IN_SECONDS;
|
|
15
|
+
}
|
|
16
|
+
getProductFromDynamoDBCache = async (pixelId, productId) => {
|
|
17
|
+
try {
|
|
18
|
+
const cachedProduct = await DynamoDbClient.safeGet(this.TABLE_NAME, this.KEY_NAME, `${pixelId}_${productId}`);
|
|
19
|
+
if (cachedProduct && !this.isProductCacheStale(cachedProduct)) {
|
|
20
|
+
const product = decompressJSON(cachedProduct.productCompressed);
|
|
21
|
+
return product;
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
Logger.error('Failed getShopifyProductCacheREST', { keyName: this.KEY_NAME, pixelId, productId, error });
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
putProductInDynamoDBCache = async (pixelId, productId, product, ttlInSeconds) => {
|
|
31
|
+
const ttl = ttlInSeconds || this.dynamoDbCacheTtlInSeconds;
|
|
32
|
+
const expiresAt = DateTime.utc().plus({ seconds: ttl }).toSeconds();
|
|
33
|
+
const cachedAt = getCurrentTimestamp();
|
|
34
|
+
const cachedAtEpoch = DateTime.utc().toSeconds();
|
|
35
|
+
const fullSha256 = crypto.createHash('sha256').update(JSON.stringify(product)).digest('hex');
|
|
36
|
+
const noInventoryProduct = { ...product, totalInventory: undefined, variants: product?.variants?.map(variant => ({ ...variant, inventoryQuantity: undefined, inventoryItem: undefined })) };
|
|
37
|
+
const noInventorySha256 = crypto.createHash('sha256').update(JSON.stringify(noInventoryProduct)).digest('hex');
|
|
38
|
+
const productCompressed = compressJSON(product);
|
|
39
|
+
const shopifyProductCache = {
|
|
40
|
+
pixelId_productId: `${pixelId}_${productId}`,
|
|
41
|
+
pixelId,
|
|
42
|
+
productId,
|
|
43
|
+
productCompressed,
|
|
44
|
+
fullSha256,
|
|
45
|
+
noInventorySha256,
|
|
46
|
+
cachedAt,
|
|
47
|
+
cachedAtEpoch,
|
|
48
|
+
expiresAt
|
|
49
|
+
};
|
|
50
|
+
return await DynamoDbClient.safePut(this.TABLE_NAME, shopifyProductCache);
|
|
51
|
+
};
|
|
52
|
+
isProductCacheStale = (cachedData) => {
|
|
53
|
+
if (cachedData?.expiresAt && cachedData.expiresAt < DateTime.utc().toSeconds()) {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
59
|
//# sourceMappingURL=shopify-products-cache-db-service.js.map
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { AdClickInfo, TrackingEvent, TrackingEventRecord } from '@adtrackify/at-tracking-event-types';
|
|
2
|
-
export interface LatestSessionResponseData {
|
|
3
|
-
pixelId?: string;
|
|
4
|
-
identityId?: string;
|
|
5
|
-
sessionId?: string;
|
|
6
|
-
click?: AdClickInfo;
|
|
7
|
-
}
|
|
8
|
-
export declare class TrackingEventsDbService {
|
|
9
|
-
TABLE_NAME: string;
|
|
10
|
-
KEY_NAME: string;
|
|
11
|
-
constructor(tableName: string);
|
|
12
|
-
private processResult;
|
|
13
|
-
private processResults;
|
|
14
|
-
getLatestSessionByIpAddressUserAgent: (indexName: string, ipAddressUserAgent: string, hostname?: string) => Promise<LatestSessionResponseData>;
|
|
15
|
-
getTrackingEventsByPixelIdEventName: (indexName: string, pixelId: string, eventName: string, limit?: number, afterCollectedAt?: string) => Promise<TrackingEventRecord[]>;
|
|
16
|
-
getTrackingEventCountByPixelId: (indexName: string, pixelId: string, offsetInMinutes?: number) => Promise<number>;
|
|
17
|
-
getTrackingEvent: (eventId: string) => Promise<TrackingEventRecord | null>;
|
|
18
|
-
buildTrackingEventRecord: (trackingEvent: TrackingEvent, ttlInDays?: number) => TrackingEventRecord;
|
|
19
|
-
putTrackingEvent: (trackingEvent: TrackingEvent, ttlInDays?: number) => Promise<import("@aws-sdk/lib-dynamodb").PutCommandOutput | null | undefined>;
|
|
20
|
-
}
|
|
1
|
+
import { AdClickInfo, TrackingEvent, TrackingEventRecord } from '@adtrackify/at-tracking-event-types';
|
|
2
|
+
export interface LatestSessionResponseData {
|
|
3
|
+
pixelId?: string;
|
|
4
|
+
identityId?: string;
|
|
5
|
+
sessionId?: string;
|
|
6
|
+
click?: AdClickInfo;
|
|
7
|
+
}
|
|
8
|
+
export declare class TrackingEventsDbService {
|
|
9
|
+
TABLE_NAME: string;
|
|
10
|
+
KEY_NAME: string;
|
|
11
|
+
constructor(tableName: string);
|
|
12
|
+
private processResult;
|
|
13
|
+
private processResults;
|
|
14
|
+
getLatestSessionByIpAddressUserAgent: (indexName: string, ipAddressUserAgent: string, hostname?: string) => Promise<LatestSessionResponseData>;
|
|
15
|
+
getTrackingEventsByPixelIdEventName: (indexName: string, pixelId: string, eventName: string, limit?: number, afterCollectedAt?: string) => Promise<TrackingEventRecord[]>;
|
|
16
|
+
getTrackingEventCountByPixelId: (indexName: string, pixelId: string, offsetInMinutes?: number) => Promise<number>;
|
|
17
|
+
getTrackingEvent: (eventId: string) => Promise<TrackingEventRecord | null>;
|
|
18
|
+
buildTrackingEventRecord: (trackingEvent: TrackingEvent, ttlInDays?: number) => TrackingEventRecord;
|
|
19
|
+
putTrackingEvent: (trackingEvent: TrackingEvent, ttlInDays?: number) => Promise<import("@aws-sdk/lib-dynamodb").PutCommandOutput | null | undefined>;
|
|
20
|
+
}
|
|
@@ -1,159 +1,159 @@
|
|
|
1
|
-
import { DynamoDbClient } from '../../clients';
|
|
2
|
-
import { Logger } from '../../helpers';
|
|
3
|
-
import { DateTime } from 'luxon';
|
|
4
|
-
import { compressJSON, decompressJSON } from '../../libs';
|
|
5
|
-
export class TrackingEventsDbService {
|
|
6
|
-
TABLE_NAME;
|
|
7
|
-
KEY_NAME = 'eventId';
|
|
8
|
-
constructor(tableName) {
|
|
9
|
-
this.TABLE_NAME = tableName;
|
|
10
|
-
}
|
|
11
|
-
processResult = (trackingEventRecord) => {
|
|
12
|
-
if (trackingEventRecord?.trackingEventCompressed) {
|
|
13
|
-
const trackingEventDecompressed = decompressJSON(trackingEventRecord.trackingEventCompressed);
|
|
14
|
-
if (trackingEventDecompressed) {
|
|
15
|
-
trackingEventRecord.trackingEvent = trackingEventDecompressed;
|
|
16
|
-
delete trackingEventRecord?.trackingEventCompressed;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return trackingEventRecord;
|
|
20
|
-
};
|
|
21
|
-
processResults = (trackingEventRecords) => {
|
|
22
|
-
return trackingEventRecords.map((trackingEventRecord) => this.processResult(trackingEventRecord));
|
|
23
|
-
};
|
|
24
|
-
getLatestSessionByIpAddressUserAgent = async (indexName, ipAddressUserAgent, hostname) => {
|
|
25
|
-
try {
|
|
26
|
-
const params = {
|
|
27
|
-
TableName: this.TABLE_NAME,
|
|
28
|
-
IndexName: indexName,
|
|
29
|
-
KeyConditionExpression: 'ipAddressUserAgent = :ipAddressUserAgent',
|
|
30
|
-
ExpressionAttributeValues: {
|
|
31
|
-
':ipAddressUserAgent': ipAddressUserAgent,
|
|
32
|
-
},
|
|
33
|
-
ScanIndexForward: false
|
|
34
|
-
};
|
|
35
|
-
const results = await DynamoDbClient.query(params);
|
|
36
|
-
let trackingEventRecord;
|
|
37
|
-
if (results?.Items && results.Items.length > 0) {
|
|
38
|
-
trackingEventRecord = results.Items.find((item) => {
|
|
39
|
-
const _trackingEvent = item.trackingEvent;
|
|
40
|
-
const _hostname = item?.hostname;
|
|
41
|
-
if (hostname && _hostname === hostname && _trackingEvent.context?.identity?.identityId && _trackingEvent.context.properties?.sessionId) {
|
|
42
|
-
return true;
|
|
43
|
-
}
|
|
44
|
-
else if (_trackingEvent.context?.identity?.identityId && _trackingEvent.context.properties?.sessionId) {
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
if (trackingEventRecord) {
|
|
53
|
-
trackingEventRecord = this.processResult(trackingEventRecord);
|
|
54
|
-
const trackingEvent = trackingEventRecord.trackingEvent;
|
|
55
|
-
return {
|
|
56
|
-
pixelId: trackingEvent?.pixelId,
|
|
57
|
-
identityId: trackingEvent.context?.identity?.identityId,
|
|
58
|
-
sessionId: trackingEvent.context?.properties?.sessionId,
|
|
59
|
-
click: trackingEvent.context?.properties?.click
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
return {};
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
catch (e) {
|
|
67
|
-
Logger.error('Failed to getLastTrackingEventByIpAddressUserAgent', { e });
|
|
68
|
-
return {};
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
getTrackingEventsByPixelIdEventName = async (indexName, pixelId, eventName, limit, afterCollectedAt) => {
|
|
72
|
-
const query = {
|
|
73
|
-
TableName: this.TABLE_NAME,
|
|
74
|
-
IndexName: indexName,
|
|
75
|
-
KeyConditionExpression: 'pixelIdEventName = :pixelIdEventName',
|
|
76
|
-
ExpressionAttributeValues: {
|
|
77
|
-
':pixelIdEventName': `${pixelId}_${eventName}`,
|
|
78
|
-
},
|
|
79
|
-
ScanIndexForward: false,
|
|
80
|
-
};
|
|
81
|
-
if (limit) {
|
|
82
|
-
query.Limit = limit;
|
|
83
|
-
}
|
|
84
|
-
if (afterCollectedAt) {
|
|
85
|
-
query.KeyConditionExpression += ' and collectedAt > :collectedAt';
|
|
86
|
-
query.ExpressionAttributeValues[':collectedAt'] = afterCollectedAt;
|
|
87
|
-
}
|
|
88
|
-
const result = await DynamoDbClient.query(query);
|
|
89
|
-
const trackingEventRecords = (result?.Items ?? []);
|
|
90
|
-
return this.processResults(trackingEventRecords);
|
|
91
|
-
};
|
|
92
|
-
getTrackingEventCountByPixelId = async (indexName, pixelId, offsetInMinutes = 30) => {
|
|
93
|
-
try {
|
|
94
|
-
const pastDateTime = DateTime.utc().minus({ minutes: offsetInMinutes }).toISO();
|
|
95
|
-
const params = {
|
|
96
|
-
TableName: this.TABLE_NAME,
|
|
97
|
-
IndexName: indexName,
|
|
98
|
-
KeyConditionExpression: 'pixelId = :pixelId and collectedAt > :collectedAt',
|
|
99
|
-
ExpressionAttributeValues: {
|
|
100
|
-
':pixelId': pixelId,
|
|
101
|
-
':collectedAt': pastDateTime
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
const results = await DynamoDbClient.query(params);
|
|
105
|
-
return results?.Items?.length ?? 0;
|
|
106
|
-
}
|
|
107
|
-
catch (e) {
|
|
108
|
-
Logger.error('Failed to getTrackingEventCountByPixelId', { e });
|
|
109
|
-
return 0;
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
getTrackingEvent = async (eventId) => {
|
|
113
|
-
try {
|
|
114
|
-
let trackingEventRecord = await DynamoDbClient.safeGet(this.TABLE_NAME, this.KEY_NAME, eventId);
|
|
115
|
-
trackingEventRecord = this.processResult(trackingEventRecord);
|
|
116
|
-
return trackingEventRecord;
|
|
117
|
-
}
|
|
118
|
-
catch (e) {
|
|
119
|
-
Logger.error('Failed to getTrackingEvent', { e });
|
|
120
|
-
return null;
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
buildTrackingEventRecord = (trackingEvent, ttlInDays) => {
|
|
124
|
-
const trackingEventCopy = JSON.parse(JSON.stringify(trackingEvent));
|
|
125
|
-
delete trackingEventCopy?.context?.properties?.enrichment?.ipLookupResponse;
|
|
126
|
-
const pageURL = trackingEventCopy?.context?.properties?.page?.url;
|
|
127
|
-
const parsedPageURL = new URL(pageURL);
|
|
128
|
-
const hostname = parsedPageURL?.hostname;
|
|
129
|
-
const trackingEventsTableTTLDays = ttlInDays || 15;
|
|
130
|
-
const expiredAt = DateTime.utc().plus({ days: trackingEventsTableTTLDays }).toSeconds();
|
|
131
|
-
const trackingEventRecord = {
|
|
132
|
-
eventId: trackingEventCopy.id,
|
|
133
|
-
eventName: trackingEventCopy.name,
|
|
134
|
-
pixelId: trackingEventCopy?.pixelId,
|
|
135
|
-
pixelIdEventName: `${trackingEventCopy.pixelId}_${trackingEventCopy.name}`,
|
|
136
|
-
ipAddressUserAgent: `${trackingEventCopy.context?.properties?.ipAddress}_${trackingEventCopy.context?.properties?.userAgent}`,
|
|
137
|
-
hostname,
|
|
138
|
-
identityId: trackingEventCopy?.context?.identity?.identityId,
|
|
139
|
-
sessionId: trackingEventCopy?.context?.properties?.sessionId,
|
|
140
|
-
collectedAt: trackingEventCopy.collectedAt,
|
|
141
|
-
expiredAt,
|
|
142
|
-
};
|
|
143
|
-
const trackingEventCompressed = compressJSON(trackingEventCopy);
|
|
144
|
-
if (trackingEventCompressed) {
|
|
145
|
-
trackingEventRecord.trackingEventCompressed = trackingEventCompressed;
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
trackingEventRecord.trackingEvent = trackingEventCopy;
|
|
149
|
-
}
|
|
150
|
-
return trackingEventRecord;
|
|
151
|
-
};
|
|
152
|
-
putTrackingEvent = async (trackingEvent, ttlInDays) => {
|
|
153
|
-
if (!trackingEvent.context?.properties?.ipAddress || !trackingEvent.context?.properties?.userAgent)
|
|
154
|
-
return;
|
|
155
|
-
const trackingEventRecord = this.buildTrackingEventRecord(trackingEvent, ttlInDays);
|
|
156
|
-
return await DynamoDbClient.safePut(this.TABLE_NAME, trackingEventRecord);
|
|
157
|
-
};
|
|
158
|
-
}
|
|
1
|
+
import { DynamoDbClient } from '../../clients';
|
|
2
|
+
import { Logger } from '../../helpers';
|
|
3
|
+
import { DateTime } from 'luxon';
|
|
4
|
+
import { compressJSON, decompressJSON } from '../../libs';
|
|
5
|
+
export class TrackingEventsDbService {
|
|
6
|
+
TABLE_NAME;
|
|
7
|
+
KEY_NAME = 'eventId';
|
|
8
|
+
constructor(tableName) {
|
|
9
|
+
this.TABLE_NAME = tableName;
|
|
10
|
+
}
|
|
11
|
+
processResult = (trackingEventRecord) => {
|
|
12
|
+
if (trackingEventRecord?.trackingEventCompressed) {
|
|
13
|
+
const trackingEventDecompressed = decompressJSON(trackingEventRecord.trackingEventCompressed);
|
|
14
|
+
if (trackingEventDecompressed) {
|
|
15
|
+
trackingEventRecord.trackingEvent = trackingEventDecompressed;
|
|
16
|
+
delete trackingEventRecord?.trackingEventCompressed;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return trackingEventRecord;
|
|
20
|
+
};
|
|
21
|
+
processResults = (trackingEventRecords) => {
|
|
22
|
+
return trackingEventRecords.map((trackingEventRecord) => this.processResult(trackingEventRecord));
|
|
23
|
+
};
|
|
24
|
+
getLatestSessionByIpAddressUserAgent = async (indexName, ipAddressUserAgent, hostname) => {
|
|
25
|
+
try {
|
|
26
|
+
const params = {
|
|
27
|
+
TableName: this.TABLE_NAME,
|
|
28
|
+
IndexName: indexName,
|
|
29
|
+
KeyConditionExpression: 'ipAddressUserAgent = :ipAddressUserAgent',
|
|
30
|
+
ExpressionAttributeValues: {
|
|
31
|
+
':ipAddressUserAgent': ipAddressUserAgent,
|
|
32
|
+
},
|
|
33
|
+
ScanIndexForward: false
|
|
34
|
+
};
|
|
35
|
+
const results = await DynamoDbClient.query(params);
|
|
36
|
+
let trackingEventRecord;
|
|
37
|
+
if (results?.Items && results.Items.length > 0) {
|
|
38
|
+
trackingEventRecord = results.Items.find((item) => {
|
|
39
|
+
const _trackingEvent = item.trackingEvent;
|
|
40
|
+
const _hostname = item?.hostname;
|
|
41
|
+
if (hostname && _hostname === hostname && _trackingEvent.context?.identity?.identityId && _trackingEvent.context.properties?.sessionId) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
else if (_trackingEvent.context?.identity?.identityId && _trackingEvent.context.properties?.sessionId) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (trackingEventRecord) {
|
|
53
|
+
trackingEventRecord = this.processResult(trackingEventRecord);
|
|
54
|
+
const trackingEvent = trackingEventRecord.trackingEvent;
|
|
55
|
+
return {
|
|
56
|
+
pixelId: trackingEvent?.pixelId,
|
|
57
|
+
identityId: trackingEvent.context?.identity?.identityId,
|
|
58
|
+
sessionId: trackingEvent.context?.properties?.sessionId,
|
|
59
|
+
click: trackingEvent.context?.properties?.click
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
return {};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
Logger.error('Failed to getLastTrackingEventByIpAddressUserAgent', { e });
|
|
68
|
+
return {};
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
getTrackingEventsByPixelIdEventName = async (indexName, pixelId, eventName, limit, afterCollectedAt) => {
|
|
72
|
+
const query = {
|
|
73
|
+
TableName: this.TABLE_NAME,
|
|
74
|
+
IndexName: indexName,
|
|
75
|
+
KeyConditionExpression: 'pixelIdEventName = :pixelIdEventName',
|
|
76
|
+
ExpressionAttributeValues: {
|
|
77
|
+
':pixelIdEventName': `${pixelId}_${eventName}`,
|
|
78
|
+
},
|
|
79
|
+
ScanIndexForward: false,
|
|
80
|
+
};
|
|
81
|
+
if (limit) {
|
|
82
|
+
query.Limit = limit;
|
|
83
|
+
}
|
|
84
|
+
if (afterCollectedAt) {
|
|
85
|
+
query.KeyConditionExpression += ' and collectedAt > :collectedAt';
|
|
86
|
+
query.ExpressionAttributeValues[':collectedAt'] = afterCollectedAt;
|
|
87
|
+
}
|
|
88
|
+
const result = await DynamoDbClient.query(query);
|
|
89
|
+
const trackingEventRecords = (result?.Items ?? []);
|
|
90
|
+
return this.processResults(trackingEventRecords);
|
|
91
|
+
};
|
|
92
|
+
getTrackingEventCountByPixelId = async (indexName, pixelId, offsetInMinutes = 30) => {
|
|
93
|
+
try {
|
|
94
|
+
const pastDateTime = DateTime.utc().minus({ minutes: offsetInMinutes }).toISO();
|
|
95
|
+
const params = {
|
|
96
|
+
TableName: this.TABLE_NAME,
|
|
97
|
+
IndexName: indexName,
|
|
98
|
+
KeyConditionExpression: 'pixelId = :pixelId and collectedAt > :collectedAt',
|
|
99
|
+
ExpressionAttributeValues: {
|
|
100
|
+
':pixelId': pixelId,
|
|
101
|
+
':collectedAt': pastDateTime
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const results = await DynamoDbClient.query(params);
|
|
105
|
+
return results?.Items?.length ?? 0;
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
Logger.error('Failed to getTrackingEventCountByPixelId', { e });
|
|
109
|
+
return 0;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
getTrackingEvent = async (eventId) => {
|
|
113
|
+
try {
|
|
114
|
+
let trackingEventRecord = await DynamoDbClient.safeGet(this.TABLE_NAME, this.KEY_NAME, eventId);
|
|
115
|
+
trackingEventRecord = this.processResult(trackingEventRecord);
|
|
116
|
+
return trackingEventRecord;
|
|
117
|
+
}
|
|
118
|
+
catch (e) {
|
|
119
|
+
Logger.error('Failed to getTrackingEvent', { e });
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
buildTrackingEventRecord = (trackingEvent, ttlInDays) => {
|
|
124
|
+
const trackingEventCopy = JSON.parse(JSON.stringify(trackingEvent));
|
|
125
|
+
delete trackingEventCopy?.context?.properties?.enrichment?.ipLookupResponse;
|
|
126
|
+
const pageURL = trackingEventCopy?.context?.properties?.page?.url;
|
|
127
|
+
const parsedPageURL = new URL(pageURL);
|
|
128
|
+
const hostname = parsedPageURL?.hostname;
|
|
129
|
+
const trackingEventsTableTTLDays = ttlInDays || 15;
|
|
130
|
+
const expiredAt = DateTime.utc().plus({ days: trackingEventsTableTTLDays }).toSeconds();
|
|
131
|
+
const trackingEventRecord = {
|
|
132
|
+
eventId: trackingEventCopy.id,
|
|
133
|
+
eventName: trackingEventCopy.name,
|
|
134
|
+
pixelId: trackingEventCopy?.pixelId,
|
|
135
|
+
pixelIdEventName: `${trackingEventCopy.pixelId}_${trackingEventCopy.name}`,
|
|
136
|
+
ipAddressUserAgent: `${trackingEventCopy.context?.properties?.ipAddress}_${trackingEventCopy.context?.properties?.userAgent}`,
|
|
137
|
+
hostname,
|
|
138
|
+
identityId: trackingEventCopy?.context?.identity?.identityId,
|
|
139
|
+
sessionId: trackingEventCopy?.context?.properties?.sessionId,
|
|
140
|
+
collectedAt: trackingEventCopy.collectedAt,
|
|
141
|
+
expiredAt,
|
|
142
|
+
};
|
|
143
|
+
const trackingEventCompressed = compressJSON(trackingEventCopy);
|
|
144
|
+
if (trackingEventCompressed) {
|
|
145
|
+
trackingEventRecord.trackingEventCompressed = trackingEventCompressed;
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
trackingEventRecord.trackingEvent = trackingEventCopy;
|
|
149
|
+
}
|
|
150
|
+
return trackingEventRecord;
|
|
151
|
+
};
|
|
152
|
+
putTrackingEvent = async (trackingEvent, ttlInDays) => {
|
|
153
|
+
if (!trackingEvent.context?.properties?.ipAddress || !trackingEvent.context?.properties?.userAgent)
|
|
154
|
+
return;
|
|
155
|
+
const trackingEventRecord = this.buildTrackingEventRecord(trackingEvent, ttlInDays);
|
|
156
|
+
return await DynamoDbClient.safePut(this.TABLE_NAME, trackingEventRecord);
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
159
|
//# sourceMappingURL=tracking-events-db-service.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { EventBridgeClient } from '../clients/generic/eventbridge-client.js';
|
|
2
|
-
import { Message, TemplatedMessage } from 'postmark';
|
|
3
|
-
export declare class EventBridgeIntegrationService {
|
|
4
|
-
eventBridgeClient: EventBridgeClient;
|
|
5
|
-
EVENT_BUS_NAME: string;
|
|
6
|
-
constructor(eventBusName: string);
|
|
7
|
-
sendPostmarkEmailEvent: (eventSource: string, postmarkMessage: Message, postmarkServerToken: string) => Promise<import("@aws-sdk/client-eventbridge").PutEventsCommandOutput>;
|
|
8
|
-
sendPostmarkTemplatedEmailEvent: (eventSource: string, postmarkMessage: TemplatedMessage, postmarkServerToken: string) => Promise<import("@aws-sdk/client-eventbridge").PutEventsCommandOutput>;
|
|
9
|
-
}
|
|
1
|
+
import { EventBridgeClient } from '../clients/generic/eventbridge-client.js';
|
|
2
|
+
import { Message, TemplatedMessage } from 'postmark';
|
|
3
|
+
export declare class EventBridgeIntegrationService {
|
|
4
|
+
eventBridgeClient: EventBridgeClient;
|
|
5
|
+
EVENT_BUS_NAME: string;
|
|
6
|
+
constructor(eventBusName: string);
|
|
7
|
+
sendPostmarkEmailEvent: (eventSource: string, postmarkMessage: Message, postmarkServerToken: string) => Promise<import("@aws-sdk/client-eventbridge").PutEventsCommandOutput>;
|
|
8
|
+
sendPostmarkTemplatedEmailEvent: (eventSource: string, postmarkMessage: TemplatedMessage, postmarkServerToken: string) => Promise<import("@aws-sdk/client-eventbridge").PutEventsCommandOutput>;
|
|
9
|
+
}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { EventBridgeClient } from '../clients/generic/eventbridge-client.js';
|
|
2
|
-
import { ADTRACKIFY_EVENT_BRIDGE_EVENTS, PostmarkRequestType } from '../types/internal-events/event-detail-types.js';
|
|
3
|
-
export class EventBridgeIntegrationService {
|
|
4
|
-
eventBridgeClient;
|
|
5
|
-
EVENT_BUS_NAME;
|
|
6
|
-
constructor(eventBusName) {
|
|
7
|
-
this.eventBridgeClient = new EventBridgeClient(eventBusName);
|
|
8
|
-
this.EVENT_BUS_NAME = eventBusName;
|
|
9
|
-
}
|
|
10
|
-
sendPostmarkEmailEvent = async (eventSource, postmarkMessage, postmarkServerToken) => {
|
|
11
|
-
return await this.eventBridgeClient.buildAndSendEvent(eventSource, ADTRACKIFY_EVENT_BRIDGE_EVENTS.SEND_POSTMARK_EMAIL, {
|
|
12
|
-
postmarkMessage,
|
|
13
|
-
postmarkRequestType: PostmarkRequestType.SINGLE_EMAIL,
|
|
14
|
-
postmarkServerToken
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
sendPostmarkTemplatedEmailEvent = async (eventSource, postmarkMessage, postmarkServerToken) => {
|
|
18
|
-
return await this.eventBridgeClient.buildAndSendEvent(eventSource, ADTRACKIFY_EVENT_BRIDGE_EVENTS.SEND_POSTMARK_EMAIL, {
|
|
19
|
-
postmarkMessage,
|
|
20
|
-
postmarkRequestType: PostmarkRequestType.TEMPLATE_EMAIL,
|
|
21
|
-
postmarkServerToken
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
|
-
}
|
|
1
|
+
import { EventBridgeClient } from '../clients/generic/eventbridge-client.js';
|
|
2
|
+
import { ADTRACKIFY_EVENT_BRIDGE_EVENTS, PostmarkRequestType } from '../types/internal-events/event-detail-types.js';
|
|
3
|
+
export class EventBridgeIntegrationService {
|
|
4
|
+
eventBridgeClient;
|
|
5
|
+
EVENT_BUS_NAME;
|
|
6
|
+
constructor(eventBusName) {
|
|
7
|
+
this.eventBridgeClient = new EventBridgeClient(eventBusName);
|
|
8
|
+
this.EVENT_BUS_NAME = eventBusName;
|
|
9
|
+
}
|
|
10
|
+
sendPostmarkEmailEvent = async (eventSource, postmarkMessage, postmarkServerToken) => {
|
|
11
|
+
return await this.eventBridgeClient.buildAndSendEvent(eventSource, ADTRACKIFY_EVENT_BRIDGE_EVENTS.SEND_POSTMARK_EMAIL, {
|
|
12
|
+
postmarkMessage,
|
|
13
|
+
postmarkRequestType: PostmarkRequestType.SINGLE_EMAIL,
|
|
14
|
+
postmarkServerToken
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
sendPostmarkTemplatedEmailEvent = async (eventSource, postmarkMessage, postmarkServerToken) => {
|
|
18
|
+
return await this.eventBridgeClient.buildAndSendEvent(eventSource, ADTRACKIFY_EVENT_BRIDGE_EVENTS.SEND_POSTMARK_EMAIL, {
|
|
19
|
+
postmarkMessage,
|
|
20
|
+
postmarkRequestType: PostmarkRequestType.TEMPLATE_EMAIL,
|
|
21
|
+
postmarkServerToken
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
25
|
//# sourceMappingURL=eventbridge-integration-service.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export declare class GenericCacheService {
|
|
2
|
-
private cacheLambdaClient;
|
|
3
|
-
constructor(cacheLambdaFunctionArn: string);
|
|
4
|
-
getCachedData: <T>(cacheKey: string) => Promise<T | undefined>;
|
|
5
|
-
putCachedData: <T>(cacheKey: string, data: T, ttlInSeconds?: number) => Promise<void>;
|
|
6
|
-
deleteCachedData: (cacheKey: string) => Promise<void>;
|
|
7
|
-
}
|
|
1
|
+
export declare class GenericCacheService {
|
|
2
|
+
private cacheLambdaClient;
|
|
3
|
+
constructor(cacheLambdaFunctionArn: string);
|
|
4
|
+
getCachedData: <T>(cacheKey: string) => Promise<T | undefined>;
|
|
5
|
+
putCachedData: <T>(cacheKey: string, data: T, ttlInSeconds?: number) => Promise<void>;
|
|
6
|
+
deleteCachedData: (cacheKey: string) => Promise<void>;
|
|
7
|
+
}
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { CacheLambdaClient } from '../clients';
|
|
2
|
-
import { Logger } from '../helpers';
|
|
3
|
-
export class GenericCacheService {
|
|
4
|
-
cacheLambdaClient;
|
|
5
|
-
constructor(cacheLambdaFunctionArn) {
|
|
6
|
-
this.cacheLambdaClient = new CacheLambdaClient(cacheLambdaFunctionArn);
|
|
7
|
-
}
|
|
8
|
-
getCachedData = async (cacheKey) => {
|
|
9
|
-
const start = performance.now();
|
|
10
|
-
const cacheResponse = await this.cacheLambdaClient.invokeGet(cacheKey);
|
|
11
|
-
const end = performance.now();
|
|
12
|
-
Logger.debug('getCachedData', { cacheKey, cacheResponse, duration: end - start });
|
|
13
|
-
if (cacheResponse && cacheResponse.responseData) {
|
|
14
|
-
return cacheResponse.responseData;
|
|
15
|
-
}
|
|
16
|
-
return undefined;
|
|
17
|
-
};
|
|
18
|
-
putCachedData = async (cacheKey, data, ttlInSeconds) => {
|
|
19
|
-
if (ttlInSeconds) {
|
|
20
|
-
await this.cacheLambdaClient.invokeSet(cacheKey, JSON.stringify(data), ttlInSeconds);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
await this.cacheLambdaClient.invokeSet(cacheKey, JSON.stringify(data));
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
deleteCachedData = async (cacheKey) => {
|
|
27
|
-
await this.cacheLambdaClient.invokeDelete(cacheKey);
|
|
28
|
-
};
|
|
29
|
-
}
|
|
1
|
+
import { CacheLambdaClient } from '../clients';
|
|
2
|
+
import { Logger } from '../helpers';
|
|
3
|
+
export class GenericCacheService {
|
|
4
|
+
cacheLambdaClient;
|
|
5
|
+
constructor(cacheLambdaFunctionArn) {
|
|
6
|
+
this.cacheLambdaClient = new CacheLambdaClient(cacheLambdaFunctionArn);
|
|
7
|
+
}
|
|
8
|
+
getCachedData = async (cacheKey) => {
|
|
9
|
+
const start = performance.now();
|
|
10
|
+
const cacheResponse = await this.cacheLambdaClient.invokeGet(cacheKey);
|
|
11
|
+
const end = performance.now();
|
|
12
|
+
Logger.debug('getCachedData', { cacheKey, cacheResponse, duration: end - start });
|
|
13
|
+
if (cacheResponse && cacheResponse.responseData) {
|
|
14
|
+
return cacheResponse.responseData;
|
|
15
|
+
}
|
|
16
|
+
return undefined;
|
|
17
|
+
};
|
|
18
|
+
putCachedData = async (cacheKey, data, ttlInSeconds) => {
|
|
19
|
+
if (ttlInSeconds) {
|
|
20
|
+
await this.cacheLambdaClient.invokeSet(cacheKey, JSON.stringify(data), ttlInSeconds);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
await this.cacheLambdaClient.invokeSet(cacheKey, JSON.stringify(data));
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
deleteCachedData = async (cacheKey) => {
|
|
27
|
+
await this.cacheLambdaClient.invokeDelete(cacheKey);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
30
|
//# sourceMappingURL=generic-cache-service.js.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from './eventbridge-integration-service.js';
|
|
2
|
-
export * from './ipdata-lookup-service.js';
|
|
3
|
-
export * from './log-event-service.js';
|
|
4
|
-
export * from './metric-event-service.js';
|
|
5
|
-
export * from './generic-cache-service.js';
|
|
6
|
-
export * from './db';
|
|
7
|
-
export * from './shopify';
|
|
8
|
-
export * from './cache';
|
|
1
|
+
export * from './eventbridge-integration-service.js';
|
|
2
|
+
export * from './ipdata-lookup-service.js';
|
|
3
|
+
export * from './log-event-service.js';
|
|
4
|
+
export * from './metric-event-service.js';
|
|
5
|
+
export * from './generic-cache-service.js';
|
|
6
|
+
export * from './db';
|
|
7
|
+
export * from './shopify';
|
|
8
|
+
export * from './cache';
|