@adtrackify/at-service-common 3.0.89 → 3.0.91

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (251) hide show
  1. package/dist/cjs/__tests__/identity-cache/identity-cache-db-service.spec.d.ts +1 -1
  2. package/dist/cjs/__tests__/identity-cache/identity-cache-db-service.spec.js +527 -527
  3. package/dist/cjs/__tests__/libs/compress-decompress.spec.d.ts +1 -1
  4. package/dist/cjs/__tests__/libs/compress-decompress.spec.js +16 -16
  5. package/dist/cjs/__tests__/s3-client/s3-client.spec.d.ts +1 -1
  6. package/dist/cjs/__tests__/s3-client/s3-client.spec.js +26 -26
  7. package/dist/cjs/clients/generic/cognito-client.d.ts +20 -20
  8. package/dist/cjs/clients/generic/cognito-client.js +164 -164
  9. package/dist/cjs/clients/generic/dynamodb-client.d.ts +17 -17
  10. package/dist/cjs/clients/generic/dynamodb-client.js +167 -167
  11. package/dist/cjs/clients/generic/eventbridge-client.d.ts +14 -14
  12. package/dist/cjs/clients/generic/eventbridge-client.js +49 -49
  13. package/dist/cjs/clients/generic/http-client.d.ts +88 -88
  14. package/dist/cjs/clients/generic/http-client.js +56 -56
  15. package/dist/cjs/clients/generic/index.d.ts +10 -10
  16. package/dist/cjs/clients/generic/index.js +26 -26
  17. package/dist/cjs/clients/generic/lambda-invoke-client.d.ts +10 -10
  18. package/dist/cjs/clients/generic/lambda-invoke-client.js +35 -35
  19. package/dist/cjs/clients/generic/location-client.d.ts +8 -8
  20. package/dist/cjs/clients/generic/location-client.js +31 -31
  21. package/dist/cjs/clients/generic/redis-client.d.ts +17 -17
  22. package/dist/cjs/clients/generic/redis-client.js +117 -117
  23. package/dist/cjs/clients/generic/s3-client.d.ts +16 -16
  24. package/dist/cjs/clients/generic/s3-client.js +110 -110
  25. package/dist/cjs/clients/generic/singlestore-db-client.d.ts +14 -14
  26. package/dist/cjs/clients/generic/singlestore-db-client.js +67 -67
  27. package/dist/cjs/clients/generic/sqs-client.d.ts +14 -14
  28. package/dist/cjs/clients/generic/sqs-client.js +36 -36
  29. package/dist/cjs/clients/index.d.ts +3 -3
  30. package/dist/cjs/clients/index.js +19 -19
  31. package/dist/cjs/clients/internal-api/accounts-client.d.ts +112 -112
  32. package/dist/cjs/clients/internal-api/accounts-client.js +117 -117
  33. package/dist/cjs/clients/internal-api/cache-lambda-client.d.ts +23 -23
  34. package/dist/cjs/clients/internal-api/cache-lambda-client.js +59 -59
  35. package/dist/cjs/clients/internal-api/db-management-client.d.ts +18 -18
  36. package/dist/cjs/clients/internal-api/db-management-client.js +39 -39
  37. package/dist/cjs/clients/internal-api/destinations-client.d.ts +29 -29
  38. package/dist/cjs/clients/internal-api/destinations-client.js +54 -54
  39. package/dist/cjs/clients/internal-api/event-collector-client.d.ts +20 -20
  40. package/dist/cjs/clients/internal-api/event-collector-client.js +39 -39
  41. package/dist/cjs/clients/internal-api/identity-client.d.ts +17 -17
  42. package/dist/cjs/clients/internal-api/identity-client.js +75 -75
  43. package/dist/cjs/clients/internal-api/index.d.ts +8 -8
  44. package/dist/cjs/clients/internal-api/index.js +24 -24
  45. package/dist/cjs/clients/internal-api/shopify-app-install-client.d.ts +34 -34
  46. package/dist/cjs/clients/internal-api/shopify-app-install-client.js +63 -63
  47. package/dist/cjs/clients/internal-api/users-auth-client.d.ts +31 -31
  48. package/dist/cjs/clients/internal-api/users-auth-client.js +92 -92
  49. package/dist/cjs/clients/third-party/index.d.ts +1 -1
  50. package/dist/cjs/clients/third-party/index.js +17 -17
  51. package/dist/cjs/clients/third-party/shopify-client.d.ts +198 -198
  52. package/dist/cjs/clients/third-party/shopify-client.js +150 -150
  53. package/dist/cjs/helpers/identity-cache-helper.d.ts +4 -4
  54. package/dist/cjs/helpers/identity-cache-helper.js +150 -150
  55. package/dist/cjs/helpers/index.d.ts +5 -5
  56. package/dist/cjs/helpers/index.js +21 -21
  57. package/dist/cjs/helpers/input-validation-helper.d.ts +3 -3
  58. package/dist/cjs/helpers/input-validation-helper.js +22 -22
  59. package/dist/cjs/helpers/logging-helper.d.ts +16 -16
  60. package/dist/cjs/helpers/logging-helper.js +84 -84
  61. package/dist/cjs/helpers/response-helper.d.ts +15 -15
  62. package/dist/cjs/helpers/response-helper.js +42 -42
  63. package/dist/cjs/helpers/shopify-helper.d.ts +9 -9
  64. package/dist/cjs/helpers/shopify-helper.js +28 -28
  65. package/dist/cjs/index.d.ts +5 -5
  66. package/dist/cjs/index.js +21 -21
  67. package/dist/cjs/libs/clickId-parser.d.ts +23 -23
  68. package/dist/cjs/libs/clickId-parser.js +49 -49
  69. package/dist/cjs/libs/compression.d.ts +2 -2
  70. package/dist/cjs/libs/compression.js +33 -33
  71. package/dist/cjs/libs/crypto.d.ts +1 -1
  72. package/dist/cjs/libs/crypto.js +12 -12
  73. package/dist/cjs/libs/dates.d.ts +6 -6
  74. package/dist/cjs/libs/dates.js +31 -31
  75. package/dist/cjs/libs/http-error.d.ts +21 -21
  76. package/dist/cjs/libs/http-error.js +59 -59
  77. package/dist/cjs/libs/http-status-codes.d.ts +58 -58
  78. package/dist/cjs/libs/http-status-codes.js +62 -62
  79. package/dist/cjs/libs/index.d.ts +9 -9
  80. package/dist/cjs/libs/index.js +25 -25
  81. package/dist/cjs/libs/referrer-parser/index.d.ts +2 -2
  82. package/dist/cjs/libs/referrer-parser/index.js +18 -18
  83. package/dist/cjs/libs/referrer-parser/referrer-data.d.ts +9 -9
  84. package/dist/cjs/libs/referrer-parser/referrer-data.js +4712 -4712
  85. package/dist/cjs/libs/referrer-parser/referrer-parser-util.d.ts +20 -20
  86. package/dist/cjs/libs/referrer-parser/referrer-parser-util.js +128 -128
  87. package/dist/cjs/libs/url.d.ts +1 -1
  88. package/dist/cjs/libs/url.js +13 -13
  89. package/dist/cjs/services/db/{destinations-service.d.ts → destinations-db-service.d.ts} +8 -7
  90. package/dist/cjs/services/db/{destinations-service.js → destinations-db-service.js} +48 -36
  91. package/dist/cjs/services/db/destinations-db-service.js.map +1 -0
  92. package/dist/cjs/services/db/identity-cache-db-service.d.ts +24 -24
  93. package/dist/cjs/services/db/identity-cache-db-service.js +233 -233
  94. package/dist/cjs/services/db/index.d.ts +7 -7
  95. package/dist/cjs/services/db/index.js +23 -23
  96. package/dist/cjs/services/db/index.js.map +1 -1
  97. package/dist/cjs/services/db/log-events-db-service.d.ts +11 -11
  98. package/dist/cjs/services/db/log-events-db-service.js +172 -172
  99. package/dist/cjs/services/db/purchased-contacts-db-service.d.ts +9 -9
  100. package/dist/cjs/services/db/purchased-contacts-db-service.js +38 -38
  101. package/dist/cjs/services/db/shopify-app-installs-db-service.d.ts +7 -7
  102. package/dist/cjs/services/db/shopify-app-installs-db-service.js +47 -47
  103. package/dist/cjs/services/db/shopify-products-cache-db-service.d.ts +9 -9
  104. package/dist/cjs/services/db/shopify-products-cache-db-service.js +64 -64
  105. package/dist/cjs/services/db/tracking-events-db-service.d.ts +20 -20
  106. package/dist/cjs/services/db/tracking-events-db-service.js +162 -162
  107. package/dist/cjs/services/eventbridge-integration-service.d.ts +9 -9
  108. package/dist/cjs/services/eventbridge-integration-service.js +28 -28
  109. package/dist/cjs/services/index.d.ts +5 -5
  110. package/dist/cjs/services/index.js +21 -21
  111. package/dist/cjs/services/ipdata-lookup-service.d.ts +17 -17
  112. package/dist/cjs/services/ipdata-lookup-service.js +71 -71
  113. package/dist/cjs/services/log-event-service.d.ts +9 -9
  114. package/dist/cjs/services/log-event-service.js +56 -56
  115. package/dist/cjs/services/metric-event-service.d.ts +9 -9
  116. package/dist/cjs/services/metric-event-service.js +49 -49
  117. package/dist/cjs/types/api-response.d.ts +6 -6
  118. package/dist/cjs/types/api-response.js +2 -2
  119. package/dist/cjs/types/index.d.ts +1 -1
  120. package/dist/cjs/types/index.js +17 -17
  121. package/dist/cjs/types/internal-events/event-detail-types.d.ts +20 -20
  122. package/dist/cjs/types/internal-events/event-detail-types.js +27 -27
  123. package/dist/cjs/types/internal-events/index.d.ts +1 -1
  124. package/dist/cjs/types/internal-events/index.js +17 -17
  125. package/dist/esm/__tests__/identity-cache/identity-cache-db-service.spec.d.ts +1 -1
  126. package/dist/esm/__tests__/identity-cache/identity-cache-db-service.spec.js +525 -525
  127. package/dist/esm/__tests__/libs/compress-decompress.spec.d.ts +1 -1
  128. package/dist/esm/__tests__/libs/compress-decompress.spec.js +14 -14
  129. package/dist/esm/__tests__/s3-client/s3-client.spec.d.ts +1 -1
  130. package/dist/esm/__tests__/s3-client/s3-client.spec.js +24 -24
  131. package/dist/esm/clients/generic/cognito-client.d.ts +20 -20
  132. package/dist/esm/clients/generic/cognito-client.js +159 -159
  133. package/dist/esm/clients/generic/dynamodb-client.d.ts +17 -17
  134. package/dist/esm/clients/generic/dynamodb-client.js +163 -163
  135. package/dist/esm/clients/generic/eventbridge-client.d.ts +14 -14
  136. package/dist/esm/clients/generic/eventbridge-client.js +45 -45
  137. package/dist/esm/clients/generic/http-client.d.ts +88 -88
  138. package/dist/esm/clients/generic/http-client.js +48 -48
  139. package/dist/esm/clients/generic/index.d.ts +10 -10
  140. package/dist/esm/clients/generic/index.js +10 -10
  141. package/dist/esm/clients/generic/lambda-invoke-client.d.ts +10 -10
  142. package/dist/esm/clients/generic/lambda-invoke-client.js +31 -31
  143. package/dist/esm/clients/generic/location-client.d.ts +8 -8
  144. package/dist/esm/clients/generic/location-client.js +27 -27
  145. package/dist/esm/clients/generic/redis-client.d.ts +17 -17
  146. package/dist/esm/clients/generic/redis-client.js +110 -110
  147. package/dist/esm/clients/generic/s3-client.d.ts +16 -16
  148. package/dist/esm/clients/generic/s3-client.js +106 -106
  149. package/dist/esm/clients/generic/singlestore-db-client.d.ts +14 -14
  150. package/dist/esm/clients/generic/singlestore-db-client.js +40 -40
  151. package/dist/esm/clients/generic/sqs-client.d.ts +14 -14
  152. package/dist/esm/clients/generic/sqs-client.js +32 -32
  153. package/dist/esm/clients/index.d.ts +3 -3
  154. package/dist/esm/clients/index.js +3 -3
  155. package/dist/esm/clients/internal-api/accounts-client.d.ts +112 -112
  156. package/dist/esm/clients/internal-api/accounts-client.js +113 -113
  157. package/dist/esm/clients/internal-api/cache-lambda-client.d.ts +23 -23
  158. package/dist/esm/clients/internal-api/cache-lambda-client.js +55 -55
  159. package/dist/esm/clients/internal-api/db-management-client.d.ts +18 -18
  160. package/dist/esm/clients/internal-api/db-management-client.js +32 -32
  161. package/dist/esm/clients/internal-api/destinations-client.d.ts +29 -29
  162. package/dist/esm/clients/internal-api/destinations-client.js +50 -50
  163. package/dist/esm/clients/internal-api/event-collector-client.d.ts +20 -20
  164. package/dist/esm/clients/internal-api/event-collector-client.js +32 -32
  165. package/dist/esm/clients/internal-api/identity-client.d.ts +17 -17
  166. package/dist/esm/clients/internal-api/identity-client.js +71 -71
  167. package/dist/esm/clients/internal-api/index.d.ts +8 -8
  168. package/dist/esm/clients/internal-api/index.js +8 -8
  169. package/dist/esm/clients/internal-api/shopify-app-install-client.d.ts +34 -34
  170. package/dist/esm/clients/internal-api/shopify-app-install-client.js +56 -56
  171. package/dist/esm/clients/internal-api/users-auth-client.d.ts +31 -31
  172. package/dist/esm/clients/internal-api/users-auth-client.js +88 -88
  173. package/dist/esm/clients/third-party/index.d.ts +1 -1
  174. package/dist/esm/clients/third-party/index.js +1 -1
  175. package/dist/esm/clients/third-party/shopify-client.d.ts +198 -198
  176. package/dist/esm/clients/third-party/shopify-client.js +146 -146
  177. package/dist/esm/helpers/identity-cache-helper.d.ts +4 -4
  178. package/dist/esm/helpers/identity-cache-helper.js +145 -145
  179. package/dist/esm/helpers/index.d.ts +5 -5
  180. package/dist/esm/helpers/index.js +5 -5
  181. package/dist/esm/helpers/input-validation-helper.d.ts +3 -3
  182. package/dist/esm/helpers/input-validation-helper.js +18 -18
  183. package/dist/esm/helpers/logging-helper.d.ts +16 -16
  184. package/dist/esm/helpers/logging-helper.js +56 -56
  185. package/dist/esm/helpers/response-helper.d.ts +15 -15
  186. package/dist/esm/helpers/response-helper.js +36 -36
  187. package/dist/esm/helpers/shopify-helper.d.ts +9 -9
  188. package/dist/esm/helpers/shopify-helper.js +23 -23
  189. package/dist/esm/index.d.ts +5 -5
  190. package/dist/esm/index.js +5 -5
  191. package/dist/esm/libs/clickId-parser.d.ts +23 -23
  192. package/dist/esm/libs/clickId-parser.js +45 -45
  193. package/dist/esm/libs/compression.d.ts +2 -2
  194. package/dist/esm/libs/compression.js +25 -25
  195. package/dist/esm/libs/crypto.d.ts +1 -1
  196. package/dist/esm/libs/crypto.js +5 -5
  197. package/dist/esm/libs/dates.d.ts +6 -6
  198. package/dist/esm/libs/dates.js +22 -22
  199. package/dist/esm/libs/http-error.d.ts +21 -21
  200. package/dist/esm/libs/http-error.js +55 -55
  201. package/dist/esm/libs/http-status-codes.d.ts +58 -58
  202. package/dist/esm/libs/http-status-codes.js +59 -59
  203. package/dist/esm/libs/index.d.ts +9 -9
  204. package/dist/esm/libs/index.js +9 -9
  205. package/dist/esm/libs/referrer-parser/index.d.ts +2 -2
  206. package/dist/esm/libs/referrer-parser/index.js +2 -2
  207. package/dist/esm/libs/referrer-parser/referrer-data.d.ts +9 -9
  208. package/dist/esm/libs/referrer-parser/referrer-data.js +4709 -4709
  209. package/dist/esm/libs/referrer-parser/referrer-parser-util.d.ts +20 -20
  210. package/dist/esm/libs/referrer-parser/referrer-parser-util.js +121 -121
  211. package/dist/esm/libs/url.d.ts +1 -1
  212. package/dist/esm/libs/url.js +9 -9
  213. package/dist/esm/services/db/{destinations-service.d.ts → destinations-db-service.d.ts} +8 -7
  214. package/dist/esm/services/db/{destinations-service.js → destinations-db-service.js} +44 -32
  215. package/dist/esm/services/db/destinations-db-service.js.map +1 -0
  216. package/dist/esm/services/db/identity-cache-db-service.d.ts +24 -24
  217. package/dist/esm/services/db/identity-cache-db-service.js +229 -229
  218. package/dist/esm/services/db/index.d.ts +7 -7
  219. package/dist/esm/services/db/index.js +7 -7
  220. package/dist/esm/services/db/index.js.map +1 -1
  221. package/dist/esm/services/db/log-events-db-service.d.ts +11 -11
  222. package/dist/esm/services/db/log-events-db-service.js +168 -168
  223. package/dist/esm/services/db/purchased-contacts-db-service.d.ts +9 -9
  224. package/dist/esm/services/db/purchased-contacts-db-service.js +34 -34
  225. package/dist/esm/services/db/shopify-app-installs-db-service.d.ts +7 -7
  226. package/dist/esm/services/db/shopify-app-installs-db-service.js +43 -43
  227. package/dist/esm/services/db/shopify-products-cache-db-service.d.ts +9 -9
  228. package/dist/esm/services/db/shopify-products-cache-db-service.js +60 -60
  229. package/dist/esm/services/db/tracking-events-db-service.d.ts +20 -20
  230. package/dist/esm/services/db/tracking-events-db-service.js +158 -158
  231. package/dist/esm/services/eventbridge-integration-service.d.ts +9 -9
  232. package/dist/esm/services/eventbridge-integration-service.js +24 -24
  233. package/dist/esm/services/index.d.ts +5 -5
  234. package/dist/esm/services/index.js +5 -5
  235. package/dist/esm/services/ipdata-lookup-service.d.ts +17 -17
  236. package/dist/esm/services/ipdata-lookup-service.js +67 -67
  237. package/dist/esm/services/log-event-service.d.ts +9 -9
  238. package/dist/esm/services/log-event-service.js +52 -52
  239. package/dist/esm/services/metric-event-service.d.ts +9 -9
  240. package/dist/esm/services/metric-event-service.js +45 -45
  241. package/dist/esm/types/api-response.d.ts +6 -6
  242. package/dist/esm/types/api-response.js +1 -1
  243. package/dist/esm/types/index.d.ts +1 -1
  244. package/dist/esm/types/index.js +1 -1
  245. package/dist/esm/types/internal-events/event-detail-types.d.ts +20 -20
  246. package/dist/esm/types/internal-events/event-detail-types.js +24 -24
  247. package/dist/esm/types/internal-events/index.d.ts +1 -1
  248. package/dist/esm/types/internal-events/index.js +1 -1
  249. package/package.json +1 -1
  250. package/dist/cjs/services/db/destinations-service.js.map +0 -1
  251. package/dist/esm/services/db/destinations-service.js.map +0 -1
@@ -1,151 +1,151 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ShopifyClient = void 0;
4
- const http_client_js_1 = require("../generic/http-client.js");
5
- const index_js_1 = require("../../index.js");
6
- class ShopifyClient {
7
- static _shopify_api_version = process.env.SHOPIFY_API_VERSION;
8
- static client;
9
- static getConfig = (shopifyDomain, accessToken) => {
10
- const config = {
11
- baseURL: `https://${shopifyDomain}/admin/api/${this._shopify_api_version}`,
12
- headers: {
13
- common: {
14
- 'X-Shopify-Access-Token': accessToken,
15
- },
16
- },
17
- };
18
- return config;
19
- };
20
- static getClient = () => {
21
- this.client = this.client ?? (0, http_client_js_1.axiosHttpService)();
22
- return this.client;
23
- };
24
- static registerApp = async (shop, code, appKey, appSecret) => {
25
- const client = this.getClient();
26
- const url = 'https://' + shop + '/admin/oauth/access_token';
27
- const payload = {
28
- client_id: appKey,
29
- client_secret: appSecret,
30
- code
31
- };
32
- const res = await client.post(url, payload);
33
- return res;
34
- };
35
- static registerWebhookTopic = async (shop, accessToken, eventBridgeArn, topic) => {
36
- const client = this.getClient();
37
- const url = `https://${shop}/admin/api/${this._shopify_api_version}/webhooks.json`;
38
- const payload = {
39
- webhook: {
40
- topic,
41
- address: eventBridgeArn,
42
- format: 'json'
43
- }
44
- };
45
- const res = await client.post(url, payload, { headers: { 'X-Shopify-Access-Token': accessToken } });
46
- if (res.status >= 400) {
47
- index_js_1.Logger.error('Failed to register Webhook Topic', { res, shop, accessToken, eventBridgeArn, topic, url, payload });
48
- }
49
- index_js_1.Logger.debug('Shopify Client Webhook Registration Response', { registrationResponse: res });
50
- return res;
51
- };
52
- static updateShopifyAppMetafield = async (shop, accessToken, pixelId) => {
53
- const url = `https://${shop}/admin/api/${this._shopify_api_version}/metafields.json`;
54
- const payload = {
55
- metafield: {
56
- namespace: 'adtr',
57
- key: 'adtr.config',
58
- value: pixelId,
59
- type: 'single_line_text_field'
60
- }
61
- };
62
- const res = await this.genericShopifyPost(url, accessToken, payload);
63
- if (res.status >= 400) {
64
- index_js_1.Logger.error('Failed to update Shopify app Metafield ', { shop, accessToken, url, payload });
65
- }
66
- return res;
67
- };
68
- static getShopifyStoreProperties = async (shop, accessToken) => {
69
- const url = `https://${shop}/admin/api/${this._shopify_api_version}/shop.json`;
70
- const res = await this.genericShopifyGet(url, accessToken);
71
- if (res.status >= 400) {
72
- index_js_1.Logger.error('Failed to get Shopify Store Properties', { shop, accessToken, url });
73
- }
74
- return res;
75
- };
76
- static createAppSubscription = async (shop, accessToken, planName, price, returnUrl, trialDays, test) => {
77
- const url = `https://${shop}/admin/api/${this._shopify_api_version}/recurring_application_charges.json`;
78
- const recurring_application_charge = {
79
- name: planName,
80
- price,
81
- return_url: returnUrl,
82
- trial_days: trialDays,
83
- test
84
- };
85
- const res = await this.genericShopifyPost(url, accessToken, { recurring_application_charge });
86
- if (res.status >= 400) {
87
- index_js_1.Logger.error('Failed to create App Subscription', { shop, accessToken, url });
88
- }
89
- return res;
90
- };
91
- static cancelAppSubscription = async (shop, accessToken, chargeId) => {
92
- const url = `https://${shop}/admin/api/${this._shopify_api_version}/recurring_application_charges/${chargeId}.json`;
93
- const client = this.getClient();
94
- const res = await client.delete(url, { headers: { 'X-Shopify-Access-Token': accessToken } });
95
- if (res.status !== 200) {
96
- index_js_1.Logger.error('Failed to cancel recurring App billing', { shop, accessToken, url });
97
- }
98
- return res;
99
- };
100
- static listAppSubscriptions = async (shop, accessToken) => {
101
- const url = `https://${shop}/admin/api/${this._shopify_api_version}/recurring_application_charges.json`;
102
- const res = await this.genericShopifyGet(url, accessToken);
103
- if (res.status >= 400) {
104
- index_js_1.Logger.error('Failed to get App Subscriptions', { shop, accessToken, url });
105
- }
106
- return res;
107
- };
108
- static getOrder = async (shop, accessToken, orderId) => {
109
- const url = `https://${shop}/admin/api/${this._shopify_api_version}/orders/${orderId}.json`;
110
- const res = await this.genericShopifyGet(url, accessToken);
111
- if (res.status >= 400) {
112
- index_js_1.Logger.error('Failed to get Order', { res, shop, accessToken, url, orderId });
113
- }
114
- return res;
115
- };
116
- static getProduct = async (shop, accessToken, productId) => {
117
- const url = `https://${shop}/admin/api/${this._shopify_api_version}/products/${productId}.json`;
118
- const res = await this.genericShopifyGet(url, accessToken);
119
- if (res.status >= 400) {
120
- index_js_1.Logger.error('Failed to get Product', { res, shop, accessToken, url, productId });
121
- }
122
- return res;
123
- };
124
- static genericShopifyPost = async (url, accessToken, payload) => {
125
- const client = this.getClient();
126
- const res = await client.post(url, payload, { headers: { 'X-Shopify-Access-Token': accessToken, 'Content-Type': 'application/json' } });
127
- index_js_1.Logger.debug('Shopify Client Response', { res });
128
- return res;
129
- };
130
- static genericShopifyGet = async (url, accessToken) => {
131
- const client = this.getClient();
132
- const res = await client.get(url, { headers: { 'X-Shopify-Access-Token': accessToken } });
133
- index_js_1.Logger.debug('Shopify Client Response', { res });
134
- return res;
135
- };
136
- static genericShopifyPut = async (url, accessToken, payload) => {
137
- const client = this.getClient();
138
- const res = await client.put(url, payload, { headers: { 'X-Shopify-Access-Token': accessToken } });
139
- index_js_1.Logger.debug('Shopify Client Response', { res });
140
- return res;
141
- };
142
- static unregisterWebhook = async (shop, webhookId, accessToken) => {
143
- const client = this.getClient();
144
- const url = `https://${shop}/admin/api/${this._shopify_api_version}/webhooks/${webhookId}.json`;
145
- const res = await client.delete(url, { headers: { 'X-Shopify-Access-Token': accessToken } });
146
- index_js_1.Logger.debug('Shopify Client Response', { res });
147
- return res;
148
- };
149
- }
150
- exports.ShopifyClient = ShopifyClient;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ShopifyClient = void 0;
4
+ const http_client_js_1 = require("../generic/http-client.js");
5
+ const index_js_1 = require("../../index.js");
6
+ class ShopifyClient {
7
+ static _shopify_api_version = process.env.SHOPIFY_API_VERSION;
8
+ static client;
9
+ static getConfig = (shopifyDomain, accessToken) => {
10
+ const config = {
11
+ baseURL: `https://${shopifyDomain}/admin/api/${this._shopify_api_version}`,
12
+ headers: {
13
+ common: {
14
+ 'X-Shopify-Access-Token': accessToken,
15
+ },
16
+ },
17
+ };
18
+ return config;
19
+ };
20
+ static getClient = () => {
21
+ this.client = this.client ?? (0, http_client_js_1.axiosHttpService)();
22
+ return this.client;
23
+ };
24
+ static registerApp = async (shop, code, appKey, appSecret) => {
25
+ const client = this.getClient();
26
+ const url = 'https://' + shop + '/admin/oauth/access_token';
27
+ const payload = {
28
+ client_id: appKey,
29
+ client_secret: appSecret,
30
+ code
31
+ };
32
+ const res = await client.post(url, payload);
33
+ return res;
34
+ };
35
+ static registerWebhookTopic = async (shop, accessToken, eventBridgeArn, topic) => {
36
+ const client = this.getClient();
37
+ const url = `https://${shop}/admin/api/${this._shopify_api_version}/webhooks.json`;
38
+ const payload = {
39
+ webhook: {
40
+ topic,
41
+ address: eventBridgeArn,
42
+ format: 'json'
43
+ }
44
+ };
45
+ const res = await client.post(url, payload, { headers: { 'X-Shopify-Access-Token': accessToken } });
46
+ if (res.status >= 400) {
47
+ index_js_1.Logger.error('Failed to register Webhook Topic', { res, shop, accessToken, eventBridgeArn, topic, url, payload });
48
+ }
49
+ index_js_1.Logger.debug('Shopify Client Webhook Registration Response', { registrationResponse: res });
50
+ return res;
51
+ };
52
+ static updateShopifyAppMetafield = async (shop, accessToken, pixelId) => {
53
+ const url = `https://${shop}/admin/api/${this._shopify_api_version}/metafields.json`;
54
+ const payload = {
55
+ metafield: {
56
+ namespace: 'adtr',
57
+ key: 'adtr.config',
58
+ value: pixelId,
59
+ type: 'single_line_text_field'
60
+ }
61
+ };
62
+ const res = await this.genericShopifyPost(url, accessToken, payload);
63
+ if (res.status >= 400) {
64
+ index_js_1.Logger.error('Failed to update Shopify app Metafield ', { shop, accessToken, url, payload });
65
+ }
66
+ return res;
67
+ };
68
+ static getShopifyStoreProperties = async (shop, accessToken) => {
69
+ const url = `https://${shop}/admin/api/${this._shopify_api_version}/shop.json`;
70
+ const res = await this.genericShopifyGet(url, accessToken);
71
+ if (res.status >= 400) {
72
+ index_js_1.Logger.error('Failed to get Shopify Store Properties', { shop, accessToken, url });
73
+ }
74
+ return res;
75
+ };
76
+ static createAppSubscription = async (shop, accessToken, planName, price, returnUrl, trialDays, test) => {
77
+ const url = `https://${shop}/admin/api/${this._shopify_api_version}/recurring_application_charges.json`;
78
+ const recurring_application_charge = {
79
+ name: planName,
80
+ price,
81
+ return_url: returnUrl,
82
+ trial_days: trialDays,
83
+ test
84
+ };
85
+ const res = await this.genericShopifyPost(url, accessToken, { recurring_application_charge });
86
+ if (res.status >= 400) {
87
+ index_js_1.Logger.error('Failed to create App Subscription', { shop, accessToken, url });
88
+ }
89
+ return res;
90
+ };
91
+ static cancelAppSubscription = async (shop, accessToken, chargeId) => {
92
+ const url = `https://${shop}/admin/api/${this._shopify_api_version}/recurring_application_charges/${chargeId}.json`;
93
+ const client = this.getClient();
94
+ const res = await client.delete(url, { headers: { 'X-Shopify-Access-Token': accessToken } });
95
+ if (res.status !== 200) {
96
+ index_js_1.Logger.error('Failed to cancel recurring App billing', { shop, accessToken, url });
97
+ }
98
+ return res;
99
+ };
100
+ static listAppSubscriptions = async (shop, accessToken) => {
101
+ const url = `https://${shop}/admin/api/${this._shopify_api_version}/recurring_application_charges.json`;
102
+ const res = await this.genericShopifyGet(url, accessToken);
103
+ if (res.status >= 400) {
104
+ index_js_1.Logger.error('Failed to get App Subscriptions', { shop, accessToken, url });
105
+ }
106
+ return res;
107
+ };
108
+ static getOrder = async (shop, accessToken, orderId) => {
109
+ const url = `https://${shop}/admin/api/${this._shopify_api_version}/orders/${orderId}.json`;
110
+ const res = await this.genericShopifyGet(url, accessToken);
111
+ if (res.status >= 400) {
112
+ index_js_1.Logger.error('Failed to get Order', { res, shop, accessToken, url, orderId });
113
+ }
114
+ return res;
115
+ };
116
+ static getProduct = async (shop, accessToken, productId) => {
117
+ const url = `https://${shop}/admin/api/${this._shopify_api_version}/products/${productId}.json`;
118
+ const res = await this.genericShopifyGet(url, accessToken);
119
+ if (res.status >= 400) {
120
+ index_js_1.Logger.error('Failed to get Product', { res, shop, accessToken, url, productId });
121
+ }
122
+ return res;
123
+ };
124
+ static genericShopifyPost = async (url, accessToken, payload) => {
125
+ const client = this.getClient();
126
+ const res = await client.post(url, payload, { headers: { 'X-Shopify-Access-Token': accessToken, 'Content-Type': 'application/json' } });
127
+ index_js_1.Logger.debug('Shopify Client Response', { res });
128
+ return res;
129
+ };
130
+ static genericShopifyGet = async (url, accessToken) => {
131
+ const client = this.getClient();
132
+ const res = await client.get(url, { headers: { 'X-Shopify-Access-Token': accessToken } });
133
+ index_js_1.Logger.debug('Shopify Client Response', { res });
134
+ return res;
135
+ };
136
+ static genericShopifyPut = async (url, accessToken, payload) => {
137
+ const client = this.getClient();
138
+ const res = await client.put(url, payload, { headers: { 'X-Shopify-Access-Token': accessToken } });
139
+ index_js_1.Logger.debug('Shopify Client Response', { res });
140
+ return res;
141
+ };
142
+ static unregisterWebhook = async (shop, webhookId, accessToken) => {
143
+ const client = this.getClient();
144
+ const url = `https://${shop}/admin/api/${this._shopify_api_version}/webhooks/${webhookId}.json`;
145
+ const res = await client.delete(url, { headers: { 'X-Shopify-Access-Token': accessToken } });
146
+ index_js_1.Logger.debug('Shopify Client Response', { res });
147
+ return res;
148
+ };
149
+ }
150
+ exports.ShopifyClient = ShopifyClient;
151
151
  //# sourceMappingURL=shopify-client.js.map
@@ -1,4 +1,4 @@
1
- import { AdClickInfo, EventIdentity } from '@adtrackify/at-tracking-event-types';
2
- import { IdentityCache } from '../services';
3
- export declare const isIdentityCacheStale: (identityCache: IdentityCache, incomingIdentity: EventIdentity) => boolean;
4
- export declare const isClickInfosStale: (cachedClick: AdClickInfo, incomingClick: AdClickInfo) => boolean;
1
+ import { AdClickInfo, EventIdentity } from '@adtrackify/at-tracking-event-types';
2
+ import { IdentityCache } from '../services';
3
+ export declare const isIdentityCacheStale: (identityCache: IdentityCache, incomingIdentity: EventIdentity) => boolean;
4
+ export declare const isClickInfosStale: (cachedClick: AdClickInfo, incomingClick: AdClickInfo) => boolean;
@@ -1,151 +1,151 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isClickInfosStale = exports.isIdentityCacheStale = void 0;
4
- const at_shared_utils_1 = require("@adtrackify/at-shared-utils");
5
- const logging_helper_1 = require("./logging-helper");
6
- const isIdentityCacheStale = (identityCache, incomingIdentity) => {
7
- try {
8
- const cachedTraits = identityCache.response?.traits ?? {};
9
- const incomingTraits = incomingIdentity?.traits ?? {};
10
- const identityCacheStaleTracker = {
11
- cachedTraits: cachedTraits,
12
- incomingTraits: incomingTraits,
13
- isUserIdsStale: false,
14
- isIdsStale: false,
15
- isEmailsStale: false,
16
- isPhonesStale: false,
17
- isShopifyYIdsStale: false,
18
- isGendersStale: false,
19
- isDobsStale: false,
20
- isAddressesStale: false,
21
- isClickInfosStale: false,
22
- isIpAddressStale: false,
23
- isUserAgentStale: false,
24
- isCacheStale: false
25
- };
26
- const isNewUserIds = (0, at_shared_utils_1.hasNewTrait)(cachedTraits?.userIds ?? [], incomingTraits?.userIds ?? []);
27
- if (isNewUserIds) {
28
- logging_helper_1.Logger.debug('identity cache miss - userIds changed', { cachedTraits, incomingTraits });
29
- identityCacheStaleTracker.isUserIdsStale = true;
30
- identityCacheStaleTracker.isCacheStale = true;
31
- }
32
- const isNewIds = (0, at_shared_utils_1.hasNewTrait)(cachedTraits?.ids ?? [], incomingTraits?.ids ?? []);
33
- if (isNewIds) {
34
- logging_helper_1.Logger.debug('identity cache miss - ids changed', { cachedTraits, incomingTraits });
35
- identityCacheStaleTracker.isIdsStale = true;
36
- identityCacheStaleTracker.isCacheStale = true;
37
- }
38
- const isNewEmails = (0, at_shared_utils_1.hasNewTrait)(cachedTraits?.emails ?? [], incomingTraits?.emails ?? []);
39
- if (isNewEmails) {
40
- logging_helper_1.Logger.debug('identity cache miss - emails changed', { cachedTraits, incomingTraits });
41
- identityCacheStaleTracker.isEmailsStale = true;
42
- identityCacheStaleTracker.isCacheStale = true;
43
- }
44
- const isNewPhones = (0, at_shared_utils_1.hasNewTrait)(cachedTraits?.phones ?? [], incomingTraits?.phones ?? []);
45
- if (isNewPhones) {
46
- logging_helper_1.Logger.debug('identity cache miss - phones changed', { cachedTraits, incomingTraits });
47
- identityCacheStaleTracker.isPhonesStale = true;
48
- identityCacheStaleTracker.isCacheStale = true;
49
- }
50
- const isNewShopifyYIds = (0, at_shared_utils_1.hasNewTrait)(cachedTraits?.shopifyYIds ?? [], incomingTraits?.shopifyYIds ?? []);
51
- if (isNewShopifyYIds) {
52
- logging_helper_1.Logger.debug('identity cache miss - shopify Y ids changed', { cachedTraits, incomingTraits });
53
- identityCacheStaleTracker.isShopifyYIdsStale = true;
54
- identityCacheStaleTracker.isCacheStale = true;
55
- }
56
- const isNewGenders = (0, at_shared_utils_1.hasNewTrait)(cachedTraits?.genders ?? [], incomingTraits?.genders ?? []);
57
- if (isNewGenders) {
58
- logging_helper_1.Logger.debug('identity cache miss - genders changed', { cachedTraits, incomingTraits });
59
- identityCacheStaleTracker.isGendersStale = true;
60
- identityCacheStaleTracker.isCacheStale = true;
61
- }
62
- const isNewDobs = (0, at_shared_utils_1.hasNewTrait)(cachedTraits?.dobs ?? [], incomingTraits?.dobs ?? []);
63
- if (isNewDobs) {
64
- logging_helper_1.Logger.debug('identity cache miss - dobs changed', { cachedTraits, incomingTraits });
65
- identityCacheStaleTracker.isDobsStale = true;
66
- identityCacheStaleTracker.isCacheStale = true;
67
- }
68
- const isNewAddress = (0, at_shared_utils_1.hasNewAddress)(cachedTraits?.addresses ?? [], incomingTraits?.addresses ?? []);
69
- if (isNewAddress) {
70
- logging_helper_1.Logger.debug('identity cache miss - address changed', { cachedTraits, incomingTraits });
71
- identityCacheStaleTracker.isAddressesStale = true;
72
- identityCacheStaleTracker.isCacheStale = true;
73
- }
74
- const isNewClick = (0, exports.isClickInfosStale)(cachedTraits?.click ?? {}, incomingTraits?.click ?? {});
75
- if (isNewClick) {
76
- logging_helper_1.Logger.debug('identity cache miss - clickInfos changed', { cachedTraits, incomingTraits });
77
- identityCacheStaleTracker.isClickInfosStale = true;
78
- identityCacheStaleTracker.isCacheStale = true;
79
- }
80
- if (incomingTraits?.ipAddress && cachedTraits?.ipAddress !== incomingTraits?.ipAddress) {
81
- logging_helper_1.Logger.debug('identity cache miss - ip/userAgent changed', { cachedTraits, incomingTraits });
82
- identityCacheStaleTracker.isIpAddressStale = true;
83
- identityCacheStaleTracker.isCacheStale = true;
84
- }
85
- if (incomingTraits?.userAgent && cachedTraits?.userAgent !== incomingTraits?.userAgent) {
86
- logging_helper_1.Logger.debug('identity cache miss - userAgent changed', { cachedTraits, incomingTraits });
87
- identityCacheStaleTracker.isUserAgentStale = true;
88
- identityCacheStaleTracker.isCacheStale = true;
89
- }
90
- if (identityCacheStaleTracker.isCacheStale) {
91
- logging_helper_1.Logger.debug('identity cache miss - cache stale', { identityCacheStaleTracker });
92
- }
93
- return identityCacheStaleTracker.isCacheStale;
94
- }
95
- catch (err) {
96
- logging_helper_1.Logger.error('Error while checking if identity cache is stale', { err });
97
- return true;
98
- }
99
- };
100
- exports.isIdentityCacheStale = isIdentityCacheStale;
101
- const isClickInfosStale = (cachedClick, incomingClick) => {
102
- const cleanedCachedClick = (0, at_shared_utils_1.removeEmptyFields)(cachedClick);
103
- const cleanedIncomingClick = (0, at_shared_utils_1.removeEmptyFields)(incomingClick);
104
- const incomingKeys = Object.keys(cleanedIncomingClick);
105
- const clickInfoStaleTracker = {
106
- cleanedCachedClick,
107
- cleanedIncomingClick,
108
- isClickInfosStale: false,
109
- staleKeys: []
110
- };
111
- incomingKeys.forEach(key => {
112
- if (key === 'googleClientInfos' || key.includes('CollectedAt')) {
113
- return true;
114
- }
115
- else if (key === 'fbc') {
116
- const cachedClickValue = cleanedCachedClick?.[key];
117
- const incomingClickValue = cleanedIncomingClick?.[key];
118
- if (incomingClickValue && !cachedClickValue) {
119
- clickInfoStaleTracker.isClickInfosStale = true;
120
- clickInfoStaleTracker.staleKeys.push(key);
121
- }
122
- else if (incomingClickValue && cachedClickValue && incomingClickValue !== cachedClickValue) {
123
- const incomingFbcFbclid = incomingClickValue?.split('.')?.[3];
124
- const cachedFbcFbclid = cachedClickValue?.split('.')?.[3];
125
- if (incomingFbcFbclid !== cachedFbcFbclid) {
126
- clickInfoStaleTracker.isClickInfosStale = true;
127
- clickInfoStaleTracker.staleKeys.push(key);
128
- }
129
- if (!incomingFbcFbclid || !cachedFbcFbclid) {
130
- clickInfoStaleTracker.isClickInfosStale = true;
131
- clickInfoStaleTracker.staleKeys.push(key);
132
- }
133
- }
134
- }
135
- else {
136
- const cachedClickValue = cleanedCachedClick?.[key];
137
- const incomingClickValue = cleanedIncomingClick?.[key];
138
- if ((incomingClickValue && !cachedClickValue)
139
- || incomingClickValue !== cachedClickValue) {
140
- clickInfoStaleTracker.isClickInfosStale = true;
141
- clickInfoStaleTracker.staleKeys.push(key);
142
- }
143
- }
144
- });
145
- if (clickInfoStaleTracker.isClickInfosStale) {
146
- logging_helper_1.Logger.debug('identity cache miss - clickInfos changed', { clickInfoStaleTracker });
147
- }
148
- return clickInfoStaleTracker.isClickInfosStale;
149
- };
150
- exports.isClickInfosStale = isClickInfosStale;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isClickInfosStale = exports.isIdentityCacheStale = void 0;
4
+ const at_shared_utils_1 = require("@adtrackify/at-shared-utils");
5
+ const logging_helper_1 = require("./logging-helper");
6
+ const isIdentityCacheStale = (identityCache, incomingIdentity) => {
7
+ try {
8
+ const cachedTraits = identityCache.response?.traits ?? {};
9
+ const incomingTraits = incomingIdentity?.traits ?? {};
10
+ const identityCacheStaleTracker = {
11
+ cachedTraits: cachedTraits,
12
+ incomingTraits: incomingTraits,
13
+ isUserIdsStale: false,
14
+ isIdsStale: false,
15
+ isEmailsStale: false,
16
+ isPhonesStale: false,
17
+ isShopifyYIdsStale: false,
18
+ isGendersStale: false,
19
+ isDobsStale: false,
20
+ isAddressesStale: false,
21
+ isClickInfosStale: false,
22
+ isIpAddressStale: false,
23
+ isUserAgentStale: false,
24
+ isCacheStale: false
25
+ };
26
+ const isNewUserIds = (0, at_shared_utils_1.hasNewTrait)(cachedTraits?.userIds ?? [], incomingTraits?.userIds ?? []);
27
+ if (isNewUserIds) {
28
+ logging_helper_1.Logger.debug('identity cache miss - userIds changed', { cachedTraits, incomingTraits });
29
+ identityCacheStaleTracker.isUserIdsStale = true;
30
+ identityCacheStaleTracker.isCacheStale = true;
31
+ }
32
+ const isNewIds = (0, at_shared_utils_1.hasNewTrait)(cachedTraits?.ids ?? [], incomingTraits?.ids ?? []);
33
+ if (isNewIds) {
34
+ logging_helper_1.Logger.debug('identity cache miss - ids changed', { cachedTraits, incomingTraits });
35
+ identityCacheStaleTracker.isIdsStale = true;
36
+ identityCacheStaleTracker.isCacheStale = true;
37
+ }
38
+ const isNewEmails = (0, at_shared_utils_1.hasNewTrait)(cachedTraits?.emails ?? [], incomingTraits?.emails ?? []);
39
+ if (isNewEmails) {
40
+ logging_helper_1.Logger.debug('identity cache miss - emails changed', { cachedTraits, incomingTraits });
41
+ identityCacheStaleTracker.isEmailsStale = true;
42
+ identityCacheStaleTracker.isCacheStale = true;
43
+ }
44
+ const isNewPhones = (0, at_shared_utils_1.hasNewTrait)(cachedTraits?.phones ?? [], incomingTraits?.phones ?? []);
45
+ if (isNewPhones) {
46
+ logging_helper_1.Logger.debug('identity cache miss - phones changed', { cachedTraits, incomingTraits });
47
+ identityCacheStaleTracker.isPhonesStale = true;
48
+ identityCacheStaleTracker.isCacheStale = true;
49
+ }
50
+ const isNewShopifyYIds = (0, at_shared_utils_1.hasNewTrait)(cachedTraits?.shopifyYIds ?? [], incomingTraits?.shopifyYIds ?? []);
51
+ if (isNewShopifyYIds) {
52
+ logging_helper_1.Logger.debug('identity cache miss - shopify Y ids changed', { cachedTraits, incomingTraits });
53
+ identityCacheStaleTracker.isShopifyYIdsStale = true;
54
+ identityCacheStaleTracker.isCacheStale = true;
55
+ }
56
+ const isNewGenders = (0, at_shared_utils_1.hasNewTrait)(cachedTraits?.genders ?? [], incomingTraits?.genders ?? []);
57
+ if (isNewGenders) {
58
+ logging_helper_1.Logger.debug('identity cache miss - genders changed', { cachedTraits, incomingTraits });
59
+ identityCacheStaleTracker.isGendersStale = true;
60
+ identityCacheStaleTracker.isCacheStale = true;
61
+ }
62
+ const isNewDobs = (0, at_shared_utils_1.hasNewTrait)(cachedTraits?.dobs ?? [], incomingTraits?.dobs ?? []);
63
+ if (isNewDobs) {
64
+ logging_helper_1.Logger.debug('identity cache miss - dobs changed', { cachedTraits, incomingTraits });
65
+ identityCacheStaleTracker.isDobsStale = true;
66
+ identityCacheStaleTracker.isCacheStale = true;
67
+ }
68
+ const isNewAddress = (0, at_shared_utils_1.hasNewAddress)(cachedTraits?.addresses ?? [], incomingTraits?.addresses ?? []);
69
+ if (isNewAddress) {
70
+ logging_helper_1.Logger.debug('identity cache miss - address changed', { cachedTraits, incomingTraits });
71
+ identityCacheStaleTracker.isAddressesStale = true;
72
+ identityCacheStaleTracker.isCacheStale = true;
73
+ }
74
+ const isNewClick = (0, exports.isClickInfosStale)(cachedTraits?.click ?? {}, incomingTraits?.click ?? {});
75
+ if (isNewClick) {
76
+ logging_helper_1.Logger.debug('identity cache miss - clickInfos changed', { cachedTraits, incomingTraits });
77
+ identityCacheStaleTracker.isClickInfosStale = true;
78
+ identityCacheStaleTracker.isCacheStale = true;
79
+ }
80
+ if (incomingTraits?.ipAddress && cachedTraits?.ipAddress !== incomingTraits?.ipAddress) {
81
+ logging_helper_1.Logger.debug('identity cache miss - ip/userAgent changed', { cachedTraits, incomingTraits });
82
+ identityCacheStaleTracker.isIpAddressStale = true;
83
+ identityCacheStaleTracker.isCacheStale = true;
84
+ }
85
+ if (incomingTraits?.userAgent && cachedTraits?.userAgent !== incomingTraits?.userAgent) {
86
+ logging_helper_1.Logger.debug('identity cache miss - userAgent changed', { cachedTraits, incomingTraits });
87
+ identityCacheStaleTracker.isUserAgentStale = true;
88
+ identityCacheStaleTracker.isCacheStale = true;
89
+ }
90
+ if (identityCacheStaleTracker.isCacheStale) {
91
+ logging_helper_1.Logger.debug('identity cache miss - cache stale', { identityCacheStaleTracker });
92
+ }
93
+ return identityCacheStaleTracker.isCacheStale;
94
+ }
95
+ catch (err) {
96
+ logging_helper_1.Logger.error('Error while checking if identity cache is stale', { err });
97
+ return true;
98
+ }
99
+ };
100
+ exports.isIdentityCacheStale = isIdentityCacheStale;
101
+ const isClickInfosStale = (cachedClick, incomingClick) => {
102
+ const cleanedCachedClick = (0, at_shared_utils_1.removeEmptyFields)(cachedClick);
103
+ const cleanedIncomingClick = (0, at_shared_utils_1.removeEmptyFields)(incomingClick);
104
+ const incomingKeys = Object.keys(cleanedIncomingClick);
105
+ const clickInfoStaleTracker = {
106
+ cleanedCachedClick,
107
+ cleanedIncomingClick,
108
+ isClickInfosStale: false,
109
+ staleKeys: []
110
+ };
111
+ incomingKeys.forEach(key => {
112
+ if (key === 'googleClientInfos' || key.includes('CollectedAt')) {
113
+ return true;
114
+ }
115
+ else if (key === 'fbc') {
116
+ const cachedClickValue = cleanedCachedClick?.[key];
117
+ const incomingClickValue = cleanedIncomingClick?.[key];
118
+ if (incomingClickValue && !cachedClickValue) {
119
+ clickInfoStaleTracker.isClickInfosStale = true;
120
+ clickInfoStaleTracker.staleKeys.push(key);
121
+ }
122
+ else if (incomingClickValue && cachedClickValue && incomingClickValue !== cachedClickValue) {
123
+ const incomingFbcFbclid = incomingClickValue?.split('.')?.[3];
124
+ const cachedFbcFbclid = cachedClickValue?.split('.')?.[3];
125
+ if (incomingFbcFbclid !== cachedFbcFbclid) {
126
+ clickInfoStaleTracker.isClickInfosStale = true;
127
+ clickInfoStaleTracker.staleKeys.push(key);
128
+ }
129
+ if (!incomingFbcFbclid || !cachedFbcFbclid) {
130
+ clickInfoStaleTracker.isClickInfosStale = true;
131
+ clickInfoStaleTracker.staleKeys.push(key);
132
+ }
133
+ }
134
+ }
135
+ else {
136
+ const cachedClickValue = cleanedCachedClick?.[key];
137
+ const incomingClickValue = cleanedIncomingClick?.[key];
138
+ if ((incomingClickValue && !cachedClickValue)
139
+ || incomingClickValue !== cachedClickValue) {
140
+ clickInfoStaleTracker.isClickInfosStale = true;
141
+ clickInfoStaleTracker.staleKeys.push(key);
142
+ }
143
+ }
144
+ });
145
+ if (clickInfoStaleTracker.isClickInfosStale) {
146
+ logging_helper_1.Logger.debug('identity cache miss - clickInfos changed', { clickInfoStaleTracker });
147
+ }
148
+ return clickInfoStaleTracker.isClickInfosStale;
149
+ };
150
+ exports.isClickInfosStale = isClickInfosStale;
151
151
  //# sourceMappingURL=identity-cache-helper.js.map
@@ -1,5 +1,5 @@
1
- export * from './input-validation-helper.js';
2
- export * from './logging-helper.js';
3
- export * from './response-helper.js';
4
- export * from './shopify-helper.js';
5
- export * from './identity-cache-helper.js';
1
+ export * from './input-validation-helper.js';
2
+ export * from './logging-helper.js';
3
+ export * from './response-helper.js';
4
+ export * from './shopify-helper.js';
5
+ export * from './identity-cache-helper.js';