@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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @adobe/aio-commerce-lib-core
|
|
2
2
|
|
|
3
|
+
## 1.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#345](https://github.com/adobe/aio-commerce-sdk/pull/345) [`38adb09`](https://github.com/adobe/aio-commerce-sdk/commit/38adb09e1e2bd1b8fa764ecc2e0d21ecc0071ca7) Thanks [@iivvaannxx](https://github.com/iivvaannxx)! - Drop Node 20 support (EOL April 2026).
|
|
8
|
+
|
|
9
|
+
## 1.0.0
|
|
10
|
+
|
|
11
|
+
### Major Changes
|
|
12
|
+
|
|
13
|
+
- [#294](https://github.com/adobe/aio-commerce-sdk/pull/294) [`6d5b16a`](https://github.com/adobe/aio-commerce-sdk/commit/6d5b16a7659ab0d83b251921ac478ff7faf0d4e5) Thanks [@iivvaannxx](https://github.com/iivvaannxx)! - General Availability (GA) release of the Adobe Commerce SDK and all libraries.
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- [#267](https://github.com/adobe/aio-commerce-sdk/pull/267) [`8642288`](https://github.com/adobe/aio-commerce-sdk/commit/8642288be4efd44b375d47e7cb75adb038c08334) Thanks [@jnatherley](https://github.com/jnatherley)! - Implements a rolldown plugin to correctly externalize transitive dependencies of private packages during build, but keep the source code of those same packages bundled.
|
|
18
|
+
|
|
3
19
|
## 0.6.1
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
# `@adobe/aio-commerce-lib-core`
|
|
2
2
|
|
|
3
|
-
> [!WARNING]
|
|
4
|
-
> This package is a work in progress and is not yet ready for use yet. You may be able to install it, but if you do, expect breaking changes.
|
|
5
|
-
|
|
6
3
|
This package provides core utilities used across the Adobe Commerce SDK.
|
|
7
4
|
|
|
8
5
|
## Installation
|
|
9
6
|
|
|
10
7
|
```shell
|
|
11
|
-
|
|
8
|
+
npm install @adobe/aio-commerce-lib-core
|
|
12
9
|
```
|
|
13
10
|
|
|
14
11
|
## Usage
|
package/dist/cjs/error/index.cjs
CHANGED
|
@@ -1 +1,19 @@
|
|
|
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
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
16
|
+
const require_error = require('../error-QC7QKZdI.cjs');
|
|
17
|
+
|
|
18
|
+
exports.CommerceSdkErrorBase = require_error.CommerceSdkErrorBase;
|
|
19
|
+
exports.CommerceSdkValidationError = require_error.CommerceSdkValidationError;
|
|
@@ -1,3 +1,17 @@
|
|
|
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
|
+
|
|
1
15
|
import { GenericIssue } from "valibot";
|
|
2
16
|
|
|
3
17
|
//#region source/error/base-error.d.ts
|
|
@@ -0,0 +1,228 @@
|
|
|
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 \0rolldown/runtime.js
|
|
16
|
+
var __create = Object.create;
|
|
17
|
+
var __defProp = Object.defineProperty;
|
|
18
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
19
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
20
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
21
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
22
|
+
var __copyProps = (to, from, except, desc) => {
|
|
23
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
24
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
25
|
+
key = keys[i];
|
|
26
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
27
|
+
__defProp(to, key, {
|
|
28
|
+
get: ((k) => from[k]).bind(null, key),
|
|
29
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return to;
|
|
35
|
+
};
|
|
36
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
37
|
+
value: mod,
|
|
38
|
+
enumerable: true
|
|
39
|
+
}) : target, mod));
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
let util = require("util");
|
|
43
|
+
util = __toESM(util, 1);
|
|
44
|
+
let ansis = require("ansis");
|
|
45
|
+
let valibot = require("valibot");
|
|
46
|
+
|
|
47
|
+
//#region source/error/base-error.ts
|
|
48
|
+
/**
|
|
49
|
+
* Base class for all the errors in the AIO Commerce SDK.
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* class ValidationError extends CommerceSdkErrorBase {
|
|
53
|
+
* constructor(message: string, options: ValidationErrorOptions) {
|
|
54
|
+
* super(message, options);
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
*
|
|
58
|
+
* const err = new ValidationError("Invalid value", {
|
|
59
|
+
* tag: "ValidationError",
|
|
60
|
+
* field: "name",
|
|
61
|
+
* value: "John Doe",
|
|
62
|
+
* });
|
|
63
|
+
*
|
|
64
|
+
* console.log(err.toJSON());
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
var CommerceSdkErrorBase = class CommerceSdkErrorBase extends Error {
|
|
68
|
+
/**
|
|
69
|
+
* Constructs a new CommerceSdkErrorBase instance. This is an abstract class so you
|
|
70
|
+
* should not instantiate it directly. Only invoke this constructor from a subclass.
|
|
71
|
+
*
|
|
72
|
+
* @param message - A human-friendly description of the error.
|
|
73
|
+
* @param options - Optional error options (additional information).
|
|
74
|
+
*/
|
|
75
|
+
constructor(message, options) {
|
|
76
|
+
const { traceId, ...baseOptions } = options ?? {};
|
|
77
|
+
super(message, baseOptions);
|
|
78
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
79
|
+
if (Error.captureStackTrace) Error.captureStackTrace(this, new.target);
|
|
80
|
+
this.name = new.target.name || "CommerceSdkError";
|
|
81
|
+
this.traceId = traceId;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Checks if the error is any CommerceSdkErrorBase instance.
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* class ValidationError extends CommerceSdkErrorBase {}
|
|
88
|
+
* const err = new ValidationError("Invalid", {});
|
|
89
|
+
*
|
|
90
|
+
* CommerceSdkErrorBase.isSdkError(err); // true
|
|
91
|
+
* ValidationError.isSdkError(err); // true
|
|
92
|
+
* CommerceSdkErrorBase.isSdkError(new Error("Regular")); // false
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
static isSdkError(error) {
|
|
96
|
+
return error instanceof CommerceSdkErrorBase;
|
|
97
|
+
}
|
|
98
|
+
/** Returns the full stack trace of the error and its causes. */
|
|
99
|
+
get fullStack() {
|
|
100
|
+
let out = this.stack ?? "";
|
|
101
|
+
let cause = this.cause;
|
|
102
|
+
while (cause instanceof Error) {
|
|
103
|
+
out += `\nCaused by: ${cause.stack ?? cause.message}`;
|
|
104
|
+
cause = cause.cause;
|
|
105
|
+
}
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
/** Returns the root cause of the error. */
|
|
109
|
+
get rootCause() {
|
|
110
|
+
let cause = this.cause;
|
|
111
|
+
while (cause) if (typeof cause === "object" && cause !== null && "cause" in cause) cause = cause.cause;
|
|
112
|
+
else break;
|
|
113
|
+
return cause;
|
|
114
|
+
}
|
|
115
|
+
/** Converts the error to a JSON-like representation. */
|
|
116
|
+
toJSON() {
|
|
117
|
+
return {
|
|
118
|
+
name: this.name,
|
|
119
|
+
message: this.message,
|
|
120
|
+
stack: this.fullStack,
|
|
121
|
+
cause: this.cause,
|
|
122
|
+
traceId: this.traceId
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Returns a pretty string representation of the error.
|
|
127
|
+
* @param inspect - Whether to inspect the error (returns a more detailed string, useful for debugging).
|
|
128
|
+
*/
|
|
129
|
+
toString(inspect = true) {
|
|
130
|
+
if (inspect) return util.default.inspect(this, {
|
|
131
|
+
depth: null,
|
|
132
|
+
colors: true,
|
|
133
|
+
sorted: true,
|
|
134
|
+
maxStringLength: Number.POSITIVE_INFINITY
|
|
135
|
+
});
|
|
136
|
+
return super.toString();
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region source/error/validation-error.ts
|
|
142
|
+
const LAST_RETURN_CHAR = "└── ";
|
|
143
|
+
const RETURN_CHAR = "├── ";
|
|
144
|
+
/** Maps issue kinds to their corresponding error titles for display purposes. */
|
|
145
|
+
const ISSUE_KIND_TO_ERROR_TITLE = {
|
|
146
|
+
schema: "Schema validation error",
|
|
147
|
+
transformation: "Transformation error",
|
|
148
|
+
validation: "Input error"
|
|
149
|
+
};
|
|
150
|
+
function getReturnChar(isLastItem, withColor) {
|
|
151
|
+
const char = isLastItem ? LAST_RETURN_CHAR : RETURN_CHAR;
|
|
152
|
+
return withColor ? (0, ansis.cyanBright)(char) : char;
|
|
153
|
+
}
|
|
154
|
+
function getKindText(kind, withColor) {
|
|
155
|
+
const text = ISSUE_KIND_TO_ERROR_TITLE[kind] ?? "Unknown issue kind";
|
|
156
|
+
return withColor ? (0, ansis.yellowBright)(text) : text;
|
|
157
|
+
}
|
|
158
|
+
function getPathText(dotPath, withColor) {
|
|
159
|
+
if (!dotPath) return "";
|
|
160
|
+
return withColor ? `${(0, ansis.cyanBright)(dotPath)}${(0, ansis.whiteBright)((0, ansis.dim)(" →"))}` : `${dotPath} →`;
|
|
161
|
+
}
|
|
162
|
+
function issueToDisplay(issues, withColor = true) {
|
|
163
|
+
return (issues?.map((issue, index) => {
|
|
164
|
+
const returnChar = getReturnChar(index === issues.length - 1, withColor);
|
|
165
|
+
const kindText = getKindText(issue.kind, withColor);
|
|
166
|
+
const path = getPathText((0, valibot.getDotPath)(issue), withColor);
|
|
167
|
+
const message = withColor ? (0, ansis.whiteBright)(issue.message) : issue.message;
|
|
168
|
+
return `${returnChar} ${`${kindText} ${withColor ? (0, ansis.whiteBright)("at") : "at"} ${path} ${message}`}`;
|
|
169
|
+
}))?.join("\n") ?? "";
|
|
170
|
+
}
|
|
171
|
+
function displayValidationError(error, withColor = true) {
|
|
172
|
+
const display = issueToDisplay(error.issues, withColor);
|
|
173
|
+
return `${withColor ? (0, ansis.whiteBright)(error.message) : error.message}\n${display}`;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Represents a validation error in the Commerce SDK.
|
|
177
|
+
* This error should be thrown when an input does not conform to the expected schema.
|
|
178
|
+
* It contains a list of issues that describe the validation errors.
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```ts
|
|
182
|
+
* const error = new CommerceSdkValidationError("Invalid input", {
|
|
183
|
+
* // `someIssues` is in scope, returned by some `valibot` operation.
|
|
184
|
+
* issues: someIssues
|
|
185
|
+
* });
|
|
186
|
+
*
|
|
187
|
+
* console.log(error.display());
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
var CommerceSdkValidationError = class extends CommerceSdkErrorBase {
|
|
191
|
+
/**
|
|
192
|
+
* Constructs a new {@link CommerceSdkValidationError} instance.
|
|
193
|
+
*
|
|
194
|
+
* @param message - A human-friendly description of the validation error.
|
|
195
|
+
* @param options - Options for the validation error, including the issues that caused the error.
|
|
196
|
+
*/
|
|
197
|
+
constructor(message, { issues, ...options }) {
|
|
198
|
+
super(message, options);
|
|
199
|
+
this.issues = issues;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Returns a pretty string (and colored) representation of the validation error.
|
|
203
|
+
* @param withColor Whether to use color in the output.
|
|
204
|
+
*/
|
|
205
|
+
display(withColor = true) {
|
|
206
|
+
return displayValidationError(this, withColor);
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
//#endregion
|
|
211
|
+
Object.defineProperty(exports, 'CommerceSdkErrorBase', {
|
|
212
|
+
enumerable: true,
|
|
213
|
+
get: function () {
|
|
214
|
+
return CommerceSdkErrorBase;
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
Object.defineProperty(exports, 'CommerceSdkValidationError', {
|
|
218
|
+
enumerable: true,
|
|
219
|
+
get: function () {
|
|
220
|
+
return CommerceSdkValidationError;
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
Object.defineProperty(exports, '__toESM', {
|
|
224
|
+
enumerable: true,
|
|
225
|
+
get: function () {
|
|
226
|
+
return __toESM;
|
|
227
|
+
}
|
|
228
|
+
});
|