merchi_sdk_js 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. package/package.json +4 -4
  2. package/dist/address.js +0 -109
  3. package/dist/assignment.js +0 -175
  4. package/dist/automatic_payment_relationship.js +0 -72
  5. package/dist/backup.js +0 -32
  6. package/dist/bank.js +0 -25
  7. package/dist/cart.js +0 -133
  8. package/dist/cart_item.js +0 -71
  9. package/dist/cart_shipment_group.js +0 -23
  10. package/dist/cart_shipment_quote.js +0 -26
  11. package/dist/category.js +0 -68
  12. package/dist/company.js +0 -248
  13. package/dist/company_invitation.js +0 -70
  14. package/dist/component.js +0 -107
  15. package/dist/component_tag.js +0 -60
  16. package/dist/component_version.js +0 -21
  17. package/dist/country_tax.js +0 -93
  18. package/dist/dictionary.js +0 -130
  19. package/dist/discount.js +0 -22
  20. package/dist/discount_group.js +0 -18
  21. package/dist/domain.js +0 -245
  22. package/dist/domain_invitation.js +0 -17
  23. package/dist/domain_tag.js +0 -87
  24. package/dist/domain_types.js +0 -22
  25. package/dist/draft.js +0 -97
  26. package/dist/draft_comment.js +0 -45
  27. package/dist/draft_template.js +0 -39
  28. package/dist/email_address.js +0 -34
  29. package/dist/email_counter.js +0 -47
  30. package/dist/enrolled_domain.js +0 -88
  31. package/dist/exchange_rate.js +0 -66
  32. package/dist/field_types.js +0 -19
  33. package/dist/helpers.js +0 -86
  34. package/dist/internal_tag.js +0 -98
  35. package/dist/inventory.js +0 -100
  36. package/dist/inventory_unit_variation.js +0 -19
  37. package/dist/invoice.js +0 -225
  38. package/dist/invoice_types.js +0 -11
  39. package/dist/item.js +0 -25
  40. package/dist/job.js +0 -536
  41. package/dist/job_comment.js +0 -45
  42. package/dist/job_status.js +0 -47
  43. package/dist/matching_inventory.js +0 -21
  44. package/dist/md5.js +0 -149
  45. package/dist/menu.js +0 -37
  46. package/dist/menu_item.js +0 -24
  47. package/dist/merchi.js +0 -1004
  48. package/dist/merchi_file.js +0 -165
  49. package/dist/model.js +0 -753
  50. package/dist/notification.js +0 -151
  51. package/dist/notification_types.js +0 -199
  52. package/dist/output.cjs.js +0 -31317
  53. package/dist/output.esm.js +0 -31312
  54. package/dist/page.js +0 -41
  55. package/dist/payment.js +0 -32
  56. package/dist/payment_device.js +0 -21
  57. package/dist/payment_types.js +0 -20
  58. package/dist/phone_number.js +0 -37
  59. package/dist/product.js +0 -288
  60. package/dist/product_types.js +0 -32
  61. package/dist/production_comment.js +0 -44
  62. package/dist/quote.js +0 -91
  63. package/dist/quote_item.js +0 -59
  64. package/dist/roles.js +0 -29
  65. package/dist/seo_domain_page.js +0 -42
  66. package/dist/session.js +0 -103
  67. package/dist/set.js +0 -29
  68. package/dist/shipment.js +0 -181
  69. package/dist/shipment_item.js +0 -17
  70. package/dist/shipment_item_fulfillment.js +0 -17
  71. package/dist/shipment_method.js +0 -81
  72. package/dist/shipment_method_variation.js +0 -38
  73. package/dist/subscription_plan.js +0 -75
  74. package/dist/supply_domain.js +0 -65
  75. package/dist/system_role.js +0 -12
  76. package/dist/theme.js +0 -180
  77. package/dist/theme_css_setting.js +0 -61
  78. package/dist/theme_status.js +0 -11
  79. package/dist/user.js +0 -409
  80. package/dist/user_company.js +0 -19
  81. package/dist/user_types.js +0 -23
  82. package/dist/uuid.js +0 -12
  83. package/dist/variation.js +0 -233
  84. package/dist/variation_field.js +0 -233
  85. package/dist/variation_fields_option.js +0 -41
  86. package/dist/variation_option.js +0 -62
  87. package/dist/variations_group.js +0 -43
  88. package/dist/white_label_accessibilities.js +0 -11
@@ -1,12 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.SystemRole = SystemRole;
7
- var _model = require("./model.js");
8
- function SystemRole() {
9
- this.resource = '/system_roles';
10
- this.json = 'systemRole';
11
- (0, _model.addPropertyTo)(this, 'role');
12
- }
package/dist/theme.js DELETED
@@ -1,180 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Theme = Theme;
7
- exports.Themes = Themes;
8
- var _uuid = require("./uuid.js");
9
- var _model = require("./model.js");
10
- var _theme_status = require("./theme_status.js");
11
- var _merchi_file = require("./merchi_file.js");
12
- var _component = require("./component.js");
13
- var _domain = require("./domain.js");
14
- var _page = require("./page.js");
15
- var _user = require("./user.js");
16
- var _internal_tag = require("./internal_tag.js");
17
- function Theme() {
18
- this.resource = '/themes';
19
- this.json = 'theme';
20
- this.temporaryId = (0, _uuid.generateUUID)();
21
- (0, _model.addPropertyTo)(this, 'id');
22
- (0, _model.addPropertyTo)(this, 'aiContext');
23
- (0, _model.addPropertyTo)(this, 'jsBundle');
24
- (0, _model.addPropertyTo)(this, 'name');
25
- (0, _model.addPropertyTo)(this, 'description');
26
- (0, _model.addPropertyTo)(this, 'foundation');
27
- (0, _model.addPropertyTo)(this, 'public');
28
- (0, _model.addPropertyTo)(this, 'lastUpdated');
29
- (0, _model.addPropertyTo)(this, 'components', _component.Component);
30
- (0, _model.addPropertyTo)(this, 'contextComponents', _component.Component);
31
- (0, _model.addPropertyTo)(this, 'featureImage', _merchi_file.MerchiFile);
32
- (0, _model.addPropertyTo)(this, 'images', _merchi_file.MerchiFile);
33
- (0, _model.addPropertyTo)(this, 'cssImageFiles', _merchi_file.MerchiFile);
34
- (0, _model.addPropertyTo)(this, 'pages', _page.Page);
35
- (0, _model.addPropertyTo)(this, 'headerTemplate');
36
- (0, _model.addPropertyTo)(this, 'headerHtml');
37
- (0, _model.addPropertyTo)(this, 'footerTemplate');
38
- (0, _model.addPropertyTo)(this, 'footerHtml');
39
- (0, _model.addPropertyTo)(this, 'indexPageTemplate');
40
- (0, _model.addPropertyTo)(this, 'indexHtml');
41
- (0, _model.addPropertyTo)(this, 'domainInvitePageTemplate');
42
- (0, _model.addPropertyTo)(this, 'domainInviteHtml');
43
- (0, _model.addPropertyTo)(this, 'resetPasswordPageTemplate');
44
- (0, _model.addPropertyTo)(this, 'passwordResetHtml');
45
- (0, _model.addPropertyTo)(this, 'passwordChangePageTemplate');
46
- (0, _model.addPropertyTo)(this, 'passwordChangeHtml');
47
- (0, _model.addPropertyTo)(this, 'jobDraftingPageTemplate');
48
- (0, _model.addPropertyTo)(this, 'jobDraftingHtml');
49
- (0, _model.addPropertyTo)(this, 'jobQuoteRequestedPageTemplate');
50
- (0, _model.addPropertyTo)(this, 'jobQuoteRequestedHtml');
51
- (0, _model.addPropertyTo)(this, 'draftPreviewPageTemplate');
52
- (0, _model.addPropertyTo)(this, 'draftPreviewHtml');
53
- (0, _model.addPropertyTo)(this, 'invoicePageTemplate');
54
- (0, _model.addPropertyTo)(this, 'invoiceHtml');
55
- (0, _model.addPropertyTo)(this, 'productPageTemplate');
56
- (0, _model.addPropertyTo)(this, 'productHtml');
57
- (0, _model.addPropertyTo)(this, 'invoicePaidPageTemplate');
58
- (0, _model.addPropertyTo)(this, 'invoicePaidHtml');
59
- (0, _model.addPropertyTo)(this, 'loginPageTemplate');
60
- (0, _model.addPropertyTo)(this, 'loginPageHtml');
61
- (0, _model.addPropertyTo)(this, 'errorPageTemplate');
62
- (0, _model.addPropertyTo)(this, 'errorPageHtml');
63
- (0, _model.addPropertyTo)(this, 'footerError');
64
- (0, _model.addPropertyTo)(this, 'headerError');
65
- (0, _model.addPropertyTo)(this, 'indexPageError');
66
- (0, _model.addPropertyTo)(this, 'productsPageError');
67
- (0, _model.addPropertyTo)(this, 'domainInvitePageError');
68
- (0, _model.addPropertyTo)(this, 'resetPasswordPageError');
69
- (0, _model.addPropertyTo)(this, 'passwordChangePageError');
70
- (0, _model.addPropertyTo)(this, 'jobDraftingPageError');
71
- (0, _model.addPropertyTo)(this, 'jobQuoteRequestedPageError');
72
- (0, _model.addPropertyTo)(this, 'invoicePageError');
73
- (0, _model.addPropertyTo)(this, 'productPageError');
74
- (0, _model.addPropertyTo)(this, 'invoicePaidPageError');
75
- (0, _model.addPropertyTo)(this, 'loginPageError');
76
- (0, _model.addPropertyTo)(this, 'errorPageError');
77
- (0, _model.addPropertyTo)(this, 'mainCssErrorMessage');
78
- (0, _model.addPropertyTo)(this, 'mainCssStatus');
79
- (0, _model.addPropertyTo)(this, 'mainCss');
80
- (0, _model.addPropertyTo)(this, 'mainCssTemplateEditing');
81
- (0, _model.addPropertyTo)(this, 'mainCssTemplateUsing');
82
- (0, _model.addPropertyTo)(this, 'emailCssErrorMessage');
83
- (0, _model.addPropertyTo)(this, 'emailCssStatus');
84
- (0, _model.addPropertyTo)(this, 'emailCss');
85
- (0, _model.addPropertyTo)(this, 'emailCssTemplateEditing');
86
- (0, _model.addPropertyTo)(this, 'emailCssTemplateUsing');
87
- (0, _model.addPropertyTo)(this, 'author', _user.User);
88
- (0, _model.addPropertyTo)(this, 'domain', _domain.Domain);
89
- (0, _model.addPropertyTo)(this, 'defaultForDomainType');
90
- (0, _model.addPropertyTo)(this, 'internalTags', _internal_tag.InternalTag);
91
- this.create = function (success, error, embed, as_domain) {
92
- var self = this,
93
- data = (0, _model.serialise)(this);
94
- function handleResponse(result) {
95
- success((0, _model.fromJson)(self, result[self.json]));
96
- }
97
- (0, _model.create)({
98
- resource: this.resource,
99
- parameters: data[0],
100
- as_domain: as_domain,
101
- files: (0, _model.enumerateFiles)(data[1]),
102
- success: handleResponse,
103
- error: error,
104
- embed: embed
105
- });
106
- };
107
- this.get = function (success, error, embed) {
108
- var self = this;
109
- function handleResponse(result) {
110
- success((0, _model.fromJson)(self, result[self.json], {
111
- makesDirty: false
112
- }));
113
- }
114
- (0, _model.getOne)({
115
- resource: this.resource,
116
- id: this.id(),
117
- success: handleResponse,
118
- error: error,
119
- embed: embed
120
- });
121
- };
122
- this.patch = function (success, error, embed) {
123
- var self = this,
124
- data = (0, _model.serialise)(this)[0];
125
- function handleResponse(result) {
126
- success((0, _model.fromJson)(self, result[self.json], {
127
- makesDirty: false
128
- }));
129
- }
130
- (0, _model.patchOne)({
131
- resource: this.resource,
132
- id: this.id(),
133
- success: handleResponse,
134
- error: error,
135
- data: data,
136
- embed: embed
137
- });
138
- };
139
- this.canBeActivated = function () {
140
- var validStatus = _theme_status.themeStatus.get("VALID_BUT_NOT_UPDATED");
141
- return this.mainCssStatus() >= validStatus && this.emailCssStatus() >= validStatus;
142
- };
143
- this.isActiveOnDomain = function (domainId) {
144
- var domain = this.domain();
145
- return domain && domain.id() === parseInt(domainId, 10) && domain.activeThemeId() === this.id();
146
- };
147
- this.getPageBySlug = function (slug) {
148
- var pages = this.pages() ? this.pages() : [],
149
- i;
150
- for (i = 0; i < pages.length; i++) {
151
- var page = pages[i];
152
- if (page.slug() === slug) {
153
- return page;
154
- }
155
- }
156
- return null;
157
- };
158
- this.updateTemplateByName = function (name, text) {
159
- var page = this.getPageBySlug(name);
160
- if (page) {
161
- page.template(text);
162
- } else {
163
- this[name](text);
164
- }
165
- };
166
- }
167
- function Themes() {
168
- this.resource = '/themes';
169
- this.json = 'themes';
170
- this.single = Theme;
171
- this.get = function (success, error, parameters) {
172
- var self = this;
173
- function handleResponse(result) {
174
- success((0, _model.fromJsonList)(self, result, {
175
- makesDirty: false
176
- }));
177
- }
178
- (0, _model.getList)(this.resource, handleResponse, error, parameters);
179
- };
180
- }
@@ -1,61 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.ThemeCssSetting = ThemeCssSetting;
7
- exports.ThemeCssSettings = ThemeCssSettings;
8
- var _model = require("./model.js");
9
- var _user = require("./user.js");
10
- function ThemeCssSetting() {
11
- this.resource = '/theme_css_settings';
12
- this.json = 'themeCssSetting';
13
- (0, _model.addPropertyTo)(this, 'id');
14
- (0, _model.addPropertyTo)(this, 'created');
15
- (0, _model.addPropertyTo)(this, 'createdBy', _user.User);
16
- (0, _model.addPropertyTo)(this, 'allowedAttributes');
17
- (0, _model.addPropertyTo)(this, 'notAllowedAttributes');
18
- this.create = function (success, error, embed, as_domain) {
19
- var data = (0, _model.serialise)(this),
20
- self = this;
21
- function handleResponse(result) {
22
- success((0, _model.fromJson)(self, result[self.json]));
23
- }
24
- (0, _model.create)({
25
- resource: this.resource,
26
- parameters: data[0],
27
- as_domain: as_domain,
28
- success: handleResponse,
29
- error: error,
30
- embed: embed
31
- });
32
- };
33
- this.get = function (success, error) {
34
- var self = this;
35
- function handleResponse(result) {
36
- success((0, _model.fromJson)(self, result[self.json], {
37
- makesDirty: false
38
- }));
39
- }
40
- (0, _model.getOne)({
41
- resource: this.resource,
42
- id: this.id(),
43
- success: handleResponse,
44
- error: error
45
- });
46
- };
47
- }
48
- function ThemeCssSettings() {
49
- this.resource = '/theme_css_settings';
50
- this.json = 'themeCssSettings';
51
- this.single = ThemeCssSetting;
52
- this.get = function (success, error, parameters) {
53
- var self = this;
54
- function handleResponse(result) {
55
- success((0, _model.fromJsonList)(self, result, {
56
- makesDirty: false
57
- }));
58
- }
59
- (0, _model.getList)(this.resource, handleResponse, error, parameters);
60
- };
61
- }
@@ -1,11 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.themeStatus = void 0;
7
- var _dictionary = require("./dictionary.js");
8
- var themeStatus = exports.themeStatus = new _dictionary.Dictionary();
9
- themeStatus.add("NOT_VALID", 1);
10
- themeStatus.add("VALID_BUT_NOT_UPDATED", 2);
11
- themeStatus.add("VALID_AND_UPDATED", 3);
package/dist/user.js DELETED
@@ -1,409 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.User = User;
7
- exports.Users = Users;
8
- var _momentTimezone = _interopRequireDefault(require("moment-timezone"));
9
- var _uuid = require("./uuid.js");
10
- var _set = require("./set.js");
11
- var _md = require("./md5.js");
12
- var _roles = require("./roles.js");
13
- var _helpers = require("./helpers.js");
14
- var _model = require("./model.js");
15
- var _address = require("./address.js");
16
- var _email_address = require("./email_address.js");
17
- var _enrolled_domain = require("./enrolled_domain.js");
18
- var _phone_number = require("./phone_number.js");
19
- var _product = require("./product.js");
20
- var _domain = require("./domain.js");
21
- var _merchi_file = require("./merchi_file.js");
22
- var _system_role = require("./system_role.js");
23
- var _user_company = require("./user_company.js");
24
- var _internal_tag = require("./internal_tag.js");
25
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
26
- function User() {
27
- this.resource = '/users';
28
- this.json = 'user';
29
- this.temporaryId = (0, _uuid.generateUUID)();
30
- (0, _model.addPropertyTo)(this, 'id');
31
- (0, _model.addPropertyTo)(this, 'name');
32
- (0, _model.addPropertyTo)(this, 'userType');
33
- (0, _model.addPropertyTo)(this, 'registeredAsGuest');
34
- (0, _model.addPropertyTo)(this, 'registeredUnderDomains', _domain.Domain);
35
- (0, _model.addPropertyTo)(this, 'password');
36
- (0, _model.addPropertyTo)(this, 'resetToken');
37
- (0, _model.addPropertyTo)(this, 'created');
38
- (0, _model.addPropertyTo)(this, 'timezone');
39
- (0, _model.addPropertyTo)(this, 'preferredLanguage');
40
- (0, _model.addPropertyTo)(this, 'isSuperUser');
41
- (0, _model.addPropertyTo)(this, 'systemRoles', _system_role.SystemRole);
42
- (0, _model.addPropertyTo)(this, 'enableCrashReports');
43
- (0, _model.addPropertyTo)(this, 'enableClientEmails');
44
- (0, _model.addPropertyTo)(this, 'enableInvoiceReminders');
45
- (0, _model.addPropertyTo)(this, 'enableStoreNotifications');
46
- (0, _model.addPropertyTo)(this, 'phoneNumbers', _phone_number.PhoneNumber);
47
- (0, _model.addPropertyTo)(this, 'emailAddresses', _email_address.EmailAddress);
48
- (0, _model.addPropertyTo)(this, 'addresses', _address.Address);
49
- (0, _model.addPropertyTo)(this, 'userCompanies', _user_company.UserCompany);
50
- (0, _model.addPropertyTo)(this, 'enrolledDomains', _enrolled_domain.EnrolledDomain);
51
- (0, _model.addPropertyTo)(this, 'profilePicture', _merchi_file.MerchiFile);
52
- /* products that a supplier can produce */
53
- (0, _model.addPropertyTo)(this, 'products', _product.Product);
54
- /* products that a user has saved for future reference */
55
- (0, _model.addPropertyTo)(this, 'savedProducts', _product.Product);
56
- (0, _model.addPropertyTo)(this, 'accessibleDomainsAsClient', _domain.Domain);
57
- (0, _model.addPropertyTo)(this, 'aiContext');
58
- (0, _model.addPropertyTo)(this, 'internalUseNotes');
59
- (0, _model.addPropertyTo)(this, 'internalUseAiContext');
60
- (0, _model.addPropertyTo)(this, 'internalTags', _internal_tag.InternalTag);
61
- this.create = function (success, error, embed, as_domain) {
62
- var self = this,
63
- data = (0, _model.serialise)(self);
64
- function handleResponse(result) {
65
- success((0, _model.fromJson)(self, result[self.json]));
66
- }
67
- (0, _model.create)({
68
- resource: this.resource,
69
- parameters: data[0],
70
- as_domain: as_domain,
71
- files: (0, _model.enumerateFiles)(data[1]),
72
- success: handleResponse,
73
- error: error,
74
- embed: embed
75
- });
76
- };
77
- this.publicCreate = function (success, error) {
78
- var data = (0, _model.serialise)(this),
79
- self = this,
80
- request = new _model.Request();
81
- request.data().merge(data[0]);
82
- request.resource('/public_user_create/');
83
- request.method('POST');
84
- function handleResponse(status, data) {
85
- if (status === 201) {
86
- success((0, _model.fromJson)(self, data[self.json]));
87
- } else {
88
- error(status, data);
89
- }
90
- }
91
- function handleError(status, data) {
92
- error(status, data);
93
- }
94
- request.responseHandler(handleResponse).errorHandler(handleError);
95
- request.send();
96
- };
97
- this.patch = function (success, error, embed, asDomain) {
98
- var self = this,
99
- data = (0, _model.serialise)(self, undefined, undefined, undefined, {
100
- excludeOld: true
101
- })[0];
102
- function handleResponse(result) {
103
- success((0, _model.fromJson)(self, result[self.json], {
104
- makesDirty: false
105
- }));
106
- }
107
- (0, _model.patchOne)({
108
- resource: this.resource,
109
- id: this.id(),
110
- as_domain: asDomain,
111
- success: handleResponse,
112
- error: error,
113
- data: data,
114
- embed: embed
115
- });
116
- };
117
- this.update = function (success, error, embed) {
118
- this.patch(success, error, embed);
119
- };
120
- this.isRegistered = function () {
121
- var id = this.id();
122
- return !(0, _helpers.isUndefinedOrNull)(id) && id > 0;
123
- };
124
- this.enrolledDomainByDomainId = function (domainId) {
125
- var i,
126
- enrolledDomains = this.enrolledDomains();
127
- for (i = 0; i < enrolledDomains.length; i++) {
128
- var domain = enrolledDomains[i].domain();
129
- if (domain && domain.id() === domainId) {
130
- return enrolledDomains[i];
131
- }
132
- }
133
- return null;
134
- };
135
- this.roleInDomain = function (domainId) {
136
- var enrolledDomains = this.enrolledDomainByDomainId(domainId);
137
- return enrolledDomains ? enrolledDomains.role() : _roles.roles.get("public");
138
- };
139
- this.hasAuthority = function (domainId, roles) {
140
- var i,
141
- domainRole = this.roleInDomain(domainId);
142
- if (this.isSuperUser()) {
143
- return true;
144
- }
145
- for (i = 0; i < roles.length; i++) {
146
- if (roles[i] === domainRole) {
147
- return true;
148
- }
149
- }
150
- return false;
151
- };
152
- this.isJobsAssignee = function (domainId) {
153
- var enrolledDomain = this.enrolledDomainByDomainId(domainId);
154
- return enrolledDomain ? enrolledDomain.isJobsAssignee() : false;
155
- };
156
- this.isAdmin = function (domainId) {
157
- return this.hasAuthority(domainId, [_roles.roles.get('admin')]);
158
- };
159
- this.isAdminOrManager = function (domainId) {
160
- var managerRole = _roles.roles.get('manager'),
161
- adminRole = _roles.roles.get('admin');
162
- return this.hasAuthority(domainId, [managerRole, adminRole]);
163
- };
164
- this.canEditInvoice = function (domainId) {
165
- var managerRole = _roles.roles.get('manager'),
166
- adminRole = _roles.roles.get('admin'),
167
- accountantRole = _roles.roles.get('accountant');
168
- return this.hasAuthority(domainId, [managerRole, adminRole, accountantRole]);
169
- };
170
- this.canEditTheme = function (domainId) {
171
- var managerRole = _roles.roles.get('manager'),
172
- adminRole = _roles.roles.get('admin'),
173
- themeRole = _roles.roles.get('theme editor');
174
- return this.hasAuthority(domainId, [managerRole, adminRole, themeRole]);
175
- };
176
- this.allRoles = function () {
177
- var rolesSet = new _set.Set(),
178
- i,
179
- enrolledDomains = this.enrolledDomains();
180
- if (this.isSuperUser()) {
181
- return _roles.allRoles;
182
- }
183
- for (i = 0; i < enrolledDomains.length; i++) {
184
- rolesSet.add(enrolledDomains[i].role());
185
- }
186
- rolesSet.add(_roles.roles.get("public"));
187
- return rolesSet;
188
- };
189
- this.hasRole = function (roles, combineFunction) {
190
- var userRoles = this.allRoles(),
191
- i,
192
- isRoleInJudgementResult = [];
193
- if (!combineFunction) {
194
- combineFunction = _helpers.any;
195
- }
196
- for (i = 0; i < roles.length; i++) {
197
- isRoleInJudgementResult.append(userRoles.has(roles[i]));
198
- }
199
- return combineFunction(isRoleInJudgementResult);
200
- };
201
- this.hasRoleInAnyDomain = function (rolesArray) {
202
- var i,
203
- hasRole = false;
204
- this.allRoles().each(function (roleInt) {
205
- for (i = 0; i < rolesArray.length; i++) {
206
- if (roleInt === rolesArray[i]) {
207
- hasRole = true;
208
- }
209
- }
210
- });
211
- return hasRole;
212
- };
213
- this.domainsByRoles = function (rolesArray) {
214
- /* takes an array of roles and returns an array of domains where
215
- the user has one of the provided roles.
216
- */
217
- var enrolledDomains = this.enrolledDomains() ? this.enrolledDomains() : [],
218
- domains = [],
219
- domain,
220
- i;
221
- for (i = 0; i < enrolledDomains.length; i++) {
222
- domain = enrolledDomains[i].domain();
223
- if (domain && this.hasAuthority(domain.id(), rolesArray)) {
224
- domains.push(domain);
225
- }
226
- }
227
- return domains;
228
- };
229
- this.update = function (success, error, embed) {
230
- this.patch(success, error, (0, _model.serialise)(this, undefined, undefined, undefined, {
231
- excludeOld: true
232
- })[0], embed);
233
- };
234
- this.get = function (success, error, embed) {
235
- var self = this;
236
- function handleResponse(result) {
237
- success((0, _model.fromJson)(self, result[self.json], {
238
- makesDirty: false
239
- }));
240
- }
241
- (0, _model.getOne)({
242
- resource: this.resource,
243
- id: this.id(),
244
- success: handleResponse,
245
- error: error,
246
- embed: embed
247
- });
248
- };
249
- this.inDomain = function (domainId) {
250
- var i,
251
- domain,
252
- userDomains = this.enrolledDomains();
253
- for (i = 0; i < userDomains.length; i += 1) {
254
- domain = userDomains[i].domain();
255
- if (domain && domain.id() === parseInt(domainId, 10)) {
256
- return true;
257
- }
258
- }
259
- return false;
260
- };
261
- this.managedDomains = function () {
262
- var domains = [],
263
- i,
264
- enrolment,
265
- userDomains = this.enrolledDomains();
266
- for (i = 0; i < userDomains.length; i += 1) {
267
- enrolment = userDomains[i];
268
- if (enrolment.role() === _roles.roles.get('admin') || enrolment.role() === _roles.roles.get('manager')) {
269
- domains.push(enrolment.domain());
270
- }
271
- }
272
- return domains;
273
- };
274
- this.supplierDesignerDomains = function () {
275
- var domains = [],
276
- i,
277
- enrolment,
278
- userDomains = this.enrolledDomains();
279
- for (i = 0; i < userDomains.length; i += 1) {
280
- enrolment = userDomains[i];
281
- if (enrolment.role() === _roles.roles.get('designer') || enrolment.role() === _roles.roles.get('supplier')) {
282
- domains.push(enrolment.domain());
283
- }
284
- }
285
- return domains;
286
- };
287
- this.hasSystemRole = function (systemRole) {
288
- var systemRoles = this.systemRoles() ? this.systemRoles() : [],
289
- i;
290
- for (i = 0; i < systemRoles.length; i++) {
291
- if (systemRoles[i].role() === systemRole) {
292
- return true;
293
- }
294
- }
295
- return false;
296
- };
297
- this.isPlatformStaff = function () {
298
- return this.isSuperUser() || this.hasSystemRole();
299
- };
300
- this.isComponentBuilder = function () {
301
- return this.hasSystemRole(_roles.systemRoles.get(_roles.COMPONENT_BUILDER));
302
- };
303
- this.indexOfSystemRole = function (systemRole) {
304
- var systemRoles = this.systemRoles() ? this.systemRoles() : [];
305
- return systemRoles.findIndex(function (ent) {
306
- return systemRole === ent.role();
307
- });
308
- };
309
- this.userLocalTime = function (time) {
310
- return (0, _momentTimezone["default"])(time).tz(this.timezone()).toDate();
311
- };
312
- this.userLocalTimeUnix = function (time) {
313
- return (0, _momentTimezone["default"])(time).tz(this.timezone()).unix();
314
- };
315
- this.userLocalTimeMoment = function (time) {
316
- return (0, _momentTimezone["default"])(time).tz(this.timezone());
317
- };
318
- this.userLocalTimeFormat = function (unixTix, formaString) {
319
- var format = formaString ? formaString : 'ddd Do MMM YY';
320
- return (0, _momentTimezone["default"])(unixTix).tz(this.timezone()).format(format);
321
- };
322
- this.profilePictureUrl = function (size) {
323
- var email = this.emailAddresses() ? this.emailAddresses()[0].emailAddress().toLowerCase() : 'this address does not exist. md5 collision unlikely';
324
- size = size || 50;
325
- if (this.profilePicture()) {
326
- return String(this.profilePicture().viewUrl());
327
- }
328
- return 'https://www.gravatar.com/avatar/' + (0, _md.md5)(email) + '?d=mm&s=' + size;
329
- };
330
- this.primaryEmailAddressEntity = function () {
331
- var emails = this.emailAddresses();
332
- return emails && emails[0] ? emails[0] : null;
333
- };
334
- this.primaryEmailAddress = function () {
335
- var email = this.primaryEmailAddressEntity();
336
- return email ? email.emailAddress() : null;
337
- };
338
- this.primaryPhoneNumberEntity = function () {
339
- var numbers = this.phoneNumbers();
340
- return numbers && numbers[0] ? numbers[0] : null;
341
- };
342
- this.primaryPhoneNumber = function () {
343
- var primary = this.primaryPhoneNumberEntity();
344
- return primary ? primary.internationalFormatNumber() : null;
345
- };
346
- this.primaryCompany = function () {
347
- var companies = this.userCompanies();
348
- return companies && companies[0] ? companies[0].company() : null;
349
- };
350
- this.primaryAddress = function () {
351
- var self = this;
352
- if (Boolean(self.addresses()) && Boolean(self.addresses()[0])) {
353
- return self.addresses()[0];
354
- }
355
- return null;
356
- };
357
- this.primaryAddressString = function () {
358
- var self = this;
359
- if (Boolean(self.primaryAddress())) {
360
- return self.primaryAddress().fullAddressString();
361
- }
362
- return 'Address not shared.';
363
- };
364
- this.findCompanyInUserCompanies = function (company) {
365
- var companies = this.userCompanies() ? this.userCompanies() : [],
366
- i;
367
- for (i = 0; i < companies.length; i++) {
368
- var c = companies[i].company();
369
- if (c.id() === company.id()) {
370
- return companies[i];
371
- }
372
- }
373
- return null;
374
- };
375
- this.isInCompany = function (company) {
376
- return Boolean(this.findCompanyInUserCompanies(company));
377
- };
378
- this.isCompanyAdmin = function (company) {
379
- return this.isInCompany(company) && this.findCompanyInUserCompanies(company).isAdmin();
380
- };
381
- }
382
- function Users() {
383
- this.resource = '/users';
384
- this.json = 'users';
385
- this.single = User;
386
- this.get = function (success, error, parameters) {
387
- var self = this;
388
- function handleResponse(result) {
389
- success((0, _model.fromJsonList)(self, result, {
390
- makesDirty: false
391
- }));
392
- }
393
- (0, _model.getList)(this.resource, handleResponse, error, parameters);
394
- };
395
- this.getRolesInDomain = function (success, error, domainId, roles, q, offset, limit, query, embed) {
396
- var self = this;
397
- function handleResponse(result) {
398
- success((0, _model.fromJsonList)(self, result));
399
- }
400
- (0, _model.getList)(self.resource, handleResponse, error, {
401
- offset: offset,
402
- limit: limit,
403
- q: q,
404
- inDomain: domainId,
405
- inDomainRoles: roles,
406
- embed: embed
407
- });
408
- };
409
- }
@@ -1,19 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.UserCompany = UserCompany;
7
- var _uuid = require("./uuid.js");
8
- var _model = require("./model.js");
9
- var _company = require("./company.js");
10
- var _user = require("./user.js");
11
- function UserCompany() {
12
- this.resource = '/user_companies';
13
- this.json = 'userCompany';
14
- this.temporaryId = (0, _uuid.generateUUID)();
15
- (0, _model.addPropertyTo)(this, 'id');
16
- (0, _model.addPropertyTo)(this, 'isAdmin');
17
- (0, _model.addPropertyTo)(this, 'user', _user.User);
18
- (0, _model.addPropertyTo)(this, 'company', _company.Company);
19
- }