@droppii-org/chat-sdk 0.1.66 → 0.1.68
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/dist/components/conversation-detail/PinnedMessageBar.d.ts.map +1 -1
- package/dist/components/conversation-detail/PinnedMessageBar.js +11 -4
- package/dist/components/conversation-detail/PinnedMessagesPanel.js +1 -1
- package/dist/components/conversation-inbox/ConversationInboxItem.d.ts.map +1 -1
- package/dist/components/conversation-inbox/ConversationInboxItem.js +2 -2
- package/dist/components/message/item/CustomMessage.d.ts +7 -0
- package/dist/components/message/item/CustomMessage.d.ts.map +1 -0
- package/dist/components/message/item/CustomMessage.js +26 -0
- package/dist/components/message/item/TextMessage.d.ts.map +1 -1
- package/dist/components/message/item/TextMessage.js +0 -6
- package/dist/components/message/item/index.d.ts.map +1 -1
- package/dist/components/message/item/index.js +6 -51
- package/dist/components/message/item/renderMessageContent.d.ts.map +1 -1
- package/dist/components/message/item/renderMessageContent.js +3 -0
- package/dist/components/message/reply/ReplyQuoteContent.d.ts.map +1 -1
- package/dist/components/message/reply/ReplyQuoteContent.js +1 -1
- package/dist/components/message/toolbox/MessageToolboxMenu.js +1 -1
- package/dist/components/message/toolbox/types.d.ts +1 -0
- package/dist/components/message/toolbox/types.d.ts.map +1 -1
- package/dist/components/message/toolbox/types.js +1 -0
- package/dist/context/ChatContext.d.ts +1 -1
- package/dist/context/ChatContext.d.ts.map +1 -1
- package/dist/context/ChatContext.js +2 -1
- package/dist/hooks/global/useGlobalEvent.d.ts.map +1 -1
- package/dist/hooks/global/useGlobalEvent.js +8 -10
- package/dist/hooks/message/useMessage.d.ts +1 -0
- package/dist/hooks/message/useMessage.d.ts.map +1 -1
- package/dist/hooks/message/useMessage.js +16 -1
- package/dist/hooks/message/useRevokeMessage.d.ts +1 -0
- package/dist/hooks/message/useRevokeMessage.d.ts.map +1 -1
- package/dist/hooks/message/useRevokeMessage.js +22 -0
- package/dist/hooks/message/useSendCustomMessage.d.ts +7 -0
- package/dist/hooks/message/useSendCustomMessage.d.ts.map +1 -0
- package/dist/hooks/message/useSendCustomMessage.js +5 -0
- package/dist/hooks/message/useSendMessage.d.ts +9 -2
- package/dist/hooks/message/useSendMessage.d.ts.map +1 -1
- package/dist/hooks/message/useSendMessage.js +49 -3
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/locales/vi/common.json +6 -1
- package/dist/store/conversation.d.ts.map +1 -1
- package/dist/store/conversation.js +6 -0
- package/dist/store/type.d.ts +3 -0
- package/dist/store/type.d.ts.map +1 -1
- package/dist/styles/global.css +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/chat.d.ts +5 -2
- package/dist/types/chat.d.ts.map +1 -1
- package/dist/types/chat.js +4 -4
- package/dist/types/customMessage.d.ts +25 -0
- package/dist/types/customMessage.d.ts.map +1 -0
- package/dist/types/customMessage.js +4 -0
- package/dist/utils/common.d.ts +5 -2
- package/dist/utils/common.d.ts.map +1 -1
- package/dist/utils/common.js +26 -11
- package/dist/utils/customMessage.d.ts +5 -0
- package/dist/utils/customMessage.d.ts.map +1 -0
- package/dist/utils/customMessage.js +36 -0
- package/package.json +1 -1
package/dist/types/chat.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { FileMsgParamsByURL, ImageMsgParamsByURL, MessageType, Platform, SelfUserInfo, VideoMsgParamsByURL } from "@openim/wasm-client-sdk";
|
|
2
2
|
export type DChatPlatform = Platform;
|
|
3
3
|
import { UploadFile } from "antd";
|
|
4
|
+
import type { RenderCustomMessage } from "./customMessage";
|
|
4
5
|
export declare enum DChatApplicationType {
|
|
5
6
|
OBEFE = "OBEFE",
|
|
6
7
|
DROPPII = "DROPPII"
|
|
@@ -22,10 +23,10 @@ export declare enum CustomType {
|
|
|
22
23
|
CallingCancel = 203,
|
|
23
24
|
CallingHungup = 204
|
|
24
25
|
}
|
|
25
|
-
export declare enum
|
|
26
|
+
export declare enum UrlContentType {
|
|
26
27
|
URL = 160
|
|
27
28
|
}
|
|
28
|
-
export type DChatMessageType =
|
|
29
|
+
export type DChatMessageType = UrlContentType | MessageType;
|
|
29
30
|
export declare enum AccountType {
|
|
30
31
|
Collaborator = "Collaborator",
|
|
31
32
|
NewAgent = "NewAgent",
|
|
@@ -41,10 +42,12 @@ export interface ChatContextType {
|
|
|
41
42
|
getSelfUserInfo: () => void;
|
|
42
43
|
updateConnectStatus: (status: ConnectStatus) => void;
|
|
43
44
|
updateSyncStatus: (status: SyncStatus) => void;
|
|
45
|
+
renderCustomMessage?: RenderCustomMessage;
|
|
44
46
|
}
|
|
45
47
|
export interface ChatProviderProps {
|
|
46
48
|
children: React.ReactNode;
|
|
47
49
|
config: DChatInitAndLoginConfig | null;
|
|
50
|
+
renderCustomMessage?: RenderCustomMessage;
|
|
48
51
|
}
|
|
49
52
|
export interface UrlMetadataInfo {
|
|
50
53
|
title?: string;
|
package/dist/types/chat.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/types/chat.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,mBAAmB,EACpB,MAAM,yBAAyB,CAAC;AAEjC,MAAM,MAAM,aAAa,GAAG,QAAQ,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/types/chat.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,mBAAmB,EACpB,MAAM,yBAAyB,CAAC;AAEjC,MAAM,MAAM,aAAa,GAAG,QAAQ,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,KA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a;IACvB,UAAU,eAAe;IACzB,eAAe,oBAAoB;IACnC,UAAU,eAAe;IACzB,SAAS,cAAc;CACxB;AAED,oBAAY,UAAU;IACpB,IAAI,SAAS;IACb,eAAe,oBAAoB;IACnC,cAAc,mBAAmB;IACjC,kBAAkB,uBAAuB;CAC1C;AAED,oBAAY,wBAAwB;IAClC,qBAAqB,0BAA0B;IAC/C,cAAc,mBAAmB;IACjC,eAAe,oBAAoB;CACpC;AAED,oBAAY,0BAA0B;IACpC,IAAI,SAAS;IACb,OAAO,YAAY;CACpB"}
|
package/dist/types/chat.js
CHANGED
|
@@ -23,10 +23,10 @@ export var CustomType;
|
|
|
23
23
|
CustomType[CustomType["CallingCancel"] = 203] = "CallingCancel";
|
|
24
24
|
CustomType[CustomType["CallingHungup"] = 204] = "CallingHungup";
|
|
25
25
|
})(CustomType || (CustomType = {}));
|
|
26
|
-
export var
|
|
27
|
-
(function (
|
|
28
|
-
|
|
29
|
-
})(
|
|
26
|
+
export var UrlContentType;
|
|
27
|
+
(function (UrlContentType) {
|
|
28
|
+
UrlContentType[UrlContentType["URL"] = 160] = "URL";
|
|
29
|
+
})(UrlContentType || (UrlContentType = {}));
|
|
30
30
|
export var AccountType;
|
|
31
31
|
(function (AccountType) {
|
|
32
32
|
AccountType["Collaborator"] = "Collaborator";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { MessageItem } from "@openim/wasm-client-sdk";
|
|
3
|
+
export declare const CustomMessageType: {
|
|
4
|
+
readonly Order: "Order";
|
|
5
|
+
readonly Product: "Product";
|
|
6
|
+
};
|
|
7
|
+
export type CustomMessageType = (typeof CustomMessageType)[keyof typeof CustomMessageType];
|
|
8
|
+
export type CustomElemOrderData = {
|
|
9
|
+
id: string;
|
|
10
|
+
orderCode: string;
|
|
11
|
+
timestamp: number;
|
|
12
|
+
};
|
|
13
|
+
export type CustomMessagePayload = {
|
|
14
|
+
type: typeof CustomMessageType.Order;
|
|
15
|
+
data: CustomElemOrderData;
|
|
16
|
+
} | {
|
|
17
|
+
type: typeof CustomMessageType.Product;
|
|
18
|
+
data: Record<string, unknown>;
|
|
19
|
+
};
|
|
20
|
+
export interface RenderCustomMessageArgs {
|
|
21
|
+
message: MessageItem;
|
|
22
|
+
payload: CustomMessagePayload | null;
|
|
23
|
+
}
|
|
24
|
+
export type RenderCustomMessage = (args: RenderCustomMessageArgs) => ReactNode | null;
|
|
25
|
+
//# sourceMappingURL=customMessage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customMessage.d.ts","sourceRoot":"","sources":["../../src/types/customMessage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D,eAAO,MAAM,iBAAiB;;;CAGpB,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAC3B,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAC;AAE7D,MAAM,MAAM,mBAAmB,GAAG;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAC5B;IAAE,IAAI,EAAE,OAAO,iBAAiB,CAAC,KAAK,CAAC;IAAC,IAAI,EAAE,mBAAmB,CAAA;CAAE,GACnE;IAAE,IAAI,EAAE,OAAO,iBAAiB,CAAC,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,CAAC;AAE9E,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,WAAW,CAAC;IACrB,OAAO,EAAE,oBAAoB,GAAG,IAAI,CAAC;CACtC;AAED,MAAM,MAAM,mBAAmB,GAAG,CAChC,IAAI,EAAE,uBAAuB,KAC1B,SAAS,GAAG,IAAI,CAAC"}
|
package/dist/utils/common.d.ts
CHANGED
|
@@ -4,8 +4,11 @@ import { UrlMetadataInfo } from "../types/chat";
|
|
|
4
4
|
export declare const parseUrlMetadata: (ex?: string) => UrlMetadataInfo | undefined;
|
|
5
5
|
export declare function formatDuration(seconds: number): string;
|
|
6
6
|
export declare function renderFileSize(bytes: number): string;
|
|
7
|
-
export declare const generateContentBasedOnMessageType: (contentType: MessageType, plainText?: string, t?: TFunction
|
|
8
|
-
|
|
7
|
+
export declare const generateContentBasedOnMessageType: (contentType: MessageType, plainText?: string, t?: TFunction, customElem?: {
|
|
8
|
+
extension?: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
}) => string;
|
|
11
|
+
export declare const parseLatestMessage: (latestMsg: string, currentUserId?: string, t?: TFunction) => string;
|
|
9
12
|
export declare const highlightSearch: (text: string, keyword: string, maxLength?: number) => string;
|
|
10
13
|
interface FormatOptions {
|
|
11
14
|
hasTime?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/utils/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGnE,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAqB,eAAe,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/utils/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGnE,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAqB,eAAe,EAAE,MAAM,cAAc,CAAC;AAIlE,eAAO,MAAM,gBAAgB,GAAI,KAAK,MAAM,KAAG,eAAe,GAAG,SAQhE,CAAC;AAiBF,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAItD;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAapD;AAED,eAAO,MAAM,iCAAiC,GAC5C,aAAa,WAAW,EACxB,YAAY,MAAM,EAClB,IAAI,SAAS,EACb,aAAa;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,WA6B1D,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAC7B,WAAW,MAAM,EACjB,gBAAgB,MAAM,EACtB,IAAI,SAAS,WA4Dd,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,MAAM,MAAM,EACZ,SAAS,MAAM,EACf,kBAAc,WA2Cf,CAAC;AAEF,UAAU,aAAa;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAgB,eAAe,CAC7B,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,aAAa,GACtB,MAAM,CAqBR;AAED,eAAO,MAAM,QAAQ,QAAkD,CAAC;AAExE,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAqC3D;AAED,eAAO,MAAM,cAAc,GAAI,KAAK,MAAM,KAAG,MAAM,GAAG,IAOrD,CAAC;AAKF,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,KAAG,OACf,CAAC;AAEnC,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,KAAG,MAO9B,CAAC;AAEZ;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAgEjD"}
|
package/dist/utils/common.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MessageType } from "@openim/wasm-client-sdk";
|
|
2
2
|
import dayjs from "dayjs";
|
|
3
3
|
import DOMPurify from "dompurify";
|
|
4
|
+
import { CustomMessageType } from "../types/customMessage";
|
|
4
5
|
import { getSystemLogMessageText } from "./messageLog";
|
|
5
6
|
export const parseUrlMetadata = (ex) => {
|
|
6
7
|
if (!ex)
|
|
@@ -41,10 +42,11 @@ export function renderFileSize(bytes) {
|
|
|
41
42
|
}
|
|
42
43
|
return `${size.toFixed(1)} ${units[index]}`;
|
|
43
44
|
}
|
|
44
|
-
export const generateContentBasedOnMessageType = (contentType, plainText, t) => {
|
|
45
|
+
export const generateContentBasedOnMessageType = (contentType, plainText, t, customElem) => {
|
|
45
46
|
switch (contentType) {
|
|
46
47
|
case MessageType.TextMessage:
|
|
47
48
|
case MessageType.QuoteMessage:
|
|
49
|
+
case MessageType.UrlTextMessage:
|
|
48
50
|
case MessageType.LogTextMessage:
|
|
49
51
|
return plainText || "";
|
|
50
52
|
case MessageType.PictureMessage:
|
|
@@ -56,46 +58,59 @@ export const generateContentBasedOnMessageType = (contentType, plainText, t) =>
|
|
|
56
58
|
return t ? t("msg_type_video") : "[Video]";
|
|
57
59
|
case MessageType.FileMessage:
|
|
58
60
|
return t ? t("msg_type_file") : "[Tập tin]";
|
|
59
|
-
case MessageType.UrlTextMessage:
|
|
60
|
-
return t ? t("msg_type_link") : "[Liên kết]";
|
|
61
61
|
case MessageType.RevokeMessage:
|
|
62
62
|
return t ? t("revoked") : "Đã thu hồi tin nhắn";
|
|
63
|
+
case MessageType.CustomMessage: {
|
|
64
|
+
if ((customElem === null || customElem === void 0 ? void 0 : customElem.extension) !== CustomMessageType.Order)
|
|
65
|
+
return "";
|
|
66
|
+
const orderCode = (customElem === null || customElem === void 0 ? void 0 : customElem.description) || "";
|
|
67
|
+
return t
|
|
68
|
+
? t("msg_type_order", { orderCode })
|
|
69
|
+
: `[Đơn hàng] ${orderCode}`;
|
|
70
|
+
}
|
|
63
71
|
default:
|
|
64
72
|
return "";
|
|
65
73
|
}
|
|
66
74
|
};
|
|
67
|
-
export const parseLatestMessage = (latestMsg, currentUserId, t
|
|
68
|
-
var _a, _b, _c;
|
|
75
|
+
export const parseLatestMessage = (latestMsg, currentUserId, t) => {
|
|
76
|
+
var _a, _b, _c, _d, _e, _f;
|
|
69
77
|
if (!latestMsg || !t)
|
|
70
78
|
return "";
|
|
71
79
|
try {
|
|
72
80
|
const msgData = JSON.parse(latestMsg);
|
|
73
81
|
const contentType = msgData === null || msgData === void 0 ? void 0 : msgData.contentType;
|
|
74
|
-
const isSelfSender = !!currentUserId && msgData.sendID === currentUserId;
|
|
75
82
|
const sender = getSenderLabelForLatestPreview(msgData, currentUserId, t);
|
|
76
|
-
const senderPrefix = !onlySelfSender || isSelfSender ? `${sender}: ` : "";
|
|
77
83
|
switch (contentType) {
|
|
78
84
|
case MessageType.LogTextMessage:
|
|
79
85
|
return getSystemLogMessageText(msgData);
|
|
80
86
|
case MessageType.TextMessage:
|
|
81
87
|
case MessageType.QuoteMessage:
|
|
82
|
-
|
|
88
|
+
case MessageType.UrlTextMessage:
|
|
89
|
+
return `${sender}: ${generateContentBasedOnMessageType(contentType, ((_a = msgData === null || msgData === void 0 ? void 0 : msgData.textElem) === null || _a === void 0 ? void 0 : _a.content) ||
|
|
90
|
+
((_b = msgData === null || msgData === void 0 ? void 0 : msgData.quoteElem) === null || _b === void 0 ? void 0 : _b.text) ||
|
|
91
|
+
((_c = msgData === null || msgData === void 0 ? void 0 : msgData.urlTextElem) === null || _c === void 0 ? void 0 : _c.content) ||
|
|
92
|
+
"")}`;
|
|
83
93
|
case MessageType.PictureMessage:
|
|
84
94
|
case MessageType.MergeMessage:
|
|
85
95
|
case MessageType.VoiceMessage:
|
|
86
96
|
case MessageType.VideoMessage:
|
|
87
97
|
case MessageType.FileMessage:
|
|
88
|
-
|
|
98
|
+
return `${sender}: ${generateContentBasedOnMessageType(contentType)}`;
|
|
89
99
|
case MessageType.RevokeMessage:
|
|
90
|
-
return
|
|
100
|
+
return t("revoked_with_sender", { name: sender });
|
|
91
101
|
case MessageType.CustomMessage: {
|
|
92
|
-
const customData = (
|
|
102
|
+
const customData = (_d = msgData.customElem) === null || _d === void 0 ? void 0 : _d.data;
|
|
93
103
|
if (customData === "#SESSION - START") {
|
|
94
104
|
return t("session_started");
|
|
95
105
|
}
|
|
96
106
|
if (customData === "#SESSION - END") {
|
|
97
107
|
return t("session_ended");
|
|
98
108
|
}
|
|
109
|
+
if (((_e = msgData.customElem) === null || _e === void 0 ? void 0 : _e.extension) === CustomMessageType.Order) {
|
|
110
|
+
return `${sender}: ${t("msg_type_order", {
|
|
111
|
+
orderCode: ((_f = msgData.customElem) === null || _f === void 0 ? void 0 : _f.description) || "",
|
|
112
|
+
})}`;
|
|
113
|
+
}
|
|
99
114
|
return "";
|
|
100
115
|
}
|
|
101
116
|
default:
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { MessageItem } from "@openim/wasm-client-sdk";
|
|
2
|
+
import { type CustomMessagePayload } from "../types/customMessage";
|
|
3
|
+
export declare const isRenderableCustomMessage: (message: MessageItem) => boolean;
|
|
4
|
+
export declare const parseCustomMessagePayload: (message: MessageItem) => CustomMessagePayload | null;
|
|
5
|
+
//# sourceMappingURL=customMessage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customMessage.d.ts","sourceRoot":"","sources":["../../src/utils/customMessage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAGL,KAAK,oBAAoB,EAC1B,MAAM,uBAAuB,CAAC;AAY/B,eAAO,MAAM,yBAAyB,GAAI,SAAS,WAAW,KAAG,OAGhE,CAAC;AAEF,eAAO,MAAM,yBAAyB,GACpC,SAAS,WAAW,KACnB,oBAAoB,GAAG,IAuBzB,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { CustomMessageType, } from "../types/customMessage";
|
|
2
|
+
const KNOWN_CUSTOM_MESSAGE_TYPES = Object.values(CustomMessageType);
|
|
3
|
+
const isCustomElemOrderData = (data) => {
|
|
4
|
+
if (typeof data !== "object" || data === null)
|
|
5
|
+
return false;
|
|
6
|
+
const orderData = data;
|
|
7
|
+
return (typeof orderData.id === "string" && typeof orderData.orderCode === "string");
|
|
8
|
+
};
|
|
9
|
+
export const isRenderableCustomMessage = (message) => {
|
|
10
|
+
var _a;
|
|
11
|
+
const extension = (_a = message === null || message === void 0 ? void 0 : message.customElem) === null || _a === void 0 ? void 0 : _a.extension;
|
|
12
|
+
return !!extension && KNOWN_CUSTOM_MESSAGE_TYPES.includes(extension);
|
|
13
|
+
};
|
|
14
|
+
export const parseCustomMessagePayload = (message) => {
|
|
15
|
+
const customElem = message === null || message === void 0 ? void 0 : message.customElem;
|
|
16
|
+
if (!customElem || !isRenderableCustomMessage(message))
|
|
17
|
+
return null;
|
|
18
|
+
let parsedData = null;
|
|
19
|
+
try {
|
|
20
|
+
parsedData = JSON.parse(customElem.data || "");
|
|
21
|
+
}
|
|
22
|
+
catch (_a) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
if (typeof parsedData !== "object" || parsedData === null)
|
|
26
|
+
return null;
|
|
27
|
+
if (customElem.extension === CustomMessageType.Order) {
|
|
28
|
+
return isCustomElemOrderData(parsedData)
|
|
29
|
+
? { type: CustomMessageType.Order, data: parsedData }
|
|
30
|
+
: null;
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
type: CustomMessageType.Product,
|
|
34
|
+
data: parsedData,
|
|
35
|
+
};
|
|
36
|
+
};
|