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.
Files changed (444) hide show
  1. package/.babelrc +13 -0
  2. package/.eslintrc.cjs +43 -0
  3. package/LICENSE +21 -0
  4. package/README.md +2 -0
  5. package/dist/constants/auto_assign_production_on_actions.js +7 -0
  6. package/dist/constants/call_to_actions.js +15 -0
  7. package/dist/constants/call_to_actions.test.js +4 -0
  8. package/dist/constants/discount_types.js +4 -0
  9. package/dist/constants/discount_types.test.js +4 -0
  10. package/dist/constants/domain_types.js +13 -0
  11. package/dist/constants/domain_types.test.js +4 -0
  12. package/dist/constants/errors.js +32 -0
  13. package/dist/constants/event_types.js +6 -0
  14. package/dist/constants/event_types.test.js +4 -0
  15. package/dist/constants/field_types.js +14 -0
  16. package/dist/constants/field_types.test.js +4 -0
  17. package/dist/constants/input_types.js +14 -0
  18. package/dist/constants/input_types.test.js +4 -0
  19. package/dist/constants/inventory_status.test.js +4 -0
  20. package/dist/constants/inventory_statuses.js +7 -0
  21. package/dist/constants/invoice_types.js +6 -0
  22. package/dist/constants/invoice_types.test.js +4 -0
  23. package/dist/constants/item_types.js +6 -0
  24. package/dist/constants/item_types.test.js +4 -0
  25. package/dist/constants/job/drafting_status.js +8 -0
  26. package/dist/constants/job/drafting_status.test.js +4 -0
  27. package/dist/constants/job/payment_status.js +8 -0
  28. package/dist/constants/job/payment_status.test.js +4 -0
  29. package/dist/constants/job/production_status.js +13 -0
  30. package/dist/constants/job/production_status.test.js +4 -0
  31. package/dist/constants/job/shipment_status.js +12 -0
  32. package/dist/constants/job/shipment_status.test.js +4 -0
  33. package/dist/constants/job/supply_chain_request_status.js +7 -0
  34. package/dist/constants/job/supply_chain_request_status.test.js +4 -0
  35. package/dist/constants/job_priorities.js +7 -0
  36. package/dist/constants/job_priorities.test.js +4 -0
  37. package/dist/constants/job_status.js +50 -0
  38. package/dist/constants/job_status.test.js +4 -0
  39. package/dist/constants/job_types.js +16 -0
  40. package/dist/constants/job_types.test.js +4 -0
  41. package/dist/constants/notification_sections.js +14 -0
  42. package/dist/constants/notification_sections.test.js +4 -0
  43. package/dist/constants/notification_types.js +98 -0
  44. package/dist/constants/notification_types.test.js +4 -0
  45. package/dist/constants/notification_urgencies.js +7 -0
  46. package/dist/constants/notification_urgencies.test.js +4 -0
  47. package/dist/constants/payment_types.js +11 -0
  48. package/dist/constants/payment_types.test.js +4 -0
  49. package/dist/constants/platform.js +5 -0
  50. package/dist/constants/platform.test.js +8 -0
  51. package/dist/constants/product_types.js +26 -0
  52. package/dist/constants/product_types.test.js +4 -0
  53. package/dist/constants/rights.js +6 -0
  54. package/dist/constants/rights.test.js +4 -0
  55. package/dist/constants/robots_meta_directives.js +1 -0
  56. package/dist/constants/robots_meta_directives.test.js +4 -0
  57. package/dist/constants/roles.js +25 -0
  58. package/dist/constants/roles.test.js +4 -0
  59. package/dist/constants/shipment_companies.js +19 -0
  60. package/dist/constants/shipment_companies.test.js +4 -0
  61. package/dist/constants/shipment_services.js +4 -0
  62. package/dist/constants/shipment_services.test.js +4 -0
  63. package/dist/constants/system_roles.js +4 -0
  64. package/dist/constants/system_roles.test.js +4 -0
  65. package/dist/constants/theme_foundations.js +7 -0
  66. package/dist/constants/theme_foundations.test.js +4 -0
  67. package/dist/constants/theme_status.js +6 -0
  68. package/dist/constants/theme_status.test.js +4 -0
  69. package/dist/constants/user_types.js +18 -0
  70. package/dist/constants/user_types.test.js +4 -0
  71. package/dist/constants/white_label_accessibilities.js +6 -0
  72. package/dist/constants/white_label_accessibilities.test.js +4 -0
  73. package/dist/cookie.js +16 -0
  74. package/dist/cookie.test.js +12 -0
  75. package/dist/entities/address.js +166 -0
  76. package/dist/entities/address.test.js +6 -0
  77. package/dist/entities/assignment.js +185 -0
  78. package/dist/entities/assignment.test.js +38 -0
  79. package/dist/entities/automatic_payment_relationship.js +77 -0
  80. package/dist/entities/automatic_payment_relationship.test.js +6 -0
  81. package/dist/entities/backup.js +44 -0
  82. package/dist/entities/backup.test.js +6 -0
  83. package/dist/entities/bank.js +116 -0
  84. package/dist/entities/bank.test.js +6 -0
  85. package/dist/entities/cart.js +203 -0
  86. package/dist/entities/cart.test.js +52 -0
  87. package/dist/entities/cart_item.js +153 -0
  88. package/dist/entities/cart_item.test.js +34 -0
  89. package/dist/entities/cart_shipment_group.js +62 -0
  90. package/dist/entities/cart_shipment_quote.js +85 -0
  91. package/dist/entities/category.js +92 -0
  92. package/dist/entities/category.test.js +52 -0
  93. package/dist/entities/company.js +648 -0
  94. package/dist/entities/company.test.js +6 -0
  95. package/dist/entities/company_invitation.js +82 -0
  96. package/dist/entities/company_invitation.test.js +6 -0
  97. package/dist/entities/component.js +209 -0
  98. package/dist/entities/component.test.js +12 -0
  99. package/dist/entities/component_tag.js +50 -0
  100. package/dist/entities/component_tag.test.js +6 -0
  101. package/dist/entities/component_version.js +80 -0
  102. package/dist/entities/component_version.test.js +6 -0
  103. package/dist/entities/country_tax.js +110 -0
  104. package/dist/entities/country_tax.test.js +11 -0
  105. package/dist/entities/discount.js +77 -0
  106. package/dist/entities/discount.test.js +20 -0
  107. package/dist/entities/discount_group.js +74 -0
  108. package/dist/entities/discount_group.test.js +6 -0
  109. package/dist/entities/domain.js +535 -0
  110. package/dist/entities/domain.test.js +75 -0
  111. package/dist/entities/domain_invitation.js +90 -0
  112. package/dist/entities/domain_invitation.test.js +6 -0
  113. package/dist/entities/domain_tag.js +100 -0
  114. package/dist/entities/domain_tag.test.js +6 -0
  115. package/dist/entities/draft.js +180 -0
  116. package/dist/entities/draft.test.js +39 -0
  117. package/dist/entities/draft_comment.js +132 -0
  118. package/dist/entities/draft_comment.test.js +6 -0
  119. package/dist/entities/draft_template.js +105 -0
  120. package/dist/entities/draft_template.test.js +6 -0
  121. package/dist/entities/email_address.js +68 -0
  122. package/dist/entities/email_address.test.js +6 -0
  123. package/dist/entities/email_counter.js +56 -0
  124. package/dist/entities/email_counter.test.js +6 -0
  125. package/dist/entities/enrolled_domain.js +85 -0
  126. package/dist/entities/enrolled_domain.test.js +6 -0
  127. package/dist/entities/exchange_rate.js +62 -0
  128. package/dist/entities/exchange_rate.test.js +6 -0
  129. package/dist/entities/file.js +383 -0
  130. package/dist/entities/file.test.js +38 -0
  131. package/dist/entities/internal_tag.js +120 -0
  132. package/dist/entities/internal_tag.test.js +6 -0
  133. package/dist/entities/inventory.js +120 -0
  134. package/dist/entities/inventory.test.js +26 -0
  135. package/dist/entities/inventory_unit_variation.js +64 -0
  136. package/dist/entities/inventory_unit_variation.test.js +6 -0
  137. package/dist/entities/invoice.js +420 -0
  138. package/dist/entities/invoice.test.js +39 -0
  139. package/dist/entities/item.js +102 -0
  140. package/dist/entities/item.test.js +17 -0
  141. package/dist/entities/job.js +744 -0
  142. package/dist/entities/job.test.js +103 -0
  143. package/dist/entities/job_comment.js +120 -0
  144. package/dist/entities/job_comment.test.js +6 -0
  145. package/dist/entities/matching_inventory.js +77 -0
  146. package/dist/entities/menu.js +78 -0
  147. package/dist/entities/menu.test.js +6 -0
  148. package/dist/entities/menu_item.js +76 -0
  149. package/dist/entities/menu_item.test.js +6 -0
  150. package/dist/entities/notification.js +234 -0
  151. package/dist/entities/notification.test.js +6 -0
  152. package/dist/entities/page.js +84 -0
  153. package/dist/entities/page.test.js +6 -0
  154. package/dist/entities/payment.js +141 -0
  155. package/dist/entities/payment.test.js +18 -0
  156. package/dist/entities/payment_device.js +87 -0
  157. package/dist/entities/payment_device.test.js +6 -0
  158. package/dist/entities/phone_number.js +98 -0
  159. package/dist/entities/phone_number.test.js +6 -0
  160. package/dist/entities/product.js +806 -0
  161. package/dist/entities/product.test.js +811 -0
  162. package/dist/entities/production_comment.js +120 -0
  163. package/dist/entities/production_comment.test.js +6 -0
  164. package/dist/entities/quote.js +208 -0
  165. package/dist/entities/quote.test.js +107 -0
  166. package/dist/entities/quote_item.js +121 -0
  167. package/dist/entities/quote_item.test.js +56 -0
  168. package/dist/entities/seo_domain_page.js +82 -0
  169. package/dist/entities/seo_domain_page.test.js +6 -0
  170. package/dist/entities/session.js +77 -0
  171. package/dist/entities/session.test.js +6 -0
  172. package/dist/entities/shipment.js +401 -0
  173. package/dist/entities/shipment.test.js +28 -0
  174. package/dist/entities/shipment_item.js +49 -0
  175. package/dist/entities/shipment_item.test.js +6 -0
  176. package/dist/entities/shipment_item_fulfillment.js +48 -0
  177. package/dist/entities/shipment_item_fulfillment.test.js +6 -0
  178. package/dist/entities/shipment_method.js +146 -0
  179. package/dist/entities/shipment_method.test.js +6 -0
  180. package/dist/entities/shipment_method_variation.js +104 -0
  181. package/dist/entities/shipment_method_variation.test.js +6 -0
  182. package/dist/entities/short_url.js +95 -0
  183. package/dist/entities/short_url.test.js +6 -0
  184. package/dist/entities/subscription_plan.js +172 -0
  185. package/dist/entities/subscription_plan.test.js +6 -0
  186. package/dist/entities/supply_domain.js +73 -0
  187. package/dist/entities/supply_domain.test.js +6 -0
  188. package/dist/entities/system_role.js +50 -0
  189. package/dist/entities/system_role.test.js +6 -0
  190. package/dist/entities/theme.js +614 -0
  191. package/dist/entities/theme.test.js +39 -0
  192. package/dist/entities/theme_css_setting.js +67 -0
  193. package/dist/entities/theme_css_setting.test.js +6 -0
  194. package/dist/entities/user.js +749 -0
  195. package/dist/entities/user.test.js +157 -0
  196. package/dist/entities/user_company.js +78 -0
  197. package/dist/entities/user_company.test.js +6 -0
  198. package/dist/entities/variation.js +147 -0
  199. package/dist/entities/variation.test.js +6 -0
  200. package/dist/entities/variation_field.js +313 -0
  201. package/dist/entities/variation_field.test.js +69 -0
  202. package/dist/entities/variation_fields_option.js +190 -0
  203. package/dist/entities/variation_fields_option.test.js +47 -0
  204. package/dist/entities/variation_option.js +129 -0
  205. package/dist/entities/variation_option.test.js +6 -0
  206. package/dist/entities/variations_group.js +111 -0
  207. package/dist/entities/variations_group.test.js +6 -0
  208. package/dist/entity.js +888 -0
  209. package/dist/merchi.js +259 -0
  210. package/dist/merchi.test.js +35 -0
  211. package/dist/request.js +132 -0
  212. package/dist/request.test.js +46 -0
  213. package/dist/test_util.js +19 -0
  214. package/dist/toasts.js +27 -0
  215. package/dist/toasts.test.js +46 -0
  216. package/dist/util/float.js +24 -0
  217. package/dist/util/query_string.js +11 -0
  218. package/dist/util/query_string.test.js +6 -0
  219. package/dist/util/validation.js +3 -0
  220. package/dist/util/validation.test.js +12 -0
  221. package/dist/uuid.js +8 -0
  222. package/dist/uuid.test.js +13 -0
  223. package/jest.config.js +17 -0
  224. package/package.json +44 -0
  225. package/src/constants/auto_assign_production_on_actions.ts +6 -0
  226. package/src/constants/call_to_actions.test.ts +5 -0
  227. package/src/constants/call_to_actions.ts +14 -0
  228. package/src/constants/discount_types.test.ts +5 -0
  229. package/src/constants/discount_types.ts +3 -0
  230. package/src/constants/domain_types.test.ts +5 -0
  231. package/src/constants/domain_types.ts +12 -0
  232. package/src/constants/errors.ts +32 -0
  233. package/src/constants/event_types.test.ts +5 -0
  234. package/src/constants/event_types.ts +5 -0
  235. package/src/constants/field_types.test.ts +5 -0
  236. package/src/constants/field_types.ts +13 -0
  237. package/src/constants/input_types.test.ts +5 -0
  238. package/src/constants/input_types.ts +13 -0
  239. package/src/constants/inventory_status.test.ts +5 -0
  240. package/src/constants/inventory_statuses.ts +6 -0
  241. package/src/constants/invoice_types.test.ts +5 -0
  242. package/src/constants/invoice_types.ts +5 -0
  243. package/src/constants/item_types.test.ts +5 -0
  244. package/src/constants/item_types.ts +5 -0
  245. package/src/constants/job/drafting_status.test.ts +5 -0
  246. package/src/constants/job/drafting_status.ts +7 -0
  247. package/src/constants/job/payment_status.test.ts +5 -0
  248. package/src/constants/job/payment_status.ts +7 -0
  249. package/src/constants/job/production_status.test.ts +5 -0
  250. package/src/constants/job/production_status.ts +12 -0
  251. package/src/constants/job/shipment_status.test.ts +5 -0
  252. package/src/constants/job/shipment_status.ts +11 -0
  253. package/src/constants/job/supply_chain_request_status.test.ts +5 -0
  254. package/src/constants/job/supply_chain_request_status.ts +6 -0
  255. package/src/constants/job_priorities.test.ts +5 -0
  256. package/src/constants/job_priorities.ts +6 -0
  257. package/src/constants/job_status.test.ts +5 -0
  258. package/src/constants/job_status.ts +49 -0
  259. package/src/constants/job_types.test.ts +5 -0
  260. package/src/constants/job_types.ts +15 -0
  261. package/src/constants/notification_sections.test.ts +5 -0
  262. package/src/constants/notification_sections.ts +13 -0
  263. package/src/constants/notification_types.test.ts +5 -0
  264. package/src/constants/notification_types.ts +97 -0
  265. package/src/constants/notification_urgencies.test.ts +5 -0
  266. package/src/constants/notification_urgencies.ts +7 -0
  267. package/src/constants/payment_types.test.ts +5 -0
  268. package/src/constants/payment_types.ts +10 -0
  269. package/src/constants/platform.test.ts +15 -0
  270. package/src/constants/platform.ts +6 -0
  271. package/src/constants/product_types.test.ts +6 -0
  272. package/src/constants/product_types.ts +25 -0
  273. package/src/constants/rights.test.ts +5 -0
  274. package/src/constants/rights.ts +5 -0
  275. package/src/constants/robots_meta_directives.test.ts +5 -0
  276. package/src/constants/robots_meta_directives.ts +11 -0
  277. package/src/constants/roles.test.ts +5 -0
  278. package/src/constants/roles.ts +38 -0
  279. package/src/constants/shipment_companies.test.ts +5 -0
  280. package/src/constants/shipment_companies.ts +18 -0
  281. package/src/constants/shipment_services.test.ts +5 -0
  282. package/src/constants/shipment_services.ts +3 -0
  283. package/src/constants/system_roles.test.ts +5 -0
  284. package/src/constants/system_roles.ts +3 -0
  285. package/src/constants/theme_foundations.test.ts +5 -0
  286. package/src/constants/theme_foundations.ts +6 -0
  287. package/src/constants/theme_status.test.ts +5 -0
  288. package/src/constants/theme_status.ts +5 -0
  289. package/src/constants/user_types.test.ts +5 -0
  290. package/src/constants/user_types.ts +17 -0
  291. package/src/constants/white_label_accessibilities.test.ts +5 -0
  292. package/src/constants/white_label_accessibilities.ts +6 -0
  293. package/src/cookie.test.ts +11 -0
  294. package/src/cookie.ts +16 -0
  295. package/src/entities/address.test.ts +7 -0
  296. package/src/entities/address.ts +65 -0
  297. package/src/entities/assignment.test.ts +39 -0
  298. package/src/entities/assignment.ts +92 -0
  299. package/src/entities/automatic_payment_relationship.test.ts +8 -0
  300. package/src/entities/automatic_payment_relationship.ts +26 -0
  301. package/src/entities/backup.test.ts +7 -0
  302. package/src/entities/backup.ts +14 -0
  303. package/src/entities/bank.test.ts +7 -0
  304. package/src/entities/bank.ts +45 -0
  305. package/src/entities/cart.test.ts +50 -0
  306. package/src/entities/cart.ts +89 -0
  307. package/src/entities/cart_item.test.ts +33 -0
  308. package/src/entities/cart_item.ts +77 -0
  309. package/src/entities/cart_shipment_group.ts +21 -0
  310. package/src/entities/cart_shipment_quote.ts +33 -0
  311. package/src/entities/category.test.ts +57 -0
  312. package/src/entities/category.ts +37 -0
  313. package/src/entities/company.test.ts +7 -0
  314. package/src/entities/company.ts +275 -0
  315. package/src/entities/company_invitation.test.ts +7 -0
  316. package/src/entities/company_invitation.ts +33 -0
  317. package/src/entities/component.test.ts +14 -0
  318. package/src/entities/component.ts +92 -0
  319. package/src/entities/component_tag.test.ts +7 -0
  320. package/src/entities/component_tag.ts +17 -0
  321. package/src/entities/component_version.test.ts +7 -0
  322. package/src/entities/component_version.ts +30 -0
  323. package/src/entities/country_tax.test.ts +13 -0
  324. package/src/entities/country_tax.ts +46 -0
  325. package/src/entities/discount.test.ts +18 -0
  326. package/src/entities/discount.ts +34 -0
  327. package/src/entities/discount_group.test.ts +7 -0
  328. package/src/entities/discount_group.ts +28 -0
  329. package/src/entities/domain.test.ts +79 -0
  330. package/src/entities/domain.ts +246 -0
  331. package/src/entities/domain_invitation.test.ts +7 -0
  332. package/src/entities/domain_invitation.ts +36 -0
  333. package/src/entities/domain_tag.test.ts +7 -0
  334. package/src/entities/domain_tag.ts +42 -0
  335. package/src/entities/draft.test.ts +43 -0
  336. package/src/entities/draft.ts +88 -0
  337. package/src/entities/draft_comment.test.ts +7 -0
  338. package/src/entities/draft_comment.ts +54 -0
  339. package/src/entities/draft_template.test.ts +7 -0
  340. package/src/entities/draft_template.ts +40 -0
  341. package/src/entities/email_address.test.ts +7 -0
  342. package/src/entities/email_address.ts +24 -0
  343. package/src/entities/email_counter.test.ts +7 -0
  344. package/src/entities/email_counter.ts +20 -0
  345. package/src/entities/enrolled_domain.test.ts +7 -0
  346. package/src/entities/enrolled_domain.ts +40 -0
  347. package/src/entities/exchange_rate.test.ts +7 -0
  348. package/src/entities/exchange_rate.ts +22 -0
  349. package/src/entities/file.test.ts +43 -0
  350. package/src/entities/file.ts +172 -0
  351. package/src/entities/internal_tag.test.ts +7 -0
  352. package/src/entities/internal_tag.ts +51 -0
  353. package/src/entities/inventory.test.ts +28 -0
  354. package/src/entities/inventory.ts +56 -0
  355. package/src/entities/inventory_unit_variation.test.ts +7 -0
  356. package/src/entities/inventory_unit_variation.ts +29 -0
  357. package/src/entities/invoice.test.ts +43 -0
  358. package/src/entities/invoice.ts +179 -0
  359. package/src/entities/item.test.ts +19 -0
  360. package/src/entities/item.ts +44 -0
  361. package/src/entities/job.test.ts +95 -0
  362. package/src/entities/job.ts +349 -0
  363. package/src/entities/job_comment.test.ts +7 -0
  364. package/src/entities/job_comment.ts +50 -0
  365. package/src/entities/matching_inventory.ts +29 -0
  366. package/src/entities/menu.test.ts +7 -0
  367. package/src/entities/menu.ts +30 -0
  368. package/src/entities/menu_item.test.ts +7 -0
  369. package/src/entities/menu_item.ts +29 -0
  370. package/src/entities/notification.test.ts +7 -0
  371. package/src/entities/notification.ts +99 -0
  372. package/src/entities/page.test.ts +7 -0
  373. package/src/entities/page.ts +32 -0
  374. package/src/entities/payment.test.ts +19 -0
  375. package/src/entities/payment.ts +65 -0
  376. package/src/entities/payment_device.test.ts +7 -0
  377. package/src/entities/payment_device.ts +30 -0
  378. package/src/entities/phone_number.test.ts +7 -0
  379. package/src/entities/phone_number.ts +36 -0
  380. package/src/entities/product.test.ts +750 -0
  381. package/src/entities/product.ts +427 -0
  382. package/src/entities/production_comment.test.ts +7 -0
  383. package/src/entities/production_comment.ts +50 -0
  384. package/src/entities/quote.test.ts +98 -0
  385. package/src/entities/quote.ts +140 -0
  386. package/src/entities/quote_item.test.ts +50 -0
  387. package/src/entities/quote_item.ts +71 -0
  388. package/src/entities/seo_domain_page.test.ts +7 -0
  389. package/src/entities/seo_domain_page.ts +33 -0
  390. package/src/entities/session.test.ts +7 -0
  391. package/src/entities/session.ts +28 -0
  392. package/src/entities/shipment.test.ts +24 -0
  393. package/src/entities/shipment.ts +185 -0
  394. package/src/entities/shipment_item.test.ts +7 -0
  395. package/src/entities/shipment_item.ts +15 -0
  396. package/src/entities/shipment_item_fulfillment.test.ts +8 -0
  397. package/src/entities/shipment_item_fulfillment.ts +15 -0
  398. package/src/entities/shipment_method.test.ts +7 -0
  399. package/src/entities/shipment_method.ts +61 -0
  400. package/src/entities/shipment_method_variation.test.ts +7 -0
  401. package/src/entities/shipment_method_variation.ts +39 -0
  402. package/src/entities/short_url.test.ts +7 -0
  403. package/src/entities/short_url.ts +36 -0
  404. package/src/entities/subscription_plan.test.ts +7 -0
  405. package/src/entities/subscription_plan.ts +73 -0
  406. package/src/entities/supply_domain.test.ts +7 -0
  407. package/src/entities/supply_domain.ts +27 -0
  408. package/src/entities/system_role.test.ts +7 -0
  409. package/src/entities/system_role.ts +17 -0
  410. package/src/entities/theme.test.ts +38 -0
  411. package/src/entities/theme.ts +267 -0
  412. package/src/entities/theme_css_setting.test.ts +7 -0
  413. package/src/entities/theme_css_setting.ts +23 -0
  414. package/src/entities/user.test.ts +154 -0
  415. package/src/entities/user.ts +394 -0
  416. package/src/entities/user_company.test.ts +7 -0
  417. package/src/entities/user_company.ts +27 -0
  418. package/src/entities/variation.test.ts +7 -0
  419. package/src/entities/variation.ts +61 -0
  420. package/src/entities/variation_field.test.ts +76 -0
  421. package/src/entities/variation_field.ts +169 -0
  422. package/src/entities/variation_fields_option.test.ts +46 -0
  423. package/src/entities/variation_fields_option.ts +95 -0
  424. package/src/entities/variation_option.test.ts +7 -0
  425. package/src/entities/variation_option.ts +52 -0
  426. package/src/entities/variations_group.test.ts +7 -0
  427. package/src/entities/variations_group.ts +41 -0
  428. package/src/entity.ts +1002 -0
  429. package/src/merchi.test.ts +25 -0
  430. package/src/merchi.ts +379 -0
  431. package/src/request.test.ts +43 -0
  432. package/src/request.ts +124 -0
  433. package/src/test_util.ts +18 -0
  434. package/src/toasts.test.ts +38 -0
  435. package/src/toasts.ts +34 -0
  436. package/src/util/float.ts +12 -0
  437. package/src/util/query_string.test.ts +7 -0
  438. package/src/util/query_string.ts +11 -0
  439. package/src/util/validation.test.ts +16 -0
  440. package/src/util/validation.ts +2 -0
  441. package/src/uuid.test.ts +15 -0
  442. package/src/uuid.ts +8 -0
  443. package/tsconfig.json +23 -0
  444. package/webpack.config.cjs +27 -0
package/dist/merchi.js ADDED
@@ -0,0 +1,259 @@
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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5
+ 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); } }
6
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
7
+ 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; }
8
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
9
+ 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); }
10
+ import { AutomaticPaymentRelationship } from './entities/automatic_payment_relationship';
11
+ import { Session } from './entities/session';
12
+ import { JobComment } from './entities/job_comment';
13
+ import { Domain } from './entities/domain';
14
+ import { ExchangeRate } from './entities/exchange_rate';
15
+ import { Job } from './entities/job';
16
+ import { Menu } from './entities/menu';
17
+ import { Backup } from './entities/backup';
18
+ import { VariationField } from './entities/variation_field';
19
+ import { VariationOption } from './entities/variation_option';
20
+ import { ProductionComment } from './entities/production_comment';
21
+ import { Product } from './entities/product';
22
+ import { InternalTag } from './entities/internal_tag';
23
+ import { Inventory } from './entities/inventory';
24
+ import { QuoteItem } from './entities/quote_item';
25
+ import { Category } from './entities/category';
26
+ import { Invoice } from './entities/invoice';
27
+ import { UserCompany } from './entities/user_company';
28
+ import { InventoryUnitVariation } from './entities/inventory_unit_variation';
29
+ import { VariationFieldsOption } from './entities/variation_fields_option';
30
+ import { Bank } from './entities/bank';
31
+ import { Shipment } from './entities/shipment';
32
+ import { ShipmentItem } from './entities/shipment_item';
33
+ import { ShipmentItemFulfillment } from './entities/shipment_item_fulfillment';
34
+ import { ShipmentMethod } from './entities/shipment_method';
35
+ import { ShipmentMethodVariation } from './entities/shipment_method_variation';
36
+ import { DomainInvitation } from './entities/domain_invitation';
37
+ import { EmailCounter } from './entities/email_counter';
38
+ import { MenuItem } from './entities/menu_item';
39
+ import { SupplyDomain } from './entities/supply_domain';
40
+ import { Cart } from './entities/cart';
41
+ import { CartShipmentGroup } from './entities/cart_shipment_group';
42
+ import { CartShipmentQuote } from './entities/cart_shipment_quote';
43
+ import { Theme } from './entities/theme';
44
+ import { ThemeCssSetting } from './entities/theme_css_setting';
45
+ import { Component } from './entities/component';
46
+ import { ComponentVersion } from './entities/component_version';
47
+ import { MerchiFile } from './entities/file';
48
+ import { EmailAddress } from './entities/email_address';
49
+ import { SeoDomainPage } from './entities/seo_domain_page';
50
+ import { ShortUrl } from './entities/short_url';
51
+ import { VariationsGroup } from './entities/variations_group';
52
+ import { Quote } from './entities/quote';
53
+ import { Draft } from './entities/draft';
54
+ import { DraftTemplate } from './entities/draft_template';
55
+ import { Discount } from './entities/discount';
56
+ import { DiscountGroup } from './entities/discount_group';
57
+ import { User } from './entities/user';
58
+ import { Company } from './entities/company';
59
+ import { ComponentTag } from './entities/component_tag';
60
+ import { EnrolledDomain } from './entities/enrolled_domain';
61
+ import { CountryTax } from './entities/country_tax';
62
+ import { Item } from './entities/item';
63
+ import { DomainTag } from './entities/domain_tag';
64
+ import { DraftComment } from './entities/draft_comment';
65
+ import { Notification } from './entities/notification';
66
+ import { Payment } from './entities/payment';
67
+ import { Page } from './entities/page';
68
+ import { CompanyInvitation } from './entities/company_invitation';
69
+ import { SystemRole } from './entities/system_role';
70
+ import { PaymentDevice } from './entities/payment_device';
71
+ import { PhoneNumber } from './entities/phone_number';
72
+ import { Variation } from './entities/variation';
73
+ import { CartItem } from './entities/cart_item';
74
+ import { Address } from './entities/address';
75
+ import { Assignment } from './entities/assignment';
76
+ import { MatchingInventory } from './entities/matching_inventory';
77
+ import { SubscriptionPlan } from './entities/subscription_plan';
78
+ import { generateUUID } from './uuid';
79
+ // eslint-disable-next-line no-unused-vars
80
+ import { apiFetch, apiFetchWithProgress } from './request';
81
+ import { getCookie } from './cookie';
82
+
83
+ // the type of classes
84
+
85
+ function cloneClass(original, arg) {
86
+ // copy the constructor, but use the empty object as `this`
87
+ var copy = original.bind({}, arg);
88
+ // pick up any static members (this is shallow, the members are not copied)
89
+ Object.assign(copy, original);
90
+ return copy;
91
+ }
92
+ export var Merchi = /*#__PURE__*/function () {
93
+ function Merchi(sessionToken, clientToken, invoiceToken, cartToken) {
94
+ var _this = this;
95
+ _classCallCheck(this, Merchi);
96
+ _defineProperty(this, "id", generateUUID());
97
+ _defineProperty(this, "authenticatedFetch", function (resource, options, expectEmptyResponse) {
98
+ if (!options.query) {
99
+ /* istanbul ignore next */
100
+ options.query = [];
101
+ }
102
+ if (_this.sessionToken) {
103
+ /* istanbul ignore next */
104
+ options.query.push(['session_token', _this.sessionToken]);
105
+ }
106
+ if (_this.clientToken) {
107
+ /* istanbul ignore next */
108
+ options.query.push(['client_token', _this.clientToken]);
109
+ }
110
+ if (_this.invoiceToken) {
111
+ /* istanbul ignore next */
112
+ options.query.push(['invoice_token', _this.invoiceToken]);
113
+ }
114
+ if (_this.cartToken) {
115
+ /* istanbul ignore next */
116
+ options.query.push(['cart_token', _this.cartToken]);
117
+ }
118
+ return apiFetch(resource, options, expectEmptyResponse);
119
+ });
120
+ /* istanbul ignore next */
121
+ _defineProperty(this, "authenticatedFetchWithProgress", function (resource, options, progressCallback) {
122
+ if (!options.query) {
123
+ options.query = [];
124
+ }
125
+ if (_this.sessionToken) {
126
+ options.query.push(['session_token', _this.sessionToken]);
127
+ }
128
+ if (_this.clientToken) {
129
+ options.query.push(['client_token', _this.clientToken]);
130
+ }
131
+ if (_this.invoiceToken) {
132
+ options.query.push(['invoice_token', _this.invoiceToken]);
133
+ }
134
+ if (_this.cartToken) {
135
+ options.query.push(['cart_token', _this.cartToken]);
136
+ }
137
+ return apiFetchWithProgress(resource, options, progressCallback);
138
+ });
139
+ _defineProperty(this, "getCurrentUser", function (options) {
140
+ var _ref = options || {},
141
+ _ref$embed = _ref.embed,
142
+ embed = _ref$embed === void 0 ? {} : _ref$embed;
143
+ var defaultEmbed = {
144
+ user: {
145
+ enrolledDomains: {
146
+ domain: {}
147
+ }
148
+ }
149
+ };
150
+ if (!_this.sessionToken) {
151
+ return Promise.resolve(null);
152
+ }
153
+ return _this.Session.get(_this.sessionToken, {
154
+ embed: _objectSpread(_objectSpread({}, defaultEmbed), embed)
155
+ }).then(function (session) {
156
+ return session.user;
157
+ });
158
+ });
159
+ if (sessionToken) {
160
+ this.sessionToken = sessionToken;
161
+ } else {
162
+ this.sessionToken = getCookie('session_token');
163
+ }
164
+ if (clientToken) {
165
+ this.clientToken = clientToken;
166
+ } else {
167
+ this.clientToken = getCookie('client_token');
168
+ }
169
+ if (invoiceToken) {
170
+ this.invoiceToken = invoiceToken;
171
+ } else {
172
+ this.invoiceToken = getCookie('invoice_token');
173
+ }
174
+ if (cartToken) {
175
+ this.cartToken = cartToken;
176
+ } else {
177
+ this.cartToken = getCookie('cart_token');
178
+ }
179
+
180
+ // re-export configured versions of all classes
181
+ this.AutomaticPaymentRelationship = this.setupClass(AutomaticPaymentRelationship);
182
+ this.Variation = this.setupClass(Variation);
183
+ this.DraftComment = this.setupClass(DraftComment);
184
+ this.Component = this.setupClass(Component);
185
+ this.ComponentVersion = this.setupClass(ComponentVersion);
186
+ this.Theme = this.setupClass(Theme);
187
+ this.ThemeCssSetting = this.setupClass(ThemeCssSetting);
188
+ this.Company = this.setupClass(Company);
189
+ this.MenuItem = this.setupClass(MenuItem);
190
+ this.InternalTag = this.setupClass(InternalTag);
191
+ this.Inventory = this.setupClass(Inventory);
192
+ this.Notification = this.setupClass(Notification);
193
+ this.Shipment = this.setupClass(Shipment);
194
+ this.ShipmentItem = this.setupClass(ShipmentItem);
195
+ this.ShipmentItemFulfillment = this.setupClass(ShipmentItemFulfillment);
196
+ this.ShipmentMethod = this.setupClass(ShipmentMethod);
197
+ this.ShipmentMethodVariation = this.setupClass(ShipmentMethodVariation);
198
+ this.Domain = this.setupClass(Domain);
199
+ this.ExchangeRate = this.setupClass(ExchangeRate);
200
+ this.Invoice = this.setupClass(Invoice);
201
+ this.Job = this.setupClass(Job);
202
+ this.ComponentTag = this.setupClass(ComponentTag);
203
+ this.Category = this.setupClass(Category);
204
+ this.VariationField = this.setupClass(VariationField);
205
+ this.InventoryUnitVariation = this.setupClass(InventoryUnitVariation);
206
+ this.PhoneNumber = this.setupClass(PhoneNumber);
207
+ this.QuoteItem = this.setupClass(QuoteItem);
208
+ this.Menu = this.setupClass(Menu);
209
+ this.Assignment = this.setupClass(Assignment);
210
+ this.Draft = this.setupClass(Draft);
211
+ this.DraftTemplate = this.setupClass(DraftTemplate);
212
+ this.VariationsGroup = this.setupClass(VariationsGroup);
213
+ this.EnrolledDomain = this.setupClass(EnrolledDomain);
214
+ this.CompanyInvitation = this.setupClass(CompanyInvitation);
215
+ this.Quote = this.setupClass(Quote);
216
+ this.EmailAddress = this.setupClass(EmailAddress);
217
+ this.SeoDomainPage = this.setupClass(SeoDomainPage);
218
+ this.ProductionComment = this.setupClass(ProductionComment);
219
+ this.Backup = this.setupClass(Backup);
220
+ this.CountryTax = this.setupClass(CountryTax);
221
+ this.ShortUrl = this.setupClass(ShortUrl);
222
+ this.Product = this.setupClass(Product);
223
+ this.SystemRole = this.setupClass(SystemRole);
224
+ this.CartItem = this.setupClass(CartItem);
225
+ this.UserCompany = this.setupClass(UserCompany);
226
+ this.DomainTag = this.setupClass(DomainTag);
227
+ this.VariationFieldsOption = this.setupClass(VariationFieldsOption);
228
+ this.Address = this.setupClass(Address);
229
+ this.Item = this.setupClass(Item);
230
+ this.SupplyDomain = this.setupClass(SupplyDomain);
231
+ this.DomainInvitation = this.setupClass(DomainInvitation);
232
+ this.EmailCounter = this.setupClass(EmailCounter);
233
+ this.Session = this.setupClass(Session);
234
+ this.Bank = this.setupClass(Bank);
235
+ this.Discount = this.setupClass(Discount);
236
+ this.DiscountGroup = this.setupClass(DiscountGroup);
237
+ this.Payment = this.setupClass(Payment);
238
+ this.PaymentDevice = this.setupClass(PaymentDevice);
239
+ this.Page = this.setupClass(Page);
240
+ this.Cart = this.setupClass(Cart);
241
+ this.CartShipmentGroup = this.setupClass(CartShipmentGroup);
242
+ this.CartShipmentQuote = this.setupClass(CartShipmentQuote);
243
+ this.MerchiFile = this.setupClass(MerchiFile);
244
+ this.User = this.setupClass(User);
245
+ this.JobComment = this.setupClass(JobComment);
246
+ this.VariationOption = this.setupClass(VariationOption);
247
+ this.MatchingInventory = this.setupClass(MatchingInventory);
248
+ this.SubscriptionPlan = this.setupClass(SubscriptionPlan);
249
+ }
250
+ _createClass(Merchi, [{
251
+ key: "setupClass",
252
+ value: function setupClass(cls) {
253
+ var result = cloneClass(cls, this);
254
+ result.merchi = this;
255
+ return result;
256
+ }
257
+ }]);
258
+ return Merchi;
259
+ }();
@@ -0,0 +1,35 @@
1
+ import { setup, mockFetch } from './test_util';
2
+ import { Merchi } from './merchi';
3
+ setup();
4
+ test('can get current user merchi has session token', function () {
5
+ var testToken = 'YrDwzmh8&QGtAfg9quh(4QfSlE^RPXWl';
6
+ var merchi = new Merchi(testToken);
7
+ mockFetch(true, {
8
+ session: {
9
+ user: {
10
+ name: 'currentUser'
11
+ }
12
+ }
13
+ }, 200);
14
+ return merchi.getCurrentUser().then(function (user) {
15
+ return expect(user.name).toBe('currentUser');
16
+ });
17
+ });
18
+ test('get current user return empty if there is no cookie', function () {
19
+ Object.defineProperty(document, 'cookie', {
20
+ get: jest.fn().mockImplementation(function () {
21
+ return '';
22
+ })
23
+ });
24
+ var merchi = new Merchi();
25
+ mockFetch(true, {
26
+ user: {
27
+ name: 'currentUser'
28
+ }
29
+ }, 200);
30
+ return merchi.getCurrentUser({
31
+ embed: {}
32
+ }).then(function (user) {
33
+ return expect(user).toBe(null);
34
+ });
35
+ });
@@ -0,0 +1,132 @@
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 _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); } }
6
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
7
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
8
+ 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); }
9
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
10
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
11
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
12
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
13
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
14
+ function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
15
+ function _construct(t, e, r) { if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments); var o = [null]; o.push.apply(o, e); var p = new (t.bind.apply(t, o))(); return r && _setPrototypeOf(p, r.prototype), p; }
16
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
17
+ function _isNativeFunction(fn) { try { return Function.toString.call(fn).indexOf("[native code]") !== -1; } catch (e) { return typeof fn === "function"; } }
18
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
19
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
20
+ // eslint-disable-next-line no-unused-vars
21
+ import { getErrorFromCode } from './constants/errors';
22
+
23
+ /* this constant are expected to be defined in webpack (or provided as
24
+ globals by some other means. */
25
+
26
+ export var ApiError = /*#__PURE__*/function (_Error) {
27
+ _inherits(ApiError, _Error);
28
+ function ApiError(err) {
29
+ var _this;
30
+ _classCallCheck(this, ApiError);
31
+ var message = JSON.stringify(err);
32
+ /* istanbul ignore next */
33
+ _this = _callSuper(this, ApiError, [message]);
34
+ _this.statusCode = err.statusCode;
35
+ _this.errorCode = getErrorFromCode(err.errorCode);
36
+ _this.errorMessage = err.message ? err.message : 'No error message';
37
+ _this.name = 'ApiError';
38
+ _this.original = err;
39
+ return _this;
40
+ }
41
+ return _createClass(ApiError);
42
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
43
+ export var version = 'v6';
44
+ export function backendFetch(resource, options) {
45
+ var server = window.merchiBackendUri ? window.merchiBackendUri : BACKEND_URI;
46
+ var url = new URL(server + version + resource);
47
+ if (options && options.query) {
48
+ var _iterator = _createForOfIteratorHelper(options.query),
49
+ _step;
50
+ try {
51
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
52
+ var entry = _step.value;
53
+ url.searchParams.append(entry[0], entry[1]);
54
+ }
55
+ } catch (err) {
56
+ _iterator.e(err);
57
+ } finally {
58
+ _iterator.f();
59
+ }
60
+ }
61
+ return fetch(url.toString(), options);
62
+ }
63
+ export function apiFetch(resource, options, expectEmptyResponse) {
64
+ return backendFetch(resource, options).then(function (response) {
65
+ if (response.status < 200 || response.status > 299) {
66
+ return response.json().then(function (json) {
67
+ var err = new ApiError(json);
68
+ return Promise.reject(err);
69
+ });
70
+ } else {
71
+ return expectEmptyResponse ? '' : response.json();
72
+ }
73
+ });
74
+ }
75
+
76
+ /* istanbul ignore next */
77
+ export function apiFetchWithProgress(resource, options, progressCallback) {
78
+ return backendFetch(resource, options).then(function (response) {
79
+ if (!response.body) {
80
+ var err = new ApiError('empty response');
81
+ return Promise.reject(err);
82
+ }
83
+ var reader = response.body.getReader();
84
+ var bodyText = '';
85
+ var errorText = '';
86
+ var haveError = false;
87
+ var expected = '{"loadingBar": "' + '.'.repeat(100) + '"}';
88
+ function readChunk() {
89
+ return reader.read().then(function (_ref) {
90
+ var done = _ref.done,
91
+ value = _ref.value;
92
+ if (done) {
93
+ if (response.status < 200 || response.status > 299) {
94
+ var _err = new ApiError('Unknown error');
95
+ return Promise.reject(_err);
96
+ } else if (haveError) {
97
+ try {
98
+ var jsonText = JSON.parse(errorText);
99
+ return Promise.reject(new ApiError(jsonText));
100
+ } catch (e) {
101
+ return Promise.reject(new ApiError(errorText));
102
+ }
103
+ } else {
104
+ return bodyText;
105
+ }
106
+ } else {
107
+ var chunk = new TextDecoder().decode(value);
108
+ if (haveError) {
109
+ errorText += chunk;
110
+ } else {
111
+ for (var i = 0; i < chunk.length; ++i) {
112
+ var _char = chunk[i];
113
+ var expectedChar = expected[bodyText.length];
114
+ if (expectedChar == _char && !haveError) {
115
+ bodyText += _char;
116
+ } else {
117
+ haveError = true;
118
+ errorText += _char;
119
+ }
120
+ }
121
+ }
122
+ if (!haveError && progressCallback) {
123
+ var _progress = Math.min(Math.max(0, bodyText.length - 16), 100);
124
+ progressCallback(_progress);
125
+ }
126
+ return readChunk();
127
+ }
128
+ });
129
+ }
130
+ return readChunk();
131
+ });
132
+ }
@@ -0,0 +1,46 @@
1
+ import { apiFetch } from './request';
2
+ import { ErrorType } from './constants/errors';
3
+ import { setup, mockFetch } from './test_util';
4
+ setup();
5
+ test('can pass through data from server', function () {
6
+ mockFetch(true, {
7
+ 'animal': 'turtle'
8
+ }, 200);
9
+ return apiFetch('/test').then(function (data) {
10
+ expect(data.animal).toBe('turtle');
11
+ });
12
+ });
13
+ test('can pass through data from server with override url', function () {
14
+ window.merchiBackendUri = 'http://override.example.com/';
15
+ mockFetch(true, {
16
+ 'animal': 'turtle'
17
+ }, 200);
18
+ return apiFetch('/test').then(function (data) {
19
+ expect(data.animal).toBe('turtle');
20
+ });
21
+ });
22
+ test('404 creates ApiError', function () {
23
+ mockFetch(false, {
24
+ 'statusCode': 404,
25
+ 'errorCode': ErrorType.RESOURCE_NOT_FOUND
26
+ }, 404);
27
+ apiFetch('/test')["catch"](function (e) {
28
+ expect(e.statusCode).toBe(404);
29
+ expect(e.name).toBe('ApiError');
30
+ expect(e.errorCode).toBe(ErrorType.RESOURCE_NOT_FOUND);
31
+ expect(e.errorMessage).toBe('No error message');
32
+ });
33
+ });
34
+ test('will get default errorCode', function () {
35
+ mockFetch(false, {
36
+ 'statusCode': 404,
37
+ 'errorCode': -1,
38
+ 'message': 'just a test'
39
+ }, 404);
40
+ apiFetch('/test')["catch"](function (e) {
41
+ expect(e.statusCode).toBe(404);
42
+ expect(e.name).toBe('ApiError');
43
+ expect(e.errorCode).toBe(ErrorType.UNKNOWN_ERROR);
44
+ expect(e.errorMessage).toBe('just a test');
45
+ });
46
+ });
@@ -0,0 +1,19 @@
1
+ export function setup() {
2
+ beforeAll(function () {
3
+ global.BACKEND_URI = 'http://example.com/';
4
+ });
5
+ }
6
+ export function mockFetch(ok, data, status) {
7
+ var mock = jest.fn();
8
+ mock.mockImplementation(function () {
9
+ return Promise.resolve({
10
+ status: status,
11
+ ok: ok,
12
+ json: function json() {
13
+ return Promise.resolve(data);
14
+ }
15
+ });
16
+ });
17
+ global.fetch = mock;
18
+ return mock;
19
+ }
package/dist/toasts.js ADDED
@@ -0,0 +1,27 @@
1
+ // eslint-disable-next-line no-unused-vars
2
+
3
+ // eslint-disable-next-line no-unused-vars
4
+
5
+ // eslint-disable-next-line no-unused-vars
6
+
7
+ // eslint-disable-next-line no-unused-vars
8
+
9
+ export var toastNotifications = function toastNotifications(merchi, options) {
10
+ var resource = '/notifications-check-update/';
11
+ var data = new FormData();
12
+ var entities = options.entities,
13
+ sections = options.sections,
14
+ notificationTypes = options.notificationTypes;
15
+ data.set('entities', JSON.stringify(entities));
16
+ data.set('sections', JSON.stringify(sections));
17
+ data.set('notificationTypes', JSON.stringify(notificationTypes));
18
+ var fetchOptions = {
19
+ method: 'POST',
20
+ body: data
21
+ };
22
+ return merchi.authenticatedFetch(resource, fetchOptions).then(function (data) {
23
+ return data.notifications.map(function (n) {
24
+ return new merchi.Notification().fromJson(n);
25
+ });
26
+ });
27
+ };
@@ -0,0 +1,46 @@
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 _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; }
3
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
4
+ 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); }
5
+ import { setup, mockFetch } from './test_util';
6
+ import { toastNotifications } from './toasts';
7
+ import { Merchi } from './merchi';
8
+ import { NotificationSection } from './constants/notification_sections';
9
+ import { NotificationType } from './constants/notification_types';
10
+ setup();
11
+ test('fetch toast of jobs', function () {
12
+ var merchi = new Merchi();
13
+ var fetch = mockFetch(true, {
14
+ 'notifications': [{
15
+ id: 1,
16
+ message: 'test'
17
+ }]
18
+ }, 200);
19
+ var entities = [{
20
+ id: 1,
21
+ type: 'job'
22
+ }];
23
+ var sections = [NotificationSection.JOB_NOTIFICATIONS];
24
+ var notificationTypes = _defineProperty({}, NotificationType.JOB_PAID, true);
25
+ var options = {
26
+ entities: entities,
27
+ sections: sections,
28
+ notificationTypes: notificationTypes
29
+ };
30
+ var invocation = toastNotifications(merchi, options);
31
+ var expectUrl = "".concat(global.BACKEND_URI, "v6/notifications-check-update/");
32
+ expect(fetch.mock.calls[0][0]).toEqual(expectUrl);
33
+ expect(fetch.mock.calls[0][1].method).toEqual('POST');
34
+ expect(JSON.parse(fetch.mock.calls[0][1].body.get('entities'))).toEqual([{
35
+ id: 1,
36
+ type: 'job'
37
+ }]);
38
+ expect(fetch.mock.calls[0][1].body.get('sections')).toEqual("[".concat(NotificationSection.JOB_NOTIFICATIONS, "]"));
39
+ expect(JSON.parse(fetch.mock.calls[0][1].body.get('notificationTypes'))).toEqual(_defineProperty({}, NotificationType.JOB_PAID, true));
40
+ invocation.then(function (notifications) {
41
+ expect(notifications.length).toBe(1);
42
+ expect(notifications[0].id).toBe(1);
43
+ expect(notifications[0].message).toBe('test');
44
+ });
45
+ return invocation;
46
+ });
@@ -0,0 +1,24 @@
1
+ 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; } } }; }
2
+ 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); }
3
+ 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; }
4
+ export function kahanSum(values) {
5
+ /* Return the kahan summation of the input number array */
6
+ var accumulator = 0;
7
+ var compensation = 0;
8
+ var _iterator = _createForOfIteratorHelper(values),
9
+ _step;
10
+ try {
11
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
12
+ var value = _step.value;
13
+ var y = value - compensation;
14
+ var t = accumulator + y;
15
+ compensation = t - accumulator - y;
16
+ accumulator = t;
17
+ }
18
+ } catch (err) {
19
+ _iterator.e(err);
20
+ } finally {
21
+ _iterator.f();
22
+ }
23
+ return accumulator;
24
+ }
@@ -0,0 +1,11 @@
1
+ export function getQueryStringValue(name) {
2
+ var query = window.location.search.substring(1);
3
+ var vars = query.split('&');
4
+ for (var i = 0; i < vars.length; i++) {
5
+ var pair = vars[i].split('=');
6
+ if (pair[0] === name) {
7
+ return decodeURIComponent(pair[1]);
8
+ }
9
+ }
10
+ return undefined;
11
+ }
@@ -0,0 +1,6 @@
1
+ import { getQueryStringValue } from './query_string';
2
+ test('lol', function () {
3
+ expect(getQueryStringValue('a')).toBe(undefined);
4
+ history.replaceState({}, 'Test', '/test?a=3');
5
+ expect(getQueryStringValue('a')).toBe('3');
6
+ });
@@ -0,0 +1,3 @@
1
+ export var isUndefinedOrNull = function isUndefinedOrNull(value) {
2
+ return value === undefined || value === null;
3
+ };
@@ -0,0 +1,12 @@
1
+ import { isUndefinedOrNull } from './validation';
2
+ test('return true if value is null', function () {
3
+ expect(isUndefinedOrNull(null)).toBe(true);
4
+ });
5
+ test('return true if value is undefined', function () {
6
+ expect(isUndefinedOrNull(undefined)).toBe(true);
7
+ });
8
+ test('return false if value other than undefined or null', function () {
9
+ expect(isUndefinedOrNull(false)).toBe(false);
10
+ expect(isUndefinedOrNull('')).toBe(false);
11
+ expect(isUndefinedOrNull(0)).toBe(false);
12
+ });
package/dist/uuid.js ADDED
@@ -0,0 +1,8 @@
1
+ export function generateUUID() {
2
+ var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
3
+ uuid = uuid.replace(/[xy]/g, function (c) {
4
+ var r = Math.random() * 16 % 16 | 0;
5
+ return (c === 'x' ? r : r & 0x3 | 0x8).toString(16);
6
+ });
7
+ return uuid;
8
+ }