@adtrackify/at-service-common 1.0.44 → 1.0.46

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.44",
3
+ "version": "1.0.46",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -35,6 +35,7 @@
35
35
  "joi": "^17.6.0",
36
36
  "lambda-log": "^3.1.0",
37
37
  "luxon": "^3.0.3",
38
+ "shopify-api-node": "^3.11.1",
38
39
  "ua-parser-js": "^1.0.2"
39
40
  },
40
41
  "devDependencies": {
@@ -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,54 @@ 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
+ client.recurringApplicationCharge.list();
98
+ const response = await client.recurringApplicationCharge.create(createSubscriptionParams);
99
+
100
+ return response;
101
+ };
102
+
103
+ static appSubscriptionsList = async (shop: string, accessToken: string) => {
104
+
105
+ const config: IPublicShopifyConfig = {
106
+ accessToken,
107
+ shopName: shop
108
+ };
109
+ const client = new Shopify(config);
110
+ client.recurringApplicationCharge.list();
111
+ const response = await client.recurringApplicationCharge.list();
112
+
113
+ return response;
114
+ };
115
+
77
116
  static genericShopifyPost = async (url: string, accessToken: string, payload: any) => {
78
117
  const client = axiosHttpService();
79
118
  const res = await client.post(url, payload, { headers: { 'X-Shopify-Access-Token': accessToken } });
80
119
  log.debug('Shopify Client Response', { res });
81
120
  return res;
82
121
  };
122
+
83
123
  static genericShopifyGet = async (url: string, accessToken: string) => {
84
124
  const client = axiosHttpService();
85
125
  const res = await client.get(url, { headers: { 'X-Shopify-Access-Token': accessToken } });
86
126
  log.debug('Shopify Client Response', { res });
87
127
  return res;
88
128
  };
129
+
89
130
  static genericShopifyPut = async (url: string, accessToken: string, payload: any) => {
90
131
  const client = axiosHttpService();
91
132
  const res = await client.put(url, payload, { headers: { 'X-Shopify-Access-Token': accessToken } });