@agnostack/next-shopify 1.8.2-alpha.6 → 1.8.2-alpha.8

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.
@@ -18,6 +18,21 @@ exports.handleAppBilling = void 0;
18
18
  /* eslint-disable no-use-before-define */
19
19
  const raw_body_1 = __importDefault(require("raw-body"));
20
20
  const utils_1 = require("../../utils");
21
+ const CURRENT_INSTALLATION_QUERY = `
22
+ {
23
+ currentAppInstallation {
24
+ activeSubscriptions {
25
+ id
26
+ }
27
+ oneTimePurchases(first: 250, reverse: true) {
28
+ nodes {
29
+ id
30
+ status
31
+ }
32
+ }
33
+ }
34
+ }
35
+ `;
21
36
  // NOTE: typically handling: "/api/webhooks/app/billing"
22
37
  const handleAppBilling = (serverRuntimeConfig) => async (req, res) => {
23
38
  var _a, _b;
@@ -28,46 +43,36 @@ const handleAppBilling = (serverRuntimeConfig) => async (req, res) => {
28
43
  }
29
44
  const { shopify } = await utils_1.getShopifyHelpers(serverRuntimeConfig, { shop });
30
45
  // NOTE raw request body is required for Shopify webhook validation
31
- const rawBody = await raw_body_1.default(req);
46
+ const _rawBody = await raw_body_1.default(req);
47
+ const rawBody = _rawBody.toString();
32
48
  const _c = await shopify.webhooks.validate({
33
49
  rawBody,
34
50
  rawRequest: req,
35
51
  rawResponse: res,
36
52
  }), { valid } = _c, webhookCheck = __rest(_c, ["valid"]);
53
+ console.log(`>>> ~ rawBody`, rawBody);
37
54
  console.log(`>>> handleAppBilling ~ valid`, valid);
38
55
  console.log(`>>> handleAppBilling ~ webhookCheck`, webhookCheck);
39
56
  if (valid) {
40
57
  try {
41
- const { Rest, Graphql } = await utils_1.getVerifiedClients(serverRuntimeConfig, { shop });
42
- console.log(`>>> ~ Graphql`, Graphql);
43
- // TODO support pagination
44
- const currentInstallations = await Graphql.query({
45
- data: `
46
- {
47
- currentAppInstallation {
48
- activeSubscriptions {
49
- id
50
- }
51
- oneTimePurchases(first: 250, reverse: true) {
52
- nodes {
53
- id
54
- status
55
- }
56
- }
57
- }
58
- }
59
- `,
60
- });
61
- const { currentAppInstallation: { activeSubscriptions, oneTimePurchases: { nodes: _oneTimePurchases, } = {}, } = {}, } = utils_1.ensureObject((_b = currentInstallations === null || currentInstallations === void 0 ? void 0 : currentInstallations.body) === null || _b === void 0 ? void 0 : _b.data);
62
- console.log(`>>> ~ currentInstallations`, currentInstallations);
63
- const activeSubscriptionPurchases = utils_1.arrayNotEmpty(activeSubscriptions);
64
- console.log(`>>> ~ activeSubscriptionPurchases`, activeSubscriptionPurchases);
65
- const activeOneTimePurchases = utils_1.ensureArray(_oneTimePurchases).some((({ status } = {}) => (status === 'ACTIVE')));
66
- console.log(`>>> ~ activeOneTimePurchases`, activeOneTimePurchases);
67
- if (activeSubscriptionPurchases || activeOneTimePurchases) {
68
- await Rest.delete({
69
- path: '/admin/api_permissions/current.json',
70
- });
58
+ const [{ status } = {}] = Object.entries(JSON.parse(rawBody))[0];
59
+ console.log(`>>> ~ status`, status);
60
+ if (status === 'DECLINED') {
61
+ const { Rest, Graphql } = await utils_1.getVerifiedClients(serverRuntimeConfig, { shop });
62
+ console.log(`>>> ~ Graphql`, Graphql);
63
+ // TODO support pagination
64
+ const currentInstallations = await Graphql.query({ data: CURRENT_INSTALLATION_QUERY });
65
+ const { currentAppInstallation: { activeSubscriptions, oneTimePurchases: { nodes: _oneTimePurchases, } = {}, } = {}, } = utils_1.ensureObject((_b = currentInstallations === null || currentInstallations === void 0 ? void 0 : currentInstallations.body) === null || _b === void 0 ? void 0 : _b.data);
66
+ console.log(`>>> ~ currentInstallations`, currentInstallations);
67
+ const activeSubscriptionPurchases = utils_1.arrayNotEmpty(activeSubscriptions);
68
+ console.log(`>>> ~ activeSubscriptionPurchases`, activeSubscriptionPurchases);
69
+ const activeOneTimePurchases = utils_1.ensureArray(_oneTimePurchases).some((({ status } = {}) => (status === 'ACTIVE')));
70
+ console.log(`>>> ~ activeOneTimePurchases`, activeOneTimePurchases);
71
+ if (activeSubscriptionPurchases || activeOneTimePurchases) {
72
+ await Rest.delete({
73
+ path: '/admin/api_permissions/current.json',
74
+ });
75
+ }
71
76
  }
72
77
  return res.status(200).json({ handler: 'billing', message: 'success' });
73
78
  }
@@ -1 +1 @@
1
- {"version":3,"file":"billing.js","sourceRoot":"","sources":["../../../src/handlers/api/billing.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,yCAAyC;AACzC,wDAAiC;AAEjC,uCAOoB;AAEpB,wDAAwD;AACjD,MAAM,gBAAgB,GAAG,CAAC,mBAAmB,EAAE,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;;IAC1E,IAAI;QACF,MAAM,EAAE,uBAAuB,EAAE,IAAI,EAAE,GAAG,MAAA,GAAG,CAAC,OAAO,mCAAI,EAAE,CAAA;QAE3D,IAAI,mBAAW,CAAC,IAAI,CAAC,EAAE;YACrB,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,CAAA;SAC3E;QAED,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,yBAAiB,CAAC,mBAAmB,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;QAE1E,mEAAmE;QACnE,MAAM,OAAO,GAAG,MAAM,kBAAU,CAAC,GAAG,CAAC,CAAA;QAErC,MAAM,KAA6B,MAAM,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;YACjE,OAAO;YACP,UAAU,EAAE,GAAG;YACf,WAAW,EAAE,GAAG;SACjB,CAAC,EAJI,EAAE,KAAK,OAIX,EAJgB,YAAY,cAAxB,SAA0B,CAI9B,CAAA;QAEF,OAAO,CAAC,GAAG,CAAC,8BAA8B,EAAE,KAAK,CAAC,CAAA;QAClD,OAAO,CAAC,GAAG,CAAC,qCAAqC,EAAE,YAAY,CAAC,CAAA;QAEhE,IAAI,KAAK,EAAE;YAC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,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,EAAE,CAAC,CAAA;aAC3E;SACF;QAED,OAAO,CAAC,IAAI,CAAC,oCAAoC,EAAE,YAAY,CAAC,CAAA;QAChE,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,oCAAoC,EAAE,CAAC,CAAA;KACjG;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAA;QAC9C,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,wBAAwB,EAAE,CAAC,CAAA;KACrF;AACH,CAAC,CAAA;AAvEY,QAAA,gBAAgB,oBAuE5B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agnostack/next-shopify",
3
- "version": "1.8.2-alpha.6",
3
+ "version": "1.8.2-alpha.8",
4
4
  "author": "agnoStack Dev <developers@agnostack.com> (https://agnostack.com)",
5
5
  "owner": "agnoStack",
6
6
  "description": "Please contact agnoStack via info@agnostack.com for any questions",