merchi_sdk_ts 0.0.1

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 (226) 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/jest.config.js +17 -0
  6. package/package.json +44 -0
  7. package/src/constants/auto_assign_production_on_actions.ts +6 -0
  8. package/src/constants/call_to_actions.test.ts +5 -0
  9. package/src/constants/call_to_actions.ts +14 -0
  10. package/src/constants/discount_types.test.ts +5 -0
  11. package/src/constants/discount_types.ts +3 -0
  12. package/src/constants/domain_types.test.ts +5 -0
  13. package/src/constants/domain_types.ts +12 -0
  14. package/src/constants/errors.ts +32 -0
  15. package/src/constants/event_types.test.ts +5 -0
  16. package/src/constants/event_types.ts +5 -0
  17. package/src/constants/field_types.test.ts +5 -0
  18. package/src/constants/field_types.ts +13 -0
  19. package/src/constants/input_types.test.ts +5 -0
  20. package/src/constants/input_types.ts +13 -0
  21. package/src/constants/inventory_status.test.ts +5 -0
  22. package/src/constants/inventory_statuses.ts +6 -0
  23. package/src/constants/invoice_types.test.ts +5 -0
  24. package/src/constants/invoice_types.ts +5 -0
  25. package/src/constants/item_types.test.ts +5 -0
  26. package/src/constants/item_types.ts +5 -0
  27. package/src/constants/job/drafting_status.test.ts +5 -0
  28. package/src/constants/job/drafting_status.ts +7 -0
  29. package/src/constants/job/payment_status.test.ts +5 -0
  30. package/src/constants/job/payment_status.ts +7 -0
  31. package/src/constants/job/production_status.test.ts +5 -0
  32. package/src/constants/job/production_status.ts +12 -0
  33. package/src/constants/job/shipment_status.test.ts +5 -0
  34. package/src/constants/job/shipment_status.ts +11 -0
  35. package/src/constants/job/supply_chain_request_status.test.ts +5 -0
  36. package/src/constants/job/supply_chain_request_status.ts +6 -0
  37. package/src/constants/job_priorities.test.ts +5 -0
  38. package/src/constants/job_priorities.ts +6 -0
  39. package/src/constants/job_status.test.ts +5 -0
  40. package/src/constants/job_status.ts +49 -0
  41. package/src/constants/job_types.test.ts +5 -0
  42. package/src/constants/job_types.ts +15 -0
  43. package/src/constants/notification_sections.test.ts +5 -0
  44. package/src/constants/notification_sections.ts +13 -0
  45. package/src/constants/notification_types.test.ts +5 -0
  46. package/src/constants/notification_types.ts +97 -0
  47. package/src/constants/notification_urgencies.test.ts +5 -0
  48. package/src/constants/notification_urgencies.ts +7 -0
  49. package/src/constants/payment_types.test.ts +5 -0
  50. package/src/constants/payment_types.ts +10 -0
  51. package/src/constants/platform.test.ts +15 -0
  52. package/src/constants/platform.ts +6 -0
  53. package/src/constants/product_types.test.ts +6 -0
  54. package/src/constants/product_types.ts +25 -0
  55. package/src/constants/rights.test.ts +5 -0
  56. package/src/constants/rights.ts +5 -0
  57. package/src/constants/robots_meta_directives.test.ts +5 -0
  58. package/src/constants/robots_meta_directives.ts +11 -0
  59. package/src/constants/roles.test.ts +5 -0
  60. package/src/constants/roles.ts +38 -0
  61. package/src/constants/shipment_companies.test.ts +5 -0
  62. package/src/constants/shipment_companies.ts +18 -0
  63. package/src/constants/shipment_services.test.ts +5 -0
  64. package/src/constants/shipment_services.ts +3 -0
  65. package/src/constants/system_roles.test.ts +5 -0
  66. package/src/constants/system_roles.ts +3 -0
  67. package/src/constants/theme_foundations.test.ts +5 -0
  68. package/src/constants/theme_foundations.ts +6 -0
  69. package/src/constants/theme_status.test.ts +5 -0
  70. package/src/constants/theme_status.ts +5 -0
  71. package/src/constants/user_types.test.ts +5 -0
  72. package/src/constants/user_types.ts +17 -0
  73. package/src/constants/white_label_accessibilities.test.ts +5 -0
  74. package/src/constants/white_label_accessibilities.ts +6 -0
  75. package/src/cookie.test.ts +11 -0
  76. package/src/cookie.ts +16 -0
  77. package/src/entities/address.test.ts +7 -0
  78. package/src/entities/address.ts +65 -0
  79. package/src/entities/assignment.test.ts +39 -0
  80. package/src/entities/assignment.ts +92 -0
  81. package/src/entities/automatic_payment_relationship.test.ts +8 -0
  82. package/src/entities/automatic_payment_relationship.ts +26 -0
  83. package/src/entities/backup.test.ts +7 -0
  84. package/src/entities/backup.ts +14 -0
  85. package/src/entities/bank.test.ts +7 -0
  86. package/src/entities/bank.ts +45 -0
  87. package/src/entities/cart.test.ts +50 -0
  88. package/src/entities/cart.ts +89 -0
  89. package/src/entities/cart_item.test.ts +33 -0
  90. package/src/entities/cart_item.ts +77 -0
  91. package/src/entities/cart_shipment_group.ts +21 -0
  92. package/src/entities/cart_shipment_quote.ts +33 -0
  93. package/src/entities/category.test.ts +57 -0
  94. package/src/entities/category.ts +37 -0
  95. package/src/entities/company.test.ts +7 -0
  96. package/src/entities/company.ts +275 -0
  97. package/src/entities/company_invitation.test.ts +7 -0
  98. package/src/entities/company_invitation.ts +33 -0
  99. package/src/entities/component.test.ts +14 -0
  100. package/src/entities/component.ts +92 -0
  101. package/src/entities/component_tag.test.ts +7 -0
  102. package/src/entities/component_tag.ts +17 -0
  103. package/src/entities/component_version.test.ts +7 -0
  104. package/src/entities/component_version.ts +30 -0
  105. package/src/entities/country_tax.test.ts +13 -0
  106. package/src/entities/country_tax.ts +46 -0
  107. package/src/entities/discount.test.ts +18 -0
  108. package/src/entities/discount.ts +34 -0
  109. package/src/entities/discount_group.test.ts +7 -0
  110. package/src/entities/discount_group.ts +28 -0
  111. package/src/entities/domain.test.ts +79 -0
  112. package/src/entities/domain.ts +246 -0
  113. package/src/entities/domain_invitation.test.ts +7 -0
  114. package/src/entities/domain_invitation.ts +36 -0
  115. package/src/entities/domain_tag.test.ts +7 -0
  116. package/src/entities/domain_tag.ts +42 -0
  117. package/src/entities/draft.test.ts +43 -0
  118. package/src/entities/draft.ts +88 -0
  119. package/src/entities/draft_comment.test.ts +7 -0
  120. package/src/entities/draft_comment.ts +54 -0
  121. package/src/entities/draft_template.test.ts +7 -0
  122. package/src/entities/draft_template.ts +40 -0
  123. package/src/entities/email_address.test.ts +7 -0
  124. package/src/entities/email_address.ts +24 -0
  125. package/src/entities/email_counter.test.ts +7 -0
  126. package/src/entities/email_counter.ts +20 -0
  127. package/src/entities/enrolled_domain.test.ts +7 -0
  128. package/src/entities/enrolled_domain.ts +40 -0
  129. package/src/entities/exchange_rate.test.ts +7 -0
  130. package/src/entities/exchange_rate.ts +22 -0
  131. package/src/entities/file.test.ts +43 -0
  132. package/src/entities/file.ts +172 -0
  133. package/src/entities/internal_tag.test.ts +7 -0
  134. package/src/entities/internal_tag.ts +51 -0
  135. package/src/entities/inventory.test.ts +28 -0
  136. package/src/entities/inventory.ts +56 -0
  137. package/src/entities/inventory_unit_variation.test.ts +7 -0
  138. package/src/entities/inventory_unit_variation.ts +29 -0
  139. package/src/entities/invoice.test.ts +43 -0
  140. package/src/entities/invoice.ts +179 -0
  141. package/src/entities/item.test.ts +19 -0
  142. package/src/entities/item.ts +44 -0
  143. package/src/entities/job.test.ts +95 -0
  144. package/src/entities/job.ts +349 -0
  145. package/src/entities/job_comment.test.ts +7 -0
  146. package/src/entities/job_comment.ts +50 -0
  147. package/src/entities/matching_inventory.ts +29 -0
  148. package/src/entities/menu.test.ts +7 -0
  149. package/src/entities/menu.ts +30 -0
  150. package/src/entities/menu_item.test.ts +7 -0
  151. package/src/entities/menu_item.ts +29 -0
  152. package/src/entities/notification.test.ts +7 -0
  153. package/src/entities/notification.ts +99 -0
  154. package/src/entities/page.test.ts +7 -0
  155. package/src/entities/page.ts +32 -0
  156. package/src/entities/payment.test.ts +19 -0
  157. package/src/entities/payment.ts +65 -0
  158. package/src/entities/payment_device.test.ts +7 -0
  159. package/src/entities/payment_device.ts +30 -0
  160. package/src/entities/phone_number.test.ts +7 -0
  161. package/src/entities/phone_number.ts +36 -0
  162. package/src/entities/product.test.ts +750 -0
  163. package/src/entities/product.ts +427 -0
  164. package/src/entities/production_comment.test.ts +7 -0
  165. package/src/entities/production_comment.ts +50 -0
  166. package/src/entities/quote.test.ts +98 -0
  167. package/src/entities/quote.ts +140 -0
  168. package/src/entities/quote_item.test.ts +50 -0
  169. package/src/entities/quote_item.ts +71 -0
  170. package/src/entities/seo_domain_page.test.ts +7 -0
  171. package/src/entities/seo_domain_page.ts +33 -0
  172. package/src/entities/session.test.ts +7 -0
  173. package/src/entities/session.ts +28 -0
  174. package/src/entities/shipment.test.ts +24 -0
  175. package/src/entities/shipment.ts +185 -0
  176. package/src/entities/shipment_item.test.ts +7 -0
  177. package/src/entities/shipment_item.ts +15 -0
  178. package/src/entities/shipment_item_fulfillment.test.ts +8 -0
  179. package/src/entities/shipment_item_fulfillment.ts +15 -0
  180. package/src/entities/shipment_method.test.ts +7 -0
  181. package/src/entities/shipment_method.ts +61 -0
  182. package/src/entities/shipment_method_variation.test.ts +7 -0
  183. package/src/entities/shipment_method_variation.ts +39 -0
  184. package/src/entities/short_url.test.ts +7 -0
  185. package/src/entities/short_url.ts +36 -0
  186. package/src/entities/subscription_plan.test.ts +7 -0
  187. package/src/entities/subscription_plan.ts +73 -0
  188. package/src/entities/supply_domain.test.ts +7 -0
  189. package/src/entities/supply_domain.ts +27 -0
  190. package/src/entities/system_role.test.ts +7 -0
  191. package/src/entities/system_role.ts +17 -0
  192. package/src/entities/theme.test.ts +38 -0
  193. package/src/entities/theme.ts +267 -0
  194. package/src/entities/theme_css_setting.test.ts +7 -0
  195. package/src/entities/theme_css_setting.ts +23 -0
  196. package/src/entities/user.test.ts +154 -0
  197. package/src/entities/user.ts +394 -0
  198. package/src/entities/user_company.test.ts +7 -0
  199. package/src/entities/user_company.ts +27 -0
  200. package/src/entities/variation.test.ts +7 -0
  201. package/src/entities/variation.ts +61 -0
  202. package/src/entities/variation_field.test.ts +76 -0
  203. package/src/entities/variation_field.ts +169 -0
  204. package/src/entities/variation_fields_option.test.ts +46 -0
  205. package/src/entities/variation_fields_option.ts +95 -0
  206. package/src/entities/variation_option.test.ts +7 -0
  207. package/src/entities/variation_option.ts +52 -0
  208. package/src/entities/variations_group.test.ts +7 -0
  209. package/src/entities/variations_group.ts +41 -0
  210. package/src/entity.ts +1002 -0
  211. package/src/merchi.test.ts +25 -0
  212. package/src/merchi.ts +379 -0
  213. package/src/request.test.ts +43 -0
  214. package/src/request.ts +124 -0
  215. package/src/test_util.ts +18 -0
  216. package/src/toasts.test.ts +38 -0
  217. package/src/toasts.ts +34 -0
  218. package/src/util/float.ts +12 -0
  219. package/src/util/query_string.test.ts +7 -0
  220. package/src/util/query_string.ts +11 -0
  221. package/src/util/validation.test.ts +16 -0
  222. package/src/util/validation.ts +2 -0
  223. package/src/uuid.test.ts +15 -0
  224. package/src/uuid.ts +8 -0
  225. package/tsconfig.json +23 -0
  226. package/webpack.config.cjs +27 -0
@@ -0,0 +1,7 @@
1
+ export enum NotificationUrgency {
2
+ LOW = 0,
3
+ MEDIUM = 1,
4
+ HIGH = 2,
5
+ URGENT = 3,
6
+ }
7
+
@@ -0,0 +1,5 @@
1
+ import { PaymentType } from './payment_types';
2
+
3
+ test('urgent notification urgency exists', () => {
4
+ expect(PaymentType.ONLINE_PAYMENT).toBe(1);
5
+ });
@@ -0,0 +1,10 @@
1
+ export enum PaymentType {
2
+ ONLINE_PAYMENT = 1,
3
+ PAYPAL_PAYMENT = 2,
4
+ BANK_TRANSFER = 3,
5
+ CASH = 4,
6
+ CHEQUE = 5,
7
+ PHONE_PAYMENT = 6,
8
+ CREDIT_CARD = 7,
9
+ UTRUST_PAYMENT = 8,
10
+ }
@@ -0,0 +1,15 @@
1
+ import {
2
+ platformName,
3
+ platformCopyright,
4
+ platformDomain,
5
+ platformSellerDomain,
6
+ platformSellerDomainPlus
7
+ } from './platform';
8
+
9
+ test('platform variables all there', () => {
10
+ expect(platformName).toBe('Merchi');
11
+ expect(platformCopyright).toBe(2021);
12
+ expect(platformDomain).toBe('merchi.co');
13
+ expect(platformSellerDomain).toBe('merchi.co');
14
+ expect(platformSellerDomainPlus).toBe('merchi.co');
15
+ });
@@ -0,0 +1,6 @@
1
+ export const platformName = 'Merchi';
2
+ export const platformCopyright = 2021;
3
+ export const platformDomain = 'merchi.co';
4
+ export const platformSellerDomain = 'merchi.co';
5
+ export const platformSellerDomainPlus = 'merchi.co';
6
+
@@ -0,0 +1,6 @@
1
+ import { ProductType } from './product_types';
2
+
3
+ test('product types exists', () => {
4
+ expect(ProductType.SUPPLIER_MOD).toBe(0);
5
+
6
+ });
@@ -0,0 +1,25 @@
1
+ export enum ProductType {
2
+ SUPPLIER_MOD = 0,
3
+ SUPPLIER = 1,
4
+ SELLER = 2,
5
+ SELLER_MOD = 3,
6
+ CLONED_SUPPLIER_MOD = 4,
7
+ CLONED_SELLER_MOD = 5,
8
+ PRODUCTION_MOD = 6,
9
+ CLONED_SUPPLIER = 7,
10
+ INVENTORY_SELLER = 8,
11
+ INVENTORY_SUPPLIER = 9,
12
+ SELLER_GROUP_BUY = 10,
13
+ SUPPLIER_RESELL_MOD = 11,
14
+ SUPPLIER_RESELL = 12,
15
+ SUPPLIER_GROUP_BUY_INVENTORY = 13,
16
+ CLONED_INVENTORY_SELLER = 14,
17
+ CLONED_SELLER_GROUP_BUY_INVENTORY = 15,
18
+ CLONED_SUPPLIER_RESELL_MOD = 16,
19
+ SUPPLIER_TO_SUPPLIER_RESELL_MOD = 17,
20
+ CLONED_SUPPLIER_RESELL = 18,
21
+ SUPPLY_DOMAIN_REFERENCE = 19,
22
+ SELLER_FILE_DOWNLOAD = 20,
23
+ SUPPLIER_MOD_SUPPLY_CHAIN_REQUEST = 21,
24
+ SUPPLIER_SUPPLY_CHAIN_REQUEST = 22,
25
+ }
@@ -0,0 +1,5 @@
1
+ import { Right } from './rights';
2
+
3
+ test('access right exists', () => {
4
+ expect(Right.ACCESS).toBe(1);
5
+ });
@@ -0,0 +1,5 @@
1
+ export enum Right {
2
+ ACCESS = 1,
3
+ EDIT = 2,
4
+ DELETE = 3,
5
+ }
@@ -0,0 +1,5 @@
1
+ import { robotsMetaDirectives } from './robots_meta_directives';
2
+
3
+ test('robot meta directive exists', () => {
4
+ expect(robotsMetaDirectives[0]).toBe('noindex');
5
+ });
@@ -0,0 +1,11 @@
1
+ export const robotsMetaDirectives = [
2
+ 'noindex',
3
+ 'index',
4
+ 'follow',
5
+ 'nofollow',
6
+ 'noimageindex',
7
+ 'none',
8
+ 'noarchive',
9
+ 'nocache',
10
+ 'nosnippet',
11
+ ];
@@ -0,0 +1,5 @@
1
+ import { Role } from './roles';
2
+
3
+ test('admin role exists', () => {
4
+ expect(Role.ADMIN).toBe(1);
5
+ });
@@ -0,0 +1,38 @@
1
+ export enum Role {
2
+ PUBLIC = 0,
3
+ ADMIN = 1,
4
+ SALES = 2,
5
+ DESIGNER = 3,
6
+ SUPPLIER = 4,
7
+ CLIENT = 5,
8
+ MANAGER = 6,
9
+ ACCOUNTANT = 7,
10
+ THEME_EDITOR = 8,
11
+ }
12
+
13
+ export const DOMAIN_MANAGERS = [Role.ADMIN, Role.MANAGER];
14
+
15
+ export const MANAGEMENT_TEAM = [
16
+ ...DOMAIN_MANAGERS,
17
+ Role.SALES,
18
+ Role.DESIGNER,
19
+ Role.ACCOUNTANT,
20
+ ];
21
+
22
+ export const BUSINESS_ACCOUNTS = [...MANAGEMENT_TEAM, Role.SUPPLIER];
23
+
24
+ export const MANAGEMENT_ROLES = [Role.ADMIN, Role.MANAGER];
25
+
26
+ export const THEME_ROLES = [...MANAGEMENT_ROLES, Role.THEME_EDITOR];
27
+ export const ROLES_RANK = [
28
+ Role.PUBLIC,
29
+ Role.CLIENT,
30
+ Role.ACCOUNTANT,
31
+ Role.SALES,
32
+ Role.DESIGNER,
33
+ Role.SUPPLIER,
34
+ Role.MANAGER,
35
+ Role.ADMIN,
36
+ ];
37
+
38
+ export const ALL_ROLES = ROLES_RANK;
@@ -0,0 +1,5 @@
1
+ import { ShipmentCompany } from './shipment_companies';
2
+
3
+ test('dhl exists', () => {
4
+ expect(ShipmentCompany.DHL).toBe(0);
5
+ });
@@ -0,0 +1,18 @@
1
+ export enum ShipmentCompany {
2
+ DHL = 0,
3
+ UPS = 1,
4
+ EMS = 2,
5
+ FED_EX = 3,
6
+ AUSTRALIA_POST = 4,
7
+ STAR_TRACK = 5,
8
+ TOLL = 6,
9
+ TNT = 7,
10
+ CUSTOM_TRACK_LINK = 8,
11
+ ARAMEX = 9,
12
+ REALTIME_EXPRESS = 10,
13
+ UBER = 11,
14
+ CIVIC_TRANSPORT_COURIERS = 12,
15
+ NZ_POST = 13,
16
+ SENDLE = 14,
17
+ USPS = 15,
18
+ }
@@ -0,0 +1,5 @@
1
+ import { ShipmentService } from './shipment_services';
2
+
3
+ test('dhl exists', () => {
4
+ expect(ShipmentService.SENDLE).toBe(1);
5
+ });
@@ -0,0 +1,3 @@
1
+ export enum ShipmentService {
2
+ SENDLE = 1
3
+ }
@@ -0,0 +1,5 @@
1
+ import { SystemRoles } from './system_roles';
2
+
3
+ test('system component builder role exists', () => {
4
+ expect(SystemRoles.SYSTEM_COMPONENT_BUILDER).toBe(1);
5
+ });
@@ -0,0 +1,3 @@
1
+ export enum SystemRoles {
2
+ SYSTEM_COMPONENT_BUILDER = 1
3
+ }
@@ -0,0 +1,5 @@
1
+ import { ThemeFoundations } from './theme_foundations';
2
+
3
+ test('not valid status exists', () => {
4
+ expect(ThemeFoundations.BOOTSTRAP_3).toBe(1);
5
+ });
@@ -0,0 +1,6 @@
1
+ export enum ThemeFoundations {
2
+ NO_FOUNDATION = 0,
3
+ BOOTSTRAP_3 = 1,
4
+ BOOTSTRAP_4 = 2,
5
+ BOOTSTRAP_5 = 3,
6
+ }
@@ -0,0 +1,5 @@
1
+ import { ThemeStatus } from './theme_status';
2
+
3
+ test('not valid status exists', () => {
4
+ expect(ThemeStatus.NOT_VALID).toBe(1);
5
+ });
@@ -0,0 +1,5 @@
1
+ export enum ThemeStatus {
2
+ NOT_VALID = 1,
3
+ VALID_BUT_NOT_UPDATED = 2,
4
+ VALID_AND_UPDATED = 3
5
+ }
@@ -0,0 +1,5 @@
1
+ import { UserType } from './user_types';
2
+
3
+ test('not valid status exists', () => {
4
+ expect(UserType.CLIENT_GUEST).toBe(1);
5
+ });
@@ -0,0 +1,17 @@
1
+ export enum UserType {
2
+ PUBLIC = 0,
3
+ CLIENT_GUEST = 1, // A user who has not oppted in for a user account
4
+ CLIENT_DOMAIN = 2, // A user who is a client of one domain
5
+ CLIENT_MULTIPLE_DOMAINS = 3, // A user who is a client of multiple domains
6
+ CLIENT_MERCHI = 4, // A user has a client profile with Merchi
7
+ SELLER_FREE_MERCHI = 5, // A user who has opened a seller store through Merchi
8
+ SELLER_FREE_DOMAIN = 6, // A user who has opened a seller store through a domain/supplier
9
+ SELLER_PAID = 7, // A user who is paying for a seller store
10
+ SELLER_PAID_MULTIPLE_DOMAINS = 8, // A user who is paying for multiple seller stores
11
+ SUPPLIER_THIRD_PARTY = 9, // A user who has a "domain supplier" domain
12
+ SUPPLIER_RESTRICTED = 10, // A user who has a restricted supply domain
13
+ SUPPLIER_MERCHI = 11, // A user who has a supply domain which has been verified by Merchi
14
+ UNRESTRICTED = 12, // A user who has a domain which is unrestricted
15
+ SHOPIFY_REFERENCE = 13, // A user who makes order from shopify and linked to our system
16
+ RESERVED_FROM_SOCIAL = 14, // A user crawled from Social network
17
+ }
@@ -0,0 +1,5 @@
1
+ import { WhiteLabelAccessibility } from './white_label_accessibilities';
2
+
3
+ test('not reachable exists', () => {
4
+ expect(WhiteLabelAccessibility.UNREACHABLE).toBe(0);
5
+ });
@@ -0,0 +1,6 @@
1
+ export enum WhiteLabelAccessibility {
2
+ UNREACHABLE = 0,
3
+ NO_CERTIFICATE = 1,
4
+ REACHABLE = 2,
5
+ }
6
+
@@ -0,0 +1,11 @@
1
+ import { getCookie } from './cookie';
2
+
3
+ test('can get cookie', () => {
4
+ const token = 'IMiF7rpT$5ciUJ38QY';
5
+ const cookie = `session_token=${token}`;
6
+ Object.defineProperty(document, 'cookie', {
7
+ get: jest.fn().mockImplementation(() => { return cookie; }),
8
+ set: jest.fn().mockImplementation(() => {}),
9
+ });
10
+ expect(getCookie('session_token')).toBe('IMiF7rpT$5ciUJ38QY');
11
+ });
package/src/cookie.ts ADDED
@@ -0,0 +1,16 @@
1
+ export function getCookie(name: string) {
2
+ // code might be executed during SSR
3
+ // istanbul ignore next
4
+ if (typeof document !== 'undefined') {
5
+ const searchPrefix = name + '=',
6
+ cookies = document.cookie.split(';');
7
+ for (let i = 0; i < cookies.length; ++i) {
8
+ let cookie = cookies[i];
9
+ cookie = cookie.replace(/^\s*/, '');
10
+ if (cookie.indexOf(searchPrefix) === 0) {
11
+ return cookie.substring(searchPrefix.length, cookie.length);
12
+ }
13
+ }
14
+ }
15
+ return undefined;
16
+ }
@@ -0,0 +1,7 @@
1
+ import { Merchi } from '../merchi';
2
+
3
+ test('can make Address', () => {
4
+ const merchi = new Merchi();
5
+ const address = new merchi.Address();
6
+ expect(address).toBeTruthy();
7
+ });
@@ -0,0 +1,65 @@
1
+ import { Bank } from './bank';
2
+ import { Company } from './company';
3
+ import { Entity } from '../entity';
4
+ import { Inventory } from './inventory';
5
+ import { Invoice } from './invoice';
6
+ import { Job } from './job';
7
+ import { Shipment } from './shipment';
8
+ import { User } from './user';
9
+
10
+ export class Address extends Entity {
11
+ protected static resourceName = 'addresses';
12
+ protected static singularName = 'address';
13
+ protected static pluralName = 'addresses';
14
+
15
+ @Address.property({type: Date})
16
+ public archived?: Date | null;
17
+
18
+ @Address.property()
19
+ public id?: number;
20
+
21
+ @Address.property({type: String})
22
+ public lineOne?: string | null;
23
+
24
+ @Address.property({type: String})
25
+ public lineTwo?: string | null;
26
+
27
+ @Address.property({type: String})
28
+ public city?: string | null;
29
+
30
+ @Address.property({type: String})
31
+ public state?: string | null;
32
+
33
+ @Address.property({type: String})
34
+ public country?: string | null;
35
+
36
+ @Address.property({type: String})
37
+ public postcode?: string | null;
38
+
39
+ @Address.property({arrayType: 'Shipment'})
40
+ public shipmentAsSenderAddress?: Shipment[];
41
+
42
+ @Address.property({arrayType: 'Shipment'})
43
+ public shipmentsAsReceiverAddress?: Shipment[];
44
+
45
+ @Address.property({arrayType: 'Bank'})
46
+ public banks?: Bank[];
47
+
48
+ @Address.property({arrayType: 'User'})
49
+ public users?: User[];
50
+
51
+ @Address.property({arrayType: 'Inventory'})
52
+ public inventories?: Inventory[];
53
+
54
+ @Address.property({arrayType: 'Job'})
55
+ public jobs?: Job[];
56
+
57
+ @Address.property({arrayType: 'Job'})
58
+ public productedJobs?: Job[];
59
+
60
+ @Address.property({arrayType: 'Invoice'})
61
+ public shippingTo?: Invoice[];
62
+
63
+ @Address.property({arrayType: 'Company'})
64
+ public companies?: Company[];
65
+ }
@@ -0,0 +1,39 @@
1
+ import { Merchi } from '../merchi';
2
+ import { setup, mockFetch } from '../test_util';
3
+
4
+ setup();
5
+
6
+ test('can make Assignment', () => {
7
+ const merchi = new Merchi();
8
+ const assignment = new merchi.Assignment();
9
+ expect(assignment).toBeTruthy();
10
+ });
11
+
12
+ test('can generate new invoice', () => {
13
+ mockFetch(true, {'id': 1, 'totalCost': 100}, 200);
14
+
15
+ const merchi = new Merchi();
16
+ const assignment = new merchi.Assignment();
17
+ assignment.id = 1;
18
+ assignment.generateInvoice().then(invoice => {
19
+ expect(invoice.totalCost).toEqual(100);
20
+ expect(invoice.id).toEqual(1);
21
+ });
22
+ });
23
+
24
+ test('can add to invoice', () => {
25
+ const fetch = mockFetch(true, {'id': 2, 'totalCost': 100}, 200);
26
+ const merchi = new Merchi();
27
+ const assignment = new merchi.Assignment();
28
+ assignment.id = 1;
29
+ assignment.generateInvoice({addToInvoice: 2}).then(invoice => {
30
+ expect(invoice.totalCost).toEqual(100);
31
+ expect(invoice.id).toEqual(2);
32
+ });
33
+
34
+ const correct = [['add_to_invoice', '2']];
35
+ expect(
36
+ Array.from(fetch.mock.calls[0][1]['query'])
37
+ ).toEqual(correct);
38
+ });
39
+
@@ -0,0 +1,92 @@
1
+ import { Entity } from '../entity';
2
+ import { Quote } from './quote';
3
+ import { MerchiFile } from './file';
4
+ import { Job } from './job';
5
+ import { Notification } from './notification';
6
+ import { ProductionComment } from './production_comment';
7
+ import { Shipment } from './shipment';
8
+ import { SupplyDomain } from './supply_domain';
9
+ import { User } from './user';
10
+ import { RequestOptions } from '../request';
11
+
12
+ interface GenerateInvoiceProps {
13
+ addToInvoice? : number;
14
+ }
15
+
16
+ export class Assignment extends Entity {
17
+ protected static resourceName = 'assignments';
18
+ protected static singularName = 'assignment';
19
+ protected static pluralName = 'assignments';
20
+
21
+ @Assignment.property({type: Date})
22
+ public archived?: Date | null;
23
+
24
+ @Assignment.property()
25
+ public id?: number;
26
+
27
+ @Assignment.property({type: Date})
28
+ public managerAccepts?: Date | null;
29
+
30
+ @Assignment.property({type: Date})
31
+ public supplierRefused?: Date | null;
32
+
33
+ @Assignment.property()
34
+ public needsDrafting?: boolean;
35
+
36
+ @Assignment.property()
37
+ public needsShipping?: boolean;
38
+
39
+ @Assignment.property()
40
+ public productionDeadline?: Date;
41
+
42
+ @Assignment.property()
43
+ public assignmentDeadline?: Date;
44
+
45
+ @Assignment.property({type: String})
46
+ public notes?: string | null;
47
+
48
+ @Assignment.property({type: 'Job'})
49
+ public job?: Job | null;
50
+
51
+ @Assignment.property({type: 'Job'})
52
+ public supplyJob?: Job | null;
53
+
54
+ @Assignment.property({type: User})
55
+ public supplier?: User | null;
56
+
57
+ @Assignment.property({type: Quote})
58
+ public quote?: Quote | null;
59
+
60
+ @Assignment.property({arrayType: 'ProductionComment'})
61
+ public comments?: ProductionComment[];
62
+
63
+ @Assignment.property({type: Shipment})
64
+ public shipment?: Shipment | null;
65
+
66
+ @Assignment.property({type: SupplyDomain})
67
+ public supplyDomain?: SupplyDomain | null;
68
+
69
+ @Assignment.property({arrayType: 'Notification'})
70
+ public notifications?: Notification[];
71
+
72
+ @Assignment.property({arrayType: 'MerchiFile'})
73
+ public productionFiles?: MerchiFile[];
74
+
75
+ public generateInvoice = (props?: GenerateInvoiceProps) => {
76
+ const resource = `/generate-invoice-for-assignment/${this.id}/`;
77
+ const fetchOptions: RequestOptions = {method: 'POST'};
78
+ fetchOptions.query = [];
79
+
80
+ if (props && props.addToInvoice) {
81
+ fetchOptions.query.push(['add_to_invoice', String(props.addToInvoice!)]);
82
+ }
83
+
84
+ return this.merchi.authenticatedFetch(resource, fetchOptions).
85
+ then((data: any) => {
86
+ const invoice = new this.merchi.Invoice();
87
+ invoice.fromJson(data);
88
+ return invoice;
89
+ });
90
+ };
91
+
92
+ }
@@ -0,0 +1,8 @@
1
+ import { Merchi } from '../merchi';
2
+
3
+ test('can make AutomaticPaymentRelationship', () => {
4
+ const merchi = new Merchi();
5
+ const automaticPaymentRelationship =
6
+ new merchi.AutomaticPaymentRelationship();
7
+ expect(automaticPaymentRelationship).toBeTruthy();
8
+ });
@@ -0,0 +1,26 @@
1
+ import { Company } from './company';
2
+ import { Entity } from '../entity';
3
+
4
+ export class AutomaticPaymentRelationship extends Entity {
5
+ protected static resourceName = 'automatic_payment_relationships';
6
+ protected static singularName = 'automaticPaymentRelationship';
7
+ protected static pluralName = 'automaticPaymentRelationships';
8
+
9
+ @AutomaticPaymentRelationship.property({type: Date})
10
+ public archived?: Date | null;
11
+
12
+ @AutomaticPaymentRelationship.property()
13
+ public id?: number;
14
+
15
+ @AutomaticPaymentRelationship.property()
16
+ public creationDate?: Date;
17
+
18
+ @AutomaticPaymentRelationship.property({type: Company})
19
+ public companyCustomer?: Company;
20
+
21
+ @AutomaticPaymentRelationship.property({type: Company})
22
+ public companySupplier?: Company;
23
+
24
+ @AutomaticPaymentRelationship.property({type: String})
25
+ public stripeCustomerId?: string;
26
+ }
@@ -0,0 +1,7 @@
1
+ import { Merchi } from '../merchi';
2
+
3
+ test('can make Backup', () => {
4
+ const merchi = new Merchi();
5
+ const backup = new merchi.Backup();
6
+ expect(backup).toBeTruthy();
7
+ });
@@ -0,0 +1,14 @@
1
+ import { Entity } from '../entity';
2
+ import { MerchiFile } from './file';
3
+
4
+ export class Backup extends Entity {
5
+ protected static resourceName = 'backups';
6
+ protected static singularName = 'backup';
7
+ protected static pluralName = 'backups';
8
+
9
+ @Backup.property()
10
+ public id?: number;
11
+
12
+ @Backup.property()
13
+ public file?: MerchiFile;
14
+ }
@@ -0,0 +1,7 @@
1
+ import { Merchi } from '../merchi';
2
+
3
+ test('can make Bank', () => {
4
+ const merchi = new Merchi();
5
+ const bank = new merchi.Bank();
6
+ expect(bank).toBeTruthy();
7
+ });
@@ -0,0 +1,45 @@
1
+ import { Address } from './address';
2
+ import { Company } from './company';
3
+ import { Entity } from '../entity';
4
+
5
+ export class Bank extends Entity {
6
+ protected static resourceName = 'banks';
7
+ protected static singularName = 'bank';
8
+ protected static pluralName = 'banks';
9
+
10
+ @Bank.property({type: Date})
11
+ public archived?: Date | null;
12
+
13
+ @Bank.property()
14
+ public id?: number;
15
+
16
+ @Bank.property()
17
+ public default?: boolean;
18
+
19
+ @Bank.property()
20
+ public bankName?: string;
21
+
22
+ @Bank.property()
23
+ public accountNumber?: string;
24
+
25
+ @Bank.property()
26
+ public accountName?: string;
27
+
28
+ @Bank.property({type: String})
29
+ public bsb?: string | null;
30
+
31
+ @Bank.property({type: String})
32
+ public swiftCode?: string | null;
33
+
34
+ @Bank.property({type: String})
35
+ public iban?: string | null;
36
+
37
+ @Bank.property({type: String})
38
+ public bankCode?: string | null;
39
+
40
+ @Bank.property({type: 'Address'})
41
+ public bankAddress?: Address | null;
42
+
43
+ @Bank.property()
44
+ public company?: Company;
45
+ }