@adtrackify/at-service-common 3.0.43 → 3.0.45

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.
@@ -1,8 +1,8 @@
1
1
  import * as mysql from 'mysql2/promise';
2
- export declare const getPool: () => mysql.Pool;
3
2
  export declare class SingleStoreDBClient {
4
- conn: mysql.Connection;
5
- constructor();
3
+ _pool: mysql.Pool;
4
+ constructor(host: string, user: string, password: string, database: string, port: string);
5
+ private getPool;
6
6
  private getConnection;
7
7
  executeQuery(query: string, values?: any): Promise<{
8
8
  rows: mysql.QueryResult;
@@ -23,37 +23,31 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.SingleStoreDBClient = exports.getPool = void 0;
26
+ exports.SingleStoreDBClient = void 0;
27
27
  const mysql = __importStar(require("mysql2/promise"));
28
28
  const helpers_1 = require("../../helpers");
29
- const host = process.env.SINGLESTORE_HOST;
30
- const user = process.env.SINGLESTORE_USER;
31
- const password = process.env.SINGLESTORE_PASSWORD;
32
- const database = process.env.SINGLESTORE_DATABASE;
33
- const port = process.env.SINGLESTORE_PORT;
34
- const getPool = () => {
35
- let pool = null;
36
- pool = mysql.createPool({
37
- host: host,
38
- port: +port,
39
- user: user,
40
- password: password,
41
- database: database,
42
- multipleStatements: true,
43
- });
44
- return pool;
45
- };
46
- exports.getPool = getPool;
47
- const _pool = (0, exports.getPool)();
48
29
  class SingleStoreDBClient {
49
- conn;
50
- constructor() {
30
+ _pool;
31
+ constructor(host, user, password, database, port) {
51
32
  if (!host || !user || !password || !database || !port) {
52
33
  throw new Error('SingleStore env values not found');
53
34
  }
35
+ this._pool = this.getPool(host, user, password, database, port);
36
+ }
37
+ getPool(host, user, password, database, port) {
38
+ let pool = null;
39
+ pool = mysql.createPool({
40
+ host: host,
41
+ port: +port,
42
+ user: user,
43
+ password: password,
44
+ database: database,
45
+ multipleStatements: true,
46
+ });
47
+ return pool;
54
48
  }
55
49
  async getConnection() {
56
- return _pool;
50
+ return this._pool;
57
51
  }
58
52
  async executeQuery(query, values) {
59
53
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"singlestore-db-client.js","sourceRoot":"","sources":["../../../../src/clients/generic/singlestore-db-client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAwC;AACxC,2CAAuC;AAEvC,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,gBAA0B,CAAC;AACpD,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,gBAA0B,CAAC;AACpD,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,oBAA8B,CAAC;AAC5D,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,oBAA8B,CAAC;AAC5D,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,gBAA0B,CAAC;AAE7C,MAAM,OAAO,GAAG,GAAG,EAAE;IAC1B,IAAI,IAAI,GAAG,IAAI,CAAC;IAChB,IAAI,GAAG,KAAK,CAAC,UAAU,CAAC;QACtB,IAAI,EAAE,IAAI;QACV,IAAI,EAAE,CAAC,IAAI;QACX,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,QAAQ;QAClB,QAAQ,EAAE,QAAQ;QAClB,kBAAkB,EAAE,IAAI;KACzB,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAXW,QAAA,OAAO,WAWlB;AAEF,MAAM,KAAK,GAAG,IAAA,eAAO,GAAE,CAAC;AAExB,MAAa,mBAAmB;IAC9B,IAAI,CAAoB;IAExB;QACE,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,EAAE;YACrD,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;SACrD;IACH,CAAC;IAEO,KAAK,CAAC,aAAa;QACz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AC,CAAC;IAClE,CAAC;IAEO,OAAO,CAAC,IAAY,EAAE,IAAY,EAAE,QAAgB,EAAE,QAAgB,EAAE,IAAY;QAC1F,IAAI,IAAI,GAAG,IAAI,CAAC;QAChB,IAAI,GAAG,KAAK,CAAC,UAAU,CAAC;YACtB,IAAI,EAAE,IAAI;YACV,IAAI,EAAE,CAAC,IAAI;YACX,IAAI,EAAE,IAAI;YACV,QAAQ,EAAE,QAAQ;YAClB,QAAQ,EAAE,QAAQ;YAClB,kBAAkB,EAAE,IAAI;SACzB,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,KAAK,CAAC,aAAa;QACzB,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,KAAa,EAAE,MAAY;QAC5C,IAAI;YACF,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;YACxC,gBAAM,CAAC,KAAK,CAAC,iBAAiB,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;YACnD,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;YACvD,gBAAM,CAAC,KAAK,CAAC,gBAAgB,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;YAEjD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;SAChC;QAAC,OAAO,KAAK,EAAE;YACd,gBAAM,CAAC,KAAK,CAAC,uBAAuB,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;YACxD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;SAC3B;IACH,CAAC;CACF;AAzCD,kDAyCC"}
@@ -0,0 +1,22 @@
1
+ import { EventIdentity } from '@adtrackify/at-tracking-event-types';
2
+ import { IdentityClient } from '../../clients';
3
+ export interface IdentityCache {
4
+ identityId: string;
5
+ request: EventIdentity;
6
+ response: EventIdentity;
7
+ createdAt: string;
8
+ updatedAt: string;
9
+ expiresAt: number;
10
+ }
11
+ export declare class IdentityCacheDbService {
12
+ TABLE_NAME: string;
13
+ TABLE_KEY: string;
14
+ TTL_IN_MONTHS: number;
15
+ identityClient: IdentityClient;
16
+ constructor(tableName: string, tableKey: string, ttlInMonths: number, baseApiUrl: string, identityApiKey?: string);
17
+ lookupIdentityCache: (pixelId: string, identityId: string, incomingIdentity: EventIdentity) => Promise<any>;
18
+ putIdentityCache: (identityId: string, request: EventIdentity, response: EventIdentity) => Promise<import("@aws-sdk/lib-dynamodb").PutCommandOutput | null>;
19
+ updateIdentityCache: (identityId: string, request: EventIdentity, response: EventIdentity) => Promise<void>;
20
+ getIdentityCache: (identityId: string) => Promise<IdentityCache>;
21
+ deleteIdentityCache: (identityId: string) => Promise<import("@aws-sdk/lib-dynamodb").DeleteCommandOutput | null>;
22
+ }
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IdentityCacheDbService = void 0;
4
+ const luxon_1 = require("luxon");
5
+ const clients_1 = require("../../clients");
6
+ const libs_1 = require("../../libs");
7
+ const at_shared_utils_1 = require("@adtrackify/at-shared-utils");
8
+ const helpers_1 = require("../../helpers");
9
+ class IdentityCacheDbService {
10
+ TABLE_NAME;
11
+ TABLE_KEY;
12
+ TTL_IN_MONTHS;
13
+ identityClient;
14
+ constructor(tableName, tableKey, ttlInMonths, baseApiUrl, identityApiKey) {
15
+ this.TABLE_NAME = tableName;
16
+ this.TABLE_KEY = tableKey;
17
+ this.TTL_IN_MONTHS = ttlInMonths;
18
+ this.identityClient = new clients_1.IdentityClient(baseApiUrl, identityApiKey);
19
+ }
20
+ lookupIdentityCache = async (pixelId, identityId, incomingIdentity) => {
21
+ const cachedIdentity = await this.getIdentityCache(identityId);
22
+ if (cachedIdentity && (0, at_shared_utils_1.compareIdentityAndShouldUseCache)(cachedIdentity, incomingIdentity)) {
23
+ helpers_1.Logger.debug('identity cache hit', { cachedIdentity, incomingIdentity });
24
+ if (incomingIdentity?.traits?.emails && cachedIdentity?.response?.traits?.emails && incomingIdentity?.traits?.emails?.length !== cachedIdentity.response?.traits?.emails?.length) {
25
+ helpers_1.Logger.warn('Incoming identity & response identity having different emails lengths', { incomingIdentity, cachedIdentity });
26
+ }
27
+ else if (incomingIdentity?.traits?.userIds && cachedIdentity?.response?.traits?.userIds && incomingIdentity?.traits?.userIds?.length !== cachedIdentity.response?.traits?.userIds?.length) {
28
+ helpers_1.Logger.warn('Incoming identity & response identity having different userIds lengths', { incomingIdentity, cachedIdentity });
29
+ }
30
+ return cachedIdentity.response;
31
+ }
32
+ else if (cachedIdentity) {
33
+ helpers_1.Logger.debug('identity cache miss - record exists but stale', { cachedIdentity, incomingIdentity });
34
+ return await this.identityClient.getIdentity(pixelId, { identity: incomingIdentity });
35
+ }
36
+ };
37
+ putIdentityCache = async (identityId, request, response) => {
38
+ const expiresAt = luxon_1.DateTime.now().plus({ months: this.TTL_IN_MONTHS }).toSeconds();
39
+ const identityCache = {
40
+ identityId,
41
+ request,
42
+ response,
43
+ createdAt: (0, libs_1.getCurrentTimestamp)(),
44
+ updatedAt: (0, libs_1.getCurrentTimestamp)(),
45
+ expiresAt
46
+ };
47
+ return await clients_1.DynamoDbClient.safePut(this.TABLE_NAME, identityCache);
48
+ };
49
+ updateIdentityCache = async (identityId, request, response) => {
50
+ const cachedIdentity = await this.getIdentityCache(identityId);
51
+ if (cachedIdentity) {
52
+ cachedIdentity.request = request;
53
+ cachedIdentity.response = response;
54
+ cachedIdentity.updatedAt = (0, libs_1.getCurrentTimestamp)();
55
+ await clients_1.DynamoDbClient.safePut(this.TABLE_NAME, cachedIdentity);
56
+ }
57
+ else {
58
+ await this.putIdentityCache(identityId, request, response);
59
+ }
60
+ };
61
+ getIdentityCache = async (identityId) => {
62
+ return await clients_1.DynamoDbClient.safeGet(this.TABLE_NAME, this.TABLE_KEY, identityId);
63
+ };
64
+ deleteIdentityCache = async (identityId) => {
65
+ return await clients_1.DynamoDbClient.safeDelete(this.TABLE_NAME, this.TABLE_KEY, identityId);
66
+ };
67
+ }
68
+ exports.IdentityCacheDbService = IdentityCacheDbService;
69
+ //# sourceMappingURL=identity-cache-db-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity-cache-db-service.js","sourceRoot":"","sources":["../../../../src/services/db/identity-cache-db-service.ts"],"names":[],"mappings":";;;AACA,iCAAiC;AACjC,2CAA+D;AAC/D,qCAAiD;AACjD,iEAA+E;AAC/E,2CAAuC;AAWvC,MAAa,sBAAsB;IAC1B,UAAU,CAAS;IACnB,SAAS,CAAS;IAClB,aAAa,CAAS;IACtB,cAAc,CAAiB;IAEtC,YAAY,SAAiB,EAAE,QAAgB,EAAE,WAAmB,EAAE,UAAkB,EAAE,cAAuB;QAC/G,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,aAAa,GAAG,WAAW,CAAC;QAEjC,IAAI,CAAC,cAAc,GAAG,IAAI,wBAAc,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;IACvE,CAAC;IAEM,mBAAmB,GAAG,KAAK,EAAE,OAAe,EAAE,UAAkB,EAAE,gBAA+B,EAAE,EAAE;QAC1G,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC;QAE/D,IAAI,cAAc,IAAI,IAAA,kDAAgC,EAAC,cAAc,EAAE,gBAAgB,CAAC,EAAE;YACxF,gBAAM,CAAC,KAAK,CAAC,oBAAoB,EAAE,EAAE,cAAc,EAAE,gBAAgB,EAAE,CAAC,CAAC;YACzE,IAAI,gBAAgB,EAAE,MAAM,EAAE,MAAM,IAAI,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,EAAE,MAAM,EAAE,M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C;IACtE,CAAC,CAAA;IAEM,mBAAmB,GAAG,KAAK,EAAE,UAAkB,EAAE,OAAsB,EAAE,QAAuB,EAAE,EAAE;QACzG,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC;QAC/D,IAAI,cAAc,EAAE;YAClB,cAAc,CAAC,OAAO,GAAG,OAAO,CAAC;YACjC,cAAc,CAAC,QAAQ,GAAG,QAAQ,CAAC;YACnC,cAAc,CAAC,SAAS,GAAG,IAAA,0BAAmB,GAAE,CAAC;YACjD,MAAM,wBAAc,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;SAC/D;aACI;YACH,MAAM,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;SAC5D;IACH,CAAC,CAAA;IAEM,gBAAgB,GAAG,KAAK,EAAE,UAAkB,EAA0B,EAAE;QAC7E,OAAO,MAAM,wBAAc,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,EAAE,UAAU,CAAkB,CAAC;IACpG,CAAC,CAAA;IAEM,mBAAmB,GAAG,KAAK,EAAE,UAAkB,EAAE,EAAE;QACxD,OAAO,MAAM,wBAAc,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IACtF,CAAC,CAAA;CACF;AApED,wDAoEC"}
@@ -4,3 +4,4 @@ export * from './purchased-contacts-db-service.js';
4
4
  export * from './tracking-events-db-service.js';
5
5
  export * from './shopify-products-cache-db-service.js';
6
6
  export * from './shopify-app-installs-db-service.js';
7
+ export * from './identity-cache-db-service.js';
@@ -20,4 +20,5 @@ __exportStar(require("./purchased-contacts-db-service.js"), exports);
20
20
  __exportStar(require("./tracking-events-db-service.js"), exports);
21
21
  __exportStar(require("./shopify-products-cache-db-service.js"), exports);
22
22
  __exportStar(require("./shopify-app-installs-db-service.js"), exports);
23
+ __exportStar(require("./identity-cache-db-service.js"), exports);
23
24
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/services/db/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C;AAC1C,6DAA2C;AAC3C,qEAAmD;AACnD,kEAAgD;AAChD,yEAAuD;AACvD,uEAAqD"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/services/db/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C;AAC1C,6DAA2C;AAC3C,qEAAmD;AACnD,kEAAgD;AAChD,yEAAuD;AACvD,uEAAqD;AACrD,iEAA+C"}
@@ -1,8 +1,8 @@
1
1
  import * as mysql from 'mysql2/promise';
2
- export declare const getPool: () => mysql.Pool;
3
2
  export declare class SingleStoreDBClient {
4
- conn: mysql.Connection;
5
- constructor();
3
+ _pool: mysql.Pool;
4
+ constructor(host: string, user: string, password: string, database: string, port: string);
5
+ private getPool;
6
6
  private getConnection;
7
7
  executeQuery(query: string, values?: any): Promise<{
8
8
  rows: mysql.QueryResult;
@@ -1,32 +1,27 @@
1
1
  import * as mysql from 'mysql2/promise';
2
2
  import { Logger } from '../../helpers';
3
- const host = process.env.SINGLESTORE_HOST;
4
- const user = process.env.SINGLESTORE_USER;
5
- const password = process.env.SINGLESTORE_PASSWORD;
6
- const database = process.env.SINGLESTORE_DATABASE;
7
- const port = process.env.SINGLESTORE_PORT;
8
- export const getPool = () => {
9
- let pool = null;
10
- pool = mysql.createPool({
11
- host: host,
12
- port: +port,
13
- user: user,
14
- password: password,
15
- database: database,
16
- multipleStatements: true,
17
- });
18
- return pool;
19
- };
20
- const _pool = getPool();
21
3
  export class SingleStoreDBClient {
22
- conn;
23
- constructor() {
4
+ _pool;
5
+ constructor(host, user, password, database, port) {
24
6
  if (!host || !user || !password || !database || !port) {
25
7
  throw new Error('SingleStore env values not found');
26
8
  }
9
+ this._pool = this.getPool(host, user, password, database, port);
10
+ }
11
+ getPool(host, user, password, database, port) {
12
+ let pool = null;
13
+ pool = mysql.createPool({
14
+ host: host,
15
+ port: +port,
16
+ user: user,
17
+ password: password,
18
+ database: database,
19
+ multipleStatements: true,
20
+ });
21
+ return pool;
27
22
  }
28
23
  async getConnection() {
29
- return _pool;
24
+ return this._pool;
30
25
  }
31
26
  async executeQuery(query, values) {
32
27
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"singlestore-db-client.js","sourceRoot":"","sources":["../../../../src/clients/generic/singlestore-db-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,gBAA0B,CAAC;AACpD,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,gBAA0B,CAAC;AACpD,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,oBAA8B,CAAC;AAC5D,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,oBAA8B,CAAC;AAC5D,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,gBAA0B,CAAC;AAEpD,MAAM,CAAC,MAAM,OAAO,GAAG,GAAG,EAAE;IAC1B,IAAI,IAAI,GAAG,IAAI,CAAC;IAChB,IAAI,GAAG,KAAK,CAAC,UAAU,CAAC;QACtB,IAAI,EAAE,IAAI;QACV,IAAI,EAAE,CAAC,IAAI;QACX,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,QAAQ;QAClB,QAAQ,EAAE,QAAQ;QAClB,kBAAkB,EAAE,IAAI;KACzB,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,MAAM,KAAK,GAAG,OAAO,EAAE,CAAC;AAExB,MAAM,OAAO,mBAAmB;IAC9B,IAAI,CAAoB;IAExB;QACE,IA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AAC,CAAC;YACxD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;SAC3B;IACH,CAAC;CACF"}
@@ -0,0 +1,22 @@
1
+ import { EventIdentity } from '@adtrackify/at-tracking-event-types';
2
+ import { IdentityClient } from '../../clients';
3
+ export interface IdentityCache {
4
+ identityId: string;
5
+ request: EventIdentity;
6
+ response: EventIdentity;
7
+ createdAt: string;
8
+ updatedAt: string;
9
+ expiresAt: number;
10
+ }
11
+ export declare class IdentityCacheDbService {
12
+ TABLE_NAME: string;
13
+ TABLE_KEY: string;
14
+ TTL_IN_MONTHS: number;
15
+ identityClient: IdentityClient;
16
+ constructor(tableName: string, tableKey: string, ttlInMonths: number, baseApiUrl: string, identityApiKey?: string);
17
+ lookupIdentityCache: (pixelId: string, identityId: string, incomingIdentity: EventIdentity) => Promise<any>;
18
+ putIdentityCache: (identityId: string, request: EventIdentity, response: EventIdentity) => Promise<import("@aws-sdk/lib-dynamodb").PutCommandOutput | null>;
19
+ updateIdentityCache: (identityId: string, request: EventIdentity, response: EventIdentity) => Promise<void>;
20
+ getIdentityCache: (identityId: string) => Promise<IdentityCache>;
21
+ deleteIdentityCache: (identityId: string) => Promise<import("@aws-sdk/lib-dynamodb").DeleteCommandOutput | null>;
22
+ }
@@ -0,0 +1,65 @@
1
+ import { DateTime } from 'luxon';
2
+ import { DynamoDbClient, IdentityClient } from '../../clients';
3
+ import { getCurrentTimestamp } from '../../libs';
4
+ import { compareIdentityAndShouldUseCache } from '@adtrackify/at-shared-utils';
5
+ import { Logger } from '../../helpers';
6
+ export class IdentityCacheDbService {
7
+ TABLE_NAME;
8
+ TABLE_KEY;
9
+ TTL_IN_MONTHS;
10
+ identityClient;
11
+ constructor(tableName, tableKey, ttlInMonths, baseApiUrl, identityApiKey) {
12
+ this.TABLE_NAME = tableName;
13
+ this.TABLE_KEY = tableKey;
14
+ this.TTL_IN_MONTHS = ttlInMonths;
15
+ this.identityClient = new IdentityClient(baseApiUrl, identityApiKey);
16
+ }
17
+ lookupIdentityCache = async (pixelId, identityId, incomingIdentity) => {
18
+ const cachedIdentity = await this.getIdentityCache(identityId);
19
+ if (cachedIdentity && compareIdentityAndShouldUseCache(cachedIdentity, incomingIdentity)) {
20
+ Logger.debug('identity cache hit', { cachedIdentity, incomingIdentity });
21
+ if (incomingIdentity?.traits?.emails && cachedIdentity?.response?.traits?.emails && incomingIdentity?.traits?.emails?.length !== cachedIdentity.response?.traits?.emails?.length) {
22
+ Logger.warn('Incoming identity & response identity having different emails lengths', { incomingIdentity, cachedIdentity });
23
+ }
24
+ else if (incomingIdentity?.traits?.userIds && cachedIdentity?.response?.traits?.userIds && incomingIdentity?.traits?.userIds?.length !== cachedIdentity.response?.traits?.userIds?.length) {
25
+ Logger.warn('Incoming identity & response identity having different userIds lengths', { incomingIdentity, cachedIdentity });
26
+ }
27
+ return cachedIdentity.response;
28
+ }
29
+ else if (cachedIdentity) {
30
+ Logger.debug('identity cache miss - record exists but stale', { cachedIdentity, incomingIdentity });
31
+ return await this.identityClient.getIdentity(pixelId, { identity: incomingIdentity });
32
+ }
33
+ };
34
+ putIdentityCache = async (identityId, request, response) => {
35
+ const expiresAt = DateTime.now().plus({ months: this.TTL_IN_MONTHS }).toSeconds();
36
+ const identityCache = {
37
+ identityId,
38
+ request,
39
+ response,
40
+ createdAt: getCurrentTimestamp(),
41
+ updatedAt: getCurrentTimestamp(),
42
+ expiresAt
43
+ };
44
+ return await DynamoDbClient.safePut(this.TABLE_NAME, identityCache);
45
+ };
46
+ updateIdentityCache = async (identityId, request, response) => {
47
+ const cachedIdentity = await this.getIdentityCache(identityId);
48
+ if (cachedIdentity) {
49
+ cachedIdentity.request = request;
50
+ cachedIdentity.response = response;
51
+ cachedIdentity.updatedAt = getCurrentTimestamp();
52
+ await DynamoDbClient.safePut(this.TABLE_NAME, cachedIdentity);
53
+ }
54
+ else {
55
+ await this.putIdentityCache(identityId, request, response);
56
+ }
57
+ };
58
+ getIdentityCache = async (identityId) => {
59
+ return await DynamoDbClient.safeGet(this.TABLE_NAME, this.TABLE_KEY, identityId);
60
+ };
61
+ deleteIdentityCache = async (identityId) => {
62
+ return await DynamoDbClient.safeDelete(this.TABLE_NAME, this.TABLE_KEY, identityId);
63
+ };
64
+ }
65
+ //# sourceMappingURL=identity-cache-db-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity-cache-db-service.js","sourceRoot":"","sources":["../../../../src/services/db/identity-cache-db-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,gCAAgC,EAAE,MAAM,6BAA6B,CAAC;AAC/E,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAWvC,MAAM,OAAO,sBAAsB;IAC1B,UAAU,CAAS;IACnB,SAAS,CAAS;IAClB,aAAa,CAAS;IACtB,cAAc,CAAiB;IAEtC,YAAY,SAAiB,EAAE,QAAgB,EAAE,WAAmB,EAAE,UAAkB,EAAE,cAAuB;QAC/G,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,aAAa,GAAG,WAAW,CAAC;QAEjC,IAAI,CAAC,cAAc,GAAG,IAAI,cAAc,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;IACvE,CAAC;IAEM,mBAAmB,GAAG,KAAK,EAAE,OAAe,EAAE,UAAkB,EAAE,gBAA+B,EAAE,EAAE;QAC1G,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC;QAE/D,IAAI,cAAc,IAAI,gCAAgC,CAAC,cAAc,EAAE,gBAAgB,CAAC,EAAE;YACxF,MAAM,CAAC,KAAK,CAAC,oBAAoB,EAAE,EAAE,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AS,EAAE,mBAAmB,EAAE;YAChC,SAAS,EAAE,mBAAmB,EAAE;YAChC,SAAS;SACV,CAAC;QACF,OAAO,MAAM,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;IACtE,CAAC,CAAA;IAEM,mBAAmB,GAAG,KAAK,EAAE,UAAkB,EAAE,OAAsB,EAAE,QAAuB,EAAE,EAAE;QACzG,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC;QAC/D,IAAI,cAAc,EAAE;YAClB,cAAc,CAAC,OAAO,GAAG,OAAO,CAAC;YACjC,cAAc,CAAC,QAAQ,GAAG,QAAQ,CAAC;YACnC,cAAc,CAAC,SAAS,GAAG,mBAAmB,EAAE,CAAC;YACjD,MAAM,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;SAC/D;aACI;YACH,MAAM,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;SAC5D;IACH,CAAC,CAAA;IAEM,gBAAgB,GAAG,KAAK,EAAE,UAAkB,EAA0B,EAAE;QAC7E,OAAO,MAAM,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,EAAE,UAAU,CAAkB,CAAC;IACpG,CAAC,CAAA;IAEM,mBAAmB,GAAG,KAAK,EAAE,UAAkB,EAAE,EAAE;QACxD,OAAO,MAAM,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IACtF,CAAC,CAAA;CACF"}
@@ -4,3 +4,4 @@ export * from './purchased-contacts-db-service.js';
4
4
  export * from './tracking-events-db-service.js';
5
5
  export * from './shopify-products-cache-db-service.js';
6
6
  export * from './shopify-app-installs-db-service.js';
7
+ export * from './identity-cache-db-service.js';
@@ -4,4 +4,5 @@ export * from './purchased-contacts-db-service.js';
4
4
  export * from './tracking-events-db-service.js';
5
5
  export * from './shopify-products-cache-db-service.js';
6
6
  export * from './shopify-app-installs-db-service.js';
7
+ export * from './identity-cache-db-service.js';
7
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/services/db/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oCAAoC,CAAC;AACnD,cAAc,iCAAiC,CAAC;AAChD,cAAc,wCAAwC,CAAC;AACvD,cAAc,sCAAsC,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/services/db/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oCAAoC,CAAC;AACnD,cAAc,iCAAiC,CAAC;AAChD,cAAc,wCAAwC,CAAC;AACvD,cAAc,sCAAsC,CAAC;AACrD,cAAc,gCAAgC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adtrackify/at-service-common",
3
- "version": "3.0.43",
3
+ "version": "3.0.45",
4
4
  "description": "",
5
5
  "files": [
6
6
  "dist/*"
@@ -35,7 +35,7 @@
35
35
  "prepublishOnly": "npm run tsc"
36
36
  },
37
37
  "dependencies": {
38
- "@adtrackify/at-shared-utils": "^3.0.28",
38
+ "@adtrackify/at-shared-utils": "^3.0.30",
39
39
  "pako": "^2.1.0",
40
40
  "shopify-api-node": "^3.12.7"
41
41
  },