@adobe/aio-commerce-lib-core
Version:
Core utilities for AIO Commerce SDK Libraries
14 lines • 2.06 kB
JavaScript
/**
* @license
*
* Copyright 2025 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
function buildErrorResponse(statusCode,payload){return{type:`error`,error:{...payload?.headers&&{headers:payload.headers},statusCode,body:payload.body}}}function buildSuccessResponse(statusCode,payload){return{type:`success`,statusCode,...payload?.headers&&{headers:payload.headers},...payload?.body&&{body:payload.body}}}const HTTP_OK=200,HTTP_CREATED=201,HTTP_NON_AUTHORITATIVE_INFORMATION=203,HTTP_BAD_REQUEST=400,HTTP_UNAUTHORIZED=401,HTTP_FORBIDDEN=403,HTTP_NOT_FOUND=404,HTTP_INTERNAL_SERVER_ERROR=500;function curryBuildSuccessResponse(code){return payload=>buildSuccessResponse(code,typeof payload==`string`?{body:{message:payload}}:payload)}function curryBuildErrorResponse(code){return payload=>buildErrorResponse(code,typeof payload==`string`?{body:{message:payload}}:payload)}const ok=curryBuildSuccessResponse(200),created=curryBuildSuccessResponse(201),nonAuthoritativeInformation=curryBuildSuccessResponse(203),badRequest=curryBuildErrorResponse(400),unauthorized=curryBuildErrorResponse(401),forbidden=curryBuildErrorResponse(403),notFound=curryBuildErrorResponse(404),internalServerError=curryBuildErrorResponse(500);export{HTTP_BAD_REQUEST,HTTP_CREATED,HTTP_FORBIDDEN,HTTP_INTERNAL_SERVER_ERROR,HTTP_NON_AUTHORITATIVE_INFORMATION,HTTP_NOT_FOUND,HTTP_OK,HTTP_UNAUTHORIZED,badRequest,buildErrorResponse,buildSuccessResponse,created,forbidden,internalServerError,nonAuthoritativeInformation,notFound,ok,unauthorized};