merchi_sdk_js 0.4.10 → 0.4.12
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/draft_template.js +3 -0
- package/src/job.js +1 -0
- package/src/merchi.js +110 -1
- package/src/product.js +3 -0
- package/src/product_review.js +96 -0
- package/src/shipment.js +2 -0
- package/src/shipment_log.js +74 -0
package/package.json
CHANGED
package/src/draft_template.js
CHANGED
|
@@ -24,6 +24,9 @@ export function DraftTemplate() {
|
|
|
24
24
|
addPropertyTo(this, 'height');
|
|
25
25
|
addPropertyTo(this, 'width');
|
|
26
26
|
addPropertyTo(this, 'draftPreviewLayer', DraftPreviewLayer);
|
|
27
|
+
addPropertyTo(this, 'customisationMap');
|
|
28
|
+
addPropertyTo(this, 'customisationMapSource');
|
|
29
|
+
addPropertyTo(this, 'customisationMapFileId');
|
|
27
30
|
|
|
28
31
|
this.create = function (options) {
|
|
29
32
|
var data = serialise(this),
|
package/src/job.js
CHANGED
|
@@ -50,6 +50,7 @@ export function Job() {
|
|
|
50
50
|
addPropertyTo(this, 'received');
|
|
51
51
|
addPropertyTo(this, 'deadline');
|
|
52
52
|
addPropertyTo(this, 'updated');
|
|
53
|
+
addPropertyTo(this, 'dateLastActioned');
|
|
53
54
|
addPropertyTo(this, 'deductionDate');
|
|
54
55
|
addPropertyTo(this, 'preDraftCommentsCount');
|
|
55
56
|
addPropertyTo(this, 'clientFiles', MerchiFile);
|
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,
|
|
@@ -62,6 +63,7 @@ import { ProductionComment } from './production_comment.js';
|
|
|
62
63
|
import { PhoneNumber, PhoneNumbers } from './phone_number.js';
|
|
63
64
|
import { Session, Sessions } from './session.js';
|
|
64
65
|
import { Shipment, Shipments } from './shipment.js';
|
|
66
|
+
import { ShipmentLog, ShipmentLogs } from './shipment_log.js';
|
|
65
67
|
import { ShipmentMethod, ShipmentMethods } from './shipment_method.js';
|
|
66
68
|
import { ShipmentMethodVariation, ShipmentMethodVariations } from
|
|
67
69
|
'./shipment_method_variation.js';
|
|
@@ -87,6 +89,12 @@ import { AgentSkillApproval, AgentSkillApprovals } from './agent_skill_approval.
|
|
|
87
89
|
import { DomainChatSettings, DomainChatSettingsList } from './domain_chat_settings.js';
|
|
88
90
|
import { SupportConversation, SupportConversations } from './support_conversation.js';
|
|
89
91
|
import { SupportMessage, SupportMessages } from './support_message.js';
|
|
92
|
+
import {
|
|
93
|
+
ProductReview,
|
|
94
|
+
ProductReviews,
|
|
95
|
+
normalizeProductReviewApiJson,
|
|
96
|
+
wireProductReviewCreateBody,
|
|
97
|
+
} from './product_review.js';
|
|
90
98
|
|
|
91
99
|
export function merchi(backendUri, websocketUri) {
|
|
92
100
|
getGlobal().merchiJsonpHandlers = {};
|
|
@@ -865,6 +873,98 @@ export function merchi(backendUri, websocketUri) {
|
|
|
865
873
|
request.send();
|
|
866
874
|
}
|
|
867
875
|
|
|
876
|
+
function productReviewsApiRoot() {
|
|
877
|
+
var base = getGlobal().merchiBackendUri;
|
|
878
|
+
if (!base.endsWith('/')) {
|
|
879
|
+
base += '/';
|
|
880
|
+
}
|
|
881
|
+
return base + 'v6';
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
function productReviewsSessionSuffix() {
|
|
885
|
+
if (getGlobal().currentSession &&
|
|
886
|
+
getGlobal().currentSession.token()) {
|
|
887
|
+
return '?session_token=' + encodeURIComponent(
|
|
888
|
+
getGlobal().currentSession.token());
|
|
889
|
+
}
|
|
890
|
+
return '';
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
/**
|
|
894
|
+
* List product reviews (domain manager/admin). ``success`` receives
|
|
895
|
+
* ``{ productReviews: ... }`` — same keys as the API, but each row is a
|
|
896
|
+
* ``ProductReview`` model instance with ``job`` / ``product`` / ``domain``.
|
|
897
|
+
*/
|
|
898
|
+
function listProductReviews(productId, success, error) {
|
|
899
|
+
var url = productReviewsApiRoot() + '/products/' + productId +
|
|
900
|
+
'/reviews/' + productReviewsSessionSuffix();
|
|
901
|
+
axios.get(url)
|
|
902
|
+
.then(function (res) {
|
|
903
|
+
var reviews = new ProductReviews().fromProductListResponse(
|
|
904
|
+
res.data);
|
|
905
|
+
success(Object.assign({}, res.data, {productReviews: reviews}));
|
|
906
|
+
})
|
|
907
|
+
.catch(function (err) {
|
|
908
|
+
error(err.response ? err.response.data : err);
|
|
909
|
+
});
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
/**
|
|
913
|
+
* Create a product review (buyer, JSON body). Send ``jobId`` or ``job: { id }``
|
|
914
|
+
* (completed job whose catalog product matches ``productId`` after clone
|
|
915
|
+
* resolution), plus ``rating`` and optional ``title`` / ``content``.
|
|
916
|
+
* ``success`` receives ``{ productReview }`` as a ``ProductReview`` model.
|
|
917
|
+
*/
|
|
918
|
+
function createProductReview(productId, data, success, error) {
|
|
919
|
+
var url = productReviewsApiRoot() + '/products/' + productId +
|
|
920
|
+
'/reviews/' + productReviewsSessionSuffix();
|
|
921
|
+
axios.post(url, wireProductReviewCreateBody(data), {
|
|
922
|
+
headers: {'Content-Type': 'application/json'},
|
|
923
|
+
})
|
|
924
|
+
.then(function (res) {
|
|
925
|
+
var pr = fromJson(
|
|
926
|
+
new ProductReview(),
|
|
927
|
+
normalizeProductReviewApiJson(res.data.productReview),
|
|
928
|
+
{makesDirty: false});
|
|
929
|
+
success(Object.assign({}, res.data, {productReview: pr}));
|
|
930
|
+
})
|
|
931
|
+
.catch(function (err) {
|
|
932
|
+
error(err.response ? err.response.data : err);
|
|
933
|
+
});
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
/**
|
|
937
|
+
* Patch a review (``formFields`` plain object: status, rejectionReason,
|
|
938
|
+
* rating, title, content — sent as multipart form data).
|
|
939
|
+
* ``success`` receives ``{ productReview }`` as a model when present.
|
|
940
|
+
*/
|
|
941
|
+
function patchProductReview(reviewId, formFields, success, error) {
|
|
942
|
+
var url = productReviewsApiRoot() + '/product-reviews/' + reviewId +
|
|
943
|
+
'/' + productReviewsSessionSuffix();
|
|
944
|
+
var fd = new FormData();
|
|
945
|
+
Object.keys(formFields || {}).forEach(function (k) {
|
|
946
|
+
var v = formFields[k];
|
|
947
|
+
if (v !== undefined && v !== null) {
|
|
948
|
+
fd.append(k, String(v));
|
|
949
|
+
}
|
|
950
|
+
});
|
|
951
|
+
axios.patch(url, fd)
|
|
952
|
+
.then(function (res) {
|
|
953
|
+
if (!res.data || !res.data.productReview) {
|
|
954
|
+
success(res.data);
|
|
955
|
+
return;
|
|
956
|
+
}
|
|
957
|
+
var pr = fromJson(
|
|
958
|
+
new ProductReview(),
|
|
959
|
+
normalizeProductReviewApiJson(res.data.productReview),
|
|
960
|
+
{makesDirty: false});
|
|
961
|
+
success(Object.assign({}, res.data, {productReview: pr}));
|
|
962
|
+
})
|
|
963
|
+
.catch(function (err) {
|
|
964
|
+
error(err.response ? err.response.data : err);
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
|
|
868
968
|
function getProductShipmentOptions(
|
|
869
969
|
productId, quantity, address, success, error) {
|
|
870
970
|
var request = new Request(),
|
|
@@ -981,6 +1081,8 @@ export function merchi(backendUri, websocketUri) {
|
|
|
981
1081
|
'removeUnstoredFiles': removeUnstoredFiles,
|
|
982
1082
|
'Shipment': Shipment,
|
|
983
1083
|
'shipments': new Shipments(),
|
|
1084
|
+
'ShipmentLog': ShipmentLog,
|
|
1085
|
+
'shipmentLogs': new ShipmentLogs(),
|
|
984
1086
|
'ShipmentMethod': ShipmentMethod,
|
|
985
1087
|
'shipmentMethods': new ShipmentMethods(),
|
|
986
1088
|
'ShipmentMethodVariation': ShipmentMethodVariation,
|
|
@@ -1022,6 +1124,10 @@ export function merchi(backendUri, websocketUri) {
|
|
|
1022
1124
|
'supportConversations': new SupportConversations(),
|
|
1023
1125
|
'SupportMessage': SupportMessage,
|
|
1024
1126
|
'supportMessages': new SupportMessages(),
|
|
1127
|
+
'ProductReview': ProductReview,
|
|
1128
|
+
'productReviews': new ProductReviews(),
|
|
1129
|
+
'normalizeProductReviewApiJson': normalizeProductReviewApiJson,
|
|
1130
|
+
'wireProductReviewCreateBody': wireProductReviewCreateBody,
|
|
1025
1131
|
'SubscriptionPlan': SubscriptionPlan,
|
|
1026
1132
|
'subscriptionPlans': new SubscriptionPlans(),
|
|
1027
1133
|
'VariationField': VariationField,
|
|
@@ -1100,5 +1206,8 @@ export function merchi(backendUri, websocketUri) {
|
|
|
1100
1206
|
'productTypes': productTypes,
|
|
1101
1207
|
'productTypesInts': productTypesInts,
|
|
1102
1208
|
'productTypesSeller': productTypesSeller,
|
|
1103
|
-
'getProductShipmentOptions': getProductShipmentOptions
|
|
1209
|
+
'getProductShipmentOptions': getProductShipmentOptions,
|
|
1210
|
+
'listProductReviews': listProductReviews,
|
|
1211
|
+
'createProductReview': createProductReview,
|
|
1212
|
+
'patchProductReview': patchProductReview};
|
|
1104
1213
|
}
|
package/src/product.js
CHANGED
|
@@ -42,10 +42,12 @@ export function Product() {
|
|
|
42
42
|
addPropertyTo(this, 'independent');
|
|
43
43
|
addPropertyTo(this, 'productType');
|
|
44
44
|
addPropertyTo(this, 'description');
|
|
45
|
+
addPropertyTo(this, 'aiContextDrafting');
|
|
45
46
|
addPropertyTo(this, 'notes');
|
|
46
47
|
addPropertyTo(this, 'spProductId');
|
|
47
48
|
addPropertyTo(this, 'shopifyProductId');
|
|
48
49
|
addPropertyTo(this, 'minimum');
|
|
50
|
+
addPropertyTo(this, 'defaultQuantity')
|
|
49
51
|
addPropertyTo(this, 'minimumPrice')
|
|
50
52
|
addPropertyTo(this, 'minimumPerGroup');
|
|
51
53
|
addPropertyTo(this, 'deliveryDaysNormal');
|
|
@@ -116,6 +118,7 @@ export function Product() {
|
|
|
116
118
|
addPropertyTo(this, 'shipmentMethods', ShipmentMethod);
|
|
117
119
|
addPropertyTo(this, 'seoDomainPages', SeoDomainPage);
|
|
118
120
|
addPropertyTo(this, 'aiContext');
|
|
121
|
+
addPropertyTo(this, 'aiContextDrafting');
|
|
119
122
|
addPropertyTo(this, 'internalUseNotes');
|
|
120
123
|
addPropertyTo(this, 'internalUseAiContext');
|
|
121
124
|
addPropertyTo(this, 'groupsFirst');
|
|
@@ -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
|
+
}
|
package/src/shipment.js
CHANGED
|
@@ -12,6 +12,7 @@ import { Invoice } from './invoice.js';
|
|
|
12
12
|
import { Job } from './job.js';
|
|
13
13
|
import { MerchiFile } from './merchi_file.js';
|
|
14
14
|
import { ShipmentItem } from './shipment_item.js';
|
|
15
|
+
import { ShipmentLog } from './shipment_log.js';
|
|
15
16
|
import { ShipmentMethod } from './shipment_method.js';
|
|
16
17
|
import { Reminder } from './reminder.js';
|
|
17
18
|
import { InternalTag } from './internal_tag.js';
|
|
@@ -60,6 +61,7 @@ export function Shipment() {
|
|
|
60
61
|
addPropertyTo(this, 'shipmentMethod', ShipmentMethod);
|
|
61
62
|
addPropertyTo(this, 'internalTags', InternalTag);
|
|
62
63
|
addPropertyTo(this, 'reminders', Reminder);
|
|
64
|
+
addPropertyTo(this, 'logs', ShipmentLog);
|
|
63
65
|
|
|
64
66
|
this.get = function (success, error, embed) {
|
|
65
67
|
var self = this;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { generateUUID } from './uuid.js';
|
|
2
|
+
import {
|
|
3
|
+
addPropertyTo,
|
|
4
|
+
serialise,
|
|
5
|
+
create,
|
|
6
|
+
enumerateFiles,
|
|
7
|
+
fromJson,
|
|
8
|
+
getOne,
|
|
9
|
+
getList,
|
|
10
|
+
fromJsonList,
|
|
11
|
+
} from './model.js';
|
|
12
|
+
import { Shipment } from './shipment.js';
|
|
13
|
+
import { User } from './user.js';
|
|
14
|
+
|
|
15
|
+
export function ShipmentLog() {
|
|
16
|
+
this.resource = '/shipment_logs';
|
|
17
|
+
this.json = 'shipmentLog';
|
|
18
|
+
this.temporaryId = generateUUID();
|
|
19
|
+
|
|
20
|
+
addPropertyTo(this, 'id');
|
|
21
|
+
addPropertyTo(this, 'shipment', Shipment);
|
|
22
|
+
addPropertyTo(this, 'user', User);
|
|
23
|
+
addPropertyTo(this, 'sourceType');
|
|
24
|
+
addPropertyTo(this, 'message');
|
|
25
|
+
addPropertyTo(this, 'detailJson');
|
|
26
|
+
addPropertyTo(this, 'createdAt');
|
|
27
|
+
|
|
28
|
+
this.create = function (options) {
|
|
29
|
+
var data = serialise(this),
|
|
30
|
+
self = this;
|
|
31
|
+
function handleResponse(result) {
|
|
32
|
+
options.success(fromJson(self, result[self.json]));
|
|
33
|
+
}
|
|
34
|
+
create({
|
|
35
|
+
resource: this.resource,
|
|
36
|
+
parameters: data[0],
|
|
37
|
+
files: enumerateFiles(data[1]),
|
|
38
|
+
success: handleResponse,
|
|
39
|
+
as_domain: options.as_domain,
|
|
40
|
+
error: options.error,
|
|
41
|
+
embed: options.embed,
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
this.get = function (success, error, embed) {
|
|
46
|
+
var self = this;
|
|
47
|
+
function handleResponse(result) {
|
|
48
|
+
success(
|
|
49
|
+
fromJson(self, result[self.json], { makesDirty: false })
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
getOne({
|
|
53
|
+
resource: this.resource,
|
|
54
|
+
id: this.id(),
|
|
55
|
+
success: handleResponse,
|
|
56
|
+
error: error,
|
|
57
|
+
embed: embed,
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function ShipmentLogs() {
|
|
63
|
+
this.resource = '/shipment_logs';
|
|
64
|
+
this.json = 'shipmentLogs';
|
|
65
|
+
this.single = ShipmentLog;
|
|
66
|
+
|
|
67
|
+
this.get = function (success, error, parameters) {
|
|
68
|
+
var self = this;
|
|
69
|
+
function handleResponse(result) {
|
|
70
|
+
success(fromJsonList(self, result, { makesDirty: false }));
|
|
71
|
+
}
|
|
72
|
+
getList(this.resource, handleResponse, error, parameters || {});
|
|
73
|
+
};
|
|
74
|
+
}
|