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
package/dist/merchi.js DELETED
@@ -1,1004 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.merchi = merchi;
7
- var _browserOrNode = require("browser-or-node");
8
- var _uuid = require("./uuid.js");
9
- var _helpers = require("./helpers.js");
10
- var _model = require("./model.js");
11
- var _job_status = require("./job_status.js");
12
- var _roles = require("./roles.js");
13
- var _domain_types = require("./domain_types.js");
14
- var _product_types = require("./product_types.js");
15
- var _payment_types = require("./payment_types.js");
16
- var _dictionary = require("./dictionary.js");
17
- var _field_types = require("./field_types.js");
18
- var _notification_types = require("./notification_types.js");
19
- var _address = require("./address.js");
20
- var _assignment = require("./assignment.js");
21
- var _automatic_payment_relationship = require("./automatic_payment_relationship.js");
22
- var _backup = require("./backup.js");
23
- var _bank = require("./bank.js");
24
- var _category = require("./category.js");
25
- var _cart = require("./cart.js");
26
- var _cart_item = require("./cart_item.js");
27
- var _country_tax = require("./country_tax.js");
28
- var _company = require("./company.js");
29
- var _company_invitation = require("./company_invitation.js");
30
- var _component = require("./component.js");
31
- var _component_tag = require("./component_tag.js");
32
- var _discount = require("./discount.js");
33
- var _discount_group = require("./discount_group.js");
34
- var _domain = require("./domain.js");
35
- var _domain_tag = require("./domain_tag.js");
36
- var _domain_invitation = require("./domain_invitation.js");
37
- var _draft = require("./draft.js");
38
- var _draft_template = require("./draft_template.js");
39
- var _draft_comment = require("./draft_comment.js");
40
- var _enrolled_domain = require("./enrolled_domain.js");
41
- var _email_address = require("./email_address.js");
42
- var _email_counter = require("./email_counter.js");
43
- var _exchange_rate = require("./exchange_rate.js");
44
- var _item = require("./item.js");
45
- var _inventory = require("./inventory.js");
46
- var _inventory_unit_variation = require("./inventory_unit_variation.js");
47
- var _matching_inventory = require("./matching_inventory.js");
48
- var _notification = require("./notification.js");
49
- var _invoice = require("./invoice.js");
50
- var _job = require("./job.js");
51
- var _job_comment = require("./job_comment.js");
52
- var _merchi_file = require("./merchi_file.js");
53
- var _menu = require("./menu.js");
54
- var _menu_item = require("./menu_item.js");
55
- var _page = require("./page.js");
56
- var _payment = require("./payment.js");
57
- var _product = require("./product.js");
58
- var _production_comment = require("./production_comment.js");
59
- var _phone_number = require("./phone_number.js");
60
- var _session = require("./session.js");
61
- var _shipment = require("./shipment.js");
62
- var _shipment_method = require("./shipment_method.js");
63
- var _shipment_method_variation = require("./shipment_method_variation.js");
64
- var _subscription_plan = require("./subscription_plan.js");
65
- var _supply_domain = require("./supply_domain.js");
66
- var _system_role = require("./system_role.js");
67
- var _theme = require("./theme.js");
68
- var _user = require("./user.js");
69
- var _user_types = require("./user_types.js");
70
- var _user_company = require("./user_company.js");
71
- var _variation = require("./variation.js");
72
- var _variation_field = require("./variation_field.js");
73
- var _variation_fields_option = require("./variation_fields_option.js");
74
- var _variations_group = require("./variations_group.js");
75
- var _quote_item = require("./quote_item.js");
76
- var _quote = require("./quote.js");
77
- var _internal_tag = require("./internal_tag.js");
78
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
79
- function merchi(backendUri, websocketUri) {
80
- (0, _helpers.getGlobal)().merchiJsonpHandlers = {};
81
- (0, _helpers.getGlobal)().merchiBackendUri = backendUri;
82
- (0, _helpers.getGlobal)().merchiSubscriptionManager = new SubscriptionManager();
83
- function isJSON(x) {
84
- return _typeof(x) === 'object' && x !== null && !(x instanceof Array) && !(x instanceof Date);
85
- }
86
- function isFunction(x) {
87
- return typeof x === 'function';
88
- }
89
- function indexOfEntityInArrayByAttribute(attributeName, array, entity) {
90
- return array.findIndex(function (ent) {
91
- return entity[attributeName]() === ent[attributeName]();
92
- });
93
- }
94
- function indexOfEntityInArrayById(array, entity) {
95
- return indexOfEntityInArrayByAttribute('id', array, entity);
96
- }
97
- function indexOfEntityInArrayByName(array, entity) {
98
- return indexOfEntityInArrayByAttribute('name', array, entity);
99
- }
100
- function displayMoney(amount) {
101
- return parseFloat(amount).toFixed(2);
102
- }
103
- function SubscriptionManager() {
104
- var socket = null,
105
- subscriptions = new _dictionary.Dictionary();
106
- function handleUpdate(data) {
107
- var handler = subscriptions.get(data.subscriptionToken, null);
108
- if (handler !== null) {
109
- handler(data.statusCode, data.data);
110
- }
111
- }
112
- function getSocket() {
113
- if (socket === null) {
114
- socket = io.connect(websocketUri);
115
- socket.on('update', handleUpdate);
116
- }
117
- return socket;
118
- }
119
- function emit(name, data) {
120
- getSocket().emit(name, data);
121
- }
122
- this.subscribe = function (eventTypes, uri, method, onUpdate) {
123
- var subscriptionToken = (0, _uuid.generateUUID)();
124
- subscriptions.add(subscriptionToken, onUpdate);
125
- emit('subscribe', {
126
- eventTypes: eventTypes,
127
- method: method,
128
- subscriptionToken: subscriptionToken,
129
- uri: uri
130
- });
131
- return subscriptionToken;
132
- };
133
- this.unsubscribe = function (subscriptionToken) {
134
- subscriptions.remove(subscriptionToken);
135
- emit('unsubscribe', {
136
- subscriptionToken: subscriptionToken
137
- });
138
- };
139
- }
140
-
141
- /** Closures and file scope vars **/
142
- var roleStrings = new _dictionary.Dictionary(),
143
- roleCssClass = new _dictionary.Dictionary(),
144
- rights = new _dictionary.Dictionary(),
145
- eventTypes = new _dictionary.Dictionary(),
146
- itemTypes = new _dictionary.Dictionary(),
147
- priorityLevels = new _dictionary.Dictionary(),
148
- priorityLevelsOptions = new _dictionary.Dictionary(),
149
- shipmentCompanies = new _dictionary.Dictionary(),
150
- productTypesSeller = new _dictionary.Dictionary(),
151
- notificationAvatar = new _dictionary.Dictionary(),
152
- inventoryStatuses = new _dictionary.Dictionary(),
153
- themeFoundation = new _dictionary.Dictionary(),
154
- inputTypes = new _dictionary.Dictionary(),
155
- fieldTypesString = new _dictionary.Dictionary(),
156
- menuType = new _dictionary.Dictionary(),
157
- menuTypeCodes = new _dictionary.Dictionary(),
158
- menuItemType = new _dictionary.Dictionary(),
159
- menuItemTypeCodes = new _dictionary.Dictionary(),
160
- currentUserEmbed = {
161
- 'emailAddresses': {},
162
- 'profilePicture': {},
163
- 'userCompanies': {
164
- "company": {}
165
- },
166
- 'enrolledDomains': {
167
- 'domain': {}
168
- }
169
- },
170
- platformName = 'Merchi',
171
- platformCopyright = 2023,
172
- platformSellerDomain = 'merchi.co',
173
- platformSellerDomainPlus = 'merchi.co',
174
- backendImgUri = backendUri + 'static/img/',
175
- platformIcon = backendImgUri + 'merchi-monster-blue.png',
176
- platformLogo = backendImgUri + 'merchi-master-colour-with-monster.png',
177
- defaultUserAvatar = backendImgUri + 'default-user-32px.jpg',
178
- STATUS = {
179
- PROD: ['Init', 'Rejected', 'Quoteding', 'Waiting Quote', 'Close Deadline', 'Assigned', 'Questioning', 'Commenced', 'Finish', 'Shipped'],
180
- DESIGN: ['not start', 'started', 'changes request', 'waiting for check', 'approved'],
181
- PAYMENT: ['Not Paid', 'Partially Paid', 'Fully Paid']
182
- },
183
- GSTrate = 0.1,
184
- DEFAULT_RIGHTS = [];
185
- _roles.roles.each(function (key, value) {
186
- roleStrings.add(value, key);
187
- });
188
- roleCssClass.add(_roles.roles.get('public'), 'default');
189
- roleCssClass.add(_roles.roles.get('admin'), 'inverse');
190
- roleCssClass.add(_roles.roles.get('sales'), 'success');
191
- roleCssClass.add(_roles.roles.get('designer'), 'success');
192
- roleCssClass.add(_roles.roles.get('supplier'), 'warning');
193
- roleCssClass.add(_roles.roles.get('client'), 'danger');
194
- roleCssClass.add(_roles.roles.get('manager'), 'primary');
195
- roleCssClass.add(_roles.roles.get('accountant'), 'info');
196
- inputTypes.add(1, "text");
197
- inputTypes.add(2, "select");
198
- inputTypes.add(3, "file");
199
- inputTypes.add(4, "textarea");
200
- inputTypes.add(5, "number");
201
- inputTypes.add(6, "checkbox");
202
- inputTypes.add(7, "radio");
203
- inputTypes.add(8, "instructions");
204
- inputTypes.add(9, "image select");
205
- inputTypes.add(10, "colour picker");
206
- inputTypes.add(11, "colour select");
207
- fieldTypesString.add(1, "TEXT_INPUT");
208
- fieldTypesString.add(2, "SELECT");
209
- themeFoundation.add("NO_FOUNDATION", 0);
210
- themeFoundation.add("BOOTSTRAP_3", 1);
211
- themeFoundation.add("BOOTSTRAP_4", 2);
212
- themeFoundation.add("BOOTSTRAP_5", 3);
213
- shipmentCompanies.add(0, 'DHL');
214
- shipmentCompanies.add(1, 'UPS');
215
- shipmentCompanies.add(2, 'EMS');
216
- shipmentCompanies.add(3, 'FedEx');
217
- shipmentCompanies.add(4, 'Australia Post');
218
- shipmentCompanies.add(5, 'StarTrack');
219
- shipmentCompanies.add(6, 'Toll');
220
- shipmentCompanies.add(7, 'TNT');
221
- shipmentCompanies.add(8, 'Custom Track Link');
222
- shipmentCompanies.add(9, 'Aramex');
223
- shipmentCompanies.add(10, 'realtime express');
224
- shipmentCompanies.add(11, 'Uber');
225
- shipmentCompanies.add(12, 'Civic Transport Couriers');
226
- inventoryStatuses.add("DEDUCTED", 0);
227
- inventoryStatuses.add("CAN_DEDUCT", 1);
228
- inventoryStatuses.add("NOT_SUFFICIENT", 2);
229
- inventoryStatuses.add("NO_MATCHING_INVENTORY", 3);
230
- productTypesSeller.add(2, 'seller');
231
- productTypesSeller.add(3, 'seller (made on demand)');
232
- priorityLevels.add("URGENT_JOB_PRIORITY", 1);
233
- priorityLevels.add("HIGH_JOB_PRIORITY", 2);
234
- priorityLevels.add("MEDIUM_JOB_PRIORITY", 3);
235
- priorityLevels.add("LOW_JOB_PRIORITY", 4);
236
- priorityLevelsOptions.add(1, 'Urgent');
237
- priorityLevelsOptions.add(2, 'High');
238
- priorityLevelsOptions.add(3, 'Medium');
239
- priorityLevelsOptions.add(4, 'Low');
240
- rights.add('canAccess', 1);
241
- rights.add('canEdit', 2);
242
- rights.add('canDelete', 3);
243
- eventTypes.add('POST', 0);
244
- eventTypes.add('PATCH', 1);
245
- eventTypes.add('DELETE', 2);
246
- itemTypes.add('custom', 0);
247
- itemTypes.add('shipping', 1);
248
- itemTypes.add('tax', 2);
249
- menuType.add(0, 'Main menu');
250
- menuType.add(1, 'Footer menu');
251
- menuType.add(2, 'Other menu');
252
- menuType.each(function (key, value) {
253
- menuTypeCodes.add(value, parseInt(key, 10));
254
- });
255
- menuItemType.add(0, 'Redirect');
256
- menuItemType.add(1, 'Internal');
257
- menuItemType.each(function (key, value) {
258
- menuItemTypeCodes.add(value, parseInt(key, 10));
259
- });
260
- DEFAULT_RIGHTS = [rights.get("canAccess"), rights.get("canEdit"), rights.get("canDelete")];
261
- function toJsonList(objs) {
262
- var result = [],
263
- i,
264
- obj,
265
- obj_dict;
266
- for (i = 0; i < objs.length; i++) {
267
- obj = objs[i];
268
- obj_dict = toJson(obj);
269
- result.push(obj_dict);
270
- }
271
- return result;
272
- }
273
- function toJson(model) {
274
- var json = {},
275
- value,
276
- dict;
277
- (0, _model.forEachProperty)(model, function (propName, Type) {
278
- var propNameCamel = propName.replace(/_([a-z])/g, function (g) {
279
- return g[1].toUpperCase();
280
- });
281
- try {
282
- value = model[propName]();
283
- if (value !== null && (!Type || typeof value === 'number')) {
284
- // if the value is default value skip from to json
285
- // Prop is untyped or only id received
286
- json[propNameCamel] = value;
287
- } else if (!(0, _helpers.isUndefinedOrNull)(value)) {
288
- // Prop is typed and other thing rather than
289
- // single id received
290
- if (value instanceof Array) {
291
- if (value.length > 0) {
292
- if (value[0] instanceof Object) {
293
- // value is a array of objs
294
- dict = toJsonList(value);
295
- } else {
296
- // value is a array of id
297
- dict = value;
298
- }
299
- json[propNameCamel] = dict;
300
- } else {
301
- json[propNameCamel] = [];
302
- }
303
- } else {
304
- // Embed Object received
305
- dict = toJson(value);
306
- json[propNameCamel] = dict;
307
- }
308
- }
309
- } catch (ignore) {}
310
- });
311
- json.rights = model.rights;
312
- return json;
313
- }
314
- function entAsBlank(obj) {
315
- /* Return a copy of obj with only obj.id() set */
316
- var newEnt = Object.create(Object.getPrototypeOf(obj));
317
- Object.assign(newEnt, obj);
318
- function copyProp(propertyName, propertyType) {
319
- (0, _model.addPropertyTo)(newEnt, propertyName, propertyType);
320
- if (propertyName === 'id') {
321
- newEnt[propertyName](obj.id());
322
- } else {
323
- newEnt["_" + propertyName] = undefined;
324
- }
325
- }
326
- (0, _model.forEachProperty)(obj, copyProp);
327
- return newEnt;
328
- }
329
- function cleanEntities(entityArray) {
330
- var newArray = [];
331
- entityArray.map(function (entity) {
332
- newArray.push(entAsBlank(entity));
333
- });
334
- return newArray;
335
- }
336
- ;
337
- function copyEnt(obj) {
338
- var newEnt = Object.create(Object.getPrototypeOf(obj));
339
- Object.assign(newEnt, obj);
340
- function copyProp(propertyName, propertyType) {
341
- var propertyValue = obj[propertyName](),
342
- newValue;
343
- (0, _model.addPropertyTo)(newEnt, propertyName, propertyType);
344
- if (!!propertyType) {
345
- if (!!propertyValue) {
346
- if (propertyValue instanceof Array) {
347
- newValue = propertyValue.map(copyEnt);
348
- } else {
349
- newValue = copyEnt(propertyValue);
350
- }
351
- }
352
- } else {
353
- newValue = propertyValue;
354
- }
355
- newEnt[propertyName](newValue);
356
- }
357
- (0, _model.forEachProperty)(obj, copyProp);
358
- return newEnt;
359
- }
360
- function copyEntIfNotNullOrUndefined(obj) {
361
- var entCopy = obj ? copyEnt(obj) : null;
362
- if (entCopy) {
363
- entCopy.id(null);
364
- }
365
- return entCopy;
366
- }
367
- function updateEntNonEmbeddableAttrbibutes(ent, newEnt) {
368
- function notArrayOrEmbeddableAttr(attrVal) {
369
- return attrVal && !Array.isArray(attrVal) && !attrVal.json;
370
- }
371
- function copyProp(propertyName, propertyType) {
372
- var entAttr = ent[propertyName](),
373
- newEntAttr = newEnt[propertyName]();
374
- if (notArrayOrEmbeddableAttr(entAttr) && notArrayOrEmbeddableAttr(newEntAttr)) {
375
- ent[propertyName](newEntAttr);
376
- }
377
- }
378
- (0, _model.forEachProperty)(newEnt, copyProp);
379
- return ent;
380
- }
381
- function updateEntAttributes(ent, newEnt, attrs) {
382
- var updatedEnt = updateEntNonEmbeddableAttrbibutes(ent, newEnt),
383
- i;
384
- for (i = 0; i < attrs.length; i++) {
385
- var attributeName = attrs[i];
386
- updatedEnt[attributeName](newEnt[attributeName]());
387
- }
388
- return updatedEnt;
389
- }
390
- function ignoreAttributesUpdateEnt(ent, newEnt, ignoredAttrs) {
391
- /* Update an entity with new values from an updated entity
392
- but ignore specified attributes
393
- */
394
- var updatedEnt = newEnt,
395
- i;
396
- for (i = 0; i < ignoredAttrs.length; i++) {
397
- var attributeName = ignoredAttrs[i];
398
- updatedEnt[attributeName](ent[attributeName]());
399
- }
400
- return updatedEnt;
401
- }
402
- function getCookie(name, defaultValue) {
403
- var searchPrefix = name + '=',
404
- cookies = document.cookie.split(';'),
405
- i,
406
- cookie;
407
- for (i = 0; i < cookies.length; ++i) {
408
- cookie = cookies[i];
409
- cookie = cookie.replace(/^\s*/, '');
410
- if (cookie.indexOf(searchPrefix) === 0) {
411
- return cookie.substring(searchPrefix.length, cookie.length);
412
- }
413
- }
414
- if ((0, _helpers.isUndefined)(defaultValue)) {
415
- throw 'no such cookie present';
416
- } else {
417
- return defaultValue;
418
- }
419
- }
420
- function getCartCookie(storeId) {
421
- var idAndToken = getCookie('cart-' + String(storeId), null);
422
- return idAndToken ? idAndToken.split(',') : null;
423
- }
424
- function setSessionCookie(name, value, domain) {
425
- var cookie = name + '=' + value;
426
- if (!!domain) {
427
- // remove port, if it exists
428
- var n = domain.indexOf(':');
429
- domain = domain.substring(0, n != -1 ? n : domain.length);
430
- // remove trailing slash and path, if they exists
431
- n = domain.indexOf('/');
432
- domain = domain.substring(0, n != -1 ? n : domain.length);
433
- cookie += '; Domain=' + domain;
434
- } else {
435
- cookie += '; Domain=' + '.' + location.hostname;
436
- }
437
- cookie += '; path=/';
438
- document.cookie = cookie;
439
- }
440
- function setCartCookie(storeId, cart, domain) {
441
- var cookieValue = cart ? cart.id() + ',' + cart.token() : '';
442
- setSessionCookie('cart-' + String(storeId), cookieValue, domain);
443
- }
444
- function logout() {
445
- if (Boolean((0, _helpers.getGlobal)().currentSession)) {
446
- (0, _helpers.getGlobal)().currentSession.remove(_helpers.id, _helpers.id);
447
- (0, _helpers.getGlobal)().loggedInUser = null;
448
- (0, _helpers.getGlobal)().currentSession = null;
449
- }
450
- }
451
- function removeUnstoredFiles(files, removeAll) {
452
- var count = 1,
453
- i;
454
- if (Boolean(removeAll)) {
455
- count = files.filter(function (file) {
456
- return (0, _helpers.isUndefinedOrNull)(file.id());
457
- }).length;
458
- }
459
- for (i = 0; i < count; i++) {
460
- files.splice(files.findIndex(function (obj) {
461
- return obj.id() === null;
462
- }), 1);
463
- }
464
- return files;
465
- }
466
- function toUnix(date) {
467
- return Math.floor(date.getTime() / 1000);
468
- }
469
- function forquoteEdit(rights) {
470
- var forbitEdit = false;
471
- if (rights.indexOf(rights.get("canEdit")) === -1) {
472
- forbitEdit = true;
473
- }
474
- return forbitEdit;
475
- }
476
- function forquoteDelete(rights) {
477
- var forbitDelete = false;
478
- if (rights.indexOf(rights.get("canDelete")) === -1) {
479
- forbitDelete = true;
480
- }
481
- return forbitDelete;
482
- }
483
- function getRights(data) {
484
- var return_rights;
485
- if (data.rights !== undefined && data.rights !== null) {
486
- return_rights = data.rights;
487
- } else {
488
- return_rights = DEFAULT_RIGHTS;
489
- }
490
- return return_rights;
491
- }
492
- function canEditAttributes(rights) {
493
- var canEdit = false;
494
- if (rights.indexOf(rights.get("canEdit")) !== -1) {
495
- canEdit = true;
496
- }
497
- return canEdit;
498
- }
499
- function editAttributes(rights) {
500
- var disableCommand = '';
501
- if (!canEditAttributes(rights)) {
502
- disableCommand += " disabled=disabled ";
503
- }
504
- return disableCommand;
505
- }
506
- function getQuote(productId, quantity, success, error) {
507
- var request = new _model.Request(),
508
- data = new _dictionary.Dictionary();
509
- request.resource('/estimate/');
510
- request.method('POST');
511
- data.add('product', productId);
512
- data.add('quantity', quantity);
513
- request.query().add('skip_rights', true);
514
- request.data().merge(data);
515
- function handleResponse(status, data) {
516
- if (status === 200) {
517
- success(data);
518
- } else {
519
- error(data);
520
- }
521
- }
522
- function handleError() {
523
- error({
524
- message: 'could not connect to server',
525
- errorCode: 0
526
- });
527
- }
528
- request.responseHandler(handleResponse).errorHandler(handleError);
529
- request.send();
530
- }
531
- function getJobQuote(job, success, error) {
532
- var slimProduct = new _product.Product().id(job.product().id()),
533
- slimJob = job.domain(new _domain.Domain()).product(slimProduct),
534
- request = new _model.Request(),
535
- data = (0, _model.serialise)(slimJob)[0];
536
- request.resource('/specialised-order-estimate/');
537
- request.method('POST');
538
- request.data().merge(data);
539
- request.query().add('skip_rights', true);
540
- // add this to helping backend to know what the product id is
541
- request.query().add('product_id', job.product().id());
542
- function handleResponse(status, data) {
543
- if (status === 201) {
544
- success(data);
545
- } else {
546
- error(data);
547
- }
548
- }
549
- function handleError() {
550
- error({
551
- message: 'could not connect to server',
552
- errorCode: 0
553
- });
554
- }
555
- request.responseHandler(handleResponse).errorHandler(handleError);
556
- request.send();
557
- }
558
- function initSessionByToken(tokenStringForUser, success, error, embed) {
559
- if (!(0, _helpers.getGlobal)().currentSession) {
560
- (0, _helpers.getGlobal)().currentSession = new _session.Session();
561
- }
562
- if (!embed) {
563
- embed = {};
564
- }
565
- (0, _helpers.getGlobal)().currentSession.token(tokenStringForUser).get(success, error, {
566
- 'user': embed
567
- });
568
- }
569
- function getCurrentUser(success, error, embed) {
570
- var tokenStringForUser;
571
- if (!!(0, _helpers.getGlobal)().loggedInUser && !embed) {
572
- success((0, _helpers.getGlobal)().loggedInUser);
573
- return;
574
- }
575
- function haveToken(token) {
576
- (0, _helpers.getGlobal)().loggedInUser = token.user();
577
- success((0, _helpers.getGlobal)().loggedInUser);
578
- }
579
- try {
580
- tokenStringForUser = getCookie('session_token');
581
- } catch (e) {
582
- error(e);
583
- }
584
- if (Boolean(tokenStringForUser)) {
585
- initSessionByToken(tokenStringForUser, haveToken, error, embed);
586
- }
587
- }
588
- function checkUserInfo(args) {
589
- var request = new _model.Request(),
590
- data = new _dictionary.Dictionary();
591
- function handleResponse(status, data) {
592
- if (status === 200) {
593
- args.success(data);
594
- } else {
595
- args.error(data);
596
- }
597
- }
598
- function handleError() {
599
- args.error({
600
- message: 'could not connect to server',
601
- errorCode: 0
602
- });
603
- }
604
- if (isNaN(args.user_id)) {
605
- args.error({
606
- message: 'User id is not a number.'
607
- });
608
- } else {
609
- data.add('subdomain', args.subdomain);
610
- data.add('name', args.user_name);
611
- data.add('email_address', args.user_email);
612
- request.data().merge(data);
613
- request.resource('/user-check/' + args.user_id + '/');
614
- request.method('POST');
615
- request.responseHandler(handleResponse).errorHandler(handleError);
616
- request.send();
617
- }
618
- }
619
- function getUpdateNotifications(optionsDict) {
620
- var request = new _model.Request(),
621
- data = new _dictionary.Dictionary();
622
- function checkDictKey(optionsDict, key, checker, alerter) {
623
- var checkObject = Object.prototype.hasOwnProperty.call(optionsDict, key) ? optionsDict[key] : [];
624
- if (checker(checkObject)) {
625
- return checkObject;
626
- }
627
- alerter();
628
- return null;
629
- }
630
- function checkDictKeyForArray(optionsDict, key) {
631
- return checkDictKey(optionsDict, key, _helpers.isArray, function () {
632
- alert(key + " is not an array.");
633
- });
634
- }
635
- function checkDictKeyForDict(optionsDict, key) {
636
- return checkDictKey(optionsDict, key, isJSON, function () {
637
- alert(key + " is not a dictionary.");
638
- });
639
- }
640
- function checkDictKeyForFunction(optionsDict, key) {
641
- return checkDictKey(optionsDict, key, isFunction, function () {
642
- alert(key + " is not a function.");
643
- });
644
- }
645
- function serlialiseEntitiesArray(optionsDict, key) {
646
- var entitiesArray = checkDictKeyForArray(optionsDict, key),
647
- arrayWithObjects = [],
648
- entityObject,
649
- i;
650
- for (i = 0; i < entitiesArray.length; i++) {
651
- entityObject = entitiesArray[i];
652
- if (Boolean(entityObject)) {
653
- arrayWithObjects.push({
654
- type: entityObject.json,
655
- id: entityObject.id()
656
- });
657
- }
658
- }
659
- return arrayWithObjects;
660
- }
661
- request.resource('/notifications-check-update/');
662
- request.method('POST');
663
- data.add('sections', JSON.stringify(checkDictKeyForArray(optionsDict, 'sections')));
664
- data.add('entities', JSON.stringify(serlialiseEntitiesArray(optionsDict, 'entities')));
665
- data.add('notificationTypes', JSON.stringify(checkDictKeyForDict(optionsDict, 'notificationTypes')));
666
- request.data().merge(data);
667
- request.query().add('skip_rights', 'y');
668
- function handleResponse(status, data) {
669
- if (status === 200) {
670
- checkDictKeyForFunction(optionsDict, 'success')(data);
671
- } else {
672
- checkDictKeyForFunction(optionsDict, 'error')(data);
673
- }
674
- }
675
- function handleError() {
676
- alert('could not connect to server');
677
- }
678
- request.responseHandler(handleResponse).errorHandler(handleError);
679
- request.send();
680
- }
681
- function checkAndUpdateNotifications(related_object_id, section, senderId, success, error) {
682
- var request = new _model.Request(),
683
- data = new _dictionary.Dictionary();
684
- request.resource('/notifications-toast/');
685
- request.method('POST');
686
- data.add('related_object_id', related_object_id);
687
- data.add('section', section);
688
- data.add('sender_id', senderId);
689
- request.query().add('skip_rights', 'y');
690
- request.data().merge(data);
691
- function handleResponse(status, data) {
692
- if (status === 200) {
693
- success(data);
694
- } else {
695
- error(data);
696
- }
697
- }
698
- function handleError() {
699
- error({
700
- message: 'could not connect to server',
701
- errorCode: 0
702
- });
703
- }
704
- request.responseHandler(handleResponse).errorHandler(handleError);
705
- request.send();
706
- (0, _helpers.getGlobal)().merchiSubscriptionManager.subscribe([eventTypes.get('POST')], request.path(), "POST", handleResponse);
707
- }
708
- function escapeHtml(dangerousString) {
709
- var entityMap = {
710
- "&": "&amp;",
711
- "<": "&lt;",
712
- ">": "&gt;",
713
- '"': '&quot;',
714
- "'": '&#39;',
715
- "/": '&#x2F;'
716
- };
717
- return String(dangerousString).replace(/[&<>"'/]/g, function (s) {
718
- return entityMap[s];
719
- });
720
- }
721
- function getQueryStringValue(name) {
722
- if (_browserOrNode.isBrowser) {
723
- var query = window.location.search.substring(1),
724
- vars = query.split("&"),
725
- pair,
726
- i;
727
- for (i = 0; i < vars.length; i++) {
728
- pair = vars[i].split("=");
729
- if (pair[0] === name) {
730
- return decodeURIComponent(pair[1]);
731
- }
732
- }
733
- }
734
- return undefined;
735
- }
736
- function getUserIdByEmail(emailAddress, success, error) {
737
- var request = new _model.Request(),
738
- data = new _dictionary.Dictionary();
739
- request.resource('/user-check-email/');
740
- request.method('POST');
741
- data.add('email_address', emailAddress);
742
- request.data().merge(data);
743
- function handleResponse(status, data) {
744
- if (status === 200) {
745
- success(data);
746
- } else {
747
- error(status, data);
748
- }
749
- }
750
- request.responseHandler(handleResponse).errorHandler(error);
751
- request.send();
752
- }
753
- function placeOrder(clientId, quantity, product, address, variations, success, error) {
754
- var request = new _model.Request(),
755
- productId = product.id(),
756
- data = new _dictionary.Dictionary();
757
- data.add('client_id', clientId);
758
- data.add('quantity', quantity);
759
- data.add('product_id', productId);
760
- data.add('variation_notes', variations);
761
- if (address !== null) {
762
- data = (0, _model.serialise)(address, data)[0];
763
- }
764
- request.resource('/public-order/');
765
- request.method('POST');
766
- request.data().merge(data);
767
- function handleResponse(status, data) {
768
- if (status === 200) {
769
- success(data);
770
- } else {
771
- error(data);
772
- }
773
- }
774
- function handleError() {
775
- error({
776
- message: 'could not connect to server',
777
- errorCode: 0
778
- });
779
- }
780
- request.responseHandler(handleResponse).errorHandler(handleError);
781
- request.send();
782
- }
783
- function getProductShipmentOptions(productId, quantity, address, success, error) {
784
- var request = new _model.Request(),
785
- data = new _dictionary.Dictionary();
786
- data.add('quantity', quantity);
787
- data = (0, _model.serialise)(address, data, 'address')[0];
788
- request.resource("/products/".concat(productId, "/shipment_options/"));
789
- request.method('POST');
790
- request.data().merge(data);
791
- function handleResponse(status, data) {
792
- if (status === 200) {
793
- success(data);
794
- } else {
795
- error(data);
796
- }
797
- }
798
- function handleError() {
799
- error({
800
- message: 'could not connect to server',
801
- errorCode: 0
802
- });
803
- }
804
- request.responseHandler(handleResponse).errorHandler(handleError);
805
- request.send();
806
- }
807
- if (!(0, _helpers.getGlobal)().currentUser) getCurrentUser(_helpers.id, _helpers.id, currentUserEmbed);
808
- return {
809
- 'roles': _roles.roles,
810
- 'roleStrings': roleStrings,
811
- 'systemRoles': _roles.systemRoles,
812
- 'roleCssClass': roleCssClass,
813
- 'eventTypes': eventTypes,
814
- 'getGlobal': _helpers.getGlobal,
815
- 'logout': logout,
816
- 'canEditAttributes': canEditAttributes,
817
- 'editAttributes': editAttributes,
818
- 'forquoteEdit': forquoteEdit,
819
- 'getRights': getRights,
820
- 'forquoteDelete': forquoteDelete,
821
- 'DEFAULT_RIGHTS': DEFAULT_RIGHTS,
822
- 'priorityLevels': priorityLevels,
823
- 'URGENT_JOB_PRIORITY': priorityLevels.get('URGENT_JOB_PRIORITY'),
824
- 'HIGH_JOB_PRIORITY': priorityLevels.get('HIGH_JOB_PRIORITY'),
825
- 'MEDIUM_JOB_PRIORITY': priorityLevels.get('MEDIUM_JOB_PRIORITY'),
826
- 'LOW_JOB_PRIORITY': priorityLevels.get('LOW_JOB_PRIORITY'),
827
- 'priorityLevelsOptions': priorityLevelsOptions,
828
- 'PhoneNumber': _phone_number.PhoneNumber,
829
- 'Dictionary': _dictionary.Dictionary,
830
- 'phoneNumbers': new _phone_number.PhoneNumbers(),
831
- 'EmailAddress': _email_address.EmailAddress,
832
- 'emailAddresses': new _email_address.EmailAddresses(),
833
- 'EmailCounter': _email_counter.EmailCounter,
834
- 'emailCounters': new _email_counter.EmailCounters(),
835
- 'Address': _address.Address,
836
- 'addresses': new _address.Addresses(),
837
- 'User': _user.User,
838
- 'users': new _user.Users(),
839
- 'Domain': _domain.Domain,
840
- 'domains': new _domain.Domains(),
841
- 'DomainInvitation': _domain_invitation.DomainInvitation,
842
- 'Draft': _draft.Draft,
843
- 'drafts': new _draft.Drafts(),
844
- 'DraftComment': _draft_comment.DraftComment,
845
- 'DraftTemplate': _draft_template.DraftTemplate,
846
- 'ExchangeRate': _exchange_rate.ExchangeRate,
847
- 'exchangeRates': new _exchange_rate.ExchangeRates(),
848
- 'Theme': _theme.Theme,
849
- 'themes': new _theme.Themes(),
850
- 'EnrolledDomain': _enrolled_domain.EnrolledDomain,
851
- 'enrolledDomains': new _enrolled_domain.EnrolledDomains(),
852
- 'AutomaticPaymentRelationship': _automatic_payment_relationship.AutomaticPaymentRelationship,
853
- 'automaticPaymentRelationships': new _automatic_payment_relationship.AutomaticPaymentRelationships(),
854
- 'Company': _company.Company,
855
- 'companies': new _company.Companies(),
856
- 'CompanyInvitation': _company_invitation.CompanyInvitation,
857
- 'companyInvitations': new _company_invitation.CompanyInvitations(),
858
- 'UserCompany': _user_company.UserCompany,
859
- 'Category': _category.Category,
860
- 'categories': new _category.Categories(),
861
- 'Component': _component.Component,
862
- 'components': new _component.Components(),
863
- 'ComponentTag': _component_tag.ComponentTag,
864
- 'componentTags': new _component_tag.ComponentTags(),
865
- 'DomainTag': _domain_tag.DomainTag,
866
- 'domainTags': new _domain_tag.DomainTags(),
867
- 'Product': _product.Product,
868
- 'products': new _product.Products(),
869
- 'ProductionComment': _production_comment.ProductionComment,
870
- 'Inventory': _inventory.Inventory,
871
- 'inventories': new _inventory.Inventories(),
872
- 'InventoryUnitVariation': _inventory_unit_variation.InventoryUnitVariation,
873
- 'matchiingInventory': _matching_inventory.MatchingInventory,
874
- 'InternalTag': _internal_tag.InternalTag,
875
- 'internalTags': new _internal_tag.InternalTags(),
876
- 'Invoice': _invoice.Invoice,
877
- 'invoices': new _invoice.Invoices(),
878
- 'Job': _job.Job,
879
- 'jobs': new _job.Jobs(),
880
- 'JobComment': _job_comment.JobComment,
881
- 'Cart': _cart.Cart,
882
- 'CartItem': _cart_item.CartItem,
883
- 'Bank': _bank.Bank,
884
- 'QuoteItem': _quote_item.QuoteItem,
885
- 'QuoteItems': new _quote_item.QuoteItems(),
886
- 'Quote': _quote.Quote,
887
- 'Quotes': new _quote.Quotes(),
888
- 'Assignment': _assignment.Assignment,
889
- 'Assignments': new _assignment.Assignments(),
890
- 'File': _merchi_file.MerchiFile,
891
- 'files': new _merchi_file.MerchiFiles(),
892
- 'Backup': _backup.Backup,
893
- 'backups': new _backup.Backups(),
894
- 'removeUnstoredFiles': removeUnstoredFiles,
895
- 'Shipment': _shipment.Shipment,
896
- 'shipments': new _shipment.Shipments(),
897
- 'ShipmentMethod': _shipment_method.ShipmentMethod,
898
- 'shipmentMethods': new _shipment_method.ShipmentMethods(),
899
- 'ShipmentMethodVariation': _shipment_method_variation.ShipmentMethodVariation,
900
- 'shipmentMethodVariations': new _shipment_method_variation.ShipmentMethodVariations(),
901
- 'CountryTax': _country_tax.CountryTax,
902
- 'countryTaxes': new _country_tax.CountryTaxes(),
903
- 'Discount': _discount.Discount,
904
- 'DiscountGroups': _discount_group.DiscountGroup,
905
- 'SupplyDomain': _supply_domain.SupplyDomain,
906
- 'SupplyDomains': new _supply_domain.SupplyDomains(),
907
- 'initSessionByToken': initSessionByToken,
908
- 'getCurrentUser': getCurrentUser,
909
- 'Payment': _payment.Payment,
910
- 'Item': _item.Item,
911
- 'Session': _session.Session,
912
- 'sessions': new _session.Sessions(),
913
- 'serialise': _model.serialise,
914
- 'SystemRole': _system_role.SystemRole,
915
- 'toJson': toJson,
916
- 'toJsonList': toJsonList,
917
- 'rights': rights,
918
- 'itemTypes': itemTypes,
919
- 'Request': _model.Request,
920
- 'STATUS': STATUS,
921
- 'GSTrate': GSTrate,
922
- 'Notification': _notification.Notification,
923
- 'notifications': new _notification.Notifications(),
924
- 'SubscriptionPlan': _subscription_plan.SubscriptionPlan,
925
- 'subscriptionPlans': new _subscription_plan.SubscriptionPlans(),
926
- 'VariationField': _variation_field.VariationField,
927
- 'Variation': _variation.Variation,
928
- 'VariationsGroup': _variations_group.VariationsGroup,
929
- 'VariationFieldsOption': _variation_fields_option.VariationFieldsOption,
930
- 'Menu': _menu.Menu,
931
- 'MenuItem': _menu_item.MenuItem,
932
- 'notificationTypes': _notification_types.notificationTypes,
933
- 'paymentTypes': _payment_types.paymentTypes,
934
- 'paymentTypeIds': _payment_types.paymentTypeIds,
935
- 'Page': _page.Page,
936
- 'toUnix': toUnix,
937
- 'id': _helpers.id,
938
- 'isUndefined': _helpers.isUndefined,
939
- 'isNull': _helpers.isNull,
940
- 'isUndefinedOrNull': _helpers.isUndefinedOrNull,
941
- 'indexOfEntityInArrayById': indexOfEntityInArrayById,
942
- 'indexOfEntityInArrayByName': indexOfEntityInArrayByName,
943
- 'jobStatusProduction': _job_status.jobStatusProduction,
944
- 'jobPriority': _job_status.jobPriority,
945
- 'notEmptyArray': _helpers.notEmptyArray,
946
- 'displayMoney': displayMoney,
947
- 'sortArrayByObjectKey': _helpers.sortArrayByObjectKey,
948
- 'fromJson': _model.fromJson,
949
- 'fromJsonList': _model.fromJsonList,
950
- 'setSessionCookie': setSessionCookie,
951
- 'setCartCookie': setCartCookie,
952
- 'getQuote': getQuote,
953
- 'checkAndUpdateNotifications': checkAndUpdateNotifications,
954
- 'escapeHtml': escapeHtml,
955
- 'getQueryStringValue': getQueryStringValue,
956
- 'NoTaxEntity': _country_tax.NoTaxEntity,
957
- 'notificationSectionCodes': _notification_types.notificationSectionCodes,
958
- 'notificationSectionClass': _notification_types.notificationSectionClass,
959
- 'notificationSectionIconClass': _notification_types.notificationSectionIconClass,
960
- 'notificationSection': _notification_types.notificationSection,
961
- 'notificationSectionKey': _notification_types.notificationSectionKey,
962
- 'notificationAvatar': notificationAvatar,
963
- 'fieldTypes': _field_types.fieldTypes,
964
- 'fieldTypesString': fieldTypesString,
965
- 'inputTypes': inputTypes,
966
- 'domainTypes': _domain_types.domainTypes,
967
- 'getCookie': getCookie,
968
- 'getCartCookie': getCartCookie,
969
- 'getUserIdByEmail': getUserIdByEmail,
970
- 'placeOrder': placeOrder,
971
- 'platformName': platformName,
972
- 'platformSellerDomain': platformSellerDomain,
973
- 'platformSellerDomainPlus': platformSellerDomainPlus,
974
- 'platformCopyright': platformCopyright,
975
- 'platformIcon': platformIcon,
976
- 'defaultUserAvatar': defaultUserAvatar,
977
- 'platformLogo': platformLogo,
978
- 'menuItemType': menuItemType,
979
- 'menuItemTypeCodes': menuItemTypeCodes,
980
- 'menuType': menuType,
981
- 'menuTypeCodes': menuTypeCodes,
982
- 'checkUserInfo': checkUserInfo,
983
- 'getJobQuote': getJobQuote,
984
- 'removeObjectFromArrayWithIntegerValue': _helpers.removeObjectFromArrayWithIntegerValue,
985
- 'shipmentCompanies': shipmentCompanies,
986
- 'generateUUID': _uuid.generateUUID,
987
- 'getUpdateNotifications': getUpdateNotifications,
988
- 'currentUserEmbed': currentUserEmbed,
989
- 'create': _model.create,
990
- 'copyEnt': copyEnt,
991
- 'copyEntIfNotNullOrUndefined': copyEntIfNotNullOrUndefined,
992
- 'entAsBlank': entAsBlank,
993
- 'cleanEntities': cleanEntities,
994
- 'userTypes': _user_types.userTypes,
995
- 'updateEntNonEmbeddableAttrbibutes': updateEntNonEmbeddableAttrbibutes,
996
- 'updateEntAttributes': updateEntAttributes,
997
- 'ignoreAttributesUpdateEnt': ignoreAttributesUpdateEnt,
998
- 'inventoryStatuses': inventoryStatuses,
999
- 'productTypes': _product_types.productTypes,
1000
- 'productTypesInts': _product_types.productTypesInts,
1001
- 'productTypesSeller': productTypesSeller,
1002
- 'getProductShipmentOptions': getProductShipmentOptions
1003
- };
1004
- }