@scayle/storefront-core 7.25.1 → 7.26.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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @scayle/storefront-core
2
2
 
3
+ ## 7.26.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Don't return oauth tokens from RPC methods
8
+
3
9
  ## 7.25.1
4
10
 
5
11
  ### Patch Changes
@@ -26,7 +26,7 @@ function getOAuthSettings(context) {
26
26
  throw new MissingCredentialsError();
27
27
  }
28
28
  const BASIC_AUTH_HASH = (0, _hash.encodeBase64)(`${clientId}:${clientSecret}`);
29
- const axiosInstance2 = _axios.default.create({
29
+ const axiosInstance = _axios.default.create({
30
30
  baseURL: `${apiHost}/v1`,
31
31
  headers: {
32
32
  Authorization: `Basic ${BASIC_AUTH_HASH}`
@@ -36,7 +36,7 @@ function getOAuthSettings(context) {
36
36
  clientId,
37
37
  clientSecret,
38
38
  apiHost,
39
- axiosInstance: axiosInstance2
39
+ axiosInstance
40
40
  };
41
41
  }
42
42
  const saveUserOnSession = async (accessToken, context) => {
@@ -54,13 +54,13 @@ const saveUserOnSession = async (accessToken, context) => {
54
54
  const oauthLogin = async (login, context) => {
55
55
  const shopId = context.shopId;
56
56
  const {
57
- axiosInstance: axiosInstance2
57
+ axiosInstance
58
58
  } = getOAuthSettings(context);
59
59
  if (!login.email || !login.password) {
60
60
  throw new Error("Login or password are missing, seems like validation has failed");
61
61
  }
62
62
  try {
63
- const response = await axiosInstance2.post("/auth/login", {
63
+ const response = await axiosInstance.post("/auth/login", {
64
64
  ...login,
65
65
  shop_id: shopId
66
66
  });
@@ -74,27 +74,21 @@ const oauthLogin = async (login, context) => {
74
74
  } = (0, _jose.decodeJwt)(response.data.access_token);
75
75
  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)]);
76
76
  await context.createUserBoundSession();
77
- return {
78
- oauth: response.data
79
- };
80
77
  } catch (error) {
81
78
  const err = (0, _rpc.convertErrorForRpcCall)(error, [_constants.HttpStatusCode.INTERNAL_SERVER_ERROR, _constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusCode.UNAUTHORIZED, _constants.HttpStatusCode.NOT_FOUND]);
82
79
  if (err) {
83
80
  throw err;
84
81
  }
85
- return {
86
- oauth: null
87
- };
88
82
  }
89
83
  };
90
84
  exports.oauthLogin = oauthLogin;
91
85
  const oauthRegister = async (register, context) => {
92
86
  const shopId = context.shopId;
93
87
  const {
94
- axiosInstance: axiosInstance2
88
+ axiosInstance
95
89
  } = getOAuthSettings(context);
96
90
  try {
97
- const response = await axiosInstance2.post("/auth/register", {
91
+ const response = await axiosInstance.post("/auth/register", {
98
92
  ...register,
99
93
  shop_id: shopId
100
94
  });
@@ -108,27 +102,21 @@ const oauthRegister = async (register, context) => {
108
102
  } = (0, _jose.decodeJwt)(response.data.access_token);
109
103
  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)]);
110
104
  await context.createUserBoundSession();
111
- return {
112
- oauth: response.data
113
- };
114
105
  } catch (error) {
115
106
  const err = (0, _rpc.convertErrorForRpcCall)(error, [_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusCode.UNAUTHORIZED, _constants.HttpStatusCode.CONFLICT]);
116
107
  if (err) {
117
108
  throw err;
118
109
  }
119
- return {
120
- oauth: null
121
- };
122
110
  }
123
111
  };
124
112
  exports.oauthRegister = oauthRegister;
125
113
  const oauthGuestLogin = async (guest, context) => {
126
114
  const shopId = context.shopId;
127
115
  const {
128
- axiosInstance: axiosInstance2
116
+ axiosInstance
129
117
  } = getOAuthSettings(context);
130
118
  try {
131
- const response = await axiosInstance2.post("/auth/login/guest", {
119
+ const response = await axiosInstance.post("/auth/login/guest", {
132
120
  ...guest,
133
121
  shop_id: shopId
134
122
  });
@@ -142,44 +130,39 @@ const oauthGuestLogin = async (guest, context) => {
142
130
  } = (0, _jose.decodeJwt)(response.data.access_token);
143
131
  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)]);
144
132
  await context.createUserBoundSession();
145
- return {
146
- oauth: response.data
147
- };
148
133
  } catch (error) {
149
134
  const err = (0, _rpc.convertErrorForRpcCall)(error, [_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusCode.UNAUTHORIZED, _constants.HttpStatusCode.CONFLICT]);
150
135
  if (err) {
151
136
  throw err;
152
137
  }
153
- return {
154
- oauth: null
155
- };
156
138
  }
157
139
  };
158
140
  exports.oauthGuestLogin = oauthGuestLogin;
159
141
  const refreshAccessToken = async context => {
160
142
  const refreshToken = context.refreshToken;
161
143
  const {
162
- axiosInstance: axiosInstance2
144
+ axiosInstance
163
145
  } = getOAuthSettings(context);
164
146
  if (!refreshToken) {
165
147
  throw new Error("No app refresh token provided");
166
148
  }
167
149
  try {
168
- const response = await axiosInstance2.post("/oauth/token", {
150
+ const response = await axiosInstance.post("/oauth/token", {
169
151
  grant_type: "refresh_token",
170
152
  refresh_token: refreshToken
171
153
  });
172
154
  context.updateTokens({
173
- accessToken: response.data.access_token,
174
- refreshToken: response.data.refresh_token
155
+ accessToken: response.data?.access_token,
156
+ refreshToken: response.data?.refresh_token
175
157
  });
176
- return response.data;
158
+ return {
159
+ success: !!response.data
160
+ };
177
161
  } catch (error) {
178
162
  const err = (0, _rpc.convertErrorForRpcCall)(error, [_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusCode.UNAUTHORIZED]);
179
163
  if (err) {
180
164
  throw err;
181
165
  }
182
- return null;
183
166
  }
184
167
  };
185
168
  exports.refreshAccessToken = refreshAccessToken;
@@ -189,6 +172,9 @@ const oauthRevokeToken = async context => {
189
172
  throw new Error("No app oauth authentication credentials");
190
173
  }
191
174
  const decodedAccessToken = (0, _jose.decodeJwt)(accessToken);
175
+ const {
176
+ axiosInstance
177
+ } = getOAuthSettings(context);
192
178
  await context.destroySession();
193
179
  try {
194
180
  await axiosInstance.delete(`/oauth/tokens/${decodedAccessToken.jti}`, {
@@ -215,7 +201,7 @@ const oauthForgetPassword = async ({
215
201
  }, context) => {
216
202
  const shopId = context.shopId;
217
203
  const {
218
- axiosInstance: axiosInstance2
204
+ axiosInstance
219
205
  } = getOAuthSettings(context);
220
206
  try {
221
207
  const resetUrl = new URL(context.auth.resetPasswordUrl);
@@ -224,7 +210,7 @@ const oauthForgetPassword = async ({
224
210
  } else {
225
211
  resetUrl.searchParams.set("hash", "{hash}");
226
212
  }
227
- await axiosInstance2.post("/auth/password/send-reset-email", {
213
+ await axiosInstance.post("/auth/password/send-reset-email", {
228
214
  email,
229
215
  reset_url: decodeURI(resetUrl.toString()),
230
216
  shop_id: shopId
@@ -246,10 +232,10 @@ exports.oauthForgetPassword = oauthForgetPassword;
246
232
  const updatePasswordByHash = async (passwordHash, context) => {
247
233
  const shopId = context.shopId;
248
234
  const {
249
- axiosInstance: axiosInstance2
235
+ axiosInstance
250
236
  } = getOAuthSettings(context);
251
237
  try {
252
- const response = await axiosInstance2.put("/auth/password/update-by-hash", {
238
+ const response = await axiosInstance.put("/auth/password/update-by-hash", {
253
239
  ...passwordHash,
254
240
  shop_id: shopId
255
241
  });
@@ -258,17 +244,11 @@ const updatePasswordByHash = async (passwordHash, context) => {
258
244
  refreshToken: response.data.refresh_token
259
245
  });
260
246
  await context.createUserBoundSession();
261
- return {
262
- oauth: response.data
263
- };
264
247
  } catch (error) {
265
248
  const err = (0, _rpc.convertErrorForRpcCall)(error, [_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusCode.UNAUTHORIZED, _constants.HttpStatusCode.NOT_ACCEPTABLE]);
266
249
  if (err) {
267
250
  throw err;
268
251
  }
269
- return {
270
- oauth: null
271
- };
272
252
  }
273
253
  };
274
254
  exports.updatePasswordByHash = updatePasswordByHash;
@@ -1,20 +1,14 @@
1
- import { GuestRequest, LoginRequest, Oauth, RegisterRequest, RpcHandler, SendResetPasswordEmailRequest, UpdatePasswordByHashRequest } from '../../types';
2
- export declare const oauthLogin: RpcHandler<LoginRequest, {
3
- oauth: Oauth | null;
4
- }>;
5
- export declare const oauthRegister: RpcHandler<RegisterRequest, {
6
- oauth: Oauth | null;
7
- }>;
8
- export declare const oauthGuestLogin: RpcHandler<GuestRequest, {
9
- oauth: Oauth | null;
1
+ import { GuestRequest, LoginRequest, ParamRpcHandler, RegisterRequest, RpcHandler, SendResetPasswordEmailRequest, UpdatePasswordByHashRequest } from '../../types';
2
+ export declare const oauthLogin: ParamRpcHandler<LoginRequest, undefined>;
3
+ export declare const oauthRegister: ParamRpcHandler<RegisterRequest, undefined>;
4
+ export declare const oauthGuestLogin: ParamRpcHandler<GuestRequest, undefined>;
5
+ export declare const refreshAccessToken: RpcHandler<{
6
+ success: boolean;
10
7
  }>;
11
- export declare const refreshAccessToken: RpcHandler<Oauth | null>;
12
8
  export declare const oauthRevokeToken: RpcHandler<{
13
9
  result: boolean;
14
10
  }>;
15
11
  export declare const oauthForgetPassword: RpcHandler<SendResetPasswordEmailRequest, {
16
12
  success: boolean;
17
13
  }>;
18
- export declare const updatePasswordByHash: RpcHandler<UpdatePasswordByHashRequest, {
19
- oauth: Oauth | null;
20
- }>;
14
+ export declare const updatePasswordByHash: ParamRpcHandler<UpdatePasswordByHashRequest, undefined>;
@@ -19,7 +19,7 @@ function getOAuthSettings(context) {
19
19
  throw new MissingCredentialsError();
20
20
  }
21
21
  const BASIC_AUTH_HASH = encodeBase64(`${clientId}:${clientSecret}`);
22
- const axiosInstance2 = axios.create({
22
+ const axiosInstance = axios.create({
23
23
  baseURL: `${apiHost}/v1`,
24
24
  headers: {
25
25
  Authorization: `Basic ${BASIC_AUTH_HASH}`
@@ -29,7 +29,7 @@ function getOAuthSettings(context) {
29
29
  clientId,
30
30
  clientSecret,
31
31
  apiHost,
32
- axiosInstance: axiosInstance2
32
+ axiosInstance
33
33
  };
34
34
  }
35
35
  const saveUserOnSession = async (accessToken, context) => {
@@ -46,14 +46,14 @@ const saveUserOnSession = async (accessToken, context) => {
46
46
  };
47
47
  export const oauthLogin = async (login, context) => {
48
48
  const shopId = context.shopId;
49
- const { axiosInstance: axiosInstance2 } = getOAuthSettings(context);
49
+ const { axiosInstance } = getOAuthSettings(context);
50
50
  if (!login.email || !login.password) {
51
51
  throw new Error(
52
52
  "Login or password are missing, seems like validation has failed"
53
53
  );
54
54
  }
55
55
  try {
56
- const response = await axiosInstance2.post(
56
+ const response = await axiosInstance.post(
57
57
  "/auth/login",
58
58
  {
59
59
  ...login,
@@ -81,9 +81,6 @@ export const oauthLogin = async (login, context) => {
81
81
  )
82
82
  ]);
83
83
  await context.createUserBoundSession();
84
- return {
85
- oauth: response.data
86
- };
87
84
  } catch (error) {
88
85
  const err = convertErrorForRpcCall(error, [
89
86
  HttpStatusCode.INTERNAL_SERVER_ERROR,
@@ -94,14 +91,13 @@ export const oauthLogin = async (login, context) => {
94
91
  if (err) {
95
92
  throw err;
96
93
  }
97
- return { oauth: null };
98
94
  }
99
95
  };
100
96
  export const oauthRegister = async (register, context) => {
101
97
  const shopId = context.shopId;
102
- const { axiosInstance: axiosInstance2 } = getOAuthSettings(context);
98
+ const { axiosInstance } = getOAuthSettings(context);
103
99
  try {
104
- const response = await axiosInstance2.post(
100
+ const response = await axiosInstance.post(
105
101
  "/auth/register",
106
102
  {
107
103
  ...register,
@@ -129,9 +125,6 @@ export const oauthRegister = async (register, context) => {
129
125
  )
130
126
  ]);
131
127
  await context.createUserBoundSession();
132
- return {
133
- oauth: response.data
134
- };
135
128
  } catch (error) {
136
129
  const err = convertErrorForRpcCall(error, [
137
130
  HttpStatusCode.BAD_REQUEST,
@@ -141,14 +134,13 @@ export const oauthRegister = async (register, context) => {
141
134
  if (err) {
142
135
  throw err;
143
136
  }
144
- return { oauth: null };
145
137
  }
146
138
  };
147
139
  export const oauthGuestLogin = async (guest, context) => {
148
140
  const shopId = context.shopId;
149
- const { axiosInstance: axiosInstance2 } = getOAuthSettings(context);
141
+ const { axiosInstance } = getOAuthSettings(context);
150
142
  try {
151
- const response = await axiosInstance2.post(
143
+ const response = await axiosInstance.post(
152
144
  "/auth/login/guest",
153
145
  {
154
146
  ...guest,
@@ -176,9 +168,6 @@ export const oauthGuestLogin = async (guest, context) => {
176
168
  )
177
169
  ]);
178
170
  await context.createUserBoundSession();
179
- return {
180
- oauth: response.data
181
- };
182
171
  } catch (error) {
183
172
  const err = convertErrorForRpcCall(error, [
184
173
  HttpStatusCode.BAD_REQUEST,
@@ -188,17 +177,16 @@ export const oauthGuestLogin = async (guest, context) => {
188
177
  if (err) {
189
178
  throw err;
190
179
  }
191
- return { oauth: null };
192
180
  }
193
181
  };
194
182
  export const refreshAccessToken = async (context) => {
195
183
  const refreshToken = context.refreshToken;
196
- const { axiosInstance: axiosInstance2 } = getOAuthSettings(context);
184
+ const { axiosInstance } = getOAuthSettings(context);
197
185
  if (!refreshToken) {
198
186
  throw new Error("No app refresh token provided");
199
187
  }
200
188
  try {
201
- const response = await axiosInstance2.post(
189
+ const response = await axiosInstance.post(
202
190
  "/oauth/token",
203
191
  {
204
192
  grant_type: "refresh_token",
@@ -206,10 +194,10 @@ export const refreshAccessToken = async (context) => {
206
194
  }
207
195
  );
208
196
  context.updateTokens({
209
- accessToken: response.data.access_token,
210
- refreshToken: response.data.refresh_token
197
+ accessToken: response.data?.access_token,
198
+ refreshToken: response.data?.refresh_token
211
199
  });
212
- return response.data;
200
+ return { success: !!response.data };
213
201
  } catch (error) {
214
202
  const err = convertErrorForRpcCall(error, [
215
203
  HttpStatusCode.BAD_REQUEST,
@@ -218,7 +206,6 @@ export const refreshAccessToken = async (context) => {
218
206
  if (err) {
219
207
  throw err;
220
208
  }
221
- return null;
222
209
  }
223
210
  };
224
211
  export const oauthRevokeToken = async (context) => {
@@ -227,6 +214,7 @@ export const oauthRevokeToken = async (context) => {
227
214
  throw new Error("No app oauth authentication credentials");
228
215
  }
229
216
  const decodedAccessToken = decodeJwt(accessToken);
217
+ const { axiosInstance } = getOAuthSettings(context);
230
218
  await context.destroySession();
231
219
  try {
232
220
  await axiosInstance.delete(`/oauth/tokens/${decodedAccessToken.jti}`, {
@@ -249,7 +237,7 @@ export const oauthRevokeToken = async (context) => {
249
237
  };
250
238
  export const oauthForgetPassword = async ({ email }, context) => {
251
239
  const shopId = context.shopId;
252
- const { axiosInstance: axiosInstance2 } = getOAuthSettings(context);
240
+ const { axiosInstance } = getOAuthSettings(context);
253
241
  try {
254
242
  const resetUrl = new URL(context.auth.resetPasswordUrl);
255
243
  if (!resetUrl.searchParams.has("hash")) {
@@ -257,7 +245,7 @@ export const oauthForgetPassword = async ({ email }, context) => {
257
245
  } else {
258
246
  resetUrl.searchParams.set("hash", "{hash}");
259
247
  }
260
- await axiosInstance2.post("/auth/password/send-reset-email", {
248
+ await axiosInstance.post("/auth/password/send-reset-email", {
261
249
  email,
262
250
  reset_url: decodeURI(resetUrl.toString()),
263
251
  shop_id: shopId
@@ -278,9 +266,9 @@ export const oauthForgetPassword = async ({ email }, context) => {
278
266
  };
279
267
  export const updatePasswordByHash = async (passwordHash, context) => {
280
268
  const shopId = context.shopId;
281
- const { axiosInstance: axiosInstance2 } = getOAuthSettings(context);
269
+ const { axiosInstance } = getOAuthSettings(context);
282
270
  try {
283
- const response = await axiosInstance2.put(
271
+ const response = await axiosInstance.put(
284
272
  "/auth/password/update-by-hash",
285
273
  {
286
274
  ...passwordHash,
@@ -292,9 +280,6 @@ export const updatePasswordByHash = async (passwordHash, context) => {
292
280
  refreshToken: response.data.refresh_token
293
281
  });
294
282
  await context.createUserBoundSession();
295
- return {
296
- oauth: response.data
297
- };
298
283
  } catch (error) {
299
284
  const err = convertErrorForRpcCall(error, [
300
285
  HttpStatusCode.BAD_REQUEST,
@@ -304,6 +289,5 @@ export const updatePasswordByHash = async (passwordHash, context) => {
304
289
  if (err) {
305
290
  throw err;
306
291
  }
307
- return { oauth: null };
308
292
  }
309
293
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/storefront-core",
3
- "version": "7.25.1",
3
+ "version": "7.26.0",
4
4
  "description": "Collection of essential utilities to work with the Storefront API",
5
5
  "author": "SCAYLE Commerce Engine",
6
6
  "license": "MIT",
@@ -56,11 +56,11 @@
56
56
  "test:ci": "jest --passWithNoTests --runInBand --coverage --reporters=default --reporters=jest-junit"
57
57
  },
58
58
  "peerDependencies": {
59
- "@aboutyou/backbone": "15.14.1",
59
+ "@aboutyou/backbone": "15.14.2",
60
60
  "axios": "^0.21.1 || ^0.27.0"
61
61
  },
62
62
  "dependencies": {
63
- "@aboutyou/backbone": "15.14.1",
63
+ "@aboutyou/backbone": "15.14.2",
64
64
  "crypto-js": "4.2.0",
65
65
  "jose": "^4.14.4",
66
66
  "radash": "^11.0.0",