@01.software/sdk 0.46.1 → 0.49.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 +96 -1
- package/README.md +145 -14
- package/dist/client.cjs +485 -81
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +7 -6
- package/dist/client.d.ts +7 -6
- package/dist/client.js +485 -81
- package/dist/client.js.map +1 -1
- package/dist/{collection-client-BEGXnfQe.d.ts → collection-client-DnDt6EQz.d.ts} +4 -4
- package/dist/{collection-client-L2rEgBaR.d.cts → collection-client-XfGLPuTf.d.cts} +4 -4
- package/dist/{const-y0eipvnQ.d.cts → const-CBba4lDo.d.cts} +4 -4
- package/dist/{const-GYVwlXLr.d.ts → const-DCNV5Kq7.d.ts} +4 -4
- package/dist/errors.cjs +112 -16
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts +13 -4
- package/dist/errors.d.ts +13 -4
- package/dist/errors.js +112 -16
- package/dist/errors.js.map +1 -1
- package/dist/{index-BfYL6Qb1.d.cts → index-CbKyoEzy.d.cts} +3 -3
- package/dist/{index-Bei4WlVw.d.ts → index-DUuIqUS8.d.ts} +3 -3
- package/dist/index.cjs +452 -104
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +452 -104
- package/dist/index.js.map +1 -1
- package/dist/{payload-types-3WNyC0gk.d.cts → payload-types-MKbx5MuJ.d.cts} +309 -17
- package/dist/{payload-types-3WNyC0gk.d.ts → payload-types-MKbx5MuJ.d.ts} +309 -17
- package/dist/query.cjs +165 -43
- package/dist/query.cjs.map +1 -1
- package/dist/query.d.cts +5 -5
- package/dist/query.d.ts +5 -5
- package/dist/query.js +165 -43
- package/dist/query.js.map +1 -1
- package/dist/realtime.d.cts +2 -2
- package/dist/realtime.d.ts +2 -2
- package/dist/server.cjs +566 -81
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +8 -7
- package/dist/server.d.ts +8 -7
- package/dist/server.js +566 -81
- package/dist/server.js.map +1 -1
- package/dist/storefront-cache.cjs +70 -1
- package/dist/storefront-cache.cjs.map +1 -1
- package/dist/storefront-cache.js +70 -1
- package/dist/storefront-cache.js.map +1 -1
- package/dist/{types-mIROvhhP.d.ts → types-1UeOk1Uy.d.cts} +110 -8
- package/dist/{types-CAicTn-o.d.cts → types-BKr_2avj.d.cts} +2 -2
- package/dist/{types-CDJ2M-MJ.d.cts → types-Du4s5anw.d.ts} +110 -8
- package/dist/{types-DpSyNTxy.d.ts → types-L_nh-ED7.d.ts} +2 -2
- package/dist/ui/form.d.cts +1 -1
- package/dist/ui/form.d.ts +1 -1
- package/dist/ui/video.d.cts +1 -1
- package/dist/ui/video.d.ts +1 -1
- package/dist/webhook.d.cts +4 -4
- package/dist/webhook.d.ts +4 -4
- package/package.json +6 -5
package/dist/errors.d.cts
CHANGED
|
@@ -8,6 +8,8 @@ declare class SDKError extends Error {
|
|
|
8
8
|
readonly kind?: 'commerce';
|
|
9
9
|
readonly reason?: CommerceErrorCode | 'unknown_commerce_error';
|
|
10
10
|
readonly rawReason?: string;
|
|
11
|
+
/** Machine-readable reason from a non-commerce API response. */
|
|
12
|
+
readonly apiReason?: string;
|
|
11
13
|
readonly retryable?: boolean;
|
|
12
14
|
readonly retryAfter?: number;
|
|
13
15
|
constructor(code: string, message: string, status?: number, details?: unknown, userMessage?: string, suggestion?: string, requestId?: string);
|
|
@@ -15,8 +17,9 @@ declare class SDKError extends Error {
|
|
|
15
17
|
toJSON(): {
|
|
16
18
|
retryAfter?: number | undefined;
|
|
17
19
|
retryable?: boolean | undefined;
|
|
20
|
+
apiReason?: string | undefined;
|
|
18
21
|
rawReason?: string | undefined;
|
|
19
|
-
reason?: "currency_mismatch" | "validation_failed" | "unauthorized" | "forbidden" | "token_expired" | "origin_not_allowed" | "server_credentials_required" | "not_found" | "conflict" | "cart_revision_conflict" | "rate_limit_exceeded" | "usage_limit_exceeded" | "service_unavailable" | "idempotency_conflict" | "idempotency_in_progress" | "cart_not_active" | "cart_locked" | "cart_empty" | "cart_market_unavailable" | "cart_market_mismatch" | "checkout_not_open" | "payment_slot_held" | "reservation_expired" | "payment_session_not_cancelable" | "provider_identity_mismatch" | "provider_unavailable" | "lock_timeout" | "price_changed" | "pricing_fact_in_use" | "insufficient_stock" | "market_not_found" | "market_shipping_currency_unsupported" | "missing_market_rate" | "missing_shipping_amount" | "no_enabled_payment_provider" | "product_market_unavailable" | "unsupported_currency" | "missing_price_row" | "payment_provider_currency_unsupported" | "discount_code_not_found" | "discount_not_started" | "discount_expired" | "discount_usage_limit" | "discount_per_customer_limit" | "discount_customer_required" | "discount_first_order_only" | "discount_customer_not_eligible" | "discount_customer_excluded" | "discount_items_required" | "discount_product_not_eligible" | "discount_product_excluded" | "discount_min_order_amount" | "discount_currency_scope_required" | "discount_allocation_method_unsupported" | "unknown_commerce_error" | undefined;
|
|
22
|
+
reason?: "currency_mismatch" | "validation_failed" | "bad_request" | "unauthorized" | "forbidden" | "account_suspended" | "key_invalid" | "pat_tenant_header_forbidden" | "tenant_mismatch" | "test_tenant_expired" | "token_invalid" | "token_expired" | "origin_not_allowed" | "server_credentials_required" | "role_denied" | "scope_denied" | "feature_disabled" | "not_found" | "conflict" | "locked" | "cart_revision_conflict" | "rate_limit_exceeded" | "usage_limit_exceeded" | "service_unavailable" | "idempotency_conflict" | "idempotency_in_progress" | "idempotency_key_required" | "invalid_idempotency_key" | "cart_not_active" | "cart_locked" | "cart_empty" | "cart_market_unavailable" | "cart_market_mismatch" | "checkout_not_open" | "checkout_already_open" | "payment_slot_held" | "reservation_expired" | "payment_session_not_cancelable" | "payment_session_conflict" | "provider_identity_mismatch" | "payment_method_unavailable" | "provider_unavailable" | "lock_timeout" | "price_changed" | "pricing_fact_in_use" | "insufficient_stock" | "reservation_conflict" | "stock_lock_unavailable" | "variant_not_found" | "variant_stock_write_failed" | "stock_invariant_violation" | "payment_confirmation_in_flight" | "checkout_reservation_release_requires_transaction" | "admission_metadata_invalid" | "admission_metadata_required" | "capacity_exceeded" | "occurrence_lock_unavailable" | "occurrence_not_open" | "admission_type_capacity_exceeded" | "admission_type_occurrence_mismatch" | "admission_hold_expired" | "admission_hold_checkout_item_conflict" | "admission_hold_checkout_conflict" | "admission_hold_quantity_mismatch" | "admission_hold_unbound" | "admission_hold_missing" | "admission_hold_checkout_item_missing" | "admission_hold_expiry_failed" | "admission_hold_expiry_requires_transaction" | "admission_hold_line_item_mismatch" | "admission_materialization_failed" | "variant_inactive" | "variant_product_mismatch" | "product_not_public" | "market_not_found" | "market_shipping_currency_unsupported" | "missing_market_rate" | "missing_shipping_amount" | "no_enabled_payment_provider" | "product_market_unavailable" | "unsupported_currency" | "missing_price_row" | "payment_provider_currency_unsupported" | "discount_code_not_found" | "discount_not_started" | "discount_expired" | "discount_usage_limit" | "discount_per_customer_limit" | "discount_customer_required" | "discount_first_order_only" | "discount_customer_not_eligible" | "discount_customer_excluded" | "discount_items_required" | "discount_product_not_eligible" | "discount_product_excluded" | "discount_min_order_amount" | "discount_currency_scope_required" | "discount_allocation_method_unsupported" | "customer_token_required" | "market_required" | "server_derived" | "internal_error" | "unknown_commerce_error" | undefined;
|
|
20
23
|
kind?: "commerce" | undefined;
|
|
21
24
|
requestId?: string | undefined;
|
|
22
25
|
name: string;
|
|
@@ -33,7 +36,7 @@ declare class SDKError extends Error {
|
|
|
33
36
|
* intentionally does not import the private contracts package; parity is
|
|
34
37
|
* enforced by a type test.
|
|
35
38
|
*/
|
|
36
|
-
declare const COMMERCE_ERROR_CODES: readonly ["validation_failed", "unauthorized", "forbidden", "token_expired", "origin_not_allowed", "server_credentials_required", "not_found", "conflict", "cart_revision_conflict", "rate_limit_exceeded", "usage_limit_exceeded", "service_unavailable", "idempotency_conflict", "idempotency_in_progress", "cart_not_active", "cart_locked", "cart_empty", "cart_market_unavailable", "cart_market_mismatch", "checkout_not_open", "payment_slot_held", "reservation_expired", "payment_session_not_cancelable", "provider_identity_mismatch", "provider_unavailable", "lock_timeout", "price_changed", "pricing_fact_in_use", "insufficient_stock", "market_not_found", "market_shipping_currency_unsupported", "missing_market_rate", "missing_shipping_amount", "no_enabled_payment_provider", "product_market_unavailable", "unsupported_currency", "missing_price_row", "payment_provider_currency_unsupported", "discount_code_not_found", "discount_not_started", "discount_expired", "discount_usage_limit", "discount_per_customer_limit", "discount_customer_required", "discount_first_order_only", "discount_customer_not_eligible", "discount_customer_excluded", "discount_items_required", "discount_product_not_eligible", "discount_product_excluded", "discount_min_order_amount", "discount_currency_scope_required", "discount_allocation_method_unsupported", "currency_mismatch"];
|
|
39
|
+
declare const COMMERCE_ERROR_CODES: readonly ["validation_failed", "bad_request", "unauthorized", "forbidden", "account_suspended", "key_invalid", "pat_tenant_header_forbidden", "tenant_mismatch", "test_tenant_expired", "token_invalid", "token_expired", "origin_not_allowed", "server_credentials_required", "role_denied", "scope_denied", "feature_disabled", "not_found", "conflict", "locked", "cart_revision_conflict", "rate_limit_exceeded", "usage_limit_exceeded", "service_unavailable", "idempotency_conflict", "idempotency_in_progress", "idempotency_key_required", "invalid_idempotency_key", "cart_not_active", "cart_locked", "cart_empty", "cart_market_unavailable", "cart_market_mismatch", "checkout_not_open", "checkout_already_open", "payment_slot_held", "reservation_expired", "payment_session_not_cancelable", "payment_session_conflict", "provider_identity_mismatch", "payment_method_unavailable", "provider_unavailable", "lock_timeout", "price_changed", "pricing_fact_in_use", "insufficient_stock", "reservation_conflict", "stock_lock_unavailable", "variant_not_found", "variant_stock_write_failed", "stock_invariant_violation", "payment_confirmation_in_flight", "checkout_reservation_release_requires_transaction", "admission_metadata_invalid", "admission_metadata_required", "capacity_exceeded", "occurrence_lock_unavailable", "occurrence_not_open", "admission_type_capacity_exceeded", "admission_type_occurrence_mismatch", "admission_hold_expired", "admission_hold_checkout_item_conflict", "admission_hold_checkout_conflict", "admission_hold_quantity_mismatch", "admission_hold_unbound", "admission_hold_missing", "admission_hold_checkout_item_missing", "admission_hold_expiry_failed", "admission_hold_expiry_requires_transaction", "admission_hold_line_item_mismatch", "admission_materialization_failed", "variant_inactive", "variant_product_mismatch", "product_not_public", "market_not_found", "market_shipping_currency_unsupported", "missing_market_rate", "missing_shipping_amount", "no_enabled_payment_provider", "product_market_unavailable", "unsupported_currency", "missing_price_row", "payment_provider_currency_unsupported", "discount_code_not_found", "discount_not_started", "discount_expired", "discount_usage_limit", "discount_per_customer_limit", "discount_customer_required", "discount_first_order_only", "discount_customer_not_eligible", "discount_customer_excluded", "discount_items_required", "discount_product_not_eligible", "discount_product_excluded", "discount_min_order_amount", "discount_currency_scope_required", "discount_allocation_method_unsupported", "currency_mismatch", "customer_token_required", "market_required", "server_derived", "internal_error"];
|
|
37
40
|
type CommerceErrorCode = (typeof COMMERCE_ERROR_CODES)[number];
|
|
38
41
|
type CommerceSDKErrorBase = SDKError & {
|
|
39
42
|
readonly kind: 'commerce';
|
|
@@ -49,6 +52,11 @@ type CommerceSDKError = CommerceSDKErrorBase & ({
|
|
|
49
52
|
readonly reason: 'unknown_commerce_error';
|
|
50
53
|
readonly rawReason: string;
|
|
51
54
|
});
|
|
55
|
+
/**
|
|
56
|
+
* Read the server-provided machine reason across strict commerce and
|
|
57
|
+
* non-commerce SDK errors. Unknown commerce reasons are returned verbatim.
|
|
58
|
+
*/
|
|
59
|
+
declare function getSDKErrorReason(error: SDKError): string | undefined;
|
|
52
60
|
declare function isCommerceSDKError(error: unknown): error is CommerceSDKError;
|
|
53
61
|
declare class NetworkError extends SDKError {
|
|
54
62
|
constructor(message: string, status?: number, details?: unknown, userMessage?: string, suggestion?: string);
|
|
@@ -91,8 +99,9 @@ declare class UsageLimitError extends SDKError {
|
|
|
91
99
|
};
|
|
92
100
|
retryAfter?: number | undefined;
|
|
93
101
|
retryable?: boolean | undefined;
|
|
102
|
+
apiReason?: string | undefined;
|
|
94
103
|
rawReason?: string | undefined;
|
|
95
|
-
reason?: "currency_mismatch" | "validation_failed" | "unauthorized" | "forbidden" | "token_expired" | "origin_not_allowed" | "server_credentials_required" | "not_found" | "conflict" | "cart_revision_conflict" | "rate_limit_exceeded" | "usage_limit_exceeded" | "service_unavailable" | "idempotency_conflict" | "idempotency_in_progress" | "cart_not_active" | "cart_locked" | "cart_empty" | "cart_market_unavailable" | "cart_market_mismatch" | "checkout_not_open" | "payment_slot_held" | "reservation_expired" | "payment_session_not_cancelable" | "provider_identity_mismatch" | "provider_unavailable" | "lock_timeout" | "price_changed" | "pricing_fact_in_use" | "insufficient_stock" | "market_not_found" | "market_shipping_currency_unsupported" | "missing_market_rate" | "missing_shipping_amount" | "no_enabled_payment_provider" | "product_market_unavailable" | "unsupported_currency" | "missing_price_row" | "payment_provider_currency_unsupported" | "discount_code_not_found" | "discount_not_started" | "discount_expired" | "discount_usage_limit" | "discount_per_customer_limit" | "discount_customer_required" | "discount_first_order_only" | "discount_customer_not_eligible" | "discount_customer_excluded" | "discount_items_required" | "discount_product_not_eligible" | "discount_product_excluded" | "discount_min_order_amount" | "discount_currency_scope_required" | "discount_allocation_method_unsupported" | "unknown_commerce_error" | undefined;
|
|
104
|
+
reason?: "currency_mismatch" | "validation_failed" | "bad_request" | "unauthorized" | "forbidden" | "account_suspended" | "key_invalid" | "pat_tenant_header_forbidden" | "tenant_mismatch" | "test_tenant_expired" | "token_invalid" | "token_expired" | "origin_not_allowed" | "server_credentials_required" | "role_denied" | "scope_denied" | "feature_disabled" | "not_found" | "conflict" | "locked" | "cart_revision_conflict" | "rate_limit_exceeded" | "usage_limit_exceeded" | "service_unavailable" | "idempotency_conflict" | "idempotency_in_progress" | "idempotency_key_required" | "invalid_idempotency_key" | "cart_not_active" | "cart_locked" | "cart_empty" | "cart_market_unavailable" | "cart_market_mismatch" | "checkout_not_open" | "checkout_already_open" | "payment_slot_held" | "reservation_expired" | "payment_session_not_cancelable" | "payment_session_conflict" | "provider_identity_mismatch" | "payment_method_unavailable" | "provider_unavailable" | "lock_timeout" | "price_changed" | "pricing_fact_in_use" | "insufficient_stock" | "reservation_conflict" | "stock_lock_unavailable" | "variant_not_found" | "variant_stock_write_failed" | "stock_invariant_violation" | "payment_confirmation_in_flight" | "checkout_reservation_release_requires_transaction" | "admission_metadata_invalid" | "admission_metadata_required" | "capacity_exceeded" | "occurrence_lock_unavailable" | "occurrence_not_open" | "admission_type_capacity_exceeded" | "admission_type_occurrence_mismatch" | "admission_hold_expired" | "admission_hold_checkout_item_conflict" | "admission_hold_checkout_conflict" | "admission_hold_quantity_mismatch" | "admission_hold_unbound" | "admission_hold_missing" | "admission_hold_checkout_item_missing" | "admission_hold_expiry_failed" | "admission_hold_expiry_requires_transaction" | "admission_hold_line_item_mismatch" | "admission_materialization_failed" | "variant_inactive" | "variant_product_mismatch" | "product_not_public" | "market_not_found" | "market_shipping_currency_unsupported" | "missing_market_rate" | "missing_shipping_amount" | "no_enabled_payment_provider" | "product_market_unavailable" | "unsupported_currency" | "missing_price_row" | "payment_provider_currency_unsupported" | "discount_code_not_found" | "discount_not_started" | "discount_expired" | "discount_usage_limit" | "discount_per_customer_limit" | "discount_customer_required" | "discount_first_order_only" | "discount_customer_not_eligible" | "discount_customer_excluded" | "discount_items_required" | "discount_product_not_eligible" | "discount_product_excluded" | "discount_min_order_amount" | "discount_currency_scope_required" | "discount_allocation_method_unsupported" | "customer_token_required" | "market_required" | "server_derived" | "internal_error" | "unknown_commerce_error" | undefined;
|
|
96
105
|
kind?: "commerce" | undefined;
|
|
97
106
|
requestId?: string | undefined;
|
|
98
107
|
name: string;
|
|
@@ -152,4 +161,4 @@ declare const createNotFoundError: (message: string, details?: unknown, userMess
|
|
|
152
161
|
declare const createConflictError: (message: string, details?: unknown, userMessage?: string, suggestion?: string, requestId?: string) => ConflictError;
|
|
153
162
|
declare const createRateLimitError: (message: string, retryAfter?: number, details?: unknown, userMessage?: string, suggestion?: string, requestId?: string) => RateLimitError;
|
|
154
163
|
|
|
155
|
-
export { ApiError, AuthError, COMMERCE_ERROR_CODES, type CommerceErrorCode, type CommerceSDKError, ConfigError, ConflictError, GoneError, NetworkError, NotFoundError, PermissionError, RateLimitError, SDKError, ServiceUnavailableError, TimeoutError, UsageLimitError, ValidationError, createApiError, createAuthError, createConfigError, createConflictError, createGoneError, createNetworkError, createNotFoundError, createPermissionError, createRateLimitError, createServiceUnavailableError, createTimeoutError, createUsageLimitError, createValidationError, isApiError, isAuthError, isCommerceSDKError, isConfigError, isConflictError, isGoneError, isNetworkError, isNotFoundError, isPermissionError, isRateLimitError, isSDKError, isServiceUnavailableError, isTimeoutError, isUsageLimitError, isValidationError };
|
|
164
|
+
export { ApiError, AuthError, COMMERCE_ERROR_CODES, type CommerceErrorCode, type CommerceSDKError, ConfigError, ConflictError, GoneError, NetworkError, NotFoundError, PermissionError, RateLimitError, SDKError, ServiceUnavailableError, TimeoutError, UsageLimitError, ValidationError, createApiError, createAuthError, createConfigError, createConflictError, createGoneError, createNetworkError, createNotFoundError, createPermissionError, createRateLimitError, createServiceUnavailableError, createTimeoutError, createUsageLimitError, createValidationError, getSDKErrorReason, isApiError, isAuthError, isCommerceSDKError, isConfigError, isConflictError, isGoneError, isNetworkError, isNotFoundError, isPermissionError, isRateLimitError, isSDKError, isServiceUnavailableError, isTimeoutError, isUsageLimitError, isValidationError };
|
package/dist/errors.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ declare class SDKError extends Error {
|
|
|
8
8
|
readonly kind?: 'commerce';
|
|
9
9
|
readonly reason?: CommerceErrorCode | 'unknown_commerce_error';
|
|
10
10
|
readonly rawReason?: string;
|
|
11
|
+
/** Machine-readable reason from a non-commerce API response. */
|
|
12
|
+
readonly apiReason?: string;
|
|
11
13
|
readonly retryable?: boolean;
|
|
12
14
|
readonly retryAfter?: number;
|
|
13
15
|
constructor(code: string, message: string, status?: number, details?: unknown, userMessage?: string, suggestion?: string, requestId?: string);
|
|
@@ -15,8 +17,9 @@ declare class SDKError extends Error {
|
|
|
15
17
|
toJSON(): {
|
|
16
18
|
retryAfter?: number | undefined;
|
|
17
19
|
retryable?: boolean | undefined;
|
|
20
|
+
apiReason?: string | undefined;
|
|
18
21
|
rawReason?: string | undefined;
|
|
19
|
-
reason?: "currency_mismatch" | "validation_failed" | "unauthorized" | "forbidden" | "token_expired" | "origin_not_allowed" | "server_credentials_required" | "not_found" | "conflict" | "cart_revision_conflict" | "rate_limit_exceeded" | "usage_limit_exceeded" | "service_unavailable" | "idempotency_conflict" | "idempotency_in_progress" | "cart_not_active" | "cart_locked" | "cart_empty" | "cart_market_unavailable" | "cart_market_mismatch" | "checkout_not_open" | "payment_slot_held" | "reservation_expired" | "payment_session_not_cancelable" | "provider_identity_mismatch" | "provider_unavailable" | "lock_timeout" | "price_changed" | "pricing_fact_in_use" | "insufficient_stock" | "market_not_found" | "market_shipping_currency_unsupported" | "missing_market_rate" | "missing_shipping_amount" | "no_enabled_payment_provider" | "product_market_unavailable" | "unsupported_currency" | "missing_price_row" | "payment_provider_currency_unsupported" | "discount_code_not_found" | "discount_not_started" | "discount_expired" | "discount_usage_limit" | "discount_per_customer_limit" | "discount_customer_required" | "discount_first_order_only" | "discount_customer_not_eligible" | "discount_customer_excluded" | "discount_items_required" | "discount_product_not_eligible" | "discount_product_excluded" | "discount_min_order_amount" | "discount_currency_scope_required" | "discount_allocation_method_unsupported" | "unknown_commerce_error" | undefined;
|
|
22
|
+
reason?: "currency_mismatch" | "validation_failed" | "bad_request" | "unauthorized" | "forbidden" | "account_suspended" | "key_invalid" | "pat_tenant_header_forbidden" | "tenant_mismatch" | "test_tenant_expired" | "token_invalid" | "token_expired" | "origin_not_allowed" | "server_credentials_required" | "role_denied" | "scope_denied" | "feature_disabled" | "not_found" | "conflict" | "locked" | "cart_revision_conflict" | "rate_limit_exceeded" | "usage_limit_exceeded" | "service_unavailable" | "idempotency_conflict" | "idempotency_in_progress" | "idempotency_key_required" | "invalid_idempotency_key" | "cart_not_active" | "cart_locked" | "cart_empty" | "cart_market_unavailable" | "cart_market_mismatch" | "checkout_not_open" | "checkout_already_open" | "payment_slot_held" | "reservation_expired" | "payment_session_not_cancelable" | "payment_session_conflict" | "provider_identity_mismatch" | "payment_method_unavailable" | "provider_unavailable" | "lock_timeout" | "price_changed" | "pricing_fact_in_use" | "insufficient_stock" | "reservation_conflict" | "stock_lock_unavailable" | "variant_not_found" | "variant_stock_write_failed" | "stock_invariant_violation" | "payment_confirmation_in_flight" | "checkout_reservation_release_requires_transaction" | "admission_metadata_invalid" | "admission_metadata_required" | "capacity_exceeded" | "occurrence_lock_unavailable" | "occurrence_not_open" | "admission_type_capacity_exceeded" | "admission_type_occurrence_mismatch" | "admission_hold_expired" | "admission_hold_checkout_item_conflict" | "admission_hold_checkout_conflict" | "admission_hold_quantity_mismatch" | "admission_hold_unbound" | "admission_hold_missing" | "admission_hold_checkout_item_missing" | "admission_hold_expiry_failed" | "admission_hold_expiry_requires_transaction" | "admission_hold_line_item_mismatch" | "admission_materialization_failed" | "variant_inactive" | "variant_product_mismatch" | "product_not_public" | "market_not_found" | "market_shipping_currency_unsupported" | "missing_market_rate" | "missing_shipping_amount" | "no_enabled_payment_provider" | "product_market_unavailable" | "unsupported_currency" | "missing_price_row" | "payment_provider_currency_unsupported" | "discount_code_not_found" | "discount_not_started" | "discount_expired" | "discount_usage_limit" | "discount_per_customer_limit" | "discount_customer_required" | "discount_first_order_only" | "discount_customer_not_eligible" | "discount_customer_excluded" | "discount_items_required" | "discount_product_not_eligible" | "discount_product_excluded" | "discount_min_order_amount" | "discount_currency_scope_required" | "discount_allocation_method_unsupported" | "customer_token_required" | "market_required" | "server_derived" | "internal_error" | "unknown_commerce_error" | undefined;
|
|
20
23
|
kind?: "commerce" | undefined;
|
|
21
24
|
requestId?: string | undefined;
|
|
22
25
|
name: string;
|
|
@@ -33,7 +36,7 @@ declare class SDKError extends Error {
|
|
|
33
36
|
* intentionally does not import the private contracts package; parity is
|
|
34
37
|
* enforced by a type test.
|
|
35
38
|
*/
|
|
36
|
-
declare const COMMERCE_ERROR_CODES: readonly ["validation_failed", "unauthorized", "forbidden", "token_expired", "origin_not_allowed", "server_credentials_required", "not_found", "conflict", "cart_revision_conflict", "rate_limit_exceeded", "usage_limit_exceeded", "service_unavailable", "idempotency_conflict", "idempotency_in_progress", "cart_not_active", "cart_locked", "cart_empty", "cart_market_unavailable", "cart_market_mismatch", "checkout_not_open", "payment_slot_held", "reservation_expired", "payment_session_not_cancelable", "provider_identity_mismatch", "provider_unavailable", "lock_timeout", "price_changed", "pricing_fact_in_use", "insufficient_stock", "market_not_found", "market_shipping_currency_unsupported", "missing_market_rate", "missing_shipping_amount", "no_enabled_payment_provider", "product_market_unavailable", "unsupported_currency", "missing_price_row", "payment_provider_currency_unsupported", "discount_code_not_found", "discount_not_started", "discount_expired", "discount_usage_limit", "discount_per_customer_limit", "discount_customer_required", "discount_first_order_only", "discount_customer_not_eligible", "discount_customer_excluded", "discount_items_required", "discount_product_not_eligible", "discount_product_excluded", "discount_min_order_amount", "discount_currency_scope_required", "discount_allocation_method_unsupported", "currency_mismatch"];
|
|
39
|
+
declare const COMMERCE_ERROR_CODES: readonly ["validation_failed", "bad_request", "unauthorized", "forbidden", "account_suspended", "key_invalid", "pat_tenant_header_forbidden", "tenant_mismatch", "test_tenant_expired", "token_invalid", "token_expired", "origin_not_allowed", "server_credentials_required", "role_denied", "scope_denied", "feature_disabled", "not_found", "conflict", "locked", "cart_revision_conflict", "rate_limit_exceeded", "usage_limit_exceeded", "service_unavailable", "idempotency_conflict", "idempotency_in_progress", "idempotency_key_required", "invalid_idempotency_key", "cart_not_active", "cart_locked", "cart_empty", "cart_market_unavailable", "cart_market_mismatch", "checkout_not_open", "checkout_already_open", "payment_slot_held", "reservation_expired", "payment_session_not_cancelable", "payment_session_conflict", "provider_identity_mismatch", "payment_method_unavailable", "provider_unavailable", "lock_timeout", "price_changed", "pricing_fact_in_use", "insufficient_stock", "reservation_conflict", "stock_lock_unavailable", "variant_not_found", "variant_stock_write_failed", "stock_invariant_violation", "payment_confirmation_in_flight", "checkout_reservation_release_requires_transaction", "admission_metadata_invalid", "admission_metadata_required", "capacity_exceeded", "occurrence_lock_unavailable", "occurrence_not_open", "admission_type_capacity_exceeded", "admission_type_occurrence_mismatch", "admission_hold_expired", "admission_hold_checkout_item_conflict", "admission_hold_checkout_conflict", "admission_hold_quantity_mismatch", "admission_hold_unbound", "admission_hold_missing", "admission_hold_checkout_item_missing", "admission_hold_expiry_failed", "admission_hold_expiry_requires_transaction", "admission_hold_line_item_mismatch", "admission_materialization_failed", "variant_inactive", "variant_product_mismatch", "product_not_public", "market_not_found", "market_shipping_currency_unsupported", "missing_market_rate", "missing_shipping_amount", "no_enabled_payment_provider", "product_market_unavailable", "unsupported_currency", "missing_price_row", "payment_provider_currency_unsupported", "discount_code_not_found", "discount_not_started", "discount_expired", "discount_usage_limit", "discount_per_customer_limit", "discount_customer_required", "discount_first_order_only", "discount_customer_not_eligible", "discount_customer_excluded", "discount_items_required", "discount_product_not_eligible", "discount_product_excluded", "discount_min_order_amount", "discount_currency_scope_required", "discount_allocation_method_unsupported", "currency_mismatch", "customer_token_required", "market_required", "server_derived", "internal_error"];
|
|
37
40
|
type CommerceErrorCode = (typeof COMMERCE_ERROR_CODES)[number];
|
|
38
41
|
type CommerceSDKErrorBase = SDKError & {
|
|
39
42
|
readonly kind: 'commerce';
|
|
@@ -49,6 +52,11 @@ type CommerceSDKError = CommerceSDKErrorBase & ({
|
|
|
49
52
|
readonly reason: 'unknown_commerce_error';
|
|
50
53
|
readonly rawReason: string;
|
|
51
54
|
});
|
|
55
|
+
/**
|
|
56
|
+
* Read the server-provided machine reason across strict commerce and
|
|
57
|
+
* non-commerce SDK errors. Unknown commerce reasons are returned verbatim.
|
|
58
|
+
*/
|
|
59
|
+
declare function getSDKErrorReason(error: SDKError): string | undefined;
|
|
52
60
|
declare function isCommerceSDKError(error: unknown): error is CommerceSDKError;
|
|
53
61
|
declare class NetworkError extends SDKError {
|
|
54
62
|
constructor(message: string, status?: number, details?: unknown, userMessage?: string, suggestion?: string);
|
|
@@ -91,8 +99,9 @@ declare class UsageLimitError extends SDKError {
|
|
|
91
99
|
};
|
|
92
100
|
retryAfter?: number | undefined;
|
|
93
101
|
retryable?: boolean | undefined;
|
|
102
|
+
apiReason?: string | undefined;
|
|
94
103
|
rawReason?: string | undefined;
|
|
95
|
-
reason?: "currency_mismatch" | "validation_failed" | "unauthorized" | "forbidden" | "token_expired" | "origin_not_allowed" | "server_credentials_required" | "not_found" | "conflict" | "cart_revision_conflict" | "rate_limit_exceeded" | "usage_limit_exceeded" | "service_unavailable" | "idempotency_conflict" | "idempotency_in_progress" | "cart_not_active" | "cart_locked" | "cart_empty" | "cart_market_unavailable" | "cart_market_mismatch" | "checkout_not_open" | "payment_slot_held" | "reservation_expired" | "payment_session_not_cancelable" | "provider_identity_mismatch" | "provider_unavailable" | "lock_timeout" | "price_changed" | "pricing_fact_in_use" | "insufficient_stock" | "market_not_found" | "market_shipping_currency_unsupported" | "missing_market_rate" | "missing_shipping_amount" | "no_enabled_payment_provider" | "product_market_unavailable" | "unsupported_currency" | "missing_price_row" | "payment_provider_currency_unsupported" | "discount_code_not_found" | "discount_not_started" | "discount_expired" | "discount_usage_limit" | "discount_per_customer_limit" | "discount_customer_required" | "discount_first_order_only" | "discount_customer_not_eligible" | "discount_customer_excluded" | "discount_items_required" | "discount_product_not_eligible" | "discount_product_excluded" | "discount_min_order_amount" | "discount_currency_scope_required" | "discount_allocation_method_unsupported" | "unknown_commerce_error" | undefined;
|
|
104
|
+
reason?: "currency_mismatch" | "validation_failed" | "bad_request" | "unauthorized" | "forbidden" | "account_suspended" | "key_invalid" | "pat_tenant_header_forbidden" | "tenant_mismatch" | "test_tenant_expired" | "token_invalid" | "token_expired" | "origin_not_allowed" | "server_credentials_required" | "role_denied" | "scope_denied" | "feature_disabled" | "not_found" | "conflict" | "locked" | "cart_revision_conflict" | "rate_limit_exceeded" | "usage_limit_exceeded" | "service_unavailable" | "idempotency_conflict" | "idempotency_in_progress" | "idempotency_key_required" | "invalid_idempotency_key" | "cart_not_active" | "cart_locked" | "cart_empty" | "cart_market_unavailable" | "cart_market_mismatch" | "checkout_not_open" | "checkout_already_open" | "payment_slot_held" | "reservation_expired" | "payment_session_not_cancelable" | "payment_session_conflict" | "provider_identity_mismatch" | "payment_method_unavailable" | "provider_unavailable" | "lock_timeout" | "price_changed" | "pricing_fact_in_use" | "insufficient_stock" | "reservation_conflict" | "stock_lock_unavailable" | "variant_not_found" | "variant_stock_write_failed" | "stock_invariant_violation" | "payment_confirmation_in_flight" | "checkout_reservation_release_requires_transaction" | "admission_metadata_invalid" | "admission_metadata_required" | "capacity_exceeded" | "occurrence_lock_unavailable" | "occurrence_not_open" | "admission_type_capacity_exceeded" | "admission_type_occurrence_mismatch" | "admission_hold_expired" | "admission_hold_checkout_item_conflict" | "admission_hold_checkout_conflict" | "admission_hold_quantity_mismatch" | "admission_hold_unbound" | "admission_hold_missing" | "admission_hold_checkout_item_missing" | "admission_hold_expiry_failed" | "admission_hold_expiry_requires_transaction" | "admission_hold_line_item_mismatch" | "admission_materialization_failed" | "variant_inactive" | "variant_product_mismatch" | "product_not_public" | "market_not_found" | "market_shipping_currency_unsupported" | "missing_market_rate" | "missing_shipping_amount" | "no_enabled_payment_provider" | "product_market_unavailable" | "unsupported_currency" | "missing_price_row" | "payment_provider_currency_unsupported" | "discount_code_not_found" | "discount_not_started" | "discount_expired" | "discount_usage_limit" | "discount_per_customer_limit" | "discount_customer_required" | "discount_first_order_only" | "discount_customer_not_eligible" | "discount_customer_excluded" | "discount_items_required" | "discount_product_not_eligible" | "discount_product_excluded" | "discount_min_order_amount" | "discount_currency_scope_required" | "discount_allocation_method_unsupported" | "customer_token_required" | "market_required" | "server_derived" | "internal_error" | "unknown_commerce_error" | undefined;
|
|
96
105
|
kind?: "commerce" | undefined;
|
|
97
106
|
requestId?: string | undefined;
|
|
98
107
|
name: string;
|
|
@@ -152,4 +161,4 @@ declare const createNotFoundError: (message: string, details?: unknown, userMess
|
|
|
152
161
|
declare const createConflictError: (message: string, details?: unknown, userMessage?: string, suggestion?: string, requestId?: string) => ConflictError;
|
|
153
162
|
declare const createRateLimitError: (message: string, retryAfter?: number, details?: unknown, userMessage?: string, suggestion?: string, requestId?: string) => RateLimitError;
|
|
154
163
|
|
|
155
|
-
export { ApiError, AuthError, COMMERCE_ERROR_CODES, type CommerceErrorCode, type CommerceSDKError, ConfigError, ConflictError, GoneError, NetworkError, NotFoundError, PermissionError, RateLimitError, SDKError, ServiceUnavailableError, TimeoutError, UsageLimitError, ValidationError, createApiError, createAuthError, createConfigError, createConflictError, createGoneError, createNetworkError, createNotFoundError, createPermissionError, createRateLimitError, createServiceUnavailableError, createTimeoutError, createUsageLimitError, createValidationError, isApiError, isAuthError, isCommerceSDKError, isConfigError, isConflictError, isGoneError, isNetworkError, isNotFoundError, isPermissionError, isRateLimitError, isSDKError, isServiceUnavailableError, isTimeoutError, isUsageLimitError, isValidationError };
|
|
164
|
+
export { ApiError, AuthError, COMMERCE_ERROR_CODES, type CommerceErrorCode, type CommerceSDKError, ConfigError, ConflictError, GoneError, NetworkError, NotFoundError, PermissionError, RateLimitError, SDKError, ServiceUnavailableError, TimeoutError, UsageLimitError, ValidationError, createApiError, createAuthError, createConfigError, createConflictError, createGoneError, createNetworkError, createNotFoundError, createPermissionError, createRateLimitError, createServiceUnavailableError, createTimeoutError, createUsageLimitError, createValidationError, getSDKErrorReason, isApiError, isAuthError, isCommerceSDKError, isConfigError, isConflictError, isGoneError, isNetworkError, isNotFoundError, isPermissionError, isRateLimitError, isSDKError, isServiceUnavailableError, isTimeoutError, isUsageLimitError, isValidationError };
|
package/dist/errors.js
CHANGED
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
// src/core/errors.ts
|
|
2
|
+
var SDK_ERROR_BRAND = /* @__PURE__ */ Symbol.for("@01.software/sdk/SDKError");
|
|
3
|
+
var SDK_ERROR_TYPE_BRAND = /* @__PURE__ */ Symbol.for("@01.software/sdk/SDKError.type");
|
|
4
|
+
function defineSDKErrorBrand(error) {
|
|
5
|
+
Object.defineProperty(error, SDK_ERROR_BRAND, {
|
|
6
|
+
value: true,
|
|
7
|
+
enumerable: false,
|
|
8
|
+
configurable: false,
|
|
9
|
+
writable: false
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
function defineSDKErrorType(error, type) {
|
|
13
|
+
Object.defineProperty(error, SDK_ERROR_TYPE_BRAND, {
|
|
14
|
+
value: type,
|
|
15
|
+
enumerable: false,
|
|
16
|
+
configurable: false,
|
|
17
|
+
writable: false
|
|
18
|
+
});
|
|
19
|
+
}
|
|
2
20
|
var SDKError = class extends Error {
|
|
3
21
|
constructor(code, message, status, details, userMessage, suggestion, requestId) {
|
|
4
22
|
super(message);
|
|
@@ -9,6 +27,7 @@ var SDKError = class extends Error {
|
|
|
9
27
|
this.userMessage = userMessage;
|
|
10
28
|
this.suggestion = suggestion;
|
|
11
29
|
this.requestId = requestId;
|
|
30
|
+
defineSDKErrorBrand(this);
|
|
12
31
|
if (Error.captureStackTrace) {
|
|
13
32
|
Error.captureStackTrace(this, new.target);
|
|
14
33
|
}
|
|
@@ -29,6 +48,7 @@ var SDKError = class extends Error {
|
|
|
29
48
|
...this.kind !== void 0 && { kind: this.kind },
|
|
30
49
|
...this.reason !== void 0 && { reason: this.reason },
|
|
31
50
|
...this.rawReason !== void 0 && { rawReason: this.rawReason },
|
|
51
|
+
...this.apiReason !== void 0 && { apiReason: this.apiReason },
|
|
32
52
|
...this.retryable !== void 0 && { retryable: this.retryable },
|
|
33
53
|
...this.retryAfter !== void 0 && { retryAfter: this.retryAfter }
|
|
34
54
|
};
|
|
@@ -36,34 +56,78 @@ var SDKError = class extends Error {
|
|
|
36
56
|
};
|
|
37
57
|
var COMMERCE_ERROR_CODES = [
|
|
38
58
|
"validation_failed",
|
|
59
|
+
"bad_request",
|
|
39
60
|
"unauthorized",
|
|
40
61
|
"forbidden",
|
|
62
|
+
"account_suspended",
|
|
63
|
+
"key_invalid",
|
|
64
|
+
"pat_tenant_header_forbidden",
|
|
65
|
+
"tenant_mismatch",
|
|
66
|
+
"test_tenant_expired",
|
|
67
|
+
"token_invalid",
|
|
41
68
|
"token_expired",
|
|
42
69
|
"origin_not_allowed",
|
|
43
70
|
"server_credentials_required",
|
|
71
|
+
"role_denied",
|
|
72
|
+
"scope_denied",
|
|
73
|
+
"feature_disabled",
|
|
44
74
|
"not_found",
|
|
45
75
|
"conflict",
|
|
76
|
+
"locked",
|
|
46
77
|
"cart_revision_conflict",
|
|
47
78
|
"rate_limit_exceeded",
|
|
48
79
|
"usage_limit_exceeded",
|
|
49
80
|
"service_unavailable",
|
|
50
81
|
"idempotency_conflict",
|
|
51
82
|
"idempotency_in_progress",
|
|
83
|
+
"idempotency_key_required",
|
|
84
|
+
"invalid_idempotency_key",
|
|
52
85
|
"cart_not_active",
|
|
53
86
|
"cart_locked",
|
|
54
87
|
"cart_empty",
|
|
55
88
|
"cart_market_unavailable",
|
|
56
89
|
"cart_market_mismatch",
|
|
57
90
|
"checkout_not_open",
|
|
91
|
+
"checkout_already_open",
|
|
58
92
|
"payment_slot_held",
|
|
59
93
|
"reservation_expired",
|
|
60
94
|
"payment_session_not_cancelable",
|
|
95
|
+
"payment_session_conflict",
|
|
61
96
|
"provider_identity_mismatch",
|
|
97
|
+
"payment_method_unavailable",
|
|
62
98
|
"provider_unavailable",
|
|
63
99
|
"lock_timeout",
|
|
64
100
|
"price_changed",
|
|
65
101
|
"pricing_fact_in_use",
|
|
66
102
|
"insufficient_stock",
|
|
103
|
+
"reservation_conflict",
|
|
104
|
+
"stock_lock_unavailable",
|
|
105
|
+
"variant_not_found",
|
|
106
|
+
"variant_stock_write_failed",
|
|
107
|
+
"stock_invariant_violation",
|
|
108
|
+
"payment_confirmation_in_flight",
|
|
109
|
+
"checkout_reservation_release_requires_transaction",
|
|
110
|
+
"admission_metadata_invalid",
|
|
111
|
+
"admission_metadata_required",
|
|
112
|
+
"capacity_exceeded",
|
|
113
|
+
"occurrence_lock_unavailable",
|
|
114
|
+
"occurrence_not_open",
|
|
115
|
+
"admission_type_capacity_exceeded",
|
|
116
|
+
"admission_type_occurrence_mismatch",
|
|
117
|
+
"admission_hold_expired",
|
|
118
|
+
"admission_hold_checkout_item_conflict",
|
|
119
|
+
"admission_hold_checkout_conflict",
|
|
120
|
+
"admission_hold_quantity_mismatch",
|
|
121
|
+
"admission_hold_unbound",
|
|
122
|
+
"admission_hold_missing",
|
|
123
|
+
"admission_hold_checkout_item_missing",
|
|
124
|
+
"admission_hold_expiry_failed",
|
|
125
|
+
"admission_hold_expiry_requires_transaction",
|
|
126
|
+
"admission_hold_line_item_mismatch",
|
|
127
|
+
"admission_materialization_failed",
|
|
128
|
+
"variant_inactive",
|
|
129
|
+
"variant_product_mismatch",
|
|
130
|
+
"product_not_public",
|
|
67
131
|
"market_not_found",
|
|
68
132
|
"market_shipping_currency_unsupported",
|
|
69
133
|
"missing_market_rate",
|
|
@@ -88,13 +152,21 @@ var COMMERCE_ERROR_CODES = [
|
|
|
88
152
|
"discount_min_order_amount",
|
|
89
153
|
"discount_currency_scope_required",
|
|
90
154
|
"discount_allocation_method_unsupported",
|
|
91
|
-
"currency_mismatch"
|
|
155
|
+
"currency_mismatch",
|
|
156
|
+
"customer_token_required",
|
|
157
|
+
"market_required",
|
|
158
|
+
"server_derived",
|
|
159
|
+
"internal_error"
|
|
92
160
|
];
|
|
93
161
|
var COMMERCE_ERROR_CODE_SET = new Set(
|
|
94
162
|
COMMERCE_ERROR_CODES
|
|
95
163
|
);
|
|
164
|
+
function getSDKErrorReason(error) {
|
|
165
|
+
if (error.kind !== "commerce") return error.apiReason;
|
|
166
|
+
return error.reason === "unknown_commerce_error" ? error.rawReason : error.reason;
|
|
167
|
+
}
|
|
96
168
|
function isCommerceSDKError(error) {
|
|
97
|
-
if (!(error
|
|
169
|
+
if (!isSDKError(error) || error.kind !== "commerce") return false;
|
|
98
170
|
if (typeof error.requestId !== "string" || typeof error.retryable !== "boolean" || error.retryAfter !== void 0 && (!Number.isSafeInteger(error.retryAfter) || error.retryAfter < 0) || typeof error.reason !== "string") {
|
|
99
171
|
return false;
|
|
100
172
|
}
|
|
@@ -104,12 +176,14 @@ var NetworkError = class extends SDKError {
|
|
|
104
176
|
constructor(message, status, details, userMessage, suggestion) {
|
|
105
177
|
super("NETWORK_ERROR", message, status, details, userMessage, suggestion);
|
|
106
178
|
this.name = "NetworkError";
|
|
179
|
+
defineSDKErrorType(this, "NetworkError");
|
|
107
180
|
}
|
|
108
181
|
};
|
|
109
182
|
var ValidationError = class extends SDKError {
|
|
110
183
|
constructor(message, details, userMessage, suggestion, status = 400) {
|
|
111
184
|
super("VALIDATION_ERROR", message, status, details, userMessage, suggestion);
|
|
112
185
|
this.name = "ValidationError";
|
|
186
|
+
defineSDKErrorType(this, "ValidationError");
|
|
113
187
|
}
|
|
114
188
|
};
|
|
115
189
|
var ApiError = class extends SDKError {
|
|
@@ -124,24 +198,28 @@ var ApiError = class extends SDKError {
|
|
|
124
198
|
requestId
|
|
125
199
|
);
|
|
126
200
|
this.name = "ApiError";
|
|
201
|
+
defineSDKErrorType(this, "ApiError");
|
|
127
202
|
}
|
|
128
203
|
};
|
|
129
204
|
var ConfigError = class extends SDKError {
|
|
130
205
|
constructor(message, details, userMessage, suggestion) {
|
|
131
206
|
super("CONFIG_ERROR", message, void 0, details, userMessage, suggestion);
|
|
132
207
|
this.name = "ConfigError";
|
|
208
|
+
defineSDKErrorType(this, "ConfigError");
|
|
133
209
|
}
|
|
134
210
|
};
|
|
135
211
|
var TimeoutError = class extends SDKError {
|
|
136
212
|
constructor(message = "Request timed out.", details, userMessage, suggestion) {
|
|
137
213
|
super("TIMEOUT_ERROR", message, 408, details, userMessage, suggestion);
|
|
138
214
|
this.name = "TimeoutError";
|
|
215
|
+
defineSDKErrorType(this, "TimeoutError");
|
|
139
216
|
}
|
|
140
217
|
};
|
|
141
218
|
var GoneError = class extends SDKError {
|
|
142
219
|
constructor(message = "The requested resource is no longer available.", details, userMessage, suggestion) {
|
|
143
220
|
super("GONE_ERROR", message, 410, details, userMessage, suggestion);
|
|
144
221
|
this.name = "GoneError";
|
|
222
|
+
defineSDKErrorType(this, "GoneError");
|
|
145
223
|
}
|
|
146
224
|
};
|
|
147
225
|
var ServiceUnavailableError = class extends SDKError {
|
|
@@ -156,6 +234,7 @@ var ServiceUnavailableError = class extends SDKError {
|
|
|
156
234
|
);
|
|
157
235
|
this.name = "ServiceUnavailableError";
|
|
158
236
|
this.retryAfter = retryAfter;
|
|
237
|
+
defineSDKErrorType(this, "ServiceUnavailableError");
|
|
159
238
|
}
|
|
160
239
|
};
|
|
161
240
|
var UsageLimitError = class extends SDKError {
|
|
@@ -163,6 +242,7 @@ var UsageLimitError = class extends SDKError {
|
|
|
163
242
|
super("USAGE_LIMIT_ERROR", message, 429, details, userMessage, suggestion);
|
|
164
243
|
this.name = "UsageLimitError";
|
|
165
244
|
this.usage = usage;
|
|
245
|
+
defineSDKErrorType(this, "UsageLimitError");
|
|
166
246
|
}
|
|
167
247
|
toJSON() {
|
|
168
248
|
return {
|
|
@@ -183,6 +263,7 @@ var AuthError = class extends SDKError {
|
|
|
183
263
|
requestId
|
|
184
264
|
);
|
|
185
265
|
this.name = "AuthError";
|
|
266
|
+
defineSDKErrorType(this, "AuthError");
|
|
186
267
|
}
|
|
187
268
|
};
|
|
188
269
|
var PermissionError = class extends SDKError {
|
|
@@ -197,6 +278,7 @@ var PermissionError = class extends SDKError {
|
|
|
197
278
|
requestId
|
|
198
279
|
);
|
|
199
280
|
this.name = "PermissionError";
|
|
281
|
+
defineSDKErrorType(this, "PermissionError");
|
|
200
282
|
}
|
|
201
283
|
};
|
|
202
284
|
var NotFoundError = class extends SDKError {
|
|
@@ -211,12 +293,14 @@ var NotFoundError = class extends SDKError {
|
|
|
211
293
|
requestId
|
|
212
294
|
);
|
|
213
295
|
this.name = "NotFoundError";
|
|
296
|
+
defineSDKErrorType(this, "NotFoundError");
|
|
214
297
|
}
|
|
215
298
|
};
|
|
216
299
|
var ConflictError = class extends SDKError {
|
|
217
300
|
constructor(message, details, userMessage, suggestion, requestId) {
|
|
218
301
|
super("conflict", message, 409, details, userMessage, suggestion, requestId);
|
|
219
302
|
this.name = "ConflictError";
|
|
303
|
+
defineSDKErrorType(this, "ConflictError");
|
|
220
304
|
}
|
|
221
305
|
};
|
|
222
306
|
var RateLimitError = class extends SDKError {
|
|
@@ -232,52 +316,63 @@ var RateLimitError = class extends SDKError {
|
|
|
232
316
|
);
|
|
233
317
|
this.name = "RateLimitError";
|
|
234
318
|
this.retryAfter = retryAfter;
|
|
319
|
+
defineSDKErrorType(this, "RateLimitError");
|
|
235
320
|
}
|
|
236
321
|
};
|
|
322
|
+
function hasBrandedSDKErrorShape(error) {
|
|
323
|
+
if (error === null || typeof error !== "object") return false;
|
|
324
|
+
const candidate = error;
|
|
325
|
+
return candidate[SDK_ERROR_BRAND] === true && typeof candidate.name === "string" && typeof candidate.code === "string" && typeof candidate.message === "string" && (candidate.status === void 0 || typeof candidate.status === "number") && (candidate.userMessage === void 0 || typeof candidate.userMessage === "string") && (candidate.suggestion === void 0 || typeof candidate.suggestion === "string") && (candidate.requestId === void 0 || typeof candidate.requestId === "string") && (candidate.kind === void 0 || candidate.kind === "commerce") && (candidate.reason === void 0 || typeof candidate.reason === "string") && (candidate.rawReason === void 0 || typeof candidate.rawReason === "string") && (candidate.apiReason === void 0 || typeof candidate.apiReason === "string") && (candidate.retryable === void 0 || typeof candidate.retryable === "boolean") && (candidate.retryAfter === void 0 || typeof candidate.retryAfter === "number") && typeof candidate.getUserMessage === "function" && typeof candidate.toJSON === "function";
|
|
326
|
+
}
|
|
327
|
+
function hasSDKErrorType(error, type) {
|
|
328
|
+
return hasBrandedSDKErrorShape(error) && error[SDK_ERROR_TYPE_BRAND] === type;
|
|
329
|
+
}
|
|
237
330
|
function isSDKError(error) {
|
|
238
|
-
return error instanceof SDKError;
|
|
331
|
+
return error instanceof SDKError || hasBrandedSDKErrorShape(error);
|
|
239
332
|
}
|
|
240
333
|
function isNetworkError(error) {
|
|
241
|
-
return error instanceof NetworkError;
|
|
334
|
+
return error instanceof NetworkError || hasSDKErrorType(error, "NetworkError");
|
|
242
335
|
}
|
|
243
336
|
function isValidationError(error) {
|
|
244
|
-
if (error instanceof ValidationError)
|
|
337
|
+
if (error instanceof ValidationError || hasSDKErrorType(error, "ValidationError")) {
|
|
338
|
+
return true;
|
|
339
|
+
}
|
|
245
340
|
if (error == null || typeof error !== "object") return false;
|
|
246
341
|
const candidate = error;
|
|
247
342
|
return candidate.name === "ValidationError" && candidate.code === "VALIDATION_ERROR" && typeof candidate.message === "string" && typeof candidate.getUserMessage === "function" && typeof candidate.toJSON === "function";
|
|
248
343
|
}
|
|
249
344
|
function isApiError(error) {
|
|
250
|
-
return error instanceof ApiError;
|
|
345
|
+
return error instanceof ApiError || hasSDKErrorType(error, "ApiError");
|
|
251
346
|
}
|
|
252
347
|
function isConfigError(error) {
|
|
253
|
-
return error instanceof ConfigError;
|
|
348
|
+
return error instanceof ConfigError || hasSDKErrorType(error, "ConfigError");
|
|
254
349
|
}
|
|
255
350
|
function isTimeoutError(error) {
|
|
256
|
-
return error instanceof TimeoutError;
|
|
351
|
+
return error instanceof TimeoutError || hasSDKErrorType(error, "TimeoutError");
|
|
257
352
|
}
|
|
258
353
|
function isGoneError(error) {
|
|
259
|
-
return error instanceof GoneError;
|
|
354
|
+
return error instanceof GoneError || hasSDKErrorType(error, "GoneError");
|
|
260
355
|
}
|
|
261
356
|
function isServiceUnavailableError(error) {
|
|
262
|
-
return error instanceof ServiceUnavailableError;
|
|
357
|
+
return error instanceof ServiceUnavailableError || hasSDKErrorType(error, "ServiceUnavailableError");
|
|
263
358
|
}
|
|
264
359
|
function isUsageLimitError(error) {
|
|
265
|
-
return error instanceof UsageLimitError;
|
|
360
|
+
return error instanceof UsageLimitError || hasSDKErrorType(error, "UsageLimitError");
|
|
266
361
|
}
|
|
267
362
|
function isAuthError(error) {
|
|
268
|
-
return error instanceof AuthError;
|
|
363
|
+
return error instanceof AuthError || hasSDKErrorType(error, "AuthError");
|
|
269
364
|
}
|
|
270
365
|
function isPermissionError(error) {
|
|
271
|
-
return error instanceof PermissionError;
|
|
366
|
+
return error instanceof PermissionError || hasSDKErrorType(error, "PermissionError");
|
|
272
367
|
}
|
|
273
368
|
function isNotFoundError(error) {
|
|
274
|
-
return error instanceof NotFoundError;
|
|
369
|
+
return error instanceof NotFoundError || hasSDKErrorType(error, "NotFoundError");
|
|
275
370
|
}
|
|
276
371
|
function isConflictError(error) {
|
|
277
|
-
return error instanceof ConflictError;
|
|
372
|
+
return error instanceof ConflictError || hasSDKErrorType(error, "ConflictError");
|
|
278
373
|
}
|
|
279
374
|
function isRateLimitError(error) {
|
|
280
|
-
return error instanceof RateLimitError;
|
|
375
|
+
return error instanceof RateLimitError || hasSDKErrorType(error, "RateLimitError");
|
|
281
376
|
}
|
|
282
377
|
var createNetworkError = (message, status, details, userMessage, suggestion) => new NetworkError(message, status, details, userMessage, suggestion);
|
|
283
378
|
var createValidationError = (message, details, userMessage, suggestion, status) => new ValidationError(message, details, userMessage, suggestion, status);
|
|
@@ -334,6 +429,7 @@ export {
|
|
|
334
429
|
createTimeoutError,
|
|
335
430
|
createUsageLimitError,
|
|
336
431
|
createValidationError,
|
|
432
|
+
getSDKErrorReason,
|
|
337
433
|
isApiError,
|
|
338
434
|
isAuthError,
|
|
339
435
|
isCommerceSDKError,
|