@agnostack/next-shopify 2.0.14-alpha.6 → 2.0.14-alpha.8
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.8](https://github.com/agnostack/next-shopify/compare/v2.0.14-alpha.7...v2.0.14-alpha.8) (2024-10-06)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* protect route mods ([b01c4b3](https://github.com/agnostack/next-shopify/commit/b01c4b3327db6aee58fd1c49882aa493cdb4d823))
|
|
7
|
+
|
|
8
|
+
## [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)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* debug ([428e094](https://github.com/agnostack/next-shopify/commit/428e094aacd8222a1910bf4d795eddc04a90d066))
|
|
14
|
+
|
|
1
15
|
## [2.0.14-alpha.6](https://github.com/agnostack/next-shopify/compare/v2.0.14-alpha.5...v2.0.14-alpha.6) (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;;;;;;;;;;;;;;GAqKN"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// import chalk from 'chalk'
|
|
2
3
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
4
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
5
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,92 +9,82 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
9
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
10
|
});
|
|
10
11
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
13
|
exports.protectRoute = void 0;
|
|
16
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
17
14
|
const utils_1 = require("../../utils");
|
|
18
15
|
const shared_1 = require("../../../shared");
|
|
19
16
|
const protectRoute = (serverRuntimeConfig, props) => {
|
|
20
|
-
const { PAGE_PATHS } = serverRuntimeConfig; // API_PATHS
|
|
17
|
+
const { PAGE_PATHS } = serverRuntimeConfig; // API_PATHS // PAYMENT_CONFIG
|
|
18
|
+
const prepareWebhookHandlers = (0, utils_1.getPrepareWebhookHandlers)(serverRuntimeConfig);
|
|
21
19
|
return ({ req, res, query, locale, } = {}, data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
20
|
var _a, _b, _c, _d;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const { session: offlineSession } = yield handleTokenExchange({ idToken: tokenContext });
|
|
54
|
-
console.info(`>>> ~ offlineSession`, offlineSession);
|
|
55
|
-
const { session: onlineSession } = yield handleTokenExchange({ idToken: tokenContext, isOnline: true });
|
|
56
|
-
console.info(`>>> ~ onlineSession`, onlineSession);
|
|
57
|
-
}
|
|
58
|
-
/*
|
|
59
|
-
const existingSessionIds = await findSessionIds(shop)
|
|
60
|
-
if (arrayEmpty(existingSessionIds)) {
|
|
61
|
-
// TODO: explore objectToQuerystring
|
|
62
|
-
const queryParams = new URLSearchParams({ ...query, shop }).toString()
|
|
63
|
-
|
|
64
|
-
return {
|
|
65
|
-
redirect: {
|
|
66
|
-
destination: `${API_PATHS[API_ROUTE_NAMES.AUTH_ONLINE]}?${queryParams}`,
|
|
67
|
-
permanent: false,
|
|
68
|
-
},
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (embedded !== '1') {
|
|
73
|
-
try {
|
|
74
|
-
// NOTE: this does not work if called INSIDE of embedded
|
|
75
|
-
await loadSession({ req, res })
|
|
76
|
-
|
|
77
|
-
const destination = await shopify.auth.getEmbeddedAppUrl({
|
|
78
|
-
rawRequest: req,
|
|
79
|
-
rawResponse: res,
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
return {
|
|
83
|
-
redirect: {
|
|
84
|
-
destination,
|
|
85
|
-
permanent: false,
|
|
86
|
-
},
|
|
21
|
+
try {
|
|
22
|
+
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;
|
|
23
|
+
// const embedded = query?.embedded ?? req.query?.embedded
|
|
24
|
+
const idToken = (_c = query === null || query === void 0 ? void 0 : query.id_token) !== null && _c !== void 0 ? _c : (_d = req.query) === null || _d === void 0 ? void 0 : _d.id_token;
|
|
25
|
+
if ((0, shared_1.stringEmpty)(shop)) {
|
|
26
|
+
return {
|
|
27
|
+
redirect: {
|
|
28
|
+
destination: `${PAGE_PATHS[shared_1.PAGE_ROUTE_NAMES.ERROR]}?code=no_shop_provided&type=protectRoute`,
|
|
29
|
+
permanent: false,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
// // NOTE: this should handle running in next to test non-shopify functionality
|
|
34
|
+
// const shouldBypassProtect = allowLocalBypass(serverRuntimeConfig)
|
|
35
|
+
// if (shouldBypassProtect) {
|
|
36
|
+
// console.info(`${chalk.yellowBright('next-shopify')} - [${chalk.bold('protectRoute')}]: ${
|
|
37
|
+
// `Bypassing local protect - should ONLY happen when running in next to test non-shopify functionality!`
|
|
38
|
+
// }`)
|
|
39
|
+
// return {
|
|
40
|
+
// props: cleanObject({
|
|
41
|
+
// locale,
|
|
42
|
+
// ...props,
|
|
43
|
+
// ...data,
|
|
44
|
+
// }, false, stringEmptyOnly),
|
|
45
|
+
// }
|
|
46
|
+
// }
|
|
47
|
+
// findSessionIds, loadSession,
|
|
48
|
+
const { shopify, loadAppData, encryptStoreSession, handleTokenExchange, } = yield (0, utils_1.getShopifyHelpers)(serverRuntimeConfig, { shop });
|
|
49
|
+
if (shopify === null || shopify === void 0 ? void 0 : shopify.config) {
|
|
50
|
+
res.setHeader('Content-Security-Policy', (0, utils_1.getSecurityHeader)(shop, shopify.config));
|
|
87
51
|
}
|
|
88
|
-
|
|
89
|
-
if (
|
|
52
|
+
// NOTE initial load
|
|
53
|
+
if ((0, shared_1.stringNotEmpty)(idToken)) {
|
|
54
|
+
const { session: _offlineSession } = yield handleTokenExchange({ idToken });
|
|
55
|
+
const offlineSession = _offlineSession.toObject();
|
|
56
|
+
console.info(`>>> ~ offlineSession`, offlineSession);
|
|
57
|
+
// const { session: onlineSession } = await handleTokenExchange({ idToken, isOnline: true })
|
|
58
|
+
// console.info(`>>> ~ onlineSession`, onlineSession)
|
|
59
|
+
yield encryptStoreSession(offlineSession);
|
|
60
|
+
let appId;
|
|
61
|
+
try {
|
|
62
|
+
const { appInfo } = yield loadAppData();
|
|
63
|
+
appId = (0, shared_1.normalizeShopifyId)(appInfo === null || appInfo === void 0 ? void 0 : appInfo.id).id;
|
|
64
|
+
// eslint-disable-next-line no-empty
|
|
65
|
+
}
|
|
66
|
+
catch (_ignore) {
|
|
67
|
+
console.info('Ignoring error loading appData', _ignore);
|
|
68
|
+
}
|
|
69
|
+
// Register webhooks
|
|
70
|
+
const webhookHandlers = prepareWebhookHandlers({ appId });
|
|
71
|
+
shopify.webhooks.addHandlers(webhookHandlers);
|
|
72
|
+
// NOTE: webhooks cannot use an online session to make API calls to Shopify (but not all webooks may be doing that for all apps)
|
|
73
|
+
yield shopify.webhooks.register({ session: offlineSession });
|
|
74
|
+
// if (PAYMENT_CONFIG?.required) {
|
|
75
|
+
// // NOTE: handleEnsureBilling handles calling encryptStoreSession for offline session when shouldCheckBilling
|
|
76
|
+
// const confirmationUrl = await handleEnsureBilling(session, reAuth)
|
|
77
|
+
// if (stringNotEmpty(confirmationUrl)) {
|
|
78
|
+
// redirectUrl = confirmationUrl
|
|
79
|
+
// }
|
|
80
|
+
// }
|
|
81
|
+
}
|
|
82
|
+
/*
|
|
83
|
+
const existingSessionIds = await findSessionIds(shop)
|
|
84
|
+
if (arrayEmpty(existingSessionIds)) {
|
|
90
85
|
// TODO: explore objectToQuerystring
|
|
91
|
-
const queryParams = new URLSearchParams({
|
|
92
|
-
|
|
93
|
-
shop,
|
|
94
|
-
reAuth: (error instanceof ShopifySessionAuthenticationError),
|
|
95
|
-
}).toString()
|
|
96
|
-
|
|
86
|
+
const queryParams = new URLSearchParams({ ...query, shop }).toString()
|
|
87
|
+
|
|
97
88
|
return {
|
|
98
89
|
redirect: {
|
|
99
90
|
destination: `${API_PATHS[API_ROUTE_NAMES.AUTH_ONLINE]}?${queryParams}`,
|
|
@@ -101,15 +92,57 @@ const protectRoute = (serverRuntimeConfig, props) => {
|
|
|
101
92
|
},
|
|
102
93
|
}
|
|
103
94
|
}
|
|
104
|
-
|
|
95
|
+
|
|
96
|
+
if (embedded !== '1') {
|
|
97
|
+
try {
|
|
98
|
+
// NOTE: this does not work if called INSIDE of embedded
|
|
99
|
+
await loadSession({ req, res })
|
|
100
|
+
|
|
101
|
+
const destination = await shopify.auth.getEmbeddedAppUrl({
|
|
102
|
+
rawRequest: req,
|
|
103
|
+
rawResponse: res,
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
redirect: {
|
|
108
|
+
destination,
|
|
109
|
+
permanent: false,
|
|
110
|
+
},
|
|
111
|
+
}
|
|
112
|
+
} catch (error) {
|
|
113
|
+
if (error instanceof ShopifyAuthenticationError) {
|
|
114
|
+
// TODO: explore objectToQuerystring
|
|
115
|
+
const queryParams = new URLSearchParams({
|
|
116
|
+
...query,
|
|
117
|
+
shop,
|
|
118
|
+
reAuth: (error instanceof ShopifySessionAuthenticationError),
|
|
119
|
+
}).toString()
|
|
105
120
|
|
|
106
|
-
|
|
107
|
-
|
|
121
|
+
return {
|
|
122
|
+
redirect: {
|
|
123
|
+
destination: `${API_PATHS[API_ROUTE_NAMES.AUTH_ONLINE]}?${queryParams}`,
|
|
124
|
+
permanent: false,
|
|
125
|
+
},
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
console.error('Error protecting route.', error)
|
|
129
|
+
|
|
130
|
+
throw error
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
*/
|
|
134
|
+
const foo = (0, shared_1.cleanObject)(Object.assign(Object.assign({ locale }, props), data), false, shared_1.stringEmptyOnly);
|
|
135
|
+
return {
|
|
136
|
+
props: foo,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
console.error(`>>> ~ error`, error);
|
|
141
|
+
const foo = (0, shared_1.cleanObject)(Object.assign(Object.assign({ locale }, props), data), false, shared_1.stringEmptyOnly);
|
|
142
|
+
return {
|
|
143
|
+
props: foo,
|
|
144
|
+
};
|
|
108
145
|
}
|
|
109
|
-
*/
|
|
110
|
-
return {
|
|
111
|
-
props: (0, shared_1.cleanObject)(Object.assign(Object.assign({ locale }, props), data), false, shared_1.stringEmptyOnly),
|
|
112
|
-
};
|
|
113
146
|
});
|
|
114
147
|
};
|
|
115
148
|
exports.protectRoute = protectRoute;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protect.js","sourceRoot":"","sources":["../../../../src/lib/handlers/ssr/protect.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"protect.js","sourceRoot":"","sources":["../../../../src/lib/handlers/ssr/protect.js"],"names":[],"mappings":";AAAA,4BAA4B;;;;;;;;;;;;AAE5B,uCAKoB;AACpB,4CAWwB;AAEjB,MAAM,YAAY,GAAG,CAAC,mBAAmB,EAAE,KAAK,EAAE,EAAE;IACzD,MAAM,EAAE,UAAU,EAAE,GAAG,mBAAmB,CAAA,CAAC,8BAA8B;IAEzE,MAAM,sBAAsB,GAAG,IAAA,iCAAyB,EAAC,mBAAmB,CAAC,CAAA;IAE7E,OAAO,CAAO,EACZ,GAAG,EACH,GAAG,EACH,KAAK,EACL,MAAM,GACP,GAAG,EAAE,EAAE,IAAI,EAAE,EAAE;;QACd,IAAI;YACF,MAAM,IAAI,GAAG,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,mCAAI,MAAA,GAAG,CAAC,KAAK,0CAAE,IAAI,CAAA;YAC3C,0DAA0D;YAC1D,MAAM,OAAO,GAAG,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,QAAQ,mCAAI,MAAA,GAAG,CAAC,KAAK,0CAAE,QAAQ,CAAA;YAEtD,IAAI,IAAA,oBAAW,EAAC,IAAI,CAAC,EAAE;gBACrB,OAAO;oBACL,QAAQ,EAAE;wBACR,WAAW,EAAE,GAAG,UAAU,CAAC,yBAAgB,CAAC,KAAK,CAAC,0CAA0C;wBAC5F,SAAS,EAAE,KAAK;qBACjB;iBACF,CAAA;aACF;YAED,gFAAgF;YAChF,oEAAoE;YACpE,6BAA6B;YAC7B,8FAA8F;YAC9F,6GAA6G;YAC7G,QAAQ;YAER,aAAa;YACb,2BAA2B;YAC3B,gBAAgB;YA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CAAC,CAAA;gBAC7C,gIAAgI;gBAChI,MAAM,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC,CAAA;gBAE5D,kCAAkC;gBAClC,iHAAiH;gBACjH,uEAAuE;gBAEvE,2CAA2C;gBAC3C,oCAAoC;gBACpC,MAAM;gBACN,IAAI;aAGL;YAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBAmDI;YAEJ,MAAM,GAAG,GAAG,IAAA,oBAAW,gCACrB,MAAM,IACH,KAAK,GACL,IAAI,GACN,KAAK,EAAE,wBAAe,CAAC,CAAA;YAE1B,OAAO;gBACL,KAAK,EAAE,GAAG;aACX,CAAA;SACF;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,KAAK,CAAC,aAAa,EAAE,KAAK,CAAC,CAAA;YACnC,MAAM,GAAG,GAAG,IAAA,oBAAW,gCACrB,MAAM,IACH,KAAK,GACL,IAAI,GACN,KAAK,EAAE,wBAAe,CAAC,CAAA;YAE1B,OAAO;gBACL,KAAK,EAAE,GAAG;aACX,CAAA;SACF;IACH,CAAC,CAAA,CAAA;AACH,CAAC,CAAA;AArKY,QAAA,YAAY,gBAqKxB"}
|
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.8",
|
|
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",
|