@scayle/storefront-core 7.60.1 → 7.62.0
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 +20 -6
- package/dist/rpc/methods/basket/basket.cjs +12 -4
- package/dist/rpc/methods/basket/basket.d.ts +1 -1
- package/dist/rpc/methods/basket/basket.mjs +31 -5
- package/dist/rpc/methods/checkout/checkout.cjs +1 -1
- package/dist/rpc/methods/checkout/checkout.d.ts +2 -1
- package/dist/rpc/methods/checkout/checkout.mjs +1 -1
- package/dist/rpc/methods/oauth/idp.cjs +3 -1
- package/dist/rpc/methods/oauth/idp.d.ts +1 -1
- package/dist/rpc/methods/oauth/idp.mjs +8 -2
- package/dist/rpc/methods/session.cjs +21 -7
- package/dist/rpc/methods/session.mjs +50 -8
- package/dist/rpc/methods/user.cjs +10 -8
- package/dist/rpc/methods/user.d.ts +3 -2
- package/dist/rpc/methods/user.mjs +27 -5
- package/dist/rpc/methods/wishlist.cjs +9 -3
- package/dist/rpc/methods/wishlist.d.ts +4 -3
- package/dist/rpc/methods/wishlist.mjs +22 -4
- package/dist/types/api/context.cjs +4 -0
- package/dist/types/api/context.d.ts +5 -0
- package/dist/types/api/context.mjs +3 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @scayle/storefront-core
|
|
2
2
|
|
|
3
|
+
## 7.62.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Return `ErrorResponse` from RPC when Session is missing
|
|
8
|
+
|
|
9
|
+
## 7.61.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- Add `sapiClient: StorefrontAPIClient` to `RpcContext`
|
|
14
|
+
|
|
15
|
+
Deprecate `bapiClient` in favour of `sapiClient`
|
|
16
|
+
|
|
3
17
|
## 7.60.1
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -220,8 +234,8 @@
|
|
|
220
234
|
|
|
221
235
|
```ts
|
|
222
236
|
const { data: externalIDPRedirects } = await useIDP({
|
|
223
|
-
queryParams: { redirectTo:
|
|
224
|
-
})
|
|
237
|
+
queryParams: { redirectTo: '/account' },
|
|
238
|
+
})
|
|
225
239
|
```
|
|
226
240
|
|
|
227
241
|
Please note that `code` and `state` are not supported as these are used by the SCAYLE Authentication API.
|
|
@@ -838,7 +852,7 @@
|
|
|
838
852
|
|
|
839
853
|
```js
|
|
840
854
|
env: {
|
|
841
|
-
SFC_OMIT_MD5: true
|
|
855
|
+
SFC_OMIT_MD5: true
|
|
842
856
|
}
|
|
843
857
|
```
|
|
844
858
|
|
|
@@ -846,7 +860,7 @@
|
|
|
846
860
|
|
|
847
861
|
```js
|
|
848
862
|
env: {
|
|
849
|
-
SFC_OMIT_MD5: process.env.SFC_OMIT_MD5
|
|
863
|
+
SFC_OMIT_MD5: process.env.SFC_OMIT_MD5
|
|
850
864
|
}
|
|
851
865
|
```
|
|
852
866
|
|
|
@@ -884,7 +898,7 @@
|
|
|
884
898
|
|
|
885
899
|
```js
|
|
886
900
|
env: {
|
|
887
|
-
SFC_OMIT_MD5: true
|
|
901
|
+
SFC_OMIT_MD5: true
|
|
888
902
|
}
|
|
889
903
|
```
|
|
890
904
|
|
|
@@ -892,7 +906,7 @@
|
|
|
892
906
|
|
|
893
907
|
```js
|
|
894
908
|
env: {
|
|
895
|
-
SFC_OMIT_MD5: process.env.SFC_OMIT_MD5
|
|
909
|
+
SFC_OMIT_MD5: process.env.SFC_OMIT_MD5
|
|
896
910
|
}
|
|
897
911
|
```
|
|
898
912
|
|
|
@@ -23,7 +23,9 @@ const addItemToBasket = exports.addItemToBasket = async function addItemToBasket
|
|
|
23
23
|
itemGroup,
|
|
24
24
|
with: _with
|
|
25
25
|
}, context) {
|
|
26
|
-
(0, _types.
|
|
26
|
+
if (!(0, _types.hasSession)(context)) {
|
|
27
|
+
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
28
|
+
}
|
|
27
29
|
const {
|
|
28
30
|
campaignKey,
|
|
29
31
|
bapiClient,
|
|
@@ -67,7 +69,9 @@ const addItemToBasket = exports.addItemToBasket = async function addItemToBasket
|
|
|
67
69
|
}
|
|
68
70
|
};
|
|
69
71
|
const addItemsToBasket = exports.addItemsToBasket = async function addItemsToBasket2(params, context) {
|
|
70
|
-
(0, _types.
|
|
72
|
+
if (!(0, _types.hasSession)(context)) {
|
|
73
|
+
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
74
|
+
}
|
|
71
75
|
const {
|
|
72
76
|
campaignKey,
|
|
73
77
|
bapiClient,
|
|
@@ -111,7 +115,9 @@ const addItemsToBasket = exports.addItemsToBasket = async function addItemsToBas
|
|
|
111
115
|
}
|
|
112
116
|
};
|
|
113
117
|
const getBasket = exports.getBasket = async function getBasket2(options, context) {
|
|
114
|
-
(0, _types.
|
|
118
|
+
if (!(0, _types.hasSession)(context)) {
|
|
119
|
+
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
120
|
+
}
|
|
115
121
|
const {
|
|
116
122
|
bapiClient,
|
|
117
123
|
campaignKey,
|
|
@@ -137,7 +143,9 @@ const getBasket = exports.getBasket = async function getBasket2(options, context
|
|
|
137
143
|
return response.basket;
|
|
138
144
|
};
|
|
139
145
|
const removeItemFromBasket = exports.removeItemFromBasket = async function removeItemFromBasket2(options, context) {
|
|
140
|
-
(0, _types.
|
|
146
|
+
if (!(0, _types.hasSession)(context)) {
|
|
147
|
+
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
148
|
+
}
|
|
141
149
|
const {
|
|
142
150
|
bapiClient,
|
|
143
151
|
campaignKey,
|
|
@@ -15,7 +15,7 @@ export declare const getBasket: (options: BasketWithOptions | undefined, context
|
|
|
15
15
|
export declare const removeItemFromBasket: (options: {
|
|
16
16
|
itemKey: string;
|
|
17
17
|
with?: BasketWithOptions;
|
|
18
|
-
}, context: RpcContext) => Promise<BasketResponseData<Product, Variant>>;
|
|
18
|
+
}, context: RpcContext) => Promise<ErrorResponse | BasketResponseData<Product, Variant>>;
|
|
19
19
|
export declare const clearBasket: (context: RpcContext) => Promise<true | ErrorResponse>;
|
|
20
20
|
export declare const mergeBaskets: ({ fromBasketKey, toBasketKey, with: _with }: {
|
|
21
21
|
fromBasketKey: string;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { ErrorResponse } from "../../../errors/index.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { hasSession } from "../../../types/index.mjs";
|
|
3
3
|
import {
|
|
4
4
|
ExistingItemHandling,
|
|
5
|
+
HttpStatusCode,
|
|
6
|
+
HttpStatusMessage,
|
|
5
7
|
MIN_WITH_PARAMS_BASKET
|
|
6
8
|
} from "../../../constants/index.mjs";
|
|
7
9
|
import { mergeBaskets as mergeBasketFunction } from "../../../utils/user.mjs";
|
|
@@ -20,7 +22,13 @@ export const addItemToBasket = async function addItemToBasket2({
|
|
|
20
22
|
itemGroup,
|
|
21
23
|
with: _with
|
|
22
24
|
}, context) {
|
|
23
|
-
|
|
25
|
+
if (!hasSession(context)) {
|
|
26
|
+
return new ErrorResponse(
|
|
27
|
+
HttpStatusCode.BAD_REQUEST,
|
|
28
|
+
HttpStatusMessage.BAD_REQUEST,
|
|
29
|
+
"No Session found"
|
|
30
|
+
);
|
|
31
|
+
}
|
|
24
32
|
const { campaignKey, bapiClient, basketKey } = context;
|
|
25
33
|
const resolvedWith = getWithParams(
|
|
26
34
|
{ with: _with },
|
|
@@ -67,7 +75,13 @@ export const addItemToBasket = async function addItemToBasket2({
|
|
|
67
75
|
}
|
|
68
76
|
};
|
|
69
77
|
export const addItemsToBasket = async function addItemsToBasket2(params, context) {
|
|
70
|
-
|
|
78
|
+
if (!hasSession(context)) {
|
|
79
|
+
return new ErrorResponse(
|
|
80
|
+
HttpStatusCode.BAD_REQUEST,
|
|
81
|
+
HttpStatusMessage.BAD_REQUEST,
|
|
82
|
+
"No Session found"
|
|
83
|
+
);
|
|
84
|
+
}
|
|
71
85
|
const { campaignKey, bapiClient, basketKey } = context;
|
|
72
86
|
const resolvedWith = getWithParams(params, context);
|
|
73
87
|
const itemsToBeAddedOrUpdated = params.items.map((item) => ({
|
|
@@ -114,7 +128,13 @@ export const addItemsToBasket = async function addItemsToBasket2(params, context
|
|
|
114
128
|
}
|
|
115
129
|
};
|
|
116
130
|
export const getBasket = async function getBasket2(options, context) {
|
|
117
|
-
|
|
131
|
+
if (!hasSession(context)) {
|
|
132
|
+
return new ErrorResponse(
|
|
133
|
+
HttpStatusCode.BAD_REQUEST,
|
|
134
|
+
HttpStatusMessage.BAD_REQUEST,
|
|
135
|
+
"No Session found"
|
|
136
|
+
);
|
|
137
|
+
}
|
|
118
138
|
const { bapiClient, campaignKey, basketKey } = context;
|
|
119
139
|
const resolvedWith = getWithParams(
|
|
120
140
|
{ with: options },
|
|
@@ -139,7 +159,13 @@ export const getBasket = async function getBasket2(options, context) {
|
|
|
139
159
|
return response.basket;
|
|
140
160
|
};
|
|
141
161
|
export const removeItemFromBasket = async function removeItemFromBasket2(options, context) {
|
|
142
|
-
|
|
162
|
+
if (!hasSession(context)) {
|
|
163
|
+
return new ErrorResponse(
|
|
164
|
+
HttpStatusCode.BAD_REQUEST,
|
|
165
|
+
HttpStatusMessage.BAD_REQUEST,
|
|
166
|
+
"No Session found"
|
|
167
|
+
);
|
|
168
|
+
}
|
|
143
169
|
const { bapiClient, campaignKey, basketKey } = context;
|
|
144
170
|
const resolvedWith = getWithParams(options, context);
|
|
145
171
|
return await bapiClient.basket.deleteItem(basketKey, options.itemKey, {
|
|
@@ -33,7 +33,7 @@ const getCheckoutToken = exports.getCheckoutToken = async function getCheckoutTo
|
|
|
33
33
|
carrier,
|
|
34
34
|
basketId: context.basketKey,
|
|
35
35
|
campaignKey: context.campaignKey
|
|
36
|
-
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"7.
|
|
36
|
+
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"7.62.0"}`).setProtectedHeader({
|
|
37
37
|
alg: "HS256",
|
|
38
38
|
typ: "JWT"
|
|
39
39
|
}).sign(secret);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ErrorResponse } from '../../../errors';
|
|
1
2
|
import type { RpcContext } from '../../../types';
|
|
2
3
|
interface CheckoutJwtPayload {
|
|
3
4
|
voucher?: string;
|
|
@@ -8,7 +9,7 @@ interface CheckoutJwtPayload {
|
|
|
8
9
|
};
|
|
9
10
|
carrier?: string;
|
|
10
11
|
}
|
|
11
|
-
export declare const getCheckoutToken: (jwtPayload: CheckoutJwtPayload | undefined, context: RpcContext) => Promise<
|
|
12
|
+
export declare const getCheckoutToken: (jwtPayload: CheckoutJwtPayload | undefined, context: RpcContext) => Promise<ErrorResponse | {
|
|
12
13
|
accessToken: string;
|
|
13
14
|
checkoutJwt: string;
|
|
14
15
|
}>;
|
|
@@ -27,7 +27,7 @@ export const getCheckoutToken = async function getCheckoutToken2(jwtPayload = {}
|
|
|
27
27
|
carrier,
|
|
28
28
|
basketId: context.basketKey,
|
|
29
29
|
campaignKey: context.campaignKey
|
|
30
|
-
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"7.
|
|
30
|
+
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"7.62.0"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
|
|
31
31
|
return {
|
|
32
32
|
accessToken: refreshedAccessToken,
|
|
33
33
|
checkoutJwt
|
|
@@ -47,7 +47,9 @@ const getExternalIdpRedirect = exports.getExternalIdpRedirect = async function g
|
|
|
47
47
|
return Object.fromEntries(results);
|
|
48
48
|
};
|
|
49
49
|
const handleIDPLoginCallback = exports.handleIDPLoginCallback = async function handleIDPLoginCallback2(payload, context) {
|
|
50
|
-
(0, _types.
|
|
50
|
+
if (!(0, _types.hasSession)(context)) {
|
|
51
|
+
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
52
|
+
}
|
|
51
53
|
const OAuthClient = (0, _oauth.getOAuthClient)(context);
|
|
52
54
|
const code = typeof payload === "string" ? payload : payload.code;
|
|
53
55
|
const tokens = await OAuthClient.generateToken(code);
|
|
@@ -7,6 +7,6 @@ export declare const getExternalIdpRedirect: ({ queryParams }: {
|
|
|
7
7
|
}>;
|
|
8
8
|
export declare const handleIDPLoginCallback: (payload: {
|
|
9
9
|
code: string;
|
|
10
|
-
} | string, context: RpcContext) => Promise<{
|
|
10
|
+
} | string, context: RpcContext) => Promise<ErrorResponse | {
|
|
11
11
|
message: string;
|
|
12
12
|
}>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SignJWT } from "jose";
|
|
2
2
|
import { ErrorResponse } from "../../../errors/index.mjs";
|
|
3
3
|
import { HttpStatusCode, HttpStatusMessage } from "../../../constants/index.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { hasSession } from "../../../types/index.mjs";
|
|
5
5
|
import { getOAuthClient } from "../../../api/oauth.mjs";
|
|
6
6
|
import { postLogin } from "../session.mjs";
|
|
7
7
|
export const getExternalIdpRedirect = async function getExternalIdpRedirect2({ queryParams }, context) {
|
|
@@ -46,7 +46,13 @@ export const getExternalIdpRedirect = async function getExternalIdpRedirect2({ q
|
|
|
46
46
|
return Object.fromEntries(results);
|
|
47
47
|
};
|
|
48
48
|
export const handleIDPLoginCallback = async function handleIDPLoginCallback2(payload, context) {
|
|
49
|
-
|
|
49
|
+
if (!hasSession(context)) {
|
|
50
|
+
return new ErrorResponse(
|
|
51
|
+
HttpStatusCode.BAD_REQUEST,
|
|
52
|
+
HttpStatusMessage.BAD_REQUEST,
|
|
53
|
+
"No Session found"
|
|
54
|
+
);
|
|
55
|
+
}
|
|
50
56
|
const OAuthClient = getOAuthClient(context);
|
|
51
57
|
const code = typeof payload === "string" ? payload : payload.code;
|
|
52
58
|
const tokens = await OAuthClient.generateToken(code);
|
|
@@ -46,7 +46,9 @@ async function postLogin(context, tokens) {
|
|
|
46
46
|
}, context);
|
|
47
47
|
}
|
|
48
48
|
const oauthLogin = async (login, context) => {
|
|
49
|
-
(0, _types.
|
|
49
|
+
if (!(0, _types.hasSession)(context)) {
|
|
50
|
+
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
51
|
+
}
|
|
50
52
|
const shopId = context.shopId;
|
|
51
53
|
const client = (0, _oauth.getOAuthClient)(context);
|
|
52
54
|
if (!login.email || !login.password) {
|
|
@@ -71,7 +73,9 @@ const oauthLogin = async (login, context) => {
|
|
|
71
73
|
};
|
|
72
74
|
exports.oauthLogin = oauthLogin;
|
|
73
75
|
const oauthRegister = async (register, context) => {
|
|
74
|
-
(0, _types.
|
|
76
|
+
if (!(0, _types.hasSession)(context)) {
|
|
77
|
+
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
78
|
+
}
|
|
75
79
|
const shopId = context.shopId;
|
|
76
80
|
const client = (0, _oauth.getOAuthClient)(context);
|
|
77
81
|
try {
|
|
@@ -93,7 +97,9 @@ const oauthRegister = async (register, context) => {
|
|
|
93
97
|
};
|
|
94
98
|
exports.oauthRegister = oauthRegister;
|
|
95
99
|
const oauthGuestLogin = async (guest, context) => {
|
|
96
|
-
(0, _types.
|
|
100
|
+
if (!(0, _types.hasSession)(context)) {
|
|
101
|
+
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
102
|
+
}
|
|
97
103
|
const shopId = context.shopId;
|
|
98
104
|
const client = (0, _oauth.getOAuthClient)(context);
|
|
99
105
|
try {
|
|
@@ -115,7 +121,9 @@ const oauthGuestLogin = async (guest, context) => {
|
|
|
115
121
|
};
|
|
116
122
|
exports.oauthGuestLogin = oauthGuestLogin;
|
|
117
123
|
const refreshAccessToken = async context => {
|
|
118
|
-
(0, _types.
|
|
124
|
+
if (!(0, _types.hasSession)(context)) {
|
|
125
|
+
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
126
|
+
}
|
|
119
127
|
const refreshToken = context.refreshToken;
|
|
120
128
|
const client = (0, _oauth.getOAuthClient)(context);
|
|
121
129
|
if (!refreshToken) {
|
|
@@ -145,7 +153,9 @@ const refreshAccessToken = async context => {
|
|
|
145
153
|
};
|
|
146
154
|
exports.refreshAccessToken = refreshAccessToken;
|
|
147
155
|
const oauthRevokeToken = async context => {
|
|
148
|
-
(0, _types.
|
|
156
|
+
if (!(0, _types.hasSession)(context)) {
|
|
157
|
+
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
158
|
+
}
|
|
149
159
|
const accessToken = context.accessToken;
|
|
150
160
|
if (!accessToken) {
|
|
151
161
|
return new _errors.ErrorResponse(_constants.HttpStatusCode.UNAUTHORIZED, _constants.HttpStatusMessage.UNAUTHORIZED, "No access token present");
|
|
@@ -177,7 +187,9 @@ exports.oauthRevokeToken = oauthRevokeToken;
|
|
|
177
187
|
const oauthForgetPassword = async ({
|
|
178
188
|
email
|
|
179
189
|
}, context) => {
|
|
180
|
-
(0, _types.
|
|
190
|
+
if (!(0, _types.hasSession)(context)) {
|
|
191
|
+
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
192
|
+
}
|
|
181
193
|
const shopId = context.shopId;
|
|
182
194
|
const client = (0, _oauth.getOAuthClient)(context);
|
|
183
195
|
try {
|
|
@@ -210,7 +222,9 @@ const oauthForgetPassword = async ({
|
|
|
210
222
|
};
|
|
211
223
|
exports.oauthForgetPassword = oauthForgetPassword;
|
|
212
224
|
const updatePasswordByHash = async (passwordHash, context) => {
|
|
213
|
-
(0, _types.
|
|
225
|
+
if (!(0, _types.hasSession)(context)) {
|
|
226
|
+
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
227
|
+
}
|
|
214
228
|
const shopId = context.shopId;
|
|
215
229
|
const client = (0, _oauth.getOAuthClient)(context);
|
|
216
230
|
try {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { decodeJwt } from "jose";
|
|
2
|
-
import {
|
|
2
|
+
import { hasSession } from "../../types/index.mjs";
|
|
3
3
|
import {
|
|
4
4
|
DEFAULT_WITH_LISTING,
|
|
5
5
|
HttpStatusCode,
|
|
@@ -58,7 +58,13 @@ export async function postLogin(context, tokens) {
|
|
|
58
58
|
}, context);
|
|
59
59
|
}
|
|
60
60
|
export const oauthLogin = async (login, context) => {
|
|
61
|
-
|
|
61
|
+
if (!hasSession(context)) {
|
|
62
|
+
return new ErrorResponse(
|
|
63
|
+
HttpStatusCode.BAD_REQUEST,
|
|
64
|
+
HttpStatusMessage.BAD_REQUEST,
|
|
65
|
+
"No Session found"
|
|
66
|
+
);
|
|
67
|
+
}
|
|
62
68
|
const shopId = context.shopId;
|
|
63
69
|
const client = getOAuthClient(context);
|
|
64
70
|
if (!login.email || !login.password) {
|
|
@@ -85,7 +91,13 @@ export const oauthLogin = async (login, context) => {
|
|
|
85
91
|
}
|
|
86
92
|
};
|
|
87
93
|
export const oauthRegister = async (register, context) => {
|
|
88
|
-
|
|
94
|
+
if (!hasSession(context)) {
|
|
95
|
+
return new ErrorResponse(
|
|
96
|
+
HttpStatusCode.BAD_REQUEST,
|
|
97
|
+
HttpStatusMessage.BAD_REQUEST,
|
|
98
|
+
"No Session found"
|
|
99
|
+
);
|
|
100
|
+
}
|
|
89
101
|
const shopId = context.shopId;
|
|
90
102
|
const client = getOAuthClient(context);
|
|
91
103
|
try {
|
|
@@ -108,7 +120,13 @@ export const oauthRegister = async (register, context) => {
|
|
|
108
120
|
}
|
|
109
121
|
};
|
|
110
122
|
export const oauthGuestLogin = async (guest, context) => {
|
|
111
|
-
|
|
123
|
+
if (!hasSession(context)) {
|
|
124
|
+
return new ErrorResponse(
|
|
125
|
+
HttpStatusCode.BAD_REQUEST,
|
|
126
|
+
HttpStatusMessage.BAD_REQUEST,
|
|
127
|
+
"No Session found"
|
|
128
|
+
);
|
|
129
|
+
}
|
|
112
130
|
const shopId = context.shopId;
|
|
113
131
|
const client = getOAuthClient(context);
|
|
114
132
|
try {
|
|
@@ -131,7 +149,13 @@ export const oauthGuestLogin = async (guest, context) => {
|
|
|
131
149
|
}
|
|
132
150
|
};
|
|
133
151
|
export const refreshAccessToken = async (context) => {
|
|
134
|
-
|
|
152
|
+
if (!hasSession(context)) {
|
|
153
|
+
return new ErrorResponse(
|
|
154
|
+
HttpStatusCode.BAD_REQUEST,
|
|
155
|
+
HttpStatusMessage.BAD_REQUEST,
|
|
156
|
+
"No Session found"
|
|
157
|
+
);
|
|
158
|
+
}
|
|
135
159
|
const refreshToken = context.refreshToken;
|
|
136
160
|
const client = getOAuthClient(context);
|
|
137
161
|
if (!refreshToken) {
|
|
@@ -163,7 +187,13 @@ export const refreshAccessToken = async (context) => {
|
|
|
163
187
|
}
|
|
164
188
|
};
|
|
165
189
|
export const oauthRevokeToken = async (context) => {
|
|
166
|
-
|
|
190
|
+
if (!hasSession(context)) {
|
|
191
|
+
return new ErrorResponse(
|
|
192
|
+
HttpStatusCode.BAD_REQUEST,
|
|
193
|
+
HttpStatusMessage.BAD_REQUEST,
|
|
194
|
+
"No Session found"
|
|
195
|
+
);
|
|
196
|
+
}
|
|
167
197
|
const accessToken = context.accessToken;
|
|
168
198
|
if (!accessToken) {
|
|
169
199
|
return new ErrorResponse(
|
|
@@ -196,7 +226,13 @@ export const oauthRevokeToken = async (context) => {
|
|
|
196
226
|
}
|
|
197
227
|
};
|
|
198
228
|
export const oauthForgetPassword = async ({ email }, context) => {
|
|
199
|
-
|
|
229
|
+
if (!hasSession(context)) {
|
|
230
|
+
return new ErrorResponse(
|
|
231
|
+
HttpStatusCode.BAD_REQUEST,
|
|
232
|
+
HttpStatusMessage.BAD_REQUEST,
|
|
233
|
+
"No Session found"
|
|
234
|
+
);
|
|
235
|
+
}
|
|
200
236
|
const shopId = context.shopId;
|
|
201
237
|
const client = getOAuthClient(context);
|
|
202
238
|
try {
|
|
@@ -233,7 +269,13 @@ export const oauthForgetPassword = async ({ email }, context) => {
|
|
|
233
269
|
}
|
|
234
270
|
};
|
|
235
271
|
export const updatePasswordByHash = async (passwordHash, context) => {
|
|
236
|
-
|
|
272
|
+
if (!hasSession(context)) {
|
|
273
|
+
return new ErrorResponse(
|
|
274
|
+
HttpStatusCode.BAD_REQUEST,
|
|
275
|
+
HttpStatusMessage.BAD_REQUEST,
|
|
276
|
+
"No Session found"
|
|
277
|
+
);
|
|
278
|
+
}
|
|
237
279
|
const shopId = context.shopId;
|
|
238
280
|
const client = getOAuthClient(context);
|
|
239
281
|
try {
|
|
@@ -7,6 +7,8 @@ exports.refreshUser = exports.getUser = exports.getAccessToken = exports.fetchUs
|
|
|
7
7
|
var _types = require("../../types/index.cjs");
|
|
8
8
|
var _customer = require("../../api/customer.cjs");
|
|
9
9
|
var _oauth = require("../../api/oauth.cjs");
|
|
10
|
+
var _constants = require("../../constants/index.cjs");
|
|
11
|
+
var _errors = require("../../errors/index.cjs");
|
|
10
12
|
const getUser = exports.getUser = function getUser2(context) {
|
|
11
13
|
const {
|
|
12
14
|
user,
|
|
@@ -42,7 +44,9 @@ const fetchUser = exports.fetchUser = async function fetchUser2({
|
|
|
42
44
|
return user;
|
|
43
45
|
};
|
|
44
46
|
const refreshUser = exports.refreshUser = async function refreshUser2(context) {
|
|
45
|
-
(0, _types.
|
|
47
|
+
if (!(0, _types.hasSession)(context)) {
|
|
48
|
+
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
49
|
+
}
|
|
46
50
|
const {
|
|
47
51
|
accessToken
|
|
48
52
|
} = context;
|
|
@@ -69,17 +73,15 @@ const refreshUser = exports.refreshUser = async function refreshUser2(context) {
|
|
|
69
73
|
const getAccessToken = exports.getAccessToken = async function getAccessToken2({
|
|
70
74
|
forceTokenRefresh = false
|
|
71
75
|
}, context) {
|
|
72
|
-
(0, _types.
|
|
76
|
+
if (!(0, _types.hasSession)(context)) {
|
|
77
|
+
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
78
|
+
}
|
|
73
79
|
if (!context.accessToken) {
|
|
74
|
-
return new
|
|
75
|
-
status: 401
|
|
76
|
-
});
|
|
80
|
+
return new _errors.ErrorResponse(_constants.HttpStatusCode.UNAUTHORIZED, _constants.HttpStatusMessage.UNAUTHORIZED, "No access token present");
|
|
77
81
|
}
|
|
78
82
|
if (forceTokenRefresh) {
|
|
79
83
|
if (!context.refreshToken) {
|
|
80
|
-
return new
|
|
81
|
-
status: 401
|
|
82
|
-
});
|
|
84
|
+
return new _errors.ErrorResponse(_constants.HttpStatusCode.UNAUTHORIZED, _constants.HttpStatusMessage.UNAUTHORIZED, "No refresh token present");
|
|
83
85
|
}
|
|
84
86
|
const client = (0, _oauth.getOAuthClient)(context);
|
|
85
87
|
const tokens = await client.refreshToken({
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { RpcContext, ShopUser } from '../../types';
|
|
2
|
+
import { ErrorResponse } from '../../errors';
|
|
2
3
|
declare const getUser: (context: RpcContext) => {
|
|
3
4
|
user: ShopUser | undefined;
|
|
4
5
|
};
|
|
@@ -11,12 +12,12 @@ declare const fetchUser: ({ accessToken }: {
|
|
|
11
12
|
* @param context
|
|
12
13
|
* @returns ShopUser
|
|
13
14
|
*/
|
|
14
|
-
declare const refreshUser: (context: RpcContext) => Promise<{
|
|
15
|
+
declare const refreshUser: (context: RpcContext) => Promise<ErrorResponse | {
|
|
15
16
|
user: undefined;
|
|
16
17
|
} | {
|
|
17
18
|
user: ShopUser;
|
|
18
19
|
}>;
|
|
19
20
|
declare const getAccessToken: ({ forceTokenRefresh }: {
|
|
20
21
|
forceTokenRefresh?: boolean;
|
|
21
|
-
}, context: RpcContext) => Promise<string |
|
|
22
|
+
}, context: RpcContext) => Promise<string | ErrorResponse>;
|
|
22
23
|
export { getUser, fetchUser, refreshUser, getAccessToken };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { hasSession } from "../../types/index.mjs";
|
|
2
2
|
import { CustomerAPIClient } from "../../api/customer.mjs";
|
|
3
3
|
import { getOAuthClient } from "../../api/oauth.mjs";
|
|
4
|
+
import { HttpStatusCode, HttpStatusMessage } from "../../constants/index.mjs";
|
|
5
|
+
import { ErrorResponse } from "../../errors/index.mjs";
|
|
4
6
|
const getUser = function getUser2(context) {
|
|
5
7
|
const { user, accessToken, shopId } = context;
|
|
6
8
|
if (user) {
|
|
@@ -28,7 +30,13 @@ const fetchUser = async function fetchUser2({ accessToken }, context) {
|
|
|
28
30
|
return user;
|
|
29
31
|
};
|
|
30
32
|
const refreshUser = async function refreshUser2(context) {
|
|
31
|
-
|
|
33
|
+
if (!hasSession(context)) {
|
|
34
|
+
return new ErrorResponse(
|
|
35
|
+
HttpStatusCode.BAD_REQUEST,
|
|
36
|
+
HttpStatusMessage.BAD_REQUEST,
|
|
37
|
+
"No Session found"
|
|
38
|
+
);
|
|
39
|
+
}
|
|
32
40
|
const { accessToken } = context;
|
|
33
41
|
if (!accessToken) {
|
|
34
42
|
return { user: void 0 };
|
|
@@ -43,13 +51,27 @@ const refreshUser = async function refreshUser2(context) {
|
|
|
43
51
|
}
|
|
44
52
|
};
|
|
45
53
|
const getAccessToken = async function getAccessToken2({ forceTokenRefresh = false }, context) {
|
|
46
|
-
|
|
54
|
+
if (!hasSession(context)) {
|
|
55
|
+
return new ErrorResponse(
|
|
56
|
+
HttpStatusCode.BAD_REQUEST,
|
|
57
|
+
HttpStatusMessage.BAD_REQUEST,
|
|
58
|
+
"No Session found"
|
|
59
|
+
);
|
|
60
|
+
}
|
|
47
61
|
if (!context.accessToken) {
|
|
48
|
-
return new
|
|
62
|
+
return new ErrorResponse(
|
|
63
|
+
HttpStatusCode.UNAUTHORIZED,
|
|
64
|
+
HttpStatusMessage.UNAUTHORIZED,
|
|
65
|
+
"No access token present"
|
|
66
|
+
);
|
|
49
67
|
}
|
|
50
68
|
if (forceTokenRefresh) {
|
|
51
69
|
if (!context.refreshToken) {
|
|
52
|
-
return new
|
|
70
|
+
return new ErrorResponse(
|
|
71
|
+
HttpStatusCode.UNAUTHORIZED,
|
|
72
|
+
HttpStatusMessage.UNAUTHORIZED,
|
|
73
|
+
"No refresh token present"
|
|
74
|
+
);
|
|
53
75
|
}
|
|
54
76
|
const client = getOAuthClient(context);
|
|
55
77
|
const tokens = await client.refreshToken({
|
|
@@ -12,7 +12,9 @@ function getWithParams(params, context) {
|
|
|
12
12
|
return params.with ?? context.withParams?.wishlist ?? _constants.MIN_WITH_PARAMS_WISHLIST;
|
|
13
13
|
}
|
|
14
14
|
const getWishlist = exports.getWishlist = async function getWishlist2(options, context) {
|
|
15
|
-
(0, _types.
|
|
15
|
+
if (!(0, _types.hasSession)(context)) {
|
|
16
|
+
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
17
|
+
}
|
|
16
18
|
const {
|
|
17
19
|
bapiClient,
|
|
18
20
|
campaignKey,
|
|
@@ -28,7 +30,9 @@ const getWishlist = exports.getWishlist = async function getWishlist2(options, c
|
|
|
28
30
|
});
|
|
29
31
|
};
|
|
30
32
|
const addItemToWishlist = exports.addItemToWishlist = async function addItemToWishlist2(options, context) {
|
|
31
|
-
(0, _types.
|
|
33
|
+
if (!(0, _types.hasSession)(context)) {
|
|
34
|
+
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
35
|
+
}
|
|
32
36
|
const {
|
|
33
37
|
bapiClient,
|
|
34
38
|
campaignKey,
|
|
@@ -70,7 +74,9 @@ const addItemToWishlist = exports.addItemToWishlist = async function addItemToWi
|
|
|
70
74
|
}
|
|
71
75
|
};
|
|
72
76
|
const removeItemFromWishlist = exports.removeItemFromWishlist = async function removeItemFromWishlist2(options, context) {
|
|
73
|
-
(0, _types.
|
|
77
|
+
if (!(0, _types.hasSession)(context)) {
|
|
78
|
+
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
79
|
+
}
|
|
74
80
|
const {
|
|
75
81
|
bapiClient,
|
|
76
82
|
campaignKey,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Wishlist } from '@scayle/storefront-api';
|
|
2
2
|
import type { RpcContext, WishlistWithOptions } from '../../types';
|
|
3
|
-
|
|
3
|
+
import { ErrorResponse } from '../../errors';
|
|
4
|
+
export declare const getWishlist: (options: WishlistWithOptions | undefined, context: RpcContext) => Promise<ErrorResponse | Wishlist>;
|
|
4
5
|
export declare const addItemToWishlist: (options: {
|
|
5
6
|
variantId?: number;
|
|
6
7
|
productId?: number;
|
|
@@ -9,5 +10,5 @@ export declare const addItemToWishlist: (options: {
|
|
|
9
10
|
export declare const removeItemFromWishlist: (options: {
|
|
10
11
|
itemKey: string;
|
|
11
12
|
with?: WishlistWithOptions;
|
|
12
|
-
}, context: RpcContext) => Promise<Wishlist>;
|
|
13
|
-
export declare const clearWishlist: (context: RpcContext) => Promise<Wishlist>;
|
|
13
|
+
}, context: RpcContext) => Promise<ErrorResponse | Wishlist>;
|
|
14
|
+
export declare const clearWishlist: (context: RpcContext) => Promise<ErrorResponse | Wishlist>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { hasSession } from "../../types/index.mjs";
|
|
2
2
|
import {
|
|
3
3
|
HttpStatusCode,
|
|
4
4
|
HttpStatusMessage,
|
|
@@ -10,7 +10,13 @@ function getWithParams(params, context) {
|
|
|
10
10
|
return params.with ?? context.withParams?.wishlist ?? MIN_WITH_PARAMS_WISHLIST;
|
|
11
11
|
}
|
|
12
12
|
export const getWishlist = async function getWishlist2(options, context) {
|
|
13
|
-
|
|
13
|
+
if (!hasSession(context)) {
|
|
14
|
+
return new ErrorResponse(
|
|
15
|
+
HttpStatusCode.BAD_REQUEST,
|
|
16
|
+
HttpStatusMessage.BAD_REQUEST,
|
|
17
|
+
"No Session found"
|
|
18
|
+
);
|
|
19
|
+
}
|
|
14
20
|
const { bapiClient, campaignKey, wishlistKey } = context;
|
|
15
21
|
const resolvedWith = getWithParams({ with: options }, context);
|
|
16
22
|
return await bapiClient.wishlist.get(wishlistKey, {
|
|
@@ -20,7 +26,13 @@ export const getWishlist = async function getWishlist2(options, context) {
|
|
|
20
26
|
});
|
|
21
27
|
};
|
|
22
28
|
export const addItemToWishlist = async function addItemToWishlist2(options, context) {
|
|
23
|
-
|
|
29
|
+
if (!hasSession(context)) {
|
|
30
|
+
return new ErrorResponse(
|
|
31
|
+
HttpStatusCode.BAD_REQUEST,
|
|
32
|
+
HttpStatusMessage.BAD_REQUEST,
|
|
33
|
+
"No Session found"
|
|
34
|
+
);
|
|
35
|
+
}
|
|
24
36
|
const { bapiClient, campaignKey, wishlistKey } = context;
|
|
25
37
|
const { productId, variantId } = options;
|
|
26
38
|
const resolvedWith = getWithParams(options, context);
|
|
@@ -50,7 +62,13 @@ export const addItemToWishlist = async function addItemToWishlist2(options, cont
|
|
|
50
62
|
}
|
|
51
63
|
};
|
|
52
64
|
export const removeItemFromWishlist = async function removeItemFromWishlist2(options, context) {
|
|
53
|
-
|
|
65
|
+
if (!hasSession(context)) {
|
|
66
|
+
return new ErrorResponse(
|
|
67
|
+
HttpStatusCode.BAD_REQUEST,
|
|
68
|
+
HttpStatusMessage.BAD_REQUEST,
|
|
69
|
+
"No Session found"
|
|
70
|
+
);
|
|
71
|
+
}
|
|
54
72
|
const { bapiClient, campaignKey, wishlistKey } = context;
|
|
55
73
|
const resolvedWith = getWithParams(options, context);
|
|
56
74
|
return await bapiClient.wishlist.deleteItem(wishlistKey, options.itemKey, {
|
|
@@ -4,8 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.assertSession = assertSession;
|
|
7
|
+
exports.hasSession = hasSession;
|
|
7
8
|
function assertSession(context) {
|
|
8
9
|
if (!context.sessionId) {
|
|
9
10
|
throw new Error("No session for RpcContext available");
|
|
10
11
|
}
|
|
12
|
+
}
|
|
13
|
+
function hasSession(context) {
|
|
14
|
+
return !!context.sessionId;
|
|
11
15
|
}
|
|
@@ -72,7 +72,11 @@ export type RpcContext = {
|
|
|
72
72
|
*/
|
|
73
73
|
cbdExpiration?: number;
|
|
74
74
|
};
|
|
75
|
+
/**
|
|
76
|
+
* @deprecated bapiClient got renamed. Use {@link RpcContext.sapiClient} from now on.
|
|
77
|
+
*/
|
|
75
78
|
bapiClient: StorefrontAPIClient;
|
|
79
|
+
sapiClient?: StorefrontAPIClient;
|
|
76
80
|
cached: CachedType;
|
|
77
81
|
/**
|
|
78
82
|
* @deprecated this flag will be removed in a future release.
|
|
@@ -106,4 +110,5 @@ export type RpcContext = {
|
|
|
106
110
|
} & AdditionalRpcContext & (ContextWithoutSession | ContextWithSession);
|
|
107
111
|
export type RpcContextWithSession = RpcContext & ContextWithSession;
|
|
108
112
|
export declare function assertSession(context: RpcContext): asserts context is RpcContextWithSession;
|
|
113
|
+
export declare function hasSession(context: RpcContext): context is RpcContextWithSession;
|
|
109
114
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scayle/storefront-core",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.62.0",
|
|
4
4
|
"description": "Collection of essential utilities to work with the Storefront API",
|
|
5
5
|
"author": "SCAYLE Commerce Engine",
|
|
6
6
|
"license": "MIT",
|
|
@@ -74,17 +74,17 @@
|
|
|
74
74
|
"@types/crypto-js": "4.2.2",
|
|
75
75
|
"@types/node": "20.14.11",
|
|
76
76
|
"@types/webpack-env": "1.18.5",
|
|
77
|
-
"@vitest/coverage-v8": "2.0.
|
|
77
|
+
"@vitest/coverage-v8": "2.0.4",
|
|
78
78
|
"dprint": "0.47.2",
|
|
79
79
|
"eslint": "9.7.0",
|
|
80
80
|
"eslint-formatter-gitlab": "5.1.0",
|
|
81
81
|
"publint": "0.2.9",
|
|
82
82
|
"rimraf": "6.0.1",
|
|
83
83
|
"ts-node": "10.9.2",
|
|
84
|
-
"typescript": "5.5.
|
|
84
|
+
"typescript": "5.5.4",
|
|
85
85
|
"unbuild": "2.0.0",
|
|
86
86
|
"unstorage": "1.10.2",
|
|
87
|
-
"vitest": "2.0.
|
|
87
|
+
"vitest": "2.0.4"
|
|
88
88
|
},
|
|
89
89
|
"optionalDependencies": {
|
|
90
90
|
"redis": "4"
|