@scayle/storefront-core 7.59.1 → 7.60.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 +25 -0
- package/dist/errors/errorResponse.cjs +27 -0
- package/dist/errors/errorResponse.d.ts +12 -0
- package/dist/errors/errorResponse.mjs +20 -0
- package/dist/errors/index.cjs +11 -0
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.mjs +1 -0
- package/dist/rpc/methods/basket/basket.cjs +14 -4
- package/dist/rpc/methods/basket/basket.d.ts +5 -4
- package/dist/rpc/methods/basket/basket.mjs +24 -14
- package/dist/rpc/methods/checkout/checkout.cjs +4 -2
- package/dist/rpc/methods/checkout/checkout.mjs +8 -2
- package/dist/rpc/methods/checkout/order.cjs +9 -6
- package/dist/rpc/methods/checkout/order.d.ts +2 -1
- package/dist/rpc/methods/checkout/order.mjs +38 -7
- package/dist/rpc/methods/checkout/shopUser.cjs +14 -7
- package/dist/rpc/methods/checkout/shopUser.d.ts +3 -2
- package/dist/rpc/methods/checkout/shopUser.mjs +42 -9
- package/dist/rpc/methods/oauth/idp.cjs +4 -6
- package/dist/rpc/methods/oauth/idp.d.ts +2 -1
- package/dist/rpc/methods/oauth/idp.mjs +12 -2
- package/dist/rpc/methods/products.cjs +15 -6
- package/dist/rpc/methods/products.d.ts +3 -2
- package/dist/rpc/methods/products.mjs +15 -10
- package/dist/rpc/methods/session.cjs +40 -37
- package/dist/rpc/methods/session.d.ts +3 -2
- package/dist/rpc/methods/session.mjs +74 -46
- package/dist/rpc/methods/wishlist.cjs +7 -2
- package/dist/rpc/methods/wishlist.mjs +16 -3
- package/dist/utils/timeout.cjs +5 -4
- package/dist/utils/timeout.d.ts +1 -1
- package/dist/utils/timeout.mjs +5 -4
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @scayle/storefront-core
|
|
2
2
|
|
|
3
|
+
## 7.60.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Instead of throwing errors, RPCs will now return an `ErrorResponse` object conforming to [RFC9457](https://datatracker.ietf.org/doc/html/rfc9457).
|
|
8
|
+
|
|
9
|
+
In addition to this change, existing RPCs have been reviewed and updated to return more accurate and descriptive HTTP status codes.
|
|
10
|
+
|
|
11
|
+
This change allows us to provide more informative error messages and utilize standardized HTTP status codes for better context. The `ErrorResponse` object can include additional details about the error, making it easier to identify and address root causes.
|
|
12
|
+
|
|
13
|
+
**Action Required:**
|
|
14
|
+
|
|
15
|
+
Code that previously made direct RPC calls (calling the function directly instead of via `useRpc` or `rpcCall`) and relied on `try {} catch {}` blocks for error handling needs to be updated. Moving forward, please check the status of the RPC response directly.
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies
|
|
20
|
+
- @scayle/storefront-api@17.4.1
|
|
21
|
+
|
|
22
|
+
## 7.59.2
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- Resolved a memory leak within the `timeout` util where `setTimeout` might not have been garbage collected if the promise had been resolved/rejected before the timeout itself
|
|
27
|
+
|
|
3
28
|
## 7.59.1
|
|
4
29
|
|
|
5
30
|
### Patch Changes
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ErrorResponse = void 0;
|
|
7
|
+
class ErrorResponse extends Response {
|
|
8
|
+
title;
|
|
9
|
+
details;
|
|
10
|
+
constructor(statusCode, statusMessage, title, detail) {
|
|
11
|
+
const response = {
|
|
12
|
+
title,
|
|
13
|
+
status: statusCode,
|
|
14
|
+
...detail
|
|
15
|
+
};
|
|
16
|
+
super(JSON.stringify(response, null, 2), {
|
|
17
|
+
status: statusCode,
|
|
18
|
+
statusText: statusMessage,
|
|
19
|
+
headers: {
|
|
20
|
+
"Content-Type": "application/problem+json"
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
this.title = title;
|
|
24
|
+
this.details = detail;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.ErrorResponse = ErrorResponse;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface ErrorResponseDetails {
|
|
2
|
+
detail?: string;
|
|
3
|
+
instance?: string;
|
|
4
|
+
type?: string;
|
|
5
|
+
[s: string]: string | undefined;
|
|
6
|
+
}
|
|
7
|
+
export declare class ErrorResponse extends Response {
|
|
8
|
+
title: string;
|
|
9
|
+
details?: ErrorResponseDetails;
|
|
10
|
+
constructor(statusCode: number, statusMessage: string, title: string, detail?: ErrorResponseDetails);
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export class ErrorResponse extends Response {
|
|
2
|
+
title;
|
|
3
|
+
details;
|
|
4
|
+
constructor(statusCode, statusMessage, title, detail) {
|
|
5
|
+
const response = {
|
|
6
|
+
title,
|
|
7
|
+
status: statusCode,
|
|
8
|
+
...detail
|
|
9
|
+
};
|
|
10
|
+
super(JSON.stringify(response, null, 2), {
|
|
11
|
+
status: statusCode,
|
|
12
|
+
statusText: statusMessage,
|
|
13
|
+
headers: {
|
|
14
|
+
"Content-Type": "application/problem+json"
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
this.title = title;
|
|
18
|
+
this.details = detail;
|
|
19
|
+
}
|
|
20
|
+
}
|
package/dist/errors/index.cjs
CHANGED
|
@@ -24,4 +24,15 @@ Object.keys(_baseError).forEach(function (key) {
|
|
|
24
24
|
return _baseError[key];
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
|
+
});
|
|
28
|
+
var _errorResponse = require("./errorResponse.cjs");
|
|
29
|
+
Object.keys(_errorResponse).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _errorResponse[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return _errorResponse[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
27
38
|
});
|
package/dist/errors/index.d.ts
CHANGED
package/dist/errors/index.mjs
CHANGED
|
@@ -61,7 +61,9 @@ const addItemToBasket = exports.addItemToBasket = async function addItemToBasket
|
|
|
61
61
|
message,
|
|
62
62
|
statusCode
|
|
63
63
|
});
|
|
64
|
-
|
|
64
|
+
return new _errors.ErrorResponse(statusCode, BAPI_ERROR_NAME, "Adding item to basket failed", {
|
|
65
|
+
detail: message
|
|
66
|
+
});
|
|
65
67
|
}
|
|
66
68
|
};
|
|
67
69
|
const addItemsToBasket = exports.addItemsToBasket = async function addItemsToBasket2(params, context) {
|
|
@@ -103,7 +105,9 @@ const addItemsToBasket = exports.addItemsToBasket = async function addItemsToBas
|
|
|
103
105
|
statusCode,
|
|
104
106
|
message
|
|
105
107
|
});
|
|
106
|
-
|
|
108
|
+
return new _errors.ErrorResponse(statusCode, BAPI_ERROR_NAME, "Adding one or more items to basket failed", {
|
|
109
|
+
detail: message
|
|
110
|
+
});
|
|
107
111
|
}
|
|
108
112
|
};
|
|
109
113
|
const getBasket = exports.getBasket = async function getBasket2(options, context) {
|
|
@@ -126,7 +130,9 @@ const getBasket = exports.getBasket = async function getBasket2(options, context
|
|
|
126
130
|
statusCode,
|
|
127
131
|
message
|
|
128
132
|
} = parseBasketError(response);
|
|
129
|
-
|
|
133
|
+
return new _errors.ErrorResponse(statusCode, BAPI_ERROR_NAME, "Adding item to basket failed", {
|
|
134
|
+
detail: message
|
|
135
|
+
});
|
|
130
136
|
}
|
|
131
137
|
return response.basket;
|
|
132
138
|
};
|
|
@@ -145,7 +151,11 @@ const removeItemFromBasket = exports.removeItemFromBasket = async function remov
|
|
|
145
151
|
});
|
|
146
152
|
};
|
|
147
153
|
const clearBasket = exports.clearBasket = async function clearBasket2(context) {
|
|
148
|
-
const
|
|
154
|
+
const getBasketResponse = await getBasket({}, context);
|
|
155
|
+
if (getBasketResponse instanceof _errors.ErrorResponse) {
|
|
156
|
+
return getBasketResponse;
|
|
157
|
+
}
|
|
158
|
+
const basket = await (0, _response.unwrap)(getBasketResponse);
|
|
149
159
|
await Promise.all(basket.items.map(async item => {
|
|
150
160
|
await removeItemFromBasket({
|
|
151
161
|
itemKey: item.key
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import type { AddOrUpdateItemError } from '@scayle/storefront-api';
|
|
2
|
+
import { ErrorResponse } from '../../../errors';
|
|
2
3
|
import type { AddOrUpdateItemType, BasketResponseData, BasketWithOptions, Product, RpcContext, Variant } from '../../../types';
|
|
3
4
|
import { ExistingItemHandling } from '../../../constants';
|
|
4
5
|
export declare const addItemToBasket: ({ variantId, promotionId, quantity, displayData, customData, existingItemHandling, itemGroup, with: _with, }: AddOrUpdateItemType & {
|
|
5
6
|
existingItemHandling?: ExistingItemHandling;
|
|
6
7
|
with?: BasketWithOptions;
|
|
7
|
-
}, context: RpcContext) => Promise<BasketResponseData<Product, Variant>>;
|
|
8
|
+
}, context: RpcContext) => Promise<ErrorResponse | BasketResponseData<Product, Variant>>;
|
|
8
9
|
export declare const addItemsToBasket: (params: {
|
|
9
10
|
items: AddOrUpdateItemType[];
|
|
10
11
|
existingItemHandling: ExistingItemHandling;
|
|
11
12
|
with?: BasketWithOptions;
|
|
12
|
-
}, context: RpcContext) => Promise<BasketResponseData<Product, Variant>>;
|
|
13
|
-
export declare const getBasket: (options: BasketWithOptions | undefined, context: RpcContext) => Promise<BasketResponseData<Product, Variant>>;
|
|
13
|
+
}, context: RpcContext) => Promise<ErrorResponse | BasketResponseData<Product, Variant>>;
|
|
14
|
+
export declare const getBasket: (options: BasketWithOptions | undefined, context: RpcContext) => Promise<ErrorResponse | BasketResponseData<Product, Variant>>;
|
|
14
15
|
export declare const removeItemFromBasket: (options: {
|
|
15
16
|
itemKey: string;
|
|
16
17
|
with?: BasketWithOptions;
|
|
17
18
|
}, context: RpcContext) => Promise<BasketResponseData<Product, Variant>>;
|
|
18
|
-
export declare const clearBasket: (context: RpcContext) => Promise<
|
|
19
|
+
export declare const clearBasket: (context: RpcContext) => Promise<true | ErrorResponse>;
|
|
19
20
|
export declare const mergeBaskets: ({ fromBasketKey, toBasketKey, with: _with }: {
|
|
20
21
|
fromBasketKey: string;
|
|
21
22
|
toBasketKey: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ErrorResponse } from "../../../errors/index.mjs";
|
|
2
2
|
import { assertSession } from "../../../types/index.mjs";
|
|
3
3
|
import {
|
|
4
4
|
ExistingItemHandling,
|
|
@@ -56,11 +56,13 @@ export const addItemToBasket = async function addItemToBasket2({
|
|
|
56
56
|
} else {
|
|
57
57
|
const { message, statusCode } = parseBasketError(result);
|
|
58
58
|
context.log.error("Adding item to basket failed", { message, statusCode });
|
|
59
|
-
|
|
60
|
-
BAPI_ERROR_NAME,
|
|
59
|
+
return new ErrorResponse(
|
|
61
60
|
statusCode,
|
|
62
|
-
|
|
63
|
-
"
|
|
61
|
+
BAPI_ERROR_NAME,
|
|
62
|
+
"Adding item to basket failed",
|
|
63
|
+
{
|
|
64
|
+
detail: message
|
|
65
|
+
}
|
|
64
66
|
);
|
|
65
67
|
}
|
|
66
68
|
};
|
|
@@ -101,11 +103,13 @@ export const addItemsToBasket = async function addItemsToBasket2(params, context
|
|
|
101
103
|
statusCode,
|
|
102
104
|
message
|
|
103
105
|
});
|
|
104
|
-
|
|
105
|
-
BAPI_ERROR_NAME,
|
|
106
|
+
return new ErrorResponse(
|
|
106
107
|
statusCode,
|
|
107
|
-
|
|
108
|
-
"
|
|
108
|
+
BAPI_ERROR_NAME,
|
|
109
|
+
"Adding one or more items to basket failed",
|
|
110
|
+
{
|
|
111
|
+
detail: message
|
|
112
|
+
}
|
|
109
113
|
);
|
|
110
114
|
}
|
|
111
115
|
};
|
|
@@ -123,11 +127,13 @@ export const getBasket = async function getBasket2(options, context) {
|
|
|
123
127
|
});
|
|
124
128
|
if (response.type === "failure") {
|
|
125
129
|
const { statusCode, message } = parseBasketError(response);
|
|
126
|
-
|
|
127
|
-
BAPI_ERROR_NAME,
|
|
130
|
+
return new ErrorResponse(
|
|
128
131
|
statusCode,
|
|
129
|
-
|
|
130
|
-
"
|
|
132
|
+
BAPI_ERROR_NAME,
|
|
133
|
+
"Adding item to basket failed",
|
|
134
|
+
{
|
|
135
|
+
detail: message
|
|
136
|
+
}
|
|
131
137
|
);
|
|
132
138
|
}
|
|
133
139
|
return response.basket;
|
|
@@ -143,7 +149,11 @@ export const removeItemFromBasket = async function removeItemFromBasket2(options
|
|
|
143
149
|
});
|
|
144
150
|
};
|
|
145
151
|
export const clearBasket = async function clearBasket2(context) {
|
|
146
|
-
const
|
|
152
|
+
const getBasketResponse = await getBasket({}, context);
|
|
153
|
+
if (getBasketResponse instanceof ErrorResponse) {
|
|
154
|
+
return getBasketResponse;
|
|
155
|
+
}
|
|
156
|
+
const basket = await unwrap(getBasketResponse);
|
|
147
157
|
await Promise.all(
|
|
148
158
|
basket.items.map(async (item) => {
|
|
149
159
|
await removeItemFromBasket({ itemKey: item.key }, context);
|
|
@@ -5,10 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.getCheckoutToken = void 0;
|
|
7
7
|
var _jose = require("jose");
|
|
8
|
+
var _errors = require("../../../errors/index.cjs");
|
|
9
|
+
var _constants = require("../../../constants/index.cjs");
|
|
8
10
|
var _user = require("../user.cjs");
|
|
9
11
|
const getCheckoutToken = exports.getCheckoutToken = async function getCheckoutToken2(jwtPayload = {}, context) {
|
|
10
12
|
if (!context.accessToken) {
|
|
11
|
-
|
|
13
|
+
return new _errors.ErrorResponse(_constants.HttpStatusCode.UNAUTHORIZED, _constants.HttpStatusMessage.UNAUTHORIZED, "No access token present");
|
|
12
14
|
}
|
|
13
15
|
const refreshedAccessToken = await (0, _user.getAccessToken)({
|
|
14
16
|
forceTokenRefresh: true
|
|
@@ -31,7 +33,7 @@ const getCheckoutToken = exports.getCheckoutToken = async function getCheckoutTo
|
|
|
31
33
|
carrier,
|
|
32
34
|
basketId: context.basketKey,
|
|
33
35
|
campaignKey: context.campaignKey
|
|
34
|
-
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"7.
|
|
36
|
+
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"7.60.0"}`).setProtectedHeader({
|
|
35
37
|
alg: "HS256",
|
|
36
38
|
typ: "JWT"
|
|
37
39
|
}).sign(secret);
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { SignJWT } from "jose";
|
|
2
|
+
import { ErrorResponse } from "../../../errors/index.mjs";
|
|
3
|
+
import { HttpStatusCode, HttpStatusMessage } from "../../../constants/index.mjs";
|
|
2
4
|
import { getAccessToken } from "../user.mjs";
|
|
3
5
|
export const getCheckoutToken = async function getCheckoutToken2(jwtPayload = {}, context) {
|
|
4
6
|
if (!context.accessToken) {
|
|
5
|
-
|
|
7
|
+
return new ErrorResponse(
|
|
8
|
+
HttpStatusCode.UNAUTHORIZED,
|
|
9
|
+
HttpStatusMessage.UNAUTHORIZED,
|
|
10
|
+
"No access token present"
|
|
11
|
+
);
|
|
6
12
|
}
|
|
7
13
|
const refreshedAccessToken = await getAccessToken(
|
|
8
14
|
{ forceTokenRefresh: true },
|
|
@@ -21,7 +27,7 @@ export const getCheckoutToken = async function getCheckoutToken2(jwtPayload = {}
|
|
|
21
27
|
carrier,
|
|
22
28
|
basketId: context.basketKey,
|
|
23
29
|
campaignKey: context.campaignKey
|
|
24
|
-
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"7.
|
|
30
|
+
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"7.60.0"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
|
|
25
31
|
return {
|
|
26
32
|
accessToken: refreshedAccessToken,
|
|
27
33
|
checkoutJwt
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getOrderById = void 0;
|
|
7
|
+
var _errors = require("../../../errors/index.cjs");
|
|
7
8
|
var _fetch = require("../../../utils/fetch.cjs");
|
|
8
9
|
var _customer = require("../../../api/customer.cjs");
|
|
9
10
|
var _httpStatus = require("../../../constants/httpStatus.cjs");
|
|
@@ -12,14 +13,14 @@ const getOrderById = exports.getOrderById = async function getOrderById2({
|
|
|
12
13
|
}, context) {
|
|
13
14
|
const accessToken = context.accessToken;
|
|
14
15
|
if (!orderId || isNaN(orderId)) {
|
|
15
|
-
|
|
16
|
+
return new _errors.ErrorResponse(_httpStatus.HttpStatusCode.NOT_FOUND, _httpStatus.HttpStatusMessage.NOT_FOUND, "No order ID provided");
|
|
16
17
|
}
|
|
17
18
|
if (!accessToken) {
|
|
18
|
-
|
|
19
|
+
return new _errors.ErrorResponse(_httpStatus.HttpStatusCode.UNAUTHORIZED, _httpStatus.HttpStatusMessage.UNAUTHORIZED, "No access token present");
|
|
19
20
|
}
|
|
20
21
|
const isOrderInUserOrderlist = context.user?.orderSummary?.find(order => order.id === orderId);
|
|
21
22
|
if (!isOrderInUserOrderlist) {
|
|
22
|
-
|
|
23
|
+
return new _errors.ErrorResponse(_httpStatus.HttpStatusCode.UNAUTHORIZED, _httpStatus.HttpStatusMessage.UNAUTHORIZED, "Order not belonging to current user");
|
|
23
24
|
}
|
|
24
25
|
const client = new _customer.CustomerAPIClient(context);
|
|
25
26
|
try {
|
|
@@ -27,13 +28,15 @@ const getOrderById = exports.getOrderById = async function getOrderById2({
|
|
|
27
28
|
} catch (error) {
|
|
28
29
|
if (error instanceof _fetch.FetchError) {
|
|
29
30
|
if (error.response.status === _httpStatus.HttpStatusCode.NOT_FOUND) {
|
|
30
|
-
|
|
31
|
+
return new _errors.ErrorResponse(_httpStatus.HttpStatusCode.NOT_FOUND, _httpStatus.HttpStatusMessage.NOT_FOUND, "Order not found");
|
|
31
32
|
}
|
|
32
|
-
|
|
33
|
+
return new _errors.ErrorResponse(_httpStatus.HttpStatusCode.INTERNAL_SERVER_ERROR, _httpStatus.HttpStatusMessage.INTERNAL_SERVER_ERROR, "Unknown error", {
|
|
34
|
+
detail: `Fetching order "${orderId}" failed with status code ${error.response.status}`
|
|
35
|
+
});
|
|
33
36
|
}
|
|
34
37
|
context.log.error("Error while fetching order details", {
|
|
35
38
|
error
|
|
36
39
|
});
|
|
37
|
-
|
|
40
|
+
return new _errors.ErrorResponse(_httpStatus.HttpStatusCode.INTERNAL_SERVER_ERROR, _httpStatus.HttpStatusMessage.INTERNAL_SERVER_ERROR, "Unknown error");
|
|
38
41
|
}
|
|
39
42
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import { ErrorResponse } from '../../../errors';
|
|
1
2
|
import type { Order } from '../../../types';
|
|
2
3
|
export declare const getOrderById: ({ orderId }: {
|
|
3
4
|
orderId: number;
|
|
4
|
-
}, context: import("../../../types").RpcContext) => Promise<Order>;
|
|
5
|
+
}, context: import("../../../types").RpcContext) => Promise<Order | ErrorResponse>;
|
|
@@ -1,19 +1,35 @@
|
|
|
1
|
+
import { ErrorResponse } from "../../../errors/index.mjs";
|
|
1
2
|
import { FetchError } from "../../../utils/fetch.mjs";
|
|
2
3
|
import { CustomerAPIClient } from "../../../api/customer.mjs";
|
|
3
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
HttpStatusCode,
|
|
6
|
+
HttpStatusMessage
|
|
7
|
+
} from "../../../constants/httpStatus.mjs";
|
|
4
8
|
export const getOrderById = async function getOrderById2({ orderId }, context) {
|
|
5
9
|
const accessToken = context.accessToken;
|
|
6
10
|
if (!orderId || isNaN(orderId)) {
|
|
7
|
-
|
|
11
|
+
return new ErrorResponse(
|
|
12
|
+
HttpStatusCode.NOT_FOUND,
|
|
13
|
+
HttpStatusMessage.NOT_FOUND,
|
|
14
|
+
"No order ID provided"
|
|
15
|
+
);
|
|
8
16
|
}
|
|
9
17
|
if (!accessToken) {
|
|
10
|
-
|
|
18
|
+
return new ErrorResponse(
|
|
19
|
+
HttpStatusCode.UNAUTHORIZED,
|
|
20
|
+
HttpStatusMessage.UNAUTHORIZED,
|
|
21
|
+
"No access token present"
|
|
22
|
+
);
|
|
11
23
|
}
|
|
12
24
|
const isOrderInUserOrderlist = context.user?.orderSummary?.find(
|
|
13
25
|
(order) => order.id === orderId
|
|
14
26
|
);
|
|
15
27
|
if (!isOrderInUserOrderlist) {
|
|
16
|
-
|
|
28
|
+
return new ErrorResponse(
|
|
29
|
+
HttpStatusCode.UNAUTHORIZED,
|
|
30
|
+
HttpStatusMessage.UNAUTHORIZED,
|
|
31
|
+
"Order not belonging to current user"
|
|
32
|
+
);
|
|
17
33
|
}
|
|
18
34
|
const client = new CustomerAPIClient(context);
|
|
19
35
|
try {
|
|
@@ -21,11 +37,26 @@ export const getOrderById = async function getOrderById2({ orderId }, context) {
|
|
|
21
37
|
} catch (error) {
|
|
22
38
|
if (error instanceof FetchError) {
|
|
23
39
|
if (error.response.status === HttpStatusCode.NOT_FOUND) {
|
|
24
|
-
|
|
40
|
+
return new ErrorResponse(
|
|
41
|
+
HttpStatusCode.NOT_FOUND,
|
|
42
|
+
HttpStatusMessage.NOT_FOUND,
|
|
43
|
+
"Order not found"
|
|
44
|
+
);
|
|
25
45
|
}
|
|
26
|
-
|
|
46
|
+
return new ErrorResponse(
|
|
47
|
+
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
|
48
|
+
HttpStatusMessage.INTERNAL_SERVER_ERROR,
|
|
49
|
+
"Unknown error",
|
|
50
|
+
{
|
|
51
|
+
detail: `Fetching order "${orderId}" failed with status code ${error.response.status}`
|
|
52
|
+
}
|
|
53
|
+
);
|
|
27
54
|
}
|
|
28
55
|
context.log.error("Error while fetching order details", { error });
|
|
29
|
-
|
|
56
|
+
return new ErrorResponse(
|
|
57
|
+
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
|
58
|
+
HttpStatusMessage.INTERNAL_SERVER_ERROR,
|
|
59
|
+
"Unknown error"
|
|
60
|
+
);
|
|
30
61
|
}
|
|
31
62
|
};
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.updateShopUser = exports.updatePassword = void 0;
|
|
7
|
+
var _errors = require("../../../errors/index.cjs");
|
|
7
8
|
var _customer = require("../../../api/customer.cjs");
|
|
8
9
|
var _oauth = require("../../../api/oauth.cjs");
|
|
9
10
|
var _fetch = require("../../../utils/fetch.cjs");
|
|
@@ -22,7 +23,7 @@ const updateShopUser = exports.updateShopUser = async function updateShopUser2(p
|
|
|
22
23
|
if (!context.user) {
|
|
23
24
|
const message = "Unauthorized request: Missing access token";
|
|
24
25
|
context.log.error(message);
|
|
25
|
-
|
|
26
|
+
return new _errors.ErrorResponse(_httpStatus.HttpStatusCode.UNAUTHORIZED, _httpStatus.HttpStatusMessage.UNAUTHORIZED, "No access token present");
|
|
26
27
|
}
|
|
27
28
|
const user = {
|
|
28
29
|
...context.user,
|
|
@@ -50,7 +51,7 @@ const updateShopUser = exports.updateShopUser = async function updateShopUser2(p
|
|
|
50
51
|
};
|
|
51
52
|
} catch (error) {
|
|
52
53
|
context.log.error("Error while updating user information", error);
|
|
53
|
-
|
|
54
|
+
return new _errors.ErrorResponse(_httpStatus.HttpStatusCode.INTERNAL_SERVER_ERROR, _httpStatus.HttpStatusMessage.INTERNAL_SERVER_ERROR, "Error while updating user information");
|
|
54
55
|
}
|
|
55
56
|
};
|
|
56
57
|
const updatePassword = exports.updatePassword = async function updatePassword2({
|
|
@@ -63,7 +64,7 @@ const updatePassword = exports.updatePassword = async function updatePassword2({
|
|
|
63
64
|
if (oauthEnabled) {
|
|
64
65
|
const client2 = (0, _oauth.getOAuthClient)(context);
|
|
65
66
|
if (!context.accessToken) {
|
|
66
|
-
|
|
67
|
+
return new _errors.ErrorResponse(_httpStatus.HttpStatusCode.UNAUTHORIZED, _httpStatus.HttpStatusMessage.UNAUTHORIZED, "No access token present");
|
|
67
68
|
}
|
|
68
69
|
await client2.updatePassword({
|
|
69
70
|
password: oldPassword,
|
|
@@ -87,14 +88,20 @@ const updatePassword = exports.updatePassword = async function updatePassword2({
|
|
|
87
88
|
} catch (error) {
|
|
88
89
|
if (!(error instanceof _fetch.FetchError)) {
|
|
89
90
|
context.log.error("Error while updating user's password", error);
|
|
90
|
-
|
|
91
|
+
return new _errors.ErrorResponse(_httpStatus.HttpStatusCode.INTERNAL_SERVER_ERROR, _httpStatus.HttpStatusMessage.INTERNAL_SERVER_ERROR, "Error while updating user's password");
|
|
91
92
|
}
|
|
92
93
|
if (error.response.status === _httpStatus.HttpStatusCode.UNAUTHORIZED) {
|
|
93
|
-
|
|
94
|
+
return new _errors.ErrorResponse(_httpStatus.HttpStatusCode.UNAUTHORIZED, _httpStatus.HttpStatusMessage.UNAUTHORIZED, "Failed to update user's password", {
|
|
95
|
+
detail: "Unauthorized request"
|
|
96
|
+
});
|
|
94
97
|
} else if (error.response.status === _httpStatus.HttpStatusCode.FORBIDDEN) {
|
|
95
|
-
|
|
98
|
+
return new _errors.ErrorResponse(_httpStatus.HttpStatusCode.FORBIDDEN, _httpStatus.HttpStatusMessage.FORBIDDEN, "Failed to update user's password", {
|
|
99
|
+
detail: "Invalid auth"
|
|
100
|
+
});
|
|
96
101
|
} else if (error.response.status === _httpStatus.HttpStatusCode.NOT_FOUND) {
|
|
97
|
-
|
|
102
|
+
return new _errors.ErrorResponse(_httpStatus.HttpStatusCode.NOT_FOUND, _httpStatus.HttpStatusMessage.NOT_FOUND, "Failed to update user's password", {
|
|
103
|
+
detail: "User not found"
|
|
104
|
+
});
|
|
98
105
|
}
|
|
99
106
|
}
|
|
100
107
|
return {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { ErrorResponse } from '../../../errors';
|
|
1
2
|
import type { ShopUser, UpdatePasswordParams } from '../../../types';
|
|
2
|
-
export declare const updateShopUser: (payload: Partial<ShopUser>, context: import("../../../types").RpcContext) => Promise<{
|
|
3
|
+
export declare const updateShopUser: (payload: Partial<ShopUser>, context: import("../../../types").RpcContext) => Promise<ErrorResponse | {
|
|
3
4
|
user: ShopUser;
|
|
4
5
|
}>;
|
|
5
|
-
export declare const updatePassword: ({ oldPassword, newPassword }: UpdatePasswordParams, context: import("../../../types").RpcContext) => Promise<{
|
|
6
|
+
export declare const updatePassword: ({ oldPassword, newPassword }: UpdatePasswordParams, context: import("../../../types").RpcContext) => Promise<ErrorResponse | {
|
|
6
7
|
user: ShopUser | undefined;
|
|
7
8
|
}>;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { ErrorResponse } from "../../../errors/index.mjs";
|
|
1
2
|
import { CustomerAPIClient } from "../../../api/customer.mjs";
|
|
2
3
|
import { getOAuthClient } from "../../../api/oauth.mjs";
|
|
3
4
|
import { FetchError } from "../../../utils/fetch.mjs";
|
|
4
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
HttpStatusCode,
|
|
7
|
+
HttpStatusMessage
|
|
8
|
+
} from "../../../constants/httpStatus.mjs";
|
|
5
9
|
export const updateShopUser = async function updateShopUser2(payload, context) {
|
|
6
10
|
const shopId = context.shopId;
|
|
7
11
|
const updatedUser = {
|
|
@@ -16,7 +20,11 @@ export const updateShopUser = async function updateShopUser2(payload, context) {
|
|
|
16
20
|
if (!context.user) {
|
|
17
21
|
const message = "Unauthorized request: Missing access token";
|
|
18
22
|
context.log.error(message);
|
|
19
|
-
|
|
23
|
+
return new ErrorResponse(
|
|
24
|
+
HttpStatusCode.UNAUTHORIZED,
|
|
25
|
+
HttpStatusMessage.UNAUTHORIZED,
|
|
26
|
+
"No access token present"
|
|
27
|
+
);
|
|
20
28
|
}
|
|
21
29
|
const user = {
|
|
22
30
|
...context.user,
|
|
@@ -41,7 +49,11 @@ export const updateShopUser = async function updateShopUser2(payload, context) {
|
|
|
41
49
|
return { user };
|
|
42
50
|
} catch (error) {
|
|
43
51
|
context.log.error("Error while updating user information", error);
|
|
44
|
-
|
|
52
|
+
return new ErrorResponse(
|
|
53
|
+
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
|
54
|
+
HttpStatusMessage.INTERNAL_SERVER_ERROR,
|
|
55
|
+
"Error while updating user information"
|
|
56
|
+
);
|
|
45
57
|
}
|
|
46
58
|
};
|
|
47
59
|
export const updatePassword = async function updatePassword2({ oldPassword, newPassword }, context) {
|
|
@@ -51,7 +63,11 @@ export const updatePassword = async function updatePassword2({ oldPassword, newP
|
|
|
51
63
|
if (oauthEnabled) {
|
|
52
64
|
const client2 = getOAuthClient(context);
|
|
53
65
|
if (!context.accessToken) {
|
|
54
|
-
|
|
66
|
+
return new ErrorResponse(
|
|
67
|
+
HttpStatusCode.UNAUTHORIZED,
|
|
68
|
+
HttpStatusMessage.UNAUTHORIZED,
|
|
69
|
+
"No access token present"
|
|
70
|
+
);
|
|
55
71
|
}
|
|
56
72
|
await client2.updatePassword(
|
|
57
73
|
{
|
|
@@ -74,16 +90,33 @@ export const updatePassword = async function updatePassword2({ oldPassword, newP
|
|
|
74
90
|
} catch (error) {
|
|
75
91
|
if (!(error instanceof FetchError)) {
|
|
76
92
|
context.log.error("Error while updating user's password", error);
|
|
77
|
-
|
|
93
|
+
return new ErrorResponse(
|
|
94
|
+
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
|
95
|
+
HttpStatusMessage.INTERNAL_SERVER_ERROR,
|
|
96
|
+
"Error while updating user's password"
|
|
97
|
+
);
|
|
78
98
|
}
|
|
79
99
|
if (error.response.status === HttpStatusCode.UNAUTHORIZED) {
|
|
80
|
-
|
|
81
|
-
|
|
100
|
+
return new ErrorResponse(
|
|
101
|
+
HttpStatusCode.UNAUTHORIZED,
|
|
102
|
+
HttpStatusMessage.UNAUTHORIZED,
|
|
103
|
+
"Failed to update user's password",
|
|
104
|
+
{ detail: "Unauthorized request" }
|
|
82
105
|
);
|
|
83
106
|
} else if (error.response.status === HttpStatusCode.FORBIDDEN) {
|
|
84
|
-
|
|
107
|
+
return new ErrorResponse(
|
|
108
|
+
HttpStatusCode.FORBIDDEN,
|
|
109
|
+
HttpStatusMessage.FORBIDDEN,
|
|
110
|
+
"Failed to update user's password",
|
|
111
|
+
{ detail: "Invalid auth" }
|
|
112
|
+
);
|
|
85
113
|
} else if (error.response.status === HttpStatusCode.NOT_FOUND) {
|
|
86
|
-
|
|
114
|
+
return new ErrorResponse(
|
|
115
|
+
HttpStatusCode.NOT_FOUND,
|
|
116
|
+
HttpStatusMessage.NOT_FOUND,
|
|
117
|
+
"Failed to update user's password",
|
|
118
|
+
{ detail: "User not found" }
|
|
119
|
+
);
|
|
87
120
|
}
|
|
88
121
|
}
|
|
89
122
|
return { user: shopUser };
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.handleIDPLoginCallback = exports.getExternalIdpRedirect = void 0;
|
|
7
7
|
var _jose = require("jose");
|
|
8
|
+
var _errors = require("../../../errors/index.cjs");
|
|
9
|
+
var _constants = require("../../../constants/index.cjs");
|
|
8
10
|
var _types = require("../../../types/index.cjs");
|
|
9
11
|
var _oauth = require("../../../api/oauth.cjs");
|
|
10
12
|
var _session = require("../session.cjs");
|
|
@@ -15,14 +17,10 @@ const getExternalIdpRedirect = exports.getExternalIdpRedirect = async function g
|
|
|
15
17
|
return {};
|
|
16
18
|
}
|
|
17
19
|
if (context.idp.idpKeys.length === 0) {
|
|
18
|
-
return new
|
|
19
|
-
status: 400
|
|
20
|
-
});
|
|
20
|
+
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No IDP keys are configured");
|
|
21
21
|
}
|
|
22
22
|
if (!context.idp.idpRedirectURL) {
|
|
23
|
-
return new
|
|
24
|
-
status: 400
|
|
25
|
-
});
|
|
23
|
+
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No IDP redirect url is configured");
|
|
26
24
|
}
|
|
27
25
|
const OAuthClient = (0, _oauth.getOAuthClient)(context);
|
|
28
26
|
const redirectUrl = new URL(context.idp.idpRedirectURL);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { ErrorResponse } from '../../../errors';
|
|
1
2
|
import type { RpcContext } from '../../../types';
|
|
2
3
|
export declare const getExternalIdpRedirect: ({ queryParams }: {
|
|
3
4
|
queryParams?: Record<string, string>;
|
|
4
|
-
}, context: RpcContext) => Promise<
|
|
5
|
+
}, context: RpcContext) => Promise<ErrorResponse | {
|
|
5
6
|
[k: string]: string;
|
|
6
7
|
}>;
|
|
7
8
|
export declare const handleIDPLoginCallback: (payload: {
|