@agnostack/next-shopify 1.7.1-beta.15 → 1.7.1-beta.16
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/dist/handlers/api/proxy.js +22 -84
- package/dist/handlers/api/proxy.js.map +1 -1
- package/dist/handlers/api/uninstall.d.ts +0 -5
- package/dist/handlers/api/uninstall.js +1 -7
- package/dist/handlers/api/uninstall.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/response.d.ts +5 -0
- package/dist/utils/response.js +10 -0
- package/dist/utils/response.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,36 +1,16 @@
|
|
|
1
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
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
16
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
6
|
exports.handleProxy = void 0;
|
|
18
7
|
// NOTE: api routes do NOT work in `next export`
|
|
8
|
+
const http_proxy_1 = __importDefault(require("http-proxy"));
|
|
19
9
|
const nextjs_cors_1 = __importDefault(require("nextjs-cors"));
|
|
20
|
-
const shopify_api_1 = require("@shopify/shopify-api");
|
|
21
10
|
const utils_1 = require("../../utils");
|
|
22
|
-
// import {
|
|
23
|
-
// isType,
|
|
24
|
-
// stringEmpty,
|
|
25
|
-
// ensureString,
|
|
26
|
-
// ensureObject,
|
|
27
|
-
// getVerifiedClients,
|
|
28
|
-
// querystringToObject,
|
|
29
|
-
// getAuthErrorResponse,
|
|
30
|
-
// ShopifyAuthenticationError,
|
|
31
|
-
// } from '../../utils'
|
|
32
11
|
const handleProxy = (serverRuntimeConfig) => async (req, res, _params) => {
|
|
33
|
-
const
|
|
12
|
+
const proxy = http_proxy_1.default.createProxyServer();
|
|
13
|
+
const { TARGET_SAFELIST, ORIGIN_SAFELIST } = serverRuntimeConfig;
|
|
34
14
|
const originSafelist = [
|
|
35
15
|
...utils_1.ensureArray(ORIGIN_SAFELIST),
|
|
36
16
|
'https://cdn.shopify.com'
|
|
@@ -50,70 +30,28 @@ const handleProxy = (serverRuntimeConfig) => async (req, res, _params) => {
|
|
|
50
30
|
},
|
|
51
31
|
optionsSuccessStatus: 200, // some legacy browsers (IE11, various SmartTVs) choke on 204
|
|
52
32
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const { 'x-proxy-source': proxySource, authorization, } = _headers !== null && _headers !== void 0 ? _headers : {};
|
|
59
|
-
console.log(`>>> > handleProxy > proxySource:`, proxySource);
|
|
60
|
-
console.log(`>>> > handleProxy > authorization:`, authorization);
|
|
61
|
-
// const { shop } = _query ?? {}
|
|
62
|
-
const _a = _params !== null && _params !== void 0 ? _params : {}, {
|
|
63
|
-
// method: methodParam,
|
|
64
|
-
// query: queryParam,
|
|
65
|
-
// body: bodyParam,
|
|
66
|
-
path } = _a, params = __rest(_a, ["path"]);
|
|
67
|
-
console.log(`>>> ~ path`, path);
|
|
68
|
-
// if (stringEmpty(shop) || stringEmpty(path)) {
|
|
69
|
-
// return {
|
|
70
|
-
// statusCode: 400,
|
|
71
|
-
// message: 'Invalid arguments',
|
|
72
|
-
// }
|
|
73
|
-
// }
|
|
74
|
-
let statusCode;
|
|
75
|
-
let response;
|
|
76
|
-
let message;
|
|
77
|
-
let headers = {};
|
|
78
|
-
try {
|
|
79
|
-
response = 'proxy success';
|
|
80
|
-
statusCode = 200;
|
|
33
|
+
const { query: _query, headers: _headers } = req;
|
|
34
|
+
const { shop: _shop, host: _host } = _query !== null && _query !== void 0 ? _query : {};
|
|
35
|
+
const { target } = _params !== null && _params !== void 0 ? _params : {};
|
|
36
|
+
if (utils_1.arrayEmpty(TARGET_SAFELIST) || !TARGET_SAFELIST.includes(target)) {
|
|
37
|
+
return res.status(407).json({ message: 'Unproxyable target.' });
|
|
81
38
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
// case error instanceof ShopifyAuthenticationError: {
|
|
87
|
-
// console.error(`${message}. Authentication Error`, error)
|
|
88
|
-
// const errroResponse = getAuthErrorResponse({ error, shop, serverRuntimeConfig })
|
|
89
|
-
// statusCode = errroResponse.statusCode
|
|
90
|
-
// message = errroResponse.message
|
|
91
|
-
// headers = errroResponse.headers
|
|
92
|
-
// break
|
|
93
|
-
// }
|
|
94
|
-
case error instanceof shopify_api_1.BillingError: {
|
|
95
|
-
console.error(`${message}. Billing Error - ${error.message}`, error.errorData);
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
default: {
|
|
99
|
-
console.error(message, error);
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
39
|
+
// TODO: explore moving this to sessionToken middleware??
|
|
40
|
+
const { authorization, 'x-proxy-source': proxySource } = _headers !== null && _headers !== void 0 ? _headers : {};
|
|
41
|
+
if (!_shop || !_host || !proxySource) {
|
|
42
|
+
return res.status(400).json({ message: 'Invalid shop, host or proxy source.' });
|
|
103
43
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (!response) {
|
|
108
|
-
return res.status(statusCode).json({ message });
|
|
109
|
-
}
|
|
110
|
-
if ((params === null || params === void 0 ? void 0 : params.type) && ![shopify_api_1.DataType.GraphQL, shopify_api_1.DataType.JSON].includes(params.type)) {
|
|
111
|
-
return res.status(statusCode).send(response);
|
|
44
|
+
const { shop, host } = utils_1.decodeShopData(utils_1.ensureString(authorization).replace('Bearer '));
|
|
45
|
+
if ((shop !== _shop) || (host !== _host)) {
|
|
46
|
+
return res.status(403).json({ message: 'Unauthorized shop or host.' });
|
|
112
47
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
48
|
+
// TODO: explore adding hmac check/middleware?
|
|
49
|
+
return new Promise((resolve, reject) => (proxy.web(req, res, { target, changeOrigin: true, secure: true }, (error) => {
|
|
50
|
+
if (error) {
|
|
51
|
+
return reject(error);
|
|
52
|
+
}
|
|
53
|
+
resolve();
|
|
54
|
+
})));
|
|
117
55
|
};
|
|
118
56
|
exports.handleProxy = handleProxy;
|
|
119
57
|
//# sourceMappingURL=proxy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../../src/handlers/api/proxy.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../../src/handlers/api/proxy.js"],"names":[],"mappings":";;;;;;AAAA,gDAAgD;AAChD,4DAAkC;AAClC,8DAAkC;AAElC,uCAOoB;AAEb,MAAM,WAAW,GAAG,CAAC,mBAAmB,EAAE,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE;IAC9E,MAAM,KAAK,GAAG,oBAAS,CAAC,iBAAiB,EAAE,CAAA;IAE3C,MAAM,EAAE,eAAe,EAAE,eAAe,EAAE,GAAG,mBAAmB,CAAA;IAChE,MAAM,cAAc,GAAG;QACrB,GAAG,mBAAW,CAAC,eAAe,CAAC;QAC/B,yBAAyB;KAC1B,CAAA;IAED,MAAM,qBAAQ,CAAC,GAAG,EAAE,GAAG,EAAE;QACvB,OAAO,EAA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KAAK,IAAI,CAAC,KAAK,IAAI,CAAC,WAAW,EAAE;QACpC,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,qCAAqC,EAAE,CAAC,CAAA;KAChF;IAED,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,sBAAc,CAAC,oBAAY,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAA;IACrF,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,EAAE;QACxC,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,4BAA4B,EAAE,CAAC,CAAA;KACvE;IAED,8CAA8C;IAE/C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,CACvC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE;QAC3E,IAAI,KAAK,EAAE;YACV,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;SACpB;QACD,OAAO,EAAE,CAAA;IACV,CAAC,CAAC,CACD,CAAC,CAAA;AACJ,CAAC,CAAA;AApDY,QAAA,WAAW,eAoDvB"}
|
|
@@ -3,16 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.handleAppUninstalled =
|
|
6
|
+
exports.handleAppUninstalled = void 0;
|
|
7
7
|
const raw_body_1 = __importDefault(require("raw-body"));
|
|
8
8
|
const runtime_1 = require("@shopify/shopify-api/runtime");
|
|
9
9
|
const utils_1 = require("../../utils");
|
|
10
|
-
// NOTE raw request body is required for Shopify webhook validation
|
|
11
|
-
exports.rawBodyConfig = {
|
|
12
|
-
api: {
|
|
13
|
-
bodyParser: false,
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
10
|
// NOTE: typically handling: "/api/webhooks/app/uninstalled"
|
|
17
11
|
const handleAppUninstalled = (serverRuntimeConfig) => async (req, res) => {
|
|
18
12
|
// NOTE raw request body is required for Shopify webhook validation
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uninstall.js","sourceRoot":"","sources":["../../../src/handlers/api/uninstall.js"],"names":[],"mappings":";;;;;;AAAA,wDAAiC;AACjC,0DAGqC;AAErC,uCAMoB;AAEpB,
|
|
1
|
+
{"version":3,"file":"uninstall.js","sourceRoot":"","sources":["../../../src/handlers/api/uninstall.js"],"names":[],"mappings":";;;;;;AAAA,wDAAiC;AACjC,0DAGqC;AAErC,uCAMoB;AAEpB,4DAA4D;AACrD,MAAM,oBAAoB,GAAG,CAAC,mBAAmB,EAAE,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;IAC9E,mEAAmE;IACnE,MAAM,OAAO,GAAG,MAAM,kBAAU,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QACpD,OAAO,CAAC,KAAK,CAAC,6CAA6C,EAAE,KAAK,CAAC,CAAA;QAEnE,2EAA2E;QAC3E,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAA;IAC3D,CAAC,CAAC,CAAA;IAEF,IAAI;QACF,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,uBAAuB,CAAC,CAAA;QAEjD,IAAI,mBAAW,CAAC,IAAI,CAAC,EAAE;YACrB,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;SAC5C;QAED,MAAM,EAAE,O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AC,CAAA;KACH;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,KAAK,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAA;QAChD,sFAAsF;QACtF,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAA;KACxD;AACH,CAAC,CAAA;AAnDY,QAAA,oBAAoB,wBAmDhC"}
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -15,6 +15,7 @@ __exportStar(require("./constants"), exports);
|
|
|
15
15
|
__exportStar(require("./display"), exports);
|
|
16
16
|
__exportStar(require("./errors"), exports);
|
|
17
17
|
__exportStar(require("./firebase"), exports);
|
|
18
|
+
__exportStar(require("./response"), exports);
|
|
18
19
|
__exportStar(require("./session"), exports);
|
|
19
20
|
__exportStar(require("./shopify"), exports);
|
|
20
21
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.js"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAAyB;AACzB,8CAA2B;AAC3B,4CAAyB;AACzB,2CAAwB;AACxB,6CAA0B;AAC1B,4CAAyB;AACzB,4CAAyB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.js"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAAyB;AACzB,8CAA2B;AAC3B,4CAAyB;AACzB,2CAAwB;AACxB,6CAA0B;AAC1B,6CAA0B;AAC1B,4CAAyB;AACzB,4CAAyB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rawBodyConfig = void 0;
|
|
4
|
+
// NOTE raw request body is required for Shopify webhook validation
|
|
5
|
+
exports.rawBodyConfig = {
|
|
6
|
+
api: {
|
|
7
|
+
bodyParser: false,
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=response.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.js","sourceRoot":"","sources":["../../src/utils/response.js"],"names":[],"mappings":";;;AAAA,mEAAmE;AACtD,QAAA,aAAa,GAAG;IAC3B,GAAG,EAAE;QACH,UAAU,EAAE,KAAK;KAClB;CACF,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agnostack/next-shopify",
|
|
3
|
-
"version": "1.7.1-beta.
|
|
3
|
+
"version": "1.7.1-beta.16",
|
|
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",
|