@adtrackify/at-service-common 1.0.43 → 1.0.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +12 -12
- package/dist/index.d.ts +5 -0
- package/dist/index.js +12550 -4817
- package/dist/index.js.map +4 -4
- package/package.json +19 -18
- package/src/clients/generic/axios.d.ts +7 -7
- package/src/clients/internal-api/index.ts +2 -1
- package/src/clients/internal-api/shopify-app-install-client.ts +7 -0
- package/src/clients/third-party/shopify-client.ts +33 -6
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.45",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -25,45 +25,46 @@
|
|
|
25
25
|
"type-check": "tsc --noEmit"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
+
"@types/axios": "^0.14.0",
|
|
29
|
+
"@types/lambda-log": "^2.2.1",
|
|
30
|
+
"@types/luxon": "^3.0.1",
|
|
31
|
+
"@types/ua-parser-js": "^0.7.36",
|
|
28
32
|
"axios": "^0.27.2",
|
|
29
33
|
"axios-retry": "^3.3.1",
|
|
30
34
|
"crypto": "^1.0.1",
|
|
31
35
|
"joi": "^17.6.0",
|
|
32
36
|
"lambda-log": "^3.1.0",
|
|
33
|
-
"luxon": "^3.0.
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"@types/lambda-log": "^2.2.1",
|
|
37
|
-
"@types/luxon": "^3.0.0",
|
|
38
|
-
"@types/axios": "^0.14.0"
|
|
37
|
+
"luxon": "^3.0.3",
|
|
38
|
+
"shopify-api-node": "^3.11.1",
|
|
39
|
+
"ua-parser-js": "^1.0.2"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
|
-
"@adtrackify/at-tracking-event-types": "^1.0.
|
|
42
|
+
"@adtrackify/at-tracking-event-types": "^1.0.25",
|
|
42
43
|
"@babel/cli": "^7.13.16",
|
|
43
|
-
"@babel/core": "^7.
|
|
44
|
+
"@babel/core": "^7.19.0",
|
|
44
45
|
"@babel/plugin-proposal-optional-chaining": "^7.13.8",
|
|
45
46
|
"@babel/plugin-transform-runtime": "^7.10.3",
|
|
46
|
-
"@babel/preset-env": "^7.
|
|
47
|
+
"@babel/preset-env": "^7.19.0",
|
|
47
48
|
"@babel/preset-typescript": "^7.16.7",
|
|
48
|
-
"@babel/runtime-corejs3": "^7.
|
|
49
|
+
"@babel/runtime-corejs3": "^7.19.0",
|
|
49
50
|
"@types/jest": "^27.4.1",
|
|
50
51
|
"@types/node": "^17.0.8",
|
|
51
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
52
|
-
"@typescript-eslint/parser": "^5.
|
|
53
|
-
"aws-sdk": "^2.
|
|
52
|
+
"@typescript-eslint/eslint-plugin": "^5.36.2",
|
|
53
|
+
"@typescript-eslint/parser": "^5.36.2",
|
|
54
|
+
"aws-sdk": "^2.1213.0",
|
|
54
55
|
"babel-eslint": "^10.1.0",
|
|
55
56
|
"babel-jest": "^26.6.3",
|
|
56
57
|
"babel-polyfill": "^6.26.0",
|
|
57
|
-
"core-js": "^3.
|
|
58
|
+
"core-js": "^3.25.1",
|
|
58
59
|
"cross-env": "^7.0.3",
|
|
59
60
|
"esbuild": "^0.14.54",
|
|
60
|
-
"eslint": "^8.
|
|
61
|
+
"eslint": "^8.23.0",
|
|
61
62
|
"eslint-config-standard": "^17.0.0",
|
|
62
63
|
"eslint-loader": "^4.0.2",
|
|
63
64
|
"eslint-plugin-babel": "^5.3.1",
|
|
64
65
|
"eslint-plugin-import": "^2.26.0",
|
|
65
|
-
"eslint-plugin-n": "^15.2.
|
|
66
|
-
"eslint-plugin-promise": "^6.0.
|
|
66
|
+
"eslint-plugin-n": "^15.2.5",
|
|
67
|
+
"eslint-plugin-promise": "^6.0.1",
|
|
67
68
|
"eslint-webpack-plugin": "^3.1.1",
|
|
68
69
|
"glob": "^8.0.3",
|
|
69
70
|
"husky": "^6.0.0",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
declare module 'axios/lib/adapters/http' {
|
|
2
|
-
import { AxiosAdapter } from 'axios';
|
|
3
|
-
|
|
4
|
-
const httpAdapter: AxiosAdapter;
|
|
5
|
-
namespace httpAdapter { }
|
|
6
|
-
|
|
7
|
-
export = httpAdapter;
|
|
1
|
+
declare module 'axios/lib/adapters/http' {
|
|
2
|
+
import { AxiosAdapter } from 'axios';
|
|
3
|
+
|
|
4
|
+
const httpAdapter: AxiosAdapter;
|
|
5
|
+
namespace httpAdapter { }
|
|
6
|
+
|
|
7
|
+
export = httpAdapter;
|
|
8
8
|
}
|
|
@@ -48,4 +48,11 @@ export class ShopifyAppInstallClient {
|
|
|
48
48
|
log.info('updateShopifyAppInstall', { response });
|
|
49
49
|
return response as ApiResponse<ShopifyAppInstallResponseData>;
|
|
50
50
|
};
|
|
51
|
+
|
|
52
|
+
getShopifyAppInstall = async (shopifyAppInstallId: string): Promise<ApiResponse<ShopifyAppInstallResponseData>> => {
|
|
53
|
+
const client = await this.getClient();
|
|
54
|
+
const response = await client.get(`/${shopifyAppInstallId}`);
|
|
55
|
+
log.info('getShopifyAppInstall', { response });
|
|
56
|
+
return response as ApiResponse<ShopifyAppInstallResponseData>;
|
|
57
|
+
};
|
|
51
58
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { axiosHttpService } from '../generic/http-client';
|
|
2
2
|
import * as log from 'lambda-log';
|
|
3
|
-
|
|
4
|
-
const _shopify_api_version = process.env.SHOPIFY_API_VERSION as string;
|
|
3
|
+
import Shopify, { IPublicShopifyConfig } from 'shopify-api-node';
|
|
5
4
|
|
|
6
5
|
export class ShopifyClient {
|
|
6
|
+
static _shopify_api_version = process.env.SHOPIFY_API_VERSION as string;
|
|
7
7
|
static getConfig = (shopifyDomain: string, accessToken: string) => {
|
|
8
8
|
const config = {
|
|
9
|
-
baseURL: `https://${shopifyDomain}/admin/api/${_shopify_api_version}`,
|
|
9
|
+
baseURL: `https://${shopifyDomain}/admin/api/${this._shopify_api_version}`,
|
|
10
10
|
headers: {
|
|
11
11
|
common: {
|
|
12
12
|
'X-Shopify-Access-Token': accessToken,
|
|
@@ -15,11 +15,13 @@ export class ShopifyClient {
|
|
|
15
15
|
};
|
|
16
16
|
return config;
|
|
17
17
|
};
|
|
18
|
+
|
|
18
19
|
static getClient = (shopifyDomain: string, accessToken: string) => {
|
|
19
20
|
return axiosHttpService(
|
|
20
21
|
this.getConfig(shopifyDomain, accessToken)
|
|
21
22
|
);
|
|
22
23
|
};
|
|
24
|
+
|
|
23
25
|
static registerApp = async (shop: string, code: string, appKey: string, appSecret: string) => {
|
|
24
26
|
const client = axiosHttpService();
|
|
25
27
|
const url = 'https://' + shop + '/admin/oauth/access_token';
|
|
@@ -31,9 +33,10 @@ export class ShopifyClient {
|
|
|
31
33
|
const res = await client.post(url, payload);
|
|
32
34
|
return res;
|
|
33
35
|
};
|
|
36
|
+
|
|
34
37
|
static registerWebhookTopic = async (shop: string, accessToken: string, eventBridgeArn: string, topic: string) => {
|
|
35
38
|
const client = axiosHttpService();
|
|
36
|
-
const url = `https://${shop}/admin/api/${_shopify_api_version}/webhooks.json`;
|
|
39
|
+
const url = `https://${shop}/admin/api/${this._shopify_api_version}/webhooks.json`;
|
|
37
40
|
const payload = {
|
|
38
41
|
webhook: {
|
|
39
42
|
topic,
|
|
@@ -48,8 +51,9 @@ export class ShopifyClient {
|
|
|
48
51
|
log.debug('Shopify Client Webhook Registration Response', { registrationResponse: res });
|
|
49
52
|
return res;
|
|
50
53
|
};
|
|
54
|
+
|
|
51
55
|
static updateShopifyAppMetafield = async (shop: string, accessToken: string, pixelId: string) => {
|
|
52
|
-
const url = `https://${shop}/admin/api/${_shopify_api_version}/metafields.json`;
|
|
56
|
+
const url = `https://${shop}/admin/api/${this._shopify_api_version}/metafields.json`;
|
|
53
57
|
const payload = {
|
|
54
58
|
metafield: {
|
|
55
59
|
namespace: 'adtr',
|
|
@@ -65,8 +69,9 @@ export class ShopifyClient {
|
|
|
65
69
|
}
|
|
66
70
|
return res;
|
|
67
71
|
};
|
|
72
|
+
|
|
68
73
|
static getShopifyStoreProperties = async (shop: string, accessToken: string) => {
|
|
69
|
-
const url = `https://${shop}/admin/api/${_shopify_api_version}/shop.json`;
|
|
74
|
+
const url = `https://${shop}/admin/api/${this._shopify_api_version}/shop.json`;
|
|
70
75
|
const res = await this.genericShopifyGet(url, accessToken);
|
|
71
76
|
|
|
72
77
|
if (res.status >= 400) {
|
|
@@ -74,18 +79,40 @@ export class ShopifyClient {
|
|
|
74
79
|
}
|
|
75
80
|
return res;
|
|
76
81
|
};
|
|
82
|
+
|
|
83
|
+
static appSubscriptionCreate = async (shop: string, accessToken: string,
|
|
84
|
+
planName: string, price: number, returnUrl: string, trialDays: number) => {
|
|
85
|
+
|
|
86
|
+
const config: IPublicShopifyConfig = {
|
|
87
|
+
accessToken,
|
|
88
|
+
shopName: shop
|
|
89
|
+
};
|
|
90
|
+
const client = new Shopify(config);
|
|
91
|
+
const createSubscriptionParams: Shopify.ICreateRecurringApplicationCharge = {
|
|
92
|
+
name: planName,
|
|
93
|
+
price,
|
|
94
|
+
return_url: returnUrl,
|
|
95
|
+
trial_days: trialDays
|
|
96
|
+
};
|
|
97
|
+
const response = await client.recurringApplicationCharge.create(createSubscriptionParams);
|
|
98
|
+
|
|
99
|
+
return response;
|
|
100
|
+
};
|
|
101
|
+
|
|
77
102
|
static genericShopifyPost = async (url: string, accessToken: string, payload: any) => {
|
|
78
103
|
const client = axiosHttpService();
|
|
79
104
|
const res = await client.post(url, payload, { headers: { 'X-Shopify-Access-Token': accessToken } });
|
|
80
105
|
log.debug('Shopify Client Response', { res });
|
|
81
106
|
return res;
|
|
82
107
|
};
|
|
108
|
+
|
|
83
109
|
static genericShopifyGet = async (url: string, accessToken: string) => {
|
|
84
110
|
const client = axiosHttpService();
|
|
85
111
|
const res = await client.get(url, { headers: { 'X-Shopify-Access-Token': accessToken } });
|
|
86
112
|
log.debug('Shopify Client Response', { res });
|
|
87
113
|
return res;
|
|
88
114
|
};
|
|
115
|
+
|
|
89
116
|
static genericShopifyPut = async (url: string, accessToken: string, payload: any) => {
|
|
90
117
|
const client = axiosHttpService();
|
|
91
118
|
const res = await client.put(url, payload, { headers: { 'X-Shopify-Access-Token': accessToken } });
|