@agnostack/next-shopify 1.3.2-alpha.3 → 1.3.2-alpha.31

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.
Files changed (56) hide show
  1. package/CHANGELOG.md +198 -0
  2. package/dist/{apiHandlers.d.ts → handlers/api.d.ts} +0 -0
  3. package/dist/{apiHandlers.js → handlers/api.js} +8 -8
  4. package/dist/handlers/api.js.map +1 -0
  5. package/dist/handlers/index.d.ts +2 -0
  6. package/dist/handlers/index.js +15 -0
  7. package/dist/handlers/index.js.map +1 -0
  8. package/dist/{protectRoute.d.ts → handlers/ssr.d.ts} +4 -0
  9. package/dist/{protectRoute.js → handlers/ssr.js} +21 -10
  10. package/dist/handlers/ssr.js.map +1 -0
  11. package/dist/helpers/auth.d.ts +13 -0
  12. package/dist/helpers/auth.js +26 -0
  13. package/dist/helpers/auth.js.map +1 -0
  14. package/dist/helpers/callback.d.ts +8 -0
  15. package/dist/helpers/callback.js +86 -0
  16. package/dist/helpers/callback.js.map +1 -0
  17. package/dist/helpers/error.d.ts +12 -0
  18. package/dist/helpers/error.js +19 -0
  19. package/dist/helpers/error.js.map +1 -0
  20. package/dist/helpers/graph.d.ts +21 -0
  21. package/dist/helpers/graph.js +77 -0
  22. package/dist/helpers/graph.js.map +1 -0
  23. package/dist/helpers/index.d.ts +6 -0
  24. package/dist/helpers/index.js +19 -0
  25. package/dist/helpers/index.js.map +1 -0
  26. package/dist/helpers/rest.d.ts +21 -0
  27. package/dist/helpers/rest.js +71 -0
  28. package/dist/helpers/rest.js.map +1 -0
  29. package/dist/helpers/uninstall.d.ts +7 -0
  30. package/dist/helpers/uninstall.js +29 -0
  31. package/dist/helpers/uninstall.js.map +1 -0
  32. package/dist/index.d.ts +2 -3
  33. package/dist/index.js +2 -3
  34. package/dist/index.js.map +1 -1
  35. package/dist/utils/billing.d.ts +0 -5
  36. package/dist/utils/billing.js +19 -131
  37. package/dist/utils/billing.js.map +1 -1
  38. package/dist/utils/constants.d.ts +21 -0
  39. package/dist/utils/constants.js +97 -0
  40. package/dist/utils/constants.js.map +1 -0
  41. package/dist/utils/firebase.js +2 -2
  42. package/dist/utils/firebase.js.map +1 -1
  43. package/dist/utils/index.d.ts +1 -0
  44. package/dist/utils/index.js +1 -0
  45. package/dist/utils/index.js.map +1 -1
  46. package/dist/utils/shopify.d.ts +1 -10
  47. package/dist/utils/shopify.js +13 -25
  48. package/dist/utils/shopify.js.map +1 -1
  49. package/dist/withShopify.js +3 -27
  50. package/dist/withShopify.js.map +1 -1
  51. package/package.json +1 -1
  52. package/dist/apiHandlers.js.map +0 -1
  53. package/dist/apiHelpers.d.ts +0 -70
  54. package/dist/apiHelpers.js +0 -251
  55. package/dist/apiHelpers.js.map +0 -1
  56. package/dist/protectRoute.js.map +0 -1
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.graphHelper = void 0;
15
+ const shopify_api_1 = require("@shopify/shopify-api");
16
+ const utils_1 = require("../utils");
17
+ const error_1 = require("./error");
18
+ const graphHelper = async ({ req, res, params: _params, serverRuntimeConfig }) => {
19
+ var _a;
20
+ const { body, query: _query } = req;
21
+ const { shop } = _query !== null && _query !== void 0 ? _query : {};
22
+ const _b = _params !== null && _params !== void 0 ? _params : {}, { data: dataParam, query: queryParam } = _b, params = __rest(_b, ["data", "query"]);
23
+ let query = queryParam !== null && queryParam !== void 0 ? queryParam : _query;
24
+ const data = dataParam !== null && dataParam !== void 0 ? dataParam : JSON.parse(body !== null && body !== void 0 ? body : {});
25
+ if (utils_1.isType(query, 'string')) {
26
+ query = utils_1.querystringToObject(query);
27
+ }
28
+ if (!shop || !data) {
29
+ return {
30
+ statusCode: 400,
31
+ message: 'Invalid arguments',
32
+ };
33
+ }
34
+ try {
35
+ const session = await utils_1.getVerifiedSession({ req, res, shop, serverRuntimeConfig });
36
+ const client = new shopify_api_1.Shopify.Clients.Graphql(shop, session === null || session === void 0 ? void 0 : session.accessToken);
37
+ const payload = Object.assign(Object.assign({ data }, query && { query }), params);
38
+ const response = await client.query(payload);
39
+ return {
40
+ statusCode: 200,
41
+ response,
42
+ };
43
+ }
44
+ catch (error) {
45
+ const errorMessage = 'Error handling query call';
46
+ switch (true) {
47
+ case error instanceof utils_1.ShopifyAuthenticationError: {
48
+ console.error(`${errorMessage}. Authentication Error`, error);
49
+ return error_1.authenticationErrorHelper({ error, shop, serverRuntimeConfig });
50
+ }
51
+ case error instanceof shopify_api_1.Shopify.Errors.BillingError: {
52
+ console.error(`${errorMessage}. Billing Error - ${error.message}`, error.errorData);
53
+ return {
54
+ statusCode: 500,
55
+ message: errorMessage,
56
+ };
57
+ }
58
+ case error instanceof shopify_api_1.Shopify.Errors.GraphqlQueryError: {
59
+ const errorMessages = utils_1.ensureArray((_a = error.response) === null || _a === void 0 ? void 0 : _a.errors).map(({ message }) => utils_1.ensureString(message));
60
+ console.error(`${errorMessage}. ${errorMessages.join('. ')}`);
61
+ return {
62
+ statusCode: 500,
63
+ message: errorMessage,
64
+ };
65
+ }
66
+ default: {
67
+ console.error(errorMessage, error);
68
+ return {
69
+ statusCode: 500,
70
+ message: errorMessage,
71
+ };
72
+ }
73
+ }
74
+ }
75
+ };
76
+ exports.graphHelper = graphHelper;
77
+ //# sourceMappingURL=graph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.js","sourceRoot":"","sources":["../../src/helpers/graph.js"],"names":[],"mappings":";;;;;;;;;;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AAC,YAAY,EAAE,KAAK,CAAC,CAAA;gBAClC,OAAO;oBACL,UAAU,EAAE,GAAG;oBACf,OAAO,EAAE,YAAY;iBACtB,CAAA;aACF;SACF;KACF;AACH,CAAC,CAAA;AAzEY,QAAA,WAAW,eAyEvB"}
@@ -0,0 +1,6 @@
1
+ export * from "./auth";
2
+ export * from "./callback";
3
+ export * from "./error";
4
+ export * from "./graph";
5
+ export * from "./rest";
6
+ export * from "./uninstall";
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./auth"), exports);
14
+ __exportStar(require("./callback"), exports);
15
+ __exportStar(require("./error"), exports);
16
+ __exportStar(require("./graph"), exports);
17
+ __exportStar(require("./rest"), exports);
18
+ __exportStar(require("./uninstall"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helpers/index.js"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAsB;AACtB,6CAA0B;AAC1B,0CAAuB;AACvB,0CAAuB;AACvB,yCAAsB;AACtB,8CAA2B"}
@@ -0,0 +1,21 @@
1
+ export function restHelper({ req, res, params: _params, serverRuntimeConfig }: {
2
+ req: any;
3
+ res: any;
4
+ params: any;
5
+ serverRuntimeConfig: any;
6
+ }): Promise<{
7
+ statusCode: number;
8
+ message: any;
9
+ headers: {
10
+ 'X-Shopify-API-Request-Failure-Reauthorize': string;
11
+ 'X-Shopify-API-Request-Failure-Reauthorize-Url': any;
12
+ };
13
+ } | {
14
+ statusCode: number;
15
+ message: string;
16
+ response?: undefined;
17
+ } | {
18
+ statusCode: number;
19
+ response: any;
20
+ message?: undefined;
21
+ }>;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.restHelper = void 0;
15
+ const shopify_api_1 = require("@shopify/shopify-api");
16
+ const utils_1 = require("../utils");
17
+ const error_1 = require("./error");
18
+ const restHelper = async ({ req, res, params: _params, serverRuntimeConfig }) => {
19
+ const { query: _query, method: _method, body: _body } = req;
20
+ const { shop } = _query !== null && _query !== void 0 ? _query : {};
21
+ const _a = _params !== null && _params !== void 0 ? _params : {}, { method: methodParam, query: queryParam, body: bodyParam, path } = _a, params = __rest(_a, ["method", "query", "body", "path"]);
22
+ let query = queryParam !== null && queryParam !== void 0 ? queryParam : _query;
23
+ const body = bodyParam !== null && bodyParam !== void 0 ? bodyParam : _body;
24
+ const method = utils_1.ensureString(methodParam !== null && methodParam !== void 0 ? methodParam : _method).toLowerCase();
25
+ if (utils_1.isType(query, 'string')) {
26
+ query = utils_1.querystringToObject(query);
27
+ }
28
+ if (!shop || !path) {
29
+ return {
30
+ statusCode: 400,
31
+ message: 'Invalid arguments',
32
+ };
33
+ }
34
+ try {
35
+ const session = await utils_1.getVerifiedSession({ req, res, shop, serverRuntimeConfig });
36
+ const shopify = utils_1.getInitializedShopify(serverRuntimeConfig, shop, '2021-04');
37
+ const client = new shopify.Clients.Rest(shop, session === null || session === void 0 ? void 0 : session.accessToken);
38
+ const response = await client[method](Object.assign({ path,
39
+ query,
40
+ body, type: shopify_api_1.DataType.JSON }, params));
41
+ return {
42
+ statusCode: 200,
43
+ response,
44
+ };
45
+ }
46
+ catch (error) {
47
+ const errorMessage = 'Error handling rest call';
48
+ switch (true) {
49
+ case error instanceof utils_1.ShopifyAuthenticationError: {
50
+ console.error(`${errorMessage}. Authentication Error`, error);
51
+ return error_1.authenticationErrorHelper({ error, shop, serverRuntimeConfig });
52
+ }
53
+ case error instanceof shopify_api_1.Shopify.Errors.BillingError: {
54
+ console.error(`${errorMessage}. Billing Error - ${error.message}`, error.errorData);
55
+ return {
56
+ statusCode: 500,
57
+ message: errorMessage,
58
+ };
59
+ }
60
+ default: {
61
+ console.error(errorMessage, error);
62
+ return {
63
+ statusCode: 500,
64
+ message: errorMessage,
65
+ };
66
+ }
67
+ }
68
+ }
69
+ };
70
+ exports.restHelper = restHelper;
71
+ //# sourceMappingURL=rest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rest.js","sourceRoot":"","sources":["../../src/helpers/rest.js"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,sDAAwD;AAExD,oCAOiB;AACjB,mCAAmD;AAE5C,MAAM,UAAU,GAAG,KAAK,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB,EAAE,EAAE,EAAE;IACrF,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,GAAG,CAAA;IAC3D,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAA;IAC7B,MAAM,KAMF,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,EANX,EACJ,MAAM,EAAE,WAAW,EACnB,KAAK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,KAAK,KAAK,YAAY,kCAA0B,CAAC,CAAC;gBAChD,OAAO,CAAC,KAAK,CAAC,GAAG,YAAY,wBAAwB,EAAE,KAAK,CAAC,CAAA;gBAC7D,OAAO,iCAAyB,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,mBAAmB,EAAE,CAAC,CAAA;aACvE;YAED,KAAK,KAAK,YAAY,qBAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;gBACjD,OAAO,CAAC,KAAK,CAAC,GAAG,YAAY,qBAAqB,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,SAAS,CAAC,CAAA;gBACnF,OAAO;oBACL,UAAU,EAAE,GAAG;oBACf,OAAO,EAAE,YAAY;iBACtB,CAAA;aACF;YAED,OAAO,CAAC,CAAC;gBACP,OAAO,CAAC,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,CAAA;gBAClC,OAAO;oBACL,UAAU,EAAE,GAAG;oBACf,OAAO,EAAE,YAAY;iBACtB,CAAA;aACF;SACF;KACF;AACH,CAAC,CAAA;AAzEY,QAAA,UAAU,cAyEtB"}
@@ -0,0 +1,7 @@
1
+ export function uninstallHelper({ req, serverRuntimeConfig }: {
2
+ req: any;
3
+ serverRuntimeConfig: any;
4
+ }): Promise<{
5
+ statusCode: number;
6
+ message: string;
7
+ }>;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.uninstallHelper = void 0;
4
+ const utils_1 = require("../utils");
5
+ const uninstallHelper = async ({ req, serverRuntimeConfig }) => {
6
+ var _a, _b, _c, _d;
7
+ try {
8
+ const { domain } = req.body;
9
+ const shopify = utils_1.getInitializedShopify(serverRuntimeConfig, domain);
10
+ const existingSessions = await ((_b = (_a = shopify.Context.SESSION_STORAGE) === null || _a === void 0 ? void 0 : _a.findSessionsByShop) === null || _b === void 0 ? void 0 : _b.call(_a, domain));
11
+ if (utils_1.arrayNotEmpty(existingSessions)) {
12
+ await ((_d = (_c = shopify.Context.SESSION_STORAGE) === null || _c === void 0 ? void 0 : _c.deleteSessions) === null || _d === void 0 ? void 0 : _d.call(_c, existingSessions.map((session) => session.id)));
13
+ }
14
+ return {
15
+ statusCode: 200,
16
+ message: 'success',
17
+ };
18
+ }
19
+ catch (error) {
20
+ const errorMessage = 'Error handling uninstall route';
21
+ console.error(errorMessage, error);
22
+ return {
23
+ statusCode: 500,
24
+ message: errorMessage,
25
+ };
26
+ }
27
+ };
28
+ exports.uninstallHelper = uninstallHelper;
29
+ //# sourceMappingURL=uninstall.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uninstall.js","sourceRoot":"","sources":["../../src/helpers/uninstall.js"],"names":[],"mappings":";;;AAAA,oCAA+D;AAExD,MAAM,eAAe,GAAG,KAAK,EAAE,EAAE,GAAG,EAAE,mBAAmB,EAAE,EAAE,EAAE;;IACpE,IAAI;QACF,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,IAAI,CAAA;QAC3B,MAAM,OAAO,GAAG,6BAAqB,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAA;QAElE,MAAM,gBAAgB,GAAG,MAAM,CAAA,MAAA,MAAA,OAAO,CAAC,OAAO,CAAC,eAAe,0CAAE,kBAAkB,mDAAG,MAAM,CAAC,CAAA,CAAA;QAC5F,IAAI,qBAAa,CAAC,gBAAgB,CAAC,EAAE;YACnC,MAAM,CAAA,MAAA,MAAA,OAAO,CAAC,OAAO,CAAC,eAAe,0CAAE,cAAc,mDAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAA,CAAA;SACvG;QAED,OAAO;YACL,UAAU,EAAE,GAAG;YACf,OAAO,EAAE,SAAS;SACnB,CAAA;KACF;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,YAAY,GAAG,gCAAgC,CAAA;QACrD,OAAO,CAAC,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,CAAA;QAElC,OAAO;YACL,UAAU,EAAE,GAAG;YACf,OAAO,EAAE,YAAY;SACtB,CAAA;KACF;AACH,CAAC,CAAA;AAvBY,QAAA,eAAe,mBAuB3B"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export * from './apiHelpers';
2
- export * from './apiHandlers';
3
- export * from './protectRoute';
1
+ export * from './handlers';
2
+ export * from './helpers';
4
3
  export * from './withShopify';
package/dist/index.js CHANGED
@@ -10,8 +10,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./apiHelpers"), exports);
14
- __exportStar(require("./apiHandlers"), exports);
15
- __exportStar(require("./protectRoute"), exports);
13
+ __exportStar(require("./handlers"), exports);
14
+ __exportStar(require("./helpers"), exports);
16
15
  __exportStar(require("./withShopify"), exports);
17
16
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAA4B;AAC5B,gDAA6B;AAC7B,iDAA8B;AAC9B,gDAA6B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAA0B;AAC1B,4CAAyB;AACzB,gDAA6B"}
@@ -1,8 +1,3 @@
1
- export namespace BILLING_INTERVALS {
2
- const ONE_TIME: string;
3
- const EVERY_30_DAYS: string;
4
- const ANNUAL: string;
5
- }
6
1
  export class BillingManager {
7
2
  constructor(session: any, serverRuntimeConfig: any);
8
3
  shop: any;
@@ -1,90 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BillingManager = exports.BILLING_INTERVALS = void 0;
3
+ exports.BillingManager = void 0;
4
4
  const shopify_api_1 = require("@shopify/shopify-api"); // DataType
5
5
  const display_1 = require("./display");
6
- exports.BILLING_INTERVALS = {
7
- ONE_TIME: 'ONE_TIME',
8
- EVERY_30_DAYS: 'EVERY_30_DAYS',
9
- ANNUAL: 'ANNUAL',
10
- };
11
- const RECURRING_INTERVALS = [
12
- exports.BILLING_INTERVALS.EVERY_30_DAYS,
13
- exports.BILLING_INTERVALS.ANNUAL
14
- ];
15
- const RECURRING_PURCHASES_QUERY = `
16
- query appSubscription {
17
- currentAppInstallation {
18
- activeSubscriptions {
19
- id, name, test
20
- }
21
- }
22
- }
23
- `;
24
- const ONE_TIME_PURCHASES_QUERY = `
25
- query appPurchases($endCursor: String) {
26
- currentAppInstallation {
27
- oneTimePurchases(first: 250, sortKey: CREATED_AT, after: $endCursor) {
28
- edges {
29
- node {
30
- id, name, test, status
31
- }
32
- }
33
- pageInfo {
34
- hasNextPage, endCursor
35
- }
36
- }
37
- }
38
- }
39
- `;
40
- const RECURRING_PURCHASE_MUTATION = `
41
- mutation test(
42
- $name: String!
43
- $lineItems: [AppSubscriptionLineItemInput!]!
44
- $returnUrl: URL!
45
- $test: Boolean
46
- ) {
47
- appSubscriptionCreate(
48
- name: $name
49
- lineItems: $lineItems
50
- returnUrl: $returnUrl
51
- test: $test
52
- ) {
53
- confirmationUrl
54
- userErrors {
55
- field
56
- message
57
- }
58
- }
59
- }
60
- `;
61
- const ONE_TIME_PURCHASE_MUTATION = `
62
- mutation test(
63
- $name: String!
64
- $price: MoneyInput!
65
- $returnUrl: URL!
66
- $test: Boolean
67
- ) {
68
- appPurchaseOneTimeCreate(
69
- name: $name
70
- price: $price
71
- returnUrl: $returnUrl
72
- test: $test
73
- ) {
74
- confirmationUrl
75
- userErrors {
76
- field
77
- message
78
- }
79
- }
80
- }
81
- `;
6
+ const constants_1 = require("./constants");
82
7
  class BillingManager {
83
8
  constructor(session, serverRuntimeConfig) {
84
9
  const { APP_ID, APP_BASE_URL, PAYMENT_CONFIG } = serverRuntimeConfig;
85
10
  if (display_1.stringEmpty(session === null || session === void 0 ? void 0 : session.shop) ||
86
11
  display_1.stringEmpty(session === null || session === void 0 ? void 0 : session.accessToken) ||
87
- !Object.values(exports.BILLING_INTERVALS).includes(PAYMENT_CONFIG === null || PAYMENT_CONFIG === void 0 ? void 0 : PAYMENT_CONFIG.type)) {
12
+ !Object.values(constants_1.BILLING_INTERVALS).includes(PAYMENT_CONFIG === null || PAYMENT_CONFIG === void 0 ? void 0 : PAYMENT_CONFIG.type)) {
88
13
  throw new shopify_api_1.Shopify.Errors.BillingError({
89
14
  message: 'Invalid billing configuration',
90
15
  });
@@ -94,12 +19,13 @@ class BillingManager {
94
19
  this.appId = APP_ID;
95
20
  this.appBaseUrl = APP_BASE_URL;
96
21
  this.paymentConfig = display_1.ensureObject(PAYMENT_CONFIG);
97
- this.isRecurring = RECURRING_INTERVALS.includes(this.paymentConfig.type);
22
+ this.isRecurring = constants_1.RECURRING_INTERVALS.includes(this.paymentConfig.type);
98
23
  }
99
24
  async ensureBilling() {
100
25
  var _a;
101
26
  try {
102
- if (await this.hasActivePayment()) {
27
+ const hasActive = await this.hasActivePayment();
28
+ if (hasActive) {
103
29
  return undefined;
104
30
  }
105
31
  return this.requestPayment();
@@ -117,85 +43,47 @@ class BillingManager {
117
43
  async hasActiveRecurringPayment(client) {
118
44
  var _a, _b, _c;
119
45
  const currentInstallations = await client.query({
120
- data: RECURRING_PURCHASES_QUERY,
46
+ data: constants_1.RECURRING_PURCHASES_QUERY,
121
47
  });
122
48
  const subscriptions = (_c = (_b = (_a = currentInstallations === null || currentInstallations === void 0 ? void 0 : currentInstallations.body) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.currentAppInstallation) === null || _c === void 0 ? void 0 : _c.activeSubscriptions;
123
49
  const matchingSubscription = display_1.ensureArray(subscriptions).find((sub) => {
124
- console.log(`>>> ~ sub`, sub);
125
50
  const { name: chargeName, test: chargeTest } = sub;
126
51
  return ((chargeName === this.paymentConfig.name)
127
- && (display_1.isTrue(chargeTest) === display_1.isTrue(this.paymentConfig.test)));
52
+ && (display_1.isTrue(chargeTest) === this.paymentConfig.test));
128
53
  });
129
- const foo = display_1.objectNotEmpty(matchingSubscription);
130
- console.log(`>>> ~ hasActiveRecurringPayment`, foo);
131
- return foo;
54
+ return display_1.objectNotEmpty(matchingSubscription);
132
55
  }
133
56
  async hasActiveOneTimePayment(client, endCursor = null) {
134
57
  var _a, _b, _c, _d, _e;
135
- const currentInstallations = await client.query({
58
+ const payload = {
136
59
  data: {
137
- query: ONE_TIME_PURCHASES_QUERY,
60
+ query: constants_1.ONE_TIME_PURCHASES_QUERY,
138
61
  variables: { endCursor },
139
62
  },
140
- });
63
+ };
64
+ const currentInstallations = await client.query(payload);
141
65
  const purchases = (_c = (_b = (_a = currentInstallations === null || currentInstallations === void 0 ? void 0 : currentInstallations.body) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.currentAppInstallation) === null || _c === void 0 ? void 0 : _c.oneTimePurchases;
142
66
  const matchingPurchase = display_1.ensureArray(purchases === null || purchases === void 0 ? void 0 : purchases.edges).find((pur) => {
143
67
  const { node } = pur;
144
- console.log(`>>> ~ node`, node);
145
68
  return (((node === null || node === void 0 ? void 0 : node.name) === this.paymentConfig.name)
146
69
  && ((node === null || node === void 0 ? void 0 : node.status) === 'ACTIVE')
147
- && (display_1.isTrue(node === null || node === void 0 ? void 0 : node.test) === display_1.isTrue(this.paymentConfig.test)));
70
+ && (display_1.isTrue(node === null || node === void 0 ? void 0 : node.test) === this.paymentConfig.test));
148
71
  });
149
- console.log(`>>> ~ matchingPurchases`, matchingPurchase);
150
72
  if (display_1.objectNotEmpty(matchingPurchase)) {
151
73
  return true;
152
74
  }
153
75
  if ((_d = purchases === null || purchases === void 0 ? void 0 : purchases.pageInfo) === null || _d === void 0 ? void 0 : _d.hasNextPage) {
154
76
  return this.hasActiveOneTimePayment(client, (_e = purchases === null || purchases === void 0 ? void 0 : purchases.pageInfo) === null || _e === void 0 ? void 0 : _e.endCursor);
155
77
  }
156
- console.log(`>>> ~ NO matchingPurchases`);
157
78
  return false;
158
79
  }
159
80
  async hasActivePayment() {
160
81
  const client = new shopify_api_1.Shopify.Clients.Graphql(this.shop, this.accessToken);
161
- return this.isRecurring
162
- ? this.hasActiveRecurringPayment(client)
163
- : this.hasActiveOneTimePayment(client);
164
- }
165
- /*
166
- // TODO ensure this logic works for recurring payments
167
- async hasActivePayment () {
168
- const client = new Shopify.Clients.Rest(this.shop, this.accessToken)
169
-
170
- // TODO: move this to match scaffold (/ensure we check !test)
171
- const { body: { application_charges } = {} } = ensureObject(await client.get({
172
- path: 'application_charges',
173
- type: DataType.JSON,
174
- }))
175
-
176
- console.log(`>>> > BillingManager > existingCharge > this.appId`, this.appId)
177
- console.log(`>>> > BillingManager > hasActivePayment > ensureArray(application_charges).length`, ensureArray(application_charges).length)
178
-
179
- const existingCharge = ensureArray(application_charges).reduce((_existingCharge, charge) => {
180
- const { api_client_id, status: chargeStatus } = ensureObject(charge)
181
- const isMatching = (stringNotEmpty(api_client_id) && (ensureString(api_client_id) === this.appId))
182
- console.log(`>>> > BillingManager > existingCharge > ${api_client_id}`, chargeStatus)
183
-
184
- if (_existingCharge.status === 'active') {
185
- return _existingCharge
186
- }
187
-
188
- if (isMatching && ['active', 'pending'].includes(chargeStatus)) {
189
- return charge
82
+ if (this.isRecurring) {
83
+ return this.hasActiveRecurringPayment(client);
190
84
  }
191
-
192
- return _existingCharge
193
- }, {})
194
- console.log(`>>> > BillingManager > hasActivePayment > existingCharge`, existingCharge)
195
-
196
- return objectNotEmpty(existingCharge)
85
+ return this.hasActiveOneTimePayment(client);
197
86
  }
198
- */
199
87
  async requestPayment() {
200
88
  const client = new shopify_api_1.Shopify.Clients.Graphql(this.shop, this.accessToken);
201
89
  // TODO: explore objectToQuerystring
@@ -219,7 +107,7 @@ class BillingManager {
219
107
  const { price, name, test, } = this.paymentConfig;
220
108
  const payload = {
221
109
  data: {
222
- query: ONE_TIME_PURCHASE_MUTATION,
110
+ query: constants_1.ONE_TIME_PURCHASE_MUTATION,
223
111
  variables: {
224
112
  test,
225
113
  name,
@@ -242,7 +130,7 @@ class BillingManager {
242
130
  const { price, name, test, type: interval, } = this.paymentConfig;
243
131
  const payload = {
244
132
  data: {
245
- query: RECURRING_PURCHASE_MUTATION,
133
+ query: constants_1.RECURRING_PURCHASE_MUTATION,
246
134
  variables: {
247
135
  test,
248
136
  name,
@@ -1 +1 @@
1
- {"version":3,"file":"billing.js","sourceRoot":"","sources":["../../src/utils/billing.js"],"names":[],"mappings":";;;AAAA,sDAA8C,CAAC,WAAW;AAE1D,uCAUkB;AAGL,QAAA,iBAAiB,GAAG;IAC/B,QAAQ,EAAE,UAAU;IACpB,aAAa,EAAE,eAAe;IAC9B,MAAM,EAAE,QAAQ;CACjB,CAAA;AAED,MAAM,mBAAmB,GAAG;IAC1B,yBAAiB,CAAC,aAAa;IAC/B,yBAAiB,CAAC,MAAM;CACzB,CAAA;AAED,MAAM,yBAAyB,GAAG;;;;;;;;CAQjC,CAAA;AAED,MAAM,wBAAwB,GAAG;;;;;;;;;;;;;;;CAehC,CAAA;AAED,MAAM,2BAA2B,GAAG;;;;;;;;;;;;;;;;;;;;CAoBnC,CAAA;AAED,MAAM,0BAA0B,GAAG;;;;;;;;;;;;;;;;;;;;CAoBlC,CAAA;AAED,MAAa,cAAc;IACzB,YAAY,OAAO,EAAE,mBAAmB;QACtC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,GAAG,mBAAmB,CAAA;QAEpE,IACE,qBAAW,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,CAAC;YAC1B,qBAAW,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,CAAC;YACjC,CAAC,MAAM,CAAC,MAAM,CAAC,yBAAiB,CAAC,CAAC,QAAQ,CAAC,cAAc,aAAd,cAAc,uBAA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C5G,CAAC,CAAA;SACH;QAED,OAAO,MAAA,MAAA,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,IAAI,0CAAE,IAAI,0CAAE,qBAAqB,CAAA;IAC5D,CAAC;CACF;AAhMD,wCAgMC"}
@@ -0,0 +1,21 @@
1
+ export const COLLECTION_ROOT: "oauth-data";
2
+ export namespace PAGE_ROUTE_NAMES {
3
+ const EXIT: string;
4
+ const ERROR: string;
5
+ }
6
+ export namespace API_ROUTE_NAMES {
7
+ const AUTH: string;
8
+ const AUTH_CALLBACK: string;
9
+ const APP_UNINSTALLED: string;
10
+ }
11
+ export namespace BILLING_INTERVALS {
12
+ const ONE_TIME: string;
13
+ const EVERY_30_DAYS: string;
14
+ const ANNUAL: string;
15
+ }
16
+ export const RECURRING_INTERVALS: string[];
17
+ export const SHOP_QUERY: "\n {\n shop {\n name\n }\n }\n";
18
+ export const RECURRING_PURCHASES_QUERY: "\n query appSubscription {\n currentAppInstallation {\n activeSubscriptions {\n name, test\n }\n }\n }\n";
19
+ export const ONE_TIME_PURCHASES_QUERY: "\n query appPurchases($endCursor: String) {\n currentAppInstallation {\n oneTimePurchases(first: 250, sortKey: CREATED_AT, after: $endCursor) {\n edges {\n node {\n name, test, status\n }\n }\n pageInfo {\n hasNextPage, endCursor\n }\n }\n }\n }\n";
20
+ export const RECURRING_PURCHASE_MUTATION: "\n mutation test(\n $name: String!\n $lineItems: [AppSubscriptionLineItemInput!]!\n $returnUrl: URL!\n $test: Boolean\n ) {\n appSubscriptionCreate(\n name: $name\n lineItems: $lineItems\n returnUrl: $returnUrl\n test: $test\n ) {\n confirmationUrl\n userErrors {\n field\n message\n }\n }\n }\n";
21
+ export const ONE_TIME_PURCHASE_MUTATION: "\n mutation test(\n $name: String!\n $price: MoneyInput!\n $returnUrl: URL!\n $test: Boolean\n ) {\n appPurchaseOneTimeCreate(\n name: $name\n price: $price\n returnUrl: $returnUrl\n test: $test\n ) {\n confirmationUrl\n userErrors {\n field\n message\n }\n }\n }\n";