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