@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,111 @@
|
|
|
1
|
+
import { PricingRules, PricingField, PricingOption, Selections } from './types.js';
|
|
2
|
+
|
|
3
|
+
function collectSelectedOptionIds(selections: Selections): number[] {
|
|
4
|
+
const ids: number[] = [];
|
|
5
|
+
const addFrom = (fieldValues: Record<number, { selectedOptionIds?: number[] }>) => {
|
|
6
|
+
for (const key of Object.keys(fieldValues)) {
|
|
7
|
+
const sel = fieldValues[Number(key)];
|
|
8
|
+
if (sel && sel.selectedOptionIds) ids.push(...sel.selectedOptionIds);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
addFrom(selections.fieldValues || {});
|
|
12
|
+
for (const group of selections.groups || []) addFrom(group.fieldValues || {});
|
|
13
|
+
return ids;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface Resolver {
|
|
17
|
+
allFields: PricingField[];
|
|
18
|
+
fieldsToConsider: PricingField[];
|
|
19
|
+
isFulfilled: (selectedBy: number[], checked: number[]) => boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Shared machinery for both field- and option-level conditional visibility.
|
|
23
|
+
// Mirrors the server's `check_selected_by_fullfilled` recursion: a `selectedBy`
|
|
24
|
+
// list is fulfilled when any of its trigger option ids is currently selected
|
|
25
|
+
// AND that selecting option is itself fulfilled (its own `selectedBy` and its
|
|
26
|
+
// owning field's `selectedBy`), with a `checked` accumulator to break cycles.
|
|
27
|
+
function buildResolver(rules: PricingRules, selections: Selections): Resolver {
|
|
28
|
+
const allFields: PricingField[] = [...rules.fields, ...rules.groupFields];
|
|
29
|
+
const optionsById = new Map<number, PricingOption>();
|
|
30
|
+
const fieldByOptionId = new Map<number, PricingField>();
|
|
31
|
+
for (const f of allFields) {
|
|
32
|
+
for (const o of f.options) {
|
|
33
|
+
optionsById.set(o.id, o);
|
|
34
|
+
fieldByOptionId.set(o.id, f);
|
|
35
|
+
if (o.originalId != null) {
|
|
36
|
+
optionsById.set(o.originalId, o);
|
|
37
|
+
fieldByOptionId.set(o.originalId, f);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const selectedOptionIds = collectSelectedOptionIds(selections);
|
|
43
|
+
|
|
44
|
+
const sameOption = (a: number, b: number): boolean => {
|
|
45
|
+
const oa = optionsById.get(a);
|
|
46
|
+
return oa != null && oa === optionsById.get(b);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const isFulfilled = (selectedBy: number[], checked: number[]): boolean => {
|
|
50
|
+
if (!selectedBy || selectedBy.length === 0) return true;
|
|
51
|
+
for (const triggerId of selectedBy) {
|
|
52
|
+
for (const selId of selectedOptionIds) {
|
|
53
|
+
if (!sameOption(triggerId, selId)) continue;
|
|
54
|
+
if (checked.includes(selId)) return true;
|
|
55
|
+
// sameOption only returns true for ids present in optionsById, and
|
|
56
|
+
// fieldByOptionId is populated in the same loop, so both lookups are
|
|
57
|
+
// guaranteed non-null here (mirrors server dereferencing directly).
|
|
58
|
+
const opt = optionsById.get(selId) as PricingOption;
|
|
59
|
+
const field = fieldByOptionId.get(selId) as PricingField;
|
|
60
|
+
const nextChecked = [...checked, selId];
|
|
61
|
+
if (
|
|
62
|
+
isFulfilled(opt.selectedBy, nextChecked) &&
|
|
63
|
+
isFulfilled(field.selectedBy, nextChecked)
|
|
64
|
+
) {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return false;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// Group variation fields only materialise as variations when the job
|
|
73
|
+
// actually has groups (the server builds them inside each `variations_group`
|
|
74
|
+
// via `VariationsGroups.mapper_variations`; with no groups there are no group
|
|
75
|
+
// variations at all). Independent fields are always in play. This mirrors the
|
|
76
|
+
// server, where a non-group job exposes no group fields.
|
|
77
|
+
const hasGroups = Boolean(selections.groups && selections.groups.length > 0);
|
|
78
|
+
const fieldsToConsider = hasGroups ? allFields : rules.fields;
|
|
79
|
+
|
|
80
|
+
return { allFields, fieldsToConsider, isFulfilled };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function resolveVisibleFields(
|
|
84
|
+
rules: PricingRules,
|
|
85
|
+
selections: Selections
|
|
86
|
+
): Set<number> {
|
|
87
|
+
const { fieldsToConsider, isFulfilled } = buildResolver(rules, selections);
|
|
88
|
+
const visible = new Set<number>();
|
|
89
|
+
for (const f of fieldsToConsider) {
|
|
90
|
+
if (isFulfilled(f.selectedBy, [])) visible.add(f.id);
|
|
91
|
+
}
|
|
92
|
+
return visible;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Returns the set of option ids whose own `selectedBy` is fulfilled — i.e. the
|
|
96
|
+
// options that should be visible/selectable given the current selections.
|
|
97
|
+
// Mirrors the server's per-option `isVisible = check_selected_by_fullfilled(
|
|
98
|
+
// option.selected_by)`. Options with no `selectedBy` are always visible.
|
|
99
|
+
export function resolveVisibleOptionIds(
|
|
100
|
+
rules: PricingRules,
|
|
101
|
+
selections: Selections
|
|
102
|
+
): Set<number> {
|
|
103
|
+
const { fieldsToConsider, isFulfilled } = buildResolver(rules, selections);
|
|
104
|
+
const visible = new Set<number>();
|
|
105
|
+
for (const f of fieldsToConsider) {
|
|
106
|
+
for (const o of f.options) {
|
|
107
|
+
if (isFulfilled(o.selectedBy, [])) visible.add(o.id);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return visible;
|
|
111
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { apiFetch } from './request.js';
|
|
2
|
+
import { ErrorType } from './constants/errors.js';
|
|
3
|
+
import { setup, mockFetch } from './test_util.js';
|
|
4
|
+
|
|
5
|
+
setup();
|
|
6
|
+
|
|
7
|
+
test('can pass through data from server', () => {
|
|
8
|
+
mockFetch(true, {'animal': 'turtle'}, 200);
|
|
9
|
+
return apiFetch('https://api.merchi.co/', '/test').then(data => {
|
|
10
|
+
expect(data.animal).toBe('turtle');
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test('can pass through data from server with override url', () => {
|
|
15
|
+
(window as any).merchiBackendUri = 'http://override.example.com/';
|
|
16
|
+
mockFetch(true, {'animal': 'turtle'}, 200);
|
|
17
|
+
return apiFetch('https://api.merchi.co/', '/test').then(data => {
|
|
18
|
+
expect(data.animal).toBe('turtle');
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('404 creates ApiError', () => {
|
|
23
|
+
mockFetch(false, {'statusCode': 404, 'errorCode': ErrorType.RESOURCE_NOT_FOUND}, 404);
|
|
24
|
+
apiFetch('https://api.merchi.co/', '/test').catch(e => {
|
|
25
|
+
expect(e.statusCode).toBe(404);
|
|
26
|
+
expect(e.name).toBe('ApiError');
|
|
27
|
+
expect(e.errorCode).toBe(ErrorType.RESOURCE_NOT_FOUND);
|
|
28
|
+
expect(e.errorMessage).toBe('No error message');
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('will get default errorCode', () => {
|
|
33
|
+
mockFetch(false,
|
|
34
|
+
{'statusCode': 404,
|
|
35
|
+
'errorCode': -1,
|
|
36
|
+
'message': 'just a test'}, 404);
|
|
37
|
+
apiFetch('https://api.merchi.co/', '/test').catch(e => {
|
|
38
|
+
expect(e.statusCode).toBe(404);
|
|
39
|
+
expect(e.name).toBe('ApiError');
|
|
40
|
+
expect(e.errorCode).toBe(ErrorType.UNKNOWN_ERROR);
|
|
41
|
+
expect(e.errorMessage).toBe('just a test');
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('ApiError exposes details when the server supplies them', () => {
|
|
46
|
+
const details = {
|
|
47
|
+
relation: 'file',
|
|
48
|
+
parentType: 'variation',
|
|
49
|
+
id: 'abc123',
|
|
50
|
+
index: 0,
|
|
51
|
+
provided: {
|
|
52
|
+
id: 'abc123',
|
|
53
|
+
uploadId: 'upload-xyz',
|
|
54
|
+
creationDate: '1776978388',
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
mockFetch(false, {
|
|
58
|
+
'statusCode': 404,
|
|
59
|
+
'errorCode': ErrorType.RESOURCE_NOT_FOUND,
|
|
60
|
+
'message': 'no such file #abc123 on variation',
|
|
61
|
+
'details': details,
|
|
62
|
+
}, 404);
|
|
63
|
+
return apiFetch('https://api.merchi.co/', '/test').catch(e => {
|
|
64
|
+
expect(e.name).toBe('ApiError');
|
|
65
|
+
expect(e.details).toEqual(details);
|
|
66
|
+
expect(e.details.provided.uploadId).toBe('upload-xyz');
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('ApiError leaves details undefined when the server omits them', () => {
|
|
71
|
+
mockFetch(false,
|
|
72
|
+
{'statusCode': 400,
|
|
73
|
+
'errorCode': ErrorType.RESOURCE_NOT_FOUND,
|
|
74
|
+
'message': 'plain error'}, 400);
|
|
75
|
+
return apiFetch('https://api.merchi.co/', '/test').catch(e => {
|
|
76
|
+
expect(e.name).toBe('ApiError');
|
|
77
|
+
expect(e.details).toBeUndefined();
|
|
78
|
+
});
|
|
79
|
+
});
|
package/src/request.ts
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
// eslint-disable-next-line no-unused-vars
|
|
2
|
+
import { ErrorType, getErrorFromCode } from './constants/errors.js';
|
|
3
|
+
|
|
4
|
+
export interface RequestOptions extends RequestInit {
|
|
5
|
+
query?: string[][];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface ApiErrorDetails {
|
|
9
|
+
/**
|
|
10
|
+
* The json_name of the missing / disallowed related entity type
|
|
11
|
+
* (e.g. 'file', 'product', 'domain').
|
|
12
|
+
*/
|
|
13
|
+
relation?: string;
|
|
14
|
+
/**
|
|
15
|
+
* The json_name of the parent entity the relation was being
|
|
16
|
+
* attached to (e.g. 'variation', 'job').
|
|
17
|
+
*/
|
|
18
|
+
parentType?: string;
|
|
19
|
+
/**
|
|
20
|
+
* The id the client supplied for the missing / disallowed entity.
|
|
21
|
+
* May be a numeric id as a number, or a string id depending on
|
|
22
|
+
* the model.
|
|
23
|
+
*/
|
|
24
|
+
id?: number | string;
|
|
25
|
+
/**
|
|
26
|
+
* The form-data index the client sent the entity under (i.e. the
|
|
27
|
+
* ``N`` in ``parent-N-id``).
|
|
28
|
+
*/
|
|
29
|
+
index?: number;
|
|
30
|
+
/**
|
|
31
|
+
* The fields the client sent for the missing entity, with noisy
|
|
32
|
+
* keys (signed URLs, their expiries) stripped and long string
|
|
33
|
+
* values truncated. Useful when debugging uploads where the
|
|
34
|
+
* client knows the uploadId but the server has no matching row.
|
|
35
|
+
*/
|
|
36
|
+
provided?: { [key: string]: any };
|
|
37
|
+
// Backend may add new keys over time; keep the type permissive.
|
|
38
|
+
[key: string]: any;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export class ApiError extends Error {
|
|
42
|
+
public statusCode?: number;
|
|
43
|
+
public errorCode?: ErrorType;
|
|
44
|
+
public errorMessage: string;
|
|
45
|
+
/**
|
|
46
|
+
* Structured context the API may include alongside the error
|
|
47
|
+
* message (e.g. the missing entity id and payload echo). Present
|
|
48
|
+
* only when the backend chooses to populate it - most error
|
|
49
|
+
* responses still carry just ``statusCode``, ``errorCode`` and
|
|
50
|
+
* ``message``.
|
|
51
|
+
*/
|
|
52
|
+
public details?: ApiErrorDetails;
|
|
53
|
+
public original: any;
|
|
54
|
+
public constructor(err: any) {
|
|
55
|
+
const message = JSON.stringify(err);
|
|
56
|
+
/* istanbul ignore next */
|
|
57
|
+
super(message);
|
|
58
|
+
this.statusCode = err.statusCode;
|
|
59
|
+
this.errorCode = getErrorFromCode(err.errorCode);
|
|
60
|
+
this.errorMessage = err.message ?
|
|
61
|
+
err.message : 'No error message';
|
|
62
|
+
this.details = err.details;
|
|
63
|
+
this.name = 'ApiError';
|
|
64
|
+
this.original = err;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export const version = 'v6';
|
|
69
|
+
|
|
70
|
+
interface UriComponents {
|
|
71
|
+
baseUrl: string;
|
|
72
|
+
version: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function ensureVersionInUri(baseUrl: string): UriComponents {
|
|
76
|
+
// Ensure baseUrl ends with a slash
|
|
77
|
+
let uri = baseUrl;
|
|
78
|
+
if (!uri.endsWith('/')) {
|
|
79
|
+
uri += '/';
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Check if the URI already includes a version
|
|
83
|
+
const versionPattern = new RegExp('/v\\d+/?$');
|
|
84
|
+
const match = uri.match(versionPattern);
|
|
85
|
+
|
|
86
|
+
if (match) {
|
|
87
|
+
// Extract the version and remove it from the URI
|
|
88
|
+
const foundVersion = match[0].replace(/\//g, '');
|
|
89
|
+
const strippedUri = uri.replace(versionPattern, '/');
|
|
90
|
+
return {
|
|
91
|
+
baseUrl: strippedUri,
|
|
92
|
+
version: foundVersion
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
baseUrl: uri,
|
|
98
|
+
version: version
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function backendFetch(baseUrl: string, resource: string, options?: RequestOptions) {
|
|
103
|
+
const { baseUrl: cleanBaseUrl, version: apiVersion } = ensureVersionInUri(baseUrl);
|
|
104
|
+
// Remove leading slash from resource if it exists to prevent double slashes
|
|
105
|
+
const cleanResource = resource.startsWith('/') ? resource.slice(1) : resource;
|
|
106
|
+
const url = new URL(cleanBaseUrl + apiVersion + '/' + cleanResource);
|
|
107
|
+
if (options && options.query) {
|
|
108
|
+
for (const entry of options.query) {
|
|
109
|
+
url.searchParams.append(entry[0], entry[1]);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return fetch(url.toString(), options);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function apiFetch(
|
|
116
|
+
baseUrl: string,
|
|
117
|
+
resource: string,
|
|
118
|
+
options?: RequestOptions,
|
|
119
|
+
expectEmptyResponse?: boolean
|
|
120
|
+
) {
|
|
121
|
+
return backendFetch(baseUrl, resource, options as RequestInit | undefined).then(
|
|
122
|
+
function (response) {
|
|
123
|
+
if (response.status < 200 || response.status > 299) {
|
|
124
|
+
return response.json().then(function (json) {
|
|
125
|
+
const err = new ApiError(json);
|
|
126
|
+
return Promise.reject(err);
|
|
127
|
+
});
|
|
128
|
+
} else {
|
|
129
|
+
return expectEmptyResponse ? '' : response.json();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/* istanbul ignore next */
|
|
136
|
+
export function apiFetchWithProgress(
|
|
137
|
+
baseUrl: string,
|
|
138
|
+
resource: string,
|
|
139
|
+
options?: RequestOptions,
|
|
140
|
+
progressCallback?: (progress: number) => void
|
|
141
|
+
) {
|
|
142
|
+
return backendFetch(baseUrl, resource, options as RequestInit | undefined).then(
|
|
143
|
+
function (response) {
|
|
144
|
+
if (!response.body) {
|
|
145
|
+
const err = new ApiError('empty response');
|
|
146
|
+
return Promise.reject(err);
|
|
147
|
+
}
|
|
148
|
+
const reader = response.body.getReader();
|
|
149
|
+
let bodyText = '';
|
|
150
|
+
let errorText = '';
|
|
151
|
+
let haveError = false;
|
|
152
|
+
const expected = '{"loadingBar": "' + '.'.repeat(100) + '"}';
|
|
153
|
+
function readChunk(): any {
|
|
154
|
+
return reader.read().then(({done, value}) => {
|
|
155
|
+
if (done) {
|
|
156
|
+
if (response.status < 200 || response.status > 299) {
|
|
157
|
+
const err = new ApiError('Unknown error');
|
|
158
|
+
return Promise.reject(err);
|
|
159
|
+
} else if(haveError) {
|
|
160
|
+
try {
|
|
161
|
+
const jsonText = JSON.parse(errorText);
|
|
162
|
+
return Promise.reject(new ApiError(jsonText));
|
|
163
|
+
} catch (e) {
|
|
164
|
+
return Promise.reject(new ApiError(errorText));
|
|
165
|
+
}
|
|
166
|
+
} else {
|
|
167
|
+
return bodyText;
|
|
168
|
+
}
|
|
169
|
+
} else {
|
|
170
|
+
const chunk = new TextDecoder().decode(value);
|
|
171
|
+
if (haveError) {
|
|
172
|
+
errorText += chunk;
|
|
173
|
+
} else {
|
|
174
|
+
for (let i = 0; i < chunk.length; ++i) {
|
|
175
|
+
const char = chunk[i];
|
|
176
|
+
const expectedChar = expected[bodyText.length];
|
|
177
|
+
if (expectedChar == char && !haveError) {
|
|
178
|
+
bodyText += char;
|
|
179
|
+
} else {
|
|
180
|
+
haveError = true;
|
|
181
|
+
errorText += char;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (!haveError && progressCallback) {
|
|
186
|
+
const progress = Math.min(Math.max(0, bodyText.length - 16), 100);
|
|
187
|
+
progressCallback(progress);
|
|
188
|
+
}
|
|
189
|
+
return readChunk();
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
return readChunk();
|
|
194
|
+
}
|
|
195
|
+
);
|
|
196
|
+
}
|
package/src/test_util.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function setup() {
|
|
2
|
+
beforeAll(function() {
|
|
3
|
+
(global as any).BACKEND_URI = 'http://example.com/';
|
|
4
|
+
});
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function mockFetch(ok: boolean, data: any, status: number) {
|
|
8
|
+
const mock = jest.fn();
|
|
9
|
+
mock.mockImplementation(() =>
|
|
10
|
+
Promise.resolve({
|
|
11
|
+
status: status,
|
|
12
|
+
ok: ok,
|
|
13
|
+
json: () => Promise.resolve(data)
|
|
14
|
+
})
|
|
15
|
+
);
|
|
16
|
+
(global as any).fetch = mock;
|
|
17
|
+
return mock;
|
|
18
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { setup, mockFetch } from './test_util.js';
|
|
2
|
+
import { toastNotifications } from './toasts.js';
|
|
3
|
+
import { Merchi } from './merchi.js';
|
|
4
|
+
import { NotificationSection } from './constants/notification_sections.js';
|
|
5
|
+
import { NotificationType } from './constants/notification_types.js';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
setup();
|
|
9
|
+
|
|
10
|
+
test('fetch toast of jobs', () => {
|
|
11
|
+
const merchi = new Merchi();
|
|
12
|
+
const fetch = mockFetch(
|
|
13
|
+
true, {'notifications': [{id: 1, message: 'test'}]}, 200);
|
|
14
|
+
const entities = [{id: 1, type: 'job'}];
|
|
15
|
+
const sections = [NotificationSection.JOB_NOTIFICATIONS];
|
|
16
|
+
const notificationTypes = {[NotificationType.JOB_PAID]: true};
|
|
17
|
+
|
|
18
|
+
const options = {entities, sections, notificationTypes};
|
|
19
|
+
const invocation = toastNotifications(merchi, options as any);
|
|
20
|
+
const expectUrl = `${(global as any).BACKEND_URI}v6/notifications-check-update/`;
|
|
21
|
+
expect(fetch.mock.calls[0][0]).toEqual(expectUrl);
|
|
22
|
+
expect(fetch.mock.calls[0][1].method).toEqual('POST');
|
|
23
|
+
expect(JSON.parse(fetch.mock.calls[0][1].body.get('entities'))).toEqual(
|
|
24
|
+
[{id: 1, type: 'job'}]);
|
|
25
|
+
expect(fetch.mock.calls[0][1].body.get('sections')).toEqual(
|
|
26
|
+
`[${NotificationSection.JOB_NOTIFICATIONS}]`);
|
|
27
|
+
expect(
|
|
28
|
+
JSON.parse(fetch.mock.calls[0][1].body.get('notificationTypes'))
|
|
29
|
+
).toEqual(
|
|
30
|
+
{[NotificationType.JOB_PAID]: true}
|
|
31
|
+
);
|
|
32
|
+
invocation.then(notifications => {
|
|
33
|
+
expect(notifications.length).toBe(1);
|
|
34
|
+
expect(notifications[0].id).toBe(1);
|
|
35
|
+
expect(notifications[0].message).toBe('test');
|
|
36
|
+
});
|
|
37
|
+
return invocation;
|
|
38
|
+
});
|
package/src/toasts.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// eslint-disable-next-line no-unused-vars
|
|
2
|
+
import { RequestOptions } from './request.js';
|
|
3
|
+
// eslint-disable-next-line no-unused-vars
|
|
4
|
+
import { Merchi } from './merchi.js';
|
|
5
|
+
// eslint-disable-next-line no-unused-vars
|
|
6
|
+
import { NotificationSection } from './constants/notification_sections.js';
|
|
7
|
+
// eslint-disable-next-line no-unused-vars
|
|
8
|
+
import { NotificationType } from './constants/notification_types.js';
|
|
9
|
+
|
|
10
|
+
interface RelatedObj {
|
|
11
|
+
id: number;
|
|
12
|
+
type: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface ToastOptions {
|
|
16
|
+
entities: RelatedObj[];
|
|
17
|
+
sections: NotificationSection[];
|
|
18
|
+
notificationTypes?: Record<NotificationType, boolean>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const toastNotifications = (merchi: Merchi, options: ToastOptions) => {
|
|
22
|
+
const resource = '/notifications-check-update/';
|
|
23
|
+
const data = new FormData();
|
|
24
|
+
const { entities, sections, notificationTypes } = options;
|
|
25
|
+
data.set('entities', JSON.stringify(entities));
|
|
26
|
+
data.set('sections', JSON.stringify(sections));
|
|
27
|
+
data.set('notificationTypes', JSON.stringify(notificationTypes));
|
|
28
|
+
const fetchOptions: RequestOptions = { method: 'POST', body: data };
|
|
29
|
+
return merchi
|
|
30
|
+
.authenticatedFetch(resource, fetchOptions)
|
|
31
|
+
.then((data: any) =>
|
|
32
|
+
data.notifications.map((n: any) => new merchi.Notification().fromJson(n))
|
|
33
|
+
);
|
|
34
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function kahanSum(values: Iterable<number>) {
|
|
2
|
+
/* Return the kahan summation of the input number array */
|
|
3
|
+
let accumulator = 0;
|
|
4
|
+
let compensation = 0;
|
|
5
|
+
for (const value of values) {
|
|
6
|
+
const y = value - compensation;
|
|
7
|
+
const t = accumulator + y;
|
|
8
|
+
compensation = (t - accumulator) - y;
|
|
9
|
+
accumulator = t;
|
|
10
|
+
}
|
|
11
|
+
return accumulator;
|
|
12
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function getQueryStringValue(name: string) {
|
|
2
|
+
if ((window as any) && typeof window !== 'undefined') {
|
|
3
|
+
const query = (window as any).location.search.substring(1);
|
|
4
|
+
const vars = query.split('&');
|
|
5
|
+
for (let i = 0; i < vars.length; i++) {
|
|
6
|
+
const pair = vars[i].split('=');
|
|
7
|
+
if (pair[0] === name) {
|
|
8
|
+
return decodeURIComponent(pair[1]);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { isUndefinedOrNull } from './validation.js';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
test('return true if value is null', () => {
|
|
5
|
+
expect(isUndefinedOrNull(null)).toBe(true);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
test('return true if value is undefined', () => {
|
|
9
|
+
expect(isUndefinedOrNull(undefined)).toBe(true);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test('return false if value other than undefined or null', () => {
|
|
13
|
+
expect(isUndefinedOrNull(false)).toBe(false);
|
|
14
|
+
expect(isUndefinedOrNull('')).toBe(false);
|
|
15
|
+
expect(isUndefinedOrNull(0)).toBe(false);
|
|
16
|
+
});
|
package/src/uuid.test.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { generateUUID } from './uuid.js';
|
|
2
|
+
|
|
3
|
+
test('can generate UUID', () => {
|
|
4
|
+
const realRandom = global.Math.random;
|
|
5
|
+
const randomStub = jest.fn(() => 0.4);
|
|
6
|
+
global.Math.random = randomStub;
|
|
7
|
+
|
|
8
|
+
const correct = '66666666-6666-4666-a666-666666666666';
|
|
9
|
+
const attempt = generateUUID();
|
|
10
|
+
|
|
11
|
+
expect(randomStub).toHaveBeenCalled();
|
|
12
|
+
expect(attempt).toBe(correct);
|
|
13
|
+
|
|
14
|
+
global.Math.random = realRandom;
|
|
15
|
+
});
|
package/src/uuid.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function generateUUID(): string {
|
|
2
|
+
let uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
|
|
3
|
+
uuid = uuid.replace(/[xy]/g, function (c): string {
|
|
4
|
+
const r = (Math.random() * 16) % 16 | 0;
|
|
5
|
+
return (c === 'x' ? r : r & 0x3 | 0x8).toString(16);
|
|
6
|
+
});
|
|
7
|
+
return uuid;
|
|
8
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES5",
|
|
4
|
+
"experimentalDecorators": true,
|
|
5
|
+
"emitDecoratorMetadata": true,
|
|
6
|
+
"downlevelIteration": true,
|
|
7
|
+
"lib": ["es2017", "DOM", "ES6"],
|
|
8
|
+
"moduleResolution": "node",
|
|
9
|
+
"rootDir": "./src",
|
|
10
|
+
"outDir": "dist",
|
|
11
|
+
"module": "ES6",
|
|
12
|
+
"types": ["node", "jest"],
|
|
13
|
+
"baseUrl": ".",
|
|
14
|
+
"ignoreDeprecations": "6.0",
|
|
15
|
+
"noImplicitAny": true,
|
|
16
|
+
"noImplicitReturns": true,
|
|
17
|
+
"noImplicitThis": true,
|
|
18
|
+
"noUnusedLocals": true,
|
|
19
|
+
"strictBindCallApply": true,
|
|
20
|
+
"strictFunctionTypes": true,
|
|
21
|
+
"strictPropertyInitialization": true,
|
|
22
|
+
"strictNullChecks": true,
|
|
23
|
+
"esModuleInterop": true,
|
|
24
|
+
"pretty": true,
|
|
25
|
+
"alwaysStrict": true,
|
|
26
|
+
},
|
|
27
|
+
"include": ["src/**/*"],
|
|
28
|
+
"exclude": ["node_modules", "dist", "test"]
|
|
29
|
+
}
|