@agnostack/next-shopify 2.0.14-alpha.7 → 2.0.14-alpha.9
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
|
+
## [2.0.14-alpha.9](https://github.com/agnostack/next-shopify/compare/v2.0.14-alpha.8...v2.0.14-alpha.9) (2024-10-06)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* protect route mods ([dadc019](https://github.com/agnostack/next-shopify/commit/dadc01900f7e449bf6dc11acc30415fd920ecd39))
|
|
7
|
+
|
|
8
|
+
## [2.0.14-alpha.8](https://github.com/agnostack/next-shopify/compare/v2.0.14-alpha.7...v2.0.14-alpha.8) (2024-10-06)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* protect route mods ([b01c4b3](https://github.com/agnostack/next-shopify/commit/b01c4b3327db6aee58fd1c49882aa493cdb4d823))
|
|
14
|
+
|
|
1
15
|
## [2.0.14-alpha.7](https://github.com/agnostack/next-shopify/compare/v2.0.14-alpha.6...v2.0.14-alpha.7) (2024-10-06)
|
|
2
16
|
|
|
3
17
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protect.d.ts","sourceRoot":"","sources":["../../../../src/lib/handlers/ssr/protect.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"protect.d.ts","sourceRoot":"","sources":["../../../../src/lib/handlers/ssr/protect.js"],"names":[],"mappings":"AAqBO;;;;;;;;;;;;;;GAqJN"}
|
|
@@ -17,12 +17,13 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
17
17
|
const utils_1 = require("../../utils");
|
|
18
18
|
const shared_1 = require("../../../shared");
|
|
19
19
|
const protectRoute = (serverRuntimeConfig, props) => {
|
|
20
|
-
const { PAGE_PATHS } = serverRuntimeConfig; //
|
|
20
|
+
const { PAGE_PATHS, API_PATHS } = serverRuntimeConfig; // PAYMENT_CONFIG
|
|
21
|
+
const prepareWebhookHandlers = (0, utils_1.getPrepareWebhookHandlers)(serverRuntimeConfig);
|
|
21
22
|
return ({ req, res, query, locale, } = {}, data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
-
var _a, _b, _c, _d;
|
|
23
|
+
var _a, _b, _c, _d, _e, _f;
|
|
23
24
|
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;
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
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;
|
|
26
|
+
const idToken = (_e = query === null || query === void 0 ? void 0 : query.id_token) !== null && _e !== void 0 ? _e : (_f = req.query) === null || _f === void 0 ? void 0 : _f.id_token;
|
|
26
27
|
if ((0, shared_1.stringEmpty)(shop)) {
|
|
27
28
|
return {
|
|
28
29
|
redirect: {
|
|
@@ -39,76 +40,86 @@ const protectRoute = (serverRuntimeConfig, props) => {
|
|
|
39
40
|
props: (0, shared_1.cleanObject)(Object.assign(Object.assign({ locale }, props), data), false, shared_1.stringEmptyOnly),
|
|
40
41
|
};
|
|
41
42
|
}
|
|
42
|
-
|
|
43
|
-
const { shopify, handleTokenExchange } = yield (0, utils_1.getShopifyHelpers)(serverRuntimeConfig, { shop });
|
|
43
|
+
const { shopify, loadAppData, loadSession, findSessionIds, handleTokenExchange, encryptStoreSession, } = yield (0, utils_1.getShopifyHelpers)(serverRuntimeConfig, { shop });
|
|
44
44
|
if (shopify === null || shopify === void 0 ? void 0 : shopify.config) {
|
|
45
45
|
res.setHeader('Content-Security-Policy', (0, utils_1.getSecurityHeader)(shop, shopify.config));
|
|
46
46
|
}
|
|
47
|
-
const shopContext = (_c = data === null || data === void 0 ? void 0 : data.query) === null || _c === void 0 ? void 0 : _c.shop;
|
|
48
|
-
console.info(`>>> ~ shopContext`, shopContext);
|
|
49
|
-
const tokenContext = (_d = data === null || data === void 0 ? void 0 : data.query) === null || _d === void 0 ? void 0 : _d.id_token;
|
|
50
|
-
console.info(`>>> ~ tokenContext`, tokenContext);
|
|
51
47
|
// NOTE initial load
|
|
52
|
-
if ((
|
|
53
|
-
const { session:
|
|
48
|
+
if ((embedded === 1) && (0, shared_1.stringNotEmpty)(idToken)) {
|
|
49
|
+
const { session: _offlineSession } = yield handleTokenExchange({ idToken });
|
|
50
|
+
const offlineSession = _offlineSession.toObject();
|
|
54
51
|
console.info(`>>> ~ offlineSession`, offlineSession);
|
|
55
|
-
const { session: onlineSession } =
|
|
56
|
-
console.info(`>>> ~ onlineSession`, onlineSession)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
52
|
+
// const { session: onlineSession } = await handleTokenExchange({ idToken, isOnline: true })
|
|
53
|
+
// console.info(`>>> ~ onlineSession`, onlineSession)
|
|
54
|
+
yield encryptStoreSession(offlineSession);
|
|
55
|
+
let appId;
|
|
56
|
+
try {
|
|
57
|
+
const { appInfo } = yield loadAppData();
|
|
58
|
+
appId = (0, shared_1.normalizeShopifyId)(appInfo === null || appInfo === void 0 ? void 0 : appInfo.id).id;
|
|
59
|
+
// eslint-disable-next-line no-empty
|
|
60
|
+
}
|
|
61
|
+
catch (_ignore) {
|
|
62
|
+
console.info('Ignoring error loading appData', _ignore);
|
|
63
|
+
}
|
|
64
|
+
// Register webhooks
|
|
65
|
+
const webhookHandlers = prepareWebhookHandlers({ appId });
|
|
66
|
+
shopify.webhooks.addHandlers(webhookHandlers);
|
|
67
|
+
// NOTE: webhooks cannot use an online session to make API calls to Shopify (but not all webooks may be doing that for all apps)
|
|
68
|
+
yield shopify.webhooks.register({ session: offlineSession });
|
|
69
|
+
// if (PAYMENT_CONFIG?.required) {
|
|
70
|
+
// // NOTE: handleEnsureBilling handles calling encryptStoreSession for offline session when shouldCheckBilling
|
|
71
|
+
// const confirmationUrl = await handleEnsureBilling(session, reAuth)
|
|
72
|
+
// if (stringNotEmpty(confirmationUrl)) {
|
|
73
|
+
// redirectUrl = confirmationUrl
|
|
74
|
+
// }
|
|
75
|
+
// }
|
|
70
76
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return {
|
|
83
|
-
redirect: {
|
|
84
|
-
destination,
|
|
85
|
-
permanent: false,
|
|
86
|
-
},
|
|
77
|
+
else {
|
|
78
|
+
const existingSessionIds = yield findSessionIds(shop);
|
|
79
|
+
if ((0, shared_1.arrayEmpty)(existingSessionIds)) {
|
|
80
|
+
// TODO: explore objectToQuerystring
|
|
81
|
+
const queryParams = new URLSearchParams(Object.assign(Object.assign({}, query), { shop })).toString();
|
|
82
|
+
return {
|
|
83
|
+
redirect: {
|
|
84
|
+
destination: `${API_PATHS[shared_1.API_ROUTE_NAMES.AUTH_ONLINE]}?${queryParams}`,
|
|
85
|
+
permanent: false,
|
|
86
|
+
},
|
|
87
|
+
};
|
|
87
88
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
89
|
+
if (embedded !== '1') {
|
|
90
|
+
try {
|
|
91
|
+
// NOTE: this does not work if called INSIDE of embedded
|
|
92
|
+
yield loadSession({ req, res });
|
|
93
|
+
const destination = yield shopify.auth.getEmbeddedAppUrl({
|
|
94
|
+
rawRequest: req,
|
|
95
|
+
rawResponse: res,
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
redirect: {
|
|
99
|
+
destination,
|
|
100
|
+
permanent: false,
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
if (error instanceof shared_1.ShopifyAuthenticationError) {
|
|
106
|
+
// TODO: explore objectToQuerystring
|
|
107
|
+
const queryParams = new URLSearchParams(Object.assign(Object.assign({}, query), { shop, reAuth: (error instanceof shared_1.ShopifySessionAuthenticationError) })).toString();
|
|
108
|
+
return {
|
|
109
|
+
redirect: {
|
|
110
|
+
destination: `${API_PATHS[shared_1.API_ROUTE_NAMES.AUTH_ONLINE]}?${queryParams}`,
|
|
111
|
+
permanent: false,
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
console.error('Error protecting route.', error);
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
103
118
|
}
|
|
104
|
-
console.error('Error protecting route.', error)
|
|
105
|
-
|
|
106
|
-
throw error
|
|
107
|
-
}
|
|
108
119
|
}
|
|
109
|
-
|
|
120
|
+
const foo = (0, shared_1.cleanObject)(Object.assign(Object.assign({ locale }, props), data), false, shared_1.stringEmptyOnly);
|
|
110
121
|
return {
|
|
111
|
-
props:
|
|
122
|
+
props: foo,
|
|
112
123
|
};
|
|
113
124
|
});
|
|
114
125
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protect.js","sourceRoot":"","sources":["../../../../src/lib/handlers/ssr/protect.js"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAAyB;AAEzB,
|
|
1
|
+
{"version":3,"file":"protect.js","sourceRoot":"","sources":["../../../../src/lib/handlers/ssr/protect.js"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAAyB;AAEzB,uCAKoB;AACpB,4CAWwB;AAEjB,MAAM,YAAY,GAAG,CAAC,mBAAmB,EAAE,KAAK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CAAC,WAAW,CAAC,IAAI,WAAW,EAAE;gCACvE,SAAS,EAAE,KAAK;6BACjB;yBACF,CAAA;qBACF;oBACD,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAA;oBAE/C,MAAM,KAAK,CAAA;iBACZ;aACF;SACF;QAED,MAAM,GAAG,GAAG,IAAA,oBAAW,gCACrB,MAAM,IACH,KAAK,GACL,IAAI,GACN,KAAK,EAAE,wBAAe,CAAC,CAAA;QAE1B,OAAO;YACL,KAAK,EAAE,GAAG;SACX,CAAA;IACH,CAAC,CAAA,CAAA;AACH,CAAC,CAAA;AArJY,QAAA,YAAY,gBAqJxB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agnostack/next-shopify",
|
|
3
|
-
"version": "2.0.14-alpha.
|
|
3
|
+
"version": "2.0.14-alpha.9",
|
|
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",
|