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/product.js
ADDED
@@ -0,0 +1,309 @@
|
|
1
|
+
import { generateUUID } from './uuid.js';
|
2
|
+
import { notEmptyArray, isUndefinedOrNull,
|
3
|
+
removeObjectFromArrayWithIntegerValue } from './helpers.js';
|
4
|
+
import { addPropertyTo, getList, fromJsonList, deleteOne, patchOne, fromJson,
|
5
|
+
serialise, getOne, create, enumerateFiles, Request } from './model.js';
|
6
|
+
import { productTypesInts } from './product_types.js';
|
7
|
+
import { Category } from './category.js';
|
8
|
+
import { Component } from './component.js';
|
9
|
+
import { Company } from './company.js';
|
10
|
+
import { CountryTax } from './country_tax.js';
|
11
|
+
import { DraftTemplate } from './draft_template.js';
|
12
|
+
import { DomainTag } from './domain_tag.js';
|
13
|
+
import { DiscountGroup } from './discount_group.js';
|
14
|
+
import { Domain } from './domain.js';
|
15
|
+
import { Inventory } from './inventory.js';
|
16
|
+
import { ShipmentMethod } from './shipment_method.js';
|
17
|
+
import { VariationField } from './variation_field.js';
|
18
|
+
import { VariationsGroup } from './variations_group.js';
|
19
|
+
import { MerchiFile } from './merchi_file.js';
|
20
|
+
import { SupplyDomain } from './supply_domain.js';
|
21
|
+
import { User } from './user.js';
|
22
|
+
import { Job } from './job.js';
|
23
|
+
import { SeoDomainPage } from './seo_domain_page.js';
|
24
|
+
import { InternalTag } from './internal_tag.js';
|
25
|
+
|
26
|
+
export function Product() {
|
27
|
+
this.resource = '/products';
|
28
|
+
this.json = 'product';
|
29
|
+
this.temporaryId = generateUUID();
|
30
|
+
|
31
|
+
addPropertyTo(this, 'id');
|
32
|
+
addPropertyTo(this, 'name');
|
33
|
+
addPropertyTo(this, 'created');
|
34
|
+
addPropertyTo(this, 'updated');
|
35
|
+
addPropertyTo(this, 'country');
|
36
|
+
addPropertyTo(this, 'currency');
|
37
|
+
addPropertyTo(this, 'createdBy', User);
|
38
|
+
addPropertyTo(this, 'updatedBy', User);
|
39
|
+
addPropertyTo(this, 'independent');
|
40
|
+
addPropertyTo(this, 'productType');
|
41
|
+
addPropertyTo(this, 'description');
|
42
|
+
addPropertyTo(this, 'notes');
|
43
|
+
addPropertyTo(this, 'shopifyProductId');
|
44
|
+
addPropertyTo(this, 'minimum');
|
45
|
+
addPropertyTo(this, 'minimumPerGroup');
|
46
|
+
addPropertyTo(this, 'deliveryDaysNormal');
|
47
|
+
addPropertyTo(this, 'unitPrice');
|
48
|
+
addPropertyTo(this, 'unitPriceDiscountGroup', DiscountGroup);
|
49
|
+
addPropertyTo(this, 'bestPrice');
|
50
|
+
addPropertyTo(this, 'unitWeight');
|
51
|
+
addPropertyTo(this, 'unitHeight');
|
52
|
+
addPropertyTo(this, 'unitWidth');
|
53
|
+
addPropertyTo(this, 'unitDepth');
|
54
|
+
addPropertyTo(this, 'unitVolume');
|
55
|
+
addPropertyTo(this, 'showGroupBuyStatus');
|
56
|
+
addPropertyTo(this, 'groupBuyStatus');
|
57
|
+
addPropertyTo(this, 'needsDrafting');
|
58
|
+
addPropertyTo(this, 'needsProduction');
|
59
|
+
addPropertyTo(this, 'needsShipping');
|
60
|
+
addPropertyTo(this, 'needsInvoicing');
|
61
|
+
addPropertyTo(this, 'needsInventory');
|
62
|
+
addPropertyTo(this, 'showFeatureDeadline');
|
63
|
+
addPropertyTo(this, 'featureDeadline');
|
64
|
+
addPropertyTo(this, 'suppliers', User);
|
65
|
+
addPropertyTo(this, 'groupVariationFields', VariationField);
|
66
|
+
addPropertyTo(this, 'independentVariationFields', VariationField);
|
67
|
+
addPropertyTo(this, 'originalProduct', Product);
|
68
|
+
addPropertyTo(this, 'clonedFromProduct', Product);
|
69
|
+
addPropertyTo(this, 'chainedSupplierProduct', Product);
|
70
|
+
addPropertyTo(this, 'chainedSellerProducts', Product);
|
71
|
+
addPropertyTo(this, 'chainedInventorySupplierProduct', Product);
|
72
|
+
addPropertyTo(this, 'chainedInventorySellerProducts', Product);
|
73
|
+
addPropertyTo(this, 'component', Component);
|
74
|
+
addPropertyTo(this, 'domain', Domain);
|
75
|
+
addPropertyTo(this, 'suppliedByDomains', SupplyDomain);
|
76
|
+
addPropertyTo(this, 'autoAssignProductionOnAction');
|
77
|
+
addPropertyTo(this, 'supplyDomains', SupplyDomain);
|
78
|
+
addPropertyTo(this, 'images', MerchiFile);
|
79
|
+
addPropertyTo(this, 'featureImage', MerchiFile);
|
80
|
+
addPropertyTo(this, 'publicFiles', MerchiFile);
|
81
|
+
addPropertyTo(this, 'productionFiles', MerchiFile);
|
82
|
+
addPropertyTo(this, 'showPublic');
|
83
|
+
addPropertyTo(this, 'acceptSquare');
|
84
|
+
addPropertyTo(this, 'acceptStripe');
|
85
|
+
addPropertyTo(this, 'acceptPaypal');
|
86
|
+
addPropertyTo(this, 'acceptUtrust');
|
87
|
+
addPropertyTo(this, 'acceptBankTransfer');
|
88
|
+
addPropertyTo(this, 'acceptPhonePayment');
|
89
|
+
addPropertyTo(this, 'supplyChainDisabled');
|
90
|
+
addPropertyTo(this, 'allowAutomaticPaymentSupply');
|
91
|
+
addPropertyTo(this, 'allowGroupBuy');
|
92
|
+
addPropertyTo(this, 'allowPaymentUpfront');
|
93
|
+
addPropertyTo(this, 'allowQuotation');
|
94
|
+
addPropertyTo(this, 'allowChainedInventoryCreation');
|
95
|
+
addPropertyTo(this, 'allowClientDraftContribution');
|
96
|
+
addPropertyTo(this, 'chainedInventoryHandlingUnitPrice');
|
97
|
+
addPropertyTo(this, 'savedByUsers', User);
|
98
|
+
addPropertyTo(this, 'savedByCompanies', Company);
|
99
|
+
addPropertyTo(this, 'tags', DomainTag);
|
100
|
+
addPropertyTo(this, 'inventories', Inventory);
|
101
|
+
addPropertyTo(this, 'inventoriesOpen');
|
102
|
+
addPropertyTo(this, 'discountGroups', DiscountGroup);
|
103
|
+
addPropertyTo(this, 'categories', Category);
|
104
|
+
addPropertyTo(this, 'taxType', CountryTax);
|
105
|
+
addPropertyTo(this, 'defaultJob', Job);
|
106
|
+
addPropertyTo(this, 'supplyChainRequestJobs', Job);
|
107
|
+
addPropertyTo(this, 'draftTemplates', DraftTemplate);
|
108
|
+
addPropertyTo(this, 'shipmentMethods', ShipmentMethod);
|
109
|
+
addPropertyTo(this, 'seoDomainPages', SeoDomainPage);
|
110
|
+
addPropertyTo(this, 'aiContext');
|
111
|
+
addPropertyTo(this, 'internalUseNotes');
|
112
|
+
addPropertyTo(this, 'internalUseAiContext');
|
113
|
+
addPropertyTo(this, 'internalTags', InternalTag);
|
114
|
+
|
115
|
+
this.create = function (success, error, embed, asDomain) {
|
116
|
+
var data = serialise(this),
|
117
|
+
self = this,
|
118
|
+
domain = self.domain() ? self.domain().id() : null,
|
119
|
+
domainId = isUndefinedOrNull(asDomain) ? domain : asDomain;
|
120
|
+
function handleResponse(result) {
|
121
|
+
success(fromJson(self, result[self.json]));
|
122
|
+
}
|
123
|
+
create({resource: this.resource,
|
124
|
+
parameters: data[0],
|
125
|
+
as_domain: domainId,
|
126
|
+
files: enumerateFiles(data[1]),
|
127
|
+
success: handleResponse,
|
128
|
+
error: error,
|
129
|
+
embed: embed});
|
130
|
+
};
|
131
|
+
this.get = function (success, error, embed) {
|
132
|
+
var self = this;
|
133
|
+
function handleResponse(result) {
|
134
|
+
success(fromJson(self, result[self.json],
|
135
|
+
{makesDirty: false}));
|
136
|
+
}
|
137
|
+
getOne({resource: this.resource,
|
138
|
+
id: this.id(),
|
139
|
+
success: handleResponse,
|
140
|
+
error: error,
|
141
|
+
embed: embed});
|
142
|
+
};
|
143
|
+
|
144
|
+
this.patch = function (success, error, embed) {
|
145
|
+
var self = this,
|
146
|
+
data = serialise(this, undefined, undefined, undefined,
|
147
|
+
{excludeOld: true})[0];
|
148
|
+
function handleResponse(result) {
|
149
|
+
success(fromJson(self, result[self.json],
|
150
|
+
{makesDirty: false}));
|
151
|
+
}
|
152
|
+
patchOne({resource: this.resource,
|
153
|
+
id: this.id(),
|
154
|
+
success: handleResponse,
|
155
|
+
error: error,
|
156
|
+
data: data,
|
157
|
+
embed: embed});
|
158
|
+
};
|
159
|
+
|
160
|
+
this.destroy = function (success, error) {
|
161
|
+
deleteOne(this.resource + '/' + this.id(), success, error);
|
162
|
+
};
|
163
|
+
|
164
|
+
this.duplicate = function (success, error) {
|
165
|
+
var self = this,
|
166
|
+
request = new Request();
|
167
|
+
request.resource('/products/' + self.id() + '/copy/');
|
168
|
+
request.method('POST');
|
169
|
+
function handleResponse(status, data) {
|
170
|
+
if (status === 201) {
|
171
|
+
success(fromJson(self, data[self.json]));
|
172
|
+
} else {
|
173
|
+
error(null, data);
|
174
|
+
}
|
175
|
+
}
|
176
|
+
request.responseHandler(handleResponse).errorHandler(error);
|
177
|
+
request.send();
|
178
|
+
};
|
179
|
+
|
180
|
+
this.company = function () {
|
181
|
+
return this.domain() ? this.domain().company() : null;
|
182
|
+
}
|
183
|
+
this.variationFields = function () {
|
184
|
+
var variationFields = [];
|
185
|
+
if (notEmptyArray(this.groupVariationFields())) {
|
186
|
+
variationFields = variationFields.
|
187
|
+
concat(this.groupVariationFields());
|
188
|
+
}
|
189
|
+
|
190
|
+
if (notEmptyArray(this.independentVariationFields())) {
|
191
|
+
variationFields = variationFields.
|
192
|
+
concat(this.independentVariationFields());
|
193
|
+
}
|
194
|
+
return variationFields;
|
195
|
+
};
|
196
|
+
|
197
|
+
this.removeVariation = function (variation) {
|
198
|
+
var variations = !variation.independent() ?
|
199
|
+
this.groupVariationFields() : this.independentVariationFields();
|
200
|
+
return removeObjectFromArrayWithIntegerValue(
|
201
|
+
variations, 'id', variation.id());
|
202
|
+
};
|
203
|
+
|
204
|
+
this.primaryImage = function () {
|
205
|
+
var feature = this.featureImage(),
|
206
|
+
images = this.images(),
|
207
|
+
firstImage = images && images[0] ? images[0] : null;
|
208
|
+
return feature ? feature : firstImage;
|
209
|
+
};
|
210
|
+
|
211
|
+
this.productPrimaryImage = function () {
|
212
|
+
return this.primaryImage() ? this.primaryImage().viewUrl() : null;
|
213
|
+
};
|
214
|
+
|
215
|
+
this.productCurrency = function () {
|
216
|
+
var domain = this.domain();
|
217
|
+
return domain && domain.company() ?
|
218
|
+
domain.company().defaultCurrency() : null;
|
219
|
+
};
|
220
|
+
|
221
|
+
this.hasGroupVariationFields = function () {
|
222
|
+
return notEmptyArray(this.groupVariationFields());
|
223
|
+
};
|
224
|
+
|
225
|
+
this.hasIndependentVariationFields = function () {
|
226
|
+
return notEmptyArray(this.independentVariationFields());
|
227
|
+
};
|
228
|
+
|
229
|
+
this.buildEmptyVariationGroup = function () {
|
230
|
+
var variationsGroupBuilt = new VariationsGroup(),
|
231
|
+
groupVariationFields = this.groupVariationFields(),
|
232
|
+
emptyGroupCost = 0,
|
233
|
+
variations = [],
|
234
|
+
i,
|
235
|
+
emptyVariation;
|
236
|
+
variationsGroupBuilt.quantity('0');
|
237
|
+
|
238
|
+
for (i = 0; i < groupVariationFields.length; i++) {
|
239
|
+
emptyVariation =
|
240
|
+
groupVariationFields[i].buildEmptyVariation();
|
241
|
+
variations.push(emptyVariation);
|
242
|
+
emptyGroupCost += parseFloat(emptyVariation.cost(), 10);
|
243
|
+
}
|
244
|
+
|
245
|
+
variationsGroupBuilt.groupCost(emptyGroupCost.toString());
|
246
|
+
variationsGroupBuilt.variations(variations);
|
247
|
+
return variationsGroupBuilt;
|
248
|
+
};
|
249
|
+
|
250
|
+
this.buildEmptyVariations = function () {
|
251
|
+
var emptyVariations = [],
|
252
|
+
emptyVariation,
|
253
|
+
independentVariationFields = this.independentVariationFields(),
|
254
|
+
i;
|
255
|
+
|
256
|
+
for (i = 0; i < independentVariationFields.length; i++) {
|
257
|
+
emptyVariation =
|
258
|
+
independentVariationFields[i].buildEmptyVariation();
|
259
|
+
emptyVariations.push(emptyVariation);
|
260
|
+
}
|
261
|
+
return emptyVariations;
|
262
|
+
};
|
263
|
+
|
264
|
+
this.tax = function () {
|
265
|
+
return this.taxType();
|
266
|
+
};
|
267
|
+
|
268
|
+
this.previewImages = function (maxImages) {
|
269
|
+
var files = this.images();
|
270
|
+
if (Boolean(files)) {
|
271
|
+
return files.slice(0, maxImages);
|
272
|
+
}
|
273
|
+
return [];
|
274
|
+
};
|
275
|
+
|
276
|
+
this.stripePublishableKey = function () {
|
277
|
+
return this.domain().company() ?
|
278
|
+
this.domain().company().stripePublishableKey() : null;
|
279
|
+
};
|
280
|
+
|
281
|
+
this.stripeIsValidAndActive = function () {
|
282
|
+
const company = this.domain().company();
|
283
|
+
return this.stripePublishableKey() && company &&
|
284
|
+
company.acceptStripe();
|
285
|
+
};
|
286
|
+
|
287
|
+
this.isSupplierMOD = function () {
|
288
|
+
return this.productType() ===
|
289
|
+
productTypesInts.get('Supplier MOD (made on demand)');
|
290
|
+
};
|
291
|
+
|
292
|
+
this.isResell = function () {
|
293
|
+
return this.isSupplierMOD();
|
294
|
+
};
|
295
|
+
}
|
296
|
+
|
297
|
+
export function Products() {
|
298
|
+
this.resource = '/products';
|
299
|
+
this.json = 'products';
|
300
|
+
this.single = Product;
|
301
|
+
|
302
|
+
this.get = function (success, error, parameters) {
|
303
|
+
var self = this;
|
304
|
+
function handleResponse(result) {
|
305
|
+
success(fromJsonList(self, result, {makesDirty: false}));
|
306
|
+
}
|
307
|
+
getList(this.resource, handleResponse, error, parameters);
|
308
|
+
};
|
309
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import { Dictionary } from './dictionary.js';
|
2
|
+
|
3
|
+
export const productTypes = new Dictionary();
|
4
|
+
productTypes.add(0, 'supplier MOD (made on demand)');
|
5
|
+
productTypes.add(1, 'supplier');
|
6
|
+
productTypes.add(2, 'seller');
|
7
|
+
productTypes.add(3, 'seller MOD (made on demand)');
|
8
|
+
productTypes.add(4, 'cloned MOD (made on demand)');
|
9
|
+
productTypes.add(5, 'seller cloned MOD (made on demand)');
|
10
|
+
productTypes.add(6, 'production MOD (made on demand)');
|
11
|
+
productTypes.add(7, 'cloned supplier');
|
12
|
+
productTypes.add(8, 'seller inventory');
|
13
|
+
productTypes.add(9, 'supplir inventory');
|
14
|
+
productTypes.add(10, 'seller group buy');
|
15
|
+
productTypes.add(11, 'supplier resell MOD (made on demand)');
|
16
|
+
productTypes.add(12, 'supplier resell');
|
17
|
+
productTypes.add(14, 'supplier group buy inventory');
|
18
|
+
productTypes.add(14, 'seller inventory cloned');
|
19
|
+
productTypes.add(15, 'seller group buy inventory cloned');
|
20
|
+
productTypes.add(16, 'supply seller MOD(made on demand) cloned');
|
21
|
+
productTypes.add(17, 'supplier to supplier resell MOD(made on demand)');
|
22
|
+
productTypes.add(18, 'supplier resell cloned');
|
23
|
+
productTypes.add(19, 'supply domain reference');
|
24
|
+
|
25
|
+
export const productTypesInts = new Dictionary();
|
26
|
+
productTypes.each(function (key, value) {
|
27
|
+
productTypesInts.add(value, parseInt(key, 10));
|
28
|
+
});
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import { addPropertyTo, enumerateFiles, create, serialise,
|
2
|
+
fromJson } from './model.js';
|
3
|
+
import { Assignment } from './assignment.js';
|
4
|
+
import { User } from './user.js';
|
5
|
+
import { MerchiFile } from './merchi_file.js';
|
6
|
+
import { Notification } from './notification.js';
|
7
|
+
|
8
|
+
export function ProductionComment() {
|
9
|
+
this.resource = '/production_comments';
|
10
|
+
this.json = 'productionComment';
|
11
|
+
|
12
|
+
addPropertyTo(this, 'id');
|
13
|
+
addPropertyTo(this, 'user', User);
|
14
|
+
addPropertyTo(this, 'file', MerchiFile);
|
15
|
+
addPropertyTo(this, 'notifications', Notification);
|
16
|
+
addPropertyTo(this, 'assignment', Assignment);
|
17
|
+
addPropertyTo(this, 'date');
|
18
|
+
addPropertyTo(this, 'text');
|
19
|
+
addPropertyTo(this, 'urgency');
|
20
|
+
addPropertyTo(this, 'subject');
|
21
|
+
addPropertyTo(this, 'sendSms');
|
22
|
+
addPropertyTo(this, 'sendEmail');
|
23
|
+
addPropertyTo(this, 'isUrgentQuestion');
|
24
|
+
|
25
|
+
this.create = function (options) {
|
26
|
+
var data = serialise(this),
|
27
|
+
self = this,
|
28
|
+
embed = options.embed ? options.embed : {};
|
29
|
+
function handleResponse(result) {
|
30
|
+
options.success(fromJson(self, result[self.json]));
|
31
|
+
}
|
32
|
+
create({resource: this.resource,
|
33
|
+
parameters: data[0],
|
34
|
+
files: enumerateFiles(data[1]),
|
35
|
+
success: handleResponse,
|
36
|
+
as_domain: options.asDomain,
|
37
|
+
error: options.error,
|
38
|
+
embed: embed});
|
39
|
+
};
|
40
|
+
}
|
package/src/quote.js
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
import { generateUUID } from './uuid.js';
|
2
|
+
import { addPropertyTo, fromJson, getOne, fromJsonList,
|
3
|
+
getList } from './model.js';
|
4
|
+
import { QuoteItem } from './quote_item.js';
|
5
|
+
import { Assignment } from './assignment.js';
|
6
|
+
import { Invoice } from './invoice.js';
|
7
|
+
|
8
|
+
export function Quote() {
|
9
|
+
this.resource = '/quotes';
|
10
|
+
this.json = 'quote';
|
11
|
+
this.temporaryId = generateUUID();
|
12
|
+
|
13
|
+
addPropertyTo(this, 'id');
|
14
|
+
addPropertyTo(this, 'agreedDeadline');
|
15
|
+
addPropertyTo(this, 'quoteItems', QuoteItem);
|
16
|
+
addPropertyTo(this, 'assignments', Assignment);
|
17
|
+
addPropertyTo(this, 'currency');
|
18
|
+
addPropertyTo(this, 'invoice', Invoice);
|
19
|
+
|
20
|
+
this.get = function (success, error) {
|
21
|
+
var self = this;
|
22
|
+
function handleResponse(result) {
|
23
|
+
success(fromJson(self, result[self.json],
|
24
|
+
{makesDirty: false}));
|
25
|
+
}
|
26
|
+
getOne({resource: this.resource,
|
27
|
+
id: this.id(),
|
28
|
+
success: handleResponse,
|
29
|
+
error: error});
|
30
|
+
};
|
31
|
+
|
32
|
+
this.quoteTotal = function () {
|
33
|
+
var self = this,
|
34
|
+
items = Boolean(self.quoteItems()) ? self.quoteItems() : [],
|
35
|
+
total = parseFloat(0.000), i;
|
36
|
+
for (i = 0; i < items.length; i++) {
|
37
|
+
total += parseFloat(items[i].total());
|
38
|
+
}
|
39
|
+
return total;
|
40
|
+
};
|
41
|
+
|
42
|
+
this.deadlineTimeDifference = function () {
|
43
|
+
var self = this,
|
44
|
+
proposedDeadline = Boolean(self.agreedDeadline()) ?
|
45
|
+
self.agreedDeadline() : null,
|
46
|
+
assignments = Boolean(self.assignments()) ?
|
47
|
+
self.assignments() : null,
|
48
|
+
assignment = Boolean(assignments) && assignments.length > 0 ?
|
49
|
+
assignments[0] : null,
|
50
|
+
productionDeadline = Boolean(assignment) ?
|
51
|
+
assignment.productionDeadline() : null;
|
52
|
+
if (Boolean(proposedDeadline) && Boolean(productionDeadline)) {
|
53
|
+
return productionDeadline - proposedDeadline;
|
54
|
+
}
|
55
|
+
return null;
|
56
|
+
};
|
57
|
+
|
58
|
+
this.findQuoteItemIndex = function (quoteItemId) {
|
59
|
+
var self = this,
|
60
|
+
quoteItems = Boolean(self.quoteItems()) ? self.quoteItems() : [];
|
61
|
+
return quoteItems.findIndex(function (arrayElement) {
|
62
|
+
return String(arrayElement.id()) === String(quoteItemId);
|
63
|
+
});
|
64
|
+
};
|
65
|
+
|
66
|
+
this.removeQuoteItem = function (quoteItem) {
|
67
|
+
var self = this,
|
68
|
+
itemIndex = self.findQuoteItemIndex(quoteItem.id()),
|
69
|
+
quoteItems = self.quoteItems();
|
70
|
+
if (Boolean(quoteItems) && itemIndex >= 0) {
|
71
|
+
quoteItems.splice(itemIndex, 1);
|
72
|
+
}
|
73
|
+
};
|
74
|
+
}
|
75
|
+
|
76
|
+
export function Quotes() {
|
77
|
+
this.resource = '/quotes';
|
78
|
+
this.json = 'quotes';
|
79
|
+
this.single = Quote;
|
80
|
+
|
81
|
+
this.get = function (success, error, offset, limit, q) {
|
82
|
+
var self = this;
|
83
|
+
function handleResponse(result) {
|
84
|
+
success(fromJsonList(self, result, {makesDirty: false}));
|
85
|
+
}
|
86
|
+
getList(this.resource, handleResponse, error,
|
87
|
+
{offset: offset, limit: limit, q: q});
|
88
|
+
};
|
89
|
+
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
import { generateUUID } from './uuid.js';
|
2
|
+
import { addPropertyTo, fromJson, getOne, fromJsonList,
|
3
|
+
getList } from './model.js';
|
4
|
+
|
5
|
+
export function QuoteItem() {
|
6
|
+
this.resource = '/quote_items';
|
7
|
+
this.json = 'quoteItem';
|
8
|
+
this.temporaryId = generateUUID();
|
9
|
+
|
10
|
+
addPropertyTo(this, 'id');
|
11
|
+
addPropertyTo(this, 'type');
|
12
|
+
addPropertyTo(this, 'quantity');
|
13
|
+
addPropertyTo(this, 'description');
|
14
|
+
addPropertyTo(this, 'unitPrice');
|
15
|
+
|
16
|
+
this.get = function (success, error) {
|
17
|
+
var self = this;
|
18
|
+
function handleResponse(result) {
|
19
|
+
success(fromJson(self, result[self.json],
|
20
|
+
{makesDirty: false}));
|
21
|
+
}
|
22
|
+
getOne({resource: this.resource,
|
23
|
+
id: this.id(),
|
24
|
+
success: handleResponse,
|
25
|
+
error: error});
|
26
|
+
};
|
27
|
+
|
28
|
+
this.total = function () {
|
29
|
+
var self = this,
|
30
|
+
quantity = Boolean(self.quantity()) ? self.quantity() : 0,
|
31
|
+
unitPrice = Boolean(self.unitPrice()) ? self.unitPrice() : 0,
|
32
|
+
total;
|
33
|
+
total = quantity * unitPrice;
|
34
|
+
return total.toFixed(3);
|
35
|
+
};
|
36
|
+
}
|
37
|
+
|
38
|
+
export function QuoteItems() {
|
39
|
+
this.resource = '/quote_items';
|
40
|
+
this.json = 'quoteItems';
|
41
|
+
this.single = QuoteItem;
|
42
|
+
|
43
|
+
this.get = function (success, error, offset, limit, q) {
|
44
|
+
var self = this;
|
45
|
+
function handleResponse(result) {
|
46
|
+
success(fromJsonList(self, result, {makesDirty: false}));
|
47
|
+
}
|
48
|
+
getList(this.resource, handleResponse, error,
|
49
|
+
{offset: offset, limit: limit, q: q});
|
50
|
+
};
|
51
|
+
}
|
package/src/roles.js
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
import { Dictionary } from './dictionary.js';
|
2
|
+
import { Set } from './set.js';
|
3
|
+
|
4
|
+
export const roles = new Dictionary();
|
5
|
+
roles.add('public', 0);
|
6
|
+
roles.add('admin', 1);
|
7
|
+
roles.add('sales', 2);
|
8
|
+
roles.add('designer', 3);
|
9
|
+
roles.add('supplier', 4);
|
10
|
+
roles.add('client', 5);
|
11
|
+
roles.add('manager', 6);
|
12
|
+
roles.add('accountant', 7);
|
13
|
+
roles.add('theme editor', 8);
|
14
|
+
|
15
|
+
export const systemRoles = new Dictionary();
|
16
|
+
systemRoles.add("Component builder", 1);
|
17
|
+
|
18
|
+
export const allRoles = new Set();
|
19
|
+
roles.each(function (key, value) {
|
20
|
+
allRoles.add(value);
|
21
|
+
});
|
22
|
+
|
23
|
+
export const COMPONENT_BUILDER = 'Component builder';
|
24
|
+
export const SELLER = 'Seller';
|
25
|
+
export const SELLER_PLUS = 'Seller plus';
|
26
|
+
export const SUPPLIER = 'Supplier';
|
27
|
+
export const RESTRICTED_SUPPLIER = 'Restricted supplier';
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import { generateUUID } from './uuid.js';
|
2
|
+
import { addPropertyTo, getList, fromJsonList } from './model.js';
|
3
|
+
import { Domain } from './domain.js';
|
4
|
+
import { Product } from './product.js';
|
5
|
+
|
6
|
+
export function SeoDomainPage() {
|
7
|
+
this.resource = '/seo_domain_pages';
|
8
|
+
this.json = 'seoDomainPage';
|
9
|
+
this.temporaryId = generateUUID();
|
10
|
+
|
11
|
+
addPropertyTo(this, 'archived');
|
12
|
+
addPropertyTo(this, 'id');
|
13
|
+
addPropertyTo(this, 'metaDescription');
|
14
|
+
addPropertyTo(this, 'metaRobots');
|
15
|
+
addPropertyTo(this, 'metaTitle');
|
16
|
+
addPropertyTo(this, 'pageKey');
|
17
|
+
addPropertyTo(this, 'domain', Domain);
|
18
|
+
addPropertyTo(this, 'product', Product);
|
19
|
+
}
|
20
|
+
|
21
|
+
export function SeoDomainPages() {
|
22
|
+
this.resource = '/seo_domain_pages';
|
23
|
+
this.json = 'seoDomainPage';
|
24
|
+
this.single = SeoDomainPage;
|
25
|
+
|
26
|
+
this.get = function (success, error, offset, limit, q) {
|
27
|
+
var self = this;
|
28
|
+
function handleResponse(result) {
|
29
|
+
success(fromJsonList(self, result,
|
30
|
+
{makesDirty: false}));
|
31
|
+
}
|
32
|
+
getList(this.resource, handleResponse, error,
|
33
|
+
{offset: offset, limit: limit, q: q});
|
34
|
+
};
|
35
|
+
}
|
package/src/session.js
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
import { Dictionary } from './dictionary.js';
|
2
|
+
import { addPropertyTo, create, fromJson, getOne, deleteOne, fromJsonList,
|
3
|
+
getList, Request } from './model.js';
|
4
|
+
import { User } from './user.js';
|
5
|
+
import { Domain } from './domain.js';
|
6
|
+
|
7
|
+
export function Session() {
|
8
|
+
this.resource = '/sessions';
|
9
|
+
this.json = 'session';
|
10
|
+
|
11
|
+
addPropertyTo(this, 'ip');
|
12
|
+
addPropertyTo(this, 'user', User);
|
13
|
+
addPropertyTo(this, 'domain', Domain);
|
14
|
+
addPropertyTo(this, 'token');
|
15
|
+
addPropertyTo(this, 'remember');
|
16
|
+
|
17
|
+
this.create = function (success, error, embed, username, password) {
|
18
|
+
var self = this;
|
19
|
+
function handleResponse(result) {
|
20
|
+
success(fromJson(self, result[self.json]));
|
21
|
+
}
|
22
|
+
create({resource: this.resource,
|
23
|
+
success: handleResponse,
|
24
|
+
error: error,
|
25
|
+
embed: embed,
|
26
|
+
username: username,
|
27
|
+
password: password});
|
28
|
+
};
|
29
|
+
|
30
|
+
this.get = function (success, error, embed) {
|
31
|
+
var self = this;
|
32
|
+
function handleResponse(result) {
|
33
|
+
success(fromJson(self, result[self.json],
|
34
|
+
{makesDirty: false}));
|
35
|
+
}
|
36
|
+
getOne({resource: this.resource,
|
37
|
+
id: this.token(),
|
38
|
+
success: handleResponse,
|
39
|
+
error: error,
|
40
|
+
embed: embed});
|
41
|
+
};
|
42
|
+
|
43
|
+
this.remove = function (success, error) {
|
44
|
+
deleteOne(this.resource, success, error);
|
45
|
+
};
|
46
|
+
|
47
|
+
this.storeCreate = function (success, error, parameters) {
|
48
|
+
var request = new Request(),
|
49
|
+
query = new Dictionary(),
|
50
|
+
password = parameters.password,
|
51
|
+
remember = parameters.remember,
|
52
|
+
storeName = parameters.storeName,
|
53
|
+
username = parameters.email;
|
54
|
+
self = this;
|
55
|
+
|
56
|
+
if (password) {
|
57
|
+
request.password(password);
|
58
|
+
}
|
59
|
+
|
60
|
+
if (remember) {
|
61
|
+
query.add('remember', remember);
|
62
|
+
}
|
63
|
+
|
64
|
+
if (storeName) {
|
65
|
+
query.add('storeName', storeName);
|
66
|
+
}
|
67
|
+
|
68
|
+
if (username) {
|
69
|
+
request.username(username);
|
70
|
+
}
|
71
|
+
request.resource('/store-session/');
|
72
|
+
request.method('POST');
|
73
|
+
request.query().merge(query);
|
74
|
+
function handleResponse(status, data) {
|
75
|
+
success(fromJson(self, data[self.json]));
|
76
|
+
}
|
77
|
+
function handleError(status, data) {
|
78
|
+
var statusCode = status ? status : 400,
|
79
|
+
errorObject = data ? data :
|
80
|
+
{message: 'could not connect to server',
|
81
|
+
errorCode: 0};
|
82
|
+
error(statusCode, errorObject);
|
83
|
+
}
|
84
|
+
request.responseHandler(handleResponse).errorHandler(handleError);
|
85
|
+
request.send();
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
export function Sessions() {
|
90
|
+
this.resource = '/sessions';
|
91
|
+
this.json = 'sessions';
|
92
|
+
this.single = Session;
|
93
|
+
|
94
|
+
this.get = function (success, error, parameters) {
|
95
|
+
var self = this;
|
96
|
+
function handleResponse(result) {
|
97
|
+
success(fromJsonList(self, result, {makesDirty: false}));
|
98
|
+
}
|
99
|
+
getList(this.resource, handleResponse, error,
|
100
|
+
parameters);
|
101
|
+
};
|
102
|
+
}
|