@adobe/aio-commerce-lib-core 0.6.0 → 1.0.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.
@@ -1 +1,195 @@
1
- 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;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ //#region source/responses/helpers.ts
4
+ /**
5
+ * Creates a standardized error response for runtime actions
6
+ * @see https://developer.adobe.com/app-builder/docs/guides/runtime_guides/creating-actions#unsuccessful-response
7
+ *
8
+ * @template TBody - Additional error body properties beyond the required message field
9
+ * @template THeaders - Custom response headers
10
+ *
11
+ * @param statusCode - HTTP status code (e.g., 400, 404, 500)
12
+ * @param payload - Error response configuration
13
+ * @param payload.message - Human-readable error message (required)
14
+ * @param payload.body - Optional additional error details to include in the response body
15
+ * @param payload.headers - Optional custom response headers
16
+ *
17
+ * @returns Standardized error response object with type discriminator
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * // Simple error with just a message
22
+ * const error = buildErrorResponse(404, {
23
+ * message: 'Resource not found'
24
+ * });
25
+ *
26
+ * // Error with additional body data
27
+ * const error = buildErrorResponse(400, {
28
+ * message: 'Invalid request',
29
+ * body: { field: 'email', code: 'INVALID_FORMAT' }
30
+ * });
31
+ *
32
+ * // Error with custom headers
33
+ * const error = buildErrorResponse(429, {
34
+ * message: 'Rate limit exceeded',
35
+ * headers: { 'Retry-After': '60' }
36
+ * });
37
+ * ```
38
+ */
39
+ function buildErrorResponse(statusCode, payload) {
40
+ return {
41
+ type: "error",
42
+ error: {
43
+ ...payload?.headers && { headers: payload.headers },
44
+ statusCode,
45
+ body: payload.body
46
+ }
47
+ };
48
+ }
49
+ /**
50
+ * Creates a standardized success response for runtime actions
51
+ * @see https://developer.adobe.com/app-builder/docs/guides/runtime_guides/creating-actions#successful-response
52
+ *
53
+ * @template TBody - Response body properties
54
+ * @template THeaders - Custom response headers
55
+ *
56
+ * @param statusCode - HTTP status code (typically 200, 201, 204, etc.)
57
+ * @param payload - Success response configuration
58
+ * @param payload.message - Human-readable success message (required)
59
+ * @param payload.body - Optional additional response data to include in the response body
60
+ * @param payload.headers - Optional custom response headers
61
+ *
62
+ * @returns Standardized success response object with type discriminator
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * // Simple success response
67
+ * const response = buildSuccessResponse(200, {
68
+ * message: 'Operation successful'
69
+ * });
70
+ *
71
+ * // Success with additional body data
72
+ * const response = buildSuccessResponse(201, {
73
+ * message: 'Resource created',
74
+ * body: { id: '456', created: true },
75
+ * headers: { 'Location': '/api/resources/456' }
76
+ * });
77
+ * ```
78
+ */
79
+ function buildSuccessResponse(statusCode, payload) {
80
+ return {
81
+ type: "success",
82
+ statusCode,
83
+ ...payload?.headers && { headers: payload.headers },
84
+ ...payload?.body && { body: payload.body }
85
+ };
86
+ }
87
+
88
+ //#endregion
89
+ //#region source/responses/presets.ts
90
+ const HTTP_OK = 200;
91
+ const HTTP_CREATED = 201;
92
+ const HTTP_ACCEPTED = 202;
93
+ const HTTP_NON_AUTHORITATIVE_INFORMATION = 203;
94
+ const HTTP_NO_CONTENT = 204;
95
+ const HTTP_BAD_REQUEST = 400;
96
+ const HTTP_UNAUTHORIZED = 401;
97
+ const HTTP_FORBIDDEN = 403;
98
+ const HTTP_NOT_FOUND = 404;
99
+ const HTTP_METHOD_NOT_ALLOWED = 405;
100
+ const HTTP_CONFLICT = 409;
101
+ const HTTP_INTERNAL_SERVER_ERROR = 500;
102
+ function curryBuildSuccessResponse(code) {
103
+ return (payload) => buildSuccessResponse(code, typeof payload === "string" ? { body: { message: payload } } : payload);
104
+ }
105
+ function curryBuildErrorResponse(code) {
106
+ return (payload) => buildErrorResponse(code, typeof payload === "string" ? { body: { message: payload } } : payload);
107
+ }
108
+ /**
109
+ * Creates a success response with the HTTP status code 200.
110
+ * See {@link buildSuccessResponse} for details on the response payload.
111
+ */
112
+ const ok = curryBuildSuccessResponse(HTTP_OK);
113
+ /**
114
+ * Creates a success response with the HTTP status code 201.
115
+ * See {@link buildSuccessResponse} for details on the response payload.
116
+ */
117
+ const created = curryBuildSuccessResponse(HTTP_CREATED);
118
+ /**
119
+ * Creates a success response with the HTTP status code 202.
120
+ * See {@link buildSuccessResponse} for details on the response payload.
121
+ */
122
+ const accepted = curryBuildSuccessResponse(HTTP_ACCEPTED);
123
+ /**
124
+ * Creates a success response with the HTTP status code 203.
125
+ * See {@link buildSuccessResponse} for details on the response payload.
126
+ */
127
+ const nonAuthoritativeInformation = curryBuildSuccessResponse(HTTP_NON_AUTHORITATIVE_INFORMATION);
128
+ /**
129
+ * Creates a success response with the HTTP status code 204 (No Content).
130
+ * This response has no body.
131
+ */
132
+ const noContent = () => buildSuccessResponse(HTTP_NO_CONTENT);
133
+ /**
134
+ * Creates an error response with the HTTP status code 400.
135
+ * See {@link buildErrorResponse} for details on the response payload.
136
+ */
137
+ const badRequest = curryBuildErrorResponse(HTTP_BAD_REQUEST);
138
+ /**
139
+ * Creates an error response with the HTTP status code 401.
140
+ * See {@link buildErrorResponse} for details on the response payload.
141
+ */
142
+ const unauthorized = curryBuildErrorResponse(HTTP_UNAUTHORIZED);
143
+ /**
144
+ * Creates an error response with the HTTP status code 403.
145
+ * See {@link buildErrorResponse} for details on the response payload.
146
+ */
147
+ const forbidden = curryBuildErrorResponse(HTTP_FORBIDDEN);
148
+ /**
149
+ * Creates an error response with the HTTP status code 404.
150
+ * See {@link buildErrorResponse} for details on the response payload.
151
+ */
152
+ const notFound = curryBuildErrorResponse(HTTP_NOT_FOUND);
153
+ /**
154
+ * Creates an error response with the HTTP status code 405.
155
+ * See {@link buildErrorResponse} for details on the response payload.
156
+ */
157
+ const methodNotAllowed = curryBuildErrorResponse(HTTP_METHOD_NOT_ALLOWED);
158
+ /**
159
+ * Creates an error response with the HTTP status code 409.
160
+ * See {@link buildErrorResponse} for details on the response payload.
161
+ */
162
+ const conflict = curryBuildErrorResponse(HTTP_CONFLICT);
163
+ /**
164
+ * Creates an error response with the HTTP status code 500.
165
+ * See {@link buildErrorResponse} for details on the response payload.
166
+ */
167
+ const internalServerError = curryBuildErrorResponse(HTTP_INTERNAL_SERVER_ERROR);
168
+
169
+ //#endregion
170
+ exports.HTTP_ACCEPTED = HTTP_ACCEPTED;
171
+ exports.HTTP_BAD_REQUEST = HTTP_BAD_REQUEST;
172
+ exports.HTTP_CONFLICT = HTTP_CONFLICT;
173
+ exports.HTTP_CREATED = HTTP_CREATED;
174
+ exports.HTTP_FORBIDDEN = HTTP_FORBIDDEN;
175
+ exports.HTTP_INTERNAL_SERVER_ERROR = HTTP_INTERNAL_SERVER_ERROR;
176
+ exports.HTTP_METHOD_NOT_ALLOWED = HTTP_METHOD_NOT_ALLOWED;
177
+ exports.HTTP_NON_AUTHORITATIVE_INFORMATION = HTTP_NON_AUTHORITATIVE_INFORMATION;
178
+ exports.HTTP_NOT_FOUND = HTTP_NOT_FOUND;
179
+ exports.HTTP_NO_CONTENT = HTTP_NO_CONTENT;
180
+ exports.HTTP_OK = HTTP_OK;
181
+ exports.HTTP_UNAUTHORIZED = HTTP_UNAUTHORIZED;
182
+ exports.accepted = accepted;
183
+ exports.badRequest = badRequest;
184
+ exports.buildErrorResponse = buildErrorResponse;
185
+ exports.buildSuccessResponse = buildSuccessResponse;
186
+ exports.conflict = conflict;
187
+ exports.created = created;
188
+ exports.forbidden = forbidden;
189
+ exports.internalServerError = internalServerError;
190
+ exports.methodNotAllowed = methodNotAllowed;
191
+ exports.noContent = noContent;
192
+ exports.nonAuthoritativeInformation = nonAuthoritativeInformation;
193
+ exports.notFound = notFound;
194
+ exports.ok = ok;
195
+ exports.unauthorized = unauthorized;
@@ -36,7 +36,7 @@ type SuccessResponse<TBody extends BodyRecord = BodyRecord, THeaders extends Hea
36
36
  * @template TBody - Response/error body properties
37
37
  * @template THeaders - Custom response headers
38
38
  */
39
- type ActionResponse<TBody extends BodyRecordWithMessage = BodyRecordWithMessage, THeaders extends HeadersRecord = HeadersRecord> = SuccessResponse<TBody, THeaders> | ErrorResponse<TBody, THeaders>;
39
+ type ActionResponse<TSuccessBody extends BodyRecord = BodyRecord, TErrorBody extends BodyRecordWithMessage = BodyRecordWithMessage, THeaders extends HeadersRecord = HeadersRecord> = SuccessResponse<TSuccessBody, THeaders> | ErrorResponse<TErrorBody, THeaders>;
40
40
  /**
41
41
  * Creates a standardized error response for runtime actions
42
42
  * @see https://developer.adobe.com/app-builder/docs/guides/runtime_guides/creating-actions#unsuccessful-response
@@ -114,11 +114,15 @@ declare function buildSuccessResponse<TBody extends BodyRecord = BodyRecord, THe
114
114
  //#region source/responses/presets.d.ts
115
115
  declare const HTTP_OK = 200;
116
116
  declare const HTTP_CREATED = 201;
117
+ declare const HTTP_ACCEPTED = 202;
117
118
  declare const HTTP_NON_AUTHORITATIVE_INFORMATION = 203;
119
+ declare const HTTP_NO_CONTENT = 204;
118
120
  declare const HTTP_BAD_REQUEST = 400;
119
121
  declare const HTTP_UNAUTHORIZED = 401;
120
122
  declare const HTTP_FORBIDDEN = 403;
121
123
  declare const HTTP_NOT_FOUND = 404;
124
+ declare const HTTP_METHOD_NOT_ALLOWED = 405;
125
+ declare const HTTP_CONFLICT = 409;
122
126
  declare const HTTP_INTERNAL_SERVER_ERROR = 500;
123
127
  /**
124
128
  * Creates a success response with the HTTP status code 200.
@@ -136,6 +140,14 @@ declare const created: (payload?: string | {
136
140
  body?: BodyRecord;
137
141
  headers?: HeadersRecord;
138
142
  }) => SuccessResponse<BodyRecord, HeadersRecord>;
143
+ /**
144
+ * Creates a success response with the HTTP status code 202.
145
+ * See {@link buildSuccessResponse} for details on the response payload.
146
+ */
147
+ declare const accepted: (payload?: string | {
148
+ body?: BodyRecord;
149
+ headers?: HeadersRecord;
150
+ }) => SuccessResponse<BodyRecord, HeadersRecord>;
139
151
  /**
140
152
  * Creates a success response with the HTTP status code 203.
141
153
  * See {@link buildSuccessResponse} for details on the response payload.
@@ -144,6 +156,11 @@ declare const nonAuthoritativeInformation: (payload?: string | {
144
156
  body?: BodyRecord;
145
157
  headers?: HeadersRecord;
146
158
  }) => SuccessResponse<BodyRecord, HeadersRecord>;
159
+ /**
160
+ * Creates a success response with the HTTP status code 204 (No Content).
161
+ * This response has no body.
162
+ */
163
+ declare const noContent: () => SuccessResponse<BodyRecord, HeadersRecord>;
147
164
  /**
148
165
  * Creates an error response with the HTTP status code 400.
149
166
  * See {@link buildErrorResponse} for details on the response payload.
@@ -176,6 +193,22 @@ declare const notFound: (payload: string | {
176
193
  body: BodyRecordWithMessage;
177
194
  headers?: HeadersRecord;
178
195
  }) => ErrorResponse<BodyRecordWithMessage, HeadersRecord>;
196
+ /**
197
+ * Creates an error response with the HTTP status code 405.
198
+ * See {@link buildErrorResponse} for details on the response payload.
199
+ */
200
+ declare const methodNotAllowed: (payload: string | {
201
+ body: BodyRecordWithMessage;
202
+ headers?: HeadersRecord;
203
+ }) => ErrorResponse<BodyRecordWithMessage, HeadersRecord>;
204
+ /**
205
+ * Creates an error response with the HTTP status code 409.
206
+ * See {@link buildErrorResponse} for details on the response payload.
207
+ */
208
+ declare const conflict: (payload: string | {
209
+ body: BodyRecordWithMessage;
210
+ headers?: HeadersRecord;
211
+ }) => ErrorResponse<BodyRecordWithMessage, HeadersRecord>;
179
212
  /**
180
213
  * Creates an error response with the HTTP status code 500.
181
214
  * See {@link buildErrorResponse} for details on the response payload.
@@ -185,4 +218,4 @@ declare const internalServerError: (payload: string | {
185
218
  headers?: HeadersRecord;
186
219
  }) => ErrorResponse<BodyRecordWithMessage, HeadersRecord>;
187
220
  //#endregion
188
- export { type ActionResponse, type ErrorResponse, HTTP_BAD_REQUEST, HTTP_CREATED, HTTP_FORBIDDEN, HTTP_INTERNAL_SERVER_ERROR, HTTP_NON_AUTHORITATIVE_INFORMATION, HTTP_NOT_FOUND, HTTP_OK, HTTP_UNAUTHORIZED, type SuccessResponse, badRequest, buildErrorResponse, buildSuccessResponse, created, forbidden, internalServerError, nonAuthoritativeInformation, notFound, ok, unauthorized };
221
+ export { type ActionResponse, type ErrorResponse, 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, type SuccessResponse, accepted, badRequest, buildErrorResponse, buildSuccessResponse, conflict, created, forbidden, internalServerError, methodNotAllowed, noContent, nonAuthoritativeInformation, notFound, ok, unauthorized };
@@ -0,0 +1,38 @@
1
+ //#region source/params/helpers.d.ts
2
+ /**
3
+ * Checks if the given runtime action input value is non-empty.
4
+ *
5
+ * @param name - The name of the parameter. Required because of `aio app dev` compatibility: inputs mapped to undefined env vars come as $<input_name> in dev mode, but as '' in prod mode.
6
+ * @param value - The value of the parameter.
7
+ */
8
+ declare function nonEmpty(name: string, value: unknown): boolean;
9
+ /**
10
+ * Checks if all required parameters are non-empty.
11
+ *
12
+ * @param params - The action input parameters.
13
+ * @param required - The list of required parameter names.
14
+ */
15
+ declare function allNonEmpty<const T extends string[]>(params: Record<string, unknown>, required: T): params is Record<string, unknown> & Record<T[number], unknown>;
16
+ //#endregion
17
+ //#region source/params/types.d.ts
18
+ /**
19
+ * Standard HTTP methods supported by Adobe I/O Runtime.
20
+ * These are the methods that can be used when invoking runtime actions via HTTP.
21
+ */
22
+ type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";
23
+ /**
24
+ * Lowercase HTTP method as sent by OpenWhisk/Adobe I/O Runtime.
25
+ * OpenWhisk sends methods in lowercase (e.g., "get", "post").
26
+ */
27
+ type HttpMethodLowercase = Lowercase<HttpMethod>;
28
+ /** The type of the runtime action parameters. */
29
+ type RuntimeActionParams = {
30
+ /** If the runtime action is invoked via HTTP, this will be the headers of the request. */__ow_headers?: Record<string, string | undefined>; /** If the runtime action is invoked via HTTP, this will be the HTTP method of the request. */
31
+ __ow_method?: HttpMethodLowercase; /** If the runtime action is invoked via HTTP, this will be the unmatched path of the request (matching stops after consuming the action extension) */
32
+ __ow_path?: string; /** If the runtime action is invoked via HTTP, this will be the request body entity, as a base64-encoded string when its content is binary or JSON object/array, or as a plain string otherwise */
33
+ __ow_body?: string; /** If the runtime action is invoked via HTTP, this will be the query parameters of the request, as an unparsed string. */
34
+ __ow_query?: string;
35
+ [key: string]: unknown;
36
+ };
37
+ //#endregion
38
+ export { nonEmpty as a, allNonEmpty as i, HttpMethodLowercase as n, RuntimeActionParams as r, HttpMethod as t };
@@ -0,0 +1,214 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+ let util = require("util");
29
+ util = __toESM(util);
30
+ let ansis = require("ansis");
31
+ let valibot = require("valibot");
32
+
33
+ //#region source/error/base-error.ts
34
+ /**
35
+ * Base class for all the errors in the AIO Commerce SDK.
36
+ * @example
37
+ * ```ts
38
+ * class ValidationError extends CommerceSdkErrorBase {
39
+ * constructor(message: string, options: ValidationErrorOptions) {
40
+ * super(message, options);
41
+ * }
42
+ * }
43
+ *
44
+ * const err = new ValidationError("Invalid value", {
45
+ * tag: "ValidationError",
46
+ * field: "name",
47
+ * value: "John Doe",
48
+ * });
49
+ *
50
+ * console.log(err.toJSON());
51
+ * ```
52
+ */
53
+ var CommerceSdkErrorBase = class CommerceSdkErrorBase extends Error {
54
+ /**
55
+ * Constructs a new CommerceSdkErrorBase instance. This is an abstract class so you
56
+ * should not instantiate it directly. Only invoke this constructor from a subclass.
57
+ *
58
+ * @param message - A human-friendly description of the error.
59
+ * @param options - Optional error options (additional information).
60
+ */
61
+ constructor(message, options) {
62
+ const { traceId, ...baseOptions } = options ?? {};
63
+ super(message, baseOptions);
64
+ Object.setPrototypeOf(this, new.target.prototype);
65
+ if (Error.captureStackTrace) Error.captureStackTrace(this, new.target);
66
+ this.name = new.target.name || "CommerceSdkError";
67
+ this.traceId = traceId;
68
+ }
69
+ /**
70
+ * Checks if the error is any CommerceSdkErrorBase instance.
71
+ * @example
72
+ * ```ts
73
+ * class ValidationError extends CommerceSdkErrorBase {}
74
+ * const err = new ValidationError("Invalid", {});
75
+ *
76
+ * CommerceSdkErrorBase.isSdkError(err); // true
77
+ * ValidationError.isSdkError(err); // true
78
+ * CommerceSdkErrorBase.isSdkError(new Error("Regular")); // false
79
+ * ```
80
+ */
81
+ static isSdkError(error) {
82
+ return error instanceof CommerceSdkErrorBase;
83
+ }
84
+ /** Returns the full stack trace of the error and its causes. */
85
+ get fullStack() {
86
+ let out = this.stack ?? "";
87
+ let cause = this.cause;
88
+ while (cause instanceof Error) {
89
+ out += `\nCaused by: ${cause.stack ?? cause.message}`;
90
+ cause = cause.cause;
91
+ }
92
+ return out;
93
+ }
94
+ /** Returns the root cause of the error. */
95
+ get rootCause() {
96
+ let cause = this.cause;
97
+ while (cause) if (typeof cause === "object" && cause !== null && "cause" in cause) cause = cause.cause;
98
+ else break;
99
+ return cause;
100
+ }
101
+ /** Converts the error to a JSON-like representation. */
102
+ toJSON() {
103
+ return {
104
+ name: this.name,
105
+ message: this.message,
106
+ stack: this.fullStack,
107
+ cause: this.cause,
108
+ traceId: this.traceId
109
+ };
110
+ }
111
+ /**
112
+ * Returns a pretty string representation of the error.
113
+ * @param inspect - Whether to inspect the error (returns a more detailed string, useful for debugging).
114
+ */
115
+ toString(inspect = true) {
116
+ if (inspect) return util.default.inspect(this, {
117
+ depth: null,
118
+ colors: true,
119
+ sorted: true,
120
+ maxStringLength: Number.POSITIVE_INFINITY
121
+ });
122
+ return super.toString();
123
+ }
124
+ };
125
+
126
+ //#endregion
127
+ //#region source/error/validation-error.ts
128
+ const LAST_RETURN_CHAR = "└── ";
129
+ const RETURN_CHAR = "├── ";
130
+ /** Maps issue kinds to their corresponding error titles for display purposes. */
131
+ const ISSUE_KIND_TO_ERROR_TITLE = {
132
+ schema: "Schema validation error",
133
+ transformation: "Transformation error",
134
+ validation: "Input error"
135
+ };
136
+ function getReturnChar(isLastItem, withColor) {
137
+ const char = isLastItem ? LAST_RETURN_CHAR : RETURN_CHAR;
138
+ return withColor ? (0, ansis.cyanBright)(char) : char;
139
+ }
140
+ function getKindText(kind, withColor) {
141
+ const text = ISSUE_KIND_TO_ERROR_TITLE[kind] ?? "Unknown issue kind";
142
+ return withColor ? (0, ansis.yellowBright)(text) : text;
143
+ }
144
+ function getPathText(dotPath, withColor) {
145
+ if (!dotPath) return "";
146
+ return withColor ? `${(0, ansis.cyanBright)(dotPath)}${(0, ansis.whiteBright)((0, ansis.dim)(" →"))}` : `${dotPath} →`;
147
+ }
148
+ function issueToDisplay(issues, withColor = true) {
149
+ return (issues?.map((issue, index) => {
150
+ const returnChar = getReturnChar(index === issues.length - 1, withColor);
151
+ const kindText = getKindText(issue.kind, withColor);
152
+ const path = getPathText((0, valibot.getDotPath)(issue), withColor);
153
+ const message = withColor ? (0, ansis.whiteBright)(issue.message) : issue.message;
154
+ return `${returnChar} ${`${kindText} ${withColor ? (0, ansis.whiteBright)("at") : "at"} ${path} ${message}`}`;
155
+ }))?.join("\n") ?? "";
156
+ }
157
+ function displayValidationError(error, withColor = true) {
158
+ const display = issueToDisplay(error.issues, withColor);
159
+ return `${withColor ? (0, ansis.whiteBright)(error.message) : error.message}\n${display}`;
160
+ }
161
+ /**
162
+ * Represents a validation error in the Commerce SDK.
163
+ * This error should be thrown when an input does not conform to the expected schema.
164
+ * It contains a list of issues that describe the validation errors.
165
+ *
166
+ * @example
167
+ * ```ts
168
+ * const error = new CommerceSdkValidationError("Invalid input", {
169
+ * // `someIssues` is in scope, returned by some `valibot` operation.
170
+ * issues: someIssues
171
+ * });
172
+ *
173
+ * console.log(error.display());
174
+ * ```
175
+ */
176
+ var CommerceSdkValidationError = class extends CommerceSdkErrorBase {
177
+ /**
178
+ * Constructs a new {@link CommerceSdkValidationError} instance.
179
+ *
180
+ * @param message - A human-friendly description of the validation error.
181
+ * @param options - Options for the validation error, including the issues that caused the error.
182
+ */
183
+ constructor(message, { issues, ...options }) {
184
+ super(message, options);
185
+ this.issues = issues;
186
+ }
187
+ /**
188
+ * Returns a pretty string (and colored) representation of the validation error.
189
+ * @param withColor Whether to use color in the output.
190
+ */
191
+ display(withColor = true) {
192
+ return displayValidationError(this, withColor);
193
+ }
194
+ };
195
+
196
+ //#endregion
197
+ Object.defineProperty(exports, 'CommerceSdkErrorBase', {
198
+ enumerable: true,
199
+ get: function () {
200
+ return CommerceSdkErrorBase;
201
+ }
202
+ });
203
+ Object.defineProperty(exports, 'CommerceSdkValidationError', {
204
+ enumerable: true,
205
+ get: function () {
206
+ return CommerceSdkValidationError;
207
+ }
208
+ });
209
+ Object.defineProperty(exports, '__toESM', {
210
+ enumerable: true,
211
+ get: function () {
212
+ return __toESM;
213
+ }
214
+ });
@@ -1 +1,3 @@
1
- import{n as CommerceSdkErrorBase,t as CommerceSdkValidationError}from"../error-LySQb5Bh.mjs";export{CommerceSdkErrorBase,CommerceSdkValidationError};
1
+ import { n as CommerceSdkErrorBase, t as CommerceSdkValidationError } from "../validation-error-DT4-Oa0Z.mjs";
2
+
3
+ export { CommerceSdkErrorBase, CommerceSdkValidationError };
@@ -1,8 +1,7 @@
1
- import { t as RuntimeActionParams } from "../index-D8edNAiU.mjs";
1
+ import { r as RuntimeActionParams } from "../types-CMBSX5l-.mjs";
2
2
  import { CamelCase } from "type-fest";
3
3
 
4
4
  //#region source/headers/types.d.ts
5
-
6
5
  /** The type of an HTTP header value. */
7
6
  type HttpHeaderValue = string | string[] | undefined;
8
7
  /** The type of an HTTP headers record. */