@agnostack/next-shopify 1.13.5-beta.2 → 1.13.5-beta.4

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 CHANGED
@@ -1,3 +1,17 @@
1
+ ## [1.13.5-beta.4](https://github.com/agnostack/next-shopify/compare/v1.13.5-beta.3...v1.13.5-beta.4) (2023-11-29)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * wip ([ecd3625](https://github.com/agnostack/next-shopify/commit/ecd36257e4cde1bbdea48b895934e82ecedf0612))
7
+
8
+ ## [1.13.5-beta.3](https://github.com/agnostack/next-shopify/compare/v1.13.5-beta.2...v1.13.5-beta.3) (2023-11-29)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * wip ([825f688](https://github.com/agnostack/next-shopify/commit/825f688f614be631c13a70e1c652c45f742408ed))
14
+
1
15
  ## [1.13.5-beta.2](https://github.com/agnostack/next-shopify/compare/v1.13.5-beta.1...v1.13.5-beta.2) (2023-11-29)
2
16
 
3
17
 
@@ -1 +1 @@
1
- {"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../../../src/lib/handlers/api/proxy.js"],"names":[],"mappings":"AAsCO,sHAgPN"}
1
+ {"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../../../src/lib/handlers/api/proxy.js"],"names":[],"mappings":"AAmCO,sHA4LN"}
@@ -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,164 +13,136 @@ 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) => (req, res, params) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
18
- var _a, _b;
16
+ const handleProxy = (serverRuntimeConfig, config) => {
19
17
  const { generateReplacements } = config !== null && config !== void 0 ? config : {};
20
- const { keyPairs, API_PATHS, APP_CONFIG, APP_BASE_URL, TARGET_SAFELIST, ORIGIN_SAFELIST, } = serverRuntimeConfig;
21
- const _c = (_a = req.headers) !== null && _a !== void 0 ? _a : {}, { origin, 'x-public-key': apiKey, 'x-ephemeral-key': ephemeralPublicKey, 'x-authorization-timestamp': customAuthTimestamp, 'x-authorization': customAuth, 'x-forwarded-for': _forwardFor, 'x-forwarded-proto': _forwardProto, 'x-forwarded-host': forwardHost, 'x-proxy-origin': proxyOrigin } = _c, _headers = tslib_1.__rest(_c, ["origin", 'x-public-key', 'x-ephemeral-key', 'x-authorization-timestamp', 'x-authorization', 'x-forwarded-for', 'x-forwarded-proto', 'x-forwarded-host', 'x-proxy-origin']);
22
- 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,
23
- // 'x-shopify-app-installation-id': shopifyAppInstallationId,
24
- // 'x-app-installation-id': appInstallationId = shopifyAppInstallationId, // TODO: pass along installationId??
25
- // TODO: pass along providerSetId??
26
- } = _headers;
27
- let targetPath;
28
- try {
29
- const [authProtocol, authSignature] = (0, shared_1.ensureString)(customAuth).split(' ');
30
- const isVerifiable = (apiKey &&
31
- ephemeralPublicKey &&
32
- (keyPairs === null || keyPairs === void 0 ? void 0 : keyPairs.shared) &&
33
- customAuthTimestamp &&
34
- authSignature &&
35
- (authProtocol === 'HMAC-SHA256'));
36
- let verificationKeys;
37
- // NOTE raw request body is required for shopify's validation
38
- const _rawBody = yield (0, raw_body_1.default)(req);
39
- const rawBody = _rawBody.toString();
40
- const parsedBody = JSON.parse(rawBody || '{}'); // NOTE: parsedBody should be encrypted when isVerifiable
41
- let decryptedBody = parsedBody;
42
- // NOTE: GET requests are not always sending along origin
43
- if ((0, shared_1.stringEmpty)(origin)) {
44
- req.headers = Object.assign(Object.assign({}, req.headers), { origin: proxyOrigin || forwardHost });
45
- }
46
- const _d = (_b = req.query) !== null && _b !== void 0 ? _b : {}, { signature, proxyEncoded } = _d, verifiable = tslib_1.__rest(_d, ["signature", "proxyEncoded"]);
47
- const { shop: _shop, host, timestamp, path_prefix } = verifiable;
48
- const shop = _shop || shopHeader;
49
- yield (0, nextjs_cors_1.default)(req, res, {
50
- methods: ['PUT', 'PATCH', 'POST', 'DELETE'],
51
- origin: (origin, callback) => {
52
- const isSafelisted = (0, shared_1.matchHostname)(origin, [
53
- ...ORIGIN_SAFELIST,
54
- 'cdn.shopify.com' // NOTE: this is the domain for checkout UI extensions
55
- ]);
56
- if (isSafelisted) {
57
- return callback(null, true);
58
- }
59
- return callback(new Error('Invalid CORS origin'));
60
- },
61
- optionsSuccessStatus: 200, // some legacy browsers (IE11, various SmartTVs) choke on 204
62
- });
63
- const { target: targetParam } = params !== null && params !== void 0 ? params : {};
64
- // eslint-disable-next-line max-len
65
- const _targetUrl = ((0, shared_1.stringEmpty)(targetParam) || targetParam.startsWith('http')) ? targetParam : `${APP_BASE_URL}/${(0, shared_1.removeLeadingSlash)(targetParam)}`;
66
- const { origin: target, hostname, pathname, search } = (0, shared_1.stringNotEmpty)(_targetUrl) ? new URL(_targetUrl) : {};
67
- targetPath = [pathname, search].filter(shared_1.stringNotEmpty).join('');
68
- const safelistedTarget = (0, shared_1.matchHostname)(hostname, Object.assign({ [new URL(APP_BASE_URL).hostname]: {
69
- // 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?
70
- // headers: {
71
- // Authorization: 'Bearer {{setting.zendesk.token}}',
72
- // },
73
- params: {
74
- shop,
75
- host,
76
- },
77
- } }, TARGET_SAFELIST));
78
- if ((0, shared_1.stringEmpty)(targetPath) || (safelistedTarget == undefined)) {
79
- return res.status(407).json({ message: 'Unproxyable target' });
80
- }
81
- if (!shop || !host || !extensionPoint || !signature || !proxyEncoded) {
82
- return res.status(400).json({ message: 'Invalid or missing headers', extensionPoint });
83
- }
84
- const isShopifyOriginOrRelative = (0, shared_1.stringNotEmpty)((0, shared_1.ensureString)(path_prefix).startsWith('http')
85
- ? (0, shared_1.sanitizeShop)(new URL(path_prefix).hostname)
86
- : path_prefix);
87
- // TODO: once Shopify fixes CORS issue when origin is cdn.shopify.com, update this!
88
- if (!verifyAppProxySignature(signature, verifiable, isShopifyOriginOrRelative ? APP_CONFIG.apiSecretKey : timestamp)) {
89
- return res.status(403).json({ message: 'Invalid signature' });
90
- }
91
- // TODO: clean up targetParam.startsWith??
92
- if (!targetParam.startsWith(API_PATHS[shared_1.API_ROUTE_NAMES.SESSION_TOKEN])) {
93
- const _getVerifiedSessionData = (0, utils_1.getVerifiedSessionData)(serverRuntimeConfig);
94
- if (!_getVerifiedSessionData(sessionToken, { shop, host }).catch((_error) => {
95
- if (_error instanceof shared_1.ShopifySessionInvalidError) {
96
- return res.status(403).json({ message: _error.message });
97
- }
98
- throw _error;
99
- })) {
100
- 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,
23
+ // 'x-public-key': apiKey,
24
+ // 'x-ephemeral-key': ephemeralPublicKey,
25
+ // 'x-authorization-timestamp': customAuthTimestamp,
26
+ // 'x-authorization': customAuth,
27
+ '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']);
28
+ 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,
29
+ // 'x-shopify-app-installation-id': shopifyAppInstallationId,
30
+ // 'x-app-installation-id': appInstallationId = shopifyAppInstallationId, // TODO: pass along installationId??
31
+ // TODO: pass along providerSetId??
32
+ } = _headers;
33
+ let targetPath;
34
+ try {
35
+ // NOTE: GET requests are not always sending along origin
36
+ if ((0, shared_1.stringEmpty)(origin)) {
37
+ req.headers = Object.assign(Object.assign({}, req.headers), { origin: proxyOrigin || forwardHost });
101
38
  }
102
- }
103
- const { headers: targetHeaders, params: targetParams } = (0, shared_1.ensureObject)(safelistedTarget);
104
- if ((0, shared_1.objectNotEmpty)(targetParams)) {
105
- targetPath = (0, shared_1.appendQuery)(targetPath, new URLSearchParams(targetParams).toString());
106
- }
107
- // TEMP!!! remove isVerifiable check once webwidget moved to react
108
- if (isVerifiable) {
109
- if (!apiKey || !ephemeralPublicKey || !(keyPairs === null || keyPairs === void 0 ? void 0 : keyPairs.shared) || !customAuthTimestamp || !authSignature || (authProtocol !== 'HMAC-SHA256')) {
110
- return res.status(401).json({ message: 'Invalid or missing authorization' });
111
- }
112
- verificationKeys = yield shared_1.subtle.getVerificationKeys({
113
- publicKey: ephemeralPublicKey,
114
- privateKey: keyPairs.shared.privateKey,
39
+ const _d = (_b = req.query) !== null && _b !== void 0 ? _b : {}, { signature, proxyEncoded } = _d, verifiable = tslib_1.__rest(_d, ["signature", "proxyEncoded"]);
40
+ const { shop: _shop, host, timestamp, path_prefix } = verifiable;
41
+ const shop = _shop || shopHeader;
42
+ yield (0, nextjs_cors_1.default)(req, res, {
43
+ methods: ['PUT', 'PATCH', 'POST', 'DELETE'],
44
+ origin: (origin, callback) => {
45
+ const isSafelisted = (0, shared_1.matchHostname)(origin, [
46
+ ...ORIGIN_SAFELIST,
47
+ 'cdn.shopify.com' // NOTE: this is the domain for checkout UI extensions
48
+ ]);
49
+ if (isSafelisted) {
50
+ return callback(null, true);
51
+ }
52
+ return callback(new Error('Invalid CORS origin'));
53
+ },
54
+ optionsSuccessStatus: 200, // some legacy browsers (IE11, various SmartTVs) choke on 204
115
55
  });
116
- if (!verificationKeys) {
117
- return res.status(412).json({ message: 'Invalid or missing verification' });
118
- }
119
- const verificationPayload = (0, shared_1.objectToSortedString)(Object.assign({ method: (0, shared_1.getRequestMethod)(rawBody, req.method), timestamp: customAuthTimestamp, body: parsedBody }, (0, shared_1.normalizeURIParts)(targetPath)));
120
- const isValid = yield shared_1.subtle.verifyHMAC(verificationPayload, verificationKeys.derivedHMACKey, authSignature);
121
- if (!isValid) {
122
- return res.status(412).json({ message: 'Invalid or missing verification' });
56
+ const { target: targetParam } = params !== null && params !== void 0 ? params : {};
57
+ // eslint-disable-next-line max-len
58
+ const _targetUrl = ((0, shared_1.stringEmpty)(targetParam) || targetParam.startsWith('http')) ? targetParam : `${APP_BASE_URL}/${(0, shared_1.removeLeadingSlash)(targetParam)}`;
59
+ const { origin: target, hostname, pathname, search } = (0, shared_1.stringNotEmpty)(_targetUrl) ? new URL(_targetUrl) : {};
60
+ targetPath = [pathname, search].filter(shared_1.stringNotEmpty).join('');
61
+ const safelistedTarget = (0, shared_1.matchHostname)(hostname, Object.assign({ [new URL(APP_BASE_URL).hostname]: {
62
+ // 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?
63
+ // headers: {
64
+ // Authorization: 'Bearer {{setting.zendesk.token}}',
65
+ // },
66
+ params: {
67
+ shop,
68
+ host,
69
+ },
70
+ } }, TARGET_SAFELIST));
71
+ if ((0, shared_1.stringEmpty)(targetPath) || (safelistedTarget == undefined)) {
72
+ return res.status(407).json({ message: 'Unproxyable target' });
123
73
  }
124
- if (rawBody) {
125
- const decryptedMessage = yield shared_1.subtle.decryptMessage(parsedBody, verificationKeys.derivedSecretKey);
126
- decryptedBody = JSON.parse(decryptedMessage !== null && decryptedMessage !== void 0 ? decryptedMessage : '{}');
74
+ if (!shop || !host || !extensionPoint || !signature || !proxyEncoded) {
75
+ return res.status(400).json({ message: 'Invalid or missing headers', extensionPoint });
127
76
  }
128
- }
129
- const _prepareHeaders = (0, utils_1.prepareHeaders)(serverRuntimeConfig);
130
- const headers = yield _prepareHeaders({
131
- generateReplacements,
132
- shop,
133
- appId,
134
- headers: Object.assign(Object.assign({}, _headers), targetHeaders),
135
- });
136
- const proxy = http_proxy_1.default.createProxy();
137
- return new Promise((resolve, reject) => {
138
- req.url = targetPath;
139
- if (headers) {
140
- req.headers = headers;
77
+ const isShopifyOriginOrRelative = (0, shared_1.stringNotEmpty)((0, shared_1.ensureString)(path_prefix).startsWith('http')
78
+ ? (0, shared_1.sanitizeShop)(new URL(path_prefix).hostname)
79
+ : path_prefix);
80
+ // TODO: once Shopify fixes CORS issue when origin is cdn.shopify.com, update this!
81
+ if (!verifyAppProxySignature(signature, verifiable, isShopifyOriginOrRelative ? APP_CONFIG.apiSecretKey : timestamp)) {
82
+ return res.status(403).json({ message: 'Invalid signature' });
141
83
  }
142
- proxy.on('proxyReq', (proxyReq, proxyReqRequest, proxyReqResponse, options) => {
143
- if ((0, shared_1.objectNotEmpty)(decryptedBody)) {
144
- const bodyData = JSON.stringify(decryptedBody);
145
- proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));
146
- proxyReq.write(bodyData);
84
+ // TODO: clean up targetParam.startsWith??
85
+ if (!targetParam.startsWith(API_PATHS[shared_1.API_ROUTE_NAMES.SESSION_TOKEN])) {
86
+ const _getVerifiedSessionData = (0, utils_1.getVerifiedSessionData)(serverRuntimeConfig);
87
+ if (!_getVerifiedSessionData(sessionToken, { shop, host }).catch((_error) => {
88
+ if (_error instanceof shared_1.ShopifySessionInvalidError) {
89
+ return res.status(403).json({ message: _error.message });
90
+ }
91
+ throw _error;
92
+ })) {
93
+ return res.status(403).json({ message: 'Unverified signature' });
147
94
  }
95
+ }
96
+ const { headers: targetHeaders, params: targetParams } = (0, shared_1.ensureObject)(safelistedTarget);
97
+ if ((0, shared_1.objectNotEmpty)(targetParams)) {
98
+ targetPath = (0, shared_1.appendQuery)(targetPath, new URLSearchParams(targetParams).toString());
99
+ }
100
+ const [requestBody, processResponse] = yield _getVerifiedBody(req, res, targetPath);
101
+ console.log(`>>> > handleProxy > requestBody, processResponse:`, requestBody, processResponse);
102
+ const _prepareHeaders = (0, utils_1.prepareHeaders)(serverRuntimeConfig);
103
+ const headers = yield _prepareHeaders({
104
+ generateReplacements,
105
+ shop,
106
+ appId,
107
+ headers: Object.assign(Object.assign({}, _headers), targetHeaders),
148
108
  });
149
- proxy.on('proxyRes', function (proxyRes, proxyResRequest, proxyResResponse) {
150
- (0, node_http_proxy_json_1.default)(proxyResResponse, proxyRes, function (proxyResBody) {
151
- if (!proxyResBody || !isVerifiable || !verificationKeys) {
152
- return proxyResBody;
109
+ const proxy = http_proxy_1.default.createProxy();
110
+ return new Promise((resolve, reject) => {
111
+ req.url = targetPath;
112
+ if (headers) {
113
+ req.headers = headers;
114
+ }
115
+ proxy.on('proxyReq', (proxyReq, proxyReqRequest, proxyReqResponse, options) => {
116
+ if ((0, shared_1.objectNotEmpty)(requestBody)) {
117
+ const bodyData = JSON.stringify(requestBody);
118
+ proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));
119
+ proxyReq.write(bodyData);
153
120
  }
154
- return shared_1.subtle.encryptMessage(JSON.stringify(proxyResBody), verificationKeys.derivedSecretKey);
121
+ });
122
+ proxy.on('proxyRes', function (proxyRes, proxyResRequest, proxyResResponse) {
123
+ (0, node_http_proxy_json_1.default)(proxyResResponse, proxyRes, function (proxyResBody) {
124
+ return processResponse(proxyResBody);
125
+ });
126
+ });
127
+ proxy.once('error', (error) => {
128
+ console.error('Proxy error', error);
129
+ reject(error);
130
+ });
131
+ proxy.web(req, res, {
132
+ target,
133
+ timeout: PROXY_TIMEOUT,
134
+ proxyTimeout: PROXY_TIMEOUT,
135
+ followRedirects: false,
136
+ changeOrigin: true,
137
+ secure: true,
155
138
  });
156
139
  });
157
- proxy.once('error', (error) => {
158
- console.error('Proxy error', error);
159
- reject(error);
160
- });
161
- proxy.web(req, res, {
162
- target,
163
- timeout: PROXY_TIMEOUT,
164
- proxyTimeout: PROXY_TIMEOUT,
165
- followRedirects: false,
166
- changeOrigin: true,
167
- secure: true,
168
- });
169
- });
170
- }
171
- catch (error) {
172
- console.error(`Error handling proxy request for '${targetPath}'`, error);
173
- return res.status(200).json({ message: (error === null || error === void 0 ? void 0 : error.message) || 'Error handling proxy request', targetPath });
174
- }
175
- });
140
+ }
141
+ catch (error) {
142
+ console.error(`Error handling proxy request for '${targetPath}'`, error);
143
+ return res.status(200).json({ message: (error === null || error === void 0 ? void 0 : error.message) || 'Error handling proxy request', targetPath });
144
+ }
145
+ });
146
+ };
176
147
  exports.handleProxy = handleProxy;
177
148
  //# 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,gEAAiC;AACjC,wFAAkD;AAElD,uCAKoB;AACpB,4CAgBwB;AAExB,MAAM,aAAa,GAAG,IAAI,CAAA,CAAC,kBAAkB;AA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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;AA5LY,QAAA,WAAW,eA4LvB"}
@@ -6,4 +6,5 @@ export * from "./session";
6
6
  export * from "./shopify";
7
7
  export * from "./shopify-api-js/oauth";
8
8
  export * from "./token";
9
+ export * from "./verification";
9
10
  //# sourceMappingURL=index.d.ts.map
@@ -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"}
@@ -0,0 +1,2 @@
1
+ export function getVerifiedBody(serverRuntimeConfig: any): (req: any, res: any, uri: any) => Promise<any>;
2
+ //# sourceMappingURL=verification.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verification.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/verification.js"],"names":[],"mappings":"AAUO,0GAmFN"}
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getVerifiedBody = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const raw_body_1 = tslib_1.__importDefault(require("raw-body"));
6
+ const shared_1 = require("../../../shared");
7
+ const getVerifiedBody = (serverRuntimeConfig) => {
8
+ const { keyPairs } = serverRuntimeConfig;
9
+ return (req, res, uri) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
10
+ var _a;
11
+ const { 'x-public-key': apiKey, 'x-ephemeral-key': ephemeralPublicKey, 'x-authorization-timestamp': customAuthTimestamp, 'x-authorization': customAuth, } = (_a = req.headers) !== null && _a !== void 0 ? _a : {};
12
+ try {
13
+ const [authProtocol, authSignature] = (0, shared_1.ensureString)(customAuth).split(' ');
14
+ const isVerifiable = (apiKey &&
15
+ ephemeralPublicKey &&
16
+ (keyPairs === null || keyPairs === void 0 ? void 0 : keyPairs.shared) &&
17
+ customAuthTimestamp &&
18
+ authSignature &&
19
+ (authProtocol === 'HMAC-SHA256'));
20
+ let verificationKeys;
21
+ // NOTE raw request body is required for shopify's validation
22
+ const _rawBody = yield (0, raw_body_1.default)(req);
23
+ const rawBody = _rawBody.toString();
24
+ const parsedBody = JSON.parse(rawBody || '{}'); // NOTE: parsedBody should be encrypted when isVerifiable
25
+ let decryptedBody = parsedBody;
26
+ // TEMP!!! remove isVerifiable check once webwidget moved to react
27
+ if (isVerifiable) {
28
+ if (!apiKey || !ephemeralPublicKey || !(keyPairs === null || keyPairs === void 0 ? void 0 : keyPairs.shared) || !customAuthTimestamp || !authSignature || (authProtocol !== 'HMAC-SHA256')) {
29
+ return res.status(401).json({ message: 'Invalid or missing authorization' });
30
+ }
31
+ verificationKeys = yield shared_1.subtle.getVerificationKeys({
32
+ publicKey: ephemeralPublicKey,
33
+ privateKey: keyPairs.shared.privateKey,
34
+ });
35
+ if (!verificationKeys) {
36
+ return res.status(412).json({ message: 'Invalid or missing verification' });
37
+ }
38
+ const verificationPayload = (0, shared_1.objectToSortedString)(Object.assign({ method: (0, shared_1.getRequestMethod)(rawBody, req.method), timestamp: customAuthTimestamp, body: parsedBody }, (0, shared_1.normalizeURIParts)(uri)));
39
+ const isValid = yield shared_1.subtle.verifyHMAC(verificationPayload, verificationKeys.derivedHMACKey, authSignature);
40
+ if (!isValid) {
41
+ return res.status(412).json({ message: 'Invalid or missing verification' });
42
+ }
43
+ if (rawBody) {
44
+ const decryptedMessage = yield shared_1.subtle.decryptMessage(parsedBody, verificationKeys.derivedSecretKey);
45
+ decryptedBody = JSON.parse(decryptedMessage !== null && decryptedMessage !== void 0 ? decryptedMessage : '{}');
46
+ }
47
+ }
48
+ const postProcess = (response) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
49
+ if (!response || !isVerifiable || !(verificationKeys === null || verificationKeys === void 0 ? void 0 : verificationKeys.derivedSecretKey)) {
50
+ return response;
51
+ }
52
+ return shared_1.subtle.encryptMessage(JSON.stringify(response), verificationKeys === null || verificationKeys === void 0 ? void 0 : verificationKeys.derivedSecretKey);
53
+ });
54
+ return [decryptedBody, postProcess];
55
+ }
56
+ catch (error) {
57
+ console.error(`Error handling request verification for '${req.url}'`, error);
58
+ return res.status(200).json({ message: (error === null || error === void 0 ? void 0 : error.message) || 'Error handling request verification', targetPath: req.url });
59
+ }
60
+ });
61
+ };
62
+ exports.getVerifiedBody = getVerifiedBody;
63
+ //# sourceMappingURL=verification.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verification.js","sourceRoot":"","sources":["../../../src/lib/utils/verification.js"],"names":[],"mappings":";;;;AAAA,gEAAiC;AAEjC,4CAMwB;AAEjB,MAAM,eAAe,GAAG,CAAC,mBAAmB,EAAE,EAAE;IACrD,MAAM,EAAE,QAAQ,EAAE,GAAG,mBAAmB,CAAA;IAExC,OAAO,CAAO,GAAG,EAAE,GAAG,EAAE,GAA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AAC,QAAQ,CAAC,EAAE,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,gBAAgB,CAAC,CAAA;YAC5F,CAAC,CAAA,CAAA;YAED,OAAO,CAAC,aAAa,EAAE,WAAW,CAAC,CAAA;SACpC;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,KAAK,CAAC,4CAA4C,GAAG,CAAC,GAAG,GAAG,EAAE,KAAK,CAAC,CAAA;YAC5E,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,KAAI,qCAAqC,EAAE,UAAU,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC,CAAA;SACvH;IAEH,CAAC,CAAA,CAAA;AACH,CAAC,CAAA;AAnFY,QAAA,eAAe,mBAmF3B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agnostack/next-shopify",
3
- "version": "1.13.5-beta.2",
3
+ "version": "1.13.5-beta.4",
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",