@adtrackify/at-service-common 1.0.25 → 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/dist/index.d.ts +97 -13
- package/dist/index.js +98 -17
- package/dist/index.js.map +4 -4
- package/package.json +2 -2
- package/src/clients/internal-api/accounts-client.ts +19 -5
- package/src/clients/internal-api/destinations-client.ts +10 -10
- package/src/clients/third-party/shopify-client.ts +95 -0
- package/src/index.ts +1 -1
- package/prettier.config.js +0 -9
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;
|
|
@@ -7,6 +8,17 @@ import { axiosHttpService } from '../generic/http-client';
|
|
|
7
8
|
//const SERVICE_API_ROOT_URL = `${BASE_API_URL}/accounts`;
|
|
8
9
|
//const ACCOUNTS_API_KEY = process.env.ACCOUNTS_API_KEY;
|
|
9
10
|
|
|
11
|
+
|
|
12
|
+
export interface IsAuthorizedUserResponseData {
|
|
13
|
+
isAccountUser: boolean;
|
|
14
|
+
[ key: string ]: any;
|
|
15
|
+
}
|
|
16
|
+
export interface PixelConfigResponseData {
|
|
17
|
+
id: string;
|
|
18
|
+
destinations: Destination[];
|
|
19
|
+
[ key: string ]: any;
|
|
20
|
+
}
|
|
21
|
+
|
|
10
22
|
export class AccountsClient {
|
|
11
23
|
public BASE_API_URL: string;
|
|
12
24
|
public ACCOUNTS_API_KEY: string;
|
|
@@ -41,9 +53,11 @@ export class AccountsClient {
|
|
|
41
53
|
log.info('checkUserAuthorization', { response });
|
|
42
54
|
return response as ApiResponse<IsAuthorizedUserResponseData>;
|
|
43
55
|
};
|
|
44
|
-
}
|
|
45
56
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
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
|
+
};
|
|
63
|
+
}
|
|
@@ -5,6 +5,16 @@ import { Destination } from '../../types/db/destination';
|
|
|
5
5
|
//const BASE_API_URL = process.env.BASE_API_URL;
|
|
6
6
|
//const DESTINATIONS_API_KEY = process.env.DESTINATIONS_API_KEY;
|
|
7
7
|
|
|
8
|
+
export interface GetDestinationsResponseData {
|
|
9
|
+
destinations: Destination[];
|
|
10
|
+
[ key: string ]: any;
|
|
11
|
+
}
|
|
12
|
+
export interface CreateDestinationResponseData {
|
|
13
|
+
destination: Destination;
|
|
14
|
+
[ key: string ]: any;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
8
18
|
export class DestinationsClient {
|
|
9
19
|
|
|
10
20
|
public BASE_API_URL: string;
|
|
@@ -45,13 +55,3 @@ export class DestinationsClient {
|
|
|
45
55
|
return response as ApiResponse<GetDestinationsResponseData>;
|
|
46
56
|
};
|
|
47
57
|
}
|
|
48
|
-
|
|
49
|
-
export interface GetDestinationsResponseData {
|
|
50
|
-
destinations: Destination[];
|
|
51
|
-
[ key: string ]: any;
|
|
52
|
-
}
|
|
53
|
-
export interface CreateDestinationResponseData {
|
|
54
|
-
destination: Destination;
|
|
55
|
-
[ key: string ]: any;
|
|
56
|
-
}
|
|
57
|
-
|
|
@@ -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
|
+
}
|
package/src/index.ts
CHANGED