@adobe/aio-commerce-lib-core 0.6.1 → 1.1.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 +16 -0
- package/README.md +1 -4
- package/dist/cjs/error/index.cjs +19 -1
- package/dist/cjs/error/index.d.cts +14 -0
- package/dist/cjs/error-QC7QKZdI.cjs +228 -0
- package/dist/cjs/headers/index.cjs +462 -1
- package/dist/cjs/headers/index.d.cts +15 -2
- package/dist/cjs/{index-2lCdMqhT.d.cts → index-Ddzq9z7b.d.cts} +18 -9
- package/dist/cjs/params/index.cjs +41 -1
- package/dist/cjs/params/index.d.cts +15 -1
- package/dist/cjs/responses/index.cjs +209 -1
- package/dist/cjs/responses/index.d.cts +14 -0
- package/dist/es/error/index.d.mts +14 -0
- package/dist/es/error/index.mjs +17 -1
- package/dist/es/error-dCuAZfGs.mjs +183 -0
- package/dist/es/headers/index.d.mts +15 -2
- package/dist/es/headers/index.mjs +449 -1
- package/dist/es/{index-CPYhPt8X.d.mts → index-2lCs6JZP.d.mts} +18 -9
- package/dist/es/params/index.d.mts +15 -1
- package/dist/es/params/index.mjs +38 -1
- package/dist/es/responses/index.d.mts +14 -0
- package/dist/es/responses/index.mjs +182 -1
- package/package.json +9 -6
- package/dist/cjs/error-LUQPfUfP.cjs +0 -2
- package/dist/es/error-LySQb5Bh.mjs +0 -2
|
@@ -1 +1,182 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2026 Adobe. All rights reserved.
|
|
5
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
7
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
10
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
11
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
|
+
* governing permissions and limitations under the License.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
//#region source/responses/helpers.ts
|
|
16
|
+
/**
|
|
17
|
+
* Creates a standardized error response for runtime actions
|
|
18
|
+
* @see https://developer.adobe.com/app-builder/docs/guides/runtime_guides/creating-actions#unsuccessful-response
|
|
19
|
+
*
|
|
20
|
+
* @template TBody - Additional error body properties beyond the required message field
|
|
21
|
+
* @template THeaders - Custom response headers
|
|
22
|
+
*
|
|
23
|
+
* @param statusCode - HTTP status code (e.g., 400, 404, 500)
|
|
24
|
+
* @param payload - Error response configuration
|
|
25
|
+
* @param payload.message - Human-readable error message (required)
|
|
26
|
+
* @param payload.body - Optional additional error details to include in the response body
|
|
27
|
+
* @param payload.headers - Optional custom response headers
|
|
28
|
+
*
|
|
29
|
+
* @returns Standardized error response object with type discriminator
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* // Simple error with just a message
|
|
34
|
+
* const error = buildErrorResponse(404, {
|
|
35
|
+
* message: 'Resource not found'
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* // Error with additional body data
|
|
39
|
+
* const error = buildErrorResponse(400, {
|
|
40
|
+
* message: 'Invalid request',
|
|
41
|
+
* body: { field: 'email', code: 'INVALID_FORMAT' }
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* // Error with custom headers
|
|
45
|
+
* const error = buildErrorResponse(429, {
|
|
46
|
+
* message: 'Rate limit exceeded',
|
|
47
|
+
* headers: { 'Retry-After': '60' }
|
|
48
|
+
* });
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
function buildErrorResponse(statusCode, payload) {
|
|
52
|
+
return {
|
|
53
|
+
type: "error",
|
|
54
|
+
error: {
|
|
55
|
+
...payload?.headers && { headers: payload.headers },
|
|
56
|
+
statusCode,
|
|
57
|
+
body: payload.body
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Creates a standardized success response for runtime actions
|
|
63
|
+
* @see https://developer.adobe.com/app-builder/docs/guides/runtime_guides/creating-actions#successful-response
|
|
64
|
+
*
|
|
65
|
+
* @template TBody - Response body properties
|
|
66
|
+
* @template THeaders - Custom response headers
|
|
67
|
+
*
|
|
68
|
+
* @param statusCode - HTTP status code (typically 200, 201, 204, etc.)
|
|
69
|
+
* @param payload - Success response configuration
|
|
70
|
+
* @param payload.message - Human-readable success message (required)
|
|
71
|
+
* @param payload.body - Optional additional response data to include in the response body
|
|
72
|
+
* @param payload.headers - Optional custom response headers
|
|
73
|
+
*
|
|
74
|
+
* @returns Standardized success response object with type discriminator
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* // Simple success response
|
|
79
|
+
* const response = buildSuccessResponse(200, {
|
|
80
|
+
* message: 'Operation successful'
|
|
81
|
+
* });
|
|
82
|
+
*
|
|
83
|
+
* // Success with additional body data
|
|
84
|
+
* const response = buildSuccessResponse(201, {
|
|
85
|
+
* message: 'Resource created',
|
|
86
|
+
* body: { id: '456', created: true },
|
|
87
|
+
* headers: { 'Location': '/api/resources/456' }
|
|
88
|
+
* });
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
function buildSuccessResponse(statusCode, payload) {
|
|
92
|
+
return {
|
|
93
|
+
type: "success",
|
|
94
|
+
statusCode,
|
|
95
|
+
...payload?.headers && { headers: payload.headers },
|
|
96
|
+
...payload?.body && { body: payload.body }
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region source/responses/presets.ts
|
|
102
|
+
const HTTP_OK = 200;
|
|
103
|
+
const HTTP_CREATED = 201;
|
|
104
|
+
const HTTP_ACCEPTED = 202;
|
|
105
|
+
const HTTP_NON_AUTHORITATIVE_INFORMATION = 203;
|
|
106
|
+
const HTTP_NO_CONTENT = 204;
|
|
107
|
+
const HTTP_BAD_REQUEST = 400;
|
|
108
|
+
const HTTP_UNAUTHORIZED = 401;
|
|
109
|
+
const HTTP_FORBIDDEN = 403;
|
|
110
|
+
const HTTP_NOT_FOUND = 404;
|
|
111
|
+
const HTTP_METHOD_NOT_ALLOWED = 405;
|
|
112
|
+
const HTTP_CONFLICT = 409;
|
|
113
|
+
const HTTP_INTERNAL_SERVER_ERROR = 500;
|
|
114
|
+
function curryBuildSuccessResponse(code) {
|
|
115
|
+
return (payload) => buildSuccessResponse(code, typeof payload === "string" ? { body: { message: payload } } : payload);
|
|
116
|
+
}
|
|
117
|
+
function curryBuildErrorResponse(code) {
|
|
118
|
+
return (payload) => buildErrorResponse(code, typeof payload === "string" ? { body: { message: payload } } : payload);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Creates a success response with the HTTP status code 200.
|
|
122
|
+
* See {@link buildSuccessResponse} for details on the response payload.
|
|
123
|
+
*/
|
|
124
|
+
const ok = curryBuildSuccessResponse(200);
|
|
125
|
+
/**
|
|
126
|
+
* Creates a success response with the HTTP status code 201.
|
|
127
|
+
* See {@link buildSuccessResponse} for details on the response payload.
|
|
128
|
+
*/
|
|
129
|
+
const created = curryBuildSuccessResponse(201);
|
|
130
|
+
/**
|
|
131
|
+
* Creates a success response with the HTTP status code 202.
|
|
132
|
+
* See {@link buildSuccessResponse} for details on the response payload.
|
|
133
|
+
*/
|
|
134
|
+
const accepted = curryBuildSuccessResponse(202);
|
|
135
|
+
/**
|
|
136
|
+
* Creates a success response with the HTTP status code 203.
|
|
137
|
+
* See {@link buildSuccessResponse} for details on the response payload.
|
|
138
|
+
*/
|
|
139
|
+
const nonAuthoritativeInformation = curryBuildSuccessResponse(203);
|
|
140
|
+
/**
|
|
141
|
+
* Creates a success response with the HTTP status code 204 (No Content).
|
|
142
|
+
* This response has no body.
|
|
143
|
+
*/
|
|
144
|
+
const noContent = () => buildSuccessResponse(204);
|
|
145
|
+
/**
|
|
146
|
+
* Creates an error response with the HTTP status code 400.
|
|
147
|
+
* See {@link buildErrorResponse} for details on the response payload.
|
|
148
|
+
*/
|
|
149
|
+
const badRequest = curryBuildErrorResponse(400);
|
|
150
|
+
/**
|
|
151
|
+
* Creates an error response with the HTTP status code 401.
|
|
152
|
+
* See {@link buildErrorResponse} for details on the response payload.
|
|
153
|
+
*/
|
|
154
|
+
const unauthorized = curryBuildErrorResponse(401);
|
|
155
|
+
/**
|
|
156
|
+
* Creates an error response with the HTTP status code 403.
|
|
157
|
+
* See {@link buildErrorResponse} for details on the response payload.
|
|
158
|
+
*/
|
|
159
|
+
const forbidden = curryBuildErrorResponse(403);
|
|
160
|
+
/**
|
|
161
|
+
* Creates an error response with the HTTP status code 404.
|
|
162
|
+
* See {@link buildErrorResponse} for details on the response payload.
|
|
163
|
+
*/
|
|
164
|
+
const notFound = curryBuildErrorResponse(404);
|
|
165
|
+
/**
|
|
166
|
+
* Creates an error response with the HTTP status code 405.
|
|
167
|
+
* See {@link buildErrorResponse} for details on the response payload.
|
|
168
|
+
*/
|
|
169
|
+
const methodNotAllowed = curryBuildErrorResponse(405);
|
|
170
|
+
/**
|
|
171
|
+
* Creates an error response with the HTTP status code 409.
|
|
172
|
+
* See {@link buildErrorResponse} for details on the response payload.
|
|
173
|
+
*/
|
|
174
|
+
const conflict = curryBuildErrorResponse(409);
|
|
175
|
+
/**
|
|
176
|
+
* Creates an error response with the HTTP status code 500.
|
|
177
|
+
* See {@link buildErrorResponse} for details on the response payload.
|
|
178
|
+
*/
|
|
179
|
+
const internalServerError = curryBuildErrorResponse(500);
|
|
180
|
+
|
|
181
|
+
//#endregion
|
|
182
|
+
export { HTTP_ACCEPTED, HTTP_BAD_REQUEST, HTTP_CONFLICT, HTTP_CREATED, HTTP_FORBIDDEN, HTTP_INTERNAL_SERVER_ERROR, HTTP_METHOD_NOT_ALLOWED, HTTP_NON_AUTHORITATIVE_INFORMATION, HTTP_NOT_FOUND, HTTP_NO_CONTENT, HTTP_OK, HTTP_UNAUTHORIZED, accepted, badRequest, buildErrorResponse, buildSuccessResponse, conflict, created, forbidden, internalServerError, methodNotAllowed, noContent, nonAuthoritativeInformation, notFound, ok, unauthorized };
|
package/package.json
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
"name": "@adobe/aio-commerce-lib-core",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"author": "Adobe Inc.",
|
|
5
|
-
"version": "
|
|
5
|
+
"version": "1.1.0",
|
|
6
6
|
"private": false,
|
|
7
7
|
"engines": {
|
|
8
|
-
"node": ">=
|
|
8
|
+
"node": ">=22 <=24"
|
|
9
9
|
},
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
|
-
"description": "Core utilities for
|
|
11
|
+
"description": "Core utilities for Adobe Commerce SDK libraries",
|
|
12
12
|
"keywords": [
|
|
13
13
|
"aio",
|
|
14
14
|
"adobe-io",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"adobe-commerce-sdk",
|
|
18
18
|
"aio-commerce-sdk",
|
|
19
19
|
"aio-commerce-lib-core",
|
|
20
|
-
"
|
|
20
|
+
"app-builder"
|
|
21
21
|
],
|
|
22
22
|
"bugs": {
|
|
23
23
|
"url": "https://github.com/adobe/aio-commerce-sdk/issues"
|
|
@@ -52,11 +52,13 @@
|
|
|
52
52
|
],
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"ansis": "^4.1.0",
|
|
55
|
-
"camelcase": "^
|
|
55
|
+
"camelcase": "^9.0.0",
|
|
56
|
+
"type-fest": "^5.0.0",
|
|
56
57
|
"valibot": "^1.1.0"
|
|
57
58
|
},
|
|
58
59
|
"devDependencies": {
|
|
59
|
-
"
|
|
60
|
+
"typescript": "^6.0.0",
|
|
61
|
+
"@aio-commerce-sdk/config-tsdown": "1.0.1",
|
|
60
62
|
"@aio-commerce-sdk/config-typedoc": "1.0.0",
|
|
61
63
|
"@aio-commerce-sdk/config-typescript": "1.0.0",
|
|
62
64
|
"@aio-commerce-sdk/config-vitest": "1.0.0"
|
|
@@ -70,6 +72,7 @@
|
|
|
70
72
|
"assist": "biome check --formatter-enabled=false --linter-enabled=false --assist-enabled=true --no-errors-on-unmatched",
|
|
71
73
|
"assist:apply": "biome check --write --formatter-enabled=false --linter-enabled=false --assist-enabled=true --no-errors-on-unmatched",
|
|
72
74
|
"check:ci": "biome ci --formatter-enabled=true --linter-enabled=true --assist-enabled=true --no-errors-on-unmatched",
|
|
75
|
+
"code:fix": "pnpm run lint:fix && pnpm run assist:apply && pnpm run format && pnpm run format:markdown",
|
|
73
76
|
"format": "biome format --write --no-errors-on-unmatched",
|
|
74
77
|
"format:markdown": "prettier --no-error-on-unmatched-pattern --write '**/*.md' \"!**/{CODE_OF_CONDUCT.md,COPYRIGHT,LICENSE,SECURITY.md,CONTRIBUTING.md}\"",
|
|
75
78
|
"format:check": "biome format --no-errors-on-unmatched",
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
var __create=Object.create,__defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty,__copyProps=(to,from,except,desc)=>{if(from&&typeof from==`object`||typeof from==`function`)for(var keys=__getOwnPropNames(from),i=0,n=keys.length,key;i<n;i++)key=keys[i],!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:(k=>from[k]).bind(null,key),enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to},__toESM=(mod,isNodeMode,target)=>(target=mod==null?{}:__create(__getProtoOf(mod)),__copyProps(isNodeMode||!mod||!mod.__esModule?__defProp(target,`default`,{value:mod,enumerable:!0}):target,mod));let util=require(`util`);util=__toESM(util);let ansis=require(`ansis`),valibot=require(`valibot`);var CommerceSdkErrorBase=class CommerceSdkErrorBase extends Error{constructor(message,options){let{traceId,...baseOptions}=options??{};super(message,baseOptions),Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,new.target),this.name=new.target.name||`CommerceSdkError`,this.traceId=traceId}static isSdkError(error){return error instanceof CommerceSdkErrorBase}get fullStack(){let out=this.stack??``,cause=this.cause;for(;cause instanceof Error;)out+=`\nCaused by: ${cause.stack??cause.message}`,cause=cause.cause;return out}get rootCause(){let cause=this.cause;for(;cause&&typeof cause==`object`&&cause&&`cause`in cause;)cause=cause.cause;return cause}toJSON(){return{name:this.name,message:this.message,stack:this.fullStack,cause:this.cause,traceId:this.traceId}}toString(inspect=!0){return inspect?util.default.inspect(this,{depth:null,colors:!0,sorted:!0,maxStringLength:1/0}):super.toString()}};const LAST_RETURN_CHAR=`└── `,RETURN_CHAR=`├── `,ISSUE_KIND_TO_ERROR_TITLE={schema:`Schema validation error`,transformation:`Transformation error`,validation:`Input error`};function getReturnChar(isLastItem,withColor){let char=isLastItem?`└── `:`├── `;return withColor?(0,ansis.cyanBright)(char):char}function getKindText(kind,withColor){let text=ISSUE_KIND_TO_ERROR_TITLE[kind]??`Unknown issue kind`;return withColor?(0,ansis.yellowBright)(text):text}function getPathText(dotPath,withColor){return dotPath?withColor?`${(0,ansis.cyanBright)(dotPath)}${(0,ansis.whiteBright)((0,ansis.dim)(` →`))}`:`${dotPath} →`:``}function issueToDisplay(issues,withColor=!0){return(issues?.map((issue,index)=>{let returnChar=getReturnChar(index===issues.length-1,withColor),kindText=getKindText(issue.kind,withColor),path=getPathText((0,valibot.getDotPath)(issue),withColor),message=withColor?(0,ansis.whiteBright)(issue.message):issue.message;return`${returnChar} ${`${kindText} ${withColor?(0,ansis.whiteBright)(`at`):`at`} ${path} ${message}`}`}))?.join(`
|
|
2
|
-
`)??``}function displayValidationError(error,withColor=!0){let display=issueToDisplay(error.issues,withColor);return`${withColor?(0,ansis.whiteBright)(error.message):error.message}\n${display}`}var CommerceSdkValidationError=class extends CommerceSdkErrorBase{constructor(message,{issues,...options}){super(message,options),this.issues=issues}display(withColor=!0){return displayValidationError(this,withColor)}};Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return CommerceSdkErrorBase}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return __toESM}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return CommerceSdkValidationError}});
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import util from"util";import{cyanBright,dim,whiteBright,yellowBright}from"ansis";import{getDotPath}from"valibot";var CommerceSdkErrorBase=class CommerceSdkErrorBase extends Error{constructor(message,options){let{traceId,...baseOptions}=options??{};super(message,baseOptions),Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,new.target),this.name=new.target.name||`CommerceSdkError`,this.traceId=traceId}static isSdkError(error){return error instanceof CommerceSdkErrorBase}get fullStack(){let out=this.stack??``,cause=this.cause;for(;cause instanceof Error;)out+=`\nCaused by: ${cause.stack??cause.message}`,cause=cause.cause;return out}get rootCause(){let cause=this.cause;for(;cause&&typeof cause==`object`&&cause&&`cause`in cause;)cause=cause.cause;return cause}toJSON(){return{name:this.name,message:this.message,stack:this.fullStack,cause:this.cause,traceId:this.traceId}}toString(inspect=!0){return inspect?util.inspect(this,{depth:null,colors:!0,sorted:!0,maxStringLength:1/0}):super.toString()}};const ISSUE_KIND_TO_ERROR_TITLE={schema:`Schema validation error`,transformation:`Transformation error`,validation:`Input error`};function getReturnChar(isLastItem,withColor){let char=isLastItem?`└── `:`├── `;return withColor?cyanBright(char):char}function getKindText(kind,withColor){let text=ISSUE_KIND_TO_ERROR_TITLE[kind]??`Unknown issue kind`;return withColor?yellowBright(text):text}function getPathText(dotPath,withColor){return dotPath?withColor?`${cyanBright(dotPath)}${whiteBright(dim(` →`))}`:`${dotPath} →`:``}function issueToDisplay(issues,withColor=!0){return(issues?.map((issue,index)=>{let returnChar=getReturnChar(index===issues.length-1,withColor),kindText=getKindText(issue.kind,withColor),path=getPathText(getDotPath(issue),withColor),message=withColor?whiteBright(issue.message):issue.message;return`${returnChar} ${`${kindText} ${withColor?whiteBright(`at`):`at`} ${path} ${message}`}`}))?.join(`
|
|
2
|
-
`)??``}function displayValidationError(error,withColor=!0){let display=issueToDisplay(error.issues,withColor);return`${withColor?whiteBright(error.message):error.message}\n${display}`}var CommerceSdkValidationError=class extends CommerceSdkErrorBase{constructor(message,{issues,...options}){super(message,options),this.issues=issues}display(withColor=!0){return displayValidationError(this,withColor)}};export{CommerceSdkErrorBase as n,CommerceSdkValidationError as t};
|