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/category.js
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
import { generateUUID } from './uuid.js';
|
2
|
+
import { addPropertyTo, fromJson, serialise, create, enumerateFiles,
|
3
|
+
getOne, deleteOne, fromJsonList, getList } from './model.js';
|
4
|
+
import { Domain } from './domain.js';
|
5
|
+
|
6
|
+
export function Category() {
|
7
|
+
this.resource = '/categories';
|
8
|
+
this.json = 'category';
|
9
|
+
this.temporaryId = generateUUID();
|
10
|
+
|
11
|
+
addPropertyTo(this, 'id');
|
12
|
+
addPropertyTo(this, 'name');
|
13
|
+
addPropertyTo(this, 'showDashboard');
|
14
|
+
addPropertyTo(this, 'showPublic');
|
15
|
+
addPropertyTo(this, 'showPublicSupplierResell');
|
16
|
+
addPropertyTo(this, 'domain', Domain);
|
17
|
+
|
18
|
+
this.create = function (success, error, embed, domainId) {
|
19
|
+
var data = serialise(this),
|
20
|
+
self = this;
|
21
|
+
function handleResponse(result) {
|
22
|
+
success(fromJson(self, result[self.json]));
|
23
|
+
}
|
24
|
+
create({resource: this.resource,
|
25
|
+
parameters: data[0],
|
26
|
+
files: enumerateFiles(data[1]),
|
27
|
+
success: handleResponse,
|
28
|
+
error: error,
|
29
|
+
embed: embed,
|
30
|
+
as_domain: domainId});
|
31
|
+
};
|
32
|
+
|
33
|
+
this.get = function (success, error) {
|
34
|
+
var self = this;
|
35
|
+
function handleResponse(result) {
|
36
|
+
success(fromJson(self, result[self.json],
|
37
|
+
{makesDirty: false}));
|
38
|
+
}
|
39
|
+
getOne({resource: this.resource,
|
40
|
+
id: this.id(),
|
41
|
+
success: handleResponse,
|
42
|
+
error: error});
|
43
|
+
};
|
44
|
+
|
45
|
+
this.destroy = function (success, error) {
|
46
|
+
deleteOne(this.resource + "/" + this.id(), success, error);
|
47
|
+
};
|
48
|
+
}
|
49
|
+
|
50
|
+
export function Categories() {
|
51
|
+
this.resource = '/categories';
|
52
|
+
this.json = 'categories';
|
53
|
+
this.single = Category;
|
54
|
+
|
55
|
+
this.get = function (success, error, parameters) {
|
56
|
+
var self = this;
|
57
|
+
function handleResponse(result) {
|
58
|
+
success(fromJsonList(self, result, {makesDirty: false}));
|
59
|
+
}
|
60
|
+
getList(this.resource, handleResponse, error, parameters);
|
61
|
+
};
|
62
|
+
}
|
package/src/company.js
ADDED
@@ -0,0 +1,267 @@
|
|
1
|
+
import { addPropertyTo, getList, fromJson, getOne, serialise,
|
2
|
+
patchOne, deleteOne, create, fromJsonList, enumerateFiles,
|
3
|
+
Request } from './model.js';
|
4
|
+
import { Dictionary } from './dictionary.js';
|
5
|
+
import { AutomaticPaymentRelationship } from './automatic_payment_relationship.js';
|
6
|
+
import { Address } from './address.js';
|
7
|
+
import { Bank } from './bank.js';
|
8
|
+
import { CountryTax, NoTaxEntity } from './country_tax.js';
|
9
|
+
import { CompanyInvitation } from './company_invitation.js';
|
10
|
+
import { Domain } from './domain.js';
|
11
|
+
import { EmailAddress } from './email_address.js';
|
12
|
+
import { MerchiFile } from './merchi_file.js';
|
13
|
+
import { PhoneNumber } from './phone_number.js';
|
14
|
+
import { Product } from './product.js';
|
15
|
+
import { ShipmentMethod } from './shipment_method.js';
|
16
|
+
import { User } from './user.js';
|
17
|
+
import { UserCompany } from './user_company.js';
|
18
|
+
import { PaymentDevice } from './payment_device.js';
|
19
|
+
import { InternalTag } from './internal_tag.js';
|
20
|
+
|
21
|
+
|
22
|
+
export function Company() {
|
23
|
+
this.resource = '/companies';
|
24
|
+
this.json = 'company';
|
25
|
+
|
26
|
+
addPropertyTo(this, 'id');
|
27
|
+
addPropertyTo(this, 'name');
|
28
|
+
addPropertyTo(this, 'website');
|
29
|
+
addPropertyTo(this, 'country');
|
30
|
+
addPropertyTo(this, 'stripeAccountId');
|
31
|
+
addPropertyTo(this, 'isStripeAccountEnabled');
|
32
|
+
addPropertyTo(this, 'logo', MerchiFile);
|
33
|
+
addPropertyTo(this, 'defaultCurrency');
|
34
|
+
addPropertyTo(this, 'taxNumber');
|
35
|
+
addPropertyTo(this, 'taxNumberType');
|
36
|
+
addPropertyTo(this, 'defaultTaxType', CountryTax);
|
37
|
+
addPropertyTo(this, 'taxTypes', CountryTax);
|
38
|
+
addPropertyTo(this, 'paypalAccount');
|
39
|
+
addPropertyTo(this, 'paypalPassword');
|
40
|
+
addPropertyTo(this, 'paypalSignature');
|
41
|
+
addPropertyTo(this, 'isPaypalValid');
|
42
|
+
addPropertyTo(this, 'utrustApiKey');
|
43
|
+
addPropertyTo(this, 'utrustWebhookKey');
|
44
|
+
addPropertyTo(this, 'acceptUtrust');
|
45
|
+
addPropertyTo(this, 'isPayingCompany');
|
46
|
+
addPropertyTo(this, 'isUtrustValid');
|
47
|
+
addPropertyTo(this, 'isTesting');
|
48
|
+
addPropertyTo(this, 'isBlocked');
|
49
|
+
addPropertyTo(this, 'trialEndDate');
|
50
|
+
addPropertyTo(this, 'trialEndDateUpdated');
|
51
|
+
addPropertyTo(this, 'trialEndDateSetBy', User);
|
52
|
+
addPropertyTo(this, 'sendleActive');
|
53
|
+
addPropertyTo(this, 'sendleApiKey');
|
54
|
+
addPropertyTo(this, 'sendleId');
|
55
|
+
addPropertyTo(this, 'squareAccessToken');
|
56
|
+
addPropertyTo(this, 'squareRefreshToken');
|
57
|
+
addPropertyTo(this, 'squareExpiresAt');
|
58
|
+
addPropertyTo(this, 'squareIsValid');
|
59
|
+
addPropertyTo(this, 'squareMerchantId');
|
60
|
+
addPropertyTo(this, 'squareWebLocationId');
|
61
|
+
addPropertyTo(this, 'stripePublishableKey');
|
62
|
+
addPropertyTo(this, 'stripeApiKey');
|
63
|
+
addPropertyTo(this, 'stripePublishableTestKey');
|
64
|
+
addPropertyTo(this, 'stripeApiTestKey');
|
65
|
+
addPropertyTo(this, 'stripeConnectDisabled');
|
66
|
+
addPropertyTo(this, 'unltdAiApiOrganizationId');
|
67
|
+
addPropertyTo(this, 'unltdAiApiSecretKey');
|
68
|
+
addPropertyTo(this, 'isStripeValid');
|
69
|
+
addPropertyTo(this, 'acceptSquare');
|
70
|
+
addPropertyTo(this, 'acceptStripe');
|
71
|
+
addPropertyTo(this, 'acceptPaypal');
|
72
|
+
addPropertyTo(this, 'acceptBankTransfer');
|
73
|
+
addPropertyTo(this, 'acceptPhonePayment');
|
74
|
+
addPropertyTo(this, 'ownershipUnconfirmed');
|
75
|
+
addPropertyTo(this, 'userCompanies', UserCompany);
|
76
|
+
addPropertyTo(this, 'phoneNumbers', PhoneNumber);
|
77
|
+
addPropertyTo(this, 'paymentPhoneNumbers', PhoneNumber);
|
78
|
+
addPropertyTo(this, 'emailAddresses', EmailAddress);
|
79
|
+
addPropertyTo(this, 'addresses', Address);
|
80
|
+
addPropertyTo(this, 'banks', Bank);
|
81
|
+
/* products that a company has saved for future reference */
|
82
|
+
addPropertyTo(this, 'savedProducts', Product);
|
83
|
+
addPropertyTo(this, 'companyInvitations', CompanyInvitation);
|
84
|
+
addPropertyTo(this, 'shipmentMethods', ShipmentMethod);
|
85
|
+
addPropertyTo(
|
86
|
+
this,
|
87
|
+
'automaticPaymentRelationships',
|
88
|
+
AutomaticPaymentRelationship,
|
89
|
+
);
|
90
|
+
addPropertyTo(
|
91
|
+
this,
|
92
|
+
'accessibleDomainsAsClientCompany',
|
93
|
+
Domain,
|
94
|
+
);
|
95
|
+
addPropertyTo(this, 'paymentDevices', PaymentDevice);
|
96
|
+
addPropertyTo(this, 'aiContext');
|
97
|
+
addPropertyTo(this, 'internalUseNotes');
|
98
|
+
addPropertyTo(this, 'internalUseAiContext');
|
99
|
+
addPropertyTo(this, 'internalTags', InternalTag);
|
100
|
+
|
101
|
+
this.create = function (success, error, embed, as_domain) {
|
102
|
+
var data = serialise(this),
|
103
|
+
self = this;
|
104
|
+
function handleResponse(result) {
|
105
|
+
success(fromJson(self, result[self.json]));
|
106
|
+
}
|
107
|
+
create({resource: this.resource,
|
108
|
+
parameters: data[0],
|
109
|
+
as_domain: as_domain,
|
110
|
+
files: enumerateFiles(data[1]),
|
111
|
+
success: handleResponse,
|
112
|
+
error: error,
|
113
|
+
embed: embed});
|
114
|
+
};
|
115
|
+
this.get = function (success, error, embed) {
|
116
|
+
var self = this;
|
117
|
+
function handleResponse(result) {
|
118
|
+
success(fromJson(self, result[self.json],
|
119
|
+
{makesDirty: false}));
|
120
|
+
}
|
121
|
+
getOne({resource: this.resource,
|
122
|
+
id: this.id(),
|
123
|
+
success: handleResponse,
|
124
|
+
error: error,
|
125
|
+
embed: embed});
|
126
|
+
};
|
127
|
+
|
128
|
+
this.patch = function (success, error, embed) {
|
129
|
+
var self = this,
|
130
|
+
data = serialise(this, undefined, undefined, undefined,
|
131
|
+
{exlcudeOld: true})[0];
|
132
|
+
function handleResponse(result) {
|
133
|
+
success(fromJson(self, result[self.json],
|
134
|
+
{makesDirty: false}));
|
135
|
+
}
|
136
|
+
patchOne({resource: this.resource,
|
137
|
+
id: self.id(),
|
138
|
+
success: handleResponse,
|
139
|
+
error: error,
|
140
|
+
data: data,
|
141
|
+
embed: embed});
|
142
|
+
};
|
143
|
+
|
144
|
+
this.invite = function (companyMemberData, success, error, embed) {
|
145
|
+
var request = new Request(),
|
146
|
+
data = new Dictionary(),
|
147
|
+
self = this,
|
148
|
+
_id = self.id();
|
149
|
+
|
150
|
+
function handleResponse(status, data) {
|
151
|
+
var newInvitation = new CompanyInvitation(),
|
152
|
+
invitation = data,
|
153
|
+
invitations = self.companyInvitations() ?
|
154
|
+
self.companyInvitations() : [];
|
155
|
+
newInvitation.id(invitation.id);
|
156
|
+
newInvitation.userEmail(invitation.userEmail);
|
157
|
+
newInvitation.userName(invitation.userName);
|
158
|
+
newInvitation.inviteAsAdmin(invitation.inviteAsAdmin);
|
159
|
+
invitations.push(newInvitation);
|
160
|
+
self.companyInvitations(invitations);
|
161
|
+
success(self);
|
162
|
+
}
|
163
|
+
|
164
|
+
data = new Dictionary();
|
165
|
+
data.add("inviteUserEmail", companyMemberData.emailAddress);
|
166
|
+
data.add("inviteUserName", companyMemberData.name);
|
167
|
+
data.add("company-id", _id);
|
168
|
+
data.add("asAdmin", companyMemberData.isAdmin);
|
169
|
+
request.resource('/company_invite/').method('POST');
|
170
|
+
request.data().merge(data);
|
171
|
+
request.responseHandler(handleResponse);
|
172
|
+
request.errorHandler(error);
|
173
|
+
request.send();
|
174
|
+
}
|
175
|
+
|
176
|
+
this.primaryEmailAddressEntity = function () {
|
177
|
+
var emails = this.emailAddresses();
|
178
|
+
return emails && emails[0] ? emails[0] : null;
|
179
|
+
}
|
180
|
+
|
181
|
+
this.primaryEmailAddress = function () {
|
182
|
+
var email = this.primaryEmailAddressEntity();
|
183
|
+
return email ? email.emailAddress() : null;
|
184
|
+
};
|
185
|
+
|
186
|
+
this.primaryPhoneNumberEntity = function () {
|
187
|
+
var numbers = this.phoneNumbers();
|
188
|
+
return numbers && numbers[0] ? numbers[0] : null;
|
189
|
+
}
|
190
|
+
|
191
|
+
this.primaryPhoneNumber = function () {
|
192
|
+
var primary = this.primaryPhoneNumberEntity();
|
193
|
+
return primary ? primary.internationalFormatNumber() : null;
|
194
|
+
};
|
195
|
+
|
196
|
+
this.primaryAddress = function () {
|
197
|
+
if (Boolean(this.addresses()) && Boolean(this.addresses()[0])) {
|
198
|
+
return this.addresses()[0];
|
199
|
+
}
|
200
|
+
return null;
|
201
|
+
};
|
202
|
+
|
203
|
+
this.stateAndCountryString = function () {
|
204
|
+
var self = this;
|
205
|
+
|
206
|
+
if (Boolean(self.primaryAddress())) {
|
207
|
+
return self.primaryAddress().stateAndCountryString();
|
208
|
+
}
|
209
|
+
return 'Address not shared.';
|
210
|
+
};
|
211
|
+
|
212
|
+
this.primaryAddressString = function () {
|
213
|
+
var self = this;
|
214
|
+
|
215
|
+
if (Boolean(self.primaryAddress())) {
|
216
|
+
return self.primaryAddress().fullAddressString();
|
217
|
+
}
|
218
|
+
return 'Address not shared.';
|
219
|
+
};
|
220
|
+
|
221
|
+
this.taxOptions = function () {
|
222
|
+
var defaultOptions = this.defaultTaxType(),
|
223
|
+
options = [];
|
224
|
+
options.push(NoTaxEntity());
|
225
|
+
if (defaultOptions) {
|
226
|
+
options.push(defaultOptions);
|
227
|
+
}
|
228
|
+
return options;
|
229
|
+
}
|
230
|
+
|
231
|
+
this.destroy = function (success, error) {
|
232
|
+
deleteOne(this.resource + "/" + this.id(), success, error);
|
233
|
+
};
|
234
|
+
|
235
|
+
this.paymentMethodIsValid = function (methodAttribute) {
|
236
|
+
var method = this[methodAttribute]();
|
237
|
+
return Array.isArray(method) && method.length > 0 && method[0].id();
|
238
|
+
}
|
239
|
+
|
240
|
+
this.arePhonePaymentsValid = function () {
|
241
|
+
return this.paymentMethodIsValid('paymentPhoneNumbers');
|
242
|
+
}
|
243
|
+
|
244
|
+
this.areBankPaymentsValid = function () {
|
245
|
+
return this.paymentMethodIsValid('banks');
|
246
|
+
}
|
247
|
+
|
248
|
+
this.logoUrl = function () {
|
249
|
+
var logo = this.logo();
|
250
|
+
return logo && logo.viewUrl() ? logo.viewUrl() : null;
|
251
|
+
}
|
252
|
+
}
|
253
|
+
|
254
|
+
export function Companies() {
|
255
|
+
this.resource = '/companies';
|
256
|
+
this.json = 'companies';
|
257
|
+
this.single = Company;
|
258
|
+
|
259
|
+
this.get = function (success, error, parameters) {
|
260
|
+
var self = this;
|
261
|
+
function handleResponse(result) {
|
262
|
+
success(fromJsonList(self, result,
|
263
|
+
{makesDirty: false}));
|
264
|
+
}
|
265
|
+
getList(this.resource, handleResponse, error, parameters);
|
266
|
+
};
|
267
|
+
}
|
@@ -0,0 +1,63 @@
|
|
1
|
+
import { generateUUID } from './uuid.js';
|
2
|
+
import { addPropertyTo, serialise, fromJson, create, enumerateFiles,
|
3
|
+
deleteOne, getList, fromJsonList, getOne } from './model.js';
|
4
|
+
|
5
|
+
export function CompanyInvitation() {
|
6
|
+
this.resource = '/company_invitations';
|
7
|
+
this.json = 'companyInvitation';
|
8
|
+
this.temporaryId = generateUUID();
|
9
|
+
|
10
|
+
addPropertyTo(this, 'id');
|
11
|
+
addPropertyTo(this, 'userName');
|
12
|
+
addPropertyTo(this, 'userEmail');
|
13
|
+
addPropertyTo(this, 'token');
|
14
|
+
addPropertyTo(this, 'inviteAsAdmin');
|
15
|
+
|
16
|
+
this.create = function (success, error, embed, as_domain) {
|
17
|
+
var data = serialise(this),
|
18
|
+
self = this;
|
19
|
+
function handleResponse(result) {
|
20
|
+
success(fromJson(self, result[self.json]));
|
21
|
+
}
|
22
|
+
create({resource: this.resource,
|
23
|
+
parameters: data[0],
|
24
|
+
as_domain: as_domain,
|
25
|
+
files: enumerateFiles(data[1]),
|
26
|
+
success: handleResponse,
|
27
|
+
data: error,
|
28
|
+
embed: embed});
|
29
|
+
};
|
30
|
+
|
31
|
+
this.get = function (success, error) {
|
32
|
+
var self = this;
|
33
|
+
function handleResponse(result) {
|
34
|
+
success(fromJson(self, result[self.json],
|
35
|
+
{makesDirty: false}));
|
36
|
+
}
|
37
|
+
getOne({resource: this.resource,
|
38
|
+
id: this.id(),
|
39
|
+
success: handleResponse,
|
40
|
+
error: error});
|
41
|
+
};
|
42
|
+
|
43
|
+
this.destroy = function (success, error) {
|
44
|
+
deleteOne(this.resource + "/" + this.id(), success, error);
|
45
|
+
};
|
46
|
+
|
47
|
+
}
|
48
|
+
|
49
|
+
export function CompanyInvitations() {
|
50
|
+
this.resource = '/company_invitations';
|
51
|
+
this.json = 'companyInvitations';
|
52
|
+
this.single = CompanyInvitation;
|
53
|
+
|
54
|
+
this.get = function (success, error, offset, limit, q) {
|
55
|
+
var self = this;
|
56
|
+
function handleResponse(result) {
|
57
|
+
success(fromJsonList(self, result, {makesDirty: false}));
|
58
|
+
}
|
59
|
+
getList(this.resource, handleResponse, error,
|
60
|
+
{offset: offset, limit: limit, q: q});
|
61
|
+
};
|
62
|
+
}
|
63
|
+
|
package/src/component.js
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
import { generateUUID } from './uuid.js';
|
2
|
+
import { addPropertyTo, fromJson, getOne, serialise, enumerateFiles, patchOne,
|
3
|
+
fromJsonList, getList, create } from './model.js';
|
4
|
+
import { MerchiFile } from './merchi_file.js';
|
5
|
+
import { ComponentTag } from './component_tag.js';
|
6
|
+
import { User } from './user.js';
|
7
|
+
|
8
|
+
export function Component() {
|
9
|
+
this.resource = '/components';
|
10
|
+
this.json = 'component';
|
11
|
+
this.temporaryId = generateUUID();
|
12
|
+
|
13
|
+
addPropertyTo(this, 'id');
|
14
|
+
addPropertyTo(this, 'archived');
|
15
|
+
addPropertyTo(this, 'componentImports', Component);
|
16
|
+
addPropertyTo(this, 'componentExport', Component);
|
17
|
+
addPropertyTo(this, 'componentExports', Component);
|
18
|
+
addPropertyTo(this, 'created');
|
19
|
+
addPropertyTo(this, 'updated');
|
20
|
+
addPropertyTo(this, 'name');
|
21
|
+
addPropertyTo(this, 'needsUpdate');
|
22
|
+
addPropertyTo(this, 'outOfSyncWithOriginal');
|
23
|
+
addPropertyTo(this, 'hasImports');
|
24
|
+
addPropertyTo(this, 'isClone');
|
25
|
+
addPropertyTo(this, 'warnings');
|
26
|
+
addPropertyTo(this, 'body');
|
27
|
+
addPropertyTo(this, 'description');
|
28
|
+
addPropertyTo(this, 'compiled');
|
29
|
+
addPropertyTo(this, 'originalComponent', Component);
|
30
|
+
addPropertyTo(this, 'createdBy', User);
|
31
|
+
addPropertyTo(this, 'updatedBy', User);
|
32
|
+
addPropertyTo(this, 'featureImage', MerchiFile);
|
33
|
+
addPropertyTo(this, 'images', MerchiFile);
|
34
|
+
addPropertyTo(this, 'tags', ComponentTag);
|
35
|
+
|
36
|
+
this.get = function (success, error, embed) {
|
37
|
+
var self = this;
|
38
|
+
function handleResponse(result) {
|
39
|
+
success(fromJson(self, result[self.json],
|
40
|
+
{makesDirty: false}));
|
41
|
+
}
|
42
|
+
getOne({resource: this.resource,
|
43
|
+
id: this.id(),
|
44
|
+
success: handleResponse,
|
45
|
+
error: error,
|
46
|
+
embed: embed});
|
47
|
+
};
|
48
|
+
|
49
|
+
this.create = function (success, error, embed, domainId) {
|
50
|
+
var data = serialise(this),
|
51
|
+
self = this;
|
52
|
+
function handleResponse(result) {
|
53
|
+
success(fromJson(self, result[self.json]));
|
54
|
+
}
|
55
|
+
create({resource: this.resource,
|
56
|
+
parameters: data[0],
|
57
|
+
files: enumerateFiles(data[1]),
|
58
|
+
success: handleResponse,
|
59
|
+
error: error,
|
60
|
+
embed: embed,
|
61
|
+
as_domain: domainId});
|
62
|
+
};
|
63
|
+
|
64
|
+
this.patch = function (success, error, embed) {
|
65
|
+
var self = this,
|
66
|
+
data = serialise(this)[0];
|
67
|
+
function handleResponse(result) {
|
68
|
+
success(fromJson(self, result[self.json],
|
69
|
+
{makesDirty: false}));
|
70
|
+
}
|
71
|
+
patchOne({resource: this.resource,
|
72
|
+
id: this.id(),
|
73
|
+
success: handleResponse,
|
74
|
+
error: error,
|
75
|
+
data: data,
|
76
|
+
embed: embed});
|
77
|
+
};
|
78
|
+
|
79
|
+
this.toReact = function (context) {
|
80
|
+
const componentCode = 'with (this) { ' + this.compiled() + ' return ' +
|
81
|
+
this.name() + ';}';
|
82
|
+
const proxy = new Proxy(context, {});
|
83
|
+
const callable = new Function(componentCode);
|
84
|
+
return callable.call(proxy);
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
export function Components() {
|
89
|
+
this.resource = '/components';
|
90
|
+
this.json = 'components';
|
91
|
+
this.single = Component;
|
92
|
+
|
93
|
+
this.get = function (success, error, parameters) {
|
94
|
+
var self = this;
|
95
|
+
function handleResponse(result) {
|
96
|
+
success(fromJsonList(self, result, {makesDirty: false}));
|
97
|
+
}
|
98
|
+
getList(this.resource, handleResponse, error, parameters);
|
99
|
+
};
|
100
|
+
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import { generateUUID } from './uuid.js';
|
2
|
+
import { addPropertyTo, fromJson, getOne, serialise, create, enumerateFiles,
|
3
|
+
fromJsonList, getList } from './model.js';
|
4
|
+
|
5
|
+
export function ComponentTag() {
|
6
|
+
this.resource = '/component_tags';
|
7
|
+
this.json = 'componentTag';
|
8
|
+
this.temporaryId = generateUUID();
|
9
|
+
|
10
|
+
addPropertyTo(this, 'id');
|
11
|
+
addPropertyTo(this, 'name');
|
12
|
+
|
13
|
+
this.get = function (success, error) {
|
14
|
+
var self = this;
|
15
|
+
function handleResponse(result) {
|
16
|
+
success(fromJson(self, result[self.json],
|
17
|
+
{makesDirty: false}));
|
18
|
+
}
|
19
|
+
getOne({resource: this.resource,
|
20
|
+
id: this.id(),
|
21
|
+
success: handleResponse,
|
22
|
+
error: error});
|
23
|
+
};
|
24
|
+
|
25
|
+
this.create = function (success, error, embed, domainId) {
|
26
|
+
var data = serialise(this),
|
27
|
+
self = this;
|
28
|
+
function handleResponse(result) {
|
29
|
+
success(fromJson(self, result[self.json]));
|
30
|
+
}
|
31
|
+
create({resource: this.resource,
|
32
|
+
parameters: data[0],
|
33
|
+
files: enumerateFiles(data[1]),
|
34
|
+
success: handleResponse,
|
35
|
+
error: error,
|
36
|
+
embed: embed,
|
37
|
+
as_domain: domainId});
|
38
|
+
};
|
39
|
+
}
|
40
|
+
|
41
|
+
export function ComponentTags() {
|
42
|
+
this.resource = '/component_tags';
|
43
|
+
this.json = 'componentTags';
|
44
|
+
this.single = ComponentTag;
|
45
|
+
|
46
|
+
this.get = function (success, error, parameters) {
|
47
|
+
var self = this;
|
48
|
+
function handleResponse(result) {
|
49
|
+
success(fromJsonList(self, result, {makesDirty: false}));
|
50
|
+
}
|
51
|
+
getList(this.resource, handleResponse, error, parameters);
|
52
|
+
};
|
53
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { generateUUID } from './uuid.js';
|
2
|
+
import { addPropertyTo } from './model.js';
|
3
|
+
import { Component } from './component.js';
|
4
|
+
|
5
|
+
export function ComponentVersion() {
|
6
|
+
this.json = 'componentVersion';
|
7
|
+
this.temporaryId = generateUUID();
|
8
|
+
|
9
|
+
addPropertyTo(this, 'id');
|
10
|
+
addPropertyTo(this, 'archived');
|
11
|
+
addPropertyTo(this, 'component', Component);
|
12
|
+
addPropertyTo(this, 'created');
|
13
|
+
addPropertyTo(this, 'isClassBased');
|
14
|
+
addPropertyTo(this, 'description');
|
15
|
+
addPropertyTo(this, 'name');
|
16
|
+
addPropertyTo(this, 'body');
|
17
|
+
}
|
@@ -0,0 +1,89 @@
|
|
1
|
+
import { addPropertyTo, create, serialise, fromJson, enumerateFiles, getOne,
|
2
|
+
deleteOne, fromJsonList, getList } from './model.js';
|
3
|
+
|
4
|
+
export function CountryTax() {
|
5
|
+
this.resource = '/country_taxes';
|
6
|
+
this.json = 'countryTax';
|
7
|
+
|
8
|
+
addPropertyTo(this, 'id');
|
9
|
+
addPropertyTo(this, 'country');
|
10
|
+
addPropertyTo(this, 'taxName');
|
11
|
+
addPropertyTo(this, 'taxPercent');
|
12
|
+
|
13
|
+
this.create = function (success, error, embed, as_domain) {
|
14
|
+
var data = serialise(this),
|
15
|
+
self = this;
|
16
|
+
function handleResponse(result) {
|
17
|
+
success(fromJson(self, result[self.json]));
|
18
|
+
}
|
19
|
+
create({resource: this.resource,
|
20
|
+
parameters: data[0],
|
21
|
+
as_domain: as_domain,
|
22
|
+
files: enumerateFiles(data[1]),
|
23
|
+
success: handleResponse,
|
24
|
+
error: error,
|
25
|
+
embed: embed});
|
26
|
+
};
|
27
|
+
this.get = function (success, error) {
|
28
|
+
var self = this;
|
29
|
+
function handleResponse(result) {
|
30
|
+
success(fromJson(self, result[self.json],
|
31
|
+
{makesDirty: false}));
|
32
|
+
}
|
33
|
+
getOne({resource: this.resource,
|
34
|
+
id: this.id(),
|
35
|
+
success: handleResponse,
|
36
|
+
error: error});
|
37
|
+
};
|
38
|
+
|
39
|
+
this.destroy = function (success, error) {
|
40
|
+
deleteOne(this.resource + "/" + this.id(), success, error);
|
41
|
+
};
|
42
|
+
|
43
|
+
this.wrapedRepresentation = function () {
|
44
|
+
var representation = this.taxName();
|
45
|
+
if (this.country()) {
|
46
|
+
representation += " (" + this.country() + ")";
|
47
|
+
}
|
48
|
+
return representation;
|
49
|
+
};
|
50
|
+
}
|
51
|
+
|
52
|
+
export function CountryTaxes() {
|
53
|
+
this.resource = '/country_taxes';
|
54
|
+
this.json = 'countryTaxes';
|
55
|
+
this.single = CountryTax;
|
56
|
+
|
57
|
+
this.get = function (success, error, parameters) {
|
58
|
+
var self = this;
|
59
|
+
function handleResponse(result) {
|
60
|
+
success(fromJsonList(self, result,
|
61
|
+
{makesDirty: false}));
|
62
|
+
}
|
63
|
+
getList(this.resource, handleResponse, error,
|
64
|
+
parameters);
|
65
|
+
};
|
66
|
+
|
67
|
+
this.jsonsForOptions = function (taxes, selectedTaxId) {
|
68
|
+
var result = [],
|
69
|
+
i;
|
70
|
+
for (i = 0; i < taxes.length; i++) {
|
71
|
+
result.push({name: taxes[i].wrapedRepresentation(),
|
72
|
+
selected: selectedTaxId &&
|
73
|
+
taxes[i].id() === selectedTaxId ||
|
74
|
+
!selectedTaxId &&
|
75
|
+
taxes[i].id() === window.taxType,
|
76
|
+
id: taxes[i].id()});
|
77
|
+
}
|
78
|
+
return result;
|
79
|
+
};
|
80
|
+
}
|
81
|
+
|
82
|
+
export function NoTaxEntity() {
|
83
|
+
var tax = new CountryTax();
|
84
|
+
return fromJson(
|
85
|
+
tax,
|
86
|
+
{id: null, taxName: 'No tax', taxPercent: 0},
|
87
|
+
{makesDirty: false}
|
88
|
+
);
|
89
|
+
}
|