diff options
author | Sebastian <sebasjm@gmail.com> | 2024-04-03 15:31:28 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-04-03 15:31:28 -0300 |
commit | c7e68c254aa93778b8201227d6db1ac57e081e81 (patch) | |
tree | b5d34651a8d17180826dcd4f09bb808f2f080b21 | |
parent | 4bf1ab8ba924b2a0fc4813814bdeeb66a2928382 (diff) | |
download | wallet-core-c7e68c254aa93778b8201227d6db1ac57e081e81.tar.gz wallet-core-c7e68c254aa93778b8201227d6db1ac57e081e81.tar.bz2 wallet-core-c7e68c254aa93778b8201227d6db1ac57e081e81.zip |
wip #8655: unauthorized not documented
25 files changed, 495 insertions, 228 deletions
diff --git a/packages/merchant-backoffice-ui/src/hooks/order.ts b/packages/merchant-backoffice-ui/src/hooks/order.ts index 1ce76bf58..47ddf1c38 100644 --- a/packages/merchant-backoffice-ui/src/hooks/order.ts +++ b/packages/merchant-backoffice-ui/src/hooks/order.ts @@ -88,7 +88,7 @@ export function useInstanceOrders( if (error) return error; if (data === undefined) return undefined; - // if (data.type !== "ok") return data; + if (data.type !== "ok") return data; return buildPaginatedResult(data.body.orders, args?.position, updatePosition, (d) => String(d.row_id)) } diff --git a/packages/merchant-backoffice-ui/src/hooks/transfer.ts b/packages/merchant-backoffice-ui/src/hooks/transfer.ts index 7a701d44f..2810a4cba 100644 --- a/packages/merchant-backoffice-ui/src/hooks/transfer.ts +++ b/packages/merchant-backoffice-ui/src/hooks/transfer.ts @@ -64,7 +64,7 @@ export function useInstanceTransfers( if (error) return error; if (data === undefined) return undefined; - // if (data.type !== "ok") return data; + if (data.type !== "ok") return data; return buildPaginatedResult(data.body.transfers, args?.position, updatePosition, (d) => String(d.transfer_serial_id)) diff --git a/packages/merchant-backoffice-ui/src/paths/admin/list/index.tsx b/packages/merchant-backoffice-ui/src/paths/admin/list/index.tsx index 7dd5d74bb..f26ff8935 100644 --- a/packages/merchant-backoffice-ui/src/paths/admin/list/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/admin/list/index.tsx @@ -19,7 +19,7 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { TalerError, TalerMerchantApi } from "@gnu-taler/taler-util"; +import { HttpStatusCode, TalerError, TalerMerchantApi, assertUnreachable } from "@gnu-taler/taler-util"; import { useMerchantApiContext, useTranslationContext @@ -34,6 +34,7 @@ import { useSessionContext } from "../../../context/session.js"; import { useBackendInstances } from "../../../hooks/instance.js"; import { Notification } from "../../../utils/types.js"; import { View } from "./View.js"; +import { LoginPage } from "../../login/index.js"; interface Props { onCreate: () => void; @@ -59,6 +60,16 @@ export default function Instances({ if (result instanceof TalerError) { return <ErrorLoadingMerchant error={result} /> } + if (result.type === "fail") { + switch(result.case) { + case HttpStatusCode.Unauthorized: { + return <LoginPage /> + } + default: { + assertUnreachable(result.case) + } + } + } return ( <Fragment> diff --git a/packages/merchant-backoffice-ui/src/paths/instance/accounts/list/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/accounts/list/index.tsx index 1d5c523a4..a9454cd07 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/accounts/list/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/accounts/list/index.tsx @@ -34,6 +34,7 @@ import { useInstanceBankAccounts } from "../../../../hooks/bank.js"; import { Notification } from "../../../../utils/types.js"; import { NotFoundPageOrAdminCreate } from "../../../notfound/index.js"; import { ListPage } from "./ListPage.js"; +import { LoginPage } from "../../../login/index.js"; interface Props { onCreate: () => void; @@ -59,8 +60,11 @@ export default function ListOtpDevices({ case HttpStatusCode.NotFound: { return <NotFoundPageOrAdminCreate /> } + case HttpStatusCode.Unauthorized: { + return <LoginPage /> + } default: { - assertUnreachable(result.case) + assertUnreachable(result) } } } diff --git a/packages/merchant-backoffice-ui/src/paths/instance/accounts/update/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/accounts/update/index.tsx index f5b7436d4..97610e96b 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/accounts/update/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/accounts/update/index.tsx @@ -32,6 +32,7 @@ import { NotificationCard } from "../../../../components/menu/index.js"; import { useSessionContext } from "../../../../context/session.js"; import { useBankAccountDetails } from "../../../../hooks/bank.js"; import { Notification } from "../../../../utils/types.js"; +import { LoginPage } from "../../../login/index.js"; import { NotFoundPageOrAdminCreate } from "../../../notfound/index.js"; import { UpdatePage } from "./UpdatePage.js"; @@ -63,8 +64,11 @@ export default function UpdateValidator({ case HttpStatusCode.NotFound: { return <NotFoundPageOrAdminCreate />; } + case HttpStatusCode.Unauthorized: { + return <LoginPage /> + } default: { - assertUnreachable(result.case); + assertUnreachable(result); } } } diff --git a/packages/merchant-backoffice-ui/src/paths/instance/details/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/details/index.tsx index 627b5d1be..5b6564485 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/details/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/details/index.tsx @@ -13,31 +13,26 @@ You should have received a copy of the GNU General Public License along with GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -import { ErrorType, HttpError, useMerchantApiContext } from "@gnu-taler/web-util/browser"; -import { Fragment, h, VNode } from "preact"; +import { HttpStatusCode, TalerError, assertUnreachable } from "@gnu-taler/taler-util"; +import { useMerchantApiContext } from "@gnu-taler/web-util/browser"; +import { Fragment, VNode, h } from "preact"; import { useState } from "preact/hooks"; +import { ErrorLoadingMerchant } from "../../../components/ErrorLoadingMerchant.js"; import { Loading } from "../../../components/exception/loading.js"; import { DeleteModal } from "../../../components/modal/index.js"; +import { useSessionContext } from "../../../context/session.js"; import { useInstanceDetails } from "../../../hooks/instance.js"; +import { LoginPage } from "../../login/index.js"; import { DetailPage } from "./DetailPage.js"; -import { HttpStatusCode, TalerError, TalerErrorDetail } from "@gnu-taler/taler-util"; -import { useSessionContext } from "../../../context/session.js"; -import { ErrorLoadingMerchant } from "../../../components/ErrorLoadingMerchant.js"; interface Props { - onUnauthorized: () => VNode; - onLoadError: (error: HttpError<TalerErrorDetail>) => VNode; onUpdate: () => void; - onNotFound: () => VNode; onDelete: () => void; } export default function Detail({ onUpdate, - onLoadError, - onUnauthorized, onDelete, - onNotFound, }: Props): VNode { const { state } = useSessionContext(); const result = useInstanceDetails(); @@ -50,21 +45,17 @@ export default function Detail({ if (result instanceof TalerError) { return <ErrorLoadingMerchant error={result} /> } + if (result.type === "fail") { + switch(result.case) { + case HttpStatusCode.Unauthorized: { + return <LoginPage /> + } + default: { + assertUnreachable(result.case) + } + } + } - // if (result.loading) return <Loading />; - // if (!result.ok) { - // if ( - // result.type === ErrorType.CLIENT && - // result.status === HttpStatusCode.Unauthorized - // ) - // return onUnauthorized(); - // if ( - // result.type === ErrorType.CLIENT && - // result.status === HttpStatusCode.NotFound - // ) - // return onNotFound(); - // return onLoadError(result); - // } return ( <Fragment> diff --git a/packages/merchant-backoffice-ui/src/paths/instance/kyc/list/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/kyc/list/index.tsx index 9d0bd2e16..32c7b6c7f 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/kyc/list/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/kyc/list/index.tsx @@ -19,44 +19,23 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { ErrorType, HttpError } from "@gnu-taler/web-util/browser"; -import { h, VNode } from "preact"; +import { HttpStatusCode, TalerError, assertUnreachable } from "@gnu-taler/taler-util"; +import { VNode, h } from "preact"; +import { ErrorLoadingMerchant } from "../../../../components/ErrorLoadingMerchant.js"; import { Loading } from "../../../../components/exception/loading.js"; import { useInstanceKYCDetails } from "../../../../hooks/instance.js"; +import { LoginPage } from "../../../login/index.js"; import { ListPage } from "./ListPage.js"; -import { HttpStatusCode, TalerError, TalerErrorDetail } from "@gnu-taler/taler-util"; -import { ErrorLoadingMerchant } from "../../../../components/ErrorLoadingMerchant.js"; interface Props { - onUnauthorized: () => VNode; - onLoadError: (error: HttpError<TalerErrorDetail>) => VNode; - onNotFound: () => VNode; } -export default function ListKYC({ - onUnauthorized, - onLoadError, - onNotFound, -}: Props): VNode { +export default function ListKYC(_p: Props): VNode { const result = useInstanceKYCDetails(); if (!result) return <Loading /> if (result instanceof TalerError) { return <ErrorLoadingMerchant error={result} /> } - // if (result.loading) return <Loading />; - // if (!result.ok) { - // if ( - // result.type === ErrorType.CLIENT && - // result.status === HttpStatusCode.Unauthorized - // ) - // return onUnauthorized(); - // if ( - // result.type === ErrorType.CLIENT && - // result.status === HttpStatusCode.NotFound - // ) - // return onNotFound(); - // return onLoadError(result); - // } if (result.type === "fail") { switch (result.case) { case HttpStatusCode.GatewayTimeout: { @@ -74,6 +53,12 @@ export default function ListKYC({ case HttpStatusCode.ServiceUnavailable: { return <div /> } + case HttpStatusCode.Unauthorized: { + return <LoginPage /> + } + default: { + assertUnreachable(result) + } } } const status = result.body; diff --git a/packages/merchant-backoffice-ui/src/paths/instance/orders/create/OrderCreatedSuccessfully.tsx b/packages/merchant-backoffice-ui/src/paths/instance/orders/create/OrderCreatedSuccessfully.tsx index d7abc4fbe..32f3f05c7 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/orders/create/OrderCreatedSuccessfully.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/orders/create/OrderCreatedSuccessfully.tsx @@ -21,6 +21,7 @@ import { CreatedSuccessfully } from "../../../../components/notifications/Create import { useOrderDetails } from "../../../../hooks/order.js"; import { NotFoundPageOrAdminCreate } from "../../../notfound/index.js"; import { Entity } from "./index.js"; +import { LoginPage } from "../../../login/index.js"; interface Props { entity: Entity; @@ -53,6 +54,9 @@ export function OrderCreatedSuccessfully({ <div>The merchant's interaction with the exchange took too long</div> ); } + case HttpStatusCode.Unauthorized: { + return <LoginPage /> + } default: { assertUnreachable(result) } diff --git a/packages/merchant-backoffice-ui/src/paths/instance/orders/create/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/orders/create/index.tsx index e40e766dd..10b115905 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/orders/create/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/orders/create/index.tsx @@ -32,6 +32,7 @@ import { useInstanceProducts } from "../../../../hooks/product.js"; import { Notification } from "../../../../utils/types.js"; import { CreatePage } from "./CreatePage.js"; import { NotFoundPageOrAdminCreate } from "../../../notfound/index.js"; +import { LoginPage } from "../../../login/index.js"; export type Entity = { request: TalerMerchantApi.PostOrderRequest; @@ -55,6 +56,16 @@ export default function OrderCreate({ if (detailsResult instanceof TalerError) { return <ErrorLoadingMerchant error={detailsResult} /> } + if (detailsResult.type === "fail") { + switch (detailsResult.case) { + case HttpStatusCode.Unauthorized: { + return <LoginPage /> + } + default: { + assertUnreachable(detailsResult.case); + } + } + } if (!inventoryResult) return <Loading /> if (inventoryResult instanceof TalerError) { return <ErrorLoadingMerchant error={inventoryResult} /> @@ -64,8 +75,11 @@ export default function OrderCreate({ case HttpStatusCode.NotFound: { return <NotFoundPageOrAdminCreate />; } + case HttpStatusCode.Unauthorized: { + return <LoginPage /> + } default: { - assertUnreachable(inventoryResult.case); + assertUnreachable(inventoryResult); } } } diff --git a/packages/merchant-backoffice-ui/src/paths/instance/orders/details/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/orders/details/index.tsx index 1c8ceb90e..b232a146b 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/orders/details/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/orders/details/index.tsx @@ -32,6 +32,7 @@ import { useOrderDetails } from "../../../../hooks/order.js"; import { Notification } from "../../../../utils/types.js"; import { NotFoundPageOrAdminCreate } from "../../../notfound/index.js"; import { DetailPage } from "./DetailPage.js"; +import { LoginPage } from "../../../login/index.js"; export interface Props { oid: string; @@ -63,6 +64,9 @@ export default function Update({ oid, onBack }: Props): VNode { <div>The merchant's interaction with the exchange took too long</div> ); } + case HttpStatusCode.Unauthorized: { + return <LoginPage /> + } default: { assertUnreachable(result); } diff --git a/packages/merchant-backoffice-ui/src/paths/instance/orders/list/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/orders/list/index.tsx index 7a3fb2d22..8efef1c1b 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/orders/list/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/orders/list/index.tsx @@ -46,6 +46,7 @@ import { Notification } from "../../../../utils/types.js"; import { NotFoundPageOrAdminCreate } from "../../../notfound/index.js"; import { ListPage } from "./ListPage.js"; import { RefundModal } from "./Table.js"; +import { LoginPage } from "../../../login/index.js"; interface Props { onSelect: (id: string) => void; @@ -75,16 +76,16 @@ export default function OrderList({ onCreate, onSelect }: Props): VNode { if (result instanceof TalerError) { return <ErrorLoadingMerchant error={result} />; } - // if (result.type === "fail") { - // switch (result.case) { - // case HttpStatusCode.NotFound: { - // return <NotFoundPageOrAdminCreate />; - // } - // default: { - // assertUnreachable(result.case); - // } - // } - // } + if (result.type === "fail") { + switch(result.case) { + case HttpStatusCode.Unauthorized: { + return <LoginPage /> + } + default: { + assertUnreachable(result.case) + } + } + } const isNotPaidActive = filter.paid === false ? "is-active" : ""; const isPaidActive = @@ -206,6 +207,9 @@ function RefundModalForTable({ id, onConfirm, onCancel }: RefundProps): VNode { <div>The merchant's interaction with the exchange took too long</div> ); } + case HttpStatusCode.Unauthorized: { + return <LoginPage /> + } default: { assertUnreachable(result); } diff --git a/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/list/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/list/index.tsx index c240b99cb..6b3eded17 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/list/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/list/index.tsx @@ -39,6 +39,7 @@ import { useInstanceOtpDevices } from "../../../../hooks/otp.js"; import { Notification } from "../../../../utils/types.js"; import { NotFoundPageOrAdminCreate } from "../../../notfound/index.js"; import { ListPage } from "./ListPage.js"; +import { LoginPage } from "../../../login/index.js"; interface Props { onCreate: () => void; @@ -62,8 +63,11 @@ export default function ListOtpDevices({ onCreate, onSelect }: Props): VNode { case HttpStatusCode.NotFound: { return <NotFoundPageOrAdminCreate />; } + case HttpStatusCode.Unauthorized: { + return <LoginPage /> + } default: { - assertUnreachable(result.case); + assertUnreachable(result); } } } diff --git a/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/update/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/update/index.tsx index 43adbe253..4dc3ec67f 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/update/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/update/index.tsx @@ -40,6 +40,7 @@ import { Notification } from "../../../../utils/types.js"; import { NotFoundPageOrAdminCreate } from "../../../notfound/index.js"; import { CreatedSuccessfully } from "../create/CreatedSuccessfully.js"; import { UpdatePage } from "./UpdatePage.js"; +import { LoginPage } from "../../../login/index.js"; export type Entity = TalerMerchantApi.OtpDevicePatchDetails & WithId; @@ -71,8 +72,11 @@ export default function UpdateValidator({ case HttpStatusCode.NotFound: { return <NotFoundPageOrAdminCreate />; } + case HttpStatusCode.Unauthorized: { + return <LoginPage /> + } default: { - assertUnreachable(result.case); + assertUnreachable(result); } } } diff --git a/packages/merchant-backoffice-ui/src/paths/instance/products/list/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/products/list/index.tsx index eb38f25d9..73c221662 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/products/list/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/products/list/index.tsx @@ -38,6 +38,7 @@ import { import { Notification } from "../../../../utils/types.js"; import { NotFoundPageOrAdminCreate } from "../../../notfound/index.js"; import { CardTable } from "./Table.js"; +import { LoginPage } from "../../../login/index.js"; interface Props { onCreate: () => void; @@ -65,8 +66,11 @@ export default function ProductList({ case HttpStatusCode.NotFound: { return <NotFoundPageOrAdminCreate />; } + case HttpStatusCode.Unauthorized: { + return <LoginPage /> + } default: { - assertUnreachable(result.case); + assertUnreachable(result); } } } diff --git a/packages/merchant-backoffice-ui/src/paths/instance/products/update/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/products/update/index.tsx index 9de632218..08b169610 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/products/update/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/products/update/index.tsx @@ -34,6 +34,7 @@ import { useProductDetails } from "../../../../hooks/product.js"; import { Notification } from "../../../../utils/types.js"; import { NotFoundPageOrAdminCreate } from "../../../notfound/index.js"; import { UpdatePage } from "./UpdatePage.js"; +import { LoginPage } from "../../../login/index.js"; export type Entity = TalerMerchantApi.ProductAddDetail; interface Props { @@ -62,8 +63,11 @@ export default function UpdateProduct({ case HttpStatusCode.NotFound: { return <NotFoundPageOrAdminCreate />; } + case HttpStatusCode.Unauthorized: { + return <LoginPage /> + } default: { - assertUnreachable(result.case); + assertUnreachable(result); } } } diff --git a/packages/merchant-backoffice-ui/src/paths/instance/templates/list/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/templates/list/index.tsx index 5a8be71b0..23bc95943 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/templates/list/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/templates/list/index.tsx @@ -38,6 +38,7 @@ import { import { Notification } from "../../../../utils/types.js"; import { NotFoundPageOrAdminCreate } from "../../../notfound/index.js"; import { ListPage } from "./ListPage.js"; +import { LoginPage } from "../../../login/index.js"; interface Props { onCreate: () => void; @@ -69,8 +70,11 @@ export default function ListTemplates({ case HttpStatusCode.NotFound: { return <NotFoundPageOrAdminCreate /> } + case HttpStatusCode.Unauthorized: { + return <LoginPage /> + } default: { - assertUnreachable(result.case) + assertUnreachable(result) } } } diff --git a/packages/merchant-backoffice-ui/src/paths/instance/templates/qr/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/templates/qr/index.tsx index 3464fb04e..ed809c7b3 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/templates/qr/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/templates/qr/index.tsx @@ -28,6 +28,7 @@ import { } from "../../../../hooks/templates.js"; import { NotFoundPageOrAdminCreate } from "../../../notfound/index.js"; import { QrPage } from "./QrPage.js"; +import { LoginPage } from "../../../login/index.js"; export type Entity = TalerMerchantApi.TransferInformation; interface Props { @@ -49,8 +50,11 @@ export default function TemplateQrPage({ case HttpStatusCode.NotFound: { return <NotFoundPageOrAdminCreate /> } + case HttpStatusCode.Unauthorized: { + return <LoginPage /> + } default: { - assertUnreachable(result.case) + assertUnreachable(result) } } } diff --git a/packages/merchant-backoffice-ui/src/paths/instance/templates/update/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/templates/update/index.tsx index 1ff4b56cf..5fc8bee93 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/templates/update/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/templates/update/index.tsx @@ -36,6 +36,7 @@ import { import { Notification } from "../../../../utils/types.js"; import { NotFoundPageOrAdminCreate } from "../../../notfound/index.js"; import { UpdatePage } from "./UpdatePage.js"; +import { LoginPage } from "../../../login/index.js"; export type Entity = TalerMerchantApi.TemplatePatchDetails & WithId; @@ -65,8 +66,11 @@ export default function UpdateTemplate({ case HttpStatusCode.NotFound: { return <NotFoundPageOrAdminCreate /> } + case HttpStatusCode.Unauthorized: { + return <LoginPage /> + } default: { - assertUnreachable(result.case) + assertUnreachable(result) } } } diff --git a/packages/merchant-backoffice-ui/src/paths/instance/templates/use/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/templates/use/index.tsx index 0073ca574..d631cef96 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/templates/use/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/templates/use/index.tsx @@ -35,6 +35,7 @@ import { import { Notification } from "../../../../utils/types.js"; import { NotFoundPageOrAdminCreate } from "../../../notfound/index.js"; import { UsePage } from "./UsePage.js"; +import { LoginPage } from "../../../login/index.js"; export type Entity = TalerMerchantApi.TransferInformation; interface Props { @@ -62,8 +63,11 @@ export default function TemplateUsePage({ case HttpStatusCode.NotFound: { return <NotFoundPageOrAdminCreate /> } + case HttpStatusCode.Unauthorized: { + return <LoginPage /> + } default: { - assertUnreachable(result.case) + assertUnreachable(result) } } } diff --git a/packages/merchant-backoffice-ui/src/paths/instance/token/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/token/index.tsx index 444283b13..36ba10e30 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/token/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/token/index.tsx @@ -13,7 +13,7 @@ You should have received a copy of the GNU General Public License along with GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -import { TalerError } from "@gnu-taler/taler-util"; +import { HttpStatusCode, TalerError, assertUnreachable } from "@gnu-taler/taler-util"; import { useMerchantApiContext, useTranslationContext } from "@gnu-taler/web-util/browser"; import { Fragment, VNode, h } from "preact"; import { useState } from "preact/hooks"; @@ -23,6 +23,7 @@ import { NotificationCard } from "../../../components/menu/index.js"; import { useSessionContext } from "../../../context/session.js"; import { useInstanceDetails } from "../../../hooks/instance.js"; import { Notification } from "../../../utils/types.js"; +import { LoginPage } from "../../login/index.js"; import { DetailPage } from "./DetailPage.js"; interface Props { @@ -44,6 +45,16 @@ export default function Token({ if (result instanceof TalerError) { return <ErrorLoadingMerchant error={result} /> } + if (result.type === "fail") { + switch(result.case) { + case HttpStatusCode.Unauthorized: { + return <LoginPage /> + } + default: { + assertUnreachable(result.case) + } + } + } const hasToken = result.body.auth.method === "token" diff --git a/packages/merchant-backoffice-ui/src/paths/instance/transfers/list/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/transfers/list/index.tsx index 5edea377f..b53f67884 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/transfers/list/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/transfers/list/index.tsx @@ -19,13 +19,14 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { TalerError } from "@gnu-taler/taler-util"; +import { HttpStatusCode, TalerError, assertUnreachable } from "@gnu-taler/taler-util"; import { VNode, h } from "preact"; import { useEffect, useState } from "preact/hooks"; import { ErrorLoadingMerchant } from "../../../../components/ErrorLoadingMerchant.js"; import { Loading } from "../../../../components/exception/loading.js"; import { useInstanceBankAccounts } from "../../../../hooks/bank.js"; import { useInstanceTransfers } from "../../../../hooks/transfer.js"; +import { LoginPage } from "../../../login/index.js"; import { ListPage } from "./ListPage.js"; interface Props { @@ -73,17 +74,16 @@ export default function ListTransfer({ if (result instanceof TalerError) { return <ErrorLoadingMerchant error={result} />; } - // if (result.type === "fail") { - // switch (result.case) { - // case HttpStatusCode.NotFound: { - // return <NotFoundPageOrAdminCreate />; - // } - // default: { - // assertUnreachable(result.case); - // } - // } - // } - + if (result.type === "fail") { + switch (result.case) { + case HttpStatusCode.Unauthorized: { + return <LoginPage /> + } + default: { + assertUnreachable(result.case); + } + } + } return ( <ListPage diff --git a/packages/merchant-backoffice-ui/src/paths/instance/update/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/update/index.tsx index 6dc5b9b02..de3ffce48 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/update/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/update/index.tsx @@ -13,7 +13,7 @@ You should have received a copy of the GNU General Public License along with GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -import { OperationOk, TalerError, TalerMerchantApi, TalerMerchantInstanceHttpClient } from "@gnu-taler/taler-util"; +import { HttpStatusCode, TalerError, TalerMerchantApi, TalerMerchantInstanceHttpClient, TalerMerchantManagementResultByMethod, assertUnreachable } from "@gnu-taler/taler-util"; import { useMerchantApiContext, useTranslationContext @@ -29,6 +29,7 @@ import { useManagedInstanceDetails, } from "../../../hooks/instance.js"; import { Notification } from "../../../utils/types.js"; +import { LoginPage } from "../../login/index.js"; import { UpdatePage } from "./UpdatePage.js"; export interface Props { @@ -62,7 +63,7 @@ function CommonUpdate( onBack, onConfirm, }: Props, - result: OperationOk<TalerMerchantApi.QueryInstancesResponse> | TalerError | undefined, + result: TalerMerchantManagementResultByMethod<"getInstanceDetails"> | TalerError | undefined, updateInstance: typeof TalerMerchantInstanceHttpClient.prototype.updateCurrentInstance, ): VNode { const [notif, setNotif] = useState<Notification | undefined>(undefined); @@ -73,6 +74,16 @@ function CommonUpdate( if (result instanceof TalerError) { return <ErrorLoadingMerchant error={result} /> } + if (result.type === "fail") { + switch(result.case) { + case HttpStatusCode.Unauthorized: { + return <LoginPage /> + } + default: { + assertUnreachable(result.case) + } + } + } return ( <Fragment> diff --git a/packages/merchant-backoffice-ui/src/paths/instance/webhooks/list/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/webhooks/list/index.tsx index 7c24a7228..102aef96e 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/webhooks/list/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/webhooks/list/index.tsx @@ -39,6 +39,7 @@ import { useInstanceWebhooks } from "../../../../hooks/webhooks.js"; import { Notification } from "../../../../utils/types.js"; import { NotFoundPageOrAdminCreate } from "../../../notfound/index.js"; import { ListPage } from "./ListPage.js"; +import { LoginPage } from "../../../login/index.js"; interface Props { onCreate: () => void; @@ -61,8 +62,11 @@ export default function ListWebhooks({ onCreate, onSelect }: Props): VNode { case HttpStatusCode.NotFound: { return <NotFoundPageOrAdminCreate />; } + case HttpStatusCode.Unauthorized: { + return <LoginPage /> + } default: { - assertUnreachable(result.case); + assertUnreachable(result); } } } diff --git a/packages/merchant-backoffice-ui/src/paths/instance/webhooks/update/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/webhooks/update/index.tsx index 1c3172ffd..262e5bba4 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/webhooks/update/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/webhooks/update/index.tsx @@ -36,6 +36,7 @@ import { import { Notification } from "../../../../utils/types.js"; import { NotFoundPageOrAdminCreate } from "../../../notfound/index.js"; import { UpdatePage } from "./UpdatePage.js"; +import { LoginPage } from "../../../login/index.js"; export type Entity = TalerMerchantApi.WebhookPatchDetails & WithId; @@ -65,8 +66,11 @@ export default function UpdateWebhook({ case HttpStatusCode.NotFound: { return <NotFoundPageOrAdminCreate />; } + case HttpStatusCode.Unauthorized: { + return <LoginPage /> + } default: { - assertUnreachable(result.case); + assertUnreachable(result); } } } diff --git a/packages/taler-util/src/http-client/merchant.ts b/packages/taler-util/src/http-client/merchant.ts index c223b0a16..e895c7eef 100644 --- a/packages/taler-util/src/http-client/merchant.ts +++ b/packages/taler-util/src/http-client/merchant.ts @@ -354,9 +354,9 @@ export class TalerMerchantInstanceHttpClient { ) { const url = new URL(`private/auth`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "POST", @@ -369,6 +369,8 @@ export class TalerMerchantInstanceHttpClient { return opEmptySuccess(resp); case HttpStatusCode.NoContent: // FIXME: missing in docs return opEmptySuccess(resp); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); default: @@ -385,9 +387,9 @@ export class TalerMerchantInstanceHttpClient { ) { const url = new URL(`private`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "PATCH", @@ -397,6 +399,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.NoContent: return opEmptySuccess(resp); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); default: @@ -411,9 +415,9 @@ export class TalerMerchantInstanceHttpClient { async getCurrentInstanceDetails(token: AccessToken) { const url = new URL(`private`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "GET", @@ -423,6 +427,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.Ok: return opSuccessFromHttp(resp, codecForQueryInstancesResponse()); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); default: return opUnknownFailure(resp, await readTalerErrorResponse(resp)); } @@ -431,16 +437,19 @@ export class TalerMerchantInstanceHttpClient { /** * https://docs.taler.net/core/api-merchant.html#delete-[-instances-$INSTANCE]-private */ - async deleteCurrentInstance(token: AccessToken | undefined, params: { purge?: boolean } = {}) { + async deleteCurrentInstance( + token: AccessToken | undefined, + params: { purge?: boolean } = {}, + ) { const url = new URL(`private`, this.baseUrl); if (params.purge) { url.searchParams.set("purge", "YES"); } - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "DELETE", @@ -480,9 +489,9 @@ export class TalerMerchantInstanceHttpClient { url.searchParams.set("timeout_ms", String(params.timeout)); } - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "GET", @@ -494,8 +503,14 @@ export class TalerMerchantInstanceHttpClient { return opSuccessFromHttp(resp, codecForAccountKycRedirects()); case HttpStatusCode.NoContent: return opEmptySuccess(resp); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.BadGateway: - return opKnownAlternativeFailure(resp, resp.status, codecForAccountKycRedirects()) + return opKnownAlternativeFailure( + resp, + resp.status, + codecForAccountKycRedirects(), + ); case HttpStatusCode.ServiceUnavailable: return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.GatewayTimeout: @@ -512,12 +527,15 @@ export class TalerMerchantInstanceHttpClient { /** * https://docs.taler.net/core/api-merchant.html#post-[-instances-$INSTANCE]-private-accounts */ - async addBankAccount(token: AccessToken | undefined, body: TalerMerchantApi.AccountAddDetails) { + async addBankAccount( + token: AccessToken | undefined, + body: TalerMerchantApi.AccountAddDetails, + ) { const url = new URL(`private/accounts`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "POST", @@ -528,6 +546,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.Ok: return opSuccessFromHttp(resp, codecForAccountAddResponse()); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.Conflict: @@ -547,9 +567,9 @@ export class TalerMerchantInstanceHttpClient { ) { const url = new URL(`private/accounts/${wireAccount}`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "PATCH", @@ -559,6 +579,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.NoContent: return opEmptySuccess(resp); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); default: @@ -574,9 +596,9 @@ export class TalerMerchantInstanceHttpClient { // addMerchantPaginationParams(url, params); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "GET", @@ -586,6 +608,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.Ok: return opSuccessFromHttp(resp, codecForAccountsSummaryResponse()); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); default: @@ -596,12 +620,15 @@ export class TalerMerchantInstanceHttpClient { /** * https://docs.taler.net/core/api-merchant.html#get-[-instances-$INSTANCE]-private-accounts-$H_WIRE */ - async getBankAccountDetails(token: AccessToken | undefined, wireAccount: string) { + async getBankAccountDetails( + token: AccessToken | undefined, + wireAccount: string, + ) { const url = new URL(`private/accounts/${wireAccount}`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "GET", @@ -611,6 +638,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.Ok: return opSuccessFromHttp(resp, codecForBankAccountEntry()); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); default: @@ -624,9 +653,9 @@ export class TalerMerchantInstanceHttpClient { async deleteBankAccount(token: AccessToken | undefined, wireAccount: string) { const url = new URL(`private/accounts/${wireAccount}`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "DELETE", @@ -636,6 +665,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.NoContent: return opEmptySuccess(resp); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); default: @@ -650,12 +681,15 @@ export class TalerMerchantInstanceHttpClient { /** * https://docs.taler.net/core/api-merchant.html#post-[-instances-$INSTANCE]-private-products */ - async addProduct(token: AccessToken | undefined, body: TalerMerchantApi.ProductAddDetail) { + async addProduct( + token: AccessToken | undefined, + body: TalerMerchantApi.ProductAddDetail, + ) { const url = new URL(`private/products`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "POST", @@ -666,6 +700,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.NoContent: return opEmptySuccess(resp); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.Conflict: return opKnownHttpFailure(resp.status, resp); default: @@ -683,9 +719,9 @@ export class TalerMerchantInstanceHttpClient { ) { const url = new URL(`private/products/${productId}`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "PATCH", @@ -696,6 +732,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.NoContent: return opEmptySuccess(resp); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.Conflict: @@ -708,14 +746,17 @@ export class TalerMerchantInstanceHttpClient { /** * https://docs.taler.net/core/api-merchant.html#get-[-instances-$INSTANCE]-private-products */ - async listProducts(token: AccessToken | undefined, params?: PaginationParams) { + async listProducts( + token: AccessToken | undefined, + params?: PaginationParams, + ) { const url = new URL(`private/products`, this.baseUrl); addMerchantPaginationParams(url, params); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "GET", @@ -725,6 +766,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.Ok: return opSuccessFromHttp(resp, codecForInventorySummaryResponse()); + case HttpStatusCode.Unauthorized: + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); default: @@ -738,9 +781,9 @@ export class TalerMerchantInstanceHttpClient { async getProductDetails(token: AccessToken | undefined, productId: string) { const url = new URL(`private/products/${productId}`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "GET", @@ -750,6 +793,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.Ok: return opSuccessFromHttp(resp, codecForProductDetail()); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); default: @@ -760,12 +805,16 @@ export class TalerMerchantInstanceHttpClient { /** * https://docs.taler.net/core/api-merchant.html#reserving-inventory */ - async lockProduct(token: AccessToken | undefined, productId: string, body: TalerMerchantApi.LockRequest) { + async lockProduct( + token: AccessToken | undefined, + productId: string, + body: TalerMerchantApi.LockRequest, + ) { const url = new URL(`private/products/${productId}/lock`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "POST", @@ -776,6 +825,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.NoContent: return opEmptySuccess(resp); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.Gone: @@ -791,9 +842,9 @@ export class TalerMerchantInstanceHttpClient { async deleteProduct(token: AccessToken | undefined, productId: string) { const url = new URL(`private/products/${productId}`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "DELETE", @@ -803,6 +854,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.NoContent: return opEmptySuccess(resp); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.Conflict: @@ -819,29 +872,36 @@ export class TalerMerchantInstanceHttpClient { /** * https://docs.taler.net/core/api-merchant.html#post-[-instances-$INSTANCE]-private-orders */ - async createOrder(token: AccessToken | undefined, body: TalerMerchantApi.PostOrderRequest) { + async createOrder( + token: AccessToken | undefined, + body: TalerMerchantApi.PostOrderRequest, + ) { const url = new URL(`private/orders`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "POST", body, headers, }); - return this.procesOrderCreationResponse(resp) + return this.procesOrderCreationResponse(resp); } private async procesOrderCreationResponse(resp: HttpResponse) { switch (resp.status) { case HttpStatusCode.Ok: { - this.cacheEvictor.notifySuccess(TalerMerchantInstanceCacheEviction.CREATE_ORDER) - return opSuccessFromHttp(resp, codecForPostOrderResponse()) + this.cacheEvictor.notifySuccess( + TalerMerchantInstanceCacheEviction.CREATE_ORDER, + ); + return opSuccessFromHttp(resp, codecForPostOrderResponse()); } case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.Conflict: return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.Gone: @@ -858,7 +918,10 @@ export class TalerMerchantInstanceHttpClient { /** * https://docs.taler.net/core/api-merchant.html#inspecting-orders */ - async listOrders(token: AccessToken | undefined, params: TalerMerchantApi.ListOrdersRequestParams = {}) { + async listOrders( + token: AccessToken | undefined, + params: TalerMerchantApi.ListOrdersRequestParams = {}, + ) { const url = new URL(`private/orders`, this.baseUrl); if (params.date) { @@ -884,9 +947,9 @@ export class TalerMerchantInstanceHttpClient { } addMerchantPaginationParams(url, params); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "GET", @@ -896,6 +959,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.Ok: return opSuccessFromHttp(resp, codecForOrderHistory()); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); default: return opUnknownFailure(resp, await readTalerErrorResponse(resp)); } @@ -921,9 +986,9 @@ export class TalerMerchantInstanceHttpClient { url.searchParams.set("timeout_ms", String(params.timeout)); } - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "GET", @@ -938,6 +1003,8 @@ export class TalerMerchantInstanceHttpClient { ); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.BadGateway: return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.GatewayTimeout: @@ -954,12 +1021,16 @@ export class TalerMerchantInstanceHttpClient { /** * https://docs.taler.net/core/api-merchant.html#private-order-data-cleanup */ - async forgetOrder(token: AccessToken | undefined, orderId: string, body: TalerMerchantApi.ForgetRequest) { + async forgetOrder( + token: AccessToken | undefined, + orderId: string, + body: TalerMerchantApi.ForgetRequest, + ) { const url = new URL(`private/orders/${orderId}/forget`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "PATCH", @@ -972,6 +1043,8 @@ export class TalerMerchantInstanceHttpClient { return opEmptySuccess(resp); case HttpStatusCode.NoContent: return opEmptySuccess(resp); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.BadRequest: return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: @@ -989,9 +1062,9 @@ export class TalerMerchantInstanceHttpClient { async deleteOrder(token: AccessToken | undefined, orderId: string) { const url = new URL(`private/orders/${orderId}`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "DELETE", @@ -1001,6 +1074,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.NoContent: return opEmptySuccess(resp); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.Conflict: @@ -1017,12 +1092,16 @@ export class TalerMerchantInstanceHttpClient { /** * https://docs.taler.net/core/api-merchant.html#post-[-instances-$INSTANCE]-private-orders-$ORDER_ID-refund */ - async addRefund(token: AccessToken | undefined, orderId: string, body: TalerMerchantApi.RefundRequest) { + async addRefund( + token: AccessToken | undefined, + orderId: string, + body: TalerMerchantApi.RefundRequest, + ) { const url = new URL(`private/orders/${orderId}/refund`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "POST", @@ -1035,6 +1114,8 @@ export class TalerMerchantInstanceHttpClient { return opSuccessFromHttp(resp, codecForMerchantRefundResponse()); case HttpStatusCode.Forbidden: return opKnownHttpFailure(resp.status, resp); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.Gone: @@ -1053,12 +1134,15 @@ export class TalerMerchantInstanceHttpClient { /** * https://docs.taler.net/core/api-merchant.html#post-[-instances-$INSTANCE]-private-transfers */ - async informWireTransfer(token: AccessToken | undefined, body: TalerMerchantApi.TransferInformation) { + async informWireTransfer( + token: AccessToken | undefined, + body: TalerMerchantApi.TransferInformation, + ) { const url = new URL(`private/transfers`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "POST", @@ -1069,6 +1153,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.NoContent: return opEmptySuccess(resp); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.Conflict: @@ -1101,9 +1187,9 @@ export class TalerMerchantInstanceHttpClient { } addMerchantPaginationParams(url, params); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "GET", @@ -1113,6 +1199,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.Ok: return opSuccessFromHttp(resp, codecForTansferList()); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); default: return opUnknownFailure(resp, await readTalerErrorResponse(resp)); } @@ -1124,9 +1212,9 @@ export class TalerMerchantInstanceHttpClient { async deleteWireTransfer(token: AccessToken | undefined, transferId: string) { const url = new URL(`private/transfers/${transferId}`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "DELETE", @@ -1136,6 +1224,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.NoContent: return opEmptySuccess(resp); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.Conflict: @@ -1152,12 +1242,15 @@ export class TalerMerchantInstanceHttpClient { /** * https://docs.taler.net/core/api-merchant.html#post-[-instances-$INSTANCE]-private-otp-devices */ - async addOtpDevice(token: AccessToken | undefined, body: TalerMerchantApi.OtpDeviceAddDetails) { + async addOtpDevice( + token: AccessToken | undefined, + body: TalerMerchantApi.OtpDeviceAddDetails, + ) { const url = new URL(`private/otp-devices`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "POST", @@ -1168,6 +1261,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.NoContent: return opEmptySuccess(resp); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); default: @@ -1185,9 +1280,9 @@ export class TalerMerchantInstanceHttpClient { ) { const url = new URL(`private/otp-devices/${deviceId}`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "PATCH", @@ -1197,6 +1292,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.NoContent: return opEmptySuccess(resp); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.Conflict: @@ -1209,12 +1306,15 @@ export class TalerMerchantInstanceHttpClient { /** * https://docs.taler.net/core/api-merchant.html#get-[-instances-$INSTANCE]-private-otp-devices */ - async listOtpDevices(token: AccessToken | undefined, params?: PaginationParams) { + async listOtpDevices( + token: AccessToken | undefined, + params?: PaginationParams, + ) { const url = new URL(`private/otp-devices`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "GET", @@ -1223,6 +1323,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.Ok: return opSuccessFromHttp(resp, codecForOtpDeviceSummaryResponse()); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); default: @@ -1246,9 +1348,9 @@ export class TalerMerchantInstanceHttpClient { if (params.price) { url.searchParams.set("price", params.price); } - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "GET", @@ -1258,6 +1360,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.Ok: return opSuccessFromHttp(resp, codecForOtpDeviceDetails()); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); default: @@ -1271,9 +1375,9 @@ export class TalerMerchantInstanceHttpClient { async deleteOtpDevice(token: AccessToken | undefined, deviceId: string) { const url = new URL(`private/otp-devices/${deviceId}`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "DELETE", @@ -1282,6 +1386,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.NoContent: return opEmptySuccess(resp); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); default: @@ -1296,12 +1402,15 @@ export class TalerMerchantInstanceHttpClient { /** * https://docs.taler.net/core/api-merchant.html#post-[-instances-$INSTANCE]-private-templates */ - async addTemplate(token: AccessToken | undefined, body: TalerMerchantApi.TemplateAddDetails) { + async addTemplate( + token: AccessToken | undefined, + body: TalerMerchantApi.TemplateAddDetails, + ) { const url = new URL(`private/templates`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "POST", @@ -1311,6 +1420,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.NoContent: return opEmptySuccess(resp); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); default: @@ -1328,9 +1439,9 @@ export class TalerMerchantInstanceHttpClient { ) { const url = new URL(`private/templates/${templateId}`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "PATCH", @@ -1340,6 +1451,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.NoContent: return opEmptySuccess(resp); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.Conflict: @@ -1352,12 +1465,15 @@ export class TalerMerchantInstanceHttpClient { /** * https://docs.taler.net/core/api-merchant.html#inspecting-template */ - async listTemplates(token: AccessToken | undefined, params?: PaginationParams) { + async listTemplates( + token: AccessToken | undefined, + params?: PaginationParams, + ) { const url = new URL(`private/templates`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "GET", @@ -1366,6 +1482,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.Ok: return opSuccessFromHttp(resp, codecForTemplateSummaryResponse()); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); default: @@ -1379,9 +1497,9 @@ export class TalerMerchantInstanceHttpClient { async getTemplateDetails(token: AccessToken | undefined, templateId: string) { const url = new URL(`private/templates/${templateId}`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "GET", @@ -1390,6 +1508,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.Ok: return opSuccessFromHttp(resp, codecForTemplateDetails()); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); default: @@ -1403,9 +1523,9 @@ export class TalerMerchantInstanceHttpClient { async deleteTemplate(token: AccessToken | undefined, templateId: string) { const url = new URL(`private/templates/${templateId}`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "DELETE", @@ -1414,6 +1534,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.NoContent: return opEmptySuccess(resp); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); default: @@ -1454,7 +1576,7 @@ export class TalerMerchantInstanceHttpClient { body, }); - return this.procesOrderCreationResponse(resp) + return this.procesOrderCreationResponse(resp); } // @@ -1464,12 +1586,15 @@ export class TalerMerchantInstanceHttpClient { /** * https://docs.taler.net/core/api-merchant.html#post-[-instances-$INSTANCES]-private-webhooks */ - async addWebhook(token: AccessToken | undefined, body: TalerMerchantApi.WebhookAddDetails) { + async addWebhook( + token: AccessToken | undefined, + body: TalerMerchantApi.WebhookAddDetails, + ) { const url = new URL(`private/webhooks`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "POST", @@ -1480,6 +1605,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.NoContent: return opEmptySuccess(resp); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); default: @@ -1497,9 +1624,9 @@ export class TalerMerchantInstanceHttpClient { ) { const url = new URL(`private/webhooks/${webhookId}`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "PATCH", @@ -1510,6 +1637,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.NoContent: return opEmptySuccess(resp); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.Conflict: @@ -1522,12 +1651,15 @@ export class TalerMerchantInstanceHttpClient { /** * https://docs.taler.net/core/api-merchant.html#get-[-instances-$INSTANCES]-private-webhooks */ - async listWebhooks(token: AccessToken | undefined, params?: PaginationParams) { + async listWebhooks( + token: AccessToken | undefined, + params?: PaginationParams, + ) { const url = new URL(`private/webhooks`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "GET", @@ -1537,6 +1669,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.NoContent: return opSuccessFromHttp(resp, codecForWebhookSummaryResponse()); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); default: @@ -1550,9 +1684,9 @@ export class TalerMerchantInstanceHttpClient { async getWebhookDetails(token: AccessToken | undefined, webhookId: string) { const url = new URL(`private/webhooks/${webhookId}`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "GET", @@ -1561,6 +1695,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.NoContent: return opSuccessFromHttp(resp, codecForWebhookDetails()); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); default: @@ -1574,9 +1710,9 @@ export class TalerMerchantInstanceHttpClient { async deleteWebhook(token: AccessToken | undefined, webhookId: string) { const url = new URL(`private/webhooks/${webhookId}`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "DELETE", @@ -1585,6 +1721,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.NoContent: return opEmptySuccess(resp); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); default: @@ -1599,12 +1737,15 @@ export class TalerMerchantInstanceHttpClient { /** * https://docs.taler.net/core/api-merchant.html#post-[-instances-$INSTANCES]-private-tokenfamilies */ - async createTokenFamily(token: AccessToken | undefined, body: TalerMerchantApi.TokenFamilyCreateRequest) { + async createTokenFamily( + token: AccessToken | undefined, + body: TalerMerchantApi.TokenFamilyCreateRequest, + ) { const url = new URL(`private/tokenfamilies`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "POST", @@ -1615,6 +1756,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.NoContent: return opEmptySuccess(resp); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); default: @@ -1632,9 +1775,9 @@ export class TalerMerchantInstanceHttpClient { ) { const url = new URL(`private/tokenfamilies/${tokenSlug}`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "POST", @@ -1644,6 +1787,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.Ok: return opSuccessFromHttp(resp, codecForTokenFamilyDetails()); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); default: @@ -1654,12 +1799,15 @@ export class TalerMerchantInstanceHttpClient { /** * https://docs.taler.net/core/api-merchant.html#get-[-instances-$INSTANCES]-private-tokenfamilies */ - async listTokenFamilies(token: AccessToken | undefined, params?: PaginationParams) { + async listTokenFamilies( + token: AccessToken | undefined, + params?: PaginationParams, + ) { const url = new URL(`private/tokenfamilies`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "GET", @@ -1669,6 +1817,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.Ok: return opSuccessFromHttp(resp, codecForTokenFamiliesList()); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); default: @@ -1679,12 +1829,15 @@ export class TalerMerchantInstanceHttpClient { /** * https://docs.taler.net/core/api-merchant.html#get-[-instances-$INSTANCES]-private-tokenfamilies-$TOKEN_FAMILY_SLUG */ - async getTokenFamilyDetails(token: AccessToken | undefined, tokenSlug: string) { + async getTokenFamilyDetails( + token: AccessToken | undefined, + tokenSlug: string, + ) { const url = new URL(`private/tokenfamilies/${tokenSlug}`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "GET", @@ -1694,6 +1847,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.Ok: return opSuccessFromHttp(resp, codecForTokenFamilyDetails()); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); default: @@ -1707,9 +1862,9 @@ export class TalerMerchantInstanceHttpClient { async deleteTokenFamily(token: AccessToken | undefined, tokenSlug: string) { const url = new URL(`private/tokenfamilies/${tokenSlug}`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "DELETE", @@ -1718,6 +1873,8 @@ export class TalerMerchantInstanceHttpClient { switch (resp.status) { case HttpStatusCode.NoContent: return opEmptySuccess(resp); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); default: @@ -1734,7 +1891,6 @@ export class TalerMerchantInstanceHttpClient { getAuthenticationAPI(): URL { return new URL(`private/`, this.baseUrl); } - } export type TalerMerchantManagementResultByMethod< @@ -1767,12 +1923,15 @@ export class TalerMerchantManagementHttpClient extends TalerMerchantInstanceHttp /** * https://docs.taler.net/core/api-merchant.html#post--management-instances */ - async createInstance(token: AccessToken | undefined, body: TalerMerchantApi.InstanceConfigurationMessage) { + async createInstance( + token: AccessToken | undefined, + body: TalerMerchantApi.InstanceConfigurationMessage, + ) { const url = new URL(`management/instances`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "POST", @@ -1780,12 +1939,15 @@ export class TalerMerchantManagementHttpClient extends TalerMerchantInstanceHttp headers, }); - switch (resp.status) { case HttpStatusCode.NoContent: { - this.cacheManagementEvictor.notifySuccess(TalerMerchantManagementCacheEviction.CREATE_INSTANCE) + this.cacheManagementEvictor.notifySuccess( + TalerMerchantManagementCacheEviction.CREATE_INSTANCE, + ); return opEmptySuccess(resp); } + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.Conflict: return opKnownHttpFailure(resp.status, resp); default: @@ -1801,11 +1963,14 @@ export class TalerMerchantManagementHttpClient extends TalerMerchantInstanceHttp instanceId: string, body: TalerMerchantApi.InstanceAuthConfigurationMessage, ) { - const url = new URL(`management/instances/${instanceId}/auth`, this.baseUrl); + const url = new URL( + `management/instances/${instanceId}/auth`, + this.baseUrl, + ); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "POST", @@ -1816,6 +1981,8 @@ export class TalerMerchantManagementHttpClient extends TalerMerchantInstanceHttp switch (resp.status) { case HttpStatusCode.NoContent: return opEmptySuccess(resp); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); default: @@ -1833,9 +2000,9 @@ export class TalerMerchantManagementHttpClient extends TalerMerchantInstanceHttp ) { const url = new URL(`management/instances/${instanceId}`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "PATCH", @@ -1845,6 +2012,8 @@ export class TalerMerchantManagementHttpClient extends TalerMerchantInstanceHttp switch (resp.status) { case HttpStatusCode.NoContent: return opEmptySuccess(resp); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); default: @@ -1855,12 +2024,15 @@ export class TalerMerchantManagementHttpClient extends TalerMerchantInstanceHttp /** * https://docs.taler.net/core/api-merchant.html#get--management-instances */ - async listInstances(token: AccessToken | undefined, params?: PaginationParams) { + async listInstances( + token: AccessToken | undefined, + params?: PaginationParams, + ) { const url = new URL(`management/instances`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "GET", @@ -1870,6 +2042,8 @@ export class TalerMerchantManagementHttpClient extends TalerMerchantInstanceHttp switch (resp.status) { case HttpStatusCode.Ok: return opSuccessFromHttp(resp, codecForInstancesResponse()); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); default: return opUnknownFailure(resp, await readTalerErrorResponse(resp)); } @@ -1882,9 +2056,9 @@ export class TalerMerchantManagementHttpClient extends TalerMerchantInstanceHttp async getInstanceDetails(token: AccessToken | undefined, instanceId: string) { const url = new URL(`management/instances/${instanceId}`, this.baseUrl); - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "GET", @@ -1894,6 +2068,8 @@ export class TalerMerchantManagementHttpClient extends TalerMerchantInstanceHttp switch (resp.status) { case HttpStatusCode.Ok: return opSuccessFromHttp(resp, codecForQueryInstancesResponse()); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); default: return opUnknownFailure(resp, await readTalerErrorResponse(resp)); } @@ -1902,16 +2078,20 @@ export class TalerMerchantManagementHttpClient extends TalerMerchantInstanceHttp /** * https://docs.taler.net/core/api-merchant.html#delete--management-instances-$INSTANCE */ - async deleteInstance(token: AccessToken | undefined, instanceId: string, params: { purge?: boolean } = {}) { + async deleteInstance( + token: AccessToken | undefined, + instanceId: string, + params: { purge?: boolean } = {}, + ) { const url = new URL(`management/instances/${instanceId}`, this.baseUrl); if (params.purge) { url.searchParams.set("purge", "YES"); } - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "DELETE", @@ -1920,6 +2100,8 @@ export class TalerMerchantManagementHttpClient extends TalerMerchantInstanceHttp switch (resp.status) { case HttpStatusCode.NoContent: return opEmptySuccess(resp); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.Unauthorized: return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotFound: @@ -1951,9 +2133,9 @@ export class TalerMerchantManagementHttpClient extends TalerMerchantInstanceHttp url.searchParams.set("timeout_ms", String(params.timeout)); } - const headers: Record<string, string> = {} + const headers: Record<string, string> = {}; if (token) { - headers.Authorization = makeBearerTokenAuthHeader(token) + headers.Authorization = makeBearerTokenAuthHeader(token); } const resp = await this.httpLib.fetch(url.href, { method: "GET", @@ -1964,6 +2146,8 @@ export class TalerMerchantManagementHttpClient extends TalerMerchantInstanceHttp return opSuccessFromHttp(resp, codecForAccountKycRedirects()); case HttpStatusCode.NoContent: return opEmptySuccess(resp); + case HttpStatusCode.Unauthorized: // FIXME: missing in docs + return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.BadGateway: return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.ServiceUnavailable: |