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/address.js
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
import { generateUUID } from './uuid.js';
|
2
|
+
import { addPropertyTo, fromJson, getOne, fromJsonList,
|
3
|
+
Request } from './model.js'
|
4
|
+
import { isUndefinedOrNull } from './helpers.js';
|
5
|
+
import { Dictionary } from './dictionary.js';
|
6
|
+
|
7
|
+
export function Address() {
|
8
|
+
this.resource = '/addresses';
|
9
|
+
this.json = 'address';
|
10
|
+
this.temporaryId = generateUUID();
|
11
|
+
|
12
|
+
addPropertyTo(this, 'id');
|
13
|
+
addPropertyTo(this, 'lineOne');
|
14
|
+
addPropertyTo(this, 'lineTwo');
|
15
|
+
addPropertyTo(this, 'city');
|
16
|
+
addPropertyTo(this, 'state');
|
17
|
+
addPropertyTo(this, 'country');
|
18
|
+
addPropertyTo(this, 'postcode');
|
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
|
+
this.fullAddressString = function () {
|
32
|
+
var self = this, a = '', space = ' ', noSpace = '';
|
33
|
+
function attributeHasValue(attr, before, after) {
|
34
|
+
var value = self[attr]();
|
35
|
+
return !isUndefinedOrNull(value) ? before + value + after : '';
|
36
|
+
}
|
37
|
+
a = attributeHasValue('lineOne', noSpace, noSpace);
|
38
|
+
a += attributeHasValue('lineTwo', space, ',');
|
39
|
+
a += attributeHasValue('city', space, space);
|
40
|
+
a += attributeHasValue('state', noSpace, space);
|
41
|
+
a += attributeHasValue('postcode', noSpace, space);
|
42
|
+
a += attributeHasValue('country', noSpace, noSpace);
|
43
|
+
return a;
|
44
|
+
};
|
45
|
+
|
46
|
+
this.stateAndCountryString = function () {
|
47
|
+
var addressString = '';
|
48
|
+
addressString += this.state() + " ";
|
49
|
+
addressString += this.country();
|
50
|
+
return addressString;
|
51
|
+
};
|
52
|
+
|
53
|
+
this.cityStateCountryPostcode = function () {
|
54
|
+
return this.city() + " " + this.stateAndCountryString() +
|
55
|
+
", " + this.postcode();
|
56
|
+
}
|
57
|
+
|
58
|
+
this.isValid = function () {
|
59
|
+
return Boolean(this.lineOne() && this.city() &&
|
60
|
+
this.state() && this.country());
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
|
65
|
+
export function Addresses() {
|
66
|
+
this.resource = '/addresses';
|
67
|
+
this.json = 'addresses';
|
68
|
+
this.single = Address;
|
69
|
+
|
70
|
+
this.getRelated = function (options) {
|
71
|
+
var request = new Request(),
|
72
|
+
query = new Dictionary(),
|
73
|
+
self = this,
|
74
|
+
success = options.success,
|
75
|
+
error = options.error,
|
76
|
+
userId = options.userId,
|
77
|
+
companyId = options.companyId,
|
78
|
+
jobId = options.jobId;
|
79
|
+
if (userId) {
|
80
|
+
query.add('user_id', userId);
|
81
|
+
}
|
82
|
+
if (companyId) {
|
83
|
+
query.add('company_id', companyId);
|
84
|
+
}
|
85
|
+
if (jobId) {
|
86
|
+
query.add('job_id', jobId);
|
87
|
+
}
|
88
|
+
request.resource('/related-addresses/');
|
89
|
+
request.method('GET');
|
90
|
+
request.query().merge(query);
|
91
|
+
function handleResponse(status, data) {
|
92
|
+
if (status === 200) {
|
93
|
+
success(fromJsonList(self, data));
|
94
|
+
} else {
|
95
|
+
error(data);
|
96
|
+
}
|
97
|
+
}
|
98
|
+
function handleError(status, data) {
|
99
|
+
var responseData = data ? data :
|
100
|
+
{message: 'could not connect to server',
|
101
|
+
errorCode: 0}
|
102
|
+
error(status, responseData);
|
103
|
+
}
|
104
|
+
request.responseHandler(handleResponse).errorHandler(handleError);
|
105
|
+
request.send();
|
106
|
+
};
|
107
|
+
}
|
@@ -0,0 +1,165 @@
|
|
1
|
+
import { generateUUID } from './uuid.js';
|
2
|
+
import { addPropertyTo, fromJson, create, serialise, enumerateFiles, getList,
|
3
|
+
patchOne, fromJsonList, getOne } from './model.js';
|
4
|
+
import { notificationTypes, notificationRecieverIsCurrentUserFilter,
|
5
|
+
notificationsFilter } from './notification_types.js';
|
6
|
+
import { Job } from './job.js';
|
7
|
+
import { User } from './user.js';
|
8
|
+
import { Notification } from './notification.js';
|
9
|
+
import { Quote } from './quote.js';
|
10
|
+
import { Shipment } from './shipment.js';
|
11
|
+
import { SupplyDomain } from './supply_domain.js';
|
12
|
+
import { ProductionComment } from './production_comment.js';
|
13
|
+
|
14
|
+
export function Assignment() {
|
15
|
+
this.resource = '/assignments';
|
16
|
+
this.json = 'assignment';
|
17
|
+
this.temporaryId = generateUUID();
|
18
|
+
|
19
|
+
addPropertyTo(this, 'id');
|
20
|
+
addPropertyTo(this, 'managerAccepts');
|
21
|
+
addPropertyTo(this, 'supplierRefused');
|
22
|
+
addPropertyTo(this, 'productionDeadline');
|
23
|
+
addPropertyTo(this, 'assignmentDeadline');
|
24
|
+
addPropertyTo(this, 'needsDrafting');
|
25
|
+
addPropertyTo(this, 'needsShipping');
|
26
|
+
addPropertyTo(this, 'archived');
|
27
|
+
addPropertyTo(this, 'job', Job);
|
28
|
+
addPropertyTo(this, 'supplyJob', Job);
|
29
|
+
addPropertyTo(this, 'supplier', User);
|
30
|
+
addPropertyTo(this, 'quote', Quote);
|
31
|
+
addPropertyTo(this, 'shipment', Shipment);
|
32
|
+
addPropertyTo(this, 'supplyDomain', SupplyDomain);
|
33
|
+
addPropertyTo(this, 'comments', ProductionComment);
|
34
|
+
addPropertyTo(this, 'notifications', Notification);
|
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.agreedDeadline = function () {
|
50
|
+
var self = this,
|
51
|
+
quote = self.quote();
|
52
|
+
if (Boolean(quote)) {
|
53
|
+
return quote.agreedDeadline();
|
54
|
+
}
|
55
|
+
return null;
|
56
|
+
};
|
57
|
+
|
58
|
+
this.create = function (success, error, embed, asDomainId) {
|
59
|
+
var data = serialise(this),
|
60
|
+
self = this;
|
61
|
+
function handleResponse(result) {
|
62
|
+
success(fromJson(self, result[self.json]));
|
63
|
+
}
|
64
|
+
create({resource: this.resource,
|
65
|
+
parameters: data[0],
|
66
|
+
as_domain: asDomainId,
|
67
|
+
files: enumerateFiles(data[1]),
|
68
|
+
success: handleResponse,
|
69
|
+
error: error,
|
70
|
+
embed: embed});
|
71
|
+
};
|
72
|
+
|
73
|
+
this.patch = function (success, error, embed, asDomain) {
|
74
|
+
var self = this,
|
75
|
+
data = serialise(this, undefined, undefined, undefined,
|
76
|
+
{excludeOld: true})[0],
|
77
|
+
domainId = Boolean(asDomain) ? asDomain.id() : null;
|
78
|
+
function handleResponse(result) {
|
79
|
+
success(fromJson(self, result[self.json],
|
80
|
+
{makesDirty: false}));
|
81
|
+
}
|
82
|
+
patchOne({resource: this.resource,
|
83
|
+
id: this.id(),
|
84
|
+
success: handleResponse,
|
85
|
+
error: error,
|
86
|
+
as_domain: domainId,
|
87
|
+
data: data,
|
88
|
+
embed: embed});
|
89
|
+
};
|
90
|
+
|
91
|
+
this.setManagerAccepts = function () {
|
92
|
+
var acceptDate = Date.now();
|
93
|
+
this.managerAccepts(acceptDate / 1000);
|
94
|
+
};
|
95
|
+
|
96
|
+
this.agreedDeadline = function () {
|
97
|
+
var self = this,
|
98
|
+
quote = self.quote();
|
99
|
+
if (Boolean(quote) && Boolean(quote.agreedDeadline())) {
|
100
|
+
return quote.agreedDeadline();
|
101
|
+
}
|
102
|
+
return null;
|
103
|
+
};
|
104
|
+
this.unseenNotifications = function (currentUser) {
|
105
|
+
var notifications =
|
106
|
+
notificationRecieverIsCurrentUserFilter(currentUser,
|
107
|
+
this.notifications());
|
108
|
+
return notificationsFilter(notifications, [{'seen': false}]);
|
109
|
+
};
|
110
|
+
|
111
|
+
this.unseenNotificationCount = function (currentUser) {
|
112
|
+
return this.unseenNotifications(currentUser).length;
|
113
|
+
};
|
114
|
+
|
115
|
+
this.unseenCommentNotifications = function (currentUser) {
|
116
|
+
var noteType = notificationTypes.get('PRODUCTION_COMMENT'),
|
117
|
+
notifications = this.unseenNotifications(currentUser);
|
118
|
+
return notificationsFilter(notifications,
|
119
|
+
[{'notificationType': noteType}]);
|
120
|
+
};
|
121
|
+
|
122
|
+
this.unseenCommentNotificationsCount = function (currentUser) {
|
123
|
+
return this.unseenCommentNotifications(currentUser).length;
|
124
|
+
};
|
125
|
+
|
126
|
+
this.unseenQuoteNotifications = function (currentUser) {
|
127
|
+
var approved = notificationTypes.get('QUOTE_APPROVED'),
|
128
|
+
supplierRefused = notificationTypes.get('SUPPLIER_REFUSED'),
|
129
|
+
refused = notificationTypes.get('QUOTE_REFUSED'),
|
130
|
+
submitted = notificationTypes.get('QUOTE_SUBMITTED'),
|
131
|
+
failed = notificationTypes.get('QUOTE_FAILED'),
|
132
|
+
commenced = notificationTypes.get('QUOTE_COMMENCED'),
|
133
|
+
expired = notificationTypes.get('QUOTE_EXPIRED'),
|
134
|
+
notifications = this.unseenNotifications(currentUser);
|
135
|
+
return notificationsFilter(notifications,
|
136
|
+
[{'notificationType': approved}, {'notificationType': refused},
|
137
|
+
{'notificationType': submitted}, {'notificationType': failed},
|
138
|
+
{'notificationType': commenced}, {'notificationType': expired},
|
139
|
+
{'notificationType': supplierRefused}]);
|
140
|
+
};
|
141
|
+
|
142
|
+
this.isUserSupplier = function (user) {
|
143
|
+
var self = this;
|
144
|
+
if (Boolean(self.supplier()) &&
|
145
|
+
self.supplier().id() === user.id()) {
|
146
|
+
return true;
|
147
|
+
}
|
148
|
+
return false;
|
149
|
+
};
|
150
|
+
}
|
151
|
+
|
152
|
+
export function Assignments() {
|
153
|
+
this.resource = '/assignments';
|
154
|
+
this.json = 'assignments';
|
155
|
+
this.single = Assignment;
|
156
|
+
|
157
|
+
this.get = function (success, error, parameters, withUpdates) {
|
158
|
+
var self = this;
|
159
|
+
function handleResponse(result) {
|
160
|
+
success(fromJsonList(self, result, {makesDirty: false}));
|
161
|
+
}
|
162
|
+
getList(this.resource, handleResponse, error,
|
163
|
+
parameters, withUpdates);
|
164
|
+
};
|
165
|
+
}
|
@@ -0,0 +1,65 @@
|
|
1
|
+
import { Company } from './company.js';
|
2
|
+
import { generateUUID } from './uuid.js';
|
3
|
+
import {
|
4
|
+
addPropertyTo, serialise, fromJson, create, enumerateFiles,
|
5
|
+
deleteOne, getList, fromJsonList, getOne } from './model.js';
|
6
|
+
|
7
|
+
export function AutomaticPaymentRelationship() {
|
8
|
+
this.resource = '/automatic_payment_relationships';
|
9
|
+
this.json = 'automaticPaymentRelationship';
|
10
|
+
this.temporaryId = generateUUID();
|
11
|
+
|
12
|
+
addPropertyTo(this, 'archived');
|
13
|
+
addPropertyTo(this, 'id');
|
14
|
+
addPropertyTo(this, 'creationDate');
|
15
|
+
addPropertyTo(this, 'stripeCustomerId');
|
16
|
+
addPropertyTo(this, 'companyCustomer', Company);
|
17
|
+
addPropertyTo(this, 'companySupplier', Company);
|
18
|
+
|
19
|
+
this.create = function (success, error, embed, as_domain) {
|
20
|
+
var data = serialise(this),
|
21
|
+
self = this;
|
22
|
+
function handleResponse(result) {
|
23
|
+
success(fromJson(self, result[self.json]));
|
24
|
+
}
|
25
|
+
create({resource: this.resource,
|
26
|
+
parameters: data[0],
|
27
|
+
as_domain: as_domain,
|
28
|
+
files: enumerateFiles(data[1]),
|
29
|
+
success: handleResponse,
|
30
|
+
data: error,
|
31
|
+
embed: embed});
|
32
|
+
};
|
33
|
+
|
34
|
+
this.get = function (success, error) {
|
35
|
+
var self = this;
|
36
|
+
function handleResponse(result) {
|
37
|
+
success(fromJson(self, result[self.json],
|
38
|
+
{makesDirty: false}));
|
39
|
+
}
|
40
|
+
getOne({resource: this.resource,
|
41
|
+
id: this.id(),
|
42
|
+
success: handleResponse,
|
43
|
+
error: error});
|
44
|
+
};
|
45
|
+
|
46
|
+
this.destroy = function (success, error) {
|
47
|
+
deleteOne(this.resource + "/" + this.id(), success, error);
|
48
|
+
};
|
49
|
+
|
50
|
+
}
|
51
|
+
|
52
|
+
export function AutomaticPaymentRelationships() {
|
53
|
+
this.resource = '/automatic_payment_relationships';
|
54
|
+
this.json = 'automaticPaymentRelationships';
|
55
|
+
this.single = AutomaticPaymentRelationship;
|
56
|
+
|
57
|
+
this.get = function (success, error, offset, limit, q) {
|
58
|
+
var self = this;
|
59
|
+
function handleResponse(result) {
|
60
|
+
success(fromJsonList(self, result, {makesDirty: false}));
|
61
|
+
}
|
62
|
+
getList(this.resource, handleResponse, error,
|
63
|
+
{offset: offset, limit: limit, q: q});
|
64
|
+
};
|
65
|
+
}
|
package/src/backup.js
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
import { addPropertyTo, deleteOne, fromJsonList, getList } from './model.js'
|
2
|
+
import { MerchiFile } from './merchi_file.js';
|
3
|
+
|
4
|
+
export function Backup() {
|
5
|
+
this.resource = '/backups';
|
6
|
+
this.json = 'backup';
|
7
|
+
|
8
|
+
addPropertyTo(this, 'id');
|
9
|
+
addPropertyTo(this, 'file', MerchiFile);
|
10
|
+
|
11
|
+
this.destroy = function (success, error) {
|
12
|
+
deleteOne(this.resource + "/" + this.id(), success, error);
|
13
|
+
};
|
14
|
+
}
|
15
|
+
|
16
|
+
export function Backups() {
|
17
|
+
this.resource = '/backups';
|
18
|
+
this.json = 'backups';
|
19
|
+
this.single = Backup;
|
20
|
+
|
21
|
+
this.get = function (success, error, parameters) {
|
22
|
+
var self = this;
|
23
|
+
function handleResponse(result) {
|
24
|
+
success(fromJsonList(self, result, {makesDirty: false}));
|
25
|
+
}
|
26
|
+
getList(this.resource, handleResponse, error,
|
27
|
+
parameters);
|
28
|
+
};
|
29
|
+
}
|
package/src/bank.js
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
import { generateUUID } from './uuid.js';
|
2
|
+
import { addPropertyTo } from './model.js';
|
3
|
+
import { Address } from './address.js';
|
4
|
+
import { Companies } from './company.js';
|
5
|
+
|
6
|
+
export function Bank() {
|
7
|
+
this.resource = '/banks';
|
8
|
+
this.json = 'bank';
|
9
|
+
this.temporaryId = generateUUID();
|
10
|
+
|
11
|
+
addPropertyTo(this, 'id');
|
12
|
+
addPropertyTo(this, 'bankName');
|
13
|
+
addPropertyTo(this, 'accountNumber');
|
14
|
+
addPropertyTo(this, 'accountName');
|
15
|
+
addPropertyTo(this, 'bsb');
|
16
|
+
addPropertyTo(this, 'swiftCode');
|
17
|
+
addPropertyTo(this, 'iban');
|
18
|
+
addPropertyTo(this, 'bankCode');
|
19
|
+
addPropertyTo(this, 'bankAddress', Address);
|
20
|
+
addPropertyTo(this, 'company', Companies);
|
21
|
+
}
|
package/src/cart.js
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
import { generateUUID } from './uuid.js';
|
2
|
+
import { addPropertyTo, serialise, enumerateFiles, getOne, fromJson, patchOne,
|
3
|
+
create } from './model.js';
|
4
|
+
import { Address } from './address.js';
|
5
|
+
import { CartItem } from './cart_item.js';
|
6
|
+
import { CartShipmentGroup } from './cart_shipment_group.js';
|
7
|
+
import { Company } from './company.js';
|
8
|
+
import { Domain } from './domain.js';
|
9
|
+
import { Invoice } from './invoice.js';
|
10
|
+
import { Shipment } from './shipment.js';
|
11
|
+
import { User } from './user.js';
|
12
|
+
|
13
|
+
|
14
|
+
export function Cart() {
|
15
|
+
this.resource = '/carts';
|
16
|
+
this.json = 'cart';
|
17
|
+
this.temporaryId = generateUUID();
|
18
|
+
|
19
|
+
addPropertyTo(this, 'id');
|
20
|
+
addPropertyTo(this, 'token');
|
21
|
+
addPropertyTo(this, 'ip');
|
22
|
+
addPropertyTo(this, 'client', User);
|
23
|
+
addPropertyTo(this, 'clientCompany', Company);
|
24
|
+
addPropertyTo(this, 'creationDate');
|
25
|
+
addPropertyTo(this, 'domain', Domain);
|
26
|
+
addPropertyTo(this, 'subtotalCost');
|
27
|
+
addPropertyTo(this, 'taxAmount');
|
28
|
+
addPropertyTo(this, 'totalCost');
|
29
|
+
addPropertyTo(this, 'cartItems', CartItem);
|
30
|
+
addPropertyTo(this, 'cartItemsSubtotalCost');
|
31
|
+
addPropertyTo(this, 'cartItemsTaxAmount');
|
32
|
+
addPropertyTo(this, 'cartItemsTotalCost');
|
33
|
+
addPropertyTo(this, 'shipmentSubtotalCost');
|
34
|
+
addPropertyTo(this, 'shipmentTaxAmount');
|
35
|
+
addPropertyTo(this, 'shipmentTotalCost');
|
36
|
+
addPropertyTo(this, 'currency');
|
37
|
+
addPropertyTo(this, 'receiverNotes');
|
38
|
+
addPropertyTo(this, 'shipmentGroups', CartShipmentGroup);
|
39
|
+
addPropertyTo(this, 'invoice', Invoice);
|
40
|
+
addPropertyTo(this, 'shipment', Shipment);
|
41
|
+
addPropertyTo(this, 'receiverAddress', Address);
|
42
|
+
|
43
|
+
this.create = function (success, error, embed, asDomain) {
|
44
|
+
var self = this,
|
45
|
+
data = serialise(self);
|
46
|
+
function handleResponse(result) {
|
47
|
+
success(fromJson(self, result[self.json]));
|
48
|
+
}
|
49
|
+
create({resource: this.resource,
|
50
|
+
parameters: data[0],
|
51
|
+
as_domain: asDomain,
|
52
|
+
files: enumerateFiles(data[1]),
|
53
|
+
success: handleResponse,
|
54
|
+
error: error,
|
55
|
+
embed: embed});
|
56
|
+
};
|
57
|
+
|
58
|
+
this.get = function (success, error, embed, includeArchived,
|
59
|
+
withRights) {
|
60
|
+
var self = this,
|
61
|
+
parameters = {
|
62
|
+
cartToken: this.token(),
|
63
|
+
embed: embed,
|
64
|
+
error: error,
|
65
|
+
id: this.id(),
|
66
|
+
includeArchived: includeArchived,
|
67
|
+
withRights: withRights,
|
68
|
+
resource: this.resource};
|
69
|
+
function handleResponse(result) {
|
70
|
+
success(fromJson(self, result[self.json],
|
71
|
+
{makesDirty: false}));
|
72
|
+
}
|
73
|
+
parameters.success = handleResponse;
|
74
|
+
getOne(parameters);
|
75
|
+
};
|
76
|
+
|
77
|
+
this.patch = function (success, error, embed) {
|
78
|
+
var self = this,
|
79
|
+
data = serialise(this, undefined, undefined, undefined,
|
80
|
+
{excludeOld: true})[0];
|
81
|
+
function handleResponse(result) {
|
82
|
+
success(fromJson(self, result[self.json],
|
83
|
+
{makesDirty: false}));
|
84
|
+
}
|
85
|
+
patchOne({cartToken: this.token(),
|
86
|
+
resource: this.resource,
|
87
|
+
id: this.id(),
|
88
|
+
success: handleResponse,
|
89
|
+
error: error,
|
90
|
+
data: data,
|
91
|
+
embed: embed});
|
92
|
+
};
|
93
|
+
|
94
|
+
this.getShipmentGroupsAndQuotes = function (success, error) {
|
95
|
+
var self = this,
|
96
|
+
request = new Request();
|
97
|
+
request.resource(`/generate-cart-shipment-quotes/${self.id()}/`);
|
98
|
+
request.method('GET');
|
99
|
+
request.query().add('cart_token', this.token());
|
100
|
+
function handleResponse(status, data) {
|
101
|
+
if (status === 200) {
|
102
|
+
success(fromJson(self, data, {makesDirty: false}));
|
103
|
+
} else {
|
104
|
+
error(status, data);
|
105
|
+
}
|
106
|
+
}
|
107
|
+
request.responseHandler(handleResponse).errorHandler(error);
|
108
|
+
request.send();
|
109
|
+
};
|
110
|
+
|
111
|
+
this.requiresShipment = function () {
|
112
|
+
var cartItems = this.cartItems() ? this.cartItems() : [],
|
113
|
+
i;
|
114
|
+
for (i = 0; i < cartItems.length; i++) {
|
115
|
+
if (cartItems[i].requiresShipment()) {
|
116
|
+
return true;
|
117
|
+
}
|
118
|
+
}
|
119
|
+
};
|
120
|
+
|
121
|
+
this.stripePublishableKey = function () {
|
122
|
+
return this.domain().company() ?
|
123
|
+
this.domain().company().stripePublishableKey() : null;
|
124
|
+
};
|
125
|
+
|
126
|
+
this.stripeIsValidAndActive = function () {
|
127
|
+
const company = this.domain().company();
|
128
|
+
return this.stripePublishableKey() && company &&
|
129
|
+
company.acceptStripe();
|
130
|
+
};
|
131
|
+
}
|
package/src/cart_item.js
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
import { generateUUID } from './uuid.js';
|
2
|
+
import { addPropertyTo, serialise, fromJson, create,
|
3
|
+
enumerateFiles } from './model.js';
|
4
|
+
import { Cart } from './cart.js';
|
5
|
+
import { CountryTax } from './country_tax.js';
|
6
|
+
import { Product } from './product.js';
|
7
|
+
import { Variation } from './variation.js';
|
8
|
+
import { VariationsGroup } from './variations_group.js';
|
9
|
+
|
10
|
+
export function CartItem() {
|
11
|
+
this.resource = '/cart_items';
|
12
|
+
this.json = 'cartItem';
|
13
|
+
this.temporaryId = generateUUID();
|
14
|
+
|
15
|
+
addPropertyTo(this, 'id');
|
16
|
+
addPropertyTo(this, 'creationDate');
|
17
|
+
addPropertyTo(this, 'cart', Cart);
|
18
|
+
addPropertyTo(this, 'currency');
|
19
|
+
addPropertyTo(this, 'quantity');
|
20
|
+
addPropertyTo(this, 'currency');
|
21
|
+
addPropertyTo(this, 'product', Product);
|
22
|
+
addPropertyTo(this, 'variations', Variation);
|
23
|
+
addPropertyTo(this, 'variationsGroups', VariationsGroup);
|
24
|
+
addPropertyTo(this, 'taxType', CountryTax);
|
25
|
+
addPropertyTo(this, 'subtotalCost');
|
26
|
+
addPropertyTo(this, 'totalCost');
|
27
|
+
|
28
|
+
this.hasVariationsGroups = function () {
|
29
|
+
var groups = this.variationsGroups();
|
30
|
+
return groups && groups.length > 0;
|
31
|
+
};
|
32
|
+
|
33
|
+
this.create = function (success, error, embed, asDomain) {
|
34
|
+
var self = this,
|
35
|
+
data = serialise(self);
|
36
|
+
function handleResponse(result) {
|
37
|
+
success(fromJson(self, result[self.json]));
|
38
|
+
}
|
39
|
+
create({resource: this.resource,
|
40
|
+
parameters: data[0],
|
41
|
+
as_domain: asDomain,
|
42
|
+
files: enumerateFiles(data[1]),
|
43
|
+
success: handleResponse,
|
44
|
+
error: error,
|
45
|
+
embed: embed});
|
46
|
+
};
|
47
|
+
|
48
|
+
this.calculate = function (success, error, embed) {
|
49
|
+
var request = new Request(),
|
50
|
+
data = serialise(this)[0];
|
51
|
+
request.resource('/cart-item-cost-estimate/');
|
52
|
+
request.method('POST');
|
53
|
+
request.query().add('skip_rights', true);
|
54
|
+
request.data().merge(data);
|
55
|
+
function handleResponse(status, data) {
|
56
|
+
if (status === 201) {
|
57
|
+
success(fromJson(new CartItem(), data));
|
58
|
+
} else {
|
59
|
+
error(data);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
request.responseHandler(handleResponse).errorHandler(error);
|
63
|
+
request.send();
|
64
|
+
};
|
65
|
+
|
66
|
+
this.requiresShipment = function() {
|
67
|
+
var product = this.product();
|
68
|
+
return product ? product.needsShipping() : false;
|
69
|
+
};
|
70
|
+
|
71
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { generateUUID } from './uuid.js';
|
2
|
+
import { addPropertyTo } from './model.js';
|
3
|
+
import { CartItem } from './cart_item.js';
|
4
|
+
import { CartShipmentQuote } from './cart_shipment_quote.js';
|
5
|
+
|
6
|
+
export function CartShipmentGroup() {
|
7
|
+
this.resource = '/cart_shipment_groups';
|
8
|
+
this.json = 'cartShipmentGroup';
|
9
|
+
this.temporaryId = generateUUID();
|
10
|
+
|
11
|
+
addPropertyTo(this, 'id');
|
12
|
+
addPropertyTo(this, 'cartItems', CartItem);
|
13
|
+
addPropertyTo(this, 'quotes', CartShipmentQuote);
|
14
|
+
addPropertyTo(this, 'selectedQuote', CartShipmentQuote);
|
15
|
+
|
16
|
+
this.selectedQuoteName = function () {
|
17
|
+
var selectedQuote = this.selectedQuote();
|
18
|
+
return selectedQuote ? selectedQuote.name() : null;
|
19
|
+
}
|
20
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { generateUUID } from './uuid.js';
|
2
|
+
import { addPropertyTo } from './model.js';
|
3
|
+
import { ShipmentMethod } from './shipment_method.js';
|
4
|
+
|
5
|
+
export function CartShipmentQuote() {
|
6
|
+
this.resource = '/cart_shipment_quotes';
|
7
|
+
this.json = 'cartShipmentQuote';
|
8
|
+
this.temporaryId = generateUUID();
|
9
|
+
|
10
|
+
addPropertyTo(this, 'id');
|
11
|
+
addPropertyTo(this, 'name');
|
12
|
+
addPropertyTo(this, 'subtotalCost');
|
13
|
+
addPropertyTo(this, 'taxAmount');
|
14
|
+
addPropertyTo(this, 'totalCost');
|
15
|
+
addPropertyTo(this, 'shipmentMethod', ShipmentMethod);
|
16
|
+
addPropertyTo(this, 'shipmentServiceQuote')
|
17
|
+
addPropertyTo(this, 'shipmentService')
|
18
|
+
|
19
|
+
this.name = function () {
|
20
|
+
const shipmentMethod = this.shipmentMethod();
|
21
|
+
return shipmentMethod ? shipmentMethod.name() : null;
|
22
|
+
}
|
23
|
+
}
|