@unchainedshop/api 4.8.11 → 4.8.13
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/lib/loaders/cartLoader.d.ts +13 -0
- package/lib/loaders/cartLoader.js +8 -0
- package/lib/loaders/index.d.ts +9 -0
- package/lib/loaders/index.js +2 -0
- package/lib/middleware/createAuthMiddleware.js +1 -3
- package/lib/resolvers/type/user-types.d.ts +1 -1
- package/lib/resolvers/type/user-types.js +2 -2
- package/lib/schema/types/user.js +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { UnchainedCore } from '@unchainedshop/core';
|
|
2
|
+
import type { Order } from '@unchainedshop/core-orders';
|
|
3
|
+
import DataLoader from 'dataloader';
|
|
4
|
+
declare const _default: (unchainedAPI: UnchainedCore) => DataLoader<{
|
|
5
|
+
userId: string;
|
|
6
|
+
countryCode?: string;
|
|
7
|
+
orderNumber?: string;
|
|
8
|
+
}, Order | null, {
|
|
9
|
+
userId: string;
|
|
10
|
+
countryCode?: string;
|
|
11
|
+
orderNumber?: string;
|
|
12
|
+
}>;
|
|
13
|
+
export default _default;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import DataLoader from 'dataloader';
|
|
2
|
+
export default (unchainedAPI) => new DataLoader(async (queries) => {
|
|
3
|
+
const userIds = [...new Set(queries.map((q) => q.userId).filter(Boolean))];
|
|
4
|
+
const carts = await unchainedAPI.modules.orders.findCarts({ userIds });
|
|
5
|
+
return queries.map((q) => carts.find((cart) => cart.userId === q.userId &&
|
|
6
|
+
(!q.countryCode || cart.countryCode === q.countryCode) &&
|
|
7
|
+
(!q.orderNumber || cart.orderNumber === q.orderNumber)) || null);
|
|
8
|
+
});
|
package/lib/loaders/index.d.ts
CHANGED
|
@@ -166,6 +166,15 @@ declare const loaders: (unchainedAPI: UnchainedCore) => {
|
|
|
166
166
|
}, import("@unchainedshop/core-orders").Order, {
|
|
167
167
|
orderId: string;
|
|
168
168
|
}>;
|
|
169
|
+
cartLoader: import("dataloader")<{
|
|
170
|
+
userId: string;
|
|
171
|
+
countryCode?: string;
|
|
172
|
+
orderNumber?: string;
|
|
173
|
+
}, import("@unchainedshop/core-orders").Order | null, {
|
|
174
|
+
userId: string;
|
|
175
|
+
countryCode?: string;
|
|
176
|
+
orderNumber?: string;
|
|
177
|
+
}>;
|
|
169
178
|
orderPaymentLoader: import("dataloader")<{
|
|
170
179
|
orderPaymentId: string;
|
|
171
180
|
}, import("@unchainedshop/core-orders").OrderPayment | null, {
|
package/lib/loaders/index.js
CHANGED
|
@@ -26,6 +26,7 @@ import deliveryProviderLoader from "./deliveryProviderLoader.js";
|
|
|
26
26
|
import paymentProviderLoader from "./paymentProviderLoader.js";
|
|
27
27
|
import warehousingProviderLoader from "./warehousingProviderLoader.js";
|
|
28
28
|
import orderLoader from "./orderLoader.js";
|
|
29
|
+
import cartLoader from "./cartLoader.js";
|
|
29
30
|
import orderPaymentLoader from "./orderPaymentLoader.js";
|
|
30
31
|
import orderDeliveryLoader from "./orderDeliveryLoader.js";
|
|
31
32
|
import orderPositionsLoader from "./orderPositionsLoader.js";
|
|
@@ -63,6 +64,7 @@ const loaders = (unchainedAPI) => {
|
|
|
63
64
|
paymentProviderLoader: paymentProviderLoader(unchainedAPI),
|
|
64
65
|
warehousingProviderLoader: warehousingProviderLoader(unchainedAPI),
|
|
65
66
|
orderLoader: orderLoader(unchainedAPI),
|
|
67
|
+
cartLoader: cartLoader(unchainedAPI),
|
|
66
68
|
orderPaymentLoader: orderPaymentLoader(unchainedAPI),
|
|
67
69
|
orderDeliveryLoader: orderDeliveryLoader(unchainedAPI),
|
|
68
70
|
orderPositionsLoader: orderPositionsLoader(unchainedAPI),
|
|
@@ -65,9 +65,8 @@ export async function createAuthContext(params, authConfig) {
|
|
|
65
65
|
const fingerprintCookie = getCookie(UNCHAINED_FINGERPRINT_COOKIE_NAME);
|
|
66
66
|
const verifyToken = createAuthHandler(authConfig);
|
|
67
67
|
const authResult = token ? await verifyToken(token) : {};
|
|
68
|
-
let fingerprintValid = true;
|
|
69
68
|
if (authResult.fingerprintHash && fingerprintCookie) {
|
|
70
|
-
fingerprintValid = verifyFingerprint(fingerprintCookie, authResult.fingerprintHash);
|
|
69
|
+
const fingerprintValid = verifyFingerprint(fingerprintCookie, authResult.fingerprintHash);
|
|
71
70
|
if (!fingerprintValid) {
|
|
72
71
|
logger.warn('Token sidejacking detected: fingerprint mismatch', {
|
|
73
72
|
userId: authResult.userId,
|
|
@@ -81,7 +80,6 @@ export async function createAuthContext(params, authConfig) {
|
|
|
81
80
|
logger.warn('Token sidejacking detected: fingerprint cookie missing', {
|
|
82
81
|
userId: authResult.userId,
|
|
83
82
|
});
|
|
84
|
-
fingerprintValid = false;
|
|
85
83
|
authResult.userId = undefined;
|
|
86
84
|
authResult.tokenVersion = undefined;
|
|
87
85
|
authResult.impersonatorId = undefined;
|
|
@@ -49,9 +49,9 @@ export const User = {
|
|
|
49
49
|
return context.modules.bookmarks.findBookmarksByUserId(user._id);
|
|
50
50
|
},
|
|
51
51
|
async cart(user, params, context) {
|
|
52
|
-
const {
|
|
52
|
+
const { loaders, countryCode } = context;
|
|
53
53
|
await checkAction(context, viewUserOrders, [user, params]);
|
|
54
|
-
return
|
|
54
|
+
return loaders.cartLoader.load({
|
|
55
55
|
countryCode,
|
|
56
56
|
orderNumber: params.orderNumber,
|
|
57
57
|
userId: user._id,
|
package/lib/schema/types/user.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/api",
|
|
3
3
|
"description": "GraphQL API layer for the Unchained Engine with Express/Fastify adapters and MCP server",
|
|
4
|
-
"version": "4.8.
|
|
4
|
+
"version": "4.8.13",
|
|
5
5
|
"main": "lib/api-index.js",
|
|
6
6
|
"types": "lib/api-index.d.ts",
|
|
7
7
|
"type": "module",
|
|
@@ -116,11 +116,11 @@
|
|
|
116
116
|
}
|
|
117
117
|
},
|
|
118
118
|
"dependencies": {
|
|
119
|
-
"@unchainedshop/core": "^4.
|
|
120
|
-
"@unchainedshop/events": "^4.
|
|
121
|
-
"@unchainedshop/logger": "^4.
|
|
122
|
-
"@unchainedshop/roles": "^4.
|
|
123
|
-
"@unchainedshop/utils": "^4.
|
|
119
|
+
"@unchainedshop/core": "^4.8.12",
|
|
120
|
+
"@unchainedshop/events": "^4.8.12",
|
|
121
|
+
"@unchainedshop/logger": "^4.8.12",
|
|
122
|
+
"@unchainedshop/roles": "^4.8.12",
|
|
123
|
+
"@unchainedshop/utils": "^4.8.12",
|
|
124
124
|
"dataloader": "^2.2.3",
|
|
125
125
|
"expiry-map": "^2.0.0",
|
|
126
126
|
"graphql-scalars": "^1.24.2",
|