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