@agnostack/next-shopify 1.8.1-alpha.5 → 1.8.1-alpha.6
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.
|
@@ -17,65 +17,35 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
exports.handleAppBilling = void 0;
|
|
18
18
|
const raw_body_1 = __importDefault(require("raw-body"));
|
|
19
19
|
const utils_1 = require("../../utils");
|
|
20
|
-
const INSTALLATION_BILLING_QUERY = `
|
|
21
|
-
{
|
|
22
|
-
currentAppInstallation {
|
|
23
|
-
app {
|
|
24
|
-
title
|
|
25
|
-
}
|
|
26
|
-
oneTimePurchases(first: 25) {
|
|
27
|
-
nodes {
|
|
28
|
-
id
|
|
29
|
-
status
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
allSubscriptions(first:20) {
|
|
33
|
-
nodes {
|
|
34
|
-
id
|
|
35
|
-
status
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
`;
|
|
41
20
|
// NOTE: typically handling: "/api/webhooks/app/billing"
|
|
42
21
|
const handleAppBilling = (serverRuntimeConfig) => async (req, res) => {
|
|
43
|
-
var _a
|
|
22
|
+
var _a;
|
|
44
23
|
try {
|
|
45
|
-
const { 'x-shopify-shop-domain': shop
|
|
46
|
-
console.log(`>>> ~ req.headers`, req.headers);
|
|
24
|
+
const { 'x-shopify-shop-domain': shop } = (_a = req.headers) !== null && _a !== void 0 ? _a : {};
|
|
47
25
|
if (utils_1.stringEmpty(shop)) {
|
|
48
26
|
return res.status(200).json({ handler: 'billing', error: 'Missing shop' });
|
|
49
27
|
}
|
|
50
28
|
const { shopify } = await utils_1.getShopifyHelpers(serverRuntimeConfig, { shop });
|
|
51
|
-
console.log(`>>> > handleAppBilling > req.body`, req.body);
|
|
52
29
|
// NOTE raw request body is required for Shopify webhook validation
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
rawBody
|
|
30
|
+
const _rawBody = await raw_body_1.default(req);
|
|
31
|
+
const rawBody = _rawBody.toString();
|
|
32
|
+
const _b = await shopify.webhooks.validate({
|
|
33
|
+
rawBody,
|
|
57
34
|
rawRequest: req,
|
|
58
35
|
rawResponse: res,
|
|
59
|
-
}), { valid } =
|
|
36
|
+
}), { valid } = _b, webhookCheck = __rest(_b, ["valid"]);
|
|
60
37
|
if (valid) {
|
|
61
38
|
try {
|
|
62
|
-
const {
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const errorMessages = userErrors.map(({ message }) => utils_1.ensureString(message));
|
|
70
|
-
return res.status(200).json({
|
|
71
|
-
handler: 'billing',
|
|
72
|
-
message: `Error fetching App Installation. ${errorMessages.join('. ')}.`,
|
|
39
|
+
const [type, { status } = {}] = Object.entries(JSON.parse(rawBody))[0];
|
|
40
|
+
const { Rest } = await utils_1.getVerifiedClients(serverRuntimeConfig, { req, res, shop });
|
|
41
|
+
let response;
|
|
42
|
+
// TODO constants
|
|
43
|
+
if (type === 'app_purchase_one_time' && status === 'DECLINED') {
|
|
44
|
+
response = await Rest.delete({
|
|
45
|
+
path: '/admin/api_permissions/current.json',
|
|
73
46
|
});
|
|
74
47
|
}
|
|
75
|
-
console.log(`>>> ~
|
|
76
|
-
console.log(`>>> ~ topic`, topic);
|
|
77
|
-
console.log(`>>> > handleAppBilling > TODO!!!!!: do something here`);
|
|
78
|
-
// TODO!!!!!: do something here!?!?!?
|
|
48
|
+
console.log(`>>> ~ response`, response);
|
|
79
49
|
return res.status(200).json({ handler: 'billing', message: 'success' });
|
|
80
50
|
}
|
|
81
51
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"billing.js","sourceRoot":"","sources":["../../../src/handlers/api/billing.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,wDAAiC;AAEjC,
|
|
1
|
+
{"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next-shopify",
|
|
3
|
-
"version": "1.8.1-alpha.
|
|
3
|
+
"version": "1.8.1-alpha.6",
|
|
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",
|