@adtrackify/at-service-common 1.0.45 → 1.0.47

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.45",
3
+ "version": "1.0.47",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -35,7 +35,6 @@
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",
39
38
  "ua-parser-js": "^1.0.2"
40
39
  },
41
40
  "devDependencies": {
@@ -1,6 +1,5 @@
1
1
  import { axiosHttpService } from '../generic/http-client';
2
2
  import * as log from 'lambda-log';
3
- import Shopify, { IPublicShopifyConfig } from 'shopify-api-node';
4
3
 
5
4
  export class ShopifyClient {
6
5
  static _shopify_api_version = process.env.SHOPIFY_API_VERSION as string;
@@ -80,23 +79,29 @@ export class ShopifyClient {
80
79
  return res;
81
80
  };
82
81
 
83
- static appSubscriptionCreate = async (shop: string, accessToken: string,
82
+ static createAppSubscription = async (shop: string, accessToken: string,
84
83
  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 = {
84
+ const url = `https://${shop}/admin/api/${this._shopify_api_version}/recurring_application_charges.json`;
85
+ const recurring_application_charge = {
92
86
  name: planName,
93
87
  price,
94
88
  return_url: returnUrl,
95
89
  trial_days: trialDays
96
90
  };
97
- const response = await client.recurringApplicationCharge.create(createSubscriptionParams);
91
+ const res = await this.genericShopifyPost(url, accessToken, { recurring_application_charge });
92
+ if (res.status >= 400) {
93
+ log.error('Failed to create App Subscription', { shop, accessToken, url });
94
+ }
95
+ return res;
96
+ };
98
97
 
99
- return response;
98
+ static listAppSubscriptions = async (shop: string, accessToken: string) => {
99
+ const url = `https://${shop}/admin/api/${this._shopify_api_version}/recurring_application_charges.json`;
100
+ const res = await this.genericShopifyGet(url, accessToken);
101
+ if (res.status >= 400) {
102
+ log.error('Failed to get App Subscriptions', { shop, accessToken, url });
103
+ }
104
+ return res;
100
105
  };
101
106
 
102
107
  static genericShopifyPost = async (url: string, accessToken: string, payload: any) => {