@adtrackify/at-service-common 1.0.26 → 1.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adtrackify/at-service-common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.27",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -88,4 +88,4 @@
|
|
|
88
88
|
"author": "",
|
|
89
89
|
"license": "ISC",
|
|
90
90
|
"homepage": "https://bitbucket.org/eacap/at-tracking-event-types#readme"
|
|
91
|
-
}
|
|
91
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as log from 'lambda-log';
|
|
2
2
|
import { ApiResponse } from '../../types/api-response';
|
|
3
|
+
import { Destination } from '../../types/db/destination';
|
|
3
4
|
import { axiosHttpService } from '../generic/http-client';
|
|
4
5
|
|
|
5
6
|
//const BASE_API_URL = process.env.BASE_API_URL;
|
|
@@ -12,6 +13,11 @@ export interface IsAuthorizedUserResponseData {
|
|
|
12
13
|
isAccountUser: boolean;
|
|
13
14
|
[ key: string ]: any;
|
|
14
15
|
}
|
|
16
|
+
export interface PixelConfigResponseData {
|
|
17
|
+
id: string;
|
|
18
|
+
destinations: Destination[];
|
|
19
|
+
[ key: string ]: any;
|
|
20
|
+
}
|
|
15
21
|
|
|
16
22
|
export class AccountsClient {
|
|
17
23
|
public BASE_API_URL: string;
|
|
@@ -47,4 +53,11 @@ export class AccountsClient {
|
|
|
47
53
|
log.info('checkUserAuthorization', { response });
|
|
48
54
|
return response as ApiResponse<IsAuthorizedUserResponseData>;
|
|
49
55
|
};
|
|
56
|
+
|
|
57
|
+
getPixelConfigById = async (pixelId: string): Promise<ApiResponse<PixelConfigResponseData>> => {
|
|
58
|
+
const client = await this.getClient();
|
|
59
|
+
const pixelResponse = await client.get(`/px/${pixelId}/config`);
|
|
60
|
+
log.debug('pixelResponse', { pixelResponse });
|
|
61
|
+
return pixelResponse;
|
|
62
|
+
};
|
|
50
63
|
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { axiosHttpService } from '../generic/http-client';
|
|
2
|
+
import * as log from 'lambda-log';
|
|
3
|
+
|
|
4
|
+
const _shopify_api_version = process.env.SHOPIFY_API_VERSION as string;
|
|
5
|
+
|
|
6
|
+
export class ShopifyClient {
|
|
7
|
+
getConfig = (shopifyDomain: string, accessToken: string) => {
|
|
8
|
+
const config = {
|
|
9
|
+
baseURL: `https://${shopifyDomain}/admin/api/${_shopify_api_version}`,
|
|
10
|
+
headers: {
|
|
11
|
+
common: {
|
|
12
|
+
'X-Shopify-Access-Token': accessToken,
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
return config;
|
|
17
|
+
};
|
|
18
|
+
getClient = (shopifyDomain: string, accessToken: string) => {
|
|
19
|
+
return axiosHttpService(
|
|
20
|
+
this.getConfig(shopifyDomain, accessToken)
|
|
21
|
+
);
|
|
22
|
+
};
|
|
23
|
+
registerApp = async (shop: string, code: string, appKey: string, appSecret: string) => {
|
|
24
|
+
const client = axiosHttpService();
|
|
25
|
+
const url = 'https://' + shop + '/admin/oauth/access_token';
|
|
26
|
+
const payload = {
|
|
27
|
+
client_id: appKey,
|
|
28
|
+
client_secret: appSecret,
|
|
29
|
+
code
|
|
30
|
+
};
|
|
31
|
+
const res = await client.post(url, payload);
|
|
32
|
+
return res;
|
|
33
|
+
};
|
|
34
|
+
registerWebhookTopic = async (shop: string, accessToken: string, eventBridgeArn: string, topic: string) => {
|
|
35
|
+
const client = axiosHttpService();
|
|
36
|
+
const url = `https://${shop}/admin/api/${_shopify_api_version}/webhooks.json`;
|
|
37
|
+
const payload = {
|
|
38
|
+
webhook: {
|
|
39
|
+
topic,
|
|
40
|
+
address: eventBridgeArn,
|
|
41
|
+
format: 'json'
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const res = await client.post(url, payload, { headers: { 'X-Shopify-Access-Token': accessToken } });
|
|
45
|
+
if (res.status >= 400) {
|
|
46
|
+
log.error('Failed to register Webhook Topic', { shop, accessToken, eventBridgeArn, topic, url, payload });
|
|
47
|
+
}
|
|
48
|
+
log.debug('Shopify Client Webhook Registration Response', { registrationResponse: res });
|
|
49
|
+
return res;
|
|
50
|
+
};
|
|
51
|
+
updateShopifyAppMetafield = async (shop: string, accessToken: string, pixelId: string) => {
|
|
52
|
+
const url = `https://${shop}/admin/api/${_shopify_api_version}/metafields.json`;
|
|
53
|
+
const payload = {
|
|
54
|
+
metafield: {
|
|
55
|
+
namespace: 'adtr',
|
|
56
|
+
key: 'adtr.config',
|
|
57
|
+
value: pixelId,
|
|
58
|
+
type: 'single_line_text_field'
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const res = await this.genericShopifyPost(url, accessToken, payload);
|
|
62
|
+
|
|
63
|
+
if (res.status >= 400) {
|
|
64
|
+
log.error('Failed to register Webhook Topic', { shop, accessToken, url, payload });
|
|
65
|
+
}
|
|
66
|
+
return res;
|
|
67
|
+
};
|
|
68
|
+
getShopifyStoreProperties = async (shop: string, accessToken: string) => {
|
|
69
|
+
const url = `https://${shop}/admin/api/${_shopify_api_version}/shop.json`;
|
|
70
|
+
const res = await this.genericShopifyGet(url, accessToken);
|
|
71
|
+
|
|
72
|
+
if (res.status >= 400) {
|
|
73
|
+
log.error('Failed to get Shopify Store Properties', { shop, accessToken, url });
|
|
74
|
+
}
|
|
75
|
+
return res;
|
|
76
|
+
};
|
|
77
|
+
genericShopifyPost = async (url: string, accessToken: string, payload: any) => {
|
|
78
|
+
const client = axiosHttpService();
|
|
79
|
+
const res = await client.post(url, payload, { headers: { 'X-Shopify-Access-Token': accessToken } });
|
|
80
|
+
log.debug('Shopify Client Response', { res });
|
|
81
|
+
return res;
|
|
82
|
+
};
|
|
83
|
+
genericShopifyGet = async (url: string, accessToken: string) => {
|
|
84
|
+
const client = axiosHttpService();
|
|
85
|
+
const res = await client.get(url, { headers: { 'X-Shopify-Access-Token': accessToken } });
|
|
86
|
+
log.debug('Shopify Client Response', { res });
|
|
87
|
+
return res;
|
|
88
|
+
};
|
|
89
|
+
genericShopifyPut = async (url: string, accessToken: string, payload: any) => {
|
|
90
|
+
const client = axiosHttpService();
|
|
91
|
+
const res = await client.put(url, payload, { headers: { 'X-Shopify-Access-Token': accessToken } });
|
|
92
|
+
log.debug('Shopify Client Response', { res });
|
|
93
|
+
return res;
|
|
94
|
+
};
|
|
95
|
+
}
|