@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,238 @@
|
|
|
1
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
2
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
|
+
if (!m) return o;
|
|
4
|
+
var i = m.call(o), r, ar = [], e;
|
|
5
|
+
try {
|
|
6
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
7
|
+
}
|
|
8
|
+
catch (error) { e = { error: error }; }
|
|
9
|
+
finally {
|
|
10
|
+
try {
|
|
11
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
12
|
+
}
|
|
13
|
+
finally { if (e) throw e.error; }
|
|
14
|
+
}
|
|
15
|
+
return ar;
|
|
16
|
+
};
|
|
17
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
18
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
19
|
+
if (ar || !(i in from)) {
|
|
20
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
21
|
+
ar[i] = from[i];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
25
|
+
};
|
|
26
|
+
var __values = (this && this.__values) || function(o) {
|
|
27
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
28
|
+
if (m) return m.call(o);
|
|
29
|
+
if (o && typeof o.length === "number") return {
|
|
30
|
+
next: function () {
|
|
31
|
+
if (o && i >= o.length) o = void 0;
|
|
32
|
+
return { value: o && o[i++], done: !o };
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
36
|
+
};
|
|
37
|
+
// Returns the set of option ids that should be DISABLED because the combination
|
|
38
|
+
// of (current inventory-relevant selections + that option) has no matching
|
|
39
|
+
// inventory with stock. Mirrors the server's subset match
|
|
40
|
+
// (inventories.py `inventories_subset_match_strategy`): an inventory matches a
|
|
41
|
+
// selection when it contains every selected option; an option is available if
|
|
42
|
+
// any matching inventory has quantity > 0.
|
|
43
|
+
//
|
|
44
|
+
// Scope: pass the container's selections (independent fields use the top-level
|
|
45
|
+
// selections; a group uses its own + independent). Only options that appear in
|
|
46
|
+
// at least one inventory unit are inventory-tracked; all others are always
|
|
47
|
+
// available. Direct product inventories only (no shared inventory groups).
|
|
48
|
+
export function resolveUnavailableOptionIds(rules, selections) {
|
|
49
|
+
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f, e_7, _g;
|
|
50
|
+
var unavailable = new Set();
|
|
51
|
+
var units = rules.inventoryUnits || [];
|
|
52
|
+
if (units.length === 0)
|
|
53
|
+
return unavailable;
|
|
54
|
+
var allFields = __spreadArray(__spreadArray([], __read(rules.fields), false), __read(rules.groupFields), false);
|
|
55
|
+
// Canonicalise id/originalId to a single id per option so bundle option ids,
|
|
56
|
+
// selected ids and inventory unit ids all compare consistently.
|
|
57
|
+
var canonical = new Map();
|
|
58
|
+
var fieldIdByOption = new Map();
|
|
59
|
+
try {
|
|
60
|
+
for (var allFields_1 = __values(allFields), allFields_1_1 = allFields_1.next(); !allFields_1_1.done; allFields_1_1 = allFields_1.next()) {
|
|
61
|
+
var f = allFields_1_1.value;
|
|
62
|
+
try {
|
|
63
|
+
for (var _h = (e_2 = void 0, __values(f.options)), _j = _h.next(); !_j.done; _j = _h.next()) {
|
|
64
|
+
var o = _j.value;
|
|
65
|
+
canonical.set(o.id, o.id);
|
|
66
|
+
fieldIdByOption.set(o.id, f.id);
|
|
67
|
+
if (o.originalId != null) {
|
|
68
|
+
canonical.set(o.originalId, o.id);
|
|
69
|
+
fieldIdByOption.set(o.originalId, f.id);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
74
|
+
finally {
|
|
75
|
+
try {
|
|
76
|
+
if (_j && !_j.done && (_b = _h.return)) _b.call(_h);
|
|
77
|
+
}
|
|
78
|
+
finally { if (e_2) throw e_2.error; }
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
83
|
+
finally {
|
|
84
|
+
try {
|
|
85
|
+
if (allFields_1_1 && !allFields_1_1.done && (_a = allFields_1.return)) _a.call(allFields_1);
|
|
86
|
+
}
|
|
87
|
+
finally { if (e_1) throw e_1.error; }
|
|
88
|
+
}
|
|
89
|
+
var canon = function (id) { return (canonical.has(id) ? canonical.get(id) : id); };
|
|
90
|
+
var unitSets = units.map(function (u) { return ({
|
|
91
|
+
quantity: u.quantity,
|
|
92
|
+
optionIds: new Set(u.optionIds.map(canon)),
|
|
93
|
+
}); });
|
|
94
|
+
var inventoryOptionIds = new Set();
|
|
95
|
+
try {
|
|
96
|
+
for (var unitSets_1 = __values(unitSets), unitSets_1_1 = unitSets_1.next(); !unitSets_1_1.done; unitSets_1_1 = unitSets_1.next()) {
|
|
97
|
+
var u = unitSets_1_1.value;
|
|
98
|
+
try {
|
|
99
|
+
for (var _k = (e_4 = void 0, __values(u.optionIds)), _l = _k.next(); !_l.done; _l = _k.next()) {
|
|
100
|
+
var id = _l.value;
|
|
101
|
+
inventoryOptionIds.add(id);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
105
|
+
finally {
|
|
106
|
+
try {
|
|
107
|
+
if (_l && !_l.done && (_d = _k.return)) _d.call(_k);
|
|
108
|
+
}
|
|
109
|
+
finally { if (e_4) throw e_4.error; }
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
114
|
+
finally {
|
|
115
|
+
try {
|
|
116
|
+
if (unitSets_1_1 && !unitSets_1_1.done && (_c = unitSets_1.return)) _c.call(unitSets_1);
|
|
117
|
+
}
|
|
118
|
+
finally { if (e_3) throw e_3.error; }
|
|
119
|
+
}
|
|
120
|
+
// Collect currently-selected, inventory-tracked option ids grouped by field.
|
|
121
|
+
var selectedByField = new Map();
|
|
122
|
+
var addSelections = function (fieldValues) {
|
|
123
|
+
var e_8, _a, e_9, _b;
|
|
124
|
+
try {
|
|
125
|
+
for (var _c = __values(Object.keys(fieldValues)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
126
|
+
var key = _d.value;
|
|
127
|
+
var fieldId = Number(key);
|
|
128
|
+
var sel = fieldValues[fieldId];
|
|
129
|
+
if (!sel || !sel.selectedOptionIds)
|
|
130
|
+
continue;
|
|
131
|
+
var set = selectedByField.get(fieldId) || new Set();
|
|
132
|
+
try {
|
|
133
|
+
for (var _e = (e_9 = void 0, __values(sel.selectedOptionIds)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
134
|
+
var oid = _f.value;
|
|
135
|
+
var c = canon(oid);
|
|
136
|
+
if (inventoryOptionIds.has(c))
|
|
137
|
+
set.add(c);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
141
|
+
finally {
|
|
142
|
+
try {
|
|
143
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
144
|
+
}
|
|
145
|
+
finally { if (e_9) throw e_9.error; }
|
|
146
|
+
}
|
|
147
|
+
selectedByField.set(fieldId, set);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
151
|
+
finally {
|
|
152
|
+
try {
|
|
153
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
154
|
+
}
|
|
155
|
+
finally { if (e_8) throw e_8.error; }
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
addSelections(selections.fieldValues || {});
|
|
159
|
+
try {
|
|
160
|
+
for (var _m = __values(selections.groups || []), _o = _m.next(); !_o.done; _o = _m.next()) {
|
|
161
|
+
var group = _o.value;
|
|
162
|
+
addSelections(group.fieldValues || {});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
166
|
+
finally {
|
|
167
|
+
try {
|
|
168
|
+
if (_o && !_o.done && (_e = _m.return)) _e.call(_m);
|
|
169
|
+
}
|
|
170
|
+
finally { if (e_5) throw e_5.error; }
|
|
171
|
+
}
|
|
172
|
+
var hasGroups = Boolean(selections.groups && selections.groups.length > 0);
|
|
173
|
+
var fieldsToConsider = hasGroups ? allFields : rules.fields;
|
|
174
|
+
try {
|
|
175
|
+
for (var fieldsToConsider_1 = __values(fieldsToConsider), fieldsToConsider_1_1 = fieldsToConsider_1.next(); !fieldsToConsider_1_1.done; fieldsToConsider_1_1 = fieldsToConsider_1.next()) {
|
|
176
|
+
var f = fieldsToConsider_1_1.value;
|
|
177
|
+
var _loop_1 = function (o) {
|
|
178
|
+
var e_10, _r, e_11, _s;
|
|
179
|
+
var candidate = canon(o.id);
|
|
180
|
+
if (!inventoryOptionIds.has(candidate))
|
|
181
|
+
return "continue"; // not inventory-tracked
|
|
182
|
+
// filter = candidate + selected inventory options from OTHER fields.
|
|
183
|
+
var filter = [candidate];
|
|
184
|
+
try {
|
|
185
|
+
for (var selectedByField_1 = (e_10 = void 0, __values(selectedByField)), selectedByField_1_1 = selectedByField_1.next(); !selectedByField_1_1.done; selectedByField_1_1 = selectedByField_1.next()) {
|
|
186
|
+
var _t = __read(selectedByField_1_1.value, 2), fieldId = _t[0], set = _t[1];
|
|
187
|
+
if (fieldId === f.id)
|
|
188
|
+
continue;
|
|
189
|
+
try {
|
|
190
|
+
for (var set_1 = (e_11 = void 0, __values(set)), set_1_1 = set_1.next(); !set_1_1.done; set_1_1 = set_1.next()) {
|
|
191
|
+
var sid = set_1_1.value;
|
|
192
|
+
filter.push(sid);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
196
|
+
finally {
|
|
197
|
+
try {
|
|
198
|
+
if (set_1_1 && !set_1_1.done && (_s = set_1.return)) _s.call(set_1);
|
|
199
|
+
}
|
|
200
|
+
finally { if (e_11) throw e_11.error; }
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
205
|
+
finally {
|
|
206
|
+
try {
|
|
207
|
+
if (selectedByField_1_1 && !selectedByField_1_1.done && (_r = selectedByField_1.return)) _r.call(selectedByField_1);
|
|
208
|
+
}
|
|
209
|
+
finally { if (e_10) throw e_10.error; }
|
|
210
|
+
}
|
|
211
|
+
var available = unitSets.some(function (u) { return u.quantity > 0 && filter.every(function (id) { return u.optionIds.has(id); }); });
|
|
212
|
+
if (!available)
|
|
213
|
+
unavailable.add(o.id);
|
|
214
|
+
};
|
|
215
|
+
try {
|
|
216
|
+
for (var _p = (e_7 = void 0, __values(f.options)), _q = _p.next(); !_q.done; _q = _p.next()) {
|
|
217
|
+
var o = _q.value;
|
|
218
|
+
_loop_1(o);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
222
|
+
finally {
|
|
223
|
+
try {
|
|
224
|
+
if (_q && !_q.done && (_g = _p.return)) _g.call(_p);
|
|
225
|
+
}
|
|
226
|
+
finally { if (e_7) throw e_7.error; }
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
231
|
+
finally {
|
|
232
|
+
try {
|
|
233
|
+
if (fieldsToConsider_1_1 && !fieldsToConsider_1_1.done && (_f = fieldsToConsider_1.return)) _f.call(fieldsToConsider_1);
|
|
234
|
+
}
|
|
235
|
+
finally { if (e_6) throw e_6.error; }
|
|
236
|
+
}
|
|
237
|
+
return unavailable;
|
|
238
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { resolveUnavailableOptionIds } from './inventory.js';
|
|
2
|
+
// Size (24mm=801, 25mm=802) x Colour (Red=811, Green=812, Blue=813), with
|
|
3
|
+
// per-combination stock. 25mm-Blue = 0; 19mm/24mm-Blue has stock.
|
|
4
|
+
function rules(inventoryUnits) {
|
|
5
|
+
var opt = function (id) { return ({
|
|
6
|
+
id: id,
|
|
7
|
+
originalId: id, position: id, default: false,
|
|
8
|
+
variationCost: 0, variationUnitCost: 0,
|
|
9
|
+
variationCostDiscountGroup: null, variationUnitCostDiscountGroup: null,
|
|
10
|
+
selectedBy: [],
|
|
11
|
+
}); };
|
|
12
|
+
var f = function (id, options) { return ({
|
|
13
|
+
id: id,
|
|
14
|
+
originalId: id, position: 0, fieldType: 2, independent: false,
|
|
15
|
+
isSelectable: true, selectedBy: [],
|
|
16
|
+
variationCost: 0, variationUnitCost: 0,
|
|
17
|
+
variationCostDiscountGroup: null, variationUnitCostDiscountGroup: null,
|
|
18
|
+
options: options.map(opt),
|
|
19
|
+
}); };
|
|
20
|
+
return {
|
|
21
|
+
currency: 'AUD', taxPercent: 0,
|
|
22
|
+
product: { unitPrice: 0, minimumPrice: null, discountGroup: null },
|
|
23
|
+
fields: [], hasGroups: true, needsInventory: true,
|
|
24
|
+
groupFields: [f(800, [801, 802]), f(810, [811, 812, 813])],
|
|
25
|
+
inventoryUnits: inventoryUnits,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
var units = [
|
|
29
|
+
{ optionIds: [801, 813], quantity: 5 },
|
|
30
|
+
{ optionIds: [802, 811], quantity: 7 },
|
|
31
|
+
{ optionIds: [802, 812], quantity: 7 },
|
|
32
|
+
{ optionIds: [802, 813], quantity: 0 }, // 25mm-Blue: OUT OF STOCK
|
|
33
|
+
];
|
|
34
|
+
test('no inventory units -> nothing unavailable', function () {
|
|
35
|
+
var r = rules([]);
|
|
36
|
+
expect(resolveUnavailableOptionIds(r, { fieldValues: {}, groups: [{ quantity: 1, fieldValues: {} }] }).size).toBe(0);
|
|
37
|
+
});
|
|
38
|
+
test('with no other selection, an option with stock somewhere is available', function () {
|
|
39
|
+
var r = rules(units);
|
|
40
|
+
// Nothing selected: Blue has stock as 24mm-Blue, so not unavailable.
|
|
41
|
+
var u = resolveUnavailableOptionIds(r, { fieldValues: {}, groups: [{ quantity: 1, fieldValues: {} }] });
|
|
42
|
+
expect(u.has(813)).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
test('25mm makes Blue unavailable but keeps Red/Green available', function () {
|
|
45
|
+
var r = rules(units);
|
|
46
|
+
var u = resolveUnavailableOptionIds(r, {
|
|
47
|
+
fieldValues: {},
|
|
48
|
+
groups: [{ quantity: 1, fieldValues: { 800: { selectedOptionIds: [802] } } }],
|
|
49
|
+
});
|
|
50
|
+
expect(u.has(813)).toBe(true); // 25mm-Blue = 0 -> Blue disabled
|
|
51
|
+
expect(u.has(811)).toBe(false); // 25mm-Red ok
|
|
52
|
+
expect(u.has(812)).toBe(false); // 25mm-Green ok
|
|
53
|
+
});
|
|
54
|
+
test('selecting Blue makes 25mm unavailable (combination-aware both directions)', function () {
|
|
55
|
+
var r = rules(units);
|
|
56
|
+
var u = resolveUnavailableOptionIds(r, {
|
|
57
|
+
fieldValues: {},
|
|
58
|
+
groups: [{ quantity: 1, fieldValues: { 810: { selectedOptionIds: [813] } } }],
|
|
59
|
+
});
|
|
60
|
+
expect(u.has(802)).toBe(true); // 25mm + Blue = 0 -> 25mm disabled
|
|
61
|
+
expect(u.has(801)).toBe(false); // 24mm + Blue = 5 -> 24mm ok
|
|
62
|
+
});
|
|
63
|
+
test('per-group scope: one group selecting 25mm does not disable Blue in another', function () {
|
|
64
|
+
var r = rules(units);
|
|
65
|
+
var u = resolveUnavailableOptionIds(r, {
|
|
66
|
+
fieldValues: {},
|
|
67
|
+
groups: [{ quantity: 1, fieldValues: { 800: { selectedOptionIds: [801] } } }],
|
|
68
|
+
});
|
|
69
|
+
// 24mm selected here -> 24mm-Blue has stock -> Blue available.
|
|
70
|
+
expect(u.has(813)).toBe(false);
|
|
71
|
+
});
|
|
72
|
+
test('omitted inventoryUnits -> nothing unavailable', function () {
|
|
73
|
+
var r = rules(units);
|
|
74
|
+
delete r.inventoryUnits;
|
|
75
|
+
expect(resolveUnavailableOptionIds(r, { fieldValues: {} }).size).toBe(0);
|
|
76
|
+
});
|
|
77
|
+
test('non-group product: top-level selections drive availability', function () {
|
|
78
|
+
var opt = function (id) { return ({
|
|
79
|
+
id: id,
|
|
80
|
+
originalId: null, position: id, default: false,
|
|
81
|
+
variationCost: 0, variationUnitCost: 0,
|
|
82
|
+
variationCostDiscountGroup: null, variationUnitCostDiscountGroup: null,
|
|
83
|
+
selectedBy: [],
|
|
84
|
+
}); };
|
|
85
|
+
var f = function (id, options) { return ({
|
|
86
|
+
id: id,
|
|
87
|
+
originalId: id, position: 0, fieldType: 2, independent: true,
|
|
88
|
+
isSelectable: true, selectedBy: [],
|
|
89
|
+
variationCost: 0, variationUnitCost: 0,
|
|
90
|
+
variationCostDiscountGroup: null, variationUnitCostDiscountGroup: null,
|
|
91
|
+
options: options.map(opt),
|
|
92
|
+
}); };
|
|
93
|
+
var r = {
|
|
94
|
+
currency: 'AUD', taxPercent: 0,
|
|
95
|
+
product: { unitPrice: 0, minimumPrice: null, discountGroup: null },
|
|
96
|
+
hasGroups: false, needsInventory: true,
|
|
97
|
+
fields: [f(800, [801, 802]), f(810, [811, 813])],
|
|
98
|
+
groupFields: [],
|
|
99
|
+
inventoryUnits: [
|
|
100
|
+
{ optionIds: [802, 811], quantity: 7 },
|
|
101
|
+
{ optionIds: [802, 813], quantity: 0 }, // 25mm-Blue OUT
|
|
102
|
+
],
|
|
103
|
+
};
|
|
104
|
+
var u = resolveUnavailableOptionIds(r, {
|
|
105
|
+
quantity: 1,
|
|
106
|
+
fieldValues: { 800: { selectedOptionIds: [802] } },
|
|
107
|
+
});
|
|
108
|
+
expect(u.has(813)).toBe(true); // 25mm-Blue unavailable
|
|
109
|
+
expect(u.has(811)).toBe(false); // 25mm-Red ok
|
|
110
|
+
});
|
|
111
|
+
test('non-inventory options and non-selection field values are ignored', function () {
|
|
112
|
+
var r = rules(units);
|
|
113
|
+
// Field 810 option 999 is not in any unit (not tracked); a value-only field
|
|
114
|
+
// and an undefined selection entry exercise the skip branches.
|
|
115
|
+
r.groupFields[1].options.push({
|
|
116
|
+
id: 999, originalId: null, position: 9, default: false,
|
|
117
|
+
variationCost: 0, variationUnitCost: 0,
|
|
118
|
+
variationCostDiscountGroup: null, variationUnitCostDiscountGroup: null,
|
|
119
|
+
selectedBy: [],
|
|
120
|
+
});
|
|
121
|
+
var u = resolveUnavailableOptionIds(r, {
|
|
122
|
+
fieldValues: { 700: { value: 'text' }, 701: undefined },
|
|
123
|
+
groups: [{ quantity: 1, fieldValues: { 800: { selectedOptionIds: [802] }, 810: { selectedOptionIds: [999] } } }],
|
|
124
|
+
});
|
|
125
|
+
expect(u.has(999)).toBe(false); // untracked option is always available
|
|
126
|
+
expect(u.has(813)).toBe(true); // 25mm-Blue still unavailable
|
|
127
|
+
});
|
|
128
|
+
test('undefined top-level fieldValues and group fieldValues are tolerated', function () {
|
|
129
|
+
var r = rules(units);
|
|
130
|
+
var u = resolveUnavailableOptionIds(r, {
|
|
131
|
+
fieldValues: undefined,
|
|
132
|
+
groups: [{ quantity: 1, fieldValues: undefined }],
|
|
133
|
+
});
|
|
134
|
+
// No selections -> only options with zero stock everywhere would be flagged;
|
|
135
|
+
// every option here has stock in some combo, so none unavailable.
|
|
136
|
+
expect(u.size).toBe(0);
|
|
137
|
+
});
|
|
138
|
+
test('same field selected at top level and in a group merges selections', function () {
|
|
139
|
+
var r = rules(units);
|
|
140
|
+
var u = resolveUnavailableOptionIds(r, {
|
|
141
|
+
fieldValues: { 800: { selectedOptionIds: [802] } },
|
|
142
|
+
groups: [{ quantity: 1, fieldValues: { 800: { selectedOptionIds: [802] } } }],
|
|
143
|
+
});
|
|
144
|
+
expect(u.has(813)).toBe(true); // 25mm selected (both scopes) -> Blue unavailable
|
|
145
|
+
});
|
|
146
|
+
test('unit referencing an unknown option id falls back to the raw id', function () {
|
|
147
|
+
var r = rules([
|
|
148
|
+
{ optionIds: [802, 813], quantity: 0 },
|
|
149
|
+
{ optionIds: [802, 5555], quantity: 9 }, // 5555 not a known option
|
|
150
|
+
]);
|
|
151
|
+
// 25mm + Blue still 0; the unknown id just never matches a selection.
|
|
152
|
+
var u = resolveUnavailableOptionIds(r, {
|
|
153
|
+
fieldValues: {},
|
|
154
|
+
groups: [{ quantity: 1, fieldValues: { 800: { selectedOptionIds: [802] } } }],
|
|
155
|
+
});
|
|
156
|
+
expect(u.has(813)).toBe(true);
|
|
157
|
+
});
|
|
158
|
+
test('originalId is canonicalised when matching units', function () {
|
|
159
|
+
var opt = function (id, originalId) { return ({
|
|
160
|
+
id: id,
|
|
161
|
+
originalId: originalId,
|
|
162
|
+
position: id, default: false,
|
|
163
|
+
variationCost: 0, variationUnitCost: 0,
|
|
164
|
+
variationCostDiscountGroup: null, variationUnitCostDiscountGroup: null,
|
|
165
|
+
selectedBy: [],
|
|
166
|
+
}); };
|
|
167
|
+
var r = {
|
|
168
|
+
currency: 'AUD', taxPercent: 0,
|
|
169
|
+
product: { unitPrice: 0, minimumPrice: null, discountGroup: null },
|
|
170
|
+
fields: [], hasGroups: true, needsInventory: true,
|
|
171
|
+
groupFields: [
|
|
172
|
+
{
|
|
173
|
+
id: 800, originalId: 800, position: 0, fieldType: 2, independent: false,
|
|
174
|
+
isSelectable: true, selectedBy: [],
|
|
175
|
+
variationCost: 0, variationUnitCost: 0,
|
|
176
|
+
variationCostDiscountGroup: null, variationUnitCostDiscountGroup: null,
|
|
177
|
+
options: [opt(900, 802)], // cloned option 900 whose original is 802
|
|
178
|
+
},
|
|
179
|
+
],
|
|
180
|
+
// inventory references the original id 802
|
|
181
|
+
inventoryUnits: [{ optionIds: [802], quantity: 0 }],
|
|
182
|
+
};
|
|
183
|
+
var u = resolveUnavailableOptionIds(r, {
|
|
184
|
+
fieldValues: {},
|
|
185
|
+
groups: [{ quantity: 1, fieldValues: {} }],
|
|
186
|
+
});
|
|
187
|
+
expect(u.has(900)).toBe(true); // original 802 has 0 stock -> cloned 900 unavailable
|
|
188
|
+
});
|
|
@@ -0,0 +1,245 @@
|
|
|
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
|
+
var __values = (this && this.__values) || function(o) {
|
|
13
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
14
|
+
if (m) return m.call(o);
|
|
15
|
+
if (o && typeof o.length === "number") return {
|
|
16
|
+
next: function () {
|
|
17
|
+
if (o && i >= o.length) o = void 0;
|
|
18
|
+
return { value: o && o[i++], done: !o };
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
22
|
+
};
|
|
23
|
+
import { estimateQuote } from './estimate.js';
|
|
24
|
+
function toQuantity(value) {
|
|
25
|
+
var n = Number(value);
|
|
26
|
+
return Number.isFinite(n) ? n : 0;
|
|
27
|
+
}
|
|
28
|
+
function floorMinQuantity(value) {
|
|
29
|
+
var n = toQuantity(value);
|
|
30
|
+
return n >= 1 ? Math.round(n) : 1;
|
|
31
|
+
}
|
|
32
|
+
function addDiscountLimits(group, limits, minQuantity) {
|
|
33
|
+
var e_1, _a;
|
|
34
|
+
if (!group || !group.discounts)
|
|
35
|
+
return;
|
|
36
|
+
try {
|
|
37
|
+
for (var _b = __values(group.discounts), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
38
|
+
var discount = _c.value;
|
|
39
|
+
var n = Number(discount.lowerLimit);
|
|
40
|
+
if (!Number.isFinite(n))
|
|
41
|
+
continue;
|
|
42
|
+
var qty = Math.round(n);
|
|
43
|
+
if (qty > minQuantity)
|
|
44
|
+
limits.add(qty);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
48
|
+
finally {
|
|
49
|
+
try {
|
|
50
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
51
|
+
}
|
|
52
|
+
finally { if (e_1) throw e_1.error; }
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function collectFieldDiscountLimits(field, limits, minQuantity) {
|
|
56
|
+
var e_2, _a;
|
|
57
|
+
addDiscountLimits(field.variationCostDiscountGroup, limits, minQuantity);
|
|
58
|
+
addDiscountLimits(field.variationUnitCostDiscountGroup, limits, minQuantity);
|
|
59
|
+
addDiscountLimits(field.heightVariationCostDiscountGroup, limits, minQuantity);
|
|
60
|
+
addDiscountLimits(field.heightVariationUnitCostDiscountGroup, limits, minQuantity);
|
|
61
|
+
addDiscountLimits(field.widthVariationCostDiscountGroup, limits, minQuantity);
|
|
62
|
+
addDiscountLimits(field.widthVariationUnitCostDiscountGroup, limits, minQuantity);
|
|
63
|
+
try {
|
|
64
|
+
for (var _b = __values(field.options), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
65
|
+
var option = _c.value;
|
|
66
|
+
addDiscountLimits(option.variationCostDiscountGroup, limits, minQuantity);
|
|
67
|
+
addDiscountLimits(option.variationUnitCostDiscountGroup, limits, minQuantity);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
71
|
+
finally {
|
|
72
|
+
try {
|
|
73
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
74
|
+
}
|
|
75
|
+
finally { if (e_2) throw e_2.error; }
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function collectQuantityBreaks(rules, minQuantity) {
|
|
79
|
+
var e_3, _a, e_4, _b;
|
|
80
|
+
var limits = new Set([minQuantity]);
|
|
81
|
+
addDiscountLimits(rules.product.discountGroup, limits, minQuantity);
|
|
82
|
+
try {
|
|
83
|
+
for (var _c = __values(rules.fields), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
84
|
+
var item = _d.value;
|
|
85
|
+
collectFieldDiscountLimits(item, limits, minQuantity);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
89
|
+
finally {
|
|
90
|
+
try {
|
|
91
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
92
|
+
}
|
|
93
|
+
finally { if (e_3) throw e_3.error; }
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
for (var _e = __values(rules.groupFields), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
97
|
+
var item = _f.value;
|
|
98
|
+
collectFieldDiscountLimits(item, limits, minQuantity);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
102
|
+
finally {
|
|
103
|
+
try {
|
|
104
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
105
|
+
}
|
|
106
|
+
finally { if (e_4) throw e_4.error; }
|
|
107
|
+
}
|
|
108
|
+
return Array.from(limits).sort(function (a, b) { return a - b; });
|
|
109
|
+
}
|
|
110
|
+
function groupHasValues(group) {
|
|
111
|
+
var values = group.fieldValues || {};
|
|
112
|
+
return Object.keys(values).some(function (key) {
|
|
113
|
+
var selection = values[Number(key)];
|
|
114
|
+
if (!selection)
|
|
115
|
+
return false;
|
|
116
|
+
if (selection.selectedOptionIds && selection.selectedOptionIds.length) {
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
var value = selection.value;
|
|
120
|
+
return !(value === undefined ||
|
|
121
|
+
value === null ||
|
|
122
|
+
value === '' ||
|
|
123
|
+
value === 0);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
function representativeGroupIndex(groups) {
|
|
127
|
+
var idx = groups.findIndex(groupHasValues);
|
|
128
|
+
return idx >= 0 ? idx : 0;
|
|
129
|
+
}
|
|
130
|
+
function selectionsAtQuantity(selections, qty) {
|
|
131
|
+
var groups = selections.groups;
|
|
132
|
+
if (groups && groups.length > 0) {
|
|
133
|
+
var quantities = groups.map(function (group) { return toQuantity(group.quantity); });
|
|
134
|
+
var total = quantities.reduce(function (sum, value) { return sum + value; }, 0);
|
|
135
|
+
if (total <= 0) {
|
|
136
|
+
var idx_1 = representativeGroupIndex(groups);
|
|
137
|
+
return {
|
|
138
|
+
fieldValues: selections.fieldValues || {},
|
|
139
|
+
groups: groups.map(function (group, i) { return (__assign(__assign({}, group), { quantity: i === idx_1 ? qty : 0 })); }),
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
var scaled_1 = new Array(groups.length).fill(0);
|
|
143
|
+
var allocated = 0;
|
|
144
|
+
for (var i = 0; i < groups.length - 1; i++) {
|
|
145
|
+
scaled_1[i] = Math.round((quantities[i] / total) * qty);
|
|
146
|
+
allocated += scaled_1[i];
|
|
147
|
+
}
|
|
148
|
+
scaled_1[groups.length - 1] = Math.max(0, qty - allocated);
|
|
149
|
+
return {
|
|
150
|
+
fieldValues: selections.fieldValues || {},
|
|
151
|
+
groups: groups.map(function (group, i) { return (__assign(__assign({}, group), { quantity: scaled_1[i] })); }),
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
fieldValues: selections.fieldValues || {},
|
|
156
|
+
quantity: qty,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function formatBandLabel(quantity, upperLimit) {
|
|
160
|
+
if (upperLimit == null)
|
|
161
|
+
return "".concat(quantity, "+");
|
|
162
|
+
if (upperLimit === quantity)
|
|
163
|
+
return "".concat(quantity);
|
|
164
|
+
return "".concat(quantity, "\u2013").concat(upperLimit);
|
|
165
|
+
}
|
|
166
|
+
function samePrice(a, b) {
|
|
167
|
+
return (Math.abs(a.costPerUnit - b.costPerUnit) < 0.001 &&
|
|
168
|
+
Math.abs(a.unitPrice - b.unitPrice) < 0.001);
|
|
169
|
+
}
|
|
170
|
+
function withBandBounds(quantities) {
|
|
171
|
+
return quantities.map(function (quantity, i) {
|
|
172
|
+
var next = quantities[i + 1];
|
|
173
|
+
var upperLimit = next == null ? null : next - 1;
|
|
174
|
+
return {
|
|
175
|
+
quantity: quantity,
|
|
176
|
+
upperLimit: upperLimit,
|
|
177
|
+
label: formatBandLabel(quantity, upperLimit),
|
|
178
|
+
};
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Quantity-break price table for the current selection.
|
|
183
|
+
*
|
|
184
|
+
* Columns are unique quantity thresholds from every discount group on the
|
|
185
|
+
* product, fields, and options. Each cell is `estimateQuote` at that quantity
|
|
186
|
+
* so the table matches what the form will charge. Returns null when there are
|
|
187
|
+
* fewer than two distinct prices (nothing useful to show).
|
|
188
|
+
*/
|
|
189
|
+
export function buildPriceMatrix(rules, selections, options) {
|
|
190
|
+
var e_5, _a, e_6, _b;
|
|
191
|
+
if (selections === void 0) { selections = { fieldValues: {} }; }
|
|
192
|
+
if (options === void 0) { options = {}; }
|
|
193
|
+
if (rules.unsupported)
|
|
194
|
+
return null;
|
|
195
|
+
var safeRules = __assign(__assign({}, rules), { fields: (rules.fields || []).map(function (item) { return (__assign(__assign({}, item), { options: item.options || [] })); }), groupFields: (rules.groupFields || []).map(function (item) { return (__assign(__assign({}, item), { options: item.options || [] })); }) });
|
|
196
|
+
var minQuantity = floorMinQuantity(options.minQuantity);
|
|
197
|
+
var quantities = collectQuantityBreaks(safeRules, minQuantity);
|
|
198
|
+
var quoted = [];
|
|
199
|
+
try {
|
|
200
|
+
for (var quantities_1 = __values(quantities), quantities_1_1 = quantities_1.next(); !quantities_1_1.done; quantities_1_1 = quantities_1.next()) {
|
|
201
|
+
var quantity = quantities_1_1.value;
|
|
202
|
+
var quote = estimateQuote(safeRules, selectionsAtQuantity(selections, quantity));
|
|
203
|
+
quoted.push({
|
|
204
|
+
quantity: quantity,
|
|
205
|
+
costPerUnit: quote.costPerUnit,
|
|
206
|
+
unitPrice: quote.cost / quantity,
|
|
207
|
+
cost: quote.cost,
|
|
208
|
+
taxAmount: quote.taxAmount,
|
|
209
|
+
totalCost: quote.totalCost,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
214
|
+
finally {
|
|
215
|
+
try {
|
|
216
|
+
if (quantities_1_1 && !quantities_1_1.done && (_a = quantities_1.return)) _a.call(quantities_1);
|
|
217
|
+
}
|
|
218
|
+
finally { if (e_5) throw e_5.error; }
|
|
219
|
+
}
|
|
220
|
+
var cells = [];
|
|
221
|
+
try {
|
|
222
|
+
for (var quoted_1 = __values(quoted), quoted_1_1 = quoted_1.next(); !quoted_1_1.done; quoted_1_1 = quoted_1.next()) {
|
|
223
|
+
var cell = quoted_1_1.value;
|
|
224
|
+
var prev = cells[cells.length - 1];
|
|
225
|
+
if (prev && samePrice(prev, cell))
|
|
226
|
+
continue;
|
|
227
|
+
cells.push(cell);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
231
|
+
finally {
|
|
232
|
+
try {
|
|
233
|
+
if (quoted_1_1 && !quoted_1_1.done && (_b = quoted_1.return)) _b.call(quoted_1);
|
|
234
|
+
}
|
|
235
|
+
finally { if (e_6) throw e_6.error; }
|
|
236
|
+
}
|
|
237
|
+
if (cells.length < 2)
|
|
238
|
+
return null;
|
|
239
|
+
return {
|
|
240
|
+
currency: rules.currency,
|
|
241
|
+
taxPercent: rules.taxPercent,
|
|
242
|
+
bands: withBandBounds(cells.map(function (cell) { return cell.quantity; })),
|
|
243
|
+
cells: cells,
|
|
244
|
+
};
|
|
245
|
+
}
|