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
+ import { Merchi } from '../merchi';
2
+
3
+ test('can make InternalTag', () => {
4
+ const merchi = new Merchi();
5
+ const internalTag = new merchi.InternalTag();
6
+ expect(internalTag).toBeTruthy();
7
+ });
@@ -0,0 +1,51 @@
1
+ import { Company } from './company';
2
+ import { Domain } from './domain';
3
+ import { Entity } from '../entity';
4
+ import { Invoice } from './invoice';
5
+ import { Job } from './job';
6
+ import { Product } from './product';
7
+ import { Shipment } from './shipment';
8
+ import { Theme } from './theme';
9
+ import { User } from './user';
10
+
11
+ export class InternalTag extends Entity {
12
+ protected static resourceName = 'internal_tags';
13
+ protected static singularName = 'internalTag';
14
+ protected static pluralName = 'internalTags';
15
+
16
+ @InternalTag.property()
17
+ public id?: number;
18
+
19
+ @InternalTag.property()
20
+ public colour?: number;
21
+
22
+ @InternalTag.property()
23
+ public name?: string;
24
+
25
+ @InternalTag.property()
26
+ public description?: string;
27
+
28
+ @InternalTag.property({arrayType: 'Company'})
29
+ public companies?: Company[];
30
+
31
+ @InternalTag.property({arrayType: 'Domain'})
32
+ public domains?: Domain[];
33
+
34
+ @InternalTag.property({arrayType: 'Job'})
35
+ public jobs?: Job[];
36
+
37
+ @InternalTag.property({arrayType: 'Product'})
38
+ public products?: Product[];
39
+
40
+ @InternalTag.property({arrayType: 'Invoice'})
41
+ public invoices?: Invoice[];
42
+
43
+ @InternalTag.property({arrayType: 'Shipment'})
44
+ public shipments?: Shipment[];
45
+
46
+ @InternalTag.property({arrayType: 'Theme'})
47
+ public themes?: Theme[];
48
+
49
+ @InternalTag.property({arrayType: 'User'})
50
+ public users?: User[];
51
+ }
@@ -0,0 +1,28 @@
1
+ import { Merchi } from '../merchi';
2
+
3
+ test('can make Inventory', () => {
4
+ const merchi = new Merchi();
5
+ const inventory = new merchi.Inventory();
6
+ expect(inventory).toBeTruthy();
7
+ });
8
+
9
+ test('isVariationFieldOptionSelected function', () => {
10
+ const merchi = new Merchi();
11
+ const inventory = new merchi.Inventory();
12
+ const option1 = new merchi.VariationFieldsOption();
13
+ option1.id = 1;
14
+ const option2 = new merchi.VariationFieldsOption();
15
+ option2.id = 2;
16
+ expect(() => inventory.isVariationFieldOptionSelected(option1)).toThrow();
17
+
18
+ const inventoryUnitVariation = new merchi.InventoryUnitVariation();
19
+ inventory.inventoryUnitVariations = [inventoryUnitVariation];
20
+
21
+ expect(() => inventory.isVariationFieldOptionSelected(option1)).toThrow();
22
+
23
+ inventoryUnitVariation.variationFieldsOption = option2;
24
+ expect(inventory.isVariationFieldOptionSelected(option1)).toBe(false);
25
+
26
+ inventoryUnitVariation.variationFieldsOption = option1;
27
+ expect(inventory.isVariationFieldOptionSelected(option1)).toBe(true);
28
+ });
@@ -0,0 +1,56 @@
1
+ import { Address } from './address';
2
+ import { Entity } from '../entity';
3
+ import { InventoryUnitVariation } from './inventory_unit_variation';
4
+ import { Job } from './job';
5
+ import { Product } from './product';
6
+ import { VariationsGroup } from './variations_group';
7
+ import { VariationFieldsOption } from './variation_fields_option';
8
+ import { some } from 'lodash';
9
+
10
+ export class Inventory extends Entity {
11
+ protected static resourceName = 'inventories';
12
+ protected static singularName = 'inventory';
13
+ protected static pluralName = 'inventories';
14
+
15
+ @Inventory.property({type: Date})
16
+ public archived?: Date | null;
17
+
18
+ @Inventory.property()
19
+ public id?: number;
20
+
21
+ @Inventory.property()
22
+ public quantity?: number;
23
+
24
+ @Inventory.property()
25
+ public name?: string;
26
+
27
+ @Inventory.property()
28
+ public notes?: string;
29
+
30
+ @Inventory.property()
31
+ public isOrphan?: boolean;
32
+
33
+ @Inventory.property({arrayType: 'Product'})
34
+ public products?: Product[];
35
+
36
+ @Inventory.property({type: Address})
37
+ public address?: Address | null;
38
+
39
+ @Inventory.property({arrayType: 'VariationsGroup'})
40
+ public variationsGroups?: VariationsGroup[];
41
+
42
+ @Inventory.property({arrayType: 'Job'})
43
+ public jobs?: Job[];
44
+
45
+ @Inventory.property({arrayType: 'InventoryUnitVariation'})
46
+ public inventoryUnitVariations?: InventoryUnitVariation[];
47
+
48
+ public isVariationFieldOptionSelected = (option: VariationFieldsOption) => {
49
+ if (this.inventoryUnitVariations === undefined) {
50
+ throw new Error(
51
+ 'inventoryUnitVariations is undefined, did you forget to embed it?');
52
+ }
53
+ return some(this.inventoryUnitVariations.map(
54
+ (v: InventoryUnitVariation) => v.optionId() === option.id));
55
+ };
56
+ }
@@ -0,0 +1,7 @@
1
+ import { Merchi } from '../merchi';
2
+
3
+ test('can make InventoryUnitVariation', () => {
4
+ const merchi = new Merchi();
5
+ const inventoryUnitVariation = new merchi.InventoryUnitVariation();
6
+ expect(inventoryUnitVariation).toBeTruthy();
7
+ });
@@ -0,0 +1,29 @@
1
+ import { Entity } from '../entity';
2
+ import { Inventory } from './inventory';
3
+ import { VariationFieldsOption } from './variation_fields_option';
4
+
5
+ export class InventoryUnitVariation extends Entity {
6
+ protected static resourceName = 'inventory_unit_variations';
7
+ protected static singularName = 'inventoryUnitVariation';
8
+ protected static pluralName = 'inventoryUnitVariations';
9
+
10
+ @InventoryUnitVariation.property({type: Date})
11
+ public archived?: Date | null;
12
+
13
+ @InventoryUnitVariation.property()
14
+ public id?: number;
15
+
16
+ @InventoryUnitVariation.property()
17
+ public inventory?: Inventory;
18
+
19
+ @InventoryUnitVariation.property()
20
+ public variationFieldsOption?: VariationFieldsOption;
21
+
22
+ public optionId = () => {
23
+ if (this.variationFieldsOption === undefined) {
24
+ throw new Error(
25
+ 'variationFieldsOption is undefined, did you forget to embed it?');
26
+ }
27
+ return this.variationFieldsOption.id;
28
+ };
29
+ }
@@ -0,0 +1,43 @@
1
+ import { setup, mockFetch } from '../test_util';
2
+ import { Merchi } from '../merchi';
3
+
4
+ setup();
5
+
6
+ test('can make Invoice', () => {
7
+ const merchi = new Merchi();
8
+ const invoice = new merchi.Invoice();
9
+ expect(invoice).toBeTruthy();
10
+ });
11
+
12
+ test('pass cookie tokens to query string', () => {
13
+ const cookie = 'session_token=s; client_token=c; invoice_token=i';
14
+ Object.defineProperty(document, 'cookie', {
15
+ get: jest.fn().mockImplementation(() => { return cookie; }),
16
+ set: jest.fn().mockImplementation(() => {}),
17
+ });
18
+ const correct = [
19
+ ['skip_rights', 'y'],
20
+ ['session_token', 's'],
21
+ ['client_token', 'c'],
22
+ ['invoice_token', 'i'],
23
+ ];
24
+ const fetch = mockFetch(true, {'invoice': {'id': 1}}, 200);
25
+ const merchi = new Merchi();
26
+ const invocation = merchi.Invoice.get(1);
27
+ expect(fetch.mock.calls[0][1]['query']).toEqual(correct);
28
+ return invocation;
29
+ });
30
+
31
+ test('client and invoice tokens supported by merchi', () => {
32
+ const merchi = new Merchi('s', 'c', 'i');
33
+ const correct = [
34
+ ['skip_rights', 'y'],
35
+ ['session_token', 's'],
36
+ ['client_token', 'c'],
37
+ ['invoice_token', 'i'],
38
+ ];
39
+ const fetch = mockFetch(true, {'invoice': {'id': 1}}, 200);
40
+ const invocation = merchi.Invoice.get(1);
41
+ expect(fetch.mock.calls[0][1]['query']).toEqual(correct);
42
+ return invocation;
43
+ });
@@ -0,0 +1,179 @@
1
+ import { Address } from './address';
2
+ import { Cart } from './cart';
3
+ import { Company } from './company';
4
+ import { Domain } from './domain';
5
+ import { DomainTag } from './domain_tag';
6
+ import { EmailAddress } from './email_address';
7
+ import { Entity } from '../entity';
8
+ import { MerchiFile } from './file';
9
+ import { InternalTag } from './internal_tag';
10
+ import { Item } from './item';
11
+ import { Job } from './job';
12
+ import { Quote } from './quote';
13
+ import { Notification } from './notification';
14
+ import { Payment } from './payment';
15
+ import { PhoneNumber } from './phone_number';
16
+ import { Shipment } from './shipment';
17
+ import { User } from './user';
18
+
19
+ export class Invoice extends Entity {
20
+ protected static resourceName = 'invoices';
21
+ protected static singularName = 'invoice';
22
+ protected static pluralName = 'invoices';
23
+
24
+ @Invoice.property({type: Date})
25
+ public archived?: Date | null;
26
+
27
+ @Invoice.property()
28
+ public id?: number;
29
+
30
+ @Invoice.property({type: Date})
31
+ public creationDate?: Date | null;
32
+
33
+ @Invoice.property({type: Date})
34
+ public paymentDeadline?: Date | null;
35
+
36
+ @Invoice.property({type: Date})
37
+ public reminded?: Date | null;
38
+
39
+ @Invoice.property()
40
+ public reminderMessage?: string;
41
+
42
+ @Invoice.property()
43
+ public shopifyOrderId?: string;
44
+
45
+ @Invoice.property()
46
+ public forceReminders?: boolean;
47
+
48
+ @Invoice.property()
49
+ public buySide?: boolean;
50
+
51
+ @Invoice.property()
52
+ public canAutoPay?: boolean;
53
+
54
+ @Invoice.property({type: String})
55
+ public note?: string | null;
56
+
57
+ @Invoice.property({type: Date})
58
+ public terms?: Date | null;
59
+
60
+ @Invoice.property({type: Number})
61
+ public subtotalCost?: number | null;
62
+
63
+ @Invoice.property({type: Number})
64
+ public taxAmount?: number | null;
65
+
66
+ @Invoice.property({type: Number})
67
+ public totalCost?: number | null;
68
+
69
+ @Invoice.property({type: Boolean})
70
+ public sendSms?: boolean | null;
71
+
72
+ @Invoice.property({type: Boolean})
73
+ public sendEmail?: boolean | null;
74
+
75
+ @Invoice.property({type: Boolean})
76
+ public unpaid?: boolean | null;
77
+
78
+ @Invoice.property()
79
+ public currency?: string;
80
+
81
+ @Invoice.property()
82
+ public acceptSquare?: boolean;
83
+
84
+ @Invoice.property()
85
+ public acceptStripe?: boolean;
86
+
87
+ @Invoice.property()
88
+ public acceptPaypal?: boolean;
89
+
90
+ @Invoice.property()
91
+ public acceptUtrust?: boolean;
92
+
93
+ @Invoice.property()
94
+ public acceptBankTransfer?: boolean;
95
+
96
+ @Invoice.property()
97
+ public acceptPhonePayment?: boolean;
98
+
99
+ @Invoice.property({type: String})
100
+ public invoiceToken?: string | null;
101
+
102
+ @Invoice.property()
103
+ public isRemindable?: boolean;
104
+
105
+ @Invoice.property({embeddedByDefault: false})
106
+ public owedMoney?: number;
107
+
108
+ @Invoice.property({embeddedByDefault: false})
109
+ public paidMoney?: number;
110
+
111
+ @Invoice.property({embeddedByDefault: false})
112
+ public isCompletelyPaid?: boolean;
113
+
114
+ @Invoice.property({type: User})
115
+ public responsibleManager?: User | null;
116
+
117
+ @Invoice.property({type: User})
118
+ public creator?: User | null;
119
+
120
+ @Invoice.property()
121
+ public client?: User;
122
+
123
+ @Invoice.property({type: Company})
124
+ public clientCompany?: Company | null;
125
+
126
+ @Company.property({arrayType: 'Company'})
127
+ public subscriptionCompanies?: Company[];
128
+
129
+ @Invoice.property({type: Address})
130
+ public shipping?: Address | null;
131
+
132
+ @Invoice.property()
133
+ public domain?: Domain;
134
+
135
+ @Invoice.property({arrayType: 'Item'})
136
+ public items?: Item[];
137
+
138
+ @Invoice.property({type: MerchiFile})
139
+ public pdf?: MerchiFile | null;
140
+
141
+ @Invoice.property({type: MerchiFile})
142
+ public receipt?: MerchiFile | null;
143
+
144
+ @Invoice.property({type: PhoneNumber})
145
+ public clientPhone?: PhoneNumber | null;
146
+
147
+ @Invoice.property({type: EmailAddress})
148
+ public clientEmail?: EmailAddress | null;
149
+
150
+ @Invoice.property({type: PhoneNumber})
151
+ public clientCompanyPhone?: PhoneNumber | null;
152
+
153
+ @Invoice.property({type: EmailAddress})
154
+ public clientCompanyEmail?: EmailAddress | null;
155
+
156
+ @Invoice.property({arrayType: 'InternalTag'})
157
+ public internalTags?: InternalTag[];
158
+
159
+ @Invoice.property({arrayType: 'DomainTag'})
160
+ public tags?: DomainTag[];
161
+
162
+ @Invoice.property({arrayType: 'Shipment'})
163
+ public shipments?: Shipment[];
164
+
165
+ @Invoice.property({arrayType: 'Notification'})
166
+ public notifications?: Notification[];
167
+
168
+ @Invoice.property({arrayType: 'Job'})
169
+ public jobs?: Job[];
170
+
171
+ @Invoice.property({arrayType: 'Quote'})
172
+ public quotes?: Quote[];
173
+
174
+ @Invoice.property()
175
+ public cart?: Cart;
176
+
177
+ @Invoice.property({arrayType: 'Payment'})
178
+ public payments?: Payment[];
179
+ }
@@ -0,0 +1,19 @@
1
+ import { Merchi } from '../merchi';
2
+
3
+ test('can make Item', () => {
4
+ const merchi = new Merchi();
5
+ const item = new merchi.Item();
6
+ expect(item).toBeTruthy();
7
+ });
8
+
9
+ test('totalCost', () => {
10
+ const merchi = new Merchi();
11
+ const item = new merchi.Item();
12
+ expect(item.totalCost).toThrow();
13
+ item.quantity = 2.3;
14
+ expect(item.totalCost).toThrow();
15
+ item.cost = 4.9;
16
+ expect(item.totalCost()).toEqual(11.27);
17
+ item.quantity = null;
18
+ expect(item.totalCost()).toEqual(0);
19
+ });
@@ -0,0 +1,44 @@
1
+ import { CountryTax } from './country_tax';
2
+ import { Entity } from '../entity';
3
+ import { Invoice } from './invoice';
4
+
5
+ export class Item extends Entity {
6
+ protected static resourceName = 'items';
7
+ protected static singularName = 'item';
8
+ protected static pluralName = 'items';
9
+
10
+ @Item.property({type: Date})
11
+ public archived?: Date | null;
12
+
13
+ @Item.property()
14
+ public id?: number;
15
+
16
+ @Item.property({type: Number})
17
+ public quantity?: number | null;
18
+
19
+ @Item.property()
20
+ public description?: string;
21
+
22
+ @Item.property()
23
+ public cost?: number;
24
+
25
+ @Item.property({type: Number})
26
+ public taxAmount?: number | null;
27
+
28
+ @Item.property({type: CountryTax})
29
+ public taxType?: CountryTax | null;
30
+
31
+ @Item.property({type: Invoice})
32
+ public invoice?: Invoice | null;
33
+
34
+ public totalCost = () => {
35
+ if (this.quantity === undefined) {
36
+ throw 'quantity is undefined, did you forget to embed it?';
37
+ }
38
+ if (this.cost === undefined) {
39
+ throw 'cost is undefined, did you forget to embed it?';
40
+ }
41
+ const quantity = this.quantity === null ? 0 : this.quantity;
42
+ return quantity * this.cost;
43
+ };
44
+ }
@@ -0,0 +1,95 @@
1
+ import { Merchi } from '../merchi';
2
+ import { setup, mockFetch } from '../test_util';
3
+ import { InventoryStatus } from '../constants/inventory_statuses';
4
+
5
+ setup();
6
+
7
+ test('can make Job', () => {
8
+ const merchi = new Merchi();
9
+ const job = new merchi.Job();
10
+ expect(job).toBeTruthy();
11
+ });
12
+
13
+ test('Job deadline serialised to milliseconds in form data', () => {
14
+ const merchi = new Merchi();
15
+ const job = new merchi.Job();
16
+ job.deadline = new Date('Feb 28 2013 19:00:00 GMT-0500');
17
+ const correct = [['deadline', '1362096000']];
18
+ const backData = Array.from((job.toFormData() as any).entries());
19
+ expect(backData).toEqual(correct);
20
+ });
21
+
22
+ test('Job deadline serialised to milliseconds in JSON', () => {
23
+ const merchi = new Merchi();
24
+ const job = new merchi.Job();
25
+ job.deadline = new Date('Feb 28 2013 19:00:00 GMT-0500');
26
+ const jobJson = job.toJson();
27
+ expect(jobJson.deadline).toEqual(1362096000);
28
+ });
29
+
30
+ test('Job deadline serialised from milliseconds in JSON', () => {
31
+ const merchi = new Merchi();
32
+ const job = new merchi.Job().fromJson({deadline: 1362096000});
33
+ expect(job.deadline).toEqual(new Date('Feb 28 2013 19:00:00 GMT-0500'));
34
+ });
35
+
36
+ test('add two files to job', () => {
37
+ const merchi = new Merchi();
38
+ const job = new merchi.Job();
39
+ const f1 = new merchi.MerchiFile();
40
+ f1.fromFormFile(new File([''], '1'));
41
+ const f2 = new merchi.MerchiFile();
42
+ f2.fromFormFile(new File([''], '2'));
43
+ job.clientFiles = [f1, f2];
44
+ const fetch = mockFetch(true, {'job': {}}, 200);
45
+ return job.save().then(() => {
46
+ const data: any = Array.from(fetch.mock.calls[0][1]['body'].entries());
47
+ expect(data[1][1]).toEqual('0');
48
+ expect(data[2][1]).toEqual('1');
49
+ expect(data[6][1]).toEqual('1');
50
+ expect(data[10][1]).toEqual('2');
51
+ });
52
+ });
53
+
54
+ test('Get quote update job cost', () => {
55
+ const merchi = new Merchi();
56
+ const jobWithExistingProduct = new merchi.Job().fromJson(
57
+ {'quantity': 10, 'cost': 0, product: {'id': 1, 'name': 'test'}});
58
+ const jobWithNewProduct = new merchi.Job().fromJson(
59
+ {'quantity': 10, 'cost': 0, product: {'name': 'test'}});
60
+ mockFetch(true, {'quantity': 10, 'cost': 100}, 200);
61
+ jobWithExistingProduct.getQuote().then(job => {
62
+ expect(job.quantity).toEqual(10);
63
+ expect(job.cost).toEqual(100);
64
+ });
65
+ jobWithNewProduct.getQuote().then(job => {
66
+ expect(job.quantity).toEqual(10);
67
+ expect(job.cost).toEqual(100);
68
+ });
69
+ });
70
+
71
+ test('test deduct job inventory', () => {
72
+ const merchi = new Merchi();
73
+ const job = new merchi.Job();
74
+ const inventory = new merchi.Inventory();
75
+ inventory.id = 1;
76
+ job.id = 1;
77
+ const matchingInventoryOne = new merchi.MatchingInventory();
78
+ matchingInventoryOne.inventory = inventory;
79
+ matchingInventoryOne.status = InventoryStatus.CAN_DEDUCT;
80
+ matchingInventoryOne.deductionDate = null;
81
+ job.matchingInventories = [matchingInventoryOne];
82
+ const correct = [['inventories', '[1]']];
83
+ const fetch = mockFetch(true, {}, 200);
84
+ job.deduct([matchingInventoryOne]);
85
+ expect(Array.from(fetch.mock.calls[0][1]['body'].entries())).toEqual(correct);
86
+
87
+ job.bulkDeduct();
88
+ expect(Array.from(fetch.mock.calls[1][1]['body'].entries())).toEqual(correct);
89
+ });
90
+
91
+ test('test bulk deduct job without inventories will cause error', () => {
92
+ const merchi = new Merchi();
93
+ const job = new merchi.Job();
94
+ expect(job.bulkDeduct).toThrow();
95
+ });