@commercelayer/sdk 5.35.0 → 6.0.0-alfa.10
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/lib/cjs/api.d.ts +0 -3
- package/lib/cjs/api.js +0 -10
- package/lib/cjs/client.d.ts +6 -14
- package/lib/cjs/client.js +41 -75
- package/lib/cjs/commercelayer.d.ts +126 -125
- package/lib/cjs/commercelayer.js +267 -155
- package/lib/cjs/common.js +1 -12
- package/lib/cjs/config.js +0 -2
- package/lib/cjs/debug.js +0 -21
- package/lib/cjs/error.d.ts +6 -7
- package/lib/cjs/error.js +36 -35
- package/lib/cjs/fetch.d.ts +13 -0
- package/lib/cjs/fetch.js +67 -0
- package/lib/cjs/index.js +0 -2
- package/lib/cjs/interceptor.d.ts +22 -10
- package/lib/cjs/jsonapi.js +0 -2
- package/lib/cjs/model.d.ts +0 -3
- package/lib/cjs/model.js +0 -1
- package/lib/cjs/query.d.ts +2 -1
- package/lib/cjs/query.js +8 -7
- package/lib/cjs/resource.d.ts +2 -5
- package/lib/cjs/resource.js +32 -58
- package/lib/cjs/resources/addresses.d.ts +1 -0
- package/lib/cjs/resources/addresses.js +4 -1
- package/lib/cjs/resources/adjustments.d.ts +1 -0
- package/lib/cjs/resources/adjustments.js +4 -1
- package/lib/cjs/resources/adyen_gateways.d.ts +1 -0
- package/lib/cjs/resources/adyen_gateways.js +4 -1
- package/lib/cjs/resources/adyen_payments.d.ts +1 -0
- package/lib/cjs/resources/adyen_payments.js +4 -1
- package/lib/cjs/resources/application.d.ts +1 -0
- package/lib/cjs/resources/application.js +4 -1
- package/lib/cjs/resources/attachments.d.ts +1 -0
- package/lib/cjs/resources/attachments.js +4 -1
- package/lib/cjs/resources/authorizations.d.ts +1 -0
- package/lib/cjs/resources/authorizations.js +4 -1
- package/lib/cjs/resources/avalara_accounts.d.ts +1 -0
- package/lib/cjs/resources/avalara_accounts.js +4 -1
- package/lib/cjs/resources/axerve_gateways.d.ts +1 -0
- package/lib/cjs/resources/axerve_gateways.js +4 -1
- package/lib/cjs/resources/axerve_payments.d.ts +1 -0
- package/lib/cjs/resources/axerve_payments.js +4 -1
- package/lib/cjs/resources/billing_info_validation_rules.d.ts +1 -0
- package/lib/cjs/resources/billing_info_validation_rules.js +4 -1
- package/lib/cjs/resources/bing_geocoders.d.ts +1 -0
- package/lib/cjs/resources/bing_geocoders.js +4 -1
- package/lib/cjs/resources/braintree_gateways.d.ts +1 -0
- package/lib/cjs/resources/braintree_gateways.js +4 -1
- package/lib/cjs/resources/braintree_payments.d.ts +1 -0
- package/lib/cjs/resources/braintree_payments.js +4 -1
- package/lib/cjs/resources/bundles.d.ts +1 -0
- package/lib/cjs/resources/bundles.js +4 -1
- package/lib/cjs/resources/buy_x_pay_y_promotions.d.ts +1 -0
- package/lib/cjs/resources/buy_x_pay_y_promotions.js +4 -1
- package/lib/cjs/resources/captures.d.ts +1 -0
- package/lib/cjs/resources/captures.js +4 -1
- package/lib/cjs/resources/carrier_accounts.d.ts +1 -0
- package/lib/cjs/resources/carrier_accounts.js +4 -1
- package/lib/cjs/resources/checkout_com_gateways.d.ts +1 -0
- package/lib/cjs/resources/checkout_com_gateways.js +4 -1
- package/lib/cjs/resources/checkout_com_payments.d.ts +1 -0
- package/lib/cjs/resources/checkout_com_payments.js +4 -1
- package/lib/cjs/resources/cleanups.d.ts +1 -0
- package/lib/cjs/resources/cleanups.js +4 -1
- package/lib/cjs/resources/coupon_codes_promotion_rules.d.ts +1 -0
- package/lib/cjs/resources/coupon_codes_promotion_rules.js +4 -1
- package/lib/cjs/resources/coupon_recipients.d.ts +1 -0
- package/lib/cjs/resources/coupon_recipients.js +4 -1
- package/lib/cjs/resources/coupons.d.ts +1 -0
- package/lib/cjs/resources/coupons.js +4 -1
- package/lib/cjs/resources/custom_promotion_rules.d.ts +1 -0
- package/lib/cjs/resources/custom_promotion_rules.js +4 -1
- package/lib/cjs/resources/customer_addresses.d.ts +1 -0
- package/lib/cjs/resources/customer_addresses.js +4 -1
- package/lib/cjs/resources/customer_groups.d.ts +1 -0
- package/lib/cjs/resources/customer_groups.js +4 -1
- package/lib/cjs/resources/customer_password_resets.d.ts +1 -0
- package/lib/cjs/resources/customer_password_resets.js +4 -1
- package/lib/cjs/resources/customer_payment_sources.d.ts +1 -0
- package/lib/cjs/resources/customer_payment_sources.js +4 -1
- package/lib/cjs/resources/customer_subscriptions.d.ts +1 -0
- package/lib/cjs/resources/customer_subscriptions.js +4 -1
- package/lib/cjs/resources/customers.d.ts +1 -0
- package/lib/cjs/resources/customers.js +4 -1
- package/lib/cjs/resources/delivery_lead_times.d.ts +1 -0
- package/lib/cjs/resources/delivery_lead_times.js +4 -1
- package/lib/cjs/resources/event_callbacks.d.ts +1 -0
- package/lib/cjs/resources/event_callbacks.js +4 -1
- package/lib/cjs/resources/events.d.ts +1 -0
- package/lib/cjs/resources/events.js +4 -1
- package/lib/cjs/resources/exports.d.ts +1 -0
- package/lib/cjs/resources/exports.js +4 -1
- package/lib/cjs/resources/external_gateways.d.ts +1 -0
- package/lib/cjs/resources/external_gateways.js +4 -1
- package/lib/cjs/resources/external_payments.d.ts +1 -0
- package/lib/cjs/resources/external_payments.js +4 -1
- package/lib/cjs/resources/external_promotions.d.ts +1 -0
- package/lib/cjs/resources/external_promotions.js +4 -1
- package/lib/cjs/resources/external_tax_calculators.d.ts +1 -0
- package/lib/cjs/resources/external_tax_calculators.js +4 -1
- package/lib/cjs/resources/fixed_amount_promotions.d.ts +1 -0
- package/lib/cjs/resources/fixed_amount_promotions.js +4 -1
- package/lib/cjs/resources/fixed_price_promotions.d.ts +1 -0
- package/lib/cjs/resources/fixed_price_promotions.js +4 -1
- package/lib/cjs/resources/free_gift_promotions.d.ts +1 -0
- package/lib/cjs/resources/free_gift_promotions.js +4 -1
- package/lib/cjs/resources/free_shipping_promotions.d.ts +1 -0
- package/lib/cjs/resources/free_shipping_promotions.js +4 -1
- package/lib/cjs/resources/geocoders.d.ts +1 -0
- package/lib/cjs/resources/geocoders.js +4 -1
- package/lib/cjs/resources/gift_card_recipients.d.ts +1 -0
- package/lib/cjs/resources/gift_card_recipients.js +4 -1
- package/lib/cjs/resources/gift_cards.d.ts +1 -0
- package/lib/cjs/resources/gift_cards.js +4 -1
- package/lib/cjs/resources/google_geocoders.d.ts +1 -0
- package/lib/cjs/resources/google_geocoders.js +4 -1
- package/lib/cjs/resources/imports.d.ts +1 -0
- package/lib/cjs/resources/imports.js +4 -1
- package/lib/cjs/resources/in_stock_subscriptions.d.ts +1 -0
- package/lib/cjs/resources/in_stock_subscriptions.js +4 -1
- package/lib/cjs/resources/inventory_models.d.ts +1 -0
- package/lib/cjs/resources/inventory_models.js +4 -1
- package/lib/cjs/resources/inventory_return_locations.d.ts +1 -0
- package/lib/cjs/resources/inventory_return_locations.js +4 -1
- package/lib/cjs/resources/inventory_stock_locations.d.ts +1 -0
- package/lib/cjs/resources/inventory_stock_locations.js +4 -1
- package/lib/cjs/resources/klarna_gateways.d.ts +1 -0
- package/lib/cjs/resources/klarna_gateways.js +4 -1
- package/lib/cjs/resources/klarna_payments.d.ts +1 -0
- package/lib/cjs/resources/klarna_payments.js +4 -1
- package/lib/cjs/resources/line_item_options.d.ts +1 -0
- package/lib/cjs/resources/line_item_options.js +4 -1
- package/lib/cjs/resources/line_items.d.ts +1 -0
- package/lib/cjs/resources/line_items.js +4 -1
- package/lib/cjs/resources/manual_gateways.d.ts +1 -0
- package/lib/cjs/resources/manual_gateways.js +4 -1
- package/lib/cjs/resources/manual_tax_calculators.d.ts +1 -0
- package/lib/cjs/resources/manual_tax_calculators.js +4 -1
- package/lib/cjs/resources/markets.d.ts +1 -0
- package/lib/cjs/resources/markets.js +4 -1
- package/lib/cjs/resources/merchants.d.ts +1 -0
- package/lib/cjs/resources/merchants.js +4 -1
- package/lib/cjs/resources/order_amount_promotion_rules.d.ts +1 -0
- package/lib/cjs/resources/order_amount_promotion_rules.js +4 -1
- package/lib/cjs/resources/order_copies.d.ts +1 -0
- package/lib/cjs/resources/order_copies.js +4 -1
- package/lib/cjs/resources/order_factories.d.ts +1 -0
- package/lib/cjs/resources/order_factories.js +4 -1
- package/lib/cjs/resources/order_subscription_items.d.ts +1 -0
- package/lib/cjs/resources/order_subscription_items.js +4 -1
- package/lib/cjs/resources/order_subscriptions.d.ts +1 -0
- package/lib/cjs/resources/order_subscriptions.js +4 -1
- package/lib/cjs/resources/order_validation_rules.d.ts +1 -0
- package/lib/cjs/resources/order_validation_rules.js +4 -1
- package/lib/cjs/resources/orders.d.ts +1 -0
- package/lib/cjs/resources/orders.js +4 -1
- package/lib/cjs/resources/organization.d.ts +1 -0
- package/lib/cjs/resources/organization.js +4 -1
- package/lib/cjs/resources/packages.d.ts +1 -0
- package/lib/cjs/resources/packages.js +4 -1
- package/lib/cjs/resources/parcel_line_items.d.ts +1 -0
- package/lib/cjs/resources/parcel_line_items.js +4 -1
- package/lib/cjs/resources/parcels.d.ts +1 -0
- package/lib/cjs/resources/parcels.js +4 -1
- package/lib/cjs/resources/payment_gateways.d.ts +1 -0
- package/lib/cjs/resources/payment_gateways.js +4 -1
- package/lib/cjs/resources/payment_methods.d.ts +1 -0
- package/lib/cjs/resources/payment_methods.js +4 -1
- package/lib/cjs/resources/payment_options.d.ts +1 -0
- package/lib/cjs/resources/payment_options.js +4 -1
- package/lib/cjs/resources/paypal_gateways.d.ts +1 -0
- package/lib/cjs/resources/paypal_gateways.js +4 -1
- package/lib/cjs/resources/paypal_payments.d.ts +1 -0
- package/lib/cjs/resources/paypal_payments.js +4 -1
- package/lib/cjs/resources/percentage_discount_promotions.d.ts +1 -0
- package/lib/cjs/resources/percentage_discount_promotions.js +4 -1
- package/lib/cjs/resources/price_frequency_tiers.d.ts +1 -0
- package/lib/cjs/resources/price_frequency_tiers.js +4 -1
- package/lib/cjs/resources/price_lists.d.ts +1 -0
- package/lib/cjs/resources/price_lists.js +4 -1
- package/lib/cjs/resources/price_tiers.d.ts +1 -0
- package/lib/cjs/resources/price_tiers.js +4 -1
- package/lib/cjs/resources/price_volume_tiers.d.ts +1 -0
- package/lib/cjs/resources/price_volume_tiers.js +4 -1
- package/lib/cjs/resources/prices.d.ts +1 -0
- package/lib/cjs/resources/prices.js +4 -1
- package/lib/cjs/resources/promotion_rules.d.ts +1 -0
- package/lib/cjs/resources/promotion_rules.js +4 -1
- package/lib/cjs/resources/promotions.d.ts +1 -0
- package/lib/cjs/resources/promotions.js +4 -1
- package/lib/cjs/resources/recurring_order_copies.d.ts +1 -0
- package/lib/cjs/resources/recurring_order_copies.js +4 -1
- package/lib/cjs/resources/refunds.d.ts +1 -0
- package/lib/cjs/resources/refunds.js +4 -1
- package/lib/cjs/resources/reserved_stocks.d.ts +1 -0
- package/lib/cjs/resources/reserved_stocks.js +4 -1
- package/lib/cjs/resources/resource_errors.d.ts +1 -0
- package/lib/cjs/resources/resource_errors.js +4 -1
- package/lib/cjs/resources/return_line_items.d.ts +1 -0
- package/lib/cjs/resources/return_line_items.js +4 -1
- package/lib/cjs/resources/returns.d.ts +1 -0
- package/lib/cjs/resources/returns.js +4 -1
- package/lib/cjs/resources/satispay_gateways.d.ts +1 -0
- package/lib/cjs/resources/satispay_gateways.js +4 -1
- package/lib/cjs/resources/satispay_payments.d.ts +1 -0
- package/lib/cjs/resources/satispay_payments.js +4 -1
- package/lib/cjs/resources/shipments.d.ts +1 -0
- package/lib/cjs/resources/shipments.js +4 -1
- package/lib/cjs/resources/shipping_categories.d.ts +1 -0
- package/lib/cjs/resources/shipping_categories.js +4 -1
- package/lib/cjs/resources/shipping_method_tiers.d.ts +1 -0
- package/lib/cjs/resources/shipping_method_tiers.js +4 -1
- package/lib/cjs/resources/shipping_methods.d.ts +1 -0
- package/lib/cjs/resources/shipping_methods.js +4 -1
- package/lib/cjs/resources/shipping_weight_tiers.d.ts +1 -0
- package/lib/cjs/resources/shipping_weight_tiers.js +4 -1
- package/lib/cjs/resources/shipping_zones.d.ts +1 -0
- package/lib/cjs/resources/shipping_zones.js +4 -1
- package/lib/cjs/resources/sku_list_items.d.ts +1 -0
- package/lib/cjs/resources/sku_list_items.js +4 -1
- package/lib/cjs/resources/sku_list_promotion_rules.d.ts +1 -0
- package/lib/cjs/resources/sku_list_promotion_rules.js +4 -1
- package/lib/cjs/resources/sku_lists.d.ts +1 -0
- package/lib/cjs/resources/sku_lists.js +4 -1
- package/lib/cjs/resources/sku_options.d.ts +1 -0
- package/lib/cjs/resources/sku_options.js +4 -1
- package/lib/cjs/resources/skus.d.ts +1 -0
- package/lib/cjs/resources/skus.js +4 -1
- package/lib/cjs/resources/stock_items.d.ts +1 -0
- package/lib/cjs/resources/stock_items.js +4 -1
- package/lib/cjs/resources/stock_line_items.d.ts +1 -0
- package/lib/cjs/resources/stock_line_items.js +4 -1
- package/lib/cjs/resources/stock_locations.d.ts +1 -0
- package/lib/cjs/resources/stock_locations.js +4 -1
- package/lib/cjs/resources/stock_reservations.d.ts +1 -0
- package/lib/cjs/resources/stock_reservations.js +4 -1
- package/lib/cjs/resources/stock_transfers.d.ts +1 -0
- package/lib/cjs/resources/stock_transfers.js +4 -1
- package/lib/cjs/resources/stripe_gateways.d.ts +1 -0
- package/lib/cjs/resources/stripe_gateways.js +4 -1
- package/lib/cjs/resources/stripe_payments.d.ts +1 -0
- package/lib/cjs/resources/stripe_payments.js +4 -1
- package/lib/cjs/resources/subscription_models.d.ts +1 -0
- package/lib/cjs/resources/subscription_models.js +4 -1
- package/lib/cjs/resources/tags.d.ts +1 -0
- package/lib/cjs/resources/tags.js +4 -1
- package/lib/cjs/resources/tax_calculators.d.ts +1 -0
- package/lib/cjs/resources/tax_calculators.js +4 -1
- package/lib/cjs/resources/tax_categories.d.ts +1 -0
- package/lib/cjs/resources/tax_categories.js +4 -1
- package/lib/cjs/resources/tax_rules.d.ts +1 -0
- package/lib/cjs/resources/tax_rules.js +4 -1
- package/lib/cjs/resources/taxjar_accounts.d.ts +1 -0
- package/lib/cjs/resources/taxjar_accounts.js +4 -1
- package/lib/cjs/resources/transactions.d.ts +1 -0
- package/lib/cjs/resources/transactions.js +4 -1
- package/lib/cjs/resources/versions.d.ts +1 -0
- package/lib/cjs/resources/versions.js +4 -1
- package/lib/cjs/resources/voids.d.ts +1 -0
- package/lib/cjs/resources/voids.js +4 -1
- package/lib/cjs/resources/webhooks.d.ts +1 -0
- package/lib/cjs/resources/webhooks.js +4 -1
- package/lib/cjs/resources/wire_transfers.d.ts +1 -0
- package/lib/cjs/resources/wire_transfers.js +4 -1
- package/lib/cjs/static.js +0 -1
- package/lib/cjs/util.js +0 -1
- package/lib/esm/api.d.ts +0 -3
- package/lib/esm/api.js +0 -10
- package/lib/esm/client.d.ts +6 -14
- package/lib/esm/client.js +43 -90
- package/lib/esm/commercelayer.d.ts +126 -125
- package/lib/esm/commercelayer.js +270 -171
- package/lib/esm/common.js +1 -12
- package/lib/esm/config.js +0 -2
- package/lib/esm/debug.js +0 -21
- package/lib/esm/error.d.ts +6 -7
- package/lib/esm/error.js +44 -35
- package/lib/esm/fetch.d.ts +13 -0
- package/lib/esm/fetch.js +46 -0
- package/lib/esm/index.js +0 -2
- package/lib/esm/interceptor.d.ts +22 -10
- package/lib/esm/jsonapi.js +0 -2
- package/lib/esm/model.d.ts +0 -3
- package/lib/esm/model.js +0 -1
- package/lib/esm/query.d.ts +2 -1
- package/lib/esm/query.js +7 -7
- package/lib/esm/resource.d.ts +2 -5
- package/lib/esm/resource.js +40 -76
- package/lib/esm/resources/addresses.d.ts +1 -0
- package/lib/esm/resources/addresses.js +5 -2
- package/lib/esm/resources/adjustments.d.ts +1 -0
- package/lib/esm/resources/adjustments.js +5 -2
- package/lib/esm/resources/adyen_gateways.d.ts +1 -0
- package/lib/esm/resources/adyen_gateways.js +5 -2
- package/lib/esm/resources/adyen_payments.d.ts +1 -0
- package/lib/esm/resources/adyen_payments.js +5 -2
- package/lib/esm/resources/application.d.ts +1 -0
- package/lib/esm/resources/application.js +5 -2
- package/lib/esm/resources/attachments.d.ts +1 -0
- package/lib/esm/resources/attachments.js +5 -2
- package/lib/esm/resources/authorizations.d.ts +1 -0
- package/lib/esm/resources/authorizations.js +5 -2
- package/lib/esm/resources/avalara_accounts.d.ts +1 -0
- package/lib/esm/resources/avalara_accounts.js +5 -2
- package/lib/esm/resources/axerve_gateways.d.ts +1 -0
- package/lib/esm/resources/axerve_gateways.js +5 -2
- package/lib/esm/resources/axerve_payments.d.ts +1 -0
- package/lib/esm/resources/axerve_payments.js +5 -2
- package/lib/esm/resources/billing_info_validation_rules.d.ts +1 -0
- package/lib/esm/resources/billing_info_validation_rules.js +5 -2
- package/lib/esm/resources/bing_geocoders.d.ts +1 -0
- package/lib/esm/resources/bing_geocoders.js +5 -2
- package/lib/esm/resources/braintree_gateways.d.ts +1 -0
- package/lib/esm/resources/braintree_gateways.js +5 -2
- package/lib/esm/resources/braintree_payments.d.ts +1 -0
- package/lib/esm/resources/braintree_payments.js +5 -2
- package/lib/esm/resources/bundles.d.ts +1 -0
- package/lib/esm/resources/bundles.js +5 -2
- package/lib/esm/resources/buy_x_pay_y_promotions.d.ts +1 -0
- package/lib/esm/resources/buy_x_pay_y_promotions.js +5 -2
- package/lib/esm/resources/captures.d.ts +1 -0
- package/lib/esm/resources/captures.js +5 -2
- package/lib/esm/resources/carrier_accounts.d.ts +1 -0
- package/lib/esm/resources/carrier_accounts.js +5 -2
- package/lib/esm/resources/checkout_com_gateways.d.ts +1 -0
- package/lib/esm/resources/checkout_com_gateways.js +5 -2
- package/lib/esm/resources/checkout_com_payments.d.ts +1 -0
- package/lib/esm/resources/checkout_com_payments.js +5 -2
- package/lib/esm/resources/cleanups.d.ts +1 -0
- package/lib/esm/resources/cleanups.js +5 -2
- package/lib/esm/resources/coupon_codes_promotion_rules.d.ts +1 -0
- package/lib/esm/resources/coupon_codes_promotion_rules.js +5 -2
- package/lib/esm/resources/coupon_recipients.d.ts +1 -0
- package/lib/esm/resources/coupon_recipients.js +5 -2
- package/lib/esm/resources/coupons.d.ts +1 -0
- package/lib/esm/resources/coupons.js +5 -2
- package/lib/esm/resources/custom_promotion_rules.d.ts +1 -0
- package/lib/esm/resources/custom_promotion_rules.js +5 -2
- package/lib/esm/resources/customer_addresses.d.ts +1 -0
- package/lib/esm/resources/customer_addresses.js +5 -2
- package/lib/esm/resources/customer_groups.d.ts +1 -0
- package/lib/esm/resources/customer_groups.js +5 -2
- package/lib/esm/resources/customer_password_resets.d.ts +1 -0
- package/lib/esm/resources/customer_password_resets.js +5 -2
- package/lib/esm/resources/customer_payment_sources.d.ts +1 -0
- package/lib/esm/resources/customer_payment_sources.js +5 -2
- package/lib/esm/resources/customer_subscriptions.d.ts +1 -0
- package/lib/esm/resources/customer_subscriptions.js +5 -2
- package/lib/esm/resources/customers.d.ts +1 -0
- package/lib/esm/resources/customers.js +5 -2
- package/lib/esm/resources/delivery_lead_times.d.ts +1 -0
- package/lib/esm/resources/delivery_lead_times.js +5 -2
- package/lib/esm/resources/event_callbacks.d.ts +1 -0
- package/lib/esm/resources/event_callbacks.js +5 -2
- package/lib/esm/resources/events.d.ts +1 -0
- package/lib/esm/resources/events.js +5 -2
- package/lib/esm/resources/exports.d.ts +1 -0
- package/lib/esm/resources/exports.js +5 -2
- package/lib/esm/resources/external_gateways.d.ts +1 -0
- package/lib/esm/resources/external_gateways.js +5 -2
- package/lib/esm/resources/external_payments.d.ts +1 -0
- package/lib/esm/resources/external_payments.js +5 -2
- package/lib/esm/resources/external_promotions.d.ts +1 -0
- package/lib/esm/resources/external_promotions.js +5 -2
- package/lib/esm/resources/external_tax_calculators.d.ts +1 -0
- package/lib/esm/resources/external_tax_calculators.js +5 -2
- package/lib/esm/resources/fixed_amount_promotions.d.ts +1 -0
- package/lib/esm/resources/fixed_amount_promotions.js +5 -2
- package/lib/esm/resources/fixed_price_promotions.d.ts +1 -0
- package/lib/esm/resources/fixed_price_promotions.js +5 -2
- package/lib/esm/resources/free_gift_promotions.d.ts +1 -0
- package/lib/esm/resources/free_gift_promotions.js +5 -2
- package/lib/esm/resources/free_shipping_promotions.d.ts +1 -0
- package/lib/esm/resources/free_shipping_promotions.js +5 -2
- package/lib/esm/resources/geocoders.d.ts +1 -0
- package/lib/esm/resources/geocoders.js +5 -2
- package/lib/esm/resources/gift_card_recipients.d.ts +1 -0
- package/lib/esm/resources/gift_card_recipients.js +5 -2
- package/lib/esm/resources/gift_cards.d.ts +1 -0
- package/lib/esm/resources/gift_cards.js +5 -2
- package/lib/esm/resources/google_geocoders.d.ts +1 -0
- package/lib/esm/resources/google_geocoders.js +5 -2
- package/lib/esm/resources/imports.d.ts +1 -0
- package/lib/esm/resources/imports.js +5 -2
- package/lib/esm/resources/in_stock_subscriptions.d.ts +1 -0
- package/lib/esm/resources/in_stock_subscriptions.js +5 -2
- package/lib/esm/resources/inventory_models.d.ts +1 -0
- package/lib/esm/resources/inventory_models.js +5 -2
- package/lib/esm/resources/inventory_return_locations.d.ts +1 -0
- package/lib/esm/resources/inventory_return_locations.js +5 -2
- package/lib/esm/resources/inventory_stock_locations.d.ts +1 -0
- package/lib/esm/resources/inventory_stock_locations.js +5 -2
- package/lib/esm/resources/klarna_gateways.d.ts +1 -0
- package/lib/esm/resources/klarna_gateways.js +5 -2
- package/lib/esm/resources/klarna_payments.d.ts +1 -0
- package/lib/esm/resources/klarna_payments.js +5 -2
- package/lib/esm/resources/line_item_options.d.ts +1 -0
- package/lib/esm/resources/line_item_options.js +5 -2
- package/lib/esm/resources/line_items.d.ts +1 -0
- package/lib/esm/resources/line_items.js +5 -2
- package/lib/esm/resources/manual_gateways.d.ts +1 -0
- package/lib/esm/resources/manual_gateways.js +5 -2
- package/lib/esm/resources/manual_tax_calculators.d.ts +1 -0
- package/lib/esm/resources/manual_tax_calculators.js +5 -2
- package/lib/esm/resources/markets.d.ts +1 -0
- package/lib/esm/resources/markets.js +5 -2
- package/lib/esm/resources/merchants.d.ts +1 -0
- package/lib/esm/resources/merchants.js +5 -2
- package/lib/esm/resources/order_amount_promotion_rules.d.ts +1 -0
- package/lib/esm/resources/order_amount_promotion_rules.js +5 -2
- package/lib/esm/resources/order_copies.d.ts +1 -0
- package/lib/esm/resources/order_copies.js +5 -2
- package/lib/esm/resources/order_factories.d.ts +1 -0
- package/lib/esm/resources/order_factories.js +5 -2
- package/lib/esm/resources/order_subscription_items.d.ts +1 -0
- package/lib/esm/resources/order_subscription_items.js +5 -2
- package/lib/esm/resources/order_subscriptions.d.ts +1 -0
- package/lib/esm/resources/order_subscriptions.js +5 -2
- package/lib/esm/resources/order_validation_rules.d.ts +1 -0
- package/lib/esm/resources/order_validation_rules.js +5 -2
- package/lib/esm/resources/orders.d.ts +1 -0
- package/lib/esm/resources/orders.js +5 -2
- package/lib/esm/resources/organization.d.ts +1 -0
- package/lib/esm/resources/organization.js +5 -2
- package/lib/esm/resources/packages.d.ts +1 -0
- package/lib/esm/resources/packages.js +5 -2
- package/lib/esm/resources/parcel_line_items.d.ts +1 -0
- package/lib/esm/resources/parcel_line_items.js +5 -2
- package/lib/esm/resources/parcels.d.ts +1 -0
- package/lib/esm/resources/parcels.js +5 -2
- package/lib/esm/resources/payment_gateways.d.ts +1 -0
- package/lib/esm/resources/payment_gateways.js +5 -2
- package/lib/esm/resources/payment_methods.d.ts +1 -0
- package/lib/esm/resources/payment_methods.js +5 -2
- package/lib/esm/resources/payment_options.d.ts +1 -0
- package/lib/esm/resources/payment_options.js +5 -2
- package/lib/esm/resources/paypal_gateways.d.ts +1 -0
- package/lib/esm/resources/paypal_gateways.js +5 -2
- package/lib/esm/resources/paypal_payments.d.ts +1 -0
- package/lib/esm/resources/paypal_payments.js +5 -2
- package/lib/esm/resources/percentage_discount_promotions.d.ts +1 -0
- package/lib/esm/resources/percentage_discount_promotions.js +5 -2
- package/lib/esm/resources/price_frequency_tiers.d.ts +1 -0
- package/lib/esm/resources/price_frequency_tiers.js +5 -2
- package/lib/esm/resources/price_lists.d.ts +1 -0
- package/lib/esm/resources/price_lists.js +5 -2
- package/lib/esm/resources/price_tiers.d.ts +1 -0
- package/lib/esm/resources/price_tiers.js +5 -2
- package/lib/esm/resources/price_volume_tiers.d.ts +1 -0
- package/lib/esm/resources/price_volume_tiers.js +5 -2
- package/lib/esm/resources/prices.d.ts +1 -0
- package/lib/esm/resources/prices.js +5 -2
- package/lib/esm/resources/promotion_rules.d.ts +1 -0
- package/lib/esm/resources/promotion_rules.js +5 -2
- package/lib/esm/resources/promotions.d.ts +1 -0
- package/lib/esm/resources/promotions.js +5 -2
- package/lib/esm/resources/recurring_order_copies.d.ts +1 -0
- package/lib/esm/resources/recurring_order_copies.js +5 -2
- package/lib/esm/resources/refunds.d.ts +1 -0
- package/lib/esm/resources/refunds.js +5 -2
- package/lib/esm/resources/reserved_stocks.d.ts +1 -0
- package/lib/esm/resources/reserved_stocks.js +5 -2
- package/lib/esm/resources/resource_errors.d.ts +1 -0
- package/lib/esm/resources/resource_errors.js +5 -2
- package/lib/esm/resources/return_line_items.d.ts +1 -0
- package/lib/esm/resources/return_line_items.js +5 -2
- package/lib/esm/resources/returns.d.ts +1 -0
- package/lib/esm/resources/returns.js +5 -2
- package/lib/esm/resources/satispay_gateways.d.ts +1 -0
- package/lib/esm/resources/satispay_gateways.js +5 -2
- package/lib/esm/resources/satispay_payments.d.ts +1 -0
- package/lib/esm/resources/satispay_payments.js +5 -2
- package/lib/esm/resources/shipments.d.ts +1 -0
- package/lib/esm/resources/shipments.js +5 -2
- package/lib/esm/resources/shipping_categories.d.ts +1 -0
- package/lib/esm/resources/shipping_categories.js +5 -2
- package/lib/esm/resources/shipping_method_tiers.d.ts +1 -0
- package/lib/esm/resources/shipping_method_tiers.js +5 -2
- package/lib/esm/resources/shipping_methods.d.ts +1 -0
- package/lib/esm/resources/shipping_methods.js +5 -2
- package/lib/esm/resources/shipping_weight_tiers.d.ts +1 -0
- package/lib/esm/resources/shipping_weight_tiers.js +5 -2
- package/lib/esm/resources/shipping_zones.d.ts +1 -0
- package/lib/esm/resources/shipping_zones.js +5 -2
- package/lib/esm/resources/sku_list_items.d.ts +1 -0
- package/lib/esm/resources/sku_list_items.js +5 -2
- package/lib/esm/resources/sku_list_promotion_rules.d.ts +1 -0
- package/lib/esm/resources/sku_list_promotion_rules.js +5 -2
- package/lib/esm/resources/sku_lists.d.ts +1 -0
- package/lib/esm/resources/sku_lists.js +5 -2
- package/lib/esm/resources/sku_options.d.ts +1 -0
- package/lib/esm/resources/sku_options.js +5 -2
- package/lib/esm/resources/skus.d.ts +1 -0
- package/lib/esm/resources/skus.js +5 -2
- package/lib/esm/resources/stock_items.d.ts +1 -0
- package/lib/esm/resources/stock_items.js +5 -2
- package/lib/esm/resources/stock_line_items.d.ts +1 -0
- package/lib/esm/resources/stock_line_items.js +5 -2
- package/lib/esm/resources/stock_locations.d.ts +1 -0
- package/lib/esm/resources/stock_locations.js +5 -2
- package/lib/esm/resources/stock_reservations.d.ts +1 -0
- package/lib/esm/resources/stock_reservations.js +5 -2
- package/lib/esm/resources/stock_transfers.d.ts +1 -0
- package/lib/esm/resources/stock_transfers.js +5 -2
- package/lib/esm/resources/stripe_gateways.d.ts +1 -0
- package/lib/esm/resources/stripe_gateways.js +5 -2
- package/lib/esm/resources/stripe_payments.d.ts +1 -0
- package/lib/esm/resources/stripe_payments.js +5 -2
- package/lib/esm/resources/subscription_models.d.ts +1 -0
- package/lib/esm/resources/subscription_models.js +5 -2
- package/lib/esm/resources/tags.d.ts +1 -0
- package/lib/esm/resources/tags.js +5 -2
- package/lib/esm/resources/tax_calculators.d.ts +1 -0
- package/lib/esm/resources/tax_calculators.js +5 -2
- package/lib/esm/resources/tax_categories.d.ts +1 -0
- package/lib/esm/resources/tax_categories.js +5 -2
- package/lib/esm/resources/tax_rules.d.ts +1 -0
- package/lib/esm/resources/tax_rules.js +5 -2
- package/lib/esm/resources/taxjar_accounts.d.ts +1 -0
- package/lib/esm/resources/taxjar_accounts.js +5 -2
- package/lib/esm/resources/transactions.d.ts +1 -0
- package/lib/esm/resources/transactions.js +5 -2
- package/lib/esm/resources/versions.d.ts +1 -0
- package/lib/esm/resources/versions.js +5 -2
- package/lib/esm/resources/voids.d.ts +1 -0
- package/lib/esm/resources/voids.js +5 -2
- package/lib/esm/resources/webhooks.d.ts +1 -0
- package/lib/esm/resources/webhooks.js +5 -2
- package/lib/esm/resources/wire_transfers.d.ts +1 -0
- package/lib/esm/resources/wire_transfers.js +5 -2
- package/lib/esm/static.js +0 -1
- package/lib/esm/util.js +1 -27
- package/lib/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +20 -17
package/lib/esm/error.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import
|
1
|
+
import { FetchError } from './fetch';
|
2
2
|
var ErrorType;
|
3
3
|
(function (ErrorType) {
|
4
4
|
ErrorType["CLIENT"] = "client";
|
@@ -6,64 +6,73 @@ var ErrorType;
|
|
6
6
|
ErrorType["RESPONSE"] = "response";
|
7
7
|
ErrorType["CANCEL"] = "cancel";
|
8
8
|
ErrorType["PARSE"] = "parse";
|
9
|
-
ErrorType["
|
9
|
+
ErrorType["TIMEOUT"] = "timeout";
|
10
10
|
})(ErrorType || (ErrorType = {}));
|
11
11
|
class SdkError extends Error {
|
12
|
+
static NAME = 'SdkError';
|
12
13
|
static isSdkError(error) {
|
13
14
|
return error && [SdkError.NAME, ApiError.NAME].includes(error.name) && Object.values(ErrorType).includes(error.type);
|
14
15
|
}
|
16
|
+
type;
|
17
|
+
code;
|
18
|
+
source;
|
15
19
|
constructor(error) {
|
16
20
|
super(error.message);
|
17
|
-
this.name = SdkError.NAME;
|
18
|
-
this.type = error.type || ErrorType.
|
21
|
+
this.name = SdkError.NAME;
|
22
|
+
this.type = error.type || ErrorType.CLIENT;
|
19
23
|
}
|
20
24
|
}
|
21
|
-
SdkError.NAME = 'SdkError';
|
22
25
|
class ApiError extends SdkError {
|
26
|
+
static NAME = 'ApiError';
|
23
27
|
static isApiError(error) {
|
24
28
|
return SdkError.isSdkError(error) && (error.name === ApiError.NAME) && (error.type === ErrorType.RESPONSE);
|
25
29
|
}
|
30
|
+
errors = [];
|
31
|
+
status;
|
32
|
+
statusText;
|
26
33
|
constructor(error) {
|
27
34
|
super({ ...error, type: ErrorType.RESPONSE });
|
28
|
-
this.
|
29
|
-
this.name = ApiError.NAME; // this.constructor.name
|
35
|
+
this.name = ApiError.NAME;
|
30
36
|
}
|
31
37
|
first() {
|
32
|
-
|
33
|
-
return (((_a = this.errors) === null || _a === void 0 ? void 0 : _a.length) > 0) ? this.errors[0] : undefined;
|
38
|
+
return (this.errors?.length > 0) ? this.errors[0] : undefined;
|
34
39
|
}
|
35
40
|
}
|
36
|
-
|
41
|
+
const isRequestError = (error) => {
|
42
|
+
return error instanceof TypeError;
|
43
|
+
};
|
44
|
+
const isCancelError = (error) => {
|
45
|
+
return (error instanceof DOMException) && (error.name === 'AbortError');
|
46
|
+
};
|
47
|
+
const isTimeoutError = (error) => {
|
48
|
+
return (error instanceof DOMException) && (error.name === 'TimeoutError');
|
49
|
+
};
|
37
50
|
const handleError = (error) => {
|
38
51
|
let sdkError = new SdkError({ message: error.message });
|
39
|
-
if (
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
apiError.
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
else if (error.request) {
|
53
|
-
// The request was made but no response was received
|
54
|
-
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of http.ClientRequest in node.js
|
55
|
-
sdkError.type = ErrorType.REQUEST;
|
56
|
-
sdkError.request = error.request;
|
57
|
-
}
|
58
|
-
else {
|
59
|
-
// Something happened in setting up the request that triggered an Error
|
60
|
-
sdkError.type = ErrorType.CLIENT;
|
61
|
-
}
|
52
|
+
if (FetchError.isFetchError(error)) {
|
53
|
+
const apiError = new ApiError(sdkError);
|
54
|
+
apiError.type = ErrorType.RESPONSE;
|
55
|
+
apiError.status = error.status;
|
56
|
+
apiError.statusText = error.statusText;
|
57
|
+
apiError.code = String(apiError.status);
|
58
|
+
apiError.errors = error.errors || [];
|
59
|
+
if (!apiError.message && apiError.statusText)
|
60
|
+
apiError.message = apiError.statusText;
|
61
|
+
sdkError = apiError;
|
62
|
+
}
|
63
|
+
else if (isRequestError(error)) {
|
64
|
+
sdkError.type = ErrorType.REQUEST;
|
62
65
|
}
|
63
|
-
else if (
|
66
|
+
else if (isCancelError(error)) {
|
64
67
|
sdkError.type = ErrorType.CANCEL;
|
65
|
-
|
68
|
+
}
|
69
|
+
else if (isTimeoutError(error)) {
|
70
|
+
sdkError.type = ErrorType.TIMEOUT;
|
71
|
+
}
|
72
|
+
else {
|
73
|
+
sdkError.type = ErrorType.CLIENT;
|
66
74
|
sdkError.source = error;
|
75
|
+
}
|
67
76
|
throw sdkError;
|
68
77
|
};
|
69
78
|
export { SdkError, ApiError, ErrorType, handleError };
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import type { DocWithData } from 'jsonapi-typescript';
|
2
|
+
import type { InterceptorManager } from './interceptor';
|
3
|
+
export type FetchResponse = DocWithData;
|
4
|
+
export type FetchOptions = RequestInit;
|
5
|
+
export declare class FetchError extends Error {
|
6
|
+
#private;
|
7
|
+
static isFetchError: (error: any) => error is FetchError;
|
8
|
+
constructor(status: number, statusText: string, body?: any);
|
9
|
+
get errors(): any[] | undefined;
|
10
|
+
get status(): number;
|
11
|
+
get statusText(): string;
|
12
|
+
}
|
13
|
+
export declare const fetchURL: (url: URL, options: FetchOptions, interceptors?: InterceptorManager) => Promise<FetchResponse>;
|
package/lib/esm/fetch.js
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
import Debug from './debug';
|
2
|
+
const debug = Debug('fetch');
|
3
|
+
export class FetchError extends Error {
|
4
|
+
static isFetchError = (error) => {
|
5
|
+
return error instanceof FetchError;
|
6
|
+
};
|
7
|
+
#errors;
|
8
|
+
#status;
|
9
|
+
#statusText;
|
10
|
+
constructor(status, statusText, body) {
|
11
|
+
super(statusText);
|
12
|
+
this.#status = status;
|
13
|
+
this.#statusText = statusText;
|
14
|
+
if (body)
|
15
|
+
this.#errors = body.errors;
|
16
|
+
}
|
17
|
+
get errors() { return this.#errors; }
|
18
|
+
get status() { return this.#status; }
|
19
|
+
get statusText() { return this.#statusText; }
|
20
|
+
}
|
21
|
+
export const fetchURL = async (url, options, interceptors) => {
|
22
|
+
debug('fetch: %s, %O', url, options || {});
|
23
|
+
if (interceptors?.request?.onSuccess)
|
24
|
+
({ url, options } = await interceptors.request.onSuccess({ url, options }));
|
25
|
+
const request = new Request(url, options);
|
26
|
+
let response = await fetch(request);
|
27
|
+
if (response.ok) {
|
28
|
+
if (interceptors?.rawReader?.onSuccess)
|
29
|
+
await interceptors.rawReader.onSuccess(response);
|
30
|
+
if (interceptors?.response?.onSuccess)
|
31
|
+
response = await interceptors.response.onSuccess(response);
|
32
|
+
}
|
33
|
+
else {
|
34
|
+
if (interceptors?.rawReader?.onFailure)
|
35
|
+
await interceptors.rawReader.onFailure(response);
|
36
|
+
}
|
37
|
+
const responseBody = await response.json().catch(() => { });
|
38
|
+
if (!response.ok) {
|
39
|
+
let error = new FetchError(response.status, response.statusText, responseBody);
|
40
|
+
if (interceptors?.response?.onFailure)
|
41
|
+
error = await interceptors.response.onFailure(error);
|
42
|
+
if (error)
|
43
|
+
throw error;
|
44
|
+
}
|
45
|
+
return responseBody;
|
46
|
+
};
|
package/lib/esm/index.js
CHANGED
package/lib/esm/interceptor.d.ts
CHANGED
@@ -1,25 +1,37 @@
|
|
1
|
-
import type {
|
1
|
+
import type { FetchError, FetchOptions } from "./fetch";
|
2
|
+
type InterceptorEventManager<S extends (RequestInterceptor | ResponseInterceptor), F extends (ErrorInterceptor | ResponseInterceptor)> = {
|
3
|
+
onSuccess?: S;
|
4
|
+
onFailure?: F;
|
5
|
+
};
|
6
|
+
type RequestEventManager = InterceptorEventManager<RequestInterceptor, ErrorInterceptor>;
|
7
|
+
type ResponseEventManager = InterceptorEventManager<ResponseInterceptor, ErrorInterceptor>;
|
8
|
+
type ErrorEventManager = InterceptorEventManager<ResponseInterceptor, ResponseInterceptor>;
|
2
9
|
type InterceptorManager = {
|
3
|
-
request
|
4
|
-
response
|
10
|
+
request?: RequestEventManager;
|
11
|
+
response?: ResponseEventManager;
|
12
|
+
rawReader?: ErrorEventManager;
|
13
|
+
};
|
14
|
+
type RequestObj = {
|
15
|
+
url: URL;
|
16
|
+
options: FetchOptions;
|
5
17
|
};
|
6
|
-
type RequestObj = AxiosRequestConfig;
|
7
18
|
type RequestInterceptor = (request: RequestObj) => RequestObj | Promise<RequestObj>;
|
8
|
-
type ResponseObj =
|
19
|
+
type ResponseObj = Response;
|
9
20
|
type ResponseInterceptor = (response: ResponseObj) => ResponseObj | Promise<ResponseObj>;
|
10
21
|
type ApiHeadersList = 'x-ratelimit-limit' | 'x-ratelimit-count' | 'x-ratelimit-period' | 'x-ratelimit-interval' | 'x-ratelimit-remaining';
|
11
22
|
type ApiHeaders = {
|
12
23
|
[key in ApiHeadersList]: string | number | boolean;
|
13
24
|
};
|
14
|
-
type HeadersObj =
|
15
|
-
type ErrorObj =
|
25
|
+
type HeadersObj = Record<string, string> | ApiHeaders;
|
26
|
+
type ErrorObj = FetchError;
|
16
27
|
type ErrorInterceptor = (error: ErrorObj) => ErrorObj | Promise<ErrorObj>;
|
17
28
|
type InterceptorType = 'request' | 'response';
|
18
29
|
export type { InterceptorManager, RequestInterceptor, ResponseInterceptor, ErrorInterceptor, InterceptorType };
|
19
30
|
export type { RequestObj, ResponseObj, ErrorObj, HeadersObj };
|
20
31
|
type RawResponseReader = {
|
21
|
-
id
|
22
|
-
rawResponse
|
23
|
-
headers
|
32
|
+
id?: number;
|
33
|
+
rawResponse?: any;
|
34
|
+
headers?: HeadersObj;
|
35
|
+
ok: boolean;
|
24
36
|
};
|
25
37
|
export type { RawResponseReader };
|
package/lib/esm/jsonapi.js
CHANGED
@@ -2,7 +2,6 @@ import { isResourceId, isResourceType } from './common';
|
|
2
2
|
import config from './config';
|
3
3
|
import Debug from './debug';
|
4
4
|
const debug = Debug('jsonapi');
|
5
|
-
// DENORMALIZATION
|
6
5
|
const denormalize = (response) => {
|
7
6
|
let denormalizedResponse;
|
8
7
|
if (response.links)
|
@@ -53,7 +52,6 @@ const denormalizeResource = (res, included, chain = []) => {
|
|
53
52
|
debug('denormalized resource: %O', resource);
|
54
53
|
return resource;
|
55
54
|
};
|
56
|
-
// NORMALIZATION
|
57
55
|
const normalize = (resource) => {
|
58
56
|
debug('normalize resource: %O', resource);
|
59
57
|
const attributes = {};
|
package/lib/esm/model.d.ts
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
/**
|
2
|
-
* ©2024 Commerce Layer Inc.
|
3
|
-
**/
|
4
1
|
export type { Address, AddressCreate, AddressUpdate } from './resources/addresses';
|
5
2
|
export type { Adjustment, AdjustmentCreate, AdjustmentUpdate } from './resources/adjustments';
|
6
3
|
export type { AdyenGateway, AdyenGatewayCreate, AdyenGatewayUpdate } from './resources/adyen_gateways';
|
package/lib/esm/model.js
CHANGED
package/lib/esm/query.d.ts
CHANGED
@@ -14,4 +14,5 @@ type QueryParams = QueryParamsRetrieve | QueryParamsList;
|
|
14
14
|
export type { QueryParamsRetrieve, QueryParamsList, QueryParams, QueryFilter };
|
15
15
|
declare const isParamsList: (params: any) => params is QueryParamsList;
|
16
16
|
declare const generateQueryStringParams: (params: QueryParamsRetrieve | QueryParamsList | undefined, res: string | ResourceType) => Record<string, string>;
|
17
|
-
|
17
|
+
declare const generateSearchString: (params?: QueryParams, questionMark?: boolean) => string;
|
18
|
+
export { generateQueryStringParams, isParamsList, generateSearchString };
|
package/lib/esm/query.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import Debug from './debug';
|
2
1
|
import { ErrorType, SdkError } from "./error";
|
2
|
+
import Debug from './debug';
|
3
3
|
const debug = Debug('query');
|
4
4
|
const arrayFilters = ['_any', '_all', '_in'];
|
5
5
|
const objectFilters = ['_jcont'];
|
@@ -11,10 +11,8 @@ const generateQueryStringParams = (params, res) => {
|
|
11
11
|
const qp = {};
|
12
12
|
if (!params)
|
13
13
|
return qp;
|
14
|
-
// Include
|
15
14
|
if (params.include)
|
16
15
|
qp.include = params.include.join(',');
|
17
|
-
// Fields
|
18
16
|
if (params.fields) {
|
19
17
|
if (Array.isArray(params.fields))
|
20
18
|
params.fields = { [res.type || res]: params.fields };
|
@@ -23,19 +21,16 @@ const generateQueryStringParams = (params, res) => {
|
|
23
21
|
});
|
24
22
|
}
|
25
23
|
if (isParamsList(params)) {
|
26
|
-
// Sort
|
27
24
|
if (params.sort) {
|
28
25
|
if (Array.isArray(params.sort))
|
29
26
|
qp.sort = params.sort.join(',');
|
30
27
|
else
|
31
28
|
qp.sort = Object.entries(params.sort).map(([k, v]) => `${v === 'desc' ? '-' : ''}${k}`).join(',');
|
32
29
|
}
|
33
|
-
// Page
|
34
30
|
if (params.pageNumber)
|
35
31
|
qp['page[number]'] = String(params.pageNumber);
|
36
32
|
if (params.pageSize)
|
37
33
|
qp['page[size]'] = String(params.pageSize);
|
38
|
-
// Filters
|
39
34
|
if (params.filters) {
|
40
35
|
Object.entries(params.filters).forEach(([p, v]) => {
|
41
36
|
const filter = p.substring(p.lastIndexOf('_'));
|
@@ -59,4 +54,9 @@ const generateQueryStringParams = (params, res) => {
|
|
59
54
|
debug('query string params: %O', qp);
|
60
55
|
return qp;
|
61
56
|
};
|
62
|
-
|
57
|
+
const generateSearchString = (params, questionMark = true) => {
|
58
|
+
if (!params || (Object.keys(params).length === 0))
|
59
|
+
return '';
|
60
|
+
return `${questionMark ? '?' : ''}${Object.entries(params).map(([key, val]) => `${key}=${String(val)}`).join('&')}`;
|
61
|
+
};
|
62
|
+
export { generateQueryStringParams, isParamsList, generateSearchString };
|
package/lib/esm/resource.d.ts
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
import ApiClient, { type ApiClientInitConfig } from './client';
|
2
2
|
import type { QueryParamsRetrieve, QueryParamsList, QueryFilter, QueryParams } from './query';
|
3
3
|
import type { ResourceTypeLock } from './api';
|
4
|
-
import type { InterceptorManager } from './interceptor';
|
5
4
|
type ResourceNull = {
|
6
5
|
id: null;
|
7
6
|
} & ResourceType;
|
@@ -53,7 +52,6 @@ type ResourcesConfig = Partial<ResourcesInitConfig>;
|
|
53
52
|
declare class ResourceAdapter {
|
54
53
|
#private;
|
55
54
|
constructor(config: ResourcesInitConfig);
|
56
|
-
get interceptors(): InterceptorManager;
|
57
55
|
private localConfig;
|
58
56
|
config(config: ResourcesConfig): ResourceAdapter;
|
59
57
|
get client(): Readonly<ApiClient>;
|
@@ -70,10 +68,9 @@ declare abstract class ApiResourceBase<R extends Resource> {
|
|
70
68
|
protected readonly resources: ResourceAdapter;
|
71
69
|
constructor(adapter: ResourceAdapter);
|
72
70
|
abstract relationship(id: string | ResourceId | null): ResourceRel;
|
71
|
+
protected relationshipOneToOne<RR extends ResourceRel>(id: string | ResourceId | null): RR;
|
72
|
+
protected relationshipOneToMany<RR extends ResourceRel>(...ids: string[]): RR[];
|
73
73
|
abstract type(): ResourceTypeLock;
|
74
|
-
parse(resource: string, options?: {
|
75
|
-
ignoreSlug?: boolean;
|
76
|
-
}): R | R[];
|
77
74
|
update(resource: ResourceUpdate, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<R>;
|
78
75
|
}
|
79
76
|
declare abstract class ApiResource<R extends Resource> extends ApiResourceBase<R> {
|
package/lib/esm/resource.js
CHANGED
@@ -1,23 +1,11 @@
|
|
1
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
2
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
5
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
6
|
-
};
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
11
|
-
};
|
12
|
-
var _ResourceAdapter_client, _ResourceAdapter_config;
|
13
1
|
import ApiClient from './client';
|
14
2
|
import { denormalize, normalize } from './jsonapi';
|
15
3
|
import { generateQueryStringParams, isParamsList } from './query';
|
16
4
|
import config from './config';
|
17
|
-
import { ErrorType, SdkError } from './error';
|
18
5
|
import Debug from './debug';
|
19
6
|
const debug = Debug('resource');
|
20
7
|
class ListResponse extends Array {
|
8
|
+
meta;
|
21
9
|
constructor(meta, data) {
|
22
10
|
super(...(data || []));
|
23
11
|
this.meta = meta;
|
@@ -33,100 +21,94 @@ class ListResponse extends Array {
|
|
33
21
|
get pageCount() { return this.meta.pageCount; }
|
34
22
|
}
|
35
23
|
class ResourceAdapter {
|
24
|
+
#client;
|
25
|
+
#config = {};
|
36
26
|
constructor(config) {
|
37
|
-
|
38
|
-
_ResourceAdapter_config.set(this, {});
|
39
|
-
__classPrivateFieldSet(this, _ResourceAdapter_client, ApiClient.create(config), "f");
|
27
|
+
this.#client = ApiClient.create(config);
|
40
28
|
this.localConfig(config);
|
41
29
|
}
|
42
|
-
get interceptors() { return __classPrivateFieldGet(this, _ResourceAdapter_client, "f").interceptors; }
|
43
30
|
localConfig(config) {
|
44
|
-
// if (typeof config.xyz !== 'undefined') this.#config.xyz = config.xyz
|
45
31
|
}
|
46
32
|
config(config) {
|
47
33
|
debug('config %o', config);
|
48
|
-
// ResourceAdapter config
|
49
34
|
this.localConfig(config);
|
50
|
-
|
51
|
-
__classPrivateFieldGet(this, _ResourceAdapter_client, "f").config(config);
|
35
|
+
this.#client.config(config);
|
52
36
|
return this;
|
53
37
|
}
|
54
38
|
get client() {
|
55
|
-
return
|
39
|
+
return this.#client;
|
56
40
|
}
|
57
41
|
async singleton(resource, params, options) {
|
58
42
|
debug('singleton: %o, %O, %O', resource, params || {}, options || {});
|
59
43
|
const queryParams = generateQueryStringParams(params, resource);
|
60
|
-
if (options
|
61
|
-
Object.assign(queryParams, options
|
62
|
-
const res = await
|
44
|
+
if (options?.params)
|
45
|
+
Object.assign(queryParams, options?.params);
|
46
|
+
const res = await this.#client.request('GET', `${resource.type}`, undefined, { ...options, params: queryParams });
|
63
47
|
const r = denormalize(res);
|
64
48
|
return r;
|
65
49
|
}
|
66
50
|
async retrieve(resource, params, options) {
|
67
51
|
debug('retrieve: %o, %O, %O', resource, params || {}, options || {});
|
68
52
|
const queryParams = generateQueryStringParams(params, resource);
|
69
|
-
if (options
|
70
|
-
Object.assign(queryParams, options
|
71
|
-
const res = await
|
53
|
+
if (options?.params)
|
54
|
+
Object.assign(queryParams, options?.params);
|
55
|
+
const res = await this.#client.request('GET', `${resource.type}/${resource.id}`, undefined, { ...options, params: queryParams });
|
72
56
|
const r = denormalize(res);
|
73
57
|
return r;
|
74
58
|
}
|
75
59
|
async list(resource, params, options) {
|
76
|
-
var _a, _b;
|
77
60
|
debug('list: %o, %O, %O', resource, params || {}, options || {});
|
78
61
|
const queryParams = generateQueryStringParams(params, resource);
|
79
|
-
if (options
|
80
|
-
Object.assign(queryParams, options
|
81
|
-
const res = await
|
62
|
+
if (options?.params)
|
63
|
+
Object.assign(queryParams, options?.params);
|
64
|
+
const res = await this.#client.request('GET', `${resource.type}`, undefined, { ...options, params: queryParams });
|
82
65
|
const r = denormalize(res);
|
83
66
|
const meta = {
|
84
|
-
pageCount: Number(
|
85
|
-
recordCount: Number(
|
86
|
-
currentPage:
|
87
|
-
recordsPerPage:
|
67
|
+
pageCount: Number(res.meta?.page_count),
|
68
|
+
recordCount: Number(res.meta?.record_count),
|
69
|
+
currentPage: params?.pageNumber || config.default.pageNumber,
|
70
|
+
recordsPerPage: params?.pageSize || config.default.pageSize
|
88
71
|
};
|
89
72
|
return new ListResponse(meta, r);
|
90
73
|
}
|
91
74
|
async create(resource, params, options) {
|
92
75
|
debug('create: %o, %O, %O', resource, params || {}, options || {});
|
93
76
|
const queryParams = generateQueryStringParams(params, resource);
|
94
|
-
if (options
|
95
|
-
Object.assign(queryParams, options
|
77
|
+
if (options?.params)
|
78
|
+
Object.assign(queryParams, options?.params);
|
96
79
|
const data = normalize(resource);
|
97
|
-
const res = await
|
80
|
+
const res = await this.#client.request('POST', resource.type, data, { ...options, params: queryParams });
|
98
81
|
const r = denormalize(res);
|
99
82
|
return r;
|
100
83
|
}
|
101
84
|
async update(resource, params, options) {
|
102
85
|
debug('update: %o, %O, %O', resource, params || {}, options || {});
|
103
86
|
const queryParams = generateQueryStringParams(params, resource);
|
104
|
-
if (options
|
105
|
-
Object.assign(queryParams, options
|
87
|
+
if (options?.params)
|
88
|
+
Object.assign(queryParams, options?.params);
|
106
89
|
const data = normalize(resource);
|
107
|
-
const res = await
|
90
|
+
const res = await this.#client.request('PATCH', `${resource.type}/${resource.id}`, data, { ...options, params: queryParams });
|
108
91
|
const r = denormalize(res);
|
109
92
|
return r;
|
110
93
|
}
|
111
94
|
async delete(resource, options) {
|
112
95
|
debug('delete: %o, %O', resource, options || {});
|
113
|
-
await
|
96
|
+
await this.#client.request('DELETE', `${resource.type}/${resource.id}`, undefined, options);
|
114
97
|
}
|
115
98
|
async fetch(resource, path, params, options) {
|
116
|
-
var _a, _b;
|
117
99
|
debug('fetch: %o, %O, %O', path, params || {}, options || {});
|
118
100
|
const queryParams = generateQueryStringParams(params, resource);
|
119
|
-
if (options
|
120
|
-
Object.assign(queryParams, options
|
121
|
-
const res = await
|
101
|
+
if (options?.params)
|
102
|
+
Object.assign(queryParams, options?.params);
|
103
|
+
const res = await this.#client.request('GET', path, undefined, { ...options, params: queryParams });
|
122
104
|
const r = denormalize(res);
|
123
105
|
if (Array.isArray(r)) {
|
124
106
|
const p = params;
|
125
107
|
const meta = {
|
126
|
-
pageCount: Number(
|
127
|
-
recordCount: Number(
|
128
|
-
currentPage:
|
129
|
-
recordsPerPage:
|
108
|
+
pageCount: Number(res.meta?.page_count),
|
109
|
+
recordCount: Number(res.meta?.record_count),
|
110
|
+
currentPage: p?.pageNumber || config.default.pageNumber,
|
111
|
+
recordsPerPage: p?.pageSize || config.default.pageSize
|
130
112
|
};
|
131
113
|
return new ListResponse(meta, r);
|
132
114
|
}
|
@@ -134,37 +116,19 @@ class ResourceAdapter {
|
|
134
116
|
return r;
|
135
117
|
}
|
136
118
|
}
|
137
|
-
_ResourceAdapter_client = new WeakMap(), _ResourceAdapter_config = new WeakMap();
|
138
119
|
class ApiResourceBase {
|
120
|
+
static TYPE;
|
121
|
+
resources;
|
139
122
|
constructor(adapter) {
|
140
123
|
debug('new resource instance: %s', this.type());
|
141
124
|
this.resources = adapter;
|
142
125
|
}
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
const rtype = (_a = res.data) === null || _a === void 0 ? void 0 : _a.type;
|
149
|
-
if (rtype !== this.type())
|
150
|
-
throw new SdkError({ message: `Invalid resource type [${rtype}]`, type: ErrorType.PARSE });
|
151
|
-
// Parse options
|
152
|
-
const { ignoreSlug } = options || {};
|
153
|
-
if (!ignoreSlug) {
|
154
|
-
const links = res.data.links.self;
|
155
|
-
if (!links || !String(links).match(`^${this.resources.client.baseUrl}/${this.type()}/*`))
|
156
|
-
throw new SdkError({ message: `Resource contains invalid links [${links}]`, type: ErrorType.PARSE });
|
157
|
-
}
|
158
|
-
return denormalize(res);
|
159
|
-
}
|
160
|
-
catch (error) {
|
161
|
-
if (SdkError.isSdkError(error))
|
162
|
-
throw error;
|
163
|
-
else
|
164
|
-
throw new SdkError({ message: `Payload parse error [${error.message}]`, type: ErrorType.PARSE });
|
165
|
-
}
|
126
|
+
relationshipOneToOne(id) {
|
127
|
+
return (((id === null) || (typeof id === 'string')) ? { id, type: this.type() } : { id: id.id, type: this.type() });
|
128
|
+
}
|
129
|
+
relationshipOneToMany(...ids) {
|
130
|
+
return (((ids === null) || (ids.length === 0) || (ids[0] === null)) ? [{ id: null, type: this.type() }] : ids.map(id => { return { id, type: this.type() }; }));
|
166
131
|
}
|
167
|
-
// reference, reference_origin and metadata attributes are always updatable
|
168
132
|
async update(resource, params, options) {
|
169
133
|
return this.resources.update({ ...resource, type: this.type() }, params, options);
|
170
134
|
}
|
@@ -97,6 +97,7 @@ declare class Addresses extends ApiResource<Address> {
|
|
97
97
|
versions(addressId: string | Address, params?: QueryParamsList, options?: ResourcesConfig): Promise<ListResponse<Version>>;
|
98
98
|
isAddress(resource: any): resource is Address;
|
99
99
|
relationship(id: string | ResourceId | null): AddressRel;
|
100
|
+
relationshipToMany(...ids: string[]): AddressRel[];
|
100
101
|
type(): AddressType;
|
101
102
|
}
|
102
103
|
export default Addresses;
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import { ApiResource } from '../resource';
|
2
2
|
class Addresses extends ApiResource {
|
3
|
+
static TYPE = 'addresses';
|
3
4
|
async create(resource, params, options) {
|
4
5
|
return this.resources.create({ ...resource, type: Addresses.TYPE }, params, options);
|
5
6
|
}
|
@@ -29,11 +30,13 @@ class Addresses extends ApiResource {
|
|
29
30
|
return resource.type && (resource.type === Addresses.TYPE);
|
30
31
|
}
|
31
32
|
relationship(id) {
|
32
|
-
return (
|
33
|
+
return super.relationshipOneToOne(id);
|
34
|
+
}
|
35
|
+
relationshipToMany(...ids) {
|
36
|
+
return super.relationshipOneToMany(...ids);
|
33
37
|
}
|
34
38
|
type() {
|
35
39
|
return Addresses.TYPE;
|
36
40
|
}
|
37
41
|
}
|
38
|
-
Addresses.TYPE = 'addresses';
|
39
42
|
export default Addresses;
|
@@ -36,6 +36,7 @@ declare class Adjustments extends ApiResource<Adjustment> {
|
|
36
36
|
versions(adjustmentId: string | Adjustment, params?: QueryParamsList, options?: ResourcesConfig): Promise<ListResponse<Version>>;
|
37
37
|
isAdjustment(resource: any): resource is Adjustment;
|
38
38
|
relationship(id: string | ResourceId | null): AdjustmentRel;
|
39
|
+
relationshipToMany(...ids: string[]): AdjustmentRel[];
|
39
40
|
type(): AdjustmentType;
|
40
41
|
}
|
41
42
|
export default Adjustments;
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import { ApiResource } from '../resource';
|
2
2
|
class Adjustments extends ApiResource {
|
3
|
+
static TYPE = 'adjustments';
|
3
4
|
async create(resource, params, options) {
|
4
5
|
return this.resources.create({ ...resource, type: Adjustments.TYPE }, params, options);
|
5
6
|
}
|
@@ -17,11 +18,13 @@ class Adjustments extends ApiResource {
|
|
17
18
|
return resource.type && (resource.type === Adjustments.TYPE);
|
18
19
|
}
|
19
20
|
relationship(id) {
|
20
|
-
return (
|
21
|
+
return super.relationshipOneToOne(id);
|
22
|
+
}
|
23
|
+
relationshipToMany(...ids) {
|
24
|
+
return super.relationshipOneToMany(...ids);
|
21
25
|
}
|
22
26
|
type() {
|
23
27
|
return Adjustments.TYPE;
|
24
28
|
}
|
25
29
|
}
|
26
|
-
Adjustments.TYPE = 'adjustments';
|
27
30
|
export default Adjustments;
|
@@ -54,6 +54,7 @@ declare class AdyenGateways extends ApiResource<AdyenGateway> {
|
|
54
54
|
adyen_payments(adyenGatewayId: string | AdyenGateway, params?: QueryParamsList, options?: ResourcesConfig): Promise<ListResponse<AdyenPayment>>;
|
55
55
|
isAdyenGateway(resource: any): resource is AdyenGateway;
|
56
56
|
relationship(id: string | ResourceId | null): AdyenGatewayRel;
|
57
|
+
relationshipToMany(...ids: string[]): AdyenGatewayRel[];
|
57
58
|
type(): AdyenGatewayType;
|
58
59
|
}
|
59
60
|
export default AdyenGateways;
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import { ApiResource } from '../resource';
|
2
2
|
class AdyenGateways extends ApiResource {
|
3
|
+
static TYPE = 'adyen_gateways';
|
3
4
|
async create(resource, params, options) {
|
4
5
|
return this.resources.create({ ...resource, type: AdyenGateways.TYPE }, params, options);
|
5
6
|
}
|
@@ -25,11 +26,13 @@ class AdyenGateways extends ApiResource {
|
|
25
26
|
return resource.type && (resource.type === AdyenGateways.TYPE);
|
26
27
|
}
|
27
28
|
relationship(id) {
|
28
|
-
return (
|
29
|
+
return super.relationshipOneToOne(id);
|
30
|
+
}
|
31
|
+
relationshipToMany(...ids) {
|
32
|
+
return super.relationshipOneToMany(...ids);
|
29
33
|
}
|
30
34
|
type() {
|
31
35
|
return AdyenGateways.TYPE;
|
32
36
|
}
|
33
37
|
}
|
34
|
-
AdyenGateways.TYPE = 'adyen_gateways';
|
35
38
|
export default AdyenGateways;
|