@blotoutio/providers-shop-gpt-sdk 0.70.0 → 0.70.1
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/index.cjs.js +14 -12
- package/index.js +14 -12
- package/index.mjs +14 -12
- package/package.json +1 -1
package/index.cjs.js
CHANGED
@@ -70,6 +70,7 @@ const createShopGPTAPI = ({ fetch: fetchImpl = window.fetch, baseURL, userId, st
|
|
70
70
|
return url;
|
71
71
|
};
|
72
72
|
const processQuery = async (query, productHandle) => {
|
73
|
+
var _a;
|
73
74
|
const response = await fetchImpl(getURL('/query'), {
|
74
75
|
method: 'POST',
|
75
76
|
headers: getHeaders(),
|
@@ -82,7 +83,7 @@ const createShopGPTAPI = ({ fetch: fetchImpl = window.fetch, baseURL, userId, st
|
|
82
83
|
const data = (await response.json());
|
83
84
|
return {
|
84
85
|
message: data.message,
|
85
|
-
products: data.products.map((item) => ({ ...item, quantity: 1 })),
|
86
|
+
products: (_a = data.products) === null || _a === void 0 ? void 0 : _a.filter((item) => !!item).map((item) => ({ ...item, quantity: 1 })),
|
86
87
|
};
|
87
88
|
};
|
88
89
|
const queryPrompts = async () => {
|
@@ -965,7 +966,6 @@ const getImageProperties = (src) => {
|
|
965
966
|
let ShopGPT = class ShopGPT extends s {
|
966
967
|
constructor() {
|
967
968
|
super(...arguments);
|
968
|
-
this.recommendedProduct = null;
|
969
969
|
this.moreRecommendations = [];
|
970
970
|
this.chatbotMessages = [];
|
971
971
|
this.userMessage = '';
|
@@ -1004,7 +1004,7 @@ let ShopGPT = class ShopGPT extends s {
|
|
1004
1004
|
});
|
1005
1005
|
}
|
1006
1006
|
async loadHistory() {
|
1007
|
-
var _a, _b, _c;
|
1007
|
+
var _a, _b, _c, _d;
|
1008
1008
|
try {
|
1009
1009
|
this.isLoadingHistory = true;
|
1010
1010
|
const data = await this.shopGPTAPI.fetchChatHistory();
|
@@ -1017,8 +1017,8 @@ let ShopGPT = class ShopGPT extends s {
|
|
1017
1017
|
product: ((_a = message.products) === null || _a === void 0 ? void 0 : _a.length) ? message.products[0] : null,
|
1018
1018
|
});
|
1019
1019
|
});
|
1020
|
-
if (((_a = data[0]) === null || _a === void 0 ? void 0 : _a.sender) === 'bot' && ((_c = (_b = data[0]) === null || _b === void 0 ? void 0 : _b.products) === null || _c === void 0 ? void 0 : _c.length)
|
1021
|
-
const products = data[0].products.map((product) => ({
|
1020
|
+
if (((_a = data[0]) === null || _a === void 0 ? void 0 : _a.sender) === 'bot' && ((_c = (_b = data[0]) === null || _b === void 0 ? void 0 : _b.products) === null || _c === void 0 ? void 0 : _c.length)) {
|
1021
|
+
const products = (_d = data[0].products) === null || _d === void 0 ? void 0 : _d.map((product) => ({
|
1022
1022
|
...product,
|
1023
1023
|
quantity: 1,
|
1024
1024
|
}));
|
@@ -1034,6 +1034,7 @@ let ShopGPT = class ShopGPT extends s {
|
|
1034
1034
|
}
|
1035
1035
|
}
|
1036
1036
|
async loadInitialQuery() {
|
1037
|
+
var _a, _b, _c, _d;
|
1037
1038
|
const productHandle = this.storeAPI.getCurrentProductHandle();
|
1038
1039
|
if (this.chatbotMessages.length) {
|
1039
1040
|
return;
|
@@ -1042,11 +1043,11 @@ let ShopGPT = class ShopGPT extends s {
|
|
1042
1043
|
this.isTyping = true;
|
1043
1044
|
const reply = await this.shopGPTAPI.processQuery('', productHandle);
|
1044
1045
|
this.chatbotMessages = [
|
1045
|
-
{ sender: 'bot', message: reply.message, product: reply.products[0] },
|
1046
|
+
{ sender: 'bot', message: reply.message, product: (_a = reply.products) === null || _a === void 0 ? void 0 : _a[0] },
|
1046
1047
|
...this.chatbotMessages,
|
1047
1048
|
];
|
1048
|
-
this.recommendedProduct = reply.products[0];
|
1049
|
-
this.moreRecommendations = reply.products.slice(1, 4);
|
1049
|
+
this.recommendedProduct = (_b = reply.products) === null || _b === void 0 ? void 0 : _b[0];
|
1050
|
+
this.moreRecommendations = (_d = (_c = reply.products) === null || _c === void 0 ? void 0 : _c.slice(1, 4)) !== null && _d !== void 0 ? _d : [];
|
1050
1051
|
this.setChatWindowHeight();
|
1051
1052
|
}
|
1052
1053
|
catch (error) {
|
@@ -1075,10 +1076,11 @@ let ShopGPT = class ShopGPT extends s {
|
|
1075
1076
|
});
|
1076
1077
|
}
|
1077
1078
|
resetProductRecommendations() {
|
1078
|
-
this.recommendedProduct =
|
1079
|
+
this.recommendedProduct = undefined;
|
1079
1080
|
this.moreRecommendations = [];
|
1080
1081
|
}
|
1081
1082
|
async sendMessageToServer(e, message) {
|
1083
|
+
var _a, _b, _c, _d;
|
1082
1084
|
e.preventDefault();
|
1083
1085
|
e.stopPropagation();
|
1084
1086
|
if (!message || this.isTyping || this.isLoadingHistory) {
|
@@ -1097,11 +1099,11 @@ let ShopGPT = class ShopGPT extends s {
|
|
1097
1099
|
return;
|
1098
1100
|
}
|
1099
1101
|
this.chatbotMessages = [
|
1100
|
-
{ sender: 'bot', message: reply.message, product: reply.products[0] },
|
1102
|
+
{ sender: 'bot', message: reply.message, product: (_a = reply.products) === null || _a === void 0 ? void 0 : _a[0] },
|
1101
1103
|
...this.chatbotMessages,
|
1102
1104
|
];
|
1103
|
-
this.recommendedProduct = reply.products[0];
|
1104
|
-
this.moreRecommendations = reply.products.slice(1, 4);
|
1105
|
+
this.recommendedProduct = (_b = reply.products) === null || _b === void 0 ? void 0 : _b[0];
|
1106
|
+
this.moreRecommendations = (_d = (_c = reply.products) === null || _c === void 0 ? void 0 : _c.slice(1, 4)) !== null && _d !== void 0 ? _d : [];
|
1105
1107
|
this.setChatWindowHeight();
|
1106
1108
|
}
|
1107
1109
|
catch (e) {
|
package/index.js
CHANGED
@@ -71,6 +71,7 @@ var ProvidersShopGptSdk = (function () {
|
|
71
71
|
return url;
|
72
72
|
};
|
73
73
|
const processQuery = async (query, productHandle) => {
|
74
|
+
var _a;
|
74
75
|
const response = await fetchImpl(getURL('/query'), {
|
75
76
|
method: 'POST',
|
76
77
|
headers: getHeaders(),
|
@@ -83,7 +84,7 @@ var ProvidersShopGptSdk = (function () {
|
|
83
84
|
const data = (await response.json());
|
84
85
|
return {
|
85
86
|
message: data.message,
|
86
|
-
products: data.products.map((item) => ({ ...item, quantity: 1 })),
|
87
|
+
products: (_a = data.products) === null || _a === void 0 ? void 0 : _a.filter((item) => !!item).map((item) => ({ ...item, quantity: 1 })),
|
87
88
|
};
|
88
89
|
};
|
89
90
|
const queryPrompts = async () => {
|
@@ -966,7 +967,6 @@ var ProvidersShopGptSdk = (function () {
|
|
966
967
|
let ShopGPT = class ShopGPT extends s {
|
967
968
|
constructor() {
|
968
969
|
super(...arguments);
|
969
|
-
this.recommendedProduct = null;
|
970
970
|
this.moreRecommendations = [];
|
971
971
|
this.chatbotMessages = [];
|
972
972
|
this.userMessage = '';
|
@@ -1005,7 +1005,7 @@ var ProvidersShopGptSdk = (function () {
|
|
1005
1005
|
});
|
1006
1006
|
}
|
1007
1007
|
async loadHistory() {
|
1008
|
-
var _a, _b, _c;
|
1008
|
+
var _a, _b, _c, _d;
|
1009
1009
|
try {
|
1010
1010
|
this.isLoadingHistory = true;
|
1011
1011
|
const data = await this.shopGPTAPI.fetchChatHistory();
|
@@ -1018,8 +1018,8 @@ var ProvidersShopGptSdk = (function () {
|
|
1018
1018
|
product: ((_a = message.products) === null || _a === void 0 ? void 0 : _a.length) ? message.products[0] : null,
|
1019
1019
|
});
|
1020
1020
|
});
|
1021
|
-
if (((_a = data[0]) === null || _a === void 0 ? void 0 : _a.sender) === 'bot' && ((_c = (_b = data[0]) === null || _b === void 0 ? void 0 : _b.products) === null || _c === void 0 ? void 0 : _c.length)
|
1022
|
-
const products = data[0].products.map((product) => ({
|
1021
|
+
if (((_a = data[0]) === null || _a === void 0 ? void 0 : _a.sender) === 'bot' && ((_c = (_b = data[0]) === null || _b === void 0 ? void 0 : _b.products) === null || _c === void 0 ? void 0 : _c.length)) {
|
1022
|
+
const products = (_d = data[0].products) === null || _d === void 0 ? void 0 : _d.map((product) => ({
|
1023
1023
|
...product,
|
1024
1024
|
quantity: 1,
|
1025
1025
|
}));
|
@@ -1035,6 +1035,7 @@ var ProvidersShopGptSdk = (function () {
|
|
1035
1035
|
}
|
1036
1036
|
}
|
1037
1037
|
async loadInitialQuery() {
|
1038
|
+
var _a, _b, _c, _d;
|
1038
1039
|
const productHandle = this.storeAPI.getCurrentProductHandle();
|
1039
1040
|
if (this.chatbotMessages.length) {
|
1040
1041
|
return;
|
@@ -1043,11 +1044,11 @@ var ProvidersShopGptSdk = (function () {
|
|
1043
1044
|
this.isTyping = true;
|
1044
1045
|
const reply = await this.shopGPTAPI.processQuery('', productHandle);
|
1045
1046
|
this.chatbotMessages = [
|
1046
|
-
{ sender: 'bot', message: reply.message, product: reply.products[0] },
|
1047
|
+
{ sender: 'bot', message: reply.message, product: (_a = reply.products) === null || _a === void 0 ? void 0 : _a[0] },
|
1047
1048
|
...this.chatbotMessages,
|
1048
1049
|
];
|
1049
|
-
this.recommendedProduct = reply.products[0];
|
1050
|
-
this.moreRecommendations = reply.products.slice(1, 4);
|
1050
|
+
this.recommendedProduct = (_b = reply.products) === null || _b === void 0 ? void 0 : _b[0];
|
1051
|
+
this.moreRecommendations = (_d = (_c = reply.products) === null || _c === void 0 ? void 0 : _c.slice(1, 4)) !== null && _d !== void 0 ? _d : [];
|
1051
1052
|
this.setChatWindowHeight();
|
1052
1053
|
}
|
1053
1054
|
catch (error) {
|
@@ -1076,10 +1077,11 @@ var ProvidersShopGptSdk = (function () {
|
|
1076
1077
|
});
|
1077
1078
|
}
|
1078
1079
|
resetProductRecommendations() {
|
1079
|
-
this.recommendedProduct =
|
1080
|
+
this.recommendedProduct = undefined;
|
1080
1081
|
this.moreRecommendations = [];
|
1081
1082
|
}
|
1082
1083
|
async sendMessageToServer(e, message) {
|
1084
|
+
var _a, _b, _c, _d;
|
1083
1085
|
e.preventDefault();
|
1084
1086
|
e.stopPropagation();
|
1085
1087
|
if (!message || this.isTyping || this.isLoadingHistory) {
|
@@ -1098,11 +1100,11 @@ var ProvidersShopGptSdk = (function () {
|
|
1098
1100
|
return;
|
1099
1101
|
}
|
1100
1102
|
this.chatbotMessages = [
|
1101
|
-
{ sender: 'bot', message: reply.message, product: reply.products[0] },
|
1103
|
+
{ sender: 'bot', message: reply.message, product: (_a = reply.products) === null || _a === void 0 ? void 0 : _a[0] },
|
1102
1104
|
...this.chatbotMessages,
|
1103
1105
|
];
|
1104
|
-
this.recommendedProduct = reply.products[0];
|
1105
|
-
this.moreRecommendations = reply.products.slice(1, 4);
|
1106
|
+
this.recommendedProduct = (_b = reply.products) === null || _b === void 0 ? void 0 : _b[0];
|
1107
|
+
this.moreRecommendations = (_d = (_c = reply.products) === null || _c === void 0 ? void 0 : _c.slice(1, 4)) !== null && _d !== void 0 ? _d : [];
|
1106
1108
|
this.setChatWindowHeight();
|
1107
1109
|
}
|
1108
1110
|
catch (e) {
|
package/index.mjs
CHANGED
@@ -68,6 +68,7 @@ const createShopGPTAPI = ({ fetch: fetchImpl = window.fetch, baseURL, userId, st
|
|
68
68
|
return url;
|
69
69
|
};
|
70
70
|
const processQuery = async (query, productHandle) => {
|
71
|
+
var _a;
|
71
72
|
const response = await fetchImpl(getURL('/query'), {
|
72
73
|
method: 'POST',
|
73
74
|
headers: getHeaders(),
|
@@ -80,7 +81,7 @@ const createShopGPTAPI = ({ fetch: fetchImpl = window.fetch, baseURL, userId, st
|
|
80
81
|
const data = (await response.json());
|
81
82
|
return {
|
82
83
|
message: data.message,
|
83
|
-
products: data.products.map((item) => ({ ...item, quantity: 1 })),
|
84
|
+
products: (_a = data.products) === null || _a === void 0 ? void 0 : _a.filter((item) => !!item).map((item) => ({ ...item, quantity: 1 })),
|
84
85
|
};
|
85
86
|
};
|
86
87
|
const queryPrompts = async () => {
|
@@ -963,7 +964,6 @@ const getImageProperties = (src) => {
|
|
963
964
|
let ShopGPT = class ShopGPT extends s {
|
964
965
|
constructor() {
|
965
966
|
super(...arguments);
|
966
|
-
this.recommendedProduct = null;
|
967
967
|
this.moreRecommendations = [];
|
968
968
|
this.chatbotMessages = [];
|
969
969
|
this.userMessage = '';
|
@@ -1002,7 +1002,7 @@ let ShopGPT = class ShopGPT extends s {
|
|
1002
1002
|
});
|
1003
1003
|
}
|
1004
1004
|
async loadHistory() {
|
1005
|
-
var _a, _b, _c;
|
1005
|
+
var _a, _b, _c, _d;
|
1006
1006
|
try {
|
1007
1007
|
this.isLoadingHistory = true;
|
1008
1008
|
const data = await this.shopGPTAPI.fetchChatHistory();
|
@@ -1015,8 +1015,8 @@ let ShopGPT = class ShopGPT extends s {
|
|
1015
1015
|
product: ((_a = message.products) === null || _a === void 0 ? void 0 : _a.length) ? message.products[0] : null,
|
1016
1016
|
});
|
1017
1017
|
});
|
1018
|
-
if (((_a = data[0]) === null || _a === void 0 ? void 0 : _a.sender) === 'bot' && ((_c = (_b = data[0]) === null || _b === void 0 ? void 0 : _b.products) === null || _c === void 0 ? void 0 : _c.length)
|
1019
|
-
const products = data[0].products.map((product) => ({
|
1018
|
+
if (((_a = data[0]) === null || _a === void 0 ? void 0 : _a.sender) === 'bot' && ((_c = (_b = data[0]) === null || _b === void 0 ? void 0 : _b.products) === null || _c === void 0 ? void 0 : _c.length)) {
|
1019
|
+
const products = (_d = data[0].products) === null || _d === void 0 ? void 0 : _d.map((product) => ({
|
1020
1020
|
...product,
|
1021
1021
|
quantity: 1,
|
1022
1022
|
}));
|
@@ -1032,6 +1032,7 @@ let ShopGPT = class ShopGPT extends s {
|
|
1032
1032
|
}
|
1033
1033
|
}
|
1034
1034
|
async loadInitialQuery() {
|
1035
|
+
var _a, _b, _c, _d;
|
1035
1036
|
const productHandle = this.storeAPI.getCurrentProductHandle();
|
1036
1037
|
if (this.chatbotMessages.length) {
|
1037
1038
|
return;
|
@@ -1040,11 +1041,11 @@ let ShopGPT = class ShopGPT extends s {
|
|
1040
1041
|
this.isTyping = true;
|
1041
1042
|
const reply = await this.shopGPTAPI.processQuery('', productHandle);
|
1042
1043
|
this.chatbotMessages = [
|
1043
|
-
{ sender: 'bot', message: reply.message, product: reply.products[0] },
|
1044
|
+
{ sender: 'bot', message: reply.message, product: (_a = reply.products) === null || _a === void 0 ? void 0 : _a[0] },
|
1044
1045
|
...this.chatbotMessages,
|
1045
1046
|
];
|
1046
|
-
this.recommendedProduct = reply.products[0];
|
1047
|
-
this.moreRecommendations = reply.products.slice(1, 4);
|
1047
|
+
this.recommendedProduct = (_b = reply.products) === null || _b === void 0 ? void 0 : _b[0];
|
1048
|
+
this.moreRecommendations = (_d = (_c = reply.products) === null || _c === void 0 ? void 0 : _c.slice(1, 4)) !== null && _d !== void 0 ? _d : [];
|
1048
1049
|
this.setChatWindowHeight();
|
1049
1050
|
}
|
1050
1051
|
catch (error) {
|
@@ -1073,10 +1074,11 @@ let ShopGPT = class ShopGPT extends s {
|
|
1073
1074
|
});
|
1074
1075
|
}
|
1075
1076
|
resetProductRecommendations() {
|
1076
|
-
this.recommendedProduct =
|
1077
|
+
this.recommendedProduct = undefined;
|
1077
1078
|
this.moreRecommendations = [];
|
1078
1079
|
}
|
1079
1080
|
async sendMessageToServer(e, message) {
|
1081
|
+
var _a, _b, _c, _d;
|
1080
1082
|
e.preventDefault();
|
1081
1083
|
e.stopPropagation();
|
1082
1084
|
if (!message || this.isTyping || this.isLoadingHistory) {
|
@@ -1095,11 +1097,11 @@ let ShopGPT = class ShopGPT extends s {
|
|
1095
1097
|
return;
|
1096
1098
|
}
|
1097
1099
|
this.chatbotMessages = [
|
1098
|
-
{ sender: 'bot', message: reply.message, product: reply.products[0] },
|
1100
|
+
{ sender: 'bot', message: reply.message, product: (_a = reply.products) === null || _a === void 0 ? void 0 : _a[0] },
|
1099
1101
|
...this.chatbotMessages,
|
1100
1102
|
];
|
1101
|
-
this.recommendedProduct = reply.products[0];
|
1102
|
-
this.moreRecommendations = reply.products.slice(1, 4);
|
1103
|
+
this.recommendedProduct = (_b = reply.products) === null || _b === void 0 ? void 0 : _b[0];
|
1104
|
+
this.moreRecommendations = (_d = (_c = reply.products) === null || _c === void 0 ? void 0 : _c.slice(1, 4)) !== null && _d !== void 0 ? _d : [];
|
1103
1105
|
this.setChatWindowHeight();
|
1104
1106
|
}
|
1105
1107
|
catch (e) {
|