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,154 @@
1
+ import { Merchi } from '../merchi';
2
+ import { Role } from '../constants/roles';
3
+ import { SystemRoles } from '../constants/system_roles';
4
+ import { DomainType } from '../constants/domain_types';
5
+ import { setup, mockFetch } from '../test_util';
6
+ import { every } from 'lodash';
7
+
8
+ setup();
9
+
10
+ test('can make User', () => {
11
+ const merchi = new Merchi();
12
+ const user = new merchi.User();
13
+ expect(user).toBeTruthy();
14
+ });
15
+
16
+ test('can issue public create request to server', () => {
17
+ const merchi = new Merchi();
18
+ const user = new merchi.User();
19
+ user.name = 'Test User';
20
+ const data = Array.from((user.toFormData() as any).entries());
21
+ const fetch = mockFetch(true, {}, 201);
22
+ user.publicCreate();
23
+ const fetchUrl = fetch.mock.calls[0][0];
24
+ const sentToServer = Array.from(fetch.mock.calls[0][1]['body'].entries());
25
+ expect(sentToServer).toEqual(data);
26
+ expect(fetchUrl).toMatch('public_user_create');
27
+ });
28
+
29
+ test('role helper function', () => {
30
+ const merchi = new Merchi();
31
+ const user = new merchi.User();
32
+ const userSupplier = new merchi.User();
33
+ const domain1 = new merchi.Domain();
34
+ const domain2 = new merchi.Domain();
35
+ const enrolledDomain = new merchi.EnrolledDomain();
36
+ const enrolledDomainSupplier = new merchi.EnrolledDomain();
37
+ domain1.id = 1;
38
+ domain2.id = 2;
39
+ enrolledDomain.role = Role.ADMIN;
40
+ enrolledDomainSupplier.role = Role.SUPPLIER;
41
+ // throw error if enrolledDomains is undefined which seems to be an embed issue
42
+ expect(() => {user.roleInDomain(domain1);}).toThrow(Error);
43
+
44
+ // throw error if enrolledDomain.domain is undefined which seems to be an embed issue
45
+ user.enrolledDomains = [enrolledDomain];
46
+ expect(() => {user.roleInDomain(domain1);}).toThrow(Error);
47
+
48
+ userSupplier.enrolledDomains = [enrolledDomainSupplier];
49
+
50
+ enrolledDomain.domain = domain1;
51
+ enrolledDomainSupplier.domain = domain1;
52
+ expect(user.roleInDomain(domain1)).toBe(Role.ADMIN);
53
+ expect(userSupplier.roleInDomain(domain1)).toBe(Role.SUPPLIER);
54
+ expect(user.roleInDomain(domain2)).toBe(Role.PUBLIC);
55
+
56
+ expect(user.isManagementTeam(domain1)).toBe(true);
57
+ expect(user.isManagementTeam(domain2)).toBe(false);
58
+ expect(user.isDomainManager(domain1)).toBe(true);
59
+ expect(user.isDomainManager(domain2)).toBe(false);
60
+ expect(user.isNotClient(domain1)).toBe(true);
61
+ expect(userSupplier.isManagementTeam(domain1)).toBe(false);
62
+ expect(userSupplier.isNotClient(domain1)).toBe(true);
63
+
64
+ // have two match enrolled domain is invalid data, but we should return
65
+ // the highest permission
66
+ const enrolledDomainClient = new merchi.EnrolledDomain();
67
+ enrolledDomainClient.role = Role.CLIENT;
68
+ enrolledDomainClient.domain = domain1;
69
+
70
+ user.enrolledDomains = [enrolledDomain, enrolledDomainClient];
71
+ expect(user.roleInDomain(domain1)).toBe(Role.ADMIN);
72
+ });
73
+
74
+ test('companies', () => {
75
+ const merchi = new Merchi();
76
+ const user = new merchi.User();
77
+ // user.userCompanies not embeded yet will throw a error as it suppose to
78
+ // be a embed issue
79
+ expect(() => user.companies()).toThrow();
80
+
81
+ const userCompany1 = new merchi.UserCompany();
82
+ const userCompany2 = new merchi.UserCompany();
83
+ user.userCompanies = [userCompany1, userCompany2];
84
+ expect(() => user.companies()).toThrow();
85
+
86
+ const company1 = new merchi.Company();
87
+ const company2 = new merchi.Company();
88
+ userCompany1.company = company1;
89
+ userCompany2.company = company2;
90
+ expect(user.companies()).toEqual([company1, company2]);
91
+ });
92
+
93
+ test('hasRoles', () => {
94
+ const merchi = new Merchi();
95
+ const user = new merchi.User();
96
+ // EnrolledDomains has not been specified yet likely to be a embed issue
97
+ expect(() => user.hasRoles([Role.ADMIN])).toThrow();
98
+ const enrollment = new merchi.EnrolledDomain();
99
+ user.enrolledDomains = [enrollment];
100
+ // EnrolledDomains.domain has not been specified yet likely to be
101
+ // a embed issue
102
+ expect(() => user.hasRoles([Role.PUBLIC])).toThrow();
103
+
104
+ enrollment.domain = new merchi.Domain();
105
+ expect(user.hasRoles([Role.PUBLIC])).toBeTruthy();
106
+
107
+ enrollment.role = Role.ADMIN;
108
+ user.enrolledDomains = [enrollment];
109
+ expect(user.hasRoles([Role.ADMIN, Role.MANAGER])).toBeTruthy();
110
+ expect(user.hasRoles([Role.ADMIN, Role.MANAGER], every)).toBeFalsy();
111
+
112
+ // for internal supplier domain, role can be maximumly interpreted
113
+ // as supplier
114
+ enrollment.domain.domainType = DomainType.DOMAIN_SUPPLIER;
115
+ expect(user.hasRoles([Role.ADMIN])).toBeFalsy();
116
+ expect(user.hasRoles([Role.SUPPLIER])).toBeTruthy();
117
+ });
118
+
119
+ test('testHasSystemRoles', () => {
120
+ const merchi = new Merchi();
121
+ const user = new merchi.User();
122
+ // SystemRole has not been specified yet likely to be a embed issue
123
+ expect(
124
+ () => user.hasSystemRole(SystemRoles.SYSTEM_COMPONENT_BUILDER)).toThrow();
125
+ user.systemRoles = [];
126
+ expect(user.hasSystemRole(SystemRoles.SYSTEM_COMPONENT_BUILDER)).toBeFalsy();
127
+ const systemRole = new merchi.SystemRole();
128
+ systemRole.role = SystemRoles.SYSTEM_COMPONENT_BUILDER;
129
+ user.systemRoles = [systemRole];
130
+ expect(user.hasSystemRole(SystemRoles.SYSTEM_COMPONENT_BUILDER)).toBeTruthy();
131
+ });
132
+
133
+ test('domainsByRoles', () => {
134
+ const merchi = new Merchi();
135
+ const user = new merchi.User();
136
+ expect(() => user.domainsByRoles([])).toThrow();
137
+ user.enrolledDomains = [];
138
+ expect(user.domainsByRoles([])).toEqual([]);
139
+ const ed = new merchi.EnrolledDomain();
140
+ user.enrolledDomains = [ed];
141
+ expect(() => user.domainsByRoles([])).toThrow();
142
+ const d = new merchi.Domain();
143
+ ed.domain = d;
144
+ expect(() => user.domainsByRoles([])).toThrow();
145
+ user.isSuperUser = false;
146
+ expect(user.domainsByRoles([])).toEqual([]);
147
+ user.isSuperUser = true;
148
+ expect(user.domainsByRoles([])).toEqual([d]);
149
+ user.isSuperUser = false;
150
+ ed.role = Role.MANAGER;
151
+ expect(user.domainsByRoles([Role.MANAGER])).toEqual([d]);
152
+ ed.role = Role.DESIGNER;
153
+ expect(user.domainsByRoles([Role.MANAGER])).toEqual([]);
154
+ });
@@ -0,0 +1,394 @@
1
+ import { Address } from './address';
2
+ import { Assignment } from './assignment';
3
+ import { Cart } from './cart';
4
+ import { Category } from './category';
5
+ import { CompanyInvitation } from './company_invitation';
6
+ import { DomainInvitation } from './domain_invitation';
7
+ import { Draft } from './draft';
8
+ import { DraftComment } from './draft_comment';
9
+ import { EmailAddress } from './email_address';
10
+ import { EnrolledDomain } from './enrolled_domain';
11
+ import { Domain } from './domain';
12
+ import { Entity } from '../entity';
13
+ import { MerchiFile } from './file';
14
+ import { Invoice } from './invoice';
15
+ import { Job } from './job';
16
+ import { JobComment } from './job_comment';
17
+ import { Notification } from './notification';
18
+ import { Payment } from './payment';
19
+ import { PhoneNumber } from './phone_number';
20
+ import { Product } from './product';
21
+ import { ProductionComment } from './production_comment';
22
+ import { Session } from './session';
23
+ import { Shipment } from './shipment';
24
+ import { SystemRole } from './system_role';
25
+ import { Theme } from './theme';
26
+ import { UserCompany } from './user_company';
27
+ import { Company } from './company';
28
+ import { Role,
29
+ DOMAIN_MANAGERS,
30
+ MANAGEMENT_TEAM,
31
+ BUSINESS_ACCOUNTS,
32
+ ROLES_RANK
33
+ } from '../constants/roles';
34
+ import { InternalTag } from './internal_tag';
35
+ import { UserType } from '../constants/user_types';
36
+ import { SystemRoles as SR } from '../constants/system_roles';
37
+
38
+ import { some } from 'lodash';
39
+
40
+ export class User extends Entity {
41
+ protected static resourceName = 'users';
42
+ protected static singularName = 'user';
43
+ protected static pluralName = 'users';
44
+
45
+ @User.property({type: Date})
46
+ public archived?: Date | null;
47
+
48
+ @User.property()
49
+ public id?: number;
50
+
51
+ @User.property()
52
+ public isSuperUser?: boolean;
53
+
54
+ @User.property()
55
+ public userType?: UserType;
56
+
57
+ @User.property()
58
+ public registeredAsGuest?: boolean;
59
+
60
+ @User.property({arrayType: 'InternalTag'})
61
+ public internalTags?: InternalTag[];
62
+
63
+ @User.property({arrayType: 'Domain'})
64
+ public registeredUnderDomains?: Domain[];
65
+
66
+ @User.property({type: String})
67
+ public password?: string | null;
68
+
69
+ @User.property({type: String})
70
+ public salt?: string | null;
71
+
72
+ @User.property({type: String})
73
+ public facebookUserId?: string | null;
74
+
75
+ @User.property({type: String})
76
+ public resetToken?: string | null;
77
+
78
+ @User.property({type: String})
79
+ public resetTokenDate?: Date | null;
80
+
81
+ @User.property({type: String})
82
+ public smsToken?: string | null;
83
+
84
+ @User.property({type: Date})
85
+ public resetSmsTokenDate?: Date | null;
86
+
87
+ @User.property({type: String})
88
+ public smsClientToken?: string | null;
89
+
90
+ @User.property()
91
+ public smsTokenConfirmed?: boolean;
92
+
93
+ @User.property()
94
+ public smsLoginThreshold?: number;
95
+
96
+ @User.property()
97
+ public hasStore?: boolean;
98
+
99
+ @User.property()
100
+ public enableCrashReports?: boolean;
101
+
102
+ @User.property()
103
+ public enableClientEmails?: boolean;
104
+
105
+ @User.property({type: String})
106
+ public clientToken?: string | null;
107
+
108
+ @User.property()
109
+ public name?: string;
110
+
111
+ @User.property({type: String})
112
+ public internalUseNotes?: string;
113
+
114
+ @User.property({type: String})
115
+ public internalUseAiContext?: string;
116
+
117
+ @User.property({type: String})
118
+ public aiContext?: string;
119
+
120
+ @User.property()
121
+ public callToActions?: string;
122
+
123
+ @User.property()
124
+ public callToActionDetails?: any[];
125
+
126
+ @User.property({type: String})
127
+ public comments?: string | null;
128
+
129
+ @User.property({type: String})
130
+ public timezone?: string | null;
131
+
132
+ @User.property({type: Date})
133
+ public created?: Date | null;
134
+
135
+ @User.property({type: String})
136
+ public preferredLanguage?: string | null;
137
+
138
+ @User.property()
139
+ public enableInvoiceReminders?: boolean;
140
+
141
+ @User.property()
142
+ public enableStoreNotifications?: boolean;
143
+
144
+ @User.property()
145
+ public isAdminOfSubscribedCompany?: boolean;
146
+
147
+ @User.property({ arrayType: 'JobComment' })
148
+ public jobComments?: JobComment[];
149
+
150
+ @User.property({ arrayType: 'EmailAddress' })
151
+ public _emailAddresses?: EmailAddress[];
152
+
153
+ @User.property({ arrayType: 'PhoneNumber' })
154
+ public _phoneNumbers?: PhoneNumber[];
155
+
156
+ @User.property({ arrayType: 'Address' })
157
+ public _addresses?: Address[];
158
+
159
+ @User.property({ arrayType: 'UserCompany' })
160
+ public _companies?: UserCompany[];
161
+
162
+ @User.property({ arrayType: 'Company' })
163
+ public companiesNeedStripe?: Company[];
164
+
165
+ @User.property({ arrayType: 'Category' })
166
+ public categories?: Category[];
167
+
168
+ @User.property({ arrayType: 'Product' })
169
+ public products?: Product[];
170
+
171
+ @User.property({type: 'MerchiFile'})
172
+ public profilePicture?: MerchiFile | null;
173
+
174
+ @User.property({ arrayType: 'PhoneNumber' })
175
+ public phoneNumbers?: PhoneNumber[];
176
+
177
+ @User.property({ arrayType: 'Session' })
178
+ public sessions?: Session[];
179
+
180
+ @User.property({ arrayType: 'Shipment' })
181
+ public shipmentsAsSender?: Shipment[];
182
+
183
+ @User.property({ arrayType: 'Shipment' })
184
+ public shipmentsAsReceiver?: Shipment[];
185
+
186
+ @User.property({ arrayType: 'DraftComment' })
187
+ public draftComments?: DraftComment[];
188
+
189
+ @User.property({ arrayType: 'DraftComment' })
190
+ public forwardedDraftComments?: DraftComment[];
191
+
192
+ @User.property({ arrayType: 'SystemRole' })
193
+ public systemRoles?: SystemRole[];
194
+
195
+ @User.property({ arrayType: 'EmailAddress' })
196
+ public emailAddresses?: EmailAddress[];
197
+
198
+ @User.property({ arrayType: 'Notification' })
199
+ public notifications?: Notification[];
200
+
201
+ @User.property({ arrayType: 'Notification' })
202
+ public sentNotifications?: Notification[];
203
+
204
+ @User.property({ arrayType: 'Assignment' })
205
+ public assignments?: Assignment[];
206
+
207
+ @User.property({ arrayType: 'UserCompany' })
208
+ public userCompanies?: UserCompany[];
209
+
210
+ @User.property({ arrayType: 'Draft' })
211
+ public drafts?: Draft[];
212
+
213
+ @User.property({ arrayType: 'CompanyInvitation' })
214
+ public companyInvitations?: CompanyInvitation[];
215
+
216
+ @User.property({ arrayType: 'Address' })
217
+ public addresses?: Address[];
218
+
219
+ @User.property({ arrayType: 'MerchiFile' })
220
+ public uploadFiles?: MerchiFile[];
221
+
222
+ @User.property({ arrayType: 'JobComment' })
223
+ public forwardedJobComments?: JobComment[];
224
+
225
+ @User.property({ arrayType: 'Job' })
226
+ public appliedJobs?: Job[];
227
+
228
+ @User.property({ arrayType: 'Job' })
229
+ public managedJobs?: Job[];
230
+
231
+ @User.property({ arrayType: 'Job' })
232
+ public draftingJobs?: Job[];
233
+
234
+ @User.property({ arrayType: 'Product' })
235
+ public saved_products?: Product[];
236
+
237
+ @User.property({ arrayType: 'Cart' })
238
+ public carts?: Cart[];
239
+
240
+ @User.property({ arrayType: 'Payment' })
241
+ public payments?: Payment[];
242
+
243
+ @User.property({ arrayType: 'EnrolledDomain' })
244
+ public enrolledDomains?: EnrolledDomain[];
245
+
246
+ @User.property({ arrayType: 'Invoice' })
247
+ public responsibleInvoices?: Invoice[];
248
+
249
+ @User.property({ arrayType: 'Invoice' })
250
+ public createdInvoices?: Invoice[];
251
+
252
+ @User.property({ arrayType: 'Invoice' })
253
+ public invoicesHas?: Invoice[];
254
+
255
+ @User.property({ arrayType: 'DomainInvitation' })
256
+ public sentDomainInvitations?: DomainInvitation[];
257
+
258
+ @User.property({ arrayType: 'DomainInvitation' })
259
+ public receivedDomainInvitations?: DomainInvitation[];
260
+
261
+ @User.property({ arrayType: 'Theme' })
262
+ public themes?: Theme[];
263
+
264
+ @User.property({ arrayType: 'ProductionComment' })
265
+ public forwardedProductionComments?: ProductionComment[];
266
+
267
+ @User.property({ arrayType: 'Domain' })
268
+ public accessibleDomainsAsClient?: Domain[];
269
+
270
+ public publicCreate = this.createFactory(
271
+ {resourceName: 'public_user_create'});
272
+
273
+ public roleInDomain = (domain: Domain): Role => {
274
+ if (this.enrolledDomains === undefined) {
275
+ const err = 'enrolledDomains is undefined, did you forget to embed it?';
276
+ throw new Error(err);
277
+ }
278
+ if (
279
+ this.enrolledDomains
280
+ .map(enrolledDomain => enrolledDomain.domain)
281
+ .some(domain => domain === undefined)
282
+ ) {
283
+ const err =
284
+ 'Domain of enrolled domain is undefined, did you forget to embed it?';
285
+ throw new Error(err);
286
+ }
287
+ const matchingEnrolledDomains = this.enrolledDomains.filter(
288
+ enrolledDomain => enrolledDomain.domain && enrolledDomain.domain.id === domain.id);
289
+
290
+ if (matchingEnrolledDomains.length > 1) {
291
+ const highestRoleRank = Math.max(
292
+ ...matchingEnrolledDomains.map(ed => ROLES_RANK.findIndex(e => e === ed.role)));
293
+ return ROLES_RANK[highestRoleRank];
294
+ }
295
+
296
+ // due to some current system issues, user can have multiple enrolled domain
297
+ // of one domain, if that is the case either of them can be consider as
298
+ // valid, need to revisit it in the future related to #
299
+ if (matchingEnrolledDomains.length > 0) {
300
+ if (matchingEnrolledDomains[0].role !== undefined) {
301
+ return matchingEnrolledDomains[0].role;
302
+ }
303
+ }
304
+ return Role.PUBLIC;
305
+ };
306
+
307
+ public isSuper(): boolean {
308
+ if (this.isSuperUser === undefined) {
309
+ const err = 'isSuperUser is undefined, did you forget to embed it?';
310
+ throw new Error(err);
311
+ }
312
+ return this.isSuperUser!;
313
+ }
314
+
315
+ public companies(): Company[] {
316
+ if (this.userCompanies === undefined) {
317
+ const err = 'userCompanies is undefined, did you forget to embed it?';
318
+ throw new Error(err);
319
+ }
320
+ return this.userCompanies.map((userCompany) => {
321
+ if (userCompany.company === undefined) {
322
+ const err = 'userCompany.company is undefined, did you forget to embed it?';
323
+ throw new Error(err);
324
+ }
325
+ return userCompany.company!;
326
+ });
327
+ }
328
+
329
+ public isDomainManager(domain: Domain) {
330
+ return DOMAIN_MANAGERS.includes(this.roleInDomain(domain));
331
+ }
332
+
333
+ public isManagementTeam(domain: Domain) {
334
+ return MANAGEMENT_TEAM.includes(this.roleInDomain(domain));
335
+ }
336
+
337
+ public isNotClient(domain: Domain) {
338
+ return BUSINESS_ACCOUNTS.includes(this.roleInDomain(domain));
339
+ }
340
+
341
+ public domainsByRoles(roles: Role[]) {
342
+ if (this.enrolledDomains === undefined) {
343
+ const err = 'enrolledDomains is undefined, did you forget to embed it?';
344
+ throw new Error(err);
345
+ }
346
+ const result = [];
347
+ for (let i = 0; i < this.enrolledDomains.length; ++i) {
348
+ const domain = this.enrolledDomains[i].domain;
349
+ if (domain === undefined) {
350
+ const err = 'domain is undefined, did you forget to embed it?';
351
+ throw new Error(err);
352
+ }
353
+ if (this.hasAuthority(domain, roles)) {
354
+ result.push(domain);
355
+ }
356
+ }
357
+ return result;
358
+ }
359
+
360
+ public hasAuthority(domain: Domain, roles: Role[]) {
361
+ if (this.isSuper()) {
362
+ return true;
363
+ }
364
+ const role = this.roleInDomain(domain);
365
+ for (let i = 0; i < roles.length; ++i) {
366
+ if (roles[i] === role) {
367
+ return true;
368
+ }
369
+ }
370
+ return false;
371
+ }
372
+
373
+ public hasSystemRole(role: SR): boolean {
374
+ if (this.systemRoles === undefined) {
375
+ const err = 'systemRoles is undefined, did you forget to embed it?';
376
+ throw new Error(err);
377
+ }
378
+ return some(this.systemRoles.map(systemRole => systemRole.role === role));
379
+ }
380
+
381
+ public hasRoles(roles: Role[], combinationMethod = some) {
382
+ if (this.enrolledDomains === undefined) {
383
+ const err = 'enrolledDomains is undefined, did you forget to embed it?';
384
+ throw new Error(err);
385
+ }
386
+ const allRoles = this.enrolledDomains.map(
387
+ enrolledDomain => enrolledDomain.getRole()
388
+ );
389
+ allRoles.push(Role.PUBLIC);
390
+ return combinationMethod(
391
+ roles.map((role) => allRoles.indexOf(role) !== -1)
392
+ );
393
+ }
394
+ }
@@ -0,0 +1,7 @@
1
+ import { Merchi } from '../merchi';
2
+
3
+ test('can make UserCompany', () => {
4
+ const merchi = new Merchi();
5
+ const userCompany = new merchi.UserCompany();
6
+ expect(userCompany).toBeTruthy();
7
+ });
@@ -0,0 +1,27 @@
1
+ import { Company } from './company';
2
+ import { Entity } from '../entity';
3
+ import { User } from './user';
4
+
5
+ export class UserCompany extends Entity {
6
+ protected static resourceName = 'user_companies';
7
+ protected static singularName = 'userCompany';
8
+ protected static pluralName = 'userCompanies';
9
+
10
+ @UserCompany.property({type: Date})
11
+ public archived?: Date | null;
12
+
13
+ @UserCompany.property()
14
+ public id?: number;
15
+
16
+ @UserCompany.property({type: Boolean})
17
+ public main?: boolean | null;
18
+
19
+ @UserCompany.property()
20
+ public isAdmin?: boolean;
21
+
22
+ @UserCompany.property({type: User})
23
+ public user?: User | null;
24
+
25
+ @UserCompany.property({type: Company})
26
+ public company?: Company | null;
27
+ }
@@ -0,0 +1,7 @@
1
+ import { Merchi } from '../merchi';
2
+
3
+ test('can make Variation', () => {
4
+ const merchi = new Merchi();
5
+ const variation = new merchi.Variation();
6
+ expect(variation).toBeTruthy();
7
+ });
@@ -0,0 +1,61 @@
1
+ import { CartItem } from './cart_item';
2
+ import { Entity } from '../entity';
3
+ import { MerchiFile } from './file';
4
+ import { Job } from './job';
5
+ import { VariationField } from './variation_field';
6
+ import { VariationOption } from './variation_option';
7
+ import { VariationsGroup } from './variations_group';
8
+
9
+ export class Variation extends Entity {
10
+ protected static resourceName = 'variations';
11
+ protected static singularName = 'variation';
12
+ protected static pluralName = 'variations';
13
+
14
+ @Variation.property({type: Date})
15
+ public archived?: Date | null;
16
+
17
+ @Variation.property()
18
+ public id?: number;
19
+
20
+ @Variation.property({type: String})
21
+ public value?: string | null;
22
+
23
+ @Variation.property()
24
+ public currency?: string;
25
+
26
+ @Variation.property()
27
+ public cost?: number;
28
+
29
+ @Variation.property()
30
+ public quantity?: number;
31
+
32
+ @Variation.property()
33
+ public onceOffCost?: number;
34
+
35
+ @Variation.property()
36
+ public unitCost?: number;
37
+
38
+ @Variation.property()
39
+ public unitCostTotal?: number;
40
+
41
+ @Variation.property()
42
+ public variationField?: VariationField;
43
+
44
+ @Variation.property({type: VariationsGroup})
45
+ public variationsGroup?: VariationsGroup | null;
46
+
47
+ @Variation.property({type: Job})
48
+ public job?: Job | null;
49
+
50
+ @Variation.property({type: CartItem})
51
+ public cartItem?: CartItem | null;
52
+
53
+ @Variation.property({arrayType: 'MerchiFile'})
54
+ public variationFiles?: MerchiFile[];
55
+
56
+ @Variation.property({arrayType: 'VariationOption'})
57
+ public selectedOptions?: VariationOption[];
58
+
59
+ @Variation.property({arrayType: 'VariationOption'})
60
+ public selectableOptions?: VariationOption[];
61
+ }