merchi_sdk_ts 0.0.1-a
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/.babelrc +13 -0
- package/.eslintrc.cjs +43 -0
- package/LICENSE +21 -0
- package/README.md +2 -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 +4 -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 +14 -0
- package/dist/constants/field_types.test.js +4 -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 +16 -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 +98 -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 +26 -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 +1 -0
- package/dist/constants/robots_meta_directives.test.js +4 -0
- package/dist/constants/roles.js +25 -0
- package/dist/constants/roles.test.js +4 -0
- package/dist/constants/shipment_companies.js +19 -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_foundations.js +7 -0
- package/dist/constants/theme_foundations.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 +16 -0
- package/dist/cookie.test.js +12 -0
- package/dist/entities/address.js +166 -0
- package/dist/entities/address.test.js +6 -0
- package/dist/entities/assignment.js +185 -0
- package/dist/entities/assignment.test.js +38 -0
- package/dist/entities/automatic_payment_relationship.js +77 -0
- package/dist/entities/automatic_payment_relationship.test.js +6 -0
- package/dist/entities/backup.js +44 -0
- package/dist/entities/backup.test.js +6 -0
- package/dist/entities/bank.js +116 -0
- package/dist/entities/bank.test.js +6 -0
- package/dist/entities/cart.js +203 -0
- package/dist/entities/cart.test.js +52 -0
- package/dist/entities/cart_item.js +153 -0
- package/dist/entities/cart_item.test.js +34 -0
- package/dist/entities/cart_shipment_group.js +62 -0
- package/dist/entities/cart_shipment_quote.js +85 -0
- package/dist/entities/category.js +92 -0
- package/dist/entities/category.test.js +52 -0
- package/dist/entities/company.js +648 -0
- package/dist/entities/company.test.js +6 -0
- package/dist/entities/company_invitation.js +82 -0
- package/dist/entities/company_invitation.test.js +6 -0
- package/dist/entities/component.js +209 -0
- package/dist/entities/component.test.js +12 -0
- package/dist/entities/component_tag.js +50 -0
- package/dist/entities/component_tag.test.js +6 -0
- package/dist/entities/component_version.js +80 -0
- package/dist/entities/component_version.test.js +6 -0
- package/dist/entities/country_tax.js +110 -0
- package/dist/entities/country_tax.test.js +11 -0
- package/dist/entities/discount.js +77 -0
- package/dist/entities/discount.test.js +20 -0
- package/dist/entities/discount_group.js +74 -0
- package/dist/entities/discount_group.test.js +6 -0
- package/dist/entities/domain.js +535 -0
- package/dist/entities/domain.test.js +75 -0
- package/dist/entities/domain_invitation.js +90 -0
- package/dist/entities/domain_invitation.test.js +6 -0
- package/dist/entities/domain_tag.js +100 -0
- package/dist/entities/domain_tag.test.js +6 -0
- package/dist/entities/draft.js +180 -0
- package/dist/entities/draft.test.js +39 -0
- package/dist/entities/draft_comment.js +132 -0
- package/dist/entities/draft_comment.test.js +6 -0
- package/dist/entities/draft_template.js +105 -0
- package/dist/entities/draft_template.test.js +6 -0
- package/dist/entities/email_address.js +68 -0
- package/dist/entities/email_address.test.js +6 -0
- package/dist/entities/email_counter.js +56 -0
- package/dist/entities/email_counter.test.js +6 -0
- package/dist/entities/enrolled_domain.js +85 -0
- package/dist/entities/enrolled_domain.test.js +6 -0
- package/dist/entities/exchange_rate.js +62 -0
- package/dist/entities/exchange_rate.test.js +6 -0
- package/dist/entities/file.js +383 -0
- package/dist/entities/file.test.js +38 -0
- package/dist/entities/internal_tag.js +120 -0
- package/dist/entities/internal_tag.test.js +6 -0
- package/dist/entities/inventory.js +120 -0
- package/dist/entities/inventory.test.js +26 -0
- package/dist/entities/inventory_unit_variation.js +64 -0
- package/dist/entities/inventory_unit_variation.test.js +6 -0
- package/dist/entities/invoice.js +420 -0
- package/dist/entities/invoice.test.js +39 -0
- package/dist/entities/item.js +102 -0
- package/dist/entities/item.test.js +17 -0
- package/dist/entities/job.js +744 -0
- package/dist/entities/job.test.js +103 -0
- package/dist/entities/job_comment.js +120 -0
- package/dist/entities/job_comment.test.js +6 -0
- package/dist/entities/matching_inventory.js +77 -0
- package/dist/entities/menu.js +78 -0
- package/dist/entities/menu.test.js +6 -0
- package/dist/entities/menu_item.js +76 -0
- package/dist/entities/menu_item.test.js +6 -0
- package/dist/entities/notification.js +234 -0
- package/dist/entities/notification.test.js +6 -0
- package/dist/entities/page.js +84 -0
- package/dist/entities/page.test.js +6 -0
- package/dist/entities/payment.js +141 -0
- package/dist/entities/payment.test.js +18 -0
- package/dist/entities/payment_device.js +87 -0
- package/dist/entities/payment_device.test.js +6 -0
- package/dist/entities/phone_number.js +98 -0
- package/dist/entities/phone_number.test.js +6 -0
- package/dist/entities/product.js +806 -0
- package/dist/entities/product.test.js +811 -0
- package/dist/entities/production_comment.js +120 -0
- package/dist/entities/production_comment.test.js +6 -0
- package/dist/entities/quote.js +208 -0
- package/dist/entities/quote.test.js +107 -0
- package/dist/entities/quote_item.js +121 -0
- package/dist/entities/quote_item.test.js +56 -0
- package/dist/entities/seo_domain_page.js +82 -0
- package/dist/entities/seo_domain_page.test.js +6 -0
- package/dist/entities/session.js +77 -0
- package/dist/entities/session.test.js +6 -0
- package/dist/entities/shipment.js +401 -0
- package/dist/entities/shipment.test.js +28 -0
- package/dist/entities/shipment_item.js +49 -0
- package/dist/entities/shipment_item.test.js +6 -0
- package/dist/entities/shipment_item_fulfillment.js +48 -0
- package/dist/entities/shipment_item_fulfillment.test.js +6 -0
- package/dist/entities/shipment_method.js +146 -0
- package/dist/entities/shipment_method.test.js +6 -0
- package/dist/entities/shipment_method_variation.js +104 -0
- package/dist/entities/shipment_method_variation.test.js +6 -0
- package/dist/entities/short_url.js +95 -0
- package/dist/entities/short_url.test.js +6 -0
- package/dist/entities/subscription_plan.js +172 -0
- package/dist/entities/subscription_plan.test.js +6 -0
- package/dist/entities/supply_domain.js +73 -0
- package/dist/entities/supply_domain.test.js +6 -0
- package/dist/entities/system_role.js +50 -0
- package/dist/entities/system_role.test.js +6 -0
- package/dist/entities/theme.js +614 -0
- package/dist/entities/theme.test.js +39 -0
- package/dist/entities/theme_css_setting.js +67 -0
- package/dist/entities/theme_css_setting.test.js +6 -0
- package/dist/entities/user.js +749 -0
- package/dist/entities/user.test.js +157 -0
- package/dist/entities/user_company.js +78 -0
- package/dist/entities/user_company.test.js +6 -0
- package/dist/entities/variation.js +147 -0
- package/dist/entities/variation.test.js +6 -0
- package/dist/entities/variation_field.js +313 -0
- package/dist/entities/variation_field.test.js +69 -0
- package/dist/entities/variation_fields_option.js +190 -0
- package/dist/entities/variation_fields_option.test.js +47 -0
- package/dist/entities/variation_option.js +129 -0
- package/dist/entities/variation_option.test.js +6 -0
- package/dist/entities/variations_group.js +111 -0
- package/dist/entities/variations_group.test.js +6 -0
- package/dist/entity.js +888 -0
- package/dist/merchi.js +259 -0
- package/dist/merchi.test.js +35 -0
- package/dist/request.js +132 -0
- package/dist/request.test.js +46 -0
- package/dist/test_util.js +19 -0
- package/dist/toasts.js +27 -0
- package/dist/toasts.test.js +46 -0
- package/dist/util/float.js +24 -0
- package/dist/util/query_string.js +11 -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 +13 -0
- package/jest.config.js +17 -0
- package/package.json +44 -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 +3 -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 +13 -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 +15 -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 +97 -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 +25 -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 +38 -0
- package/src/constants/shipment_companies.test.ts +5 -0
- package/src/constants/shipment_companies.ts +18 -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_foundations.test.ts +5 -0
- package/src/constants/theme_foundations.ts +6 -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/assignment.test.ts +39 -0
- package/src/entities/assignment.ts +92 -0
- package/src/entities/automatic_payment_relationship.test.ts +8 -0
- package/src/entities/automatic_payment_relationship.ts +26 -0
- package/src/entities/backup.test.ts +7 -0
- package/src/entities/backup.ts +14 -0
- package/src/entities/bank.test.ts +7 -0
- package/src/entities/bank.ts +45 -0
- package/src/entities/cart.test.ts +50 -0
- package/src/entities/cart.ts +89 -0
- package/src/entities/cart_item.test.ts +33 -0
- package/src/entities/cart_item.ts +77 -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 +37 -0
- package/src/entities/company.test.ts +7 -0
- package/src/entities/company.ts +275 -0
- package/src/entities/company_invitation.test.ts +7 -0
- package/src/entities/company_invitation.ts +33 -0
- package/src/entities/component.test.ts +14 -0
- package/src/entities/component.ts +92 -0
- package/src/entities/component_tag.test.ts +7 -0
- package/src/entities/component_tag.ts +17 -0
- package/src/entities/component_version.test.ts +7 -0
- package/src/entities/component_version.ts +30 -0
- package/src/entities/country_tax.test.ts +13 -0
- package/src/entities/country_tax.ts +46 -0
- package/src/entities/discount.test.ts +18 -0
- package/src/entities/discount.ts +34 -0
- package/src/entities/discount_group.test.ts +7 -0
- package/src/entities/discount_group.ts +28 -0
- package/src/entities/domain.test.ts +79 -0
- package/src/entities/domain.ts +246 -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 +43 -0
- package/src/entities/draft.ts +88 -0
- package/src/entities/draft_comment.test.ts +7 -0
- package/src/entities/draft_comment.ts +54 -0
- package/src/entities/draft_template.test.ts +7 -0
- package/src/entities/draft_template.ts +40 -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 +172 -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 +56 -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 +43 -0
- package/src/entities/invoice.ts +179 -0
- package/src/entities/item.test.ts +19 -0
- package/src/entities/item.ts +44 -0
- package/src/entities/job.test.ts +95 -0
- package/src/entities/job.ts +349 -0
- package/src/entities/job_comment.test.ts +7 -0
- package/src/entities/job_comment.ts +50 -0
- package/src/entities/matching_inventory.ts +29 -0
- package/src/entities/menu.test.ts +7 -0
- package/src/entities/menu.ts +30 -0
- package/src/entities/menu_item.test.ts +7 -0
- package/src/entities/menu_item.ts +29 -0
- package/src/entities/notification.test.ts +7 -0
- package/src/entities/notification.ts +99 -0
- package/src/entities/page.test.ts +7 -0
- package/src/entities/page.ts +32 -0
- package/src/entities/payment.test.ts +19 -0
- package/src/entities/payment.ts +65 -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 +750 -0
- package/src/entities/product.ts +427 -0
- package/src/entities/production_comment.test.ts +7 -0
- package/src/entities/production_comment.ts +50 -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/seo_domain_page.test.ts +7 -0
- package/src/entities/seo_domain_page.ts +33 -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 +185 -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_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/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 +267 -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 +394 -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 +61 -0
- package/src/entities/variation_field.test.ts +76 -0
- package/src/entities/variation_field.ts +169 -0
- package/src/entities/variation_fields_option.test.ts +46 -0
- package/src/entities/variation_fields_option.ts +95 -0
- package/src/entities/variation_option.test.ts +7 -0
- package/src/entities/variation_option.ts +52 -0
- package/src/entities/variations_group.test.ts +7 -0
- package/src/entities/variations_group.ts +41 -0
- package/src/entity.ts +1002 -0
- package/src/merchi.test.ts +25 -0
- package/src/merchi.ts +379 -0
- package/src/request.test.ts +43 -0
- package/src/request.ts +124 -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/query_string.test.ts +7 -0
- package/src/util/query_string.ts +11 -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 +23 -0
- package/webpack.config.cjs +27 -0
package/dist/entity.js
ADDED
|
@@ -0,0 +1,888 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
6
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
7
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
8
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
10
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
11
|
+
import 'reflect-metadata';
|
|
12
|
+
// eslint-disable-next-line no-unused-vars
|
|
13
|
+
|
|
14
|
+
// eslint-disable-next-line no-unused-vars
|
|
15
|
+
|
|
16
|
+
// eslint-disable-next-line no-unused-vars
|
|
17
|
+
|
|
18
|
+
// eslint-disable-next-line no-unused-vars
|
|
19
|
+
|
|
20
|
+
// eslint-disable-next-line no-unused-vars
|
|
21
|
+
|
|
22
|
+
// eslint-disable-next-line no-unused-vars
|
|
23
|
+
|
|
24
|
+
// eslint-disable-next-line no-unused-vars
|
|
25
|
+
|
|
26
|
+
import { generateUUID } from './uuid';
|
|
27
|
+
function toUnixTimestamp(date) {
|
|
28
|
+
return parseInt(String(date.getTime() / 1000)).toFixed(0);
|
|
29
|
+
}
|
|
30
|
+
export var SerialiseMethod = /*#__PURE__*/function (SerialiseMethod) {
|
|
31
|
+
SerialiseMethod["TO_DICT"] = "to_dict";
|
|
32
|
+
SerialiseMethod["ONLY_ID"] = "only_id";
|
|
33
|
+
return SerialiseMethod;
|
|
34
|
+
}({});
|
|
35
|
+
export var Entity = /*#__PURE__*/function () {
|
|
36
|
+
function Entity(merchi) {
|
|
37
|
+
var _this = this;
|
|
38
|
+
_classCallCheck(this, Entity);
|
|
39
|
+
_defineProperty(this, "isDirty", false);
|
|
40
|
+
_defineProperty(this, "backObjects", new Set());
|
|
41
|
+
_defineProperty(this, "key", generateUUID());
|
|
42
|
+
_defineProperty(this, "getPrimaryKeyValue", function () {
|
|
43
|
+
var name = _this.constructor.primaryKey;
|
|
44
|
+
var info = _this.propertiesMap.get(name);
|
|
45
|
+
/* istanbul ignore next */
|
|
46
|
+
if (info !== undefined) {
|
|
47
|
+
return info.currentValue;
|
|
48
|
+
}
|
|
49
|
+
/* istanbul ignore next */
|
|
50
|
+
return undefined;
|
|
51
|
+
});
|
|
52
|
+
_defineProperty(this, "setupProperties", function () {
|
|
53
|
+
var properties = {};
|
|
54
|
+
var makeSetSingle = function makeSetSingle(info) {
|
|
55
|
+
var get = function get() {
|
|
56
|
+
return info.currentValue;
|
|
57
|
+
};
|
|
58
|
+
var set = function set(newValue) {
|
|
59
|
+
info.currentValue = newValue;
|
|
60
|
+
_this.addBackObject(newValue);
|
|
61
|
+
_this.markDirty(info.property, newValue);
|
|
62
|
+
};
|
|
63
|
+
return {
|
|
64
|
+
get: get,
|
|
65
|
+
set: set
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
var makeSetScalar = function makeSetScalar(info) {
|
|
69
|
+
var get = function get() {
|
|
70
|
+
return info.currentValue;
|
|
71
|
+
};
|
|
72
|
+
var set = function set(newValue) {
|
|
73
|
+
info.currentValue = newValue;
|
|
74
|
+
_this.markDirty(info.property, newValue);
|
|
75
|
+
};
|
|
76
|
+
return {
|
|
77
|
+
get: get,
|
|
78
|
+
set: set
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
var makeSetArray = function makeSetArray(info) {
|
|
82
|
+
var get = function get() {
|
|
83
|
+
return info.currentValue;
|
|
84
|
+
};
|
|
85
|
+
var set = function set(newValue) {
|
|
86
|
+
info.currentValue = newValue;
|
|
87
|
+
_this.addBackObjectList(newValue);
|
|
88
|
+
_this.markDirty(info.property, newValue);
|
|
89
|
+
};
|
|
90
|
+
return {
|
|
91
|
+
get: get,
|
|
92
|
+
set: set
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
var _iterator = _createForOfIteratorHelper(_this.propertiesMap.values()),
|
|
96
|
+
_step;
|
|
97
|
+
try {
|
|
98
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
99
|
+
var info = _step.value;
|
|
100
|
+
if (info.type.prototype instanceof Entity) {
|
|
101
|
+
properties[info.attribute] = makeSetSingle(info);
|
|
102
|
+
} else if (info.arrayType) {
|
|
103
|
+
properties[info.attribute] = makeSetArray(info);
|
|
104
|
+
} else {
|
|
105
|
+
properties[info.attribute] = makeSetScalar(info);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
} catch (err) {
|
|
109
|
+
_iterator.e(err);
|
|
110
|
+
} finally {
|
|
111
|
+
_iterator.f();
|
|
112
|
+
}
|
|
113
|
+
Object.defineProperties(_this, properties);
|
|
114
|
+
});
|
|
115
|
+
_defineProperty(this, "save", function (options) {
|
|
116
|
+
var primaryKey = _this.getPrimaryKeyValue();
|
|
117
|
+
var constructor = _this.constructor;
|
|
118
|
+
var resourceName = constructor.resourceName;
|
|
119
|
+
var singularName = constructor.singularName;
|
|
120
|
+
var resource = "/".concat(resourceName, "/").concat(String(primaryKey), "/");
|
|
121
|
+
var data = _this.toFormData();
|
|
122
|
+
var fetchOptions = {
|
|
123
|
+
method: 'PATCH',
|
|
124
|
+
body: data
|
|
125
|
+
};
|
|
126
|
+
fetchOptions.query = [];
|
|
127
|
+
if (options && options.embed) {
|
|
128
|
+
fetchOptions.query.push(['embed', JSON.stringify(options.embed)]);
|
|
129
|
+
}
|
|
130
|
+
if (!(options && options.withRights)) {
|
|
131
|
+
fetchOptions.query.push(['skip_rights', 'y']);
|
|
132
|
+
}
|
|
133
|
+
return _this.merchi.authenticatedFetch(resource, fetchOptions).then(function (data) {
|
|
134
|
+
_this.fromJson(data[singularName]);
|
|
135
|
+
_this.cleanDirty();
|
|
136
|
+
return _this;
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
_defineProperty(this, "createFactory", function (_ref) {
|
|
140
|
+
var _ref$resourceName = _ref.resourceName,
|
|
141
|
+
resourceName = _ref$resourceName === void 0 ? _this.constructor.resourceName : _ref$resourceName;
|
|
142
|
+
return function (options) {
|
|
143
|
+
var resource = "/".concat(resourceName, "/");
|
|
144
|
+
var data = _this.toFormData();
|
|
145
|
+
var singularName = _this.constructor.singularName;
|
|
146
|
+
var fetchOptions = {
|
|
147
|
+
method: 'POST',
|
|
148
|
+
body: data
|
|
149
|
+
};
|
|
150
|
+
fetchOptions.query = [];
|
|
151
|
+
if (options && options.embed) {
|
|
152
|
+
fetchOptions.query.push(['embed', JSON.stringify(options.embed)]);
|
|
153
|
+
}
|
|
154
|
+
if (!(options && options.withRights)) {
|
|
155
|
+
fetchOptions.query.push(['skip_rights', 'y']);
|
|
156
|
+
}
|
|
157
|
+
return _this.merchi.authenticatedFetch(resource, fetchOptions).then(function (data) {
|
|
158
|
+
_this.fromJson(data[singularName]);
|
|
159
|
+
_this.cleanDirty();
|
|
160
|
+
return _this;
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
});
|
|
164
|
+
_defineProperty(this, "create", this.createFactory({}));
|
|
165
|
+
_defineProperty(this, "getEntityClass", function (name) {
|
|
166
|
+
if (name === undefined) {
|
|
167
|
+
return undefined;
|
|
168
|
+
}
|
|
169
|
+
return _this.merchi[name];
|
|
170
|
+
});
|
|
171
|
+
_defineProperty(this, "cleanDirty", function () {
|
|
172
|
+
// remove all dirty records of this entity, makes it untouched
|
|
173
|
+
// entity
|
|
174
|
+
_this.isDirty = false;
|
|
175
|
+
var _iterator2 = _createForOfIteratorHelper(_this.propertiesMap.entries()),
|
|
176
|
+
_step2;
|
|
177
|
+
try {
|
|
178
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
179
|
+
var entry = _step2.value;
|
|
180
|
+
var propertyInfo = entry[1];
|
|
181
|
+
propertyInfo.dirty = false;
|
|
182
|
+
if (propertyInfo.currentValue !== undefined) {
|
|
183
|
+
if (propertyInfo.arrayType) {
|
|
184
|
+
propertyInfo.currentValue.map(function (v) {
|
|
185
|
+
return v.cleanDirty();
|
|
186
|
+
});
|
|
187
|
+
} else if (_this.isSingleEntityProperty(propertyInfo)) {
|
|
188
|
+
if (propertyInfo.currentValue) {
|
|
189
|
+
propertyInfo.currentValue.cleanDirty();
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
} catch (err) {
|
|
195
|
+
_iterator2.e(err);
|
|
196
|
+
} finally {
|
|
197
|
+
_iterator2.f();
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
_defineProperty(this, "fromJson", function (json, options) {
|
|
201
|
+
options = options || {};
|
|
202
|
+
var _options = options,
|
|
203
|
+
_options$makeDirty = _options.makeDirty,
|
|
204
|
+
makeDirty = _options$makeDirty === void 0 ? false : _options$makeDirty,
|
|
205
|
+
_options$arrayValueSt = _options.arrayValueStrict,
|
|
206
|
+
arrayValueStrict = _options$arrayValueSt === void 0 ? true : _options$arrayValueSt;
|
|
207
|
+
options = {
|
|
208
|
+
makeDirty: makeDirty,
|
|
209
|
+
arrayValueStrict: arrayValueStrict
|
|
210
|
+
};
|
|
211
|
+
var _loop = function _loop() {
|
|
212
|
+
var value = json[key];
|
|
213
|
+
if (value === undefined) return 0; // continue
|
|
214
|
+
var propertyInfo = _this.propertiesMap.get(key);
|
|
215
|
+
if (propertyInfo !== undefined) {
|
|
216
|
+
propertyInfo.dirty = makeDirty;
|
|
217
|
+
if (propertyInfo.arrayType) {
|
|
218
|
+
// ignore array value if it is not an array and we did expect it
|
|
219
|
+
if (!arrayValueStrict && !Array.isArray(value)) return 0; // continue
|
|
220
|
+
var newValue = value.map(function (item, index) {
|
|
221
|
+
var currentValue = propertyInfo.currentValue;
|
|
222
|
+
// if property already have an array of entities as relationship,
|
|
223
|
+
// try to merge with json one by one, this behavior may need to be
|
|
224
|
+
// configurable in the future.
|
|
225
|
+
if (currentValue && currentValue[index]) {
|
|
226
|
+
return currentValue[index].fromJson(item, options);
|
|
227
|
+
}
|
|
228
|
+
var nested = new propertyInfo.arrayType(_this.merchi);
|
|
229
|
+
return nested.fromJson(item, options);
|
|
230
|
+
});
|
|
231
|
+
propertyInfo.currentValue = newValue;
|
|
232
|
+
} else if (_this.isSingleEntityProperty(propertyInfo)) {
|
|
233
|
+
// if property already have a entity as relationship, try to merge
|
|
234
|
+
// with json first, this behavior may need to be configurable in the
|
|
235
|
+
// future.
|
|
236
|
+
if (propertyInfo.currentValue) {
|
|
237
|
+
propertyInfo.currentValue.fromJson(value, options);
|
|
238
|
+
} else {
|
|
239
|
+
var nested = new propertyInfo.type(_this.merchi);
|
|
240
|
+
propertyInfo.currentValue = nested.fromJson(value, options);
|
|
241
|
+
}
|
|
242
|
+
} else {
|
|
243
|
+
propertyInfo.currentValue = value;
|
|
244
|
+
if (propertyInfo.type === Date && !!value) {
|
|
245
|
+
propertyInfo.currentValue = new Date(value * 1000);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
_ret;
|
|
251
|
+
for (var key in json) {
|
|
252
|
+
_ret = _loop();
|
|
253
|
+
if (_ret === 0) continue;
|
|
254
|
+
}
|
|
255
|
+
return _this;
|
|
256
|
+
});
|
|
257
|
+
_defineProperty(this, "toJson", function () {
|
|
258
|
+
var json = {};
|
|
259
|
+
var _iterator3 = _createForOfIteratorHelper(_this.propertiesMap.entries()),
|
|
260
|
+
_step3;
|
|
261
|
+
try {
|
|
262
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
263
|
+
var entry = _step3.value;
|
|
264
|
+
var propertyName = entry[0];
|
|
265
|
+
var propertyInfo = entry[1];
|
|
266
|
+
if (propertyInfo.currentValue !== undefined) {
|
|
267
|
+
if (propertyInfo.arrayType) {
|
|
268
|
+
var array = propertyInfo.currentValue.map(function (v) {
|
|
269
|
+
return v.toJson();
|
|
270
|
+
});
|
|
271
|
+
json[propertyName] = array;
|
|
272
|
+
} else if (_this.isSingleEntityProperty(propertyInfo)) {
|
|
273
|
+
if (propertyInfo.currentValue === null) {
|
|
274
|
+
json[propertyName] = null;
|
|
275
|
+
} else {
|
|
276
|
+
json[propertyName] = propertyInfo.currentValue.toJson();
|
|
277
|
+
}
|
|
278
|
+
} else {
|
|
279
|
+
var value = propertyInfo.currentValue;
|
|
280
|
+
json[propertyName] = value;
|
|
281
|
+
if (propertyInfo.type === Date && !!value) {
|
|
282
|
+
json[propertyName] = value.getTime() / 1000;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
} catch (err) {
|
|
288
|
+
_iterator3.e(err);
|
|
289
|
+
} finally {
|
|
290
|
+
_iterator3.f();
|
|
291
|
+
}
|
|
292
|
+
return json;
|
|
293
|
+
});
|
|
294
|
+
_defineProperty(this, "forEachProperty", function (fn) {
|
|
295
|
+
var _iterator4 = _createForOfIteratorHelper(_this.propertiesMap.values()),
|
|
296
|
+
_step4;
|
|
297
|
+
try {
|
|
298
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
299
|
+
var info = _step4.value;
|
|
300
|
+
fn(info);
|
|
301
|
+
}
|
|
302
|
+
} catch (err) {
|
|
303
|
+
_iterator4.e(err);
|
|
304
|
+
} finally {
|
|
305
|
+
_iterator4.f();
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
_defineProperty(this, "toFormData", function (options, fileIndex) {
|
|
309
|
+
if (options === undefined) {
|
|
310
|
+
options = {};
|
|
311
|
+
}
|
|
312
|
+
var result = options.existing || new FormData();
|
|
313
|
+
var prefix = options._prefix || '';
|
|
314
|
+
var excludeOld = options.excludeOld === undefined ? true : options.excludeOld;
|
|
315
|
+
if (fileIndex === undefined) {
|
|
316
|
+
fileIndex = {
|
|
317
|
+
value: 0
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
var appendData = function appendData(name, value) {
|
|
321
|
+
/* istanbul ignore next */
|
|
322
|
+
if (name === undefined || value === undefined) {
|
|
323
|
+
/* istanbul ignore next */
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
if (prefix) {
|
|
327
|
+
name = prefix + '-' + name;
|
|
328
|
+
}
|
|
329
|
+
result.set(name, value);
|
|
330
|
+
};
|
|
331
|
+
if (_this.fileData !== undefined) {
|
|
332
|
+
result.set(String(fileIndex.value), _this.fileData);
|
|
333
|
+
appendData('fileDataIndex', fileIndex.value);
|
|
334
|
+
fileIndex.value++;
|
|
335
|
+
}
|
|
336
|
+
var processArrayProperty = function processArrayProperty(info, value) {
|
|
337
|
+
var remoteCount = value.length;
|
|
338
|
+
var initialLength = Array.from(result.entries()).length;
|
|
339
|
+
if (remoteCount === 0 && info.dirty) {
|
|
340
|
+
appendData(info.property + '-count', 0);
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
var isDirty = false;
|
|
344
|
+
var _iterator5 = _createForOfIteratorHelper(value),
|
|
345
|
+
_step5;
|
|
346
|
+
try {
|
|
347
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
348
|
+
var item = _step5.value;
|
|
349
|
+
if (item.isDirty) {
|
|
350
|
+
isDirty = true;
|
|
351
|
+
break;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
} catch (err) {
|
|
355
|
+
_iterator5.e(err);
|
|
356
|
+
} finally {
|
|
357
|
+
_iterator5.f();
|
|
358
|
+
}
|
|
359
|
+
isDirty = isDirty || info.dirty;
|
|
360
|
+
if (!isDirty && excludeOld) {
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
for (var _i = 0; _i < remoteCount; ++_i) {
|
|
364
|
+
var innerPrefix = info.property + '-' + _i;
|
|
365
|
+
if (prefix) {
|
|
366
|
+
innerPrefix = prefix + '-' + innerPrefix;
|
|
367
|
+
}
|
|
368
|
+
value[_i].toFormData({
|
|
369
|
+
existing: result,
|
|
370
|
+
_prefix: innerPrefix,
|
|
371
|
+
excludeOld: excludeOld
|
|
372
|
+
}, fileIndex);
|
|
373
|
+
}
|
|
374
|
+
var finalLength = Array.from(result.entries()).length;
|
|
375
|
+
if (finalLength - initialLength > 0) {
|
|
376
|
+
appendData(info.property + '-count', remoteCount);
|
|
377
|
+
if (info.updatingOrder) {
|
|
378
|
+
appendData(info.property + '-*updateOrder', 'true');
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
var processSingleEntityProperty = function processSingleEntityProperty(info, value) {
|
|
383
|
+
var primaryKey = _this.constructor.primaryKey;
|
|
384
|
+
var innerPrefix = info.property + '-0';
|
|
385
|
+
if (prefix) {
|
|
386
|
+
innerPrefix = prefix + '-' + innerPrefix;
|
|
387
|
+
}
|
|
388
|
+
if (value === null) {
|
|
389
|
+
if (info.dirty || !excludeOld) {
|
|
390
|
+
appendData(info.property + '-0-' + primaryKey, '-1');
|
|
391
|
+
appendData(info.property + '-count', 1);
|
|
392
|
+
}
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
if (!(info.dirty || value.isDirty) && excludeOld) {
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
var initialLength = Array.from(result.entries()).length;
|
|
399
|
+
value.toFormData({
|
|
400
|
+
existing: result,
|
|
401
|
+
_prefix: innerPrefix,
|
|
402
|
+
excludeOld: excludeOld
|
|
403
|
+
}, fileIndex);
|
|
404
|
+
var finalLength = Array.from(result.entries()).length;
|
|
405
|
+
if (finalLength - initialLength > 0) {
|
|
406
|
+
appendData(info.property + '-count', 1);
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
var processScalarProperty = function processScalarProperty(info, value) {
|
|
410
|
+
var primaryKey = _this.constructor.primaryKey;
|
|
411
|
+
if (!excludeOld || info.dirty || info.property === primaryKey && value) {
|
|
412
|
+
if (info.type === Date && !!value) {
|
|
413
|
+
value = value.getTime() / 1000;
|
|
414
|
+
}
|
|
415
|
+
appendData(info.property, value);
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
var processProperty = function processProperty(info) {
|
|
419
|
+
var value = _this[info.attribute];
|
|
420
|
+
if (value === undefined) {
|
|
421
|
+
return;
|
|
422
|
+
} else if (info.arrayType) {
|
|
423
|
+
processArrayProperty(info, value);
|
|
424
|
+
} else if (_this.isSingleEntityProperty(info)) {
|
|
425
|
+
processSingleEntityProperty(info, value);
|
|
426
|
+
} else {
|
|
427
|
+
processScalarProperty(info, value);
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
_this.forEachProperty(processProperty);
|
|
431
|
+
return result;
|
|
432
|
+
});
|
|
433
|
+
_defineProperty(this, "addBackObject", function (remote) {
|
|
434
|
+
if (remote !== undefined) {
|
|
435
|
+
remote.backObjects.add(_this);
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
_defineProperty(this, "addBackObjectList", function (remotes) {
|
|
439
|
+
if (remotes !== undefined) {
|
|
440
|
+
remotes.forEach(_this.addBackObject);
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
_defineProperty(this, "updateOrder", function (property) {
|
|
444
|
+
_this.propertiesMap.get(property).updatingOrder = true;
|
|
445
|
+
});
|
|
446
|
+
_defineProperty(this, "markDirty", function (property, newValue) {
|
|
447
|
+
if (newValue === undefined) {
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
_this.propertiesMap.get(property).dirty = true;
|
|
451
|
+
var openSet = []; /* Queue (BFS) */
|
|
452
|
+
var closedSet = new Set();
|
|
453
|
+
openSet.push(_this);
|
|
454
|
+
while (openSet.length > 0) {
|
|
455
|
+
var current = openSet.shift();
|
|
456
|
+
if (!closedSet.has(current)) {
|
|
457
|
+
current.isDirty = true;
|
|
458
|
+
closedSet.add(current);
|
|
459
|
+
var _iterator6 = _createForOfIteratorHelper(current.backObjects),
|
|
460
|
+
_step6;
|
|
461
|
+
try {
|
|
462
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
463
|
+
var child = _step6.value;
|
|
464
|
+
openSet.push(child);
|
|
465
|
+
}
|
|
466
|
+
} catch (err) {
|
|
467
|
+
_iterator6.e(err);
|
|
468
|
+
} finally {
|
|
469
|
+
_iterator6.f();
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
_defineProperty(this, "delete", function (options) {
|
|
475
|
+
var primaryKey = _this.getPrimaryKeyValue();
|
|
476
|
+
var resourceName = _this.constructor.resourceName;
|
|
477
|
+
var resource = "/".concat(resourceName, "/").concat(String(primaryKey), "/");
|
|
478
|
+
var fetchOptions = {
|
|
479
|
+
method: 'DELETE'
|
|
480
|
+
};
|
|
481
|
+
fetchOptions.query = [];
|
|
482
|
+
if (!(options && options.withRights)) {
|
|
483
|
+
fetchOptions.query.push(['skip_rights', 'y']);
|
|
484
|
+
}
|
|
485
|
+
if (_this.merchi.sessionToken) {
|
|
486
|
+
fetchOptions.query.push(['session_token', _this.merchi.sessionToken]);
|
|
487
|
+
}
|
|
488
|
+
return _this.merchi.authenticatedFetch(resource, fetchOptions, true).then(function () {
|
|
489
|
+
return _this;
|
|
490
|
+
});
|
|
491
|
+
});
|
|
492
|
+
_defineProperty(this, "recover", function (options) {
|
|
493
|
+
var primaryKey = _this.getPrimaryKeyValue();
|
|
494
|
+
var constructor = _this.constructor;
|
|
495
|
+
var resourceName = constructor.resourceName;
|
|
496
|
+
var singularName = constructor.singularName;
|
|
497
|
+
var resource = "/unarchive/".concat(resourceName, "/").concat(String(primaryKey), "/");
|
|
498
|
+
var fetchOptions = {
|
|
499
|
+
method: 'POST'
|
|
500
|
+
};
|
|
501
|
+
fetchOptions.query = [];
|
|
502
|
+
if (options && options.embed) {
|
|
503
|
+
fetchOptions.query.push(['embed', JSON.stringify(options.embed)]);
|
|
504
|
+
}
|
|
505
|
+
if (!(options && options.withRights)) {
|
|
506
|
+
fetchOptions.query.push(['skip_rights', 'y']);
|
|
507
|
+
}
|
|
508
|
+
return _this.merchi.authenticatedFetch(resource, fetchOptions).then(function (data) {
|
|
509
|
+
_this.fromJson(data[singularName]);
|
|
510
|
+
return _this;
|
|
511
|
+
});
|
|
512
|
+
});
|
|
513
|
+
/* istanbul ignore next */
|
|
514
|
+
if (merchi !== undefined) {
|
|
515
|
+
this.merchi = merchi;
|
|
516
|
+
}
|
|
517
|
+
this.propertiesMap = this.makePropertiesMap();
|
|
518
|
+
this.setupProperties();
|
|
519
|
+
}
|
|
520
|
+
_createClass(Entity, [{
|
|
521
|
+
key: "isSingleEntityProperty",
|
|
522
|
+
value: function isSingleEntityProperty(info) {
|
|
523
|
+
// the choice of 'Product' below is unimportant -- all Entities should
|
|
524
|
+
// have the same prototype but i don't know how to get instanceof
|
|
525
|
+
// working, so i just compare prototypes directly.
|
|
526
|
+
return info.type.prototype === this.merchi.Product.prototype || info.type.prototype instanceof Entity;
|
|
527
|
+
}
|
|
528
|
+
}, {
|
|
529
|
+
key: "makePropertiesMap",
|
|
530
|
+
value: function makePropertiesMap() {
|
|
531
|
+
var map = new Map();
|
|
532
|
+
var self = this;
|
|
533
|
+
var properties = Reflect.getMetadata(Entity.propertiesSetKey, this.constructor);
|
|
534
|
+
properties.forEach(function (attributeName) {
|
|
535
|
+
var jsonName = Reflect.getMetadata(Entity.jsonNameKey, self, attributeName);
|
|
536
|
+
var propertyType = Reflect.getMetadata('design:type', self, attributeName);
|
|
537
|
+
// the array type is needed because 'design:type' breaks down
|
|
538
|
+
// with recursive classes, and also, does not contain the type
|
|
539
|
+
// of an arrays elements, which we need
|
|
540
|
+
var arrayType = Reflect.getMetadata(Entity.arrayTypeKey, self, attributeName);
|
|
541
|
+
var realArrayType = self.getEntityClass(arrayType);
|
|
542
|
+
var options = Reflect.getMetadata(Entity.extraOptionsKey, self, attributeName);
|
|
543
|
+
if (arrayType !== undefined) {
|
|
544
|
+
/* istanbul ignore next */
|
|
545
|
+
if (propertyType !== Object && propertyType !== Array) {
|
|
546
|
+
/* istanbul ignore next */
|
|
547
|
+
throw new Error('array type can only be given for arrays');
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
var type;
|
|
551
|
+
if (options.type === undefined) {
|
|
552
|
+
type = propertyType;
|
|
553
|
+
} else {
|
|
554
|
+
type = options.type;
|
|
555
|
+
if (typeof type === 'string') {
|
|
556
|
+
type = self.getEntityClass(type);
|
|
557
|
+
}
|
|
558
|
+
if (type.prototype instanceof Entity) {
|
|
559
|
+
type = self.merchi.setupClass(type);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
var normallyEmbeddedByDefault = !(realArrayType || type.prototype instanceof Entity);
|
|
563
|
+
var embeddedByDefault = options.embeddedByDefault !== undefined ? options.embeddedByDefault : normallyEmbeddedByDefault;
|
|
564
|
+
/* istanbul ignore next */
|
|
565
|
+
if (type === Object) {
|
|
566
|
+
/* istanbul ignore next */
|
|
567
|
+
var resource = self.constructor.resourceName;
|
|
568
|
+
var err = 'Bad attribute type ' + "".concat(resource, ".").concat(attributeName, ": ").concat(type);
|
|
569
|
+
throw new Error(err);
|
|
570
|
+
}
|
|
571
|
+
var propertyInfo = {
|
|
572
|
+
property: jsonName,
|
|
573
|
+
attribute: attributeName,
|
|
574
|
+
type: type,
|
|
575
|
+
arrayType: realArrayType,
|
|
576
|
+
embeddedByDefault: embeddedByDefault,
|
|
577
|
+
dirty: true,
|
|
578
|
+
updatingOrder: false
|
|
579
|
+
};
|
|
580
|
+
map.set(jsonName, propertyInfo);
|
|
581
|
+
});
|
|
582
|
+
return map;
|
|
583
|
+
}
|
|
584
|
+
}], [{
|
|
585
|
+
key: "property",
|
|
586
|
+
value: function property(options) {
|
|
587
|
+
return function (target, propertyKey) {
|
|
588
|
+
if (!options) {
|
|
589
|
+
options = {};
|
|
590
|
+
}
|
|
591
|
+
var arrayType = options.arrayType;
|
|
592
|
+
var jsonName = options.jsonName || propertyKey;
|
|
593
|
+
var properties = Reflect.getMetadata(Entity.propertiesSetKey, target.constructor);
|
|
594
|
+
properties = properties || new Set();
|
|
595
|
+
properties.add(propertyKey);
|
|
596
|
+
Reflect.defineMetadata(Entity.propertiesSetKey, properties, target.constructor);
|
|
597
|
+
Reflect.defineMetadata(Entity.jsonNameKey, jsonName, target, propertyKey);
|
|
598
|
+
Reflect.defineMetadata(Entity.arrayTypeKey, arrayType, target, propertyKey);
|
|
599
|
+
Reflect.defineMetadata(Entity.extraOptionsKey, options, target, propertyKey);
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
}, {
|
|
603
|
+
key: "get",
|
|
604
|
+
value: function get(key, options) {
|
|
605
|
+
var _this2 = this;
|
|
606
|
+
var resource = "/".concat(this.resourceName, "/").concat(String(key), "/");
|
|
607
|
+
var fetchOptions = {};
|
|
608
|
+
fetchOptions.query = [];
|
|
609
|
+
if (options && options.embed) {
|
|
610
|
+
fetchOptions.query.push(['embed', JSON.stringify(options.embed)]);
|
|
611
|
+
}
|
|
612
|
+
if (options && options.includeArchived) {
|
|
613
|
+
fetchOptions.query.push(['include_archived', JSON.stringify(options.includeArchived)]);
|
|
614
|
+
}
|
|
615
|
+
if (!(options && options.withRights)) {
|
|
616
|
+
fetchOptions.query.push(['skip_rights', 'y']);
|
|
617
|
+
}
|
|
618
|
+
return this.merchi.authenticatedFetch(resource, fetchOptions).then(function (data) {
|
|
619
|
+
var result = new _this2();
|
|
620
|
+
result.fromJson(data[_this2.singularName]);
|
|
621
|
+
return result;
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
}, {
|
|
625
|
+
key: "list",
|
|
626
|
+
value: function list(options) {
|
|
627
|
+
var _this3 = this;
|
|
628
|
+
var resource = "/".concat(this.resourceName, "/");
|
|
629
|
+
var fetchOptions = {};
|
|
630
|
+
fetchOptions.query = [];
|
|
631
|
+
if (options) {
|
|
632
|
+
if (options.embed) {
|
|
633
|
+
fetchOptions.query.push(['embed', JSON.stringify(options.embed)]);
|
|
634
|
+
}
|
|
635
|
+
if (options.offset !== undefined) {
|
|
636
|
+
fetchOptions.query.push(['offset', options.offset.toString()]);
|
|
637
|
+
}
|
|
638
|
+
if (options.limit !== undefined) {
|
|
639
|
+
fetchOptions.query.push(['limit', options.limit.toString()]);
|
|
640
|
+
}
|
|
641
|
+
if (options.q !== undefined) {
|
|
642
|
+
fetchOptions.query.push(['q', options.q]);
|
|
643
|
+
}
|
|
644
|
+
if (options.sort !== undefined) {
|
|
645
|
+
fetchOptions.query.push(['sort', options.sort]);
|
|
646
|
+
}
|
|
647
|
+
if (options.order !== undefined) {
|
|
648
|
+
fetchOptions.query.push(['order', options.order]);
|
|
649
|
+
}
|
|
650
|
+
if (options.serialiseMethod !== undefined) {
|
|
651
|
+
fetchOptions.query.push(['serialise_method', options.serialiseMethod]);
|
|
652
|
+
}
|
|
653
|
+
if (options.tab !== undefined) {
|
|
654
|
+
fetchOptions.query.push(['tab', options.tab]);
|
|
655
|
+
}
|
|
656
|
+
if (options.as !== undefined) {
|
|
657
|
+
fetchOptions.query.push(['as', options.as]);
|
|
658
|
+
}
|
|
659
|
+
if (options.state !== undefined) {
|
|
660
|
+
fetchOptions.query.push(['state', options.state]);
|
|
661
|
+
}
|
|
662
|
+
if (options.categoryId !== undefined) {
|
|
663
|
+
fetchOptions.query.push(['category_id', options.categoryId.toString()]);
|
|
664
|
+
}
|
|
665
|
+
if (options.platformCategoryId !== undefined) {
|
|
666
|
+
fetchOptions.query.push(['platform_category_id', options.platformCategoryId.toString()]);
|
|
667
|
+
}
|
|
668
|
+
if (options.inDomain !== undefined) {
|
|
669
|
+
fetchOptions.query.push(['in_domain', options.inDomain.toString()]);
|
|
670
|
+
}
|
|
671
|
+
if (options.inDomainName !== undefined) {
|
|
672
|
+
fetchOptions.query.push(['in_domain_name', options.inDomainName.toString()]);
|
|
673
|
+
}
|
|
674
|
+
if (options.inDomainRoles !== undefined) {
|
|
675
|
+
fetchOptions.query.push(['in_domain_roles', JSON.stringify(options.inDomainRoles)]);
|
|
676
|
+
}
|
|
677
|
+
if (options.isPrivate !== undefined) {
|
|
678
|
+
fetchOptions.query.push(['is_private', options.isPrivate.toString()]);
|
|
679
|
+
}
|
|
680
|
+
if (options.asRole !== undefined) {
|
|
681
|
+
fetchOptions.query.push(['as_role', options.asRole.toString()]);
|
|
682
|
+
}
|
|
683
|
+
if (options.groupBuyOnly !== undefined) {
|
|
684
|
+
fetchOptions.query.push(['group_buy_only', options.groupBuyOnly.toString()]);
|
|
685
|
+
}
|
|
686
|
+
if (options.publicOnly !== undefined) {
|
|
687
|
+
fetchOptions.query.push(['public_only', options.publicOnly.toString()]);
|
|
688
|
+
}
|
|
689
|
+
if (options.managedOnly !== undefined) {
|
|
690
|
+
fetchOptions.query.push(['managed_only', options.managedOnly.toString()]);
|
|
691
|
+
}
|
|
692
|
+
if (options.doesNotHaveAdminDomain !== undefined) {
|
|
693
|
+
fetchOptions.query.push(['does_not_have_admin_domain', options.doesNotHaveAdminDomain.toString()]);
|
|
694
|
+
}
|
|
695
|
+
if (options.clientOnly !== undefined) {
|
|
696
|
+
fetchOptions.query.push(['client_only', options.clientOnly.toString()]);
|
|
697
|
+
}
|
|
698
|
+
if (options.teamOnly !== undefined) {
|
|
699
|
+
fetchOptions.query.push(['team_only', options.teamOnly.toString()]);
|
|
700
|
+
}
|
|
701
|
+
if (options.memberOnly !== undefined) {
|
|
702
|
+
fetchOptions.query.push(['member_only', options.memberOnly.toString()]);
|
|
703
|
+
}
|
|
704
|
+
if (options.merchiOnly !== undefined) {
|
|
705
|
+
fetchOptions.query.push(['merchi_only', options.merchiOnly.toString()]);
|
|
706
|
+
}
|
|
707
|
+
if (options.supplierResellOnly !== undefined) {
|
|
708
|
+
fetchOptions.query.push(['supplier_resell_only', options.supplierResellOnly.toString()]);
|
|
709
|
+
}
|
|
710
|
+
if (options.shopifyOnly !== undefined) {
|
|
711
|
+
fetchOptions.query.push(['shopify_only', options.shopifyOnly.toString()]);
|
|
712
|
+
}
|
|
713
|
+
if (options.inbound !== undefined) {
|
|
714
|
+
fetchOptions.query.push(['inbound', options.inbound.toString()]);
|
|
715
|
+
}
|
|
716
|
+
if (options.isMaster !== undefined) {
|
|
717
|
+
fetchOptions.query.push(['is_master', options.isMaster.toString()]);
|
|
718
|
+
}
|
|
719
|
+
if (options.domainRoles !== undefined) {
|
|
720
|
+
fetchOptions.query.push(['domain_roles', options.domainRoles.join(',')]);
|
|
721
|
+
}
|
|
722
|
+
if (options.domainTypes !== undefined) {
|
|
723
|
+
fetchOptions.query.push(['domain_types', options.domainTypes.join(',')]);
|
|
724
|
+
}
|
|
725
|
+
if (options.entityTypes !== undefined) {
|
|
726
|
+
fetchOptions.query.push(['entity_types', options.entityTypes.join(',')]);
|
|
727
|
+
}
|
|
728
|
+
if (options.productTypes !== undefined) {
|
|
729
|
+
fetchOptions.query.push(['product_types', options.productTypes.join(',')]);
|
|
730
|
+
}
|
|
731
|
+
if (options.managedDomainsOnly !== undefined) {
|
|
732
|
+
fetchOptions.query.push(['managed_domains_only', options.managedDomainsOnly.toString()]);
|
|
733
|
+
}
|
|
734
|
+
if (options.businessDomainsOnly !== undefined) {
|
|
735
|
+
fetchOptions.query.push(['business_domains_only', options.businessDomainsOnly.toString()]);
|
|
736
|
+
}
|
|
737
|
+
if (options.dateFrom !== undefined) {
|
|
738
|
+
fetchOptions.query.push(['date_from', toUnixTimestamp(options.dateFrom)]);
|
|
739
|
+
}
|
|
740
|
+
if (options.dateTo !== undefined) {
|
|
741
|
+
fetchOptions.query.push(['date_to', toUnixTimestamp(options.dateTo)]);
|
|
742
|
+
}
|
|
743
|
+
if (options.originalOf !== undefined) {
|
|
744
|
+
fetchOptions.query.push(['original_of', options.originalOf.toString()]);
|
|
745
|
+
}
|
|
746
|
+
if (options.relatedComponent !== undefined) {
|
|
747
|
+
fetchOptions.query.push(['related_component', options.relatedComponent.toString()]);
|
|
748
|
+
}
|
|
749
|
+
if (options.relatedAssignment !== undefined) {
|
|
750
|
+
fetchOptions.query.push(['related_assignment', options.relatedAssignment.toString()]);
|
|
751
|
+
}
|
|
752
|
+
if (options.relatedDraft !== undefined) {
|
|
753
|
+
fetchOptions.query.push(['related_draft', options.relatedDraft.toString()]);
|
|
754
|
+
}
|
|
755
|
+
if (options.relatedJob !== undefined) {
|
|
756
|
+
fetchOptions.query.push(['related_job', options.relatedJob.toString()]);
|
|
757
|
+
}
|
|
758
|
+
if (options.relatedProduct !== undefined) {
|
|
759
|
+
fetchOptions.query.push(['related_product', options.relatedProduct.toString()]);
|
|
760
|
+
}
|
|
761
|
+
if (options.jobNotifiable !== undefined) {
|
|
762
|
+
fetchOptions.query.push(['job_notifiable', options.jobNotifiable.toString()]);
|
|
763
|
+
}
|
|
764
|
+
if (options.notificationType !== undefined) {
|
|
765
|
+
fetchOptions.query.push(['notification_type', options.notificationType.toString()]);
|
|
766
|
+
}
|
|
767
|
+
if (options.notificationRecipient !== undefined) {
|
|
768
|
+
fetchOptions.query.push(['notification_recipient', options.notificationRecipient.toString()]);
|
|
769
|
+
}
|
|
770
|
+
if (options.notificationJob !== undefined) {
|
|
771
|
+
fetchOptions.query.push(['notification_job', options.notificationJob.toString()]);
|
|
772
|
+
}
|
|
773
|
+
if (options.relatedUser !== undefined) {
|
|
774
|
+
fetchOptions.query.push(['related_user', options.relatedUser.toString()]);
|
|
775
|
+
}
|
|
776
|
+
if (options.clientId !== undefined) {
|
|
777
|
+
fetchOptions.query.push(['client_id', options.clientId.toString()]);
|
|
778
|
+
}
|
|
779
|
+
if (options.managerId !== undefined) {
|
|
780
|
+
fetchOptions.query.push(['manager_id', options.managerId.toString()]);
|
|
781
|
+
}
|
|
782
|
+
if (options.masterProduct !== undefined) {
|
|
783
|
+
fetchOptions.query.push(['master_product', options.masterProduct.toString()]);
|
|
784
|
+
}
|
|
785
|
+
if (options.clientCompanyId !== undefined) {
|
|
786
|
+
fetchOptions.query.push(['client_company_id', options.clientCompanyId.toString()]);
|
|
787
|
+
}
|
|
788
|
+
if (options.savedByUser !== undefined) {
|
|
789
|
+
fetchOptions.query.push(['saved_by_user', options.savedByUser.toString()]);
|
|
790
|
+
}
|
|
791
|
+
if (options.receiverId !== undefined) {
|
|
792
|
+
fetchOptions.query.push(['receiver_id', options.receiverId.toString()]);
|
|
793
|
+
}
|
|
794
|
+
if (options.companyCustomerId !== undefined) {
|
|
795
|
+
fetchOptions.query.push(['company_customer_id', options.companyCustomerId.toString()]);
|
|
796
|
+
}
|
|
797
|
+
if (options.companyId !== undefined) {
|
|
798
|
+
fetchOptions.query.push(['company_id', options.companyId.toString()]);
|
|
799
|
+
}
|
|
800
|
+
if (options.companySupplierId !== undefined) {
|
|
801
|
+
fetchOptions.query.push(['company_supplier_id', options.companySupplierId.toString()]);
|
|
802
|
+
}
|
|
803
|
+
if (options.componentId !== undefined) {
|
|
804
|
+
fetchOptions.query.push(['component_id', options.componentId.toString()]);
|
|
805
|
+
}
|
|
806
|
+
if (options.groupBuyForJobId !== undefined) {
|
|
807
|
+
fetchOptions.query.push(['group_buy_for_job_id', options.groupBuyForJobId.toString()]);
|
|
808
|
+
}
|
|
809
|
+
if (options.section !== undefined) {
|
|
810
|
+
fetchOptions.query.push(['section', options.section.toString()]);
|
|
811
|
+
}
|
|
812
|
+
if (options.senderRole !== undefined) {
|
|
813
|
+
fetchOptions.query.push(['sender_role', options.senderRole.toString()]);
|
|
814
|
+
}
|
|
815
|
+
if (options.isOrder) {
|
|
816
|
+
fetchOptions.query.push(['is_order', 'true']);
|
|
817
|
+
}
|
|
818
|
+
if (options.tags !== undefined) {
|
|
819
|
+
fetchOptions.query.push(['tags', options.tags.join(',')]);
|
|
820
|
+
}
|
|
821
|
+
if (options.tagsInternal !== undefined) {
|
|
822
|
+
fetchOptions.query.push(['tags_internal', options.tagsInternal.join(',')]);
|
|
823
|
+
}
|
|
824
|
+
if (options.tagNames !== undefined) {
|
|
825
|
+
fetchOptions.query.push(['tag_names', options.tagNames.join(',')]);
|
|
826
|
+
}
|
|
827
|
+
if (options.exclude !== undefined) {
|
|
828
|
+
fetchOptions.query.push(['exclude', options.exclude.join(',')]);
|
|
829
|
+
}
|
|
830
|
+
if (options.excludeComponents !== undefined) {
|
|
831
|
+
fetchOptions.query.push(['exclude_components', options.excludeComponents.join(',')]);
|
|
832
|
+
}
|
|
833
|
+
if (options.excludeDomains !== undefined) {
|
|
834
|
+
fetchOptions.query.push(['exclude_domains', options.excludeDomains.join(',')]);
|
|
835
|
+
}
|
|
836
|
+
if (options.includeOnly !== undefined) {
|
|
837
|
+
fetchOptions.query.push(['include_only', options.includeOnly.join(',')]);
|
|
838
|
+
}
|
|
839
|
+
if (options.orClientId !== undefined) {
|
|
840
|
+
fetchOptions.query.push(['or_client_id', options.orClientId.toString()]);
|
|
841
|
+
}
|
|
842
|
+
if (options.orClientCompanyId !== undefined) {
|
|
843
|
+
fetchOptions.query.push(['or_client_company_id', options.orClientCompanyId.toString()]);
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
if (!(options && options.withRights)) {
|
|
847
|
+
fetchOptions.query.push(['skip_rights', 'y']);
|
|
848
|
+
}
|
|
849
|
+
return this.merchi.authenticatedFetch(resource, fetchOptions).then(function (data) {
|
|
850
|
+
var metadata = {
|
|
851
|
+
canCreate: data.canCreate,
|
|
852
|
+
available: data.available,
|
|
853
|
+
count: data.count,
|
|
854
|
+
limit: data.limit,
|
|
855
|
+
offset: data.offset
|
|
856
|
+
};
|
|
857
|
+
var pluralName = _this3.pluralName;
|
|
858
|
+
var singularName = _this3.singularName;
|
|
859
|
+
var items = data[pluralName];
|
|
860
|
+
var entities = [];
|
|
861
|
+
var _iterator7 = _createForOfIteratorHelper(items),
|
|
862
|
+
_step7;
|
|
863
|
+
try {
|
|
864
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
865
|
+
var item = _step7.value;
|
|
866
|
+
var entity = new _this3();
|
|
867
|
+
entity.fromJson(item[singularName]);
|
|
868
|
+
entities.push(entity);
|
|
869
|
+
}
|
|
870
|
+
} catch (err) {
|
|
871
|
+
_iterator7.e(err);
|
|
872
|
+
} finally {
|
|
873
|
+
_iterator7.f();
|
|
874
|
+
}
|
|
875
|
+
return {
|
|
876
|
+
items: entities,
|
|
877
|
+
metadata: metadata
|
|
878
|
+
};
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
}]);
|
|
882
|
+
return Entity;
|
|
883
|
+
}();
|
|
884
|
+
_defineProperty(Entity, "jsonNameKey", Symbol('jsonName'));
|
|
885
|
+
_defineProperty(Entity, "arrayTypeKey", Symbol('arrayType'));
|
|
886
|
+
_defineProperty(Entity, "extraOptionsKey", Symbol('extraOptions'));
|
|
887
|
+
_defineProperty(Entity, "propertiesSetKey", Symbol('propertiesSet'));
|
|
888
|
+
_defineProperty(Entity, "primaryKey", 'id');
|