merchi_sdk_js 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/job.js +3 -2
- package/src/job_note.js +36 -0
- package/src/merchi.js +109 -1
- package/src/model.js +4 -0
- package/src/product_review.js +96 -0
package/package.json
CHANGED
package/src/job.js
CHANGED
|
@@ -29,6 +29,7 @@ import { Variation } from './variation.js';
|
|
|
29
29
|
import { VariationsGroup } from './variations_group.js';
|
|
30
30
|
import { Item } from './item.js';
|
|
31
31
|
import { JobComment } from './job_comment.js';
|
|
32
|
+
import { JobNote } from './job_note.js';
|
|
32
33
|
import { Reminder } from './reminder.js';
|
|
33
34
|
import { InternalTag } from './internal_tag.js';
|
|
34
35
|
|
|
@@ -41,7 +42,7 @@ export function Job() {
|
|
|
41
42
|
addPropertyTo(this, 'id');
|
|
42
43
|
addPropertyTo(this, 'currency');
|
|
43
44
|
addPropertyTo(this, 'quantity');
|
|
44
|
-
addPropertyTo(this, '
|
|
45
|
+
addPropertyTo(this, 'jobNotes', JobNote);
|
|
45
46
|
addPropertyTo(this, 'jobType');
|
|
46
47
|
addPropertyTo(this, 'product', Product);
|
|
47
48
|
addPropertyTo(this, 'supplyChainRequestProduct', Product);
|
|
@@ -51,6 +52,7 @@ export function Job() {
|
|
|
51
52
|
addPropertyTo(this, 'deadline');
|
|
52
53
|
addPropertyTo(this, 'updated');
|
|
53
54
|
addPropertyTo(this, 'dateLastActioned');
|
|
55
|
+
addPropertyTo(this, 'dateFirstActioned');
|
|
54
56
|
addPropertyTo(this, 'deductionDate');
|
|
55
57
|
addPropertyTo(this, 'preDraftCommentsCount');
|
|
56
58
|
addPropertyTo(this, 'clientFiles', MerchiFile);
|
|
@@ -105,7 +107,6 @@ export function Job() {
|
|
|
105
107
|
addPropertyTo(this, 'limitedStock');
|
|
106
108
|
addPropertyTo(this, 'canDeduct');
|
|
107
109
|
|
|
108
|
-
addPropertyTo(this, 'productionNotes');
|
|
109
110
|
addPropertyTo(this, "needsDrafting");
|
|
110
111
|
addPropertyTo(this, "needsGroupBuy");
|
|
111
112
|
addPropertyTo(this, "needsProduction");
|
package/src/job_note.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { generateUUID } from './uuid.js';
|
|
2
|
+
import { addPropertyTo, enumerateFiles, fromJson, create, serialise } from './model.js';
|
|
3
|
+
import { Job } from './job.js';
|
|
4
|
+
import { User } from './user.js';
|
|
5
|
+
import { MerchiFile } from './merchi_file.js';
|
|
6
|
+
|
|
7
|
+
export function JobNote() {
|
|
8
|
+
this.resource = '/job_notes';
|
|
9
|
+
this.json = 'jobNote';
|
|
10
|
+
this.temporaryId = generateUUID();
|
|
11
|
+
|
|
12
|
+
addPropertyTo(this, 'id');
|
|
13
|
+
addPropertyTo(this, 'job', Job);
|
|
14
|
+
addPropertyTo(this, 'createdBy', User);
|
|
15
|
+
addPropertyTo(this, 'lastEditedBy', User);
|
|
16
|
+
addPropertyTo(this, 'files', MerchiFile);
|
|
17
|
+
addPropertyTo(this, 'noteType');
|
|
18
|
+
addPropertyTo(this, 'richText');
|
|
19
|
+
addPropertyTo(this, 'creationDate');
|
|
20
|
+
addPropertyTo(this, 'lastEditedTime');
|
|
21
|
+
|
|
22
|
+
this.create = function (options) {
|
|
23
|
+
var data = serialise(this),
|
|
24
|
+
self = this;
|
|
25
|
+
function handleResponse(result) {
|
|
26
|
+
options.success(fromJson(self, result[self.json]));
|
|
27
|
+
}
|
|
28
|
+
create({resource: this.resource,
|
|
29
|
+
parameters: data[0],
|
|
30
|
+
files: enumerateFiles(data[1]),
|
|
31
|
+
success: handleResponse,
|
|
32
|
+
as_domain: options.as_domain,
|
|
33
|
+
error: options.error,
|
|
34
|
+
embed: options.embed});
|
|
35
|
+
};
|
|
36
|
+
}
|
package/src/merchi.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
1
2
|
import { isBrowser } from 'browser-or-node';
|
|
2
3
|
import { generateUUID } from './uuid.js';
|
|
3
4
|
import { isNull, isUndefined, isUndefinedOrNull, id,
|
|
@@ -52,6 +53,7 @@ import { Notification, Notifications } from './notification.js';
|
|
|
52
53
|
import { Invoice, Invoices } from './invoice.js';
|
|
53
54
|
import { Job, Jobs } from './job.js';
|
|
54
55
|
import { JobComment } from './job_comment.js';
|
|
56
|
+
import { JobNote } from './job_note.js';
|
|
55
57
|
import { MerchiFile, MerchiFiles } from './merchi_file.js';
|
|
56
58
|
import { Menu } from './menu.js';
|
|
57
59
|
import { MenuItem } from './menu_item.js';
|
|
@@ -88,6 +90,12 @@ import { AgentSkillApproval, AgentSkillApprovals } from './agent_skill_approval.
|
|
|
88
90
|
import { DomainChatSettings, DomainChatSettingsList } from './domain_chat_settings.js';
|
|
89
91
|
import { SupportConversation, SupportConversations } from './support_conversation.js';
|
|
90
92
|
import { SupportMessage, SupportMessages } from './support_message.js';
|
|
93
|
+
import {
|
|
94
|
+
ProductReview,
|
|
95
|
+
ProductReviews,
|
|
96
|
+
normalizeProductReviewApiJson,
|
|
97
|
+
wireProductReviewCreateBody,
|
|
98
|
+
} from './product_review.js';
|
|
91
99
|
|
|
92
100
|
export function merchi(backendUri, websocketUri) {
|
|
93
101
|
getGlobal().merchiJsonpHandlers = {};
|
|
@@ -866,6 +874,98 @@ export function merchi(backendUri, websocketUri) {
|
|
|
866
874
|
request.send();
|
|
867
875
|
}
|
|
868
876
|
|
|
877
|
+
function productReviewsApiRoot() {
|
|
878
|
+
var base = getGlobal().merchiBackendUri;
|
|
879
|
+
if (!base.endsWith('/')) {
|
|
880
|
+
base += '/';
|
|
881
|
+
}
|
|
882
|
+
return base + 'v6';
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
function productReviewsSessionSuffix() {
|
|
886
|
+
if (getGlobal().currentSession &&
|
|
887
|
+
getGlobal().currentSession.token()) {
|
|
888
|
+
return '?session_token=' + encodeURIComponent(
|
|
889
|
+
getGlobal().currentSession.token());
|
|
890
|
+
}
|
|
891
|
+
return '';
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
/**
|
|
895
|
+
* List product reviews (domain manager/admin). ``success`` receives
|
|
896
|
+
* ``{ productReviews: ... }`` — same keys as the API, but each row is a
|
|
897
|
+
* ``ProductReview`` model instance with ``job`` / ``product`` / ``domain``.
|
|
898
|
+
*/
|
|
899
|
+
function listProductReviews(productId, success, error) {
|
|
900
|
+
var url = productReviewsApiRoot() + '/products/' + productId +
|
|
901
|
+
'/reviews/' + productReviewsSessionSuffix();
|
|
902
|
+
axios.get(url)
|
|
903
|
+
.then(function (res) {
|
|
904
|
+
var reviews = new ProductReviews().fromProductListResponse(
|
|
905
|
+
res.data);
|
|
906
|
+
success(Object.assign({}, res.data, {productReviews: reviews}));
|
|
907
|
+
})
|
|
908
|
+
.catch(function (err) {
|
|
909
|
+
error(err.response ? err.response.data : err);
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
/**
|
|
914
|
+
* Create a product review (buyer, JSON body). Send ``jobId`` or ``job: { id }``
|
|
915
|
+
* (completed job whose catalog product matches ``productId`` after clone
|
|
916
|
+
* resolution), plus ``rating`` and optional ``title`` / ``content``.
|
|
917
|
+
* ``success`` receives ``{ productReview }`` as a ``ProductReview`` model.
|
|
918
|
+
*/
|
|
919
|
+
function createProductReview(productId, data, success, error) {
|
|
920
|
+
var url = productReviewsApiRoot() + '/products/' + productId +
|
|
921
|
+
'/reviews/' + productReviewsSessionSuffix();
|
|
922
|
+
axios.post(url, wireProductReviewCreateBody(data), {
|
|
923
|
+
headers: {'Content-Type': 'application/json'},
|
|
924
|
+
})
|
|
925
|
+
.then(function (res) {
|
|
926
|
+
var pr = fromJson(
|
|
927
|
+
new ProductReview(),
|
|
928
|
+
normalizeProductReviewApiJson(res.data.productReview),
|
|
929
|
+
{makesDirty: false});
|
|
930
|
+
success(Object.assign({}, res.data, {productReview: pr}));
|
|
931
|
+
})
|
|
932
|
+
.catch(function (err) {
|
|
933
|
+
error(err.response ? err.response.data : err);
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
/**
|
|
938
|
+
* Patch a review (``formFields`` plain object: status, rejectionReason,
|
|
939
|
+
* rating, title, content — sent as multipart form data).
|
|
940
|
+
* ``success`` receives ``{ productReview }`` as a model when present.
|
|
941
|
+
*/
|
|
942
|
+
function patchProductReview(reviewId, formFields, success, error) {
|
|
943
|
+
var url = productReviewsApiRoot() + '/product-reviews/' + reviewId +
|
|
944
|
+
'/' + productReviewsSessionSuffix();
|
|
945
|
+
var fd = new FormData();
|
|
946
|
+
Object.keys(formFields || {}).forEach(function (k) {
|
|
947
|
+
var v = formFields[k];
|
|
948
|
+
if (v !== undefined && v !== null) {
|
|
949
|
+
fd.append(k, String(v));
|
|
950
|
+
}
|
|
951
|
+
});
|
|
952
|
+
axios.patch(url, fd)
|
|
953
|
+
.then(function (res) {
|
|
954
|
+
if (!res.data || !res.data.productReview) {
|
|
955
|
+
success(res.data);
|
|
956
|
+
return;
|
|
957
|
+
}
|
|
958
|
+
var pr = fromJson(
|
|
959
|
+
new ProductReview(),
|
|
960
|
+
normalizeProductReviewApiJson(res.data.productReview),
|
|
961
|
+
{makesDirty: false});
|
|
962
|
+
success(Object.assign({}, res.data, {productReview: pr}));
|
|
963
|
+
})
|
|
964
|
+
.catch(function (err) {
|
|
965
|
+
error(err.response ? err.response.data : err);
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
|
|
869
969
|
function getProductShipmentOptions(
|
|
870
970
|
productId, quantity, address, success, error) {
|
|
871
971
|
var request = new Request(),
|
|
@@ -966,6 +1066,7 @@ export function merchi(backendUri, websocketUri) {
|
|
|
966
1066
|
'Job': Job,
|
|
967
1067
|
'jobs': new Jobs(),
|
|
968
1068
|
'JobComment': JobComment,
|
|
1069
|
+
'JobNote': JobNote,
|
|
969
1070
|
'Cart': Cart,
|
|
970
1071
|
'CartItem': CartItem,
|
|
971
1072
|
'Bank': Bank,
|
|
@@ -1025,6 +1126,10 @@ export function merchi(backendUri, websocketUri) {
|
|
|
1025
1126
|
'supportConversations': new SupportConversations(),
|
|
1026
1127
|
'SupportMessage': SupportMessage,
|
|
1027
1128
|
'supportMessages': new SupportMessages(),
|
|
1129
|
+
'ProductReview': ProductReview,
|
|
1130
|
+
'productReviews': new ProductReviews(),
|
|
1131
|
+
'normalizeProductReviewApiJson': normalizeProductReviewApiJson,
|
|
1132
|
+
'wireProductReviewCreateBody': wireProductReviewCreateBody,
|
|
1028
1133
|
'SubscriptionPlan': SubscriptionPlan,
|
|
1029
1134
|
'subscriptionPlans': new SubscriptionPlans(),
|
|
1030
1135
|
'VariationField': VariationField,
|
|
@@ -1103,5 +1208,8 @@ export function merchi(backendUri, websocketUri) {
|
|
|
1103
1208
|
'productTypes': productTypes,
|
|
1104
1209
|
'productTypesInts': productTypesInts,
|
|
1105
1210
|
'productTypesSeller': productTypesSeller,
|
|
1106
|
-
'getProductShipmentOptions': getProductShipmentOptions
|
|
1211
|
+
'getProductShipmentOptions': getProductShipmentOptions,
|
|
1212
|
+
'listProductReviews': listProductReviews,
|
|
1213
|
+
'createProductReview': createProductReview,
|
|
1214
|
+
'patchProductReview': patchProductReview};
|
|
1107
1215
|
}
|
package/src/model.js
CHANGED
|
@@ -335,6 +335,10 @@ export function getList(resource, success, error, parameters, withUpdates) {
|
|
|
335
335
|
if (parameters.asRole) {
|
|
336
336
|
request.query().add('as_role', JSON.stringify(parameters.asRole));
|
|
337
337
|
}
|
|
338
|
+
if (notEmpty(parameters.isJobManager)) {
|
|
339
|
+
request.query().add('is_job_manager',
|
|
340
|
+
JSON.stringify(parameters.isJobManager));
|
|
341
|
+
}
|
|
338
342
|
if (parameters.groupBuyOnly) {
|
|
339
343
|
request.query().add('group_buy_only',
|
|
340
344
|
JSON.stringify(parameters.groupBuyOnly));
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { generateUUID } from './uuid.js';
|
|
2
|
+
import { addPropertyTo, fromJson } from './model.js';
|
|
3
|
+
import { Domain } from './domain.js';
|
|
4
|
+
import { Job } from './job.js';
|
|
5
|
+
import { Product } from './product.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Map flat API fields (jobId, productId, domainId) onto job / product / domain
|
|
9
|
+
* before ``fromJson``.
|
|
10
|
+
*/
|
|
11
|
+
export function normalizeProductReviewApiJson(json) {
|
|
12
|
+
if (json === null || json === undefined || typeof json !== 'object') {
|
|
13
|
+
return json;
|
|
14
|
+
}
|
|
15
|
+
var row = Object.assign({}, json);
|
|
16
|
+
if (row.jobId !== undefined && row.job === undefined) {
|
|
17
|
+
if (row.jobId != null) {
|
|
18
|
+
row.job = {id: row.jobId};
|
|
19
|
+
}
|
|
20
|
+
delete row.jobId;
|
|
21
|
+
}
|
|
22
|
+
if (row.productId !== undefined && row.product === undefined) {
|
|
23
|
+
if (row.productId != null) {
|
|
24
|
+
row.product = {id: row.productId};
|
|
25
|
+
}
|
|
26
|
+
delete row.productId;
|
|
27
|
+
}
|
|
28
|
+
if (row.domainId !== undefined && row.domain === undefined) {
|
|
29
|
+
if (row.domainId != null) {
|
|
30
|
+
row.domain = {id: row.domainId};
|
|
31
|
+
}
|
|
32
|
+
delete row.domainId;
|
|
33
|
+
}
|
|
34
|
+
return row;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Turn create payload ``{ job: { id }, rating, ... }`` into API JSON with ``jobId``.
|
|
39
|
+
* Pass-through if ``jobId`` is already set.
|
|
40
|
+
*/
|
|
41
|
+
export function wireProductReviewCreateBody(data) {
|
|
42
|
+
if (!data || typeof data !== 'object') {
|
|
43
|
+
return data;
|
|
44
|
+
}
|
|
45
|
+
var body = Object.assign({}, data);
|
|
46
|
+
if (body.job && body.job.id != null && body.jobId === undefined) {
|
|
47
|
+
body.jobId = body.job.id;
|
|
48
|
+
delete body.job;
|
|
49
|
+
}
|
|
50
|
+
return body;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function ProductReview() {
|
|
54
|
+
this.resource = '/product-reviews';
|
|
55
|
+
this.json = 'productReview';
|
|
56
|
+
this.temporaryId = generateUUID();
|
|
57
|
+
|
|
58
|
+
addPropertyTo(this, 'id');
|
|
59
|
+
addPropertyTo(this, 'product', Product);
|
|
60
|
+
addPropertyTo(this, 'domain', Domain);
|
|
61
|
+
addPropertyTo(this, 'authorUserId');
|
|
62
|
+
addPropertyTo(this, 'authorName');
|
|
63
|
+
addPropertyTo(this, 'job', Job);
|
|
64
|
+
addPropertyTo(this, 'rating');
|
|
65
|
+
addPropertyTo(this, 'title');
|
|
66
|
+
addPropertyTo(this, 'content');
|
|
67
|
+
addPropertyTo(this, 'status');
|
|
68
|
+
addPropertyTo(this, 'purchaseInvoiceId');
|
|
69
|
+
addPropertyTo(this, 'submittedAt');
|
|
70
|
+
addPropertyTo(this, 'updatedAt');
|
|
71
|
+
addPropertyTo(this, 'rejectionReason');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function ProductReviews() {
|
|
75
|
+
this.json = 'productReviews';
|
|
76
|
+
this.single = ProductReview;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @param {object} data - API body with ``productReviews`` array
|
|
80
|
+
* @param {object} [options] - passed to ``fromJson`` (e.g. ``{makesDirty: false}``)
|
|
81
|
+
* @returns {ProductReview[]}
|
|
82
|
+
*/
|
|
83
|
+
this.fromProductListResponse = function (data, options) {
|
|
84
|
+
var raw = (data && data.productReviews) ? data.productReviews : [];
|
|
85
|
+
var self = this;
|
|
86
|
+
var defaults = {makesDirty: false};
|
|
87
|
+
var opts = Object.assign({}, defaults, options);
|
|
88
|
+
return raw.map(function (row) {
|
|
89
|
+
return fromJson(
|
|
90
|
+
new self.single(),
|
|
91
|
+
normalizeProductReviewApiJson(row),
|
|
92
|
+
opts
|
|
93
|
+
);
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
}
|