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,140 @@
1
+ import { Assignment } from './assignment';
2
+ import { QuoteItem } from './quote_item';
3
+ import { Shipment } from './shipment';
4
+ import { Invoice } from './invoice';
5
+ import { Entity } from '../entity';
6
+ import { kahanSum } from '../util/float';
7
+
8
+ interface CalculateOptions {
9
+ strictEmbed?: boolean;
10
+ }
11
+
12
+ export class Quote extends Entity {
13
+ protected static resourceName = 'quotes';
14
+ protected static singularName = 'quote';
15
+ protected static pluralName = 'quotes';
16
+
17
+ @Quote.property({type: Date})
18
+ public archived?: Date | null;
19
+
20
+ @Quote.property()
21
+ public currency?: string;
22
+
23
+ @Quote.property()
24
+ public id?: number;
25
+
26
+ @Quote.property({type: Date})
27
+ public agreedDeadline?: Date | null;
28
+
29
+ @Quote.property({arrayType: 'Shipment'})
30
+ public shipments?: Shipment[];
31
+
32
+ @Quote.property({arrayType: 'QuoteItem'})
33
+ public quoteItems?: QuoteItem[];
34
+
35
+ @Quote.property({arrayType: 'Assignment'})
36
+ public assignments?: Assignment[];
37
+
38
+ @Quote.property({type: Invoice})
39
+ public invoice?: Invoice | null;
40
+
41
+ public quoteTotal = (options?: CalculateOptions) => {
42
+ const { strictEmbed = true } = options ? options : {};
43
+ const { quoteItems = [], shipments = [] } = this;
44
+ if (strictEmbed && this.quoteItems === undefined) {
45
+ throw new Error('quoteItems is undefined, did you forget to embed it?');
46
+ }
47
+ if (strictEmbed && this.shipments === undefined) {
48
+ throw new Error('shipments is undefined, did you forget to embed it?');
49
+ }
50
+ const quoteItemsTotal = kahanSum(quoteItems.map((qI: QuoteItem) =>
51
+ parseFloat(qI.calculateTotal(options)))).toFixed(3);
52
+ const shipmentItemsTotal = kahanSum(shipments.map((s: Shipment) =>
53
+ parseFloat(s.calculateTotal(options)))).toFixed(3);
54
+ return (
55
+ parseFloat(quoteItemsTotal) + parseFloat(shipmentItemsTotal)
56
+ ).toFixed(3);
57
+ };
58
+
59
+ public calculateTotal = this.quoteTotal;
60
+
61
+ public calculateSubTotal = (options?: CalculateOptions) => {
62
+ const { strictEmbed = true } = options ? options : {};
63
+ const { quoteItems = [], shipments = [] } = this;
64
+ if (strictEmbed && this.quoteItems === undefined) {
65
+ throw new Error('quoteItems is undefined, did you forget to embed it?');
66
+ }
67
+ if (strictEmbed && this.shipments === undefined) {
68
+ throw new Error('shipments is undefined, did you forget to embed it?');
69
+ }
70
+ const quoteItemsTotal = kahanSum(quoteItems.map((qI: QuoteItem) =>
71
+ parseFloat(qI.calculateSubTotal(options))));
72
+ const shipmentItemsTotal = kahanSum(shipments.map((s: Shipment) =>
73
+ parseFloat(s.calculateSubTotal(options))));
74
+ return (quoteItemsTotal + shipmentItemsTotal).toFixed(3);
75
+ };
76
+
77
+ public calculateTaxAmount = (options?: CalculateOptions) => {
78
+ const { strictEmbed = true } = options ? options : {};
79
+ const { quoteItems = [], shipments = [] } = this;
80
+ if (strictEmbed && this.quoteItems === undefined) {
81
+ throw new Error('quoteItems is undefined, did you forget to embed it?');
82
+ }
83
+ if (strictEmbed && this.shipments === undefined) {
84
+ throw new Error('shipments is undefined, did you forget to embed it?');
85
+ }
86
+ const quoteItemsTotal = kahanSum(quoteItems.map((qI: QuoteItem) =>
87
+ parseFloat(qI.calculateTaxAmount(options))));
88
+ const shipmentItemsTotal = kahanSum(shipments.map((s: Shipment) =>
89
+ parseFloat(s.calculateTaxAmount(options))));
90
+ return (quoteItemsTotal + shipmentItemsTotal).toFixed(3);
91
+ };
92
+
93
+ public findQuoteItemIndex = (quoteItemId: number) => {
94
+ if (this.quoteItems === undefined) {
95
+ throw new Error('quoteItems is undefined, did you forget to embed it?');
96
+ }
97
+ function checkEqualId(quoteItem: QuoteItem) {
98
+ return quoteItem.id === quoteItemId;
99
+ }
100
+ return this.quoteItems.findIndex(checkEqualId);
101
+ };
102
+
103
+ public removeQuoteItem = (quoteItem: QuoteItem) => {
104
+ if (this.quoteItems === undefined) {
105
+ throw new Error('quoteItems is undefined, did you forget to embed it?');
106
+ }
107
+ if (quoteItem.id === undefined) {
108
+ throw new Error('quoteItem.id is undefined, did you forget to embed it?');
109
+ }
110
+ const index = this.findQuoteItemIndex(quoteItem.id);
111
+ if (index > -1) {
112
+ this.quoteItems.splice(index, 1);
113
+ }
114
+ };
115
+
116
+ public deadlineTimeDifference = () => {
117
+ if (this.agreedDeadline === undefined) {
118
+ const err = 'agreedDeadline is undefined, did you forget to embed it?';
119
+ throw new Error(err);
120
+ }
121
+ if (this.assignments === undefined) {
122
+ const err = 'assignments is undefiend, did you forget to embed it?';
123
+ throw new Error(err);
124
+ }
125
+ if (this.assignments.length < 1) {
126
+ return null;
127
+ }
128
+ if (this.agreedDeadline === null) {
129
+ return null;
130
+ }
131
+ const assignment = this.assignments[0];
132
+ if (assignment.productionDeadline === undefined) {
133
+ const err = 'productionDeadline is undefined, did you forget to embed' +
134
+ 'it?';
135
+ throw new Error(err);
136
+ }
137
+ const productionDeadline = assignment.productionDeadline;
138
+ return productionDeadline.valueOf() - this.agreedDeadline.valueOf();
139
+ };
140
+ }
@@ -0,0 +1,50 @@
1
+ import { Merchi } from '../merchi';
2
+
3
+ test('can make QuoteItem', () => {
4
+ const merchi = new Merchi();
5
+ const quoteItem = new merchi.QuoteItem();
6
+ expect(quoteItem).toBeTruthy();
7
+ });
8
+
9
+ test('total calculation', () => {
10
+ const merchi = new Merchi();
11
+ const quoteItem = new merchi.QuoteItem();
12
+
13
+ const gst = new merchi.CountryTax();
14
+ gst.taxName = 'GST';
15
+ gst.taxPercent = 10;
16
+ const noTax = merchi.CountryTax.getNoTax();
17
+
18
+ quoteItem.unitPrice = 10;
19
+ quoteItem.quantity = 1;
20
+
21
+ // tax type not provided yet should be a embed issue
22
+ expect(quoteItem.calculateTotal()).toEqual('10.000');
23
+ expect(quoteItem.calculateTotal({strictEmbed: false})).toEqual('10.000');
24
+
25
+ // quote total include tax type properly
26
+ quoteItem.taxType = gst;
27
+ expect(quoteItem.calculateTotal()).toEqual('11.000');
28
+ quoteItem.taxType = noTax;
29
+ expect(quoteItem.calculateTotal()).toEqual('10.000');
30
+
31
+ // null and undefined price and quantity will throw error unless not strictly
32
+ // require embed
33
+ quoteItem.unitPrice = null;
34
+ expect(quoteItem.calculateTotal({strictEmbed: false})).toEqual('0.000');
35
+
36
+ quoteItem.unitPrice = 1;
37
+ quoteItem.quantity = undefined;
38
+ expect(() => quoteItem.calculateTotal()).toThrow();
39
+ expect(quoteItem.calculateTotal({strictEmbed: false})).toEqual('0.000');
40
+
41
+ quoteItem.unitPrice = undefined;
42
+ quoteItem.quantity = 1;
43
+ expect(() => quoteItem.calculateTotal()).toThrow();
44
+ expect(quoteItem.calculateTotal({strictEmbed: false})).toEqual('0.000');
45
+
46
+ // make sure float number recorded correctly
47
+ quoteItem.quantity = 3.55;
48
+ quoteItem.unitPrice = 87.12;
49
+ expect(quoteItem.calculateTotal()).toEqual('309.276');
50
+ });
@@ -0,0 +1,71 @@
1
+ import { CountryTax } from './country_tax';
2
+ import { Entity } from '../entity';
3
+ import { Quote } from './quote';
4
+
5
+ interface CalculateOptions {
6
+ strictEmbed?: boolean;
7
+ }
8
+
9
+ export class QuoteItem extends Entity {
10
+ protected static resourceName = 'quote_items';
11
+ protected static singularName = 'quoteItem';
12
+ protected static pluralName = 'quoteItems';
13
+
14
+ @QuoteItem.property({type: Date})
15
+ public archived?: Date | null;
16
+
17
+ @QuoteItem.property()
18
+ public id?: number;
19
+
20
+ @QuoteItem.property()
21
+ public type?: number;
22
+
23
+ @QuoteItem.property()
24
+ public quantity?: number;
25
+
26
+ @QuoteItem.property({type: String})
27
+ public description?: string | null;
28
+
29
+ @QuoteItem.property({type: Number})
30
+ public unitPrice?: number | null;
31
+
32
+ @QuoteItem.property({type: Number})
33
+ public taxAmount?: number | null;
34
+
35
+ @QuoteItem.property({type: CountryTax})
36
+ public taxType?: CountryTax;
37
+
38
+ @QuoteItem.property()
39
+ public quote?: Quote;
40
+
41
+ public calculateSubTotal = (options?: CalculateOptions) => {
42
+ const { strictEmbed = true } = options ? options : {};
43
+ if (strictEmbed){
44
+ if (this.unitPrice === undefined) {
45
+ throw new Error('unitPrice is undefined, did you forget to embed it?');
46
+ }
47
+ if (this.quantity === undefined) {
48
+ throw new Error('quantity is undefined, did you forget to embed it?');
49
+ }
50
+ }
51
+ const quant = this.quantity ? this.quantity : 0;
52
+ const unitPrice = this.unitPrice ? this.unitPrice : 0;
53
+ return (quant * unitPrice).toFixed(3);
54
+ };
55
+
56
+ public calculateTaxAmount = (options?: CalculateOptions) => {
57
+ const taxPercent = this.taxType && this.taxType.taxPercent ?
58
+ this.taxType.taxPercent : 0;
59
+ const taxRate = taxPercent ? Number(taxPercent) / 100 : 0;
60
+ return (parseFloat(
61
+ this.calculateSubTotal(options)) * taxRate).toFixed(3);
62
+ };
63
+
64
+ public calculateTotal = (options?: CalculateOptions) => {
65
+ return (
66
+ parseFloat(this.calculateSubTotal(options)) +
67
+ parseFloat(this.calculateTaxAmount(options))
68
+ ).toFixed(3);
69
+ };
70
+
71
+ }
@@ -0,0 +1,7 @@
1
+ import { Merchi } from '../merchi';
2
+
3
+ test('can make SeoDomainPage', () => {
4
+ const merchi = new Merchi();
5
+ const seoDomainPage = new merchi.SeoDomainPage();
6
+ expect(seoDomainPage).toBeTruthy();
7
+ });
@@ -0,0 +1,33 @@
1
+ import { Domain } from './domain';
2
+ import { Product } from './product';
3
+ import { Entity } from '../entity';
4
+
5
+ export class SeoDomainPage extends Entity {
6
+ protected static resourceName = 'seo_domain_pages';
7
+ protected static singularName = 'seoDomainPage';
8
+ protected static pluralName = 'seoDomainPages';
9
+
10
+ @SeoDomainPage.property({type: Date})
11
+ public archived?: Date | null;
12
+
13
+ @SeoDomainPage.property()
14
+ public id?: number;
15
+
16
+ @SeoDomainPage.property()
17
+ public domain?: Domain;
18
+
19
+ @SeoDomainPage.property()
20
+ public product?: Product;
21
+
22
+ @SeoDomainPage.property()
23
+ public metaDescription?: string;
24
+
25
+ @SeoDomainPage.property()
26
+ public metaRobots?: string;
27
+
28
+ @SeoDomainPage.property()
29
+ public metaTitle?: string;
30
+
31
+ @SeoDomainPage.property()
32
+ public pageKey?: string;
33
+ }
@@ -0,0 +1,7 @@
1
+ import { Merchi } from '../merchi';
2
+
3
+ test('can make Session', () => {
4
+ const merchi = new Merchi();
5
+ const session = new merchi.Session();
6
+ expect(session).toBeTruthy();
7
+ });
@@ -0,0 +1,28 @@
1
+ import { Domain } from './domain';
2
+ import { Entity } from '../entity';
3
+ import { User } from './user';
4
+
5
+ export class Session extends Entity {
6
+ protected static resourceName = 'sessions';
7
+ protected static singularName = 'session';
8
+ protected static pluralName = 'sessions';
9
+ protected static primaryKey = 'token';
10
+
11
+ @Session.property({type: Date})
12
+ public archived?: Date | null;
13
+
14
+ @Session.property({type: String})
15
+ public ip?: string | null;
16
+
17
+ @Session.property()
18
+ public token?: string;
19
+
20
+ @Session.property({type: Boolean})
21
+ public remember?: boolean | null;
22
+
23
+ @Session.property()
24
+ public user?: User;
25
+
26
+ @Session.property({type: Domain})
27
+ public domain?: Domain | null;
28
+ }
@@ -0,0 +1,24 @@
1
+ import { Merchi } from '../merchi';
2
+
3
+ test('can make Shipment', () => {
4
+ const merchi = new Merchi();
5
+ const shipment = new merchi.Shipment();
6
+ expect(shipment).toBeTruthy();
7
+ });
8
+
9
+ test('can calculation undefined handling', () => {
10
+ const merchi = new Merchi();
11
+ const shipment = new merchi.Shipment();
12
+ expect(() => shipment.calculateSubTotal()).toThrow();
13
+ expect(shipment.calculateSubTotal({strictEmbed: false})).toEqual('0.000');
14
+
15
+ expect(() => shipment.calculateTaxAmount()).toThrow();
16
+ expect(shipment.calculateTaxAmount({strictEmbed: false})).toEqual('0.000');
17
+ });
18
+
19
+ test('can calculation tax with tax type undefined', () => {
20
+ const merchi = new Merchi();
21
+ const shipment = new merchi.Shipment();
22
+ shipment.cost = 0;
23
+ expect(shipment.calculateTaxAmount()).toEqual('0.000');
24
+ });
@@ -0,0 +1,185 @@
1
+ import { Address } from './address';
2
+ import { Assignment } from './assignment';
3
+ import { Company } from './company';
4
+ import { CountryTax } from './country_tax';
5
+ import { DomainTag } from './domain_tag';
6
+ import { Entity } from '../entity';
7
+ import { InternalTag } from './internal_tag';
8
+ import { Invoice } from './invoice';
9
+ import { Quote } from './quote';
10
+ import { Job } from './job';
11
+ import { MerchiFile } from './file';
12
+ import { User } from './user';
13
+ import { ShipmentItem } from './shipment_item';
14
+ import { ShipmentMethod } from './shipment_method';
15
+
16
+ interface CalculateOptions {
17
+ strictEmbed?: boolean;
18
+ }
19
+
20
+ export class Shipment extends Entity {
21
+ protected static resourceName = 'shipments';
22
+ protected static singularName = 'shipment';
23
+ protected static pluralName = 'shipments';
24
+
25
+ @Shipment.property({type: Date})
26
+ public archived?: Date | null;
27
+
28
+ @Shipment.property()
29
+ public id?: number;
30
+
31
+ @Shipment.property()
32
+ public name?: string;
33
+
34
+ @Shipment.property()
35
+ public shipmentServiceBookingInfo?: string;
36
+
37
+ @Shipment.property()
38
+ public shipmentServiceQuote?: string;
39
+
40
+ @Shipment.property()
41
+ public pickUp?: boolean;
42
+
43
+ @Shipment.property({arrayType: 'InternalTag'})
44
+ public internalTags?: InternalTag[];
45
+
46
+ @Shipment.property({type: MerchiFile})
47
+ public shipmentLabel?: MerchiFile | null;
48
+
49
+ @Shipment.property({type: Date})
50
+ public creationDate?: Date | null;
51
+
52
+ @Shipment.property({type: Date})
53
+ public dispatchedDate?: Date | null;
54
+
55
+ @Shipment.property({type: Date})
56
+ public dispatchDate?: Date | null;
57
+
58
+ @Shipment.property({type: Date})
59
+ public expectedReceiveDate?: Date | null;
60
+
61
+ @Shipment.property({type: Date})
62
+ public receivedDate?: Date | null;
63
+
64
+ @Shipment.property()
65
+ public senderResponsible?: boolean;
66
+
67
+ @Shipment.property({type: String})
68
+ public senderNotes?: string | null;
69
+
70
+ @Shipment.property({type: String})
71
+ public receiverNotes?: string | null;
72
+
73
+ @Shipment.property({type: Number})
74
+ public transportCompany?: number | null;
75
+
76
+ @Shipment.property({type: String})
77
+ public transportCompanyName?: string | null;
78
+
79
+ @Shipment.property({type: String})
80
+ public trackingNumber?: string | null;
81
+
82
+ @Shipment.property({type: Number})
83
+ public buyCost?: number | null;
84
+
85
+ @Shipment.property({type: String})
86
+ public buyCurrency?: string | null;
87
+
88
+ @Shipment.property({type: Number})
89
+ public cost?: number | null;
90
+
91
+ @Shipment.property({type: Number})
92
+ public taxAmount?: number | null;
93
+
94
+ @Shipment.property({type: Number})
95
+ public maxWeight?: number | null;
96
+
97
+ @Shipment.property({type: Number})
98
+ public maxVolume?: number | null;
99
+
100
+ @Shipment.property()
101
+ public sendSms?: boolean;
102
+
103
+ @Shipment.property()
104
+ public sendEmail?: boolean;
105
+
106
+ @Shipment.property({type: CountryTax})
107
+ public taxType?: CountryTax | null;
108
+
109
+ @Shipment.property()
110
+ public isOnBehalfOf?: boolean;
111
+
112
+ @Shipment.property({type: User})
113
+ public onBehalfOf?: User | null;
114
+
115
+ @Shipment.property({type: Company})
116
+ public onBehalfOfCompany?: Company | null;
117
+
118
+ @Shipment.property({type: User})
119
+ public sender?: User | null;
120
+
121
+ @Shipment.property({type: Company})
122
+ public senderCompany?: Company | null;
123
+
124
+ @Shipment.property({type: Address})
125
+ public senderAddress?: Address | null;
126
+
127
+ @Shipment.property({type: String})
128
+ public blindShipTo?: string | null;
129
+
130
+ @Shipment.property({type: User})
131
+ public receiver?: User | null;
132
+
133
+ @Shipment.property({type: Company})
134
+ public receiverCompany?: Company | null;
135
+
136
+ @Shipment.property({type: Address})
137
+ public receiverAddress?: Address | null;
138
+
139
+ @Shipment.property({arrayType: 'Invoice'})
140
+ public invoices?: Invoice[];
141
+
142
+ @Shipment.property({type: Quote})
143
+ public quote?: Quote | null;
144
+
145
+ @Shipment.property({type: ShipmentMethod})
146
+ public shipmentMethod?: ShipmentMethod | null;
147
+
148
+ @Shipment.property({arrayType: 'DomainTag'})
149
+ public tags?: DomainTag[];
150
+
151
+ @Shipment.property({arrayType: 'Assignment'})
152
+ public assignments?: Assignment[];
153
+
154
+ @Shipment.property({arrayType: 'ShipmentItem'})
155
+ public items?: ShipmentItem[];
156
+
157
+ @Shipment.property({arrayType: 'Job'})
158
+ public jobs?: Job[];
159
+
160
+ public calculateSubTotal = (options?: CalculateOptions) => {
161
+ const { strictEmbed = true } = options ? options : {};
162
+ if (strictEmbed){
163
+ if (this.cost === undefined) {
164
+ throw new Error('cost is undefined, did you forget to embed it?');
165
+ }
166
+ }
167
+ const cost = this.cost ? this.cost : 0;
168
+ return parseFloat(String(cost)).toFixed(3);
169
+ };
170
+
171
+ public calculateTaxAmount = (options?: CalculateOptions) => {
172
+ const taxPercent = this.taxType && this.taxType.taxPercent ?
173
+ this.taxType.taxPercent : 0;
174
+ const taxRate = taxPercent ? Number(taxPercent) / 100 : 0;
175
+ return (parseFloat(
176
+ this.calculateSubTotal(options)) * taxRate).toFixed(3);
177
+ };
178
+
179
+ public calculateTotal = (options?: CalculateOptions) => {
180
+ return (
181
+ parseFloat(this.calculateSubTotal(options)) +
182
+ parseFloat(this.calculateTaxAmount(options))
183
+ ).toFixed(3);
184
+ };
185
+ }
@@ -0,0 +1,7 @@
1
+ import { Merchi } from '../merchi';
2
+
3
+ test('can make ShipmentItem', () => {
4
+ const merchi = new Merchi();
5
+ const shipmentItem = new merchi.ShipmentItem();
6
+ expect(shipmentItem).toBeTruthy();
7
+ });
@@ -0,0 +1,15 @@
1
+ import { Entity } from '../entity';
2
+ import { Job } from './job';
3
+ import { ShipmentItemFulfillment } from './shipment_item_fulfillment';
4
+
5
+ export class ShipmentItem extends Entity {
6
+ protected static resourceName = 'shipment_items';
7
+ protected static singularName = 'shipmentItem';
8
+ protected static pluralName = 'shipmentItems';
9
+
10
+ @ShipmentItem.property({type: Job})
11
+ public job?: Job;
12
+
13
+ @ShipmentItem.property({arrayType: 'ShipmentItemFulfillment'})
14
+ public fulfillments?: ShipmentItemFulfillment[];
15
+ }
@@ -0,0 +1,8 @@
1
+ import { Merchi } from '../merchi';
2
+
3
+ test('can make ShipmentItemFulfillment', () => {
4
+ const merchi = new Merchi();
5
+ const shipmentItemFulfillment =
6
+ new merchi.ShipmentItemFulfillment();
7
+ expect(shipmentItemFulfillment).toBeTruthy();
8
+ });
@@ -0,0 +1,15 @@
1
+ import { Entity } from '../entity';
2
+ import { Assignment } from './assignment';
3
+ import { Job } from './job';
4
+
5
+ export class ShipmentItemFulfillment extends Entity {
6
+ protected static resourceName = 'shipment_item_fulfillments';
7
+ protected static singularName = 'shipmentItemFulfillment';
8
+ protected static pluralName = 'shipmentItemFulfillments';
9
+
10
+ @ShipmentItemFulfillment.property({type: 'Assignment'})
11
+ public assignment?: Assignment;
12
+
13
+ @ShipmentItemFulfillment.property({type: 'Job'})
14
+ public job?: Job;
15
+ }
@@ -0,0 +1,7 @@
1
+ import { Merchi } from '../merchi';
2
+
3
+ test('can make ShipmentMethod', () => {
4
+ const merchi = new Merchi();
5
+ const shipmentMethod = new merchi.ShipmentMethod();
6
+ expect(shipmentMethod).toBeTruthy();
7
+ });
@@ -0,0 +1,61 @@
1
+ import { ShipmentService } from '../constants/shipment_services';
2
+ import { Entity } from '../entity';
3
+ import { Address } from './address';
4
+ import { Company } from './company';
5
+ import { CountryTax } from './country_tax';
6
+ import { Product } from './product';
7
+ import { ShipmentMethodVariation } from './shipment_method_variation';
8
+
9
+ export class ShipmentMethod extends Entity {
10
+ protected static resourceName = 'shipment_methods';
11
+ protected static singularName = 'shipmentMethod';
12
+ protected static pluralName = 'shipmentMethods';
13
+
14
+ @ShipmentMethod.property()
15
+ public id?: number;
16
+
17
+ @ShipmentMethod.property()
18
+ public name?: string;
19
+
20
+ @ShipmentMethod.property({type: ShipmentService})
21
+ public shipmentService?: ShipmentService | null;
22
+
23
+ @ShipmentMethod.property({type: Address})
24
+ public originAddress?: Address | null;
25
+
26
+ @ShipmentMethod.property()
27
+ public pickUp?: boolean;
28
+
29
+ @ShipmentMethod.property({type: Company})
30
+ public company?: Company | null;
31
+
32
+ @ShipmentMethod.property()
33
+ public companyDefault?: boolean;
34
+
35
+ @ShipmentMethod.property()
36
+ public defaultCost?: number;
37
+
38
+ @ShipmentMethod.property()
39
+ public currency?: string;
40
+
41
+ @ShipmentMethod.property()
42
+ public buyCost?: number;
43
+
44
+ @ShipmentMethod.property()
45
+ public buyCurrency?: string;
46
+
47
+ @ShipmentMethod.property({type: Number})
48
+ public transportCompany?: number | null;
49
+
50
+ @ShipmentMethod.property()
51
+ public transportCompanyName?: string;
52
+
53
+ @ShipmentMethod.property({type: CountryTax})
54
+ public taxType?: CountryTax | null;
55
+
56
+ @ShipmentMethod.property({arrayType: 'ShipmentMethodVariation'})
57
+ public variations?: ShipmentMethodVariation[];
58
+
59
+ @ShipmentMethod.property({arrayType: 'Product'})
60
+ public products?: Product[];
61
+ }
@@ -0,0 +1,7 @@
1
+ import { Merchi } from '../merchi';
2
+
3
+ test('can make ShipmentMethodVariation', () => {
4
+ const merchi = new Merchi();
5
+ const shipmentMethodVariation = new merchi.ShipmentMethodVariation();
6
+ expect(shipmentMethodVariation).toBeTruthy();
7
+ });