merchi_sdk_js 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. package/dist/address.js +109 -0
  2. package/dist/assignment.js +175 -0
  3. package/dist/automatic_payment_relationship.js +72 -0
  4. package/dist/backup.js +32 -0
  5. package/dist/bank.js +25 -0
  6. package/dist/cart.js +133 -0
  7. package/dist/cart_item.js +71 -0
  8. package/dist/cart_shipment_group.js +23 -0
  9. package/dist/cart_shipment_quote.js +26 -0
  10. package/dist/category.js +68 -0
  11. package/dist/company.js +248 -0
  12. package/dist/company_invitation.js +70 -0
  13. package/dist/component.js +107 -0
  14. package/dist/component_tag.js +60 -0
  15. package/dist/component_version.js +21 -0
  16. package/dist/country_tax.js +93 -0
  17. package/dist/dictionary.js +130 -0
  18. package/dist/discount.js +22 -0
  19. package/dist/discount_group.js +18 -0
  20. package/dist/domain.js +245 -0
  21. package/dist/domain_invitation.js +17 -0
  22. package/dist/domain_tag.js +87 -0
  23. package/dist/domain_types.js +22 -0
  24. package/dist/draft.js +97 -0
  25. package/dist/draft_comment.js +45 -0
  26. package/dist/draft_template.js +39 -0
  27. package/dist/email_address.js +34 -0
  28. package/dist/email_counter.js +47 -0
  29. package/dist/enrolled_domain.js +88 -0
  30. package/dist/exchange_rate.js +66 -0
  31. package/dist/field_types.js +19 -0
  32. package/dist/helpers.js +86 -0
  33. package/dist/internal_tag.js +98 -0
  34. package/dist/inventory.js +100 -0
  35. package/dist/inventory_unit_variation.js +19 -0
  36. package/dist/invoice.js +225 -0
  37. package/dist/invoice_types.js +11 -0
  38. package/dist/item.js +25 -0
  39. package/dist/job.js +536 -0
  40. package/dist/job_comment.js +45 -0
  41. package/dist/job_status.js +47 -0
  42. package/dist/matching_inventory.js +21 -0
  43. package/dist/md5.js +149 -0
  44. package/dist/menu.js +37 -0
  45. package/dist/menu_item.js +24 -0
  46. package/dist/merchi.js +1004 -0
  47. package/dist/merchi_file.js +165 -0
  48. package/dist/model.js +753 -0
  49. package/dist/notification.js +151 -0
  50. package/dist/notification_types.js +199 -0
  51. package/dist/output.cjs.js +31317 -0
  52. package/dist/output.esm.js +31312 -0
  53. package/dist/page.js +41 -0
  54. package/dist/payment.js +32 -0
  55. package/dist/payment_device.js +21 -0
  56. package/dist/payment_types.js +20 -0
  57. package/dist/phone_number.js +37 -0
  58. package/dist/product.js +288 -0
  59. package/dist/product_types.js +32 -0
  60. package/dist/production_comment.js +44 -0
  61. package/dist/quote.js +91 -0
  62. package/dist/quote_item.js +59 -0
  63. package/dist/roles.js +29 -0
  64. package/dist/seo_domain_page.js +42 -0
  65. package/dist/session.js +103 -0
  66. package/dist/set.js +29 -0
  67. package/dist/shipment.js +181 -0
  68. package/dist/shipment_item.js +17 -0
  69. package/dist/shipment_item_fulfillment.js +17 -0
  70. package/dist/shipment_method.js +81 -0
  71. package/dist/shipment_method_variation.js +38 -0
  72. package/dist/subscription_plan.js +75 -0
  73. package/dist/supply_domain.js +65 -0
  74. package/dist/system_role.js +12 -0
  75. package/dist/theme.js +180 -0
  76. package/dist/theme_css_setting.js +61 -0
  77. package/dist/theme_status.js +11 -0
  78. package/dist/user.js +409 -0
  79. package/dist/user_company.js +19 -0
  80. package/dist/user_types.js +23 -0
  81. package/dist/uuid.js +12 -0
  82. package/dist/variation.js +233 -0
  83. package/dist/variation_field.js +233 -0
  84. package/dist/variation_fields_option.js +41 -0
  85. package/dist/variation_option.js +62 -0
  86. package/dist/variations_group.js +43 -0
  87. package/dist/white_label_accessibilities.js +11 -0
  88. package/package.json +30 -0
  89. package/src/address.js +107 -0
  90. package/src/assignment.js +165 -0
  91. package/src/automatic_payment_relationship.js +65 -0
  92. package/src/backup.js +29 -0
  93. package/src/bank.js +21 -0
  94. package/src/cart.js +131 -0
  95. package/src/cart_item.js +71 -0
  96. package/src/cart_shipment_group.js +20 -0
  97. package/src/cart_shipment_quote.js +23 -0
  98. package/src/category.js +62 -0
  99. package/src/company.js +267 -0
  100. package/src/company_invitation.js +63 -0
  101. package/src/component.js +100 -0
  102. package/src/component_tag.js +53 -0
  103. package/src/component_version.js +17 -0
  104. package/src/country_tax.js +89 -0
  105. package/src/dictionary.js +135 -0
  106. package/src/discount.js +19 -0
  107. package/src/discount_group.js +15 -0
  108. package/src/domain.js +254 -0
  109. package/src/domain_invitation.js +13 -0
  110. package/src/domain_tag.js +79 -0
  111. package/src/domain_types.js +18 -0
  112. package/src/draft.js +92 -0
  113. package/src/draft_comment.js +41 -0
  114. package/src/draft_template.js +35 -0
  115. package/src/email_address.js +27 -0
  116. package/src/email_counter.js +42 -0
  117. package/src/enrolled_domain.js +79 -0
  118. package/src/exchange_rate.js +61 -0
  119. package/src/field_types.js +15 -0
  120. package/src/helpers.js +81 -0
  121. package/src/internal_tag.js +90 -0
  122. package/src/inventory.js +99 -0
  123. package/src/inventory_unit_variation.js +18 -0
  124. package/src/invoice.js +224 -0
  125. package/src/invoice_types.js +7 -0
  126. package/src/item.js +22 -0
  127. package/src/job.js +616 -0
  128. package/src/job_comment.js +41 -0
  129. package/src/job_status.js +51 -0
  130. package/src/matching_inventory.js +17 -0
  131. package/src/md5.js +162 -0
  132. package/src/menu.js +32 -0
  133. package/src/menu_item.js +22 -0
  134. package/src/merchi.js +1074 -0
  135. package/src/merchi_file.js +163 -0
  136. package/src/model.js +820 -0
  137. package/src/notification.js +153 -0
  138. package/src/notification_types.js +246 -0
  139. package/src/page.js +38 -0
  140. package/src/payment.js +32 -0
  141. package/src/payment_device.js +17 -0
  142. package/src/payment_types.js +18 -0
  143. package/src/phone_number.js +30 -0
  144. package/src/product.js +309 -0
  145. package/src/product_types.js +28 -0
  146. package/src/production_comment.js +40 -0
  147. package/src/quote.js +89 -0
  148. package/src/quote_item.js +51 -0
  149. package/src/roles.js +27 -0
  150. package/src/seo_domain_page.js +35 -0
  151. package/src/session.js +102 -0
  152. package/src/set.js +28 -0
  153. package/src/shipment.js +191 -0
  154. package/src/shipment_item.js +13 -0
  155. package/src/shipment_item_fulfillment.js +13 -0
  156. package/src/shipment_method.js +73 -0
  157. package/src/shipment_method_variation.js +34 -0
  158. package/src/subscription_plan.js +68 -0
  159. package/src/supply_domain.js +60 -0
  160. package/src/system_role.js +8 -0
  161. package/src/theme.js +188 -0
  162. package/src/theme_css_setting.js +54 -0
  163. package/src/theme_status.js +6 -0
  164. package/src/user.js +442 -0
  165. package/src/user_company.js +15 -0
  166. package/src/user_types.js +19 -0
  167. package/src/uuid.js +3 -0
  168. package/src/variation.js +257 -0
  169. package/src/variation_field.js +261 -0
  170. package/src/variation_fields_option.js +41 -0
  171. package/src/variation_option.js +59 -0
  172. package/src/variations_group.js +43 -0
  173. package/src/white_label_accessibilities.js +6 -0
package/dist/model.js ADDED
@@ -0,0 +1,753 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Request = Request;
7
+ exports.addPropertyTo = addPropertyTo;
8
+ exports.create = create;
9
+ exports.deleteOne = deleteOne;
10
+ exports.enumerateFiles = enumerateFiles;
11
+ exports.forEachProperty = forEachProperty;
12
+ exports.fromJson = fromJson;
13
+ exports.fromJsonList = fromJsonList;
14
+ exports.getList = getList;
15
+ exports.getOne = getOne;
16
+ exports.patchOne = patchOne;
17
+ exports.recoverOne = recoverOne;
18
+ exports.serialise = serialise;
19
+ var _helpers = require("./helpers.js");
20
+ var _dictionary = require("./dictionary.js");
21
+ var _set = require("./set.js");
22
+ var _axios = _interopRequireDefault(require("axios"));
23
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
24
+ function Request() {
25
+ var server = (0, _helpers.getGlobal)().merchiBackendUri,
26
+ version = 'v6',
27
+ method = 'GET',
28
+ resource = '/',
29
+ query = new _dictionary.Dictionary(),
30
+ data = new _dictionary.Dictionary(),
31
+ files = new _dictionary.Dictionary(),
32
+ responseHandler = _helpers.id,
33
+ errorHandler = _helpers.id,
34
+ contentType = null,
35
+ username = null,
36
+ password = null;
37
+ this.server = function (value) {
38
+ if ((0, _helpers.isUndefined)(value)) {
39
+ return server;
40
+ }
41
+ server = value;
42
+ return this;
43
+ };
44
+ this.version = function (value) {
45
+ if ((0, _helpers.isUndefined)(value)) {
46
+ return version;
47
+ }
48
+ version = value;
49
+ return this;
50
+ };
51
+ this.method = function (value) {
52
+ if ((0, _helpers.isUndefined)(value)) {
53
+ return method;
54
+ }
55
+ method = value;
56
+ return this;
57
+ };
58
+ this.resource = function (value) {
59
+ if ((0, _helpers.isUndefined)(value)) {
60
+ return resource;
61
+ }
62
+ resource = value;
63
+ return this;
64
+ };
65
+ this.query = function () {
66
+ return query;
67
+ };
68
+ this.data = function () {
69
+ return data;
70
+ };
71
+ this.files = function (value) {
72
+ if ((0, _helpers.isUndefined)(value)) {
73
+ return files;
74
+ }
75
+ files = value;
76
+ return this;
77
+ };
78
+ this.responseHandler = function (value) {
79
+ if ((0, _helpers.isUndefined)(value)) {
80
+ return responseHandler;
81
+ }
82
+ responseHandler = value;
83
+ return this;
84
+ };
85
+ this.errorHandler = function (value) {
86
+ if ((0, _helpers.isUndefined)(value)) {
87
+ return errorHandler;
88
+ }
89
+ errorHandler = value;
90
+ return this;
91
+ };
92
+ this.contentType = function (value) {
93
+ if ((0, _helpers.isUndefined)(value)) {
94
+ return contentType;
95
+ }
96
+ contentType = value;
97
+ return this;
98
+ };
99
+ this.username = function (value) {
100
+ if ((0, _helpers.isUndefined)(value)) {
101
+ return username;
102
+ }
103
+ username = value;
104
+ return this;
105
+ };
106
+ this.password = function (value) {
107
+ if ((0, _helpers.isUndefined)(value)) {
108
+ return password;
109
+ }
110
+ password = value;
111
+ return this;
112
+ };
113
+ this.p2pSupported = function () {
114
+ return false;
115
+ };
116
+ this.url = function () {
117
+ return this.server() + this.path();
118
+ };
119
+ this.path = function () {
120
+ var url = this.version();
121
+ url += this.resource();
122
+ if (Boolean((0, _helpers.getGlobal)().currentSession) && Boolean((0, _helpers.getGlobal)().currentSession.token())) {
123
+ this.query().add('session_token', (0, _helpers.getGlobal)().currentSession.token());
124
+ }
125
+ if (this.query().count() > 0) {
126
+ url += '?' + this.query().toUriEncoding();
127
+ }
128
+ return url;
129
+ };
130
+ this.send = function () {
131
+ var self = this,
132
+ allData,
133
+ params;
134
+ allData = self.data();
135
+ allData.merge(self.files());
136
+ params = {
137
+ 'url': self.url(),
138
+ 'data': allData.toFormData(),
139
+ 'method': self.method()
140
+ };
141
+ if (self.username() !== null) {
142
+ params.auth = {
143
+ username: self.username(),
144
+ password: self.password()
145
+ };
146
+ }
147
+ if (self.contentType() !== null) {
148
+ params.headers = {
149
+ 'Content-Type': self.contentType()
150
+ };
151
+ }
152
+ (0, _axios["default"])(params).then(function (response) {
153
+ return handleResponse(response);
154
+ })["catch"](function (error) {
155
+ return handleError(error);
156
+ });
157
+ function handleResponse(response) {
158
+ var func = self.responseHandler();
159
+ var argCount = func.length;
160
+ var data = response.data;
161
+ if (argCount > 1) {
162
+ func(response.status, data);
163
+ } else {
164
+ func(response.data);
165
+ }
166
+ }
167
+ function handleError(error) {
168
+ var func = self.errorHandler();
169
+ var argCount = func.length;
170
+ if (argCount > 1) {
171
+ func(error.status, error);
172
+ } else {
173
+ func(data);
174
+ }
175
+ }
176
+ };
177
+ }
178
+ function forEachProperty(obj, procedure) {
179
+ obj._properties.each(function (property) {
180
+ // elem in _propertiesSet is array
181
+ // 0 is name, 1 is type
182
+ procedure(property[0], property[1]);
183
+ });
184
+ }
185
+ function fromJson(model, json, options) {
186
+ var defaults = {
187
+ makesDirty: true
188
+ };
189
+ options = Object.assign({}, defaults, options);
190
+ forEachProperty(model, function (propName, Type) {
191
+ try {
192
+ var received = json[propName],
193
+ parsed;
194
+ if (!Type || typeof received === 'number') {
195
+ // Prop is untyped or only id received
196
+ model[propName](received, {
197
+ makesDirty: options.makesDirty
198
+ });
199
+ } else {
200
+ // Prop is typed and other thing rather than
201
+ // single id received
202
+ if (received instanceof Array) {
203
+ if (received.length > 0 && received[0] instanceof Object) {
204
+ // response has embed obj
205
+ parsed = fromJsonList(new Type(), received, options);
206
+ } else {
207
+ // response is id array
208
+ parsed = received;
209
+ }
210
+ } else {
211
+ // Embed Object received
212
+ parsed = fromJson(new Type(), received, options);
213
+ }
214
+ model[propName](parsed, {
215
+ makesDirty: options.makesDirty
216
+ });
217
+ }
218
+ } catch (ignore) {}
219
+ });
220
+ model.rights = json.rights;
221
+ return model;
222
+ }
223
+ function fromJsonList(obj, json, options) {
224
+ var result = [],
225
+ list,
226
+ i,
227
+ single;
228
+ var defaults = {
229
+ makesDirty: true
230
+ };
231
+ options = Object.assign({}, defaults, options);
232
+
233
+ // When request plural eg /users, it gives typed json list
234
+ // But when request embed data, annonymous json list returned
235
+ if (json.constructor === Array) {
236
+ // Embed data process
237
+ list = json;
238
+ for (i = 0; i < list.length; ++i) {
239
+ single = new obj.constructor();
240
+ result.push(fromJson(single, list[i], options));
241
+ }
242
+ return result;
243
+ }
244
+ // Plural request eg /users
245
+ list = json[obj.json];
246
+ for (i = 0; i < list.length; ++i) {
247
+ single = new obj.single();
248
+ result.push(fromJson(single, list[i][single.json], options));
249
+ }
250
+
251
+ // Append meta data for pagination,
252
+ // workaroundbackward compatibility
253
+ result.meta = {
254
+ available: json.available,
255
+ count: json.count,
256
+ canCreate: json.canCreate,
257
+ limit: json.limit,
258
+ offset: json.offset
259
+ };
260
+ return result;
261
+ }
262
+ function getList(resource, success, error, parameters, withUpdates) {
263
+ var request = new Request();
264
+ request.resource(resource + '/').method('GET');
265
+ request.responseHandler(success).errorHandler(error);
266
+ if ((0, _helpers.notEmpty)(parameters.cartToken)) {
267
+ request.query().add('cart_token', parameters.cartToken);
268
+ }
269
+ if ((0, _helpers.notEmpty)(parameters.offset)) {
270
+ request.query().add('offset', parameters.offset);
271
+ }
272
+ if ((0, _helpers.notEmpty)(parameters.limit)) {
273
+ request.query().add('limit', parameters.limit);
274
+ }
275
+ if ((0, _helpers.notEmpty)(parameters.q)) {
276
+ request.query().add('q', parameters.q);
277
+ }
278
+ if ((0, _helpers.notEmpty)(parameters.sort)) {
279
+ request.query().add('sort', parameters.sort);
280
+ }
281
+ if ((0, _helpers.notEmpty)(parameters.order)) {
282
+ request.query().add('order', parameters.order);
283
+ }
284
+ if ((0, _helpers.notEmpty)(parameters.tab)) {
285
+ request.query().add('tab', parameters.tab);
286
+ }
287
+ if ((0, _helpers.notEmpty)(parameters.as)) {
288
+ request.query().add('as', parameters.as);
289
+ }
290
+ if (!parameters.withRights) {
291
+ request.query().add('skip_rights', 'y');
292
+ }
293
+ if (parameters.embed && parameters.embed.constructor === Object) {
294
+ request.query().add('embed', JSON.stringify(parameters.embed));
295
+ }
296
+ if ((0, _helpers.notEmpty)(parameters.state)) {
297
+ request.query().add('state', parameters.state);
298
+ }
299
+ if ((0, _helpers.notEmpty)(parameters.categoryId)) {
300
+ request.query().add('category_id', parameters.categoryId);
301
+ }
302
+ if ((0, _helpers.notEmpty)(parameters.platformCategoryId)) {
303
+ request.query().add('platform_category_id', parameters.platformCategoryId);
304
+ }
305
+ if ((0, _helpers.notEmpty)(parameters.groupBuyForJobId)) {
306
+ request.query().add('group_buy_for_job_id', parameters.groupBuyForJobId);
307
+ }
308
+ if ((0, _helpers.notEmpty)(parameters.inDomain)) {
309
+ request.query().add('in_domain', parameters.inDomain);
310
+ }
311
+ if ((0, _helpers.notEmpty)(parameters.inDomainName)) {
312
+ request.query().add('in_domain_name', parameters.inDomainName);
313
+ }
314
+ if (parameters.inDomainRoles) {
315
+ request.query().add('in_domain_roles', JSON.stringify(parameters.inDomainRoles));
316
+ }
317
+ if (parameters.asRole) {
318
+ request.query().add('as_role', JSON.stringify(parameters.asRole));
319
+ }
320
+ if (parameters.groupBuyOnly) {
321
+ request.query().add('group_buy_only', JSON.stringify(parameters.groupBuyOnly));
322
+ }
323
+ if (parameters.publicOnly) {
324
+ request.query().add('public_only', JSON.stringify(parameters.publicOnly));
325
+ }
326
+ if (parameters.isPrivate) {
327
+ request.query().add('is_private', JSON.stringify(parameters.isPrivate));
328
+ }
329
+ if (parameters.managedOnly) {
330
+ request.query().add('managed_only', JSON.stringify(parameters.managedOnly));
331
+ }
332
+ if (parameters.doesNotHaveAdminDomain) {
333
+ request.query().add('does_not_have_admin_domain', JSON.stringify(parameters.doesNotHaveAdminDomain));
334
+ }
335
+ if (parameters.teamOnly) {
336
+ request.query().add('team_only', JSON.stringify(parameters.teamOnly));
337
+ }
338
+ if (parameters.clientOnly) {
339
+ request.query().add('client_only', JSON.stringify(parameters.clientOnly));
340
+ }
341
+ if (parameters.memberOnly) {
342
+ request.query().add('member_only', JSON.stringify(parameters.memberOnly));
343
+ }
344
+ if (parameters.merchiOnly) {
345
+ request.query().add('merchi_only', JSON.stringify(parameters.merchiOnly));
346
+ }
347
+ if (parameters.supplierResellOnly) {
348
+ request.query().add('supplier_resell_only', JSON.stringify(parameters.supplierResellOnly));
349
+ }
350
+ if (parameters.inbound) {
351
+ request.query().add('inbound', JSON.stringify(parameters.inbound));
352
+ }
353
+ if (parameters.isMaster) {
354
+ request.query().add('is_master', JSON.stringify(parameters.isMaster));
355
+ }
356
+ if (parameters.domainRoles) {
357
+ request.query().add('domain_roles', parameters.domainRoles);
358
+ }
359
+ if (parameters.domainTypes) {
360
+ request.query().add('domain_types', parameters.domainTypes);
361
+ }
362
+ if (parameters.entityTypes) {
363
+ request.query().add('entity_types', parameters.entityTypes);
364
+ }
365
+ if (parameters.productTypes) {
366
+ request.query().add('product_types', parameters.productTypes);
367
+ }
368
+ if (parameters.masterProduct) {
369
+ request.query().add('master_product', parameters.masterProduct);
370
+ }
371
+ if (parameters.managedDomainsOnly) {
372
+ request.query().add('managed_domains_only', JSON.stringify(parameters.managedDomainsOnly));
373
+ }
374
+ if (parameters.businessDomainsOnly) {
375
+ request.query().add('business_domains_only', JSON.stringify(parameters.businessDomainsOnly));
376
+ }
377
+ if ((0, _helpers.notEmpty)(parameters.dateFrom)) {
378
+ request.query().add('date_from', parameters.dateFrom);
379
+ }
380
+ if ((0, _helpers.notEmpty)(parameters.dateTo)) {
381
+ request.query().add('date_to', parameters.dateTo);
382
+ }
383
+ if ((0, _helpers.notEmpty)(parameters.relatedAssignment)) {
384
+ request.query().add('related_assignment', parameters.relatedAssignment);
385
+ }
386
+ if ((0, _helpers.notEmpty)(parameters.relatedDraft)) {
387
+ request.query().add('related_draft', parameters.relatedDraft);
388
+ }
389
+ if ((0, _helpers.notEmpty)(parameters.relatedJob)) {
390
+ request.query().add('related_job', parameters.relatedJob);
391
+ }
392
+ if ((0, _helpers.notEmpty)(parameters.relatedProduct)) {
393
+ request.query().add('related_product', parameters.relatedProduct);
394
+ }
395
+ if ((0, _helpers.notEmpty)(parameters.jobNotifiable)) {
396
+ request.query().add('job_notifiable', parameters.jobNotifiable);
397
+ }
398
+ if ((0, _helpers.notEmpty)(parameters.notificationType)) {
399
+ request.query().add('notification_type', parameters.notificationType);
400
+ }
401
+ if ((0, _helpers.notEmpty)(parameters.notificationRecipient)) {
402
+ request.query().add('notification_recipient', parameters.notificationRecipient);
403
+ }
404
+ if ((0, _helpers.notEmpty)(parameters.notificationJob)) {
405
+ request.query().add('notification_job', parameters.notificationJob);
406
+ }
407
+ if ((0, _helpers.notEmpty)(parameters.relatedUser)) {
408
+ request.query().add('related_user', parameters.relatedUser);
409
+ }
410
+ if ((0, _helpers.notEmpty)(parameters.clientId)) {
411
+ request.query().add('client_id', parameters.clientId);
412
+ }
413
+ if ((0, _helpers.notEmpty)(parameters.clientCompanyId)) {
414
+ request.query().add('client_company_id', parameters.clientCompanyId);
415
+ }
416
+ if (parameters.savedByUser) {
417
+ request.query().add('saved_by_user', JSON.stringify(parameters.savedByUser));
418
+ }
419
+ if (parameters.receiverId) {
420
+ request.query().add('receiver_id', JSON.stringify(parameters.receiverId));
421
+ }
422
+ if ((0, _helpers.notEmpty)(parameters.queryString)) {
423
+ request.query().add('query_string', parameters.queryString);
424
+ }
425
+ if ((0, _helpers.notEmpty)(parameters.companyCustomerId)) {
426
+ request.query().add('company_customer_id', parameters.companyCustomerId);
427
+ }
428
+ if ((0, _helpers.notEmpty)(parameters.companyId)) {
429
+ request.query().add('company_id', parameters.companyId);
430
+ }
431
+ if ((0, _helpers.notEmpty)(parameters.companySupplierId)) {
432
+ request.query().add('company_supplier_id', parameters.companySupplierId);
433
+ }
434
+ if ((0, _helpers.notEmpty)(parameters.componentId)) {
435
+ request.query().add('component_id', parameters.componentId);
436
+ }
437
+ if ((0, _helpers.notEmpty)(parameters.section)) {
438
+ request.query().add('section', parameters.section);
439
+ }
440
+ if ((0, _helpers.notEmpty)(parameters.senderRole)) {
441
+ request.query().add('senderRole', parameters.section);
442
+ }
443
+ if ((0, _helpers.notEmpty)(parameters.isOrder)) {
444
+ request.query().add('is_order', parameters.isOrder);
445
+ }
446
+ if ((0, _helpers.notEmpty)(parameters.tags)) {
447
+ request.query().add('tags', parameters.tags);
448
+ }
449
+ if (parameters.tagsInternal) {
450
+ request.query().add('tags_internal', parameters.tagsInternal);
451
+ }
452
+ if (parameters.tagNames) {
453
+ request.query().add('tag_names', parameters.tagNames);
454
+ }
455
+ if ((0, _helpers.notEmpty)(parameters.exclude)) {
456
+ request.query().add('exclude', parameters.exclude);
457
+ }
458
+ if ((0, _helpers.notEmpty)(parameters.excludeComponents)) {
459
+ request.query().add('exclude_components', parameters.excludeComponents);
460
+ }
461
+ if ((0, _helpers.notEmpty)(parameters.excludeDomains)) {
462
+ request.query().add('exclude_domains', parameters.excludeDomains);
463
+ }
464
+ if ((0, _helpers.notEmpty)(parameters.includeOnly)) {
465
+ request.query().add('include_only', parameters.includeOnly);
466
+ }
467
+ if ((0, _helpers.notEmpty)(parameters.orClientId)) {
468
+ request.query().add('or_client_id', parameters.orClientId);
469
+ }
470
+ if ((0, _helpers.notEmpty)(parameters.shopifyOnly)) {
471
+ request.query().add('shopify_only', parameters.shopifyOnly);
472
+ }
473
+ if ((0, _helpers.notEmpty)(parameters.relatedComponent)) {
474
+ request.query().add('related_component', parameters.relatedComponent);
475
+ }
476
+ if ((0, _helpers.notEmpty)(parameters.originalOf)) {
477
+ request.query().add('original_of', parameters.originalOf);
478
+ }
479
+ request.send();
480
+ if (withUpdates) {
481
+ return (0, _helpers.getGlobal)().merchiSusubscriptionManager.subscribe(withUpdates, request.path(), "GET", function (statusCode, data) {
482
+ return success(JSON.parse(data));
483
+ });
484
+ }
485
+ return null;
486
+ }
487
+ function serialise(obj, existing, prefix, files, options) {
488
+ var result = new _dictionary.Dictionary(),
489
+ index,
490
+ excludeOld;
491
+ options = options ? options : {};
492
+ excludeOld = !!options.excludeOld;
493
+ if (Boolean(existing)) {
494
+ result = existing;
495
+ }
496
+ if (!files) {
497
+ files = [];
498
+ }
499
+ function appendData(name, value) {
500
+ if (!(0, _helpers.isUndefined)(value) && value !== null) {
501
+ if (Boolean(prefix)) {
502
+ result.add(prefix + '-' + name, value);
503
+ } else {
504
+ result.add(name, value);
505
+ }
506
+ }
507
+ }
508
+ if (Boolean(obj.fileData)) {
509
+ index = files.length;
510
+ files.push(obj.fileData);
511
+ appendData('fileDataIndex', index);
512
+ }
513
+ forEachProperty(obj, function (property, Type) {
514
+ var value = obj[property](),
515
+ i,
516
+ innerPrefix,
517
+ nested;
518
+ if (!(0, _helpers.isUndefined)(Type) && Boolean(Type)) {
519
+ // serialise relationship
520
+ var updatingOrder = obj._updatingOrder[property];
521
+ if (updatingOrder) {
522
+ appendData(property + '-*updateOrder', 'true');
523
+ }
524
+ if (value instanceof Array) {
525
+ var isDirty = false;
526
+ for (i = 0; i < value.length; i++) {
527
+ if (!!value[i]._isDirty) {
528
+ isDirty = true;
529
+ break;
530
+ }
531
+ }
532
+ if (excludeOld && !(obj._wantsUpdate[property] || isDirty)) {
533
+ return;
534
+ }
535
+ if (value && value.length === 0) {
536
+ appendData(property + '-count', 0);
537
+ }
538
+ // multiple remove entities
539
+ var childrenSerialised = 0;
540
+ for (i = 0; i < value.length; ++i) {
541
+ innerPrefix = property + '-' + i;
542
+ if (Boolean(prefix)) {
543
+ innerPrefix = prefix + '-' + innerPrefix;
544
+ }
545
+ var initialCount = result.count();
546
+ nested = serialise(value[i], result, innerPrefix, files, options);
547
+ if (result.count() > initialCount) {
548
+ childrenSerialised += 1;
549
+ }
550
+ result = nested[0];
551
+ files = nested[1];
552
+ if (childrenSerialised > 0) {
553
+ appendData(property + '-count', childrenSerialised);
554
+ }
555
+ }
556
+ } else if (Boolean(value)) {
557
+ // one remote entity
558
+ if (excludeOld && !(obj._wantsUpdate[property] || value._isDirty)) {
559
+ return;
560
+ }
561
+ innerPrefix = property + '-0';
562
+ if (Boolean(prefix)) {
563
+ innerPrefix = prefix + '-' + innerPrefix;
564
+ }
565
+ initialCount = result.count();
566
+ nested = serialise(value, result, innerPrefix, files, options);
567
+ if (result.count() > initialCount) {
568
+ appendData(property + '-count', 1);
569
+ }
570
+ result = nested[0];
571
+ files = nested[1];
572
+ }
573
+ } else {
574
+ // serialise scalar
575
+ if (excludeOld && !obj._wantsUpdate[property] && property !== 'id') {
576
+ return;
577
+ }
578
+ appendData(property, value);
579
+ }
580
+ });
581
+ return [result, files];
582
+ }
583
+ function markDirty(obj) {
584
+ /* mark this object, and recursively all objects that have refered to it,
585
+ as changed compared to the backend. */
586
+ var openSet = []; /* Queue (BFS) */
587
+ var closedSet = new _set.Set();
588
+ openSet.push(obj);
589
+ while (openSet.length > 0) {
590
+ var current = openSet.shift();
591
+ if (!closedSet.has(current)) {
592
+ current._isDirty = true;
593
+ closedSet.add(current);
594
+ current._backObjects.each(function (child) {
595
+ openSet.push(child);
596
+ });
597
+ }
598
+ }
599
+ }
600
+ function addPropertyTo(obj, propertyName, Type) {
601
+ obj._isMerchiEntity = true;
602
+ if (!Object.prototype.hasOwnProperty.call(obj, '_wantsUpdate')) {
603
+ obj._wantsUpdate = {};
604
+ }
605
+ obj._wantsUpdate[propertyName] = false;
606
+ if (!Object.prototype.hasOwnProperty.call(obj, '_isDirty')) {
607
+ obj._isDirty = false;
608
+ }
609
+ if (!Object.prototype.hasOwnProperty.call(obj, '_backObjects')) {
610
+ obj._backObjects = new _set.Set();
611
+ }
612
+ if (!Object.prototype.hasOwnProperty.call(obj, '_properties')) {
613
+ obj._properties = new _set.Set();
614
+ }
615
+ if (!Object.prototype.hasOwnProperty.call(obj, '_updatingOrder')) {
616
+ obj._updatingOrder = {};
617
+ }
618
+ var hiddenProperty = '_' + propertyName;
619
+ if ((0, _helpers.isUndefined)(Type)) {
620
+ Type = null;
621
+ }
622
+ obj._properties.add([propertyName, Type]);
623
+ obj[propertyName] = function (value, options) {
624
+ if ((0, _helpers.isUndefined)(options)) {
625
+ options = {};
626
+ }
627
+ if ((0, _helpers.isUndefined)(options.makesDirty)) {
628
+ options.makesDirty = true;
629
+ }
630
+ if ((0, _helpers.isUndefined)(options.updatingOrder)) {
631
+ options.updatingOrder = false;
632
+ }
633
+ if ((0, _helpers.isUndefined)(value)) {
634
+ return obj[hiddenProperty];
635
+ }
636
+ obj[hiddenProperty] = value;
637
+ if (options.makesDirty) {
638
+ obj._wantsUpdate[propertyName] = true;
639
+ markDirty(obj);
640
+ }
641
+ obj._updatingOrder[propertyName] = options.updatingOrder;
642
+ if (!!value && !!value._isMerchiEntity) {
643
+ value._backObjects.add(obj);
644
+ } else if (Array.isArray(value)) {
645
+ for (var i = 0; i < value.length; i++) {
646
+ var item = value[i];
647
+ if (!!item._isMerchiEntity) {
648
+ item._backObjects.add(obj);
649
+ }
650
+ }
651
+ }
652
+ return obj;
653
+ };
654
+ }
655
+ function patchOne(options) {
656
+ var request = new Request(),
657
+ id = options.id;
658
+ options.resource = options.resource || '';
659
+ options.id = options.id || '';
660
+ options.data = options.data || {};
661
+ options.success = options.success || id;
662
+ options.error = options.error || id;
663
+ options.files = options.files || new _dictionary.Dictionary();
664
+ request.resource(options.resource + '/' + options.id + '/').method('PATCH');
665
+ request.files(options.files);
666
+ request.data().merge(options.data);
667
+ if (options.embed && options.embed.constructor === Object) {
668
+ request.query().add('embed', JSON.stringify(options.embed));
669
+ }
670
+ if ((0, _helpers.notEmpty)(options.as_domain)) {
671
+ request.query().add('as_domain', options.as_domain);
672
+ }
673
+ if (options.cartToken) {
674
+ request.query().add('cart_token', options.cartToken);
675
+ }
676
+ if (!options.withRights) {
677
+ request.query().add('skip_rights', 'y');
678
+ }
679
+ request.responseHandler(options.success).errorHandler(options.error);
680
+ request.send();
681
+ }
682
+ function getOne(options) {
683
+ var request = new Request(),
684
+ error = options.error,
685
+ embed = options.embed;
686
+ request.resource(options.resource + '/' + options.id + '/').method('GET');
687
+ if (embed && embed.constructor === Object) {
688
+ embed = JSON.stringify(embed);
689
+ request.query().add('embed', embed);
690
+ }
691
+ if (options.includeArchived) {
692
+ request.query().add("include_archived", true);
693
+ }
694
+ if (options.cartToken) {
695
+ request.query().add('cart_token', options.cartToken);
696
+ }
697
+ if (!options.withRights) {
698
+ request.query().add('skip_rights', 'y');
699
+ }
700
+ request.responseHandler(options.success).errorHandler(error);
701
+ request.send();
702
+ }
703
+ function deleteOne(resource, success, error) {
704
+ var request = new Request();
705
+ request.resource(resource + '/').method('DELETE');
706
+ request.responseHandler(success).errorHandler(error);
707
+ request.send();
708
+ }
709
+ function create(options) {
710
+ var request = new Request(),
711
+ embed;
712
+ options.resource = options.resource || '';
713
+ options.parameters = options.parameters || new _dictionary.Dictionary();
714
+ options.success = options.success || _helpers.id;
715
+ options.error = options.error || _helpers.id;
716
+ options.files = options.files || new _dictionary.Dictionary();
717
+ request.resource(options.resource + '/').method('POST');
718
+ request.data().merge(options.parameters);
719
+ request.files(options.files);
720
+ if (!(0, _helpers.isUndefined)(options.username)) {
721
+ request.username(options.username);
722
+ request.password(options.password);
723
+ }
724
+ if (options.embed && options.embed.constructor === Object) {
725
+ embed = JSON.stringify(options.embed);
726
+ request.query().add('embed', embed);
727
+ }
728
+ if ((0, _helpers.notEmpty)(options.as_domain)) {
729
+ request.query().add('as_domain', options.as_domain);
730
+ }
731
+ if (!options.withRights) {
732
+ request.query().add('skip_rights', 'y');
733
+ }
734
+ request.responseHandler(options.success).errorHandler(options.error);
735
+ request.send();
736
+ }
737
+ function enumerateFiles(files) {
738
+ /* Convert a list to a Dictionary where the keys where the indices
739
+ and the values where the values at those indices.
740
+ */
741
+ var i,
742
+ result = new _dictionary.Dictionary();
743
+ for (i = 0; i < files.length; ++i) {
744
+ result.add(i, files[i]);
745
+ }
746
+ return result;
747
+ }
748
+ function recoverOne(model, id, success, error) {
749
+ var request = new Request();
750
+ request.resource("/unarchive/" + model + '/' + id + '/').method('POST');
751
+ request.responseHandler(success).errorHandler(error);
752
+ request.send();
753
+ }