@agnostack/next-shopify 1.10.1-alpha.1 → 1.10.1-beta.2
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,11 +1,16 @@
|
|
|
1
|
-
## [1.10.1-
|
|
1
|
+
## [1.10.1-beta.2](https://github.com/agnostack/next-shopify/compare/v1.10.1-beta.1...v1.10.1-beta.2) (2023-07-12)
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
### Bug Fixes
|
|
5
5
|
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
* updates ([afd62f7](https://github.com/agnostack/next-shopify/commit/afd62f728e94b85964f079f00d5cd931a4ab1762))
|
|
7
|
+
|
|
8
|
+
## [1.10.1-beta.1](https://github.com/agnostack/next-shopify/compare/v1.10.0...v1.10.1-beta.1) (2023-07-11)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* updates ([e22eef1](https://github.com/agnostack/next-shopify/commit/e22eef1539e5b868128e530474e5a34093681c46))
|
|
9
14
|
|
|
10
15
|
# [1.10.0](https://github.com/agnostack/next-shopify/compare/v1.9.5...v1.10.0) (2023-07-10)
|
|
11
16
|
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export function handleSessionToken({ APP_CONFIG }: {
|
|
2
2
|
APP_CONFIG: any;
|
|
3
|
-
},
|
|
3
|
+
}, { clientId, secret, ...config }?: {
|
|
4
|
+
clientId: any;
|
|
5
|
+
secret: any;
|
|
6
|
+
}): (req: any, res: any) => Promise<any>;
|
|
4
7
|
//# sourceMappingURL=token.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../../../src/lib/handlers/api/token.js"],"names":[],"mappings":"AASO
|
|
1
|
+
{"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../../../src/lib/handlers/api/token.js"],"names":[],"mappings":"AASO;;;;;yCAqEN"}
|
|
@@ -9,49 +9,52 @@ const uuid_1 = require("uuid");
|
|
|
9
9
|
const utils_1 = require("../../utils");
|
|
10
10
|
const shared_1 = require("../../../shared");
|
|
11
11
|
// NOTE: typically handling: "/api/token"
|
|
12
|
-
const handleSessionToken = ({ APP_CONFIG },
|
|
13
|
-
var _a,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
try {
|
|
22
|
-
// NOTE raw request body is required for validation
|
|
23
|
-
const _rawBody = yield (0, raw_body_1.default)(req);
|
|
24
|
-
const rawBody = _rawBody.toString();
|
|
25
|
-
const _c = JSON.parse(rawBody), { sub, aud = APP_CONFIG.apiKey } = _c, _body = tslib_1.__rest(_c, ["sub", "aud"]);
|
|
26
|
-
let { dest, iss, sid, jti } = _body, body = tslib_1.__rest(_body, ["dest", "iss", "sid", "jti"]);
|
|
27
|
-
if ((0, shared_1.stringEmpty)(dest)) {
|
|
28
|
-
dest = shop;
|
|
12
|
+
const handleSessionToken = ({ APP_CONFIG }, _a = {}) => {
|
|
13
|
+
var { clientId, secret } = _a, config = tslib_1.__rest(_a, ["clientId", "secret"]);
|
|
14
|
+
return (req, res) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
var _b, _c;
|
|
16
|
+
const { host } = (_b = req.query) !== null && _b !== void 0 ? _b : {};
|
|
17
|
+
const { 'x-shop-domain': shopDomain, 'x-shopify-shop-domain': shopifyShopDomain, 'x-shopify-shop': shop = shopifyShopDomain !== null && shopifyShopDomain !== void 0 ? shopifyShopDomain : shopDomain, } = (_c = req.headers) !== null && _c !== void 0 ? _c : {};
|
|
18
|
+
// TODO: un-btoa the host and check??
|
|
19
|
+
if ((0, shared_1.stringEmpty)(shop) || (0, shared_1.stringEmpty)(host)) {
|
|
20
|
+
return res.status(412).json({ message: 'Missing required param' });
|
|
29
21
|
}
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
let token;
|
|
23
|
+
try {
|
|
24
|
+
// NOTE raw request body is required for validation
|
|
25
|
+
const _rawBody = yield (0, raw_body_1.default)(req);
|
|
26
|
+
const rawBody = _rawBody.toString();
|
|
27
|
+
const _d = JSON.parse(rawBody), { sub, aud = clientId !== null && clientId !== void 0 ? clientId : APP_CONFIG.apiKey } = _d, _body = tslib_1.__rest(_d, ["sub", "aud"]);
|
|
28
|
+
let { dest, iss, sid, jti } = _body, body = tslib_1.__rest(_body, ["dest", "iss", "sid", "jti"]);
|
|
29
|
+
if ((0, shared_1.stringEmpty)(dest)) {
|
|
30
|
+
dest = shop;
|
|
31
|
+
}
|
|
32
|
+
if ((0, shared_1.stringEmpty)(iss)) {
|
|
33
|
+
iss = (0, js_base64_1.decode)(host);
|
|
34
|
+
}
|
|
35
|
+
if ((0, shared_1.stringEmpty)(sid)) {
|
|
36
|
+
sid = (0, uuid_1.v4)();
|
|
37
|
+
}
|
|
38
|
+
if ((0, shared_1.stringEmpty)(jti)) {
|
|
39
|
+
jti = (0, uuid_1.v4)();
|
|
40
|
+
sid = `${sid}.${jti}`;
|
|
41
|
+
}
|
|
42
|
+
const payload = Object.assign(Object.assign({ shop,
|
|
43
|
+
host,
|
|
44
|
+
iss,
|
|
45
|
+
dest,
|
|
46
|
+
jti,
|
|
47
|
+
sid,
|
|
48
|
+
aud }, sub && { sub }), body);
|
|
49
|
+
const hmac = (0, utils_1.generateHMAC)((0, shared_1.objectToSortedString)(payload), secret !== null && secret !== void 0 ? secret : APP_CONFIG.apiSecretKey);
|
|
50
|
+
token = (0, jsonwebtoken_1.sign)(payload, hmac, config);
|
|
32
51
|
}
|
|
33
|
-
|
|
34
|
-
|
|
52
|
+
catch (error) {
|
|
53
|
+
console.error('Error generating session token', error);
|
|
54
|
+
return res.status(500).json({ message: 'Error generating session token' });
|
|
35
55
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
const payload = Object.assign(Object.assign({ shop,
|
|
41
|
-
host,
|
|
42
|
-
iss,
|
|
43
|
-
dest,
|
|
44
|
-
jti,
|
|
45
|
-
sid,
|
|
46
|
-
aud }, sub && { sub }), body);
|
|
47
|
-
const hmac = (0, utils_1.generateHMAC)((0, shared_1.objectToSortedString)(payload), APP_CONFIG.apiSecretKey);
|
|
48
|
-
token = (0, jsonwebtoken_1.sign)(payload, hmac, config);
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
console.error('Error generating session token', error);
|
|
52
|
-
return res.status(500).json({ message: 'Error generating session token' });
|
|
53
|
-
}
|
|
54
|
-
return res.status(200).json({ token });
|
|
55
|
-
});
|
|
56
|
+
return res.status(200).json({ token });
|
|
57
|
+
});
|
|
58
|
+
};
|
|
56
59
|
exports.handleSessionToken = handleSessionToken;
|
|
57
60
|
//# sourceMappingURL=token.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token.js","sourceRoot":"","sources":["../../../../src/lib/handlers/api/token.js"],"names":[],"mappings":";;;;AAAA,gEAAiC;AACjC,yCAAkC;AAClC,+CAAmC;AACnC,+BAAmC;AAEnC,uCAA0C;AAC1C,4CAAmE;AAEnE,yCAAyC;AAClC,MAAM,kBAAkB,GAAG,CAAC,EAAE,UAAU,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"token.js","sourceRoot":"","sources":["../../../../src/lib/handlers/api/token.js"],"names":[],"mappings":";;;;AAAA,gEAAiC;AACjC,yCAAkC;AAClC,+CAAmC;AACnC,+BAAmC;AAEnC,uCAA0C;AAC1C,4CAAmE;AAEnE,yCAAyC;AAClC,MAAM,kBAAkB,GAAG,CAAC,EAAE,UAAU,EAAE,EAAE,KAAkC,EAAE,EAAE,EAAE;QAAxC,EAAE,QAAQ,EAAE,MAAM,OAAkB,EAAb,MAAM,sBAA7B,sBAA+B,CAAF;IAAY,OAAA,CAAO,GAAG,EAAE,GAAG,EAAE,EAAE;;QAC7G,MA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GAAG,GAAG,IAAA,SAAM,GAAE,CAAA;aACf;YAED,IAAI,IAAA,oBAAW,EAAC,GAAG,CAAC,EAAE;gBACpB,GAAG,GAAG,IAAA,SAAM,GAAE,CAAA;gBACd,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,EAAE,CAAA;aACtB;YAED,MAAM,OAAO,iCACX,IAAI;gBACJ,IAAI;gBACJ,GAAG;gBACH,IAAI;gBACJ,GAAG;gBACH,GAAG;gBACH,GAAG,IACA,GAAG,IAAI,EAAE,GAAG,EAAE,GACd,IAAI,CACR,CAAA;YAED,MAAM,IAAI,GAAG,IAAA,oBAAY,EAAC,IAAA,6BAAoB,EAAC,OAAO,CAAC,EAAE,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,UAAU,CAAC,YAAY,CAAC,CAAA;YAC3F,KAAK,GAAG,IAAA,mBAAI,EAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;SACpC;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,KAAK,CAAC,CAAA;YACtD,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,gCAAgC,EAAE,CAAC,CAAA;SAC3E;QAED,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,CAAA;IACxC,CAAC,CAAA,CAAA;CAAA,CAAA;AArEY,QAAA,kBAAkB,sBAqE9B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agnostack/next-shopify",
|
|
3
|
-
"version": "1.10.1-
|
|
3
|
+
"version": "1.10.1-beta.2",
|
|
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",
|