@merchi/sdk 1.40.2
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/.eslintrc.cjs +43 -0
- package/.turbo/turbo-build.log +1 -0
- package/.turbo/turbo-test.log +849 -0
- package/LICENSE +21 -0
- package/README.md +244 -0
- package/coverage/clover.xml +5057 -0
- package/coverage/coverage-final.json +133 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +191 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +210 -0
- package/coverage/lcov-report/src/constants/auto_assign_production_on_actions.ts.html +103 -0
- package/coverage/lcov-report/src/constants/call_to_actions.ts.html +127 -0
- package/coverage/lcov-report/src/constants/discount_types.ts.html +100 -0
- package/coverage/lcov-report/src/constants/domain_types.ts.html +121 -0
- package/coverage/lcov-report/src/constants/errors.ts.html +181 -0
- package/coverage/lcov-report/src/constants/event_types.ts.html +100 -0
- package/coverage/lcov-report/src/constants/field_types.ts.html +133 -0
- package/coverage/lcov-report/src/constants/index.html +551 -0
- package/coverage/lcov-report/src/constants/index.ts.html +238 -0
- package/coverage/lcov-report/src/constants/input_types.ts.html +124 -0
- package/coverage/lcov-report/src/constants/inventory_statuses.ts.html +103 -0
- package/coverage/lcov-report/src/constants/invoice_types.ts.html +100 -0
- package/coverage/lcov-report/src/constants/item_types.ts.html +100 -0
- package/coverage/lcov-report/src/constants/job/drafting_status.ts.html +106 -0
- package/coverage/lcov-report/src/constants/job/index.html +176 -0
- package/coverage/lcov-report/src/constants/job/payment_status.ts.html +106 -0
- package/coverage/lcov-report/src/constants/job/production_status.ts.html +121 -0
- package/coverage/lcov-report/src/constants/job/shipment_status.ts.html +118 -0
- package/coverage/lcov-report/src/constants/job/supply_chain_request_status.ts.html +103 -0
- package/coverage/lcov-report/src/constants/job_priorities.ts.html +103 -0
- package/coverage/lcov-report/src/constants/job_status.ts.html +232 -0
- package/coverage/lcov-report/src/constants/job_types.ts.html +133 -0
- package/coverage/lcov-report/src/constants/notification_sections.ts.html +124 -0
- package/coverage/lcov-report/src/constants/notification_types.ts.html +385 -0
- package/coverage/lcov-report/src/constants/notification_urgencies.ts.html +106 -0
- package/coverage/lcov-report/src/constants/payment_types.ts.html +115 -0
- package/coverage/lcov-report/src/constants/platform.ts.html +103 -0
- package/coverage/lcov-report/src/constants/product_types.ts.html +163 -0
- package/coverage/lcov-report/src/constants/rights.ts.html +100 -0
- package/coverage/lcov-report/src/constants/robots_meta_directives.ts.html +118 -0
- package/coverage/lcov-report/src/constants/roles.ts.html +223 -0
- package/coverage/lcov-report/src/constants/shipment_companies.ts.html +142 -0
- package/coverage/lcov-report/src/constants/shipment_services.ts.html +94 -0
- package/coverage/lcov-report/src/constants/system_roles.ts.html +94 -0
- package/coverage/lcov-report/src/constants/theme_status.ts.html +100 -0
- package/coverage/lcov-report/src/constants/user_types.ts.html +136 -0
- package/coverage/lcov-report/src/constants/white_label_accessibilities.ts.html +103 -0
- package/coverage/lcov-report/src/cookie.ts.html +133 -0
- package/coverage/lcov-report/src/entities/address.ts.html +280 -0
- package/coverage/lcov-report/src/entities/agent_conversation.ts.html +202 -0
- package/coverage/lcov-report/src/entities/agent_skill.ts.html +382 -0
- package/coverage/lcov-report/src/entities/agent_skill_approval.ts.html +163 -0
- package/coverage/lcov-report/src/entities/agent_skill_version.ts.html +277 -0
- package/coverage/lcov-report/src/entities/agent_token_usage.ts.html +349 -0
- package/coverage/lcov-report/src/entities/assignment.ts.html +382 -0
- package/coverage/lcov-report/src/entities/automatic_payment_relationship.ts.html +172 -0
- package/coverage/lcov-report/src/entities/bank.ts.html +220 -0
- package/coverage/lcov-report/src/entities/cart.ts.html +391 -0
- package/coverage/lcov-report/src/entities/cart_item.ts.html +340 -0
- package/coverage/lcov-report/src/entities/cart_shipment_group.ts.html +148 -0
- package/coverage/lcov-report/src/entities/cart_shipment_quote.ts.html +184 -0
- package/coverage/lcov-report/src/entities/category.ts.html +262 -0
- package/coverage/lcov-report/src/entities/company.ts.html +1276 -0
- package/coverage/lcov-report/src/entities/company_invitation.ts.html +184 -0
- package/coverage/lcov-report/src/entities/country_tax.ts.html +223 -0
- package/coverage/lcov-report/src/entities/discount.ts.html +235 -0
- package/coverage/lcov-report/src/entities/discount_group.ts.html +214 -0
- package/coverage/lcov-report/src/entities/domain.ts.html +3349 -0
- package/coverage/lcov-report/src/entities/domain_chat_settings.ts.html +331 -0
- package/coverage/lcov-report/src/entities/domain_invitation.ts.html +193 -0
- package/coverage/lcov-report/src/entities/domain_tag.ts.html +211 -0
- package/coverage/lcov-report/src/entities/draft.ts.html +322 -0
- package/coverage/lcov-report/src/entities/draft_comment.ts.html +274 -0
- package/coverage/lcov-report/src/entities/draft_preview.ts.html +196 -0
- package/coverage/lcov-report/src/entities/draft_preview_layer.ts.html +148 -0
- package/coverage/lcov-report/src/entities/draft_template.ts.html +328 -0
- package/coverage/lcov-report/src/entities/email_address.ts.html +157 -0
- package/coverage/lcov-report/src/entities/email_counter.ts.html +145 -0
- package/coverage/lcov-report/src/entities/enrolled_domain.ts.html +205 -0
- package/coverage/lcov-report/src/entities/exchange_rate.ts.html +151 -0
- package/coverage/lcov-report/src/entities/file.ts.html +580 -0
- package/coverage/lcov-report/src/entities/index.html +1271 -0
- package/coverage/lcov-report/src/entities/internal_tag.ts.html +238 -0
- package/coverage/lcov-report/src/entities/inventory.ts.html +274 -0
- package/coverage/lcov-report/src/entities/inventory_group.ts.html +193 -0
- package/coverage/lcov-report/src/entities/inventory_unit_variation.ts.html +172 -0
- package/coverage/lcov-report/src/entities/invoice.ts.html +661 -0
- package/coverage/lcov-report/src/entities/item.ts.html +262 -0
- package/coverage/lcov-report/src/entities/job.ts.html +1288 -0
- package/coverage/lcov-report/src/entities/job_comment.ts.html +244 -0
- package/coverage/lcov-report/src/entities/job_note.ts.html +205 -0
- package/coverage/lcov-report/src/entities/job_operation_log.ts.html +208 -0
- package/coverage/lcov-report/src/entities/matching_inventory.ts.html +172 -0
- package/coverage/lcov-report/src/entities/notification.ts.html +403 -0
- package/coverage/lcov-report/src/entities/payment.ts.html +316 -0
- package/coverage/lcov-report/src/entities/payment_device.ts.html +175 -0
- package/coverage/lcov-report/src/entities/phone_number.ts.html +193 -0
- package/coverage/lcov-report/src/entities/product.ts.html +1543 -0
- package/coverage/lcov-report/src/entities/product_form.ts.html +238 -0
- package/coverage/lcov-report/src/entities/product_form_version.ts.html +238 -0
- package/coverage/lcov-report/src/entities/product_review.ts.html +748 -0
- package/coverage/lcov-report/src/entities/production_comment.ts.html +244 -0
- package/coverage/lcov-report/src/entities/quote.ts.html +505 -0
- package/coverage/lcov-report/src/entities/quote_item.ts.html +298 -0
- package/coverage/lcov-report/src/entities/reminder.ts.html +307 -0
- package/coverage/lcov-report/src/entities/session.ts.html +169 -0
- package/coverage/lcov-report/src/entities/shipment.ts.html +673 -0
- package/coverage/lcov-report/src/entities/shipment_item.ts.html +130 -0
- package/coverage/lcov-report/src/entities/shipment_item_fulfillment.ts.html +130 -0
- package/coverage/lcov-report/src/entities/shipment_log.ts.html +196 -0
- package/coverage/lcov-report/src/entities/shipment_method.ts.html +268 -0
- package/coverage/lcov-report/src/entities/shipment_method_variation.ts.html +202 -0
- package/coverage/lcov-report/src/entities/short_url.ts.html +193 -0
- package/coverage/lcov-report/src/entities/subscription_plan.ts.html +304 -0
- package/coverage/lcov-report/src/entities/supply_domain.ts.html +166 -0
- package/coverage/lcov-report/src/entities/support_conversation.ts.html +280 -0
- package/coverage/lcov-report/src/entities/support_message.ts.html +175 -0
- package/coverage/lcov-report/src/entities/system_role.ts.html +136 -0
- package/coverage/lcov-report/src/entities/theme.ts.html +331 -0
- package/coverage/lcov-report/src/entities/theme_css_setting.ts.html +154 -0
- package/coverage/lcov-report/src/entities/user.ts.html +1369 -0
- package/coverage/lcov-report/src/entities/user_company.ts.html +166 -0
- package/coverage/lcov-report/src/entities/variation.ts.html +277 -0
- package/coverage/lcov-report/src/entities/variation_field.ts.html +889 -0
- package/coverage/lcov-report/src/entities/variation_fields_option.ts.html +406 -0
- package/coverage/lcov-report/src/entities/variation_option.ts.html +259 -0
- package/coverage/lcov-report/src/entities/variations_group.ts.html +208 -0
- package/coverage/lcov-report/src/entity.ts.html +3379 -0
- package/coverage/lcov-report/src/index.html +221 -0
- package/coverage/lcov-report/src/index.ts.html +652 -0
- package/coverage/lcov-report/src/merchi.ts.html +1420 -0
- package/coverage/lcov-report/src/pricing/discount.ts.html +136 -0
- package/coverage/lcov-report/src/pricing/estimate.ts.html +1015 -0
- package/coverage/lcov-report/src/pricing/index.html +206 -0
- package/coverage/lcov-report/src/pricing/index.ts.html +106 -0
- package/coverage/lcov-report/src/pricing/inventory.ts.html +352 -0
- package/coverage/lcov-report/src/pricing/matrix.ts.html +736 -0
- package/coverage/lcov-report/src/pricing/round.ts.html +166 -0
- package/coverage/lcov-report/src/pricing/visibility.ts.html +418 -0
- package/coverage/lcov-report/src/request.ts.html +673 -0
- package/coverage/lcov-report/src/test_util.ts.html +139 -0
- package/coverage/lcov-report/src/toasts.ts.html +187 -0
- package/coverage/lcov-report/src/util/float.ts.html +121 -0
- package/coverage/lcov-report/src/util/index.html +161 -0
- package/coverage/lcov-report/src/util/index.ts.html +106 -0
- package/coverage/lcov-report/src/util/query_string.ts.html +124 -0
- package/coverage/lcov-report/src/util/validation.ts.html +91 -0
- package/coverage/lcov-report/src/uuid.ts.html +109 -0
- package/coverage/lcov.info +7758 -0
- package/dist/constants/auto_assign_production_on_actions.js +7 -0
- package/dist/constants/call_to_actions.js +15 -0
- package/dist/constants/call_to_actions.test.js +4 -0
- package/dist/constants/discount_types.js +6 -0
- package/dist/constants/discount_types.test.js +4 -0
- package/dist/constants/domain_types.js +13 -0
- package/dist/constants/domain_types.test.js +4 -0
- package/dist/constants/errors.js +32 -0
- package/dist/constants/event_types.js +6 -0
- package/dist/constants/event_types.test.js +4 -0
- package/dist/constants/field_types.js +17 -0
- package/dist/constants/field_types.test.js +4 -0
- package/dist/constants/index.js +25 -0
- package/dist/constants/input_types.js +14 -0
- package/dist/constants/input_types.test.js +4 -0
- package/dist/constants/inventory_status.test.js +4 -0
- package/dist/constants/inventory_statuses.js +7 -0
- package/dist/constants/invoice_types.js +6 -0
- package/dist/constants/invoice_types.test.js +4 -0
- package/dist/constants/item_types.js +6 -0
- package/dist/constants/item_types.test.js +4 -0
- package/dist/constants/job/drafting_status.js +8 -0
- package/dist/constants/job/drafting_status.test.js +4 -0
- package/dist/constants/job/payment_status.js +8 -0
- package/dist/constants/job/payment_status.test.js +4 -0
- package/dist/constants/job/production_status.js +13 -0
- package/dist/constants/job/production_status.test.js +4 -0
- package/dist/constants/job/shipment_status.js +12 -0
- package/dist/constants/job/shipment_status.test.js +4 -0
- package/dist/constants/job/supply_chain_request_status.js +7 -0
- package/dist/constants/job/supply_chain_request_status.test.js +4 -0
- package/dist/constants/job_priorities.js +7 -0
- package/dist/constants/job_priorities.test.js +4 -0
- package/dist/constants/job_status.js +50 -0
- package/dist/constants/job_status.test.js +4 -0
- package/dist/constants/job_types.js +17 -0
- package/dist/constants/job_types.test.js +4 -0
- package/dist/constants/notification_sections.js +14 -0
- package/dist/constants/notification_sections.test.js +4 -0
- package/dist/constants/notification_types.js +101 -0
- package/dist/constants/notification_types.test.js +4 -0
- package/dist/constants/notification_urgencies.js +7 -0
- package/dist/constants/notification_urgencies.test.js +4 -0
- package/dist/constants/payment_types.js +11 -0
- package/dist/constants/payment_types.test.js +4 -0
- package/dist/constants/platform.js +5 -0
- package/dist/constants/platform.test.js +8 -0
- package/dist/constants/product_types.js +27 -0
- package/dist/constants/product_types.test.js +4 -0
- package/dist/constants/rights.js +6 -0
- package/dist/constants/rights.test.js +4 -0
- package/dist/constants/robots_meta_directives.js +11 -0
- package/dist/constants/robots_meta_directives.test.js +4 -0
- package/dist/constants/roles.js +64 -0
- package/dist/constants/roles.test.js +4 -0
- package/dist/constants/shipment_companies.js +20 -0
- package/dist/constants/shipment_companies.test.js +4 -0
- package/dist/constants/shipment_services.js +4 -0
- package/dist/constants/shipment_services.test.js +4 -0
- package/dist/constants/system_roles.js +4 -0
- package/dist/constants/system_roles.test.js +4 -0
- package/dist/constants/theme_status.js +6 -0
- package/dist/constants/theme_status.test.js +4 -0
- package/dist/constants/user_types.js +18 -0
- package/dist/constants/user_types.test.js +4 -0
- package/dist/constants/white_label_accessibilities.js +6 -0
- package/dist/constants/white_label_accessibilities.test.js +4 -0
- package/dist/cookie.js +15 -0
- package/dist/cookie.test.js +10 -0
- package/dist/entities/address.js +104 -0
- package/dist/entities/address.test.js +6 -0
- package/dist/entities/agent_conversation.js +78 -0
- package/dist/entities/agent_conversation.test.js +6 -0
- package/dist/entities/agent_skill.js +133 -0
- package/dist/entities/agent_skill.test.js +11 -0
- package/dist/entities/agent_skill_approval.js +61 -0
- package/dist/entities/agent_skill_version.js +99 -0
- package/dist/entities/agent_token_analytics.js +1 -0
- package/dist/entities/agent_token_usage.js +127 -0
- package/dist/entities/agent_token_usage.test.js +6 -0
- package/dist/entities/assignment.js +135 -0
- package/dist/entities/assignment.test.js +30 -0
- package/dist/entities/automatic_payment_relationship.js +65 -0
- package/dist/entities/automatic_payment_relationship.test.js +6 -0
- package/dist/entities/bank.js +85 -0
- package/dist/entities/bank.test.js +6 -0
- package/dist/entities/cart.js +173 -0
- package/dist/entities/cart.test.js +51 -0
- package/dist/entities/cart_item.js +125 -0
- package/dist/entities/cart_item.test.js +28 -0
- package/dist/entities/cart_shipment_group.js +53 -0
- package/dist/entities/cart_shipment_quote.js +70 -0
- package/dist/entities/category.js +101 -0
- package/dist/entities/category.test.js +52 -0
- package/dist/entities/company.js +509 -0
- package/dist/entities/company.test.js +6 -0
- package/dist/entities/company_invitation.js +70 -0
- package/dist/entities/company_invitation.test.js +6 -0
- package/dist/entities/country_tax.js +80 -0
- package/dist/entities/country_tax.test.js +11 -0
- package/dist/entities/discount.js +89 -0
- package/dist/entities/discount.test.js +34 -0
- package/dist/entities/discount_group.js +80 -0
- package/dist/entities/discount_group.test.js +6 -0
- package/dist/entities/domain.js +567 -0
- package/dist/entities/domain.test.js +356 -0
- package/dist/entities/domain_chat_settings.js +134 -0
- package/dist/entities/domain_chat_settings.test.js +15 -0
- package/dist/entities/domain_invitation.js +74 -0
- package/dist/entities/domain_invitation.test.js +6 -0
- package/dist/entities/domain_tag.js +77 -0
- package/dist/entities/domain_tag.test.js +6 -0
- package/dist/entities/draft.js +122 -0
- package/dist/entities/draft.test.js +26 -0
- package/dist/entities/draft_comment.js +107 -0
- package/dist/entities/draft_comment.test.js +6 -0
- package/dist/entities/draft_preview.js +74 -0
- package/dist/entities/draft_preview.test.js +36 -0
- package/dist/entities/draft_preview_layer.js +54 -0
- package/dist/entities/draft_preview_layer.test.js +6 -0
- package/dist/entities/draft_template.js +119 -0
- package/dist/entities/draft_template.test.js +12 -0
- package/dist/entities/email_address.js +56 -0
- package/dist/entities/email_address.test.js +6 -0
- package/dist/entities/email_counter.js +53 -0
- package/dist/entities/email_counter.test.js +6 -0
- package/dist/entities/enrolled_domain.js +74 -0
- package/dist/entities/enrolled_domain.test.js +6 -0
- package/dist/entities/exchange_rate.js +56 -0
- package/dist/entities/exchange_rate.test.js +6 -0
- package/dist/entities/file.js +218 -0
- package/dist/entities/file.test.js +38 -0
- package/dist/entities/internal_tag.js +84 -0
- package/dist/entities/internal_tag.test.js +6 -0
- package/dist/entities/inventory.js +97 -0
- package/dist/entities/inventory.test.js +22 -0
- package/dist/entities/inventory_group.js +69 -0
- package/dist/entities/inventory_group.test.js +6 -0
- package/dist/entities/inventory_unit_variation.js +61 -0
- package/dist/entities/inventory_unit_variation.test.js +6 -0
- package/dist/entities/invoice.js +268 -0
- package/dist/entities/invoice.test.js +45 -0
- package/dist/entities/item.js +96 -0
- package/dist/entities/item.test.js +17 -0
- package/dist/entities/job.js +519 -0
- package/dist/entities/job.test.js +83 -0
- package/dist/entities/job_comment.js +94 -0
- package/dist/entities/job_comment.test.js +6 -0
- package/dist/entities/job_note.js +78 -0
- package/dist/entities/job_operation_log.js +82 -0
- package/dist/entities/job_operation_log.test.js +6 -0
- package/dist/entities/matching_inventory.js +63 -0
- package/dist/entities/notification.js +163 -0
- package/dist/entities/notification.test.js +51 -0
- package/dist/entities/payment.js +122 -0
- package/dist/entities/payment.test.js +22 -0
- package/dist/entities/payment_device.js +65 -0
- package/dist/entities/payment_device.test.js +6 -0
- package/dist/entities/phone_number.js +72 -0
- package/dist/entities/phone_number.test.js +6 -0
- package/dist/entities/product.js +619 -0
- package/dist/entities/product.test.js +720 -0
- package/dist/entities/product_form.js +92 -0
- package/dist/entities/product_form_version.js +95 -0
- package/dist/entities/product_review.js +234 -0
- package/dist/entities/production_comment.js +94 -0
- package/dist/entities/production_comment.test.js +6 -0
- package/dist/entities/quote.js +168 -0
- package/dist/entities/quote.test.js +86 -0
- package/dist/entities/quote_item.js +99 -0
- package/dist/entities/quote_item.test.js +40 -0
- package/dist/entities/reminder.js +120 -0
- package/dist/entities/reminder.test.js +14 -0
- package/dist/entities/session.js +63 -0
- package/dist/entities/session.test.js +6 -0
- package/dist/entities/shipment.js +256 -0
- package/dist/entities/shipment.test.js +20 -0
- package/dist/entities/shipment_item.js +45 -0
- package/dist/entities/shipment_item.test.js +6 -0
- package/dist/entities/shipment_item_fulfillment.js +46 -0
- package/dist/entities/shipment_item_fulfillment.test.js +6 -0
- package/dist/entities/shipment_log.js +75 -0
- package/dist/entities/shipment_method.js +104 -0
- package/dist/entities/shipment_method.test.js +6 -0
- package/dist/entities/shipment_method_variation.js +77 -0
- package/dist/entities/shipment_method_variation.test.js +6 -0
- package/dist/entities/short_url.js +73 -0
- package/dist/entities/short_url.test.js +6 -0
- package/dist/entities/subscription_plan.js +122 -0
- package/dist/entities/subscription_plan.test.js +6 -0
- package/dist/entities/supply_domain.js +62 -0
- package/dist/entities/supply_domain.test.js +6 -0
- package/dist/entities/support_conversation.js +106 -0
- package/dist/entities/support_conversation.test.js +6 -0
- package/dist/entities/support_message.js +66 -0
- package/dist/entities/support_message.test.js +6 -0
- package/dist/entities/system_role.js +49 -0
- package/dist/entities/system_role.test.js +6 -0
- package/dist/entities/theme.js +125 -0
- package/dist/entities/theme.test.js +35 -0
- package/dist/entities/theme_css_setting.js +57 -0
- package/dist/entities/theme_css_setting.test.js +6 -0
- package/dist/entities/user.js +508 -0
- package/dist/entities/user.test.js +134 -0
- package/dist/entities/user_company.js +62 -0
- package/dist/entities/user_company.test.js +6 -0
- package/dist/entities/variation.js +108 -0
- package/dist/entities/variation.test.js +6 -0
- package/dist/entities/variation_field.js +381 -0
- package/dist/entities/variation_field.test.js +69 -0
- package/dist/entities/variation_fields_option.js +153 -0
- package/dist/entities/variation_fields_option.test.js +43 -0
- package/dist/entities/variation_option.js +104 -0
- package/dist/entities/variation_option.test.js +6 -0
- package/dist/entities/variations_group.js +79 -0
- package/dist/entities/variations_group.test.js +6 -0
- package/dist/entity.js +950 -0
- package/dist/index.js +86 -0
- package/dist/merchi.js +296 -0
- package/dist/merchi.test.js +21 -0
- package/dist/pricing/discount.js +11 -0
- package/dist/pricing/discount.test.js +35 -0
- package/dist/pricing/estimate.js +335 -0
- package/dist/pricing/estimate.test.js +403 -0
- package/dist/pricing/golden.test.js +61 -0
- package/dist/pricing/index.js +7 -0
- package/dist/pricing/index.test.js +8 -0
- package/dist/pricing/inventory.js +238 -0
- package/dist/pricing/inventory.test.js +188 -0
- package/dist/pricing/matrix.js +245 -0
- package/dist/pricing/matrix.test.js +437 -0
- package/dist/pricing/round.js +29 -0
- package/dist/pricing/round.test.js +27 -0
- package/dist/pricing/types.js +1 -0
- package/dist/pricing/visibility.js +227 -0
- package/dist/pricing/visibility.test.js +210 -0
- package/dist/request.js +169 -0
- package/dist/request.test.js +70 -0
- package/dist/test_util.js +17 -0
- package/dist/toasts.js +14 -0
- package/dist/toasts.test.js +28 -0
- package/dist/util/float.js +34 -0
- package/dist/util/index.js +3 -0
- package/dist/util/query_string.js +13 -0
- package/dist/util/query_string.test.js +6 -0
- package/dist/util/validation.js +3 -0
- package/dist/util/validation.test.js +12 -0
- package/dist/uuid.js +8 -0
- package/dist/uuid.test.js +11 -0
- package/jest.config.js +23 -0
- package/merchi_sdk_ts-1.13.1.tgz +0 -0
- package/package.json +41 -0
- package/src/constants/auto_assign_production_on_actions.ts +6 -0
- package/src/constants/call_to_actions.test.ts +5 -0
- package/src/constants/call_to_actions.ts +14 -0
- package/src/constants/discount_types.test.ts +5 -0
- package/src/constants/discount_types.ts +5 -0
- package/src/constants/domain_types.test.ts +5 -0
- package/src/constants/domain_types.ts +12 -0
- package/src/constants/errors.ts +32 -0
- package/src/constants/event_types.test.ts +5 -0
- package/src/constants/event_types.ts +5 -0
- package/src/constants/field_types.test.ts +5 -0
- package/src/constants/field_types.ts +16 -0
- package/src/constants/index.ts +51 -0
- package/src/constants/input_types.test.ts +5 -0
- package/src/constants/input_types.ts +13 -0
- package/src/constants/inventory_status.test.ts +5 -0
- package/src/constants/inventory_statuses.ts +6 -0
- package/src/constants/invoice_types.test.ts +5 -0
- package/src/constants/invoice_types.ts +5 -0
- package/src/constants/item_types.test.ts +5 -0
- package/src/constants/item_types.ts +5 -0
- package/src/constants/job/drafting_status.test.ts +5 -0
- package/src/constants/job/drafting_status.ts +7 -0
- package/src/constants/job/payment_status.test.ts +5 -0
- package/src/constants/job/payment_status.ts +7 -0
- package/src/constants/job/production_status.test.ts +5 -0
- package/src/constants/job/production_status.ts +12 -0
- package/src/constants/job/shipment_status.test.ts +5 -0
- package/src/constants/job/shipment_status.ts +11 -0
- package/src/constants/job/supply_chain_request_status.test.ts +5 -0
- package/src/constants/job/supply_chain_request_status.ts +6 -0
- package/src/constants/job_priorities.test.ts +5 -0
- package/src/constants/job_priorities.ts +6 -0
- package/src/constants/job_status.test.ts +5 -0
- package/src/constants/job_status.ts +49 -0
- package/src/constants/job_types.test.ts +5 -0
- package/src/constants/job_types.ts +16 -0
- package/src/constants/notification_sections.test.ts +5 -0
- package/src/constants/notification_sections.ts +13 -0
- package/src/constants/notification_types.test.ts +5 -0
- package/src/constants/notification_types.ts +100 -0
- package/src/constants/notification_urgencies.test.ts +5 -0
- package/src/constants/notification_urgencies.ts +7 -0
- package/src/constants/payment_types.test.ts +5 -0
- package/src/constants/payment_types.ts +10 -0
- package/src/constants/platform.test.ts +15 -0
- package/src/constants/platform.ts +6 -0
- package/src/constants/product_types.test.ts +6 -0
- package/src/constants/product_types.ts +26 -0
- package/src/constants/rights.test.ts +5 -0
- package/src/constants/rights.ts +5 -0
- package/src/constants/robots_meta_directives.test.ts +5 -0
- package/src/constants/robots_meta_directives.ts +11 -0
- package/src/constants/roles.test.ts +5 -0
- package/src/constants/roles.ts +46 -0
- package/src/constants/shipment_companies.test.ts +5 -0
- package/src/constants/shipment_companies.ts +19 -0
- package/src/constants/shipment_services.test.ts +5 -0
- package/src/constants/shipment_services.ts +3 -0
- package/src/constants/system_roles.test.ts +5 -0
- package/src/constants/system_roles.ts +3 -0
- package/src/constants/theme_status.test.ts +5 -0
- package/src/constants/theme_status.ts +5 -0
- package/src/constants/user_types.test.ts +5 -0
- package/src/constants/user_types.ts +17 -0
- package/src/constants/white_label_accessibilities.test.ts +5 -0
- package/src/constants/white_label_accessibilities.ts +6 -0
- package/src/cookie.test.ts +11 -0
- package/src/cookie.ts +16 -0
- package/src/entities/address.test.ts +7 -0
- package/src/entities/address.ts +65 -0
- package/src/entities/agent_conversation.test.ts +7 -0
- package/src/entities/agent_conversation.ts +39 -0
- package/src/entities/agent_skill.test.ts +13 -0
- package/src/entities/agent_skill.ts +99 -0
- package/src/entities/agent_skill_approval.ts +26 -0
- package/src/entities/agent_skill_version.ts +64 -0
- package/src/entities/agent_token_analytics.ts +49 -0
- package/src/entities/agent_token_usage.test.ts +7 -0
- package/src/entities/agent_token_usage.ts +88 -0
- package/src/entities/assignment.test.ts +39 -0
- package/src/entities/assignment.ts +99 -0
- package/src/entities/automatic_payment_relationship.test.ts +8 -0
- package/src/entities/automatic_payment_relationship.ts +29 -0
- package/src/entities/bank.test.ts +7 -0
- package/src/entities/bank.ts +45 -0
- package/src/entities/cart.test.ts +57 -0
- package/src/entities/cart.ts +102 -0
- package/src/entities/cart_item.test.ts +33 -0
- package/src/entities/cart_item.ts +85 -0
- package/src/entities/cart_shipment_group.ts +21 -0
- package/src/entities/cart_shipment_quote.ts +33 -0
- package/src/entities/category.test.ts +57 -0
- package/src/entities/category.ts +59 -0
- package/src/entities/company.test.ts +7 -0
- package/src/entities/company.ts +397 -0
- package/src/entities/company_invitation.test.ts +7 -0
- package/src/entities/company_invitation.ts +33 -0
- package/src/entities/country_tax.test.ts +13 -0
- package/src/entities/country_tax.ts +46 -0
- package/src/entities/discount.test.ts +36 -0
- package/src/entities/discount.ts +50 -0
- package/src/entities/discount_group.test.ts +7 -0
- package/src/entities/discount_group.ts +43 -0
- package/src/entities/domain.test.ts +393 -0
- package/src/entities/domain.ts +1088 -0
- package/src/entities/domain_chat_settings.test.ts +16 -0
- package/src/entities/domain_chat_settings.ts +82 -0
- package/src/entities/domain_invitation.test.ts +7 -0
- package/src/entities/domain_invitation.ts +36 -0
- package/src/entities/domain_tag.test.ts +7 -0
- package/src/entities/domain_tag.ts +42 -0
- package/src/entities/draft.test.ts +29 -0
- package/src/entities/draft.ts +79 -0
- package/src/entities/draft_comment.test.ts +7 -0
- package/src/entities/draft_comment.ts +63 -0
- package/src/entities/draft_preview.test.ts +42 -0
- package/src/entities/draft_preview.ts +37 -0
- package/src/entities/draft_preview_layer.test.ts +7 -0
- package/src/entities/draft_preview_layer.ts +21 -0
- package/src/entities/draft_template.test.ts +14 -0
- package/src/entities/draft_template.ts +81 -0
- package/src/entities/email_address.test.ts +7 -0
- package/src/entities/email_address.ts +24 -0
- package/src/entities/email_counter.test.ts +7 -0
- package/src/entities/email_counter.ts +20 -0
- package/src/entities/enrolled_domain.test.ts +7 -0
- package/src/entities/enrolled_domain.ts +40 -0
- package/src/entities/exchange_rate.test.ts +7 -0
- package/src/entities/exchange_rate.ts +22 -0
- package/src/entities/file.test.ts +43 -0
- package/src/entities/file.ts +165 -0
- package/src/entities/internal_tag.test.ts +7 -0
- package/src/entities/internal_tag.ts +51 -0
- package/src/entities/inventory.test.ts +28 -0
- package/src/entities/inventory.ts +63 -0
- package/src/entities/inventory_group.test.ts +7 -0
- package/src/entities/inventory_group.ts +36 -0
- package/src/entities/inventory_unit_variation.test.ts +7 -0
- package/src/entities/inventory_unit_variation.ts +29 -0
- package/src/entities/invoice.test.ts +50 -0
- package/src/entities/invoice.ts +192 -0
- package/src/entities/item.test.ts +19 -0
- package/src/entities/item.ts +59 -0
- package/src/entities/job.test.ts +95 -0
- package/src/entities/job.ts +401 -0
- package/src/entities/job_comment.test.ts +7 -0
- package/src/entities/job_comment.ts +53 -0
- package/src/entities/job_note.ts +40 -0
- package/src/entities/job_operation_log.test.ts +7 -0
- package/src/entities/job_operation_log.ts +41 -0
- package/src/entities/matching_inventory.ts +29 -0
- package/src/entities/notification.test.ts +58 -0
- package/src/entities/notification.ts +106 -0
- package/src/entities/payment.test.ts +27 -0
- package/src/entities/payment.ts +77 -0
- package/src/entities/payment_device.test.ts +7 -0
- package/src/entities/payment_device.ts +30 -0
- package/src/entities/phone_number.test.ts +7 -0
- package/src/entities/phone_number.ts +36 -0
- package/src/entities/product.test.ts +776 -0
- package/src/entities/product.ts +486 -0
- package/src/entities/product_form.ts +51 -0
- package/src/entities/product_form_version.ts +51 -0
- package/src/entities/product_review.ts +221 -0
- package/src/entities/production_comment.test.ts +7 -0
- package/src/entities/production_comment.ts +53 -0
- package/src/entities/quote.test.ts +98 -0
- package/src/entities/quote.ts +140 -0
- package/src/entities/quote_item.test.ts +50 -0
- package/src/entities/quote_item.ts +71 -0
- package/src/entities/reminder.test.ts +16 -0
- package/src/entities/reminder.ts +74 -0
- package/src/entities/session.test.ts +7 -0
- package/src/entities/session.ts +28 -0
- package/src/entities/shipment.test.ts +24 -0
- package/src/entities/shipment.ts +196 -0
- package/src/entities/shipment_item.test.ts +7 -0
- package/src/entities/shipment_item.ts +15 -0
- package/src/entities/shipment_item_fulfillment.test.ts +8 -0
- package/src/entities/shipment_item_fulfillment.ts +15 -0
- package/src/entities/shipment_log.ts +37 -0
- package/src/entities/shipment_method.test.ts +7 -0
- package/src/entities/shipment_method.ts +61 -0
- package/src/entities/shipment_method_variation.test.ts +7 -0
- package/src/entities/shipment_method_variation.ts +39 -0
- package/src/entities/short_url.test.ts +7 -0
- package/src/entities/short_url.ts +36 -0
- package/src/entities/subscription_plan.test.ts +7 -0
- package/src/entities/subscription_plan.ts +73 -0
- package/src/entities/supply_domain.test.ts +7 -0
- package/src/entities/supply_domain.ts +27 -0
- package/src/entities/support_conversation.test.ts +7 -0
- package/src/entities/support_conversation.ts +65 -0
- package/src/entities/support_message.test.ts +7 -0
- package/src/entities/support_message.ts +30 -0
- package/src/entities/system_role.test.ts +7 -0
- package/src/entities/system_role.ts +17 -0
- package/src/entities/theme.test.ts +38 -0
- package/src/entities/theme.ts +82 -0
- package/src/entities/theme_css_setting.test.ts +7 -0
- package/src/entities/theme_css_setting.ts +23 -0
- package/src/entities/user.test.ts +154 -0
- package/src/entities/user.ts +428 -0
- package/src/entities/user_company.test.ts +7 -0
- package/src/entities/user_company.ts +27 -0
- package/src/entities/variation.test.ts +7 -0
- package/src/entities/variation.ts +64 -0
- package/src/entities/variation_field.test.ts +76 -0
- package/src/entities/variation_field.ts +268 -0
- package/src/entities/variation_fields_option.test.ts +46 -0
- package/src/entities/variation_fields_option.ts +107 -0
- package/src/entities/variation_option.test.ts +7 -0
- package/src/entities/variation_option.ts +58 -0
- package/src/entities/variations_group.test.ts +7 -0
- package/src/entities/variations_group.ts +41 -0
- package/src/entity.ts +1098 -0
- package/src/index.ts +189 -0
- package/src/merchi.test.ts +25 -0
- package/src/merchi.ts +445 -0
- package/src/pricing/__fixtures__/conditional_field_hidden.json +112 -0
- package/src/pricing/__fixtures__/conditional_field_visible.json +113 -0
- package/src/pricing/__fixtures__/group_product.json +130 -0
- package/src/pricing/__fixtures__/non_selectable_number_field.json +108 -0
- package/src/pricing/__fixtures__/quantity_break_discount.json +104 -0
- package/src/pricing/__fixtures__/simple_selectable_field.json +110 -0
- package/src/pricing/discount.test.ts +47 -0
- package/src/pricing/discount.ts +17 -0
- package/src/pricing/estimate.test.ts +486 -0
- package/src/pricing/estimate.ts +310 -0
- package/src/pricing/golden.test.ts +51 -0
- package/src/pricing/index.test.ts +9 -0
- package/src/pricing/index.ts +7 -0
- package/src/pricing/inventory.test.ts +197 -0
- package/src/pricing/inventory.ts +89 -0
- package/src/pricing/matrix.test.ts +553 -0
- package/src/pricing/matrix.ts +217 -0
- package/src/pricing/round.test.ts +31 -0
- package/src/pricing/round.ts +27 -0
- package/src/pricing/types.ts +140 -0
- package/src/pricing/visibility.test.ts +223 -0
- package/src/pricing/visibility.ts +111 -0
- package/src/request.test.ts +79 -0
- package/src/request.ts +196 -0
- package/src/test_util.ts +18 -0
- package/src/toasts.test.ts +38 -0
- package/src/toasts.ts +34 -0
- package/src/util/float.ts +12 -0
- package/src/util/index.ts +7 -0
- package/src/util/query_string.test.ts +7 -0
- package/src/util/query_string.ts +13 -0
- package/src/util/validation.test.ts +16 -0
- package/src/util/validation.ts +2 -0
- package/src/uuid.test.ts +15 -0
- package/src/uuid.ts +8 -0
- package/tsconfig.json +29 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
var __values = (this && this.__values) || function(o) {
|
|
2
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
3
|
+
if (m) return m.call(o);
|
|
4
|
+
if (o && typeof o.length === "number") return {
|
|
5
|
+
next: function () {
|
|
6
|
+
if (o && i >= o.length) o = void 0;
|
|
7
|
+
return { value: o && o[i++], done: !o };
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
11
|
+
};
|
|
12
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
13
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
14
|
+
if (!m) return o;
|
|
15
|
+
var i = m.call(o), r, ar = [], e;
|
|
16
|
+
try {
|
|
17
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
18
|
+
}
|
|
19
|
+
catch (error) { e = { error: error }; }
|
|
20
|
+
finally {
|
|
21
|
+
try {
|
|
22
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
23
|
+
}
|
|
24
|
+
finally { if (e) throw e.error; }
|
|
25
|
+
}
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
29
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
30
|
+
if (ar || !(i in from)) {
|
|
31
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
32
|
+
ar[i] = from[i];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
36
|
+
};
|
|
37
|
+
function collectSelectedOptionIds(selections) {
|
|
38
|
+
var e_1, _a;
|
|
39
|
+
var ids = [];
|
|
40
|
+
var addFrom = function (fieldValues) {
|
|
41
|
+
var e_2, _a;
|
|
42
|
+
try {
|
|
43
|
+
for (var _b = __values(Object.keys(fieldValues)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
44
|
+
var key = _c.value;
|
|
45
|
+
var sel = fieldValues[Number(key)];
|
|
46
|
+
if (sel && sel.selectedOptionIds)
|
|
47
|
+
ids.push.apply(ids, __spreadArray([], __read(sel.selectedOptionIds), false));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
51
|
+
finally {
|
|
52
|
+
try {
|
|
53
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
54
|
+
}
|
|
55
|
+
finally { if (e_2) throw e_2.error; }
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
addFrom(selections.fieldValues || {});
|
|
59
|
+
try {
|
|
60
|
+
for (var _b = __values(selections.groups || []), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
61
|
+
var group = _c.value;
|
|
62
|
+
addFrom(group.fieldValues || {});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
66
|
+
finally {
|
|
67
|
+
try {
|
|
68
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
69
|
+
}
|
|
70
|
+
finally { if (e_1) throw e_1.error; }
|
|
71
|
+
}
|
|
72
|
+
return ids;
|
|
73
|
+
}
|
|
74
|
+
// Shared machinery for both field- and option-level conditional visibility.
|
|
75
|
+
// Mirrors the server's `check_selected_by_fullfilled` recursion: a `selectedBy`
|
|
76
|
+
// list is fulfilled when any of its trigger option ids is currently selected
|
|
77
|
+
// AND that selecting option is itself fulfilled (its own `selectedBy` and its
|
|
78
|
+
// owning field's `selectedBy`), with a `checked` accumulator to break cycles.
|
|
79
|
+
function buildResolver(rules, selections) {
|
|
80
|
+
var e_3, _a, e_4, _b;
|
|
81
|
+
var allFields = __spreadArray(__spreadArray([], __read(rules.fields), false), __read(rules.groupFields), false);
|
|
82
|
+
var optionsById = new Map();
|
|
83
|
+
var fieldByOptionId = new Map();
|
|
84
|
+
try {
|
|
85
|
+
for (var allFields_1 = __values(allFields), allFields_1_1 = allFields_1.next(); !allFields_1_1.done; allFields_1_1 = allFields_1.next()) {
|
|
86
|
+
var f = allFields_1_1.value;
|
|
87
|
+
try {
|
|
88
|
+
for (var _c = (e_4 = void 0, __values(f.options)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
89
|
+
var o = _d.value;
|
|
90
|
+
optionsById.set(o.id, o);
|
|
91
|
+
fieldByOptionId.set(o.id, f);
|
|
92
|
+
if (o.originalId != null) {
|
|
93
|
+
optionsById.set(o.originalId, o);
|
|
94
|
+
fieldByOptionId.set(o.originalId, f);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
99
|
+
finally {
|
|
100
|
+
try {
|
|
101
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
102
|
+
}
|
|
103
|
+
finally { if (e_4) throw e_4.error; }
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
108
|
+
finally {
|
|
109
|
+
try {
|
|
110
|
+
if (allFields_1_1 && !allFields_1_1.done && (_a = allFields_1.return)) _a.call(allFields_1);
|
|
111
|
+
}
|
|
112
|
+
finally { if (e_3) throw e_3.error; }
|
|
113
|
+
}
|
|
114
|
+
var selectedOptionIds = collectSelectedOptionIds(selections);
|
|
115
|
+
var sameOption = function (a, b) {
|
|
116
|
+
var oa = optionsById.get(a);
|
|
117
|
+
return oa != null && oa === optionsById.get(b);
|
|
118
|
+
};
|
|
119
|
+
var isFulfilled = function (selectedBy, checked) {
|
|
120
|
+
var e_5, _a, e_6, _b;
|
|
121
|
+
if (!selectedBy || selectedBy.length === 0)
|
|
122
|
+
return true;
|
|
123
|
+
try {
|
|
124
|
+
for (var selectedBy_1 = __values(selectedBy), selectedBy_1_1 = selectedBy_1.next(); !selectedBy_1_1.done; selectedBy_1_1 = selectedBy_1.next()) {
|
|
125
|
+
var triggerId = selectedBy_1_1.value;
|
|
126
|
+
try {
|
|
127
|
+
for (var selectedOptionIds_1 = (e_6 = void 0, __values(selectedOptionIds)), selectedOptionIds_1_1 = selectedOptionIds_1.next(); !selectedOptionIds_1_1.done; selectedOptionIds_1_1 = selectedOptionIds_1.next()) {
|
|
128
|
+
var selId = selectedOptionIds_1_1.value;
|
|
129
|
+
if (!sameOption(triggerId, selId))
|
|
130
|
+
continue;
|
|
131
|
+
if (checked.includes(selId))
|
|
132
|
+
return true;
|
|
133
|
+
// sameOption only returns true for ids present in optionsById, and
|
|
134
|
+
// fieldByOptionId is populated in the same loop, so both lookups are
|
|
135
|
+
// guaranteed non-null here (mirrors server dereferencing directly).
|
|
136
|
+
var opt = optionsById.get(selId);
|
|
137
|
+
var field = fieldByOptionId.get(selId);
|
|
138
|
+
var nextChecked = __spreadArray(__spreadArray([], __read(checked), false), [selId], false);
|
|
139
|
+
if (isFulfilled(opt.selectedBy, nextChecked) &&
|
|
140
|
+
isFulfilled(field.selectedBy, nextChecked)) {
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
146
|
+
finally {
|
|
147
|
+
try {
|
|
148
|
+
if (selectedOptionIds_1_1 && !selectedOptionIds_1_1.done && (_b = selectedOptionIds_1.return)) _b.call(selectedOptionIds_1);
|
|
149
|
+
}
|
|
150
|
+
finally { if (e_6) throw e_6.error; }
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
155
|
+
finally {
|
|
156
|
+
try {
|
|
157
|
+
if (selectedBy_1_1 && !selectedBy_1_1.done && (_a = selectedBy_1.return)) _a.call(selectedBy_1);
|
|
158
|
+
}
|
|
159
|
+
finally { if (e_5) throw e_5.error; }
|
|
160
|
+
}
|
|
161
|
+
return false;
|
|
162
|
+
};
|
|
163
|
+
// Group variation fields only materialise as variations when the job
|
|
164
|
+
// actually has groups (the server builds them inside each `variations_group`
|
|
165
|
+
// via `VariationsGroups.mapper_variations`; with no groups there are no group
|
|
166
|
+
// variations at all). Independent fields are always in play. This mirrors the
|
|
167
|
+
// server, where a non-group job exposes no group fields.
|
|
168
|
+
var hasGroups = Boolean(selections.groups && selections.groups.length > 0);
|
|
169
|
+
var fieldsToConsider = hasGroups ? allFields : rules.fields;
|
|
170
|
+
return { allFields: allFields, fieldsToConsider: fieldsToConsider, isFulfilled: isFulfilled };
|
|
171
|
+
}
|
|
172
|
+
export function resolveVisibleFields(rules, selections) {
|
|
173
|
+
var e_7, _a;
|
|
174
|
+
var _b = buildResolver(rules, selections), fieldsToConsider = _b.fieldsToConsider, isFulfilled = _b.isFulfilled;
|
|
175
|
+
var visible = new Set();
|
|
176
|
+
try {
|
|
177
|
+
for (var fieldsToConsider_1 = __values(fieldsToConsider), fieldsToConsider_1_1 = fieldsToConsider_1.next(); !fieldsToConsider_1_1.done; fieldsToConsider_1_1 = fieldsToConsider_1.next()) {
|
|
178
|
+
var f = fieldsToConsider_1_1.value;
|
|
179
|
+
if (isFulfilled(f.selectedBy, []))
|
|
180
|
+
visible.add(f.id);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
184
|
+
finally {
|
|
185
|
+
try {
|
|
186
|
+
if (fieldsToConsider_1_1 && !fieldsToConsider_1_1.done && (_a = fieldsToConsider_1.return)) _a.call(fieldsToConsider_1);
|
|
187
|
+
}
|
|
188
|
+
finally { if (e_7) throw e_7.error; }
|
|
189
|
+
}
|
|
190
|
+
return visible;
|
|
191
|
+
}
|
|
192
|
+
// Returns the set of option ids whose own `selectedBy` is fulfilled — i.e. the
|
|
193
|
+
// options that should be visible/selectable given the current selections.
|
|
194
|
+
// Mirrors the server's per-option `isVisible = check_selected_by_fullfilled(
|
|
195
|
+
// option.selected_by)`. Options with no `selectedBy` are always visible.
|
|
196
|
+
export function resolveVisibleOptionIds(rules, selections) {
|
|
197
|
+
var e_8, _a, e_9, _b;
|
|
198
|
+
var _c = buildResolver(rules, selections), fieldsToConsider = _c.fieldsToConsider, isFulfilled = _c.isFulfilled;
|
|
199
|
+
var visible = new Set();
|
|
200
|
+
try {
|
|
201
|
+
for (var fieldsToConsider_2 = __values(fieldsToConsider), fieldsToConsider_2_1 = fieldsToConsider_2.next(); !fieldsToConsider_2_1.done; fieldsToConsider_2_1 = fieldsToConsider_2.next()) {
|
|
202
|
+
var f = fieldsToConsider_2_1.value;
|
|
203
|
+
try {
|
|
204
|
+
for (var _d = (e_9 = void 0, __values(f.options)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
205
|
+
var o = _e.value;
|
|
206
|
+
if (isFulfilled(o.selectedBy, []))
|
|
207
|
+
visible.add(o.id);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
211
|
+
finally {
|
|
212
|
+
try {
|
|
213
|
+
if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
|
|
214
|
+
}
|
|
215
|
+
finally { if (e_9) throw e_9.error; }
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
220
|
+
finally {
|
|
221
|
+
try {
|
|
222
|
+
if (fieldsToConsider_2_1 && !fieldsToConsider_2_1.done && (_a = fieldsToConsider_2.return)) _a.call(fieldsToConsider_2);
|
|
223
|
+
}
|
|
224
|
+
finally { if (e_8) throw e_8.error; }
|
|
225
|
+
}
|
|
226
|
+
return visible;
|
|
227
|
+
}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { resolveVisibleFields, resolveVisibleOptionIds } from './visibility.js';
|
|
13
|
+
function field(id, selectedBy, options) {
|
|
14
|
+
if (options === void 0) { options = []; }
|
|
15
|
+
return {
|
|
16
|
+
id: id,
|
|
17
|
+
originalId: id, position: 0, fieldType: 2, independent: true,
|
|
18
|
+
isSelectable: true,
|
|
19
|
+
selectedBy: selectedBy,
|
|
20
|
+
variationCost: 0, variationUnitCost: 0,
|
|
21
|
+
variationCostDiscountGroup: null, variationUnitCostDiscountGroup: null,
|
|
22
|
+
options: options.map(function (oid) { return ({
|
|
23
|
+
id: oid, originalId: oid, position: 0, default: false,
|
|
24
|
+
variationCost: 0, variationUnitCost: 0,
|
|
25
|
+
variationCostDiscountGroup: null, variationUnitCostDiscountGroup: null,
|
|
26
|
+
selectedBy: [],
|
|
27
|
+
}); }),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
var rules = {
|
|
31
|
+
currency: 'AUD', taxPercent: 0,
|
|
32
|
+
product: { unitPrice: 0, minimumPrice: null, discountGroup: null },
|
|
33
|
+
fields: [
|
|
34
|
+
field(1, [], [101, 102]),
|
|
35
|
+
field(2, [101], [201]),
|
|
36
|
+
field(3, [201], [301]), // chained: visible if option 201 selected
|
|
37
|
+
],
|
|
38
|
+
groupFields: [],
|
|
39
|
+
hasGroups: false,
|
|
40
|
+
};
|
|
41
|
+
test('field with no selectedBy is always visible', function () {
|
|
42
|
+
var v = resolveVisibleFields(rules, { fieldValues: {} });
|
|
43
|
+
expect(v.has(1)).toBe(true);
|
|
44
|
+
expect(v.has(2)).toBe(false);
|
|
45
|
+
expect(v.has(3)).toBe(false);
|
|
46
|
+
});
|
|
47
|
+
test('conditional field appears when its trigger option is selected', function () {
|
|
48
|
+
var v = resolveVisibleFields(rules, {
|
|
49
|
+
fieldValues: { 1: { selectedOptionIds: [101] } },
|
|
50
|
+
});
|
|
51
|
+
expect(v.has(2)).toBe(true);
|
|
52
|
+
expect(v.has(3)).toBe(false);
|
|
53
|
+
});
|
|
54
|
+
test('chained conditional field requires its parent to be fulfilled', function () {
|
|
55
|
+
var v = resolveVisibleFields(rules, {
|
|
56
|
+
fieldValues: { 1: { selectedOptionIds: [101] }, 2: { selectedOptionIds: [201] } },
|
|
57
|
+
});
|
|
58
|
+
expect(v.has(3)).toBe(true);
|
|
59
|
+
});
|
|
60
|
+
test('group fields are not visible when the job has no groups', function () {
|
|
61
|
+
var groupRules = __assign(__assign({}, rules), { fields: [field(1, [], [101])], hasGroups: true, groupFields: [field(20, []), field(21, [])] });
|
|
62
|
+
// No groups submitted -> the job is a single non-group job, so group fields
|
|
63
|
+
// never materialise as variations (mirrors the server).
|
|
64
|
+
var v = resolveVisibleFields(groupRules, { fieldValues: { 1: { selectedOptionIds: [101] } } });
|
|
65
|
+
expect(v.has(1)).toBe(true);
|
|
66
|
+
expect(v.has(20)).toBe(false);
|
|
67
|
+
expect(v.has(21)).toBe(false);
|
|
68
|
+
});
|
|
69
|
+
test('group field selections also drive visibility', function () {
|
|
70
|
+
var groupRules = __assign(__assign({}, rules), { fields: [], hasGroups: true, groupFields: [field(10, [], [110]), field(11, [110], [111])] });
|
|
71
|
+
var v = resolveVisibleFields(groupRules, {
|
|
72
|
+
fieldValues: {},
|
|
73
|
+
groups: [{ quantity: 5, fieldValues: { 10: { selectedOptionIds: [110] } } }],
|
|
74
|
+
});
|
|
75
|
+
expect(v.has(11)).toBe(true);
|
|
76
|
+
});
|
|
77
|
+
test('options/fields with null originalId still resolve by id', function () {
|
|
78
|
+
var noOrigOption = {
|
|
79
|
+
id: 401, originalId: null, position: 0, default: false,
|
|
80
|
+
variationCost: 0, variationUnitCost: 0,
|
|
81
|
+
variationCostDiscountGroup: null, variationUnitCostDiscountGroup: null,
|
|
82
|
+
selectedBy: [],
|
|
83
|
+
};
|
|
84
|
+
var trigger = {
|
|
85
|
+
id: 40, originalId: null, position: 0, fieldType: 2, independent: true,
|
|
86
|
+
isSelectable: true, selectedBy: [],
|
|
87
|
+
variationCost: 0, variationUnitCost: 0,
|
|
88
|
+
variationCostDiscountGroup: null, variationUnitCostDiscountGroup: null,
|
|
89
|
+
options: [noOrigOption],
|
|
90
|
+
};
|
|
91
|
+
var dependent = field(41, [401], []);
|
|
92
|
+
var noOrigRules = __assign(__assign({}, rules), { fields: [trigger, dependent] });
|
|
93
|
+
var v = resolveVisibleFields(noOrigRules, {
|
|
94
|
+
fieldValues: { 40: { selectedOptionIds: [401] } },
|
|
95
|
+
});
|
|
96
|
+
expect(v.has(41)).toBe(true);
|
|
97
|
+
});
|
|
98
|
+
test('cyclic selectedBy references terminate via the checked guard', function () {
|
|
99
|
+
function fieldWithOptSelectedBy(id, selectedBy, opts) {
|
|
100
|
+
return {
|
|
101
|
+
id: id,
|
|
102
|
+
originalId: id, position: 0, fieldType: 2, independent: true,
|
|
103
|
+
isSelectable: true,
|
|
104
|
+
selectedBy: selectedBy,
|
|
105
|
+
variationCost: 0, variationUnitCost: 0,
|
|
106
|
+
variationCostDiscountGroup: null, variationUnitCostDiscountGroup: null,
|
|
107
|
+
options: opts.map(function (o) { return ({
|
|
108
|
+
id: o.id, originalId: o.id, position: 0, default: false,
|
|
109
|
+
variationCost: 0, variationUnitCost: 0,
|
|
110
|
+
variationCostDiscountGroup: null, variationUnitCostDiscountGroup: null,
|
|
111
|
+
selectedBy: o.selectedBy,
|
|
112
|
+
}); }),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
var cyclicRules = __assign(__assign({}, rules), { fields: [
|
|
116
|
+
fieldWithOptSelectedBy(20, [], [{ id: 120, selectedBy: [121] }]),
|
|
117
|
+
fieldWithOptSelectedBy(21, [], [{ id: 121, selectedBy: [120] }]),
|
|
118
|
+
field(22, [120], []),
|
|
119
|
+
] });
|
|
120
|
+
var v = resolveVisibleFields(cyclicRules, {
|
|
121
|
+
fieldValues: { 20: { selectedOptionIds: [120] }, 21: { selectedOptionIds: [121] } },
|
|
122
|
+
});
|
|
123
|
+
expect(v.has(22)).toBe(true);
|
|
124
|
+
});
|
|
125
|
+
test('field selections without selectedOptionIds are ignored', function () {
|
|
126
|
+
var v = resolveVisibleFields(rules, {
|
|
127
|
+
fieldValues: { 1: { value: 'text-only' }, 9: undefined },
|
|
128
|
+
});
|
|
129
|
+
expect(v.has(1)).toBe(true);
|
|
130
|
+
expect(v.has(2)).toBe(false);
|
|
131
|
+
});
|
|
132
|
+
test('missing fieldValues falls back to an empty selection map', function () {
|
|
133
|
+
var v = resolveVisibleFields(rules, { fieldValues: undefined });
|
|
134
|
+
expect(v.has(1)).toBe(true);
|
|
135
|
+
expect(v.has(2)).toBe(false);
|
|
136
|
+
});
|
|
137
|
+
test('group without fieldValues falls back to an empty selection map', function () {
|
|
138
|
+
var v = resolveVisibleFields(rules, {
|
|
139
|
+
fieldValues: {},
|
|
140
|
+
groups: [{ quantity: 1, fieldValues: undefined }],
|
|
141
|
+
});
|
|
142
|
+
expect(v.has(1)).toBe(true);
|
|
143
|
+
expect(v.has(2)).toBe(false);
|
|
144
|
+
});
|
|
145
|
+
// --- resolveVisibleOptionIds (option-level conditional visibility) ---
|
|
146
|
+
// Mirrors the production case: a Size field with options (24mm=901, 25mm=902)
|
|
147
|
+
// and a Colour field whose Green option (912) is gated by `selectedBy: [902]`.
|
|
148
|
+
function sizeAndColourRules() {
|
|
149
|
+
var opt = function (id, selectedBy) {
|
|
150
|
+
if (selectedBy === void 0) { selectedBy = []; }
|
|
151
|
+
return ({
|
|
152
|
+
id: id,
|
|
153
|
+
originalId: id, position: id, default: false,
|
|
154
|
+
variationCost: 0, variationUnitCost: 0,
|
|
155
|
+
variationCostDiscountGroup: null, variationUnitCostDiscountGroup: null,
|
|
156
|
+
selectedBy: selectedBy,
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
var f = function (id, options) { return ({
|
|
160
|
+
id: id,
|
|
161
|
+
originalId: id, position: 0, fieldType: 2, independent: true,
|
|
162
|
+
isSelectable: true, selectedBy: [],
|
|
163
|
+
variationCost: 0, variationUnitCost: 0,
|
|
164
|
+
variationCostDiscountGroup: null, variationUnitCostDiscountGroup: null,
|
|
165
|
+
options: options,
|
|
166
|
+
}); };
|
|
167
|
+
return __assign(__assign({}, rules), { fields: [
|
|
168
|
+
f(900, [opt(901), opt(902)]),
|
|
169
|
+
f(910, [opt(911), opt(912, [902]), opt(913)]), // Colour: Red, Green(gated by 25mm), Blue
|
|
170
|
+
], groupFields: [] });
|
|
171
|
+
}
|
|
172
|
+
test('option with no selectedBy is always visible', function () {
|
|
173
|
+
var v = resolveVisibleOptionIds(sizeAndColourRules(), { fieldValues: {} });
|
|
174
|
+
expect(v.has(901)).toBe(true);
|
|
175
|
+
expect(v.has(911)).toBe(true);
|
|
176
|
+
expect(v.has(913)).toBe(true);
|
|
177
|
+
});
|
|
178
|
+
test('gated option is hidden until its trigger option is selected', function () {
|
|
179
|
+
var r = sizeAndColourRules();
|
|
180
|
+
var hidden = resolveVisibleOptionIds(r, { fieldValues: { 900: { selectedOptionIds: [901] } } });
|
|
181
|
+
expect(hidden.has(912)).toBe(false); // 24mm selected -> Green hidden
|
|
182
|
+
var visible = resolveVisibleOptionIds(r, { fieldValues: { 900: { selectedOptionIds: [902] } } });
|
|
183
|
+
expect(visible.has(912)).toBe(true); // 25mm selected -> Green visible
|
|
184
|
+
});
|
|
185
|
+
test('group option visibility resolves from group selections', function () {
|
|
186
|
+
var opt = function (id, selectedBy) {
|
|
187
|
+
if (selectedBy === void 0) { selectedBy = []; }
|
|
188
|
+
return ({
|
|
189
|
+
id: id,
|
|
190
|
+
originalId: id, position: id, default: false,
|
|
191
|
+
variationCost: 0, variationUnitCost: 0,
|
|
192
|
+
variationCostDiscountGroup: null, variationUnitCostDiscountGroup: null,
|
|
193
|
+
selectedBy: selectedBy,
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
var f = function (id, options) { return ({
|
|
197
|
+
id: id,
|
|
198
|
+
originalId: id, position: 0, fieldType: 2, independent: true,
|
|
199
|
+
isSelectable: true, selectedBy: [],
|
|
200
|
+
variationCost: 0, variationUnitCost: 0,
|
|
201
|
+
variationCostDiscountGroup: null, variationUnitCostDiscountGroup: null,
|
|
202
|
+
options: options,
|
|
203
|
+
}); };
|
|
204
|
+
var groupRules = __assign(__assign({}, rules), { fields: [], hasGroups: true, groupFields: [f(800, [opt(801), opt(802)]), f(810, [opt(811, [802])])] });
|
|
205
|
+
var v = resolveVisibleOptionIds(groupRules, {
|
|
206
|
+
fieldValues: {},
|
|
207
|
+
groups: [{ quantity: 5, fieldValues: { 800: { selectedOptionIds: [802] } } }],
|
|
208
|
+
});
|
|
209
|
+
expect(v.has(811)).toBe(true);
|
|
210
|
+
});
|
package/dist/request.js
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
var __values = (this && this.__values) || function(o) {
|
|
17
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
18
|
+
if (m) return m.call(o);
|
|
19
|
+
if (o && typeof o.length === "number") return {
|
|
20
|
+
next: function () {
|
|
21
|
+
if (o && i >= o.length) o = void 0;
|
|
22
|
+
return { value: o && o[i++], done: !o };
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
26
|
+
};
|
|
27
|
+
// eslint-disable-next-line no-unused-vars
|
|
28
|
+
import { getErrorFromCode } from './constants/errors.js';
|
|
29
|
+
var ApiError = /** @class */ (function (_super) {
|
|
30
|
+
__extends(ApiError, _super);
|
|
31
|
+
function ApiError(err) {
|
|
32
|
+
var _this = this;
|
|
33
|
+
var message = JSON.stringify(err);
|
|
34
|
+
/* istanbul ignore next */
|
|
35
|
+
_this = _super.call(this, message) || this;
|
|
36
|
+
_this.statusCode = err.statusCode;
|
|
37
|
+
_this.errorCode = getErrorFromCode(err.errorCode);
|
|
38
|
+
_this.errorMessage = err.message ?
|
|
39
|
+
err.message : 'No error message';
|
|
40
|
+
_this.details = err.details;
|
|
41
|
+
_this.name = 'ApiError';
|
|
42
|
+
_this.original = err;
|
|
43
|
+
return _this;
|
|
44
|
+
}
|
|
45
|
+
return ApiError;
|
|
46
|
+
}(Error));
|
|
47
|
+
export { ApiError };
|
|
48
|
+
export var version = 'v6';
|
|
49
|
+
function ensureVersionInUri(baseUrl) {
|
|
50
|
+
// Ensure baseUrl ends with a slash
|
|
51
|
+
var uri = baseUrl;
|
|
52
|
+
if (!uri.endsWith('/')) {
|
|
53
|
+
uri += '/';
|
|
54
|
+
}
|
|
55
|
+
// Check if the URI already includes a version
|
|
56
|
+
var versionPattern = new RegExp('/v\\d+/?$');
|
|
57
|
+
var match = uri.match(versionPattern);
|
|
58
|
+
if (match) {
|
|
59
|
+
// Extract the version and remove it from the URI
|
|
60
|
+
var foundVersion = match[0].replace(/\//g, '');
|
|
61
|
+
var strippedUri = uri.replace(versionPattern, '/');
|
|
62
|
+
return {
|
|
63
|
+
baseUrl: strippedUri,
|
|
64
|
+
version: foundVersion
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
baseUrl: uri,
|
|
69
|
+
version: version
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export function backendFetch(baseUrl, resource, options) {
|
|
73
|
+
var e_1, _a;
|
|
74
|
+
var _b = ensureVersionInUri(baseUrl), cleanBaseUrl = _b.baseUrl, apiVersion = _b.version;
|
|
75
|
+
// Remove leading slash from resource if it exists to prevent double slashes
|
|
76
|
+
var cleanResource = resource.startsWith('/') ? resource.slice(1) : resource;
|
|
77
|
+
var url = new URL(cleanBaseUrl + apiVersion + '/' + cleanResource);
|
|
78
|
+
if (options && options.query) {
|
|
79
|
+
try {
|
|
80
|
+
for (var _c = __values(options.query), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
81
|
+
var entry = _d.value;
|
|
82
|
+
url.searchParams.append(entry[0], entry[1]);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
86
|
+
finally {
|
|
87
|
+
try {
|
|
88
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
89
|
+
}
|
|
90
|
+
finally { if (e_1) throw e_1.error; }
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return fetch(url.toString(), options);
|
|
94
|
+
}
|
|
95
|
+
export function apiFetch(baseUrl, resource, options, expectEmptyResponse) {
|
|
96
|
+
return backendFetch(baseUrl, resource, options).then(function (response) {
|
|
97
|
+
if (response.status < 200 || response.status > 299) {
|
|
98
|
+
return response.json().then(function (json) {
|
|
99
|
+
var err = new ApiError(json);
|
|
100
|
+
return Promise.reject(err);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
return expectEmptyResponse ? '' : response.json();
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
/* istanbul ignore next */
|
|
109
|
+
export function apiFetchWithProgress(baseUrl, resource, options, progressCallback) {
|
|
110
|
+
return backendFetch(baseUrl, resource, options).then(function (response) {
|
|
111
|
+
if (!response.body) {
|
|
112
|
+
var err = new ApiError('empty response');
|
|
113
|
+
return Promise.reject(err);
|
|
114
|
+
}
|
|
115
|
+
var reader = response.body.getReader();
|
|
116
|
+
var bodyText = '';
|
|
117
|
+
var errorText = '';
|
|
118
|
+
var haveError = false;
|
|
119
|
+
var expected = '{"loadingBar": "' + '.'.repeat(100) + '"}';
|
|
120
|
+
function readChunk() {
|
|
121
|
+
return reader.read().then(function (_a) {
|
|
122
|
+
var done = _a.done, value = _a.value;
|
|
123
|
+
if (done) {
|
|
124
|
+
if (response.status < 200 || response.status > 299) {
|
|
125
|
+
var err = new ApiError('Unknown error');
|
|
126
|
+
return Promise.reject(err);
|
|
127
|
+
}
|
|
128
|
+
else if (haveError) {
|
|
129
|
+
try {
|
|
130
|
+
var jsonText = JSON.parse(errorText);
|
|
131
|
+
return Promise.reject(new ApiError(jsonText));
|
|
132
|
+
}
|
|
133
|
+
catch (e) {
|
|
134
|
+
return Promise.reject(new ApiError(errorText));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
return bodyText;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
var chunk = new TextDecoder().decode(value);
|
|
143
|
+
if (haveError) {
|
|
144
|
+
errorText += chunk;
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
for (var i = 0; i < chunk.length; ++i) {
|
|
148
|
+
var char = chunk[i];
|
|
149
|
+
var expectedChar = expected[bodyText.length];
|
|
150
|
+
if (expectedChar == char && !haveError) {
|
|
151
|
+
bodyText += char;
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
haveError = true;
|
|
155
|
+
errorText += char;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (!haveError && progressCallback) {
|
|
160
|
+
var progress = Math.min(Math.max(0, bodyText.length - 16), 100);
|
|
161
|
+
progressCallback(progress);
|
|
162
|
+
}
|
|
163
|
+
return readChunk();
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
return readChunk();
|
|
168
|
+
});
|
|
169
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { apiFetch } from './request.js';
|
|
2
|
+
import { ErrorType } from './constants/errors.js';
|
|
3
|
+
import { setup, mockFetch } from './test_util.js';
|
|
4
|
+
setup();
|
|
5
|
+
test('can pass through data from server', function () {
|
|
6
|
+
mockFetch(true, { 'animal': 'turtle' }, 200);
|
|
7
|
+
return apiFetch('https://api.merchi.co/', '/test').then(function (data) {
|
|
8
|
+
expect(data.animal).toBe('turtle');
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
test('can pass through data from server with override url', function () {
|
|
12
|
+
window.merchiBackendUri = 'http://override.example.com/';
|
|
13
|
+
mockFetch(true, { 'animal': 'turtle' }, 200);
|
|
14
|
+
return apiFetch('https://api.merchi.co/', '/test').then(function (data) {
|
|
15
|
+
expect(data.animal).toBe('turtle');
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
test('404 creates ApiError', function () {
|
|
19
|
+
mockFetch(false, { 'statusCode': 404, 'errorCode': ErrorType.RESOURCE_NOT_FOUND }, 404);
|
|
20
|
+
apiFetch('https://api.merchi.co/', '/test').catch(function (e) {
|
|
21
|
+
expect(e.statusCode).toBe(404);
|
|
22
|
+
expect(e.name).toBe('ApiError');
|
|
23
|
+
expect(e.errorCode).toBe(ErrorType.RESOURCE_NOT_FOUND);
|
|
24
|
+
expect(e.errorMessage).toBe('No error message');
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
test('will get default errorCode', function () {
|
|
28
|
+
mockFetch(false, { 'statusCode': 404,
|
|
29
|
+
'errorCode': -1,
|
|
30
|
+
'message': 'just a test' }, 404);
|
|
31
|
+
apiFetch('https://api.merchi.co/', '/test').catch(function (e) {
|
|
32
|
+
expect(e.statusCode).toBe(404);
|
|
33
|
+
expect(e.name).toBe('ApiError');
|
|
34
|
+
expect(e.errorCode).toBe(ErrorType.UNKNOWN_ERROR);
|
|
35
|
+
expect(e.errorMessage).toBe('just a test');
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
test('ApiError exposes details when the server supplies them', function () {
|
|
39
|
+
var details = {
|
|
40
|
+
relation: 'file',
|
|
41
|
+
parentType: 'variation',
|
|
42
|
+
id: 'abc123',
|
|
43
|
+
index: 0,
|
|
44
|
+
provided: {
|
|
45
|
+
id: 'abc123',
|
|
46
|
+
uploadId: 'upload-xyz',
|
|
47
|
+
creationDate: '1776978388',
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
mockFetch(false, {
|
|
51
|
+
'statusCode': 404,
|
|
52
|
+
'errorCode': ErrorType.RESOURCE_NOT_FOUND,
|
|
53
|
+
'message': 'no such file #abc123 on variation',
|
|
54
|
+
'details': details,
|
|
55
|
+
}, 404);
|
|
56
|
+
return apiFetch('https://api.merchi.co/', '/test').catch(function (e) {
|
|
57
|
+
expect(e.name).toBe('ApiError');
|
|
58
|
+
expect(e.details).toEqual(details);
|
|
59
|
+
expect(e.details.provided.uploadId).toBe('upload-xyz');
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
test('ApiError leaves details undefined when the server omits them', function () {
|
|
63
|
+
mockFetch(false, { 'statusCode': 400,
|
|
64
|
+
'errorCode': ErrorType.RESOURCE_NOT_FOUND,
|
|
65
|
+
'message': 'plain error' }, 400);
|
|
66
|
+
return apiFetch('https://api.merchi.co/', '/test').catch(function (e) {
|
|
67
|
+
expect(e.name).toBe('ApiError');
|
|
68
|
+
expect(e.details).toBeUndefined();
|
|
69
|
+
});
|
|
70
|
+
});
|