@adtrackify/at-service-common 2.0.15 → 2.0.17

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 (193) hide show
  1. package/dist/cjs/__tests__/helpers/subscription-helper.spec.d.ts +1 -1
  2. package/dist/cjs/__tests__/helpers/subscription-helper.spec.js +52 -52
  3. package/dist/cjs/__tests__/s3-client/s3-client.spec.d.ts +1 -1
  4. package/dist/cjs/__tests__/s3-client/s3-client.spec.js +26 -26
  5. package/dist/cjs/clients/generic/cognito-client.d.ts +19 -19
  6. package/dist/cjs/clients/generic/cognito-client.js +144 -144
  7. package/dist/cjs/clients/generic/dynamodb-client.d.ts +15 -15
  8. package/dist/cjs/clients/generic/dynamodb-client.js +124 -124
  9. package/dist/cjs/clients/generic/eventbridge-client.d.ts +14 -14
  10. package/dist/cjs/clients/generic/eventbridge-client.js +49 -49
  11. package/dist/cjs/clients/generic/http-client.d.ts +30 -30
  12. package/dist/cjs/clients/generic/http-client.js +35 -35
  13. package/dist/cjs/clients/generic/http-client.js.map +1 -1
  14. package/dist/cjs/clients/generic/index.d.ts +6 -6
  15. package/dist/cjs/clients/generic/index.js +22 -22
  16. package/dist/cjs/clients/generic/s3-client.d.ts +14 -14
  17. package/dist/cjs/clients/generic/s3-client.js +82 -82
  18. package/dist/cjs/clients/generic/sqs-client.d.ts +14 -14
  19. package/dist/cjs/clients/generic/sqs-client.js +38 -38
  20. package/dist/cjs/clients/index.d.ts +3 -3
  21. package/dist/cjs/clients/index.js +19 -19
  22. package/dist/cjs/clients/internal-api/accounts-client.d.ts +82 -82
  23. package/dist/cjs/clients/internal-api/accounts-client.js +82 -82
  24. package/dist/cjs/clients/internal-api/db-management-client.d.ts +48 -0
  25. package/dist/cjs/clients/internal-api/db-management-client.js +38 -0
  26. package/dist/cjs/clients/internal-api/db-management-client.js.map +1 -0
  27. package/dist/cjs/clients/internal-api/destinations-client.d.ts +54 -54
  28. package/dist/cjs/clients/internal-api/destinations-client.js +40 -40
  29. package/dist/cjs/clients/internal-api/event-collector-client.d.ts +47 -0
  30. package/dist/cjs/clients/internal-api/event-collector-client.js +38 -0
  31. package/dist/cjs/clients/internal-api/event-collector-client.js.map +1 -0
  32. package/dist/cjs/clients/internal-api/identity-client.d.ts +7 -7
  33. package/dist/cjs/clients/internal-api/identity-client.js +41 -41
  34. package/dist/cjs/clients/internal-api/index.d.ts +7 -5
  35. package/dist/cjs/clients/internal-api/index.js +23 -21
  36. package/dist/cjs/clients/internal-api/index.js.map +1 -1
  37. package/dist/cjs/clients/internal-api/shopify-app-install-client.d.ts +57 -57
  38. package/dist/cjs/clients/internal-api/shopify-app-install-client.js +49 -49
  39. package/dist/cjs/clients/internal-api/users-auth-client.d.ts +61 -61
  40. package/dist/cjs/clients/internal-api/users-auth-client.js +77 -77
  41. package/dist/cjs/clients/third-party/index.d.ts +1 -1
  42. package/dist/cjs/clients/third-party/index.js +17 -17
  43. package/dist/cjs/clients/third-party/shopify-client.d.ts +90 -90
  44. package/dist/cjs/clients/third-party/shopify-client.js +125 -125
  45. package/dist/cjs/helpers/index.d.ts +5 -5
  46. package/dist/cjs/helpers/index.js +21 -21
  47. package/dist/cjs/helpers/input-validation-helper.d.ts +2 -2
  48. package/dist/cjs/helpers/input-validation-helper.js +22 -22
  49. package/dist/cjs/helpers/logging-helper.d.ts +15 -15
  50. package/dist/cjs/helpers/logging-helper.js +80 -80
  51. package/dist/cjs/helpers/response-helper.d.ts +36 -36
  52. package/dist/cjs/helpers/response-helper.js +41 -41
  53. package/dist/cjs/helpers/shopify-helper.d.ts +9 -9
  54. package/dist/cjs/helpers/shopify-helper.js +28 -28
  55. package/dist/cjs/helpers/subscription-helper.d.ts +8 -8
  56. package/dist/cjs/helpers/subscription-helper.js +104 -104
  57. package/dist/cjs/index.d.ts +5 -5
  58. package/dist/cjs/index.js +21 -21
  59. package/dist/cjs/libs/clickId-parser.d.ts +23 -23
  60. package/dist/cjs/libs/clickId-parser.js +49 -49
  61. package/dist/cjs/libs/crypto.d.ts +1 -1
  62. package/dist/cjs/libs/crypto.js +12 -12
  63. package/dist/cjs/libs/dates.d.ts +3 -3
  64. package/dist/cjs/libs/dates.js +16 -16
  65. package/dist/cjs/libs/http-error.d.ts +21 -21
  66. package/dist/cjs/libs/http-error.js +59 -59
  67. package/dist/cjs/libs/http-status-codes.d.ts +58 -58
  68. package/dist/cjs/libs/http-status-codes.js +62 -62
  69. package/dist/cjs/libs/index.d.ts +8 -8
  70. package/dist/cjs/libs/index.js +24 -24
  71. package/dist/cjs/libs/referrer-parser/index.d.ts +2 -2
  72. package/dist/cjs/libs/referrer-parser/index.js +18 -18
  73. package/dist/cjs/libs/referrer-parser/referrer-data.d.ts +9 -9
  74. package/dist/cjs/libs/referrer-parser/referrer-data.js +4712 -4712
  75. package/dist/cjs/libs/referrer-parser/referrer-parser-util.d.ts +20 -20
  76. package/dist/cjs/libs/referrer-parser/referrer-parser-util.js +128 -128
  77. package/dist/cjs/libs/url.d.ts +1 -1
  78. package/dist/cjs/libs/url.js +13 -13
  79. package/dist/cjs/services/eventbridge-integration-service.d.ts +9 -9
  80. package/dist/cjs/services/eventbridge-integration-service.js +28 -28
  81. package/dist/cjs/services/index.d.ts +4 -4
  82. package/dist/cjs/services/index.js +20 -20
  83. package/dist/cjs/services/ipdata-lookup-service.d.ts +8 -8
  84. package/dist/cjs/services/ipdata-lookup-service.js +59 -59
  85. package/dist/cjs/services/log-event-service.d.ts +9 -9
  86. package/dist/cjs/services/log-event-service.js +50 -50
  87. package/dist/cjs/services/metric-event-service.d.ts +9 -9
  88. package/dist/cjs/services/metric-event-service.js +49 -49
  89. package/dist/cjs/types/api-response.d.ts +6 -6
  90. package/dist/cjs/types/api-response.js +2 -2
  91. package/dist/cjs/types/index.d.ts +1 -1
  92. package/dist/cjs/types/index.js +17 -17
  93. package/dist/cjs/types/internal-events/event-detail-types.d.ts +20 -20
  94. package/dist/cjs/types/internal-events/event-detail-types.js +27 -27
  95. package/dist/cjs/types/internal-events/index.d.ts +1 -1
  96. package/dist/cjs/types/internal-events/index.js +17 -17
  97. package/dist/esm/__tests__/helpers/subscription-helper.spec.d.ts +1 -1
  98. package/dist/esm/__tests__/helpers/subscription-helper.spec.js +27 -27
  99. package/dist/esm/__tests__/s3-client/s3-client.spec.d.ts +1 -1
  100. package/dist/esm/__tests__/s3-client/s3-client.spec.js +24 -24
  101. package/dist/esm/clients/generic/cognito-client.d.ts +19 -19
  102. package/dist/esm/clients/generic/cognito-client.js +139 -139
  103. package/dist/esm/clients/generic/dynamodb-client.d.ts +15 -15
  104. package/dist/esm/clients/generic/dynamodb-client.js +120 -120
  105. package/dist/esm/clients/generic/eventbridge-client.d.ts +14 -14
  106. package/dist/esm/clients/generic/eventbridge-client.js +45 -45
  107. package/dist/esm/clients/generic/http-client.d.ts +30 -30
  108. package/dist/esm/clients/generic/http-client.js +28 -28
  109. package/dist/esm/clients/generic/http-client.js.map +1 -1
  110. package/dist/esm/clients/generic/index.d.ts +6 -6
  111. package/dist/esm/clients/generic/index.js +6 -6
  112. package/dist/esm/clients/generic/s3-client.d.ts +14 -14
  113. package/dist/esm/clients/generic/s3-client.js +78 -78
  114. package/dist/esm/clients/generic/sqs-client.d.ts +14 -14
  115. package/dist/esm/clients/generic/sqs-client.js +34 -34
  116. package/dist/esm/clients/index.d.ts +3 -3
  117. package/dist/esm/clients/index.js +3 -3
  118. package/dist/esm/clients/internal-api/accounts-client.d.ts +82 -82
  119. package/dist/esm/clients/internal-api/accounts-client.js +78 -78
  120. package/dist/esm/clients/internal-api/db-management-client.d.ts +48 -0
  121. package/dist/esm/clients/internal-api/db-management-client.js +31 -0
  122. package/dist/esm/clients/internal-api/db-management-client.js.map +1 -0
  123. package/dist/esm/clients/internal-api/destinations-client.d.ts +54 -54
  124. package/dist/esm/clients/internal-api/destinations-client.js +36 -36
  125. package/dist/esm/clients/internal-api/event-collector-client.d.ts +47 -0
  126. package/dist/esm/clients/internal-api/event-collector-client.js +31 -0
  127. package/dist/esm/clients/internal-api/event-collector-client.js.map +1 -0
  128. package/dist/esm/clients/internal-api/identity-client.d.ts +7 -7
  129. package/dist/esm/clients/internal-api/identity-client.js +37 -37
  130. package/dist/esm/clients/internal-api/index.d.ts +7 -5
  131. package/dist/esm/clients/internal-api/index.js +7 -5
  132. package/dist/esm/clients/internal-api/index.js.map +1 -1
  133. package/dist/esm/clients/internal-api/shopify-app-install-client.d.ts +57 -57
  134. package/dist/esm/clients/internal-api/shopify-app-install-client.js +42 -42
  135. package/dist/esm/clients/internal-api/users-auth-client.d.ts +61 -61
  136. package/dist/esm/clients/internal-api/users-auth-client.js +73 -73
  137. package/dist/esm/clients/third-party/index.d.ts +1 -1
  138. package/dist/esm/clients/third-party/index.js +1 -1
  139. package/dist/esm/clients/third-party/shopify-client.d.ts +90 -90
  140. package/dist/esm/clients/third-party/shopify-client.js +121 -121
  141. package/dist/esm/helpers/index.d.ts +5 -5
  142. package/dist/esm/helpers/index.js +5 -5
  143. package/dist/esm/helpers/input-validation-helper.d.ts +2 -2
  144. package/dist/esm/helpers/input-validation-helper.js +18 -18
  145. package/dist/esm/helpers/logging-helper.d.ts +15 -15
  146. package/dist/esm/helpers/logging-helper.js +53 -53
  147. package/dist/esm/helpers/response-helper.d.ts +36 -36
  148. package/dist/esm/helpers/response-helper.js +35 -35
  149. package/dist/esm/helpers/shopify-helper.d.ts +9 -9
  150. package/dist/esm/helpers/shopify-helper.js +23 -23
  151. package/dist/esm/helpers/subscription-helper.d.ts +8 -8
  152. package/dist/esm/helpers/subscription-helper.js +99 -99
  153. package/dist/esm/index.d.ts +5 -5
  154. package/dist/esm/index.js +5 -5
  155. package/dist/esm/libs/clickId-parser.d.ts +23 -23
  156. package/dist/esm/libs/clickId-parser.js +45 -45
  157. package/dist/esm/libs/crypto.d.ts +1 -1
  158. package/dist/esm/libs/crypto.js +5 -5
  159. package/dist/esm/libs/dates.d.ts +3 -3
  160. package/dist/esm/libs/dates.js +10 -10
  161. package/dist/esm/libs/http-error.d.ts +21 -21
  162. package/dist/esm/libs/http-error.js +55 -55
  163. package/dist/esm/libs/http-status-codes.d.ts +58 -58
  164. package/dist/esm/libs/http-status-codes.js +59 -59
  165. package/dist/esm/libs/index.d.ts +8 -8
  166. package/dist/esm/libs/index.js +8 -8
  167. package/dist/esm/libs/referrer-parser/index.d.ts +2 -2
  168. package/dist/esm/libs/referrer-parser/index.js +2 -2
  169. package/dist/esm/libs/referrer-parser/referrer-data.d.ts +9 -9
  170. package/dist/esm/libs/referrer-parser/referrer-data.js +4709 -4709
  171. package/dist/esm/libs/referrer-parser/referrer-parser-util.d.ts +20 -20
  172. package/dist/esm/libs/referrer-parser/referrer-parser-util.js +121 -121
  173. package/dist/esm/libs/url.d.ts +1 -1
  174. package/dist/esm/libs/url.js +9 -9
  175. package/dist/esm/services/eventbridge-integration-service.d.ts +9 -9
  176. package/dist/esm/services/eventbridge-integration-service.js +24 -24
  177. package/dist/esm/services/index.d.ts +4 -4
  178. package/dist/esm/services/index.js +4 -4
  179. package/dist/esm/services/ipdata-lookup-service.d.ts +8 -8
  180. package/dist/esm/services/ipdata-lookup-service.js +55 -55
  181. package/dist/esm/services/log-event-service.d.ts +9 -9
  182. package/dist/esm/services/log-event-service.js +46 -46
  183. package/dist/esm/services/metric-event-service.d.ts +9 -9
  184. package/dist/esm/services/metric-event-service.js +45 -45
  185. package/dist/esm/types/api-response.d.ts +6 -6
  186. package/dist/esm/types/api-response.js +1 -1
  187. package/dist/esm/types/index.d.ts +1 -1
  188. package/dist/esm/types/index.js +1 -1
  189. package/dist/esm/types/internal-events/event-detail-types.d.ts +20 -20
  190. package/dist/esm/types/internal-events/event-detail-types.js +24 -24
  191. package/dist/esm/types/internal-events/index.d.ts +1 -1
  192. package/dist/esm/types/internal-events/index.js +1 -1
  193. package/package.json +1 -1
@@ -1,90 +1,90 @@
1
- export declare class ShopifyClient {
2
- static _shopify_api_version: string;
3
- static getConfig: (shopifyDomain: string, accessToken: string) => {
4
- baseURL: string;
5
- headers: {
6
- common: {
7
- 'X-Shopify-Access-Token': string;
8
- };
9
- };
10
- };
11
- static getClient: (shopifyDomain: string, accessToken: string) => {
12
- instance: () => import("axios").AxiosInstance;
13
- get: (url: string, config?: any) => Promise<{
14
- headers: any;
15
- data: any;
16
- status: any;
17
- }>;
18
- post: (url: string, data?: any, config?: any) => Promise<{
19
- headers: any;
20
- data: any;
21
- status: any;
22
- }>;
23
- delete: (url: string, config?: any) => Promise<{
24
- headers: any;
25
- data: any;
26
- status: any;
27
- }>;
28
- put: (url: string, data?: any, config?: any) => Promise<{
29
- headers: any;
30
- data: any;
31
- status: any;
32
- }>;
33
- patch: (url: string, data?: any, config?: any) => Promise<{
34
- headers: any;
35
- data: any;
36
- status: any;
37
- }>;
38
- setBaseUrl: (url: string) => boolean;
39
- };
40
- static registerApp: (shop: string, code: string, appKey: string, appSecret: string) => Promise<{
41
- headers: any;
42
- data: any;
43
- status: any;
44
- }>;
45
- static registerWebhookTopic: (shop: string, accessToken: string, eventBridgeArn: string, topic: string) => Promise<{
46
- headers: any;
47
- data: any;
48
- status: any;
49
- }>;
50
- static updateShopifyAppMetafield: (shop: string, accessToken: string, pixelId: string) => Promise<{
51
- headers: any;
52
- data: any;
53
- status: any;
54
- }>;
55
- static getShopifyStoreProperties: (shop: string, accessToken: string) => Promise<{
56
- headers: any;
57
- data: any;
58
- status: any;
59
- }>;
60
- static createAppSubscription: (shop: string, accessToken: string, planName: string, price: number, returnUrl: string, trialDays: number, test?: boolean) => Promise<{
61
- headers: any;
62
- data: any;
63
- status: any;
64
- }>;
65
- static cancelAppSubscription: (shop: string, accessToken: string, chargeId: string) => Promise<{
66
- headers: any;
67
- data: any;
68
- status: any;
69
- }>;
70
- static listAppSubscriptions: (shop: string, accessToken: string) => Promise<{
71
- headers: any;
72
- data: any;
73
- status: any;
74
- }>;
75
- static genericShopifyPost: (url: string, accessToken: string, payload: any) => Promise<{
76
- headers: any;
77
- data: any;
78
- status: any;
79
- }>;
80
- static genericShopifyGet: (url: string, accessToken: string) => Promise<{
81
- headers: any;
82
- data: any;
83
- status: any;
84
- }>;
85
- static genericShopifyPut: (url: string, accessToken: string, payload: any) => Promise<{
86
- headers: any;
87
- data: any;
88
- status: any;
89
- }>;
90
- }
1
+ export declare class ShopifyClient {
2
+ static _shopify_api_version: string;
3
+ static getConfig: (shopifyDomain: string, accessToken: string) => {
4
+ baseURL: string;
5
+ headers: {
6
+ common: {
7
+ 'X-Shopify-Access-Token': string;
8
+ };
9
+ };
10
+ };
11
+ static getClient: (shopifyDomain: string, accessToken: string) => {
12
+ instance: () => import("axios").AxiosInstance;
13
+ get: (url: string, config?: import("axios").AxiosRequestConfig<any> | undefined) => Promise<{
14
+ headers: any;
15
+ data: any;
16
+ status: any;
17
+ }>;
18
+ post: (url: string, data?: any, config?: any) => Promise<{
19
+ headers: any;
20
+ data: any;
21
+ status: any;
22
+ }>;
23
+ delete: (url: string, config?: any) => Promise<{
24
+ headers: any;
25
+ data: any;
26
+ status: any;
27
+ }>;
28
+ put: (url: string, data?: any, config?: any) => Promise<{
29
+ headers: any;
30
+ data: any;
31
+ status: any;
32
+ }>;
33
+ patch: (url: string, data?: any, config?: any) => Promise<{
34
+ headers: any;
35
+ data: any;
36
+ status: any;
37
+ }>;
38
+ setBaseUrl: (url: string) => boolean;
39
+ };
40
+ static registerApp: (shop: string, code: string, appKey: string, appSecret: string) => Promise<{
41
+ headers: any;
42
+ data: any;
43
+ status: any;
44
+ }>;
45
+ static registerWebhookTopic: (shop: string, accessToken: string, eventBridgeArn: string, topic: string) => Promise<{
46
+ headers: any;
47
+ data: any;
48
+ status: any;
49
+ }>;
50
+ static updateShopifyAppMetafield: (shop: string, accessToken: string, pixelId: string) => Promise<{
51
+ headers: any;
52
+ data: any;
53
+ status: any;
54
+ }>;
55
+ static getShopifyStoreProperties: (shop: string, accessToken: string) => Promise<{
56
+ headers: any;
57
+ data: any;
58
+ status: any;
59
+ }>;
60
+ static createAppSubscription: (shop: string, accessToken: string, planName: string, price: number, returnUrl: string, trialDays: number, test?: boolean) => Promise<{
61
+ headers: any;
62
+ data: any;
63
+ status: any;
64
+ }>;
65
+ static cancelAppSubscription: (shop: string, accessToken: string, chargeId: string) => Promise<{
66
+ headers: any;
67
+ data: any;
68
+ status: any;
69
+ }>;
70
+ static listAppSubscriptions: (shop: string, accessToken: string) => Promise<{
71
+ headers: any;
72
+ data: any;
73
+ status: any;
74
+ }>;
75
+ static genericShopifyPost: (url: string, accessToken: string, payload: any) => Promise<{
76
+ headers: any;
77
+ data: any;
78
+ status: any;
79
+ }>;
80
+ static genericShopifyGet: (url: string, accessToken: string) => Promise<{
81
+ headers: any;
82
+ data: any;
83
+ status: any;
84
+ }>;
85
+ static genericShopifyPut: (url: string, accessToken: string, payload: any) => Promise<{
86
+ headers: any;
87
+ data: any;
88
+ status: any;
89
+ }>;
90
+ }
@@ -1,122 +1,122 @@
1
- import { axiosHttpService } from '../generic/http-client.js';
2
- import { Logger } from '../../index.js';
3
- export class ShopifyClient {
4
- static _shopify_api_version = process.env.SHOPIFY_API_VERSION;
5
- static getConfig = (shopifyDomain, accessToken) => {
6
- const config = {
7
- baseURL: `https://${shopifyDomain}/admin/api/${this._shopify_api_version}`,
8
- headers: {
9
- common: {
10
- 'X-Shopify-Access-Token': accessToken,
11
- },
12
- },
13
- };
14
- return config;
15
- };
16
- static getClient = (shopifyDomain, accessToken) => {
17
- return axiosHttpService(this.getConfig(shopifyDomain, accessToken));
18
- };
19
- static registerApp = async (shop, code, appKey, appSecret) => {
20
- const client = axiosHttpService();
21
- const url = 'https://' + shop + '/admin/oauth/access_token';
22
- const payload = {
23
- client_id: appKey,
24
- client_secret: appSecret,
25
- code
26
- };
27
- const res = await client.post(url, payload);
28
- return res;
29
- };
30
- static registerWebhookTopic = async (shop, accessToken, eventBridgeArn, topic) => {
31
- const client = axiosHttpService();
32
- const url = `https://${shop}/admin/api/${this._shopify_api_version}/webhooks.json`;
33
- const payload = {
34
- webhook: {
35
- topic,
36
- address: eventBridgeArn,
37
- format: 'json'
38
- }
39
- };
40
- const res = await client.post(url, payload, { headers: { 'X-Shopify-Access-Token': accessToken } });
41
- if (res.status >= 400) {
42
- Logger.error('Failed to register Webhook Topic', { res, shop, accessToken, eventBridgeArn, topic, url, payload });
43
- }
44
- Logger.debug('Shopify Client Webhook Registration Response', { registrationResponse: res });
45
- return res;
46
- };
47
- static updateShopifyAppMetafield = async (shop, accessToken, pixelId) => {
48
- const url = `https://${shop}/admin/api/${this._shopify_api_version}/metafields.json`;
49
- const payload = {
50
- metafield: {
51
- namespace: 'adtr',
52
- key: 'adtr.config',
53
- value: pixelId,
54
- type: 'single_line_text_field'
55
- }
56
- };
57
- const res = await this.genericShopifyPost(url, accessToken, payload);
58
- if (res.status >= 400) {
59
- Logger.error('Failed to update Shopify app Metafield ', { shop, accessToken, url, payload });
60
- }
61
- return res;
62
- };
63
- static getShopifyStoreProperties = async (shop, accessToken) => {
64
- const url = `https://${shop}/admin/api/${this._shopify_api_version}/shop.json`;
65
- const res = await this.genericShopifyGet(url, accessToken);
66
- if (res.status >= 400) {
67
- Logger.error('Failed to get Shopify Store Properties', { shop, accessToken, url });
68
- }
69
- return res;
70
- };
71
- static createAppSubscription = async (shop, accessToken, planName, price, returnUrl, trialDays, test) => {
72
- const url = `https://${shop}/admin/api/${this._shopify_api_version}/recurring_application_charges.json`;
73
- const recurring_application_charge = {
74
- name: planName,
75
- price,
76
- return_url: returnUrl,
77
- trial_days: trialDays,
78
- test
79
- };
80
- const res = await this.genericShopifyPost(url, accessToken, { recurring_application_charge });
81
- if (res.status >= 400) {
82
- Logger.error('Failed to create App Subscription', { shop, accessToken, url });
83
- }
84
- return res;
85
- };
86
- static cancelAppSubscription = async (shop, accessToken, chargeId) => {
87
- const url = `https://${shop}/admin/api/${this._shopify_api_version}/recurring_application_charges/${chargeId}.json`;
88
- const client = axiosHttpService();
89
- const res = await client.delete(url, { headers: { 'X-Shopify-Access-Token': accessToken } });
90
- if (res.status !== 200) {
91
- Logger.error('Failed to cancel recurring App billing', { shop, accessToken, url });
92
- }
93
- return res;
94
- };
95
- static listAppSubscriptions = async (shop, accessToken) => {
96
- const url = `https://${shop}/admin/api/${this._shopify_api_version}/recurring_application_charges.json`;
97
- const res = await this.genericShopifyGet(url, accessToken);
98
- if (res.status >= 400) {
99
- Logger.error('Failed to get App Subscriptions', { shop, accessToken, url });
100
- }
101
- return res;
102
- };
103
- static genericShopifyPost = async (url, accessToken, payload) => {
104
- const client = axiosHttpService();
105
- const res = await client.post(url, payload, { headers: { 'X-Shopify-Access-Token': accessToken, 'Content-Type': 'application/json' } });
106
- Logger.debug('Shopify Client Response', { res });
107
- return res;
108
- };
109
- static genericShopifyGet = async (url, accessToken) => {
110
- const client = axiosHttpService();
111
- const res = await client.get(url, { headers: { 'X-Shopify-Access-Token': accessToken } });
112
- Logger.debug('Shopify Client Response', { res });
113
- return res;
114
- };
115
- static genericShopifyPut = async (url, accessToken, payload) => {
116
- const client = axiosHttpService();
117
- const res = await client.put(url, payload, { headers: { 'X-Shopify-Access-Token': accessToken } });
118
- Logger.debug('Shopify Client Response', { res });
119
- return res;
120
- };
121
- }
1
+ import { axiosHttpService } from '../generic/http-client.js';
2
+ import { Logger } from '../../index.js';
3
+ export class ShopifyClient {
4
+ static _shopify_api_version = process.env.SHOPIFY_API_VERSION;
5
+ static getConfig = (shopifyDomain, accessToken) => {
6
+ const config = {
7
+ baseURL: `https://${shopifyDomain}/admin/api/${this._shopify_api_version}`,
8
+ headers: {
9
+ common: {
10
+ 'X-Shopify-Access-Token': accessToken,
11
+ },
12
+ },
13
+ };
14
+ return config;
15
+ };
16
+ static getClient = (shopifyDomain, accessToken) => {
17
+ return axiosHttpService(this.getConfig(shopifyDomain, accessToken));
18
+ };
19
+ static registerApp = async (shop, code, appKey, appSecret) => {
20
+ const client = axiosHttpService();
21
+ const url = 'https://' + shop + '/admin/oauth/access_token';
22
+ const payload = {
23
+ client_id: appKey,
24
+ client_secret: appSecret,
25
+ code
26
+ };
27
+ const res = await client.post(url, payload);
28
+ return res;
29
+ };
30
+ static registerWebhookTopic = async (shop, accessToken, eventBridgeArn, topic) => {
31
+ const client = axiosHttpService();
32
+ const url = `https://${shop}/admin/api/${this._shopify_api_version}/webhooks.json`;
33
+ const payload = {
34
+ webhook: {
35
+ topic,
36
+ address: eventBridgeArn,
37
+ format: 'json'
38
+ }
39
+ };
40
+ const res = await client.post(url, payload, { headers: { 'X-Shopify-Access-Token': accessToken } });
41
+ if (res.status >= 400) {
42
+ Logger.error('Failed to register Webhook Topic', { res, shop, accessToken, eventBridgeArn, topic, url, payload });
43
+ }
44
+ Logger.debug('Shopify Client Webhook Registration Response', { registrationResponse: res });
45
+ return res;
46
+ };
47
+ static updateShopifyAppMetafield = async (shop, accessToken, pixelId) => {
48
+ const url = `https://${shop}/admin/api/${this._shopify_api_version}/metafields.json`;
49
+ const payload = {
50
+ metafield: {
51
+ namespace: 'adtr',
52
+ key: 'adtr.config',
53
+ value: pixelId,
54
+ type: 'single_line_text_field'
55
+ }
56
+ };
57
+ const res = await this.genericShopifyPost(url, accessToken, payload);
58
+ if (res.status >= 400) {
59
+ Logger.error('Failed to update Shopify app Metafield ', { shop, accessToken, url, payload });
60
+ }
61
+ return res;
62
+ };
63
+ static getShopifyStoreProperties = async (shop, accessToken) => {
64
+ const url = `https://${shop}/admin/api/${this._shopify_api_version}/shop.json`;
65
+ const res = await this.genericShopifyGet(url, accessToken);
66
+ if (res.status >= 400) {
67
+ Logger.error('Failed to get Shopify Store Properties', { shop, accessToken, url });
68
+ }
69
+ return res;
70
+ };
71
+ static createAppSubscription = async (shop, accessToken, planName, price, returnUrl, trialDays, test) => {
72
+ const url = `https://${shop}/admin/api/${this._shopify_api_version}/recurring_application_charges.json`;
73
+ const recurring_application_charge = {
74
+ name: planName,
75
+ price,
76
+ return_url: returnUrl,
77
+ trial_days: trialDays,
78
+ test
79
+ };
80
+ const res = await this.genericShopifyPost(url, accessToken, { recurring_application_charge });
81
+ if (res.status >= 400) {
82
+ Logger.error('Failed to create App Subscription', { shop, accessToken, url });
83
+ }
84
+ return res;
85
+ };
86
+ static cancelAppSubscription = async (shop, accessToken, chargeId) => {
87
+ const url = `https://${shop}/admin/api/${this._shopify_api_version}/recurring_application_charges/${chargeId}.json`;
88
+ const client = axiosHttpService();
89
+ const res = await client.delete(url, { headers: { 'X-Shopify-Access-Token': accessToken } });
90
+ if (res.status !== 200) {
91
+ Logger.error('Failed to cancel recurring App billing', { shop, accessToken, url });
92
+ }
93
+ return res;
94
+ };
95
+ static listAppSubscriptions = async (shop, accessToken) => {
96
+ const url = `https://${shop}/admin/api/${this._shopify_api_version}/recurring_application_charges.json`;
97
+ const res = await this.genericShopifyGet(url, accessToken);
98
+ if (res.status >= 400) {
99
+ Logger.error('Failed to get App Subscriptions', { shop, accessToken, url });
100
+ }
101
+ return res;
102
+ };
103
+ static genericShopifyPost = async (url, accessToken, payload) => {
104
+ const client = axiosHttpService();
105
+ const res = await client.post(url, payload, { headers: { 'X-Shopify-Access-Token': accessToken, 'Content-Type': 'application/json' } });
106
+ Logger.debug('Shopify Client Response', { res });
107
+ return res;
108
+ };
109
+ static genericShopifyGet = async (url, accessToken) => {
110
+ const client = axiosHttpService();
111
+ const res = await client.get(url, { headers: { 'X-Shopify-Access-Token': accessToken } });
112
+ Logger.debug('Shopify Client Response', { res });
113
+ return res;
114
+ };
115
+ static genericShopifyPut = async (url, accessToken, payload) => {
116
+ const client = axiosHttpService();
117
+ const res = await client.put(url, payload, { headers: { 'X-Shopify-Access-Token': accessToken } });
118
+ Logger.debug('Shopify Client Response', { res });
119
+ return res;
120
+ };
121
+ }
122
122
  //# sourceMappingURL=shopify-client.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 './subscription-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 './subscription-helper.js';
@@ -1,6 +1,6 @@
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 './subscription-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 './subscription-helper.js';
6
6
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- import Joi from 'joi';
2
- export declare const validateInput: (schema: Joi.ObjectSchema<any>, input: any) => any;
1
+ import Joi from 'joi';
2
+ export declare const validateInput: (schema: Joi.ObjectSchema<any>, input: any) => any;
@@ -1,19 +1,19 @@
1
- import { Logger } from './logging-helper.js';
2
- import { HttpError } from '../libs/http-error.js';
3
- export const validateInput = (schema, input) => {
4
- const { error, value } = schema.validate(input);
5
- if (error) {
6
- Logger.info('', { error });
7
- const httperr = HttpError.badRequest('Bad Request', {
8
- errors: error.details.map(detail => ({
9
- message: detail?.message,
10
- key: detail?.context?.key,
11
- path: detail?.path,
12
- }))
13
- });
14
- Logger.error('validation failure', { httperr });
15
- throw httperr;
16
- }
17
- return value;
18
- };
1
+ import { Logger } from './logging-helper.js';
2
+ import { HttpError } from '../libs/http-error.js';
3
+ export const validateInput = (schema, input) => {
4
+ const { error, value } = schema.validate(input);
5
+ if (error) {
6
+ Logger.info('', { error });
7
+ const httperr = HttpError.badRequest('Bad Request', {
8
+ errors: error.details.map(detail => ({
9
+ message: detail?.message,
10
+ key: detail?.context?.key,
11
+ path: detail?.path,
12
+ }))
13
+ });
14
+ Logger.error('validation failure', { httperr });
15
+ throw httperr;
16
+ }
17
+ return value;
18
+ };
19
19
  //# sourceMappingURL=input-validation-helper.js.map
@@ -1,15 +1,15 @@
1
- export declare const LogLevelId: {
2
- trace: number;
3
- debug: number;
4
- info: number;
5
- warn: number;
6
- error: number;
7
- };
8
- export declare const configureLogger: (event: any, context: any, debug?: boolean) => void;
9
- export declare const Logger: {
10
- log: (logLevel: string, msg: string | Error, meta?: object | undefined, tags?: string[] | undefined) => void;
11
- debug: (msg: string, meta?: object | undefined, tags?: string[] | undefined) => void;
12
- info: (msg: string, meta?: object | undefined, tags?: string[] | undefined) => void;
13
- warn: (msg: string, meta?: object | undefined, tags?: string[] | undefined) => void;
14
- error: (msg: string | Error, meta?: object | undefined, tags?: string[] | undefined) => void;
15
- };
1
+ export declare const LogLevelId: {
2
+ trace: number;
3
+ debug: number;
4
+ info: number;
5
+ warn: number;
6
+ error: number;
7
+ };
8
+ export declare const configureLogger: (event: any, context: any, debug?: boolean) => void;
9
+ export declare const Logger: {
10
+ log: (logLevel: string, msg: string | Error, meta?: object | undefined, tags?: string[] | undefined) => void;
11
+ debug: (msg: string, meta?: object | undefined, tags?: string[] | undefined) => void;
12
+ info: (msg: string, meta?: object | undefined, tags?: string[] | undefined) => void;
13
+ warn: (msg: string, meta?: object | undefined, tags?: string[] | undefined) => void;
14
+ error: (msg: string | Error, meta?: object | undefined, tags?: string[] | undefined) => void;
15
+ };
@@ -1,54 +1,54 @@
1
- import * as _logger from 'lambda-log';
2
- const stage = process?.env?.STAGE;
3
- const LEVEL = process?.env?.LOG_LEVEL ?? 'info';
4
- export const LogLevelId = {
5
- trace: 0,
6
- debug: 1,
7
- info: 2,
8
- warn: 3,
9
- error: 4,
10
- };
11
- export const configureLogger = (event, context, debug = LEVEL === 'debug') => {
12
- _logger.options.meta.stage = stage;
13
- _logger.options.meta.source_name = context?.functionName || 'unknown';
14
- _logger.options.meta.awsRequestId = context?.awsRequestId || 'unknown';
15
- _logger.options.meta.lambdaEvent = event;
16
- _logger.options.debug = debug;
17
- };
18
- export const Logger = {
19
- log: (logLevel, msg, meta = {}, tags) => {
20
- if (logLevel === 'debug') {
21
- Logger.debug(msg, meta, tags);
22
- }
23
- else if (logLevel === 'info') {
24
- Logger.info(msg, meta, tags);
25
- }
26
- else if (logLevel === 'warn') {
27
- Logger.warn(msg, meta, tags);
28
- }
29
- else if (logLevel === 'error') {
30
- Logger.error(msg, meta, tags);
31
- }
32
- },
33
- debug: (msg, meta, tags) => {
34
- if (LogLevelId['debug'] >= LogLevelId[LEVEL]) {
35
- _logger.debug(msg, meta, tags);
36
- }
37
- },
38
- info: (msg, meta, tags) => {
39
- if (LogLevelId['info'] >= LogLevelId[LEVEL]) {
40
- _logger.info(msg, meta, tags);
41
- }
42
- },
43
- warn: (msg, meta, tags) => {
44
- if (LogLevelId['warn'] >= LogLevelId[LEVEL]) {
45
- _logger.warn(msg, meta, tags);
46
- }
47
- },
48
- error: (msg, meta, tags) => {
49
- if (LogLevelId['error'] >= LogLevelId[LEVEL]) {
50
- _logger.error(msg, meta, tags);
51
- }
52
- }
53
- };
1
+ import * as _logger from 'lambda-log';
2
+ const stage = process?.env?.STAGE;
3
+ const LEVEL = process?.env?.LOG_LEVEL ?? 'info';
4
+ export const LogLevelId = {
5
+ trace: 0,
6
+ debug: 1,
7
+ info: 2,
8
+ warn: 3,
9
+ error: 4,
10
+ };
11
+ export const configureLogger = (event, context, debug = LEVEL === 'debug') => {
12
+ _logger.options.meta.stage = stage;
13
+ _logger.options.meta.source_name = context?.functionName || 'unknown';
14
+ _logger.options.meta.awsRequestId = context?.awsRequestId || 'unknown';
15
+ _logger.options.meta.lambdaEvent = event;
16
+ _logger.options.debug = debug;
17
+ };
18
+ export const Logger = {
19
+ log: (logLevel, msg, meta = {}, tags) => {
20
+ if (logLevel === 'debug') {
21
+ Logger.debug(msg, meta, tags);
22
+ }
23
+ else if (logLevel === 'info') {
24
+ Logger.info(msg, meta, tags);
25
+ }
26
+ else if (logLevel === 'warn') {
27
+ Logger.warn(msg, meta, tags);
28
+ }
29
+ else if (logLevel === 'error') {
30
+ Logger.error(msg, meta, tags);
31
+ }
32
+ },
33
+ debug: (msg, meta, tags) => {
34
+ if (LogLevelId['debug'] >= LogLevelId[LEVEL]) {
35
+ _logger.debug(msg, meta, tags);
36
+ }
37
+ },
38
+ info: (msg, meta, tags) => {
39
+ if (LogLevelId['info'] >= LogLevelId[LEVEL]) {
40
+ _logger.info(msg, meta, tags);
41
+ }
42
+ },
43
+ warn: (msg, meta, tags) => {
44
+ if (LogLevelId['warn'] >= LogLevelId[LEVEL]) {
45
+ _logger.warn(msg, meta, tags);
46
+ }
47
+ },
48
+ error: (msg, meta, tags) => {
49
+ if (LogLevelId['error'] >= LogLevelId[LEVEL]) {
50
+ _logger.error(msg, meta, tags);
51
+ }
52
+ }
53
+ };
54
54
  //# sourceMappingURL=logging-helper.js.map