@adobe/aio-commerce-lib-core 1.2.0 → 1.3.0-alpha-20261029105213
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 +6 -0
- package/dist/cjs/commerce/index.cjs +2 -3
- package/dist/cjs/commerce/index.d.cts +4 -7
- package/dist/cjs/error/index.cjs +3 -2
- package/dist/cjs/error/index.d.cts +20 -12
- package/dist/cjs/{error-DcSWQLuA.cjs → error-D892zgDO.cjs} +32 -7
- package/dist/cjs/headers/index.cjs +16 -18
- package/dist/cjs/headers/index.d.cts +15 -26
- package/dist/{es/index-CkxLqyh-.d.mts → cjs/index-_sNhjzIe.d.cts} +9 -8
- package/dist/cjs/params/index.cjs +2 -4
- package/dist/cjs/params/index.d.cts +1 -1
- package/dist/cjs/responses/index.cjs +2 -5
- package/dist/cjs/responses/index.d.cts +30 -34
- package/dist/cjs/{rolldown-runtime-Cozy-1ZF.cjs → rolldown-runtime-CoOt0iuZ.cjs} +3 -5
- package/dist/es/commerce/index.d.mts +4 -7
- package/dist/es/commerce/index.mjs +1 -2
- package/dist/es/error/index.d.mts +20 -12
- package/dist/es/error/index.mjs +2 -2
- package/dist/es/{error-hJtCYFBx.mjs → error-DHfBWC_D.mjs} +24 -5
- package/dist/es/headers/index.d.mts +15 -26
- package/dist/es/headers/index.mjs +15 -17
- package/dist/{cjs/index-CkxLqyh-.d.cts → es/index-_sNhjzIe.d.mts} +9 -8
- package/dist/es/params/index.d.mts +1 -1
- package/dist/es/params/index.mjs +2 -3
- package/dist/es/responses/index.d.mts +30 -34
- package/dist/es/responses/index.mjs +2 -4
- package/package.json +26 -25
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
* governing permissions and limitations under the License.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
//#region source/responses/helpers.d.ts
|
|
16
15
|
type HeadersRecord = Record<string, string>;
|
|
17
16
|
type BodyRecord = Record<string, unknown>;
|
|
18
17
|
type BodyRecordWithMessage = BodyRecord & {
|
|
@@ -65,7 +64,7 @@ type ActionResponse<TSuccessBody extends BodyRecord = BodyRecord, TErrorBody ext
|
|
|
65
64
|
* }
|
|
66
65
|
* ```
|
|
67
66
|
*/
|
|
68
|
-
declare function isSuccessResponse(response: unknown): response is SuccessResponse;
|
|
67
|
+
export declare function isSuccessResponse(response: unknown): response is SuccessResponse;
|
|
69
68
|
/**
|
|
70
69
|
* Determines whether a value is a standardized SDK error response.
|
|
71
70
|
*
|
|
@@ -80,7 +79,7 @@ declare function isSuccessResponse(response: unknown): response is SuccessRespon
|
|
|
80
79
|
* }
|
|
81
80
|
* ```
|
|
82
81
|
*/
|
|
83
|
-
declare function isErrorResponse(response: unknown): response is ErrorResponse;
|
|
82
|
+
export declare function isErrorResponse(response: unknown): response is ErrorResponse;
|
|
84
83
|
/**
|
|
85
84
|
* Determines whether a value is a standardized SDK action response.
|
|
86
85
|
*
|
|
@@ -95,7 +94,7 @@ declare function isErrorResponse(response: unknown): response is ErrorResponse;
|
|
|
95
94
|
* }
|
|
96
95
|
* ```
|
|
97
96
|
*/
|
|
98
|
-
declare function isActionResponse(response: unknown): response is ActionResponse;
|
|
97
|
+
export declare function isActionResponse(response: unknown): response is ActionResponse;
|
|
99
98
|
/**
|
|
100
99
|
* Creates a standardized error response for runtime actions
|
|
101
100
|
* @see https://developer.adobe.com/app-builder/docs/guides/runtime_guides/creating-actions#unsuccessful-response
|
|
@@ -131,7 +130,7 @@ declare function isActionResponse(response: unknown): response is ActionResponse
|
|
|
131
130
|
* });
|
|
132
131
|
* ```
|
|
133
132
|
*/
|
|
134
|
-
declare function buildErrorResponse<TBody extends BodyRecordWithMessage = BodyRecordWithMessage, THeaders extends HeadersRecord = HeadersRecord>(statusCode: number, payload: {
|
|
133
|
+
export declare function buildErrorResponse<TBody extends BodyRecordWithMessage = BodyRecordWithMessage, THeaders extends HeadersRecord = HeadersRecord>(statusCode: number, payload: {
|
|
135
134
|
body: TBody;
|
|
136
135
|
headers?: THeaders;
|
|
137
136
|
}): ErrorResponse<TBody, THeaders>;
|
|
@@ -165,29 +164,27 @@ declare function buildErrorResponse<TBody extends BodyRecordWithMessage = BodyRe
|
|
|
165
164
|
* });
|
|
166
165
|
* ```
|
|
167
166
|
*/
|
|
168
|
-
declare function buildSuccessResponse<TBody extends BodyRecord = BodyRecord, THeaders extends HeadersRecord = HeadersRecord>(statusCode: number, payload?: {
|
|
167
|
+
export declare function buildSuccessResponse<TBody extends BodyRecord = BodyRecord, THeaders extends HeadersRecord = HeadersRecord>(statusCode: number, payload?: {
|
|
169
168
|
body?: TBody;
|
|
170
169
|
headers?: THeaders;
|
|
171
170
|
}): SuccessResponse<TBody, THeaders>;
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
declare const
|
|
175
|
-
declare const
|
|
176
|
-
declare const
|
|
177
|
-
declare const
|
|
178
|
-
declare const
|
|
179
|
-
declare const
|
|
180
|
-
declare const
|
|
181
|
-
declare const
|
|
182
|
-
declare const
|
|
183
|
-
declare const
|
|
184
|
-
declare const HTTP_CONFLICT = 409;
|
|
185
|
-
declare const HTTP_INTERNAL_SERVER_ERROR = 500;
|
|
171
|
+
export declare const HTTP_OK = 200;
|
|
172
|
+
export declare const HTTP_CREATED = 201;
|
|
173
|
+
export declare const HTTP_ACCEPTED = 202;
|
|
174
|
+
export declare const HTTP_NON_AUTHORITATIVE_INFORMATION = 203;
|
|
175
|
+
export declare const HTTP_NO_CONTENT = 204;
|
|
176
|
+
export declare const HTTP_BAD_REQUEST = 400;
|
|
177
|
+
export declare const HTTP_UNAUTHORIZED = 401;
|
|
178
|
+
export declare const HTTP_FORBIDDEN = 403;
|
|
179
|
+
export declare const HTTP_NOT_FOUND = 404;
|
|
180
|
+
export declare const HTTP_METHOD_NOT_ALLOWED = 405;
|
|
181
|
+
export declare const HTTP_CONFLICT = 409;
|
|
182
|
+
export declare const HTTP_INTERNAL_SERVER_ERROR = 500;
|
|
186
183
|
/**
|
|
187
184
|
* Creates a success response with the HTTP status code 200.
|
|
188
185
|
* See {@link buildSuccessResponse} for details on the response payload.
|
|
189
186
|
*/
|
|
190
|
-
declare const ok: <TBody extends BodyRecord = BodyRecord>(payload?: string | {
|
|
187
|
+
export declare const ok: <TBody extends BodyRecord = BodyRecord>(payload?: string | {
|
|
191
188
|
body?: TBody;
|
|
192
189
|
headers?: HeadersRecord;
|
|
193
190
|
}) => SuccessResponse<TBody>;
|
|
@@ -195,7 +192,7 @@ declare const ok: <TBody extends BodyRecord = BodyRecord>(payload?: string | {
|
|
|
195
192
|
* Creates a success response with the HTTP status code 201.
|
|
196
193
|
* See {@link buildSuccessResponse} for details on the response payload.
|
|
197
194
|
*/
|
|
198
|
-
declare const created: <TBody extends BodyRecord = BodyRecord>(payload?: string | {
|
|
195
|
+
export declare const created: <TBody extends BodyRecord = BodyRecord>(payload?: string | {
|
|
199
196
|
body?: TBody;
|
|
200
197
|
headers?: HeadersRecord;
|
|
201
198
|
}) => SuccessResponse<TBody>;
|
|
@@ -203,7 +200,7 @@ declare const created: <TBody extends BodyRecord = BodyRecord>(payload?: string
|
|
|
203
200
|
* Creates a success response with the HTTP status code 202.
|
|
204
201
|
* See {@link buildSuccessResponse} for details on the response payload.
|
|
205
202
|
*/
|
|
206
|
-
declare const accepted: <TBody extends BodyRecord = BodyRecord>(payload?: string | {
|
|
203
|
+
export declare const accepted: <TBody extends BodyRecord = BodyRecord>(payload?: string | {
|
|
207
204
|
body?: TBody;
|
|
208
205
|
headers?: HeadersRecord;
|
|
209
206
|
}) => SuccessResponse<TBody>;
|
|
@@ -211,7 +208,7 @@ declare const accepted: <TBody extends BodyRecord = BodyRecord>(payload?: string
|
|
|
211
208
|
* Creates a success response with the HTTP status code 203.
|
|
212
209
|
* See {@link buildSuccessResponse} for details on the response payload.
|
|
213
210
|
*/
|
|
214
|
-
declare const nonAuthoritativeInformation: <TBody extends BodyRecord = BodyRecord>(payload?: string | {
|
|
211
|
+
export declare const nonAuthoritativeInformation: <TBody extends BodyRecord = BodyRecord>(payload?: string | {
|
|
215
212
|
body?: TBody;
|
|
216
213
|
headers?: HeadersRecord;
|
|
217
214
|
}) => SuccessResponse<TBody>;
|
|
@@ -219,12 +216,12 @@ declare const nonAuthoritativeInformation: <TBody extends BodyRecord = BodyRecor
|
|
|
219
216
|
* Creates a success response with the HTTP status code 204 (No Content).
|
|
220
217
|
* This response has no body.
|
|
221
218
|
*/
|
|
222
|
-
declare const noContent: () => SuccessResponse<BodyRecord, HeadersRecord>;
|
|
219
|
+
export declare const noContent: () => SuccessResponse<BodyRecord, HeadersRecord>;
|
|
223
220
|
/**
|
|
224
221
|
* Creates an error response with the HTTP status code 400.
|
|
225
222
|
* See {@link buildErrorResponse} for details on the response payload.
|
|
226
223
|
*/
|
|
227
|
-
declare const badRequest: <TBody extends BodyRecordWithMessage = BodyRecordWithMessage>(payload: string | {
|
|
224
|
+
export declare const badRequest: <TBody extends BodyRecordWithMessage = BodyRecordWithMessage>(payload: string | {
|
|
228
225
|
body: TBody;
|
|
229
226
|
headers?: HeadersRecord;
|
|
230
227
|
}) => ErrorResponse<TBody>;
|
|
@@ -232,7 +229,7 @@ declare const badRequest: <TBody extends BodyRecordWithMessage = BodyRecordWithM
|
|
|
232
229
|
* Creates an error response with the HTTP status code 401.
|
|
233
230
|
* See {@link buildErrorResponse} for details on the response payload.
|
|
234
231
|
*/
|
|
235
|
-
declare const unauthorized: <TBody extends BodyRecordWithMessage = BodyRecordWithMessage>(payload: string | {
|
|
232
|
+
export declare const unauthorized: <TBody extends BodyRecordWithMessage = BodyRecordWithMessage>(payload: string | {
|
|
236
233
|
body: TBody;
|
|
237
234
|
headers?: HeadersRecord;
|
|
238
235
|
}) => ErrorResponse<TBody>;
|
|
@@ -240,7 +237,7 @@ declare const unauthorized: <TBody extends BodyRecordWithMessage = BodyRecordWit
|
|
|
240
237
|
* Creates an error response with the HTTP status code 403.
|
|
241
238
|
* See {@link buildErrorResponse} for details on the response payload.
|
|
242
239
|
*/
|
|
243
|
-
declare const forbidden: <TBody extends BodyRecordWithMessage = BodyRecordWithMessage>(payload: string | {
|
|
240
|
+
export declare const forbidden: <TBody extends BodyRecordWithMessage = BodyRecordWithMessage>(payload: string | {
|
|
244
241
|
body: TBody;
|
|
245
242
|
headers?: HeadersRecord;
|
|
246
243
|
}) => ErrorResponse<TBody>;
|
|
@@ -248,7 +245,7 @@ declare const forbidden: <TBody extends BodyRecordWithMessage = BodyRecordWithMe
|
|
|
248
245
|
* Creates an error response with the HTTP status code 404.
|
|
249
246
|
* See {@link buildErrorResponse} for details on the response payload.
|
|
250
247
|
*/
|
|
251
|
-
declare const notFound: <TBody extends BodyRecordWithMessage = BodyRecordWithMessage>(payload: string | {
|
|
248
|
+
export declare const notFound: <TBody extends BodyRecordWithMessage = BodyRecordWithMessage>(payload: string | {
|
|
252
249
|
body: TBody;
|
|
253
250
|
headers?: HeadersRecord;
|
|
254
251
|
}) => ErrorResponse<TBody>;
|
|
@@ -256,7 +253,7 @@ declare const notFound: <TBody extends BodyRecordWithMessage = BodyRecordWithMes
|
|
|
256
253
|
* Creates an error response with the HTTP status code 405.
|
|
257
254
|
* See {@link buildErrorResponse} for details on the response payload.
|
|
258
255
|
*/
|
|
259
|
-
declare const methodNotAllowed: <TBody extends BodyRecordWithMessage = BodyRecordWithMessage>(payload: string | {
|
|
256
|
+
export declare const methodNotAllowed: <TBody extends BodyRecordWithMessage = BodyRecordWithMessage>(payload: string | {
|
|
260
257
|
body: TBody;
|
|
261
258
|
headers?: HeadersRecord;
|
|
262
259
|
}) => ErrorResponse<TBody>;
|
|
@@ -264,7 +261,7 @@ declare const methodNotAllowed: <TBody extends BodyRecordWithMessage = BodyRecor
|
|
|
264
261
|
* Creates an error response with the HTTP status code 409.
|
|
265
262
|
* See {@link buildErrorResponse} for details on the response payload.
|
|
266
263
|
*/
|
|
267
|
-
declare const conflict: <TBody extends BodyRecordWithMessage = BodyRecordWithMessage>(payload: string | {
|
|
264
|
+
export declare const conflict: <TBody extends BodyRecordWithMessage = BodyRecordWithMessage>(payload: string | {
|
|
268
265
|
body: TBody;
|
|
269
266
|
headers?: HeadersRecord;
|
|
270
267
|
}) => ErrorResponse<TBody>;
|
|
@@ -272,9 +269,8 @@ declare const conflict: <TBody extends BodyRecordWithMessage = BodyRecordWithMes
|
|
|
272
269
|
* Creates an error response with the HTTP status code 500.
|
|
273
270
|
* See {@link buildErrorResponse} for details on the response payload.
|
|
274
271
|
*/
|
|
275
|
-
declare const internalServerError: <TBody extends BodyRecordWithMessage = BodyRecordWithMessage>(payload: string | {
|
|
272
|
+
export declare const internalServerError: <TBody extends BodyRecordWithMessage = BodyRecordWithMessage>(payload: string | {
|
|
276
273
|
body: TBody;
|
|
277
274
|
headers?: HeadersRecord;
|
|
278
275
|
}) => ErrorResponse<TBody>;
|
|
279
|
-
|
|
280
|
-
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, isActionResponse, isErrorResponse, isSuccessResponse, methodNotAllowed, noContent, nonAuthoritativeInformation, notFound, ok, unauthorized };
|
|
276
|
+
export type { ActionResponse, ErrorResponse, SuccessResponse };
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* governing permissions and limitations under the License.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
// \0rolldown/runtime.js
|
|
16
16
|
var __create = Object.create;
|
|
17
17
|
var __defProp = Object.defineProperty;
|
|
18
18
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -33,14 +33,12 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
33
33
|
}
|
|
34
34
|
return to;
|
|
35
35
|
};
|
|
36
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
36
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
37
37
|
value: mod,
|
|
38
38
|
enumerable: true
|
|
39
39
|
}) : target, mod));
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
Object.defineProperty(exports, '__toESM', {
|
|
41
|
+
Object.defineProperty(exports, "__toESM", {
|
|
44
42
|
enumerable: true,
|
|
45
43
|
get: function () {
|
|
46
44
|
return __toESM;
|
|
@@ -13,14 +13,12 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import * as v from "valibot";
|
|
16
|
-
|
|
17
|
-
//#region source/commerce/env.d.ts
|
|
18
16
|
/** The list of supported Commerce environments an item can be scoped to. */
|
|
19
|
-
declare const COMMERCE_ENVS: ["paas", "saas"];
|
|
17
|
+
export declare const COMMERCE_ENVS: ["paas", "saas"];
|
|
20
18
|
/** A single Commerce environment an item can be scoped to. */
|
|
21
19
|
type CommerceEnv = (typeof COMMERCE_ENVS)[number];
|
|
22
20
|
/** Schema for a single Commerce environment an item can be scoped to. */
|
|
23
|
-
declare const CommerceEnvSchema: v.PicklistSchema<["paas", "saas"], `Expected one of: ${string}`>;
|
|
21
|
+
export declare const CommerceEnvSchema: v.PicklistSchema<["paas", "saas"], `Expected one of: ${string}`>;
|
|
24
22
|
/**
|
|
25
23
|
* Schema for a non-empty array of Commerce environments, used to scope an item
|
|
26
24
|
* (a configuration field, webhook, or event) to specific environments.
|
|
@@ -28,6 +26,5 @@ declare const CommerceEnvSchema: v.PicklistSchema<["paas", "saas"], `Expected on
|
|
|
28
26
|
* Apply the optional wrapper at the call site (`v.optional(CommerceEnvArraySchema)`);
|
|
29
27
|
* when omitted, the item applies to all environments.
|
|
30
28
|
*/
|
|
31
|
-
declare const CommerceEnvArraySchema: v.SchemaWithPipe<readonly [v.ArraySchema<v.PicklistSchema<["paas", "saas"], `Expected one of: ${string}`>, "Expected an array of commerce environments for the field \"env\"">, v.NonEmptyAction<("paas" | "saas")[], "The \"env\" array must contain at least one commerce environment">]>;
|
|
32
|
-
|
|
33
|
-
export { COMMERCE_ENVS, type CommerceEnv, CommerceEnvArraySchema, CommerceEnvSchema };
|
|
29
|
+
export declare const CommerceEnvArraySchema: v.SchemaWithPipe<readonly [v.ArraySchema<v.PicklistSchema<["paas", "saas"], `Expected one of: ${string}`>, "Expected an array of commerce environments for the field \"env\"">, v.NonEmptyAction<("paas" | "saas")[], "The \"env\" array must contain at least one commerce environment">]>;
|
|
30
|
+
export type { CommerceEnv };
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
import * as v from "valibot";
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
// source/commerce/env.ts
|
|
18
18
|
/** The list of supported Commerce environments an item can be scoped to. */
|
|
19
19
|
const COMMERCE_ENVS = ["paas", "saas"];
|
|
20
20
|
/** Schema for a single Commerce environment an item can be scoped to. */
|
|
@@ -28,5 +28,4 @@ const CommerceEnvSchema = v.picklist(COMMERCE_ENVS, `Expected one of: ${COMMERCE
|
|
|
28
28
|
*/
|
|
29
29
|
const CommerceEnvArraySchema = v.pipe(v.array(CommerceEnvSchema, "Expected an array of commerce environments for the field \"env\""), v.nonEmpty("The \"env\" array must contain at least one commerce environment"));
|
|
30
30
|
|
|
31
|
-
//#endregion
|
|
32
31
|
export { COMMERCE_ENVS, CommerceEnvArraySchema, CommerceEnvSchema };
|
|
@@ -13,8 +13,6 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import { GenericIssue } from "valibot";
|
|
16
|
-
|
|
17
|
-
//#region source/error/base-error.d.ts
|
|
18
16
|
/** Defines the base options for {@link CommerceSdkErrorBase}. */
|
|
19
17
|
type CommerceSdkErrorBaseOptions = ErrorOptions & {
|
|
20
18
|
traceId?: string;
|
|
@@ -49,7 +47,7 @@ type CommerceSdkErrorOptions<T extends Record<string, unknown> = Record<string,
|
|
|
49
47
|
* console.log(err.toJSON());
|
|
50
48
|
* ```
|
|
51
49
|
*/
|
|
52
|
-
declare abstract class CommerceSdkErrorBase extends Error {
|
|
50
|
+
export declare abstract class CommerceSdkErrorBase extends Error {
|
|
53
51
|
readonly traceId?: string;
|
|
54
52
|
/**
|
|
55
53
|
* Constructs a new CommerceSdkErrorBase instance. This is an abstract class so you
|
|
@@ -90,8 +88,22 @@ declare abstract class CommerceSdkErrorBase extends Error {
|
|
|
90
88
|
*/
|
|
91
89
|
toString(inspect?: boolean): string;
|
|
92
90
|
}
|
|
93
|
-
|
|
94
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Converts any thrown value to a human-friendly string.
|
|
93
|
+
*
|
|
94
|
+
* Validation errors use their formatted `display()` output, other errors use their message, and any other value goes through `String()`.
|
|
95
|
+
*
|
|
96
|
+
* @param error - The thrown value to convert.
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* try {
|
|
100
|
+
* await doSomething();
|
|
101
|
+
* } catch (error) {
|
|
102
|
+
* console.error(stringifyError(error));
|
|
103
|
+
* }
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export declare function stringifyError(error: unknown): string;
|
|
95
107
|
/** Defines the base options for {@link CommerceSdkValidationError}. */
|
|
96
108
|
type CommerceSdkValidationErrorOptions = CommerceSdkErrorOptions<{
|
|
97
109
|
issues: GenericIssue[];
|
|
@@ -111,7 +123,7 @@ type CommerceSdkValidationErrorOptions = CommerceSdkErrorOptions<{
|
|
|
111
123
|
* console.log(error.display());
|
|
112
124
|
* ```
|
|
113
125
|
*/
|
|
114
|
-
declare class CommerceSdkValidationError extends CommerceSdkErrorBase {
|
|
126
|
+
export declare class CommerceSdkValidationError extends CommerceSdkErrorBase {
|
|
115
127
|
readonly issues: GenericIssue[];
|
|
116
128
|
/**
|
|
117
129
|
* Constructs a new {@link CommerceSdkValidationError} instance.
|
|
@@ -119,15 +131,11 @@ declare class CommerceSdkValidationError extends CommerceSdkErrorBase {
|
|
|
119
131
|
* @param message - A human-friendly description of the validation error.
|
|
120
132
|
* @param options - Options for the validation error, including the issues that caused the error.
|
|
121
133
|
*/
|
|
122
|
-
constructor(message: string, {
|
|
123
|
-
issues,
|
|
124
|
-
...options
|
|
125
|
-
}: CommerceSdkValidationErrorOptions);
|
|
134
|
+
constructor(message: string, { issues, ...options }: CommerceSdkValidationErrorOptions);
|
|
126
135
|
/**
|
|
127
136
|
* Returns a pretty string (and colored) representation of the validation error.
|
|
128
137
|
* @param withColor Whether to use color in the output.
|
|
129
138
|
*/
|
|
130
139
|
display(withColor?: boolean): string;
|
|
131
140
|
}
|
|
132
|
-
|
|
133
|
-
export { CommerceSdkErrorBase, type CommerceSdkErrorBaseOptions, type CommerceSdkErrorOptions, CommerceSdkValidationError };
|
|
141
|
+
export type { CommerceSdkErrorBaseOptions, CommerceSdkErrorOptions };
|
package/dist/es/error/index.mjs
CHANGED
|
@@ -12,6 +12,6 @@
|
|
|
12
12
|
* governing permissions and limitations under the License.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import { n as CommerceSdkErrorBase, t as
|
|
15
|
+
import { n as CommerceSdkValidationError, r as CommerceSdkErrorBase, t as stringifyError } from "../error-DHfBWC_D.mjs";
|
|
16
16
|
|
|
17
|
-
export { CommerceSdkErrorBase, CommerceSdkValidationError };
|
|
17
|
+
export { CommerceSdkErrorBase, CommerceSdkValidationError, stringifyError };
|
|
@@ -16,7 +16,7 @@ import { getDotPath } from "valibot";
|
|
|
16
16
|
import util from "util";
|
|
17
17
|
import { cyanBright, dim, whiteBright, yellowBright } from "ansis";
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
// source/error/base-error.ts
|
|
20
20
|
/**
|
|
21
21
|
* Base class for all the errors in the AIO Commerce SDK.
|
|
22
22
|
* @example
|
|
@@ -110,8 +110,7 @@ var CommerceSdkErrorBase = class CommerceSdkErrorBase extends Error {
|
|
|
110
110
|
}
|
|
111
111
|
};
|
|
112
112
|
|
|
113
|
-
|
|
114
|
-
//#region source/error/validation-error.ts
|
|
113
|
+
// source/error/validation-error.ts
|
|
115
114
|
const LAST_RETURN_CHAR = "└── ";
|
|
116
115
|
const RETURN_CHAR = "├── ";
|
|
117
116
|
/** Maps issue kinds to their corresponding error titles for display purposes. */
|
|
@@ -181,5 +180,25 @@ var CommerceSdkValidationError = class extends CommerceSdkErrorBase {
|
|
|
181
180
|
}
|
|
182
181
|
};
|
|
183
182
|
|
|
184
|
-
|
|
185
|
-
|
|
183
|
+
// source/error/stringify-error.ts
|
|
184
|
+
/**
|
|
185
|
+
* Converts any thrown value to a human-friendly string.
|
|
186
|
+
*
|
|
187
|
+
* Validation errors use their formatted `display()` output, other errors use their message, and any other value goes through `String()`.
|
|
188
|
+
*
|
|
189
|
+
* @param error - The thrown value to convert.
|
|
190
|
+
* @example
|
|
191
|
+
* ```typescript
|
|
192
|
+
* try {
|
|
193
|
+
* await doSomething();
|
|
194
|
+
* } catch (error) {
|
|
195
|
+
* console.error(stringifyError(error));
|
|
196
|
+
* }
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
function stringifyError(error) {
|
|
200
|
+
if (error instanceof CommerceSdkValidationError) return error.display();
|
|
201
|
+
return error instanceof Error ? error.message : String(error);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export { CommerceSdkValidationError as n, CommerceSdkErrorBase as r, stringifyError as t };
|
|
@@ -12,10 +12,8 @@
|
|
|
12
12
|
* governing permissions and limitations under the License.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import { r as RuntimeActionParams } from "../index-
|
|
15
|
+
import { r as RuntimeActionParams } from "../index-_sNhjzIe.mjs";
|
|
16
16
|
import { CamelCase } from "type-fest";
|
|
17
|
-
|
|
18
|
-
//#region source/headers/types.d.ts
|
|
19
17
|
/** The type of an HTTP header value. */
|
|
20
18
|
type HttpHeaderValue = string | string[] | undefined;
|
|
21
19
|
/** The type of an HTTP headers record. */
|
|
@@ -35,9 +33,7 @@ type GetHeaderReturn<T extends GetHeaderOptions | undefined> = T extends {
|
|
|
35
33
|
splitCommaSeparated: true;
|
|
36
34
|
} ? HttpHeaderValue : Exclude<HttpHeaderValue, string[]>;
|
|
37
35
|
/** The type of an HTTP header accessor object. */
|
|
38
|
-
type HttpHeaderAccessorMap<T extends string[], O extends GetHeaderOptions | undefined = undefined> = { [K in T[number] as CamelCase<K>]: Exclude<GetHeaderReturn<O>, undefined
|
|
39
|
-
//#endregion
|
|
40
|
-
//#region source/headers/accessor.d.ts
|
|
36
|
+
type HttpHeaderAccessorMap<T extends string[], O extends GetHeaderOptions | undefined = undefined> = { [K in T[number] as CamelCase<K>]: Exclude<GetHeaderReturn<O>, undefined>; };
|
|
41
37
|
/**
|
|
42
38
|
* Creates a type-safe header accessor object with validated required headers.
|
|
43
39
|
* Header names are normalized to camelCase for consistent access.
|
|
@@ -68,9 +64,7 @@ type HttpHeaderAccessorMap<T extends string[], O extends GetHeaderOptions | unde
|
|
|
68
64
|
* // accessor.cacheControl may be string | string[] depending on comma presence
|
|
69
65
|
* ```
|
|
70
66
|
*/
|
|
71
|
-
declare function createHeaderAccessor<const T extends string[], const O extends GetHeaderOptions | undefined = undefined>(headers: HttpHeaders, requiredHeaders: T, options?: O): HttpHeaderAccessorMap<T, O>;
|
|
72
|
-
//#endregion
|
|
73
|
-
//#region source/headers/auth.d.ts
|
|
67
|
+
export declare function createHeaderAccessor<const T extends string[], const O extends GetHeaderOptions | undefined = undefined>(headers: HttpHeaders, requiredHeaders: T, options?: O): HttpHeaderAccessorMap<T, O>;
|
|
74
68
|
/**
|
|
75
69
|
* Represents a Bearer authentication scheme (RFC 6750).
|
|
76
70
|
*/
|
|
@@ -153,15 +147,15 @@ type Authorization = BearerAuthorization | BasicAuthorization | OAuth1Authorizat
|
|
|
153
147
|
/**
|
|
154
148
|
* Type guard to check if authorization is Bearer type.
|
|
155
149
|
*/
|
|
156
|
-
declare function isBearerAuth(auth: Authorization): auth is BearerAuthorization;
|
|
150
|
+
export declare function isBearerAuth(auth: Authorization): auth is BearerAuthorization;
|
|
157
151
|
/**
|
|
158
152
|
* Type guard to check if authorization is Basic type.
|
|
159
153
|
*/
|
|
160
|
-
declare function isBasicAuth(auth: Authorization): auth is BasicAuthorization;
|
|
154
|
+
export declare function isBasicAuth(auth: Authorization): auth is BasicAuthorization;
|
|
161
155
|
/**
|
|
162
156
|
* Type guard to check if authorization is OAuth type.
|
|
163
157
|
*/
|
|
164
|
-
declare function isOAuth(auth: Authorization): auth is OAuth1Authorization;
|
|
158
|
+
export declare function isOAuth(auth: Authorization): auth is OAuth1Authorization;
|
|
165
159
|
/**
|
|
166
160
|
* Parses an Authorization header value into its scheme and parameters.
|
|
167
161
|
*
|
|
@@ -195,7 +189,7 @@ declare function isOAuth(auth: Authorization): auth is OAuth1Authorization;
|
|
|
195
189
|
* // { realm: "Example", nonce: "abc" }
|
|
196
190
|
* ```
|
|
197
191
|
*/
|
|
198
|
-
declare function parseAuthorization(authorization: string): Authorization;
|
|
192
|
+
export declare function parseAuthorization(authorization: string): Authorization;
|
|
199
193
|
/**
|
|
200
194
|
* Parses and validates a Bearer authorization header.
|
|
201
195
|
*
|
|
@@ -217,7 +211,7 @@ declare function parseAuthorization(authorization: string): Authorization;
|
|
|
217
211
|
* }
|
|
218
212
|
* ```
|
|
219
213
|
*/
|
|
220
|
-
declare function parseBearerToken(authorization: string): BearerAuthorization;
|
|
214
|
+
export declare function parseBearerToken(authorization: string): BearerAuthorization;
|
|
221
215
|
/**
|
|
222
216
|
* Parses and validates a Basic authorization header.
|
|
223
217
|
*
|
|
@@ -230,7 +224,7 @@ declare function parseBearerToken(authorization: string): BearerAuthorization;
|
|
|
230
224
|
* console.log(auth.credentials); // "dXNlcjpwYXNz"
|
|
231
225
|
* ```
|
|
232
226
|
*/
|
|
233
|
-
declare function parseBasicToken(authorization: string): BasicAuthorization;
|
|
227
|
+
export declare function parseBasicToken(authorization: string): BasicAuthorization;
|
|
234
228
|
/**
|
|
235
229
|
* Parses and validates an OAuth 1.0 authorization header.
|
|
236
230
|
*
|
|
@@ -244,9 +238,7 @@ declare function parseBasicToken(authorization: string): BasicAuthorization;
|
|
|
244
238
|
* console.log(auth.parameters.oauth_token); // "token"
|
|
245
239
|
* ```
|
|
246
240
|
*/
|
|
247
|
-
declare function parseOAuthToken(authorization: string): OAuth1Authorization;
|
|
248
|
-
//#endregion
|
|
249
|
-
//#region source/headers/helpers.d.ts
|
|
241
|
+
export declare function parseOAuthToken(authorization: string): OAuth1Authorization;
|
|
250
242
|
/**
|
|
251
243
|
* Extracts a header value from an object with case-insensitive lookup.
|
|
252
244
|
* This is useful for handling HTTP headers which can be case-insensitive per RFC 7230.
|
|
@@ -275,7 +267,7 @@ declare function parseOAuthToken(authorization: string): OAuth1Authorization;
|
|
|
275
267
|
* @see https://datatracker.ietf.org/doc/html/rfc7230 - HTTP/1.1 Message Syntax and Routing
|
|
276
268
|
* @see https://datatracker.ietf.org/doc/html/rfc9110#name-field-lines-and-combined-fi - HTTP Semantics: Field Lines and Combined Field Values
|
|
277
269
|
*/
|
|
278
|
-
declare function getHeader<T extends GetHeaderOptions | undefined = undefined>(headers: HttpHeaders, name: string, options?: T): GetHeaderReturn<T>;
|
|
270
|
+
export declare function getHeader<T extends GetHeaderOptions | undefined = undefined>(headers: HttpHeaders, name: string, options?: T): GetHeaderReturn<T>;
|
|
279
271
|
/**
|
|
280
272
|
* Extracts the `__ow_headers` object from App Builder runtime action parameters.
|
|
281
273
|
*
|
|
@@ -290,9 +282,7 @@ declare function getHeader<T extends GetHeaderOptions | undefined = undefined>(h
|
|
|
290
282
|
* }
|
|
291
283
|
* ```
|
|
292
284
|
*/
|
|
293
|
-
declare function getHeadersFromParams(params: RuntimeActionParams): HttpHeaders;
|
|
294
|
-
//#endregion
|
|
295
|
-
//#region source/headers/validation.d.ts
|
|
285
|
+
export declare function getHeadersFromParams(params: RuntimeActionParams): HttpHeaders;
|
|
296
286
|
/**
|
|
297
287
|
* Returns an array of missing or empty headers using Valibot validation.
|
|
298
288
|
* Case-insensitive by default.
|
|
@@ -319,7 +309,7 @@ declare function getHeadersFromParams(params: RuntimeActionParams): HttpHeaders;
|
|
|
319
309
|
* // Returns: ["x-api-key"] (empty string is considered missing)
|
|
320
310
|
* ```
|
|
321
311
|
*/
|
|
322
|
-
declare function getMissingOrEmptyHeaders(headers: HttpHeaders, requiredHeaders: string[]): string[];
|
|
312
|
+
export declare function getMissingOrEmptyHeaders(headers: HttpHeaders, requiredHeaders: string[]): string[];
|
|
323
313
|
/**
|
|
324
314
|
* Validates that required headers are present and non-empty in the headers object.
|
|
325
315
|
* Performs case-insensitive validation with {@link getHeader}.
|
|
@@ -348,6 +338,5 @@ declare function getMissingOrEmptyHeaders(headers: HttpHeaders, requiredHeaders:
|
|
|
348
338
|
* }
|
|
349
339
|
* ```
|
|
350
340
|
*/
|
|
351
|
-
declare function assertRequiredHeaders(headers: HttpHeaders, requiredHeaders: string[]): void;
|
|
352
|
-
|
|
353
|
-
export { type Authorization, type BasicAuthorization, type BearerAuthorization, type GenericAuthorization, type HttpHeaderAccessorMap, type HttpHeaderValue, type HttpHeaders, type OAuth1Authorization, type OAuth1Parameters, assertRequiredHeaders, createHeaderAccessor, getHeader, getHeadersFromParams, getMissingOrEmptyHeaders, isBasicAuth, isBearerAuth, isOAuth, parseAuthorization, parseBasicToken, parseBearerToken, parseOAuthToken };
|
|
341
|
+
export declare function assertRequiredHeaders(headers: HttpHeaders, requiredHeaders: string[]): void;
|
|
342
|
+
export type { Authorization, BasicAuthorization, BearerAuthorization, GenericAuthorization, HttpHeaderAccessorMap, HttpHeaderValue, HttpHeaders, OAuth1Authorization, OAuth1Parameters };
|
|
@@ -12,15 +12,14 @@
|
|
|
12
12
|
* governing permissions and limitations under the License.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import {
|
|
15
|
+
import { n as CommerceSdkValidationError } from "../error-DHfBWC_D.mjs";
|
|
16
16
|
import { literal, nonEmpty, object, pipe, rawCheck, rawTransform, record, safeParse, string, trim, undefined as undefined$1, union } from "valibot";
|
|
17
17
|
import * as camelcaseModule from "camelcase";
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
// source/headers/camelcase.ts
|
|
20
20
|
const camelcase = camelcaseModule.default.default ?? camelcaseModule.default;
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
//#region source/headers/helpers.ts
|
|
22
|
+
// source/headers/helpers.ts
|
|
24
23
|
/**
|
|
25
24
|
* Extracts a header value from an object with case-insensitive lookup.
|
|
26
25
|
* This is useful for handling HTTP headers which can be case-insensitive per RFC 7230.
|
|
@@ -55,7 +54,7 @@ function getHeader(headers, name, options) {
|
|
|
55
54
|
if (Object.hasOwn(headers, name)) value = headers[name];
|
|
56
55
|
else {
|
|
57
56
|
const lowerName = name.toLowerCase();
|
|
58
|
-
for (const key
|
|
57
|
+
for (const key of Object.keys(headers)) if (key.toLowerCase() === lowerName) {
|
|
59
58
|
value = headers[key];
|
|
60
59
|
break;
|
|
61
60
|
}
|
|
@@ -78,13 +77,13 @@ function getHeader(headers, name, options) {
|
|
|
78
77
|
* ```
|
|
79
78
|
*/
|
|
80
79
|
function getHeadersFromParams(params) {
|
|
81
|
-
const
|
|
80
|
+
const schema = object({ __ow_headers: record(string(), union([string(), undefined$1()])) });
|
|
81
|
+
const parsed = safeParse(schema, params);
|
|
82
82
|
if (!parsed.success) throw new CommerceSdkValidationError("Missing __ow_headers in action params", { issues: parsed.issues });
|
|
83
83
|
return parsed.output.__ow_headers;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
//#region source/headers/validation.ts
|
|
86
|
+
// source/headers/validation.ts
|
|
88
87
|
/**
|
|
89
88
|
* Returns an array of missing or empty headers using Valibot validation.
|
|
90
89
|
* Case-insensitive by default.
|
|
@@ -117,7 +116,8 @@ function getMissingOrEmptyHeaders(headers, requiredHeaders) {
|
|
|
117
116
|
const value = headers[key];
|
|
118
117
|
if (value !== void 0 && value !== null) normalized[key.toLowerCase()] = value;
|
|
119
118
|
}
|
|
120
|
-
const
|
|
119
|
+
const schema = buildHeadersSchema(requiredHeaders.map((h) => literal(h)));
|
|
120
|
+
const parsed = safeParse(schema, normalized);
|
|
121
121
|
if (parsed.success) return [];
|
|
122
122
|
const lookup = new Map(requiredHeaders.map((h) => [h.toLowerCase(), h]));
|
|
123
123
|
return parsed.issues.flatMap((issue) => {
|
|
@@ -185,7 +185,8 @@ function assertRequiredHeadersSchema(headers, requiredHeaders) {
|
|
|
185
185
|
const value = headers[key];
|
|
186
186
|
if (value !== void 0 && value !== null) normalized[key.toLowerCase()] = value;
|
|
187
187
|
}
|
|
188
|
-
const
|
|
188
|
+
const schema = buildHeadersSchema(requiredHeaders);
|
|
189
|
+
const parsed = safeParse(schema, normalized);
|
|
189
190
|
if (!parsed.success) throw new CommerceSdkValidationError("The headers object does not match the required headers (case-insensitive)", { issues: parsed.issues });
|
|
190
191
|
}
|
|
191
192
|
/**
|
|
@@ -220,9 +221,8 @@ function assertRequiredHeaders(headers, requiredHeaders) {
|
|
|
220
221
|
assertRequiredHeadersSchema(headers, requiredHeaders.map((header) => literal(header)));
|
|
221
222
|
}
|
|
222
223
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
const LEADING_UNDERSCORES = /^_+/;
|
|
224
|
+
// source/headers/accessor.ts
|
|
225
|
+
const LEADING_UNDERSCORES = /^_+/u;
|
|
226
226
|
/**
|
|
227
227
|
* Converts a header name to a camelCase key aligned with `type-fest`'s `CamelCase` type.
|
|
228
228
|
*
|
|
@@ -278,8 +278,7 @@ function createHeaderAccessor(headers, requiredHeaders, options) {
|
|
|
278
278
|
return accessor;
|
|
279
279
|
}
|
|
280
280
|
|
|
281
|
-
|
|
282
|
-
//#region source/headers/auth.ts
|
|
281
|
+
// source/headers/auth.ts
|
|
283
282
|
/**
|
|
284
283
|
* Type guard to check if authorization is Bearer type.
|
|
285
284
|
*/
|
|
@@ -306,7 +305,7 @@ function isOAuth(auth) {
|
|
|
306
305
|
*/
|
|
307
306
|
function parseKeyValueParameters(parametersString) {
|
|
308
307
|
const params = {};
|
|
309
|
-
const paramPattern = /(
|
|
308
|
+
const paramPattern = /(?<key>\w+)=(?:"(?<quotedValue>[^"]*)"|(?<unquotedValue>[^,\s]+))/gu;
|
|
310
309
|
let match = paramPattern.exec(parametersString);
|
|
311
310
|
while (match !== null) {
|
|
312
311
|
const [, key, quotedValue, unquotedValue] = match;
|
|
@@ -449,5 +448,4 @@ function parseOAuthToken(authorization) {
|
|
|
449
448
|
return auth;
|
|
450
449
|
}
|
|
451
450
|
|
|
452
|
-
//#endregion
|
|
453
451
|
export { assertRequiredHeaders, createHeaderAccessor, getHeader, getHeadersFromParams, getMissingOrEmptyHeaders, isBasicAuth, isBearerAuth, isOAuth, parseAuthorization, parseBasicToken, parseBearerToken, parseOAuthToken };
|
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
* governing permissions and limitations under the License.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
//#region source/params/helpers.d.ts
|
|
16
15
|
/**
|
|
17
16
|
* Checks if the given runtime action input value is non-empty.
|
|
18
17
|
*
|
|
@@ -27,8 +26,6 @@ declare function nonEmpty(name: string, value: unknown): boolean;
|
|
|
27
26
|
* @param required - The list of required parameter names.
|
|
28
27
|
*/
|
|
29
28
|
declare function allNonEmpty<const T extends string[]>(params: Record<string, unknown>, required: T): params is Record<string, unknown> & Record<T[number], unknown>;
|
|
30
|
-
//#endregion
|
|
31
|
-
//#region source/params/types.d.ts
|
|
32
29
|
/**
|
|
33
30
|
* Standard HTTP methods supported by Adobe I/O Runtime.
|
|
34
31
|
* These are the methods that can be used when invoking runtime actions via HTTP.
|
|
@@ -41,12 +38,16 @@ type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTION
|
|
|
41
38
|
type HttpMethodLowercase = Lowercase<HttpMethod>;
|
|
42
39
|
/** The type of the runtime action parameters. */
|
|
43
40
|
type RuntimeActionParams = {
|
|
44
|
-
/** If the runtime action is invoked via HTTP, this will be the headers of the request. */
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
/** If the runtime action is invoked via HTTP, this will be the headers of the request. */
|
|
42
|
+
__ow_headers?: Record<string, string | undefined>;
|
|
43
|
+
/** If the runtime action is invoked via HTTP, this will be the HTTP method of the request. */
|
|
44
|
+
__ow_method?: HttpMethodLowercase;
|
|
45
|
+
/** If the runtime action is invoked via HTTP, this will be the unmatched path of the request (matching stops after consuming the action extension) */
|
|
46
|
+
__ow_path?: string;
|
|
47
|
+
/** 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 */
|
|
48
|
+
__ow_body?: string;
|
|
49
|
+
/** If the runtime action is invoked via HTTP, this will be the query parameters of the request, as an unparsed string. */
|
|
48
50
|
__ow_query?: string;
|
|
49
51
|
[key: string]: unknown;
|
|
50
52
|
};
|
|
51
|
-
//#endregion
|
|
52
53
|
export { nonEmpty as a, allNonEmpty as i, HttpMethodLowercase as n, RuntimeActionParams as r, HttpMethod as t };
|
|
@@ -12,5 +12,5 @@
|
|
|
12
12
|
* governing permissions and limitations under the License.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import { a as nonEmpty, i as allNonEmpty, n as HttpMethodLowercase, r as RuntimeActionParams, t as HttpMethod } from "../index-
|
|
15
|
+
import { a as nonEmpty, i as allNonEmpty, n as HttpMethodLowercase, r as RuntimeActionParams, t as HttpMethod } from "../index-_sNhjzIe.mjs";
|
|
16
16
|
export { HttpMethod, HttpMethodLowercase, RuntimeActionParams, allNonEmpty, nonEmpty };
|