@scayle/storefront-core 8.4.0 → 8.5.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 +16 -0
- package/dist/rpc/methods/checkout/checkout.mjs +1 -1
- package/dist/rpc/methods/search.d.ts +22 -0
- package/package.json +9 -19
- package/dist/api/customer.cjs +0 -164
- package/dist/api/oauth.cjs +0 -238
- package/dist/cache/cache.cjs +0 -1
- package/dist/cache/cached.cjs +0 -90
- package/dist/cache/index.cjs +0 -27
- package/dist/cache/providers/unstorage.cjs +0 -55
- package/dist/constants/basket.cjs +0 -26
- package/dist/constants/cache.cjs +0 -7
- package/dist/constants/hash.cjs +0 -11
- package/dist/constants/httpStatus.cjs +0 -634
- package/dist/constants/index.cjs +0 -93
- package/dist/constants/product.cjs +0 -10
- package/dist/constants/promotion.cjs +0 -12
- package/dist/constants/sorting.cjs +0 -22
- package/dist/constants/withParameters.cjs +0 -132
- package/dist/errors/errorResponse.cjs +0 -27
- package/dist/errors/index.cjs +0 -16
- package/dist/helpers/advancedAttributeHelpers.cjs +0 -30
- package/dist/helpers/arrayHelpers.cjs +0 -10
- package/dist/helpers/attributeHelpers.cjs +0 -24
- package/dist/helpers/basketHelpers.cjs +0 -12
- package/dist/helpers/categoryHelper.cjs +0 -61
- package/dist/helpers/filterHelper.cjs +0 -185
- package/dist/helpers/formHelpers.cjs +0 -114
- package/dist/helpers/imageHelpers.cjs +0 -20
- package/dist/helpers/index.cjs +0 -181
- package/dist/helpers/localization.cjs +0 -13
- package/dist/helpers/objectHelpers.cjs +0 -19
- package/dist/helpers/orderHelpers.cjs +0 -10
- package/dist/helpers/product.fixture.cjs +0 -766
- package/dist/helpers/productDisruptorHelper.cjs +0 -37
- package/dist/helpers/productHelpers.cjs +0 -156
- package/dist/helpers/sanitizationHelpers.cjs +0 -35
- package/dist/helpers/sortingHelper.cjs +0 -68
- package/dist/helpers/stringHelpers.cjs +0 -8
- package/dist/index.cjs +0 -100
- package/dist/rpc/methods/basket/basket.cjs +0 -270
- package/dist/rpc/methods/brands.cjs +0 -33
- package/dist/rpc/methods/categories.cjs +0 -129
- package/dist/rpc/methods/cbd.cjs +0 -38
- package/dist/rpc/methods/checkout/checkout.cjs +0 -48
- package/dist/rpc/methods/checkout/index.cjs +0 -49
- package/dist/rpc/methods/checkout/order.cjs +0 -42
- package/dist/rpc/methods/checkout/shopUser.cjs +0 -110
- package/dist/rpc/methods/checkout/shopUserAddresses.cjs +0 -12
- package/dist/rpc/methods/index.cjs +0 -225
- package/dist/rpc/methods/navigationTrees.cjs +0 -54
- package/dist/rpc/methods/oauth/idp.cjs +0 -59
- package/dist/rpc/methods/products.cjs +0 -309
- package/dist/rpc/methods/promotion.cjs +0 -51
- package/dist/rpc/methods/search.cjs +0 -40
- package/dist/rpc/methods/session.cjs +0 -257
- package/dist/rpc/methods/shopConfiguration.cjs +0 -15
- package/dist/rpc/methods/user.cjs +0 -103
- package/dist/rpc/methods/variants.cjs +0 -29
- package/dist/rpc/methods/wishlist.cjs +0 -104
- package/dist/server.cjs +0 -47
- package/dist/test/factories/index.cjs +0 -16
- package/dist/types/api/auth.cjs +0 -1
- package/dist/types/api/context.cjs +0 -15
- package/dist/types/api/rpc.cjs +0 -1
- package/dist/types/breadcrumb.cjs +0 -1
- package/dist/types/index.cjs +0 -267
- package/dist/types/promises.cjs +0 -1
- package/dist/types/sapi/basket.cjs +0 -1
- package/dist/types/sapi/brand.cjs +0 -1
- package/dist/types/sapi/campaign.cjs +0 -1
- package/dist/types/sapi/category.cjs +0 -1
- package/dist/types/sapi/filter.cjs +0 -1
- package/dist/types/sapi/navigation.cjs +0 -1
- package/dist/types/sapi/order.cjs +0 -1
- package/dist/types/sapi/product.cjs +0 -1
- package/dist/types/sapi/productFilter.cjs +0 -1
- package/dist/types/sapi/promotion.cjs +0 -1
- package/dist/types/sapi/redirects.cjs +0 -1
- package/dist/types/sapi/router.cjs +0 -1
- package/dist/types/sapi/search.cjs +0 -1
- package/dist/types/sapi/sorting.cjs +0 -1
- package/dist/types/sapi/variant.cjs +0 -1
- package/dist/types/sapi/wishlist.cjs +0 -1
- package/dist/types/user.cjs +0 -1
- package/dist/utils/basket.cjs +0 -14
- package/dist/utils/fetch.cjs +0 -19
- package/dist/utils/hash.cjs +0 -72
- package/dist/utils/index.cjs +0 -49
- package/dist/utils/keys.cjs +0 -67
- package/dist/utils/log.cjs +0 -93
- package/dist/utils/response.cjs +0 -13
- package/dist/utils/sapi.cjs +0 -26
- package/dist/utils/timeout.cjs +0 -18
- package/dist/utils/user.cjs +0 -90
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.oauthRevokeToken = exports.oauthRegister = exports.oauthLogin = exports.oauthGuestLogin = exports.oauthForgetPassword = void 0;
|
|
7
|
-
exports.postLogin = postLogin;
|
|
8
|
-
exports.updatePasswordByHash = exports.refreshAccessToken = void 0;
|
|
9
|
-
var _jose = require("jose");
|
|
10
|
-
var _types = require("../../types/index.cjs");
|
|
11
|
-
var _constants = require("../../constants/index.cjs");
|
|
12
|
-
var _fetch = require("../../utils/fetch.cjs");
|
|
13
|
-
var _user = require("../../utils/user.cjs");
|
|
14
|
-
var _user2 = require("../../rpc/methods/user.cjs");
|
|
15
|
-
var _response = require("../../utils/response.cjs");
|
|
16
|
-
var _oauth = require("../../api/oauth.cjs");
|
|
17
|
-
var _errors = require("../../errors/index.cjs");
|
|
18
|
-
const convertErrorForRpcCall = (error, httpStatuses) => {
|
|
19
|
-
if (error instanceof _fetch.FetchError && httpStatuses.includes(error.response.status)) {
|
|
20
|
-
return new _errors.ErrorResponse(error.response.status, error.response.statusText, error.name);
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
async function postLogin(context, tokens) {
|
|
24
|
-
const fetchUserResponse = await (0, _user2.fetchUser)({
|
|
25
|
-
accessToken: tokens.access_token
|
|
26
|
-
}, context);
|
|
27
|
-
if (fetchUserResponse instanceof _errors.ErrorResponse) {
|
|
28
|
-
return fetchUserResponse;
|
|
29
|
-
}
|
|
30
|
-
const user = await (0, _response.unwrap)(fetchUserResponse);
|
|
31
|
-
context.updateTokens({
|
|
32
|
-
accessToken: tokens.access_token,
|
|
33
|
-
refreshToken: tokens.refresh_token
|
|
34
|
-
});
|
|
35
|
-
context.updateUser(user);
|
|
36
|
-
const {
|
|
37
|
-
customerId
|
|
38
|
-
} = (0, _jose.decodeJwt)(tokens.access_token);
|
|
39
|
-
await Promise.all([(0, _user.mergeBaskets)(context.sessionId, await context.generateBasketKeyForUserId(customerId), _constants.DEFAULT_WITH_LISTING, context), (0, _user.mergeWishlists)(context.sessionId, await context.generateWishlistKeyForUserId(customerId), _constants.DEFAULT_WITH_LISTING, context)]);
|
|
40
|
-
await context.createUserBoundSession();
|
|
41
|
-
await context.callHook?.("storefront:afterLogin", {
|
|
42
|
-
shopId: context.shopId,
|
|
43
|
-
user,
|
|
44
|
-
authenticationType: user.authentication?.type,
|
|
45
|
-
accessToken: tokens.access_token
|
|
46
|
-
}, context);
|
|
47
|
-
}
|
|
48
|
-
const oauthLogin = async (login, context) => {
|
|
49
|
-
if (!(0, _types.hasSession)(context)) {
|
|
50
|
-
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
51
|
-
}
|
|
52
|
-
const shopId = context.shopId;
|
|
53
|
-
const client = (0, _oauth.getOAuthClient)(context);
|
|
54
|
-
if (!login.email || !login.password) {
|
|
55
|
-
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "Login or password are missing");
|
|
56
|
-
}
|
|
57
|
-
try {
|
|
58
|
-
const tokens = await client.login({
|
|
59
|
-
...login,
|
|
60
|
-
shop_id: shopId
|
|
61
|
-
});
|
|
62
|
-
const postLoginResponse = await postLogin(context, tokens);
|
|
63
|
-
if (postLoginResponse instanceof _errors.ErrorResponse) {
|
|
64
|
-
return postLoginResponse;
|
|
65
|
-
}
|
|
66
|
-
return new Response(null, {
|
|
67
|
-
status: _constants.HttpStatusCode.NO_CONTENT
|
|
68
|
-
});
|
|
69
|
-
} catch (error) {
|
|
70
|
-
context.log.error("OAuthClient.login failed", error);
|
|
71
|
-
return convertErrorForRpcCall(error, [_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusCode.NOT_FOUND]) ?? new _errors.ErrorResponse(_constants.HttpStatusCode.INTERNAL_SERVER_ERROR, _constants.HttpStatusMessage.INTERNAL_SERVER_ERROR, "Login failed");
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
exports.oauthLogin = oauthLogin;
|
|
75
|
-
const oauthRegister = async (register, context) => {
|
|
76
|
-
if (!(0, _types.hasSession)(context)) {
|
|
77
|
-
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
78
|
-
}
|
|
79
|
-
const shopId = context.shopId;
|
|
80
|
-
const client = (0, _oauth.getOAuthClient)(context);
|
|
81
|
-
try {
|
|
82
|
-
const tokens = await client.register({
|
|
83
|
-
...register,
|
|
84
|
-
shop_id: shopId
|
|
85
|
-
});
|
|
86
|
-
const postLoginResponse = await postLogin(context, tokens);
|
|
87
|
-
if (postLoginResponse instanceof _errors.ErrorResponse) {
|
|
88
|
-
return postLoginResponse;
|
|
89
|
-
}
|
|
90
|
-
return new Response(null, {
|
|
91
|
-
status: _constants.HttpStatusCode.NO_CONTENT
|
|
92
|
-
});
|
|
93
|
-
} catch (error) {
|
|
94
|
-
context.log.error("OAuthClient.register failed", error);
|
|
95
|
-
return convertErrorForRpcCall(error, [_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusCode.CONFLICT, _constants.HttpStatusCode.UNPROCESSABLE_CONTENT]) ?? new _errors.ErrorResponse(_constants.HttpStatusCode.INTERNAL_SERVER_ERROR, _constants.HttpStatusMessage.INTERNAL_SERVER_ERROR, "Register failed");
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
exports.oauthRegister = oauthRegister;
|
|
99
|
-
const oauthGuestLogin = async (guest, context) => {
|
|
100
|
-
if (!(0, _types.hasSession)(context)) {
|
|
101
|
-
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
102
|
-
}
|
|
103
|
-
const shopId = context.shopId;
|
|
104
|
-
const client = (0, _oauth.getOAuthClient)(context);
|
|
105
|
-
try {
|
|
106
|
-
const tokens = await client.guestLogin({
|
|
107
|
-
...guest,
|
|
108
|
-
shop_id: shopId
|
|
109
|
-
});
|
|
110
|
-
const postLoginResponse = await postLogin(context, tokens);
|
|
111
|
-
if (postLoginResponse instanceof _errors.ErrorResponse) {
|
|
112
|
-
return postLoginResponse;
|
|
113
|
-
}
|
|
114
|
-
return new Response(null, {
|
|
115
|
-
status: _constants.HttpStatusCode.NO_CONTENT
|
|
116
|
-
});
|
|
117
|
-
} catch (error) {
|
|
118
|
-
context.log.error("OAuthClient.guestLogin failed", error);
|
|
119
|
-
return convertErrorForRpcCall(error, [_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusCode.CONFLICT]) ?? new _errors.ErrorResponse(_constants.HttpStatusCode.INTERNAL_SERVER_ERROR, _constants.HttpStatusMessage.INTERNAL_SERVER_ERROR, "Guest login failed");
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
exports.oauthGuestLogin = oauthGuestLogin;
|
|
123
|
-
const refreshAccessToken = async context => {
|
|
124
|
-
if (!(0, _types.hasSession)(context)) {
|
|
125
|
-
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
126
|
-
}
|
|
127
|
-
const refreshToken = context.refreshToken;
|
|
128
|
-
const client = (0, _oauth.getOAuthClient)(context);
|
|
129
|
-
if (!refreshToken) {
|
|
130
|
-
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No refresh token present");
|
|
131
|
-
}
|
|
132
|
-
try {
|
|
133
|
-
const tokens = await client.refreshToken({
|
|
134
|
-
grant_type: "refresh_token",
|
|
135
|
-
refresh_token: refreshToken
|
|
136
|
-
});
|
|
137
|
-
context.updateTokens({
|
|
138
|
-
accessToken: tokens?.access_token,
|
|
139
|
-
refreshToken: tokens?.refresh_token
|
|
140
|
-
});
|
|
141
|
-
return {
|
|
142
|
-
success: !!tokens
|
|
143
|
-
};
|
|
144
|
-
} catch (error) {
|
|
145
|
-
const res = convertErrorForRpcCall(error, [_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusCode.UNAUTHORIZED]);
|
|
146
|
-
if (res && res.status === _constants.HttpStatusCode.UNAUTHORIZED) {
|
|
147
|
-
context.log.debug("Failed to refresh Checkout Token due to invalid refresh token. Deleting session");
|
|
148
|
-
await context.destroySession();
|
|
149
|
-
} else {
|
|
150
|
-
context.log.debug("Failed to refresh Checkout Token for unknown reason.");
|
|
151
|
-
}
|
|
152
|
-
if (res) {
|
|
153
|
-
return res;
|
|
154
|
-
}
|
|
155
|
-
return {
|
|
156
|
-
success: false
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
exports.refreshAccessToken = refreshAccessToken;
|
|
161
|
-
const oauthRevokeToken = async context => {
|
|
162
|
-
if (!(0, _types.hasSession)(context)) {
|
|
163
|
-
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
164
|
-
}
|
|
165
|
-
const accessToken = context.accessToken;
|
|
166
|
-
if (!accessToken) {
|
|
167
|
-
return new _errors.ErrorResponse(_constants.HttpStatusCode.UNAUTHORIZED, _constants.HttpStatusMessage.UNAUTHORIZED, "No access token present");
|
|
168
|
-
}
|
|
169
|
-
const user = context.user;
|
|
170
|
-
const client = (0, _oauth.getOAuthClient)(context);
|
|
171
|
-
await context.destroySession();
|
|
172
|
-
try {
|
|
173
|
-
await client.revokeToken(context.shopId, accessToken);
|
|
174
|
-
await context.callHook?.("storefront:afterLogout", {
|
|
175
|
-
shopId: context.shopId,
|
|
176
|
-
user,
|
|
177
|
-
authenticationType: user.authentication?.type
|
|
178
|
-
}, context);
|
|
179
|
-
return {
|
|
180
|
-
result: true
|
|
181
|
-
};
|
|
182
|
-
} catch (error) {
|
|
183
|
-
const res = convertErrorForRpcCall(error, [_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusCode.UNAUTHORIZED, _constants.HttpStatusCode.NOT_FOUND]);
|
|
184
|
-
if (res) {
|
|
185
|
-
return res;
|
|
186
|
-
}
|
|
187
|
-
return {
|
|
188
|
-
result: false
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
exports.oauthRevokeToken = oauthRevokeToken;
|
|
193
|
-
const oauthForgetPassword = async ({
|
|
194
|
-
email
|
|
195
|
-
}, context) => {
|
|
196
|
-
if (!(0, _types.hasSession)(context)) {
|
|
197
|
-
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
198
|
-
}
|
|
199
|
-
const shopId = context.shopId;
|
|
200
|
-
const client = (0, _oauth.getOAuthClient)(context);
|
|
201
|
-
try {
|
|
202
|
-
if (!context.auth.resetPasswordUrl) {
|
|
203
|
-
return new _errors.ErrorResponse(_constants.HttpStatusCode.INTERNAL_SERVER_ERROR, _constants.HttpStatusMessage.INTERNAL_SERVER_ERROR, "Missing password reset URL");
|
|
204
|
-
}
|
|
205
|
-
const resetUrl = new URL(context.auth.resetPasswordUrl);
|
|
206
|
-
if (!resetUrl.searchParams.has("hash")) {
|
|
207
|
-
resetUrl.searchParams.append("hash", "{hash}");
|
|
208
|
-
} else {
|
|
209
|
-
resetUrl.searchParams.set("hash", "{hash}");
|
|
210
|
-
}
|
|
211
|
-
await client.sendPasswordResetEmail({
|
|
212
|
-
email,
|
|
213
|
-
reset_url: decodeURI(resetUrl.toString()),
|
|
214
|
-
shop_id: shopId
|
|
215
|
-
});
|
|
216
|
-
return {
|
|
217
|
-
success: true
|
|
218
|
-
};
|
|
219
|
-
} catch (error) {
|
|
220
|
-
const res = convertErrorForRpcCall(error, [_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusCode.NOT_FOUND, _constants.HttpStatusCode.UNAUTHORIZED, _constants.HttpStatusCode.FORBIDDEN]);
|
|
221
|
-
if (res) {
|
|
222
|
-
return res;
|
|
223
|
-
}
|
|
224
|
-
return {
|
|
225
|
-
success: false
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
exports.oauthForgetPassword = oauthForgetPassword;
|
|
230
|
-
const updatePasswordByHash = async (passwordHash, context) => {
|
|
231
|
-
if (!(0, _types.hasSession)(context)) {
|
|
232
|
-
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
233
|
-
}
|
|
234
|
-
const shopId = context.shopId;
|
|
235
|
-
const client = (0, _oauth.getOAuthClient)(context);
|
|
236
|
-
try {
|
|
237
|
-
const tokens = await client.updatePasswordByHash({
|
|
238
|
-
...passwordHash,
|
|
239
|
-
shop_id: shopId
|
|
240
|
-
});
|
|
241
|
-
context.updateTokens({
|
|
242
|
-
accessToken: tokens.access_token,
|
|
243
|
-
refreshToken: tokens.refresh_token
|
|
244
|
-
});
|
|
245
|
-
await context.createUserBoundSession();
|
|
246
|
-
} catch (error) {
|
|
247
|
-
const res = convertErrorForRpcCall(error, [_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusCode.UNAUTHORIZED, _constants.HttpStatusCode.NOT_ACCEPTABLE]);
|
|
248
|
-
if (res) {
|
|
249
|
-
return res;
|
|
250
|
-
}
|
|
251
|
-
return new _errors.ErrorResponse(_constants.HttpStatusCode.INTERNAL_SERVER_ERROR, _constants.HttpStatusMessage.INTERNAL_SERVER_ERROR, "Error during update password by hash");
|
|
252
|
-
}
|
|
253
|
-
return new Response(null, {
|
|
254
|
-
status: _constants.HttpStatusCode.NO_CONTENT
|
|
255
|
-
});
|
|
256
|
-
};
|
|
257
|
-
exports.updatePasswordByHash = updatePasswordByHash;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getShopConfiguration = void 0;
|
|
7
|
-
var _sapi = require("../../utils/sapi.cjs");
|
|
8
|
-
const getShopConfiguration = exports.getShopConfiguration = async function getShopConfiguration2({
|
|
9
|
-
cached,
|
|
10
|
-
sapiClient
|
|
11
|
-
}) {
|
|
12
|
-
return await cached((0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.shopConfiguration.get), {
|
|
13
|
-
cacheKeyPrefix: "get-shopConfigurations"
|
|
14
|
-
})();
|
|
15
|
-
};
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.refreshUser = exports.getUser = exports.getAccessToken = exports.fetchUser = void 0;
|
|
7
|
-
var _types = require("../../types/index.cjs");
|
|
8
|
-
var _customer = require("../../api/customer.cjs");
|
|
9
|
-
var _oauth = require("../../api/oauth.cjs");
|
|
10
|
-
var _constants = require("../../constants/index.cjs");
|
|
11
|
-
var _errors = require("../../errors/index.cjs");
|
|
12
|
-
var _fetch = require("../../utils/fetch.cjs");
|
|
13
|
-
const getUser = exports.getUser = function getUser2(context) {
|
|
14
|
-
const {
|
|
15
|
-
user
|
|
16
|
-
} = context;
|
|
17
|
-
if (user) {
|
|
18
|
-
user.authentication = user.authentication ?? {
|
|
19
|
-
type: "idp"
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
return {
|
|
23
|
-
user
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
const fetchUser = exports.fetchUser = async function fetchUser2({
|
|
27
|
-
accessToken
|
|
28
|
-
}, context) {
|
|
29
|
-
const {
|
|
30
|
-
shopId
|
|
31
|
-
} = context;
|
|
32
|
-
const client = new _customer.CustomerAPIClient(context);
|
|
33
|
-
const user = await client.getMe(shopId, accessToken);
|
|
34
|
-
if (!user.authentication) {
|
|
35
|
-
user.authentication = {
|
|
36
|
-
type: "idp"
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
return user;
|
|
40
|
-
};
|
|
41
|
-
const refreshUser = exports.refreshUser = async function refreshUser2(context) {
|
|
42
|
-
if (!(0, _types.hasSession)(context)) {
|
|
43
|
-
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
44
|
-
}
|
|
45
|
-
const {
|
|
46
|
-
accessToken
|
|
47
|
-
} = context;
|
|
48
|
-
if (!accessToken) {
|
|
49
|
-
return {
|
|
50
|
-
user: void 0
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
try {
|
|
54
|
-
const user = await fetchUser({
|
|
55
|
-
accessToken
|
|
56
|
-
}, context);
|
|
57
|
-
context.updateUser(user);
|
|
58
|
-
return {
|
|
59
|
-
user
|
|
60
|
-
};
|
|
61
|
-
} catch {
|
|
62
|
-
await context.destroySession();
|
|
63
|
-
return {
|
|
64
|
-
user: void 0
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
const getAccessToken = exports.getAccessToken = async function getAccessToken2({
|
|
69
|
-
forceTokenRefresh = false
|
|
70
|
-
} = {
|
|
71
|
-
forceTokenRefresh: false
|
|
72
|
-
}, context) {
|
|
73
|
-
if (!(0, _types.hasSession)(context)) {
|
|
74
|
-
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
75
|
-
}
|
|
76
|
-
if (!context.accessToken) {
|
|
77
|
-
return new _errors.ErrorResponse(_constants.HttpStatusCode.UNAUTHORIZED, _constants.HttpStatusMessage.UNAUTHORIZED, "No access token present");
|
|
78
|
-
}
|
|
79
|
-
if (forceTokenRefresh) {
|
|
80
|
-
if (!context.refreshToken) {
|
|
81
|
-
return new _errors.ErrorResponse(_constants.HttpStatusCode.UNAUTHORIZED, _constants.HttpStatusMessage.UNAUTHORIZED, "No refresh token present");
|
|
82
|
-
}
|
|
83
|
-
const client = (0, _oauth.getOAuthClient)(context);
|
|
84
|
-
try {
|
|
85
|
-
const tokens = await client.refreshToken({
|
|
86
|
-
grant_type: "refresh_token",
|
|
87
|
-
refresh_token: context.refreshToken
|
|
88
|
-
});
|
|
89
|
-
context.updateTokens({
|
|
90
|
-
accessToken: tokens.access_token,
|
|
91
|
-
refreshToken: tokens.refresh_token
|
|
92
|
-
});
|
|
93
|
-
} catch (e) {
|
|
94
|
-
if (e instanceof _fetch.FetchError && e.response.status === _constants.HttpStatusCode.UNAUTHORIZED) {
|
|
95
|
-
context.log.debug("Failed to refresh Checkout Token due to invalid refresh token. Deleting session");
|
|
96
|
-
await context.destroySession();
|
|
97
|
-
} else {
|
|
98
|
-
context.log.debug("Failed to refresh Checkout Token for unknown reason.");
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return context.accessToken;
|
|
103
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getVariantById = void 0;
|
|
7
|
-
var _sapi = require("../../utils/sapi.cjs");
|
|
8
|
-
const defaultWith = {
|
|
9
|
-
attributes: "all"
|
|
10
|
-
};
|
|
11
|
-
const getVariantById = exports.getVariantById = async function getVariantById2({
|
|
12
|
-
ids,
|
|
13
|
-
include = defaultWith,
|
|
14
|
-
pricePromotionKey = "default"
|
|
15
|
-
}, {
|
|
16
|
-
sapiClient,
|
|
17
|
-
cached,
|
|
18
|
-
campaignKey,
|
|
19
|
-
withParams
|
|
20
|
-
}) {
|
|
21
|
-
const resolvedWith = include ?? withParams?.variant ?? defaultWith;
|
|
22
|
-
return await cached((0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.variants.getByIds), {
|
|
23
|
-
cacheKeyPrefix: "getByIds-variants"
|
|
24
|
-
})(ids, include ? {
|
|
25
|
-
with: resolvedWith,
|
|
26
|
-
campaignKey,
|
|
27
|
-
pricePromotionKey
|
|
28
|
-
} : void 0);
|
|
29
|
-
};
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.removeItemFromWishlist = exports.getWishlist = exports.clearWishlist = exports.addItemToWishlist = void 0;
|
|
7
|
-
var _types = require("../../types/index.cjs");
|
|
8
|
-
var _constants = require("../../constants/index.cjs");
|
|
9
|
-
var _response = require("../../utils/response.cjs");
|
|
10
|
-
var _errors = require("../../errors/index.cjs");
|
|
11
|
-
var _sapi = require("../../utils/sapi.cjs");
|
|
12
|
-
function getWithParams(params, context) {
|
|
13
|
-
return params.with ?? context.withParams?.wishlist ?? _constants.MIN_WITH_PARAMS_WISHLIST;
|
|
14
|
-
}
|
|
15
|
-
const getWishlist = exports.getWishlist = async function getWishlist2(options, context) {
|
|
16
|
-
if (!(0, _types.hasSession)(context)) {
|
|
17
|
-
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
18
|
-
}
|
|
19
|
-
const {
|
|
20
|
-
sapiClient,
|
|
21
|
-
campaignKey,
|
|
22
|
-
wishlistKey
|
|
23
|
-
} = context;
|
|
24
|
-
const resolvedWith = getWithParams({
|
|
25
|
-
with: options
|
|
26
|
-
}, context);
|
|
27
|
-
return await (0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.wishlist.get)(wishlistKey, {
|
|
28
|
-
with: resolvedWith,
|
|
29
|
-
campaignKey,
|
|
30
|
-
pricePromotionKey: resolvedWith?.pricePromotionKey ?? ""
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
const addItemToWishlist = exports.addItemToWishlist = async function addItemToWishlist2(options, context) {
|
|
34
|
-
if (!(0, _types.hasSession)(context)) {
|
|
35
|
-
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
36
|
-
}
|
|
37
|
-
const {
|
|
38
|
-
sapiClient,
|
|
39
|
-
campaignKey,
|
|
40
|
-
wishlistKey
|
|
41
|
-
} = context;
|
|
42
|
-
const {
|
|
43
|
-
productId,
|
|
44
|
-
variantId
|
|
45
|
-
} = options;
|
|
46
|
-
const resolvedWith = getWithParams(options, context);
|
|
47
|
-
const pricePromotionKey = resolvedWith?.pricePromotionKey ?? "";
|
|
48
|
-
if (!productId && !variantId) {
|
|
49
|
-
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No productId or variantId given");
|
|
50
|
-
}
|
|
51
|
-
const result = await sapiClient.wishlist.addItem(wishlistKey, variantId ? {
|
|
52
|
-
variantId
|
|
53
|
-
} : {
|
|
54
|
-
productId
|
|
55
|
-
}, {
|
|
56
|
-
with: resolvedWith,
|
|
57
|
-
campaignKey,
|
|
58
|
-
pricePromotionKey
|
|
59
|
-
});
|
|
60
|
-
if (result.type === "success") {
|
|
61
|
-
return result.wishlist;
|
|
62
|
-
} else {
|
|
63
|
-
const {
|
|
64
|
-
statusCode: code,
|
|
65
|
-
kind,
|
|
66
|
-
type
|
|
67
|
-
} = result;
|
|
68
|
-
context.log.error("Adding to wishlist failed", result.wishlist);
|
|
69
|
-
return new Response(JSON.stringify({
|
|
70
|
-
kind,
|
|
71
|
-
type
|
|
72
|
-
}), {
|
|
73
|
-
status: code
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
const removeItemFromWishlist = exports.removeItemFromWishlist = async function removeItemFromWishlist2(options, context) {
|
|
78
|
-
if (!(0, _types.hasSession)(context)) {
|
|
79
|
-
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
80
|
-
}
|
|
81
|
-
const {
|
|
82
|
-
sapiClient,
|
|
83
|
-
campaignKey,
|
|
84
|
-
wishlistKey
|
|
85
|
-
} = context;
|
|
86
|
-
const resolvedWith = getWithParams(options, context);
|
|
87
|
-
return await (0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.wishlist.deleteItem)(wishlistKey, options.itemKey, {
|
|
88
|
-
with: resolvedWith,
|
|
89
|
-
campaignKey
|
|
90
|
-
});
|
|
91
|
-
};
|
|
92
|
-
const clearWishlist = exports.clearWishlist = async function clearWishlist2(context) {
|
|
93
|
-
const wishlistResponse = await getWishlist({}, context);
|
|
94
|
-
if (wishlistResponse instanceof _errors.ErrorResponse) {
|
|
95
|
-
return wishlistResponse;
|
|
96
|
-
}
|
|
97
|
-
const wishlist = await (0, _response.unwrap)(wishlistResponse);
|
|
98
|
-
await Promise.all(wishlist.items.map(async item => {
|
|
99
|
-
await removeItemFromWishlist({
|
|
100
|
-
itemKey: item.key
|
|
101
|
-
}, context);
|
|
102
|
-
}));
|
|
103
|
-
return await getWishlist({}, context);
|
|
104
|
-
};
|
package/dist/server.cjs
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _exportNames = {
|
|
7
|
-
UnstorageCache: true,
|
|
8
|
-
CACHE_TIMEOUT: true
|
|
9
|
-
};
|
|
10
|
-
Object.defineProperty(exports, "CACHE_TIMEOUT", {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _cache.CACHE_TIMEOUT;
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
Object.defineProperty(exports, "UnstorageCache", {
|
|
17
|
-
enumerable: true,
|
|
18
|
-
get: function () {
|
|
19
|
-
return _unstorage.UnstorageCache;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
var _unstorage = require("./cache/providers/unstorage.cjs");
|
|
23
|
-
var _cache = require("./constants/cache.cjs");
|
|
24
|
-
var _customer = require("./api/customer.cjs");
|
|
25
|
-
Object.keys(_customer).forEach(function (key) {
|
|
26
|
-
if (key === "default" || key === "__esModule") return;
|
|
27
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
28
|
-
if (key in exports && exports[key] === _customer[key]) return;
|
|
29
|
-
Object.defineProperty(exports, key, {
|
|
30
|
-
enumerable: true,
|
|
31
|
-
get: function () {
|
|
32
|
-
return _customer[key];
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
var _oauth = require("./api/oauth.cjs");
|
|
37
|
-
Object.keys(_oauth).forEach(function (key) {
|
|
38
|
-
if (key === "default" || key === "__esModule") return;
|
|
39
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
40
|
-
if (key in exports && exports[key] === _oauth[key]) return;
|
|
41
|
-
Object.defineProperty(exports, key, {
|
|
42
|
-
enumerable: true,
|
|
43
|
-
get: function () {
|
|
44
|
-
return _oauth[key];
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _factories = require("@scayle/storefront-api/dist/test/factories");
|
|
7
|
-
Object.keys(_factories).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _factories[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _factories[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
package/dist/types/api/auth.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.assertSession = assertSession;
|
|
7
|
-
exports.hasSession = hasSession;
|
|
8
|
-
function assertSession(context) {
|
|
9
|
-
if (!context.sessionId) {
|
|
10
|
-
throw new Error("No session for RpcContext available");
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
function hasSession(context) {
|
|
14
|
-
return !!context.sessionId;
|
|
15
|
-
}
|
package/dist/types/api/rpc.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|