@adobe/aio-commerce-lib-core
Version:
Core utilities for AIO Commerce SDK Libraries
14 lines • 2.37 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);exports.HTTP_BAD_REQUEST=400,exports.HTTP_CREATED=201,exports.HTTP_FORBIDDEN=403,exports.HTTP_INTERNAL_SERVER_ERROR=500,exports.HTTP_NON_AUTHORITATIVE_INFORMATION=203,exports.HTTP_NOT_FOUND=404,exports.HTTP_OK=200,exports.HTTP_UNAUTHORIZED=401,exports.badRequest=badRequest,exports.buildErrorResponse=buildErrorResponse,exports.buildSuccessResponse=buildSuccessResponse,exports.created=created,exports.forbidden=forbidden,exports.internalServerError=internalServerError,exports.nonAuthoritativeInformation=nonAuthoritativeInformation,exports.notFound=notFound,exports.ok=ok,exports.unauthorized=unauthorized;