@agnostack/next-shopify 1.13.8 → 1.13.9-beta.1
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 +60 -32
- package/dist/lib/handlers/api/graph.d.ts.map +1 -1
- package/dist/lib/handlers/api/graph.js +84 -79
- package/dist/lib/handlers/api/graph.js.map +1 -1
- package/dist/lib/handlers/api/proxy.d.ts.map +1 -1
- package/dist/lib/handlers/api/proxy.js +115 -156
- package/dist/lib/handlers/api/proxy.js.map +1 -1
- package/dist/lib/handlers/api/rest.d.ts.map +1 -1
- package/dist/lib/handlers/api/rest.js +70 -65
- package/dist/lib/handlers/api/rest.js.map +1 -1
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +5 -4
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/utils/index.d.ts +1 -0
- package/dist/lib/utils/index.js +1 -0
- package/dist/lib/utils/index.js.map +1 -1
- package/dist/lib/utils/session.d.ts.map +1 -1
- package/dist/lib/utils/session.js +2 -2
- package/dist/lib/utils/session.js.map +1 -1
- package/dist/lib/utils/verification.d.ts +2 -0
- package/dist/lib/utils/verification.d.ts.map +1 -0
- package/dist/lib/utils/verification.js +69 -0
- package/dist/lib/utils/verification.js.map +1 -0
- package/dist/react/hooks/index.d.ts +2 -0
- package/dist/react/hooks/index.d.ts.map +1 -0
- package/dist/react/hooks/index.js +5 -0
- package/dist/react/hooks/index.js.map +1 -0
- package/dist/react/hooks/useVerification.d.ts +9 -0
- package/dist/react/hooks/useVerification.d.ts.map +1 -0
- package/dist/react/hooks/useVerification.js +63 -0
- package/dist/react/hooks/useVerification.js.map +1 -0
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +5 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/types.d.ts +1 -0
- package/dist/react/types.d.ts.map +1 -0
- package/dist/react/types.js +1 -0
- package/dist/react/types.js.map +1 -0
- package/dist/shared/datetime.d.ts +96 -0
- package/dist/shared/datetime.d.ts.map +1 -0
- package/dist/shared/datetime.js +285 -0
- package/dist/shared/datetime.js.map +1 -0
- package/dist/shared/display.d.ts +88 -23
- package/dist/shared/display.d.ts.map +1 -1
- package/dist/shared/display.js +409 -104
- package/dist/shared/display.js.map +1 -1
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +1 -0
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/shopify.d.ts +0 -6
- package/dist/shared/shopify.d.ts.map +1 -1
- package/dist/shared/shopify.js +1 -28
- package/dist/shared/shopify.js.map +1 -1
- package/package.json +6 -1
|
@@ -5,7 +5,6 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
6
6
|
const nextjs_cors_1 = tslib_1.__importDefault(require("nextjs-cors"));
|
|
7
7
|
const http_proxy_1 = tslib_1.__importDefault(require("http-proxy"));
|
|
8
|
-
const raw_body_1 = tslib_1.__importDefault(require("raw-body"));
|
|
9
8
|
const node_http_proxy_json_1 = tslib_1.__importDefault(require("node-http-proxy-json"));
|
|
10
9
|
const utils_1 = require("../../utils");
|
|
11
10
|
const shared_1 = require("../../../shared");
|
|
@@ -14,171 +13,131 @@ const verifyAppProxySignature = (signature, verifiable, hmacSecret) => {
|
|
|
14
13
|
const hmac = (0, utils_1.generateHMAC)((0, shared_1.objectToSortedString)(verifiable), hmacSecret);
|
|
15
14
|
return (0, utils_1.compareHashes)(signature, hmac);
|
|
16
15
|
};
|
|
17
|
-
const handleProxy = (serverRuntimeConfig, config) =>
|
|
18
|
-
var _a, _b;
|
|
16
|
+
const handleProxy = (serverRuntimeConfig, config) => {
|
|
19
17
|
const { generateReplacements } = config !== null && config !== void 0 ? config : {};
|
|
20
|
-
const {
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
(keyPairs === null || keyPairs === void 0 ? void 0 : keyPairs.shared) &&
|
|
36
|
-
(authProtocol === 'HMAC-SHA256'));
|
|
37
|
-
let verificationKeys;
|
|
38
|
-
// NOTE raw request body is required for shopify's validation
|
|
39
|
-
const _rawBody = yield (0, raw_body_1.default)(req);
|
|
40
|
-
const rawBody = _rawBody.toString();
|
|
41
|
-
const parsedBody = JSON.parse(rawBody || '{}'); // NOTE: parsedBody should be encrypted when isVerifiable
|
|
42
|
-
let decryptedBody = parsedBody;
|
|
43
|
-
// NOTE: GET requests are not always sending along origin
|
|
44
|
-
if ((0, shared_1.stringEmpty)(origin)) {
|
|
45
|
-
req.headers = Object.assign(Object.assign({}, req.headers), { origin: proxyOrigin || forwardHost });
|
|
46
|
-
}
|
|
47
|
-
const _d = (_b = req.query) !== null && _b !== void 0 ? _b : {}, { signature, proxyEncoded } = _d, verifiable = tslib_1.__rest(_d, ["signature", "proxyEncoded"]);
|
|
48
|
-
const { shop: _shop, host, timestamp, path_prefix } = verifiable;
|
|
49
|
-
const shop = _shop || shopHeader;
|
|
50
|
-
yield (0, nextjs_cors_1.default)(req, res, {
|
|
51
|
-
methods: ['PUT', 'PATCH', 'POST', 'DELETE'],
|
|
52
|
-
origin: (origin, callback) => {
|
|
53
|
-
const isSafelisted = (0, shared_1.matchHostname)(origin, [
|
|
54
|
-
...ORIGIN_SAFELIST,
|
|
55
|
-
'cdn.shopify.com' // NOTE: this is the domain for checkout UI extensions
|
|
56
|
-
]);
|
|
57
|
-
if (isSafelisted) {
|
|
58
|
-
return callback(null, true);
|
|
59
|
-
}
|
|
60
|
-
return callback(new Error('Invalid CORS origin'));
|
|
61
|
-
},
|
|
62
|
-
optionsSuccessStatus: 200, // some legacy browsers (IE11, various SmartTVs) choke on 204
|
|
63
|
-
});
|
|
64
|
-
const { target: targetParam } = params !== null && params !== void 0 ? params : {};
|
|
65
|
-
// eslint-disable-next-line max-len
|
|
66
|
-
const _targetUrl = ((0, shared_1.stringEmpty)(targetParam) || targetParam.startsWith('http')) ? targetParam : `${APP_BASE_URL}/${(0, shared_1.removeLeadingSlash)(targetParam)}`;
|
|
67
|
-
const { origin: target, hostname, pathname, search } = (0, shared_1.stringNotEmpty)(_targetUrl) ? new URL(_targetUrl) : {};
|
|
68
|
-
targetPath = [pathname, search].filter(shared_1.stringNotEmpty).join('');
|
|
69
|
-
const safelistedTarget = (0, shared_1.matchHostname)(hostname, Object.assign({ [new URL(APP_BASE_URL).hostname]: {
|
|
70
|
-
// HMMM: can we generate our own session token (or use the current one) so as to not have to tell handleGraph/Rest to behave as offline?
|
|
71
|
-
// headers: {
|
|
72
|
-
// Authorization: 'Bearer {{setting.zendesk.token}}',
|
|
73
|
-
// },
|
|
74
|
-
params: {
|
|
75
|
-
shop,
|
|
76
|
-
host,
|
|
77
|
-
},
|
|
78
|
-
} }, TARGET_SAFELIST));
|
|
79
|
-
if ((0, shared_1.stringEmpty)(targetPath) || (safelistedTarget == undefined)) {
|
|
80
|
-
return res.status(407).json({ message: 'Unproxyable target' });
|
|
81
|
-
}
|
|
82
|
-
if (!apiKey || !shop || !host || !extensionPoint || !signature || !proxyEncoded) {
|
|
83
|
-
return res.status(400).json({ message: 'Invalid or missing headers', extensionPoint });
|
|
84
|
-
}
|
|
85
|
-
const isShopifyOriginOrRelative = (0, shared_1.stringNotEmpty)((0, shared_1.ensureString)(path_prefix).startsWith('http')
|
|
86
|
-
? (0, shared_1.sanitizeShop)(new URL(path_prefix).hostname)
|
|
87
|
-
: path_prefix);
|
|
88
|
-
// TODO: once Shopify fixes CORS issue when origin is cdn.shopify.com, update this!
|
|
89
|
-
if (!verifyAppProxySignature(signature, verifiable, isShopifyOriginOrRelative ? APP_CONFIG.apiSecretKey : timestamp)) {
|
|
90
|
-
return res.status(403).json({ message: 'Invalid signature' });
|
|
91
|
-
}
|
|
92
|
-
// TODO: clean up targetParam.startsWith??
|
|
93
|
-
if (!targetParam.startsWith(API_PATHS[shared_1.API_ROUTE_NAMES.SESSION_TOKEN])) {
|
|
94
|
-
const _getVerifiedSessionData = (0, utils_1.getVerifiedSessionData)(serverRuntimeConfig);
|
|
95
|
-
if (!_getVerifiedSessionData(sessionToken, { shop, host }).catch((_error) => {
|
|
96
|
-
if (_error instanceof shared_1.ShopifySessionInvalidError) {
|
|
97
|
-
return res.status(403).json({ message: _error.message });
|
|
98
|
-
}
|
|
99
|
-
throw _error;
|
|
100
|
-
})) {
|
|
101
|
-
return res.status(403).json({ message: 'Unverified signature' });
|
|
18
|
+
const { API_PATHS, APP_CONFIG, APP_BASE_URL, TARGET_SAFELIST, ORIGIN_SAFELIST, } = serverRuntimeConfig;
|
|
19
|
+
const _getVerifiedBody = (0, utils_1.getVerifiedBody)(serverRuntimeConfig);
|
|
20
|
+
return (req, res, params) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
var _a, _b;
|
|
22
|
+
const _c = (_a = req.headers) !== null && _a !== void 0 ? _a : {}, { origin, 'x-forwarded-for': _forwardFor, 'x-forwarded-proto': _forwardProto, 'x-forwarded-host': forwardHost, 'x-proxy-origin': proxyOrigin } = _c, _headers = tslib_1.__rest(_c, ["origin", 'x-forwarded-for', 'x-forwarded-proto', 'x-forwarded-host', 'x-proxy-origin']);
|
|
23
|
+
const { 'x-extension-session': sessionToken, 'x-extension-point': extensionPoint, 'x-shop-domain': shopDomainHeader, 'x-shopify-shop-domain': shopifyShopDomainHeader, 'x-shopify-shop': shopHeader = shopifyShopDomainHeader !== null && shopifyShopDomainHeader !== void 0 ? shopifyShopDomainHeader : shopDomainHeader, 'x-shopify-app-id': shopifyAppId, 'x-app-id': appId = shopifyAppId,
|
|
24
|
+
// 'x-shopify-app-installation-id': shopifyAppInstallationId,
|
|
25
|
+
// 'x-app-installation-id': appInstallationId = shopifyAppInstallationId, // TODO: pass along installationId??
|
|
26
|
+
// TODO: pass along providerSetId???
|
|
27
|
+
} = _headers;
|
|
28
|
+
let targetPath;
|
|
29
|
+
try {
|
|
30
|
+
// NOTE: GET requests are not always sending along origin
|
|
31
|
+
if ((0, shared_1.stringEmpty)(origin)) {
|
|
32
|
+
req.headers = Object.assign(Object.assign({}, req.headers), { origin: proxyOrigin || forwardHost });
|
|
102
33
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
verificationKeys = yield shared_1.subtle.getVerificationKeys({
|
|
120
|
-
publicKey: ephemeralPublicKey,
|
|
121
|
-
privateKey: keyPairs.shared.privateKey,
|
|
34
|
+
const _d = (_b = req.query) !== null && _b !== void 0 ? _b : {}, { signature, proxyEncoded } = _d, verifiable = tslib_1.__rest(_d, ["signature", "proxyEncoded"]);
|
|
35
|
+
const { shop: _shop, host, timestamp, path_prefix } = verifiable;
|
|
36
|
+
const shop = _shop || shopHeader;
|
|
37
|
+
yield (0, nextjs_cors_1.default)(req, res, {
|
|
38
|
+
methods: ['PUT', 'PATCH', 'POST', 'DELETE'],
|
|
39
|
+
origin: (origin, callback) => {
|
|
40
|
+
const isSafelisted = (0, shared_1.matchHostname)(origin, [
|
|
41
|
+
...ORIGIN_SAFELIST,
|
|
42
|
+
'cdn.shopify.com' // NOTE: this is the domain for checkout UI extensions
|
|
43
|
+
]);
|
|
44
|
+
if (isSafelisted) {
|
|
45
|
+
return callback(null, true);
|
|
46
|
+
}
|
|
47
|
+
return callback(new Error('Invalid CORS origin'));
|
|
48
|
+
},
|
|
49
|
+
optionsSuccessStatus: 200, // some legacy browsers (IE11, various SmartTVs) choke on 204
|
|
122
50
|
});
|
|
123
|
-
|
|
124
|
-
|
|
51
|
+
const { target: targetParam } = params !== null && params !== void 0 ? params : {};
|
|
52
|
+
// eslint-disable-next-line max-len
|
|
53
|
+
const _targetUrl = ((0, shared_1.stringEmpty)(targetParam) || targetParam.startsWith('http')) ? targetParam : `${APP_BASE_URL}/${(0, shared_1.removeLeadingSlash)(targetParam)}`;
|
|
54
|
+
const { origin: target, hostname, pathname, search } = (0, shared_1.stringNotEmpty)(_targetUrl) ? new URL(_targetUrl) : {};
|
|
55
|
+
targetPath = [pathname, search].filter(shared_1.stringNotEmpty).join('');
|
|
56
|
+
const safelistedTarget = (0, shared_1.matchHostname)(hostname, Object.assign({ [new URL(APP_BASE_URL).hostname]: {
|
|
57
|
+
// HMMM: can we generate our own session token (or use the current one) so as to not have to tell handleGraph/Rest to behave as offline?
|
|
58
|
+
// headers: {
|
|
59
|
+
// Authorization: 'Bearer {{setting.zendesk.token}}',
|
|
60
|
+
// },
|
|
61
|
+
params: {
|
|
62
|
+
shop,
|
|
63
|
+
host,
|
|
64
|
+
},
|
|
65
|
+
} }, TARGET_SAFELIST));
|
|
66
|
+
if ((0, shared_1.stringEmpty)(targetPath) || (safelistedTarget == undefined)) {
|
|
67
|
+
return res.status(407).json({ message: 'Unproxyable target' });
|
|
125
68
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
if (!isValid) {
|
|
129
|
-
return res.status(412).json({ message: 'Invalid or missing verification' });
|
|
69
|
+
if (!shop || !host || !extensionPoint || !signature || !proxyEncoded) {
|
|
70
|
+
return res.status(400).json({ message: 'Invalid or missing headers', extensionPoint });
|
|
130
71
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
72
|
+
const isShopifyOriginOrRelative = (0, shared_1.stringNotEmpty)((0, shared_1.ensureString)(path_prefix).startsWith('http')
|
|
73
|
+
? (0, shared_1.sanitizeShop)(new URL(path_prefix).hostname)
|
|
74
|
+
: path_prefix);
|
|
75
|
+
// TODO: once Shopify fixes CORS issue when origin is cdn.shopify.com, update this!
|
|
76
|
+
if (!verifyAppProxySignature(signature, verifiable, isShopifyOriginOrRelative ? APP_CONFIG.apiSecretKey : timestamp)) {
|
|
77
|
+
return res.status(403).json({ message: 'Invalid signature' });
|
|
134
78
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
req.url = targetPath;
|
|
146
|
-
if (headers) {
|
|
147
|
-
req.headers = headers;
|
|
148
|
-
}
|
|
149
|
-
proxy.on('proxyReq', (proxyReq, proxyReqRequest, proxyReqResponse, options) => {
|
|
150
|
-
if ((0, shared_1.objectNotEmpty)(decryptedBody)) {
|
|
151
|
-
const bodyData = JSON.stringify(decryptedBody);
|
|
152
|
-
proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));
|
|
153
|
-
proxyReq.write(bodyData);
|
|
79
|
+
// TODO: clean up targetParam.startsWith??
|
|
80
|
+
if (!targetParam.startsWith(API_PATHS[shared_1.API_ROUTE_NAMES.SESSION_TOKEN])) {
|
|
81
|
+
const _getVerifiedSessionData = (0, utils_1.getVerifiedSessionData)(serverRuntimeConfig);
|
|
82
|
+
if (!_getVerifiedSessionData(sessionToken, { shop, host }).catch((_error) => {
|
|
83
|
+
if (_error instanceof shared_1.ShopifySessionInvalidError) {
|
|
84
|
+
return res.status(403).json({ message: _error.message });
|
|
85
|
+
}
|
|
86
|
+
throw _error;
|
|
87
|
+
})) {
|
|
88
|
+
return res.status(403).json({ message: 'Unverified signature' });
|
|
154
89
|
}
|
|
90
|
+
}
|
|
91
|
+
const { headers: targetHeaders, params: targetParams } = (0, shared_1.ensureObject)(safelistedTarget);
|
|
92
|
+
if ((0, shared_1.objectNotEmpty)(targetParams)) {
|
|
93
|
+
targetPath = (0, shared_1.appendQuery)(targetPath, new URLSearchParams(targetParams).toString());
|
|
94
|
+
}
|
|
95
|
+
const [requestBody, processResponse] = yield _getVerifiedBody(req, res, targetPath);
|
|
96
|
+
console.log(`>>> > handleProxy > requestBody, processResponse:`, requestBody, processResponse);
|
|
97
|
+
const _prepareHeaders = (0, utils_1.prepareHeaders)(serverRuntimeConfig);
|
|
98
|
+
const headers = yield _prepareHeaders({
|
|
99
|
+
generateReplacements,
|
|
100
|
+
shop,
|
|
101
|
+
appId,
|
|
102
|
+
headers: Object.assign(Object.assign({}, _headers), targetHeaders),
|
|
155
103
|
});
|
|
156
|
-
proxy
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
104
|
+
const proxy = http_proxy_1.default.createProxy();
|
|
105
|
+
return new Promise((resolve, reject) => {
|
|
106
|
+
req.url = targetPath;
|
|
107
|
+
if (headers) {
|
|
108
|
+
req.headers = headers;
|
|
109
|
+
}
|
|
110
|
+
proxy.on('proxyReq', (proxyReq, proxyReqRequest, proxyReqResponse, options) => {
|
|
111
|
+
if ((0, shared_1.objectNotEmpty)(requestBody)) {
|
|
112
|
+
const bodyData = JSON.stringify(requestBody);
|
|
113
|
+
proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));
|
|
114
|
+
proxyReq.write(bodyData);
|
|
160
115
|
}
|
|
161
|
-
|
|
116
|
+
});
|
|
117
|
+
proxy.on('proxyRes', function (proxyRes, proxyResRequest, proxyResResponse) {
|
|
118
|
+
(0, node_http_proxy_json_1.default)(proxyResResponse, proxyRes, function (proxyResBody) {
|
|
119
|
+
return processResponse(proxyResBody);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
proxy.once('error', (error) => {
|
|
123
|
+
console.error('Proxy error', error);
|
|
124
|
+
reject(error);
|
|
125
|
+
});
|
|
126
|
+
proxy.web(req, res, {
|
|
127
|
+
target,
|
|
128
|
+
timeout: PROXY_TIMEOUT,
|
|
129
|
+
proxyTimeout: PROXY_TIMEOUT,
|
|
130
|
+
followRedirects: false,
|
|
131
|
+
changeOrigin: true,
|
|
132
|
+
secure: true,
|
|
162
133
|
});
|
|
163
134
|
});
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
proxyTimeout: PROXY_TIMEOUT,
|
|
172
|
-
followRedirects: false,
|
|
173
|
-
changeOrigin: true,
|
|
174
|
-
secure: true,
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
catch (error) {
|
|
179
|
-
console.error(`Error handling proxy request for '${targetPath}'`, error);
|
|
180
|
-
return res.status(200).json({ message: (error === null || error === void 0 ? void 0 : error.message) || 'Error handling proxy request', targetPath });
|
|
181
|
-
}
|
|
182
|
-
});
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
console.error(`Error handling proxy request for '${targetPath}'`, error);
|
|
138
|
+
return res.status(200).json({ message: (error === null || error === void 0 ? void 0 : error.message) || 'Error handling proxy request', targetPath });
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
};
|
|
183
142
|
exports.handleProxy = handleProxy;
|
|
184
143
|
//# sourceMappingURL=proxy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../../../src/lib/handlers/api/proxy.js"],"names":[],"mappings":";;;;AAAA,sDAAsD;AACtD,sEAAkC;AAClC,oEAAkC;AAClC,
|
|
1
|
+
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../../../src/lib/handlers/api/proxy.js"],"names":[],"mappings":";;;;AAAA,sDAAsD;AACtD,sEAAkC;AAClC,oEAAkC;AAClC,wFAAkD;AAElD,uCAMoB;AACpB,4CAawB;AAExB,MAAM,aAAa,GAAG,IAAI,CAAA,CAAC,kBAAkB;AAE7C,MAAM,uBAAuB,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE;IACpE,MAAM,IAAI,GAAG,IAAA,oBAAY,EAAC,IAAA,6BAAoB,EAAC,UAAU,CAAC,EAAE,UAAU,CAAC,CAAA;IAEvE,OAAO,IAAA,qBAAa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,CAAC,aAAa,EAAE,KAAK,CAAC,CAAA;oBACnC,MAAM,CAAC,KAAK,CAAC,CAAA;gBACf,CAAC,CAAC,CAAA;gBAEF,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE;oBAClB,MAAM;oBACN,OAAO,EAAE,aAAa;oBACtB,YAAY,EAAE,aAAa;oBAC3B,eAAe,EAAE,KAAK;oBACtB,YAAY,EAAE,IAAI;oBAClB,MAAM,EAAE,IAAI;iBACb,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;SACH;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,KAAK,CAAC,qCAAqC,UAAU,GAAG,EAAE,KAAK,CAAC,CAAA;YACxE,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,KAAI,8BAA8B,EAAE,UAAU,EAAE,CAAC,CAAA;SACvG;IACH,CAAC,CAAA,CAAA;AACH,CAAC,CAAA;AAxLY,QAAA,WAAW,eAwLvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest.d.ts","sourceRoot":"","sources":["../../../../src/lib/handlers/api/rest.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rest.d.ts","sourceRoot":"","sources":["../../../../src/lib/handlers/api/rest.js"],"names":[],"mappings":"AAgBO,yGAuGN"}
|
|
@@ -5,76 +5,81 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const shopify_api_1 = require("@shopify/shopify-api");
|
|
6
6
|
const utils_1 = require("../../utils");
|
|
7
7
|
const shared_1 = require("../../../shared");
|
|
8
|
-
const handleRest = (serverRuntimeConfig) =>
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
let message;
|
|
21
|
-
let headers = {};
|
|
22
|
-
try {
|
|
23
|
-
let queryData = queryParam !== null && queryParam !== void 0 ? queryParam : _query;
|
|
24
|
-
if ((0, shared_1.isType)(queryData, 'string')) {
|
|
25
|
-
queryData = (0, shared_1.querystringToObject)(queryData);
|
|
8
|
+
const handleRest = (serverRuntimeConfig) => {
|
|
9
|
+
const _getVerifiedBody = (0, utils_1.getVerifiedBody)(serverRuntimeConfig);
|
|
10
|
+
return (req, res, _params) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
11
|
+
const [requestBody, processResponse] = yield _getVerifiedBody(req, res);
|
|
12
|
+
const { query: _query, method: _method } = req;
|
|
13
|
+
const { shop } = _query !== null && _query !== void 0 ? _query : {};
|
|
14
|
+
const _a = _params !== null && _params !== void 0 ? _params : {}, { path, isOnline, method: methodParam, query: queryParam, body: bodyParam, transform = (_data) => _data } = _a, params = tslib_1.__rest(_a, ["path", "isOnline", "method", "query", "body", "transform"]);
|
|
15
|
+
if ((0, shared_1.stringEmpty)(shop) || (0, shared_1.stringEmpty)(path)) {
|
|
16
|
+
return {
|
|
17
|
+
statusCode: 400,
|
|
18
|
+
message: 'Invalid arguments',
|
|
19
|
+
};
|
|
26
20
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
statusCode = 200;
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
message = 'Error handling rest call';
|
|
39
|
-
statusCode = 500;
|
|
40
|
-
// TODO: clean up to share between rest and graph (pr at least keep in sync)
|
|
41
|
-
switch (true) {
|
|
42
|
-
case error instanceof shared_1.ShopifyAuthenticationError: {
|
|
43
|
-
console.error(`${message}. Authentication Error.`, error);
|
|
44
|
-
const errorResponse = (0, utils_1.getAuthErrorResponse)(serverRuntimeConfig, { error, shop });
|
|
45
|
-
statusCode = errorResponse.statusCode;
|
|
46
|
-
message = errorResponse.message;
|
|
47
|
-
headers = errorResponse.headers;
|
|
48
|
-
break;
|
|
21
|
+
let statusCode;
|
|
22
|
+
let response;
|
|
23
|
+
let message;
|
|
24
|
+
let headers = {};
|
|
25
|
+
try {
|
|
26
|
+
let queryData = queryParam !== null && queryParam !== void 0 ? queryParam : _query;
|
|
27
|
+
if ((0, shared_1.isType)(queryData, 'string')) {
|
|
28
|
+
queryData = (0, shared_1.querystringToObject)(queryData);
|
|
49
29
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
30
|
+
const _b = (0, shared_1.ensureObject)(queryData), { apiVersion } = _b, query = tslib_1.__rest(_b, ["apiVersion"]);
|
|
31
|
+
const body = bodyParam !== null && bodyParam !== void 0 ? bodyParam : requestBody;
|
|
32
|
+
const method = (0, shared_1.ensureString)(methodParam !== null && methodParam !== void 0 ? methodParam : _method).toLowerCase();
|
|
33
|
+
const { getVerifiedClients } = yield (0, utils_1.getShopifyHelpers)(serverRuntimeConfig, { shop });
|
|
34
|
+
const { Rest } = yield getVerifiedClients({ req, res, shop, apiVersion, isOnline });
|
|
35
|
+
response = yield Rest[method](Object.assign({ path,
|
|
36
|
+
query,
|
|
37
|
+
body, type: shopify_api_1.DataType.JSON }, params))
|
|
38
|
+
.then(processResponse);
|
|
39
|
+
statusCode = 200;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
message = 'Error handling rest call';
|
|
43
|
+
statusCode = 500;
|
|
44
|
+
// TODO: clean up to share between rest and graph (pr at least keep in sync)
|
|
45
|
+
switch (true) {
|
|
46
|
+
case error instanceof shared_1.ShopifyAuthenticationError: {
|
|
47
|
+
console.error(`${message}. Authentication Error.`, error);
|
|
48
|
+
const errorResponse = (0, utils_1.getAuthErrorResponse)(serverRuntimeConfig, { error, shop });
|
|
49
|
+
statusCode = errorResponse.statusCode;
|
|
50
|
+
message = errorResponse.message;
|
|
51
|
+
headers = errorResponse.headers;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
case error instanceof shopify_api_1.BillingError: {
|
|
55
|
+
console.error(`${message}. Billing Error - ${error.message}.`, error.errorData);
|
|
56
|
+
statusCode = 402;
|
|
57
|
+
if (error === null || error === void 0 ? void 0 : error.message) {
|
|
58
|
+
message = error.message;
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
default: {
|
|
63
|
+
console.error(message, error);
|
|
64
|
+
break;
|
|
55
65
|
}
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
default: {
|
|
59
|
-
console.error(message, error);
|
|
60
|
-
break;
|
|
61
66
|
}
|
|
62
67
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
68
|
+
Object.entries(headers).forEach(([key, value]) => {
|
|
69
|
+
res.setHeader(key, value);
|
|
70
|
+
});
|
|
71
|
+
if (!response) {
|
|
72
|
+
return res.status(statusCode).json({ message });
|
|
73
|
+
}
|
|
74
|
+
// HMMMMM???
|
|
75
|
+
if ((params === null || params === void 0 ? void 0 : params.type) && ![shopify_api_1.DataType.GraphQL, shopify_api_1.DataType.JSON].includes(params.type)) {
|
|
76
|
+
return res.status(statusCode).send(response);
|
|
77
|
+
}
|
|
78
|
+
if (!(response === null || response === void 0 ? void 0 : response.body)) {
|
|
79
|
+
return res.status(statusCode).json({ message });
|
|
80
|
+
}
|
|
81
|
+
return res.status(statusCode).json(transform(response.body));
|
|
66
82
|
});
|
|
67
|
-
|
|
68
|
-
return res.status(statusCode).json({ message });
|
|
69
|
-
}
|
|
70
|
-
// HMMMMM???
|
|
71
|
-
if ((params === null || params === void 0 ? void 0 : params.type) && ![shopify_api_1.DataType.GraphQL, shopify_api_1.DataType.JSON].includes(params.type)) {
|
|
72
|
-
return res.status(statusCode).send(response);
|
|
73
|
-
}
|
|
74
|
-
if (!(response === null || response === void 0 ? void 0 : response.body)) {
|
|
75
|
-
return res.status(statusCode).json({ message });
|
|
76
|
-
}
|
|
77
|
-
return res.status(statusCode).json(transform(response.body));
|
|
78
|
-
});
|
|
83
|
+
};
|
|
79
84
|
exports.handleRest = handleRest;
|
|
80
85
|
//# sourceMappingURL=rest.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest.js","sourceRoot":"","sources":["../../../../src/lib/handlers/api/rest.js"],"names":[],"mappings":";;;;AAAA,sDAA6D;AAE7D,
|
|
1
|
+
{"version":3,"file":"rest.js","sourceRoot":"","sources":["../../../../src/lib/handlers/api/rest.js"],"names":[],"mappings":";;;;AAAA,sDAA6D;AAE7D,uCAIoB;AACpB,4CAOwB;AAEjB,MAAM,UAAU,GAAG,CAAC,mBAAmB,EAAE,EAAE;IAChD,MAAM,gBAAgB,GAAG,IAAA,uBAAe,EAAC,mBAAmB,CAAC,CAAA;IAE7D,OAAO,CAAO,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE;QACjC,MAAM,CAAC,WAAW,EAAE,eAAe,CAAC,GAAG,MAAM,gBAAgB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;QAEvE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,CAAA;QAC9C,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAA;QAC7B,MAAM,KAQF,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,EARX,EACJ,IAAI,EACJ,QAAQ,EACR,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,UAAU,EACjB,IAAI,EAAE,SAAS,EACf,SAAS,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,OAEb,EADZ,MAAM,sBAPL,4DAQL,CAAgB,CAAA;QAEjB,IAAI,IAAA,oBAAW,EAAC,IAAI,CAAC,IAAI,IAAA,oBAAW,EAAC,IAAI,CAAC,EAAE;YAC1C,OAAO;gBACL,UAAU,EAAE,GAAG;gBACf,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AI,CAAC,CAAC,sBAAQ,CAAC,OAAO,EAAE,sBAAQ,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;YAC5E,OAAO,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;SAC7C;QAED,IAAI,CAAC,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,CAAA,EAAE;YACnB,OAAO,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;SAChD;QAED,OAAO,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAA;IAC9D,CAAC,CAAA,CAAA;AACH,CAAC,CAAA;AAvGY,QAAA,UAAU,cAuGtB"}
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from '../shared';
|
|
2
2
|
export * from './handlers';
|
|
3
3
|
export * from './withShopify';
|
|
4
|
-
export { getShopifyHelpers, prepareHeaders } from './utils
|
|
4
|
+
export { getShopifyHelpers, prepareHeaders, getVerifiedBody } from './utils';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA"}
|
package/dist/lib/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.prepareHeaders = exports.getShopifyHelpers = void 0;
|
|
3
|
+
exports.getVerifiedBody = exports.prepareHeaders = exports.getShopifyHelpers = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
tslib_1.__exportStar(require("../shared"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./handlers"), exports);
|
|
7
7
|
tslib_1.__exportStar(require("./withShopify"), exports);
|
|
8
|
-
var
|
|
9
|
-
Object.defineProperty(exports, "getShopifyHelpers", { enumerable: true, get: function () { return
|
|
10
|
-
Object.defineProperty(exports, "prepareHeaders", { enumerable: true, get: function () { return
|
|
8
|
+
var utils_1 = require("./utils");
|
|
9
|
+
Object.defineProperty(exports, "getShopifyHelpers", { enumerable: true, get: function () { return utils_1.getShopifyHelpers; } });
|
|
10
|
+
Object.defineProperty(exports, "prepareHeaders", { enumerable: true, get: function () { return utils_1.prepareHeaders; } });
|
|
11
|
+
Object.defineProperty(exports, "getVerifiedBody", { enumerable: true, get: function () { return utils_1.getVerifiedBody; } });
|
|
11
12
|
//# sourceMappingURL=index.js.map
|
package/dist/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":";;;;AAAA,oDAAyB;AACzB,qDAA0B;AAC1B,wDAA6B;AAC7B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":";;;;AAAA,oDAAyB;AACzB,qDAA0B;AAC1B,wDAA6B;AAC7B,iCAA4E;AAAnE,0GAAA,iBAAiB,OAAA;AAAE,uGAAA,cAAc,OAAA;AAAE,wGAAA,eAAe,OAAA"}
|
package/dist/lib/utils/index.js
CHANGED
|
@@ -9,4 +9,5 @@ tslib_1.__exportStar(require("./session"), exports);
|
|
|
9
9
|
tslib_1.__exportStar(require("./shopify"), exports);
|
|
10
10
|
tslib_1.__exportStar(require("./shopify-api-js/oauth"), exports);
|
|
11
11
|
tslib_1.__exportStar(require("./token"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./verification"), exports);
|
|
12
13
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/utils/index.js"],"names":[],"mappings":";;;AAAA,oDAAyB;AACzB,mDAAwB;AACxB,qDAA0B;AAC1B,oDAAyB;AACzB,oDAAyB;AACzB,oDAAyB;AACzB,iEAAsC;AACtC,kDAAuB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/utils/index.js"],"names":[],"mappings":";;;AAAA,oDAAyB;AACzB,mDAAwB;AACxB,qDAA0B;AAC1B,oDAAyB;AACzB,oDAAyB;AACzB,oDAAyB;AACzB,iEAAsC;AACtC,kDAAuB;AACvB,yDAA8B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/session.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/session.js"],"names":[],"mappings":"AAuCO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkTN;AA+BM;;;;;;mBAoBN"}
|
|
@@ -4,7 +4,6 @@ exports.prepareHeaders = exports.getShopifyHelpers = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const js_base64_1 = require("js-base64");
|
|
6
6
|
const shopify_api_1 = require("@shopify/shopify-api");
|
|
7
|
-
const luxon_1 = require("luxon");
|
|
8
7
|
const shared_1 = require("../../shared");
|
|
9
8
|
const headers_1 = require("./headers");
|
|
10
9
|
const billing_1 = require("./billing");
|
|
@@ -57,7 +56,8 @@ const getShopifyHelpers = (serverRuntimeConfig, config) => tslib_1.__awaiter(voi
|
|
|
57
56
|
throw new Error('Invalid shop');
|
|
58
57
|
}
|
|
59
58
|
// NOTE only online sessions have expirations
|
|
60
|
-
const sessionExpired = (isOnline && (!(session === null || session === void 0 ? void 0 : session.expires) ||
|
|
59
|
+
const sessionExpired = (isOnline && (!(session === null || session === void 0 ? void 0 : session.expires) ||
|
|
60
|
+
((0, shared_1.ensureDateTime)(session.expires) < (0, shared_1.getCurrentDateTime)())));
|
|
61
61
|
const sessionActive = (!sessionExpired && (0, shared_1.arraysMatch)((0, shared_1.splitCommas)((_e = (_d = shopify.config) === null || _d === void 0 ? void 0 : _d.scopes) === null || _e === void 0 ? void 0 : _e.toString()), (0, shared_1.splitCommas)(session === null || session === void 0 ? void 0 : session.scope)));
|
|
62
62
|
if (!sessionActive) {
|
|
63
63
|
throw new shared_1.ShopifySessionAuthenticationError('Inactive session');
|