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,50 @@
1
+ import { Merchi } from '../merchi';
2
+ import { setup, mockFetch } from '../test_util';
3
+
4
+ setup();
5
+
6
+ test('can make Cart', () => {
7
+ const merchi = new Merchi();
8
+ const cart = new merchi.Cart();
9
+ expect(cart).toBeTruthy();
10
+ });
11
+
12
+ test('cart token supported by merchi', () => {
13
+ const merchi = new Merchi(undefined, undefined, undefined, 'c');
14
+ const correct = [['skip_rights', 'y'], ['cart_token', 'c']];
15
+ const fetch = mockFetch(true, {'invoice': {'id': 1}}, 200);
16
+ const invocation = merchi.Invoice.get(1);
17
+ expect(fetch.mock.calls[0][1]['query']).toEqual(correct);
18
+ return invocation;
19
+ });
20
+
21
+ test('requiresShipment', () => {
22
+ const merchi = new Merchi();
23
+ const cart = new merchi.Cart();
24
+ expect(cart.requiresShipment).toThrow();
25
+ cart.cartItems = [];
26
+ expect(cart.requiresShipment()).toBe(false);
27
+ cart.cartItems = [new merchi.CartItem()];
28
+ cart.cartItems[0].product = new merchi.Product();
29
+ cart.cartItems[0].product.needsShipping = true;
30
+ expect(cart.requiresShipment()).toBe(true);
31
+ cart.cartItems[0].product.needsShipping = false;
32
+ expect(cart.requiresShipment()).toBe(false);
33
+ });
34
+
35
+ test('pass cookie tokens to query string', () => {
36
+ const cookie = 'cart_token=c;';
37
+ Object.defineProperty(document, 'cookie', {
38
+ get: jest.fn().mockImplementation(() => { return cookie; }),
39
+ set: jest.fn().mockImplementation(() => {}),
40
+ });
41
+ const correct = [
42
+ ['skip_rights', 'y'],
43
+ ['cart_token', 'c'],
44
+ ];
45
+ const fetch = mockFetch(true, {'cart': {'id': 1}}, 200);
46
+ const merchi = new Merchi();
47
+ const invocation = merchi.Cart.get(1);
48
+ expect(fetch.mock.calls[0][1]['query']).toEqual(correct);
49
+ return invocation;
50
+ });
@@ -0,0 +1,89 @@
1
+ import { Address } from './address';
2
+ import { CartItem } from './cart_item';
3
+ import { CartShipmentGroup } from './cart_shipment_group';
4
+ import { Company } from './company';
5
+ import { Domain } from './domain';
6
+ import { Entity } from '../entity';
7
+ import { Invoice } from './invoice';
8
+ import { User } from './user';
9
+
10
+ export class Cart extends Entity {
11
+ protected static resourceName = 'carts';
12
+ protected static singularName = 'cart';
13
+ protected static pluralName = 'carts';
14
+
15
+ @Cart.property({type: Date})
16
+ public archived?: Date | null;
17
+
18
+ @Cart.property()
19
+ public id?: number;
20
+
21
+ @Cart.property()
22
+ public creationDate?: Date;
23
+
24
+ @Cart.property({type: Date})
25
+ public ip?: string | null;
26
+
27
+ @Cart.property({type: String})
28
+ public token?: string | null;
29
+
30
+ @Cart.property({type: String})
31
+ public receiverNotes?: string | null;
32
+
33
+ @Cart.property()
34
+ public currency?: string;
35
+
36
+ @Cart.property()
37
+ public cartItemsSubtotalCost?: number;
38
+
39
+ @Cart.property()
40
+ public cartItemsTaxAmount?: number;
41
+
42
+ @Cart.property()
43
+ public cartItemsTotalCost?: number;
44
+
45
+ @Cart.property()
46
+ public shipmentTotalCost?: number;
47
+
48
+ @Cart.property()
49
+ public subtotalCost?: number;
50
+
51
+ @Cart.property()
52
+ public taxAmount?: number;
53
+
54
+ @Cart.property()
55
+ public totalCost?: number;
56
+
57
+ @Cart.property({type: 'User'})
58
+ public client?: User | null;
59
+
60
+ @Cart.property({type: Company})
61
+ public clientCompany?: Company | null;
62
+
63
+ @Cart.property()
64
+ public domain?: Domain;
65
+
66
+ @Cart.property({type: 'Invoice'})
67
+ public invoice?: Invoice | null;
68
+
69
+ @Cart.property({type: Address})
70
+ public receiverAddress?: Address | null;
71
+
72
+ @Cart.property({arrayType: 'CartItem'})
73
+ public cartItems?: CartItem[];
74
+
75
+ @Cart.property({arrayType: 'CartShipmentGroup'})
76
+ public shipmentGroups?: CartShipmentGroup[];
77
+
78
+ public requiresShipment = () => {
79
+ if (this.cartItems === undefined) {
80
+ throw 'cartItems is undefined, did you forget to embed it?';
81
+ }
82
+ for (const cartItem of this.cartItems) {
83
+ if (cartItem.requiresShipment()) {
84
+ return true;
85
+ }
86
+ }
87
+ return false;
88
+ };
89
+ }
@@ -0,0 +1,33 @@
1
+ import { Merchi } from '../merchi';
2
+ import { setup, mockFetch } from '../test_util';
3
+
4
+ setup();
5
+
6
+ test('can make CartItem', () => {
7
+ const merchi = new Merchi();
8
+ const cartItem = new merchi.CartItem();
9
+ expect(cartItem).toBeTruthy();
10
+ });
11
+
12
+ test('requiresShipment', () => {
13
+ const merchi = new Merchi();
14
+ const cartItem = new merchi.CartItem();
15
+ expect(cartItem.requiresShipment).toThrow();
16
+ cartItem.product = new merchi.Product();
17
+ expect(cartItem.requiresShipment).toThrow();
18
+ cartItem.product.needsShipping = false;
19
+ expect(cartItem.requiresShipment()).toBe(false);
20
+ cartItem.product.needsShipping = true;
21
+ expect(cartItem.requiresShipment()).toBe(true);
22
+ });
23
+
24
+ test('Get quote update job cost', () => {
25
+ const merchi = new Merchi();
26
+ const cartItem = new merchi.CartItem().fromJson(
27
+ {'quantity': 10, 'totalCost': 0});
28
+ mockFetch(true, {'quantity': 10, 'totalCost': 100}, 200);
29
+ cartItem.calculate().then(item => {
30
+ expect(item.quantity).toEqual(10);
31
+ expect(item.totalCost).toEqual(100);
32
+ });
33
+ });
@@ -0,0 +1,77 @@
1
+ import { Cart } from './cart';
2
+ import { CountryTax } from './country_tax';
3
+ import { Entity } from '../entity';
4
+ import { Product } from './product';
5
+ import { RequestOptions } from '../request';
6
+ import { Variation } from './variation';
7
+ import { VariationsGroup } from './variations_group';
8
+
9
+ export class CartItem extends Entity {
10
+ protected static resourceName = 'cart_items';
11
+ protected static singularName = 'cartItem';
12
+ protected static pluralName = 'cartItems';
13
+
14
+ @CartItem.property({type: Date})
15
+ public archived?: Date | null;
16
+
17
+ @CartItem.property()
18
+ public id?: number;
19
+
20
+ @CartItem.property()
21
+ public quantity?: number;
22
+
23
+ @CartItem.property({type: String})
24
+ public notes?: string | null;
25
+
26
+ @CartItem.property()
27
+ public creationDate?: Date;
28
+
29
+ @CartItem.property()
30
+ public currency?: string;
31
+
32
+ @CartItem.property()
33
+ public subtotalCost?: number;
34
+
35
+ @CartItem.property()
36
+ public taxAmount?: number;
37
+
38
+ @CartItem.property()
39
+ public totalCost?: number;
40
+
41
+ @CartItem.property()
42
+ public product?: Product;
43
+
44
+ @CartItem.property()
45
+ public cart?: Cart;
46
+
47
+ @CartItem.property({embeddedByDefault: false})
48
+ public taxType?: CountryTax;
49
+
50
+ @CartItem.property({arrayType: 'VariationsGroup'})
51
+ public variationsGroups?: VariationsGroup[];
52
+
53
+ @CartItem.property({arrayType: 'Variation'})
54
+ public variations?: Variation[];
55
+
56
+ public requiresShipment = () => {
57
+ if (this.product === undefined) {
58
+ throw 'product is undefined, did you forget to embed it?';
59
+ }
60
+ if (this.product.needsShipping === undefined) {
61
+ throw 'needsShipping is undefined, did you forget to embed it?';
62
+ }
63
+ return this.product.needsShipping;
64
+ };
65
+
66
+ public calculate = () => {
67
+ const resource = '/cart-item-cost-estimate/';
68
+ const data = this.toFormData({excludeOld: false});
69
+ const fetchOptions: RequestOptions = {method: 'POST', body: data};
70
+ fetchOptions.query = [];
71
+ fetchOptions.query.push(['skip_rights', 'y']);
72
+
73
+ return this.merchi.authenticatedFetch(resource, fetchOptions).
74
+ then((data: any) => { this.fromJson(data, {makeDirty: true});
75
+ return this;});
76
+ };
77
+ }
@@ -0,0 +1,21 @@
1
+ import { CartItem } from './cart_item';
2
+ import { CartShipmentQuote } from './cart_shipment_quote';
3
+ import { Entity } from '../entity';
4
+
5
+ export class CartShipmentGroup extends Entity {
6
+ protected static resourceName = 'cart_shipment_groups';
7
+ protected static singularName = 'cartShipmentGroup';
8
+ protected static pluralName = 'cartShipmentGroups';
9
+
10
+ @CartShipmentGroup.property()
11
+ public id?: number;
12
+
13
+ @CartShipmentGroup.property({arrayType: 'CartItem'})
14
+ public cartItems?: CartItem[];
15
+
16
+ @CartShipmentGroup.property({arrayType: 'CartShipmentQuote'})
17
+ public quotes?: CartShipmentQuote[];
18
+
19
+ @CartShipmentGroup.property({type: 'CartShipmentQuote'})
20
+ public selectedQuote?: CartShipmentQuote;
21
+ }
@@ -0,0 +1,33 @@
1
+ import { ShipmentMethod } from './shipment_method';
2
+ import { Entity } from '../entity';
3
+ import { ShipmentService } from '../constants/shipment_services';
4
+
5
+ export class CartShipmentQuote extends Entity {
6
+ protected static resourceName = 'cart_shipment_quotes';
7
+ protected static singularName = 'cartShipmentQuote';
8
+ protected static pluralName = 'cartShipmentQuotes';
9
+
10
+ @CartShipmentQuote.property()
11
+ public id?: number;
12
+
13
+ @CartShipmentQuote.property()
14
+ public name?: string;
15
+
16
+ @CartShipmentQuote.property()
17
+ public subtotalCost?: number;
18
+
19
+ @CartShipmentQuote.property()
20
+ public taxAmount?: number;
21
+
22
+ @CartShipmentQuote.property()
23
+ public totalCost?: number;
24
+
25
+ @CartShipmentQuote.property({type: ShipmentService})
26
+ public shipmentService?: ShipmentService | null;
27
+
28
+ @CartShipmentQuote.property()
29
+ public shipmentServiceQuote?: string;
30
+
31
+ @CartShipmentQuote.property({type: 'ShipmentMethod'})
32
+ public shipmentMethod?: ShipmentMethod;
33
+ }
@@ -0,0 +1,57 @@
1
+ import { Merchi } from '../merchi';
2
+
3
+ test('can make category', () => {
4
+ const merchi = new Merchi();
5
+ const category = new merchi.Category();
6
+ expect(category).toBeTruthy();
7
+ });
8
+
9
+ test('can get and set id', () => {
10
+ const merchi = new Merchi();
11
+ const category = new merchi.Category();
12
+ category.id = 2;
13
+ expect(category.id).toBe(2);
14
+ });
15
+
16
+ test('can get and set name', () => {
17
+ const merchi = new Merchi();
18
+ const category = new merchi.Category();
19
+ category.name = 'example';
20
+ expect(category.name).toBe('example');
21
+ });
22
+
23
+ test('can get and set product', () => {
24
+ const merchi = new Merchi();
25
+ const c1 = new merchi.Category();
26
+ const c2 = new merchi.Category();
27
+ const p1 = new merchi.Product();
28
+ const p2 = new merchi.Product();
29
+ const cs = [c1, c2];
30
+ const ps = [p1, p2];
31
+ c1.products = ps;
32
+ expect(c1.products).toBe(ps);
33
+ expect(c2.products).toBe(undefined);
34
+ expect(p1.categories).toBe(undefined);
35
+ p1.categories = cs;
36
+ expect(p1.categories).toBe(cs);
37
+ p1.categories = undefined;
38
+ expect(p1.categories).toBe(undefined);
39
+ });
40
+
41
+ test('independence of entities', () => {
42
+ const merchi = new Merchi();
43
+ const c1 = new merchi.Category();
44
+ const c2 = new merchi.Category();
45
+ const p = new merchi.Product();
46
+ const name = 'vMjssEhwpHtMT';
47
+ const products = [p];
48
+ c1.name = name;
49
+ c1.products = products;
50
+ expect(c1.name).toBe(name);
51
+ expect(c1.products).toBe(products);
52
+ expect(c1.isDirty).toBe(true);
53
+ // c2 is a different object, and therefore totally unnaffected
54
+ expect(c2.name).toBe(undefined);
55
+ expect(c2.products).toBe(undefined);
56
+ expect(c2.isDirty).toBe(false);
57
+ });
@@ -0,0 +1,37 @@
1
+ import { Domain } from './domain';
2
+ import { Entity } from '../entity';
3
+ import { Product } from './product';
4
+ import { User } from './user';
5
+
6
+ export class Category extends Entity {
7
+ protected static resourceName = 'categories';
8
+ protected static singularName = 'category';
9
+ protected static pluralName = 'categories';
10
+
11
+ @Category.property({type: Date})
12
+ public archived?: Date | null;
13
+
14
+ @Category.property()
15
+ public id?: number;
16
+
17
+ @Category.property()
18
+ public name?: string;
19
+
20
+ @Category.property()
21
+ public showDashboard?: boolean;
22
+
23
+ @Category.property()
24
+ public showPublic?: boolean;
25
+
26
+ @Category.property()
27
+ public showPublicSupplierResell?: boolean;
28
+
29
+ @Category.property()
30
+ public domain?: Domain;
31
+
32
+ @Category.property({arrayType: 'Product'})
33
+ public products?: Product[];
34
+
35
+ @Category.property({arrayType: 'User'})
36
+ public users?: User[];
37
+ }
@@ -0,0 +1,7 @@
1
+ import { Merchi } from '../merchi';
2
+
3
+ test('can make Company', () => {
4
+ const merchi = new Merchi();
5
+ const company = new merchi.Company();
6
+ expect(company).toBeTruthy();
7
+ });
@@ -0,0 +1,275 @@
1
+ import { Address } from './address';
2
+ import { AutomaticPaymentRelationship } from './automatic_payment_relationship';
3
+ import { Bank } from './bank';
4
+ import { Cart } from './cart';
5
+ import { CompanyInvitation } from './company_invitation';
6
+ import { CountryTax } from './country_tax';
7
+ import { Domain } from './domain';
8
+ import { EmailAddress } from './email_address';
9
+ import { Entity } from '../entity';
10
+ import { MerchiFile } from './file';
11
+ import { InternalTag } from './internal_tag';
12
+ import { Invoice } from './invoice';
13
+ import { Job } from './job';
14
+ import { PhoneNumber } from './phone_number';
15
+ import { Product } from './product';
16
+ import { Shipment } from './shipment';
17
+ import { User } from './user';
18
+ import { UserCompany } from './user_company';
19
+ import { SubscriptionPlan } from './subscription_plan';
20
+ import { PaymentDevice } from './payment_device';
21
+
22
+ export class Company extends Entity {
23
+ protected static resourceName = 'companies';
24
+ protected static singularName = 'company';
25
+ protected static pluralName = 'companies';
26
+
27
+ @Company.property({type: Date})
28
+ public archived?: Date | null;
29
+
30
+ @Company.property()
31
+ public id?: number;
32
+
33
+ @Company.property()
34
+ public name?: string;
35
+
36
+ @Company.property()
37
+ public callToActions?: string;
38
+
39
+ @Company.property()
40
+ public callToActionDetails?: any[];
41
+
42
+ @Company.property({type: String})
43
+ public website?: string | null;
44
+
45
+ @Company.property()
46
+ public ownershipUnconfirmed?: boolean;
47
+
48
+ @Company.property({type: String})
49
+ public taxNumber?: string | null;
50
+
51
+ @Company.property({type: String})
52
+ public taxNumberType?: string | null;
53
+
54
+ @Company.property({type: String})
55
+ public paypalAccount?: string | null;
56
+
57
+ @Company.property({type: String})
58
+ public paypalPassword?: string | null;
59
+
60
+ @Company.property({type: String})
61
+ public paypalSignature?: string | null;
62
+
63
+ @Company.property()
64
+ public isPaypalValid?: boolean;
65
+
66
+ @Company.property({embeddedByDefault: false})
67
+ public isStripeAccountEnabled?: boolean;
68
+
69
+ @Company.property()
70
+ public stripeAccountId?: string;
71
+
72
+ @Company.property({type: String})
73
+ public stripeCustomerId?: string;
74
+
75
+ @Company.property()
76
+ public sendleActive?: boolean;
77
+
78
+ @Company.property({type: String})
79
+ public sendleApiKey?: string;
80
+
81
+ @Company.property({type: String})
82
+ public sendleId?: string;
83
+
84
+ @Company.property({type: String})
85
+ public unltdAiApiOrganizationId?: string;
86
+
87
+ @Company.property({type: String})
88
+ public unltdAiApiSecretKey?: string;
89
+
90
+ @Company.property({type: String})
91
+ public internalUseNotes?: string;
92
+
93
+ @Company.property({type: String})
94
+ public internalUseAiContext?: string;
95
+
96
+ @Company.property({type: String})
97
+ public aiContext?: string;
98
+
99
+ @Company.property()
100
+ public isNew?: boolean;
101
+
102
+ @Company.property()
103
+ public subscriptionOutstanding?: boolean;
104
+
105
+ @Company.property({type: Date})
106
+ public trialEndDate?: Date | null;
107
+
108
+ @Company.property({type: Date})
109
+ public trialEndDateUpdated?: Date | null;
110
+
111
+ @Company.property({type: 'User'})
112
+ public trialEndDateSetBy?: User;
113
+
114
+ @Company.property()
115
+ public isBlocked?: boolean;
116
+
117
+ @Company.property()
118
+ public isTesting?: boolean;
119
+
120
+ @Company.property({type: String})
121
+ public squareAccessToken?: string | null;
122
+
123
+ @Company.property({type: String})
124
+ public squareRefreshToken?: string | null;
125
+
126
+ @Company.property({type: Date})
127
+ public squareExpiresAt?: Date | null;
128
+
129
+ @Company.property()
130
+ public squareIsValid?: boolean;
131
+
132
+ @Company.property({type: String})
133
+ public squareMerchantId?: string | null;
134
+
135
+ @Company.property({type: String})
136
+ public squareWebLocationId?: string | null;
137
+
138
+ @Company.property({type: String})
139
+ public stripePublishableTestKey?: string | null;
140
+
141
+ @Company.property({type: String})
142
+ public stripeApiTestKey?: string | null;
143
+
144
+ @Company.property({type: String})
145
+ public stripePublishableKey?: string | null;
146
+
147
+ @Company.property({type: String})
148
+ public stripeApiKey?: string | null;
149
+
150
+ @Company.property()
151
+ public stripeConnectDisabled?: boolean;
152
+
153
+ @Company.property()
154
+ public isPayingCompany?: boolean;
155
+
156
+ @Company.property()
157
+ public isStripeValid?: boolean;
158
+
159
+ @Company.property()
160
+ public acceptSquare?: boolean;
161
+
162
+ @Company.property()
163
+ public acceptStripe?: boolean;
164
+
165
+ @Company.property()
166
+ public acceptPaypal?: boolean;
167
+
168
+ @Company.property()
169
+ public acceptUtrust?: boolean;
170
+
171
+ @Company.property({type: String})
172
+ public utrustApiKey?: string | null;
173
+
174
+ @Company.property({type: String})
175
+ public utrustWebhookKey?: string | null;
176
+
177
+ @Company.property()
178
+ public isUtrustValid?: boolean;
179
+
180
+ @Company.property()
181
+ public acceptBankTransfer?: boolean;
182
+
183
+ @Company.property()
184
+ public acceptPhonePayment?: boolean;
185
+
186
+ @Company.property()
187
+ public defaultCurrency?: string;
188
+
189
+ @Company.property()
190
+ public country?: string;
191
+
192
+ @Company.property({arrayType: 'InternalTag'})
193
+ public internalTags?: InternalTag[];
194
+
195
+ @Company.property({type: MerchiFile})
196
+ public logo?: MerchiFile | null;
197
+
198
+ @Company.property({type: 'CountryTax'})
199
+ public defaultTaxType?: CountryTax | null;
200
+
201
+ @Company.property({arrayType: 'AutomaticPaymentRelationship'})
202
+ public automaticPaymentRelationships?: AutomaticPaymentRelationship[];
203
+
204
+ @Company.property({arrayType: 'CountryTax'})
205
+ public taxTypes?: CountryTax[];
206
+
207
+ @Company.property({arrayType: 'PaymentDevice'})
208
+ public paymentDevices?: PaymentDevice[];
209
+
210
+ @Company.property({type: SubscriptionPlan})
211
+ public subscriptionPlan?: SubscriptionPlan | null;
212
+
213
+ @Company.property({arrayType: 'EmailAddress'})
214
+ public _emailAddresses?: EmailAddress[];
215
+
216
+ @Company.property({arrayType: 'PhoneNumber'})
217
+ public _paymentPhoneNumbers?: PhoneNumber[];
218
+
219
+ @Company.property({arrayType: 'PhoneNumber'})
220
+ public _phoneNumbers?: PhoneNumber[];
221
+
222
+ @Company.property({arrayType: 'Address'})
223
+ public _addresses?: Address[];
224
+
225
+ @Company.property({arrayType: 'UserCompany'})
226
+ public _users?: UserCompany[];
227
+
228
+ @Company.property({arrayType: 'Shipment'})
229
+ public shipmentsAsSender?: Shipment[];
230
+
231
+ @Company.property({arrayType: 'Shipment'})
232
+ public shipmentsAsReceiver?: Shipment[];
233
+
234
+ @Company.property({arrayType: 'Product'})
235
+ public savedProducts?: Product[];
236
+
237
+ @Company.property({arrayType: 'Bank'})
238
+ public banks?: Bank[];
239
+
240
+ @Company.property({arrayType: 'UserCompany'})
241
+ public userCompanies?: UserCompany[];
242
+
243
+ @Company.property({arrayType: 'CompanyInvitation'})
244
+ public companyInvitations?: CompanyInvitation[];
245
+
246
+ @Company.property({arrayType: 'Job'})
247
+ public appliedJobs?: Job[];
248
+
249
+ @Company.property({arrayType: 'Cart'})
250
+ public carts?: Cart[];
251
+
252
+ @Company.property({arrayType: 'Domain'})
253
+ public domains?: Domain[];
254
+
255
+ @Company.property({arrayType: 'Domain'})
256
+ public accessibleDomainsAsClientCompany?: Domain[];
257
+
258
+ @Company.property({arrayType: 'EmailAddress'})
259
+ public emailAddresses?: EmailAddress[];
260
+
261
+ @Company.property({arrayType: 'PhoneNumber'})
262
+ public phoneNumbers?: PhoneNumber[];
263
+
264
+ @Company.property({arrayType: 'PhoneNumber'})
265
+ public paymentPhoneNumbers?: PhoneNumber[];
266
+
267
+ @Company.property({arrayType: 'Invoice'})
268
+ public invoicesHas?: Invoice[];
269
+
270
+ @Company.property({arrayType: 'Invoice'})
271
+ public subscriptionInvoices?: Invoice[];
272
+
273
+ @Company.property({arrayType: 'Address'})
274
+ public addresses?: Address[];
275
+ }
@@ -0,0 +1,7 @@
1
+ import { Merchi } from '../merchi';
2
+
3
+ test('can make CompanyInvitation', () => {
4
+ const merchi = new Merchi();
5
+ const companyInvitation = new merchi.CompanyInvitation();
6
+ expect(companyInvitation).toBeTruthy();
7
+ });