merchi_sdk_js 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/address.js +109 -0
- package/dist/assignment.js +175 -0
- package/dist/automatic_payment_relationship.js +72 -0
- package/dist/backup.js +32 -0
- package/dist/bank.js +25 -0
- package/dist/cart.js +133 -0
- package/dist/cart_item.js +71 -0
- package/dist/cart_shipment_group.js +23 -0
- package/dist/cart_shipment_quote.js +26 -0
- package/dist/category.js +68 -0
- package/dist/company.js +248 -0
- package/dist/company_invitation.js +70 -0
- package/dist/component.js +107 -0
- package/dist/component_tag.js +60 -0
- package/dist/component_version.js +21 -0
- package/dist/country_tax.js +93 -0
- package/dist/dictionary.js +130 -0
- package/dist/discount.js +22 -0
- package/dist/discount_group.js +18 -0
- package/dist/domain.js +245 -0
- package/dist/domain_invitation.js +17 -0
- package/dist/domain_tag.js +87 -0
- package/dist/domain_types.js +22 -0
- package/dist/draft.js +97 -0
- package/dist/draft_comment.js +45 -0
- package/dist/draft_template.js +39 -0
- package/dist/email_address.js +34 -0
- package/dist/email_counter.js +47 -0
- package/dist/enrolled_domain.js +88 -0
- package/dist/exchange_rate.js +66 -0
- package/dist/field_types.js +19 -0
- package/dist/helpers.js +86 -0
- package/dist/internal_tag.js +98 -0
- package/dist/inventory.js +100 -0
- package/dist/inventory_unit_variation.js +19 -0
- package/dist/invoice.js +225 -0
- package/dist/invoice_types.js +11 -0
- package/dist/item.js +25 -0
- package/dist/job.js +536 -0
- package/dist/job_comment.js +45 -0
- package/dist/job_status.js +47 -0
- package/dist/matching_inventory.js +21 -0
- package/dist/md5.js +149 -0
- package/dist/menu.js +37 -0
- package/dist/menu_item.js +24 -0
- package/dist/merchi.js +1004 -0
- package/dist/merchi_file.js +165 -0
- package/dist/model.js +753 -0
- package/dist/notification.js +151 -0
- package/dist/notification_types.js +199 -0
- package/dist/output.cjs.js +31317 -0
- package/dist/output.esm.js +31312 -0
- package/dist/page.js +41 -0
- package/dist/payment.js +32 -0
- package/dist/payment_device.js +21 -0
- package/dist/payment_types.js +20 -0
- package/dist/phone_number.js +37 -0
- package/dist/product.js +288 -0
- package/dist/product_types.js +32 -0
- package/dist/production_comment.js +44 -0
- package/dist/quote.js +91 -0
- package/dist/quote_item.js +59 -0
- package/dist/roles.js +29 -0
- package/dist/seo_domain_page.js +42 -0
- package/dist/session.js +103 -0
- package/dist/set.js +29 -0
- package/dist/shipment.js +181 -0
- package/dist/shipment_item.js +17 -0
- package/dist/shipment_item_fulfillment.js +17 -0
- package/dist/shipment_method.js +81 -0
- package/dist/shipment_method_variation.js +38 -0
- package/dist/subscription_plan.js +75 -0
- package/dist/supply_domain.js +65 -0
- package/dist/system_role.js +12 -0
- package/dist/theme.js +180 -0
- package/dist/theme_css_setting.js +61 -0
- package/dist/theme_status.js +11 -0
- package/dist/user.js +409 -0
- package/dist/user_company.js +19 -0
- package/dist/user_types.js +23 -0
- package/dist/uuid.js +12 -0
- package/dist/variation.js +233 -0
- package/dist/variation_field.js +233 -0
- package/dist/variation_fields_option.js +41 -0
- package/dist/variation_option.js +62 -0
- package/dist/variations_group.js +43 -0
- package/dist/white_label_accessibilities.js +11 -0
- package/package.json +30 -0
- package/src/address.js +107 -0
- package/src/assignment.js +165 -0
- package/src/automatic_payment_relationship.js +65 -0
- package/src/backup.js +29 -0
- package/src/bank.js +21 -0
- package/src/cart.js +131 -0
- package/src/cart_item.js +71 -0
- package/src/cart_shipment_group.js +20 -0
- package/src/cart_shipment_quote.js +23 -0
- package/src/category.js +62 -0
- package/src/company.js +267 -0
- package/src/company_invitation.js +63 -0
- package/src/component.js +100 -0
- package/src/component_tag.js +53 -0
- package/src/component_version.js +17 -0
- package/src/country_tax.js +89 -0
- package/src/dictionary.js +135 -0
- package/src/discount.js +19 -0
- package/src/discount_group.js +15 -0
- package/src/domain.js +254 -0
- package/src/domain_invitation.js +13 -0
- package/src/domain_tag.js +79 -0
- package/src/domain_types.js +18 -0
- package/src/draft.js +92 -0
- package/src/draft_comment.js +41 -0
- package/src/draft_template.js +35 -0
- package/src/email_address.js +27 -0
- package/src/email_counter.js +42 -0
- package/src/enrolled_domain.js +79 -0
- package/src/exchange_rate.js +61 -0
- package/src/field_types.js +15 -0
- package/src/helpers.js +81 -0
- package/src/internal_tag.js +90 -0
- package/src/inventory.js +99 -0
- package/src/inventory_unit_variation.js +18 -0
- package/src/invoice.js +224 -0
- package/src/invoice_types.js +7 -0
- package/src/item.js +22 -0
- package/src/job.js +616 -0
- package/src/job_comment.js +41 -0
- package/src/job_status.js +51 -0
- package/src/matching_inventory.js +17 -0
- package/src/md5.js +162 -0
- package/src/menu.js +32 -0
- package/src/menu_item.js +22 -0
- package/src/merchi.js +1074 -0
- package/src/merchi_file.js +163 -0
- package/src/model.js +820 -0
- package/src/notification.js +153 -0
- package/src/notification_types.js +246 -0
- package/src/page.js +38 -0
- package/src/payment.js +32 -0
- package/src/payment_device.js +17 -0
- package/src/payment_types.js +18 -0
- package/src/phone_number.js +30 -0
- package/src/product.js +309 -0
- package/src/product_types.js +28 -0
- package/src/production_comment.js +40 -0
- package/src/quote.js +89 -0
- package/src/quote_item.js +51 -0
- package/src/roles.js +27 -0
- package/src/seo_domain_page.js +35 -0
- package/src/session.js +102 -0
- package/src/set.js +28 -0
- package/src/shipment.js +191 -0
- package/src/shipment_item.js +13 -0
- package/src/shipment_item_fulfillment.js +13 -0
- package/src/shipment_method.js +73 -0
- package/src/shipment_method_variation.js +34 -0
- package/src/subscription_plan.js +68 -0
- package/src/supply_domain.js +60 -0
- package/src/system_role.js +8 -0
- package/src/theme.js +188 -0
- package/src/theme_css_setting.js +54 -0
- package/src/theme_status.js +6 -0
- package/src/user.js +442 -0
- package/src/user_company.js +15 -0
- package/src/user_types.js +19 -0
- package/src/uuid.js +3 -0
- package/src/variation.js +257 -0
- package/src/variation_field.js +261 -0
- package/src/variation_fields_option.js +41 -0
- package/src/variation_option.js +59 -0
- package/src/variations_group.js +43 -0
- package/src/white_label_accessibilities.js +6 -0
@@ -0,0 +1,163 @@
|
|
1
|
+
import { generateUUID } from './uuid.js';
|
2
|
+
import { Dictionary } from './dictionary.js';
|
3
|
+
import { addPropertyTo, fromJson, getOne, serialise, create, enumerateFiles,
|
4
|
+
getList, fromJsonList, deleteOne, Request } from './model.js';
|
5
|
+
|
6
|
+
export function MerchiFile() {
|
7
|
+
this.resource = '/files';
|
8
|
+
this.json = 'file';
|
9
|
+
this.temporaryId = generateUUID();
|
10
|
+
|
11
|
+
addPropertyTo(this, 'id');
|
12
|
+
addPropertyTo(this, 'name');
|
13
|
+
addPropertyTo(this, 'size');
|
14
|
+
addPropertyTo(this, 'mimetype');
|
15
|
+
addPropertyTo(this, 'viewUrl');
|
16
|
+
addPropertyTo(this, 'downloadUrl');
|
17
|
+
addPropertyTo(this, 'creationDate');
|
18
|
+
|
19
|
+
this.get = function (success, error, embed) {
|
20
|
+
var self = this;
|
21
|
+
function handleResponse(result) {
|
22
|
+
success(fromJson(self, result[self.json],
|
23
|
+
{makesDirty: false}));
|
24
|
+
}
|
25
|
+
getOne({resource: this.resource,
|
26
|
+
id: this.id(),
|
27
|
+
success: handleResponse,
|
28
|
+
error: error,
|
29
|
+
embed: embed});
|
30
|
+
};
|
31
|
+
this.create = function (success, error, embed, as_domain) {
|
32
|
+
var data = serialise(this),
|
33
|
+
self = this;
|
34
|
+
function handleResponse(result) {
|
35
|
+
success(fromJson(self, result[self.json]));
|
36
|
+
}
|
37
|
+
create({resource: this.resource,
|
38
|
+
parameters: data[0],
|
39
|
+
files: enumerateFiles(data[1]),
|
40
|
+
success: handleResponse,
|
41
|
+
as_domain: as_domain,
|
42
|
+
error: error,
|
43
|
+
embed: embed});
|
44
|
+
};
|
45
|
+
|
46
|
+
this.destroy = function (success, error) {
|
47
|
+
deleteOne(this.resource + "/" + this.id(), success, error);
|
48
|
+
};
|
49
|
+
this.publicCreate = function (success, error) {
|
50
|
+
var self = this,
|
51
|
+
filesObject = serialise(this),
|
52
|
+
request = new Request();
|
53
|
+
request.resource('/public-upload-job-files/');
|
54
|
+
request.method('POST');
|
55
|
+
request.files(enumerateFiles(filesObject[1]));
|
56
|
+
function handleResponse(status, data) {
|
57
|
+
if (status === 201) {
|
58
|
+
success(fromJson(self, data[self.json]));
|
59
|
+
} else {
|
60
|
+
error(data);
|
61
|
+
}
|
62
|
+
}
|
63
|
+
function handleError(status, data) {
|
64
|
+
error({message: 'could not connect to server'});
|
65
|
+
}
|
66
|
+
request.responseHandler(handleResponse).errorHandler(handleError);
|
67
|
+
request.send();
|
68
|
+
};
|
69
|
+
this.fromString = function (name, mimetype, data) {
|
70
|
+
this.name(name);
|
71
|
+
this.mimetype(mimetype);
|
72
|
+
this.size(data.length);
|
73
|
+
this.fileData = new File([data], name, {type: mimetype});
|
74
|
+
return this;
|
75
|
+
};
|
76
|
+
|
77
|
+
this.fromFormFile = function (file) {
|
78
|
+
this.name(file.name);
|
79
|
+
this.mimetype(file.type);
|
80
|
+
this.size(file.size);
|
81
|
+
this.fileData = file;
|
82
|
+
return this;
|
83
|
+
};
|
84
|
+
|
85
|
+
this.isPdf = function () {
|
86
|
+
return this.mimetype() === 'application/pdf' ||
|
87
|
+
this.mimetype() === 'application/x-pdf';
|
88
|
+
}
|
89
|
+
|
90
|
+
this.isImage = function () {
|
91
|
+
var imageTypeString = this.mimetype() ?
|
92
|
+
this.mimetype().split('/')[0] : null;
|
93
|
+
return imageTypeString === 'image';
|
94
|
+
}
|
95
|
+
|
96
|
+
this.fetchFileContents = function () {
|
97
|
+
var downloadUrl = this.downloadUrl()
|
98
|
+
return fetch(downloadUrl).then(
|
99
|
+
function (response) {
|
100
|
+
return response.text();
|
101
|
+
});
|
102
|
+
};
|
103
|
+
}
|
104
|
+
|
105
|
+
export function MerchiFiles() {
|
106
|
+
this.resource = '/files';
|
107
|
+
this.json = 'files';
|
108
|
+
this.single = MerchiFile;
|
109
|
+
|
110
|
+
this.get = function (success, error, parameters) {
|
111
|
+
var self = this;
|
112
|
+
function handleResponse(result) {
|
113
|
+
success(fromJsonList(self, result, {makesDirty: false}));
|
114
|
+
}
|
115
|
+
getList(this.resource, handleResponse, error,
|
116
|
+
parameters);
|
117
|
+
};
|
118
|
+
|
119
|
+
this.getUserFiles = function (success, error, parameters) {
|
120
|
+
var self = this,
|
121
|
+
query = new Dictionary(),
|
122
|
+
request = new Request();
|
123
|
+
|
124
|
+
if (parameters.limit) {
|
125
|
+
query.add('limit', parameters.limit);
|
126
|
+
}
|
127
|
+
if (parameters.offset) {
|
128
|
+
query.add('offset', parameters.offset);
|
129
|
+
}
|
130
|
+
if (parameters.order) {
|
131
|
+
query.add('order', parameters.order);
|
132
|
+
}
|
133
|
+
if (parameters.q) {
|
134
|
+
query.add('q', parameters.q);
|
135
|
+
}
|
136
|
+
if (parameters.sort) {
|
137
|
+
query.add('sort', parameters.sort);
|
138
|
+
}
|
139
|
+
if (parameters.relatedUser) {
|
140
|
+
query.add('related_user', parameters.relatedUser);
|
141
|
+
}
|
142
|
+
query.add('skip_rights', true);
|
143
|
+
request.resource('/files/user/');
|
144
|
+
request.method('GET');
|
145
|
+
request.query().merge(query);
|
146
|
+
function handleResponse(status, data) {
|
147
|
+
if (status === 200) {
|
148
|
+
success(fromJsonList(self, data));
|
149
|
+
} else {
|
150
|
+
error(data);
|
151
|
+
}
|
152
|
+
}
|
153
|
+
function handleError(status, data) {
|
154
|
+
var statusCode = status ? status : 400,
|
155
|
+
errorObject = data ? data :
|
156
|
+
{message: 'could not connect to server',
|
157
|
+
errorCode: 0};
|
158
|
+
error(statusCode, errorObject);
|
159
|
+
}
|
160
|
+
request.responseHandler(handleResponse).errorHandler(handleError);
|
161
|
+
request.send();
|
162
|
+
}
|
163
|
+
}
|