@agnostack/next-shopify 1.3.2-alpha.27 → 1.3.2-alpha.29
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/CHANGELOG.md +15 -0
- package/dist/{apiHandlers.d.ts → handlers/api.d.ts} +0 -0
- package/dist/{apiHandlers.js → handlers/api.js} +8 -8
- package/dist/handlers/api.js.map +1 -0
- package/dist/handlers/index.d.ts +2 -0
- package/dist/handlers/index.js +15 -0
- package/dist/handlers/index.js.map +1 -0
- package/dist/{protectRoute.d.ts → handlers/ssr.d.ts} +4 -0
- package/dist/{protectRoute.js → handlers/ssr.js} +11 -13
- package/dist/handlers/ssr.js.map +1 -0
- package/dist/helpers/auth.d.ts +13 -0
- package/dist/helpers/auth.js +26 -0
- package/dist/helpers/auth.js.map +1 -0
- package/dist/helpers/callback.d.ts +8 -0
- package/dist/helpers/callback.js +86 -0
- package/dist/helpers/callback.js.map +1 -0
- package/dist/helpers/error.d.ts +12 -0
- package/dist/helpers/error.js +19 -0
- package/dist/helpers/error.js.map +1 -0
- package/dist/helpers/graph.d.ts +21 -0
- package/dist/helpers/graph.js +77 -0
- package/dist/helpers/graph.js.map +1 -0
- package/dist/helpers/index.d.ts +5 -0
- package/dist/helpers/index.js +18 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/rest.d.ts +21 -0
- package/dist/helpers/rest.js +71 -0
- package/dist/helpers/rest.js.map +1 -0
- package/dist/index.d.ts +2 -4
- package/dist/index.js +2 -4
- package/dist/index.js.map +1 -1
- package/dist/utils/billing.d.ts +0 -5
- package/dist/utils/billing.js +8 -93
- package/dist/utils/billing.js.map +1 -1
- package/dist/utils/constants.d.ts +21 -0
- package/dist/utils/constants.js +97 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/firebase.js +2 -2
- package/dist/utils/firebase.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/shopify.d.ts +0 -9
- package/dist/utils/shopify.js +9 -23
- package/dist/utils/shopify.js.map +1 -1
- package/dist/withShopify.js +0 -1
- package/dist/withShopify.js.map +1 -1
- package/package.json +1 -1
- package/dist/apiHandlers.js.map +0 -1
- package/dist/apiHelpers.d.ts +0 -70
- package/dist/apiHelpers.js +0 -271
- package/dist/apiHelpers.js.map +0 -1
- package/dist/ensureSecurityHeader.d.ts +0 -4
- package/dist/ensureSecurityHeader.js +0 -11
- package/dist/ensureSecurityHeader.js.map +0 -1
- package/dist/protectRoute.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
## [1.3.2-alpha.29](https://github.com/agnostack/next-shopify/compare/v1.3.2-alpha.28...v1.3.2-alpha.29) (2022-11-19)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* file cleanup ([4d7d26a](https://github.com/agnostack/next-shopify/commit/4d7d26a65d5c9d92a89a0f26c13c99af9462bdf3))
|
|
7
|
+
* file cleanup ([dfe8efb](https://github.com/agnostack/next-shopify/commit/dfe8efb34ef8a6ef37ccd38aa6d69c258c14282e))
|
|
8
|
+
|
|
9
|
+
## [1.3.2-alpha.28](https://github.com/agnostack/next-shopify/compare/v1.3.2-alpha.27...v1.3.2-alpha.28) (2022-11-19)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* rename ([f99a48f](https://github.com/agnostack/next-shopify/commit/f99a48f5a064cc5fe12e3492c99dcb18fa62b6c0))
|
|
15
|
+
|
|
1
16
|
## [1.3.2-alpha.27](https://github.com/agnostack/next-shopify/compare/v1.3.2-alpha.26...v1.3.2-alpha.27) (2022-11-18)
|
|
2
17
|
|
|
3
18
|
|
|
File without changes
|
|
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.handleAppUninstalled = exports.handleCallback = exports.handleAuth = exports.handleGraph = exports.handleRest = void 0;
|
|
4
4
|
// NOTE: api routes do NOT work in `next export`
|
|
5
5
|
const shopify_api_1 = require("@shopify/shopify-api");
|
|
6
|
-
const
|
|
7
|
-
const utils_1 = require("
|
|
6
|
+
const helpers_1 = require("../helpers");
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
8
|
const handleRest = (serverRuntimeConfig) => async (req, res, params) => {
|
|
9
9
|
const { PAGE_PATHS } = serverRuntimeConfig;
|
|
10
|
-
const { message, response, headers, statusCode = 302, redirectUrl = `${PAGE_PATHS[utils_1.PAGE_ROUTE_NAMES.ERROR]}?invalid_rest_response`, } = await
|
|
10
|
+
const { message, response, headers, statusCode = 302, redirectUrl = `${PAGE_PATHS[utils_1.PAGE_ROUTE_NAMES.ERROR]}?invalid_rest_response`, } = await helpers_1.restHelper({
|
|
11
11
|
req,
|
|
12
12
|
res,
|
|
13
13
|
params,
|
|
@@ -35,7 +35,7 @@ exports.handleRest = handleRest;
|
|
|
35
35
|
const handleGraph = (serverRuntimeConfig) => async (req, res, params) => {
|
|
36
36
|
var _a, _b;
|
|
37
37
|
const { PAGE_PATHS } = serverRuntimeConfig;
|
|
38
|
-
const { message, response, headers, statusCode = 302, redirectUrl = `${PAGE_PATHS[utils_1.PAGE_ROUTE_NAMES.ERROR]}?invalid_query_response`, } = await
|
|
38
|
+
const { message, response, headers, statusCode = 302, redirectUrl = `${PAGE_PATHS[utils_1.PAGE_ROUTE_NAMES.ERROR]}?invalid_query_response`, } = await helpers_1.graphHelper({
|
|
39
39
|
req,
|
|
40
40
|
res,
|
|
41
41
|
params,
|
|
@@ -56,7 +56,7 @@ exports.handleGraph = handleGraph;
|
|
|
56
56
|
// NOTE: typically handling: "/api/auth"
|
|
57
57
|
const handleAuth = (serverRuntimeConfig) => async (req, res) => {
|
|
58
58
|
const { PAGE_PATHS } = serverRuntimeConfig;
|
|
59
|
-
const { message, statusCode = 302, redirectUrl = `${PAGE_PATHS[utils_1.PAGE_ROUTE_NAMES.ERROR]}?invalid_auth_response`, } = await
|
|
59
|
+
const { message, statusCode = 302, redirectUrl = `${PAGE_PATHS[utils_1.PAGE_ROUTE_NAMES.ERROR]}?invalid_auth_response`, } = await helpers_1.authHelper({ req, res, serverRuntimeConfig });
|
|
60
60
|
if (statusCode >= 300 && statusCode < 400) {
|
|
61
61
|
return res.redirect(statusCode, redirectUrl);
|
|
62
62
|
}
|
|
@@ -66,7 +66,7 @@ exports.handleAuth = handleAuth;
|
|
|
66
66
|
// NOTE: typically handling: "/api/auth/callback"
|
|
67
67
|
const handleCallback = (serverRuntimeConfig) => async (req, res) => {
|
|
68
68
|
const { PAGE_PATHS } = serverRuntimeConfig;
|
|
69
|
-
const { message, statusCode = 302, redirectUrl = `${PAGE_PATHS[utils_1.PAGE_ROUTE_NAMES.ERROR]}?invalid_callback_response`, } = await
|
|
69
|
+
const { message, statusCode = 302, redirectUrl = `${PAGE_PATHS[utils_1.PAGE_ROUTE_NAMES.ERROR]}?invalid_callback_response`, } = await helpers_1.callbackHelper({ req, res, serverRuntimeConfig });
|
|
70
70
|
if (statusCode >= 300 && statusCode < 400) {
|
|
71
71
|
return res.redirect(statusCode, redirectUrl);
|
|
72
72
|
}
|
|
@@ -76,11 +76,11 @@ exports.handleCallback = handleCallback;
|
|
|
76
76
|
// NOTE: typically handling: "/api/webhooks/app/uninstalled"
|
|
77
77
|
const handleAppUninstalled = (serverRuntimeConfig) => async (req, res) => {
|
|
78
78
|
const { PAGE_PATHS } = serverRuntimeConfig;
|
|
79
|
-
const { message, statusCode = 302, redirectUrl = `${PAGE_PATHS[utils_1.PAGE_ROUTE_NAMES.ERROR]}?invalid_uninstall_response`, } = await
|
|
79
|
+
const { message, statusCode = 302, redirectUrl = `${PAGE_PATHS[utils_1.PAGE_ROUTE_NAMES.ERROR]}?invalid_uninstall_response`, } = await helpers_1.uninstallHelper({ req, serverRuntimeConfig });
|
|
80
80
|
if (statusCode >= 300 && statusCode < 400) {
|
|
81
81
|
return res.redirect(statusCode, redirectUrl);
|
|
82
82
|
}
|
|
83
83
|
return res.status(statusCode).send(message);
|
|
84
84
|
};
|
|
85
85
|
exports.handleAppUninstalled = handleAppUninstalled;
|
|
86
|
-
//# sourceMappingURL=
|
|
86
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/handlers/api.js"],"names":[],"mappings":";;;AAAA,gDAAgD;AAChD,sDAA+C;AAE/C,wCAMmB;AACnB,oCAAyD;AAElD,MAAM,UAAU,GAAG,CAAC,mBAAmB,EAAE,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE;IAC5E,MAAM,EAAE,UAAU,EAAE,GAAG,mBAAmB,CAAA;IAC1C,MAAM,EACJ,OAAO,EACP,QAAQ,EACR,OAAO,EACP,UAAU,GAAG,GAAG,EAChB,WAAW,GAAG,GAAG,UAAU,CAAC,wBAAgB,CAAC,KAAK,CAAC,wBAAwB,GAC5E,GAAG,MAAM,oBAAU,CAAC;QACnB,GAAG;QACH,GAAG;QACH,MAAM;QACN,mBAAmB;KACpB,CAAC,CAAA;IAEF,MAAM,CAAC,OAAO,CAAC,oBAAY,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QAC7D,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;IAC3B,CAAC,CAAC,CAAA;IAEF,6BAA6B;IAC7B,IAAI,UAAU,IAAI,GAAG,IAAI,UAAU,GAAG,GAAG,EAAE;QACzC,OAAO,GAAG,CAAC,QAAQ,CAAC,UAAU,EAAE,WAAW,CAAC,CAAA;KAC7C;IAED,IAAI,CAAC,QAAQ,EAAE;QACb,OAAO,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;KAC5C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(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("./api"), exports);
|
|
14
|
+
__exportStar(require("./ssr"), exports);
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/handlers/index.js"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAAqB;AACrB,wCAAqB"}
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.protectRoute = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
3
|
+
exports.protectRoute = exports.ensureSecurityHeader = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const ensureSecurityHeader = ({ res, query } = {}) => {
|
|
6
|
+
const headerValue = (query === null || query === void 0 ? void 0 : query.shop)
|
|
7
|
+
? `frame-ancestors self https://admin.shopify.com https://${query === null || query === void 0 ? void 0 : query.shop};`
|
|
8
|
+
: "frame-ancestors 'none';";
|
|
9
|
+
res.setHeader('Content-Security-Policy', headerValue);
|
|
10
|
+
};
|
|
11
|
+
exports.ensureSecurityHeader = ensureSecurityHeader;
|
|
6
12
|
const protectRoute = (props) => async ({ req, res, query, locale } = {}, data) => {
|
|
7
13
|
var _a, _b, _c, _d, _e, _f;
|
|
8
|
-
console.log(`>>> ~~~~~~~~~~~ PROTECTROUTE ~~~~~~~~~~~`);
|
|
9
14
|
const { PAGE_PATHS } = props;
|
|
10
15
|
const shop = (_a = query === null || query === void 0 ? void 0 : query.shop) !== null && _a !== void 0 ? _a : (_b = req.query) === null || _b === void 0 ? void 0 : _b.shop;
|
|
11
|
-
console.log(`>>> ~ protectRoute ~ req.query`, req.query);
|
|
12
16
|
const embedded = (_c = query === null || query === void 0 ? void 0 : query.embedded) !== null && _c !== void 0 ? _c : (_d = req.query) === null || _d === void 0 ? void 0 : _d.embedded;
|
|
13
|
-
|
|
14
|
-
ensureSecurityHeader_1.ensureSecurityHeader({ res, query });
|
|
17
|
+
exports.ensureSecurityHeader({ res, query });
|
|
15
18
|
if (!shop) {
|
|
16
19
|
const noshopurl = `${PAGE_PATHS[utils_1.PAGE_ROUTE_NAMES.ERROR]}?code=no_shop_provided&type=protectRoute`;
|
|
17
|
-
console.log(`>>> ~ protectRoute ~ noshopurl`, noshopurl);
|
|
18
20
|
return {
|
|
19
21
|
redirect: {
|
|
20
22
|
destination: noshopurl,
|
|
@@ -24,14 +26,12 @@ const protectRoute = (props) => async ({ req, res, query, locale } = {}, data) =
|
|
|
24
26
|
}
|
|
25
27
|
const shopify = utils_1.getInitializedShopify(props, shop);
|
|
26
28
|
const shopSessions = await ((_f = (_e = shopify.Context.SESSION_STORAGE) === null || _e === void 0 ? void 0 : _e.findSessionsByShop) === null || _f === void 0 ? void 0 : _f.call(_e, shop));
|
|
27
|
-
console.log(`>>> ~ protectRoute ~ shopSessions length`, utils_1.ensureArray(shopSessions).length);
|
|
28
29
|
if (utils_1.arrayEmpty(shopSessions)) {
|
|
29
30
|
const emptySessionUrl = utils_1.getRedirectUrl(props, {
|
|
30
31
|
req,
|
|
31
32
|
res,
|
|
32
33
|
query,
|
|
33
34
|
});
|
|
34
|
-
console.log(`>>> ~ protectRoute ~ emptySessionUrl`, emptySessionUrl);
|
|
35
35
|
return {
|
|
36
36
|
redirect: {
|
|
37
37
|
destination: emptySessionUrl,
|
|
@@ -41,7 +41,6 @@ const protectRoute = (props) => async ({ req, res, query, locale } = {}, data) =
|
|
|
41
41
|
}
|
|
42
42
|
if (embedded !== '1') {
|
|
43
43
|
const embeddedappUrl = shopify.Utils.getEmbeddedAppUrl(req);
|
|
44
|
-
console.log(`>>> ~ protectRoute ~ embeddedappUrl`, embeddedappUrl);
|
|
45
44
|
return {
|
|
46
45
|
redirect: {
|
|
47
46
|
destination: embeddedappUrl,
|
|
@@ -49,10 +48,9 @@ const protectRoute = (props) => async ({ req, res, query, locale } = {}, data) =
|
|
|
49
48
|
},
|
|
50
49
|
};
|
|
51
50
|
}
|
|
52
|
-
console.log(`>>> ~ protectRoute ~ PROCEED`);
|
|
53
51
|
return {
|
|
54
52
|
props: Object.assign({ locale }, data),
|
|
55
53
|
};
|
|
56
54
|
};
|
|
57
55
|
exports.protectRoute = protectRoute;
|
|
58
|
-
//# sourceMappingURL=
|
|
56
|
+
//# sourceMappingURL=ssr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ssr.js","sourceRoot":"","sources":["../../src/handlers/ssr.js"],"names":[],"mappings":";;;AAAA,oCAKiB;AAEV,MAAM,oBAAoB,GAAG,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE;IAC1D,MAAM,WAAW,GAAG,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI;QAC7B,CAAC,CAAC,0DAA0D,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,GAAG;QAC1E,CAAC,CAAC,yBAAyB,CAAA;IAC7B,GAAG,CAAC,SAAS,CAAC,yBAAyB,EAAE,WAAW,CAAC,CAAA;AACvD,CAAC,CAAA;AALY,QAAA,oBAAoB,wBAKhC;AAEM,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,E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AW,EAAE,cAAc;gBAC3B,SAAS,EAAE,KAAK;aACjB;SACF,CAAA;KACF;IAED,OAAO;QACL,KAAK,kBACH,MAAM,IACH,IAAI,CACR;KACF,CAAA;AACH,CAAC,CAAA;AApDY,QAAA,YAAY,gBAoDxB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function authHelper({ req, res, serverRuntimeConfig }: {
|
|
2
|
+
req: any;
|
|
3
|
+
res: any;
|
|
4
|
+
serverRuntimeConfig: any;
|
|
5
|
+
}): Promise<{
|
|
6
|
+
statusCode: number;
|
|
7
|
+
redirectUrl: string;
|
|
8
|
+
message?: undefined;
|
|
9
|
+
} | {
|
|
10
|
+
statusCode: number;
|
|
11
|
+
message: string;
|
|
12
|
+
redirectUrl?: undefined;
|
|
13
|
+
}>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.authHelper = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const authHelper = async ({ req, res, serverRuntimeConfig }) => {
|
|
6
|
+
try {
|
|
7
|
+
const authredurectUrl = utils_1.getRedirectUrl(serverRuntimeConfig, {
|
|
8
|
+
req,
|
|
9
|
+
res,
|
|
10
|
+
});
|
|
11
|
+
return {
|
|
12
|
+
statusCode: 302,
|
|
13
|
+
redirectUrl: authredurectUrl,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
const errorMessage = 'Error handling auth route';
|
|
18
|
+
console.error(errorMessage, error);
|
|
19
|
+
return {
|
|
20
|
+
statusCode: 500,
|
|
21
|
+
message: errorMessage,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
exports.authHelper = authHelper;
|
|
26
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/helpers/auth.js"],"names":[],"mappings":";;;AAAA,oCAAyC;AAElC,MAAM,UAAU,GAAG,KAAK,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,mBAAmB,EAAE,EAAE,EAAE;IACpE,IAAI;QACF,MAAM,eAAe,GAAG,sBAAc,CAAC,mBAAmB,EAAE;YAC1D,GAAG;YACH,GAAG;SACJ,CAAC,CAAA;QAEF,OAAO;YACL,UAAU,EAAE,GAAG;YACf,WAAW,EAAE,eAAe;SAC7B,CAAA;KACF;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,YAAY,GAAG,2BAA2B,CAAA;QAChD,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;AApBY,QAAA,UAAU,cAoBtB"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.callbackHelper = void 0;
|
|
7
|
+
const shopify_api_1 = require("@shopify/shopify-api");
|
|
8
|
+
const cookies_1 = __importDefault(require("cookies"));
|
|
9
|
+
const utils_1 = require("../utils");
|
|
10
|
+
const callbackHelper = async ({ req, res, serverRuntimeConfig }) => {
|
|
11
|
+
var _a;
|
|
12
|
+
const { PAGE_PATHS, APP_WEBHOOKS, APP_CONFIG, PAYMENT_CONFIG } = serverRuntimeConfig;
|
|
13
|
+
const { shop, host, state } = req.query;
|
|
14
|
+
if (!shop || !host) {
|
|
15
|
+
return {
|
|
16
|
+
statusCode: 303,
|
|
17
|
+
redirectUrl: `${PAGE_PATHS[utils_1.PAGE_ROUTE_NAMES.ERROR]}?code=invalid_callback`,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
let redirectUrl;
|
|
21
|
+
try {
|
|
22
|
+
const shopify = utils_1.getInitializedShopify(serverRuntimeConfig, shop);
|
|
23
|
+
const session = await shopify.Auth.validateAuthCallback(req, res, req.query);
|
|
24
|
+
await utils_1.registerWebhooks(serverRuntimeConfig, APP_WEBHOOKS, session);
|
|
25
|
+
// TODO: explore objectToQuerystring
|
|
26
|
+
const embeddedURL = shopify_api_1.Shopify.Utils.getEmbeddedAppUrl(req);
|
|
27
|
+
redirectUrl = `${embeddedURL}?${new URLSearchParams(req.query).toString()}`;
|
|
28
|
+
if (PAYMENT_CONFIG === null || PAYMENT_CONFIG === void 0 ? void 0 : PAYMENT_CONFIG.required) {
|
|
29
|
+
const billingManager = new utils_1.BillingManager(session, serverRuntimeConfig);
|
|
30
|
+
const confirmationUrl = await billingManager.ensureBilling();
|
|
31
|
+
if (utils_1.stringNotEmpty(confirmationUrl)) {
|
|
32
|
+
redirectUrl = confirmationUrl;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const cookies = new cookies_1.default(req, res, {
|
|
36
|
+
keys: [APP_CONFIG.API_SECRET_KEY],
|
|
37
|
+
secure: true,
|
|
38
|
+
});
|
|
39
|
+
cookies.set(shopify_api_1.Shopify.Auth.STATE_COOKIE_NAME, state, {
|
|
40
|
+
sameSite: 'none',
|
|
41
|
+
expires: new Date(Date.now()),
|
|
42
|
+
signed: true,
|
|
43
|
+
secure: true,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
const errorMessage = 'Error handling callback route';
|
|
48
|
+
switch (true) {
|
|
49
|
+
case error instanceof shopify_api_1.Shopify.Errors.CookieNotFound:
|
|
50
|
+
case error instanceof shopify_api_1.Shopify.Errors.SessionNotFound: {
|
|
51
|
+
console.error(`${errorMessage}. Cookie/Session Error`, error);
|
|
52
|
+
redirectUrl = utils_1.getRedirectUrl(serverRuntimeConfig, {
|
|
53
|
+
req,
|
|
54
|
+
res,
|
|
55
|
+
});
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
case error instanceof shopify_api_1.Shopify.Errors.BillingError: {
|
|
59
|
+
console.error(`${errorMessage}. Billing Error ${error.message}`, error.errorData);
|
|
60
|
+
redirectUrl = '/error?code=billing_error';
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
case error instanceof shopify_api_1.Shopify.Errors.GraphqlQueryError: {
|
|
64
|
+
const errorMessages = utils_1.ensureArray((_a = error.response) === null || _a === void 0 ? void 0 : _a.errors).map(({ message }) => utils_1.ensureString(message));
|
|
65
|
+
console.error(`${errorMessage}. GraphqlQuery Error ${errorMessages.join('. ')}`);
|
|
66
|
+
redirectUrl = '/error?code=query_error';
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
case error instanceof shopify_api_1.Shopify.Errors.InvalidOAuthError: {
|
|
70
|
+
console.error(`${errorMessage}. InvalidOAuth Error`, error);
|
|
71
|
+
redirectUrl = '/error?code=oauth_error';
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
default: {
|
|
75
|
+
console.error(errorMessage, error);
|
|
76
|
+
redirectUrl = '/error?code=callback_error';
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
statusCode: 302,
|
|
82
|
+
redirectUrl,
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
exports.callbackHelper = callbackHelper;
|
|
86
|
+
//# sourceMappingURL=callback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callback.js","sourceRoot":"","sources":["../../src/helpers/callback.js"],"names":[],"mappings":";;;;;;AAAA,sDAA8C;AAC9C,sDAA6B;AAE7B,oCASiB;AAEV,MAAM,cAAc,GAAG,KAAK,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,mBAAmB,EAAE,EAAE,EAAE;;IACxE,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,G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,WAAW,GAAG,yBAAyB,CAAA;gBACvC,MAAK;aACN;YAED,KAAK,KAAK,YAAY,qBAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;gBACtD,OAAO,CAAC,KAAK,CAAC,GAAG,YAAY,sBAAsB,EAAE,KAAK,CAAC,CAAA;gBAC3D,WAAW,GAAG,yBAAyB,CAAA;gBACvC,MAAK;aACN;YAED,OAAO,CAAC,CAAC;gBACP,OAAO,CAAC,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,CAAA;gBAClC,WAAW,GAAG,4BAA4B,CAAA;aAC3C;SACF;KACF;IAED,OAAO;QACL,UAAU,EAAE,GAAG;QACf,WAAW;KACZ,CAAA;AACH,CAAC,CAAA;AAzFY,QAAA,cAAc,kBAyF1B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function authenticationErrorHelper({ error, shop, serverRuntimeConfig }: {
|
|
2
|
+
error: any;
|
|
3
|
+
shop: any;
|
|
4
|
+
serverRuntimeConfig: any;
|
|
5
|
+
}): {
|
|
6
|
+
statusCode: number;
|
|
7
|
+
message: any;
|
|
8
|
+
headers: {
|
|
9
|
+
'X-Shopify-API-Request-Failure-Reauthorize': string;
|
|
10
|
+
'X-Shopify-API-Request-Failure-Reauthorize-Url': any;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.authenticationErrorHelper = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const authenticationErrorHelper = ({ error, shop, serverRuntimeConfig }) => {
|
|
6
|
+
const { message, data } = error;
|
|
7
|
+
const { API_URLS } = serverRuntimeConfig;
|
|
8
|
+
const reauthorizationUrl = (data === null || data === void 0 ? void 0 : data.redirectUrl) || `${API_URLS[utils_1.API_ROUTE_NAMES.AUTH]}?shop=${shop}`;
|
|
9
|
+
return {
|
|
10
|
+
statusCode: 403,
|
|
11
|
+
message,
|
|
12
|
+
headers: {
|
|
13
|
+
'X-Shopify-API-Request-Failure-Reauthorize': '1',
|
|
14
|
+
'X-Shopify-API-Request-Failure-Reauthorize-Url': reauthorizationUrl,
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
exports.authenticationErrorHelper = authenticationErrorHelper;
|
|
19
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/helpers/error.js"],"names":[],"mappings":";;;AAAA,oCAA0C;AAEnC,MAAM,yBAAyB,GAAG,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,mBAAmB,EAAE,EAAE,EAAE;IAChF,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,KAAK,CAAA;IAC/B,MAAM,EAAE,QAAQ,EAAE,GAAG,mBAAmB,CAAA;IACxC,MAAM,kBAAkB,GAAG,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,KAAI,GAAG,QAAQ,CAAC,uBAAe,CAAC,IAAI,CAAC,SAAS,IAAI,EAAE,CAAA;IAEhG,OAAO;QACL,UAAU,EAAE,GAAG;QACf,OAAO;QACP,OAAO,EAAE;YACP,2CAA2C,EAAE,GAAG;YAChD,+CAA+C,EAAE,kBAAkB;SACpE;KACF,CAAA;AACH,CAAC,CAAA;AAbY,QAAA,yBAAyB,6BAarC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export function graphHelper({ 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: import("@shopify/shopify-api").RequestReturn<unknown>;
|
|
20
|
+
message?: undefined;
|
|
21
|
+
}>;
|
|
@@ -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":";;;;;;;;;;;;;;AAAA,sDAA8C;AAE9C,oCAOiB;AACjB,mCAAmD;AAE5C,MAAM,WAAW,GAAG,KAAK,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB,EAAE,EAAE,EAAE;;IACtF,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,GAAG,CAAA;IACnC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAA;IAC7B,MAAM,KAAoD,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,EAAjE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,OAA6B,EAAxB,MAAM,cAA/C,iBAAiD,CAAgB,CAAA;IACvE,IAAI,KAAK,GAAG,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,MAAM,CAAA;IAChC,MAAM,IAAI,GAAG,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,IAAI,CAAC,KAAK,CAAC,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,EAAE,CAAC,CAAA;IAEhD,IAAI,cAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE;QAC3B,KAAK,GAAG,2BAAmB,CAAC,KAAK,CAAC,CAAA;KACnC;IAED,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE;QAClB,OAAO;YACL,UAAU,EAAE,GAAG;YACf,OAAO,EAAE,mBAAmB;S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AAE,OAAO,EAAE,EAAE,EAAE,CAAC,oBAAY,CAAC,OAAO,CAAC,CAAC,CAAA;gBACrG,OAAO,CAAC,KAAK,CAAC,GAAG,YAAY,KAAK,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;gBAC7D,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,WAAW,eAyEvB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
//# 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"}
|
|
@@ -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,EAAE,UAAU,EACjB,IAAI,EAAE,SAAS,EACf,IAAI,OAEW,EADZ,MAAM,cALL,mCAML,CAAgB,CAAA;IACjB,IAAI,KAAK,GAAG,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,MAAM,CAAA;IAChC,MAAM,IAAI,GAAG,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,KAAK,CAAA;IAC/B,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